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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_HD_ST_STAGING_BUFFER_H
8 #define PXR_IMAGING_HD_ST_STAGING_BUFFER_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hdSt/api.h"
12 
14 #include "pxr/imaging/hgi/buffer.h"
15 
16 #include <memory>
17 #include <vector>
18 
20 
22 
24  std::shared_ptr<class HdStStagingBuffer>;
25 
26 /// \class HdStStagingBuffer
27 ///
28 /// Provides a staging buffer for CPU writes of triple-buffered resources.
29 /// None of the function calls are thread safe, they should be only accessed
30 /// from the commit call to ResourceRegistry.
31 ///
33 {
34 public:
35  HDST_API
36  HdStStagingBuffer(HdStResourceRegistry *resourceRegistry);
37 
38  HDST_API
40 
41  /// Destroys contained HgiBuffers and resets state to empty.
42  HDST_API
43  void Deallocate();
44 
45  /// Set the capacity for the staging buffer. Only applied once first call
46  /// to StageCopy is called.
47  /// Cannot be called if there have already been calls to StageCopy for this
48  /// commit.
49  HDST_API
50  void Resize(size_t totalSize);
51 
52  /// Submit a CPU to GPU copy operation to be added to the staging buffer.
53  /// The contents are memcpy'd over into the staging buffer during this call
54  /// and a GPU to GPU blit is queued up to do the final copy to destination.
55  HDST_API
56  void StageCopy(HgiBufferCpuToGpuOp const &copyOp);
57 
58  /// Flush the queued GPU to GPU blits from the calls to StageCopy. Resets
59  /// the state for the next ResoureRegistry commit.
60  HDST_API
61  void Flush();
62 
63 private:
64  static constexpr int32_t MULTIBUFFERING = 3;
65 
66  HdStResourceRegistry *_resourceRegistry;
67  HgiBufferHandle _handles[MULTIBUFFERING];
68  size_t _head;
69  size_t _capacity;
70  size_t _activeSlot;
71  bool _tripleBuffered;
72  std::vector<HgiBufferGpuToGpuOp> _gpuCopyOps;
73 };
74 
76 
77 #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:24
HDST_API HdStStagingBuffer(HdStResourceRegistry *resourceRegistry)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define HDST_API
Definition: api.h:23
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HDST_API void Resize(size_t totalSize)