mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 18:08:40 +00:00
rt::rootsig::pack_stage() lays a root signature out for one stage the way the console compiler does: root order from the stage base, a table one dword (its 32-bit VA), a root view two, constants one per value, and the first parameter that does not fit refused (the spill array behind s[0:1] is not modelled). Compute (base s4) is measured: on the package's FidelityFX DLL, whose 29 compute containers carry their RTS0 next to the console-compiled program, base plus span equals RSRC2 USER_SGPR in 29 of 29, and root_sig_contract.py --model console finds all 20 translated programs compatible (the s0 model contradicts 7). VS/PS/GS s8 and MS s16 stay a census hypothesis. The compute bind point now uses this layout; graphics keeps pack(), since every stage reads one push-constant block and a mesh shader (s16) and a pixel shader (s8) would collide. A signature carries both layouts; binding it where its layout refused it invalidates the list. Test fixtures follow: the compute GLSL shaders read the new places, and the asm fixtures a D3D12 compute PSO runs are built with LEONIDA_USER_DATA_SHIFT=4 (compute_fixture.py shifts every SGPR and the RSRC2 user count), so the standalone harness keeps using them at s0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
92 lines
3.8 KiB
Python
92 lines
3.8 KiB
Python
"""runtime/test/shaders/compute_fixture.py: the user-data shift for D3D12 compute fixtures (D3D-448).
|
|
|
|
python -I tests/test_compute_fixture_shift.py
|
|
|
|
Hand-written asm text only; no game files, no llvm-mc, no GPU.
|
|
"""
|
|
import os
|
|
import struct
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from unittest import mock
|
|
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
sys.path.insert(0, os.path.join(ROOT, "runtime", "test", "shaders"))
|
|
|
|
import compute_fixture as cf # noqa: E402
|
|
|
|
ASM = """; rsrc2: 0x808c
|
|
; s0 = seed, s[4:5] = table (comments keep their register names)
|
|
s_load_dwordx4 s[8:11], s[4:5], 0x0
|
|
s_lshl_b32 s7, s6, 6
|
|
v_add_nc_u32_e32 v4, s0, v3 ; s0 again
|
|
s_mov_b64 exec, vcc
|
|
s_and_b32 s105, s0, m0
|
|
"""
|
|
|
|
|
|
class ShiftTest(unittest.TestCase):
|
|
def test_every_sgpr_moves_and_comments_stay(self):
|
|
got = cf.shift_user_data(ASM.replace("s105", "s100"), 4).splitlines()
|
|
self.assertEqual(got[0], "; rsrc2: 0x808c")
|
|
self.assertEqual(got[1], "; s0 = seed, s[4:5] = table (comments keep their register names)")
|
|
self.assertEqual(got[2], "s_load_dwordx4 s[12:15], s[8:9], 0x0")
|
|
self.assertEqual(got[3], "s_lshl_b32 s11, s10, 6")
|
|
self.assertEqual(got[4], "v_add_nc_u32_e32 v4, s4, v3 ; s0 again")
|
|
self.assertEqual(got[5], "s_mov_b64 exec, vcc") # named registers stay
|
|
self.assertEqual(got[6], "s_and_b32 s104, s4, m0")
|
|
|
|
def test_zero_shift_is_identity(self):
|
|
self.assertEqual(cf.shift_user_data(ASM, 0), ASM)
|
|
|
|
def test_past_s105_is_refused(self):
|
|
with self.assertRaises(ValueError):
|
|
cf.shift_user_data(ASM, 4) # s105 + 4
|
|
with self.assertRaises(ValueError):
|
|
cf.shift_user_data("s_load_dwordx4 s[100:103], s[0:1], 0x0\n", 4)
|
|
|
|
def test_mnemonics_and_vgprs_untouched(self):
|
|
line = "s_buffer_load_dword s1, s[4:7], 0x10 v_mov_b32 v1, v2\n"
|
|
self.assertEqual(cf.shift_user_data(line, 4), "s_buffer_load_dword s5, s[8:11], 0x10 v_mov_b32 v1, v2\n")
|
|
|
|
|
|
class Rsrc2Test(unittest.TestCase):
|
|
def test_user_count_moves_other_fields_stay(self):
|
|
# 0x808c: USER_SGPR 6, TGID_X, LDS 1 unit. +4 -> USER_SGPR 10, the rest unchanged.
|
|
got = cf.shifted_rsrc2(0x808c, 4)
|
|
self.assertEqual((got >> 1) & 31, 10)
|
|
self.assertEqual(got & ~(31 << 1), 0x808c & ~(31 << 1))
|
|
self.assertEqual(cf.shifted_rsrc2(0x8088, 4), 0x8090) # the default header: 4 -> 8 user SGPRs
|
|
self.assertEqual(cf.shifted_rsrc2(0x8088, 0), 0x8088)
|
|
|
|
def test_user_count_overflow_refused(self):
|
|
with self.assertRaises(ValueError):
|
|
cf.shifted_rsrc2(31 << 1, 1)
|
|
|
|
def test_header_uses_the_shift(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
path = os.path.join(tmp, "cs_x.asm")
|
|
with open(path, "w", encoding="utf-8") as f:
|
|
f.write("; rsrc2: 0x808c\n; group: 32,2,1\ns_endpgm\n")
|
|
plain = struct.unpack_from("<4I", cf.compute_header(path), 0x138)
|
|
shifted = struct.unpack_from("<4I", cf.compute_header(path, 4), 0x138)
|
|
self.assertEqual(plain, (0x808c, 32, 2, 1))
|
|
self.assertEqual(shifted, (cf.shifted_rsrc2(0x808c, 4), 32, 2, 1))
|
|
|
|
|
|
class EnvTest(unittest.TestCase):
|
|
def test_env_values(self):
|
|
for value, want in ((None, 0), ("", 0), ("4", 4), (" 4 ", 4)):
|
|
env = {} if value is None else {"LEONIDA_USER_DATA_SHIFT": value}
|
|
with mock.patch.dict(os.environ, env, clear=True):
|
|
self.assertEqual(cf.user_data_shift(), want)
|
|
for bad in ("four", "-1", "28"):
|
|
with mock.patch.dict(os.environ, {"LEONIDA_USER_DATA_SHIFT": bad}, clear=True):
|
|
with self.assertRaises(ValueError):
|
|
cf.user_data_shift()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|