stagingBuffer.h
1 //
2 // Copyright 2021 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_STAGING_BUFFER_H
25 #define PXR_IMAGING_HD_ST_STAGING_BUFFER_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
29 
30 #include "pxr/imaging/hgi/blitCmdsOps.h"
31 #include "pxr/imaging/hgi/buffer.h"
32 
33 #include <memory>
34 #include <vector>
35 
36 PXR_NAMESPACE_OPEN_SCOPE
37 
39 
40 using HdStStagingBufferSharedPtr =
41  std::shared_ptr<class HdStStagingBuffer>;
42 
50 {
51 public:
52  HDST_API
53  HdStStagingBuffer(HdStResourceRegistry *resourceRegistry);
54 
55  HDST_API
57 
59  HDST_API
60  void Deallocate();
61 
66  HDST_API
67  void Resize(size_t totalSize);
68 
72  HDST_API
73  void StageCopy(HgiBufferCpuToGpuOp const &copyOp);
74 
77  HDST_API
78  void Flush();
79 
80 private:
81  static constexpr int32_t MULTIBUFFERING = 3;
82 
83  HdStResourceRegistry *_resourceRegistry;
84  HgiBufferHandle _handles[MULTIBUFFERING];
85  size_t _head;
86  size_t _capacity;
87  size_t _activeSlot;
88  bool _tripleBuffered;
89  std::vector<HgiBufferGpuToGpuOp> _gpuCopyOps;
90 };
91 
92 PXR_NAMESPACE_CLOSE_SCOPE
93 
94 #endif // PXR_IMAGING_HD_ST_STAGING_BUFFER_H
Describes the properties needed to copy buffer data from CPU to GPU.
Definition: blitCmdsOps.h:190
HDST_API void Deallocate()
Destroys contained HgiBuffers and resets state to empty.
HDST_API void Resize(size_t totalSize)
Set the capacity for the staging buffer.
HDST_API void Flush()
Flush the queued GPU to GPU blits from the calls to StageCopy.
A central registry of all GPU resources.
Provides a staging buffer for CPU writes of triple-buffered resources.
Definition: stagingBuffer.h:49
HDST_API void StageCopy(HgiBufferCpuToGpuOp const &copyOp)
Submit a CPU to GPU copy operation to be added to the staging buffer.