Skip to content

mesh_compute_vs: read output address from %pc_tail when pc_tail_address_dwords is set - #2528

Open
whoalin1 wants to merge 1 commit into
ItsNotRexed:mainfrom
whoalin1:mesh-compute-vs-pc-tail
Open

whoalin1 wants to merge 1 commit into
ItsNotRexed:mainfrom
whoalin1:mesh-compute-vs-pc-tail

Conversation

@whoalin1

Copy link
Copy Markdown
Contributor

Claimed in #2300 (comment).
Depends on: #2046 (which adds --pc-tail-ubo and writes pc_tail_address_dwords: [4, 5] into mesh_compute metadata).

Summary

  • tools/mesh_compute_vs.py:
    • When a mesh_compute layout contains pc_tail_address_dwords (two non-negative ints, e.g. [4, 5] from rdna2spirv.py --mesh-compute --pc-tail-ubo), emit the vertex shader's 64-bit output-buffer address loads from the set-1 binding-0 Uniform block %pc_tail (%PcTail, 24 bytes / 6 dwords) instead of a 152-byte %pc PushConstant block, and include %pc_tail in OpEntryPoint's interface.
    • Because this vertex shader does not read user SGPRs s0..s31, omitting the PushConstant block leaves it at 0 push-constant bytes, so it links cleanly on 128-byte push-constant devices alongside a 128-byte --pc-tail-ubo pixel shader.
    • Reject malformed pc_tail_address_dwords values (wrong length, negative, bool, non-int) with ValueError.
    • Without pc_tail_address_dwords, vs_spvasm() output is byte-identical to main.
  • Tests:
    • tests/test_mesh_compute_vs.py: add interface check for %pc_tail / set-1 binding-0 / no PushConstant, malformed-value validation tests, and spirv-as + spirv-val --target-env vulkan1.2 assembly tests (plain, clip, clip+cull+params, f16_halves).
    • tests/test_mesh_compute.py: add test_vertex_shader_text_pc_tail and parametrize test_vertex_shader_validates across both push-constant and --pc-tail-ubo layouts.

Testing

