mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 16:38:38 +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>
103 lines
4.4 KiB
Python
103 lines
4.4 KiB
Python
"""Synthetic FSSM compute headers shared by both GPU test runners."""
|
|
import os
|
|
import re
|
|
import struct
|
|
from pathlib import Path
|
|
|
|
|
|
def compute_header(asm_path, shift=0):
|
|
# Default: four user SGPRs (V#), TGID_X, 512 bytes LDS, 64 threads. `shift`: see shift_user_data.
|
|
rsrc2, group = 0x8088, (64, 1, 1)
|
|
for line in Path(asm_path).read_text(encoding="utf-8").splitlines():
|
|
line = line.strip()
|
|
if not line:
|
|
continue
|
|
if not line.startswith(";"):
|
|
break
|
|
size = re.match(r";\s*group:\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)", line)
|
|
if size:
|
|
group = tuple(map(int, size.groups()))
|
|
elif line[1:].lstrip().startswith("rsrc2:"):
|
|
rsrc2 = int(line.split(":", 1)[1].strip(), 0)
|
|
header = bytearray(0x148)
|
|
struct.pack_into("<4I", header, 0x138, shifted_rsrc2(rsrc2, shift), *group)
|
|
return header
|
|
|
|
|
|
SGPR_LIMIT = 106 # s0..s105 on GFX10
|
|
_SGPR = re.compile(r"\bs(\d+)\b")
|
|
_SGPR_RANGE = re.compile(r"\bs\[(\d+):(\d+)\]")
|
|
|
|
|
|
def shift_user_data(text, shift):
|
|
"""The asm text with every scalar register moved up by `shift` (s[0:3] -> s[4:7] for 4), comments untouched.
|
|
|
|
The fixtures here read their user data from s0 (the standalone harnesses push it there). In a D3D12 compute PSO
|
|
the console layout starts the root arguments at s4 (rt::rootsig::pack_stage, D3D-448), so a D3D12 test that
|
|
reuses such a fixture builds it with LEONIDA_USER_DATA_SHIFT=4: the same program, its user data 4 SGPRs up, and
|
|
shifted_rsrc2 moves the user count and the thread-group ids that follow it. Named registers (vcc, exec, m0,
|
|
ttmp) don't move. Raises ValueError when a register would pass s105."""
|
|
if shift == 0:
|
|
return text
|
|
|
|
def one(m):
|
|
n = int(m.group(1)) + shift
|
|
if n >= SGPR_LIMIT:
|
|
raise ValueError(f"s{m.group(1)} + {shift} is past s{SGPR_LIMIT - 1}")
|
|
return f"s{n}"
|
|
|
|
def pair(m):
|
|
lo, hi = int(m.group(1)) + shift, int(m.group(2)) + shift
|
|
if hi >= SGPR_LIMIT:
|
|
raise ValueError(f"s[{m.group(1)}:{m.group(2)}] + {shift} is past s{SGPR_LIMIT - 1}")
|
|
return f"s[{lo}:{hi}]"
|
|
|
|
out = []
|
|
for line in text.splitlines(keepends=True):
|
|
code, sep, comment = line.partition(";")
|
|
code = _SGPR.sub(one, _SGPR_RANGE.sub(pair, code))
|
|
out.append(code + sep + comment)
|
|
return "".join(out)
|
|
|
|
|
|
def shifted_rsrc2(rsrc2, shift):
|
|
"""COMPUTE_PGM_RSRC2 with USER_SGPR [5:1] raised by `shift` (the enabled thread-group ids follow it)."""
|
|
user = ((rsrc2 >> 1) & 31) + shift
|
|
if not 0 <= user <= 31:
|
|
raise ValueError(f"USER_SGPR {user} does not fit RSRC2's 5-bit field")
|
|
return (rsrc2 & ~(31 << 1)) | (user << 1)
|
|
|
|
|
|
def user_data_shift():
|
|
"""LEONIDA_USER_DATA_SHIFT as an int (0 when unset); see shift_user_data."""
|
|
text = (os.environ.get("LEONIDA_USER_DATA_SHIFT") or "0").strip()
|
|
try:
|
|
shift = int(text)
|
|
except ValueError:
|
|
raise ValueError(f"LEONIDA_USER_DATA_SHIFT must be a whole number, not {text!r}") from None
|
|
if not 0 <= shift <= 27:
|
|
raise ValueError(f"LEONIDA_USER_DATA_SHIFT {shift} is outside 0..27")
|
|
return shift
|
|
|
|
|
|
def unpinned_subgroup(out):
|
|
"""The lane count vk_compute_test was asked for with VKC_SUBGROUP_SIZE and could not pin on this device, or None.
|
|
|
|
vk_compute_test then prints "compute subgroup size: N not available" and runs at whatever size the driver picks
|
|
(#774); Mesa llvmpipe's only size is 8. A wave32 program's words from such a run say nothing about the translator,
|
|
so the fuzzers skip it, as check.py's unpinned_subgroup_skip does for its lane-mask dumps. Output without the line
|
|
(the size was pinned, none was asked for, or an older vk_compute_test) gives None."""
|
|
m = re.search(r"^compute subgroup size: (\d+) not available$", out, re.MULTILINE)
|
|
return int(m.group(1)) if m else None
|
|
|
|
|
|
def find_test_program(build, name):
|
|
"""The folder holding test program `name`: `build` itself (Ninja, Makefiles) or the RelWithDebInfo/Release
|
|
subfolder a Visual Studio build puts it in, as run_gpu_tests.py's find_test_programs looks. None if not built.
|
|
A Debug configuration isn't searched (neither does run_gpu_tests.py): GPU fuzzing wants an optimized harness."""
|
|
exe = name + (".exe" if os.name == "nt" else "")
|
|
for folder in (build, os.path.join(build, "RelWithDebInfo"), os.path.join(build, "Release")):
|
|
if os.path.isfile(os.path.join(folder, exe)):
|
|
return folder
|
|
return None
|