Repository navigation
rdna2spirv: v_writelane_b32 reads its destination (SHADER-768) - #4297
LouisRiverstone wants to merge 2 commits into
Conversation
v_writelane_b32 writes one lane of vD and keeps the others, so the value vD held before is read. read_before_write_vgprs and reg_reads_writes counted only a write. Both now use one DST_ALSO_READ tuple (the accumulating ops they listed separately, plus v_writelane_b32). tests/semantic/test_writelane_read_before_write.py covers a first-touch writelane, a written-first one, scalar lane operands, reg_reads_writes, v_readlane_b32 unchanged and the existing fmac case.
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.
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.