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