|
KiCad PCB EDA Suite
|
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. | |
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.
| RHI_COMPOSITOR::RHI_COMPOSITOR | ( | RHI_DEVICE & | aDevice | ) |
Definition at line 29 of file rhi_compositor.cpp.
References m_device.
| RHI_COMPOSITOR::~RHI_COMPOSITOR | ( | ) |
Definition at line 35 of file rhi_compositor.cpp.
References Destroy().
|
private |
Definition at line 206 of file rhi_compositor.cpp.
References RHI_BIND_GROUP_DESC::entries, RHI_BIND_GROUP_DESC::layout, m_device, m_fboBindGroups, traceRhi, and RHI_HANDLE< Tag >::value.
Referenced by compositeLayer().
| 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.
| aDrawOnTop | draws after the layers in the same pass with its own pipelines, which is how the cursor is 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.
|
private |
Definition at line 251 of file rhi_compositor.cpp.
References COMPOSITOR_LAYER::alpha, COMPOSITOR_PUSH_CONSTANTS::alpha, bindFBOTexture(), COMPOSITOR_LAYER::fbo, m_device, m_singleTexLayout, COMPOSITOR_LAYER::uvOffset, COMPOSITOR_PUSH_CONSTANTS::uvOffset, COMPOSITOR_LAYER::uvScale, and COMPOSITOR_PUSH_CONSTANTS::uvScale.
Referenced by Composite().
| 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().
|
private |
Definition at line 270 of file rhi_compositor.cpp.
References m_device, and m_fboBindGroups.
Referenced by Destroy(), and InvalidateCachedBindGroups().
|
inline |
Definition at line 102 of file rhi_compositor.h.
References m_quadVB.
|
inline |
Definition at line 101 of file rhi_compositor.h.
References m_singleTexLayout.
| bool RHI_COMPOSITOR::Initialize | ( | RHI_BindGroupLayoutHandle | aSingleTexLayout = {} | ) |
Create the clear pass and fullscreen quad.
Must be called before Composite().
| aSingleTexLayout | is the layout baked into the fullscreen pipelines. Without one the compositor makes its own. |
Definition at line 41 of file rhi_compositor.cpp.
References CLEAR, RHI_COLOR_ATTACHMENT_DESC::clearColor, RHI_RENDER_PASS_DESC::colorAttachments, COMBINED_TEXTURE_SAMPLER, Destroy(), RHI_BIND_GROUP_LAYOUT_DESC::entries, RHI_COLOR_ATTACHMENT_DESC::format, FRAGMENT, RHI_BIND_GROUP_LAYOUT_DESC::frequency, RHI_COLOR_ATTACHMENT_DESC::loadOp, m_clearRenderPass, m_device, m_initialized, m_ownsSingleTexLayout, m_quadVB, m_singleTexLayout, RHI_BUFFER_DESC::mappable, PER_DRAW, RGBA8, RHI_BUFFER_DESC::sizeBytes, STORE, RHI_COLOR_ATTACHMENT_DESC::storeOp, RHI_BUFFER_DESC::type, and VERTEX.
|
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().
|
inline |
Definition at line 104 of file rhi_compositor.h.
References m_initialized.
| 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.
|
private |
Definition at line 121 of file rhi_compositor.h.
Referenced by Composite(), Destroy(), and Initialize().
|
private |
Definition at line 126 of file rhi_compositor.h.
Referenced by Composite(), and SetCompositorPipeline().
|
private |
Definition at line 119 of file rhi_compositor.h.
Referenced by bindFBOTexture(), Composite(), compositeLayer(), Destroy(), destroyFBOBindGroups(), Initialize(), and RHI_COMPOSITOR().
|
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().
|
private |
Definition at line 128 of file rhi_compositor.h.
Referenced by Composite(), Destroy(), Initialize(), and IsInitialized().
|
private |
Definition at line 124 of file rhi_compositor.h.
Referenced by Destroy(), and Initialize().
|
private |
Definition at line 122 of file rhi_compositor.h.
Referenced by Composite(), Destroy(), GetQuadVB(), and Initialize().
|
private |
Definition at line 123 of file rhi_compositor.h.
Referenced by compositeLayer(), Destroy(), GetSingleTexLayout(), and Initialize().