HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
indirectCommandEncoder.h
Go to the documentation of this file.
1 //
2 // Copyright 2022 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_INDIRECT_COMMAND_ENCODER_H
25 #define PXR_IMAGING_HGI_INDIRECT_COMMAND_ENCODER_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hgi/api.h"
29 #include "pxr/imaging/hgi/cmds.h"
32 
33 #include <memory>
34 #include <stdint.h>
35 
37 
38 class Hgi;
39 class HgiComputeCmds;
40 class HgiGraphicsCmds;
41 
43 {
47  : drawCount(drawCount)
48  , graphicsPipeline(graphicsPipeline)
49  , resourceBindings(resourceBindings)
50  {
51  }
52 
53  virtual ~HgiIndirectCommands() = default;
54 
55  uint32_t drawCount;
58 };
59 
60 using HgiIndirectCommandsUniquePtr = std::unique_ptr<HgiIndirectCommands>;
61 
62 /// \class HgiIndirectCommandEncoder
63 ///
64 /// The indirect command encoder is used to record the drawing primitives for a
65 /// batch and capture the resource bindings so that it can be executed
66 /// efficently in a later stage of rendering.
67 /// The EncodeDraw and EncodeDrawIndexed functions store all the necessary state
68 /// in the HgiIndirectCommands structure. This is sub-classed based on the
69 /// platform implementation to maintain all the custom state.
70 /// Execute draw takes the HgiIndirectCommands structure and replays it on the
71 /// device. Currently this is only implemented on the Metal HGI device.
72 ///
74 {
75 public:
76  HGI_API
77  ~HgiIndirectCommandEncoder() override;
78 
79  /// Encodes a batch of draw commands from the drawParameterBuffer.
80  /// Returns a HgiIndirectCommands which holds the necessary buffers and
81  /// state for replaying the batch.
82  HGI_API
84  HgiComputeCmds * computeCmds,
85  HgiGraphicsPipelineHandle const& pipeline,
86  HgiResourceBindingsHandle const& resourceBindings,
87  HgiVertexBufferBindingVector const& vertexBindings,
88  HgiBufferHandle const& drawParameterBuffer,
89  uint32_t drawBufferByteOffset,
90  uint32_t drawCount,
91  uint32_t stride) = 0;
92 
93  /// Encodes a batch of indexed draw commands from the drawParameterBuffer.
94  /// Returns a HgiIndirectCommands which holds the necessary buffers and
95  /// state for replaying the batch.
96  HGI_API
98  HgiComputeCmds * computeCmds,
99  HgiGraphicsPipelineHandle const& pipeline,
100  HgiResourceBindingsHandle const& resourceBindings,
101  HgiVertexBufferBindingVector const& vertexBindings,
102  HgiBufferHandle const& indexBuffer,
103  HgiBufferHandle const& drawParameterBuffer,
104  uint32_t drawBufferByteOffset,
105  uint32_t drawCount,
106  uint32_t stride,
107  uint32_t patchBaseVertexByteOffset) = 0;
108 
109  /// Excutes an indirect command batch from the HgiIndirectCommands
110  /// structure.
111  HGI_API
112  virtual void ExecuteDraw(
113  HgiGraphicsCmds * gfxCmds,
114  HgiIndirectCommands const* commands) = 0;
115 
116 protected:
117  HGI_API
119 
120 private:
121  HgiIndirectCommandEncoder & operator=(const HgiIndirectCommandEncoder&) = delete;
122  HgiIndirectCommandEncoder(const HgiIndirectCommandEncoder&) = delete;
123 };
124 
126 
127 #endif
virtual HGI_API HgiIndirectCommandsUniquePtr EncodeDrawIndexed(HgiComputeCmds *computeCmds, HgiGraphicsPipelineHandle const &pipeline, HgiResourceBindingsHandle const &resourceBindings, HgiVertexBufferBindingVector const &vertexBindings, HgiBufferHandle const &indexBuffer, HgiBufferHandle const &drawParameterBuffer, uint32_t drawBufferByteOffset, uint32_t drawCount, uint32_t stride, uint32_t patchBaseVertexByteOffset)=0
HgiResourceBindingsHandle resourceBindings
HGI_API ~HgiIndirectCommandEncoder() override
std::vector< HgiVertexBufferBinding > HgiVertexBufferBindingVector
HGI_API HgiIndirectCommandEncoder()
virtual HGI_API void ExecuteDraw(HgiGraphicsCmds *gfxCmds, HgiIndirectCommands const *commands)=0
std::unique_ptr< HgiIndirectCommands > HgiIndirectCommandsUniquePtr
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:872
HgiGraphicsPipelineHandle graphicsPipeline
Definition: hgi.h:110
#define HGI_API
Definition: api.h:40
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
virtual HGI_API HgiIndirectCommandsUniquePtr EncodeDraw(HgiComputeCmds *computeCmds, HgiGraphicsPipelineHandle const &pipeline, HgiResourceBindingsHandle const &resourceBindings, HgiVertexBufferBindingVector const &vertexBindings, HgiBufferHandle const &drawParameterBuffer, uint32_t drawBufferByteOffset, uint32_t drawCount, uint32_t stride)=0
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
virtual ~HgiIndirectCommands()=default
Definition: cmds.h:44
HgiIndirectCommands(uint32_t drawCount, HgiGraphicsPipelineHandle const &graphicsPipeline, HgiResourceBindingsHandle const &resourceBindings)