Foundation
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Foundation::RenderCore::Renderer Class Reference

Renderer implementing a Frame Graph system with automatic resource tracking and synchronization. More...

#include <Renderer.hpp>

Classes

struct  ExecutePerThreadCommandLists
 
struct  FrameSyncObjects
 
struct  RendererSetup
 Helper class containing all states pertaining to Renderer's Setup phase. More...
 

Public Types

enum class  State { Undefined , Setup , PostSetup , Execute }
 

Public Member Functions

 Renderer ()=delete
 
 Renderer (RendererDesc const &desc, RHIApplicationHandle< RHIDevice > device, RHIDeviceHandle< RHISwapchain > swapchain, 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, const char *shader_path, Span< const char > specializationData={}) 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 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 BindDescriptorSet (PassHandle pass, StringView bind_point, RHIDeviceDescriptorSetLayout *layout)
 Manually bind an existing descriptor set (layout) to the pipeline.
 
ResourceHandle 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).
 
ResourceHandle 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.
 
ResourceHandle 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.
 
ResourceHandle BindTextureDSV (PassHandle pass, ResourceHandle texture, RHITextureViewDesc const &desc) 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 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 EndSetup ()
 Finish setting up the render graph.
 
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 * > DerefResource (const ResourceHandle handle) const
 Dereference a resource handle to its underlying RHI resource.
 
RHITextureViewDerefTextureView (const ResourceHandle handle) const
 Dereference a texture view handle to its underlying RHI texture view.
 
RHIDeviceSamplerDerefSampler (const ResourceHandle handle) const
 Dereference a sampler handle to its underlying RHI sampler.
 
RHIPipelineStateDerefPipelineState (const PassHandle pass) const
 Dereference the automatically built pipeline state object handle associated with a given pass.
 
Vector< RHIDeviceDescriptorSet * > constDerefDescriptorSets (const PassHandle pass) const
 Dereference the built descriptor sets associated with a given pass.
 
