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 marker.
37  HGI_API
38  virtual void PushDebugGroup(const char* label) = 0;
39 
40  /// Pop the last debug marker.
41  HGI_API
42  virtual void PopDebugGroup() = 0;
43 
44  /// Set viewport [left, BOTTOM, width, height] - OpenGL coords
45  HGI_API
46  virtual void SetViewport(GfVec4i const& vp) = 0;
47 
48  /// Only pixels that lie within the scissor box are modified by
49  /// drawing commands.
50  HGI_API
51  virtual void SetScissor(GfVec4i const& sc) = 0;
52 
53  /// Bind a pipeline state object. Usually you call this right after calling
54  /// CreateGraphicsCmds to set the graphics pipeline state.
55  /// The resource bindings used when creating the pipeline must be compatible
56  /// with the resources bound via BindResources().
57  HGI_API
58  virtual void BindPipeline(HgiGraphicsPipelineHandle pipeline) = 0;
59 
60  /// Bind resources such as textures and uniform buffers.
61  /// Usually you call this right after BindPipeline() and the resources bound
62  /// must be compatible with the bound pipeline.
63  HGI_API
64  virtual void BindResources(HgiResourceBindingsHandle resources) = 0;
65 
66  /// Set Push / Function constants.
67  /// `pipeline` is the pipeline that you are binding before the draw call. It
68  /// contains the program used for the uniform buffer
69  /// `stages` describes for what shader stage you are setting the push
70  /// constant values for. Each stage can have its own (or none) binding
71  /// and they must match what is described in the shader functions.
72  /// `bindIndex` is the binding point index in the pipeline's shader
73  /// to bind the data to.
74  /// `byteSize` is the size of the data you are updating.
75  /// `data` is the data you are copying into the push constants block.
76  HGI_API
77  virtual void SetConstantValues(
80  uint32_t bindIndex,
81  uint32_t byteSize,
82  const void* data) = 0;
83 
84  /// Binds the vertex buffer(s) that describe the vertex attributes.
85  HGI_API
86  virtual void BindVertexBuffers(
87  HgiVertexBufferBindingVector const &bindings) = 0;
88 
89  /// Records a draw command that renders one or more instances of primitives
90  /// using the number of vertices provided.
91  /// The 'primitive type' (eg. Lines, Triangles, etc) can be acquired from
92  /// the bound HgiPipeline.
93  /// `vertexCount`: The number of vertices to draw.
94  /// `baseVertex`: The index of the first vertex to draw.
95  /// `instanceCount`: Number of instances to draw.
96  /// `baseInstance`: The first instance to draw.
97  HGI_API
98  virtual void Draw(
99  uint32_t vertexCount,
100  uint32_t baseVertex,
101  uint32_t instanceCount,
102  uint32_t baseInstance) = 0;
103 
104  /// Records a multi-draw command that reads the draw parameters
105  /// from a provided drawParameterBuffer.
106  /// The 'primitive type' (eg. Lines, Triangles, etc) can be acquired from
107  /// the bound HgiPipeline.
108  /// `drawParameterBuffer`: an array of structures:
109  // struct IndirectCommand {
110  // uint32_t vertexCount;
111  // uint32_t instanceCount;
112  // uint32_t baseVertex;
113  // uint32_t baseInstance;
114  // }
115  /// `drawBufferByteOffset`: Byte offset where the draw parameters begin.
116  /// `drawCount`: The number of draws to execute.
117  /// `stride`: byte stride between successive sets of draw parameters.
118  HGI_API
119  virtual void DrawIndirect(
120  HgiBufferHandle const& drawParameterBuffer,
121  uint32_t drawBufferByteOffset,
122  uint32_t drawCount,
123  uint32_t stride) = 0;
124 
125  /// Records a draw command that renders one or more instances of primitives
126  /// using an indexBuffer starting from the base vertex.
127  /// The 'primitive type' (eg. Lines, Triangles, etc) can be acquired from
128  /// the bound HgiPipeline.
129  /// `indexCount`: The number of indices in the index buffer (num vertices).
130  /// `indexBufferByteOffset`: Byte offset within index buffer to start
131  /// reading the indices from.
132  /// `baseVertex`: The value added to the vertex index before indexing
133  /// into the vertex buffer (baseVertex).
134  /// `instanceCount`: Number of instances to draw.
135  /// `baseInstance`: The first instance to draw.
136  HGI_API
137  virtual void DrawIndexed(
138  HgiBufferHandle const& indexBuffer,
139  uint32_t indexCount,
140  uint32_t indexBufferByteOffset,
141  uint32_t baseVertex,
142  uint32_t instanceCount,
143  uint32_t baseInstance) = 0;
144 
145  /// Records a indexed multi-draw command that reads the draw parameters
146  /// from a provided drawParameterBuffer, and indices from indexBuffer.
147  /// The 'primitive type' (eg. Lines, Triangles, etc) can be acquired from
148  /// the bound HgiPipeline.
149  /// `drawParameterBuffer`: an array of structures (Metal has a different
150  /// encoding of indirect commands for tessellated patches):
151  // struct IndirectCommand {
152  // uint32_t indexCount;
153  // uint32_t instanceCount;
154  // uint32_t baseIndex;
155  // uint32_t baseVertex;
156  // uint32_t baseInstance;
157  // }
158  // struct MetalPatchIndirectCommand {
159  // uint32_t patchCount;
160  // uint32_t instanceCount;
161  // uint32_t patchStart;
162  // uint32_t baseInstance;
163  // }
164  /// `drawBufferByteOffset`: Byte offset where the draw parameters begin.
165  /// `drawCount`: The number of draws to execute.
166  /// `stride`: byte stride between successive sets of draw parameters.
167  /// `drawParameterBufferUInt32`: CPU addressable `drawParameterBuffer`
168  /// which contains the `baseVertex` offset needed for each patch draw
169  /// for Metal.
170  /// `patchBaseVertexByteOffset`: Byte offset to the uint32_t value
171  /// in `drawParameterBufferUint32` which is the `baseVertex` value
172  /// which must be applied to each HgiVertexBufferPerPatchControlPoint
173  /// vertex buffer for each patch draw for Metal.
174  HGI_API
175  virtual void DrawIndexedIndirect(
176  HgiBufferHandle const& indexBuffer,
177  HgiBufferHandle const& drawParameterBuffer,
178  uint32_t drawBufferByteOffset,
179  uint32_t drawCount,
180  uint32_t stride,
181  std::vector<uint32_t> const& drawParameterBufferUInt32,
182  uint32_t patchBaseVertexByteOffset) = 0;
183 
184  /// Inserts a barrier so that data written to memory by commands before
185  /// the barrier is available to commands after the barrier.
186  HGI_API
187  virtual void InsertMemoryBarrier(HgiMemoryBarrier barrier) = 0;
188 
189 protected:
190  HGI_API
191  HgiGraphicsCmds();
192 
193 private:
194  HgiGraphicsCmds & operator=(const HgiGraphicsCmds&) = delete;
195  HgiGraphicsCmds(const HgiGraphicsCmds&) = delete;
196 };
197 
198 
199 
201 
202 #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
virtual HGI_API void BindResources(HgiResourceBindingsHandle resources)=0
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 marker.
std::vector< HgiVertexBufferBinding > HgiVertexBufferBindingVector
virtual HGI_API void PushDebugGroup(const char *label)=0
Push a debug marker.
HgiBits HgiMemoryBarrier
Definition: enums.h:672
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
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.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HgiBits HgiShaderStage
Definition: enums.h:357
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:27
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.