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 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 #ifndef PXR_IMAGING_HIO_GLSLFX_RESOURCE_LAYOUT_H
25 #define PXR_IMAGING_HIO_GLSLFX_RESOURCE_LAYOUT_H
26 
27 #include "pxr/pxr.h"
28 
29 #include "pxr/imaging/hio/types.h"
30 
31 #include "pxr/base/tf/token.h"
33 
34 #include <vector>
35 
37 
38 
39 #define HIO_GLSLFX_RESOURCE_LAYOUT_TOKENS \
40  (unknown) \
41  (block) \
42  ((inValue, "in")) \
43  ((outValue, "out")) \
44  ((inBlock, "in block")) \
45  ((outBlock, "out block")) \
46  ((inValueArray, "in array")) \
47  ((outValueArray, "out array")) \
48  ((inBlockArray, "in block array")) \
49  ((outBlockArray, "out block array")) \
50  ((uniformBlock, "uniform block")) \
51  ((bufferReadOnly, "buffer readOnly")) \
52  ((bufferReadWrite, "buffer readWrite"))
53 
54 TF_DECLARE_PUBLIC_TOKENS(HioGlslfxResourceLayoutTokens, HIO_API,
56 
57 class VtDictionary;
58 
59 /// \class HioGlslfxResourceLayout
60 /// The resource layout for stages in a shader pipeline.
61 ///
62 /// The main geometric shader pipelines for meshes, curves, points,
63 /// volumes, as well as compute shaders for subdivision refinement,
64 /// etc. are expressed as GLSL source code and aspects of the main
65 /// shader pipeline that are generated at runtime also are expressed
66 /// as GLSL source code.
67 ///
68 /// This class provides an intermediate representation for shader
69 /// resources that are needed to provide access to external data
70 /// like buffers and textures and also interstage data like input
71 /// and output variables and input and output interface blocks.
72 ///
73 /// A method is provided to parse resource data from HioGlslfx
74 /// resource layout dictionaries so that resource layout definitions
75 /// can continue to be authored alongside related GLSL shader source.
76 ///
77 /// The dictionary layouts have been designed to match the concepts
78 /// and syntax used by GLSL.
79 ///
81 {
82 public:
83  /// Specifies whether a resource element is a shader input,
84  /// a shader output (i.e. an input or output variable or input
85  /// or output interface block), or neither (i.e. a buffer or texture).
86  enum class InOut {
87  NONE,
88  STAGE_IN,
89  STAGE_OUT,
90  };
91 
92  /// Specifies the kind of resource element.
93  enum class Kind {
94  NONE,
95  VALUE,
96  BLOCK,
97  QUALIFIER,
103  };
104 
105  /// Specifies a member of an aggregate resource element.
106  struct Member {
108  TfToken const & name,
109  TfToken const & arraySize = TfToken())
110  : dataType(dataType)
111  , name(name)
113  { }
117  };
118  using MemberVector = std::vector<Member>;
119 
120  /// Specifies a resource element.
121  struct Element {
123  Kind kind = Kind::NONE,
124  TfToken dataType = HioGlslfxResourceLayoutTokens->unknown,
125  TfToken name = HioGlslfxResourceLayoutTokens->unknown,
128  : inOut(inOut)
129  , kind(kind)
130  , location(-1)
131  , dataType(dataType)
132  , name(name)
135  , aggregateName()
136  , members()
137  { }
140  int location;
147  };
148  using ElementVector = std::vector<Element>;
149 
150  /// Specifies the type of a texture element.
151  enum class TextureType {
152  TEXTURE, // a texture
153  SHADOW_TEXTURE, // a texture used as a shadow
154  ARRAY_TEXTURE, // e.g. texture1DArray, texture2DArray, etc.
155  };
156 
157  /// Specifies a texture element.
158  struct TextureElement {
160  int dim,
161  int bindingIndex,
164  int arraySize = 0)
165  : name(name)
166  , dim(dim)
167  , bindingIndex(bindingIndex)
168  , format(format)
171  { }
173  int dim;
178  };
179  using TextureElementVector = std::vector<TextureElement>;
180 
183 
184  /// Parses GLSLFX resource layout elements from the specified
185  /// \a layoutDict and appends the parsed elements to \a result.
186  HIO_API
187  static void ParseLayout(
189  TfToken const &shaderStage,
190  VtDictionary const &layoutDict);
191 };
192 
193 
195 
196 #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:613
#define HIO_API
Definition: api.h:40
Definition: token.h:87
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
Member(TfToken const &dataType, TfToken const &name, TfToken const &arraySize=TfToken())
HioFormat
Definition: types.h:42
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
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:91
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)