Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions docs/experiments/translator-corpus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Compare native translator output

The source-built corpus exercises graphics pairs, RTV variants, compute requests,
and raw mesh shaders. The TSV records one row per request key. It contains the
status and either a SHA-256 fingerprint of the published DXIL or the refusal reason.
For a request with several stages, the fingerprint hashes each stage name, a NUL
byte, and its binary SHA-256 digest in stage name order.

Build `compile_dxil` in two separate build directories with the same preset and
DXC version. From the checkout containing the corpus script, use that same copy
of the script and the same DXC directory for both builds. Set `$baseCompiler`
and `$headCompiler` to the two executable paths.

```powershell
$sdk = (Get-Content out/build/dev/x2w-dxc-dir.txt -Raw).Trim()
python -B tests/translator_corpus_hash.py $baseCompiler $sdk --out out/translator-base.tsv
if ($LASTEXITCODE -ne 0) { throw 'Base corpus run failed' }
python -B tests/translator_corpus_hash.py $headCompiler $sdk --out out/translator-head.tsv
if ($LASTEXITCODE -ne 0) { throw 'Head corpus run failed' }
git diff --no-index --exit-code -- out/translator-base.tsv out/translator-head.tsv
```

An empty diff means the fixture outputs and refusal reasons match. The script
uses fresh caches on each run and the default translator settings. For a local
corpus, pass `--corpus-dir` with a directory of `req_<key>.*` inputs in both
commands. Supported request markers are `.a`, `.rtv`, `.c67`, and `.m57`.
For `req_<key>.m57`, the raw mesh profile reads `req_<key>.mslayout` and the
corpus hashes the resulting mesh stage.

Add `--ir` to both commands to hash each successful stage's pre-DXC text. Both
compiler builds must support `--dump-ir`. DXC still validates the stages and
supplies the root signature fixtures. Use DXIL mode when comparing builds that
predate `--dump-ir`.

```powershell
cmake --build --preset dev --target compile_dxil
ctest --preset dev --no-tests=error -R '^native_translator_corpus_(dxil|ir)$' --output-on-failure
```

Each test checks known compilations and refusals and compares two cold snapshots
byte for byte. The IR test also compares DXIL from runs with and without the dump
flag.
13 changes: 13 additions & 0 deletions tests/cmake/translator_corpus.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if(TARGET compile_dxil AND EXISTS "${INTAKE_PYTHON}" AND EXISTS "${DXC_BIN_DIR}/dxc.exe"
AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll")
add_test(NAME native_translator_corpus_dxil COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/translator_corpus_hash.py"
"$<TARGET_FILE:compile_dxil>" "${DXC_BIN_DIR}" --check-repeat
--out "${CMAKE_CURRENT_BINARY_DIR}/translator_corpus_dxil.tsv")
add_test(NAME native_translator_corpus_ir COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/translator_corpus_hash.py"
"$<TARGET_FILE:compile_dxil>" "${DXC_BIN_DIR}" --ir --check-repeat
--out "${CMAKE_CURRENT_BINARY_DIR}/translator_corpus_ir.tsv")
set_tests_properties(native_translator_corpus_dxil PROPERTIES TIMEOUT 120)
set_tests_properties(native_translator_corpus_ir PROPERTIES TIMEOUT 240)
endif()
26 changes: 17 additions & 9 deletions tests/native_compile_dxil_refusals_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ def put_mesh_request(directory, words, pixel, root, *, layout=None, wrong_key=Fa
return key


def put_batch_graphics_requests(cache, root):
return (
put_graphics_request(cache, VS_WORDS, ps_words(4), root, TARGET_MASKS),
put_graphics_request(cache, VS_WORDS, ps_words(2), root, (0x0002, 0x8002)),
put_graphics_request(cache, VS_WORDS, struct.pack("<2I", 0xFFFFFFFF, 0xBF810000), root, DECOY_MASKS),
)


def put_batch_compute_requests(cache, code, root, state):
return (
put_compute_request(cache, code, root, state),
put_compute_request(cache, code[:-4] + struct.pack("<2I", 0xFFFFFFFF, 0xBF810000), root, state),
)


def check_mesh_report(parsed, report, translated, refusals, caller_layout=None):
mesh = parsed["mesh57"]
assert mesh["examined"] == 7, mesh
Expand Down Expand Up @@ -88,11 +103,7 @@ def main(argv: list[str]) -> int:
# 1. Batch --requests writes <key>.fail on refusal and removes stale <key>.fail on subsequent success.
cache = work / "batch_cache"
cache.mkdir()
valid_gfx = put_graphics_request(cache, VS_WORDS, ps_words(4), g_root, TARGET_MASKS)
bad_vgpr2 = put_graphics_request(cache, VS_WORDS, ps_words(2), g_root, (0x0002, 0x8002))
bad_decode_gfx = put_graphics_request(
cache, VS_WORDS, struct.pack("<2I", 0xFFFFFFFF, 0xBF810000), g_root, DECOY_MASKS
)
valid_gfx, bad_vgpr2, bad_decode_gfx = put_batch_graphics_requests(cache, g_root)
# Pre-seed a stale .fail beside a valid request to verify --requests deletes it upon success.
stale_fail = cache / f"{valid_gfx:016x}.fail"
stale_fail.write_text("stale failure\n", encoding="utf-8")
Expand All @@ -116,10 +127,7 @@ def main(argv: list[str]) -> int:
assert not (cache / f"{bad_key:016x}.vs.cso").exists()
assert not (cache / f"{bad_key:016x}.ps.cso").exists()

valid_cs = put_compute_request(cache, c_code, c_root, c_sa)
bad_cs_decode = put_compute_request(
cache, c_code[:-4] + struct.pack("<2I", 0xFFFFFFFF, 0xBF810000), c_root, c_sa
)
valid_cs, bad_cs_decode = put_batch_compute_requests(cache, c_code, c_root, c_sa)
stale_cs_fail = cache / f"{valid_cs:016x}.fail"
stale_cs_fail.write_text("stale compute failure\n", encoding="utf-8")

Expand Down
11 changes: 7 additions & 4 deletions tests/native_compile_dxil_watch_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ def run_once(cli: Path, sdk: Path, frontend: Path, req_dir: Path, jobs: int = 1)
)


def put_watch_rtv_requests(directory, root):
base = put_graphics_request(directory, VS_WORDS, ps_words(4), root, TARGET_MASKS)
return (base, put_variant(directory, base, (UINT16, UNORM8)),
put_variant(directory, base, (FLOAT32,)), put_variant(directory, base, (7,)))


def main(argv: list[str]) -> int:
if len(argv) != 2:
raise SystemExit(__doc__)
Expand Down Expand Up @@ -251,10 +257,7 @@ def main(argv: list[str]) -> int:
# RTV variants in --once: compile base + variants, publish rtv1 manifest + .psdep, and recheck on base .psin update.
d_rtv = work / "once_rtv"
d_rtv.mkdir()
rtv_base = put_graphics_request(d_rtv, VS_WORDS, ps_words(4), g_root, TARGET_MASKS)
rtv_u16, rtv_u16_line = put_variant(d_rtv, rtv_base, (UINT16, UNORM8))
rtv_f32, rtv_f32_line = put_variant(d_rtv, rtv_base, (FLOAT32,))
rtv_bad, _ = put_variant(d_rtv, rtv_base, (7,))
rtv_base, (rtv_u16, rtv_u16_line), (rtv_f32, rtv_f32_line), (rtv_bad, _) = put_watch_rtv_requests(d_rtv, g_root)
r_rtv = run_once(cli, sdk, frontend, d_rtv, jobs=2)
assert r_rtv.returncode == 0, (r_rtv.returncode, r_rtv.stdout, r_rtv.stderr)
for vkey, vline in ((rtv_u16, rtv_u16_line), (rtv_f32, rtv_f32_line)):
Expand Down
29 changes: 21 additions & 8 deletions tests/native_direct_mesh_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import tempfile


TRIANGLE_LAYOUT = 'mesh1 128 3 1 2 128 64'


def triangle():
return [
0xbefc03ff, 0x1003, 0xbf900009, # m0 = (1 primitive << 12) | 3 vertices; GS_ALLOC_REQ
Expand Down Expand Up @@ -86,6 +89,12 @@ def s_cmp_le_u32_words(program, left, right):
return program[:5] + moves + program[6:]


def signed_le_refusal(program):
words = s_cmp_le_u32_words(program, 1, 2)
words[7] = 0xBF051514 # s_cmp_le_i32 s20, s21
return words, 'unsupported mesh instruction or EXEC state: s_cmp_le_i32'


def assert_unsigned_le(text, left, right):
value = r'%[\w.]+'
ule = re.search(rf'(?P<ule>{value}) = icmp ule i32 {_ir_u32(left)}, {_ir_u32(right)}\n', text)
Expand All @@ -112,6 +121,13 @@ def v_cmpx_ne_u32_words(program, compare):
return program[:7] + body + program[7:]


def cmpx_ne_cases(program):
return (
('v-cmpx-ne-narrow', v_cmpx_ne_u32_words(program, 0x7DAA0080), r'icmp ne i32 0, %[\w.]+'),
('v-cmpx-ne-empty', v_cmpx_ne_u32_words(program, 0x7DAA0100), r'icmp ne i32 (?P<same>%[\w.]+), (?P=same)'),
)


def _v_mov_b32(dst, src):
return (63 << 25) | ((dst & 0xFF) << 17) | (1 << 9) | (src & 0x1FF)

Expand Down Expand Up @@ -433,7 +449,7 @@ def main():
checked_pixel_entry(root, compiler, sdk)
raw = root / 'fixture.m57'
layout = raw.with_suffix('.mslayout')
layout.write_text('mesh1 128 3 1 2 128 64')
layout.write_text(TRIANGLE_LAYOUT)
def compile_mesh(name, words):
raw.write_bytes(struct.pack('<%dI' % len(words), *words))
out = root / (name + '.dxil')
Expand Down Expand Up @@ -516,14 +532,11 @@ def run(name, words, expected=None):
('s-cmp-le-unsigned-ones', 0xFFFFFFFF, 0),
):
assert_unsigned_le(run(name, s_cmp_le_u32_words(program, left, right)), left, right)
signed_le = s_cmp_le_u32_words(program, 1, 2)
signed_le[7] = 0xBF051514 # s_cmp_le_i32 s20, s21 stays refused
run('s-cmp-le-i32-refused', signed_le, 'unsupported mesh instruction or EXEC state: s_cmp_le_i32')
signed_le, reason = signed_le_refusal(program)
run('s-cmp-le-i32-refused', signed_le, reason)
# V_CMPX replaces EXEC with the per-lane predicate and does not write a VCC ballot.
assert_cmpx_ne(run('v-cmpx-ne-narrow', v_cmpx_ne_u32_words(program, 0x7DAA0080)),
r'icmp ne i32 0, %[\w.]+')
assert_cmpx_ne(run('v-cmpx-ne-empty', v_cmpx_ne_u32_words(program, 0x7DAA0100)),
r'icmp ne i32 (?P<same>%[\w.]+), (?P=same)')
for name, words, predicate in cmpx_ne_cases(program):
assert_cmpx_ne(run(name, words), predicate)
# v_cmpx_lt_u32 writes EXEC from icmp ult and leaves VCC unused.
# Lane id < 2 is true for the lower lanes, false when the lane is equal or greater.
lane = r'%[\w.]+'
Expand Down
Loading
Loading