Skip to content

audit_shader4_regs: non-returning DS ops read every operand and write nothing - #3905

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
JRamos1993:fix-audit-rbw-lds-atomics
Nov 23, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
JRamos1993:fix-audit-rbw-lds-atomics

Conversation

@JRamos1993

Copy link
Copy Markdown
Contributor

New item (claimed in #3796).

What

scripts/audit_shader4_regs.py rbw_registers() treated args[0] of non-returning DS ops as a written destination, the case left after #3214. ds_add_u32 v1, v2 then v_mov_b32 v3, v1 gave ([], [2], []): v1 is the LDS address and is only read. The same applied to every non-_rtn DS atomic (ds_sub/rsub/inc/dec/min/max/and/or/xor/mskor/cmpst, the _f32/_f64/_u64/_b64 forms, ds_*_src2_*) and to ds_gws_init/ds_gws_barrier, whose data VGPR was counted as written.

A ds_ op now has no destination unless its name has _rtn or it is ds_read*, ds_swizzle*, ds_permute*, ds_bpermute*, ds_append, ds_consume or ds_ordered_count (new DS_HAS_DST, same rule as tools/lane_masks.py:143). Already correct on main and unchanged: ds_write* (in NO_DEST_OPS), all _rtn forms including ds_wrxchg*_rtn and ds_cmpst_rtn, ds_append/ds_consume, ds_swizzle, ds_permute/ds_bpermute, ds_read*, ds_ordered_count.

tests/test_audit_shader4_regs.py adds test_non_returning_ds_ops_read_every_operand, built with shader_ir.parse_line: the ds_add_u32 case above, 22 non-returning forms, and 12 returning forms that must keep args[0] written and not read.

Tested

Windows 11, Python 3.14 and 3.13, CPU only.

  • python -I tests/test_audit_shader4_regs.py: 8 tests OK (3.14 and 3.13). On main the new test fails: [2] != [1, 2] for ds_add_u32 v1, v2.
  • Mutations: dropping the _rtn guard fails 4 subtests (the _rtn forms); dropping the DS_HAS_DST guard fails 8 subtests (read/swizzle/permute/append/consume/ordered_count).
  • tests/test_text_write_line_endings.py, tests/test_tool_stdout_encoding.py: OK. python -m compileall -q on both files: OK.

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

… nothing

ds_add_u32 v1, v2 and the other non-_rtn LDS atomics (cmpst, mskor, the
f32/f64/u64/b64 forms, src2 forms) and ds_gws_init/ds_gws_barrier treated
args[0] as a written destination, so a later read of the LDS address
register was not reported as read-before-write. A ds_ op now has no
destination unless it has _rtn or is ds_read*, ds_swizzle, ds_permute,
ds_bpermute, ds_append, ds_consume or ds_ordered_count, the rule
tools/lane_masks.py already uses.
@tupacfan04

Copy link
Copy Markdown
Contributor

Tested at the head on Windows 11 / Python 3.13.0: 8 tests OK (7 on main), compileall clean, merge clean. Negative control: 1 failure, ([], [2], []) != ([], [1, 2], []) for ds_add_u32 v1, v2.

DS_HAS_DST (scripts/audit_shader4_regs.py:32-33) is character-identical to tools/lane_masks.py:48-49, ds_nop included. I probed ds_wrxchg_b32, ds_write/read_addtid, ds_cmpstore_b32, ds_gws_sema_v s2, ds_add_rtn_u64 and ds_wrxchg2st64_rtn_b32: all read correctly and write only where the ISA has a VDST, and no _rtn-less DS op in the repo or the design.md LDS rows carries a destination, so no real dependency is lost - the read set only grows.

Nit: this is now the third copy of the lane-mask rule; a shared constant would stop it drifting.

Approve. AI-assisted review, no game files, no GPU.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 72f5d2f merged with main 3faac55 on Linux (WSL2), Python 3.12.16: pass.
Ran tests/test_audit_shader4_regs.py (8 OK).
Negative control: scripts/audit_shader4_regs.py reverted to main gives 1 failure of 8, so only one of the new tests exercises the change; the other 7 pass against main's code too.

@JRamos1993

Copy link
Copy Markdown
Contributor Author

The two red checks on this run don't come from this PR, which only changes scripts/audit_shader4_regs.py and its test:

The branch still merges cleanly. A rerun on current main should clear the Windows one.

AI-assisted (Claude Code).

@ItsNotRexed
ItsNotRexed merged commit 54f9682 into ItsNotRexed:main Nov 23, 2026
3 of 10 checks passed
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.

4 participants