Files
mandy/tests/test_vs_input_survey.py
S1m0ne1997 07bd05fa95 Translator: zero-based VS v0/v3 (VertexIndex - BaseVertex, InstanceIndex - BaseInstance); VS is legacy, not NGG (SHADER-33)
Corpus (scripts/vs_input_survey.py, all 2,236 VS): no exp prim, no s_sendmsg, no v_mbcnt, every
VS exports pos0/param, so the console runs them as legacy hardware VS. Their input VGPRs are
Mesa's GFX10 legacy layout (radv_shader_args.c, declare_vs_input_vgprs, not is_ngg): v0 vertex
id, v1 unused, v2 primitive id, v3 instance id; no VS reads v1/v2 on entry, 788 start with the
fetch call and read attributes from v4.

Those ids are zero-based on the hardware (ac_nir_lower_intrinsics_to_args.c: vertex_id is
load_vertex_id_zero_base, instance_id is load_instance_id; the bases come in SGPRs), while
Vulkan's VertexIndex/InstanceIndex include firstVertex|vertexOffset/firstInstance. The
translator now seeds v0 = VertexIndex - BaseVertex and v3 = InstanceIndex - BaseInstance
(DrawParameters; feature shaderDrawParameters in every VS's metadata).

GPU test vs_base_ids.asm, drawn with VKH_DRAW=16,7 (new vk_harness option): 0x101 on every
pixel, where before it was 0x7111. Run by check.py and run_gpu_tests.py. vk_harness,
vk_pipeline_check, vk_bindless_test, vk_texture_test and the runtime's Vulkan device enable
shaderDrawParameters. design.md's "Inputs and outputs" row replaces the "unverified" note.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 11:59:04 +01:00

89 lines
4.0 KiB
Python

"""vs_input_survey: NGG markers, input VGPRs read before written, and the VS families, on hand-written listings.
python -I tests/test_vs_input_survey.py
Every input is built here (index.json and five tiny .s listings). No game data.
"""
import json
import os
import subprocess
import sys
import tempfile
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(ROOT, "scripts"))
import vs_input_survey as V # noqa: E402
failures = 0
def check(cond, what):
global failures
print(("PASS " if cond else "FAIL ") + what)
failures += not cond
LISTINGS = {
# vertex id only, legacy exports
"a_vs": "\tv_cvt_f32_u32_e32 v1, v0\n\texp pos0 v1, v1, v1, v1 done\n\texp param0 v1, v1, v1, v1\n\ts_endpgm\n",
# vertex and instance id (v3 read before v3 is written)
"b_vs": "\tv_add_nc_u32_e32 v1, v0, v3\n\tv_mov_b32_e32 v3, 0\n\texp pos0 v1, v1, v1, v3 done\n"
"\texp param0 v1, v1, v1, v1\n\ts_endpgm\n",
# fetch call, then the fetched attributes from v4
"c_vs": "\ts_swappc_b64 s[4:5], s[4:5]\n\tv_fma_f32 v1, v4, v5, v6\n\texp pos0 v1, v1, v1, v1 done\n"
"\texp param0 v4, v5, v6, v1\n\ts_endpgm\n",
# constant position: reads neither
"d_vs": "\tv_mov_b32_e32 v1, 1.0\n\texp pos0 v1, v1, v1, v1 done\n\texp param0 v1, v1, v1, v1\n\ts_endpgm\n",
# a pixel shader, which the survey must skip
"e_ps": "\tv_mov_b32_e32 v1, v0\n\ts_endpgm\n",
}
def build(root):
dx = os.path.join(root, "dxbc")
os.makedirs(os.path.join(dx, "disasm"))
index = []
for name, text in LISTINGS.items():
with open(os.path.join(dx, "disasm", name + ".s"), "w", encoding="utf-8") as f:
f.write(f"; {name}\n" + text)
index.append({"name": name, "file": name + ".dxbc", "stage": name.split("_")[1]})
with open(os.path.join(dx, "index.json"), "w", encoding="utf-8") as f:
json.dump(index, f)
return dx
def test_vs_input_survey():
"""Runs under pytest (CI's translator-tests job) and as a plain script."""
with tempfile.TemporaryDirectory() as tmp:
dx = build(tmp)
r = V.survey(dx)
check(r["vertex_shaders"] == 4, "only the four vertex shaders are surveyed")
m = r["markers"]
check(m["exp prim"] == 0 and m["s_sendmsg"] == 0 and m["v_mbcnt"] == 0, "no NGG markers in legacy listings")
check(m["exp pos0"] == 4 and m["exp param"] == 4 and m["fetch call"] == 1, "exports and the fetch call counted")
check(r["input_vgprs_read"].get("v0") == 2 and r["input_vgprs_read"].get("v3") == 1,
"v0 read on entry by two shaders, v3 by one (before it is written)")
check("v1" not in r["input_vgprs_read"], "v1 is written before it is read, so it is not an input")
check(r["input_vgprs_read"].get("v4") == 1, "the fetched attribute v4 counts as read on entry")
check(r["families"] == {"reads v0 (vertex id)": 1, "reads v0 (vertex id) and v3 (instance id)": 1,
"fetch call, attributes from v4 up": 1, "reads neither v0 nor a fetch call": 1},
"each shader lands in exactly one family")
with open(os.path.join(dx, "disasm", "a_vs.s"), "a", encoding="utf-8") as f:
f.write("\texp prim v0, off, off, off done\n")
out = subprocess.run([sys.executable, "-I", os.path.join(ROOT, "scripts", "vs_input_survey.py"), dx],
capture_output=True, text=True)
check(out.returncode == 0 and "exp prim 1" in out.stdout and "NGG markers present" in out.stdout,
"a primitive export flips the verdict away from legacy")
check("a_vs" not in out.stdout and "c_vs" not in out.stdout, "the summary prints counts, not shader names")
assert failures == 0, f"{failures} vs_input_survey check(s) failed"
if __name__ == "__main__":
try:
test_vs_input_survey()
except AssertionError:
pass
print(f"test_vs_input_survey: {'OK' if not failures else 'FAILED'} ({failures} failure{'s' if failures != 1 else ''})")
sys.exit(1 if failures else 0)