KiCad PCB EDA Suite
Loading...
Searching...
No Matches
RHI_COMPOSITOR Class Reference

Blends layer FBOs back-to-front into an accumulation FBO, drawing each as a fullscreen quad with its own alpha. More...

#include <rhi_compositor.h>

Public Member Functions

 RHI_COMPOSITOR (RHI_DEVICE &aDevice)
 
 ~RHI_COMPOSITOR ()
 
bool Initialize (RHI_BindGroupLayoutHandle aSingleTexLayout={})
 Create the clear pass and fullscreen quad.
 
void Destroy ()
 Release all GPU resources.
 
void SetCompositorPipeline (RHI_PipelineHandle aPipeline)
 Set the pipeline that draws each layer as an alpha-blended fullscreen quad.
 
RHI_FramebufferHandle Composite (RHI_FramebufferHandle aAccumulationFBO, uint32_t aWidth, uint32_t aHeight, const std::vector< COMPOSITOR_LAYER > &aLayers, const float *aBackgroundColor=nullptr, const std::function< void()> &aDrawOnTop={})
 Blend aLayers back-to-front into aAccumulationFBO, which is cleared to aBackgroundColor first.
 
RHI_BindGroupLayoutHandle GetSingleTexLayout () const
 
RHI_BufferHandle GetQuadVB () const
 
bool IsInitialized () const
 
void InvalidateCachedBindGroups ()
 Drop the cached bind groups over layer FBO textures.
 

Private Member Functions

void compositeLayer (const COMPOSITOR_LAYER &aLayer)
 
RHI_BindGroupHandle bindFBOTexture (RHI_FramebufferHandle aFBO, RHI_BindGroupLayoutHandle aLayout, uint32_t aGroupIndex)
 
void destroyFBOBindGroups ()
 

Private Attributes

RHI_DEVICE & m_device
 
RHI_RenderPassHandle m_clearRenderPass
 
RHI_BufferHandle m_quadVB
 
RHI_BindGroupLayoutHandle m_singleTexLayout
 
bool m_ownsSingleTexLayout = true
 
RHI_PipelineHandle m_compositorPipeline
 
bool m_initialized = false
 
std::unordered_map< uint64_t, RHI_BindGroupHandle > m_fboBindGroups
 Bind groups over FBO color textures, keyed by texture and layout handles.
 

Detailed Description

Blends layer FBOs back-to-front into an accumulation FBO, drawing each as a fullscreen quad with its own alpha.

Definition at line 64 of file rhi_compositor.h.

Constructor & Destructor Documentation

◆ RHI_COMPOSITOR()

RHI_COMPOSITOR::RHI_COMPOSITOR ( RHI_DEVICE & aDevice)

Definition at line 29 of file rhi_compositor.cpp.

References m_device.

◆ ~RHI_COMPOSITOR()

RHI_COMPOSITOR::~RHI_COMPOSITOR ( )

Definition at line 35 of file rhi_compositor.cpp.

References Destroy().

Member Function Documentation

◆ bindFBOTexture()

RHI_BindGroupHandle RHI_COMPOSITOR::bindFBOTexture ( RHI_FramebufferHandle aFBO,
RHI_BindGroupLayoutHandle aLayout,
uint32_t aGroupIndex )
private

◆ Composite()

RHI_FramebufferHandle RHI_COMPOSITOR::Composite ( RHI_FramebufferHandle aAccumulationFBO,
uint32_t aWidth,
uint32_t aHeight,
const std::vector< COMPOSITOR_LAYER > & aLayers,
const float * aBackgroundColor = nullptr,
const std::function< void()> & aDrawOnTop = {} )

Blend aLayers back-to-front into aAccumulationFBO, which is cleared to aBackgroundColor first.

Parameters
aDrawOnTopdraws after the layers in the same pass with its own pipelines, which is how the cursor is drawn.
Returns
aAccumulationFBO, or a null handle when nothing could be drawn.

Definition at line 146 of file rhi_compositor.cpp.

References RHI_RENDER_PASS_BEGIN_DESC::clearColorOverride, compositeLayer(), RHI_RENDER_PASS_BEGIN_DESC::framebuffer, RHI_RENDER_PASS_BEGIN_DESC::hasClearColorOverride, RHI_SCISSOR_RECT::height, RHI_VIEWPORT::height, m_clearRenderPass, m_compositorPipeline, m_device, m_initialized, m_quadVB, RHI_RENDER_PASS_BEGIN_DESC::renderPass, RHI_SCISSOR_RECT::width, and RHI_VIEWPORT::width.

