Loading...
Searching...
No Matches
geometricShader.h
1//
2// Copyright 2016 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_HD_ST_GEOMETRIC_SHADER_H
25#define PXR_IMAGING_HD_ST_GEOMETRIC_SHADER_H
26
27#include "pxr/pxr.h"
28#include "pxr/imaging/hdSt/api.h"
29#include "pxr/imaging/hdSt/shaderCode.h"
30#include "pxr/imaging/hd/version.h"
31#include "pxr/imaging/hd/enums.h"
32#include "pxr/imaging/hgi/enums.h"
33#include "pxr/usd/sdf/path.h"
34
35#include <memory>
36
37PXR_NAMESPACE_OPEN_SCOPE
38
39using HdSt_GeometricShaderSharedPtr =
40 std::shared_ptr<class HdSt_GeometricShader>;
41using HdStResourceRegistrySharedPtr =
42 std::shared_ptr<class HdStResourceRegistry>;
43struct HdSt_ShaderKey;
44class HioGlslfx;
45
60class HdSt_GeometricShader : public HdStShaderCode {
61public:
63 enum class PrimitiveType {
64 PRIM_POINTS,
65 PRIM_BASIS_CURVES_LINES, // when linear (or) non-refined cubic
66 PRIM_BASIS_CURVES_LINEAR_PATCHES, // refined linear curves
67 PRIM_BASIS_CURVES_CUBIC_PATCHES, // refined cubic curves
68 PRIM_MESH_COARSE_TRIANGLES,
69 PRIM_MESH_REFINED_TRIANGLES, // e.g: loop subdiv
70 PRIM_MESH_COARSE_QUADS, // e.g: quadrangulation for ptex
71 PRIM_MESH_REFINED_QUADS, // e.g: catmark/bilinear subdiv
72 PRIM_MESH_COARSE_TRIQUADS, // e.g: triangulated quadrangulation
73 PRIM_MESH_REFINED_TRIQUADS, // e.g: triangulated catmark/bilinear
74 PRIM_MESH_BSPLINE, // e.g. catmark limit surface patches
75 PRIM_MESH_BOXSPLINETRIANGLE, // e.g. loop limit surface patches
76 PRIM_VOLUME, // Triangles of bounding box of a volume.
77 PRIM_COMPUTE // A compute shader, e.g frustum culling
78 };
79
81 static inline bool IsPrimTypePoints (PrimitiveType primType) {
82 return primType == PrimitiveType::PRIM_POINTS;
83 }
84
85 static inline bool IsPrimTypeBasisCurves(PrimitiveType primType) {
86 return (primType == PrimitiveType::PRIM_BASIS_CURVES_LINES ||
87 primType == PrimitiveType::PRIM_BASIS_CURVES_CUBIC_PATCHES ||
88 primType == PrimitiveType::PRIM_BASIS_CURVES_LINEAR_PATCHES);
89 }
90
91 static inline bool IsPrimTypeMesh(PrimitiveType primType) {
92 return (primType == PrimitiveType::PRIM_MESH_COARSE_TRIANGLES ||
93 primType == PrimitiveType::PRIM_MESH_REFINED_TRIANGLES ||
94 primType == PrimitiveType::PRIM_MESH_COARSE_QUADS ||
95 primType == PrimitiveType::PRIM_MESH_REFINED_QUADS ||
96 primType == PrimitiveType::PRIM_MESH_COARSE_TRIQUADS ||
97 primType == PrimitiveType::PRIM_MESH_REFINED_TRIQUADS ||
98 primType == PrimitiveType::PRIM_MESH_BSPLINE ||
99 primType == PrimitiveType::PRIM_MESH_BOXSPLINETRIANGLE);
100 }
101
102 static inline bool IsPrimTypeTriangles(PrimitiveType primType) {
103 return (primType == PrimitiveType::PRIM_MESH_COARSE_TRIANGLES ||
104 primType == PrimitiveType::PRIM_MESH_REFINED_TRIANGLES ||
105 primType == PrimitiveType::PRIM_VOLUME);
106 }
107
108 static inline bool IsPrimTypeQuads(PrimitiveType primType) {
109 return (primType == PrimitiveType::PRIM_MESH_COARSE_QUADS ||
110 primType == PrimitiveType::PRIM_MESH_REFINED_QUADS);
111 }
112
113 static inline bool IsPrimTypeTriQuads(PrimitiveType primType) {
114 return (primType == PrimitiveType::PRIM_MESH_COARSE_TRIQUADS ||
115 primType == PrimitiveType::PRIM_MESH_REFINED_TRIQUADS);
116 }
117
118 static inline bool IsPrimTypeRefinedMesh(PrimitiveType primType) {
119 return (primType == PrimitiveType::PRIM_MESH_REFINED_TRIANGLES ||
120 primType == PrimitiveType::PRIM_MESH_REFINED_QUADS ||
121 primType == PrimitiveType::PRIM_MESH_REFINED_TRIQUADS ||
122 primType == PrimitiveType::PRIM_MESH_BSPLINE ||
123 primType == PrimitiveType::PRIM_MESH_BOXSPLINETRIANGLE);
124 }
125
126 static inline bool IsPrimTypePatches(PrimitiveType primType) {
127 return primType == PrimitiveType::PRIM_MESH_BSPLINE ||
128 primType == PrimitiveType::PRIM_MESH_BOXSPLINETRIANGLE ||
129 primType == PrimitiveType::PRIM_BASIS_CURVES_CUBIC_PATCHES ||
130 primType == PrimitiveType::PRIM_BASIS_CURVES_LINEAR_PATCHES;
131 }
132
133 static inline bool IsPrimTypeCompute(PrimitiveType primType) {
134 return primType == PrimitiveType::PRIM_COMPUTE;
135 }
136
137 // Face-varying patch type
138 enum class FvarPatchType {
139 PATCH_COARSE_TRIANGLES,
140 PATCH_REFINED_TRIANGLES,
141 PATCH_COARSE_QUADS,
142 PATCH_REFINED_QUADS,
143 PATCH_BSPLINE,
144 PATCH_BOXSPLINETRIANGLE,
145 PATCH_NONE
146 };
147
148 HDST_API
149 HdSt_GeometricShader(std::string const &glslfxString,
150 PrimitiveType primType,
151 HdCullStyle cullStyle,
152 bool useHardwareFaceCulling,
153 bool hasMirroredTransform,
154 bool doubleSided,
155 bool useMetalTessellation,
156 HdPolygonMode polygonMode,
157 bool cullingPass,
158 FvarPatchType fvarPatchType,
159 SdfPath const &debugId = SdfPath(),
160 float lineWidth = 0);
161
162 HDST_API
163 ~HdSt_GeometricShader() override;
164
165 // HdShader overrides
166 HDST_API
167 ID ComputeHash() const override;
168 HDST_API
169 std::string GetSource(TfToken const &shaderStageKey) const override;
170 HDST_API
171 void BindResources(int program,
172 HdSt_ResourceBinder const &binder) override;
173
174 HDST_API
175 void UnbindResources(int program,
176 HdSt_ResourceBinder const &binder) override;
177 HDST_API
178 void AddBindings(HdStBindingRequestVector *customBindings) override;
179
181 bool IsFrustumCullingPass() const {
182 return _frustumCullingPass;
183 }
184
185 PrimitiveType GetPrimitiveType() const {
186 return _primType;
187 }
188
189 bool GetUseMetalTessellation() const {
190 return _useMetalTessellation;
191 }
192
193 float GetLineWidth() const {
194 return _lineWidth;
195 }
196
197 HdPolygonMode GetPolygonMode() const {
198 return _polygonMode;
199 }
200
202 bool IsPrimTypePoints() const {
203 return IsPrimTypePoints(_primType);
204 }
205
206 bool IsPrimTypeBasisCurves() const {
207 return IsPrimTypeBasisCurves(_primType);
208 }
209
210 bool IsPrimTypeMesh() const {
211 return IsPrimTypeMesh(_primType);
212 }
213
214 bool IsPrimTypeTriangles() const {
215 return IsPrimTypeTriangles(_primType);
216 }
217
218 bool IsPrimTypeQuads() const {
219 return IsPrimTypeQuads(_primType);
220 }
221
222 bool IsPrimTypeTriQuads() const {
223 return IsPrimTypeTriQuads(_primType);
224 }
225
226 bool IsPrimTypeRefinedMesh() const {
227 return IsPrimTypeRefinedMesh(_primType);
228 }
229
230 bool IsPrimTypePatches() const {
231 return IsPrimTypePatches(_primType);
232 }
233
234 bool IsPrimTypeCompute() const {
235 return IsPrimTypeCompute(_primType);
236 }
237
238 FvarPatchType GetFvarPatchType() const {
239 return _fvarPatchType;
240 }
241
242 // Returns the primitive index size based on the primitive type
243 // 3 for triangles, 4 for quads, 16 for regular b-spline patches etc.
244 HDST_API
245 int GetPrimitiveIndexSize() const;
246
247 // Returns the number of vertices output for patch evaluation,
248 // i.e. the number of tessellation control shader invocations.
249 HDST_API
250 int GetNumPatchEvalVerts() const;
251
252 // Returns the primitive index size for the geometry shader shade
253 // 1 for points, 2 for lines, 3 for triangles, 4 for lines_adjacency
254 HDST_API
255 int GetNumPrimitiveVertsForGeometryShader() const;
256
257 // Returns the HgiPrimitiveType for the primitive type.
258 HDST_API
259 HgiPrimitiveType GetHgiPrimitiveType() const;
260
261 // Resolve the cull mode from the cull style in the render state.
262 HDST_API
263 HgiCullMode ResolveCullMode(HdCullStyle const renderStateCullStyle) const;
264
265 // Factory for convenience.
266 static HdSt_GeometricShaderSharedPtr Create(
267 HdSt_ShaderKey const &shaderKey,
268 HdStResourceRegistrySharedPtr const &resourceRegistry);
269
270private:
271 PrimitiveType _primType;
272 HdCullStyle _cullStyle;
273 bool _useHardwareFaceCulling;
274 bool _hasMirroredTransform;
275 bool _doubleSided;
276 bool _useMetalTessellation;
277 HdPolygonMode _polygonMode;
278 float _lineWidth;
279
280 std::unique_ptr<HioGlslfx> _glslfx;
281 bool _frustumCullingPass;
282 FvarPatchType _fvarPatchType;
283 ID _hash;
284
285 // No copying
286 HdSt_GeometricShader(const HdSt_GeometricShader &) = delete;
287 HdSt_GeometricShader &operator =(const HdSt_GeometricShader &) = delete;
288
289 HioGlslfx const * _GetGlslfx() const override;
290};
291
292
293PXR_NAMESPACE_CLOSE_SCOPE
294
295#endif // PXR_IMAGING_HD_ST_GEOMETRIC_SHADER_H
A base class representing the implementation (code) of a shader, used in conjunction with HdRenderPas...
Definition: shaderCode.h:76
virtual void BindResources(int program, HdSt_ResourceBinder const &binder)=0
Binds shader-specific resources to program XXX: this interface is meant to be used for bridging the G...
virtual void AddBindings(HdStBindingRequestVector *customBindings)=0
Add custom bindings (used by codegen)
virtual std::string GetSource(TfToken const &shaderStageKey) const =0
Returns the shader source provided by this shader for shaderStageKey.
virtual void UnbindResources(int program, HdSt_ResourceBinder const &binder)=0
Unbinds shader-specific resources.
virtual ID ComputeHash() const =0
Returns the hash value of the shader code and configuration.
A class representing the config and shader source of a glslfx file.
Definition: glslfx.h:151
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88