HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
resourceBindings.h
Go to the documentation of this file.
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_RESOURCEBINDINGS_H
8 #define PXR_IMAGING_HGI_RESOURCEBINDINGS_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hgi/api.h"
12 #include "pxr/imaging/hgi/buffer.h"
13 #include "pxr/imaging/hgi/enums.h"
14 #include "pxr/imaging/hgi/handle.h"
17 #include "pxr/imaging/hgi/types.h"
18 
19 #include <string>
20 #include <vector>
21 
22 
24 
25 
26 
27 
28 
29 /// \struct HgiBufferBindDesc
30 ///
31 /// Describes the binding information of a buffer (or array of buffers).
32 ///
33 /// <ul>
34 /// <li>buffers:
35 /// The buffer(s) to be bound.
36 /// If there are more than one buffer, the buffers will be put in an
37 /// array-of-buffers. Please note that different platforms have varying
38 /// limits to max buffers in an array.</li>
39 /// <li>offsets:
40 /// Offset (in bytes) where data begins from the start of the buffer.
41 /// There is an offset corresponding to each buffer in 'buffers'.</li>
42 /// <li>sizes:
43 /// Size (in bytes) of the range of data in the buffer to bind.
44 /// There is a size corresponding to each buffer in 'buffers'.
45 /// If sizes is empty or the size for a buffer is specified as zero,
46 /// then the entire buffer is bound.
47 /// If the offset for a buffer is non-zero, then a non-zero size must
48 /// also be specified.</li>
49 /// <li>resourceType:
50 /// The type of buffer(s) that is to be bound.
51 /// All buffers in the array must have the same type.
52 /// Vertex, index and indirect buffers are not bound to a resourceSet.
53 /// They are instead passed to the draw command.</li>
54 /// <li>bindingIndex:
55 /// Binding location for the buffer(s).</li>
56 /// <li>stageUsage:
57 /// What shader stage(s) the buffer will be used in.</li>
58 /// <li>writable:
59 /// Whether the buffer binding should be non-const.</li>
60 /// </ul>
61 ///
63 {
64  HGI_API
66 
68  std::vector<uint32_t> offsets;
69  std::vector<uint32_t> sizes;
71  uint32_t bindingIndex;
73  bool writable;
74 };
75 using HgiBufferBindDescVector = std::vector<HgiBufferBindDesc>;
76 
77 HGI_API
78 bool operator==(
79  const HgiBufferBindDesc& lhs,
80  const HgiBufferBindDesc& rhs);
81 
82 HGI_API
83 inline bool operator!=(
84  const HgiBufferBindDesc& lhs,
85  const HgiBufferBindDesc& rhs);
86 
87 /// \struct HgiTextureBindDesc
88 ///
89 /// Describes the binding information of a texture (or array of textures).
90 ///
91 /// <ul>
92 /// <li>textures:
93 /// The texture(s) to be bound.
94 /// If there are more than one texture, the textures will be put in an
95 /// array-of-textures (not texture-array). Please note that different
96 /// platforms have varying limits to max textures in an array.</li>
97 /// <li>samplers:
98 /// (optional) The sampler(s) to be bound for each texture in `textures`.
99 /// If empty a default sampler (clamp_to_edge, linear) should be used. </li>
100 /// <li>resourceType:
101 /// The type of the texture(s) that is to be bound.
102 /// All textures in the array must have the same type.</li>
103 /// <li>bindingIndex:
104 /// Binding location for the texture</li>
105 /// <li>stageUsage:
106 /// What shader stage(s) the texture will be used in.</li>
107 /// <li>writable:
108 /// Whether the texture binding should be non-const.</li>
109 /// </ul>
110 ///
112 {
113  HGI_API
115 
119  uint32_t bindingIndex;
121  bool writable;
122 };
123 using HgiTextureBindDescVector = std::vector<HgiTextureBindDesc>;
124 
125 HGI_API
126 bool operator==(
127  const HgiTextureBindDesc& lhs,
128  const HgiTextureBindDesc& rhs);
129 
130 HGI_API
131 bool operator!=(
132  const HgiTextureBindDesc& lhs,
133  const HgiTextureBindDesc& rhs);
134 
135 /// \struct HgiResourceBindingsDesc
136 ///
137 /// Describes a set of resources that are bound to the GPU during encoding.
138 ///
139 /// <ul>
140 /// <li>buffers:
141 /// The buffers to be bound (E.g. uniform or shader storage).</li>
142 /// <li>textures:
143 /// The textures to be bound.</li>
144 /// </ul>
145 ///
147 {
148  HGI_API
150 
151  std::string debugName;
154 };
155 
156 HGI_API
157 bool operator==(
158  const HgiResourceBindingsDesc& lhs,
159  const HgiResourceBindingsDesc& rhs);
160 
161 HGI_API
162 bool operator!=(
163  const HgiResourceBindingsDesc& lhs,
164  const HgiResourceBindingsDesc& rhs);
165 
166 
167 ///
168 /// \class HgiResourceBindings
169 ///
170 /// Represents a collection of buffers, texture and vertex attributes that will
171 /// be used by an cmds object (and pipeline).
172 ///
174 {
175 public:
176  HGI_API
177  virtual ~HgiResourceBindings();
178 
179  /// The descriptor describes the object.
180  HGI_API
181  HgiResourceBindingsDesc const& GetDescriptor() const;
182 
183 protected:
184  HGI_API
186 
188 
189 private:
190  HgiResourceBindings() = delete;
191  HgiResourceBindings & operator=(const HgiResourceBindings&) = delete;
192  HgiResourceBindings(const HgiResourceBindings&) = delete;
193 };
194 
196 using HgiResourceBindingsHandleVector = std::vector<HgiResourceBindingsHandle>;
197 
198 /// \struct HgiVertexBufferBinding
199 ///
200 /// Describes a buffer to be bound during encoding.
201 ///
202 /// <ul>
203 /// <li>buffer:
204 /// The buffer to be bound (e.g. uniform, storage, vertex).</li>
205 /// <li>byteOffset:
206 /// The byte offset into the buffer from where the data will be bound.</li>
207 /// <li>index:
208 /// The binding index to which the buffer will be bound.</li>
209 /// </ul>
210 ///
212 {
213  HGI_API
215  uint32_t byteOffset,
216  uint32_t index)
217  : buffer(buffer)
218  , byteOffset(byteOffset)
219  , index(index)
220  {
221  }
222 
224  uint32_t byteOffset;
225  uint32_t index;
226 };
227 
228 using HgiVertexBufferBindingVector = std::vector<HgiVertexBufferBinding>;
229 
230 
232 
233 #endif
HgiBindResourceType resourceType
HGI_API HgiVertexBufferBinding(HgiBufferHandle const &buffer, uint32_t byteOffset, uint32_t index)
HgiTextureHandleVector textures
std::vector< HgiTextureBindDesc > HgiTextureBindDescVector
virtual HGI_API ~HgiResourceBindings()
std::vector< HgiBufferBindDesc > HgiBufferBindDescVector
std::vector< HgiTextureHandle > HgiTextureHandleVector
Definition: texture.h:196
GLuint buffer
Definition: glcorearb.h:660
HgiBufferBindDescVector buffers
HGI_API HgiTextureBindDesc()
std::vector< HgiVertexBufferBinding > HgiVertexBufferBindingVector
std::vector< uint32_t > sizes
std::vector< uint32_t > offsets
std::vector< HgiBufferHandle > HgiBufferHandleVector
Definition: buffer.h:135
HgiBindResourceType
Definition: enums.h:385
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition: Mat3.h:556
std::vector< HgiResourceBindingsHandle > HgiResourceBindingsHandleVector
HGI_API HgiResourceBindingsDesc()
HgiTextureBindDescVector textures
HgiResourceBindingsDesc _descriptor
HgiShaderStage stageUsage
HGI_API HgiResourceBindingsDesc const & GetDescriptor() const
The descriptor describes the object.
#define HGI_API
Definition: api.h:23
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
GLuint index
Definition: glcorearb.h:786
HgiShaderStage stageUsage
HgiBufferHandleVector buffers
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HgiBits HgiShaderStage
Definition: enums.h:357
std::vector< HgiSamplerHandle > HgiSamplerHandleVector
Definition: sampler.h:143
HgiBindResourceType resourceType
HgiSamplerHandleVector samplers
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:542
HGI_API HgiBufferBindDesc()