shaderFunctionDesc.h
1 //
2 // Copyright 2020 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 
25 #ifndef PXR_IMAGING_HGI_SHADERFUNCTIONDESC_H
26 #define PXR_IMAGING_HGI_SHADERFUNCTIONDESC_H
27 
28 #include "pxr/pxr.h"
29 #include "pxr/imaging/hgi/api.h"
30 #include "pxr/imaging/hgi/enums.h"
31 #include "pxr/imaging/hgi/types.h"
32 
33 #include <string>
34 #include <vector>
35 
36 PXR_NAMESPACE_OPEN_SCOPE
37 
38 
64 {
65  HGI_API
67 
68  std::string nameInShader;
69  uint32_t dimensions;
70  HgiFormat format;
71  HgiShaderTextureType textureType;
72  size_t arraySize;
73  bool writable;
74 };
75 
76 using HgiShaderFunctionTextureDescVector =
77  std::vector<HgiShaderFunctionTextureDesc>;
78 
79 HGI_API
80 bool operator==(
82  const HgiShaderFunctionTextureDesc& rhs);
83 
84 HGI_API
85 bool operator!=(
87  const HgiShaderFunctionTextureDesc& rhs);
88 
109 {
110  HGI_API
112 
113  std::string nameInShader;
114  std::string type;
115  int32_t bindIndex;
116  uint32_t arraySize;
117  HgiBindingType binding;
118  bool writable;
119 };
120 
121 using HgiShaderFunctionBufferDescVector =
122  std::vector<HgiShaderFunctionBufferDesc>;
123 
124 HGI_API
125 bool operator==(
126  const HgiShaderFunctionBufferDesc& lhs,
127  const HgiShaderFunctionBufferDesc& rhs);
128 
129 HGI_API
130 bool operator!=(
131  const HgiShaderFunctionBufferDesc& lhs,
132  const HgiShaderFunctionBufferDesc& rhs);
133 
157 {
158  HGI_API
160 
161  std::string nameInShader;
162  std::string type;
163  int32_t location;
164  int32_t interstageSlot;
165  HgiInterpolationType interpolation;
166  std::string role;
167  std::string arraySize;
168 };
169 
170 using HgiShaderFunctionParamDescVector =
171  std::vector<HgiShaderFunctionParamDesc>;
172 
173 HGI_API
174 bool operator==(
175  const HgiShaderFunctionParamDesc& lhs,
176  const HgiShaderFunctionParamDesc& rhs);
177 
178 HGI_API
179 bool operator!=(
180  const HgiShaderFunctionParamDesc& lhs,
181  const HgiShaderFunctionParamDesc& rhs);
182 
202 {
203  HGI_API
205 
206  struct Member {
207  std::string name;
208  std::string type;
209  };
210  using MemberVector = std::vector<Member>;
211 
212  std::string blockName;
213  std::string instanceName;
214  MemberVector members;
215  std::string arraySize;
216  int32_t interstageSlot;
217 };
218 
219 using HgiShaderFunctionParamBlockDescVector =
220  std::vector<HgiShaderFunctionParamBlockDesc>;
221 
222 HGI_API
223 bool operator==(
226 
227 HGI_API
228 bool operator!=(
231 
232 HGI_API
233 bool operator==(
234  const HgiShaderFunctionParamBlockDesc::Member& lhs,
235  const HgiShaderFunctionParamBlockDesc::Member& rhs);
236 
237 HGI_API
238 bool operator!=(
239  const HgiShaderFunctionParamBlockDesc::Member& lhs,
240  const HgiShaderFunctionParamBlockDesc::Member& rhs);
241 
259 {
260  HGI_API
262 
263  GfVec3i localSize;
264 };
265 
266 HGI_API
267 bool operator==(
268  const HgiShaderFunctionComputeDesc& lhs,
269  const HgiShaderFunctionComputeDesc& rhs);
270 
271 HGI_API
272 bool operator!=(
273  const HgiShaderFunctionComputeDesc& lhs,
274  const HgiShaderFunctionComputeDesc& rhs);
275 
290 {
291  enum class PatchType { Quad, Triangle };
292  HGI_API
294 
295  PatchType patchType = PatchType::Triangle;
296  uint32_t numVertsPerPatchIn = 3;
297  uint32_t numVertsPerPatchOut = 3;
298 };
299 
300 HGI_API
301 bool operator==(
304 
305 HGI_API
306 bool operator!=(
309 
320 {
321  HGI_API
323 
324  bool earlyFragmentTests;
325 
326 };
327 
328 HGI_API
329 bool operator==(
331  const HgiShaderFunctionFragmentDesc& rhs);
332 
333 HGI_API
334 bool operator!=(
336  const HgiShaderFunctionFragmentDesc& rhs);
337 
378 {
379  HGI_API
381  std::string debugName;
382  HgiShaderStage shaderStage;
383  const char *shaderCodeDeclarations;
384  const char *shaderCode;
385  std::string *generatedShaderCodeOut;
386  std::vector<HgiShaderFunctionTextureDesc> textures;
387  std::vector<HgiShaderFunctionBufferDesc> buffers;
388  std::vector<HgiShaderFunctionParamDesc> constantParams;
389  std::vector<HgiShaderFunctionParamDesc> stageGlobalMembers;
390  std::vector<HgiShaderFunctionParamDesc> stageInputs;
391  std::vector<HgiShaderFunctionParamDesc> stageOutputs;
392  std::vector<HgiShaderFunctionParamBlockDesc> stageInputBlocks;
393  std::vector<HgiShaderFunctionParamBlockDesc> stageOutputBlocks;
394  HgiShaderFunctionTessellationDesc tessellationDescriptor;
395  HgiShaderFunctionComputeDesc computeDescriptor;
396  HgiShaderFunctionFragmentDesc fragmentDescriptor;
397 };
398 
399 using HgiShaderFunctionDescVector =
400  std::vector<HgiShaderFunctionDesc>;
401 
402 HGI_API
403 bool operator==(
404  const HgiShaderFunctionDesc& lhs,
405  const HgiShaderFunctionDesc& rhs);
406 
407 HGI_API
408 bool operator!=(
409  const HgiShaderFunctionDesc& lhs,
410  const HgiShaderFunctionDesc& rhs);
411 
413 HGI_API
414 void
415 HgiShaderFunctionAddTexture(
416  HgiShaderFunctionDesc *desc,
417  const std::string &nameInShader,
418  uint32_t dimensions = 2,
419  const HgiFormat &format = HgiFormatFloat32Vec4,
420  const HgiShaderTextureType textureType = HgiShaderTextureTypeTexture);
421 
423 HGI_API
424 void
425 HgiShaderFunctionAddArrayOfTextures(
426  HgiShaderFunctionDesc *desc,
427  const std::string &nameInShader,
428  const uint32_t arraySize,
429  const uint32_t dimensions = 2,
430  const HgiFormat &format = HgiFormatFloat32Vec4,
431  const HgiShaderTextureType textureType = HgiShaderTextureTypeTexture);
432 
434 HGI_API
435 void
436 HgiShaderFunctionAddWritableTexture(
437  HgiShaderFunctionDesc *desc,
438  const std::string &nameInShader,
439  const uint32_t dimensions = 2,
440  const HgiFormat &format = HgiFormatFloat32Vec4,
441  const HgiShaderTextureType textureType = HgiShaderTextureTypeTexture);
442 
444 HGI_API
445 void
446 HgiShaderFunctionAddBuffer(
447  HgiShaderFunctionDesc *desc,
448  const std::string &nameInShader,
449  const std::string &type,
450  const uint32_t bindIndex,
451  HgiBindingType binding,
452  const uint32_t arraySize = 0);
453 
455 HGI_API
456 void
457 HgiShaderFunctionAddWritableBuffer(
458  HgiShaderFunctionDesc *desc,
459  const std::string &nameInShader,
460  const std::string &type,
461  const uint32_t bindIndex);
462 
465 HGI_API
466 void
467 HgiShaderFunctionAddConstantParam(
468  HgiShaderFunctionDesc *desc,
469  const std::string &nameInShader,
470  const std::string &type,
471  const std::string &role = std::string());
472 
476 HGI_API
477 void
478 HgiShaderFunctionAddStageInput(
479  HgiShaderFunctionDesc *desc,
480  const std::string &nameInShader,
481  const std::string &type,
482  const std::string &role = std::string());
483 
486 HGI_API
487 void
488 HgiShaderFunctionAddStageInput(
489  HgiShaderFunctionDesc *functionDesc,
490  HgiShaderFunctionParamDesc const &paramDesc);
491 
493 HGI_API
494 void
495 HgiShaderFunctionAddGlobalVariable(
496  HgiShaderFunctionDesc *desc,
497  const std::string &nameInShader,
498  const std::string &type,
499  const std::string &arraySize);
500 
503 HGI_API
504 void
505 HgiShaderFunctionAddStageOutput(
506  HgiShaderFunctionDesc *desc,
507  const std::string &nameInShader,
508  const std::string &type,
509  const std::string &role = std::string());
510 
513 HGI_API
514 void
515 HgiShaderFunctionAddStageOutput(
516  HgiShaderFunctionDesc *desc,
517  const std::string &nameInShader,
518  const std::string &type,
519  const uint32_t location);
520 
523 HGI_API
524 void
525 HgiShaderFunctionAddStageOutput(
526  HgiShaderFunctionDesc *functionDesc,
527  HgiShaderFunctionParamDesc const &paramDesc);
528 
529 PXR_NAMESPACE_CLOSE_SCOPE
530 
531 #endif
Describes a buffer to be passed into a shader.
AR_API bool operator!=(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
AR_API bool operator==(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
Describes a tessellation function's description.
Describes a param passed into a shader or between shader stages.
Describes a compute function's description.
Basic type for a vector of 3 int components.
Definition: vec3i.h:61
Describes an interstage param block between shader stages.
Describes a texture to be passed into a shader.
Describes a fragment function's description.
Describes the properties needed to create a GPU shader function.