Repository navigation
shader_meta: fold s_not_b32, s_nand_b32, s_nor_b32 and s_xnor_b32 so a literal S# built with them reaches literal_samplers - #4546
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>
|
Tested
AI-assisted (Devin). |
Kam471
left a comment
There was a problem hiding this comment.
Ran this at 14b51cc7 on Windows 11: python -I tests/test_shader_meta.py -> 21 tests, OK; git diff --check clean.
shader_meta now folds s_not_b32, s_nand_b32, s_nor_b32 and s_xnor_b32 of known constants, so an S# built with them reaches literal_samplers; the added cases pass. No blocking issue.
|
Automated test:
Same machine and setup as my earlier manual reports. AI-assisted (Claude Code). |
|
Tested 14b51cc merged with main d0835dd (merge 154d85a85, no conflicts) on Linux (WSL2) Python 3.12.16 and native Windows 11 Python 3.13.1: pass.
|
|
Verified on Linux: merges cleanly into current main; test_shader_meta 21/21 including the constant folds, chained folds and the unknown-source invalidation negatives (re-run); masking is 32-bit-clean and no other shader_meta consumer mentions the four mnemonics, so the widened const-prop cannot shift current analyses. Unrelated observation: tests/test_shader_index.py silently runs nothing under python -I — pre-existing on main, confirmed here, not from this PR. 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. Finding: test report on #4289.
What and why
_step_stateintools/shader_meta.pyfollows the constants in the SGPRs. It did not fold the inverted scalar logic operations. Thus a literal S# that has one dword made with one of these operations was not inliteral_samplersof the index.Hand-written listing (no game data):
main(03b09a08):literal_samplersis[].literal_samplersis[[146, 4294967295, 0, 0]].This change:
s_not_b32of a known constant gives a known constant (the complement, 32 bits).s_nand_b32,s_nor_b32ands_xnor_b32of two known constants fold together with the two-source logic operations that_fold_scalar_alualready has (s_and_b32,s_or_b32,s_xor_b32,s_andn2_b32,s_orn2_b32).The diff in
tools/shader_meta.pyis 13 added lines and 1 removed line.Relation to #4289
#4289 folds
s_brev_b32. The two changes are independent. This branch starts atmainand does not need #4289. I merged #4289 (8479d6c0) into this branch as a test: Git merges the two files without a conflict, andtests/test_shader_meta.pygives 23 tests OK. With the two changes together, the listing from the report (s_not_b32 s13, 0, thens_brev_b32 s13, s13) gives[[146, 4294967295, 0, 0]].Operations that I did not fold
A probe with hand-written listings shows that
_step_statealso does not folds_ashr_i32,s_bfm_b32,s_bfe_u32,s_min_u32,s_max_u32ands_abs_i32. I did not add them, to keep this change small. I do not know if a title uses them to make an S# dword.Tested
Windows 11, CPython 3.14.7, CPU only. No GPU and no game files.
New tests in
tests/test_shader_meta.py:test_inverted_scalar_logic_folds_into_literal_sampler: 11 listings. Each listing makes the dwords13of the S# withs_not_b32,s_nand_b32,s_nor_b32ors_xnor_b32from immediates and from SGPRs that hold known constants. One listing uses the same register as source and destination. One listing folds the result a second time withs_and_b32.test_inverted_scalar_logic_of_unknown_source_is_not_a_literal: 5 listings where one source is a user SGPR. The result must be no literal sampler, also when the destination held a constant before.tools/shader_meta.pyofmain(03b09a08)python -I tests/test_shader_meta.pyFAILED (failures=11): the 11 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: no problem found.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