|
Foundation
|
Renderer implementing a Frame Graph system with automatic resource tracking and synchronization. More...
#include <Renderer.hpp>
Classes | |
| struct | ExecutePerThreadCommandLists |
| struct | FrameSyncObjects |
| struct | MemoryStat |
| struct | RendererSetup |
| Helper class containing all states pertaining to Renderer's Setup phase. More... | |
| struct | TexturePreviewStat |
Public Types | |
| enum class | State { Undefined , Setup , PostSetup , Execute } |
Public Member Functions | |
| Renderer ()=delete | |
| Renderer (RendererDesc const &desc, RHIApplicationHandle< RHIDevice > device, RHIDeviceHandle< RHISwapchain > swapchain, Core::JobSystem *jobs, Allocator *allocator) | |
| void | BeginSetup () |
| Begins the setup phase of the render graph. | |
| template<typename T , typename... Args> requires std::is_base_of_v<RenderPass, T> | |
| PassHandle | CreatePassImpl (StringView name, RHIDeviceQueueType queue, size_t priority, Args &&... args) |
| Create a render pass from a RenderPass* implementation and add it to the render graph. | |
| template<typename FSetup , typename FRecord > | |
| PassHandle | CreatePass (StringView name, RHIDeviceQueueType queue, size_t priority, FSetup &&setup, FRecord &&record) |
| Create a render pass from a Setup(Renderer*, PassHandle) and Record(Renderer*, PassHandle,
RHICommandList*) lambda. | |
| template<typename T > | |
| ResourceHandle | CreateResource (StringView name, T const &desc) |
| Create a new resource to be used in the render graph. | |
| ResourceHandle | CreateSampler (RHIDeviceSampler::SamplerDesc const &desc) const |
| Creates a sampler with the specified name and descriptor. | |
| void | BindPass (PassHandle pass, PassHandle other) |
| Declares an inter-pass dependency, where the other pass should execute-before the current pass. | |
| void | BindShader (PassHandle pass, RHIShaderStage stage, StringView entry_point, StringView shader_path, Span< const char > specializationData={}, uint32_t rtHitGroupIndex=0, RHIPipelineState::PipelineStateDesc::RayTracingHitGroupType rtHitGroupType=RHIPipelineState::PipelineStateDesc::RayTracingHitGroupType::Triangles) const |
| Binds shader file path to a certain pass at a certain stage. | |
| void | BindPushConstant (PassHandle pass, RHIShaderStage stage, size_t offset, size_t size) const |
| Declares a range of Push Constant used in a stage. | |
| void | BindVertexInput (PassHandle pass, RHIPipelineState::PipelineStateDesc::VertexInput const &info) const |
| Associates Vertex Input description with this pass. | |
| void | BindBufferUniform (PassHandle pass, ResourceHandle buffer, RHIPipelineStage stage, StringView bind_point) const |
| Binds a uniform buffer to a specified binding point in a rendering pass. | |
| void | BindBufferStorageRead (PassHandle pass, ResourceHandle buffer, RHIPipelineStage stage, StringView bind_point) const |
| Binds a read-only storage buffer to a specified binding point. | |
| void | BindBufferUnordered (PassHandle pass, ResourceHandle buffer, RHIPipelineStage stage, StringView bind_point) const |
| Binds a buffer for unordered (UAV) access from shaders (read and/or write in any order). | |
| void | BindBufferShaderRead (PassHandle pass, ResourceHandle buffer, RHIPipelineStage stage) const |
| Declares this pass has shaders that will read from this buffer. e.g. Vertex, Index. | |
| void | BindBufferIndirectRead (PassHandle pass, ResourceHandle buffer) const |
| Declares that this pass will consume this buffer as the source of an indirect draw/dispatch command. | |
| void | BindBufferCopyDst (PassHandle pass, ResourceHandle buffer) const |
| Declares that this pass will write to the buffer via copy. | |
| void | BindBufferCopySrc (PassHandle pass, ResourceHandle buffer) const |
| Declares that this pass will read from the buffer via copy. | |
| void | BindTextureSampler (PassHandle pass, ResourceHandle sampler, StringView bind_point) const |
| Binds a sampler to the shader. | |
| void | BindDescriptorSetWrite (PassHandle pass, StringView bind_point, RHIDeviceDescriptorSetLayout *layout, RHIDeviceDescriptorSetLayout *reading_layout=nullptr) |
| Binds an externally managed descriptor set that this pass writes. | |
| void | BindDescriptorSetWrite (PassHandle pass, RHIDeviceDescriptorSetLayout *layout, RHIDeviceDescriptorSetLayout *reading_layout=nullptr) |
| Declares an external descriptor-set write without binding it to a pipeline. | |
| void | BindDescriptorSetRead (PassHandle pass, StringView bind_point, RHIDeviceDescriptorSetLayout *layout) |
| Binds an externally managed descriptor set that this pass reads. | |
| void | MakePassUncullable (PassHandle pass) const |
| Marks a pass as "uncullable", meaning it will always be executed even if it has no dependencies. | |
| void | BindTextureSRV (PassHandle pass, ResourceHandle texture, StringView bind_point, RHIPipelineStage stage, RHITextureViewDesc const &desc) const |
| Binds a texture as a Shader Resource View (read-only sampling / fetch). | |
| void | BindTextureUAV (PassHandle pass, ResourceHandle texture, StringView bind_point, RHIPipelineStage stage, RHITextureViewDesc const &desc) const |
| Binds a texture for unordered (UAV) read-write access in shaders. | |
| void | BindTextureShaderRead (PassHandle pass, ResourceHandle texture, RHIPipelineStage stage, RHITextureSubresourceRange const &range) const |
| Declares a shader read dependency for a texture without creating an internal binding. | |
| void | BindTextureRTV (PassHandle pass, ResourceHandle texture, RHITextureViewDesc const &desc, RHIPipelineState::PipelineStateDesc::Attachment::Blending const &blending={}) const |
| Binds a texture as a Render Target View (color attachment) for a graphics pass. | |
| void | BindTextureDSV (PassHandle pass, ResourceHandle texture, RHITextureViewDesc const &desc, bool readOnly=false) const |
| Binds a texture as a Depth-Stencil View for a graphics pass. | |
| void | BindBackbufferRTV (PassHandle pass, RHIPipelineState::PipelineStateDesc::Attachment::Blending const &blending={}) const |
| void | BindBackbufferUAV (PassHandle pass, int set_index) const |
| Binds the backbuffer as RW access at binding 0 of set index. | |
| void | BindTextureCopyDst (PassHandle pass, ResourceHandle texture, RHITextureSubresourceRange const &range={}) const |
| Declares that this pass will write to the texture via copy / blit (transfer destination). | |
| void | BindTextureCopySrc (PassHandle pass, ResourceHandle texture, RHITextureSubresourceRange const &range={}) const |
| Declares that this pass will read from the texture via copy / blit (transfer source). | |
| void | BindAccelerationStructureWrite (PassHandle pass, ResourceHandle as) const |
| Declares that this pass will build, or update the AS. | |
| void | BindAccelerationStructureSRV (PassHandle pass, ResourceHandle as, RHIPipelineStage stage, StringView bind_point) const |
| Declares that this pass has shaders that will read from this AS. | |
| void | PassSetRasterizerFlags (PassHandle pass, RHIPipelineState::PipelineStateDesc::Rasterizer const &rasterizer={}, RHIPipelineState::PipelineStateDesc::DepthStencil const &depth_stencil={}) const |
| Sets the rasterizer and depth-stencil state for a graphics pass. | |
| void | PassSetTopology (PassHandle pass, RHIPipelineState::PipelineStateDesc::Topology topology) const |
| Sets the input assembly topology for a graphics pass (TriangleList, LineList, etc.). | |
| Core::JobBarrier | EndSetup (bool wait=true) |
| Finish setting up the render graph. | |
| void | DbgGetMemoryStatistics (Vector< MemoryStat > &outStats) const |
| void | DbgGetTexturePreviews (Vector< TexturePreviewStat > &outStats) const |
| RHIDevice * | GetDevice () const |
| Get the RHIDevice this Renderer was constructed with. | |
| const RHIApplication * | GetApplication () const |
| Get the RHIApplication this Renderer was constructed with. | |
| RHIExtent2D | GetSwapchainExtent () const |
| Get the current swapchain extents. | |
| RHIExtent3D | GetSwapchainExtent3D () const |
| Get the current swapchain extents as a 3D extent with depth 1. | |
| Variant< RHIBuffer *, RHITexture *, RHIAccelerationStructure * > | DerefResource (const ResourceHandle handle) const |
| Dereference a resource handle to its underlying RHI resource. | |
| RHITextureView * | DerefTextureView (const ResourceHandle handle) const |
| Dereference a texture view handle to its underlying RHI texture view. | |
| RHIDeviceSampler * | DerefSampler (const ResourceHandle handle) const |
| Dereference a sampler handle to its underlying RHI sampler. | |
| RHIPipelineState * | DerefPipelineState (const PassHandle pass) const |
| Dereference the automatically built pipeline state object handle associated with a given pass. | |
| Vector< RHIDeviceDescriptorSet * > const & | DerefDescriptorSets (const PassHandle pass) const |
| Dereference the built descriptor sets associated with a given pass. | |
| Allocator * | GetAllocator () const |
| RHIExtent3D | CmdGetComputeLocalSize (PassHandle pass) const |
| Helper that retrieves the local size declared by a compute pass. | |
| void | CmdDispatch (PassHandle pass, RHICommandList *cmd, RHIExtent3D thread_size) const |
| Helper that dispatches a compute shader with the specified THREAD count. | |
| void | CmdSetPipeline (PassHandle pass, RHICommandList *cmd) const |
| Helper that sets the current pass's PSO and descriptor sets to the current command list. | |
| void | CmdBindDescriptorSet (PassHandle pass, RHICommandList *cmd, uint32_t set_index, RHIDeviceDescriptorSet *descriptor_set) const |
| Helper that binds a single descriptor set to the current command list. | |
| void | CmdBindDescriptorSet (PassHandle pass, RHICommandList *cmd, StringView bind_point, RHIDeviceDescriptorSet *descriptor_set) const |
| Helper that binds a single descriptor set to the set of the specified bind point. | |
| void | CmdBeginGraphics (PassHandle pass, RHICommandList *cmd, RHIExtent2D const &extent, Span< const RHIColorAttachmentLoad > rtv_loads={}, RHIDepthAttachmentLoad dsv_load={RHIAttachmentLoadOp::Clear, {0.0f, 0u}}) |
| Helper that pushes correct descriptor sets and PSO to the current command list, and pushes correct BeginGraphics() commands with declared RTVs and DSVs to the current command list. | |
| template<typename T > | |
| void | CmdSetPushConstant (PassHandle pass, RHICommandList *cmd, RHIShaderStage stage, size_t offset, T const &data) |
| Helper that sets a Push Constant range data with a single l-value. | |
| State | GetState () const |
| Retrieves the current state of the renderer. | |
| uint32_t | GetFrameSwaps () const |
| Get the number of frames that can be simultaneously in-flight. | |
| uint64_t | GetFrame () const |
| Retrieves the current frame number. | |
| uint32_t | GetSwap () const |
| Retrieves the current swap index at the time of ExecuteFrame(). | |
| uint64_t | GetSync () const |
| Retrieves the current synchronization index. | |
| TrackedPass const & | GetTrackedPass (PassHandle pass) |
| Retrieves an internal tracked pass associated with the given handle, read-only. | |
| bool | IsAsyncComputeEnabled () const |
| Returns whether async compute is enabled. | |
| bool | IsPresentEnabled () const |
| Returns whether a swapchain is bound. | |
| void | SetSwapchain (RHIDeviceHandle< RHISwapchain > swapchain) |
| Update the swapchain to a new one. You must call this when the window is resized or the swapchain is invalidated. | |
| RHISwapchain * | GetSwapchain () const |
| Returns the currently used RHISwapchain object. | |
| RHIDeviceHandle< RHIDeviceSemaphore > | GetRenderCompleteSemaphore () const |
| Binary semaphore signaled when GPU work for the current swap image is complete. | |
| void | WaitForFrame () |
| Blocks until the most recently submitted frame has finished executing on the GPU. | |
| void | BeginExecute () |
| Begins execution for a headless (no swapchain) frame. | |
| RHISwapchainResult | BeginExecute (Presenter *presenter) |
| Convenience overload for the common present loop. Waits for the synchronization slot being reused, then acquires the next swapchain image. | |
| void | ExecuteFrame () |
| Executes all passes in the render graph for one frame. | |
| void | EndExecute () |
| Ends the execution phase and performs GPU submission. | |
| String | DbgDumpGraphviz () const |
| String | DbgDumpActivePasses () const |
| String | DbgDumpExecutionGroups () const |
| Span< const uint64_t > | DbgProfilePassTiming (uint64_t sync, float &resolutionNS) const |
| Retrieves timings for all passes executed in the last frame associated with the specified sync index. The values are refreshed upon BeginExecute() call. | |
Private Types | |
| using | ExecuteBarrierList = Vector< Pair< Variant< RHIBuffer *, RHITexture *, RHIAccelerationStructure * >, RHICommandList::TransitionDesc > > |
| using | ExecuteBarrierPCmdOrPBarrierList = Variant< RHICommandList *, ExecuteBarrierList * > |
Private Member Functions | |
| ResourceHandle | CreateTextureView (PassHandle pass, ResourceHandle handle, RHITextureViewDesc const &desc) const |
| void | CullPasses (PassHandle epilogue) const |
| void | BuildPipelineState (PassHandle pass) |
| Core::JobBarrier | BuildPipelineStateAll () |
| void | FinalizeResources () |
| void | FinalizePasses () |
| RHICommandList * | ExecuteAllocateCommandList (RHIDeviceQueueType queue, int thread_id=-1) |
| uint32_t | ExecuteGetQueueFamily (RHIDeviceQueueType queue) const |
| Helper to get the queue index of a queue type. | |
| void | ExecuteBarrierSubresourceState (PassHandle pass, RHITexture *res, TrackedResource::SubresourceState &sta, RHIResourceAccess access, RHIPipelineStage stage, RHITextureLayout layout, ExecuteBarrierPCmdOrPBarrierList cmd) const |
| void | ExecuteBarrierSubresource (PassHandle pass, TrackedResource &res, RHITextureSubresourceRange const &range, RHIResourceAccess access, RHIPipelineStage stage, RHITextureLayout layout, ExecuteBarrierPCmdOrPBarrierList cmd) |
| Executes barriers for a subresource range of a texture. | |
| void | ExecuteBarrierBuffer (PassHandle pass, TrackedResource &res, RHIResourceAccess access, RHIPipelineStage stage, ExecuteBarrierPCmdOrPBarrierList cmd) |
| Executes barriers for a whole buffer. | |
| void | ExecuteBarrierAccelerationStructure (PassHandle pass, TrackedResource &res, RHIResourceAccess access, RHIPipelineStage stage, ExecuteBarrierPCmdOrPBarrierList cmd) |
| Executes barriers for an acceleration structure. | |
| void | ExecuteBarriers (TrackedPass &pass, ExecuteBarrierPCmdOrPBarrierList cmd) |
| Executes all barriers for a pass. | |
| void | AcquireSync () |
| Acquires the synchronization primitives for the current frame. Internal. Called by BeginExecute. | |
| void | BeginExecute (uint32_t swapImageIndex, RHIDeviceSemaphore *imageAcquire) |
| Core implementation of BeginExecute. | |
| void | SetFrameSyncObjects () |
| Sets backbuffer views and sync primitives. | |
| void | DeclareBufferAccess (PassHandle pass, ResourceHandle handle, RHIPipelineStage stage, RHIResourceAccess access=RHIResourceAccessBits::ShaderRead) const |
| Explicitly declares that this pass will access the buffer in the specified stage with the specified access. | |
| void | DeclareTextureAccess (PassHandle pass, ResourceHandle handle, RHIPipelineStage stage, RHITextureSubresourceRange range={}, RHIResourceAccess access=RHIResourceAccessBits::ShaderRead, RHITextureLayout layout=RHITextureLayout::ShaderReadOnly) const |
| Declares that this pass will access the texture in the specified stage with the specified access. | |
Renderer implementing a Frame Graph system with automatic resource tracking and synchronization.
The Renderer is responsible for managing rendering passes, resources, and synchronization on both the Graphics queue and an optional Async Compute queue (if enabled and supported).
Do note - that the Transfer queue is not used in the Renderer. As such, you're free to use it for asynchronous resource uploads.
|
private |
|
private |
|
strong |
|
delete |
| Renderer::Renderer | ( | RendererDesc const & | desc, |
| RHIApplicationHandle< RHIDevice > | device, | ||
| RHIDeviceHandle< RHISwapchain > | swapchain, | ||
| Core::JobSystem * | jobs, | ||
| Allocator * | allocator | ||
| ) |
|
private |
Acquires the synchronization primitives for the current frame. Internal. Called by BeginExecute.
| void Renderer::BeginExecute | ( | ) |
Begins execution for a headless (no swapchain) frame.
Resets the temporary execution allocator and selects the default swap index (0) with no acquire semaphore. This is the public entry point for headless renderers; see IsPresentEnabled().
| RHISwapchainResult Renderer::BeginExecute | ( | Presenter * | presenter | ) |
Convenience overload for the common present loop. Waits for the synchronization slot being reused, then acquires the next swapchain image.
|
private |
Core implementation of BeginExecute.
Resets the temporary execution allocator and selects the acquired swapchain image (when a swapchain is bound).
| swapImageIndex | Image index from RHISwapchain::GetNextImage. Ignored when headless. |
| imageAcquire | Binary semaphore signaled by RHISwapchain::GetNextImage. May be null (headless); stored and waited on by the last graphics submit. |
| void Renderer::BeginSetup | ( | ) |
Begins the setup phase of the render graph.
| void Renderer::BindAccelerationStructureSRV | ( | PassHandle | pass, |
| ResourceHandle | as, | ||
| RHIPipelineStage | stage, | ||
| StringView | bind_point | ||
| ) | const |
Declares that this pass has shaders that will read from this AS.
Multiple bind declarations to the same bind point will create array-style bindings, indexed by order of declaration.
| void Renderer::BindAccelerationStructureWrite | ( | PassHandle | pass, |
| ResourceHandle | as | ||
| ) | const |
Declares that this pass will build, or update the AS.
| void Renderer::BindBackbufferRTV | ( | PassHandle | pass, |
| RHIPipelineState::PipelineStateDesc::Attachment::Blending const & | blending = {} |
||
| ) | const |
@breif Binds the backbuffer as the first Render Target.
This can be automatically bound to the pipeline with CmdBeginGraphics().
| void Renderer::BindBackbufferUAV | ( | PassHandle | pass, |
| int | set_index | ||
| ) | const |
Binds the backbuffer as RW access at binding 0 of set index.
| void Renderer::BindBufferCopyDst | ( | PassHandle | pass, |
| ResourceHandle | buffer | ||
| ) | const |
Declares that this pass will write to the buffer via copy.
This MUST be called before calling cmd->CopyBuffer(), etc. at Record time.
| void Renderer::BindBufferCopySrc | ( | PassHandle | pass, |
| ResourceHandle | buffer | ||
| ) | const |
Declares that this pass will read from the buffer via copy.
This MUST be called before calling cmd->CopyBuffer(), etc. at Record time.
| void Renderer::BindBufferIndirectRead | ( | PassHandle | pass, |
| ResourceHandle | buffer | ||
| ) | const |
Declares that this pass will consume this buffer as the source of an indirect draw/dispatch command.
This does not bind the buffer to any shader. You must call cmd->DrawIndirect(), cmd->DrawMeshTasksIndirect(), or cmd->DispatchIndirect() at Record time to consume it.
| void Renderer::BindBufferShaderRead | ( | PassHandle | pass, |
| ResourceHandle | buffer, | ||
| RHIPipelineStage | stage | ||
| ) | const |
Declares this pass has shaders that will read from this buffer. e.g. Vertex, Index.
This by itself has no effect on binding. You need to call cmd->BindVertexBuffer(), cmd->BindIndexBuffer() at Record time to use the buffer.
| void Renderer::BindBufferStorageRead | ( | PassHandle | pass, |
| ResourceHandle | buffer, | ||
| RHIPipelineStage | stage, | ||
| StringView | bind_point | ||
| ) | const |
Binds a read-only storage buffer to a specified binding point.
This is only available at Setup time.
Bind points are effectively shader variable names, which will be automatically dereferenced.
Multiple bind declarations to the same bind point will create array-style bindings, indexed by order of declaration.
This can be automatically bound to the pipeline with CmdSetPipeline()
| void Renderer::BindBufferUniform | ( | PassHandle | pass, |
| ResourceHandle | buffer, | ||
| RHIPipelineStage | stage, | ||
| StringView | bind_point | ||
| ) | const |
Binds a uniform buffer to a specified binding point in a rendering pass.
This is only available at Setup time.
Bind points are effectively shader variable names, which will be automatically dereferenced.
Multiple bind declarations to the same bind point will create array-style bindings, indexed by order of declaration.
This can be automatically bound to the pipeline with CmdSetPipeline()
| void Renderer::BindBufferUnordered | ( | PassHandle | pass, |
| ResourceHandle | buffer, | ||
| RHIPipelineStage | stage, | ||
| StringView | bind_point | ||
| ) | const |
Binds a buffer for unordered (UAV) access from shaders (read and/or write in any order).
This is only available at Setup time.
Bind points are effectively shader variable names, which will be automatically dereferenced.
Multiple bind declarations to the same bind point will create array-style bindings, indexed by order of declaration.
This can be automatically bound to the pipeline with CmdSetPipeline()
| void Renderer::BindDescriptorSetRead | ( | PassHandle | pass, |
| StringView | bind_point, | ||
| RHIDeviceDescriptorSetLayout * | layout | ||
| ) |
Binds an externally managed descriptor set that this pass reads.
This creates an execution dependency from the last writer of the same layout. It does not transition or otherwise synchronize the descriptor set's resources. Call CmdBindDescriptorSet at Record time to bind the set.
| void Renderer::BindDescriptorSetWrite | ( | PassHandle | pass, |
| RHIDeviceDescriptorSetLayout * | layout, | ||
| RHIDeviceDescriptorSetLayout * | reading_layout = nullptr |
||
| ) |
Declares an external descriptor-set write without binding it to a pipeline.
This only establishes pass dependencies. Resource transitions remain the caller's responsibility.
| void Renderer::BindDescriptorSetWrite | ( | PassHandle | pass, |
| StringView | bind_point, | ||
| RHIDeviceDescriptorSetLayout * | layout, | ||
| RHIDeviceDescriptorSetLayout * | reading_layout = nullptr |
||
| ) |
Binds an externally managed descriptor set that this pass writes.
This creates an execution dependency from the previous writer of the same layout. It does not transition or otherwise synchronize the descriptor set's resources. Call CmdBindDescriptorSet at Record time to bind the set.
| reading_layout | If provided, the Renderer will ensure this pass become the new writer of reading_layout as well as a dependency of the last writer of reading_layout and layout. |
| void Renderer::BindPass | ( | PassHandle | pass, |
| PassHandle | other | ||
| ) |
Declares an inter-pass dependency, where the other pass should execute-before the current pass.
| void Renderer::BindPushConstant | ( | PassHandle | pass, |
| RHIShaderStage | stage, | ||
| size_t | offset, | ||
| size_t | size | ||
| ) | const |
Declares a range of Push Constant used in a stage.
This is only available at Setup time.
You MUST bind a valid range if Push Constants are used in shaders, i.e. before calling CmdSetPushConstant()
| void Renderer::BindShader | ( | PassHandle | pass, |
| RHIShaderStage | stage, | ||
| StringView | entry_point, | ||
| StringView | shader_path, | ||
| Span< const char > | specializationData = {}, |
||
| uint32_t | rtHitGroupIndex = 0, |
||
| RHIPipelineState::PipelineStateDesc::RayTracingHitGroupType | rtHitGroupType = RHIPipelineState::PipelineStateDesc::RayTracingHitGroupType::Triangles |
||
| ) | const |
Binds shader file path to a certain pass at a certain stage.
This is only available at Setup time. No allocation, or parsing of shader is performed until EndSetup() is called.
Shaders are unique per stage, and may be omitted e.g. there's only a copy.
| specializationData | Binary blob of specialization data, if any. Must be bound in shader at ID 0, offset 0. |
| void Renderer::BindTextureCopyDst | ( | PassHandle | pass, |
| ResourceHandle | texture, | ||
| RHITextureSubresourceRange const & | range = {} |
||
| ) | const |
Declares that this pass will write to the texture via copy / blit (transfer destination).
Sets TransferWrite access over the specified subresource range (all if empty). No view is created; raw resource state tracking is updated.
| void Renderer::BindTextureCopySrc | ( | PassHandle | pass, |
| ResourceHandle | texture, | ||
| RHITextureSubresourceRange const & | range = {} |
||
| ) | const |
Declares that this pass will read from the texture via copy / blit (transfer source).
Sets TransferRead access over the specified subresource range (all if empty). No view is created; raw resource state tracking is updated.
| void Renderer::BindTextureDSV | ( | PassHandle | pass, |
| ResourceHandle | texture, | ||
| RHITextureViewDesc const & | desc, | ||
| bool | readOnly = false |
||
| ) | const |
Binds a texture as a Depth-Stencil View for a graphics pass.
Only one DSV may be active per pass. Layout transitions include depth / stencil write or read. Returns the created/assigned view handle (auto-created if needed).
This can be automatically bound to the pipeline with CmdBeginGraphics().
| void Renderer::BindTextureRTV | ( | PassHandle | pass, |
| ResourceHandle | texture, | ||
| RHITextureViewDesc const & | desc, | ||
| RHIPipelineState::PipelineStateDesc::Attachment::Blending const & | blending = {} |
||
| ) | const |
Binds a texture as a Render Target View (color attachment) for a graphics pass.
The pass must execute on a graphics-capable queue. Multiple RTVs may be bound. Returns the created/assigned view handle (auto-created if needed).
This can be automatically bound to the pipeline with CmdBeginGraphics().
The order of multiple render targets is the same as the insertion order of the RTVs.
| void Renderer::BindTextureSampler | ( | PassHandle | pass, |
| ResourceHandle | sampler, | ||
| StringView | bind_point | ||
| ) | const |
Binds a sampler to the shader.
Bind points are effectively shader variable names, which will be automatically dereferenced.
Multiple bind declarations to the same bind point will create array-style bindings, indexed by order of declaration.
| void Renderer::BindTextureShaderRead | ( | PassHandle | pass, |
| ResourceHandle | texture, | ||
| RHIPipelineStage | stage, | ||
| RHITextureSubresourceRange const & | range | ||
| ) | const |
Declares a shader read dependency for a texture without creating an internal binding.
Use this when an external descriptor set samples a renderer-managed texture.
| void Renderer::BindTextureSRV | ( | PassHandle | pass, |
| ResourceHandle | texture, | ||
| StringView | bind_point, | ||
| RHIPipelineStage | stage, | ||
| RHITextureViewDesc const & | desc | ||
| ) | const |
Binds a texture as a Shader Resource View (read-only sampling / fetch).
Bind points are effectively shader variable names, which will be automatically dereferenced.
Multiple bind declarations to the same bind point will create array-style bindings, indexed by order of declaration.
No view is created until EndSetup() is called.
| void Renderer::BindTextureUAV | ( | PassHandle | pass, |
| ResourceHandle | texture, | ||
| StringView | bind_point, | ||
| RHIPipelineStage | stage, | ||
| RHITextureViewDesc const & | desc | ||
| ) | const |
Binds a texture for unordered (UAV) read-write access in shaders.
Bind points are effectively shader variable names, which will be automatically dereferenced.
Multiple bind declarations to the same bind point will create array-style bindings, indexed by order of declaration.
Declares ShaderRead | ShaderWrite access and sets layout to General (or equivalent), bound as StorageImage, and creates a view.
No view is created until EndSetup() is called.
| void Renderer::BindVertexInput | ( | PassHandle | pass, |
| RHIPipelineState::PipelineStateDesc::VertexInput const & | info | ||
| ) | const |
Associates Vertex Input description with this pass.
This is only available at Setup time.
This only applies to passes on Graphics queues. And will CHECK otherwise.
You MUST bind a valid VertexInput at creation time if cmd->Draw[Indexed] is used.
This can be automatically bound to the pipeline with CmdBeginGraphics().
|
private |
|
private |
| void Renderer::CmdBeginGraphics | ( | PassHandle | pass, |
| RHICommandList * | cmd, | ||
| RHIExtent2D const & | extent, | ||
| Span< const RHIColorAttachmentLoad > | rtv_loads = {}, |
||
| RHIDepthAttachmentLoad | dsv_load = {RHIAttachmentLoadOp::Clear, {0.0f, 0u}} |
||
| ) |
Helper that pushes correct descriptor sets and PSO to the current command list, and pushes correct BeginGraphics() commands with declared RTVs and DSVs to the current command list.
| void Renderer::CmdBindDescriptorSet | ( | PassHandle | pass, |
| RHICommandList * | cmd, | ||
| StringView | bind_point, | ||
| RHIDeviceDescriptorSet * | descriptor_set | ||
| ) | const |
Helper that binds a single descriptor set to the set of the specified bind point.
| void Renderer::CmdBindDescriptorSet | ( | PassHandle | pass, |
| RHICommandList * | cmd, | ||
| uint32_t | set_index, | ||
| RHIDeviceDescriptorSet * | descriptor_set | ||
| ) | const |
Helper that binds a single descriptor set to the current command list.
| void Renderer::CmdDispatch | ( | PassHandle | pass, |
| RHICommandList * | cmd, | ||
| RHIExtent3D | thread_size | ||
| ) | const |
Helper that dispatches a compute shader with the specified THREAD count.
This is equivalent to calling:
| RHIExtent3D Renderer::CmdGetComputeLocalSize | ( | PassHandle | pass | ) | const |
Helper that retrieves the local size declared by a compute pass.
Calling this on a non-CS/Task/Mesh bound queue is incorrect, and will CHECK.
| void Renderer::CmdSetPipeline | ( | PassHandle | pass, |
| RHICommandList * | cmd | ||
| ) | const |
Helper that sets the current pass's PSO and descriptor sets to the current command list.
|
inline |
Helper that sets a Push Constant range data with a single l-value.
|
inline |
Create a render pass from a Setup(Renderer*, PassHandle) and Record(Renderer*, PassHandle, RHICommandList*) lambda.
NOTE: Prefer using this over CreatePass<T>() for stateless passes
This can be called inside a pass's Setup() function, or after CreatePass() but before EndSetup().
| queue | Queue to prefer running this pass in - this is a hint, and might be ignored if async compute is disabled. |
| priority | Priority of this pass. Higher priority passes are scheduled earlier. |
| setup | Lambda of type void(PassHandle self, Renderer*) called at Setup time. |
| record | Lambda of type void(PassHandle self, Renderer*, RHICommandList*) called at Record time. |
|
inline |
Create a render pass from a RenderPass* implementation and add it to the render graph.
This is only available at Setup time.
| T | Type of RenderPass to create. |
| queue | Queue to prefer running this pass in - this is a hint, and might be ignored if async compute is disabled. |
| priority | Priority of this pass. Higher priority passes are scheduled earlier. |
|
inline |
Create a new resource to be used in the render graph.
This is only available at Setup time. No allocation is performed until EndSetup() is called.
All resources created by a pass that is not culled will be created, regardless of usage.
Resources can be imported by passing in RHIDeviceHandle<RHIBuffer> or RHIDeviceHandle<RHITexture>.
| desc | Resources can be created by passing in RHIBufferDesc, RHITextureDesc, RHIAccelerationStructureDesc and can be imported by passing in RHIBuffer*, RHITexture*, RHIAccelerationStructure*. |
| ResourceHandle Renderer::CreateSampler | ( | RHIDeviceSampler::SamplerDesc const & | desc | ) | const |
Creates a sampler with the specified name and descriptor.
This is only available at Setup time. No allocation is performed until EndSetup() is called.
createSampler() should be generally preferred over this.
|
private |
|
private |
| String Renderer::DbgDumpActivePasses | ( | ) | const |
| String Renderer::DbgDumpExecutionGroups | ( | ) | const |
| String Renderer::DbgDumpGraphviz | ( | ) | const |
| void Renderer::DbgGetMemoryStatistics | ( | Vector< MemoryStat > & | outStats | ) | const |
| void Renderer::DbgGetTexturePreviews | ( | Vector< TexturePreviewStat > & | outStats | ) | const |
| Span< const uint64_t > Renderer::DbgProfilePassTiming | ( | uint64_t | sync, |
| float & | resolutionNS | ||
| ) | const |
Retrieves timings for all passes executed in the last frame associated with the specified sync index. The values are refreshed upon BeginExecute() call.
|
private |
Explicitly declares that this pass will access the buffer in the specified stage with the specified access.
This is only available at Setup time.
This does not bind the buffer to any shader - use BindBuffer...() for that.
|
private |
Declares that this pass will access the texture in the specified stage with the specified access.
This is only available at Setup time.
This does not bind the texture to any shader - use BindTexture...() for that.
|
inline |
Dereference the built descriptor sets associated with a given pass.
|
inline |
Dereference the automatically built pipeline state object handle associated with a given pass.
|
inline |
Dereference a resource handle to its underlying RHI resource.
This should only be called inside a pass's Record() function, or after EndSetup().
|
inline |
Dereference a sampler handle to its underlying RHI sampler.
This should only be called inside a pass's Record() function, or after EndSetup().
|
inline |
Dereference a texture view handle to its underlying RHI texture view.
This should only be called inside a pass's Record() function, or after EndSetup().
| void Renderer::EndExecute | ( | ) |
Ends the execution phase and performs GPU submission.
| Core::JobBarrier Renderer::EndSetup | ( | bool | wait = true | ) |
Finish setting up the render graph.
The last created pass is used as the epilogue (final) pass, and will be used to determine active passes and resource lifetimes.
You must call this before Execute().
| wait | Wait for pipeline state compilation before returning. |
|
private |
| thread_id | -1 for main thread, [0, kRecordThreadpoolSize] for workers |
|
private |
Executes barriers for an acceleration structure.
|
private |
Executes barriers for a whole buffer.
|
private |
Executes all barriers for a pass.
|
private |
Executes barriers for a subresource range of a texture.
|
private |
| void Renderer::ExecuteFrame | ( | ) |
Executes all passes in the render graph for one frame.
This includes recording command lists and submitting them to the appropriate queues. When a swapchain is bound, the last submit waits on the acquire semaphore and signals the render-complete semaphore; the caller must Present afterward.
|
inlineprivate |
Helper to get the queue index of a queue type.
|
private |
|
private |
|
inline |
|
inline |
Get the RHIApplication this Renderer was constructed with.
|
inline |
Get the RHIDevice this Renderer was constructed with.
|
inline |
Retrieves the current frame number.
This value is updated at EndExecute(), and is guaranteed to be monotonic.
|
inline |
Get the number of frames that can be simultaneously in-flight.
| RHIDeviceHandle< RHIDeviceSemaphore > Renderer::GetRenderCompleteSemaphore | ( | ) | const |
Binary semaphore signaled when GPU work for the current swap image is complete.
|
inline |
Retrieves the current state of the renderer.
|
inline |
Retrieves the current swap index at the time of ExecuteFrame().
This value is associated with the current frame in flight. It's guaranteed to be less than GetFrameSwaps(), and starts from 0.
|
inline |
Returns the currently used RHISwapchain object.
|
inline |
Get the current swapchain extents.
|
inline |
Get the current swapchain extents as a 3D extent with depth 1.
|
inline |
Retrieves the current synchronization index.
This value is associated with the current synchronization primitives at the current time. It's guaranteed to be less than GetFrameSwaps(), and starts from 0.
|
inline |
Retrieves an internal tracked pass associated with the given handle, read-only.
|
inline |
Returns whether async compute is enabled.
If this returns false, all passes will be executed on the graphics queue, and any queue hints passed during pass creation will be ignored.
|
inline |
Returns whether a swapchain is bound.
If this returns false, the Renderer is headless: no backbuffer waits/signals are scheduled, and any passes that attempt to bind the backbuffer (BindBackbufferRTV / BindBackbufferUAV) will CHECK at setup time.
Acquire/Present are always the caller's responsibility when a swapchain is bound.
| void Renderer::MakePassUncullable | ( | PassHandle | pass | ) | const |
Marks a pass as "uncullable", meaning it will always be executed even if it has no dependencies.
This is useful for passes that produces resources that's only used on the next frame, or have side effects that are not tracked by the Renderer, e.g. async readback, timestamp queries, etc.
| void Renderer::PassSetRasterizerFlags | ( | PassHandle | pass, |
| RHIPipelineState::PipelineStateDesc::Rasterizer const & | rasterizer = {}, |
||
| RHIPipelineState::PipelineStateDesc::DepthStencil const & | depth_stencil = {} |
||
| ) | const |
Sets the rasterizer and depth-stencil state for a graphics pass.
If shaders are bound to the pass, a pipeline state object will be automatically created. The parameters here will be used for the PSO creation, instead of the defaults.
| void Renderer::PassSetTopology | ( | PassHandle | pass, |
| RHIPipelineState::PipelineStateDesc::Topology | topology | ||
| ) | const |
Sets the input assembly topology for a graphics pass (TriangleList, LineList, etc.).
|
private |
Sets backbuffer views and sync primitives.
| void Renderer::SetSwapchain | ( | RHIDeviceHandle< RHISwapchain > | swapchain | ) |
Update the swapchain to a new one. You must call this when the window is resized or the swapchain is invalidated.
| void Renderer::WaitForFrame | ( | ) |
Blocks until the most recently submitted frame has finished executing on the GPU.
This waits on the graphics / compute fences associated with the previous frame (i.e. the frame submitted by the last EndExecute() call), without resetting them or advancing any per-frame state.
Typical use cases:
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |