Repository navigation
rdna2spirv: vertex fetch fills the registers the shader reads, not every declared one (SHADER-628) - #3814
rdna2spirv: vertex fetch fills the registers the shader reads, not every declared one (SHADER-628)#3814kotorvr wants to merge 5 commits into
Conversation
|
Tested ceebf6f on CPU only (no GPU, no game files), Linux (WSL2), Python 3.12.3: pass
One observation, not a blocker and unchanged from AI-assisted. |
|
The shared-register case in import sys
sys.path.insert(0, "tests/semantic")
import test_vertex_fetch_slots as t
sig = t.isg1_dxbc([(0, 3, 3, 0, t.FLOAT), (0, 12, 12, 0, t.FLOAT)])
lines = ["s_swappc_b64 s[4:5], s[4:5]", "exp pos0 v4, v5, v6, v7 done", "s_endpgm"]
s = t.support.translate_lines("vs_fetch", lines, dxbc=sig)
for prefix in ("%vin0 =", "%vinv0 =", "%vinc0_0 ="):
print(prefix, sum(line.strip().startswith(prefix) for line in s.splitlines()))Each count is 2; each result ID needs exactly one definition. The merge base also emits duplicates, so this predates the PR. The new slot map coalesces the elements, but the declaration and fetch loops still walk one |
whattheflop
left a comment
There was a problem hiding this comment.
AI-assisted Windows CPU review at ceebf6f0 on the original base f847748c, with #3403 a8d84cfc and #3512 147396bd. The nine focused tests and the full 7,331-test semantic run passed (one expected failure), and the translator/index pytest selection had 572 pass and four skips.
A compound synthetic fixture declared unread COLOR0 at register 0, packed TEXCOORD3.xy and BLENDWEIGHT0.zw at register 1, and ordinary POSITION0 at register 2. The original #3512 keeps physical locations separate but places register 1 in its original VGPR slot, so a shader using the compact slot reads the wrong four words. In scratch I kept #3512's per-semantic locations and applied this PR's read-register order to the logical VGPRs. The combined module validated and exported the expected words c0200000 3e000000 40600000 bf400000. The native Windows layout builder still bound the two independent attributes at locations 1 and 3, with their original buffer slots and offsets.
The composition ORs ISG1 read masks across rows in a shared register to decide whether that register receives a slot. The declared masks continue to route each semantic's components. Both focused suites passed in the local composition. Upstream 4c52ce27 has since landed its own per-register deduplication and #3512 is being reconciled. When both changes are combined, the two independently testable contracts are the compact VGPR mapping and the per-semantic Vulkan binding. No corpus or GPU run.
|
On 1.0.2.1, all 788 fetch-calling vertex shaders translated and passed spirv-val on base f847748 and head ceebf6f. All 12 distinguishing cases matched the compact VGPR rule and zero matched the old rule; emitted destinations agreed with the header in every one. No corpus shader shared an attribute register, leaving the synthetic shared-register finding open. CPU only, aggregate counts. AI-assisted. |
|
The code is right and the test is real, but it needs a rebase with a semantic (not just textual) resolution. Verified at the head ( The rule holds: the k-th register (in register order) whose ISG1 read mask (byte 25) is non-zero gets Blocking: the PR is Non-blocking, pre-existing here but fixed on AI-assisted review, no game files, no GPU. |
One fetch slot and one Vulkan input for the register, and the registers above an unread one still move down. Asked for in review of ItsNotRexed#3814. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ceebf6f to
26299ac
Compare
…ery declared one A VS that starts with s_swappc_b64 gets its attributes from the driver's fetch program. The translator wrote input register r to v(4 + 4r + c). The fetch program hands out VGPRs only to the registers the shader reads: the k-th register whose ISG1 read mask is not 0 is in v(4 + 4k + c), and a register that is declared and never read gets none. With an unread register below a read one the shader translated with its attributes in the wrong VGPRs. Counted on a 1.0.2.1 work folder: of 775 fetch-calling VS the rules differ for 12, which read exactly the new rule's VGPRs (12 of 12), and the FSSM header records name first VGPR 4 + 4*position in 775 of 775. Locations stay the D3D input registers and every declared register is still declared, so the index metadata is unchanged. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The first count missed the shaders whose file names start with a dot (a glob does not match them): 788 fetch-calling VS, not 775. The rules still differ for 12, all 12 read the new rule's VGPRs, and the FSSM records agree in 788 of 788. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…nd xbox-emulator 116 of the 788 fetch-calling VS declare SV_VertexID or SV_InstanceID; none of those registers has an FSSM record or a fetch VGPR. related_projects.md gets an entry for the two projects the row cites (xcl is GPL-2.0-only: facts only). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
xbox-emulator is GPL-3.0-or-later and does look at this game's data; xcl and it are not counted as independent. The system-value result rests on the FSSM records, which the row now says. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
One fetch slot and one Vulkan input for the register, and the registers above an unread one still move down. Asked for in review of ItsNotRexed#3814. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
26299ac to
36dbc71
Compare
|
Tested on Windows 11 with two GPUs on one machine (head merged with main aa2988c, MSVC 14.51, Python 3.13.1):
I did not check shdann's duplicate-SPIR-V-ID report on the shared-register case. The vk_* programs came from a runtime built from main f847748. |
|
Thanks, all four of you (and @kacper-serewis and @kapitche for the corpus and GPU runs). Rebased on @shdann: right, and it predates this PR. Since you wrote, @ramosbezzu: thanks for the independent run. On the unread register keeping its After the rebase, on Windows 11, Python 3.13.7:
AI-assisted (Claude Code). |
|
A suggestion for this block, since this PR rewrites it and a separate PR would conflict with it: the last line, A guard would keep the VS path as honest: replace only the recognised fetch call and raise AI-assisted. |
|
Tested 36dbc71 merged onto main 03b09a0 on an RTX 5090 (driver 616.92), Windows 11, Vulkan SDK 1.4.363. The GPU test programs were built from the same tree:
AI-assisted (Claude Code). |
SHADER-628 (listed in #3574). Claim: #3232 (comment)
What was wrong
A vertex shader that starts with
s_swappc_b64calls the driver's fetch program, and the translator replaces that call with Vulkan vertex inputs written into VGPRs at entry. It put input registerrinv(4 + 4r + c).The fetch program gives VGPRs only to the registers the shader reads. The k-th register whose
ISG1read mask (byte 25 of the element) is not 0 is inv(4 + 4k + c); a register that is declared and never read gets none, so the registers above it move down. The two rules agree unless an unread register sits below a read one. In that case the shader still translated (the check only asked that reads stay inside the declared registers' slots), with every attribute above the unread register in the wrong VGPRs.How it was confirmed
Counts over my own 1.0.2.1 work folder (all 788 fetch-calling VS; counts only, no shader content here or in the diff):
SV_VertexID/SV_InstanceID(a register of their own)The 3 VS that
docs/design.mdexplained as reading.wof anxyzelement are among the 12: they read thexyzwregister above an unread one.Where the lead came from: this is one of the points where other Xbox Series translators differ from Leonida. xcl (
crates/xcl/src/gpu/recomp/mod.rs,cf08a50a, GPL-2.0-only) and omonkeyz/xbox-emulator (crates/tombox-xshader/src/hlsl.rs,0fc72956, GPL-3.0-or-later) use the read-registers rule; xcl records seeing it on another title. The notes of xcl cite the library map of TomBox, which xbox-emulator continues, so I do not count the two as independent. realdody/americas-recomp (tools/xbox/fssm_header.py,f1c25d72, GPL-2.0-only) describes the FSSM record layout. I read those sources for the facts; nothing is copied or ported. The rule here rests on the counts above, and the code is this repository's own.What changed
tools/rdna2spirv.py:input_signature_read()returns the ISG1 read mask as well (input_signature()is unchanged for its callers);vertex_fetch_slots()gives each read register its position;translate()and the entry code use4 + 4·position. Locations stay the D3D input registers and every declared register is still declared, sovertex_inputs/vertex_input_signaturein the index and the runtime contract are unchanged. An unread register is declared and never loaded. A read past the fetched registers is stillUnsupported("fetch mapping").docs/design.md: the Vertex fetch row states the rule and how it was confirmed.docs/related_projects.md: an entry for xcl and xbox-emulator, which the row cites (facts only).Open #3403 (SHADER-644, dedupe packed VS input registers) changes the same lines of
tools/rdna2spirv.py: a trial merge conflicts there. It is a different fix, not a duplicate; whichever lands second rebases.tests/semantic/test_vertex_fetch_slots.py(new, 9 tests) and its entry intests/semantic/README.md.Tests
mainaa2988cc(head36dbc716):python -m unittest discover -s tests/semantic: 7,466 tests; the only failures are 7 failures and 2 errors thatmainaa2988cchas without this PR (intest_loop_ballot_barrier,test_mutationsandtest_cmp_class_f64: the same 9, checked on a clean checkout ofmain), so this PR adds none.test_two_elements_in_one_registeradded in review): against the translator before this change, 5 failures and 2 errors of the first 9 (the 2 that pass are the cases where both rules agree).python -m pytest tests/test_translate.py tests/test_shader_index.py: 591 passed, 4 skipped (after the rebase).python -m compileall -q make_game.py tools tests,python -I make_game.py --help,python -I tests/test_text_write_line_endings.py,python -I tests/test_vs_input_survey.py,python -I tests/test_isa_coverage.py: pass.spirv-val-valid before, 788 translated and 788 valid after (spirv-asandspirv-val --target-env vulkan1.2 --allow-offset-texture-operand, SPIRV-Tools v2026.4 from Vulkan SDK 1.4.363.0). The output text changes for 34: the 12 above, plus 22 that no longer load an unread register.python -I tests/test_docs_design_rows.py,test_docs_links.py,test_docs_list_items.py,test_docs_repo_paths.py: OK.No GPU was used: the fetch program is the console driver's, so there is nothing to run on a PC GPU. Windows 11, Python 3.13.7.
AI-assisted (Claude Code).
🤖 Generated with Claude Code