Skip to content

Vulkan: occlusion queries, dynamic blend constants/stencil reference, root descriptors, render pass and framebuffer fixes - #136

Closed
itar3 wants to merge 6 commits into
renderbag:mainfrom
itar3:vulkan-queries-dynamic-state-render-passes-main
Closed

itar3 wants to merge 6 commits into
renderbag:mainfrom
itar3:vulkan-queries-dynamic-state-render-passes-main

Conversation

@itar3

@itar3 itar3 commented Nov 13, 2026 •

Copy link
Copy Markdown

Six self-contained changes from porting Fable II to macOS on plume's Vulkan backend (through MoltenVK, Apple Silicon). Each commit stands on its own and builds on its own, so they can be taken one at a time; I can split this into separate pull requests if you prefer.

  1. Vulkan: scaled and 10:10:10:2 vertex formats. R8, R8G8, R8G8B8A8, R16, R16G16 and R16G16B16A16 USCALED/SSCALED, and A2B10G10R10 UNORM/SNORM, with Vulkan mappings and size tables. Console vertex data often needs unnormalized integers read as floats. Vulkan only (D3D12 has no scaled formats).
  2. Vulkan: root descriptors through VK_KHR_push_descriptor. Root descriptors asserted on Vulkan. Each register space becomes a push descriptor set at the set index equal to the space, after the layout's descriptor sets (empty layouts fill gaps). The extension is optional and checked.
  3. Dynamic blend constants and stencil reference. RenderCommandList::setBlendConstants / setStencilReference with RenderGraphicsPipelineDesc::dynamicBlendConstantsEnabled / dynamicStencilReferenceEnabled, off by default, so existing pipelines behave as before. Implemented for Vulkan, D3D12 (OMSetBlendFactor / OMSetStencilRef; a pipeline with a dynamic reference no longer gets the static one from fix: apply the pipeline stencil reference on d3d12 #122 applied on draw) and Metal (through the dirty state; GraphicsStateFlags::setAll mask updated for the new bit). Without it, a stencil reference that changes per draw needs a pipeline per value.
  4. Vulkan: framebuffer size from the attachment view's mip level. A framebuffer on a view of mip N used the base level's size as its size and render area; on MoltenVK draws then wrote outside the attachment (GPU page faults).
  5. Vulkan: occlusion queries. RenderDevice::createOcclusionQueryPool, RenderCommandList::beginQuery / endQuery, RenderQueryPool::getRawResults (no wait; false while any result is unavailable). Other backends return no pool for now. Queries are precise when the device supports it. A query begun inside a render pass stays in it instead of ending the pass, and ends with the pass at the latest, as Vulkan requires (queriesEndRenderPass restores the old behaviour). resetQueryPool now ends the active pass, since vkCmdResetQueryPool is not allowed inside one.
  6. Vulkan: keep the render pass across framebuffer rebinds. setFramebuffer ended the active pass every time, so rebinding the same framebuffer (or one that got no draws before switching back) cost a store and reload of every attachment on tile GPUs. Now a draw or clear ends the pass only when it needs another framebuffer. setFramebuffer(nullptr) still ends it, and dispatch, traceRays and acceleration structure builds now end it themselves (resolves already do since vulkan: End active render pass before resolve #133).

Testing. Every commit builds with the Vulkan and Metal backends on macOS. I also ran the game on this branch (plus the two commits from zolaware/plume, a fork of this repository, that the game needs: the R11G11B10_FLOAT format and a Vulkan pipeline cache, and the renderer's own plume patch) on MoltenVK: three saves in automated runs, no errors in the logs, frame times the same as on the fork, where these changes are in daily use (also proposed there: zolaware#2). The Metal part of commit 3 is compiled but not run, and the D3D12 part is not compiled (no Windows machine here); it is a few lines, but please check it.

These are used by Fable2RecompMac.

🤖 Generated with Claude Code

itar3 and others added 6 commits November 13, 2026 15:35
Adds R8, R8G8 and R8G8B8A8 USCALED/SSCALED, R16, R16G16 and R16G16B16A16
USCALED/SSCALED, and A2B10G10R10 UNORM/SNORM packed formats, with their
Vulkan mappings and size tables. USCALED/SSCALED read unnormalized integers
as floats, which vertex data from consoles often needs. Vulkan only: D3D12
has no scaled formats.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Root descriptors (RenderPipelineLayoutDesc::rootDescriptorDescs) asserted
on Vulkan. Each register space becomes a push descriptor set at the set
index equal to the space, after the layout's descriptor sets (empty set
layouts fill any gap); setGraphicsRootDescriptor pushes the buffer.
Constant buffers map to uniform buffers, SRVs and UAVs to storage buffers.
Needs VK_KHR_push_descriptor (now an optional extension).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds RenderCommandList::setBlendConstants and setStencilReference, and
RenderGraphicsPipelineDesc::dynamicBlendConstantsEnabled and
dynamicStencilReferenceEnabled (both off by default, so existing pipelines
behave as before).

Vulkan: the flags enable VK_DYNAMIC_STATE_BLEND_CONSTANTS and
VK_DYNAMIC_STATE_STENCIL_REFERENCE. D3D12: OMSetBlendFactor and
OMSetStencilRef; binding a pipeline with a dynamic stencil reference no
longer overwrites it. Metal: setBlendColor and setStencilReferenceValue
through the dirty state.

Without them, a renderer whose stencil reference or blend constant changes
per draw needs a pipeline per value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A framebuffer whose attachment is a view of mip level N took the base
level's size as its size and render area, larger than the attachment: on
MoltenVK draws then wrote outside it (GPU page faults). The size is now
the view's mip level size, for colour and depth-only framebuffers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds RenderDevice::createOcclusionQueryPool, RenderCommandList::beginQuery
and endQuery, and RenderQueryPool::getRawResults (results without waiting,
false while any is unavailable). Other backends return no pool for now.

Queries are precise (sample counts) when the device supports it; MoltenVK
otherwise uses Metal's boolean visibility mode. A query begun inside a
render pass instance stays in it instead of ending the pass (a store and
reload of every attachment on tile GPUs) and ends with the pass at the
latest, as Vulkan requires; queriesEndRenderPass restores begin/end outside
passes. resetQueryPool now ends the active pass (vkCmdResetQueryPool is not
allowed inside one).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
setFramebuffer ended the active render pass every time, so rebinding the
active framebuffer, or binding one that got no draws before switching
back, ended and restarted the pass: a store and reload of every
attachment on tile GPUs (MoltenVK, mobile).

Now a draw or clear ends the pass only when it needs another framebuffer.
setFramebuffer(nullptr) still ends it, and dispatch, traceRays and
acceleration structure builds end it themselves (they relied on
setFramebuffer ending it before; resolves already do).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DarioSamo

DarioSamo commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Please read the contribution guide. AI-generated contributions are not accepted.

https://github.com/renderbag/plume/blob/main/CONTRIBUTING.md

@DarioSamo DarioSamo closed this Nov 13, 2026
@renderbag renderbag locked and limited conversation to collaborators Nov 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants