HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
shaderFunctionDesc.h
Go to the documentation of this file.
1 //
2 // Copyright 2020 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 
8 #ifndef PXR_IMAGING_HGI_SHADERFUNCTIONDESC_H
9 #define PXR_IMAGING_HGI_SHADERFUNCTIONDESC_H
10 
11 #include "pxr/pxr.h"
12 #include "pxr/imaging/hgi/api.h"
13 #include "pxr/imaging/hgi/enums.h"
14 #include "pxr/imaging/hgi/types.h"
15 
16 #include <string>
17 #include <vector>
18 
20 
21 
22 /// \struct HgiShaderFunctionTextureDesc
23 ///
24 /// Describes a texture to be passed into a shader
25 ///
26 /// <ul>
27 /// <li>nameInShader:
28 /// The name written from the codegen into shader file for the texture.</li>
29 /// <li>dimensions:
30 /// 1d, 2d or 3d texture declaration.</li>
31 /// <li>format
32 /// Format of the texture. This is required in APIs where sampler types depend
33 /// on the texture (e.g., GL) </li>
34 /// <li>textureType:
35 /// Type of the texture (e.g. array texture, shadow, etc.).</li>
36 /// <li>bindIndex:
37 /// The index of the resource.</li>
38 /// <li>arraySize:
39 /// If arraySize > 0, indicates the size of the array. Note that textureType
40 /// = HgiTextureTypeTexture and arraySize = 2 would create an array with two
41 /// textures whereas textureType = HgiTextureTypeArrayTexture and arraySize
42 /// = 0 would create a single array texture (arrays of array textures are
43 /// supported as well).</li>
44 /// <li>writable
45 /// Whether the texture is writable.</li>
46 /// </ul>
47 ///
49 {
50  HGI_API
52 
53  std::string nameInShader;
54  uint32_t dimensions;
57  uint32_t bindIndex;
58  size_t arraySize;
59  bool writable;
60 };
61 
63  std::vector<HgiShaderFunctionTextureDesc>;
64 
65 HGI_API
66 bool operator==(
68  const HgiShaderFunctionTextureDesc& rhs);
69 
70 HGI_API
71 bool operator!=(
73  const HgiShaderFunctionTextureDesc& rhs);
74 
75 /// \struct HgiShaderFunctionBufferDesc
76 ///
77 /// Describes a buffer to be passed into a shader
78 ///
79 /// <ul>
80 /// <li>nameInShader:
81 /// The name written from the codegen into shader file for the texture.</li>
82 /// <li>type:
83 /// Type of the param within the shader file.</li>
84 /// <li>bindIndex:
85 /// The index of the resource.</li>
86 /// <li>arraySize:
87 /// The size of the array when binding is a HgiBindingTypeArray.</li>
88 /// <li>bindingType:
89 /// The binding model to use to expose the buffer to the shader.</li>
90 /// <li>writeable:
91 /// Whether the resource is writable.</li>
92 /// </ul>
93 ///
95 {
96  HGI_API
98 
99  std::string nameInShader;
100  std::string type;
101  uint32_t bindIndex;
102  uint32_t arraySize;
104  bool writable;
105 };
106 
108  std::vector<HgiShaderFunctionBufferDesc>;
109 
110 HGI_API
111 bool operator==(
112  const HgiShaderFunctionBufferDesc& lhs,
113  const HgiShaderFunctionBufferDesc& rhs);
114 
115 HGI_API
116 bool operator!=(
117  const HgiShaderFunctionBufferDesc& lhs,
118  const HgiShaderFunctionBufferDesc& rhs);
119 
120 /// \struct HgiShaderFunctionParamDesc
121 ///
122 /// Describes a param passed into a shader or between shader stages.
123 ///
124 /// <ul>
125 /// <li>nameInShader:
126 /// The name written from the codegen into the shader file for the param.</li>
127 /// <li>type:
128 /// Type of the param within the shader file.</li>
129 /// <li>location:
130 /// For OpenGL, optionally specify the layout location.
131 /// For Metal, if no role is specified, this generates the role</li>
132 /// <li>interstageSlot:
133 /// Optionally specify an index for interstage parameters.</li>
134 /// <li>interpolation:
135 /// Optionally specify the interpolation: Default, Flat or NoPerspective.</li>
136 /// <li>sampling:
137 /// Optionally specify the sampling: Default, Centroid or Sample.</li>
138 /// <li>storage:
139 /// Optionally specify the storage type: Default, Patch.</li>
140 /// <li>role:
141 /// Optionally a role can be specified, like position, uv, color.</li>
142 /// <li>arraySize:
143 /// If specified, generates an array type parameter with given size.</li>
144 /// </ul>
145 ///
147 {
148  HGI_API
150 
151  std::string nameInShader;
152  std::string type;
153  int32_t location;
154  int32_t interstageSlot;
158  std::string role;
159  std::string arraySize;
160 };
161 
163  std::vector<HgiShaderFunctionParamDesc>;
164 
165 HGI_API
166 bool operator==(
167  const HgiShaderFunctionParamDesc& lhs,
168  const HgiShaderFunctionParamDesc& rhs);
169 
170 HGI_API
171 bool operator!=(
172  const HgiShaderFunctionParamDesc& lhs,
173  const HgiShaderFunctionParamDesc& rhs);
174 
175 /// \struct HgiShaderFunctionParamBlockDesc
176 ///
177 /// Describes an interstage param block between shader stages
178 ///
179 /// <ul>
180 /// <li>blockName:
181 /// The name used to match blocks between shader stages.</li>
182 /// <li>instanceName:
183 /// The name used to scope access to block members.</li>
184 /// <li>members:
185 /// The members of the block.</li>
186 /// <li>arraySize:
187 /// If specified, generates a block with given size.</li>
188 /// <li>interstageSlot:
189 /// The interstage slot index of the first member of the block,
190 /// subsequent members are assigned sequential interstage slot indices.</li>
191 /// </ul>
192 ///
194 {
195  HGI_API
197 
198  struct Member {
199  std::string name;
200  std::string type;
203  };
204  using MemberVector = std::vector<Member>;
205 
206  std::string blockName;
207  std::string instanceName;
209  std::string arraySize;
210  int32_t interstageSlot;
211 };
212 
214  std::vector<HgiShaderFunctionParamBlockDesc>;
215 
216 HGI_API
217 bool operator==(
220 
221 HGI_API
222 bool operator!=(
225 
226 HGI_API
227 bool operator==(
230 
231 HGI_API
232 bool operator!=(
235 
236 /// \struct HgiShaderFunctionComputeDesc
237 ///
238 /// Describes a compute function's description
239 ///
240 /// <ul>
241 /// <li>localSize:
242 /// Optional. Specifices the 3D size of the local thread grouping. Defaults to
243 /// 0, meaning it is not set. When x > 0, y and z must also be set > 0.
244 /// When localSize is set to > 0, the following source is generated:
245 /// GLSL: layout(local_size_x = localSize[0],
246 /// local_size_y = localSize[1], local_size_z = localSize[2]) in;
247 /// MSL: [[max_total_threads_per_threadgroup(localSize[0] *
248 /// localSize[1] * localSize[w])]]
249 /// </li>
250 /// </ul>
251 ///
253 {
254  HGI_API
256 
258 };
259 
260 HGI_API
261 bool operator==(
262  const HgiShaderFunctionComputeDesc& lhs,
263  const HgiShaderFunctionComputeDesc& rhs);
264 
265 HGI_API
266 bool operator!=(
267  const HgiShaderFunctionComputeDesc& lhs,
268  const HgiShaderFunctionComputeDesc& rhs);
269 
270 /// \struct HgiShaderFunctionTessellationDesc
271 ///
272 /// Describes a tessellation function's description
273 ///
274 /// <ul>
275 /// <li>patchType:
276 /// The type of patch</li>
277 /// <li>spacing
278 /// The spacing used by the tessellation primitive generator</li>
279 /// <li>ordering
280 /// The ordering used by the tessellation primitive generator</li>
281 /// <li>numVertsInPerPatch:
282 /// The number of vertices in per patch</li>
283 /// <li>numVertsOutPerPatch:
284 /// The number of vertices out per patch</li>
285 /// </ul>
286 ///
288 {
289  enum class PatchType { Triangles, Quads, Isolines };
291  enum class Ordering { CW, CCW };
292  HGI_API
294 
298  std::string numVertsPerPatchIn;
299  std::string numVertsPerPatchOut;
300 };
301 
302 HGI_API
303 bool operator==(
306 
307 HGI_API
308 bool operator!=(
311 
312 /// \struct HgiShaderFunctionGeometryDesc
313 ///
314 /// Describes a geometry function's description
315 ///
316 /// <ul>
317 /// <li>inPrimitiveType:
318 /// The input primitive type.</li>
319 /// <li>outPrimitiveType:
320 /// The output primitive type.</li>
321 /// <li>outMaxVertices:
322 /// The maximum number of vertices written by a single invovation of the
323 /// geometry shader.</li>
324 /// </ul>
325 ///
327 {
328  enum class InPrimitiveType {
330  enum class OutPrimitiveType {
332 
333  HGI_API
335 
338  std::string outMaxVertices;
339 };
340 
341 HGI_API
342 bool operator==(
344  const HgiShaderFunctionGeometryDesc& rhs);
345 
346 HGI_API
347 bool operator!=(
349  const HgiShaderFunctionGeometryDesc& rhs);
350 
351 ///
352 /// Describes a fragment function's description
353 ///
354 /// <ul>
355 /// <li>earlyFragmentTests:
356 /// Fragment shader tests will be performed before fragment
357 /// shader execution when enabled.</li>
358 /// </ul>
359 ///
361 {
362  HGI_API
364 
366 
367 };
368 
369 HGI_API
370 bool operator==(
372  const HgiShaderFunctionFragmentDesc& rhs);
373 
374 HGI_API
375 bool operator!=(
377  const HgiShaderFunctionFragmentDesc& rhs);
378 
379 /// \struct HgiShaderFunctionDesc
380 ///
381 /// Describes the properties needed to create a GPU shader function.
382 ///
383 /// <ul>
384 /// <li>debugName:
385 /// This label can be applied as debug label for gpu debugging.</li>
386 /// <li>shaderStage:
387 /// The shader stage this function represents.</li>
388 /// <li>shaderCodeDeclarations:
389 /// Optional ascii shader code containing defines and type declarations
390 /// which need to be emitted before generated resource bindings.</li>
391 /// <li>shaderCode:
392 /// The ascii shader code used to compile the shader.</li>
393 /// <li>generatedShaderCodeOut:
394 /// Optional pointer to a string that will be filled in with the
395 /// ascii shader code after shader generation is complete.</li>
396 /// <li>textures:
397 /// List of texture descriptions to be passed into a shader.</li>
398 /// <li>buffers:
399 /// List of buffer descriptions to be passed into a shader.</li>
400 /// <li>constantParams:
401 /// List of descriptions of constant params passed into a shader.</li>
402 /// <li>stageGlobalMembers:
403 /// List of descriptions of params declared at global scope.</li>
404 /// <li>stageInputs:
405 /// List of descriptions of the inputs of the shader.</li>
406 /// <li>stageOutputs:
407 /// List of descriptions of the outputs of the shader.</li>
408 /// <li>stageInputBlocks:
409 /// List of descriptions of the input blocks of the shader.</li>
410 /// <li>stageOutputsBlocks:
411 /// List of descriptions of the output blocks of the shader.</li>
412 /// <li>computeDescriptor:
413 /// Description of compute shader function.</li>
414 /// <li>tessellationDescriptor:
415 /// Description of tessellation shader function.</li>
416 /// <li>geometryDescriptor:
417 /// Description of geometry shader function.</li>
418 /// <li>fragmentDescriptor:
419 /// Description of fragment shader function.</li>
420 /// </ul>
421 ///
423 {
424  HGI_API
426  std::string debugName;
429  const char *shaderCode;
431  std::vector<HgiShaderFunctionTextureDesc> textures;
432  std::vector<HgiShaderFunctionBufferDesc> buffers;
433  std::vector<HgiShaderFunctionParamDesc> constantParams;
434  std::vector<HgiShaderFunctionParamDesc> stageGlobalMembers;
435  std::vector<HgiShaderFunctionParamDesc> stageInputs;
436  std::vector<HgiShaderFunctionParamDesc> stageOutputs;
437  std::vector<HgiShaderFunctionParamBlockDesc> stageInputBlocks;
438  std::vector<HgiShaderFunctionParamBlockDesc> stageOutputBlocks;
443 };
444 
446  std::vector<HgiShaderFunctionDesc>;
447 
448 HGI_API
449 bool operator==(
450  const HgiShaderFunctionDesc& lhs,
451  const HgiShaderFunctionDesc& rhs);
452 
453 HGI_API
454 bool operator!=(
455  const HgiShaderFunctionDesc& lhs,
456  const HgiShaderFunctionDesc& rhs);
457 
458 /// Adds texture descriptor to given shader function descriptor.
459 HGI_API
460 void
462  HgiShaderFunctionDesc *desc,
463  const std::string &nameInShader,
464  const uint32_t bindIndex = 0,
465  uint32_t dimensions = 2,
468 
469 /// Adds array of textures descriptor to given shader function descriptor.
470 HGI_API
471 void
473  HgiShaderFunctionDesc *desc,
474  const std::string &nameInShader,
475  const uint32_t arraySize,
476  const uint32_t bindIndex = 0,
477  const uint32_t dimensions = 2,
480 
481 /// Adds writable texture descriptor to given shader function descriptor.
482 HGI_API
483 void
485  HgiShaderFunctionDesc *desc,
486  const std::string &nameInShader,
487  const uint32_t bindIndex = 0,
488  const uint32_t dimensions = 2,
491 
492 /// Adds buffer descriptor to given shader function descriptor.
493 HGI_API
494 void
496  HgiShaderFunctionDesc *desc,
497  const std::string &nameInShader,
498  const std::string &type,
499  const uint32_t bindIndex,
500  HgiBindingType binding,
501  const uint32_t arraySize = 0);
502 
503 /// Adds buffer descriptor to given shader function descriptor.
504 HGI_API
505 void
507  HgiShaderFunctionDesc *desc,
508  const std::string &nameInShader,
509  const std::string &type,
510  const uint32_t bindIndex);
511 
512 /// Adds constant function param descriptor to given shader function
513 /// descriptor.
514 HGI_API
515 void
517  HgiShaderFunctionDesc *desc,
518  const std::string &nameInShader,
519  const std::string &type,
520  const std::string &role = std::string());
521 
522 /// Adds stage input function param descriptor to given shader function
523 /// descriptor.
524 /// The location is will be set to the next available.
525 HGI_API
526 void
528  HgiShaderFunctionDesc *desc,
529  const std::string &nameInShader,
530  const std::string &type,
531  const std::string &role = std::string());
532 
533 /// Adds stage input function param descriptor to given shader function
534 /// descriptor given param descriptor.
535 HGI_API
536 void
538  HgiShaderFunctionDesc *functionDesc,
539  HgiShaderFunctionParamDesc const &paramDesc);
540 
541 /// Interstage input.
542 HGI_API
543 void
545  HgiShaderFunctionDesc *desc,
546  const std::string &nameInShader,
547  const std::string &type,
548  const std::string &arraySize);
549 
550 /// Adds stage output function param descriptor to given shader function
551 /// descriptor.
552 HGI_API
553 void
555  HgiShaderFunctionDesc *desc,
556  const std::string &nameInShader,
557  const std::string &type,
558  const std::string &role = std::string(),
559  const std::string &arraySize = std::string());
560 
561 /// Adds stage output function param descriptor to given shader function
562 /// descriptor.
563 HGI_API
564 void
566  HgiShaderFunctionDesc *desc,
567  const std::string &nameInShader,
568  const std::string &type,
569  const uint32_t location);
570 
571 /// Adds stage output function param descriptor to given shader function
572 /// descriptor given param descriptor.
573 HGI_API
574 void
576  HgiShaderFunctionDesc *functionDesc,
577  HgiShaderFunctionParamDesc const &paramDesc);
578 
580 
581 #endif
HgiStorageType
Definition: enums.h:775
std::vector< HgiShaderFunctionParamDesc > HgiShaderFunctionParamDescVector
std::string * generatedShaderCodeOut
std::vector< HgiShaderFunctionParamDesc > constantParams
const char * shaderCodeDeclarations
HGI_API void HgiShaderFunctionAddWritableTexture(HgiShaderFunctionDesc *desc, const std::string &nameInShader, const uint32_t bindIndex=0, const uint32_t dimensions=2, const HgiFormat &format=HgiFormatFloat32Vec4, const HgiShaderTextureType textureType=HgiShaderTextureTypeTexture)
Adds writable texture descriptor to given shader function descriptor.
std::vector< HgiShaderFunctionParamDesc > stageGlobalMembers
std::vector< HgiShaderFunctionTextureDesc > textures
HgiShaderFunctionFragmentDesc fragmentDescriptor
HgiShaderFunctionComputeDesc computeDescriptor
std::vector< HgiShaderFunctionParamDesc > stageOutputs
HGI_API void HgiShaderFunctionAddArrayOfTextures(HgiShaderFunctionDesc *desc, const std::string &nameInShader, const uint32_t arraySize, const uint32_t bindIndex=0, const uint32_t dimensions=2, const HgiFormat &format=HgiFormatFloat32Vec4, const HgiShaderTextureType textureType=HgiShaderTextureTypeTexture)
Adds array of textures descriptor to given shader function descriptor.
std::vector< HgiShaderFunctionTextureDesc > HgiShaderFunctionTextureDescVector
HgiFormat
Definition: types.h:28
HgiShaderFunctionGeometryDesc geometryDescriptor
HGI_API void HgiShaderFunctionAddGlobalVariable(HgiShaderFunctionDesc *desc, const std::string &nameInShader, const std::string &type, const std::string &arraySize)
Interstage input.
std::vector< HgiShaderFunctionDesc > HgiShaderFunctionDescVector
std::vector< HgiShaderFunctionParamBlockDesc > HgiShaderFunctionParamBlockDescVector
HgiInterpolationType interpolation
std::vector< HgiShaderFunctionParamBlockDesc > stageInputBlocks
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
HgiInterpolationType
Definition: enums.h:729
HgiShaderFunctionTessellationDesc tessellationDescriptor
HgiBindingType
Definition: enums.h:701
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
HGI_API HgiShaderFunctionDesc()
HgiShaderTextureType textureType
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition: Mat3.h:556
GLint location
Definition: glcorearb.h:805
Definition: vec3i.h:43
HgiSamplingType
Definition: enums.h:755
HGI_API void HgiShaderFunctionAddTexture(HgiShaderFunctionDesc *desc, const std::string &nameInShader, const uint32_t bindIndex=0, uint32_t dimensions=2, const HgiFormat &format=HgiFormatFloat32Vec4, const HgiShaderTextureType textureType=HgiShaderTextureTypeTexture)
Adds texture descriptor to given shader function descriptor.
HGI_API void HgiShaderFunctionAddConstantParam(HgiShaderFunctionDesc *desc, const std::string &nameInShader, const std::string &type, const std::string &role=std::string())
HGI_API void HgiShaderFunctionAddBuffer(HgiShaderFunctionDesc *desc, const std::string &nameInShader, const std::string &type, const uint32_t bindIndex, HgiBindingType binding, const uint32_t arraySize=0)
Adds buffer descriptor to given shader function descriptor.
std::vector< Member > MemberVector
#define HGI_API
Definition: api.h:23
std::vector< HgiShaderFunctionParamBlockDesc > stageOutputBlocks
HGI_API HgiShaderFunctionParamDesc()
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
std::vector< HgiShaderFunctionBufferDesc > HgiShaderFunctionBufferDescVector
std::vector< HgiShaderFunctionBufferDesc > buffers
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HGI_API void HgiShaderFunctionAddStageOutput(HgiShaderFunctionDesc *desc, const std::string &nameInShader, const std::string &type, const std::string &role=std::string(), const std::string &arraySize=std::string())
std::vector< HgiShaderFunctionParamDesc > stageInputs
HgiBits HgiShaderStage
Definition: enums.h:357
HgiShaderTextureType
Definition: enums.h:794
HGI_API void HgiShaderFunctionAddWritableBuffer(HgiShaderFunctionDesc *desc, const std::string &nameInShader, const std::string &type, const uint32_t bindIndex)
Adds buffer descriptor to given shader function descriptor.
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:542
HGI_API void HgiShaderFunctionAddStageInput(HgiShaderFunctionDesc *desc, const std::string &nameInShader, const std::string &type, const std::string &role=std::string())