mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 12:08:36 +00:00
RDNA2's FRONT_FACE system VGPR is 0xffffffff (front) / 0 (back) with SPI_BARYC_CNTL.FRONT_FACE_ALL_BITS = 1 and +1.0 / -1.0 without it (#5123); which one the console programs wasn't known. Over the 1.0.2.1 corpus, 1,984 pixel shaders declare SV_IsFrontFace, 345 read the VGPR, and every first use is an integer compare against 0 (282 v_cmp_ne_u32_e32, 62 v_cmp_ne_u32_e64, 1 v_cmp_eq_u32_e32) - no float compare, bit op or other use. +1.0 and -1.0 are both non-zero, so with the float form the translator wrote, all 345 saw every face as front. It now stores the mask form. tests/test_ps_front_face.py translates a hand-written PS that tests the VGPR the same way and checks the stored values (fails on the old code). The 712 corpus PS that compare the FRONT_FACE register translate and pass spirv-val before and after. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
48 lines
2.2 KiB
Python
48 lines
2.2 KiB
Python
"""The FRONT_FACE pixel-shader system VGPR holds 0xffffffff (front) / 0 (back) (SHADER-892).
|
|
|
|
On RDNA2 the VGPR is 0xffffffff / 0 when SPI_BARYC_CNTL.FRONT_FACE_ALL_BITS = 1 and +1.0 / -1.0 when it is 0
|
|
(#5123). Every one of the game's 345 pixel shaders that reads it tests it as an integer against 0, which only the
|
|
mask form answers correctly (+1.0 and -1.0 are both non-zero). This translates a hand-written PS that reads it the
|
|
same way, after the two SV_Position components it reads, and checks what the translator stores. No game data.
|
|
"""
|
|
import os
|
|
import re
|
|
import sys
|
|
import unittest
|
|
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
sys.path.insert(0, os.path.join(ROOT, "tests"))
|
|
|
|
from test_shader_meta import isg1_chunk, make_dxbc, translate_synthetic # noqa: E402
|
|
|
|
# SV_Position (system value 1) with x and y read, then SV_IsFrontFace (system value 9): v2, v3 = x, y; v4 = facing.
|
|
SIGNATURE = make_dxbc([isg1_chunk([("SV_Position", 0, 0, 0xF, 0x3, 1, 3),
|
|
("SV_IsFrontFace", 0, 1, 0x1, 0x1, 9, 1)])])
|
|
LINES = [
|
|
"v_cmp_ne_u32_e32 vcc_lo, 0, v4",
|
|
"v_cndmask_b32_e64 v0, 0, 1.0, vcc_lo",
|
|
"exp mrt0 v0, v0, v0, v0 done vm",
|
|
"s_endpgm",
|
|
]
|
|
|
|
|
|
class FrontFaceMaskTest(unittest.TestCase):
|
|
def test_front_face_is_stored_as_all_bits_or_zero(self):
|
|
asm, _ = translate_synthetic("ps_front_face", LINES, dxbc=SIGNATURE)
|
|
self.assertIn("BuiltIn FrontFacing", asm)
|
|
select = re.search(r"%ffu = OpSelect %uint %ff (%\S+) (%\S+)", asm)
|
|
self.assertIsNotNone(select, "FRONT_FACE is not stored as a uint select")
|
|
consts = dict(re.findall(r"(%\S+) = OpConstant %uint (\d+)", asm))
|
|
self.assertEqual(int(consts[select.group(1)]), 0xFFFFFFFF) # front
|
|
self.assertEqual(int(consts[select.group(2)]), 0) # back
|
|
# The float form (+1.0 / -1.0) is gone: nothing negates 1.0 for the facing value.
|
|
self.assertNotIn("%ffm1", asm)
|
|
# And the value goes into the VGPR the shader reads, v4.
|
|
store = re.search(r"%ffp = OpAccessChain %_ptr_Function_uint %vgpr (%\S+)", asm)
|
|
self.assertIsNotNone(store)
|
|
self.assertEqual(int(consts[store.group(1)]), 4)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|