All tests ran on Windows 11 with Python 3.14, Vulkan SDK 1.4.363 (spirv-as/spirv-val, VK_LAYER_KHRONOS_validation), llvm-mc 21, synthetic inputs only (no game data):

  1. Unit & SPIR-V validation tests (pytest):
    • tests/test_mesh_compute_vs.py, tests/test_mesh_compute.py, tests/test_text_write_line_endings.py: 43 passed, 10 subtests passed (0 failed).
    • Verified vs_spvasm() output without pc_tail_address_dwords is byte-identical to origin/main across plain, clip, clip+cull+params, and f16_halves layouts.
    • py -3.14 -m compileall -q tools/mesh_compute_vs.py tests/test_mesh_compute_vs.py tests/test_mesh_compute.py: clean.
  2. Real-GPU pipeline check (vk_pipeline_check from vk_pipeline_check: support --pc-tail-ubo set-1 layouts and 128-byte push-constant devices #2480 with VK_LAYER_KHRONOS_validation, paired with spirv_stubs.py PS stubs using #2046's mesh_compute_layout(..., PC_TAIL_UBO=True)):
    • AMD Radeon(TM) Graphics (Ryzen 5 7600 RDNA2 iGPU, AMD Windows driver 24.10.24, Vulkan 1.3.280, 128-byte push constants): 2/2 VS pipelines ok, 0 failed, 0 skipped, 0 validation errors (ms_tri.mesh_vs, ms_clip.mesh_vs).
    • NVIDIA GeForce RTX 4070 SUPER (driver 610.88, 256-byte push constants): 2/2 VS pipelines ok, 0 failed, 0 skipped, 0 validation errors.

Checklist

  • Synthetic inputs only (no game data)
  • AI-assisted (Antigravity / Gemini 4 Neon)
  • Pure LF line endings verified (git diff --check clean)

🤖 Generated with Antigravity (Gemini 4 Neon)

@duudiis

duudiis commented Nov 22, 2026

Copy link
Copy Markdown

Independent RTX 5070 / Windows run at 784580d (driver 621.24, 32-wide subgroups). I dispatched and drew the synthetic ms_tri fixture using wave64 emulation and the generated companion VS.

  • Baseline used a 152-byte push-constant range. The tail build used a 128-byte range and a 24-byte uniform block at set 1, binding 0, with the address words at offsets 16 and 20.
  • Both generated companion shaders passed spirv-val --target-env vulkan1.2. Both GPU draws produced byte-identical 64×64 RGBA32F readbacks. All 4,096 pixels matched the analytic ramp exactly.
  • For the tail run, I added the descriptor binding to a temporary copy of the test harness. The RTX 5070 exposes 256 push-constant bytes, so this covers the shader pair and the 128-byte layout on NVIDIA. The hardware-limit result on a 128-byte device is covered by the author’s pipeline test above.

@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested head 784580d merged onto main 4947579 (clean merge), Windows 11, Python 3.13, CPU only. python -m pytest tests/test_mesh_compute.py tests/test_mesh_compute_vs.py: 41 passed, 10 subtests passed in 2.77s. Negative control: the same test file against main's non-test sources gives 10 failed, 39 passed, 2 subtests passed in 2.19s, so the test exercises the change.

AI-assisted (Claude Code); runs on my machine.

@whoalin1
whoalin1 force-pushed the mesh-compute-vs-pc-tail branch from 784580d to 41760b9 Compare November 22, 2026 18:12
…ss_dwords is set

When index.json's mesh_compute layout carries pc_tail_address_dwords (as
produced by rdna2spirv.py --mesh-compute --pc-tail-ubo), emit the vertex
shader's output-buffer address loads from the set-1 binding-0 Uniform block
%pc_tail (%PcTail) instead of a 152-byte PushConstant block, omitting
PushConstant completely so the vertex shader fits 128-byte push-constant
devices. Without pc_tail_address_dwords, the emitted SPIR-V assembly is
byte-identical to before.

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 312794a1 merged onto main 1cc6e3c1 on Windows 11, CPython 3.14.3, CPU only: pass.

  • python -I -m pytest -q tests/test_mesh_compute.py: 28 passed.
  • python -I tests/test_mesh_compute_vs.py: 16 tests OK.
  • Negative control (tools/mesh_compute_vs.py from main, the PR's tests kept): tests/test_mesh_compute.py 1 failed, 27 passed; tests/test_mesh_compute_vs.py 16 tests FAILED (failures=9).
  • py_compile on the 3 changed Python files: OK; git diff --check: clean.

No game files. AI-assisted (Claude Code).

@NJ1912

NJ1912 commented Nov 23, 2026

Copy link
Copy Markdown

Code read of 312794a1 (merges cleanly onto main 1cc6e3c1): the generator change looks right; one gap in GPU coverage.

  • tools/mesh_compute_vs.py:37 (_pc_tail_dwords) and the --pc-tail-ubo branch match what rdna2spirv.py emits for --mesh-compute with --pc-tail-ubo: the address in tail dwords 4..5 (pc_tail_address_dwords=[4, 5]), set 1 / binding 0, a Block of uint members at Offset 4*k, 6 dwords = 24 bytes, which is the slot size in runtime/test/vk_pc_tail.h. The malformed-value checks (bool, negative, wrong length) look complete.
  • Gap: runtime/test/vk_harness.cpp:372 on main (:371 on this branch) still refuses LEONIDA_PC_TAIL_UBO=1 together with VKH_MESH_COMPUTE and exits 77 with "--mesh-compute's vertex shader reads the output address from push constants, not from the --pc-tail-ubo block". With this PR that message and the comment above it are no longer true, and the new vertex-shader path cannot run on a GPU through the harness, so a mesh-compute run through it cannot have used %pc_tail. Suggest lifting the guard here (and checking that the harness writes the output address into dwords 4..5 of the tail slot), or posting it as a finding: follow-up.

Not run: code read only; I compared against rdna2spirv.py and the harness on main, no GPU. AI-assisted review.

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.

5 participants