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 
38 {
39 public:
41  int location = -1;
43 
44  bool operator== (const RV_VKAttributeInfo& other) const
45  {
46  return format == other.format
47  && location == other.location
48  && myName == other.myName;
49  }
50 };
51 
52 // ------------------------
53 // RV_VKPushConstantRange
55 {
58  int myOffset;
59  int mySize;
60 
61  bool operator==(const RV_VKPushConstantRange &other) const
62  {
63  return myOffset == other.myOffset
64  && mySize == other.mySize
65  && myStages == other.myStages;
66  }
67 };
68 
69 
70 // -----------------------
71 // Push Constant info
73 {
74 public:
75  RV_VKPushConstantInfo() = default;
77  UT_Array<RV_Uniform>&& members,
79  int offset,
80  int size);
81 
83  { return myRanges; }
84 
85  bool merge(const RV_VKPushConstantInfo& other);
86  bool merge(const RV_VKPushConstantRange& new_range);
87 
88  bool operator== (const RV_VKPushConstantInfo & other) const
89  { return myRanges == other.myRanges; }
90 
91  bool operator!= (const RV_VKPushConstantInfo & other) const
92  { return !(myRanges == other.myRanges); }
93 
94 private:
96  friend class RV_VKPipelineLayout;
97 };
98 
99 // -----------------------
100 // RV_VKPipelineLayoutInfo
101 //
102 // NOTE: unlike other info classes, this one owns resource handles
103 // so can't be directly copied
104 // It shouldn't need to be, as shader layouts are unique
105 //
106 // tracks Pipeline create info that will be constant accross all pipelines
107 // created from the same set of shaders. This includes all of the data for creating the
108 // pipeline layout, and SOME of the structs for the final pipeline
109 // Effectively just the pipeline layout + the vertex attribute formats
111 {
112 public:
115 
116  // NOTE: currently, since pipeline layouts are built from shader
117  // files, they must be a specific shader type, and we
118  // will not have layouts that can be used with multiple
119  // pipeline types (e.g. graphics + compute) .. if changing
120  // this, pipeline type will need to be provided at higher
121  // level
122  // NOTE: simliarily, some of the values here are only valid for either
123  // for graphices or compute shaders (i.e. workgroup size, inputs)
125 
129 
130  UT_Vector3i myWorkGroupSize = UT_Vector3i(0,0,0);
131  bool myWorkGroupIsSpecConst = false;
132 
133  // features requires
134  VE_PhysicalDeviceFeatures myRequiredFeatures = {};
135 
136  // TODO: list of specialization constants
137  //UT_Array<RV_SpecializaitonConstant>
138 
139  bool isInit() const;
140  bool isValidForCompile(RV_Instance *inst) const;
141  bool isGraphicsShader() const;
142  bool isComputeShader() const;
143 
144  // Creation Structs
145  bool hasShaderStage(VkShaderStageFlagBits stage) const;
146  bool addShaderModule(RV_VKShaderModuleInfo *shader_module);
147  bool addShaderModule(RV_VKShaderReflect& module_info, VkShaderStageFlagBits stage);
148 
149  bool operator==(const RV_VKPipelineLayoutInfo& other) const;
150 
151  SYS_HashType calcHash() const;
152 };
153 
155 {
156  return in.calcHash();
157 }
158 
159 // ----------------------
160 // RV_VKPipelineLayout
161 //
162 // RAII wrapper for VkPipelineLayout, created using RV_VKPipelineLayoutInfo
163 // Also takes ownership of the shader modules matching it, which are also
164 // needed to create pipelines
166 {
167 public:
168 
169  VkPipelineLayout getVkLayout() const { return myVkPipelineLayout; }
170 
171  const RV_VKPipelineLayoutInfo& getInfo() const { return *myInfo; }
172 
174  { return myShaderModules; }
175 
177  RV_Instance* inst,
178  VkPipelineLayout pipe_layout,
180  UT_Array<RV_VKShaderModulePtr> shader_modules);
181 
182  RV_VKPipelineLayout(const RV_VKPipelineLayout&) = delete;
184 
186 protected:
187  RV_Instance* myInst = nullptr;
188  VkPipelineLayout myVkPipelineLayout = VK_NULL_HANDLE;
189 
192 };
193 
194 /// convenience function to fill out a pipeline layout info struct
195 /// matching the list of passed in shader modules. Returns null if
196 /// the modules are invalid, or there is an error
198  const char* name,
200 
201 /// Create a pipeline layout loading a list of compiled SPIR-V files
202 /// and matching spirv modules. It is up to the caller to ensure that
203 /// the info struct matches the conde in the shader modules.
204 /// Failure to do so can result in errors or undefined behavior.
205 /// Takes ownership of the shader modules
207  RV_Instance* inst,
210 
211 /// Create a pipeline layout from an RV_VKShader that compiled SPIR-V shaders
213  RV_Instance* inst,
214  const char* name,
216 
217 /// Create a pipeline layout from a list of SPIR-V VkShaderModules
219  RV_Instance* inst,
220  const char* name,
222 
223 /// Create a pipeline layout loading a list of compiled SPIR-V files
225  RV_Instance* inst,
226  const char* name,
227  const UT_StringArray& filenames);
228 
229 #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:44
RV_ShaderType
Definition: RV_Type.h:484
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
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