Raven Engine v0.1
A modern 3D Game Engine
Loading...
Searching...
No Matches
Raven::IllumineRenderer Class Reference

Static facade for all renderer operations. More...

#include <IllumineRenderer.h>

Static Public Member Functions

static ILLUMINE_API void Init (Window &wnd, const RendererConfig &config)
 Initializes the renderer, render thread, and all GPU resources.
static ILLUMINE_API void Shutdown ()
 Shuts down the renderer and releases all GPU and CPU resources.
static ILLUMINE_API void WaitRender ()
 Blocks the calling thread until the GPU is fully idle.
static ILLUMINE_API void SwapQueues ()
 Swaps the write and read command queues, kicking the render thread.
static ILLUMINE_API void FlushAndWait ()
 Submits the current queue and blocks until the render thread AND GPU have fully completed execution.
static ILLUMINE_API void BeginFrame ()
 Enqueues the swapchain acquire and command buffer begin onto the render thread.
static ILLUMINE_API void EndFrame ()
 Enqueues the command buffer end, queue submit, and swapchain present.
template<typename Fn>
static void SubmitCmd (Fn &&fn)
 Allocates a render command in the current write queue.
static ILLUMINE_API void BeginRenderPass (Ref< RenderPass > renderPass)
 Enqueues a render pass begin command.
static ILLUMINE_API void EndRenderPass ()
 Enqueues a render pass end command.
static ILLUMINE_API void DrawGeometry (Ref< Pipeline > pipeline, Ref< VertexBuffer > vertexBuffer, Ref< IndexBuffer > indexBuffer, const Crux::mat4 &transform)
 Enqueues a draw call for indexed geometry.
static ILLUMINE_API void DrawGeometryIndexed (Ref< VertexBuffer > vertexBuffer, Ref< IndexBuffer > indexBuffer, u32 indexCount)
 Enqueues a draw call for indexed geometry.
static ILLUMINE_API void DrawGeometryRaw (Ref< VertexBuffer > vertexBuffer, u32 vertexCount)
 Enqueues a draw call for geometry.
static ILLUMINE_API void DrawStaticMesh (Ref< Pipeline > pipeline, Ref< Mesh > mesh, const Crux::mat4 &transform, const Crux::Frustum &frustum)
 Enqueues draw calls for all submeshes of a static mesh.
static ILLUMINE_API void DrawStaticMeshDepthOnly (Ref< Pipeline > pipeline, Ref< Mesh > mesh, const Crux::mat4 &transform, const Crux::Frustum &frustum)
static ILLUMINE_API void DrawSkybox (Ref< Pipeline > pipeline, Ref< VertexBuffer > vb)
static ILLUMINE_API void DrawFullscreenQuad (Ref< Pipeline > pipeline, Ref< VertexBuffer > vb, Ref< IndexBuffer > ib)
static ILLUMINE_API void Submit (const StaticMeshSubmission &s)
 Submits a static mesh for rendering this frame.
static ILLUMINE_API const std::vector< StaticMeshSubmission > & GetStaticMeshSubmissions ()
 Returns all static mesh submissions queued for the current frame.
static ILLUMINE_API void BeginGPUPerf (const std::string &name)
 Enqueues a GPU timestamp begin marker.
static ILLUMINE_API void EndGPUPerf ()
 Enqueues a GPU timestamp end marker.
static ILLUMINE_API std::vector< GPUTimeSpanGetGPUTimes ()
 Returns all GPU time spans recorded in the last completed frame.
static ILLUMINE_API void DrainPendingPresent ()
static ILLUMINE_API Ref< RenderCommandBufferGetCommandBuffer ()
 Returns the command buffer for the current frame slot.
static ILLUMINE_API Ref< RenderCommandBufferGetCommandBuffer (u8 index)
 Returns the command buffer at an explicit frame index.
static ILLUMINE_API u32 GetImageIndex ()
 Returns the current swapchain image index.
static ILLUMINE_API void * BeginSingleTimeCommand ()
 Allocates and begins a one-shot command buffer on the graphics queue.
static ILLUMINE_API void EndSingleTimeCommand (void *commandBuffer)
 Ends and submits a one-shot command buffer, then frees it.
static ILLUMINE_API void TransitionImageLayout (Ref< Image2D > image, ImageFormat format, ImageLayout oldLayout, ImageLayout newLayout, u32 mipCount=0)
 Transitions a Vulkan image between layout states.
static ILLUMINE_API void CopyBuffer (void *srcBuffer, void *dstBuffer, u32 size)
 Copies data between two Vulkan buffers synchronously.
