Skip to content

runtime: run a --vs-compute prepass before a non-indexed draw (#94, atom 3) - #8653

Open
claudetools-gh wants to merge 8 commits into
ItsNotRexed:mainfrom
claudetools-gh:vs-compute-runtime
Open

claudetools-gh wants to merge 8 commits into
ItsNotRexed:mainfrom
claudetools-gh:vs-compute-runtime

Conversation

@claudetools-gh

Copy link
Copy Markdown

Claimed in the coordination issue: #8504 (comment) (atom 3 of the plan in #94 (comment)).

Depends on: #8483, #8487. This branch is stacked on both; only the last commit, runtime: run a --vs-compute prepass before a non-indexed draw, is new here.

What and why

#8483 builds a tier-C wave64 VS as an emulated compute module, and #8487 adds the VS that draws its slots. This PR makes the layer use them.

Pipeline creation (d3d12_vulkan_device.cpp). A graphics PSO qualifies when its VS has a vs_compute index entry, it has no geometry shader, maxPushConstantsSize >= 156, and the device does not guarantee the VS 64-wide subgroups. Such a PSO also gets:

  • the compute pipeline from <name>.vs_compute.spv;
  • the same graphics pipeline with <name>.vs_compute_draw.spv as the VS.

"Not guaranteed" covers device_default as well as unavailable. AMD's Windows driver on an RDNA2 iGPU reports a default size of 64 and size control for compute only, and runs the VS 32-wide (measurement below and in #94 (comment)).

Replay (vulkan_replay.h). A non-indexed Draw with every attachment bound, on such a pipeline:

  1. A shader-read -> shader-write barrier.
  2. vkCmdDispatch(ceil(count / 64), instances, 1) outside the render pass. It writes into one 32 MiB region of the GPU address arena, allocated by the first such pipeline and shared by all of them.
  3. A compute-write -> vertex-read barrier.
  4. The draw itself, with the slot VS.

The push-constant block grows to 156 bytes for both: dwords 36..37 hold the region's address, and dword 38 holds the vertex count for the prepass and the slots per instance for the draw.

Unchanged. Indexed draws (atom 4), draws larger than the region, and draws that leave an attachment unbound keep the plain pipeline, so they behave as on main.

Shader library. ShaderLibrary reads vs_compute.vertex_stride, and spirv() takes a file suffix. The layer also reads the device's subgroup sizes itself when the device was created elsewhere (the tests); without that, every decision was unknown_device.

Tested

Windows 11, MSVC 14.51 (VS 2026), RelWithDebInfo, Vulkan SDK 1.4.363.0.

  • d3d12_vs_compute_test (new). It draws vs_w64_c_wave_color (new fixture: each full-target triangle coloured by its wave's active-lane count / 64) through a D3D12 PSO found by FSSM hash, with DrawInstanced(48, 2). The last triangle (vertices 45..47 in a wave of 48 lanes) decides every pixel.
GPU without the prepass with this PR (Khronos validation on)
RTX 5070 Ti, 621.01 (subgroups 32..32) 0.09375 (6 lanes: NVIDIA's VS batching) 0.75 on 4096 of 4096 pixels, 0 validation errors
Radeon RDNA2 iGPU of a Ryzen 7 9700X, AMD Windows driver (32..64, default 64, required for compute only) 0.5 (32 lanes) 0.75 on 4096 of 4096 pixels, 0 validation errors
  • d3d12_translated_draw still passes; it uses a non-tier-C VS, so the plain path.
  • Full ctest: 270 of 273 pass. The 3 failures (d3d12_vulkan_device, d3d12_indirect_dispatch_count, d3d12_depth_resolve) fail the same way on a clean main dde82f27e build on the same machine (TEST-1649 / d3d12_indirect_dispatch_count fails on main since #4312: cs_indirect_dispatch_count.comp still reads its root UAV from s0:s1 #6162 / the depth-resolve PRs).
  • test/shaders/build.py takes LEONIDA_VS_COMPUTE=1, which adds --vs-compute and runs tools/vs_compute_vs.py.
  • Not run: the retail boot with this. The game's own tier-C VS need a --vs-compute shaders stage first (make_game.py does not pass the flag yet).

AI-assisted: yes.

Checklist

claudetools-gh and others added 4 commits November 23, 2026 18:20
…pute module (issue ItsNotRexed#94, atom 1)

A wave64 vertex shader that wave64_halves puts in tier C is not exact on a 32-wide
subgroup. With --vs-compute the translator also builds it as a GLCompute module of one
64-lane wave per workgroup, so --wave64-emulate's workgroup exchange makes every
cross-lane operation exact: invocation i of workgroup (x, y) is vertex x * 64 + i of
instance y, lanes past the vertex count (push-constant dword 38) start inactive, and the
position and params go to the vertex's slot of a buffer at push-constant dwords 36..37
(vs_compute_layout, recorded in the VS's index entry as vs_compute). The VS module is
unchanged.

Tests: tests/semantic/test_vs_compute.py runs vs_w64_c_bcnt_export's code as one
64-invocation workgroup: the lane count is the 64-lane wave's (16, not 2 x 32's 8), a
40-vertex last wave counts 10 and stores nothing past the count, and the exports land in
slot y * (nx * 64) + x * 64 + i. run_emulated_workgroup gains Private variables and
WorkgroupId / NumWorkgroups values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ts (issue ItsNotRexed#94, atom 2)

Vertex v of instance n (VertexIndex - BaseVertex, InstanceIndex - BaseInstance, the v0
and v3 the original VS sees) reads slot n * row + v of the --vs-compute buffer (address
in push-constant dwords 36..37, row = NumWorkgroups.x * 64 in dword 38) and exports its
position and params at the original locations, so the pixel shader is unchanged.

tests/semantic/test_vs_compute_draw.py runs a tier-C VS (a lane count next to v0 and
v3) as the compute prepass over a 2 x 2 grid, then the draw shader per vertex: every
vertex of both instances exports what the VS exports in a 64-lane wave.
spirv_wave_interp's OpLoad now reads through PhysicalStorageBuffer pointers; the
branch that did it sat after OpAccessChain's return and was never reached.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tsNotRexed#94, atom 3)

A graphics PSO whose VS has a vs_compute layout, on a device that does not guarantee
the VS 64-wide subgroups, also gets the VS as a compute pipeline (<name>.vs_compute.spv)
and the same graphics pipeline with the VS that reads its slots
(<name>.vs_compute_draw.spv). A non-indexed draw with every attachment bound then
dispatches the prepass outside the render pass into one 32 MiB arena region (a
shader-read -> write barrier before, a write -> vertex-read barrier after) and draws
with the slot VS; the push-constant block grows to 156 bytes (dwords 36..38). Indexed
draws, draws past the region and draws with unbound attachments keep the plain
pipeline.

'Not guaranteed' includes a default subgroup size of 64: AMD's Windows driver on an
RDNA2 iGPU reports default 64 and size control for compute only, and runs the VS
32-wide (the test reads 32 lanes there without the prepass).

d3d12_vs_compute_test draws vs_w64_c_wave_color (each triangle coloured by its wave's
active lane count / 64) with DrawInstanced(48, 2): 4096 of 4096 pixels are 0.75 on an
RTX 5070 Ti (621.01) and on the Radeon iGPU of a Ryzen 7 9700X, with the Khronos
validation layer and no validation errors; without the prepass they were 0.09375 and
0.5. test/shaders/build.py takes LEONIDA_VS_COMPUTE=1. The layer reads the subgroup
sizes itself when the device was created elsewhere (the tests).
…ute; CLI and error-path tests

Review on ItsNotRexed#8483: the VS's index entry describes the VS (subgroup_size 64, no workgroup
memory, its capabilities), so a runtime building the compute variant from it would get
the wrong facts. vs_compute now also carries the module's: stage cs, local_size
[64, 1, 1], subgroup_size null, wave64_exchange workgroup, lds_bytes, capabilities,
extensions, features, float_controls, bindings and the rest of VS_COMPUTE_META_KEYS.

Tests: rdna2spirv.py --vs-compute on a folder (the written module validates, the
metadata above, the VS entry unchanged), build_vs_compute's refusal (vs_compute_error,
no module, VS_COMPUTE_PASS reset), and a partial wave whose inactive lanes still
write their slot.
…r mode's validated modules

Review on ItsNotRexed#8487: the draw test only had full waves and zero bases. Now 40 vertices of
one instance drawn with BaseVertex 100 and BaseInstance 7 read the slots the prepass
wrote (10 of the 40 lanes with v % 4 == 1), the 24 inactive slots, pre-filled with a
sentinel, hold the null outputs, and tools/vs_compute_vs.py's build_for_index writes one
validated .vs_compute_draw.spv per vs_compute entry and none for a plain VS.
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