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 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_BUFFER_UTILS_H
25 #define PXR_IMAGING_HD_ST_BUFFER_UTILS_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
29 #include "pxr/imaging/hd/types.h"
30 #include "pxr/imaging/hgi/buffer.h"
31 
32 #include "pxr/base/vt/value.h"
33 
35 
37 
38 /// Reads the content of buffer back to VtArray.
39 /// The \p offset is expressed in bytes.
42  HdTupleType tupleType,
43  int offset,
44  int stride,
45  int numElements,
46  int elementStride,
47  HdStResourceRegistry *resourceRegistry);
48 
49 /// \class HdStBufferRelocator
50 ///
51 /// A utility class to perform batched buffer copy.
52 ///
54 public:
56  HgiBufferHandle const& srcBuffer, HgiBufferHandle const& dstBuffer) :
57  _srcBuffer(srcBuffer), _dstBuffer(dstBuffer) {}
58 
59  /// Schedule the range to be copied. The consecutive ranges could be
60  /// aggregated into a single copy where possible.
61  HDST_API
62  void AddRange(ptrdiff_t readOffset,
63  ptrdiff_t writeOffset,
64  ptrdiff_t copySize);
65 
66  /// Execute Hgi buffer copy command to flush all scheduled range copies.
67  HDST_API
68  void Commit(class HgiBlitCmds* blitCmds);
69 
70 private:
71  struct _CopyUnit {
72  _CopyUnit(ptrdiff_t read, ptrdiff_t write, ptrdiff_t size)
73  : readOffset(read), writeOffset(write), copySize(size) {}
74 
75  bool Concat(_CopyUnit const &next) {
76  if (readOffset + copySize == next.readOffset &&
77  writeOffset + copySize == next.writeOffset) {
78  copySize += next.copySize;
79  return true;
80  }
81  return false;
82  }
83 
84  ptrdiff_t readOffset;
85  ptrdiff_t writeOffset;
86  ptrdiff_t copySize;
87  };
88 
89  std::vector<_CopyUnit> _queue;
90  HgiBufferHandle _srcBuffer;
91  HgiBufferHandle _dstBuffer;
92 };
93 
94 
96 
97 #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
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
Definition: core.h:760
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:1432
#define HDST_API
Definition: api.h:40
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
Definition: value.h:164
HdStBufferRelocator(HgiBufferHandle const &srcBuffer, HgiBufferHandle const &dstBuffer)
Definition: bufferUtils.h:55