HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
commandBuffer.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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_HD_ST_COMMAND_BUFFER_H
8 #define PXR_IMAGING_HD_ST_COMMAND_BUFFER_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hdSt/api.h"
12 #include "pxr/imaging/hd/version.h"
14 
15 #include "pxr/base/gf/matrix4d.h"
16 
17 #include <memory>
18 #include <vector>
19 
21 
22 class HdRenderIndex;
23 class HdStDrawItem;
25 class Hgi;
26 class HgiGraphicsCmds;
27 
28 using HdStRenderPassStateSharedPtr = std::shared_ptr<class HdStRenderPassState>;
30  std::shared_ptr<class HdStResourceRegistry>;
31 
32 using HdDrawItemConstPtrVector = std::vector<class HdDrawItem const*>;
34  = std::shared_ptr<HdDrawItemConstPtrVector>;
35 
36 using HdSt_DrawBatchSharedPtr = std::shared_ptr<class HdSt_DrawBatch>;
37 using HdSt_DrawBatchSharedPtrVector = std::vector<HdSt_DrawBatchSharedPtr>;
38 
39 /// \class HdStCommandBuffer
40 ///
41 /// A buffer of commands (HdStDrawItem or HdComputeItem objects) to be executed.
42 ///
43 /// The HdStCommandBuffer is responsible for accumulating draw items and sorting
44 /// them for correctness (e.g. alpha transparency) and efficiency (e.g. the
45 /// fewest number of GPU state changes).
46 ///
48 public:
49  HDST_API
51  HDST_API
53 
54  /// Prepare the command buffer for draw
55  HDST_API
56  void PrepareDraw(HgiGraphicsCmds *gfxCmds,
57  HdStRenderPassStateSharedPtr const &renderPassState,
58  HdRenderIndex *renderIndex);
59 
60  /// Execute the command buffer
61  HDST_API
62  void ExecuteDraw(HgiGraphicsCmds *gfxCmds,
63  HdStRenderPassStateSharedPtr const &renderPassState,
64  HdStResourceRegistrySharedPtr const &resourceRegistry);
65 
66  /// Sync visibility state from RprimSharedState to DrawItemInstances.
67  HDST_API
68  void SyncDrawItemVisibility(unsigned visChangeCount);
69 
70  /// Sets the draw items to use for batching.
71  /// If the shared pointer or version is different, batches are rebuilt and
72  /// the batch version is updated.
73  HDST_API
74  void SetDrawItems(HdDrawItemConstPtrVectorSharedPtr const &drawItems,
75  unsigned currentBatchVersion,
76  Hgi const *hgi);
77 
78  /// Rebuild all draw batches if any underlying buffer array is invalidated.
79  HDST_API
80  void RebuildDrawBatchesIfNeeded(unsigned currentBatchVersion,
81  Hgi const *hgi);
82 
83  /// Returns the total number of draw items, including culled items.
84  size_t GetTotalSize() const {
85  if (_drawItems) return _drawItems->size();
86  return 0;
87  }
88 
89  /// Returns the number of draw items, excluding culled items.
90  size_t GetVisibleSize() const { return _visibleSize; }
91 
92  /// Returns the number of culled draw items.
93  size_t GetCulledSize() const {
94  if (_drawItems) {
95  return _drawItems->size() - _visibleSize;
96  }
97  return 0;
98  }
99 
100  HDST_API
101  void SetEnableTinyPrimCulling(bool tinyPrimCulling);
102 
103 private:
104  void _RebuildDrawBatches(Hgi const *hgi);
105 
106  /// Cull drawItemInstances based on view frustum cull matrix
107  void _FrustumCullCPU(GfMatrix4d const &cullMatrix);
108 
110  std::vector<HdStDrawItemInstance> _drawItemInstances;
111  HdSt_DrawBatchSharedPtrVector _drawBatches;
112  size_t _visibleSize;
113  unsigned int _visChangeCount;
114  unsigned int _drawBatchesVersion;
115 };
116 
117 
119 
120 #endif //PXR_IMAGING_HD_ST_COMMAND_BUFFER_H
std::shared_ptr< class HdStRenderPassState > HdStRenderPassStateSharedPtr
Definition: commandBuffer.h:28
std::shared_ptr< HdDrawItemConstPtrVector > HdDrawItemConstPtrVectorSharedPtr
Definition: commandBuffer.h:34
HDST_API HdStCommandBuffer()
HDST_API void SyncDrawItemVisibility(unsigned visChangeCount)
Sync visibility state from RprimSharedState to DrawItemInstances.
HDST_API void SetDrawItems(HdDrawItemConstPtrVectorSharedPtr const &drawItems, unsigned currentBatchVersion, Hgi const *hgi)
size_t GetTotalSize() const
Returns the total number of draw items, including culled items.
Definition: commandBuffer.h:84
size_t GetVisibleSize() const
Returns the number of draw items, excluding culled items.
Definition: commandBuffer.h:90
HDST_API void SetEnableTinyPrimCulling(bool tinyPrimCulling)
HDST_API void ExecuteDraw(HgiGraphicsCmds *gfxCmds, HdStRenderPassStateSharedPtr const &renderPassState, HdStResourceRegistrySharedPtr const &resourceRegistry)
Execute the command buffer.
Definition: hgi.h:93
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
size_t GetCulledSize() const
Returns the number of culled draw items.
Definition: commandBuffer.h:93
std::vector< HdSt_DrawBatchSharedPtr > HdSt_DrawBatchSharedPtrVector
Definition: commandBuffer.h:37
HDST_API ~HdStCommandBuffer()
#define HDST_API
Definition: api.h:23
HDST_API void RebuildDrawBatchesIfNeeded(unsigned currentBatchVersion, Hgi const *hgi)
Rebuild all draw batches if any underlying buffer array is invalidated.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HDST_API void PrepareDraw(HgiGraphicsCmds *gfxCmds, HdStRenderPassStateSharedPtr const &renderPassState, HdRenderIndex *renderIndex)
Prepare the command buffer for draw.
std::vector< class HdDrawItem const * > HdDrawItemConstPtrVector
Definition: commandBuffer.h:32
std::shared_ptr< class HdStResourceRegistry > HdStResourceRegistrySharedPtr
Definition: commandBuffer.h:30
std::shared_ptr< class HdSt_DrawBatch > HdSt_DrawBatchSharedPtr
Definition: commandBuffer.h:36