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 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_HGI_RESOURCEBINDINGS_H
25 #define PXR_IMAGING_HGI_RESOURCEBINDINGS_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hgi/api.h"
29 #include "pxr/imaging/hgi/buffer.h"
30 #include "pxr/imaging/hgi/enums.h"
31 #include "pxr/imaging/hgi/handle.h"
34 #include "pxr/imaging/hgi/types.h"
35 
36 #include <string>
37 #include <vector>
38 
39 
41 
42 
43 
44 
45 
46 /// \struct HgiBufferBindDesc
47 ///
48 /// Describes the binding information of a buffer (or array of buffers).
49 ///
50 /// <ul>
51 /// <li>buffers:
52 /// The buffer(s) to be bound.
53 /// If there are more than one buffer, the buffers will be put in an
54 /// array-of-buffers. Please note that different platforms have varying
55 /// limits to max buffers in an array.</li>
56 /// <li>offsets:
57 /// Offset (in bytes) where data begins from the start of the buffer.
58 /// There is an offset corresponding to each buffer in 'buffers'.</li>
59 /// <li>sizes:
60 /// Size (in bytes) of the range of data in the buffer to bind.
61 /// There is a size corresponding to each buffer in 'buffers'.
62 /// If sizes is empty or the size for a buffer is specified as zero,
63 /// then the entire buffer is bound.
64 /// If the offset for a buffer is non-zero, then a non-zero size must
65 /// also be specified.</li>
66 /// <li>resourceType:
67 /// The type of buffer(s) that is to be bound.
68 /// All buffers in the array must have the same type.
69 /// Vertex, index and indirect buffers are not bound to a resourceSet.
70 /// They are instead passed to the draw command.</li>
71 /// <li>bindingIndex:
72 /// Binding location for the buffer(s).</li>
73 /// <li>stageUsage:
74 /// What shader stage(s) the buffer will be used in.</li>
75 /// <li>writable:
76 /// Whether the buffer binding should be non-const.</li>
77 /// </ul>
78 ///
80 {
81  HGI_API
83 
85  std::vector<uint32_t> offsets;
86  std::vector<uint32_t> sizes;
88  uint32_t bindingIndex;
90  bool writable;
91 };
92 using HgiBufferBindDescVector = std::vector<HgiBufferBindDesc>;
93 
94 HGI_API
95 bool operator==(
96  const HgiBufferBindDesc& lhs,
97  const HgiBufferBindDesc& rhs);
98 
99 HGI_API
100 inline bool operator!=(
101  const HgiBufferBindDesc& lhs,
102  const HgiBufferBindDesc& rhs);
103 
104 /// \struct HgiTextureBindDesc
105 ///
106 /// Describes the binding information of a texture (or array of textures).
107 ///
108 /// <ul>
109 /// <li>textures:
110 /// The texture(s) to be bound.
111 /// If there are more than one texture, the textures will be put in an
112 /// array-of-textures (not texture-array). Please note that different
113 /// platforms have varying limits to max textures in an array.</li>
114 /// <li>samplers:
115 /// (optional) The sampler(s) to be bound for each texture in `textures`.
116 /// If empty a default sampler (clamp_to_edge, linear) should be used. </li>
117 /// <li>resourceType:
118 /// The type of the texture(s) that is to be bound.
119 /// All textures in the array must have the same type.</li>
120 /// <li>bindingIndex:
121 /// Binding location for the texture</li>
122 /// <li>stageUsage:
123 /// What shader stage(s) the texture will be used in.</li>
124 /// <li>writable:
125 /// Whether the texture binding should be non-const.</li>
126 /// </ul>
127 ///
129 {
130  HGI_API
132 
136  uint32_t bindingIndex;
138  bool writable;
139 };
140 using HgiTextureBindDescVector = std::vector<HgiTextureBindDesc>;
141 
142 HGI_API
143 bool operator==(
144  const HgiTextureBindDesc& lhs,
145  const HgiTextureBindDesc& rhs);
146 
147 HGI_API
148 bool operator!=(
149  const HgiTextureBindDesc& lhs,
150  const HgiTextureBindDesc& rhs);
151 
152 /// \struct HgiResourceBindingsDesc
153 ///
154 /// Describes a set of resources that are bound to the GPU during encoding.
155 ///
156 /// <ul>
157 /// <li>buffers:
158 /// The buffers to be bound (E.g. uniform or shader storage).</li>
159 /// <li>textures:
160 /// The textures to be bound.</li>
161 /// </ul>
162 ///
164 {
165  HGI_API
167 
171 };
172 
173 HGI_API
174 bool operator==(
175  const HgiResourceBindingsDesc& lhs,
176  const HgiResourceBindingsDesc& rhs);
177 
178 HGI_API
179 bool operator!=(
180  const HgiResourceBindingsDesc& lhs,
181  const HgiResourceBindingsDesc& rhs);
182 
183 
184 ///
185 /// \class HgiResourceBindings
186 ///
187 /// Represents a collection of buffers, texture and vertex attributes that will
188 /// be used by an cmds object (and pipeline).
189 ///
191 {
192 public:
193  HGI_API
194  virtual ~HgiResourceBindings();
195 
196  /// The descriptor describes the object.
197  HGI_API
198  HgiResourceBindingsDesc const& GetDescriptor() const;
199 
200 protected:
201  HGI_API
203 
205 
206 private:
207  HgiResourceBindings() = delete;
208  HgiResourceBindings & operator=(const HgiResourceBindings&) = delete;
209  HgiResourceBindings(const HgiResourceBindings&) = delete;
210 };
211 
213 using HgiResourceBindingsHandleVector = std::vector<HgiResourceBindingsHandle>;
214 
215 /// \struct HgiVertexBufferBinding
216 ///
217 /// Describes a buffer to be bound during encoding.
218 ///
219 /// <ul>
220 /// <li>buffer:
221 /// The buffer to be bound (e.g. uniform, storage, vertex).</li>
222 /// <li>byteOffset:
223 /// The byte offset into the buffer from where the data will be bound.</li>
224 /// <li>index:
225 /// The binding index to which the buffer will be bound.</li>
226 /// </ul>
227 ///
229 {
230  HGI_API
232  uint32_t byteOffset,
233  uint32_t index)
234  : buffer(buffer)
235  , byteOffset(byteOffset)
236  , index(index)
237  {
238  }
239 
241  uint32_t byteOffset;
242  uint32_t index;
243 };
244 
245 using HgiVertexBufferBindingVector = std::vector<HgiVertexBufferBinding>;
246 
247 
249 
250 #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
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
std::vector< HgiTextureHandle > HgiTextureHandleVector
Definition: texture.h:207
HgiBufferBindDescVector buffers
HGI_API HgiTextureBindDesc()
std::vector< HgiVertexBufferBinding > HgiVertexBufferBindingVector
std::vector< uint32_t > sizes
Definition: core.h:760
std::vector< uint32_t > offsets
std::vector< HgiBufferHandle > HgiBufferHandleVector
Definition: buffer.h:152
HgiBindResourceType
Definition: enums.h:398
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:40
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
GLuint index
Definition: glcorearb.h:786
HgiShaderStage stageUsage
HgiBufferHandleVector buffers
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HgiBits HgiShaderStage
Definition: enums.h:370
std::vector< HgiSamplerHandle > HgiSamplerHandleVector
Definition: sampler.h:144
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()