HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RV_VKPipelineLayout.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: RV_VKPipelineLayout.h ( RV Library, C++)
7  *
8  * COMMENTS:
9  * Class Representing a Vulkan Graphics Pipeline Layout
10  * And sub-classes used in layout creation
11  */
12 
13 #ifndef RV_VKPipelineLayout_h
14 #define RV_VKPipelineLayout_h
15 
16 #include "RV_API.h"
17 
18 #include <UT/UT_Array.h>
19 #include <UT/UT_Map.h>
20 #include <UT/UT_StringHolder.h>
21 #include <UT/UT_UniquePtr.h>
22 #include <UT/UT_NonCopyable.h>
23 
24 #include <SYS/SYS_Hash.h>
25 
26 #include <VE/VE_VK.h>
28 #include "RV_Type.h"
29 #include "RV_TypePtrs.h"
30 #include "RV_VKDescriptorSet.h"
31 
32 class RV_Instance;
33 class RV_VKShaderModule;
34 class RV_VKShader;
35 class RV_VKShaderReflect;
36 
37 class RV_Uniform;
38 class RV_VKDescriptorSet;
43 
45 {
46 public:
48  int location = -1;
50 
51  bool operator== (const RV_VKAttributeInfo& other) const
52  {
53  return format == other.format
54  && location == other.location
55  && myName == other.myName;
56  }
57 };
58 
59 // ------------------------
60 // RV_VKPushConstantRange
62 {
65  int myOffset;
66  int mySize;
67 
68  bool operator==(const RV_VKPushConstantRange &other) const
69  {
70  return myOffset == other.myOffset
71  && mySize == other.mySize
72  && myStages == other.myStages;
73  }
74 };
75 
76 
77 // -----------------------
78 // Push Constant info
80 {
81 public:
82  RV_VKPushConstantInfo() = default;
84  UT_Array<RV_Uniform>&& members,
86  int offset,
87  int size);
88 
90  { return myRanges; }
91 
92  bool merge(const RV_VKPushConstantInfo& other);
93  bool merge(const RV_VKPushConstantRange& new_range);
94 
95  bool operator== (const RV_VKPushConstantInfo & other) const
96  { return myRanges == other.myRanges; }
97 
98  bool operator!= (const RV_VKPushConstantInfo & other) const
99  { return !(myRanges == other.myRanges); }
100 
101 private:
103  friend class RV_VKPipelineLayout;
104 };
105 
106 // -----------------------
107 // RV_VKPipelineLayoutInfo
108 //
109 // NOTE: unlike other info classes, this one owns resource handles
110 // so can't be directly copied
111 // It shouldn't need to be, as shader layouts are unique
112 //
113 // tracks Pipeline create info that will be constant accross all pipelines
114 // created from the same set of shaders. This includes all of the data for creating the
115 // pipeline layout, and SOME of the structs for the final pipeline
116 // Effectively just the pipeline layout + the vertex attribute formats
118 {
119 public:
122 
123  // NOTE: currently, since pipeline layouts are built from shader
124  // files, they must be a specific shader type, and we
125  // will not have layouts that can be used with multiple
126  // pipeline types (e.g. graphics + compute) .. if changing
127  // this, pipeline type will need to be provided at higher
128  // level
129  // NOTE: simliarily, some of the values here are only valid for either
130  // for graphices or compute shaders (i.e. workgroup size, inputs)
132 
136 
137  UT_Vector3i myWorkGroupSize = UT_Vector3i(0,0,0);
138  bool myWorkGroupIsSpecConst = false;
139 
140  // features requires
141  VE_PhysicalDeviceFeatures myRequiredFeatures = {};
142 
143  // TODO: list of specialization constants
144  //UT_Array<RV_SpecializaitonConstant>
145 
146  bool isInit() const;
147  bool isValidForCompile(RV_Instance *inst) const;
148  bool isGraphicsShader() const;
149  bool isComputeShader() const;
150 
151  // Creation Structs
152  bool hasShaderStage(VkShaderStageFlagBits stage) const;
153  bool addShaderModule(RV_VKShaderModuleInfo *shader_module);
154  bool addShaderModule(RV_VKShaderReflect& module_info, VkShaderStageFlagBits stage);
155 
156  bool operator==(const RV_VKPipelineLayoutInfo& other) const;
157 
158  SYS_HashType calcHash() const;
159 };
160 
162 {
163  return in.calcHash();
164 }
165 
166 // ----------------------
167 // RV_VKPipelineLayout
168 //
169 // RAII wrapper for VkPipelineLayout, created using RV_VKPipelineLayoutInfo
170 // Also takes ownership of the shader modules matching it, which are also
171 // needed to create pipelines
173 {
174 public:
175 
176  VkPipelineLayout getVkLayout() const { return myVkPipelineLayout; }
177 
178  const RV_VKPipelineLayoutInfo& getInfo() const { return *myInfo; }
179 
181  { return myShaderModules; }
182 
184  RV_Instance* inst,
185  VkPipelineLayout pipe_layout,
187  UT_Array<RV_VKShaderModulePtr> shader_modules);
188 
189  RV_VKPipelineLayout(const RV_VKPipelineLayout&) = delete;
191 
193 protected:
194  RV_Instance* myInst = nullptr;
195  VkPipelineLayout myVkPipelineLayout = VK_NULL_HANDLE;
196 
199 };
200 
201 /// convenience function to fill out a pipeline layout info struct
202 /// matching the list of passed in shader modules. Returns null if
203 /// the modules are invalid, or there is an error
205  const char* name,
207 
208 /// Create a pipeline layout loading a list of compiled SPIR-V files
209 /// and matching spirv modules. It is up to the caller to ensure that
210 /// the info struct matches the conde in the shader modules.
211 /// Failure to do so can result in errors or undefined behavior.
212 /// Takes ownership of the shader modules
214  RV_Instance* inst,
217 
218 /// Create a pipeline layout from an RV_VKShader that compiled SPIR-V shaders
220  RV_Instance* inst,
221  const char* name,
223 
224 /// Create a pipeline layout from a list of SPIR-V VkShaderModules
226  RV_Instance* inst,
227  const char* name,
229 
230 /// Create a pipeline layout loading a list of compiled SPIR-V files
232  RV_Instance* inst,
233  const char* name,
234  const UT_StringArray& filenames);
235 
236 #endif
#define VK_NULL_HANDLE
Definition: vulkan_core.h:45
UT_Vector3T< int32 > UT_Vector3i
SYS_HashType hash_value(const RV_VKPipelineLayoutInfo &in)
VkShaderStageFlags myStages
const UT_Array< RV_VKPushConstantRange > & getRanges() const
std::size_t SYS_HashType
Define the type for hash values.
Definition: SYS_Hash.h:19
UT_UniquePtr< RV_VKPipelineLayoutInfo > myInfo
constexpr auto in(type t, int set) -> bool
Definition: core.h:611
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
SYS_HashType calcHash() const
GLintptr offset
Definition: glcorearb.h:665
const RV_VKPipelineLayoutInfo & getInfo() const
RV_API UT_UniquePtr< RV_VKPipelineLayoutInfo > RVfillPipelineLayoutInfo(const char *name, UT_Array< RV_VKShaderModuleInfoPtr > &shaders)
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
const UT_Array< RV_VKShaderModulePtr > & getShaderModules() const
#define RV_API
Definition: RV_API.h:10
GLint location
Definition: glcorearb.h:805
UT_StringHolder myName
UT_Array< RV_VKAttributeInfo > myInputs
RV_API RV_VKPipelineLayoutPtr RVcreatePipelineLayout(RV_Instance *inst, UT_UniquePtr< RV_VKPipelineLayoutInfo > info, UT_Array< RV_VKShaderModulePtr > shaders)
VkShaderStageFlagBits
Definition: vulkan_core.h:2594
GLuint const GLchar * name
Definition: glcorearb.h:786
GLsizei GLsizei GLuint * shaders
Definition: glcorearb.h:797
VkPipelineLayout getVkLayout() const
Handle to the main interface of Vulkan.
Definition: RV_Instance.h:48
RV_ShaderType
Definition: RV_Type.h:418
UT_Array< RV_VKShaderModulePtr > myShaderModules
RAII wrapper class for Vk Shader Module.
GLsizeiptr size
Definition: glcorearb.h:664
GLuint shader
Definition: glcorearb.h:785
Info loaded from file, used to create VK Shader Module.
RV_VKPushConstantInfo myPushConstants
LeafData & operator=(const LeafData &)=delete
UT_UniquePtr< RV_VKPipelineLayout > RV_VKPipelineLayoutPtr
Definition: RV_TypePtrs.h:72
VkFormat
Definition: vulkan_core.h:1386
OutGridT XformOp bool bool MergePolicy merge
bool operator!=(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:165
UT_Array< RV_VKDescriptorSetInfo > myDescriptorSets
Type info for a single variable in a shader.
bool operator==(const RV_VKAttributeInfo &other) const
UT_Array< RV_Uniform > myMembers
VkFlags VkShaderStageFlags
Definition: vulkan_core.h:2660
bool operator==(const RV_VKPushConstantRange &other) const