HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
graphicsPipeline.h
Go to the documentation of this file.
1 //
2 // Copyright 2020 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_HGI_GRAPHICS_PIPELINE_H
8 #define PXR_IMAGING_HGI_GRAPHICS_PIPELINE_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hgi/api.h"
13 #include "pxr/imaging/hgi/enums.h"
14 #include "pxr/imaging/hgi/handle.h"
17 #include "pxr/imaging/hgi/types.h"
18 
19 #include "pxr/base/gf/vec2f.h"
20 
21 #include <string>
22 #include <vector>
23 
25 
26 
27 /// \struct HgiVertexAttributeDesc
28 ///
29 /// Describes one attribute of a vertex.
30 ///
31 /// <ul>
32 /// <li>format:
33 /// Format of the vertex attribute.</li>
34 /// <li>offset:
35 /// The byte offset of the attribute in vertex buffer</li>
36 /// <li>shaderBindLocation:
37 /// The location of the attribute in the shader. layout(location = X)</li>
38 /// </ul>
39 ///
41 {
42  HGI_API
44 
46  uint32_t offset;
48 };
49 using HgiVertexAttributeDescVector = std::vector<HgiVertexAttributeDesc>;
50 
51 HGI_API
52 bool operator==(
53  const HgiVertexAttributeDesc& lhs,
54  const HgiVertexAttributeDesc& rhs);
55 
56 HGI_API
57 inline bool operator!=(
58  const HgiVertexAttributeDesc& lhs,
59  const HgiVertexAttributeDesc& rhs);
60 
61 
62 /// \struct HgiVertexBufferDesc
63 ///
64 /// Describes the attributes of a vertex buffer.
65 ///
66 /// <ul>
67 /// <li>bindingIndex:
68 /// Binding location for this vertex buffer.</li>
69 /// <li>vertexAttributes:
70 /// List of vertex attributes (in vertex buffer).</li>
71 /// <li>vertexStepFunction:
72 /// The rate at which data is pulled for this vertex buffer.</li>
73 /// <li>vertexStride:
74 /// The byte size of a vertex (distance between two vertices).</li>
75 /// </ul>
76 ///
78 {
79  HGI_API
81 
82  uint32_t bindingIndex;
85  uint32_t vertexStride;
86 };
87 using HgiVertexBufferDescVector = std::vector<HgiVertexBufferDesc>;
88 
89 HGI_API
90 bool operator==(
91  const HgiVertexBufferDesc& lhs,
92  const HgiVertexBufferDesc& rhs);
93 
94 HGI_API
95 inline bool operator!=(
96  const HgiVertexBufferDesc& lhs,
97  const HgiVertexBufferDesc& rhs);
98 
99 
100 /// \struct HgiMultiSampleState
101 ///
102 /// Properties to configure multi sampling.
103 ///
104 /// <ul>
105 /// <li>multiSampleEnable:
106 /// When enabled and sampleCount and attachments match and allow for it, use
107 /// multi-sampling.</li>
108 /// <li>alphaToCoverageEnable:
109 /// Fragment's color.a determines coverage (screen door transparency).</li>
110 /// <li>alphaToOneEnable:
111 /// Fragment's color.a is replaced by the maximum representable alpha
112 /// value for fixed-point color attachments, or by 1.0 for floating-point
113 /// attachments.</li>
114 /// <li>sampleCount:
115 /// The number of samples for each fragment. Must match attachments</li>
116 /// </ul>
117 ///
119 {
120  HGI_API
122 
127 };
128 
129 HGI_API
130 bool operator==(
131  const HgiMultiSampleState& lhs,
132  const HgiMultiSampleState& rhs);
133 
134 HGI_API
135 bool operator!=(
136  const HgiMultiSampleState& lhs,
137  const HgiMultiSampleState& rhs);
138 
139 
140 /// \struct HgiRasterizationState
141 ///
142 /// Properties to configure the rasterization state.
143 ///
144 /// <ul>
145 /// <li>polygonMode:
146 /// Determines the rasterization draw mode of primitve (triangles).</li>
147 /// <li>lineWidth:
148 /// The width of lines when polygonMode is set to line drawing.</li>
149 /// <li>cullMode:
150 /// Determines the culling rules for primitives (triangles).</li>
151 /// <li>winding:
152 /// The rule that determines what makes a front-facing primitive.</li>
153 /// <li>rasterizationEnabled:
154 /// When false all primitives are discarded before rasterization stage.</li>
155 /// <li>depthClampEnabled:
156 /// When enabled clamps the clip space depth to the view volume, rather than
157 /// clipping the depth to the near and far planes.</li>
158 /// <li>depthRange:
159 /// The mapping of NDC depth values to window depth values.</li>
160 /// <li>conservativeRaster:
161 /// When enabled, any pixel at least partially covered by a rendered primitive
162 /// will be rasterized.</li>
163 /// <li>numClipDistances:
164 /// The number of user-defined clip distances.</li>
165 /// </ul>
166 ///
168 {
169  HGI_API
171 
173  float lineWidth;
181 };
182 
183 HGI_API
184 bool operator==(
185  const HgiRasterizationState& lhs,
186  const HgiRasterizationState& rhs);
187 
188 HGI_API
189 bool operator!=(
190  const HgiRasterizationState& lhs,
191  const HgiRasterizationState& rhs);
192 
193 /// \struct HgiStencilState
194 ///
195 /// Properties controlling the operation of the stencil test.
196 ///
197 /// <ul>
198 /// <li>compareFn:
199 /// The function used to test the reference value with the masked
200 /// value read from the stencil buffer.</li>
201 /// <li>referenceValue:
202 //. The reference value used by the stencil test function.</li>
203 /// <li>stencilFailOp:
204 /// The operation executed when the stencil test fails.</li>
205 /// <li>depthFailOp:
206 /// The operation executed when the stencil test passes but the
207 /// depth test fails.</li>
208 /// <li>depthStencilPassOp:
209 /// The operation executed when both stencil and depth tests pass.</li>
210 /// <li>readMask:
211 /// The mask applied to values before the stencil test function.</li>
212 /// <li>writeMask:
213 /// The mask applied when writing to the stencil buffer.</li>
214 /// </ul>
215 ///
217 {
218  HGI_API
219  HgiStencilState();
220 
222  uint32_t referenceValue;
226  uint32_t readMask;
227  uint32_t writeMask;
228 };
229 
230 HGI_API
231 bool operator==(
232  const HgiStencilState& lhs,
233  const HgiStencilState& rhs);
234 
235 HGI_API
236 bool operator!=(
237  const HgiStencilState& lhs,
238  const HgiStencilState& rhs);
239 
240 /// \struct HgiDepthStencilState
241 ///
242 /// Properties to configure depth and stencil test.
243 ///
244 /// <ul>
245 /// <li>depthTestEnabled:
246 /// When enabled uses `depthCompareFn` to test if a fragment passes the
247 /// depth test. Note that depth writes are automatically disabled when
248 /// depthTestEnabled is false.</li>
249 /// <li>depthWriteEnabled:
250 /// When enabled uses `depthCompareFn` to test if a fragment passes the
251 /// depth test. Note that depth writes are automatically disabled when
252 /// depthTestEnabled is false.</li>
253 /// <li>depthCompareFn:
254 /// The function used to test depth values.</li>
255 /// <li>depthBiasEnabled:
256 /// When enabled applies a bias to depth values before the depth test.
257 /// <li>depthBiasConstantFactor:
258 /// The constant depth bias.</li>
259 /// <li>depthBiasSlopeFactor:
260 /// The depth bias that scales with the gradient of the primitive.</li>
261 /// <li>stencilTestEnabled:
262 /// Enables the stencil test.</li>
263 /// <li>stencilFront:
264 /// Stencil operation for front faces.</li>
265 /// <li>stencilBack:
266 /// Stencil operation for back faces.</li>
267 /// </ul>
268 ///
270 {
271  HGI_API
273 
277 
281 
285 };
286 
287 HGI_API
288 bool operator==(
289  const HgiDepthStencilState& lhs,
290  const HgiDepthStencilState& rhs);
291 
292 HGI_API
293 bool operator!=(
294  const HgiDepthStencilState& lhs,
295  const HgiDepthStencilState& rhs);
296 
297 /// \struct HgiGraphicsShaderConstantsDesc
298 ///
299 /// A small, but fast buffer of uniform data for shaders.
300 ///
301 /// <ul>
302 /// <li>byteSize:
303 /// Size of the constants in bytes. (max 256 bytes)</li>
304 /// <li>stageUsage:
305 /// What shader stage(s) the constants will be used in.</li>
306 /// </ul>
307 ///
309  HGI_API
311 
312  uint32_t byteSize;
314 };
315 
316 HGI_API
317 bool operator==(
319  const HgiGraphicsShaderConstantsDesc& rhs);
320 
321 HGI_API
322 bool operator!=(
324  const HgiGraphicsShaderConstantsDesc& rhs);
325 
327 {
328  HGI_API
330 
331  float innerTessLevel[2];
332  float outerTessLevel[4];
333 };
334 
335 /// \struct HgiTessellationState
336 ///
337 /// Properties to configure tessellation.
338 ///
339 /// <ul>
340 /// <li>patchType:
341 /// The type of tessellation patch.</li>
342 /// <li>primitiveIndexSize:
343 /// The number of control indices per patch.</li>
344 /// <li>tessellationLevel:
345 /// The fallback tessellation levels.</li>
346 /// </ul>
347 ///
349 {
350  enum PatchType {
354  };
355 
360  };
361 
362  HGI_API
364 
367  TessFactorMode tessFactorMode = TessFactorMode::Constant;
369 };
370 
371 /// \struct HgiGraphicsPipelineDesc
372 ///
373 /// Describes the properties needed to create a GPU pipeline.
374 ///
375 /// <ul>
376 /// <li>primitiveType:
377 /// Describes the stream of vertices (primitive topology).</li>
378 /// <li>shaderProgram:
379 /// Shader functions/stages used in this pipeline.</li>
380 /// <li>depthState:
381 /// Describes depth state for a pipeline.</li>
382 /// <li>multiSampleState:
383 /// Various settings to control multi-sampling.</li>
384 /// <li>rasterizationState:
385 /// Various settings to control rasterization.</li>
386 /// <li>vertexBuffers:
387 /// Description of the vertex buffers (per-vertex attributes).
388 /// The actual VBOs are bound via GraphicsCmds.</li>
389 /// <li>colorAttachmentDescs:
390 /// Describes each of the color attachments.</li>
391 /// <li>depthAttachmentDesc:
392 /// Describes the depth attachment (optional)
393 /// Use HgiFormatInvalid to indicate no depth attachment.</li>
394 /// <li>resolveAttachments:
395 /// Indicates whether or not to resolve the color and depth attachments.</li>
396 /// <li>shaderConstantsDesc:
397 /// Describes the shader uniforms.</li>
398 /// <li>tessellationState:
399 /// Describes the tessellation state.</li>
400 /// </ul>
401 ///
403 {
404  HGI_API
406 
407  std::string debugName;
419 };
420 
421 HGI_API
422 bool operator==(
423  const HgiGraphicsPipelineDesc& lhs,
424  const HgiGraphicsPipelineDesc& rhs);
425 
426 HGI_API
427 bool operator!=(
428  const HgiGraphicsPipelineDesc& lhs,
429  const HgiGraphicsPipelineDesc& rhs);
430 
431 
432 ///
433 /// \class HgiGraphicsPipeline
434 ///
435 /// Represents a graphics platform independent GPU graphics pipeline
436 /// resource.
437 ///
438 /// Base class for Hgi pipelines.
439 /// To the client (HdSt) pipeline resources are referred to via
440 /// opaque, stateless handles (HgiPipelineHandle).
441 ///
443 {
444 public:
445  HGI_API
446  virtual ~HgiGraphicsPipeline();
447 
448  /// The descriptor describes the object.
449  HGI_API
450  HgiGraphicsPipelineDesc const& GetDescriptor() const;
451 
452 protected:
453  HGI_API
455 
457 
458 private:
459  HgiGraphicsPipeline() = delete;
460  HgiGraphicsPipeline & operator=(const HgiGraphicsPipeline&) = delete;
461  HgiGraphicsPipeline(const HgiGraphicsPipeline&) = delete;
462 };
463 
465 using HgiGraphicsPipelineHandleVector = std::vector<HgiGraphicsPipelineHandle>;
466 
467 
469 
470 #endif
HgiVertexBufferDescVector vertexBuffers
HgiPolygonMode
Definition: enums.h:411
HgiStencilOp
Definition: enums.h:545
HgiVertexBufferStepFunction
Definition: enums.h:627
HgiStencilOp stencilFailOp
HgiVertexAttributeDescVector vertexAttributes
HgiCompareFunction
Definition: enums.h:527
HGI_API HgiMultiSampleState()
HGI_API HgiDepthStencilState()
virtual HGI_API ~HgiGraphicsPipeline()
TessFactorMode tessFactorMode
std::vector< HgiAttachmentDesc > HgiAttachmentDescVector
HgiWinding
Definition: enums.h:456
HgiDepthStencilState depthState
HgiAttachmentDescVector colorAttachmentDescs
HgiGraphicsPipelineDesc _descriptor
HgiFormat
Definition: types.h:28
HgiStencilState stencilFront
HgiTessellationLevel tessellationLevel
HgiVertexBufferStepFunction vertexStepFunction
std::vector< HgiVertexBufferDesc > HgiVertexBufferDescVector
HgiCullMode
Definition: enums.h:435
std::vector< HgiGraphicsPipelineHandle > HgiGraphicsPipelineHandleVector
HgiSampleCount sampleCount
HgiStencilState stencilBack
HgiMultiSampleState multiSampleState
HgiGraphicsShaderConstantsDesc shaderConstantsDesc
HgiRasterizationState rasterizationState
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition: Mat3.h:556
HGI_API HgiStencilState()
HGI_API HgiVertexAttributeDesc()
HgiPrimitiveType
Definition: enums.h:596
HGI_API HgiVertexBufferDesc()
HGI_API HgiTessellationState()
#define HGI_API
Definition: api.h:23
HgiStencilOp depthStencilPassOp
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
Definition: vec2f.h:45
HgiShaderProgramHandle shaderProgram
HGI_API HgiRasterizationState()
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HGI_API HgiGraphicsPipelineDesc()
HgiAttachmentDesc depthAttachmentDesc
HgiTessellationState tessellationState
HgiBits HgiShaderStage
Definition: enums.h:357
HgiCompareFunction compareFn
HgiPolygonMode polygonMode
HgiStencilOp depthFailOp
HgiPrimitiveType primitiveType
HgiSampleCount
Definition: enums.h:234
HGI_API HgiGraphicsPipelineDesc const & GetDescriptor() const
The descriptor describes the object.
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:542
HgiCompareFunction depthCompareFn
HGI_API HgiTessellationLevel()
std::vector< HgiVertexAttributeDesc > HgiVertexAttributeDescVector