7#ifndef PXR_IMAGING_HDST_BINDING_H
8#define PXR_IMAGING_HDST_BINDING_H
11#include "pxr/imaging/hdSt/api.h"
12#include "pxr/imaging/hdSt/bufferResource.h"
14#include "pxr/imaging/hd/bufferArrayRange.h"
15#include "pxr/imaging/hd/types.h"
19PXR_NAMESPACE_OPEN_SCOPE
22using HdStBindingVector = std::vector<class HdStBinding>;
23using HdStBindingRequestVector = std::vector<class HdStBindingRequest>;
38 DRAW_INDEX_INSTANCE_ARRAY,
64 BINDLESS_ARRAY_OF_TEXTURE_2D,
65 BINDLESS_TEXTURE_FIELD,
67 BINDLESS_TEXTURE_UDIM_ARRAY,
68 BINDLESS_TEXTURE_UDIM_LAYOUT,
69 BINDLESS_TEXTURE_PTEX_TEXEL,
70 BINDLESS_TEXTURE_PTEX_LAYOUT,
71 BINDLESS_TEXTURE_CUBEMAP,
84 HdStBinding(Type type,
int location,
int textureUnit=0) {
85 Set(type, location, textureUnit);
87 void Set(Type type,
int location,
int textureUnit) {
88 _typeAndLocation = (textureUnit << 24)|(location << 8)|(int)(type);
90 bool IsValid()
const {
return _typeAndLocation >= 0; }
91 Type GetType()
const {
return (Type)(_typeAndLocation & 0xff); }
92 int GetLocation()
const {
return (_typeAndLocation >> 8) & 0xffff; }
93 int GetTextureUnit()
const {
return (_typeAndLocation >> 24) & 0xff; }
94 int GetValue()
const {
return _typeAndLocation; }
96 return (_typeAndLocation < b._typeAndLocation);
120 : _bindingType(bindingType)
121 , _dataType(HdTypeInvalid)
125 , _isInterleaved(false)
128 , _concatenateNames(false)
135 : _bindingType(bindingType)
136 , _dataType(dataType)
140 , _isInterleaved(false)
143 , _concatenateNames(false)
149 HdStBufferResourceSharedPtr
const& resource)
150 : _bindingType(bindingType)
151 , _dataType(resource->GetTupleType().type)
153 , _resource(resource)
155 , _isInterleaved(false)
158 , _concatenateNames(false)
167 HdBufferArrayRangeSharedPtr bar,
168 bool interleave,
bool writable =
false,
169 size_t arraySize = 0,
bool concatenateNames =
false,
170 HgiShaderStage stageVisibility = HgiShaderStageAll)
172 , _dataType(HdTypeInvalid)
176 , _isInterleaved(interleave)
177 , _isWritable(writable)
178 , _arraySize(arraySize)
179 , _concatenateNames(concatenateNames)
180 , _stageVisibility(stageVisibility)
190 return bool(_resource);
197 return _bar && !_isInterleaved;
205 return _bar && _isInterleaved;
211 return _bar && _isWritable;
217 return (!_bar) && (!_resource) && (_dataType == HdTypeInvalid);
241 if (_resource)
return _resource->
GetOffset();
250 HdBufferArrayRangeSharedPtr
const&
GetBar()
const {
267 return _concatenateNames;
272 return _stageVisibility;
297 template <
class HashState>
312 HdStBinding::Type _bindingType;
317 HdStBufferResourceSharedPtr _resource;
320 HdBufferArrayRangeSharedPtr _bar;
327 bool _concatenateNames;
329 HgiShaderStage _stageVisibility;
333PXR_NAMESPACE_CLOSE_SCOPE
virtual int GetByteOffset(TfToken const &resourceName) const =0
Returns the byte offset at which this range begins in the underlying buffer array for the given resou...
Bindings are used for buffers or textures, it simply associates a binding type with a binding locatio...
BindingRequest allows externally allocated buffers to be bound at render time.
HdStBindingRequest(HdStBinding::Type bindingType, TfToken const &name)
A data binding, not backed by neither BufferArrayRange nor BufferResource.
int GetByteOffset() const
Returns the resource or buffer array range offset, defaults to zero.
bool IsTypeless() const
This binding is typelss.
bool IsBufferArray() const
A buffer array binding has several buffers bundled together and each buffer will be bound individuall...
HgiShaderStage GetStageVisibility() const
Returns the stage visibility of the binding.
HdStBindingRequest(HdStBinding::Type bindingType, TfToken const &name, HdType dataType)
A data binding, not backed by neither BufferArrayRange nor BufferResource.
bool ConcatenateNames() const
Returns whether the struct binding point and struct member names should be concatenated when codegen'...
size_t GetArraySize() const
Array size if request is for an array of structs.
bool isWritable() const
True when the resource is being bound so that it can be written to.
HdStBufferResourceSharedPtr const & GetResource() const
Returns the single resource associated with this binding request or null when IsResource() returns fa...
bool IsInterleavedBufferArray() const
Like BufferArray binding requests, struct bindings have several buffers, however they must be allocat...
HDST_API size_t ComputeHash() const
Returns the hash corresponding to this buffer request.
HdStBinding::Type GetBindingType() const
Returns the HdStBinding type of this request.
HdStBindingRequest(HdStBinding::Type bindingType, TfToken const &name, HdStBufferResourceSharedPtr const &resource)
A buffer resource binding.
TfToken const & GetName() const
Returns the name of the binding point, if any; buffer arrays and structs need not be named.
bool IsResource() const
Resource bingings have a single associated Hydra resource, but no buffer array.
HdType GetDataType() const
Return the data type of this request.
HdBufferArrayRangeSharedPtr const & GetBar() const
Returns the buffer array range associated with this binding request or null when IsBufferArrqay() ret...
HdStBindingRequest(HdStBinding::Type type, TfToken const &name, HdBufferArrayRangeSharedPtr bar, bool interleave, bool writable=false, size_t arraySize=0, bool concatenateNames=false, HgiShaderStage stageVisibility=HgiShaderStageAll)
A named struct binding.
int GetOffset() const
Returns the interleaved offset (in bytes) of the data.
Token for efficient comparison, assignment, and hashing of known strings.