static ILLUMINE_API void CopyBufferToImage (void *srcBuffer, void *dstImage, u32 width, u32 height)
 Copies buffer data into a Vulkan image synchronously.
static ILLUMINE_API Ref< ShaderLibraryGetShaderLibrary ()
 Returns the global shader library.
static ILLUMINE_API Ref< MaterialRegistryGetMaterialRegistry ()
 Returns the global material registry.
static ILLUMINE_API RendererConfigGetConfig ()
 Returns the current renderer configuration.
static ILLUMINE_API RendererDataGetRenderData ()
 Returns current frame statistics and shared renderer resources.
static ILLUMINE_API RenderResourceRegistryGetResourceRegistry ()
 Returns the render resource registry.
static WindowGetWindow ()
 Returns the window the renderer is rendering into.
static SwapchainGetSwapchain ()
 Returns the active swapchain.
static ILLUMINE_API void * GetDescriptorPool ()
 Returns the raw Vulkan descriptor pool handle.
static ILLUMINE_API void * GetInstance ()
 Returns the raw Vulkan instance handle.
static RendererAPIGetRendererAPI ()
 Returns the underlying RendererAPI implementation.
static bool ShouldRecreateSwapchain ()
static bool ShouldResizeFramebuffers ()
static void QueueRecreate ()
static void QueueResize ()
static void Recreated ()
static ILLUMINE_API void SetVSync (bool enabled)
 Enable or disable vertical synchronization.
static ILLUMINE_API void RequestPresent ()
static ILLUMINE_API void InitCommandBuffers ()
 Initializes Vulkan command buffers for all frame slots.
static ILLUMINE_API void TransitionImage (Ref< Image2D > image, ResourceState newState)
static ILLUMINE_API void FullBarrier ()
static ILLUMINE_API void StorageWriteToComputeRead ()
static ILLUMINE_API void StorageWriteToFragmentRead ()
static ILLUMINE_API void DepthWriteToComputeRead ()
static ILLUMINE_API void ComputeReadToDepthWrite ()

Static Public Attributes

static constexpr u32 MAX_FRAMES_IN_FLIGHT = 4
 Maximum supported frames in flight. Matches semaphore template parameter.

Detailed Description

Static facade for all renderer operations.

All public methods are safe to call from the main thread unless explicitly documented as render-thread-only. See file-level documentation for the full threading model and SubmitCmd usage rules.

Member Function Documentation

◆ BeginFrame()

void Raven::IllumineRenderer::BeginFrame ( )
static

Enqueues the swapchain acquire and command buffer begin onto the render thread.

Internally calls SubmitCmd. Must be called after SwapQueues() each frame. The render thread will acquire the next swapchain image and begin recording.

◆ BeginGPUPerf()

void Raven::IllumineRenderer::BeginGPUPerf ( const std::string & name)
static

Enqueues a GPU timestamp begin marker.

Parameters
nameLabel for the time span. Displayed in profiling tools.

◆ BeginRenderPass()

void Raven::IllumineRenderer::BeginRenderPass ( Ref< RenderPass > renderPass)
static

Enqueues a render pass begin command.

Parameters
renderPassThe render pass to begin. Captured by value.

Sets viewport, scissor, and clears attachments as specified in the render pass framebuffer specification. Must be paired with EndRenderPass().

◆ BeginSingleTimeCommand()

void * Raven::IllumineRenderer::BeginSingleTimeCommand ( )
static

Allocates and begins a one-shot command buffer on the graphics queue.

Returns
Raw pointer to the VkCommandBuffer (cast to void*).

Used for immediate GPU operations such as buffer uploads, image layout transitions, and texture copies during resource initialization. Must be paired with EndSingleTimeCommand().

Note
Submits synchronously and stalls the graphics queue. Avoid during rendering.

◆ ComputeReadToDepthWrite()

void Raven::IllumineRenderer::ComputeReadToDepthWrite ( )
static

◆ CopyBuffer()

void Raven::IllumineRenderer::CopyBuffer ( void * srcBuffer,
void * dstBuffer,
u32 size )
static

Copies data between two Vulkan buffers synchronously.

Parameters
srcBufferSource VkBuffer (as void*).
dstBufferDestination VkBuffer (as void*).
sizeNumber of bytes to copy.

◆ CopyBufferToImage()

void Raven::IllumineRenderer::CopyBufferToImage ( void * srcBuffer,
void * dstImage,
u32 width,
u32 height )
static

Copies buffer data into a Vulkan image synchronously.

