|
KiCad PCB EDA Suite
|
Creates, uses and destroys GPU resources through one graphics API backend. More...
#include <rhi_device.h>
Public Member Functions | |
| virtual | ~RHI_DEVICE ()=default |
| virtual bool | SupportsCompute () const |
| Compute defaults keep backends without compute support usable for graphics. | |
| virtual RHI_COMPUTE_DEVICE_LIMITS | ComputeDeviceLimits () const |
| virtual RHI_ComputePipelineHandle | CreateComputePipeline (const RHI_COMPUTE_PIPELINE_DESC &) |
| virtual void | DestroyComputePipeline (RHI_ComputePipelineHandle) |
| virtual RHI_COMPUTE_PIPELINE_LIMITS | ComputePipelineLimits (RHI_ComputePipelineHandle) const |
| virtual RHI_COMPUTE_RESULT | ExecuteCompute (const RHI_COMPUTE_JOB &) |
| Submit, wait for completion, and copy all readbacks before returning. | |
| virtual const char * | GetName () const =0 |
| Backend and GPU name for display, such as "Vulkan (GeForce RTX 3080)". | |
| virtual RHI_BACKEND | GetBackend () const =0 |
| virtual uint32_t | MaxTextureSize () const |
| Largest texture width or height in texels. | |
| virtual bool | IsInitialized () const =0 |
| RHI_BufferHandle | CreateBuffer (const RHI_BUFFER_DESC &desc) |
| Reserve and realize in one call, so render thread only. | |
| virtual RHI_BufferHandle | ReserveBufferHandle ()=0 |
| Reserve a handle without creating the GPU buffer, so the UI thread can hand out handles while RealizeBuffer() runs later on the render thread. | |
| virtual bool | RealizeBuffer (RHI_BufferHandle handle, const RHI_BUFFER_DESC &desc)=0 |
| Create the GPU buffer for a reserved handle. | |
| virtual void | DestroyBuffer (RHI_BufferHandle handle)=0 |
| The handle's generation is retired, so later use of the stale handle is detected. | |
| virtual void | UpdateBuffer (RHI_BufferHandle handle, const void *data, size_t sizeBytes, size_t offset=0)=0 |
| The buffer need not be mappable. | |
| RHI_TextureHandle | CreateTexture (const RHI_TEXTURE_DESC &desc) |
| Reserve and realize in one call, so render thread only. | |
| virtual RHI_TextureHandle | ReserveTextureHandle ()=0 |
| Thread-safe handle reservation, realized later by RealizeTexture(). | |
| virtual bool | RealizeTexture (RHI_TextureHandle handle, const RHI_TEXTURE_DESC &desc)=0 |
| Create the GPU texture for a reserved handle. | |
| virtual void | DestroyTexture (RHI_TextureHandle handle)=0 |
| Render thread only. | |
| virtual void | UploadTexture (RHI_TextureHandle handle, const void *data, size_t sizeBytes)=0 |
| Data is tightly packed rows in the texture's format, exactly width * height * bpp bytes. | |
| virtual void | BeginUploadBatch () |
| UpdateBuffer() and UploadTexture() calls between these share one submission instead of syncing with the GPU each time. | |
| virtual void | EndUploadBatch () |
| virtual RHI_ShaderHandle | CreateShader (const RHI_SHADER_DESC &desc)=0 |
| Returns a null handle on failure. | |
| virtual void | DestroyShader (RHI_ShaderHandle handle)=0 |
| virtual RHI_PipelineHandle | CreatePipeline (const RHI_PIPELINE_DESC &desc)=0 |
| Returns a null handle on failure. | |
| virtual void | DestroyPipeline (RHI_PipelineHandle handle)=0 |
| virtual RHI_RenderPassHandle | CreateRenderPass (const RHI_RENDER_PASS_DESC &desc)=0 |
| Returns a null handle on failure. | |
| virtual void | DestroyRenderPass (RHI_RenderPassHandle handle)=0 |
| virtual RHI_FramebufferHandle | CreateFramebuffer (const RHI_FRAMEBUFFER_DESC &desc)=0 |
| Returns a null handle on failure. | |
| virtual void | DestroyFramebuffer (RHI_FramebufferHandle handle)=0 |
| virtual RHI_TextureHandle | GetFramebufferColorTexture (RHI_FramebufferHandle handle, uint32_t attachmentIndex=0) const =0 |
| The texture lets a later pass sample the framebuffer. | |
| virtual RHI_BindGroupLayoutHandle | CreateBindGroupLayout (const RHI_BIND_GROUP_LAYOUT_DESC &desc)=0 |
| Returns a null handle on failure. | |
| virtual void | DestroyBindGroupLayout (RHI_BindGroupLayoutHandle handle)=0 |
| virtual RHI_BindGroupHandle | CreateBindGroup (const RHI_BIND_GROUP_DESC &desc)=0 |
| Returns a null handle on failure. | |
| virtual void | DestroyBindGroup (RHI_BindGroupHandle handle)=0 |
| virtual void | BindGroup (uint32_t groupIndex, RHI_BindGroupHandle group)=0 |
| Only valid inside a render pass with a bound pipeline. | |
| virtual bool | BeginRenderPass (const RHI_RENDER_PASS_BEGIN_DESC &desc)=0 |
| Draws and dynamic state changes must come between this and EndRenderPass(). | |
| virtual bool | EndRenderPass ()=0 |
| Returns false if no render pass is active. | |
| virtual void | SetViewport (const RHI_VIEWPORT &viewport)=0 |
| Only valid inside a render pass. | |
| virtual void | SetScissor (const RHI_SCISSOR_RECT &scissor)=0 |
| Only valid inside a render pass. | |
| virtual void | BindPipeline (RHI_PipelineHandle pipeline)=0 |
| Only valid inside a render pass. | |
| virtual void | SetPushConstants (const void *data, size_t sizeBytes)=0 |
| Size must not exceed RHI_MAX_PUSH_CONSTANT_BYTES. | |
| virtual void | BindVertexBuffer (uint32_t slot, RHI_BufferHandle buffer)=0 |
| Only valid inside a render pass. | |
| virtual void | BindIndexBuffer (RHI_BufferHandle buffer)=0 |
| Indices are 16 bits on every backend. | |
| virtual void | Draw (uint32_t vertexCount, uint32_t firstVertex=0)=0 |
| Draws are only valid inside a render pass with a bound pipeline. | |
| virtual void | DrawInstanced (uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex=0, int32_t vertexOffset=0, uint32_t firstInstance=0)=0 |
| Non-indexed, so vertexOffset is ignored. | |
| virtual void | DrawIndexedInstanced (uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex=0, int32_t vertexOffset=0, uint32_t firstInstance=0)=0 |
| Reads 16-bit indices from the bound index buffer. | |
| virtual RHI_SurfaceHandle | CreateSurface (const RHI_SURFACE_DESC &desc)=0 |
| Returns a null handle if the native window handle is invalid. | |
| virtual void | DestroySurface (RHI_SurfaceHandle handle)=0 |
| Destroy the surface's swapchain first. | |
| virtual RHI_SwapchainHandle | CreateSwapchain (const RHI_SWAPCHAIN_DESC &desc)=0 |
| Returns a null handle on failure. | |
| virtual bool | ResizeSwapchain (RHI_SwapchainHandle handle, uint32_t width, uint32_t height, float dpiScale)=0 |
| Call when the window size or DPI scale changes. | |
| virtual void | DestroySwapchain (RHI_SwapchainHandle handle)=0 |
| void | Release (RHI_BufferHandle &aHandle) |
| Destroy the resource, if there is one, and clear the handle. | |
| void | Release (RHI_TextureHandle &aHandle) |
| void | Release (RHI_ShaderHandle &aHandle) |
| void | Release (RHI_PipelineHandle &aHandle) |
| void | Release (RHI_BindGroupLayoutHandle &aHandle) |
| void | Release (RHI_RenderPassHandle &aHandle) |
| void | Release (RHI_FramebufferHandle &aHandle) |
| void | Release (RHI_BindGroupHandle &aHandle) |
| void | Release (RHI_SurfaceHandle &aHandle) |
| void | Release (RHI_SwapchainHandle &aHandle) |
| virtual RHI_FRAME_OP_RESULT | Present (RHI_SwapchainHandle handle, RHI_FramebufferHandle aSrcFBO={}, const RHI_SCISSOR_RECT *aSourceRect=nullptr)=0 |
When aSrcFBO is valid its first color attachment is copied to the swapchain first. | |
| virtual bool | ReadbackFramebufferPixels (RHI_FramebufferHandle handle, uint32_t attachmentIndex, void *buffer, size_t bufferSize)=0 |
buffer must hold at least width * height * bpp bytes. | |
| virtual bool | CopyFramebufferDepth (RHI_FramebufferHandle aSource, RHI_FramebufferHandle aDestination, uint32_t aSourceX=0, uint32_t aSourceY=0) |
Fill all of aDestination with source depth from (aSourceX, aSourceY) on, ordered after passes already issued. | |
| virtual bool | WaitForPresentSlot (RHI_SwapchainHandle aSwapchain, std::chrono::milliseconds aTimeout, int aAllowed) |
Wait until fewer than aAllowed presents are queued for the display or the timeout passes, so the next frame renders from the newest input. | |
| virtual RHI_SURFACE_EXTENT_POLL_RESULT | PollSurfaceExtent (RHI_SwapchainHandle aSwapchain) |
| Retry a fixed surface extent that lagged behind the requested window size. | |
| virtual bool | PresentWaitsForDisplay (RHI_SwapchainHandle aSwapchain) const |
| False when presents show at once instead of at the next vertical blank, so frames drawn faster than the display refreshes are never seen. | |
| virtual bool | PresentReplacesQueued (RHI_SwapchainHandle aSwapchain) const |
| True when a present replaces one still queued for the next vertical blank, as in Vulkan MAILBOX mode, so frames drawn faster than the display only cost GPU time. | |
| virtual std::optional< std::chrono::steady_clock::time_point > | LastDisplayRefresh (RHI_SwapchainHandle aSwapchain) const |
| The vertical blank at which the display last showed a frame, or nothing if the backend cannot tell. | |
| virtual void | EndFrame () |
| Retire deferred releases that are due. | |
| size_t | PendingDeferredReleases () const |
| Releases still waiting on later frames, which only EndFrame() retires. | |
Protected Member Functions | |
| virtual void | ExecuteDeferredReleases ()=0 |
| template<typename Tag> | |
| void | deferDestroy (RHI_HANDLE_POOL< Tag > &aPool, RHI_DEFERRED_RESOURCE_TYPE aType, RHI_HANDLE< Tag > aHandle) |
| Only the destroy that wins the pending-destroy claim enqueues, so racing destroys of one handle cannot free it twice. | |
Protected Attributes | |
| uint64_t | m_frameCounter = 0 |
| RHI_DEFERRED_RELEASE_QUEUE | m_deferredReleaseQueue |
Creates, uses and destroys GPU resources through one graphics API backend.
RhiCreatePlatformDevice() creates the backend a platform is built with.
Definition at line 65 of file rhi_device.h.
|
virtualdefault |
|
pure virtual |
Draws and dynamic state changes must come between this and EndRenderPass().
Returns false if a render pass is already active or a handle is invalid.
Implemented in RHI_VULKAN_DEVICE.
|
inlinevirtual |
UpdateBuffer() and UploadTexture() calls between these share one submission instead of syncing with the GPU each time.
The default does nothing.
Reimplemented in RHI_VULKAN_DEVICE.
Definition at line 159 of file rhi_device.h.
|
pure virtual |
Only valid inside a render pass with a bound pipeline.
Implemented in RHI_VULKAN_DEVICE.
References group.
|
pure virtual |
Indices are 16 bits on every backend.
Only valid inside a render pass.
Implemented in RHI_VULKAN_DEVICE.
|
pure virtual |
Only valid inside a render pass.
Implemented in RHI_VULKAN_DEVICE.
|
pure virtual |
Only valid inside a render pass.
Implemented in RHI_VULKAN_DEVICE.
|
inlinevirtual |
Reimplemented in RHI_VULKAN_DEVICE.
Definition at line 72 of file rhi_device.h.
|
inlinevirtual |
Reimplemented in RHI_VULKAN_DEVICE.
Definition at line 75 of file rhi_device.h.
|
inlinevirtual |
Fill all of aDestination with source depth from (aSourceX, aSourceY) on, ordered after passes already issued.
The offset counts texels in storage order, which follows normalized device Y on every backend. Must not be called inside a render pass.
Reimplemented in RHI_VULKAN_DEVICE.
Definition at line 297 of file rhi_device.h.
|
pure virtual |
Returns a null handle on failure.
Implemented in RHI_VULKAN_DEVICE.
|
pure virtual |
Returns a null handle on failure.
Implemented in RHI_VULKAN_DEVICE.
|
inline |
Reserve and realize in one call, so render thread only.
Returns a null handle on failure.
Definition at line 96 of file rhi_device.h.
References RealizeBuffer(), and ReserveBufferHandle().
|
inlinevirtual |
Reimplemented in RHI_VULKAN_DEVICE.
Definition at line 73 of file rhi_device.h.
|
pure virtual |
Returns a null handle on failure.
Implemented in RHI_VULKAN_DEVICE.
|
pure virtual |
Returns a null handle on failure.
Implemented in RHI_VULKAN_DEVICE.
|
pure virtual |
Returns a null handle on failure.
Implemented in RHI_VULKAN_DEVICE.
|
pure virtual |
Returns a null handle on failure.
Implemented in RHI_VULKAN_DEVICE.
|
pure virtual |
Returns a null handle if the native window handle is invalid.
Implemented in RHI_VULKAN_DEVICE.
|
pure virtual |
Returns a null handle on failure.
Implemented in RHI_VULKAN_DEVICE.
|
inline |
Reserve and realize in one call, so render thread only.
Returns a null handle on failure.
Definition at line 130 of file rhi_device.h.
References RealizeTexture(), and ReserveTextureHandle().
|
inlineprotected |
Only the destroy that wins the pending-destroy claim enqueues, so racing destroys of one handle cannot free it twice.
Definition at line 365 of file rhi_device.h.
References m_deferredReleaseQueue, m_frameCounter, RHI_HANDLE_POOL< Tag >::MarkPendingDestroy(), and RHI_HANDLE< Tag >::value.
Referenced by RHI_VULKAN_DEVICE::DestroyBindGroup(), RHI_VULKAN_DEVICE::DestroyBindGroupLayout(), RHI_VULKAN_DEVICE::DestroyBuffer(), RHI_VULKAN_DEVICE::DestroyFramebuffer(), RHI_VULKAN_DEVICE::DestroyPipeline(), RHI_VULKAN_DEVICE::DestroyRenderPass(), RHI_VULKAN_DEVICE::DestroyShader(), and RHI_VULKAN_DEVICE::DestroyTexture().
|
pure virtual |
Implemented in RHI_VULKAN_DEVICE.
Referenced by Release().
|
pure virtual |
Implemented in RHI_VULKAN_DEVICE.
Referenced by Release().
|
pure virtual |
The handle's generation is retired, so later use of the stale handle is detected.
Render thread only, as it reads the frame counter. The UI thread destroys through RHI_DEVICE_PROXY.
Implemented in RHI_VULKAN_DEVICE.
Referenced by Release().
|
inlinevirtual |
Reimplemented in RHI_VULKAN_DEVICE.
Definition at line 74 of file rhi_device.h.
|
pure virtual |
Implemented in RHI_VULKAN_DEVICE.
Referenced by Release().
|
pure virtual |
Implemented in RHI_VULKAN_DEVICE.
Referenced by Release().
|
pure virtual |
Implemented in RHI_VULKAN_DEVICE.
Referenced by Release().
|
pure virtual |
Implemented in RHI_VULKAN_DEVICE.
Referenced by Release().
|
pure virtual |
|
pure virtual |
Implemented in RHI_VULKAN_DEVICE.
Referenced by Release().
|
pure virtual |
|
pure virtual |
Draws are only valid inside a render pass with a bound pipeline.
Implemented in RHI_VULKAN_DEVICE.
|
pure virtual |
Reads 16-bit indices from the bound index buffer.
Implemented in RHI_VULKAN_DEVICE.
|
pure virtual |
Non-indexed, so vertexOffset is ignored.
Implemented in RHI_VULKAN_DEVICE.
|
inlinevirtual |
Retire deferred releases that are due.
The render thread must call this once per frame after presenting.
Definition at line 348 of file rhi_device.h.
References ExecuteDeferredReleases(), and m_frameCounter.
|
pure virtual |
Returns false if no render pass is active.
Implemented in RHI_VULKAN_DEVICE.
|
inlinevirtual |
Reimplemented in RHI_VULKAN_DEVICE.
Definition at line 160 of file rhi_device.h.
|
inlinevirtual |
Submit, wait for completion, and copy all readbacks before returning.
Reimplemented in RHI_VULKAN_DEVICE.
Definition at line 78 of file rhi_device.h.
References INVALID.
|
protectedpure virtual |
Implemented in RHI_VULKAN_DEVICE.
Referenced by EndFrame().
|
pure virtual |
Implemented in RHI_VULKAN_DEVICE.
|
pure virtual |
The texture lets a later pass sample the framebuffer.
Returns a null handle if the framebuffer or attachment index is invalid. The framebuffer owns the texture, so never destroy or release it.
Implemented in RHI_VULKAN_DEVICE.
|
pure virtual |
Backend and GPU name for display, such as "Vulkan (GeForce RTX 3080)".
Implemented in RHI_VULKAN_DEVICE.
|
pure virtual |
Implemented in RHI_VULKAN_DEVICE.
|
inlinevirtual |
The vertical blank at which the display last showed a frame, or nothing if the backend cannot tell.
Definition at line 338 of file rhi_device.h.
|
inlinevirtual |
Largest texture width or height in texels.
The default suits every GPU Metal runs on, and a backend that can query its GPU overrides it.
Reimplemented in RHI_VULKAN_DEVICE.
Definition at line 89 of file rhi_device.h.
|
inline |
Releases still waiting on later frames, which only EndFrame() retires.
Definition at line 355 of file rhi_device.h.
References m_deferredReleaseQueue.
|
inlinevirtual |
Retry a fixed surface extent that lagged behind the requested window size.
Reimplemented in RHI_VULKAN_DEVICE.
Definition at line 316 of file rhi_device.h.
References IDLE.
|
pure virtual |
When aSrcFBO is valid its first color attachment is copied to the swapchain first.
OUT_OF_DATE means the swapchain must be recreated, and SURFACE_LOST means the surface must be too.
| aSourceRect | the part of aSrcFBO to show, in texels in storage order as for CopyFramebufferDepth(), or all of it when null. |
Implemented in RHI_VULKAN_DEVICE.
|
inlinevirtual |
True when a present replaces one still queued for the next vertical blank, as in Vulkan MAILBOX mode, so frames drawn faster than the display only cost GPU time.
Reimplemented in RHI_VULKAN_DEVICE.
Definition at line 331 of file rhi_device.h.
|
inlinevirtual |
False when presents show at once instead of at the next vertical blank, so frames drawn faster than the display refreshes are never seen.
Reimplemented in RHI_VULKAN_DEVICE.
Definition at line 325 of file rhi_device.h.
|
pure virtual |
buffer must hold at least width * height * bpp bytes.
Returns false if the handle or attachment index is invalid or the backend cannot read back.
Implemented in RHI_VULKAN_DEVICE.
|
pure virtual |
Create the GPU buffer for a reserved handle.
Render thread only. On failure the handle is released and false is returned.
Implemented in RHI_VULKAN_DEVICE.
Referenced by CreateBuffer().
|
pure virtual |
Create the GPU texture for a reserved handle.
Render thread only. On failure the handle is released and false is returned.
Implemented in RHI_VULKAN_DEVICE.
Referenced by CreateTexture().
|
inline |
Definition at line 267 of file rhi_device.h.
References DestroyBindGroup().
|
inline |
Definition at line 264 of file rhi_device.h.
References DestroyBindGroupLayout().
|
inline |
Destroy the resource, if there is one, and clear the handle.
Definition at line 260 of file rhi_device.h.
References DestroyBuffer().
Referenced by destroyDiffCopies().
|
inline |
Definition at line 266 of file rhi_device.h.
References DestroyFramebuffer().
|
inline |
Definition at line 263 of file rhi_device.h.
References DestroyPipeline().
|
inline |
Definition at line 265 of file rhi_device.h.
References DestroyRenderPass().
|
inline |
Definition at line 262 of file rhi_device.h.
References DestroyShader().
|
inline |
Definition at line 268 of file rhi_device.h.
References DestroySurface().
|
inline |
Definition at line 269 of file rhi_device.h.
References DestroySwapchain().
|
inline |
Definition at line 261 of file rhi_device.h.
References DestroyTexture().
|
pure virtual |
Reserve a handle without creating the GPU buffer, so the UI thread can hand out handles while RealizeBuffer() runs later on the render thread.
Thread-safe. Returns a null handle when the pool is exhausted.
Implemented in RHI_VULKAN_DEVICE.
Referenced by CreateBuffer().
|
pure virtual |
Thread-safe handle reservation, realized later by RealizeTexture().
Implemented in RHI_VULKAN_DEVICE.
Referenced by CreateTexture().
|
pure virtual |
Call when the window size or DPI scale changes.
Returns false on failure.
Implemented in RHI_VULKAN_DEVICE.
|
pure virtual |
Size must not exceed RHI_MAX_PUSH_CONSTANT_BYTES.
Only valid inside a render pass.
Implemented in RHI_VULKAN_DEVICE.
|
pure virtual |
Only valid inside a render pass.
Implemented in RHI_VULKAN_DEVICE.
|
pure virtual |
Only valid inside a render pass.
Implemented in RHI_VULKAN_DEVICE.
|
inlinevirtual |
Compute defaults keep backends without compute support usable for graphics.
Reimplemented in RHI_VULKAN_DEVICE.
Definition at line 71 of file rhi_device.h.
|
pure virtual |
The buffer need not be mappable.
The backend may go through a staging copy.
Implemented in RHI_VULKAN_DEVICE.
|
pure virtual |
Data is tightly packed rows in the texture's format, exactly width * height * bpp bytes.
Implemented in RHI_VULKAN_DEVICE.
|
inlinevirtual |
Wait until fewer than aAllowed presents are queued for the display or the timeout passes, so the next frame renders from the newest input.
Reimplemented in RHI_VULKAN_DEVICE.
Definition at line 309 of file rhi_device.h.
|
protected |
Definition at line 373 of file rhi_device.h.
Referenced by deferDestroy(), RHI_VULKAN_DEVICE::ExecuteDeferredReleases(), PendingDeferredReleases(), and RHI_VULKAN_DEVICE::~RHI_VULKAN_DEVICE().
|
protected |
Definition at line 372 of file rhi_device.h.
Referenced by deferDestroy(), EndFrame(), and RHI_VULKAN_DEVICE::ExecuteDeferredReleases().