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 (RendererDesc const &desc, RHIApplicationObjectHandle< RHIDevice > device, RHIDeviceObjectHandle< 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>
TCreatePassImpl (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 , typename FSkip = FSkipDefault>
LambdaPass< FSetup, FRecord, FSkip > * CreatePass (StringView name, RHIDeviceQueueType queue, size_t priority, FSetup &&setup, FRecord &&record, FSkip &&skip={})
 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 BindShader (PassHandle pass, RHIShaderStage stage, StringView entry_point, Native::Path const &shader_path) const
 Binds shader file path to a certain pass at a certain stage.
 
void BindDescriptorBindPoint (PassHandle pass, StringView bind_point, uint32_t binding, uint32_t set)
 Declares that a bind point in a certain pass is a descriptor set at the specified set and binding index. This is only useful if you don't have control over the shader code, and cannot rely on automatic reflection. You can use the same bind point name with subsequent BindTextureSRV, etc. calls.
 
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, RHIDeviceDescriptorSet *descriptor_set, RHIDeviceDescriptorSetLayout *layout)
 Manually bind an existing descriptor set 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
 Declares that this pass will write to the current (at Record time) swapchain backbuffer.
 
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.
 
RHITextureViewDerefCurrentBackbufferView (const PassHandle pass) const
 Returns a pointer to the current backbuffer texture view.
 
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 TOTAL 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 index, RHIDeviceDescriptorSet *descriptor_set) const
 Helper that binds a single descriptor set to the current command list.
 
