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
96 using ShaderStage = uint32_t;
97
99 struct Member {
100 Member(TfToken const & dataType,
101 TfToken const & name,
102 TfToken const & arraySize = TfToken(),
103 TfToken const & qualifiers = TfToken())
104 : dataType(dataType)
105 , name(name)
106 , arraySize(arraySize)
107 { }
108 TfToken dataType;
109 TfToken name;
110 TfToken arraySize;
111 TfToken qualifiers;
112 };
113 using MemberVector = std::vector<Member>;
114
116 struct Element {
117 Element(InOut inOut = InOut::NONE,
118 Kind kind = Kind::NONE,
119 TfToken dataType = HioGlslfxResourceLayoutTokens->unknown,
120 TfToken name = HioGlslfxResourceLayoutTokens->unknown,
121 TfToken arraySize = TfToken(),
122 TfToken qualifiers = TfToken(),
123 ShaderStage stageVisibility = UINT32_MAX)
124 : inOut(inOut)
125 , kind(kind)
126 , location(-1)
127 , dataType(dataType)
128 , name(name)
129 , qualifiers(qualifiers)
130 , arraySize(arraySize)
131 , aggregateName()
132 , members()
133 , stageVisibility(stageVisibility)
134 { }
135 InOut inOut;
136 Kind kind;
137 int location;
138 TfToken dataType;
139 TfToken name;
140 TfToken qualifiers;
141 TfToken arraySize;
142 TfToken aggregateName;
143 MemberVector members;
144 ShaderStage stageVisibility;
145 };
146 using ElementVector = std::vector<Element>;
147
149 enum class TextureType {
150 TEXTURE, // a texture
151 SHADOW_TEXTURE, // a texture used as a shadow
152 ARRAY_TEXTURE, // e.g. texture1DArray, texture2DArray, etc.
153 CUBEMAP_TEXTURE, // a cubemap texture
154 };
155
159 int dim,
160 int bindingIndex,
161 HioFormat format = HioFormatFloat32Vec4,
162 TextureType textureType = TextureType::TEXTURE,
163 int arraySize = 0)
164 : name(name)
165 , dim(dim)
166 , bindingIndex(bindingIndex)
167 , format(format)
168 , textureType(textureType)
169 , arraySize(arraySize)
170 { }
171 TfToken name;
172 int dim;
173 int bindingIndex;
174 HioFormat format;
175 TextureType textureType;
176 int arraySize;
177 };
178 using TextureElementVector = std::vector<TextureElement>;
179
182
185 HIO_API
186 static void ParseLayout(
187 ElementVector *result,
188 TfToken const &shaderStage,
189 VtDictionary const &layoutDict);
190};
191
192
193PXR_NAMESPACE_CLOSE_SCOPE
194
195#endif // PXR_IMAGING_HIO_GLSLFX_RESOURCE_LAYOUT_H
The resource layout for stages in a shader pipeline.
uint32_t ShaderStage
Describes the stage a shader function operates in.
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:81
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.
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...