Parameters
srcBufferSource VkBuffer (as void*).
dstImageDestination VkImage (as void*).
widthWidth of the target image region.
heightHeight of the target image region.

◆ DepthWriteToComputeRead()

void Raven::IllumineRenderer::DepthWriteToComputeRead ( )
static

◆ DrainPendingPresent()

void Raven::IllumineRenderer::DrainPendingPresent ( )
static

◆ DrawFullscreenQuad()

void Raven::IllumineRenderer::DrawFullscreenQuad ( Ref< Pipeline > pipeline,
Ref< VertexBuffer > vb,
Ref< IndexBuffer > ib )
static

◆ DrawGeometry()

void Raven::IllumineRenderer::DrawGeometry ( Ref< Pipeline > pipeline,
Ref< VertexBuffer > vertexBuffer,
Ref< IndexBuffer > indexBuffer,
const Crux::mat4 & transform )
static

Enqueues a draw call for indexed geometry.

Parameters
pipelineGraphics pipeline to bind.
vertexBufferVertex buffer containing geometry data.
indexBufferIndex buffer defining draw topology.
transformModel matrix pushed as a push constant.

◆ DrawGeometryIndexed()

void Raven::IllumineRenderer::DrawGeometryIndexed ( Ref< VertexBuffer > vertexBuffer,
Ref< IndexBuffer > indexBuffer,
u32 indexCount )
static

Enqueues a draw call for indexed geometry.

Parameters
vertexBufferVertex buffer containing geometry data.
indexBufferIndex buffer defining draw topology.
indexCountThe amount of indices.
Note
Needed for functions that have pre-allocated IndexBuffers but only a subset is drawn

◆ DrawGeometryRaw()

void Raven::IllumineRenderer::DrawGeometryRaw ( Ref< VertexBuffer > vertexBuffer,
u32 vertexCount )
static

Enqueues a draw call for geometry.

Parameters
vertexBufferVertex buffer containing geometry data.
vertexCountThe amount of indices.

◆ DrawSkybox()

void Raven::IllumineRenderer::DrawSkybox ( Ref< Pipeline > pipeline,
Ref< VertexBuffer > vb )
static

◆ DrawStaticMesh()

void Raven::IllumineRenderer::DrawStaticMesh ( Ref< Pipeline > pipeline,
Ref< Mesh > mesh,
const Crux::mat4 & transform,
const Crux::Frustum & frustum )
static

Enqueues draw calls for all submeshes of a static mesh.

Parameters
pipelineGraphics pipeline to bind.
meshStatic mesh containing vertex buffer, index buffer, and submesh list.
transformModel matrix pushed as a push constant.

Iterates submeshes, binds per-submesh materials, and issues one vkCmdDrawIndexed per submesh.

◆ DrawStaticMeshDepthOnly()

void Raven::IllumineRenderer::DrawStaticMeshDepthOnly ( Ref< Pipeline > pipeline,
Ref< Mesh > mesh,
const Crux::mat4 & transform,
const Crux::Frustum & frustum )
static

◆ EndFrame()

void Raven::IllumineRenderer::EndFrame ( )
static

Enqueues the command buffer end, queue submit, and swapchain present.

Internally calls SubmitCmd. Must be called at the end of each frame after all draw commands have been submitted. Presentation is deferred to the render thread.

◆ EndGPUPerf()

void Raven::IllumineRenderer::EndGPUPerf ( )
static

Enqueues a GPU timestamp end marker.

Must be paired with a preceding BeginGPUPerf() call.

◆ EndRenderPass()

void Raven::IllumineRenderer::EndRenderPass ( )
static

Enqueues a render pass end command.

Must be called after BeginRenderPass() and all draw commands for that pass.

◆ EndSingleTimeCommand()

void Raven::IllumineRenderer::EndSingleTimeCommand ( void * commandBuffer)
static

Ends and submits a one-shot command buffer, then frees it.

Parameters
commandBufferPointer returned by BeginSingleTimeCommand().

Calls vkQueueWaitIdle after submission. The command buffer is freed back to the command pool on return.

◆ FlushAndWait()

void Raven::IllumineRenderer::FlushAndWait ( )
static

Submits the current queue and blocks until the render thread AND GPU have fully completed execution.

Performs a full CPU + GPU drain. Significantly more expensive than SwapQueues(). Only use during Shutdown. Prefer Framework::SyncPoint + WaitRender

Warning
Never call from within a SubmitCmd lambda.
Never call from the render thread.

◆ FullBarrier()

void Raven::IllumineRenderer::FullBarrier ( )
static