void CmdBeginGraphics (PassHandle pass, RHICommandList *cmd, RHIExtent2D const &extent, Optional< RHIClearColor > const &clear_rtv=RHIClearColor{}, Optional< RHIClearDepthStencil > const &clear_dsv=RHIClearDepthStencil{1.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.
 
bool IsAsyncComputeEnabled () const
 Returns whether async compute is enabled.
 
bool IsPresentEnabled () const
 Returns whether the swapchain is enabled.
 
void SetSwapchain (RHIDeviceObjectHandle< 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 prepares for the next frame.
 
String DbgDumpGraphviz () const
 
String DbgDumpActivePasses () const
 
String DbgDumpExecutionGroups () const
 

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 FinalizeResources ()
 
void FinalizePSOs ()
 
RHICommandListExecuteAllocateCommandList (RHIDeviceQueueType queue, int thread_id)
 
uint32_t ExecuteGetQueueIndex (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 ExecuteAcquireQueueResources (RHIDeviceQueueType currentQueue, size_t groupIndex, RHICommandList *cmd)
 Acquires resources for the current group.
 
void ExecuteReleaseQueueResources (RHIDeviceQueueType currentQueue, size_t groupIndex, RHICommandList *cmd)
 Performs transitions that's otherwise impossible (e.g. Fragment -> Compute) for the next group, and releases resources for the current group.
 
void SetFrameSyncObjects ()
 
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
 
RHIDeviceScopedObjectHandle< RHIDeviceDescriptorPoolmDescPool
 
Async::Mutex mDescPoolMutex
 
Vector< FrameSyncObjectsmSwaps
 
RHIDeviceScopedObjectHandle< RHIDeviceSemaphoremGraphicsTimeline {}
 
RHIDeviceScopedObjectHandle< RHIDeviceSemaphoremComputeTimeline {}
 
RHIApplicationObjectHandle< RHIDevicemDevice {}
 
RHIDeviceObjectHandle< RHISwapchainmSwapchain {}
 
RHIDeviceQueuemGraphicsQueue {}
 
RHIDeviceQueuemComputeQueue {}
 
UniquePtr< RendererSetupmSetup
 
ScopedArena mExecuteArena
 
StackAllocator mExecuteAlloc
 
Vector< RHIDeviceQueue::SubmitDesc > * mExecuteGraphicsSubmits {}
 
Vector< RHIDeviceQueue::SubmitDesc > * mExecuteComputeSubmits {}
 
Async::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()

Renderer::Renderer ( RendererDesc const desc,
RHIApplicationObjectHandle< RHIDevice device,
RHIDeviceObjectHandle< 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

Declares that this pass will write to the current (at Record time) swapchain backbuffer.

Note
This invalidates any other bound RTVs. With this enabled, existence of other RTVs will throw at EndSetup() time.

You can retrieve the current backbuffer RTV via DerefCurrentBackbufferView() at Record time.

This can be automatically bound to the pipeline with CmdBeginGraphics().

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

Note
bind_point may be ignored if shader usage is not required. For readability, you may use kBindpointIgnored as the bind_point to indicate that the actual bind point is not known or not important.

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

Note
bind_point may be ignored if shader usage is not required. For readability, you may use kBindpointIgnored as the bind_point to indicate that the actual bind point is not known or not important.

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

Note
bind_point may be ignored if shader usage is not required. For readability, you may use kBindpointIgnored as the bind_point to indicate that the actual bind point is not known or not important.

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

Note
bind_point may be ignored if shader usage is not required. For readability, you may use kBindpointIgnored as the bind_point to indicate that the actual bind point is not known or not important.

◆ BindDescriptorBindPoint()

void Renderer::BindDescriptorBindPoint ( PassHandle  pass,
StringView  bind_point,
uint32_t  binding,
uint32_t  set 
)

Declares that a bind point in a certain pass is a descriptor set at the specified set and binding index. This is only useful if you don't have control over the shader code, and cannot rely on automatic reflection. You can use the same bind point name with subsequent BindTextureSRV, etc. calls.

Note
Same bind point names from a shader bound with BindShader will override ones set by this function.

◆ BindDescriptorSet()

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

Manually bind an existing descriptor set to the pipeline.

Note
The bind point is only used to determine the set index. The binding index themselves is then not checked by the Renderer, therefore the shader and the descriptor set must guarantee match.

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

Note
bind_point may be ignored if shader usage is not required. For readability, you may use kBindpointIgnored as the bind_point to indicate that the actual bind point is not known or not important.

◆ 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,
Native::Path const shader_path 
) 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.

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

Note
bind_point may be ignored if shader usage is not required. For readability, you may use kBindpointIgnored as the bind_point to indicate that the actual bind point is not known or not important.

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

Note
bind_point may be ignored if shader usage is not required. For readability, you may use kBindpointIgnored as the bind_point to indicate that the actual bind point is not known or not important.

◆ 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

◆ CmdBeginGraphics()

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

void Renderer::CmdBindDescriptorSet ( PassHandle  pass,
RHICommandList cmd,
uint32_t  index,
RHIDeviceDescriptorSet descriptor_set 
) const

Helper that binds a single descriptor set to the current command list.

You generally want to use CmdSetPipeline() instead.

◆ CmdDispatch()

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

Helper that dispatches a compute shader with the specified TOTAL thread count.

Note
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:1677
std::unique_ptr< T, StlDeleter< T > > UniquePtr
std::unique_ptr with custom deleter that uses a Foundation::Core::Allocator to deallocate memory.
Definition Allocator.hpp:161

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

template<typename FSetup , typename FRecord , typename FSkip = FSkipDefault>
LambdaPass< FSetup, FRecord, FSkip > * Foundation::RenderCore::Renderer::CreatePass ( StringView  name,
RHIDeviceQueueType  queue,
size_t  priority,
FSetup &&  setup,
FRecord &&  record,
FSkip &&  skip = {} 
)
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().

createPass() should be generally preferred over this.

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(PassHandel self, Renderer*, RHICommandList*) called at Record time.
skip(Optional) Lambda of type bool(PassHandle self, Renderer*) called at Record time to determine whether this pass should be skipped if true. This is by default always false.

◆ CreatePassImpl()

template<typename T , typename... Args>
requires std::is_base_of_v<RenderPass, T>
T * 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.

createPassImpl() should be generally preferred over this.

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 RHIDeviceObjectHandle<RHIBuffer> or RHIDeviceObjectHandle<RHITexture>.

createResource() should be generally preferred over this.

Parameters
descResources can be created by passing in RHIBufferDesc, RHITextureDesc, and can be imported by passing in RHIDeviceObjectHandle<RHIBuffer>, RHIDeviceObjectHandle<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

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

◆ DerefCurrentBackbufferView()

RHITextureView * Foundation::RenderCore::Renderer::DerefCurrentBackbufferView ( const PassHandle  pass) const
inline

Returns a pointer to the current backbuffer texture view.

The pass must have declared BindBackbufferRTV() during setup.

◆ 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 prepares for the next frame.

Note
This MUST be called after ExecuteFrame(), and before BeginExecuteImpl() of the next frame.

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

◆ ExecuteAcquireQueueResources()

void Renderer::ExecuteAcquireQueueResources ( RHIDeviceQueueType  currentQueue,
size_t  groupIndex,
RHICommandList cmd 
)
private

Acquires resources for the current group.

◆ ExecuteAllocateCommandList()

RHICommandList * Renderer::ExecuteAllocateCommandList ( RHIDeviceQueueType  queue,
int  thread_id 
)
private
Parameters
thread_id-1 for main thread, [0, kRecordThreadpoolSize] for workers
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 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:1350
void BeginExecute()
Resets the temporary execution allocator , and waits for the possibly multi-buffered next frame to fi...
Definition Renderer.cpp:1006
void EndExecute()
Ends the execution phase, and prepares for the next frame.
Definition Renderer.cpp:1568

◆ ExecuteGetQueueIndex()

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

Helper to get the queue index of a queue type.

◆ ExecuteReleaseQueueResources()

void Renderer::ExecuteReleaseQueueResources ( RHIDeviceQueueType  currentQueue,
size_t  groupIndex,
RHICommandList cmd 
)
private

Performs transitions that's otherwise impossible (e.g. Fragment -> Compute) for the next group, and releases resources for the current group.

◆ FinalizePSOs()

void Renderer::FinalizePSOs ( )
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 monotonically increasing every time EndExecute() is called, and starts from 0.

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

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

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

◆ 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

◆ SetSwapchain()

void Renderer::SetSwapchain ( RHIDeviceObjectHandle< 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

RHIDeviceScopedObjectHandle<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

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

◆ mDescPoolMutex

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

◆ mDevice

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

◆ mExecuteAlloc

StackAllocator Foundation::RenderCore::Renderer::mExecuteAlloc
private

◆ mExecuteArena

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

◆ mExecuteComputeSubmits

Vector<RHIDeviceQueue::SubmitDesc> * Foundation::RenderCore::Renderer::mExecuteComputeSubmits {}
private

◆ mExecuteGraphicsSubmits

Vector<RHIDeviceQueue::SubmitDesc>* Foundation::RenderCore::Renderer::mExecuteGraphicsSubmits {}
private

◆ mExecutePerSwapCmds

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

◆ mExecuteThreadPool

Async::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

RHIDeviceScopedObjectHandle<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

RHIDeviceObjectHandle<RHISwapchain> Foundation::RenderCore::Renderer::mSwapchain {}
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: