HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
bufferUtils.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_BUFFER_UTILS_H
8 #define PXR_IMAGING_HD_ST_BUFFER_UTILS_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hdSt/api.h"
12 #include "pxr/imaging/hd/types.h"
13 #include "pxr/imaging/hgi/buffer.h"
14 
15 #include "pxr/base/vt/value.h"
16 
18 
20 
21 /// Reads the content of buffer back to VtArray.
22 /// The \p offset is expressed in bytes.
25  HdTupleType tupleType,
26  int offset,
27  int stride,
28  int numElements,
29  int elementStride,
30  HdStResourceRegistry *resourceRegistry);
31 
32 /// \class HdStBufferRelocator
33 ///
34 /// A utility class to perform batched buffer copy.
35 ///
37 public:
39  HgiBufferHandle const& srcBuffer, HgiBufferHandle const& dstBuffer) :
40  _srcBuffer(srcBuffer), _dstBuffer(dstBuffer) {}
41 
42  /// Schedule the range to be copied. The consecutive ranges could be
43  /// aggregated into a single copy where possible.
44  HDST_API
45  void AddRange(ptrdiff_t readOffset,
46  ptrdiff_t writeOffset,
47  ptrdiff_t copySize);
48 
49  /// Execute Hgi buffer copy command to flush all scheduled range copies.
50  HDST_API
51  void Commit(class HgiBlitCmds* blitCmds);
52 
53 private:
54  struct _CopyUnit {
55  _CopyUnit(ptrdiff_t read, ptrdiff_t write, ptrdiff_t size)
56  : readOffset(read), writeOffset(write), copySize(size) {}
57 
58  bool Concat(_CopyUnit const &next) {
59  if (readOffset + copySize == next.readOffset &&
60  writeOffset + copySize == next.writeOffset) {
61  copySize += next.copySize;
62  return true;
63  }
64  return false;
65  }
66 
67  ptrdiff_t readOffset;
68  ptrdiff_t writeOffset;
69  ptrdiff_t copySize;
70  };
71 
72  std::vector<_CopyUnit> _queue;
73  HgiBufferHandle _srcBuffer;
74  HgiBufferHandle _dstBuffer;
75 };
76 
77 
79 
80 #endif // PXR_IMAGING_HD_ST_GL_UTILS_H
HDST_API void AddRange(ptrdiff_t readOffset, ptrdiff_t writeOffset, ptrdiff_t copySize)
GLenum GLintptr GLintptr writeOffset
Definition: glcorearb.h:1461
GLuint buffer
Definition: glcorearb.h:660
HDST_API VtValue HdStReadBuffer(HgiBufferHandle const &buffer, HdTupleType tupleType, int offset, int stride, int numElements, int elementStride, HdStResourceRegistry *resourceRegistry)
GLintptr offset
Definition: glcorearb.h:665
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:872
HDST_API void Commit(class HgiBlitCmds *blitCmds)
Execute Hgi buffer copy command to flush all scheduled range copies.
GLenum GLintptr readOffset
Definition: glcorearb.h:1461
GLsizeiptr size
Definition: glcorearb.h:664
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
Definition: value.h:146
HdStBufferRelocator(HgiBufferHandle const &srcBuffer, HgiBufferHandle const &dstBuffer)
Definition: bufferUtils.h:38