Loading...
Searching...
No Matches
glslfxResourceLayout.h
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
36PXR_NAMESPACE_OPEN_SCOPE
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 (centroid) \
54 (sample) \
55 (smooth) \
56 (flat) \
57 (noperspective)
58
59
60TF_DECLARE_PUBLIC_TOKENS(HioGlslfxResourceLayoutTokens, HIO_API,
61 HIO_GLSLFX_RESOURCE_LAYOUT_TOKENS);
62
63class VtDictionary;
64
87{
88public:
92 enum class InOut {
93 NONE,
94 STAGE_IN,
95 STAGE_OUT,
96 };
97
99 enum class Kind {
100 NONE,
101 VALUE,
102 BLOCK,
103 QUALIFIER,
104 UNIFORM_VALUE,
105 UNIFORM_BLOCK,
106 UNIFORM_BLOCK_CONSTANT_PARAMS,
107 BUFFER_READ_ONLY,
108 BUFFER_READ_WRITE,
109 };
110
112 struct Member {
113 Member(TfToken const & dataType,
114 TfToken const & name,
115 TfToken const & arraySize = TfToken(),
116 TfToken const & qualifiers = TfToken())
117 : dataType(dataType)
118 , name(name)
119 , arraySize(arraySize)
120 { }
121 TfToken dataType;
122 TfToken name;
123 TfToken arraySize;
124 TfToken qualifiers;
125 };
126 using MemberVector = std::vector<Member>;
127
129 struct Element {
130 Element(InOut inOut = InOut::NONE,
131 Kind kind = Kind::NONE,
132 TfToken dataType = HioGlslfxResourceLayoutTokens->unknown,
133 TfToken name = HioGlslfxResourceLayoutTokens->unknown,
134 TfToken arraySize = TfToken(),
135 TfToken qualifiers = TfToken())
136 : inOut(inOut)
137 , kind(kind)
138 , location(-1)
139 , dataType(dataType)
140 , name(name)
141 , qualifiers(qualifiers)
142 , arraySize(arraySize)
143 , aggregateName()
144 , members()
145 { }
146 InOut inOut;
147 Kind kind;
148 int location;
149 TfToken dataType;
150 TfToken name;
151 TfToken qualifiers;
152 TfToken arraySize;
153 TfToken aggregateName;
154 MemberVector members;
155 };
156 using ElementVector = std::vector<Element>;
157
159 enum class TextureType {
160 TEXTURE, // a texture
161 SHADOW_TEXTURE, // a texture used as a shadow
162 ARRAY_TEXTURE, // e.g. texture1DArray, texture2DArray, etc.
163 };
164
168 int dim,
169 int bindingIndex,
170 HioFormat format = HioFormatFloat32Vec4,
171 TextureType textureType = TextureType::TEXTURE,
172 int arraySize = 0)
173 : name(name)
174 , dim(dim)
175 , bindingIndex(bindingIndex)
176 , format(format)
177 , textureType(textureType)
178 , arraySize(arraySize)
179 { }
180 TfToken name;
181 int dim;
182 int bindingIndex;
183 HioFormat format;
184 TextureType textureType;
185 int arraySize;
186 };
187 using TextureElementVector = std::vector<TextureElement>;
188
191
194 HIO_API
195 static void ParseLayout(
196 ElementVector *result,
197 TfToken const &shaderStage,
198 VtDictionary const &layoutDict);
199};
200
201
202PXR_NAMESPACE_CLOSE_SCOPE
203
204#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:88
A map with string keys and VtValue values.
Definition: dictionary.h:60
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:98
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...