AllocatorGetAllocator () 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 Optional< RHIClearColor > > clear_rtv={}, Optional< RHIClearDepthStencil > const &clear_dsv=RHIClearDepthStencil{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 constGetTrackedPass (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 the swapchain is enabled.
 
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.
 
void BeginExecute ()
 Resets the temporary execution allocator , and waits for the possibly multi-buffered next frame to finish rendering.
 
void ExecuteFrame ()
 Executes all passes in the render graph for one frame.
 
void EndExecute ()
 Ends the execution phase and performs GPU submission, possibly with a RHIDeviceQueue::Present.
 
String DbgDumpGraphviz () const
 
String DbgDumpActivePasses () const
 
String DbgDumpExecutionGroups () const
 
Span< const uint64_tDbgProfilePassTiming (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.
 
uint64_t DbgProfilePresentTiming (uint64_t sync, float &resolutionNS) const
 Retrieves the total ticks between two subsequent swapchain presents by EndExecute, measured on CPU with system's high-resolution timer. The value is refreshed upon EndExecute() call.
 

Private Types

using ExecuteBarrierList = Vector< Pair< Variant< RHIBuffer *, RHITexture * >, 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)
 
void BuildPipelineStateAll ()
 
void FinalizeResources ()
 
void FinalizePasses ()
 
RHICommandListExecuteAllocateCommandList (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 ExecuteBarriers (TrackedPass &pass, ExecuteBarrierPCmdOrPBarrierList cmd)
 Executes all barriers for a pass.
 
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.
 

Private Attributes

State mState
 
AllocatormAllocator {nullptr}
 
const RendererDesc mDesc {}
 
uint64_t mFrameSwapped {0}
 
uint32_t mFrameSwaps {1}
 
uint32_t mCurrentSync {0}
 
uint32_t mCurrentSwap {0}
 
UniquePtr< ExecuteResourcesmResources
 
RHIDeviceScopedHandle< RHIDeviceDescriptorPoolmDescPool
 
Mutex mDescPoolMutex
 
RHIDeviceScopedHandle< RHIDeviceDescriptorPoolmSwapDescriptorPool
 
RHIDeviceScopedHandle< RHIDeviceDescriptorSetLayoutmSwapDescriptorSetLayout
 
Vector< FrameSyncObjectsmSwaps
 
RHIDeviceScopedHandle< RHIDeviceSemaphoremGraphicsTimeline {}
 
RHIDeviceScopedHandle< RHIDeviceSemaphoremComputeTimeline {}
 
RHIApplicationHandle< RHIDevicemDevice {}
 
RHIDeviceHandle< RHISwapchainmSwapchain {}
 
RHIDeviceQueuemGraphicsQueue {}
 
RHIDeviceQueuemComputeQueue {}
 
UniquePtr< RendererSetupmSetup
 
ScopedArena mExecuteArena
 
AllocatorStack mExecuteAlloc
 
Vector< Pair< RHIDeviceQueueType, RHIDeviceQueue::SubmitDesc > > * mExecuteSubmits
 
ThreadPool mExecuteThreadPool
 
Vector< Vector< UniquePtr< ExecutePerThreadCommandLists > > > mExecutePerSwapCmds
 
RHIDeviceIdleGuard mWaitIdle
 

Detailed Description

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.

Member Typedef Documentation

◆ ExecuteBarrierList

◆ ExecuteBarrierPCmdOrPBarrierList

Member Enumeration Documentation

◆ State

Enumerator
Undefined 
Setup 
PostSetup 
Execute 

Constructor & Destructor Documentation

◆ Renderer() [1/2]

Foundation::RenderCore::Renderer::Renderer ( )
delete

◆ Renderer() [2/2]

Renderer::Renderer ( RendererDesc const desc,
RHIApplicationHandle< RHIDevice device,
RHIDeviceHandle< RHISwapchain swapchain,
Allocator allocator 
)

Member Function Documentation

◆ BeginExecute()

void Renderer::BeginExecute ( )

Resets the temporary execution allocator , and waits for the possibly multi-buffered next frame to finish rendering.

See also GetSync(), GetSwap()

Note
This MUST be called before entering Execute* functions.

◆ BeginSetup()

void Renderer::BeginSetup ( )

Begins the setup phase of the render graph.

Note
You MUST call this before any other Create..., Bind..., or Declare... functions.

◆ BindBackbufferRTV()

void Renderer::BindBackbufferRTV ( PassHandle  pass,
RHIPipelineState::PipelineStateDesc::Attachment::Blending const blending = {} 
) const

@breif Binds the backbuffer as the first Render Target.

Note
If this is used, the first RTV will always be the Backbuffer itself.
   This can be automatically bound to the pipeline with CmdBeginGraphics().

◆ BindBackbufferUAV()

void Renderer::BindBackbufferUAV ( PassHandle  pass,
int  set_index 
) const

Binds the backbuffer as RW access at binding 0 of set index.

◆ BindBufferCopyDst()

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.

◆ BindBufferCopySrc()

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.

◆ BindBufferShaderRead()

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.

◆ BindBufferStorageRead()

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.

This can be automatically bound to the pipeline with CmdSetPipeline()

◆ BindBufferUniform()

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.

This can be automatically bound to the pipeline with CmdSetPipeline()

◆ BindBufferUnordered()

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.

This can be automatically bound to the pipeline with CmdSetPipeline()

◆ BindDescriptorSet()

void Renderer::BindDescriptorSet ( PassHandle  pass,
StringView  bind_point,
RHIDeviceDescriptorSetLayout layout 
)

Manually bind an existing descriptor set (layout) to the pipeline.

Note
This applies to the bind point's whole set. You'll need to call CmdBindDescriptorSet at Record time to bind the set to the pipeline.

◆ BindPass()

void Renderer::BindPass ( PassHandle  pass,
PassHandle  other 
)

Declares an inter-pass dependency, where the other pass should execute-before the current pass.

Note
This is especially useful with passes without in-graph resource dependency, or the transitions are difficult to track within the Renderer. The ordering is enforced on recording, and on device execution.

◆ BindPushConstant()

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()

◆ BindShader()

void Renderer::BindShader ( PassHandle  pass,
RHIShaderStage  stage,
StringView  entry_point,
const char shader_path,
Span< const char specializationData = {} 
) 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.

Parameters
specializationDataBinary blob of specialization data, if any. Must be bound in shader at ID 0, offset 0.

◆ BindTextureCopyDst()

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.

◆ BindTextureCopySrc()

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.

◆ BindTextureDSV()

ResourceHandle Renderer::BindTextureDSV ( PassHandle  pass,
ResourceHandle  texture,
RHITextureViewDesc const desc 
) 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().

◆ BindTextureRTV()

ResourceHandle 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.

◆ BindTextureSampler()

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.

◆ BindTextureSRV()

ResourceHandle 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.

No view is created until EndSetup() is called.

◆ BindTextureUAV()

ResourceHandle 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.

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.

◆ BindVertexInput()

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 throw 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().

◆ BuildPipelineState()

void Renderer::BuildPipelineState ( PassHandle  pass)
private

◆ BuildPipelineStateAll()

void Renderer::BuildPipelineStateAll ( )
private

◆ CmdBeginGraphics()

void Renderer::CmdBeginGraphics ( PassHandle  pass,
RHICommandList cmd,
RHIExtent2D const extent,
Span< const Optional< RHIClearColor > >  clear_rtv = {},
Optional< RHIClearDepthStencil > const clear_dsv = RHIClearDepthStencil{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.

Note
: There MUST be a matching RHICommandList::EndGraphics() call AFTER calling this, or the behaviour is undefined.
: The Pipeline state MUST be set with CmdSetPipeline() AFTER calling this, or the behaviour is undefined.

◆ CmdBindDescriptorSet() [1/2]

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.

Note
For this to work, the descriptor set MUST have been bound at Setup time with BindDescriptorSet().

◆ CmdBindDescriptorSet() [2/2]

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.

◆ CmdDispatch()

void Renderer::CmdDispatch ( PassHandle  pass,
RHICommandList cmd,
RHIExtent3D  thread_size 
) const

Helper that dispatches a compute shader with the specified THREAD count.

Note
To dispatch groups - use RHICommandList::Dispatch as is!
A valid CmdSetPipeline call MUST be made before this, or the behaviour is undefined.

This is equivalent to calling:

cmd->Dispatch(
);
RHIExtent3D CmdGetComputeLocalSize(PassHandle pass) const
Helper that retrieves the local size declared by a compute pass.
Definition Renderer.cpp:1696
T * Construct(Allocator *resource, Args &&...args)
Convenience placement new with object of type T using a Foundation::Core::Allocator.
Definition Allocator.hpp:149

◆ CmdGetComputeLocalSize()

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 throw.

◆ CmdSetPipeline()

void Renderer::CmdSetPipeline ( PassHandle  pass,
RHICommandList cmd 
) const

Helper that sets the current pass's PSO and descriptor sets to the current command list.

◆ CmdSetPushConstant()

template<typename T >
void Foundation::RenderCore::Renderer::CmdSetPushConstant ( PassHandle  pass,
RHICommandList cmd,
RHIShaderStage  stage,
size_t  offset,
T const data 
)
inline

Helper that sets a Push Constant range data with a single l-value.

Note
A valid CmdSetPipeline call MUST be made before this, or the behaviour is undefined.
The stage param must overlap with at least one stage that the PSO was created with, and must be a subset of a range declared with BindPushConstant(), or the behaviour is undefined.

◆ CreatePass()

PassHandle Foundation::RenderCore::Renderer::CreatePass ( StringView  name,
RHIDeviceQueueType  queue,
size_t  priority,
FSetup &&  setup,
FRecord &&  record 
)
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().

Parameters
queueQueue to prefer running this pass in - this is a hint, and might be ignored if async compute is disabled.
priorityPriority of this pass. Higher priority passes are scheduled earlier.
setupLambda of type void(PassHandle self, Renderer*) called at Setup time.
recordLambda of type void(PassHandle self, Renderer*, RHICommandList*) called at Record time.

◆ CreatePassImpl()

template<typename T , typename... Args>
requires std::is_base_of_v<RenderPass, T>
PassHandle Foundation::RenderCore::Renderer::CreatePassImpl ( StringView  name,
RHIDeviceQueueType  queue,
size_t  priority,
Args &&...  args 
)
inline

Create a render pass from a RenderPass* implementation and add it to the render graph.

This is only available at Setup time.

Template Parameters
TType of RenderPass to create.
Parameters
queueQueue to prefer running this pass in - this is a hint, and might be ignored if async compute is disabled.
priorityPriority of this pass. Higher priority passes are scheduled earlier.

◆ CreateResource()

template<typename T >
ResourceHandle Foundation::RenderCore::Renderer::CreateResource ( StringView  name,
T const desc 
)
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 RHIDeviceRef<RHIBuffer> or RHIDeviceRef<RHITexture>.

Parameters
descResources can be created by passing in RHIBufferDesc, RHITextureDesc, and can be imported by passing in RHIDeviceRef<RHIBuffer>, RHIDeviceRef<RHITexture>, or raw, pinned pointers RHIBuffer*, or RHITexture*
Note
ALWAYS ENSURE that your IMPORTED resources OUTLIVE the Renderer. There's NO reference counting or tracking of the underlying resource lifetime.

◆ CreateSampler()

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.

◆ CreateTextureView()

ResourceHandle Renderer::CreateTextureView ( PassHandle  pass,
ResourceHandle  handle,
RHITextureViewDesc const desc 
) const
private

◆ CullPasses()

void Renderer::CullPasses ( PassHandle  epilogue) const
private

◆ DbgDumpActivePasses()

String Renderer::DbgDumpActivePasses ( ) const

◆ DbgDumpExecutionGroups()

String Renderer::DbgDumpExecutionGroups ( ) const

◆ DbgDumpGraphviz()

String Renderer::DbgDumpGraphviz ( ) const

◆ DbgProfilePassTiming()

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.

Note
The values are laid out as follows: [pass 0 start tick] [pass 0 end tick] [pass 1 start tick] [pass 1 end tick] ...
A span of size 0 is ALWAYS returned if no timing information is available.

◆ DbgProfilePresentTiming()

uint64_t Renderer::DbgProfilePresentTiming ( uint64_t  sync,
float resolutionNS 
) const

Retrieves the total ticks between two subsequent swapchain presents by EndExecute, measured on CPU with system's high-resolution timer. The value is refreshed upon EndExecute() call.

◆ DeclareBufferAccess()

void Renderer::DeclareBufferAccess ( PassHandle  pass,
ResourceHandle  handle,
RHIPipelineStage  stage,
RHIResourceAccess  access = RHIResourceAccessBits::ShaderRead 
) const
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.

◆ DeclareTextureAccess()

void Renderer::DeclareTextureAccess ( PassHandle  pass,
ResourceHandle  handle,
RHIPipelineStage  stage,
RHITextureSubresourceRange  range = {},
RHIResourceAccess  access = RHIResourceAccessBits::ShaderRead,
RHITextureLayout  layout = RHITextureLayout::ShaderReadOnly 
) const
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.

◆ DerefDescriptorSets()

Vector< RHIDeviceDescriptorSet * > const & Foundation::RenderCore::Renderer::DerefDescriptorSets ( const PassHandle  pass) const
inline

Dereference the built descriptor sets associated with a given pass.

◆ DerefPipelineState()

RHIPipelineState * Foundation::RenderCore::Renderer::DerefPipelineState ( const PassHandle  pass) const
inline

Dereference the automatically built pipeline state object handle associated with a given pass.

◆ DerefResource()

Variant< RHIBuffer *, RHITexture * > Foundation::RenderCore::Renderer::DerefResource ( const ResourceHandle  handle) const
inline

Dereference a resource handle to its underlying RHI resource.

This should only be called inside a pass's Record() function, or after EndSetup().

Note
Passes that use DerefResource() on a resource that was not declared with Bind...() or Declare...() in the pass may be allowed, but the behaviour is undefined as the transitions will then not be tracked.
This returns a rvalue Variant - do not use a reference to the return value!

◆ DerefSampler()

RHIDeviceSampler * Foundation::RenderCore::Renderer::DerefSampler ( const ResourceHandle  handle) const
inline

Dereference a sampler handle to its underlying RHI sampler.

This should only be called inside a pass's Record() function, or after EndSetup().

◆ DerefTextureView()

RHITextureView * Foundation::RenderCore::Renderer::DerefTextureView ( const ResourceHandle  handle) const
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().

◆ EndExecute()

void Renderer::EndExecute ( )

Ends the execution phase and performs GPU submission, possibly with a RHIDeviceQueue::Present.

Note
This MUST be called after ExecuteFrame(), and before BeginExecuteImpl() of the next frame.
This function will block until all command list recording is finished, but will NOT wait for GPU.
Exceptions

ref RHISwapchainResizeException if swapchain is resized and has not been recreated.

◆ EndSetup()

void Renderer::EndSetup ( )

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().

◆ ExecuteAllocateCommandList()

RHICommandList * Renderer::ExecuteAllocateCommandList ( RHIDeviceQueueType  queue,
int  thread_id = -1 
)
private
Parameters
thread_id-1 for main thread, [0, kRecordThreadpoolSize] for workers
Note
The lifetime of the command list is only valid between ExecuteBegin calls. Proper CPU-GPU synchronization is required to avoid race.
Returns
A command list allocated from the appropriate pool only used for the specified thread_id (dense)

◆ ExecuteBarrierBuffer()

void Renderer::ExecuteBarrierBuffer ( PassHandle  pass,
TrackedResource res,
RHIResourceAccess  access,
RHIPipelineStage  stage,
ExecuteBarrierPCmdOrPBarrierList  cmd 
)
private

Executes barriers for a whole buffer.

◆ ExecuteBarriers()

void Renderer::ExecuteBarriers ( TrackedPass pass,
ExecuteBarrierPCmdOrPBarrierList  cmd 
)
private

Executes all barriers for a pass.

◆ ExecuteBarrierSubresource()

void Renderer::ExecuteBarrierSubresource ( PassHandle  pass,
TrackedResource res,
RHITextureSubresourceRange const range,
RHIResourceAccess  access,
RHIPipelineStage  stage,
RHITextureLayout  layout,
ExecuteBarrierPCmdOrPBarrierList  cmd 
)
private

Executes barriers for a subresource range of a texture.

◆ ExecuteBarrierSubresourceState()

void Renderer::ExecuteBarrierSubresourceState ( PassHandle  pass,
RHITexture res,
TrackedResource::SubresourceState sta,
RHIResourceAccess  access,
RHIPipelineStage  stage,
RHITextureLayout  layout,
ExecuteBarrierPCmdOrPBarrierList  cmd 
) const
private

◆ ExecuteFrame()

void Renderer::ExecuteFrame ( )

Executes all passes in the render graph for one frame.

This includes recording command lists, submitting them to the appropriate queues, and presenting the swapchain if enabled.

Note
This is asynchronously executed - the function will return once all passes have been scheduled for recording. EndExecute() is the synchronization point for the frame. Meaning - if work is required during the frame, you can do it after ExecuteFrame() and before EndExecute() to overlap recording work.
This MUST be called after BeginExecuteImpl(), and before EndExecuteImpl().
// With the above Execute... functions, a correct usage may look like this:
// ...Additional pre-frame logic...
// ...Additional post-frame logic...
void ExecuteFrame()
Executes all passes in the render graph for one frame.
Definition Renderer.cpp:1281
void BeginExecute()
Resets the temporary execution allocator , and waits for the possibly multi-buffered next frame to fi...
Definition Renderer.cpp:1059
void EndExecute()
Ends the execution phase and performs GPU submission, possibly with a RHIDeviceQueue::Present.
Definition Renderer.cpp:1565

◆ ExecuteGetQueueFamily()

uint32_t Foundation::RenderCore::Renderer::ExecuteGetQueueFamily ( RHIDeviceQueueType  queue) const
inlineprivate

Helper to get the queue index of a queue type.

◆ FinalizePasses()

void Renderer::FinalizePasses ( )
private

◆ FinalizeResources()

void Renderer::FinalizeResources ( )
private

◆ GetAllocator()

Allocator * Foundation::RenderCore::Renderer::GetAllocator ( ) const
inline
Returns
The backing general-purpose allocator used for the Renderer

◆ GetFrame()

uint64_t Foundation::RenderCore::Renderer::GetFrame ( ) const
inline

Retrieves the current frame number.

This value is updated at EndExecute(), and is guaranteed to be monotonic.

◆ GetFrameSwaps()

uint32_t Foundation::RenderCore::Renderer::GetFrameSwaps ( ) const
inline

Get the number of frames that can be simultaneously in-flight.

◆ GetState()

State Foundation::RenderCore::Renderer::GetState ( ) const
inline

Retrieves the current state of the renderer.

◆ GetSwap()

uint32_t Foundation::RenderCore::Renderer::GetSwap ( ) const
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.

Note
This value is updated at BeginExecute(), and remains the same until the next BeginExecute() call.
See also GetSync

◆ GetSwapchainExtent()

RHIExtent2D Foundation::RenderCore::Renderer::GetSwapchainExtent ( ) const
inline

Get the current swapchain extents.

◆ GetSwapchainExtent3D()

RHIExtent3D Foundation::RenderCore::Renderer::GetSwapchainExtent3D ( ) const
inline

Get the current swapchain extents as a 3D extent with depth 1.

◆ GetSync()

uint64_t Foundation::RenderCore::Renderer::GetSync ( ) const
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.

Note
Values this returns can be used to index into per-swap resources, and is guaranteed to be not used by the GPU with values acquired after BeginExecute(), and before EndExecute().
This value is updated at BeginExecute(), and remains the same until the next BeginExecute() call.
This value is guaranteed to be monotonic.

◆ GetTrackedPass()

TrackedPass const & Foundation::RenderCore::Renderer::GetTrackedPass ( PassHandle  pass)
inline

Retrieves an internal tracked pass associated with the given handle, read-only.

◆ IsAsyncComputeEnabled()

bool Foundation::RenderCore::Renderer::IsAsyncComputeEnabled ( ) const
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.

◆ IsPresentEnabled()

bool Foundation::RenderCore::Renderer::IsPresentEnabled ( ) const
inline

Returns whether the swapchain is enabled.

If this returns false, no backbuffer will be acquired or presented, and any passes that write to the backbuffer will throw at EndSetup() time.

◆ PassSetRasterizerFlags()

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.

◆ SetFrameSyncObjects()

void Renderer::SetFrameSyncObjects ( )
private

Sets backbuffer views and sync primitives.

◆ SetSwapchain()

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.

Note
This call will block if pending GPU work exists.
You may want to re-create the entire Renderer instead if your resources depend on the backbuffer size.

Member Data Documentation

◆ mAllocator

Allocator* Foundation::RenderCore::Renderer::mAllocator {nullptr}
private

◆ mComputeQueue

RHIDeviceQueue * Foundation::RenderCore::Renderer::mComputeQueue {}
private

◆ mComputeTimeline

RHIDeviceScopedHandle<RHIDeviceSemaphore> Foundation::RenderCore::Renderer::mComputeTimeline {}
private

◆ mCurrentSwap

uint32_t Foundation::RenderCore::Renderer::mCurrentSwap {0}
private

◆ mCurrentSync

uint32_t Foundation::RenderCore::Renderer::mCurrentSync {0}
private

◆ mDesc

const RendererDesc Foundation::RenderCore::Renderer::mDesc {}
private

◆ mDescPool

RHIDeviceScopedHandle<RHIDeviceDescriptorPool> Foundation::RenderCore::Renderer::mDescPool
private

◆ mDescPoolMutex

Mutex Foundation::RenderCore::Renderer::mDescPoolMutex
private

◆ mDevice

RHIApplicationHandle<RHIDevice> Foundation::RenderCore::Renderer::mDevice {}
private

◆ mExecuteAlloc

AllocatorStack Foundation::RenderCore::Renderer::mExecuteAlloc
private

◆ mExecuteArena

ScopedArena Foundation::RenderCore::Renderer::mExecuteArena
private

◆ mExecutePerSwapCmds

Vector<Vector<UniquePtr<ExecutePerThreadCommandLists> > > Foundation::RenderCore::Renderer::mExecutePerSwapCmds
private

◆ mExecuteSubmits

Vector<Pair<RHIDeviceQueueType, RHIDeviceQueue::SubmitDesc> >* Foundation::RenderCore::Renderer::mExecuteSubmits
private

◆ mExecuteThreadPool

ThreadPool Foundation::RenderCore::Renderer::mExecuteThreadPool
private

◆ mFrameSwapped

uint64_t Foundation::RenderCore::Renderer::mFrameSwapped {0}
private

◆ mFrameSwaps

uint32_t Foundation::RenderCore::Renderer::mFrameSwaps {1}
private

◆ mGraphicsQueue

RHIDeviceQueue* Foundation::RenderCore::Renderer::mGraphicsQueue {}
private

◆ mGraphicsTimeline

RHIDeviceScopedHandle<RHIDeviceSemaphore> Foundation::RenderCore::Renderer::mGraphicsTimeline {}
private

◆ mResources

UniquePtr<ExecuteResources> Foundation::RenderCore::Renderer::mResources
private

◆ mSetup

UniquePtr<RendererSetup> Foundation::RenderCore::Renderer::mSetup
private

◆ mState

State Foundation::RenderCore::Renderer::mState
private

◆ mSwapchain

RHIDeviceHandle<RHISwapchain> Foundation::RenderCore::Renderer::mSwapchain {}
private

◆ mSwapDescriptorPool

RHIDeviceScopedHandle<RHIDeviceDescriptorPool> Foundation::RenderCore::Renderer::mSwapDescriptorPool
private

◆ mSwapDescriptorSetLayout

RHIDeviceScopedHandle<RHIDeviceDescriptorSetLayout> Foundation::RenderCore::Renderer::mSwapDescriptorSetLayout
private

◆ mSwaps

Vector<FrameSyncObjects> Foundation::RenderCore::Renderer::mSwaps
private

◆ mWaitIdle

RHIDeviceIdleGuard Foundation::RenderCore::Renderer::mWaitIdle
private

The documentation for this class was generated from the following files: