HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
glslfxResourceLayout.h
Go to the documentation of this file.
1 //
2 // Copyright 2022 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_HIO_GLSLFX_RESOURCE_LAYOUT_H
8 #define PXR_IMAGING_HIO_GLSLFX_RESOURCE_LAYOUT_H
9 
10 #include "pxr/pxr.h"
11 
12 #include "pxr/imaging/hio/types.h"
13 
14 #include "pxr/base/tf/token.h"
16 
17 #include <vector>
18 
20 
21 
22 #define HIO_GLSLFX_RESOURCE_LAYOUT_TOKENS \
23  (unknown) \
24  (block) \
25  ((inValue, "in")) \
26  ((outValue, "out")) \
27  ((inBlock, "in block")) \
28  ((outBlock, "out block")) \
29  ((inValueArray, "in array")) \
30  ((outValueArray, "out array")) \
31  ((inBlockArray, "in block array")) \
32  ((outBlockArray, "out block array")) \
33  ((uniformBlock, "uniform block")) \
34  ((bufferReadOnly, "buffer readOnly")) \
35  ((bufferReadWrite, "buffer readWrite")) \
36  (centroid) \
37  (sample) \
38  (smooth) \
39  (flat) \
40  (noperspective)
41 
42 
43 TF_DECLARE_PUBLIC_TOKENS(HioGlslfxResourceLayoutTokens, HIO_API,
45 
46 class VtDictionary;
47 
48 /// \class HioGlslfxResourceLayout
49 /// The resource layout for stages in a shader pipeline.
50 ///
51 /// The main geometric shader pipelines for meshes, curves, points,
52 /// volumes, as well as compute shaders for subdivision refinement,
53 /// etc. are expressed as GLSL source code and aspects of the main
54 /// shader pipeline that are generated at runtime also are expressed
55 /// as GLSL source code.
56 ///
57 /// This class provides an intermediate representation for shader
58 /// resources that are needed to provide access to external data
59 /// like buffers and textures and also interstage data like input
60 /// and output variables and input and output interface blocks.
61 ///
62 /// A method is provided to parse resource data from HioGlslfx
63 /// resource layout dictionaries so that resource layout definitions
64 /// can continue to be authored alongside related GLSL shader source.
65 ///
66 /// The dictionary layouts have been designed to match the concepts
67 /// and syntax used by GLSL.
68 ///
70 {
71 public:
72  /// Specifies whether a resource element is a shader input,
73  /// a shader output (i.e. an input or output variable or input
74  /// or output interface block), or neither (i.e. a buffer or texture).
75  enum class InOut {
76  NONE,
77  STAGE_IN,
78  STAGE_OUT,
79  };
80 
81  /// Specifies the kind of resource element.
82  enum class Kind {
83  NONE,
84  VALUE,
85  BLOCK,
86  QUALIFIER,
92  };
93 
94  /// Specifies a member of an aggregate resource element.
95  struct Member {
97  TfToken const & name,
98  TfToken const & arraySize = TfToken(),
99  TfToken const & qualifiers = TfToken())
100  : dataType(dataType)
101  , name(name)
103  { }
108  };
109  using MemberVector = std::vector<Member>;
110 
111  /// Specifies a resource element.
112  struct Element {
114  Kind kind = Kind::NONE,
115  TfToken dataType = HioGlslfxResourceLayoutTokens->unknown,
116  TfToken name = HioGlslfxResourceLayoutTokens->unknown,
119  : inOut(inOut)
120  , kind(kind)
121  , location(-1)
122  , dataType(dataType)
123  , name(name)
126  , aggregateName()
127  , members()
128  { }
131  int location;
138  };
139  using ElementVector = std::vector<Element>;
140 
141  /// Specifies the type of a texture element.
142  enum class TextureType {
143  TEXTURE, // a texture
144  SHADOW_TEXTURE, // a texture used as a shadow
145  ARRAY_TEXTURE, // e.g. texture1DArray, texture2DArray, etc.
146  };
147 
148  /// Specifies a texture element.
149  struct TextureElement {
151  int dim,
152  int bindingIndex,
155  int arraySize = 0)
156  : name(name)
157  , dim(dim)
158  , bindingIndex(bindingIndex)
159  , format(format)
162  { }
164  int dim;
169  };
170  using TextureElementVector = std::vector<TextureElement>;
171 
174 
175  /// Parses GLSLFX resource layout elements from the specified
176  /// \a layoutDict and appends the parsed elements to \a result.
177  HIO_API
178  static void ParseLayout(
180  TfToken const &shaderStage,
181  VtDictionary const &layoutDict);
182 };
183 
184 
186 
187 #endif // PXR_IMAGING_HIO_GLSLFX_RESOURCE_LAYOUT_H
std::vector< Element > ElementVector
std::vector< Member > MemberVector
TF_DECLARE_PUBLIC_TOKENS(HioGlslfxResourceLayoutTokens, HIO_API, HIO_GLSLFX_RESOURCE_LAYOUT_TOKENS)
Specifies a member of an aggregate resource element.
**But if you need a result
Definition: thread.h:622
#define HIO_API
Definition: api.h:23
Definition: token.h:70
Specifies a resource element.
std::vector< TextureElement > TextureElementVector
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
GLint location
Definition: glcorearb.h:805
Element(InOut inOut=InOut::NONE, Kind kind=Kind::NONE, TfToken dataType=HioGlslfxResourceLayoutTokens->unknown, TfToken name=HioGlslfxResourceLayoutTokens->unknown, TfToken arraySize=TfToken(), TfToken qualifiers=TfToken())
GLuint const GLchar * name
Definition: glcorearb.h:786
HioFormat
Definition: types.h:25
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
TextureElement(TfToken name, int dim, int bindingIndex, HioFormat format=HioFormatFloat32Vec4, TextureType textureType=TextureType::TEXTURE, int arraySize=0)
Kind
Specifies the kind of resource element.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Member(TfToken const &dataType, TfToken const &name, TfToken const &arraySize=TfToken(), TfToken const &qualifiers=TfToken())
TextureType
Specifies the type of a texture element.
#define HIO_GLSLFX_RESOURCE_LAYOUT_TOKENS
static HIO_API void ParseLayout(ElementVector *result, TfToken const &shaderStage, VtDictionary const &layoutDict)