Skip to content

gfx: shading rate, per-view draw lists and face masks in raw rasters, and multiview without MultiView - #2419

Open
jcelerier wants to merge 6 commits into
masterfrom
split/raw-raster-vulkan
Open

jcelerier wants to merge 6 commits into
masterfrom
split/raw-raster-vulkan

Conversation

@jcelerier

Copy link
Copy Markdown
Member

Performance work on raw raster cube and per-layer rendering, found while rendering Sponza into a cube for the CAVE, plus two fixes on the shared Vulkan device that it needed.

  • Shared VkDevice extensions. Every Vulkan QRhi score creates imports the shared device built for video decode. That device did not enable VK_KHR_fragment_shading_rate or VK_EXT_device_fault. QRhi reads its VRS caps from the physical device, so it reported VariableRateShading as supported while vkCmdSetFragmentShadingRateKHR resolved to null, and setShadingRate silently did nothing. Device loss only ever said VK_ERROR_DEVICE_LOST. Both extensions are now requested with their feature structs.
  • PIPELINE_STATE.SHADING_RATE was parsed but never applied. Raw rasters now opt their pipeline in when the state sets a rate and the backend supports VRS, and they record the rate before drawing. Intel ARL, Sponza cube at 2x2: 41 -> 81 fps. RTX 5090, face 1024, 2x2: GPU 2.68 -> 1.30 ms.
  • Per-view indirect draw lists. A geometry may carry an indirect_draw_cmds_per_view auxiliary: one copy of the indirect command list per view, view-major. With it, each pass of a PER_CUBE_FACE or PER_LAYER raw raster draws from its own view's copy. A compute filter that culls against each view's frustum (scene_cull_per_view.csf in score-csf-testers) then leaves every face only the draws it can see. Scenes made of many objects: GPU time -13% on an RTX 5090, frame rate +10-21% on Intel ARL.
  • FACES mask for PER_CUBE_FACE. An optional expression in EXECUTION_MODEL, evaluated every frame like MANUAL's COUNT: bit i set draws face i (+X -X +Y -Y +Z -Z). A face left out is cleared to transparent once and then skipped, so the cube stays defined for whatever samples it. On the CAVE no projector looks at +Y or behind, and one 1024² face is about 1.2 ms of an ~8 ms Sponza cube.
  • Multiview fallback. QRhi's OpenGL backend reports MultiView only with both GL_OVR_multiview and GL_OVR_multiview2, and Mesa's Intel driver has neither. MULTIVIEW shaders were still baked with gl_ViewIndex, which failed to build (prefilter_ggx, Camera Array). The per-pass VIEWINDEX lowering and the N-pass path are now taken on any backend without MultiView, not only D3D.

Commits

  • fe8949fae0 gfx: enable VK_KHR_fragment_shading_rate on the shared VkDevice
  • c6b6d6b433 gfx: enable VK_EXT_device_fault on the shared VkDevice
  • 417cb3caf3 gfx: apply PIPELINE_STATE.SHADING_RATE in raw rasters. Only raw rasters opt in. A pipeline with the flag and no rate set is invalid use on Vulkan, so plain ISF passes keep ignoring SHADING_RATE. Needs the first commit.
  • e3f5b879dd gfx: per-view indirect draw lists for per-face raster passes
  • 162fa1d3b1 gfx: fall back to N passes for multiview when QRhi has no MultiView. viewIndexNeedsPassIndexFallback takes the renderer's MultiView support, and ShaderCache keys its bakers on it (a single-view shader gets one baker). Plain ISF passes have no N-pass loop, so a MULTIVIEW ISF shader on such a backend renders view 0 only and warns once.
  • 9d644ab613 raw raster: PER_CUBE_FACE draws only the faces a FACES mask selects. Bool inputs now bind in these expressions as 0/1. An integer FACES is used directly, an expression is clamped to 0..63, and a FACES on a pass that is not per face is ignored with a warning.

Tests

  • New test_gfx_shared_device_extensions: the device score creates enables fragment shading rate and device fault where the GPU has them.
  • New test_gfx_shader_cache_multiview (no device): bakers keyed on MultiView only for multi-view shaders.
  • test_gfx_cube_face_orientation gains two FACES mask cases (selected faces only, and a mask that changes between frames), with the cube-dir-ndc-perface-mask corpus shader.
  • test_gfx_camera_array_faces and test_gfx_cubemap_six_faces follow the new viewIndexNeedsPassIndexFallback signature.
  • The whole series was built and tested with ctest on Linux (Xvfb, lavapipe Vulkan and Mesa OpenGL). Nothing failed beyond master's own known failures (test_gfx_shader_corpus_targets, test_gfx_window_layout, test_threedim_ply_fingerprint, test_unit_miniaudio_alsa and the few others master's run lists).

Notes for review

  • Two features have no automated test. For shading rate, only the extension's presence is tested: nothing checks that the rate reaches the GPU. For the per-view indirect lists, no test builds a geometry with indirect_draw_cmds_per_view. Both were measured by hand on the GPUs above.
  • The per-view copies are not compacted. A per-view cull zeroes the commands it drops, and the indirect count is not applied to the copies. A sub-mesh with its own indirect buffer keeps it. An auxiliary too small for a pass's view warns once and falls back to the shared list.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KdPgujQFUTMVZBdH6Hv7Vj

