Repository navigation
shader_meta: fold s_ashr_i32, s_bfm_b32, s_bfe_u32, s_min_u32, s_max_u32 and s_abs_i32 of known constants (follow-up of #4546) - #4604
Conversation
…known constants _step_state did not fold the inverted scalar logic operations. Thus a literal S# that has one dword made with one of them (for example 0xFFFFFFFF as s_not_b32 of 0) was not in literal_samplers. s_not_b32 of a known constant is now a known constant. s_nand_b32, s_nor_b32 and s_xnor_b32 of two known constants fold together with the other two-source logic operations. A source that is not a known constant gives no constant, as before. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…u32 and s_abs_i32 of known constants _step_state did not fold these scalar operations. Thus a literal S# that has one dword made with one of them was not in literal_samplers. The two-source operations fold in _fold_scalar_alu with the values that the translator computes for immediates: the shift count of s_ashr_i32 is modulo 32, s_bfm_b32 makes a mask of (width & 31) ones at (offset & 31), and the field of s_bfe_u32 stops at bit 31. s_abs_i32 of a known constant is a known constant. A source that is not a known constant gives no constant, as before. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Tested What I ran:
Code review:
|
Kam471
left a comment
There was a problem hiding this comment.
Ran this at 005b2306 on Windows 11: tests/test_shader_meta.py -> 23 tests, OK; git diff --check clean.
The six ops (s_ashr_i32, s_bfm_b32, s_bfe_u32, s_min_u32, s_max_u32, s_abs_i32) fold known constants with the same 32-bit width/signedness handling as the #4546 set, and the added cases cover each op plus the non-constant case that must stay unfolded. No blocking issue.
|
Tested 005b230 merged with main d0835dd (merge c68760b72, no conflicts) on Linux (WSL2) Python 3.12.16 and native Windows 11 Python 3.13.1: pass.
|
whattheflop
left a comment
There was a problem hiding this comment.
AI-assisted independent Windows CPU check of the top commit 005b2306 on #4546 14b51cc7, uv CPython 3.12.13. analyse_instructions() returned the expected literal_samplers in 427 synthetic comparisons against a separate bit-list reference. The matrix covered shift counts 31/32/33/63, bitfields extending past bit 31, unsigned high-bit ordering, abs(INT_MIN), and destinations aliasing source 0, source 1 or both. Chained folds across both PRs propagated known words, and an unknown input invalidated a previously known destination. The two stock metadata suites passed 28/28. No game data or GPU execution.
|
Tested head
AI-assisted (Devin). |
|
Verified against main 3faac55: merges cleanly; test_shader_meta 23/23, test_shader_meta_operands 5/5, test_vs_packed_inputs 3/3 in the venv (re-run). The new fold rules match GCN/RDNA semantics including the bfe width clamp, bfm width-0 to 0 and the INT_MIN abs edge, so conservative folding cannot change a known-constant result. Title references closed #4546 — its content is carried in your own commits, no dependency. Checks pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run). |
Claimed in the coordination issue (claim). The claim has no item ID at this time.
Depends on: #4546
This branch is one commit (
005b2306) on top of the commit of #4546 (14b51cc7). Until #4546 merges, the diff of this pull request also shows the commit of #4546. Review only the second commit here.What and why
_step_stateintools/shader_meta.pyfollows the constants in the SGPRs. #4546 lists six scalar operations that it does not fold. This pull request folds them. Without the fold, a literal S# that has one dword made with one of these operations is not inliteral_samplersof the index.Hand-written listing (no game data), one example:
14b51cc7):literal_samplersis[].literal_samplersis[[146, 3840, 0, 0]].The folds use the same rules that
tools/rdna2spirv.pyuses when the sources are immediates:x,ys_ashr_i32xas a signed value, shifted right byy & 31s_bfm_b32x & 31ones, shifted left byy & 31s_bfe_u32y & 31, width bits 22 to 16 ofy; the field stops at bit 31; width 0 gives 0s_min_u32,s_max_u32s_abs_i32xas a signed value;0x80000000stays0x80000000A source that is not a known constant gives no constant, as before.
The second commit changes
tools/shader_meta.pyby 22 added lines and 2 removed lines.I did not add
s_bfe_i32,s_min_i32ands_max_i32. My probe did not include them, and I keep this change to the six operations of the claim.Tested
Windows 11, CPython 3.14.7, CPU only. No GPU and no game files.
New tests in
tests/test_shader_meta.py:test_shift_bitfield_min_max_abs_fold_into_literal_sampler: 16 listings. They include a shift count larger than 31, a width of 0, a field that goes past bit 31, values with the top bit set for the unsigned minimum and maximum, and0x80000000fors_abs_i32.test_shift_bitfield_min_max_abs_of_unknown_source_is_not_a_literal: 8 listings where one source is a user SGPR. The result must be no literal sampler.tools/shader_meta.pyof #4546 (14b51cc7)python -I tests/test_shader_meta.pyFAILED (failures=16): the 16 listings of the first new testpython -I tests/test_shader_meta_operands.pyOther tests that import
shader_meta, on this branch:python -I tests/test_fspx_shaders_stage.py: OK.python -I tests/test_fssm_wave_size.py: OK.python -I tests/test_shader_index.py: exit code 0.python -I tests/test_spirv_stubs.py: exit code 0.python -I scripts/check_no_game_data.py: exit code 0.tests/test_mesh_compute.py,tests/test_pc_tail_ubo.py,tests/test_rdna2spirv_pixelinput.pyandtests/test_translate.py. They needpytest, andpytestis not installed on this computer.AI-assisted (Claude Code).
Checklist
docs/design.md, with how it was confirmed. (Not applicable: no translator rule.)🤖 Generated with Claude Code