HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
graphicsCmds.h
Go to the documentation of this file.
1 //
2 // Copyright 2019 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_CMDS_H
8 #define PXR_IMAGING_HGI_GRAPHICS_CMDS_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/base/gf/vec4i.h"
12 #include "pxr/imaging/hgi/api.h"
16 #include "pxr/imaging/hgi/cmds.h"
17 #include <memory>
18 
20 
21 using HgiGraphicsCmdsUniquePtr = std::unique_ptr<class HgiGraphicsCmds>;
22 
23 
24 /// \class HgiGraphicsCmds
25 ///
26 /// A graphics API independent abstraction of graphics commands.
27 /// HgiGraphicsCmds is a lightweight object that cannot be re-used after it has
28 /// been submitted. A new cmds object should be acquired for each frame.
29 ///
30 class HgiGraphicsCmds : public HgiCmds
31 {
32 public:
33  HGI_API
34  ~HgiGraphicsCmds() override;
35 
36  /// Push a debug scope.
37  HGI_API
38  virtual void PushDebugGroup(const char* label,
39  const GfVec4f& color = s_graphicsDebugColor) = 0;
40 
41  /// Pop the last debug scope.
42  HGI_API
43  virtual void PopDebugGroup() = 0;
44 
45  /// Insert a debug marker
46  HGI_API
47  virtual void InsertDebugMarker(
48  const char* label,
49  const GfVec4f& color = s_markerDebugColor) = 0;
50 
51  /// Set viewport [left, BOTTOM, width, height] - OpenGL coords
52  HGI_API
53  virtual void SetViewport(GfVec4i const& vp) = 0;
54 
55  /// Only pixels that lie within the scissor box are modified by
56  /// drawing commands.
57  HGI_API
58  virtual void SetScissor(GfVec4i const& sc) = 0;
59 
60  /// Bind a pipeline state object. Usually you call this right after calling
61  /// CreateGraphicsCmds to set the graphics pipeline state.
62  /// The resource bindings used when creating the pipeline must be compatible
63  /// with the resources bound via BindResources().
64  HGI_API
65  virtual void BindPipeline(HgiGraphicsPipelineHandle pipeline) = 0;
66 
67  /// Bind resources such as textures and uniform buffers.
68  /// Usually you call this right after BindPipeline() and the resources bound
69  /// must be compatible with the bound pipeline.
70  HGI_API
71  virtual void BindResources(HgiResourceBindingsHandle resources) = 0;
72 
73  /// Set Push / Function constants.
74  /// `pipeline` is the pipeline that you are binding before the draw call. It
75  /// contains the program used for the uniform buffer
76  /// `stages` describes for what shader stage you are setting the push
77  /// constant values for. Each stage can have its own (or none) binding
78  /// and they must match what is described in the shader functions.
79  /// `bindIndex` is the binding point index in the pipeline's shader
80  /// to bind the data to.
81  /// `byteSize` is the size of the data you are updating.
82  /// `data` is the data you are copying into the push constants block.
83  HGI_API
84  virtual void SetConstantValues(
87  uint32_t bindIndex,
88  uint32_t byteSize,
89  const void* data) = 0;
90 
91  /// Binds the vertex buffer(s) that describe the vertex attributes.
92  HGI_API
93  virtual void BindVertexBuffers(
94  HgiVertexBufferBindingVector const &bindings) = 0;
95 
96  /// Records a draw command that renders one or more instances of primitives
97  /// using the number of vertices provided.
98  /// The 'primitive type' (eg. Lines, Triangles, etc) can be acquired from
99  /// the bound HgiPipeline.
100  /// `vertexCount`: The number of vertices to draw.
101  /// `baseVertex`: The index of the first vertex to draw.
102  /// `instanceCount`: Number of instances to draw.
103  /// `baseInstance`: The first instance to draw.
104  HGI_API
105  virtual void Draw(
106  uint32_t vertexCount,
107  uint32_t baseVertex,
108  uint32_t instanceCount,
109  uint32_t baseInstance) = 0;
110 
111  /// Records a multi-draw command that reads the draw parameters
112  /// from a provided drawParameterBuffer.
113  /// The 'primitive type' (eg. Lines, Triangles, etc) can be acquired from
114  /// the bound HgiPipeline.
115  /// `drawParameterBuffer`: an array of structures:
116  // struct IndirectCommand {
117  // uint32_t vertexCount;
118  // uint32_t instanceCount;
119  // uint32_t baseVertex;
120  // uint32_t baseInstance;
121  // }
122  /// `drawBufferByteOffset`: Byte offset where the draw parameters begin.
123  /// `drawCount`: The number of draws to execute.
124  /// `stride`: byte stride between successive sets of draw parameters.
125  HGI_API
126  virtual void DrawIndirect(
127  HgiBufferHandle const& drawParameterBuffer,
128  uint32_t drawBufferByteOffset,
129  uint32_t drawCount,
130  uint32_t stride) = 0;
131 
132  /// Records a draw command that renders one or more instances of primitives
133  /// using an indexBuffer starting from the base vertex.
134  /// The 'primitive type' (eg. Lines, Triangles, etc) can be acquired from
135  /// the bound HgiPipeline.
136  /// `indexCount`: The number of indices in the index buffer (num vertices).
137  /// `indexBufferByteOffset`: Byte offset within index buffer to start
138  /// reading the indices from.
139  /// `baseVertex`: The value added to the vertex index before indexing
140  /// into the vertex buffer (baseVertex).
141  /// `instanceCount`: Number of instances to draw.
142  /// `baseInstance`: The first instance to draw.
143  HGI_API
144  virtual void DrawIndexed(
145  HgiBufferHandle const& indexBuffer,
146  uint32_t indexCount,
147  uint32_t indexBufferByteOffset,
148  uint32_t baseVertex,
149  uint32_t instanceCount,
150  uint32_t baseInstance) = 0;
151 
152  /// Records a indexed multi-draw command that reads the draw parameters
153  /// from a provided drawParameterBuffer, and indices from indexBuffer.
154  /// The 'primitive type' (eg. Lines, Triangles, etc) can be acquired from
155  /// the bound HgiPipeline.
156  /// `drawParameterBuffer`: an array of structures (Metal has a different
157  /// encoding of indirect commands for tessellated patches):
158  // struct IndirectCommand {
159  // uint32_t indexCount;
160  // uint32_t instanceCount;
161  // uint32_t baseIndex;
162  // uint32_t baseVertex;
163  // uint32_t baseInstance;
164  // }
165  // struct MetalPatchIndirectCommand {
166  // uint32_t patchCount;
167  // uint32_t instanceCount;
168  // uint32_t patchStart;
169  // uint32_t baseInstance;
170  // }
171  /// `drawBufferByteOffset`: Byte offset where the draw parameters begin.
172  /// `drawCount`: The number of draws to execute.
173  /// `stride`: byte stride between successive sets of draw parameters.
174  /// `drawParameterBufferUInt32`: CPU addressable `drawParameterBuffer`
175  /// which contains the `baseVertex` offset needed for each patch draw
176  /// for Metal.
177  /// `patchBaseVertexByteOffset`: Byte offset to the uint32_t value
178  /// in `drawParameterBufferUint32` which is the `baseVertex` value
179  /// which must be applied to each HgiVertexBufferPerPatchControlPoint
180  /// vertex buffer for each patch draw for Metal.
181  HGI_API
182  virtual void DrawIndexedIndirect(
183  HgiBufferHandle const& indexBuffer,
184  HgiBufferHandle const& drawParameterBuffer,
185  uint32_t drawBufferByteOffset,
186  uint32_t drawCount,
187  uint32_t stride,
188  std::vector<uint32_t> const& drawParameterBufferUInt32,
189  uint32_t patchBaseVertexByteOffset) = 0;
190 
191  /// Inserts a barrier so that data written to memory by commands before
192  /// the barrier is available to commands after the barrier.
193  HGI_API
194  virtual void InsertMemoryBarrier(HgiMemoryBarrier barrier) = 0;
195 
196 protected:
197  HGI_API
198  HgiGraphicsCmds();
199 
200 private:
201  HgiGraphicsCmds & operator=(const HgiGraphicsCmds&) = delete;
202  HgiGraphicsCmds(const HgiGraphicsCmds&) = delete;
203 };
204 
205 
206 
208 
209 #endif
Definition: vec4i.h:43
virtual HGI_API void DrawIndirect(HgiBufferHandle const &drawParameterBuffer, uint32_t drawBufferByteOffset, uint32_t drawCount, uint32_t stride)=0
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
virtual HGI_API void DrawIndexed(HgiBufferHandle const &indexBuffer, uint32_t indexCount, uint32_t indexBufferByteOffset, uint32_t baseVertex, uint32_t instanceCount, uint32_t baseInstance)=0
GLbitfield stages
Definition: glcorearb.h:1931
virtual HGI_API void SetScissor(GfVec4i const &sc)=0
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
virtual HGI_API void BindResources(HgiResourceBindingsHandle resources)=0
static constexpr GfVec4f s_graphicsDebugColor
Definition: cmds.h:57
virtual HGI_API void Draw(uint32_t vertexCount, uint32_t baseVertex, uint32_t instanceCount, uint32_t baseInstance)=0
virtual HGI_API void PopDebugGroup()=0
Pop the last debug scope.
virtual HGI_API void PushDebugGroup(const char *label, const GfVec4f &color=s_graphicsDebugColor)=0
Push a debug scope.
std::vector< HgiVertexBufferBinding > HgiVertexBufferBindingVector
HgiBits HgiMemoryBarrier
Definition: enums.h:679
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:872
virtual HGI_API void InsertMemoryBarrier(HgiMemoryBarrier barrier)=0
std::unique_ptr< class HgiGraphicsCmds > HgiGraphicsCmdsUniquePtr
Definition: effectsShader.h:28
static constexpr GfVec4f s_markerDebugColor
Definition: cmds.h:61
Definition: vec4f.h:45
HGI_API HgiGraphicsCmds()
#define HGI_API
Definition: api.h:23
virtual HGI_API void BindVertexBuffers(HgiVertexBufferBindingVector const &bindings)=0
Binds the vertex buffer(s) that describe the vertex attributes.
GLuint color
Definition: glcorearb.h:1261
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
virtual HGI_API void InsertDebugMarker(const char *label, const GfVec4f &color=s_markerDebugColor)=0
Insert a debug marker.
HgiBits HgiShaderStage
Definition: enums.h:364
virtual HGI_API void SetConstantValues(HgiGraphicsPipelineHandle pipeline, HgiShaderStage stages, uint32_t bindIndex, uint32_t byteSize, const void *data)=0
virtual HGI_API void BindPipeline(HgiGraphicsPipelineHandle pipeline)=0
Definition: cmds.h:28
HGI_API ~HgiGraphicsCmds() override
virtual HGI_API void DrawIndexedIndirect(HgiBufferHandle const &indexBuffer, HgiBufferHandle const &drawParameterBuffer, uint32_t drawBufferByteOffset, uint32_t drawCount, uint32_t stride, std::vector< uint32_t > const &drawParameterBufferUInt32, uint32_t patchBaseVertexByteOffset)=0
Definition: format.h:1821
virtual HGI_API void SetViewport(GfVec4i const &vp)=0
Set viewport [left, BOTTOM, width, height] - OpenGL coords.