NAP
shadervariabledeclarations.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // Local includes
8 #include "vulkan/vulkan_core.h"
9 #include "rtti/typeinfo.h"
10 
11 // External Includes
12 #include <nap/numeric.h>
13 #include <string>
14 #include <vector>
15 
16 namespace nap
17 {
28  enum class EDescriptorType : uint
29  {
30  Uniform,
31  Storage
32  };
33 
34 
39  {
40  Unknown = 0,
41  Float,
42  Int,
43  UInt,
44  Vec2,
45  Vec3,
46  Vec4,
47  IVec4,
48  UVec4,
49  Mat2,
50  Mat3,
51  Mat4
52  };
53 
54 
59  {
60  RTTI_ENABLE()
61  public:
62  ShaderVariableDeclaration(const std::string& name, int offset, int size);
64 
65  // Move is allowed
67  ShaderVariableDeclaration& operator=(ShaderVariableDeclaration&& inRHS) = default;
68 
69  // Copy is not allowed
71  ShaderVariableDeclaration& operator=(const ShaderVariableDeclaration&) = delete;
72 
73  std::string mName;
74  int mOffset;
75  int mSize;
76  };
77 
78 
83  {
84  RTTI_ENABLE(ShaderVariableDeclaration)
85 
86  public:
87  ShaderVariableValueDeclaration(const std::string& name, int offset, int size, EShaderVariableValueType type);
89  };
90 
91 
96  {
97  RTTI_ENABLE(ShaderVariableDeclaration)
98  public:
99  ShaderVariableStructDeclaration(const std::string& name, EDescriptorType descriptorType, int offset, int size);
100  virtual ~ShaderVariableStructDeclaration() override;
101 
104 
110  const ShaderVariableDeclaration* findMember(const std::string& name) const;
111  std::vector<std::unique_ptr<ShaderVariableDeclaration>> mMembers;
113  };
114 
115 
120  {
121  RTTI_ENABLE(ShaderVariableDeclaration)
122  public:
123  ShaderVariableStructArrayDeclaration(const std::string& name, int offset, int size);
124 
127 
128  std::vector<std::unique_ptr<ShaderVariableStructDeclaration>> mElements;
129  };
130 
131 
141  {
142  RTTI_ENABLE(ShaderVariableDeclaration)
143  public:
144  ShaderVariableStructBufferDeclaration(const std::string& name, int offset, int size, int stride, int numElements);
145 
146  std::unique_ptr<ShaderVariableStructDeclaration> mElement;
148  int mStride;
149  };
150 
151 
156  {
157  RTTI_ENABLE(ShaderVariableDeclaration)
158  public:
159  ShaderVariableValueArrayDeclaration(const std::string& name, int offset, int size, int stride, EShaderVariableValueType elementType, int numElements);
160 
163  int mStride;
164  };
165 
166 
172  {
174  public:
175  BufferObjectDeclaration(const std::string& name, int binding, VkShaderStageFlags inStages, EDescriptorType descriptorType, int size);
176 
179 
184  const ShaderVariableDeclaration& getBufferDeclaration() const;
185 
186  int mBinding;
187  VkShaderStageFlags mStages;
188  };
189 
190  // Type alias
191  using BufferObjectDeclarationList = std::vector<nap::BufferObjectDeclaration>;
192 }
nap::uint
unsigned int uint
Definition: numeric.h:23
nap::ShaderVariableDeclaration
Definition: shadervariabledeclarations.h:58
nap::EShaderVariableValueType::IVec4
@ IVec4
4 int vector
nap::EShaderVariableValueType::Mat3
@ Mat3
3x3 float matrix
nap::ShaderVariableValueDeclaration::mType
EShaderVariableValueType mType
ShaderVariable type.
Definition: shadervariabledeclarations.h:88
nap::EShaderVariableValueType::Vec4
@ Vec4
4 float vector
nap::uint8
uint8_t uint8
Definition: numeric.h:16
nap::EShaderVariableValueType::Float
@ Float
float
nap::ShaderVariableDeclaration::~ShaderVariableDeclaration
virtual ~ShaderVariableDeclaration()
Definition: shadervariabledeclarations.h:63
nap::EShaderVariableValueType::Vec3
@ Vec3
3 float vector
nap::ShaderVariableValueArrayDeclaration::mNumElements
int mNumElements
Total number of elements in list.
Definition: shadervariabledeclarations.h:162
nap::EShaderVariableValueType::Int
@ Int
int
nap::ShaderVariableDeclaration::mOffset
int mOffset
Memory offset.
Definition: shadervariabledeclarations.h:74
nap::ShaderVariableStructArrayDeclaration::mElements
std::vector< std::unique_ptr< ShaderVariableStructDeclaration > > mElements
Struct declaration.
Definition: shadervariabledeclarations.h:128
nap::ShaderVariableStructBufferDeclaration::mNumElements
int mNumElements
Total number of struct elements in list.
Definition: shadervariabledeclarations.h:147
nap::EShaderVariableValueType::UVec4
@ UVec4
4 uint vector
nap::ShaderVariableStructBufferDeclaration
Definition: shadervariabledeclarations.h:140
nap::ShaderVariableStructBufferDeclaration::mStride
int mStride
Stride of struct element in array.
Definition: shadervariabledeclarations.h:148
nap::ShaderVariableValueArrayDeclaration::mStride
int mStride
Stride of element in array.
Definition: shadervariabledeclarations.h:163
nap::ShaderVariableStructArrayDeclaration
Definition: shadervariabledeclarations.h:119
nap::BufferObjectDeclaration::mStages
VkShaderStageFlags mStages
Shader stages: vertex, fragment, compute etc.
Definition: shadervariabledeclarations.h:187
nap::EShaderVariableValueType::Mat4
@ Mat4
4x4 float matrix
nap::ShaderVariableValueArrayDeclaration::mElementType
EShaderVariableValueType mElementType
Shader variable type.
Definition: shadervariabledeclarations.h:161
nap::ShaderVariableStructDeclaration::mDescriptorType
EDescriptorType mDescriptorType
The type of descriptor for this resource.
Definition: shadervariabledeclarations.h:112
nap::EDescriptorType
EDescriptorType
Definition: shadervariabledeclarations.h:28
nap::EShaderVariableValueType
EShaderVariableValueType
Definition: shadervariabledeclarations.h:38
nap::BufferObjectDeclarationList
std::vector< nap::BufferObjectDeclaration > BufferObjectDeclarationList
Definition: shadervariabledeclarations.h:191
nap::ShaderVariableDeclaration::mSize
int mSize
Total size (in bytes) of declaration.
Definition: shadervariabledeclarations.h:75
nap::EDescriptorType::Uniform
@ Uniform
Specifies a uniform buffer descriptor. device readonly.
nap::ShaderVariableStructDeclaration
Definition: shadervariabledeclarations.h:95
nap
Definition: templateapp.h:17
nap::ShaderVariableValueDeclaration
Definition: shadervariabledeclarations.h:82
nap::ShaderVariableDeclaration::mName
std::string mName
Name of the declaration.
Definition: shadervariabledeclarations.h:73
nap::EShaderVariableValueType::Unknown
@ Unknown
unknown or invalid shader uniform
nap::BufferObjectDeclaration
Definition: shadervariabledeclarations.h:171
nap::EDescriptorType::Storage
@ Storage
Specifies a storage buffer descriptor. device read/write.
nap::BufferObjectDeclaration::mBinding
int mBinding
Shader binding identifier.
Definition: shadervariabledeclarations.h:186
nap::ShaderVariableStructBufferDeclaration::mElement
std::unique_ptr< ShaderVariableStructDeclaration > mElement
Struct declaration.
Definition: shadervariabledeclarations.h:146
nap::EShaderVariableValueType::Mat2
@ Mat2
2x2 float matrix
nap::ShaderVariableStructDeclaration::mMembers
std::vector< std::unique_ptr< ShaderVariableDeclaration > > mMembers
All shader declarations associated with struct.
Definition: shadervariabledeclarations.h:111
nap::ShaderVariableValueArrayDeclaration
Definition: shadervariabledeclarations.h:155
nap::EShaderVariableValueType::UInt
@ UInt
unsigned int
nap::EShaderVariableValueType::Vec2
@ Vec2
2 float vector