◆ GetCommandBuffer() [1/2]

Ref< RenderCommandBuffer > Raven::IllumineRenderer::GetCommandBuffer ( )
static

Returns the command buffer for the current frame slot.

Returns
Ref to the active RenderCommandBuffer.
Warning
RENDER THREAD ONLY. Never call from the main thread. Always call inside a SubmitCmd lambda body.

◆ GetCommandBuffer() [2/2]

Ref< RenderCommandBuffer > Raven::IllumineRenderer::GetCommandBuffer ( u8 index)
static

Returns the command buffer at an explicit frame index.

Parameters
indexFrame slot index. Must be < FramesInFlight.
Returns
Ref to the RenderCommandBuffer at the given index.
Warning
RENDER THREAD ONLY. Never call from the main thread.

◆ GetConfig()

RendererConfig & Raven::IllumineRenderer::GetConfig ( )
static

Returns the current renderer configuration.

Returns
Reference to the RendererConfig. Do not store across frames.

◆ GetDescriptorPool()

void * Raven::IllumineRenderer::GetDescriptorPool ( )
static

Returns the raw Vulkan descriptor pool handle.

Returns
void* wrapping a VkDescriptorPool.

Exposed for low-level descriptor set allocation (e.g. ImGui integration).

◆ GetGPUTimes()

std::vector< GPUTimeSpan > Raven::IllumineRenderer::GetGPUTimes ( )
static

Returns all GPU time spans recorded in the last completed frame.

Returns
Vector of GPUTimeSpan objects with name and duration in milliseconds.

◆ GetImageIndex()

u32 Raven::IllumineRenderer::GetImageIndex ( )
static

Returns the current swapchain image index.

Returns
Index of the swapchain image targeted by the current frame.
Warning
RENDER THREAD ONLY. Value is only valid after BeginFrame executes.

◆ GetInstance()

void * Raven::IllumineRenderer::GetInstance ( )
static

Returns the raw Vulkan instance handle.

Returns
void* wrapping a VkInstance.

◆ GetMaterialRegistry()

Ref< MaterialRegistry > Raven::IllumineRenderer::GetMaterialRegistry ( )
static

Returns the global material registry.

Returns
Ref to the MaterialRegistry.

◆ GetRenderData()

RendererData & Raven::IllumineRenderer::GetRenderData ( )
static

Returns current frame statistics and shared renderer resources.

Returns
Reference to RendererData.

◆ GetRendererAPI()

RendererAPI & Raven::IllumineRenderer::GetRendererAPI ( )
inlinestatic

Returns the underlying RendererAPI implementation.

Returns
Reference to RendererAPI.
Warning
Calling RendererAPI methods directly bypasses the command queue. Only use from within SubmitCmd lambdas or render-thread-only code.

◆ GetResourceRegistry()

RenderResourceRegistry & Raven::IllumineRenderer::GetResourceRegistry ( )
static

Returns the render resource registry.

Returns
const reference to the ResourceRegistry

◆ GetShaderLibrary()

Ref< ShaderLibrary > Raven::IllumineRenderer::GetShaderLibrary ( )
static

Returns the global shader library.

Returns
Ref to the ShaderLibrary.

◆ GetStaticMeshSubmissions()

const std::vector< StaticMeshSubmission > & Raven::IllumineRenderer::GetStaticMeshSubmissions ( )
static

Returns all static mesh submissions queued for the current frame.

Returns
Const reference to the submission list.
Warning
Must only be called from the main thread before SwapQueues(). Snapshot the result by value before passing into a SubmitCmd lambda.

◆ GetSwapchain()

Swapchain & Raven::IllumineRenderer::GetSwapchain ( )
inlinestatic

Returns the active swapchain.

Returns
Reference to the Swapchain.

◆ GetWindow()

Window & Raven::IllumineRenderer::GetWindow ( )
inlinestatic

Returns the window the renderer is rendering into.

Returns
Reference to the Window.

◆ Init()

void Raven::IllumineRenderer::Init ( Window & wnd,
const RendererConfig & config )
static

Initializes the renderer, render thread, and all GPU resources.

Parameters
wndReference to the application window to render into.
configRenderer configuration. FramesInFlight is clamped to [1, MAX_FRAMES_IN_FLIGHT].

Creates the RendererAPI backend, swapchain, command pools, command queues, shader library, material registry, and starts the render thread. Must be called before any other IllumineRenderer function.

◆ InitCommandBuffers()

void Raven::IllumineRenderer::InitCommandBuffers ( )
static

