Foundation
Loading...
Searching...
No Matches
Descriptor.hpp
Go to the documentation of this file.
1#pragma once
2#include "Common.hpp"
3namespace Foundation::RHI {
4 class RHIBuffer;
5 class RHITextureView;
6 class RHIDeviceSampler;
7 class RHIDeviceDescriptorPool;
8 class RHIDeviceDescriptorSetLayout;
9 class RHIAccelerationStructure;
13 protected:
15 public:
17 struct UpdateDesc {
18 size_t binding{ 0 }; // 0-indexed, first to update in the descriptor set
19 size_t startIndex{ 0 }; // First index in the binding array to update
21 struct Buffer {
22 RHIBuffer* buffer{ nullptr }; // Buffer to bind
23 size_t offset{ 0 }; // Offset in bytes
24 size_t size{ kFullSize }; // Size in bytes
25 };
26 Span<const Buffer> buffers; // Applies to type of UniformBuffer, StorageBuffer
27 struct Image {
28 RHITextureView* imageView{ nullptr }; // Image view to bind, can be null
29 RHIDeviceSampler* sampler{ nullptr }; // Sampler to bind, can be null
30 RHITextureLayout layout{}; // Layout of the image
31 };
32 Span<const Image> images; // Applies to type of Sampler, SampledImage
34 {
35 RHIAccelerationStructure* as{ nullptr }; // Acceleration structure to bind
36 };
37 Span<const AccelerationStructure> accelerationStructures; // Applies to type of AccelerationStructure
38 };
39 // NOTE: `desc.type` is used to determine which of the next spans is used
40 // to update the descriptors.
41 // Implementations should guarantee that descriptor type updates within
42 // a single call is homogenous, and throw if type mismatches the spans given,
43 // or some spans are unused.
44 virtual void Update(UpdateDesc const& desc) = 0;
45
46 virtual void DebugSetObjectName(const char* name) = 0;
47 };
48 // XXX: Vulkanism. Not really a thing in other APIs.
50 protected:
52 public:
53 struct PoolDesc {
54 struct Binding {
55 RHIDescriptorType type; // Type of this binding
56 uint32_t maxCount{ 1 }; // Max number of descriptors of this type that can be allocated
57 };
58 // Bindings that make up this pool
60 // Allow updating descriptors after being bound to a command buffer when
61 // they are not used
62 bool updateAfterBind{ false };
63 } const mDesc;
64 RHIDeviceDescriptorPool(RHIDevice const& device, PoolDesc const& desc)
65 : mDevice(device), mDesc(desc) {
66 }
70 virtual void DestroyDescriptorSet(Handle handle) = 0;
71
72 virtual void DebugSetObjectName(const char* name) = 0;
73 };
76 return pool->GetDescriptorSet(handle);
77 }
79 pool->DestroyDescriptorSet(handle);
80 }
81 };
82}
Definition Resource.hpp:57
Definition Descriptor.hpp:49
const RHIDevice & mDevice
Definition Descriptor.hpp:51
RHIDeviceDescriptorPool(RHIDevice const &device, PoolDesc const &desc)
Definition Descriptor.hpp:64
virtual void DestroyDescriptorSet(Handle handle)=0
virtual void DebugSetObjectName(const char *name)=0
virtual RHIDeviceDescriptorSet * GetDescriptorSet(Handle handle) const =0
struct Foundation::RHI::RHIDeviceDescriptorPool::PoolDesc mDesc
virtual RHIDeviceDescriptorPoolScopedHandle< RHIDeviceDescriptorSet > CreateDescriptorSet(RHIDeviceHandle< RHIDeviceDescriptorSetLayout >, uint32_t max_variable_count=0)=0
Definition Descriptor.hpp:12
RHIDeviceDescriptorSet(RHIDeviceDescriptorPool const &pool)
Definition Descriptor.hpp:16
const RHIDeviceDescriptorPool & mPool
Definition Descriptor.hpp:14
virtual void Update(UpdateDesc const &desc)=0
virtual void DebugSetObjectName(const char *name)=0
Definition Device.hpp:104
Definition Device.hpp:189
Handle type for RHI Objects.
Definition Details.hpp:42
Base class for all RHI objects.
Definition Details.hpp:16
Scoped move-only RAII handle wrapper for RHI Objects.
Definition Details.hpp:86
Definition Resource.hpp:211
T * Construct(Allocator *resource, Args &&...args)
Convenience placement new with object of type T using a Foundation::Core::Allocator.
Definition Allocator.hpp:149
std::span< T > Span
Alias for std::span
Definition Container.hpp:60
Low-level Rendering Hardware Interface (RHI) abstractions.
Definition Application.hpp:4
RHITextureLayout
Definition Common.hpp:148
uintptr_t Handle
Definition Details.hpp:8
RHIDescriptorType
Definition Common.hpp:183
static constexpr size_t kFullSize
Definition Common.hpp:8
RHIDescriptorType type
Definition Descriptor.hpp:55
Span< const Binding > bindings
Definition Descriptor.hpp:59
bool updateAfterBind
Definition Descriptor.hpp:62
RHIAccelerationStructure * as
Definition Descriptor.hpp:35
RHIBuffer * buffer
Definition Descriptor.hpp:22
RHITextureLayout layout
Definition Descriptor.hpp:30
RHIDeviceSampler * sampler
Definition Descriptor.hpp:29
RHITextureView * imageView
Definition Descriptor.hpp:28
size_t startIndex
Definition Descriptor.hpp:19
RHIDescriptorType type
Definition Descriptor.hpp:20
Span< const Buffer > buffers
Definition Descriptor.hpp:26
size_t binding
Definition Descriptor.hpp:18
Span< const Image > images
Definition Descriptor.hpp:32
Span< const AccelerationStructure > accelerationStructures
Definition Descriptor.hpp:37
static void Destroy(RHIDeviceDescriptorPool *pool, Handle handle)
Definition Descriptor.hpp:78
static RHIDeviceDescriptorSet * Get(RHIDeviceDescriptorPool const *pool, Handle handle)
Definition Descriptor.hpp:75
Provides type traits for types derived from RHIObject.
Definition Details.hpp:30