HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stagingBuffer.h
Go to the documentation of this file.
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 
31 #include "pxr/imaging/hgi/buffer.h"
32 
33 #include <memory>
34 #include <vector>
35 
37 
39 
41  std::shared_ptr<class HdStStagingBuffer>;
42 
43 /// \class HdStStagingBuffer
44 ///
45 /// Provides a staging buffer for CPU writes of triple-buffered resources.
46 /// None of the function calls are thread safe, they should be only accessed
47 /// from the commit call to ResourceRegistry.
48 ///
50 {
51 public:
52  HDST_API
53  HdStStagingBuffer(HdStResourceRegistry *resourceRegistry);
54 
55  HDST_API
57 
58  /// Destroys contained HgiBuffers and resets state to empty.
59  HDST_API
60  void Deallocate();
61 
62  /// Set the capacity for the staging buffer. Only applied once first call
63  /// to StageCopy is called.
64  /// Cannot be called if there have already been calls to StageCopy for this
65  /// commit.
66  HDST_API
67  void Resize(size_t totalSize);
68 
69  /// Submit a CPU to GPU copy operation to be added to the staging buffer.
70  /// The contents are memcpy'd over into the staging buffer during this call
71  /// and a GPU to GPU blit is queued up to do the final copy to destination.
72  HDST_API
73  void StageCopy(HgiBufferCpuToGpuOp const &copyOp);
74 
75  /// Flush the queued GPU to GPU blits from the calls to StageCopy. Resets
76  /// the state for the next ResoureRegistry commit.
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 
93 
94 #endif // PXR_IMAGING_HD_ST_STAGING_BUFFER_H
HDST_API void Flush()
HDST_API void Deallocate()
Destroys contained HgiBuffers and resets state to empty.
HDST_API ~HdStStagingBuffer()
HDST_API void StageCopy(HgiBufferCpuToGpuOp const &copyOp)
std::shared_ptr< class HdStStagingBuffer > HdStStagingBufferSharedPtr
Definition: stagingBuffer.h:41
HDST_API HdStStagingBuffer(HdStResourceRegistry *resourceRegistry)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
#define HDST_API
Definition: api.h:40
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HDST_API void Resize(size_t totalSize)