Initializes Vulkan command buffers for all frame slots.

Allocates one command buffer per frame in flight from the graphics command pool. Called automatically during Init(). May be called again after device loss recovery.

◆ QueueRecreate()

void Raven::IllumineRenderer::QueueRecreate ( )
inlinestatic

◆ QueueResize()

void Raven::IllumineRenderer::QueueResize ( )
inlinestatic

◆ Recreated()

void Raven::IllumineRenderer::Recreated ( )
inlinestatic

◆ RequestPresent()

void Raven::IllumineRenderer::RequestPresent ( )
static

◆ SetVSync()

void Raven::IllumineRenderer::SetVSync ( bool enabled)
static

Enable or disable vertical synchronization.

Parameters
enabledTrue to enable VSync, false to disable.

◆ ShouldRecreateSwapchain()

bool Raven::IllumineRenderer::ShouldRecreateSwapchain ( )
inlinestatic

◆ ShouldResizeFramebuffers()

bool Raven::IllumineRenderer::ShouldResizeFramebuffers ( )
inlinestatic

◆ Shutdown()

void Raven::IllumineRenderer::Shutdown ( )
static

Shuts down the renderer and releases all GPU and CPU resources.

Calls FlushAndWait() to drain all in-flight work, then signals the render thread to exit and joins it. Safe to call only from the main thread. No IllumineRenderer functions may be called after Shutdown().

◆ StorageWriteToComputeRead()

void Raven::IllumineRenderer::StorageWriteToComputeRead ( )
static

◆ StorageWriteToFragmentRead()

void Raven::IllumineRenderer::StorageWriteToFragmentRead ( )
static

◆ Submit()

void Raven::IllumineRenderer::Submit ( const StaticMeshSubmission & s)
static

Submits a static mesh for rendering this frame.

Parameters
sSubmission data including mesh handle and transform.

Adds the submission to the current frame's submission list, which is consumed by SceneRenderer::EndScene(). Cleared at the end of each frame by the render thread.

◆ SubmitCmd()

template<typename Fn>
void Raven::IllumineRenderer::SubmitCmd ( Fn && fn)
inlinestatic

Allocates a render command in the current write queue.

The functor is placement-new'd into the queue's linear memory buffer and executed on the render thread during the next Execute() pass. The functor's destructor is called immediately after execution.

Alignment is handled automatically.

Template Parameters
FnCallable type. Must be moveable and destructible.
Parameters
fnFunctor to enqueue. Captured by forward — prefer lambdas with explicit capture lists.
Warning
Resolve GetCommandBuffer() inside fn, never before calling SubmitCmd.
Do not capture raw Vulkan handles resolved on the main thread.
Do not call SwapQueues() or FlushAndWait() from within fn.

◆ SwapQueues()

void Raven::IllumineRenderer::SwapQueues ( )
static

Swaps the write and read command queues, kicking the render thread.

The current write queue is handed off to the render thread for execution. Main thread immediately begins filling the next queue. Blocks only if the render thread is MAX_FRAMES_IN_FLIGHT frames behind (semaphore exhausted), which in practice should never happen under normal load.

Call once per frame at the top of the render loop, before BeginFrame().

Warning
Never call from within a SubmitCmd lambda.
Never call from the render thread.

◆ TransitionImage()

void Raven::IllumineRenderer::TransitionImage ( Ref< Image2D > image,
ResourceState newState )
static

◆ TransitionImageLayout()

void Raven::IllumineRenderer::TransitionImageLayout ( Ref< Image2D > image,
ImageFormat format,
ImageLayout oldLayout,
ImageLayout newLayout,
u32 mipCount = 0 )
static

Transitions a Vulkan image between layout states.

Parameters
imageRaw VkImage pointer (as void*).
formatImage format used to select the correct aspect mask.
oldLayoutSource image layout.
newLayoutDestination image layout.
mipCountNumber of mip levels to transition. Pass 0 for all levels.

Executed synchronously via a single-time command buffer.

◆ WaitRender()

void Raven::IllumineRenderer::WaitRender ( )
static

Blocks the calling thread until the GPU is fully idle.

Equivalent to vkDeviceWaitIdle. Use sparingly — prefer FlushAndWait() for CPU/GPU sync and SwapQueues() for normal frame pacing.

Member Data Documentation

◆ MAX_FRAMES_IN_FLIGHT

u32 Raven::IllumineRenderer::MAX_FRAMES_IN_FLIGHT = 4
staticconstexpr

Maximum supported frames in flight. Matches semaphore template parameter.


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