◆ compositeLayer()

◆ Destroy()

void RHI_COMPOSITOR::Destroy ( )

Release all GPU resources.

Safe to call multiple times.

Definition at line 124 of file rhi_compositor.cpp.

References destroyFBOBindGroups(), m_clearRenderPass, m_device, m_initialized, m_ownsSingleTexLayout, m_quadVB, and m_singleTexLayout.

Referenced by Initialize(), and ~RHI_COMPOSITOR().

◆ destroyFBOBindGroups()

void RHI_COMPOSITOR::destroyFBOBindGroups ( )
private

Definition at line 270 of file rhi_compositor.cpp.

References m_device, and m_fboBindGroups.

Referenced by Destroy(), and InvalidateCachedBindGroups().

◆ GetQuadVB()

RHI_BufferHandle RHI_COMPOSITOR::GetQuadVB ( ) const
inline

Definition at line 102 of file rhi_compositor.h.

References m_quadVB.

◆ GetSingleTexLayout()

RHI_BindGroupLayoutHandle RHI_COMPOSITOR::GetSingleTexLayout ( ) const
inline

Definition at line 101 of file rhi_compositor.h.

References m_singleTexLayout.

◆ Initialize()

◆ InvalidateCachedBindGroups()

void RHI_COMPOSITOR::InvalidateCachedBindGroups ( )
inline

Drop the cached bind groups over layer FBO textures.

Call before destroying layer FBOs the compositor has sampled so stale descriptors do not accumulate across resizes.

Definition at line 110 of file rhi_compositor.h.

References destroyFBOBindGroups().

◆ IsInitialized()

bool RHI_COMPOSITOR::IsInitialized ( ) const
inline

Definition at line 104 of file rhi_compositor.h.

References m_initialized.

◆ SetCompositorPipeline()

void RHI_COMPOSITOR::SetCompositorPipeline ( RHI_PipelineHandle aPipeline)

Set the pipeline that draws each layer as an alpha-blended fullscreen quad.

Definition at line 140 of file rhi_compositor.cpp.

References m_compositorPipeline.

Member Data Documentation

◆ m_clearRenderPass

RHI_RenderPassHandle RHI_COMPOSITOR::m_clearRenderPass
private

Definition at line 121 of file rhi_compositor.h.

Referenced by Composite(), Destroy(), and Initialize().

◆ m_compositorPipeline

RHI_PipelineHandle RHI_COMPOSITOR::m_compositorPipeline
private

Definition at line 126 of file rhi_compositor.h.

Referenced by Composite(), and SetCompositorPipeline().

◆ m_device

RHI_DEVICE& RHI_COMPOSITOR::m_device
private

◆ m_fboBindGroups

std::unordered_map<uint64_t, RHI_BindGroupHandle> RHI_COMPOSITOR::m_fboBindGroups
private

Bind groups over FBO color textures, keyed by texture and layout handles.

A recreated FBO has a new texture handle, so stale entries are never hit and only wait for the next clear.

Definition at line 134 of file rhi_compositor.h.

Referenced by bindFBOTexture(), and destroyFBOBindGroups().

◆ m_initialized

bool RHI_COMPOSITOR::m_initialized = false
private

Definition at line 128 of file rhi_compositor.h.

Referenced by Composite(), Destroy(), Initialize(), and IsInitialized().

◆ m_ownsSingleTexLayout

bool RHI_COMPOSITOR::m_ownsSingleTexLayout = true
private

Definition at line 124 of file rhi_compositor.h.

Referenced by Destroy(), and Initialize().

◆ m_quadVB

RHI_BufferHandle RHI_COMPOSITOR::m_quadVB
private

Definition at line 122 of file rhi_compositor.h.

Referenced by Composite(), Destroy(), GetQuadVB(), and Initialize().

◆ m_singleTexLayout

RHI_BindGroupLayoutHandle RHI_COMPOSITOR::m_singleTexLayout
private

Definition at line 123 of file rhi_compositor.h.

Referenced by compositeLayer(), Destroy(), GetSingleTexLayout(), and Initialize().


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