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  std::string mName;
66  int mOffset;
67  int mSize;
68  };
69 
70 
75  {
76  RTTI_ENABLE(ShaderVariableDeclaration)
77 
78  public:
79  ShaderVariableValueDeclaration(const std::string& name, int offset, int size, EShaderVariableValueType type);
81  };
82 
83 
88  {
89  RTTI_ENABLE(ShaderVariableDeclaration)
90  public:
91  ShaderVariableStructDeclaration(const std::string& name, EDescriptorType descriptorType, int offset, int size);
92  virtual ~ShaderVariableStructDeclaration() override;
93 
98 
104  const ShaderVariableDeclaration* findMember(const std::string& name) const;
105  std::vector<std::unique_ptr<ShaderVariableDeclaration>> mMembers;
107  };
108 
109 
114  {
115  RTTI_ENABLE(ShaderVariableDeclaration)
116  public:
117  ShaderVariableStructArrayDeclaration(const std::string& name, int offset, int size);
118 
119  std::vector<std::unique_ptr<ShaderVariableStructDeclaration>> mElements;
120  };
121 
122 
132  {
133  RTTI_ENABLE(ShaderVariableDeclaration)
134  public:
135  ShaderVariableStructBufferDeclaration(const std::string& name, int offset, int size, int stride, int numElements);
136 
137  std::unique_ptr<ShaderVariableStructDeclaration> mElement;
139  int mStride;
140  };
141 
142 
147  {
148  RTTI_ENABLE(ShaderVariableDeclaration)
149  public:
150  ShaderVariableValueArrayDeclaration(const std::string& name, int offset, int size, int stride, EShaderVariableValueType elementType, int numElements);
151 
154  int mStride;
155  };
156 
157 
163  {
165  public:
166  BufferObjectDeclaration(const std::string& name, int binding, VkShaderStageFlags inStages, EDescriptorType descriptorType, int size);
167 
172 
178 
179  int mBinding;
180  VkShaderStageFlags mStages;
181  };
182 
183  // Type alias
184  using BufferObjectDeclarationList = std::vector<nap::BufferObjectDeclaration>;
185 }
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::BufferObjectDeclaration::BufferObjectDeclaration
BufferObjectDeclaration(const std::string &name, int binding, VkShaderStageFlags inStages, EDescriptorType descriptorType, int size)
nap::ShaderVariableValueDeclaration::mType
EShaderVariableValueType mType
ShaderVariable type.
Definition: shadervariabledeclarations.h:80
nap::ShaderVariableValueDeclaration::ShaderVariableValueDeclaration
ShaderVariableValueDeclaration(const std::string &name, int offset, int size, EShaderVariableValueType type)
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:153
nap::EShaderVariableValueType::Int
@ Int
int
nap::ShaderVariableDeclaration::mOffset
int mOffset
Memory offset.
Definition: shadervariabledeclarations.h:66
nap::ShaderVariableStructArrayDeclaration::mElements
std::vector< std::unique_ptr< ShaderVariableStructDeclaration > > mElements
Struct declaration.
Definition: shadervariabledeclarations.h:119
nap::ShaderVariableStructBufferDeclaration::mNumElements
int mNumElements
Total number of struct elements in list.
Definition: shadervariabledeclarations.h:138
nap::EShaderVariableValueType::UVec4
@ UVec4
4 uint vector
nap::ShaderVariableStructBufferDeclaration
Definition: shadervariabledeclarations.h:131
nap::ShaderVariableStructBufferDeclaration::mStride
int mStride
Stride of struct element in array.
Definition: shadervariabledeclarations.h:139
nap::BufferObjectDeclaration::getBufferDeclaration
const ShaderVariableDeclaration & getBufferDeclaration() const
nap::ShaderVariableValueArrayDeclaration::mStride
int mStride
Stride of element in array.
Definition: shadervariabledeclarations.h:154
nap::ShaderVariableStructArrayDeclaration
Definition: shadervariabledeclarations.h:113
nap::ShaderVariableDeclaration::ShaderVariableDeclaration
ShaderVariableDeclaration(const std::string &name, int offset, int size)
nap::ShaderVariableStructArrayDeclaration::ShaderVariableStructArrayDeclaration
ShaderVariableStructArrayDeclaration(const std::string &name, int offset, int size)
nap::BufferObjectDeclaration::mStages
VkShaderStageFlags mStages
Shader stages: vertex, fragment, compute etc.
Definition: shadervariabledeclarations.h:180
nap::BufferObjectDeclaration::operator=
BufferObjectDeclaration & operator=(BufferObjectDeclaration &&inRHS)
nap::EShaderVariableValueType::Mat4
@ Mat4
4x4 float matrix
nap::ShaderVariableValueArrayDeclaration::mElementType
EShaderVariableValueType mElementType
Shader variable type.
Definition: shadervariabledeclarations.h:152
nap::ShaderVariableStructDeclaration::mDescriptorType
EDescriptorType mDescriptorType
The type of descriptor for this resource.
Definition: shadervariabledeclarations.h:106
nap::EDescriptorType
EDescriptorType
Definition: shadervariabledeclarations.h:28
nap::EShaderVariableValueType
EShaderVariableValueType
Definition: shadervariabledeclarations.h:38
nap::BufferObjectDeclarationList
std::vector< nap::BufferObjectDeclaration > BufferObjectDeclarationList
Definition: shadervariabledeclarations.h:184
nap::ShaderVariableDeclaration::mSize
int mSize
Total size (in bytes) of declaration.
Definition: shadervariabledeclarations.h:67
nap::EDescriptorType::Uniform
@ Uniform
Specifies a uniform buffer descriptor. device readonly.
nap::ShaderVariableStructDeclaration
Definition: shadervariabledeclarations.h:87
nap
Definition: assert.h:10
nap::ShaderVariableValueDeclaration
Definition: shadervariabledeclarations.h:74
nap::ShaderVariableDeclaration::mName
std::string mName
Name of the declaration.
Definition: shadervariabledeclarations.h:65
nap::ShaderVariableValueArrayDeclaration::ShaderVariableValueArrayDeclaration
ShaderVariableValueArrayDeclaration(const std::string &name, int offset, int size, int stride, EShaderVariableValueType elementType, int numElements)
nap::EShaderVariableValueType::Unknown
@ Unknown
unknown or invalid shader uniform
nap::BufferObjectDeclaration
Definition: shadervariabledeclarations.h:162
nap::ShaderVariableStructBufferDeclaration::ShaderVariableStructBufferDeclaration
ShaderVariableStructBufferDeclaration(const std::string &name, int offset, int size, int stride, int numElements)
nap::EDescriptorType::Storage
@ Storage
Specifies a storage buffer descriptor. device read/write.
nap::BufferObjectDeclaration::mBinding
int mBinding
Shader binding identifier.
Definition: shadervariabledeclarations.h:179
nap::ShaderVariableStructBufferDeclaration::mElement
std::unique_ptr< ShaderVariableStructDeclaration > mElement
Struct declaration.
Definition: shadervariabledeclarations.h:137
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:105
nap::ShaderVariableValueArrayDeclaration
Definition: shadervariabledeclarations.h:146
nap::EShaderVariableValueType::UInt
@ UInt
unsigned int
nap::EShaderVariableValueType::Vec2
@ Vec2
2 float vector