Foundation
Loading...
Searching...
No Matches
Device.hpp
Go to the documentation of this file.
1#pragma once
2#include "Command.hpp"
3#include "Descriptor.hpp"
4#include "PipelineState.hpp"
5#include "Resource.hpp"
6#include "Shader.hpp"
7#include "Swapchain.hpp"
8
9namespace Foundation::RHI
10{
11 class RHIApplication;
12 class RHIDevice;
13 class RHIDeviceSemaphore;
14 class RHIDeviceFence;
16 {
17 protected:
19
20 public:
21 RHIDeviceQueue(RHIDevice const& device) : mDevice(device) {}
22
23 virtual void WaitIdle() const = 0;
26 {
27 // Semaphore(s) and the minimum values to wait on
29 // Semaphore(s) and the values to signal
31 // Binary semaphore(s) to wait when the command lists are done
33 // Stages the semaphore waits occur in [timeline_waits..., waits...]
35 // Binary semaphore(s) to signal when the command lists are done
37 // Command lists to submit
39 };
40 virtual void Submit(Span<const SubmitDesc> desc, RHIDeviceFence* completionFence = nullptr) const = 0;
41
49 virtual void Present(PresentDesc const& desc) const = 0;
50 [[nodiscard]] virtual uint32_t GetVkQueueFamily() const = 0;
51 virtual void DebugSetObjectName(const char* name) = 0;
52 };
53 // https://docs.vulkan.org/samples/latest/samples/extensions/timeline_semaphore/README.html
55 {
56 protected:
58
59 public:
60 const bool mIsTimeline;
62
63 virtual void DebugSetObjectName(const char* name) = 0;
64 };
66 {
67 protected:
69
70 public:
71 RHIDeviceFence(RHIDevice const& device) : mDevice(device) {}
72
73 virtual void DebugSetObjectName(const char* name) = 0;
74 };
76 {
77 struct Binding
78 {
79 uint32_t count{1}; // Array size for array access
80 RHIShaderStage stage{RHIShaderStageBits::All}; // Stage this binding is used in
81 RHIDescriptorType type; // Type of this binding
82 };
83 // Bindings that make up this layout
85 // Allow updating descriptors after being bound to a command buffer when
86 // they are not used
87 bool updateAfterBind{false};
88 };
90 {
91 protected:
93
94 public:
97 mDevice(device), mDesc(desc)
98 {
99 }
100
101 virtual void DebugSetObjectName(const char* name) = 0;
102 };
104 {
105 protected:
107
108 public:
110 {
112 {
113 bool enable{false}; // Enable anisotropic filtering
114 float maxLevel{16.0f}; // Max anisotropy level
117 {
126 v{Repeat}, w{Repeat}; // Address modes for U, V, W coordinates
128 struct Mipmap
129 {
131 {
133 Nearest
134 } mipmapMode{Linear}; // Mipmap mode;
135 float bias{0.0f}; // Mipmap LOD bias
137 struct Filter
138 {
145 magFilter{Linear}; // Minification and magnification filters
147 struct LOD
148 {
149 float min{0.0f}; // Minimum level of detail
150 float max{16.0f}; // Maximum level of detail
151 } lod; // Level of detail settings;
158 } const mDesc;
159 RHIDeviceSampler(RHIDevice const& device, SamplerDesc const& desc) : mDevice(device), mDesc(desc) {}
160
161 virtual void DebugSetObjectName(const char* name) = 0;
162 };
164 {
165 protected:
167
168 public:
178 RHIDeviceQueryPool(RHIDevice const& device, QueryPoolDesc const& desc) : mDevice(device), mDesc(desc) {}
179
180 // NOTE: In nanoseconds
181 virtual const float GetTimestampResolution() = 0;
182
183 virtual void Reset() = 0;
184
185 virtual Span<const uint64_t> GetResults(bool wait = true) = 0;
186 virtual void DebugSetObjectName(const char* name) = 0;
187 };
188 class RHIDevice : public RHIObject
189 {
190 protected:
192
193 public:
195 {
196 uint32_t id = 0;
197 const char* name = nullptr;
198 };
200
205 [[nodiscard]] virtual RHISwapchain* GetSwapchain(Handle handle) const = 0;
206 virtual void DestroySwapchain(Handle handle) = 0;
207
211 virtual void DestroyPipelineCache(Handle handle) = 0;
212
215 [[nodiscard]] virtual RHIPipelineState* GetPipelineState(Handle handle) const = 0;
216 virtual void DestroyPipelineState(Handle handle) = 0;
217
220 [[nodiscard]] virtual RHIShaderModule* GetShaderModule(Handle handle) const = 0;
221 virtual void DestroyShaderModule(Handle handle) = 0;
222
225 [[nodiscard]] virtual RHICommandPool* GetCommandPool(Handle handle) const = 0;
226 virtual void DestroyCommandPool(Handle handle) = 0;
227
229
231 [[nodiscard]] virtual RHIDeviceSemaphore* GetSemaphore(Handle handle) const = 0;
232 virtual void DestroySemaphore(Handle handle) = 0;
233
235 [[nodiscard]] virtual RHIDeviceFence* GetFence(Handle handle) const = 0;
236 virtual void DestroyFence(Handle handle) = 0;
237
239 [[nodiscard]] virtual RHIBuffer* GetBuffer(Handle handle) const = 0;
240 virtual void DestroyBuffer(Handle handle) = 0;
241
243 [[nodiscard]] virtual RHITexture* GetTexture(Handle handle) const = 0;
244 virtual void DestroyTexture(Handle handle) = 0;
245
249 virtual void DestroyAccelerationStructure(Handle handle) = 0;
250
254 virtual void DestroyDescriptorSetLayout(Handle handle) = 0;
255
259 virtual void DestroyDescriptorPool(Handle handle) = 0;
260
263 [[nodiscard]] virtual RHIDeviceSampler* GetSampler(Handle handle) const = 0;
264 virtual void DestroySampler(Handle handle) = 0;
265
268 [[nodiscard]] virtual RHIDeviceQueryPool* GetQueryPool(Handle handle) const = 0;
269 virtual void DestroyQueryPool(Handle handle) = 0;
270
277 [[nodiscard]] virtual size_t
279 void* dest) const = 0;
280
289
297 size_t timeout) = 0;
298
299 virtual void WaitIdle() const = 0;
300
301 virtual void QueryBudget(size_t& used, size_t& budget) const = 0;
302 virtual String QueryDeviceString() const = 0;
303
304 virtual void DebugSetObjectName(const char* name) = 0;
305 };
310 {
311 RHIDevice const* mDevice{nullptr};
313 RHIDeviceIdleGuard(RHIDevice const* device) : mDevice(device) {};
314 void WaitIdle() const
315 {
316 if (mDevice)
317 mDevice->WaitIdle();
318 }
320 };
321
322 template <>
324 {
325 static RHISwapchain* Get(RHIDevice const* device, Handle handle) { return device->GetSwapchain(handle); }
326 static void Destroy(RHIDevice* device, Handle handle) { device->DestroySwapchain(handle); }
327 };
328 template <>
330 {
331 static RHIPipelineState* Get(RHIDevice const* device, Handle handle)
332 {
333 return device->GetPipelineState(handle);
334 }
335 static void Destroy(RHIDevice* device, Handle handle) { device->DestroyPipelineState(handle); }
336 };
337 template <>
339 {
340 static RHIShaderModule* Get(RHIDevice const* device, Handle handle) { return device->GetShaderModule(handle); }
341 static void Destroy(RHIDevice* device, Handle handle) { device->DestroyShaderModule(handle); }
342 };
343 template <>
345 {
346 static RHICommandPool* Get(RHIDevice const* device, Handle handle) { return device->GetCommandPool(handle); }
347 static void Destroy(RHIDevice* device, Handle handle) { device->DestroyCommandPool(handle); }
348 };
349 template <>
351 {
352 static RHIDeviceSemaphore* Get(RHIDevice const* device, Handle handle) { return device->GetSemaphore(handle); }
353 static void Destroy(RHIDevice* device, Handle handle) { device->DestroySemaphore(handle); }
354 };
355 template <>
357 {
358 static RHIDeviceFence* Get(RHIDevice const* device, Handle handle) { return device->GetFence(handle); }
359 static void Destroy(RHIDevice* device, Handle handle) { device->DestroyFence(handle); }
360 };
361 template <>
363 {
364 static RHIBuffer* Get(RHIDevice const* device, Handle handle) { return device->GetBuffer(handle); }
365 static void Destroy(RHIDevice* device, Handle handle) { device->DestroyBuffer(handle); }
366 };
367 template <>
369 {
370 static RHITexture* Get(RHIDevice const* device, Handle handle) { return device->GetTexture(handle); }
371 static void Destroy(RHIDevice* device, Handle handle) { device->DestroyTexture(handle); }
372 };
373 template <>
375 {
376 static RHIDeviceDescriptorSetLayout* Get(RHIDevice const* device, Handle handle)
377 {
378 return device->GetDescriptorSetLayout(handle);
379 }
380 static void Destroy(RHIDevice* device, Handle handle) { device->DestroyDescriptorSetLayout(handle); }
381 };
382 template <>
384 {
385 static RHIDeviceDescriptorPool* Get(RHIDevice const* device, Handle handle)
386 {
387 return device->GetDescriptorPool(handle);
388 }
389 static void Destroy(RHIDevice* device, Handle handle) { device->DestroyDescriptorPool(handle); }
390 };
391 template <>
393 {
394 static RHIDeviceSampler* Get(RHIDevice const* device, Handle handle) { return device->GetSampler(handle); }
395 static void Destroy(RHIDevice* device, Handle handle) { device->DestroySampler(handle); }
396 };
397 template <>
399 {
400 static RHIPipelineStateCache* Get(RHIDevice const* device, Handle handle)
401 {
402 return device->GetPipelineCache(handle);
403 }
404 static void Destroy(RHIDevice* device, Handle handle) { device->DestroyPipelineCache(handle); }
405 };
406 template <>
408 {
409 static RHIDeviceQueryPool* Get(RHIDevice const* device, Handle handle) { return device->GetQueryPool(handle); }
410 static void Destroy(RHIDevice* device, Handle handle) { device->DestroyQueryPool(handle); }
411 };
412 template <>
414 {
415 static RHIAccelerationStructure* Get(RHIDevice const* device, Handle handle)
416 {
417 return device->GetAccelerationStructure(handle);
418 }
419 static void Destroy(RHIDevice* device, Handle handle) { device->DestroyAccelerationStructure(handle); }
420 };
421} // namespace Foundation::RHI
The root object of everything RHI. Implementation of this class inherently defines the RHI backend.
Definition Application.hpp:11
Definition Resource.hpp:57
Definition Command.hpp:18
Definition Descriptor.hpp:49
const RHIDeviceDescriptorSetLayoutDesc mDesc
Definition Device.hpp:95
RHIDeviceDescriptorSetLayout(RHIDevice const &device, RHIDeviceDescriptorSetLayoutDesc const &desc)
Definition Device.hpp:96
const RHIDevice & mDevice
Definition Device.hpp:92
virtual void DebugSetObjectName(const char *name)=0
Definition Device.hpp:66
const RHIDevice & mDevice
Definition Device.hpp:68
RHIDeviceFence(RHIDevice const &device)
Definition Device.hpp:71
virtual void DebugSetObjectName(const char *name)=0
Definition Device.hpp:164
virtual Span< const uint64_t > GetResults(bool wait=true)=0
struct Foundation::RHI::RHIDeviceQueryPool::QueryPoolDesc mDesc
virtual const float GetTimestampResolution()=0
const RHIDevice & mDevice
Definition Device.hpp:166
virtual void DebugSetObjectName(const char *name)=0
RHIDeviceQueryPool(RHIDevice const &device, QueryPoolDesc const &desc)
Definition Device.hpp:178
Definition Device.hpp:16
RHIDeviceQueue(RHIDevice const &device)
Definition Device.hpp:21
virtual void Submit(Span< const SubmitDesc > desc, RHIDeviceFence *completionFence=nullptr) const =0
virtual void DebugSetObjectName(const char *name)=0
Pair< RHIDeviceSemaphore *, size_t > TimelinePair
Definition Device.hpp:24
virtual uint32_t GetVkQueueFamily() const =0
virtual void WaitIdle() const =0
virtual void Present(PresentDesc const &desc) const =0
const RHIDevice & mDevice
Definition Device.hpp:18
Definition Device.hpp:104
struct Foundation::RHI::RHIDeviceSampler::SamplerDesc mDesc
const RHIDevice & mDevice
Definition Device.hpp:106
RHIDeviceSampler(RHIDevice const &device, SamplerDesc const &desc)
Definition Device.hpp:159
virtual void DebugSetObjectName(const char *name)=0
Definition Device.hpp:55
RHIDeviceSemaphore(RHIDevice const &device, bool is_timeline)
Definition Device.hpp:61
const RHIDevice & mDevice
Definition Device.hpp:57
const bool mIsTimeline
Definition Device.hpp:60
virtual void DebugSetObjectName(const char *name)=0
Definition Device.hpp:189
virtual RHIBuffer * GetBuffer(Handle handle) const =0
virtual RHIDeviceScopedHandle< RHIPipelineState > CreatePipelineState(RHIPipelineState::PipelineStateDesc const &desc)=0
virtual void DestroyAccelerationStructure(Handle handle)=0
virtual RHIDeviceScopedHandle< RHIBuffer > CreateBuffer(RHIBufferDesc const &desc)=0
virtual RHIDeviceDescriptorPool * GetDescriptorPool(Handle handle) const =0
virtual void DestroyQueryPool(Handle handle)=0
virtual RHIDeviceSampler * GetSampler(Handle handle) const =0
virtual RHIPipelineState * GetPipelineState(Handle handle) const =0
virtual bool WaitForTimelineSemaphores(Span< const Pair< RHIDeviceSemaphore *, size_t > > semaphores, size_t timeout)=0
Wait for timeline semaphores to reach specified values.
virtual String QueryDeviceString() const =0
virtual RHIDeviceScopedHandle< RHICommandPool > CreateCommandPool(RHICommandPool::PoolDesc type)=0
virtual Span< RHISwapchainPresentMode const > GetSwapchainSupportedPresentModes() const =0
virtual bool WaitForFences(Span< RHIDeviceFence *const > fences, bool wait_all, size_t timeout)=0
Wait for fences to arrive.
virtual RHIDeviceFence * GetFence(Handle handle) const =0
virtual RHISwapchain * GetSwapchain(Handle handle) const =0
virtual RHIDeviceScopedHandle< RHIShaderModule > CreateShaderModule(RHIShaderModule::ShaderModuleDesc const &desc)=0
virtual void DestroyDescriptorPool(Handle handle)=0
virtual RHIPipelineStateCache * GetPipelineCache(Handle handle) const =0
virtual void DestroyPipelineState(Handle handle)=0
const RHIApplication & mApp
Definition Device.hpp:191
virtual RHITexture * GetTexture(Handle handle) const =0
virtual Span< RHIResourceFormat const > GetSwapchainSupportedFormats() const =0
virtual RHIDeviceScopedHandle< RHIDeviceDescriptorSetLayout > CreateDescriptorSetLayout(RHIDeviceDescriptorSetLayoutDesc const &desc)=0
virtual void DestroyShaderModule(Handle handle)=0
virtual void DestroyTexture(Handle handle)=0
virtual RHIDeviceScopedHandle< RHIAccelerationStructure > CreateAccelerationStructure(RHIAccelerationStructureDesc const &desc)=0
virtual RHIAccelerationStructure * GetAccelerationStructure(Handle handle) const =0
virtual RHIDeviceScopedHandle< RHITexture > CreateTexture(RHITextureDesc const &desc)=0
virtual void DestroySemaphore(Handle handle)=0
virtual void DebugSetObjectName(const char *name)=0
virtual void ResetFences(Span< RHIDeviceFence *const > fences)=0
virtual void DestroyPipelineCache(Handle handle)=0
virtual void DestroySampler(Handle handle)=0
virtual void WaitIdle() const =0
virtual RHIDeviceScopedHandle< RHIDeviceSampler > CreateSampler(RHIDeviceSampler::SamplerDesc const &desc)=0
virtual size_t WriteAccelerationStructureInstanceData(RHIAccelerationStructureGeometryInstance const &data, void *dest) const =0
virtual RHIDeviceScopedHandle< RHIPipelineStateCache > CreatePipelineCache(RHIPipelineStateCache::PipelineStateCacheDesc const &desc)=0
virtual RHIDeviceScopedHandle< RHIDeviceDescriptorPool > CreateDescriptorPool(RHIDeviceDescriptorPool::PoolDesc const &desc)=0
virtual RHIDeviceQueryPool * GetQueryPool(Handle handle) const =0
virtual RHIDeviceSemaphore * GetSemaphore(Handle handle) const =0
virtual RHIDeviceScopedHandle< RHIDeviceFence > CreateFence(bool signaled=true)=0
virtual RHIShaderModule * GetShaderModule(Handle handle) const =0
virtual void QueryBudget(size_t &used, size_t &budget) const =0
virtual RHIDeviceScopedHandle< RHIDeviceQueryPool > CreateQueryPool(RHIDeviceQueryPool::QueryPoolDesc const &desc)=0
virtual void SignalTimelineSemaphores(Span< const Pair< RHIDeviceSemaphore *, size_t > > semaphores)=0
virtual void DestroyBuffer(Handle handle)=0
virtual void DestroyFence(Handle handle)=0
virtual RHICommandPool * GetCommandPool(Handle handle) const =0
virtual void DestroyDescriptorSetLayout(Handle handle)=0
virtual void DestroySwapchain(Handle handle)=0
virtual RHIDeviceDescriptorSetLayout * GetDescriptorSetLayout(Handle handle) const =0
virtual RHIDeviceQueue * GetDeviceQueue(RHIDeviceQueueType type) const =0
virtual RHIDeviceScopedHandle< RHISwapchain > CreateSwapchain(RHISwapchain::SwapchainDesc const &desc)=0
virtual RHIDeviceScopedHandle< RHIDeviceSemaphore > CreateSemaphore(bool is_timeline=false)=0
virtual void DestroyCommandPool(Handle handle)=0
virtual RHIAccelerationStructureSizeInfo GetAccelerationStructureSizeInfo(RHIAccelerationStructureBuildDesc const &desc) const =0
RHIDevice(RHIApplication const &app)
Definition Device.hpp:199
Base class for all RHI objects.
Definition Details.hpp:16
Definition PipelineState.hpp:8
Definition PipelineState.hpp:22
Scoped move-only RAII handle wrapper for RHI Objects.
Definition Details.hpp:86
Definition Shader.hpp:5
Definition Swapchain.hpp:19
Definition Resource.hpp:190
std::basic_string< char > String
Alias for std::basic_string<char>, without an explicit allocator constructor.
Definition Container.hpp:112
std::pair< First, Second > Pair
Alias for std::pair
Definition Container.hpp:32
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
uintptr_t Handle
Definition Details.hpp:8
RHIDeviceQueueType
Definition Common.hpp:109
RHIDescriptorType
Definition Common.hpp:183
Definition Resource.hpp:28
RHIDescriptorType type
Definition Device.hpp:81
RHIShaderStage stage
Definition Device.hpp:80
Span< const Binding > bindings
Definition Device.hpp:84
bool updateAfterBind
Definition Device.hpp:87
RAII guard to wait for device idle on destruction.
Definition Device.hpp:310
~RHIDeviceIdleGuard()
Definition Device.hpp:319
void WaitIdle() const
Definition Device.hpp:314
RHIDeviceIdleGuard(RHIDevice const *device)
Definition Device.hpp:313
RHIDevice const * mDevice
Definition Device.hpp:311
uint32_t count
Definition Device.hpp:176
@ AccelerationStructureCompactedSize
Definition Device.hpp:174
enum Foundation::RHI::RHIDeviceQueryPool::QueryPoolDesc::QueryType type
RHISwapchain * swapchain
Definition Device.hpp:45
Span< RHIDeviceSemaphore *const > waits
Definition Device.hpp:47
uint32_t imageIndex
Definition Device.hpp:44
Span< RHICommandList *const > cmdLists
Definition Device.hpp:38
Span< RHIDeviceSemaphore *const > signals
Definition Device.hpp:36
Span< const TimelinePair > timelineSignals
Definition Device.hpp:30
Span< RHIDeviceSemaphore *const > waits
Definition Device.hpp:32
Span< const TimelinePair > timelineWaits
Definition Device.hpp:28
Span< const RHIPipelineStage > waitsStages
Definition Device.hpp:34
enum Foundation::RHI::RHIDeviceSampler::SamplerDesc::AddressMode::Mode Repeat
enum Foundation::RHI::RHIDeviceSampler::SamplerDesc::Filter::Type Linear
enum Foundation::RHI::RHIDeviceSampler::SamplerDesc::Mipmap::MipmapMode Linear
struct Foundation::RHI::RHIDeviceSampler::SamplerDesc::LOD lod
struct Foundation::RHI::RHIDeviceSampler::SamplerDesc::Mipmap mipmap
struct Foundation::RHI::RHIDeviceSampler::SamplerDesc::Anisotropy anisotropy
struct Foundation::RHI::RHIDeviceSampler::SamplerDesc::AddressMode addressMode
enum Foundation::RHI::RHIDeviceSampler::SamplerDesc::Reduction WeightedAverage
struct Foundation::RHI::RHIDeviceSampler::SamplerDesc::Filter filter
const char * name
Definition Device.hpp:197
static void Destroy(RHIDevice *device, Handle handle)
Definition Device.hpp:419
static RHIAccelerationStructure * Get(RHIDevice const *device, Handle handle)
Definition Device.hpp:415
static void Destroy(RHIDevice *device, Handle handle)
Definition Device.hpp:365
static RHIBuffer * Get(RHIDevice const *device, Handle handle)
Definition Device.hpp:364
static void Destroy(RHIDevice *device, Handle handle)
Definition Device.hpp:347
static RHICommandPool * Get(RHIDevice const *device, Handle handle)
Definition Device.hpp:346
static void Destroy(RHIDevice *device, Handle handle)
Definition Device.hpp:389
static RHIDeviceDescriptorPool * Get(RHIDevice const *device, Handle handle)
Definition Device.hpp:385
static RHIDeviceDescriptorSetLayout * Get(RHIDevice const *device, Handle handle)
Definition Device.hpp:376
static void Destroy(RHIDevice *device, Handle handle)
Definition Device.hpp:380
static RHIDeviceFence * Get(RHIDevice const *device, Handle handle)
Definition Device.hpp:358
static void Destroy(RHIDevice *device, Handle handle)
Definition Device.hpp:359
static void Destroy(RHIDevice *device, Handle handle)
Definition Device.hpp:410
static RHIDeviceQueryPool * Get(RHIDevice const *device, Handle handle)
Definition Device.hpp:409
static void Destroy(RHIDevice *device, Handle handle)
Definition Device.hpp:395
static RHIDeviceSampler * Get(RHIDevice const *device, Handle handle)
Definition Device.hpp:394
static RHIDeviceSemaphore * Get(RHIDevice const *device, Handle handle)
Definition Device.hpp:352
static void Destroy(RHIDevice *device, Handle handle)
Definition Device.hpp:353
static void Destroy(RHIDevice *device, Handle handle)
Definition Device.hpp:404
static RHIPipelineStateCache * Get(RHIDevice const *device, Handle handle)
Definition Device.hpp:400
static RHIPipelineState * Get(RHIDevice const *device, Handle handle)
Definition Device.hpp:331
static void Destroy(RHIDevice *device, Handle handle)
Definition Device.hpp:335
static RHIShaderModule * Get(RHIDevice const *device, Handle handle)
Definition Device.hpp:340
static void Destroy(RHIDevice *device, Handle handle)
Definition Device.hpp:341
static void Destroy(RHIDevice *device, Handle handle)
Definition Device.hpp:326
static RHISwapchain * Get(RHIDevice const *device, Handle handle)
Definition Device.hpp:325
static RHITexture * Get(RHIDevice const *device, Handle handle)
Definition Device.hpp:370
static void Destroy(RHIDevice *device, Handle handle)
Definition Device.hpp:371
Provides type traits for types derived from RHIObject.
Definition Details.hpp:30
Definition Resource.hpp:116