125 size_t sizeBytes,
size_t offset = 0 ) = 0;
233 virtual void Draw( uint32_t vertexCount, uint32_t firstVertex = 0 ) = 0;
237 uint32_t firstVertex = 0, int32_t vertexOffset = 0,
238 uint32_t firstInstance = 0 ) = 0;
242 int32_t vertexOffset = 0, uint32_t firstInstance = 0 ) = 0;
255 uint32_t height,
float dpiScale ) = 0;
286 uint32_t attachmentIndex,
287 void* buffer,
size_t bufferSize ) = 0;
298 uint32_t aSourceX = 0, uint32_t aSourceY = 0 )
337 virtual std::optional<std::chrono::steady_clock::time_point>
364 template <
typename Tag>
Plain owning command data, recordable on any thread without device access.
Holds destroyed GPU resource handles until no in-flight command buffer can still reference them.
Creates, uses and destroys GPU resources through one graphics API backend.
virtual RHI_BufferHandle ReserveBufferHandle()=0
Reserve a handle without creating the GPU buffer, so the UI thread can hand out handles while Realize...
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 t...
virtual void DestroyPipeline(RHI_PipelineHandle handle)=0
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 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...
virtual uint32_t MaxTextureSize() const
Largest texture width or height in texels.
virtual void DestroyComputePipeline(RHI_ComputePipelineHandle)
virtual ~RHI_DEVICE()=default
virtual RHI_SurfaceHandle CreateSurface(const RHI_SURFACE_DESC &desc)=0
Returns a null handle if the native window handle is invalid.
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 RHI_ComputePipelineHandle CreateComputePipeline(const RHI_COMPUTE_PIPELINE_DESC &)
void Release(RHI_FramebufferHandle &aHandle)
virtual RHI_BACKEND GetBackend() const =0
RHI_DEFERRED_RELEASE_QUEUE m_deferredReleaseQueue
virtual void EndUploadBatch()
virtual void EndFrame()
Retire deferred releases that are due.
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 canno...
virtual bool BeginRenderPass(const RHI_RENDER_PASS_BEGIN_DESC &desc)=0
Draws and dynamic state changes must come between this and EndRenderPass().
virtual void DestroyFramebuffer(RHI_FramebufferHandle handle)=0
virtual void DestroyShader(RHI_ShaderHandle handle)=0
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 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 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 EndRenderPass()=0
Returns false if no render pass is active.
virtual void DestroySurface(RHI_SurfaceHandle handle)=0
Destroy the surface's swapchain first.
virtual RHI_TextureHandle GetFramebufferColorTexture(RHI_FramebufferHandle handle, uint32_t attachmentIndex=0) const =0
The texture lets a later pass sample the framebuffer.
virtual void DestroyBindGroup(RHI_BindGroupHandle handle)=0
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,...
virtual void UpdateBuffer(RHI_BufferHandle handle, const void *data, size_t sizeBytes, size_t offset=0)=0
The buffer need not be mappable.
virtual void DestroyTexture(RHI_TextureHandle handle)=0
Render thread only.
void Release(RHI_PipelineHandle &aHandle)
void Release(RHI_BufferHandle &aHandle)
Destroy the resource, if there is one, and clear the handle.
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,...
virtual void BindGroup(uint32_t groupIndex, RHI_BindGroupHandle group)=0
Only valid inside a render pass with a bound pipeline.
virtual RHI_COMPUTE_DEVICE_LIMITS ComputeDeviceLimits() const
virtual void DestroyBuffer(RHI_BufferHandle handle)=0
The handle's generation is retired, so later use of the stale handle is detected.
RHI_BufferHandle CreateBuffer(const RHI_BUFFER_DESC &desc)
Reserve and realize in one call, so render thread only.
virtual void SetScissor(const RHI_SCISSOR_RECT &scissor)=0
Only valid inside a render pass.
virtual RHI_PipelineHandle CreatePipeline(const RHI_PIPELINE_DESC &desc)=0
Returns a null handle on failure.
virtual const char * GetName() const =0
Backend and GPU name for display, such as "Vulkan (GeForce RTX 3080)".
virtual RHI_COMPUTE_RESULT ExecuteCompute(const RHI_COMPUTE_JOB &)
Submit, wait for completion, and copy all readbacks before returning.
virtual RHI_SURFACE_EXTENT_POLL_RESULT PollSurfaceExtent(RHI_SwapchainHandle aSwapchain)
Retry a fixed surface extent that lagged behind the requested window size.
virtual void BindVertexBuffer(uint32_t slot, RHI_BufferHandle buffer)=0
Only valid inside a render pass.
virtual void DestroySwapchain(RHI_SwapchainHandle handle)=0
void Release(RHI_BindGroupHandle &aHandle)
virtual RHI_ShaderHandle CreateShader(const RHI_SHADER_DESC &desc)=0
Returns a null handle on failure.
void Release(RHI_BindGroupLayoutHandle &aHandle)
virtual RHI_COMPUTE_PIPELINE_LIMITS ComputePipelineLimits(RHI_ComputePipelineHandle) const
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.
size_t PendingDeferredReleases() const
Releases still waiting on later frames, which only EndFrame() retires.
virtual void ExecuteDeferredReleases()=0
virtual RHI_TextureHandle ReserveTextureHandle()=0
Thread-safe handle reservation, realized later by RealizeTexture().
virtual RHI_SwapchainHandle CreateSwapchain(const RHI_SWAPCHAIN_DESC &desc)=0
Returns a null handle on failure.
void Release(RHI_RenderPassHandle &aHandle)
void Release(RHI_TextureHandle &aHandle)
virtual void BindPipeline(RHI_PipelineHandle pipeline)=0
Only valid inside a render pass.
virtual void BeginUploadBatch()
UpdateBuffer() and UploadTexture() calls between these share one submission instead of syncing with t...
virtual bool RealizeTexture(RHI_TextureHandle handle, const RHI_TEXTURE_DESC &desc)=0
Create the GPU texture for a reserved handle.
virtual bool SupportsCompute() const
Compute defaults keep backends without compute support usable for graphics.
virtual void Draw(uint32_t vertexCount, uint32_t firstVertex=0)=0
Draws are only valid inside a render pass with a bound pipeline.
RHI_TextureHandle CreateTexture(const RHI_TEXTURE_DESC &desc)
Reserve and realize in one call, so render thread only.
virtual RHI_BindGroupLayoutHandle CreateBindGroupLayout(const RHI_BIND_GROUP_LAYOUT_DESC &desc)=0
Returns a null handle on failure.
virtual void SetViewport(const RHI_VIEWPORT &viewport)=0
Only valid inside a render pass.
virtual RHI_FramebufferHandle CreateFramebuffer(const RHI_FRAMEBUFFER_DESC &desc)=0
Returns a null handle on failure.
virtual RHI_BindGroupHandle CreateBindGroup(const RHI_BIND_GROUP_DESC &desc)=0
Returns a null handle on failure.
void Release(RHI_SurfaceHandle &aHandle)
virtual RHI_RenderPassHandle CreateRenderPass(const RHI_RENDER_PASS_DESC &desc)=0
Returns a null handle on failure.
virtual void SetPushConstants(const void *data, size_t sizeBytes)=0
Size must not exceed RHI_MAX_PUSH_CONSTANT_BYTES.
virtual void DestroyRenderPass(RHI_RenderPassHandle handle)=0
void Release(RHI_SwapchainHandle &aHandle)
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 bool RealizeBuffer(RHI_BufferHandle handle, const RHI_BUFFER_DESC &desc)=0
Create the GPU buffer for a reserved handle.
virtual void DestroyBindGroupLayout(RHI_BindGroupLayoutHandle handle)=0
virtual void BindIndexBuffer(RHI_BufferHandle buffer)=0
Indices are 16 bits on every backend.
virtual bool IsInitialized() const =0
void Release(RHI_ShaderHandle &aHandle)
Thread-safe pool that allocates and recycles generation-tracked handles for device implementations.
bool MarkPendingDestroy(RHI_HANDLE< Tag > handle)
Make a handle invalid while keeping its slot out of the free list until Release().
RHI_DEFERRED_RESOURCE_TYPE
RHI_SURFACE_EXTENT_POLL_RESULT
RHI_FRAME_OP_RESULT
Windows headers define ERROR as a macro.
RHI_HANDLE< RHI_TAG_FRAMEBUFFER > RHI_FramebufferHandle
RHI_HANDLE< RHI_TAG_TEXTURE > RHI_TextureHandle
RHI_HANDLE< RHI_TAG_BUFFER > RHI_BufferHandle
RHI_HANDLE< RHI_TAG_PIPELINE > RHI_PipelineHandle
RHI_HANDLE< RHI_TAG_BIND_GROUP > RHI_BindGroupHandle
RHI_HANDLE< RHI_TAG_COMPUTE_PIPELINE > RHI_ComputePipelineHandle
RHI_HANDLE< RHI_TAG_BIND_GROUP_LAYOUT > RHI_BindGroupLayoutHandle
RHI_HANDLE< RHI_TAG_SURFACE > RHI_SurfaceHandle
RHI_HANDLE< RHI_TAG_SHADER > RHI_ShaderHandle
RHI_HANDLE< RHI_TAG_RENDER_PASS > RHI_RenderPassHandle
RHI_HANDLE< RHI_TAG_SWAPCHAIN > RHI_SwapchainHandle
RHI_BACKEND
Identifies which graphics backend a device implements.
Opaque GPU resource handle, typed by a tag struct so handles of different kinds cannot be mixed.
Everything here is fixed at creation except the states listed in dynamicStates.
Same pixel space as RHI_VIEWPORT.
The bytecode is SPIR-V on Vulkan and MSL source text on Metal.
Descriptor for creating a surface from a native window.
Descriptor for creating a swapchain.
Top-left origin, in device pixels.