buffer.h
1 //
2 // Copyright 2020 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_HGI_BUFFER_H
8 #define PXR_IMAGING_HGI_BUFFER_H
9 
10 #include <string>
11 #include <vector>
12 
13 #include "pxr/pxr.h"
14 #include "pxr/base/gf/vec3i.h"
15 #include "pxr/imaging/hgi/api.h"
16 #include "pxr/imaging/hgi/enums.h"
17 #include "pxr/imaging/hgi/handle.h"
18 #include "pxr/imaging/hgi/types.h"
19 
20 
21 PXR_NAMESPACE_OPEN_SCOPE
22 
23 
46 {
47  HGI_API
49  : usage(HgiBufferUsageUniform)
50  , byteSize(0)
51  , vertexStride(0)
52  , initialData(nullptr)
53  {}
54 
55  std::string debugName;
56  HgiBufferUsage usage;
57  size_t byteSize;
58  uint32_t vertexStride;
59  void const* initialData;
60 };
61 
62 HGI_API
63 bool operator==(
64  const HgiBufferDesc& lhs,
65  const HgiBufferDesc& rhs);
66 
67 HGI_API
68 bool operator!=(
69  const HgiBufferDesc& lhs,
70  const HgiBufferDesc& rhs);
71 
72 
81 class HgiBuffer
82 {
83 public:
84  HGI_API
85  virtual ~HgiBuffer();
86 
88  HGI_API
89  HgiBufferDesc const& GetDescriptor() const;
90 
93  HGI_API
94  virtual size_t GetByteSizeOfResource() const = 0;
95 
107  HGI_API
108  virtual uint64_t GetRawResource() const = 0;
109 
119  HGI_API
120  virtual void* GetCPUStagingAddress() = 0;
121 
122 protected:
123  HGI_API
124  HgiBuffer(HgiBufferDesc const& desc);
125 
126  HgiBufferDesc _descriptor;
127 
128 private:
129  HgiBuffer() = delete;
130  HgiBuffer & operator=(const HgiBuffer&) = delete;
131  HgiBuffer(const HgiBuffer&) = delete;
132 };
133 
135 using HgiBufferHandleVector = std::vector<HgiBufferHandle>;
136 
137 
138 PXR_NAMESPACE_CLOSE_SCOPE
139 
140 #endif
AR_API bool operator!=(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
virtual HGI_API uint64_t GetRawResource() const =0
This function returns the handle to the Hgi backend's gpu resource, cast to a uint64_t.
AR_API bool operator==(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
virtual HGI_API void * GetCPUStagingAddress()=0
Returns the 'staging area' in which new buffer data is copied before it is flushed to GPU.
Describes the properties needed to create a GPU buffer.
Definition: buffer.h:45
virtual HGI_API size_t GetByteSizeOfResource() const =0
Returns the byte size of the GPU buffer.
Represents a graphics platform independent GPU buffer resource (base class).
Definition: buffer.h:81
HGI_API HgiBufferDesc const & GetDescriptor() const
The descriptor describes the object.