29#include <initializer_list>
33 struct GPUShaderReflectionDescriptor;
34 class GPUBufferObject;
125 class GPUResourceBinding :
public Variant<std::nullptr_t, GPUBufferResourceBinding, GPUImageResourceBinding, GPUSamplerResourceBinding> {
127 template<
typename>
friend struct std::hash;
151 [[nodiscard]]
bool isEmpty() const noexcept {
return super::is<std::nullptr_t>(); }
154 explicit operator bool() const noexcept {
return isEmpty(); }
157 [[nodiscard]]
bool isBufferBinding() const noexcept {
return super::is<GPUBufferResourceBinding>(); }
161 CE_ASSERT(super::is<GPUBufferResourceBinding>());
162 return as<GPUBufferResourceBinding>();
167 CE_ASSERT(super::is<GPUBufferResourceBinding>());
168 return as<GPUBufferResourceBinding>();
172 [[nodiscard]]
bool isImageBinding() const noexcept {
return super::is<GPUImageResourceBinding>(); }
176 CE_ASSERT(super::is<GPUImageResourceBinding>());
177 return as<GPUImageResourceBinding>();
182 CE_ASSERT(super::is<GPUImageResourceBinding>());
183 return as<GPUImageResourceBinding>();
187 [[nodiscard]]
bool isSamplerBinding() const noexcept {
return super::is<GPUSamplerResourceBinding>(); }
191 CE_ASSERT(super::is<GPUSamplerResourceBinding>());
192 return as<GPUSamplerResourceBinding>();
197 CE_ASSERT(super::is<GPUSamplerResourceBinding>());
198 return as<GPUSamplerResourceBinding>();
221 class GPUResourceSetBindings;
336 static constexpr UInt32 kGPUResourceSetBindingsSmallSize = 20u;
340 template<
typename>
friend struct std::hash;
459 template<
typename>
friend struct std::hash;
578 using super::operator[];
584 [[nodiscard]]
bool has(
const StringView name)
const {
return findSlotIndex(name) != ~0u; }
599 const UInt32 slot = findSlotIndex(name);
600 return super::get(slot, index);
610 const UInt32 slot = findSlotIndex(name);
611 return super::get(slot, index);
619 const UInt32 slot = findSlotIndex(name);
620 super::set(slot, index, std::move(binding));
631 const UInt32 slot = findSlotIndex(name);
632 super::set(slot, std::move(binding));
644 const UInt32 slot = findSlotIndex(name);
645 return super::add(slot, std::move(binding));
653 const UInt32 slot = findSlotIndex(name);
654 return super::remove(slot, index);
663 const UInt32 slot = findSlotIndex(name);
664 return super::remove(slot);
672 const UInt32 slot = findSlotIndex(name);
681 const UInt32 slot = findSlotIndex(name);
689 const UInt32 slot = findSlotIndex(name);
696 const UInt32 slot = findSlotIndex(name);
697 return super::operator[](slot);
703 const UInt32 slot = findSlotIndex(name);
704 return super::operator[](slot);
727 template<
typename Processor>
static constexpr void reflect(Processor&& RTTI) {
767template<>
struct std::hash<
CeresEngine::GPUResourceBinding> :
public std::hash<CeresEngine::GPUResourceBinding::super> {};
770template<>
struct std::hash<
CeresEngine::GPUResourceSetBindings> {
777template<>
struct std::hash<
CeresEngine::GPUShaderResourceSetBindings> :
public std::hash<CeresEngine::GPUShaderResourceSetBindings::super> {};
#define CE_REFLECT_HASH(T)
Definition Hash.hpp:89
#define CE_ASSERT(...)
Definition Macros.hpp:323
#define CE_REFL_DATA(N)
Definition Macros.hpp:541
#define CE_EXPLICIT(EXPR)
Definition Macros.hpp:413
Definition IndexedMultimap.hpp:12
void clear(const K &key)
Clears all values of the given key.
Definition IndexedMultimap.hpp:156
mapped_type & emplace_back(const K &key, Args &&... args)
Emplaces a new element for key at the end of container.
Definition IndexedMultimap.hpp:200
bool contains(const K &key, size_t index) const
Returns true if the container contains an element at index with key equivalent to key,...
Definition IndexedMultimap.hpp:104
size_type size(const K &key) const
Computes the number of elements for the given key.
Definition IndexedMultimap.hpp:172
mapped_type & at(const K &key, size_t index)
Gets the index-th value for the given key.
Definition IndexedMultimap.hpp:82
void resize(const K &key, size_type newSize, const Value &value=Value())
Resizes the container and ensures that there are exactly newSize items on the given key.
Definition IndexedMultimap.hpp:140
iterator erase(const K &key, size_type index) const
Erases the element at the given index for the given key.
Definition IndexedMultimap.hpp:180
A retain-release type of smart pointer.
Definition SmartPtr.hpp:132
Definition GPUBuffer.hpp:124
Definition GPUBufferObject.hpp:27
Definition GPUComputePipeline.hpp:62
Definition GPUGraphicsPipeline.hpp:790
Definition GPUImage.hpp:331
Definition GPUPipelineLayout.hpp:84
Definition GPUResourceSet.hpp:125
GPUBufferResourceBinding & asBufferBinding()
Gets the binding as a Buffer binding.
Definition GPUResourceSet.hpp:166
GPUSamplerResourceBinding & asSamplerBinding()
Gets the binding as an Sampler binding.
Definition GPUResourceSet.hpp:196
bool isBufferBinding() const noexcept
Determines if the binding is a Buffer binding.
Definition GPUResourceSet.hpp:157
const GPUBufferResourceBinding & asBufferBinding() const
Gets the binding as a Buffer binding.
Definition GPUResourceSet.hpp:160
const GPUSamplerResourceBinding & asSamplerBinding() const
Gets the binding as an Sampler binding.
Definition GPUResourceSet.hpp:190
bool isEmpty() const noexcept
Determines if the binding is empty.
Definition GPUResourceSet.hpp:151
GPUImageResourceBinding & asImageBinding()
Gets the binding as an Image binding.
Definition GPUResourceSet.hpp:181
Variant< std::nullptr_t, GPUBufferResourceBinding, GPUImageResourceBinding, GPUSamplerResourceBinding > super
Definition GPUResourceSet.hpp:126
bool isSamplerBinding() const noexcept
Determines if the binding is an Sampler binding.
Definition GPUResourceSet.hpp:187
friend bool operator!=(const GPUResourceBinding &lhs, const std::nullptr_t rhs) noexcept
Definition GPUResourceSet.hpp:203
friend bool operator==(const GPUResourceBinding &lhs, std::nullptr_t) noexcept
Definition GPUResourceSet.hpp:202
bool isImageBinding() const noexcept
Determines if the binding is an Image binding.
Definition GPUResourceSet.hpp:172
const GPUImageResourceBinding & asImageBinding() const
Gets the binding as an Image binding.
Definition GPUResourceSet.hpp:175
Definition GPUResourceSet.hpp:338
GPUResourceBinding * get(const UInt32 slot, const UInt32 index=0)
Gets a GPUResourceBinding by it's reflection slot and index.
Definition GPUResourceSet.hpp:372
Generator< Pair< Pair< UInt32, UInt32 >, GPUResourceBinding & > > forEach()
Iterates over each of the entries in the GPUResourceSetBindings.
void clear(const K &key)
Clears all values of the given key.
Definition IndexedMultimap.hpp:156
void remove(UInt32 slot)
Removes a GPUResourceBinding for the given binding slot.
Definition GPUResourceSet.hpp:420
GPUResourceBinding & set(UInt32 slot, GPUResourceBinding binding)
Sets the GPUResourceBinding for the given binding slot and index.
Definition GPUResourceSet.hpp:387
void remove(const UInt32 slot, const UInt32 index)
Removes a GPUResourceBinding for the given binding slot and index.
Definition GPUResourceSet.hpp:409
GPUResourceSetConstBindingSlot operator[](UInt32 slot) const
Helper method to have expressive access of the resource bindings.
Definition GPUResourceSet.hpp:438
GPUResourceSetBindings()=default
GPUResourceSetDescriptor createDescriptor() const &
UInt32 add(const UInt32 slot, GPUResourceBinding binding)
Adds a new GPUResourceBinding for the given binding slot.
Definition GPUResourceSet.hpp:400
const GPUResourceBinding * get(const UInt32 slot, const UInt32 index=0) const
Gets a GPUResourceBinding by it's reflection slot and index.
Definition GPUResourceSet.hpp:359
UInt32 size() const
Gets the total number of GPUResourceBinding on the bindings object.
Definition GPUResourceSet.hpp:430
void reserve(size_type newCapacity)
Tries to increase capacity by allocating additional memory.
Definition IndexedMultimap.hpp:120
GPUResourceSetBindingSlot operator[](UInt32 slot)
Helper method to have expressive access of the resource bindings.
Definition GPUResourceSet.hpp:434
GPUResourceBinding & set(const UInt32 slot, const UInt32 index, GPUResourceBinding binding)
Sets the GPUResourceBinding for the given binding slot and index.
Definition GPUResourceSet.hpp:378
void resize(const K &key, size_type newSize, const Value &value=Value())
Resizes the container and ensures that there are exactly newSize items on the given key.
Definition IndexedMultimap.hpp:140
UInt32 size(const UInt32 slot) const
Gets the number of GPUResourceBinding by on the given slot.
Definition GPUResourceSet.hpp:426
Generator< Pair< Pair< UInt32, UInt32 >, const GPUResourceBinding & > > forEach() const
Iterates over each of the entries in the GPUResourceSetBindings.
A RenderAPI object that holds a set of resources that can be bound into shader.
Definition GPUResourceSet.hpp:735
GPUPipelineLayout & pipelineLayout
The owning pipeline layout object this ResourceSet was created from.
Definition GPUResourceSet.hpp:738
GPUResourceSet(GPUPipelineLayout &pipelineLayout, const GPUResourceSetDescriptor &descriptor)
Default initializer.
GPUResourceSet(const GPUResourceSet &)=delete
Deleted copy constructor.
GPUResourceSet & operator=(const GPUResourceSet &)=delete
~GPUResourceSet() override
Destroys the resource set object.
GPUResourceSet(GPUResourceSet &&)=delete
Deleted move constructor.
GPUResourceSet & operator=(GPUResourceSet &&)=delete
Definition GPUSampler.hpp:175
Definition GPUShader.hpp:256
Definition GPUShader.hpp:361
Definition GPUResourceSet.hpp:457
GPUShaderResourceSetBindings(const GPUShaderPtr &shader, const UInt32 setIndex=0)
Constructs a new GPUShaderResourceSetBindings suitable a given GPUShader.
Definition GPUResourceSet.hpp:476
GPUShaderResourceSetBindings(const GPUShader &shader, UInt32 setIndex=0)
Constructs a new GPUShaderResourceSetBindings suitable a given GPUShader.
GPUShaderResourceSetBindings(const GPUGraphicsPipelinePtr &pipeline, const UInt32 setIndex=0)
Constructs a new GPUShaderResourceSetBindings suitable a given GPUGraphicsPipeline.
Definition GPUResourceSet.hpp:493
GPUShaderResourceSetBindings(const GPUGraphicsPipeline &pipeline, UInt32 setIndex=0)
Constructs a new GPUShaderResourceSetBindings suitable a given GPUGraphicsPipeline.
GPUShaderResourceSetBindings(const GPUResourceSetBindings &existingBindings, const GPUShaderProgram &shaderProgram, UInt32 setIndex=0)
Constructs a new GPUShaderResourceSetBindings suitable a given GPUShaderProgram.
UInt32 findSlotIndex(StringView name) const
Finds the binding named name using reflection data.
GPUShaderResourceSetBindings(const GPUResourceSetBindings &existingBindings, const GPUGraphicsPipeline &pipeline, UInt32 setIndex=0)
Constructs a new GPUShaderResourceSetBindings suitable a given GPUGraphicsPipeline.
const GPUResourceBinding * get(const StringView name, const UInt32 index=0) const
Gets a GPUResourceBinding by it's reflection name and index.
Definition GPUResourceSet.hpp:598
void resize(const StringView name, const UInt32 newSize, const GPUResourceBinding &defaultValue={})
Resizes the bindings a for the given binding slot name.
Definition GPUResourceSet.hpp:680
GPUShaderResourceSetBindings(const GPUResourceSetBindings &existingBindings, const GPUComputePipeline &pipeline, UInt32 setIndex=0)
Constructs a new GPUShaderResourceSetBindings suitable a given GPUComputePipeline.
GPUShaderResourceSetBindings(const GPUComputePipelinePtr &pipeline, const UInt32 setIndex=0)
Constructs a new GPUShaderResourceSetBindings suitable a given GPUComputePipeline.
Definition GPUResourceSet.hpp:502
GPUShaderResourceSetBindings(const GPUPipelineLayout &pipeline, UInt32 setIndex=0)
Constructs a new GPUShaderResourceSetBindings suitable a given GPUGraphicsPipeline.
UInt32 size(const StringView name) const
Gets the number of GPUResourceBinding by on the given slot.
Definition GPUResourceSet.hpp:671
GPUShaderResourceSetBindings(const GPUResourceSetBindings &existingBindings, const GPUComputePipelinePtr &pipeline, const UInt32 setIndex=0)
Constructs a new GPUShaderResourceSetBindings suitable a given GPUComputePipeline.
Definition GPUResourceSet.hpp:567
GPUShaderResourceSetBindings(const GPUShaderProgram &shaderProgram, UInt32 setIndex=0)
Constructs a new GPUShaderResourceSetBindings suitable a given GPUShaderProgram.
GPUShaderResourceSetBindings(const GPUPipelineLayoutPtr &pipelineLayout, const UInt32 setIndex=0)
Constructs a new GPUShaderResourceSetBindings suitable a given GPUGraphicsPipeline.
Definition GPUResourceSet.hpp:510
GPUShaderResourceSetBindings(const GPUResourceSetBindings &existingBindings, const GPUGraphicsPipelinePtr &pipeline, const UInt32 setIndex=0)
Constructs a new GPUShaderResourceSetBindings suitable a given GPUGraphicsPipeline.
Definition GPUResourceSet.hpp:553
GPUShaderResourceSetBindings(const GPUComputePipeline &pipeline, UInt32 setIndex=0)
Constructs a new GPUShaderResourceSetBindings suitable a given GPUComputePipeline.
GPUShaderResourceSetBindings(const GPUResourceSetBindings &existingBindings, const GPUShaderPtr &shader, const UInt32 setIndex=0)
Constructs a new GPUShaderResourceSetBindings suitable a given GPUShader.
Definition GPUResourceSet.hpp:525
UInt32 add(const StringView name, GPUResourceBinding binding)
Adds a new GPUResourceBinding for the given binding name.
Definition GPUResourceSet.hpp:643
bool has(UInt32 slot) const
Determines if a binding with the given slot exists on the reflection metadata.
void set(const StringView name, const UInt32 index, GPUResourceBinding binding)
Sets the GPUResourceBinding for the given binding name and index.
Definition GPUResourceSet.hpp:618
bool has(const StringView name) const
Determines if a binding with the given name exists on the reflection metadata.
Definition GPUResourceSet.hpp:584
GPUShaderResourceSetBindings(const GPUResourceSetBindings &existingBindings, const GPUShader &shader, UInt32 setIndex=0)
Constructs a new GPUShaderResourceSetBindings suitable a given GPUShader.
GPUShaderResourceSetBindings(const GPUResourceSetBindings &existingBindings, const GPUShaderProgramPtr &shaderProgram, const UInt32 setIndex=0)
Constructs a new GPUShaderResourceSetBindings suitable a given GPUShaderProgram.
Definition GPUResourceSet.hpp:539
void clear(const StringView name)
Clears all the bindings a for the given binding slot name.
Definition GPUResourceSet.hpp:688
void set(const StringView name, GPUResourceBinding binding)
Sets the GPUResourceBinding for the given binding name and index.
Definition GPUResourceSet.hpp:630
GPUResourceBinding * get(const StringView name, const UInt32 index=0)
Gets a GPUResourceBinding by it's reflection name and index.
Definition GPUResourceSet.hpp:609
auto operator[](const StringView name)
Helper method to have expressive access of the resource bindings.
Definition GPUResourceSet.hpp:695
void remove(const StringView name, const UInt32 index)
Removes a GPUResourceBinding for the given binding slot and index.
Definition GPUResourceSet.hpp:652
const GPUShaderReflectionDescriptor & mReflectionDescriptor
A descriptor that describes the reflection data from the shader.
Definition GPUResourceSet.hpp:463
void remove(const StringView name)
Removes a GPUResourceBinding for the given binding slot.
Definition GPUResourceSet.hpp:662
auto operator[](const StringView name) const
Helper method to have expressive access of the resource bindings.
Definition GPUResourceSet.hpp:702
GPUShaderResourceSetBindings(const GPUShaderProgramPtr &shaderProgram, const UInt32 setIndex=0)
Constructs a new GPUShaderResourceSetBindings suitable a given GPUShaderProgram.
Definition GPUResourceSet.hpp:484
A generator represents a coroutine type that produces a sequence of values of type T,...
Definition Generator.hpp:50
A class that offers high-level access to a GPUResourceSetBindings slot.
Definition GPUResourceSet.hpp:224
UInt32 slot
The slot the TGPUResourceSetBindingSlot object is representing.
Definition GPUResourceSet.hpp:234
void remove(UInt32 index)
Removes a GPUResourceBinding for the given index.
Definition GPUResourceSet.hpp:316
GPUResourceBinding & set(GPUResourceBinding binding)
Sets the GPUResourceBinding for the given index.
Definition GPUResourceSet.hpp:270
std::conditional_t< Const, const GPUResourceSetBindings, GPUResourceSetBindings > GPUResourceSetBindingsType
Definition GPUResourceSet.hpp:225
const GPUResourceBinding * get(UInt32 index=0) const
Gets a GPUResourceBinding at the given index.
Definition GPUResourceSet.hpp:249
TGPUResourceSetBindingSlot & operator=(GPUResourceBinding &&binding)
Sets the GPUResourceBinding for the given index.
Definition GPUResourceSet.hpp:289
const GPUResourceBinding & operator[](const UInt32 index) const
Gets a GPUResourceBinding at the given index.
Definition GPUResourceSet.hpp:273
GPUResourceBinding & operator[](const UInt32 index)
Gets a GPUResourceBinding at the given index.
Definition GPUResourceSet.hpp:280
TGPUResourceSetBindingSlot(GPUResourceSetBindingsType &bindings, const UInt32 slot)
Creates a new TGPUResourceSetBindingSlot from an existing.
Definition GPUResourceSet.hpp:241
GPUResourceBinding * get(UInt32 index=0)
Gets a GPUResourceBinding at the given index.
Definition GPUResourceSet.hpp:256
GPUResourceSetBindingsType & bindings
The bindings object that this TGPUResourceSetBindingSlot was created from.
Definition GPUResourceSet.hpp:231
UInt32 add(GPUResourceBinding binding)
Adds a new GPUResourceBinding.
Definition GPUResourceSet.hpp:302
GPUResourceBinding & set(UInt32 index, GPUResourceBinding binding)
Sets the GPUResourceBinding for the given index.
Definition GPUResourceSet.hpp:262
UInt32 operator+=(GPUResourceBinding binding)
Adds a new GPUResourceBinding.
Definition GPUResourceSet.hpp:308
void remove()
Removes a GPUResourceBinding for the slot.
Definition GPUResourceSet.hpp:321
UInt32 size() const
Gets the number of GPUResourceBinding bound on the slot.
Definition GPUResourceSet.hpp:325
Definition Variant.hpp:15
Definition Application.hpp:19
GPUResourceBindingType
An enumeration of supported resource binding types.
Definition GPUResourceSet.hpp:37
@ Undefined
We don't care about the previous content of the respective render target attachment.
std::initializer_list< T > InitializerList
An object of type InitializerList<T> is a lightweight proxy object that provides access to an array o...
Definition InitializerList.hpp:40
std::pair< First, Second > Pair
Pair is a struct template that provides a way to store two heterogeneous objects as a single unit.
Definition Pair.hpp:18
auto move(Vector3 position)
Moves a entity to the given position.
Definition Helpers.hpp:22
@ StorageBuffer
Storage buffer resource.
@ Sampler
Sampler state resource.
@ CombinedSampler
Combined sampler with a associated image.
@ UniformBuffer
Uniform buffer (or constant buffer) resource.
@ DynamicUniformBuffer
Dynamic uniform buffer (or constant buffer) resource.
@ StorageImage
Storage image resource type.
std::uint32_t UInt32
Definition DataTypes.hpp:23
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Definition GPUResourceSet.hpp:65
static constexpr void reflect(Processor &&RTTI)
Executes the given processor for every field of the struct.
Definition GPUResourceSet.hpp:76
GPUBufferViewDescriptor bufferView
A descriptor that describes the region of the buffer to be bound.
Definition GPUResourceSet.hpp:71
GPUBufferPtr buffer
A pointer to the resource resource to be bound.
Definition GPUResourceSet.hpp:67
Definition GPUBuffer.hpp:230
Definition GPUResourceSet.hpp:82
GPUImagePtr image
A pointer to the resource resource to be bound.
Definition GPUResourceSet.hpp:84
GPUImageViewDescriptor imageView
A descriptor that describes the region of the image to be bound.
Definition GPUResourceSet.hpp:93
static constexpr void reflect(Processor &&RTTI)
Executes the given processor for every field of the struct.
Definition GPUResourceSet.hpp:104
GPUSamplerPtr sampler
An optional sampler to be used when sampling from the image on the shader.
Definition GPUResourceSet.hpp:89
Image view descriptor structure.
Definition GPUImage.hpp:482
GPUImageType type
Hardware image type. By default ImageType::Image2D.
Definition GPUImage.hpp:485
Definition GPUResourceSet.hpp:716
GPUResourceSetBindings bindings
The resource set bindings.
Definition GPUResourceSet.hpp:718
String name
A user-facing name for the ResourceSet.
Definition GPUResourceSet.hpp:722
static constexpr void reflect(Processor &&RTTI)
Executes the given processor for every field of the struct.
Definition GPUResourceSet.hpp:727
Definition GPUResourceSet.hpp:111
static constexpr void reflect(Processor &&RTTI)
Executes the given processor for every field of the struct.
Definition GPUResourceSet.hpp:120
GPUSamplerPtr sampler
A sampler to be used when sampling from the sampler on the shader.
Definition GPUResourceSet.hpp:115
Shader reflection descriptor structure.
Definition GPUShader.hpp:108