commandBuffer.h
1 //
2 // Copyright 2016 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_HD_ST_COMMAND_BUFFER_H
25 #define PXR_IMAGING_HD_ST_COMMAND_BUFFER_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
29 #include "pxr/imaging/hd/version.h"
30 #include "pxr/imaging/hdSt/drawItemInstance.h"
31 
32 #include "pxr/base/gf/vec2f.h"
33 #include "pxr/base/gf/matrix4f.h"
34 #include "pxr/base/gf/matrix4d.h"
35 
36 #include <memory>
37 #include <vector>
38 
39 PXR_NAMESPACE_OPEN_SCOPE
40 
41 
42 class HdStDrawItem;
44 class HgiCapabilities;
45 class HgiGraphicsCmds;
46 
47 using HdStRenderPassStateSharedPtr = std::shared_ptr<class HdStRenderPassState>;
48 using HdStResourceRegistrySharedPtr =
49  std::shared_ptr<class HdStResourceRegistry>;
50 
51 using HdDrawItemConstPtrVector = std::vector<class HdDrawItem const*>;
52 using HdDrawItemConstPtrVectorSharedPtr
53  = std::shared_ptr<HdDrawItemConstPtrVector>;
54 
55 using HdSt_DrawBatchSharedPtr = std::shared_ptr<class HdSt_DrawBatch>;
56 using HdSt_DrawBatchSharedPtrVector = std::vector<HdSt_DrawBatchSharedPtr>;
57 
67 public:
68  HDST_API
70  HDST_API
72 
74  HDST_API
75  void PrepareDraw(HdStRenderPassStateSharedPtr const &renderPassState,
76  HdStResourceRegistrySharedPtr const &resourceRegistry);
77 
79  HDST_API
80  void ExecuteDraw(HgiGraphicsCmds *gfxCmds,
81  HdStRenderPassStateSharedPtr const &renderPassState,
82  HdStResourceRegistrySharedPtr const &resourceRegistry);
83 
85  HDST_API
86  void FrustumCull(GfMatrix4d const &cullMatrix);
87 
89  HDST_API
90  void SyncDrawItemVisibility(unsigned visChangeCount);
91 
95  HDST_API
96  void SetDrawItems(HdDrawItemConstPtrVectorSharedPtr const &drawItems,
97  unsigned currentBatchVersion,
98  HgiCapabilities const *hgiCapabilities);
99 
101  HDST_API
102  void RebuildDrawBatchesIfNeeded(unsigned currentBatchVersion,
103  HgiCapabilities const *hgiCapabilities);
104 
106  size_t GetTotalSize() const {
107  if (_drawItems) return _drawItems->size();
108  return 0;
109  }
110 
112  size_t GetVisibleSize() const { return _visibleSize; }
113 
115  size_t GetCulledSize() const {
116  if (_drawItems) {
117  return _drawItems->size() - _visibleSize;
118  }
119  return 0;
120  }
121 
122  HDST_API
123  void SetEnableTinyPrimCulling(bool tinyPrimCulling);
124 
125 private:
126  void _RebuildDrawBatches(HgiCapabilities const *hgiCapabilities);
127 
128  HdDrawItemConstPtrVectorSharedPtr _drawItems;
129  std::vector<HdStDrawItemInstance> _drawItemInstances;
130  HdSt_DrawBatchSharedPtrVector _drawBatches;
131  size_t _visibleSize;
132  unsigned int _visChangeCount;
133  unsigned int _drawBatchesVersion;
134 };
135 
136 
137 PXR_NAMESPACE_CLOSE_SCOPE
138 
139 #endif //PXR_IMAGING_HD_ST_COMMAND_BUFFER_H
HDST_API void SyncDrawItemVisibility(unsigned visChangeCount)
Sync visibility state from RprimSharedState to DrawItemInstances.
A graphics API independent abstraction of graphics commands.
Definition: graphicsCmds.h:47
HDST_API void PrepareDraw(HdStRenderPassStateSharedPtr const &renderPassState, HdStResourceRegistrySharedPtr const &resourceRegistry)
Prepare the command buffer for draw.
HDST_API void SetDrawItems(HdDrawItemConstPtrVectorSharedPtr const &drawItems, unsigned currentBatchVersion, HgiCapabilities const *hgiCapabilities)
Sets the draw items to use for batching.
A container to store instance state for a drawitem.
A buffer of commands (HdStDrawItem or HdComputeItem objects) to be executed.
Definition: commandBuffer.h:66
size_t GetVisibleSize() const
Returns the number of draw items, excluding culled items.
HDST_API void RebuildDrawBatchesIfNeeded(unsigned currentBatchVersion, HgiCapabilities const *hgiCapabilities)
Rebuild all draw batches if any underlying buffer array is invalidated.
size_t GetTotalSize() const
Returns the total number of draw items, including culled items.
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Reports the capabilities of the Hgi device.
Definition: capabilities.h:39
size_t GetCulledSize() const
Returns the number of culled draw items.
HDST_API void ExecuteDraw(HgiGraphicsCmds *gfxCmds, HdStRenderPassStateSharedPtr const &renderPassState, HdStResourceRegistrySharedPtr const &resourceRegistry)
Execute the command buffer.
HDST_API void FrustumCull(GfMatrix4d const &cullMatrix)
Cull drawItemInstances based on passed in combined view and projection matrix.