jcelerier and others added 6 commits November 25, 2026 10:28
Every Vulkan QRhi score creates imports the shared device built for video
decode, and that device never enabled the fragment shading rate extension.
QRhi reads its VRS caps from the physical device, so it still reported
VariableRateShading as supported, but vkGetDeviceProcAddr returned null
for vkCmdSetFragmentShadingRateKHR and setShadingRate silently did
nothing. It looked NVIDIA-specific because on GPUs without a video decode
queue score falls back to a QRhi-created device, which enables it.

The extension is now in the curated list, and its feature struct is
chained into the feature query so every supported mode is enabled.

RTX 5090, sponza cube, face 1024, 2x2: GPU 2.68 -> 1.30 ms.

Tested: on a GPU with the extension, vkCmdSetFragmentShadingRateKHR
resolves on the device score creates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KdPgufk1W2MBbpcjraruZq
QRhi assumes an imported device has it and resolves
vkGetDeviceFaultInfoEXT to report the faulting address and vendor data
on device loss; on the shared device that lookup returned null, so a
device loss in score only ever said VK_ERROR_DEVICE_LOST. The extension
is now requested with its feature struct, like the one QRhi creates.

Tested: on a GPU with the extension, vkGetDeviceFaultInfoEXT resolves on
the device score creates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KdPgufk1W2MBbpcjraruZq
SHADING_RATE was parsed and merged but never reached the GPU: no pipeline
got UsesShadingRate from it and nothing called setShadingRate. The
pipeline now opts in when the state sets a rate and the backend supports
VariableRateShading, and the raw raster records the rate before drawing.

Intel ARL, sponza cube at 2x2: 41 -> 81 fps.

Only raw rasters opt in (applyShadingRate): they are the nodes that record
the rate before drawing, and a pipeline with the flag and no rate set is
invalid use on Vulkan, so plain ISF passes keep ignoring SHADING_RATE.
This needs VK_KHR_fragment_shading_rate on the shared device (the commit
enabling it): QRhi reports VariableRateShading from the physical device
either way, and without the extension the pipeline would use a dynamic
state the device never enabled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KdPgufk1W2MBbpcjraruZq
A geometry may carry an "indirect_draw_cmds_per_view" auxiliary: one copy
of the indirect command list per view, view-major. When a raw raster runs
PER_CUBE_FACE or PER_LAYER, each pass now draws from its own view's copy,
so a compute filter that culls against each view's frustum
(scene_cull_per_view.csf in score-csf-testers) leaves every cube face only
the draws it can see. Without the auxiliary, or when it is too small for
the pass's view, the shared list is used as before.

Measured on scenes made of many separate objects: GPU time -13% on an
RTX 5090, frame rate +10-21% on Intel ARL. Material-batched assets such
as sponza (one draw per material spanning the whole scene) gain nothing.

The copies are not compacted: a per-view cull zeroes the commands it
drops, and the indirect count is not applied to them. A sub-mesh with an
indirect buffer of its own keeps it. The auxiliary's size is clamped to
its buffer (0 meaning the rest of it), and one too small for a pass's view
warns once instead of silently drawing the shared list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KdPgufk1W2MBbpcjraruZq
QRhi's OpenGL backend only reports MultiView when both GL_OVR_multiview and
GL_OVR_multiview2 are present; Mesa's Intel driver has neither. The shader
was still baked with gl_ViewIndex and a view count in that case, which the
driver rejects, so MULTIVIEW shaders (prefilter_ggx, Camera Array) failed to
build there.

viewIndexNeedsPassIndexFallback now takes whether the renderer's QRhi
supports MultiView, and ShaderCache keys its bakers on it, so the lowering
to the per-pass VIEWINDEX uniform and the N-pass path are taken on any
backend without multiview, not only D3D. SCORE_GFX_DISABLE_MULTIVIEW goes
through the same input.

Plain ISF passes have no N-pass loop: there, a MULTIVIEW shader on a
backend without multiview renders view 0 only, which now warns once (raw
rasters render every view in its own pass). A shader with a single view
gets one baker whatever the renderer's multiview, instead of being
compiled again for each.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KdPgufk1W2MBbpcjraruZq
EXECUTION_MODEL gains an optional "FACES" expression, evaluated every
frame like MANUAL's COUNT: bit i set draws face i (+X -X +Y -Y +Z -Z).
A face left out is cleared to transparent once and then skipped, so
the cube stays complete and defined for whatever samples it (cube to
equirect, mips) while no fragment work is spent on it. Bool inputs now
bind in these expressions as 0/1, so a preset can expose one checkbox
per face. Without FACES every face is drawn, as before.

Rendering in the CAVE is bound by shaded pixels (one 1024x1024 face is
about 1.2 ms of the ~8 ms Sponza cube), and no projector looks at +Y
or behind, so dropping faces is the cheapest win.

An integer FACES is taken as it is, without compiling an expression each
frame; an expression's value is clamped to 0..63 rather than offset. A
numeric FACES may be written as a double, and a FACES on a pass that does
not run per face is ignored with a warning. Tested also with a mask that
changes between frames: the faces it drops come back cleared, the ones it
adds drawn.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KdPgufk1W2MBbpcjraruZq

This branch is waiting to be deployed

1 waiting deployment
full-ci — 9d644ab6 Waiting Nov 25, 2026 by jcelerier via Approve full PR suite #8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant