Loading...
Searching...
No Matches
glslfxResourceLayout.h
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
19PXR_NAMESPACE_OPEN_SCOPE
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
43TF_DECLARE_PUBLIC_TOKENS(HioGlslfxResourceLayoutTokens, HIO_API,
44 HIO_GLSLFX_RESOURCE_LAYOUT_TOKENS);
45
46class VtDictionary;
47
70{
71public:
75 enum class InOut {
76 NONE,
77 STAGE_IN,
78 STAGE_OUT,
79 };
80
82 enum class Kind {
83 NONE,
84 VALUE,
85 BLOCK,
86 QUALIFIER,
87 UNIFORM_VALUE,
88 UNIFORM_BLOCK,
89 UNIFORM_BLOCK_CONSTANT_PARAMS,
90 BUFFER_READ_ONLY,
91 BUFFER_READ_WRITE,
92 };
93
95 struct Member {
96 Member(TfToken const & dataType,
97 TfToken const & name,
98 TfToken const & arraySize = TfToken(),
99 TfToken const & qualifiers = TfToken())
100 : dataType(dataType)
101 , name(name)
102 , arraySize(arraySize)
103 { }
104 TfToken dataType;
105 TfToken name;
106 TfToken arraySize;
107 TfToken qualifiers;
108 };
109 using MemberVector = std::vector<Member>;
110
112 struct Element {
113 Element(InOut inOut = InOut::NONE,
114 Kind kind = Kind::NONE,
115 TfToken dataType = HioGlslfxResourceLayoutTokens->unknown,
116 TfToken name = HioGlslfxResourceLayoutTokens->unknown,
117 TfToken arraySize = TfToken(),
118 TfToken qualifiers = TfToken())
119 : inOut(inOut)
120 , kind(kind)
121 , location(-1)
122 , dataType(dataType)
123 , name(name)
124 , qualifiers(qualifiers)
125 , arraySize(arraySize)
126 , aggregateName()
127 , members()
128 { }
129 InOut inOut;
130 Kind kind;
131 int location;
132 TfToken dataType;
133 TfToken name;
134 TfToken qualifiers;
135 TfToken arraySize;
136 TfToken aggregateName;
137 MemberVector members;
138 };
139 using ElementVector = std::vector<Element>;
140
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 CUBEMAP_TEXTURE, // a cubemap texture
147 };
148
152 int dim,
153 int bindingIndex,
154 HioFormat format = HioFormatFloat32Vec4,
155 TextureType textureType = TextureType::TEXTURE,
156 int arraySize = 0)
157 : name(name)
158 , dim(dim)
159 , bindingIndex(bindingIndex)
160 , format(format)
161 , textureType(textureType)
162 , arraySize(arraySize)
163 { }
164 TfToken name;
165 int dim;
166 int bindingIndex;
167 HioFormat format;
168 TextureType textureType;
169 int arraySize;
170 };
171 using TextureElementVector = std::vector<TextureElement>;
172
175
178 HIO_API
179 static void ParseLayout(
180 ElementVector *result,
181 TfToken const &shaderStage,
182 VtDictionary const &layoutDict);
183};
184
185
186PXR_NAMESPACE_CLOSE_SCOPE
187
188#endif // PXR_IMAGING_HIO_GLSLFX_RESOURCE_LAYOUT_H
The resource layout for stages in a shader pipeline.
TextureType
Specifies the type of a texture element.
InOut
Specifies whether a resource element is a shader input, a shader output (i.e.
Kind
Specifies the kind of resource element.
static HIO_API void ParseLayout(ElementVector *result, TfToken const &shaderStage, VtDictionary const &layoutDict)
Parses GLSLFX resource layout elements from the specified layoutDict and appends the parsed elements ...
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
A map with string keys and VtValue values.
Definition: dictionary.h:52
This file defines some macros that are useful for declaring and using static TfTokens.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:92
Specifies a resource element.
Specifies a member of an aggregate resource element.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...