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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_HGI_INDIRECT_COMMAND_ENCODER_H
8 #define PXR_IMAGING_HGI_INDIRECT_COMMAND_ENCODER_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hgi/api.h"
12 #include "pxr/imaging/hgi/cmds.h"
15 
16 #include <memory>
17 #include <stdint.h>
18 
20 
21 class Hgi;
22 class HgiComputeCmds;
23 class HgiGraphicsCmds;
24 
26 {
30  : drawCount(drawCount)
31  , graphicsPipeline(graphicsPipeline)
32  , resourceBindings(resourceBindings)
33  {
34  }
35 
36  virtual ~HgiIndirectCommands() = default;
37 
38  uint32_t drawCount;
41 };
42 
43 using HgiIndirectCommandsUniquePtr = std::unique_ptr<HgiIndirectCommands>;
44 
45 /// \class HgiIndirectCommandEncoder
46 ///
47 /// The indirect command encoder is used to record the drawing primitives for a
48 /// batch and capture the resource bindings so that it can be executed
49 /// efficently in a later stage of rendering.
50 /// The EncodeDraw and EncodeDrawIndexed functions store all the necessary state
51 /// in the HgiIndirectCommands structure. This is sub-classed based on the
52 /// platform implementation to maintain all the custom state.
53 /// Execute draw takes the HgiIndirectCommands structure and replays it on the
54 /// device. Currently this is only implemented on the Metal HGI device.
55 ///
57 {
58 public:
59  HGI_API
60  ~HgiIndirectCommandEncoder() override;
61 
62  /// Encodes a batch of draw commands from the drawParameterBuffer.
63  /// Returns a HgiIndirectCommands which holds the necessary buffers and
64  /// state for replaying the batch.
65  HGI_API
67  HgiComputeCmds * computeCmds,
68  HgiGraphicsPipelineHandle const& pipeline,
69  HgiResourceBindingsHandle const& resourceBindings,
70  HgiVertexBufferBindingVector const& vertexBindings,
71  HgiBufferHandle const& drawParameterBuffer,
72  uint32_t drawBufferByteOffset,
73  uint32_t drawCount,
74  uint32_t stride) = 0;
75 
76  /// Encodes a batch of indexed draw commands from the drawParameterBuffer.
77  /// Returns a HgiIndirectCommands which holds the necessary buffers and
78  /// state for replaying the batch.
79  HGI_API
81  HgiComputeCmds * computeCmds,
82  HgiGraphicsPipelineHandle const& pipeline,
83  HgiResourceBindingsHandle const& resourceBindings,
84  HgiVertexBufferBindingVector const& vertexBindings,
85  HgiBufferHandle const& indexBuffer,
86  HgiBufferHandle const& drawParameterBuffer,
87  uint32_t drawBufferByteOffset,
88  uint32_t drawCount,
89  uint32_t stride,
90  uint32_t patchBaseVertexByteOffset) = 0;
91 
92  /// Excutes an indirect command batch from the HgiIndirectCommands
93  /// structure.
94  HGI_API
95  virtual void ExecuteDraw(
96  HgiGraphicsCmds * gfxCmds,
97  HgiIndirectCommands const* commands) = 0;
98 
99 protected:
100  HGI_API
102 
103 private:
104  HgiIndirectCommandEncoder & operator=(const HgiIndirectCommandEncoder&) = delete;
105  HgiIndirectCommandEncoder(const HgiIndirectCommandEncoder&) = delete;
106 };
107 
109 
110 #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:93
#define HGI_API
Definition: api.h:23
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
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:74
virtual ~HgiIndirectCommands()=default
Definition: cmds.h:27
HgiIndirectCommands(uint32_t drawCount, HgiGraphicsPipelineHandle const &graphicsPipeline, HgiResourceBindingsHandle const &resourceBindings)