Repository navigation
Translator: gather wrap/mirror modulo without OpSMod, independent of the driver's sign (SHADER-369) - #2144
Translator: gather wrap/mirror modulo without OpSMod, independent of the driver's sign (SHADER-369)#2144Vonsek wants to merge 1 commit into
Conversation
|
Tested
AI-assisted (Claude Code). |
|
Tested 0b37b89 on AMD Radeon 610M (RDNA2 iGPU, RADV Mesa 26.2.6) and NVIDIA RTX 4070 Ti (615.78.08), Fedora 45: pass These add the two Linux drivers to the Windows results above. Neither driver showed the zeros on
AI-assisted (Claude Code); numbers copied from the run logs. |
The image_gather4_l emulation wrapped and mirrored texel coordinates with OpSMod. By the spec its result has the divisor's (positive) sign, but AMD's Windows driver 24.10.24 on a Ryzen 5 7600 iGPU returned all-zero gathers in exactly the ps_gather_wrap cases whose coordinate is negative, as if it took the dividend's sign. Use OpSRem plus the divisor when the remainder is negative (Gen.nonneg_mod): the same value under either reading.
0b37b89 to
987bf44
Compare
|
Rebased on
The stub test now evaluates the border modes too (6 as clamp, 7 as mirror once) and reads the coordinate from the Re-run after the rebase:
AI-assisted. |
SHADER-369 (Vonsek4)
Gen.gather_addr(theimage_gather4_lemulation) wrapped texel coordinates withOpSMod c nand mirrored them withOpSMod c 2n. By the SPIR-V spec,OpSMod's result has the divisor's sign, which is positive here. @whoalin1 found that AMD's Windows driver 24.10.24 on a Ryzen 5 7600 iGPU returns all-zero gathers in exactly the threeps_gather_wrapcases whose wrap or mirror coordinate is negative (cases 1, 2, 6), while NVIDIA passes (finding). That fits a driver that computesOpSModwith the dividend's sign, which sends the fetch out of range.The fix is a new
Gen.nonneg_mod(c, m)that computesOpSRem c mand addsmwhen the remainder is negative.OpSRemis defined with the dividend's sign, so it doesn't depend on which sign convention a driver uses forOpSMod. Both wrap and mirror use it, and the gather emulation no longer emitsOpSModanywhere. Thedocs/design.mdrow now records the rule.Tests
test_gather_addr_does_not_depend_on_how_a_driver_signs_smod. It drivesGen.gather_addrwith a stub and evaluates the emitted integer code on the CPU, withOpSModread both ways: the divisor's sign (spec) and the dividend's sign. The result must be Vulkan's wrap, mirror, clamp or mirror-once texel for every coordinate c in [-3n-2, 3n+2] and n ∈ {1, 2, 3, 8, 16}. It covers all four literal modes plus a run-time mode, including modes 4 and 7, which act as clamp.-1 == 1). Clamp and mirror-once use no modulo, so they pass.test_gather4_l_literal_sampler_emits_only_the_code_its_modes_needandtest_gather4_l_run_time_sampler_selects_the_mode_from_the_sgprnow countOpSRemwith itsOpSLessThanfix-up, and require zeroOpSMod. Without the change they fail on theOpSModcount.tests/test_translate.pygives 503 passed, 2 skipped.python -m unittest discover -s tests/semanticgives 1671 OK.compileallis clean.scripts/run_gpu_tests.py --filter ps_gathergivesps_gather_wrapat 4096/4096 pixels exact andps_gather_sampler_lodpassing, on both machines below. The module now has 0OpSModand 76OpSRem(before: 76 and 0).LEONIDA_VK_DEVICE=radeon.No game files used or included.
AI-assisted.