Repository navigation
rdna2spirv: v_writelane_b32 reads its destination (SHADER-768) - #4297
LouisRiverstone wants to merge 3 commits into
Conversation
Kam471
left a comment
There was a problem hiding this comment.
Ran this at 5033bf66 on Windows 11: python tests/semantic/test_writelane_read_before_write.py -> 6 tests, OK; compileall and git diff --check clean.
v_writelane_b32 now models the destination read (the old value in lanes other than the selected one), so a lane-spill pair that reads a destination before writing it round-trips. The new cases cover the read-before-write shape; the existing lane-select tests pass. No blocking issue.
|
Checked
No GPU run for this one (it changes analysis, not emission). No game files. AI-assisted (Claude Code). |
|
GPU check: tested 5033bf6 (merged onto main 03b09a0) on NVIDIA GeForce RTX 3060 12 GB (Ampere), driver 610.88, Windows 11 Pro 26300, MSVC (VS 2022 Build Tools,
As expected for an analysis-only change, no GPU result moved. AI-assisted (Claude). No game files. |
Flyander
left a comment
There was a problem hiding this comment.
Reviewed the current head 5033bf66. The translator now preserves the old destination value for lanes not selected by v_writelane_b32, which is required by the read-before-write spill pattern. The independent semantic tests cover that shape. No blocking issue found.
|
Tested 5033bf6 on Windows, CPython 3.14.7, CPU only (no GPU, no game files).
I found one point. The description says "No reject decision changes today". This is not correct for all inputs.
Reproduction with hand-written listings: save this script as import os, sys
sys.dont_write_bytecode = True
sys.path.insert(0, os.path.join(os.getcwd(), "tests", "semantic"))
sys.path.insert(0, os.path.join(os.getcwd(), "tools"))
import support, rdna2spirv
def run(label, name, lines):
try:
asm = support.translate_lines(name, lines)
asm = asm[0] if isinstance(asm, tuple) else asm
print(f"{label}: translated ({len(asm.splitlines())} lines, BaryCoord input: {'BaryCoord' in asm})")
except rdna2spirv.Unsupported as e:
print(f"{label}: rejected: {e}")
# A vertex shader that calls the fetch program and keeps an SGPR in one lane of v40 across the call.
vs = ["v_writelane_b32 v40, s2, 0",
"s_swappc_b64 s[4:5], s[4:5]",
"v_readlane_b32 s2, v40, 0",
"v_mov_b32_e32 v1, s2",
"exp pos0 v1, v1, v1, v1 done",
"s_endpgm"]
run("VS, fetch call, v_writelane_b32 v40 first", "vs_writelane_spill", vs)
run("VS, fetch call, v40 written first", "vs_writelane_spill2", ["v_mov_b32_e32 v40, 0"] + vs)
# A pixel shader whose first operation on v0 is v_writelane_b32.
run("PS, v_writelane_b32 v0 first", "ps_writelane_v0", ["v_writelane_b32 v0, s2, 0", "v_mov_b32_e32 v20, v0",
"exp mrt0 v20, v20, v20, v20 done vm", "s_endpgm"])Actual result at this head: the first vertex shader gives Expected result: the first vertex shader is translated. It keeps an SGPR in one lane of v40 while the fetch call runs, and v40 is not a fetched attribute. AI-assisted. |
|
Tested
No game files. AI-assisted (Claude Code). |
|
GPU run as well: |
|
Thanks @shdann. You're right, and the description was wrong: I took "no reject decision changes" from the table entry without checking the three callers. Counting every writelane destination as a read made your VS spill (v40 around the fetch call, read back with Fixed in
Both of your listings, plus the readlane-only spill and a full write ending the carry, are now in |
…n used @shdann showed on ItsNotRexed#4297 that counting every v_writelane_b32 destination as a read changes decisions: a VS that spills an SGPR into one lane of v40 around the fetch call (read back with v_readlane) was rejected with 'fetch mapping'. The kept lanes are now carried: they become a read when something other than v_readlane_b32 reads the register before a full write. A PS whose first touch of v0 is a writelane and then reads v0 still gets its barycentric input, which those lanes hold. reg_reads_writes (per slice) keeps counting the destination as read; DST_ALSO_READ is back to the accumulating ops. The test adds shdann's VS spill and PS cases end to end, the readlane-only spill, and a full write ending the carry.
|
Tested a35d9e5 merged onto main d0835dd 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). |
…r lanes (SHADER-768) v_writelane_b32 writes one lane and keeps the others. read_before_write_vgprs counted it as a full write. Counting every writelane destination as a read is too much the other way (@shdann on ItsNotRexed#4297: a VS spilling an SGPR into one lane of v40 around the fetch call was rejected with 'fetch mapping'). The kept lanes are now carried: they become a read when something other than v_readlane_b32 reads the register before a full write. reg_reads_writes (per slice) counts the destination as read. DST_ALSO_READ names the accumulating ops both functions list. tests/semantic/test_writelane_read_before_write.py: carried and used lanes, the readlane spill, a full write ending the carry, shdann's VS spill and PS cases end to end.
a35d9e5 to
d73fabd
Compare
|
Tested d73fabd merged with main 98fa503 on Linux (WSL2) Python 3.12.16: pass (Linux only; CPU-side translator analysis, no GPU run).
Negative control: with tools/rdna2spirv.py restored from main, 4 of the 9 new tests fail (kept_lanes_read_afterwards, lane_operands_are_scalar, ps_kept_lanes_of_v0_get_the_barycentric, reg_reads_writes_counts_the_destination); restored afterwards. Read the diff of read_before_write_vgprs: a writelane to a register not yet fully written marks it carried, a later non-readlane read of it counts, a full write clears the carry, and the DST_ALSO_READ refactor keeps the same op list as before. No issues found. |
|
Thanks @JRamos1993 (RTX 5090, same 164/210 as |
# Conflicts: # tools/rdna2spirv.py
|
Game-copy check of All 26,503 translate and pass AI-assisted (Claude Code). |
|
Follow-up for the current head AI-assisted (Claude Code). |
|
Tested PR #4297 at commit Results
|
|
Tested 7b3145e on Steam Deck LCD (Jupiter), AMD Custom GPU 0405 "Van Gogh", RADV Mesa 26.2.0-devel (git-5c65d4fc31), Vulkan 1.4.350, SteamOS 3.9.5 (holo), kernel 7.2.7-valve2-2-neptune-72-g31504582a073: pass.
No runtime C++ changes in this PR; tested from the PR worktree against the existing runtime build. AI-assisted (OpenCode). |
# Conflicts: # tools/rdna2spirv.py
|
Tested the current head
Every PASS/FAIL/SKIP row is identical between the two. The one failure on both is AI-assisted (Claude Code). |
|
Independent Windows validation at Environment: Windows 11 26300, NVIDIA GeForce RTX 4050 Laptop GPU, NVIDIA
So this head validates on the CPU suite and the emulated 64-wide path; native |
|
Tested be4ce32 merged with main 1cc6e3c on Linux/Python 3.12.16: concern (conflicts with current main) Against 1cc6e3c the merge is clean. Ran tests/semantic/test_writelane_read_before_write.py (9 tests, OK) and the lane-related semantic tests (test_fspx_wave_size, test_lane_mask_reductions, test_lane_masks_edge_cases, test_lane_masks_vector_bitwise, test_permlane_fi, test_salu_flbit_lane_mask all OK, test_salu_b32_lane_masks OK with one skip). Negative control: restoring tools/rdna2spirv.py from 1cc6e3c makes 4 of the 9 new tests fail; restored, all 9 pass. The full semantic suite did not finish inside my 20 minute limit. Nothing GPU-bound was run. Concern: against current main a66e6e3 the merge conflicts in tools/rdna2spirv.py (around line 15504). Main now has a longer destination-also-read condition (extra v_fmac/v_mac/v_dot*c ops, and buffer_load_ d16) where this PR replaces it with DST_ALSO_READ and global_load_ d16. The resolution has to keep main's added ops and the buffer_load d16 case. Redundancy: not found. #488 (aa1c217) only covers the wave32 lane select mask, and open #4134 is a fuzzer for control flow, not this fix. |
SHADER-768, from the "Up for grabs" table in #4257:
read_before_write_vgprscountedv_writelane_b32as a full write of its destination.v_writelane_b32 vD, sSRC, sLANEwrites one lane ofvDand keeps every other lane's value. The translator's own emission loads the oldvDand selects per lane. So the valuevDheld before is read, and a shader whose first touch of a VGPR is a writelane should report that VGPR as read before written.Change:
read_before_write_vgprs,v_writelane_b32no longer counts as a write of its destination. The kept lanes are carried and become a read only when something other thanv_readlane_b32reads the register before a full write.fetch mapping), a common compiler pattern.v0/v1is a writelane, and that then reads the register, now gets its barycentric input, which those lanes hold. Onmainthey read a zeroed register. The VS spill translates, as onmain.v_readlaneof a lane the writelane didn't write would read the entry value, and isn't counted.reg_reads_writes: per slice, it counts the writelane destination as read.DST_ALSO_READnames the accumulating ops both functions share.Tests:
tests/semantic/test_writelane_read_before_write.py:reg_reads_writescounts the destinationv_readlane/v_fmacare unchangedBaryCoordWith it, 9/9 pass. Against
main'stools/, the four tests of the new reads fail, and the VS spill passes as onmain.tests/test_shader_checks.pypasses.python -I -m unittest discover -s tests/semantic: 10 failures, the same onesmainhas without this change, each with an open PR (#3885/#3948test_cmp_class_f64, #3883 thev_mul_legacymutation anchor, #3995test_loop_ballot_barrier, #4004test_vcmp16_opsel). I didn't runtests/test_translate.py, because it needspytestand this machine has only the standard library.Tested on CPU only. No game files. Claimed on #4257 before starting.
AI-assisted (Claude Code): I reviewed and ran the change and the tests.