Repository navigation
Translator/runtime: per-stage code-base slots, a PS reads its code base from dwords 38-39 (SHADER-67) - #1705
AGVibecoder wants to merge 1 commit into
Conversation
…ords 38-39 (SHADER-67) A VS (or MS) and a PS of one pipeline can both read code-embedded data through s_getpc_b64, but the push-constant block had one code-base slot (dwords 34-35), so CreateGraphicsPipelineState refused such a pair with E_NOTIMPL (open question 14, left by ItsNotRexed#291). - Translator: a PS that reads its code base takes it from dwords 38-39 (block 160 bytes); every other stage keeps 34-35. 36-37 stay --mesh-compute's output address. The index records code_base_dword and the real push_constant_bytes. Shaders without a code base are unchanged. - Runtime: each code-base stage gets its own FSSM blob in the arena and its VA in its slot; the layout's range is the stages' largest block. Two stages naming the same slot (an index from before this change) are refused with both names logged. - vk_harness: VKH_CODE=vs,ps fills both slots; the range is 160 bytes where the device has them. - Tests: tests/semantic/test_code_base_slot.py; d3d12_draw_test draws a VS and a PS that each read a constant from their own program. - Docs: design.md user-data row, d3d12_vulkan.md section 5.2, question 14. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independently verified commit
AI Assisted. |
|
Tested
Build: one warning, the existing C4459 on AI-assisted. |
|
Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51): pass. |
|
Independently tested
Follow-up on the same commit and hardware, with conda-forge llvm-mc 23.1.6 (AMDGPU), SPIR-V Tools 2026.4, and
AI-assisted (OpenAI Codex). |
|
Closing this PR. Since #2046 ( — Claude Opus 5.5 (low effort), AI-assisted |
SHADER-67: per-stage code-base slots in the translator and harness (open question 14; the follow-up to the
E_NOTIMPL#291 left behind). NoDepends on: it builds onmainas it is (#291 / #1083 and the bindless set 0 are already there).Problem
A VS (or MS) and a PS in one pipeline can both read code-embedded data through
s_getpc_b64. The corpus has 54 VS, 93 PS and 266 MS that do (tools/feature_scan.py, docs/d3d12_vulkan.md §5.2). But the push-constant block had one code-base slot, dwords 34–35. SoCreateGraphicsPipelineStaterefused any pair where both stages read it, logging "two stages read their code base; one push-constant slot holds one (question 14)" and returningE_NOTIMPL.Change
Translator (
tools/rdna2spirv.py,code_base_dword())--mesh-computemodules use 36–37 for their output address, and the following draw pushes that address tomesh_compute_vs.py's VS, in the same pipeline as the PS.%UserDatanow runs up to the last dword the shader reads, with explicit members and no offset gaps.spirv/index.jsongainscode_base_dword(34 or 38) next touses_code_base.push_constant_bytesis now the real block size: 144, 152 for--mesh-compute, or 160.Runtime
CreateGraphicsPipelineStategives each code-base stage its own FSSM blob in the arena, with its VA in that stage's slot.push_constant_bytes, andpush_constants_fit()checks that size.push_bytesfor draws and 144 bytes for dispatches.ShaderUserDatanow covers dwords 0–39, with static asserts on the size and the dwords 38–39 offset.code_base_dwordand so defaults to 34.s_getpc_b64for data.Harness (
vk_harness)VKH_CODE=vs,psputs code bases in dwords 34–35 and 38–39.maxPushConstantsSizeallows it, and unchanged otherwise.Docs: the contract's user-data row in
docs/design.md; indocs/d3d12_vulkan.md, section 5.2 (now "Implemented"), the code-base row of §5, the M1 refusal and push-constant notes, and open question 14.Tested
Windows 11 Pro 26200, Ryzen 9 5900X, AMD Radeon RX 7900 XTX (AMD proprietary 26.10.1 / LLPC, Vulkan 1.4.359), MSVC 19.44 (VS Build Tools 14.44) + Ninja, Vulkan SDK 1.4.363, Python 3.12.10. Everything below was run on the rebased commit
1a74469c.python -m compileall -q make_game.py tools testsandpython -I make_game.py --help: ok.python -m unittest discover -s tests/semantic: 1402 tests, OK. This includes the newtests/semantic/test_code_base_slot.py:spirv_mini_interpwith different words in dwords 34–35, 36–37 and 38–39. It must return the 38–39 code base plus the next-instruction offset, with a carry into the high dword.%c3/%c4access chain.tests/test_shader_meta.py,test_feature_scan.py,test_feature_scan_bad_index.py,test_run_gpu_tests.py,test_shader_index.py: all pass.tests/test_mesh_compute.py(pytest): 9 passed, 13 skipped. The skipped ones need llvm-mc.spirv-val --target-env vulkan1.3on the translated VS and PS: valid.cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo,-j 4): no errors, and no warnings in the changed files.ctest: 92 pass. Skipped:bink_decode,bink_audio,fsr_dispatchandbvh_builder, which need the package DLLs.gameinputis disabled upstream.loaderfailed once in the parallel run on its own guard ("PE images ... not readable straight away ... 97 ms", security-software scanning). Run alone it passed twice, in the default temp folder and withLEONIDA_TEST_DIRon another drive. This change doesn't touch the loader.d3d12_draw_teston the GPU, withLEONIDA_VK_VALIDATION=1: all pixels match and there are no validation messages. Its new draw:code_base_dwordis refused withE_NOTIMPL.data.ps_code_base = ...in replay, the test fails with that quadrant red.vk_harnesson the GPU with a translated PS: a hand-written listing (s_getpc_b64→s_load_dwordx2from its own code → export) was translated, assembled withspirv-asand drawn withVKH_CODE=0x1000,0x2000. The data sits at code base + 4 in the heap, with a decoy at the VS's address. Result: 4096/4096 pixels(0x600dc0de, 0x12345678, 0x2004, 0).Not run: an
.asmGPU fixture inruntime/test/shaders+check.py/scripts/run_gpu_tests.py. This machine has no llvm-mc with the amdgcn target, sobuild.pycan't assemble fixtures, and I didn't add a fixture I couldn't run. Thevk_harnessrun above covers the same path, with SPIR-V from the translator under test, but without llvm-mc. A follow-up can addps_code_base.asmwithVKH_CODE/VKH_HEAPentries in bothPIXEL_ENVtables once llvm-mc is available. Nothing was tested on NVIDIA, Intel or MoltenVK.No game data: every shader and program in the tests is hand-written.
AI-assisted.
— Claude Opus 5.5 (high effort), AI-assisted
🤖 Generated with Claude Code