From 587fc6d20277c0ced1f77476285968ec04d959f9 Mon Sep 17 00:00:00 2001 From: JB2WIN Date: Fri, 27 Nov 2026 10:15:29 +0100 Subject: [PATCH 1/6] native: read formatted loads through a byte-address rewritten descriptor formatted_byte_load asked resource() for raw_vector_srv even when the descriptor was the byte-address rewrite (stride cleared in word 1), so a tbuffer_load_format_* through such a window was refused with "non-contiguous resource descriptor", for a table descriptor and for a GPU-selected heap descriptor under the raw_buffer contract. It now picks byte_window_srv by the same rule as the raw MUBUF load. Conversion, the getDimensions element bound and the raw loads are unchanged. Tests: - native_global_srv_heap_replay_check.py: a 32_UINT tbuffer load through the heap window is recorded, compiled and replayed for selections 0 and 1, with the cross-slot mismatch control; the loop guard refuses it; an 8_8_8_8_UNORM load through the window compiles. - native_mtbuf_check.py: the 11-format value check also runs through a byte window of its table SRV (native_store_replay accepts the window binding as the same raw view). - native_direct_container_check.py: compute table windows with both formats compile; without the byte-count product they are refused. Refs #3023 Co-Authored-By: Claude Opus 5.5 (cherry picked from commit e67f10177bbfb097234d1ecf8461142f1489acf1) --- .../native-global-srv-heap-replay.md | 24 ++++++++ src/gfx1013_compute_mtbuf.inl | 9 ++- tests/native_direct_container_check.py | 13 +++++ tests/native_global_srv_heap_replay_check.py | 55 ++++++++++++------- tests/native_mtbuf_check.py | 19 +++++-- tests/native_store_replay.cpp | 3 +- 6 files changed, 96 insertions(+), 27 deletions(-) diff --git a/docs/experiments/native-global-srv-heap-replay.md b/docs/experiments/native-global-srv-heap-replay.md index f267ca20ca..ff3f7a0e22 100644 --- a/docs/experiments/native-global-srv-heap-replay.md +++ b/docs/experiments/native-global-srv-heap-replay.md @@ -141,6 +141,18 @@ ctest --preset dev --no-tests=error -R "^native_global_srv_heap_replay(_warp|_ha - With the high-word check removed, both tests fail at the `mov_high` controls. - `ctest --preset dev --no-tests=error -R "native_|startup_compute|compile_dxil" -j 8`: 415 tests, 404 passed and 11 skipped (77, WARP). +- Formatted loads through the byte window (original #3034 result for #3023): `tbuffer_load_format_*` through the rewritten descriptor now reads + the same raw view as `buffer_load_dword` (`src/gfx1013_compute_mtbuf.inl` picks `byte_window_srv` when word 1 is the + stride-cleared word). Before, it was refused with "non-contiguous resource descriptor". On the local capture with the + raw contract forced and a typed heap load prototyped (both uncommitted), 861 of the 2,689 requests stopped first at + this refusal; with the change they move on to other, already-known refusals. `native_global_srv_heap_replay_hardware` + passes with 94 assertions (record, compile and replay of a 32_UINT `tbuffer_load_format_x` through the heap window + for selections 0 and 1, the cross-slot mismatch control, the loop guard for the formatted load, and a compile-only + 8_8_8_8_UNORM case). `native_mtbuf_hardware` repeats its 11-format value check through a byte window of its table SRV + and matches, including the element at the end of the view that returns 0 (`tests/native_store_replay.cpp` accepts + the window binding as the same raw view). `native_direct_container` compiles both formats through a compute table + window and refuses the window without the byte-count product. Against `837728dd` the heap check fails at the + `twindow_loop` shape (text "non-contiguous resource descriptor"). ## Limits @@ -153,6 +165,18 @@ ctest --preset dev --no-tests=error -R "^native_global_srv_heap_replay(_warp|_ha byte-address rewrite consumes it. The fixture's descriptor words are never evaluated, so a stride above 1 and the size rule of the contract are not exercised. The HLSL path's `heap_stride_srv` (`src/gfx1013_compute_native.cpp`, used by `tests/native_compute_grid.cpp`) is unchanged. +- A formatted load (`tbuffer_load_format_*`) bounds its element with the size of the desktop raw view + (`getDimensions`), not with the guest window's byte count, and returns 0 for the whole element when it does not fit. + A runtime that binds a byte window, as a table view or as a GPU-selected heap slot, must create the raw view with + exactly the guest window's byte count. The descriptor's DST_SEL (word 3) is not applied: only the identity channel + order is translated, and it is not checked. In the startup dispatch, the in-process route + (`translate_compute_natively`, `src/startup_stubs/d3d12_compute_dispatch.inl`) binds only `raw_vector_srv` inputs + and falls through to the manifest route for a byte window. A published manifest names a table byte window as + `srv buf table `, as for the raw byte window; the dispatch then binds the table descriptor as a raw + view of + `max(stride, 1) * num_records` bytes (`indirect_table_buffer`, `src/startup_stubs/d3d12_draw.inl`), the guest + window's byte count, or of the title's own view size for a view token. No fixture runs this manifest path for a + window. - Typed loads (`buffer_load_format_*`) through a heap descriptor and scalar loads through the rewritten descriptor stay refused. The startup runtime does not pass a contract yet, so none of this reaches a title run (#3023). diff --git a/src/gfx1013_compute_mtbuf.inl b/src/gfx1013_compute_mtbuf.inl index 9c8ff13124..2a8a85b88b 100644 --- a/src/gfx1013_compute_mtbuf.inl +++ b/src/gfx1013_compute_mtbuf.inl @@ -1,7 +1,8 @@ // MTBUF uses the instruction's explicit format and the descriptor's byte range. // Format numbers follow tools/disasm_rdna2.py MTBUF_FORMATS. Conversion and // unaligned addressing follow gfx2hlsl.tbuffer / ldu, cross-checked against -// Victory 9376fd6 format_load. Only the runtime-checked identity raw SRV is used. +// Victory 9376fd6 format_load. Only the runtime-checked identity raw SRV is used, or +// its byte window (the byte-address rewrite of the descriptor, read as the same raw view). enum class ChannelNumber { unorm, snorm, uscaled, sscaled, uint_, sint, float_ }; struct MtbufFamily { unsigned first, last, bits, components; @@ -53,7 +54,11 @@ void formatted_byte_load(const Inst &i, const State &s) { refuse(i.pc, "MTBUF destination tuple overflow"); const unsigned width = family->bits; const auto numeric = static_cast(unsigned(family->first_number) + format - family->first); - const auto handle = resource(i, s, (i.b >> 16 & 31) * 4, ComputeViewKind::raw_vector_srv, 4); + // The byte-address rewrite of a descriptor (stride cleared in word 1) is read as the same raw view, as for MUBUF. + const unsigned base = (i.b >> 16 & 31) * 4; + const auto handle = resource(i, s, base, s.at(base + 1).type == Symbol::Type::zero_stride_word + ? ComputeViewKind::byte_window_srv + : ComputeViewKind::raw_vector_srv, 4); const unsigned scalar_offset = i.b >> 24; auto addr = to_string(i.a & 4095); if (scalar_offset != 125 && scalar_offset != 128) diff --git a/tests/native_direct_container_check.py b/tests/native_direct_container_check.py index af6dc525e4..c7c915eda6 100644 --- a/tests/native_direct_container_check.py +++ b/tests/native_direct_container_check.py @@ -401,6 +401,19 @@ def atomic_program(instructions): broken[10] = 0xbf800000 # Leave NUM_RECORDS in elements instead of bytes. check("byte-count-missing-product", "gfx1013-container-ps", patched_pixel(len(broken), broken, table=True), "non-contiguous resource descriptor") + # The same rewrite in compute, read by MTBUF loads through s[28:31] (v_mov_b32 v5, 0 as the offset): + # tbuffer_load_format_x v8, v5, s[28:31], 0 format:[BUF_FMT_32_UINT] offen and + # tbuffer_load_format_xyzw v[8:11], v5, s[28:31], 0 format:[BUF_FMT_8_8_8_8_UNORM] offen. + tbuffer_view = [*byte_view[:13], 0x7e0a0280] + check("compute-tbuffer-byte-window", cs, compute(words(*tbuffer_view, 0xe8a01000, 0x80070805, end), table=True)) + check("compute-tbuffer-byte-window-unorm", cs, + compute(words(*tbuffer_view, 0xe9c31000, 0x80070805, end), table=True)) + # Over-acceptance control only: without the byte-count product the window fields do not match. + tbuffer_broken = tbuffer_view.copy() + tbuffer_broken[10] = 0xbf800000 + check("compute-tbuffer-byte-count-missing-product", cs, + compute(words(*tbuffer_broken, 0xe8a01000, 0x80070805, end), table=True), + "non-contiguous resource descriptor") # Convert v11 to a half in the high word of v6, retaining v6.low. # Widen the selected high word back from a scalar source into v7. halves = [0x7e0c02ff, 0xa5a53600, 0x7e1602ff, 0x3f801000, 0x7e0c14f9, 0x06150b, diff --git a/tests/native_global_srv_heap_replay_check.py b/tests/native_global_srv_heap_replay_check.py index fba18e6179..adade303b3 100644 --- a/tests/native_global_srv_heap_replay_check.py +++ b/tests/native_global_srv_heap_replay_check.py @@ -246,14 +246,18 @@ def without(prefix): load = words_list.index(0xe0301000) # buffer_load_dword v2, v1, s[20:23], 0 offen store = words_list.index(0xe0701000) # buffer_store_dword v2, v1, s[12:15], 0 offen - def window(rewritten=rewrite, prefix=(), store_word=0x80030201): + def window(rewritten=rewrite, prefix=(), store_word=0x80030201, load_words=(0xe0301000, 0x80060201)): """PROGRAM with the rewrite after the heap load and the load through s[24:27].""" program = list(words_list) - program[load + 1] = 0x80060201 # buffer_load_dword v2, v1, s[24:27], 0 offen + program[load:load + 2] = load_words # default: buffer_load_dword v2, v1, s[24:27], 0 offen program[store + 1] = store_word return program[:after_wait] + list(prefix) + list(rewritten) + program[after_wait:] WINDOW = window() + # tbuffer_load_format_x v2, v1, s[24:27], 0 format:[BUF_FMT_32_UINT] offen: a formatted load through the window. + # 32_UINT converts nothing, so the output is the slot data as for WINDOW. + TBUFFER_LOAD = (0xe8a01000, 0x80060201) + TWINDOW = window(load_words=TBUFFER_LOAD) second_load = window([0xbe980320 if w == 0xbe980314 else w for w in rewrite]) second_load[after_wait - 1:after_wait - 1] = [0xf4080801, 0x22000000] # before the s_waitcnt # The branch word sits at after_wait + 1; its target is next pc + 4 * simm16, here the s_lshl_b32 at word lshl. @@ -278,6 +282,9 @@ def window(rewritten=rewrite, prefix=(), store_word=0x80030201): # s_cmp_lg_u32 s16, s16 and s_cbranch_scc1 back to the s_lshl_b32 before the heap load (never taken): the # loop contains the heap load, which would run again for another selection "window_loop": (loop_around_load, "heap byte window loaded inside a loop"), + # the same loop around the heap load, read by the formatted load + "twindow_loop": (window(prefix=loop_around_load[after_wait:after_wait + 2], load_words=TBUFFER_LOAD), + "heap byte window loaded inside a loop"), } for name, (program, expected) in shapes.items(): directory = base / ("shape_" + name) @@ -311,6 +318,10 @@ def shader_request(name, program, **stage): # does not contain the load, which runs once "window_loop_after_load": (window(prefix=(0xbf071010, 0xbf85fffe)), "a loop after the heap load does not refuse the window, a .cso is published"), + # tbuffer_load_format_xyzw v[2:5], v1, s[24:27], 0 format:[BUF_FMT_8_8_8_8_UNORM] offen: a converting format + # through the window (values through a window are checked by native_mtbuf_check.py on a table window) + "twindow_unorm": (window(load_words=(0xe9c31000, 0x80060201)), + "a converting formatted load through the window compiles and publishes a .cso"), } for name, (program, message) in compiled_shapes.items(): directory, window_stem = shader_request(name, program) @@ -319,25 +330,29 @@ def shader_request(name, program, **stage): code, out, err = run([compile_dxil, sdk, cache, "gfx1013-container-cs", "--requests", directory, out_dir]) require(code == 0 and "requests=1 compiled=1 refused=0" in out and (out_dir / (window_stem[len("req_"):] + ".cs.cso")).exists(), "compile_dxil: " + message) - window_outputs = {} - for n in (0, 1): - directory, window_stem = shader_request(f"window{n}", WINDOW) - code, out, err = run([fixture, "record", sdk, cache, directory / (window_stem + ".cdx"), adapter, n, "ok"]) - require(code == 0 and "output matches slot %d data" % n in out, - f"record window select {n}: u0 equals the slot {n} data read through the rewritten descriptor") - out_dir = base / f"window{n}_out" - code, out, err = run([compile_dxil, sdk, cache, "gfx1013-container-cs", "--requests", directory, out_dir]) - cso = out_dir / (window_stem[len("req_"):] + ".cs.cso") - require(code == 0 and "requests=1 compiled=1 refused=0" in out and cso.exists(), - f"compile_dxil window select {n}: compiled and published a .cso") - window_outputs[n] = (directory, window_stem, cso) + # The raw load (window) and the formatted load (twindow) through the rewritten descriptor. + for label, program in (("window", WINDOW), ("twindow", TWINDOW)): + window_outputs = {} + for n in (0, 1): + directory, window_stem = shader_request(f"{label}{n}", program) + code, out, err = run([fixture, "record", sdk, cache, directory / (window_stem + ".cdx"), adapter, n, "ok"]) + require(code == 0 and "output matches slot %d data" % n in out, + f"record {label} select {n}: u0 equals the slot {n} data read through the rewritten descriptor") + out_dir = base / f"{label}{n}_out" + code, out, err = run([compile_dxil, sdk, cache, "gfx1013-container-cs", "--requests", directory, out_dir]) + cso = out_dir / (window_stem[len("req_"):] + ".cs.cso") + require(code == 0 and "requests=1 compiled=1 refused=0" in out and cso.exists(), + f"compile_dxil {label} select {n}: compiled and published a .cso") + window_outputs[n] = (directory, window_stem, cso) + code, out, err = run([fixture, "replay", sdk, cache, directory / (window_stem + ".cdx"), cso, + directory / (window_stem + ".views"), adapter, "ok", n]) + require(code == 0 and "output matches slot %d data" % n in out, + f"replay {label} select {n}: output equals slot {n} data") + directory, window_stem, cso = window_outputs[0] code, out, err = run([fixture, "replay", sdk, cache, directory / (window_stem + ".cdx"), cso, - directory / (window_stem + ".views"), adapter, "ok", n]) - require(code == 0 and "output matches slot %d data" % n in out, f"replay window select {n}: output equals slot {n} data") - directory, window_stem, cso = window_outputs[0] - code, out, err = run([fixture, "replay", sdk, cache, directory / (window_stem + ".cdx"), cso, - directory / (window_stem + ".views"), adapter, "ok", 1]) - require(code == 1 and "mismatch word 0" in out, "replay window select 0 compared with slot 1 data reports a mismatch") + directory / (window_stem + ".views"), adapter, "ok", 1]) + require(code == 1 and "mismatch word 0" in out, + f"replay {label} select 0 compared with slot 1 data reports a mismatch") missing = base / "missing" / (stem + ".views") code, out, err = replay(selections[0], outputs[0], missing, "refused", 0) diff --git a/tests/native_mtbuf_check.py b/tests/native_mtbuf_check.py index a240b9c145..9838ccfb69 100644 --- a/tests/native_mtbuf_check.py +++ b/tests/native_mtbuf_check.py @@ -15,10 +15,19 @@ PACKED = struct.pack("<6I", 0x7fff8000, 0x40008001, 0x007fff81, 0xfc003c00, 0x0001bc00, 0x42987ec5) -def program(unsigned): +# The byte-address rewrite of the SRV descriptor s[32:35] in place (LLVM 15): s_waitcnt lgkmcnt(0); +# s_bfe_u32 s40, s33, 0xe0010 (stride); s_max_u32 s40, s40, 1; s_mul_i32 s34, s34, s40 (byte count); +# s_and_b32 s33, s33, 0xc000ffff (stride cleared); s_and_b32 s35, s35, 0xcfffffff; s_or_b32 s35, s35, 0x30000000. +BYTE_WINDOW = [0xbf8cc07f, 0x93a8ff21, 0x000e0010, 0x84a88128, 0x93222822, 0x8721ff21, 0xc000ffff, + 0x8723ff23, 0xcfffffff, 0x8823ff23, 0x30000000] + + +def program(unsigned, window=False): # Load a raw SRV and UAV from separate table parameters. One writer per group. + # With window, every MTBUF load reads the byte window of the SRV (same raw view, same expected values). words = [sop1(3, 20, 4), sop1(3, 21, 128), sop1(3, 22, 5), sop1(3, 23, 128), 0xf4080000 | 32 << 6 | 10, 0xfa000020, 0xf4080000 | 36 << 6 | 11, 0xfa000020, + *(BYTE_WINDOW if window else ()), scalar(0x1e, 7, 6, 135), vmove(8, 7), sop1(3, 126, 129)] pos = 0 for index, (fmt, channels, disp) in enumerate(CASES): @@ -76,8 +85,8 @@ def main(cli, gpu, sdk): start = 8 + 32 * group row = expected(group) reference[start:start + len(row)] = row - for unsigned in (False, True): - words = program(unsigned) + for unsigned, window in ((False, False), (True, False), (False, True)): + words = program(unsigned, window) marker = write_request(work, words, root.read_bytes(), sa) dest = work / "result.bin" run = subprocess.run([gpu, sdk, marker, work/"cache", "0", dest, "--direct"]) @@ -90,6 +99,7 @@ def main(cli, gpu, sdk): assert differences and set(differences) <= {8, 9, 40, 41}, differences else: assert not differences, [(i, hex(actual[i]), hex(reference[i])) for i in differences] + words = program(False) # the guards below change the plain (non-window) program insn = next(i for i, w in enumerate(words) if w >> 26 == 0x3a) for op, error in ((words[insn] | (1 << 13), "without index"), (0xe8001000 | 24 << 19 | 3 << 16, "absent component")): @@ -99,7 +109,8 @@ def main(cli, gpu, sdk): reject = subprocess.run([cli, sdk, work/"cache", "gfx1013-direct-cs@0", marker, work/"bad.cso"], capture_output=True, text=True) assert reject.returncode and error in reject.stderr and not (work/"bad.cso").exists(), reject.stderr - print(f"MTBUF matched {2 * len(row)} result words and all guards; changed format, index and component controls passed.") + print(f"MTBUF matched {2 * len(row)} result words, also through the SRV byte window, and all guards; " + "changed format, index and component controls passed.") if __name__ == "__main__": diff --git a/tests/native_store_replay.cpp b/tests/native_store_replay.cpp index 43b7af3df3..9292eee5cc 100644 --- a/tests/native_store_replay.cpp +++ b/tests/native_store_replay.cpp @@ -161,7 +161,8 @@ int wmain(int argc, wchar_t **argv) { if (position>=hd.NumDescriptors) return 2; auto cpu=heap->GetCPUDescriptorHandleForHeapStart();cpu.ptr+=UINT64(position)*step; Window w;w.write=compute_buffer_uav(b.kind); - const bool vector_bytes = b.kind == ComputeViewKind::raw_vector_srv; + // A byte window is the byte-address rewrite of the same raw table view. + const bool vector_bytes = b.kind == ComputeViewKind::raw_vector_srv || b.kind == ComputeViewKind::byte_window_srv; const bool root_bytes = b.kind == ComputeViewKind::root_buffer_srv; if (!w.write && b.kind!=ComputeViewKind::typed_buffer_srv && b.kind!=ComputeViewKind::buffer_srv && !vector_bytes && !root_bytes) return 2; const bool raw=root_bytes || vector_bytes || b.kind==ComputeViewKind::buffer_srv || b.kind==ComputeViewKind::raw_buffer_uav; From 809521892622eee879be56e53951da83a0342444 Mon Sep 17 00:00:00 2001 From: RonLogic <307541314+RonLogic@users.noreply.github.com> Date: Sat, 28 Nov 2026 09:04:00 +0200 Subject: [PATCH 2/6] runtime: validate published MTBUF byte-window channel order --- .../native-global-srv-heap-replay.md | 20 ++-- src/direct_compute_cache.cpp | 9 +- src/gfx1013_compute_mtbuf.inl | 6 +- src/gfx1013_compute_native.h | 1 + src/gfx1013_direct_compute.inl | 7 +- src/startup_stubs/d3d12_compute_dispatch.inl | 9 +- src/startup_stubs/d3d12_draw.inl | 7 +- .../cmake/startup_compute_mtbuf_window.cmake | 10 ++ tests/startup_compute_mtbuf_window_check.py | 112 ++++++++++++++++++ tests/startup_stream_consumer.cpp | 10 ++ 10 files changed, 171 insertions(+), 20 deletions(-) create mode 100644 tests/cmake/startup_compute_mtbuf_window.cmake create mode 100644 tests/startup_compute_mtbuf_window_check.py diff --git a/docs/experiments/native-global-srv-heap-replay.md b/docs/experiments/native-global-srv-heap-replay.md index ff3f7a0e22..2a726fe379 100644 --- a/docs/experiments/native-global-srv-heap-replay.md +++ b/docs/experiments/native-global-srv-heap-replay.md @@ -166,17 +166,15 @@ ctest --preset dev --no-tests=error -R "^native_global_srv_heap_replay(_warp|_ha size rule of the contract are not exercised. The HLSL path's `heap_stride_srv` (`src/gfx1013_compute_native.cpp`, used by `tests/native_compute_grid.cpp`) is unchanged. - A formatted load (`tbuffer_load_format_*`) bounds its element with the size of the desktop raw view - (`getDimensions`), not with the guest window's byte count, and returns 0 for the whole element when it does not fit. - A runtime that binds a byte window, as a table view or as a GPU-selected heap slot, must create the raw view with - exactly the guest window's byte count. The descriptor's DST_SEL (word 3) is not applied: only the identity channel - order is translated, and it is not checked. In the startup dispatch, the in-process route - (`translate_compute_natively`, `src/startup_stubs/d3d12_compute_dispatch.inl`) binds only `raw_vector_srv` inputs - and falls through to the manifest route for a byte window. A published manifest names a table byte window as - `srv buf table `, as for the raw byte window; the dispatch then binds the table descriptor as a raw - view of - `max(stride, 1) * num_records` bytes (`indirect_table_buffer`, `src/startup_stubs/d3d12_draw.inl`), the guest - window's byte count, or of the title's own view size for a view token. No fixture runs this manifest path for a - window. + (`getDimensions`) and returns 0 for the whole element when it does not fit. A runtime that binds a byte window + must create the raw view with the exact guest window's byte count. The heap replay uses identity channel order. + A published table manifest marks the MTBUF window with `srv buf table identity_dst_sel`, including + after a frontend cache hit. The compute binder checks word 3's DST_SEL of the hardware descriptor or the + component mapping of a slot 18 buffer SRV before binding the raw view for the exact range. The in-process + path falls through to that manifest for a byte window. +- `startup_compute_mtbuf_window_{hardware,warp}` compares 12 pairs and the surrounding guards through the published + path for both a hardware descriptor and a buffer SRV token. A 44-byte window holds five full pairs. The partial + pair and the later pairs read zero. Swapped X/Y selectors refuse before Dispatch, and the output keeps its sentinel. - Typed loads (`buffer_load_format_*`) through a heap descriptor and scalar loads through the rewritten descriptor stay refused. The startup runtime does not pass a contract yet, so none of this reaches a title run (#3023). diff --git a/src/direct_compute_cache.cpp b/src/direct_compute_cache.cpp index 2c4ad29e47..cddc29dc72 100644 --- a/src/direct_compute_cache.cpp +++ b/src/direct_compute_cache.cpp @@ -90,7 +90,7 @@ Bytes encode(const NativeComputeShader &program) { for (const auto &b : program.bindings) { word(out, static_cast(b.kind)); for (unsigned n : {b.root_parameter, b.byte_offset, b.shader_register, b.required_bytes, b.array_count, - b.array_position, b.image_dimension, unsigned(b.scalar_table)}) + b.array_position, b.image_dimension, unsigned(b.scalar_table), unsigned(b.requires_identity_dst_sel)}) word(out, n); } word(out, static_cast(program.constants.size())); @@ -134,6 +134,7 @@ NativeComputeShader decode(std::string_view bytes) { auto kind = static_cast(in.count(static_cast(ComputeViewKind::float3_texture_uav))); ComputeViewBinding b{kind, in.word(), in.word(), in.word(), in.word(), in.word(), in.word(), in.count(7)}; b.scalar_table = static_cast(in.count(unsigned(ComputeViewBinding::ScalarTable::srv))); + b.requires_identity_dst_sel = in.count(1) != 0; const bool sampler_heap = kind == ComputeViewKind::heap_sampler; if (!b.array_count || b.array_position >= b.array_count || (sampler_heap ? b.root_parameter != compute_sampler_heap @@ -795,8 +796,10 @@ std::optional format_compute_runtime_manifest(const NativeComputeSh return refuse("SRV registers not contiguous"); if (b.kind == ComputeViewKind::buffer_srv || b.kind == ComputeViewKind::raw_vector_srv || b.kind == ComputeViewKind::byte_window_srv) { - srv_lines << "srv " << b.shader_register << " buf table " << b.root_parameter << ' ' << b.byte_offset - << '\n'; + srv_lines << "srv " << b.shader_register << " buf table " << b.root_parameter << ' ' << b.byte_offset; + if (b.requires_identity_dst_sel) + srv_lines << " identity_dst_sel"; + srv_lines << '\n'; } else if (b.kind == ComputeViewKind::texture_srv && b.image_dimension == 1 && b.array_count == 1) { srv_lines << "srv " << b.shader_register << " tex2d table " << b.root_parameter << ' ' << b.byte_offset << '\n'; diff --git a/src/gfx1013_compute_mtbuf.inl b/src/gfx1013_compute_mtbuf.inl index 2a8a85b88b..36a7cfd018 100644 --- a/src/gfx1013_compute_mtbuf.inl +++ b/src/gfx1013_compute_mtbuf.inl @@ -56,9 +56,9 @@ void formatted_byte_load(const Inst &i, const State &s) { const auto numeric = static_cast(unsigned(family->first_number) + format - family->first); // The byte-address rewrite of a descriptor (stride cleared in word 1) is read as the same raw view, as for MUBUF. const unsigned base = (i.b >> 16 & 31) * 4; - const auto handle = resource(i, s, base, s.at(base + 1).type == Symbol::Type::zero_stride_word - ? ComputeViewKind::byte_window_srv - : ComputeViewKind::raw_vector_srv, 4); + const bool window = s.at(base + 1).type == Symbol::Type::zero_stride_word; + const auto kind = window ? ComputeViewKind::byte_window_srv : ComputeViewKind::raw_vector_srv; + const auto handle = resource(i, s, base, kind, 4, nullptr, window); const unsigned scalar_offset = i.b >> 24; auto addr = to_string(i.a & 4095); if (scalar_offset != 125 && scalar_offset != 128) diff --git a/src/gfx1013_compute_native.h b/src/gfx1013_compute_native.h index 1ba36eaaa4..ea3382d2cc 100644 --- a/src/gfx1013_compute_native.h +++ b/src/gfx1013_compute_native.h @@ -80,6 +80,7 @@ struct ComputeViewBinding { unsigned image_dimension = 1; // ISA dimension field; 1 denotes Texture2D. enum class ScalarTable { unknown, reflected_cbv, declared_cbv, srv }; ScalarTable scalar_table = ScalarTable::unknown; + bool requires_identity_dst_sel = false; }; bool apply_reflected_table_use(ComputeViewBinding &binding, const GuestShaderStage &stage, std::optional packed_sgpr = {}); diff --git a/src/gfx1013_direct_compute.inl b/src/gfx1013_direct_compute.inl index f46ebb6c8b..0375e62ddc 100644 --- a/src/gfx1013_direct_compute.inl +++ b/src/gfx1013_direct_compute.inl @@ -363,7 +363,7 @@ struct DirectCompute { } std::set> read_write_raw_views; string resource(const Inst &i, const State &s, unsigned base, ComputeViewKind kind, unsigned bytes, - unsigned *bound_register = nullptr) { + unsigned *bound_register = nullptr, bool requires_identity_dst_sel = false) { const auto &symbol = s.at(base); const bool indexed = symbol.type == Symbol::Type::indexed_descriptor; if (indexed && symbol.value == compute_resource_heap) @@ -372,6 +372,8 @@ struct DirectCompute { (kind == ComputeViewKind::buffer_srv || kind == ComputeViewKind::raw_vector_srv || kind == ComputeViewKind::byte_window_srv) && read_write_raw_views.count({symbol.value, symbol.offset})) { + if (requires_identity_dst_sel) + refuse(i.pc, "a writable MTBUF byte window has no verified view contract"); // Both instructions read the same descriptor table entry. A // second, SRV binding would conflict with its writable resource state. kind = ComputeViewKind::raw_buffer_uav; @@ -384,6 +386,9 @@ struct DirectCompute { }); if (it == analysis.result.bindings.end()) throw std::logic_error("missing direct binding"); + if (requires_identity_dst_sel) + for (unsigned j = 0; j < count; ++j) + it[j].requires_identity_dst_sel = true; if (bound_register) *bound_register = it->shader_register; const bool raw = kind == ComputeViewKind::raw_buffer_uav || kind == ComputeViewKind::buffer_srv || kind == ComputeViewKind::raw_vector_srv || kind == ComputeViewKind::byte_window_srv || diff --git a/src/startup_stubs/d3d12_compute_dispatch.inl b/src/startup_stubs/d3d12_compute_dispatch.inl index e0cb2a5a3c..770f4eeca9 100644 --- a/src/startup_stubs/d3d12_compute_dispatch.inl +++ b/src/startup_stubs/d3d12_compute_dispatch.inl @@ -34,6 +34,7 @@ struct ComputeTranslation { std::uint32_t at = 0, times = 0; Source source = root_constant; D3D12_UAV_DIMENSION uav_dimension = D3D12_UAV_DIMENSION_UNKNOWN; + bool requires_identity_dst_sel = false; bool root = false; bool atomic_uint_texture = false; unsigned channels = 4; @@ -172,6 +173,11 @@ const char* load_compute_translation(ComputeTranslation& tr) tr.uds.push_back({a, 0, false, false, -1, 0, 0, 0, source()}); else if (std::sscanf(line.c_str(), "srv %u buf table %d %d%n", &i, &a, &b, &used) == 3 && whole() && i == tr.srvs.size()) tr.srvs.push_back({a, b}); + else if (std::sscanf(line.c_str(), "srv %u buf table %d %d identity_dst_sel%n", &i, &a, &b, &used) == 3 && whole() && + i == tr.srvs.size()) { + tr.srvs.push_back({a, b}); + tr.srvs.back().requires_identity_dst_sel = true; + } else if (std::sscanf(line.c_str(), "srv %u buf root %d%n", &i, &a, &used) == 2 && whole() && a >= 0 && i == tr.srvs.size()) { tr.srvs.push_back({a, 0}); @@ -593,7 +599,8 @@ const char* record_translated_dispatch(Wrapper* self, const TranslatedDispatch& } if (!output) { // Each condition of a complete GPU-backed buffer range has its own reason. - const IndirectBufferView view = indirect_table_buffer(self, words, false, &reason, 16u << 20, true); + const IndirectBufferView view = indirect_table_buffer(self, words, false, &reason, 16u << 20, true, + slot.requires_identity_dst_sel); if (view.source == 1) InterlockedIncrement(&compute_inputs_gpu_copied); if (view.source == 2) { InterlockedIncrement(&compute_inputs_snapshot); diff --git a/src/startup_stubs/d3d12_draw.inl b/src/startup_stubs/d3d12_draw.inl index 7d1901c53a..04d2f35429 100644 --- a/src/startup_stubs/d3d12_draw.inl +++ b/src/startup_stubs/d3d12_draw.inl @@ -2362,7 +2362,7 @@ bool title_input_snapshot_enabled() IndirectBufferView indirect_table_buffer(Wrapper* self, const std::uint32_t* words, bool allow_address_alias = false, const char** why = nullptr, u64 limit = u64{4} << D3D12_REQ_BUFFER_RESOURCE_TEXEL_COUNT_2_TO_EXP, - bool allow_title_snapshot = false) + bool allow_title_snapshot = false, bool requires_identity_dst_sel = false) { const auto refuse = [why](const char* reason) { if (why) *why = reason; @@ -2379,6 +2379,7 @@ IndirectBufferView indirect_table_buffer(Wrapper* self, const std::uint32_t* wor if (words[1] < view_records().size()) record = view_records()[words[1]]; ReleaseSRWLockShared(¬e_lock); if (record.slot == 17 && record.desc_bytes >= 12) { + if (requires_identity_dst_sel) return refuse("an MTBUF byte window requires a buffer SRV"); UINT size = 0; std::memcpy(&address, record.desc, 8); std::memcpy(&size, record.desc + 8, 4); @@ -2386,6 +2387,8 @@ IndirectBufferView indirect_table_buffer(Wrapper* self, const std::uint32_t* wor } else if (record.slot == 18 && record.desc_bytes >= 40) { D3D12_SHADER_RESOURCE_VIEW_DESC view{}; std::memcpy(&view, record.desc, 40); + if (requires_identity_dst_sel && view.Shader4ComponentMapping != D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING) + return refuse("an MTBUF byte window requires identity component mapping"); owner = as_wrapper(reinterpret_cast(record.resource)); if (!owner || owner->own().kind != resource_kind || !owner->own().real || view.ViewDimension != D3D12_SRV_DIMENSION_BUFFER) return refuse("an input view token is not a buffer view of a desktop resource"); @@ -2416,6 +2419,8 @@ IndirectBufferView indirect_table_buffer(Wrapper* self, const std::uint32_t* wor return refuse("an input view token is not a buffer view of a desktop resource"); } } else { + if (requires_identity_dst_sel && (words[3] & 0xfffu) != 0xfacu) + return refuse("an MTBUF byte window requires identity DST_SEL"); address = words[0] | (u64{words[1] & 0xffff} << 32); stride = (words[1] >> 16) & 0x3fff; bytes = u64{stride ? stride : 1} * words[2]; diff --git a/tests/cmake/startup_compute_mtbuf_window.cmake b/tests/cmake/startup_compute_mtbuf_window.cmake new file mode 100644 index 0000000000..d015bde331 --- /dev/null +++ b/tests/cmake/startup_compute_mtbuf_window.cmake @@ -0,0 +1,10 @@ +if(TARGET compile_dxil AND TARGET startup_stream_consumer AND TARGET offscreen_check AND EXISTS "${INTAKE_PYTHON}" + AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll") + foreach(adapter IN ITEMS warp hardware) + add_test(NAME startup_compute_mtbuf_window_${adapter} COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_mtbuf_window_check.py" + "$" "$" "$" + "${DXC_BIN_DIR}" ${adapter}) + set_tests_properties(startup_compute_mtbuf_window_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77) + endforeach() +endif() diff --git a/tests/startup_compute_mtbuf_window_check.py b/tests/startup_compute_mtbuf_window_check.py new file mode 100644 index 0000000000..d24a3e0793 --- /dev/null +++ b/tests/startup_compute_mtbuf_window_check.py @@ -0,0 +1,112 @@ +"""Dispatch a published MTBUF byte window with matching and swapped DST_SEL.""" + +from pathlib import Path +import struct +import subprocess +import sys +from tempfile import TemporaryDirectory + +from native_gather_lod_check import render +from native_mtbuf_check import BYTE_WINDOW +from native_scalar_lds_check import scalar, sop1, vmove +from startup_compute_dispatch_check import dispatch, lines, prepare_case +from startup_compute_translate_check import state_a +from startup_gfx2hlsl_compute_check import SENTINEL, TGID_X, TGID_Y, TGID_Z, USER7, WORDS + + +INPUT = [0x01234567 + 0x1020304 * i & 0xffffffff for i in range(WORDS)] +STATE = state_a((32, 1, 1), USER7 | TGID_X | TGID_Y | TGID_Z) +IDENTITY = 0x0103efac +SWAPPED_XY = 0x0103efa5 +EXPECTED = INPUT[:10] + [0] * 14 + [SENTINEL] * (WORDS - 24) +GUARDS = [SENTINEL] * WORDS +VIEW = 'srv 0 buf table 1 0 identity_dst_sel' + + +def program(): + words = [ + sop1(3, 20, 6), sop1(3, 21, 128), + 0xf408080a, 0xfa000000, # SRV in s[32:35] + 0xf408090a, 0xfa000020, # UAV in s[36:39] + *BYTE_WINDOW, + scalar(0x26, 8, 8, 131), # y * 3 + scalar(0x26, 9, 9, 134), # z * 6 + scalar(0, 11, 7, 8), scalar(0, 11, 11, 9), + scalar(0x1e, 12, 11, 131), # 8 * flattened group + sop1(3, 126, 129), vmove(8, 12), # one writer per group + 0xe8001000 | 62 << 19 | 1 << 16, 0x80080a08, # tbuffer_load_format_xy R32G32_UINT + 0xe0741000, 0x80090a08, # buffer_store_dwordx2 v[10:11], v8 + 0xbf810000, + ] + return struct.pack('<%dI' % len(words), *words) + + +def prepare(work, adapter): + cache, env = prepare_case(work, adapter) + env.pop('X2W_NATIVE_SHADERS', None) + env.pop('X2W_NATIVE_SHADERS_ONLY', None) + (work / 'program').write_bytes(program()) + (work / 'state').write_bytes(STATE) + source = work / 'source.bin' + source.write_bytes(struct.pack('<%dI' % WORDS, *INPUT)) + env['X2W_TEST_DISPATCH_IN'] = str(source) + env['X2W_TEST_DISPATCH_FIELDS'] = str(work / 'fields.bin') + return cache, env + + +def run(work, consumer, env, word3, *, probe=False, mapping=None): + # The 44-byte input window holds five complete pairs and one dword. + (work / 'fields.bin').write_bytes(struct.pack('<6I', 11, 4, word3, 4, WORDS, 0)) + if mapping: + env = dict(env, X2W_TEST_DISPATCH_INPUT_VIEW=mapping) + return dispatch(work, consumer, env, 'dispatch-records32', probe=probe) + + +def compare(got, expected, result): + if got != expected: + word = next(i for i, (actual, want) in enumerate(zip(got, expected)) if actual != want) + raise AssertionError(f'word {word}: expected {expected[word]:08x}, read {got[word]:08x}\n{result.stderr[-3000:]}') + + +def main(cli, consumer, renderer, sdk, adapter): + wave = render(renderer, adapter, '--shader-wave32') + assert wave.returncode == 0, wave.stdout + wave.stderr + with TemporaryDirectory() as temp: + work = Path(temp) + cache, env = prepare(work, adapter) + got, result = run(work, consumer, env, IDENTITY, probe=True) + compare(got, GUARDS, result) + assert lines(result, 'Dispatch(3, 2, 2) refused: no translation'), result.stderr + [request] = cache.glob('req_*.c67') + key = request.stem.removeprefix('req_') + command = [cli, sdk, work / 'native', 'gfx1013-direct-cs@0', '--requests', cache] + for index, dest in enumerate((cache, work / 'warm')): + result = subprocess.run([*command, dest], capture_output=True, text=True, timeout=30) + assert result.returncode == 0 and f'frontend_cache_hit={index}' in result.stdout, result.stdout + result.stderr + manifest = dest / f'{key}.txt' + assert VIEW in manifest.read_text().splitlines(), manifest.read_text() + assert (cache / f'{key}.txt').read_bytes() == (work / 'warm' / f'{key}.txt').read_bytes() + + got, result = run(work, consumer, env, IDENTITY) + compare(got, EXPECTED, result) + assert len(lines(result, 'Dispatch(3, 2, 2) translated')) == 1, result.stderr[-3000:] + assert not lines(result, 'refused: '), result.stderr[-3000:] + assert not [line for line in lines(result, 'x2w-d3d12-debug ') if ' sev=0 ' in line or ' sev=1 ' in line] + got, result = run(work, consumer, env, SWAPPED_XY) + compare(got, GUARDS, result) + refusal = 'Dispatch(3, 2, 2) refused: an MTBUF byte window requires identity DST_SEL' + assert len(lines(result, refusal)) == 1, result.stderr[-3000:] + got, result = run(work, consumer, env, IDENTITY, mapping='identity') + compare(got, EXPECTED, result) + assert len(lines(result, 'Dispatch(3, 2, 2) translated')) == 1, result.stderr[-3000:] + assert not lines(result, 'refused: '), result.stderr[-3000:] + got, result = run(work, consumer, env, IDENTITY, mapping='swapped') + compare(got, GUARDS, result) + refusal = 'Dispatch(3, 2, 2) refused: an MTBUF byte window requires identity component mapping' + assert len(lines(result, refusal)) == 1, result.stderr[-3000:] + print(f'{adapter}: identity readback matched five pairs, seven out-of-range pairs and all guards. ' + 'Swapped X/Y refused for both descriptor forms. Cold and warm manifests matched.') + + +if __name__ == '__main__': + main(*sys.argv[1:]) diff --git a/tests/startup_stream_consumer.cpp b/tests/startup_stream_consumer.cpp index 9a89c3dfe1..5c7ee9014c 100644 --- a/tests/startup_stream_consumer.cpp +++ b/tests/startup_stream_consumer.cpp @@ -363,6 +363,16 @@ static int dispatch_slot67(IDXGIAdapter* adapter, void* device, const std::strin std::memset(reinterpret_cast(cpu + sizeof(descriptors[0])), 0, sizeof(descriptors[1])); std::memcpy(reinterpret_cast(cpu + 32), descriptors[1], sizeof(descriptors[1])); } + char input_mapping[16]{}; + const auto mapping_chars = GetEnvironmentVariableA("X2W_TEST_DISPATCH_INPUT_VIEW", input_mapping, sizeof(input_mapping)); + if (mode == "dispatch-records32" && mapping_chars && mapping_chars < sizeof(input_mapping)) { + const UINT mapping = std::strcmp(input_mapping, "swapped") == 0 + ? D3D12_ENCODE_SHADER_4_COMPONENT_MAPPING(1, 0, 2, 3) + : D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; + D3D12_SHADER_RESOURCE_VIEW_DESC view{DXGI_FORMAT_R32_UINT, D3D12_SRV_DIMENSION_BUFFER, mapping}; + view.Buffer.NumElements = fields[0][0] * fields[0][1] / 4; + invoke(device, 18, word(placed[0]), word(&view), cpu); + } void* other_heap = nullptr; if (change_table_heap && (FAILED(static_cast(invoke(device, 14, word(&heap_desc), word(&__uuidof(ID3D12DescriptorHeap)), From 5399a2d81b90e2dcb11bf93d1d695c4d4924daa3 Mon Sep 17 00:00:00 2001 From: RonLogic <307541314+RonLogic@users.noreply.github.com> Date: Sat, 28 Nov 2026 14:12:09 +0200 Subject: [PATCH 3/6] test: cover MTBUF writable alias and CBV refusals --- .../cmake/startup_compute_mtbuf_window.cmake | 21 ++++++++----- tests/startup_compute_mtbuf_window_check.py | 31 +++++++++++++++---- tests/startup_stream_consumer.cpp | 17 ++++++---- 3 files changed, 49 insertions(+), 20 deletions(-) diff --git a/tests/cmake/startup_compute_mtbuf_window.cmake b/tests/cmake/startup_compute_mtbuf_window.cmake index d015bde331..6acb4d3bf7 100644 --- a/tests/cmake/startup_compute_mtbuf_window.cmake +++ b/tests/cmake/startup_compute_mtbuf_window.cmake @@ -1,10 +1,15 @@ -if(TARGET compile_dxil AND TARGET startup_stream_consumer AND TARGET offscreen_check AND EXISTS "${INTAKE_PYTHON}" +if(TARGET compile_dxil AND EXISTS "${INTAKE_PYTHON}" AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll") - foreach(adapter IN ITEMS warp hardware) - add_test(NAME startup_compute_mtbuf_window_${adapter} COMMAND "${INTAKE_PYTHON}" -B - "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_mtbuf_window_check.py" - "$" "$" "$" - "${DXC_BIN_DIR}" ${adapter}) - set_tests_properties(startup_compute_mtbuf_window_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77) - endforeach() + set(mtbuf_window_check "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_mtbuf_window_check.py") + add_test(NAME startup_compute_mtbuf_window_controls COMMAND "${INTAKE_PYTHON}" -B + "${mtbuf_window_check}" controls "$" "${DXC_BIN_DIR}") + set_tests_properties(startup_compute_mtbuf_window_controls PROPERTIES TIMEOUT 60) + if(TARGET startup_stream_consumer AND TARGET offscreen_check) + foreach(adapter IN ITEMS warp hardware) + add_test(NAME startup_compute_mtbuf_window_${adapter} COMMAND "${INTAKE_PYTHON}" -B + "${mtbuf_window_check}" "$" "$" + "$" "${DXC_BIN_DIR}" ${adapter}) + set_tests_properties(startup_compute_mtbuf_window_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77) + endforeach() + endif() endif() diff --git a/tests/startup_compute_mtbuf_window_check.py b/tests/startup_compute_mtbuf_window_check.py index d24a3e0793..717c26588b 100644 --- a/tests/startup_compute_mtbuf_window_check.py +++ b/tests/startup_compute_mtbuf_window_check.py @@ -10,8 +10,8 @@ from native_mtbuf_check import BYTE_WINDOW from native_scalar_lds_check import scalar, sop1, vmove from startup_compute_dispatch_check import dispatch, lines, prepare_case -from startup_compute_translate_check import state_a -from startup_gfx2hlsl_compute_check import SENTINEL, TGID_X, TGID_Y, TGID_Z, USER7, WORDS +from startup_compute_translate_check import state_a, write_request +from startup_gfx2hlsl_compute_check import SENTINEL, TGID_X, TGID_Y, TGID_Z, USER7, WORDS, root_blob INPUT = [0x01234567 + 0x1020304 * i & 0xffffffff for i in range(WORDS)] @@ -23,11 +23,11 @@ VIEW = 'srv 0 buf table 1 0 identity_dst_sel' -def program(): +def program(*, writable=False): words = [ sop1(3, 20, 6), sop1(3, 21, 128), 0xf408080a, 0xfa000000, # SRV in s[32:35] - 0xf408090a, 0xfa000020, # UAV in s[36:39] + 0xf408090a, 0xfa000000 if writable else 0xfa000020, # revisit the same descriptor for UAV in the negative *BYTE_WINDOW, scalar(0x26, 8, 8, 131), # y * 3 scalar(0x26, 9, 9, 134), # z * 6 @@ -41,6 +41,18 @@ def program(): return struct.pack('<%dI' % len(words), *words) +def controls(cli, sdk): + with TemporaryDirectory() as temp: + work = Path(temp) + key = write_request(work, program(writable=True), STATE, root=root_blob(table_range=True)) + result = subprocess.run([cli, sdk, work / 'native', 'gfx1013-direct-cs@0', '--requests', work, work], + capture_output=True, text=True, timeout=30) + reason = 'a writable MTBUF byte window has no verified view contract' + assert result.returncode != 0 and reason in result.stderr, result.stdout + result.stderr + assert not (work / f'{key:016x}.txt').exists() and not (work / f'{key:016x}.cs.cso').exists() + print('MTBUF writable byte-window request refused before DXIL publication') + + def prepare(work, adapter): cache, env = prepare_case(work, adapter) env.pop('X2W_NATIVE_SHADERS', None) @@ -104,9 +116,16 @@ def main(cli, consumer, renderer, sdk, adapter): compare(got, GUARDS, result) refusal = 'Dispatch(3, 2, 2) refused: an MTBUF byte window requires identity component mapping' assert len(lines(result, refusal)) == 1, result.stderr[-3000:] + got, result = run(work, consumer, env, IDENTITY, mapping='cbv') + compare(got, GUARDS, result) + refusal = 'Dispatch(3, 2, 2) refused: an MTBUF byte window requires a buffer SRV' + assert len(lines(result, refusal)) == 1, result.stderr[-3000:] print(f'{adapter}: identity readback matched five pairs, seven out-of-range pairs and all guards. ' - 'Swapped X/Y refused for both descriptor forms. Cold and warm manifests matched.') + 'Both swaps and the CBV token refused. Cold and warm manifests matched.') if __name__ == '__main__': - main(*sys.argv[1:]) + if sys.argv[1] == 'controls': + controls(*sys.argv[2:]) + else: + main(*sys.argv[1:]) diff --git a/tests/startup_stream_consumer.cpp b/tests/startup_stream_consumer.cpp index 102781412e..4904291218 100644 --- a/tests/startup_stream_consumer.cpp +++ b/tests/startup_stream_consumer.cpp @@ -390,12 +390,17 @@ static int dispatch_slot67(IDXGIAdapter* adapter, void* device, const std::strin char input_mapping[16]{}; const auto mapping_chars = GetEnvironmentVariableA("X2W_TEST_DISPATCH_INPUT_VIEW", input_mapping, sizeof(input_mapping)); if (mode == "dispatch-records32" && mapping_chars && mapping_chars < sizeof(input_mapping)) { - const UINT mapping = std::strcmp(input_mapping, "swapped") == 0 - ? D3D12_ENCODE_SHADER_4_COMPONENT_MAPPING(1, 0, 2, 3) - : D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; - D3D12_SHADER_RESOURCE_VIEW_DESC view{DXGI_FORMAT_R32_UINT, D3D12_SRV_DIMENSION_BUFFER, mapping}; - view.Buffer.NumElements = fields[0][0] * fields[0][1] / 4; - invoke(device, 18, word(placed[0]), word(&view), cpu); + if (std::strcmp(input_mapping, "cbv") == 0) { + const D3D12_CONSTANT_BUFFER_VIEW_DESC view{word(buffers[0]), D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT}; + invoke(device, 17, word(&view), cpu); + } else { + const UINT mapping = std::strcmp(input_mapping, "swapped") == 0 + ? D3D12_ENCODE_SHADER_4_COMPONENT_MAPPING(1, 0, 2, 3) + : D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; + D3D12_SHADER_RESOURCE_VIEW_DESC view{DXGI_FORMAT_R32_UINT, D3D12_SRV_DIMENSION_BUFFER, mapping}; + view.Buffer.NumElements = fields[0][0] * fields[0][1] / 4; + invoke(device, 18, word(placed[0]), word(&view), cpu); + } } void* other_heap = nullptr; if (change_table_heap && From c24ea5688225d89115e221eb59e035fdda564f1b Mon Sep 17 00:00:00 2001 From: JB2WIN Date: Fri, 27 Nov 2026 12:01:22 +0100 Subject: [PATCH 4/6] native: read single-channel typed buffers from GPU-selected heap slots (#3042) Accept the one-channel typed heap-view contract in the direct compute compiler and offline replay. Exercise typed slot selection, cache reuse, and malformed metadata refusals with source-built fixtures. Refs #3023. (cherry picked from commit a0f67731350072e43e64a89c0cf01ffb9fb565b0) --- .../native-global-srv-heap-replay.md | 32 +++++-- src/direct_compute_cache.cpp | 6 +- src/gfx1013_compute_native.h | 15 +++- src/gfx1013_direct_compute.inl | 24 ++++-- src/startup_stubs/native_global_srv.h | 52 +++++++++++- tests/native_global_srv_heap_replay.cpp | 62 ++++++++++---- tests/native_global_srv_heap_replay_check.py | 85 +++++++++++++++++++ tools/startup/compile_dxil.cpp | 11 ++- 8 files changed, 246 insertions(+), 41 deletions(-) diff --git a/docs/experiments/native-global-srv-heap-replay.md b/docs/experiments/native-global-srv-heap-replay.md index 2a726fe379..d6778f28a1 100644 --- a/docs/experiments/native-global-srv-heap-replay.md +++ b/docs/experiments/native-global-srv-heap-replay.md @@ -31,12 +31,13 @@ Issue #2908, branch `cpp-migration`. Builds on the heap read in the direct C++ D select need slot + dword (after the slot lines; typed buffers of 32-bit channels only, #3023) ``` - `compile_dxil ... gfx1013-container-cs` reads an optional `req_.views` next to the `.cdx` (single file and `--requests`). It decodes the file, refuses a selection whose slot holds another view type than `need`, refuses a `need` - other than `raw_buffer`, translates with the `raw_buffer` contract and prints `global_srv select= need=`. Every - refusal happens before the `.cso` is published. Without the file a heap-reading shader is refused as before. The + other than `raw_buffer` or a one-channel 32-bit `typed_buffer` (#3023), translates with the matching contract and + prints `global_srv select= need=`. Every refusal happens before the `.cso` is published. Without the file a heap-reading shader is refused as before. The `.views` file is not part of the `.cdx`/`.root` content key: it describes one captured dispatch. ## Meaning of "native recording" and "runtime path" here @@ -153,10 +154,31 @@ ctest --preset dev --no-tests=error -R "^native_global_srv_heap_replay(_warp|_ha the window binding as the same raw view). `native_direct_container` compiles both formats through a compute table window and refuses the window without the byte-count product. Against `837728dd` the heap check fails at the `twindow_loop` shape (text "non-contiguous resource descriptor"). +- Typed heap loads (#3023): under the new `HeapViewContract::typed_dword` a one-channel typed load + (`buffer_load_format_x`, an `idxen` element index) through the GPU-selected heap descriptor reads + `ResourceDescriptorHeap[slot]` as a typed buffer of one U32 component (binding kind `heap_typed_srv`, cache identity + `/heap-view/typed_dword`). `.views` gains a `dword ` line for each typed buffer slot of 32-bit + channels; `compile_dxil` and the fixture derive the contract from `need typed_buffer` when every captured typed + buffer slot is a one-channel 32-bit buffer (`x2w_startup::global_srv_contract`). `record` takes + `--need typed_buffer`. `native_global_srv_heap_replay_hardware` passes with 122 assertions: the typed load is + recorded for slot 3 (`R32_UINT`), compiled, compiled again from the frontend cache, and replayed (output equals the + slot 3 data); replaying it against slot 0 reports a mismatch; selections 0 and 2 are refused before the dispatch; + ten compile refusals cover a two-channel load, a raw load and a `tbuffer` load under the typed contract, the typed + load under the raw contract, and metadata without the `dword` line, with a channel count of 5, with a `dword` line for + a raw slot, a duplicate or an early `dword` line, or with another selection. On the local capture (counts only) all 906 typed heap loads behind the raw contract have this + one-channel `idxen` shape; with `typed_dword` forced by an uncommitted switch, 895 of those programs then stop at a + raw heap read of another slot: they read the heap both ways, which one captured selection does not cover. ## Limits -- Only raw buffer heap reads are translated; other view classes are refused with a named diagnostic. +- Only raw buffer heap reads (`raw_buffer`) and one-channel 32-bit typed buffer heap reads (`typed_dword`) are + translated, one class per program; other view classes are refused with a named diagnostic. +- Under `typed_dword` the translator sees no descriptor values. The caller guarantees that every selectable slot is an + `R32_UINT`, `R32_SINT` or `R32_FLOAT` buffer view bound as `R32_UINT` over the same element range, that the guest + descriptor has stride 4, a 32-bit data format, identity `dst_sel_x`, swizzle and `add_tid` disabled, and that its + `num_records` is the view's element count (reads past it return 0). `.views` records the resource size, not the + view's first element or element count, so `global_srv_contract` checks necessary conditions only. Only `R32_UINT` + slots are exercised; `R32_SINT` and `R32_FLOAT` are accepted but untested. No runtime binds a typed heap slot yet. - The selected slot's index is per-lane VGPR data in general; reads stay inside the raw buffer view, which returns 0 out of bounds. No static index bound is checked. - Replay regenerates the slot contents deterministically from the slot index; `.views` captures type, stride and size, @@ -175,8 +197,8 @@ ctest --preset dev --no-tests=error -R "^native_global_srv_heap_replay(_warp|_ha - `startup_compute_mtbuf_window_{hardware,warp}` compares 12 pairs and the surrounding guards through the published path for both a hardware descriptor and a buffer SRV token. A 44-byte window holds five full pairs. The partial pair and the later pairs read zero. Swapped X/Y selectors refuse before Dispatch, and the output keeps its sentinel. -- Typed loads (`buffer_load_format_*`) through a heap descriptor and scalar loads through the rewritten descriptor stay - refused. The startup runtime +- Multi-channel typed heap loads, typed loads under the raw contract and scalar loads through the rewritten descriptor + stay refused. The startup runtime does not pass a contract yet, so none of this reaches a title run (#3023). - The captured `select` must be the slot index the dispatch addresses; producing it from a title capture is outside this fixture. diff --git a/src/direct_compute_cache.cpp b/src/direct_compute_cache.cpp index c56df5a319..b779984592 100644 --- a/src/direct_compute_cache.cpp +++ b/src/direct_compute_cache.cpp @@ -135,7 +135,7 @@ NativeComputeShader decode(std::string_view bytes) { unsigned n = in.count(1000000); shader.bindings.reserve(n); for (unsigned j = 0; j < n; ++j) { - auto kind = static_cast(in.count(static_cast(ComputeViewKind::indexed_raw_srv))); + auto kind = static_cast(in.count(static_cast(ComputeViewKind::heap_typed_srv))); ComputeViewBinding b{kind, in.word(), in.word(), in.word(), in.word(), in.word(), in.word(), in.count(7)}; b.scalar_table = static_cast(in.count(unsigned(ComputeViewBinding::ScalarTable::srv))); b.requires_identity_dst_sel = in.count(1) != 0; @@ -372,7 +372,9 @@ NativeComputeShader prepare_direct_compute(const fs::path &input, unsigned entry Bytes identity = X2W_NATIVE_SHADER_REVISION "/container/cs_6_6"; word(identity, 0); if (heap_view != HeapViewContract::none) - identity += heap_view == HeapViewContract::raw_buffer ? "/heap-view/raw_buffer" : "/heap-view/other"; + identity += heap_view == HeapViewContract::raw_buffer ? "/heap-view/raw_buffer" + : heap_view == HeapViewContract::typed_dword ? "/heap-view/typed_dword" + : "/heap-view/other"; identity += shader_digest(packed.bytes) + shader_digest(packed.root); return cached_compute_ir(cache, shader_digest(identity), cache_hit, [&] { return translate_compute_container(std::move(packed), heap_view); }); diff --git a/src/gfx1013_compute_native.h b/src/gfx1013_compute_native.h index 63ca928239..06df7f930e 100644 --- a/src/gfx1013_compute_native.h +++ b/src/gfx1013_compute_native.h @@ -46,7 +46,8 @@ enum class ComputeViewKind { float2_texture_uav, float3_texture_uav, packed_d16_x_uav, // Single low-halfword payload; desktop buffer view determines the element size. - indexed_raw_srv // Fixed-stride record read. required_bytes is one complete record and its checked stride. + indexed_raw_srv, // Fixed-stride record read. required_bytes is one complete record and its checked stride. + heap_typed_srv // A one-channel 32-bit typed buffer read the same way (HeapViewContract::typed_dword). }; inline unsigned exact_texture_uav_channels(ComputeViewKind kind) { switch (kind) { @@ -63,7 +64,9 @@ inline constexpr unsigned compute_resource_heap = ~0u; // the directly indexed sampler heap; entry n is title byte offset 16 * n inline constexpr unsigned compute_sampler_heap = ~0u - 1; // A binding of the whole descriptor heap: it has no table register and no root parameter. -inline bool compute_heap_binding(ComputeViewKind kind) { return kind == ComputeViewKind::heap_buffer_srv; } +inline bool compute_heap_binding(ComputeViewKind kind) { + return kind == ComputeViewKind::heap_buffer_srv || kind == ComputeViewKind::heap_typed_srv; +} inline bool compute_buffer_uav(ComputeViewKind kind) { return kind == ComputeViewKind::raw_buffer_uav || kind == ComputeViewKind::typed_buffer_uav || kind == ComputeViewKind::half_buffer_uav || kind == ComputeViewKind::packed_d16_x_uav || @@ -152,7 +155,13 @@ struct NativeComputeShader { // every slot the program can select is a raw view whose size is the guest range num_records * max(stride, 1); the // translator does not check that, nor the swizzle bits (word 1 bits 31:30) or the other word 3 fields, and a program // with two heap loads from different selectors is outside what one captured selection covers. -enum class HeapViewContract : unsigned { none, raw_buffer, other }; +// typed_dword: only typed loads (buffer_load_format_x, an idxen element index or none, no offsets) read the heap; raw +// loads and byte windows are refused. The caller guarantees that every slot the program can select is a typed buffer SRV +// of R32_UINT, R32_SINT or R32_FLOAT (default mapping, no flags, no structure stride), bound as R32_UINT over the same +// resource and element range, and that the guest descriptor it stands for has stride 4, a 32-bit UINT/SINT/FLOAT data +// format, identity dst_sel_x, swizzle and add_tid disabled, and the out-of-bounds rule "index >= num_records reads 0", +// with num_records equal to the view's element count. The translator checks none of these values. +enum class HeapViewContract : unsigned { none, raw_buffer, typed_dword, other }; NativeComputeShader translate_compute(const ComputeRequest &request, unsigned entry_byte_offset, bool direct_dxil = false); NativeComputeShader translate_compute_container(ComputeContainer container, diff --git a/src/gfx1013_direct_compute.inl b/src/gfx1013_direct_compute.inl index fec2733638..9ea780d948 100644 --- a/src/gfx1013_direct_compute.inl +++ b/src/gfx1013_direct_compute.inl @@ -338,7 +338,7 @@ struct DirectCompute { entry.second = ir.binary("and",word_at(pos++),"16383"); } } - // Refuses a GPU-selected heap read that the contract does not cover. raw_buffer is the only class that is translated. + // Refuses a GPU-selected heap read that the contract does not cover. raw_buffer and typed_dword are translated. void refuse_heap_contract(unsigned pc) const { if (heap_view == HeapViewContract::none) refuse(pc, "direct resource-heap load requires the selected GPU slot and its view type"); @@ -350,11 +350,18 @@ struct DirectCompute { // dispatch before the shader runs. The binding names the heap (no table register); the pipeline indexes it directly. // A byte window is the byte-address rewrite of that descriptor (word 0 copied, word 1 without stride, word 2 the // byte count, word 3 with the raw out-of-bounds mode; see byte_descriptor_field): read as the same raw slot view. + // Under typed_dword the slot is a one-channel 32-bit typed buffer instead: a typed load of one channel (an element + // index), read as R32_UINT; raw reads and byte windows are refused. string heap_resource(const Inst &i, const State &s, unsigned base, ComputeViewKind kind, unsigned bytes) { const auto &symbol = s.at(base); refuse_heap_contract(i.pc); + const bool typed = heap_view == HeapViewContract::typed_dword; + if (typed && kind != ComputeViewKind::typed_buffer_srv) + refuse(i.pc, "a GPU-selected heap slot is read as a typed dword buffer SRV only"); + if (typed && (i.op & 3)) + refuse(i.pc, "typed heap load reads one channel only"); const bool window = kind == ComputeViewKind::byte_window_srv; - if (kind != ComputeViewKind::raw_vector_srv && kind != ComputeViewKind::buffer_srv && !window) + if (!typed && kind != ComputeViewKind::raw_vector_srv && kind != ComputeViewKind::buffer_srv && !window) refuse(i.pc, "a GPU-selected heap slot is read as a raw buffer SRV only"); if (symbol.offset % 32 || s[base].type != Symbol::Type::indexed_descriptor) refuse(i.pc, "unaligned heap descriptor"); @@ -377,13 +384,20 @@ struct DirectCompute { refuse(i.pc, "non-contiguous resource descriptor"); } auto &bindings = analysis.result.bindings; - auto it = std::find_if(bindings.begin(), bindings.end(), [](const auto &b) { - return b.kind == ComputeViewKind::heap_buffer_srv; + const auto heap_kind = typed ? ComputeViewKind::heap_typed_srv : ComputeViewKind::heap_buffer_srv; + auto it = std::find_if(bindings.begin(), bindings.end(), [heap_kind](const auto &b) { + return b.kind == heap_kind; }); if (it == bindings.end()) - bindings.push_back({ComputeViewKind::heap_buffer_srv, compute_resource_heap, 0, 0, bytes}); + bindings.push_back({heap_kind, compute_resource_heap, 0, 0, bytes}); else it->required_bytes = (std::max)(it->required_bytes, bytes); + if (typed) { + // A typed buffer of one U32 component (TypedBuffer, props: component type 5 + count * 256); the load reads + // element 0 of its ResRet only. No raw-buffer flag. + ir.features |= 0x40000000; + return ir.heap_handle(ir.binary("add", read(base), to_string(symbol.offset / 32)), 10, 5 + 1 * 256); + } // 16: raw buffers. 0x40000000: the module reads ResourceDescriptorHeap (DXC sets both for the HLSL reference, // see tests/native_heap_handle_probe_check.py); the validator refuses a module whose flags do not match. ir.features |= 16 | 0x40000000; diff --git a/src/startup_stubs/native_global_srv.h b/src/startup_stubs/native_global_srv.h index 0ea0f62d9a..10104b1996 100644 --- a/src/startup_stubs/native_global_srv.h +++ b/src/startup_stubs/native_global_srv.h @@ -12,9 +12,10 @@ // The view type of a global (descriptor heap) SRV slot that a dispatch can select from GPU data. // // A shader that picks its slot at run time can only be recorded and replayed if the type of every slot it may pick is -// known: the capture keeps {slot, type, stride} for each slot of the heap, and the dispatch is refused, before any -// shader runs, when the selected slot holds another type than the one the shader reads. No heap-indexed data read is -// translated here; this header only classifies, serializes and checks. +// known: the capture keeps {slot, type, stride, bytes} for each slot of the heap (and the 32-bit channel count of a +// typed buffer slot), and the dispatch is refused, before any shader runs, when the selected slot holds another type +// than the one the shader reads. No heap-indexed data read is translated here; this header only classifies, +// serializes and checks, and names the heap view contract a request allows (global_srv_contract). // // A .views file describes the one dispatch it was captured from. It is not part of the .cdx/.root content key of the // request it sits next to. @@ -43,6 +44,7 @@ struct GlobalSrvView { GlobalSrvType type = GlobalSrvType::none; unsigned stride = 0; // Bytes per element for a buffer view (the value native_view_stride gives), 0 for a texture. std::uint64_t bytes = 0; // Size of the buffer in bytes, 0 for a texture. Set by the caller from the resource description. + unsigned dword_channels = 0; // Typed buffer of 32-bit channels: their count (typed_dword_channels), else 0. }; // Classifies the description a title passed for an SRV (slot 18 of the device interface). False: not a view this @@ -62,6 +64,7 @@ inline bool classify_global_srv_view(unsigned heap_slot, const void *bytes, std: view.type = desc.Buffer.StructureByteStride ? GlobalSrvType::structured_buffer : (desc.Buffer.Flags & D3D12_BUFFER_SRV_FLAG_RAW) ? GlobalSrvType::raw_buffer : GlobalSrvType::typed_buffer; + if (view.type == GlobalSrvType::typed_buffer) view.dword_channels = typed_dword_channels(desc); return true; } @@ -78,6 +81,10 @@ inline std::string encode_global_srv_request(const GlobalSrvRequest &request) { out << "x2w-global-srv-views 2\nselect " << request.selected << "\nneed " << global_srv_type_name(request.needed) << '\n'; for (const auto &view : request.views) out << "slot " << view.slot << ' ' << global_srv_type_name(view.type) << ' ' << view.stride << ' ' << view.bytes << '\n'; + // After the slot lines: the 32-bit channel count of each typed buffer slot that has one. + for (const auto &view : request.views) + if (view.type == GlobalSrvType::typed_buffer && view.dword_channels) + out << "dword " << view.slot << ' ' << view.dword_channels << '\n'; return out.str(); } @@ -121,6 +128,19 @@ inline bool decode_global_srv_request(const std::string &text, GlobalSrvRequest return false; } request.views.push_back(view); + } else if (key == "dword") { + // Names an earlier typed buffer slot line, once, with 1-4 channels. + unsigned slot = 0, channels = 0; + GlobalSrvView *named = nullptr; + if (fields >> slot >> channels) + for (auto &view : request.views) + if (view.slot == slot) named = &view; + if (!named || named->type != GlobalSrvType::typed_buffer || named->dword_channels || channels < 1 || + channels > 4) { + error = "global SRV view metadata: unreadable dword line"; + return false; + } + named->dword_channels = channels; } else { error = "global SRV view metadata: unknown line '" + key + "'"; return false; @@ -145,4 +165,30 @@ inline std::string refuse_global_srv_selection(const std::vector } return "global SRV slot " + std::to_string(selected) + " has no captured view type"; } + +// The class of heap reads a request's metadata lets the translator emit (x2w::HeapViewContract::none, raw_buffer, +// typed_dword). Call after refuse_global_srv_selection accepted the selection. A typed request needs one-channel 32-bit +// typed buffers: the checks are necessary conditions on the captured resources only; the view's element range and the +// guest descriptor fields stay the caller's guarantee. +enum class GlobalSrvContract { none, raw_buffer, typed_dword }; + +inline GlobalSrvContract global_srv_contract(const GlobalSrvRequest &request, std::string &error) { + const auto refuse = [&error](std::string text) { + error = std::move(text) + "; only raw and one-channel 32-bit typed heap reads are translated"; + return GlobalSrvContract::none; + }; + if (request.needed == GlobalSrvType::raw_buffer) return GlobalSrvContract::raw_buffer; + if (request.needed != GlobalSrvType::typed_buffer) + return refuse(std::string("GPU-selected heap slot view type ") + global_srv_type_name(request.needed) + + " is not raw_buffer or typed_buffer"); + // Every captured typed buffer slot, the selected one included, must be a one-channel 32-bit buffer. + for (const auto &view : request.views) { + if (view.type != GlobalSrvType::typed_buffer) continue; + if (view.dword_channels != 1 || view.stride != 4 || !view.bytes || view.bytes % 4) + return refuse("GPU-selected heap slot " + std::to_string(view.slot) + + " is not a one-channel 32-bit typed buffer" + + (view.dword_channels ? "" : " (no 32-bit channel metadata)")); + } + return GlobalSrvContract::typed_dword; +} } // namespace x2w_startup diff --git a/tests/native_global_srv_heap_replay.cpp b/tests/native_global_srv_heap_replay.cpp index fb26837747..aefe2e8cf3 100644 --- a/tests/native_global_srv_heap_replay.cpp +++ b/tests/native_global_srv_heap_replay.cpp @@ -337,23 +337,42 @@ void check_pipeline_shape(const x2w::NativeComputePipeline &pipeline) { throw std::runtime_error("native pipeline has an unexpected binding layout"); } +// The pipeline contract a request's metadata allows; empty error when it is translated. +x2w::HeapViewContract heap_contract(const x2w_startup::GlobalSrvRequest &request, std::string &error) { + const auto contract = x2w_startup::global_srv_contract(request, error); + return contract == x2w_startup::GlobalSrvContract::typed_dword ? x2w::HeapViewContract::typed_dword + : x2w::HeapViewContract::raw_buffer; +} + int record(int argc, wchar_t **argv) { - if (argc != 8 && argc != 9) return 2; + if (argc < 8 || argc > 11) return 2; const std::wstring expect = argv[7]; - const bool guard = !(argc == 9 && std::wstring_view(argv[8]) == L"--no-guard"); - if ((argc == 9 && guard) || (expect != L"ok" && expect != L"refused")) return 2; + bool guard = true, need_given = false; + GlobalSrvType needed = GlobalSrvType::raw_buffer; + for (int a = 8; a < argc; ++a) { + const std::wstring_view flag = argv[a]; + if (flag == L"--no-guard" && guard) { + guard = false; + } else if (flag == L"--need" && a + 1 < argc && !need_given) { + need_given = true; + std::string name; // a view type name: ASCII, anything else names no type + for (const wchar_t c : std::wstring_view(argv[++a])) name += c < 0x80 ? static_cast(c) : '?'; + needed = x2w_startup::global_srv_type_from_name(name); + if (needed == GlobalSrvType::none) return 2; + } else { + return 2; + } + } + if (expect != L"ok" && expect != L"refused") return 2; const unsigned selector = static_cast(std::stoul(argv[6])); const fs::path cdx = argv[4]; Rig rig; if (int skip = rig.open(argv[5])) return skip; try { x2w::ShaderDxilCompiler compiler(argv[2]); - auto pipeline = x2w::create_native_compute_pipeline(rig.device.Get(), compiler, cdx, 0, argv[3], true, - x2w::HeapViewContract::raw_buffer); - check_pipeline_shape(pipeline); rig.create_io(); x2w_startup::GlobalSrvRequest request; - request.needed = GlobalSrvType::raw_buffer; + request.needed = needed; request.views.push_back(rig.add_slot(0, GlobalSrvType::raw_buffer, slot_words * 4)); request.views.push_back(rig.add_slot(1, GlobalSrvType::raw_buffer, slot_words * 4)); request.views.push_back(rig.add_slot(2, GlobalSrvType::texture, 0)); @@ -365,14 +384,25 @@ int record(int argc, wchar_t **argv) { auto views_path = cdx; views_path.replace_extension(L".views"); std::ofstream(views_path, std::ios::binary) << x2w_startup::encode_global_srv_request(request); - std::printf("captured select=%u need=raw_buffer views=%s\n", request.selected, views_path.string().c_str()); + std::printf("captured select=%u need=%s views=%s\n", request.selected, + x2w_startup::global_srv_type_name(request.needed), views_path.string().c_str()); + // The contract depends on the captured views, not on the selection: the shader is translated for every record, + // a refused selection included. + std::string error; + const auto contract = heap_contract(request, error); + if (!error.empty()) { + std::printf("refused: %s\n", error.c_str()); + return refused_path(rig, expect == L"ok"); + } + auto pipeline = x2w::create_native_compute_pipeline(rig.device.Get(), compiler, cdx, 0, argv[3], true, contract); + check_pipeline_shape(pipeline); const auto diagnostic = x2w_startup::refuse_global_srv_selection(request.views, request.selected, request.needed); if (!diagnostic.empty() && guard) { std::printf("refused select=%u: %s\n", request.selected, diagnostic.c_str()); return refused_path(rig, expect == L"ok"); } - if (request.selected >= slot_count || request.views[request.selected].type != GlobalSrvType::raw_buffer) - throw std::runtime_error("--no-guard only dispatches a raw buffer slot"); + if (request.selected >= slot_count || request.views[request.selected].type != request.needed) + throw std::runtime_error("--no-guard only dispatches a slot of the needed view type"); rig.dispatch(pipeline, nullptr, rig.slots[request.selected].Get()); if (expect == L"refused") { // Discrimination control: without the guard the shader ran, so the output must have changed. @@ -410,16 +440,14 @@ int replay(int argc, wchar_t **argv) { } if (error.empty()) error = x2w_startup::refuse_global_srv_selection(request.views, request.selected, request.needed); - if (error.empty() && request.needed != GlobalSrvType::raw_buffer) - error = std::string("GPU-selected heap slot view type ") + x2w_startup::global_srv_type_name(request.needed) + - " is not raw_buffer; only raw buffer heap reads are translated"; + auto contract = x2w::HeapViewContract::raw_buffer; + if (error.empty()) contract = heap_contract(request, error); if (!error.empty()) { std::printf("refused: %s\n", error.c_str()); return refused_path(rig, expect == L"ok"); } x2w::ShaderDxilCompiler compiler(argv[2]); - auto pipeline = x2w::create_native_compute_pipeline(rig.device.Get(), compiler, cdx, 0, argv[3], true, - x2w::HeapViewContract::raw_buffer); + auto pipeline = x2w::create_native_compute_pipeline(rig.device.Get(), compiler, cdx, 0, argv[3], true, contract); check_pipeline_shape(pipeline); std::ifstream shader(cso, std::ios::binary); if (!shader) throw std::runtime_error("missing compiled shader " + cso.string()); @@ -455,7 +483,7 @@ int wmain(int argc, wchar_t **argv) { return 4; } std::fputs("usage: native_global_srv_heap_replay root OUT.root | record SDK CACHE REQ.cdx ADAPTER SELECTOR ok|refused " - "[--no-guard] | replay SDK CACHE REQ.cdx COMPILED.cso VIEWS ADAPTER ok|refused REFERENCE_SLOT " - "[EXPECTED_WORDS]\n", stderr); + "[--no-guard] [--need raw_buffer|typed_buffer] | replay SDK CACHE REQ.cdx COMPILED.cso VIEWS ADAPTER " + "ok|refused REFERENCE_SLOT [EXPECTED_WORDS]\n", stderr); return 2; } diff --git a/tests/native_global_srv_heap_replay_check.py b/tests/native_global_srv_heap_replay_check.py index adade303b3..e99049be39 100644 --- a/tests/native_global_srv_heap_replay_check.py +++ b/tests/native_global_srv_heap_replay_check.py @@ -469,4 +469,89 @@ def added(lo=ADD_LO, between=(), hi=ADD_HI, load_words=ADDED_LOAD): require(code == 1 and expected in err and not any(out_dir.glob("*.cso")), f"compile_dxil shape '{name}': refused with '{expected}'") + # 12. Typed heap load (HeapViewContract::typed_dword): buffer_load_format_x v2, v0, s[20:23], 0 idxen reads element + # `lane` of the selected slot, a one-channel 32-bit typed buffer (slot 3, R32_UINT), so u0 equals the slot 3 data. + TYPED_RAW = "global SRV slot {n} has view type {t}, the shader needs typed_buffer" + TYPED_ONLY = "a GPU-selected heap slot is read as a typed dword buffer SRV only" + + def typed_program(load_words): + program = list(words_list) + program[load:load + 2] = load_words + return program + + TYPED = typed_program((0xe0002000, 0x80050200)) # buffer_load_format_x v2, v0, s[20:23], 0 idxen + + def typed_dir(name, program=TYPED): + directory = base / name + directory.mkdir() + cdx_bytes = compute_two_inputs(words(*program)) + typed_stem = "req_%016x" % key_of(root, cdx_bytes) + (directory / (typed_stem + ".cdx")).write_bytes(cdx_bytes) + (directory / (typed_stem + ".root")).write_bytes(root) + return directory, typed_stem + + def typed_compile(directory, typed_stem, out_name): + out_dir = base / out_name + code, out, err = run([compile_dxil, sdk, cache, "gfx1013-container-cs", "--requests", directory, out_dir]) + return code, out, err, out_dir / (typed_stem[len("req_"):] + ".cs.cso") + + typed_selection = {} + for n in (3, 0, 2): + directory, typed_stem = typed_dir(f"typed{n}") + typed_selection[n] = (directory, typed_stem) + expect = "ok" if n == 3 else "refused" + code, out, err = run([fixture, "record", sdk, cache, directory / (typed_stem + ".cdx"), adapter, n, expect, + "--need", "typed_buffer"]) + if n == 3: + require(code == 0 and "output matches slot 3 data" in out, + "record typed select 3: u0 equals the slot 3 data read by the typed heap load") + text = (directory / (typed_stem + ".views")).read_text() + require(text.startswith("x2w-global-srv-views 2\nselect 3\nneed typed_buffer\n") and "dword 3 1\n" in text, + "record typed select 3 captured need typed_buffer and the slot 3 channel count") + else: + type_name = "raw_buffer" if n == 0 else "texture" + require(code == 0 and TYPED_RAW.format(n=n, t=type_name) in out and "no dispatch submitted" in out and + "sentinels intact" in out, f"record typed select {n}: refused before the dispatch") + directory, typed_stem = typed_selection[3] + typed_views = (directory / (typed_stem + ".views")).read_text() + code, out, err, typed_cso = typed_compile(directory, typed_stem, "typed3_out") + require(code == 0 and "requests=1 compiled=1 refused=0" in out and "global_srv select=3 need=typed_buffer" in out and + typed_cso.exists(), "compile_dxil typed select 3: compiled and published a .cso") + code, out, err, again = typed_compile(directory, typed_stem, "typed3_again") + require(code == 0 and "frontend_cache_hit=1" in out and again.read_bytes() == typed_cso.read_bytes(), + "compile_dxil typed select 3 again: frontend cache hit (the typed heap binding decodes), same .cso") + views_path = directory / (typed_stem + ".views") + code, out, err = run([fixture, "replay", sdk, cache, directory / (typed_stem + ".cdx"), typed_cso, views_path, + adapter, "ok", 3]) + require(code == 0 and "output matches slot 3 data" in out, "replay typed select 3: output equals slot 3 data") + code, out, err = run([fixture, "replay", sdk, cache, directory / (typed_stem + ".cdx"), typed_cso, views_path, + adapter, "ok", 0]) + require(code == 1 and "mismatch word 0" in out, "replay typed select 3 compared with slot 0 data reports a mismatch") + + # Refused shapes and metadata, compile_dxil, no .cso. + typed_negatives = { + # buffer_load_format_xy v[2:3], v0, s[20:23], 0 idxen + "typed_xy": (typed_program((0xe0042000, 0x80050200)), typed_views, "typed heap load reads one channel only"), + "typed_raw_program": (list(words_list), typed_views, TYPED_ONLY), + # tbuffer_load_format_x v2, v1, s[20:23], 0 format:[BUF_FMT_32_UINT] offen through the heap descriptor + "typed_tbuffer": (typed_program((0xe8a01000, 0x80050201)), typed_views, TYPED_ONLY), + "typed_raw_views": (TYPED, good, "a GPU-selected heap slot is read as a raw buffer SRV only"), + "typed_no_dword": (TYPED, typed_views.replace("dword 3 1\n", ""), + "GPU-selected heap slot 3 is not a one-channel 32-bit typed buffer (no 32-bit channel metadata)"), + "typed_select_0": (TYPED, typed_views.replace("select 3", "select 0"), TYPED_RAW.format(n=0, t="raw_buffer")), + "typed_dword_5": (TYPED, typed_views.replace("dword 3 1", "dword 3 5"), + "global SRV view metadata: unreadable dword line"), + "typed_dword_raw_slot": (TYPED, typed_views.replace("dword 3 1", "dword 0 1"), + "global SRV view metadata: unreadable dword line"), + "typed_dword_twice": (TYPED, typed_views + "dword 3 1\n", "global SRV view metadata: unreadable dword line"), + "typed_dword_first": (TYPED, typed_views.replace("dword 3 1\n", "").replace("need typed_buffer\n", + "need typed_buffer\ndword 3 1\n"), "global SRV view metadata: unreadable dword line"), + } + for name, (program, views_text, expected) in typed_negatives.items(): + directory, typed_stem = typed_dir("neg_" + name, program) + (directory / (typed_stem + ".views")).write_text(views_text, newline="\n") + code, out, err, cso = typed_compile(directory, typed_stem, "neg_" + name + "_out") + require(code == 1 and expected in err, f"compile_dxil '{name}': refused with '{expected}'") + require(not any(cso.parent.glob("*.cso")), f"compile_dxil '{name}': no .cso") + print("native_global_srv_heap_replay: all checks passed") diff --git a/tools/startup/compile_dxil.cpp b/tools/startup/compile_dxil.cpp index 7728f227e6..3d4b210b7e 100644 --- a/tools/startup/compile_dxil.cpp +++ b/tools/startup/compile_dxil.cpp @@ -76,11 +76,10 @@ static CapturedViews read_captured_views(const fs::path& request_path) { const auto& request = views.request; auto refusal = x2w_startup::refuse_global_srv_selection(request.views, request.selected, request.needed); if (!refusal.empty()) throw std::runtime_error(refusal); - if (request.needed != x2w_startup::GlobalSrvType::raw_buffer) - throw std::runtime_error(std::string("GPU-selected heap slot view type ") + - x2w_startup::global_srv_type_name(request.needed) + - " is not raw_buffer; only raw buffer heap reads are translated"); - views.contract = x2w::HeapViewContract::raw_buffer; + const auto contract = x2w_startup::global_srv_contract(request, error); + if (contract == x2w_startup::GlobalSrvContract::none) throw std::runtime_error(error); + views.contract = contract == x2w_startup::GlobalSrvContract::typed_dword ? x2w::HeapViewContract::typed_dword + : x2w::HeapViewContract::raw_buffer; return views; } @@ -143,7 +142,7 @@ static std::optional compile_one(x2w::ShaderDxilCompiler& compiler, } if(views.present){ const bool heap_read=std::any_of(program.bindings.begin(),program.bindings.end(),[](const auto& b){ - return b.kind==x2w::ComputeViewKind::heap_buffer_srv || b.kind==x2w::ComputeViewKind::heap_stride_srv;}); + return x2w::compute_heap_binding(b.kind) || b.kind==x2w::ComputeViewKind::heap_stride_srv;}); if(heap_read){ auto refusal=x2w_startup::refuse_global_srv_selection(views.request.views,views.request.selected,views.request.needed); if(!refusal.empty())throw std::runtime_error(refusal); From d4d9af41184f62915e57119e98b0c2d61549608e Mon Sep 17 00:00:00 2001 From: JB2WIN Date: Sat, 28 Nov 2026 23:50:35 +0100 Subject: [PATCH 5/6] tests: pin the typed heap load offset refusals; fix the heap replay doc The typed heap load reads the idxen element index only. offen, an immediate offset and a nonzero soffset are already refused by the decoder ("formatted load requires zero or a single linear index"); three negative cases pin that. The doc now lists the typed_dword contract and the current assertion count. Co-Authored-By: Claude Opus 5.5 --- docs/experiments/native-global-srv-heap-replay.md | 9 +++++---- tests/native_global_srv_heap_replay_check.py | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/experiments/native-global-srv-heap-replay.md b/docs/experiments/native-global-srv-heap-replay.md index d6778f28a1..7179bca2c0 100644 --- a/docs/experiments/native-global-srv-heap-replay.md +++ b/docs/experiments/native-global-srv-heap-replay.md @@ -6,8 +6,8 @@ Issue #2908, branch `cpp-migration`. Builds on the heap read in the direct C++ D ## What changed - The direct compute translation takes a view contract for a GPU-selected heap slot (`x2w::HeapViewContract`: - `none`, `raw_buffer`, `other`). An SMEM descriptor load from the resource heap is refused unless the contract is - `raw_buffer`; without a contract the existing text stays: "direct resource-heap load requires the selected GPU slot and + `none`, `raw_buffer`, `typed_dword`, `other`). An SMEM descriptor load from the resource heap is refused unless the + contract is `raw_buffer` or `typed_dword`; without a contract the existing text stays: "direct resource-heap load requires the selected GPU slot and its view type". A scalar buffer load from the heap base, a heap descriptor load with an immediate offset or a constant index (both could address another slot than the captured selection), and a numeric use of a GPU-selected slot's stride in the direct path are refused with their own texts. The contract is part of the frontend cache key when it is @@ -160,10 +160,11 @@ ctest --preset dev --no-tests=error -R "^native_global_srv_heap_replay(_warp|_ha `/heap-view/typed_dword`). `.views` gains a `dword ` line for each typed buffer slot of 32-bit channels; `compile_dxil` and the fixture derive the contract from `need typed_buffer` when every captured typed buffer slot is a one-channel 32-bit buffer (`x2w_startup::global_srv_contract`). `record` takes - `--need typed_buffer`. `native_global_srv_heap_replay_hardware` passes with 122 assertions: the typed load is + `--need typed_buffer`. `native_global_srv_heap_replay_hardware` passes with 160 assertions: the typed load is recorded for slot 3 (`R32_UINT`), compiled, compiled again from the frontend cache, and replayed (output equals the slot 3 data); replaying it against slot 0 reports a mismatch; selections 0 and 2 are refused before the dispatch; - ten compile refusals cover a two-channel load, a raw load and a `tbuffer` load under the typed contract, the typed + thirteen compile refusals cover a two-channel load, an element index with `offen`, an immediate offset or a + nonzero `soffset` (refused by the decoder before the heap read), a raw load and a `tbuffer` load under the typed contract, the typed load under the raw contract, and metadata without the `dword` line, with a channel count of 5, with a `dword` line for a raw slot, a duplicate or an early `dword` line, or with another selection. On the local capture (counts only) all 906 typed heap loads behind the raw contract have this one-channel `idxen` shape; with `typed_dword` forced by an uncommitted switch, 895 of those programs then stop at a diff --git a/tests/native_global_srv_heap_replay_check.py b/tests/native_global_srv_heap_replay_check.py index e99049be39..d3608fc1cb 100644 --- a/tests/native_global_srv_heap_replay_check.py +++ b/tests/native_global_srv_heap_replay_check.py @@ -473,6 +473,7 @@ def added(lo=ADD_LO, between=(), hi=ADD_HI, load_words=ADDED_LOAD): # `lane` of the selected slot, a one-channel 32-bit typed buffer (slot 3, R32_UINT), so u0 equals the slot 3 data. TYPED_RAW = "global SRV slot {n} has view type {t}, the shader needs typed_buffer" TYPED_ONLY = "a GPU-selected heap slot is read as a typed dword buffer SRV only" + TYPED_OFFSETS = "formatted load requires zero or a single linear index" def typed_program(load_words): program = list(words_list) @@ -533,6 +534,11 @@ def typed_compile(directory, typed_stem, out_name): # buffer_load_format_xy v[2:3], v0, s[20:23], 0 idxen "typed_xy": (typed_program((0xe0042000, 0x80050200)), typed_views, "typed heap load reads one channel only"), "typed_raw_program": (list(words_list), typed_views, TYPED_ONLY), + # buffer_load_format_x with idxen plus offen, an immediate offset of 4, or soffset inline 1: the typed address is + # the element index only, and the decoder refuses every offset form before the heap read is lowered. + "typed_offen": (typed_program((0xe0003000, 0x80050200)), typed_views, TYPED_OFFSETS), + "typed_imm_offset": (typed_program((0xe0002004, 0x80050200)), typed_views, TYPED_OFFSETS), + "typed_soffset": (typed_program((0xe0002000, 0x81050200)), typed_views, TYPED_OFFSETS), # tbuffer_load_format_x v2, v1, s[20:23], 0 format:[BUF_FMT_32_UINT] offen through the heap descriptor "typed_tbuffer": (typed_program((0xe8a01000, 0x80050201)), typed_views, TYPED_ONLY), "typed_raw_views": (TYPED, good, "a GPU-selected heap slot is read as a raw buffer SRV only"), From 30de88b6821bd0ec3004163f8433415608864206 Mon Sep 17 00:00:00 2001 From: JB2WIN Date: Sun, 29 Nov 2026 03:08:30 +0100 Subject: [PATCH 6/6] runtime: keep the MTBUF identity check on the in-process route; pin the contract checks Review of #3409 (Leyukaka): - translate_compute_natively pushed a byte-window slot without requires_identity_dst_sel, so with X2W_NATIVE_SHADERS a swapped DST_SEL, a non-default slot 18 mapping or a slot 17 CBV token bound without the check. The slot now carries the flag. startup_compute_mtbuf_window runs the identity and swapped cases on the in-process route too; without the fix the swapped case writes the output. - A Z/W swap with identity X/Y is refused too (catches a check of the low DST_SEL fields only). - global_srv_contract: a two-channel dword line, stride 8, an odd byte count and a zero byte count each refuse on their own. - Doc: the in-process sentence now says what the code does. Co-Authored-By: Claude Opus 5.5 --- .../experiments/native-global-srv-heap-replay.md | 3 ++- src/startup_stubs/d3d12_compute_dispatch.inl | 2 ++ tests/native_global_srv_heap_replay_check.py | 9 +++++++++ tests/startup_compute_mtbuf_window_check.py | 16 +++++++++++++++- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/docs/experiments/native-global-srv-heap-replay.md b/docs/experiments/native-global-srv-heap-replay.md index 7179bca2c0..5ad5d7a6c2 100644 --- a/docs/experiments/native-global-srv-heap-replay.md +++ b/docs/experiments/native-global-srv-heap-replay.md @@ -194,7 +194,8 @@ ctest --preset dev --no-tests=error -R "^native_global_srv_heap_replay(_warp|_ha A published table manifest marks the MTBUF window with `srv buf table identity_dst_sel`, including after a frontend cache hit. The compute binder checks word 3's DST_SEL of the hardware descriptor or the component mapping of a slot 18 buffer SRV before binding the raw view for the exact range. The in-process - path falls through to that manifest for a byte window. + route (`X2W_NATIVE_SHADERS`, `translate_compute_natively`) binds the byte window itself and carries the same + identity requirement into its slot, so the same checks run before its dispatch. - `startup_compute_mtbuf_window_{hardware,warp}` compares 12 pairs and the surrounding guards through the published path for both a hardware descriptor and a buffer SRV token. A 44-byte window holds five full pairs. The partial pair and the later pairs read zero. Swapped X/Y selectors refuse before Dispatch, and the output keeps its sentinel. diff --git a/src/startup_stubs/d3d12_compute_dispatch.inl b/src/startup_stubs/d3d12_compute_dispatch.inl index 8e35c20e91..a6d097401d 100644 --- a/src/startup_stubs/d3d12_compute_dispatch.inl +++ b/src/startup_stubs/d3d12_compute_dispatch.inl @@ -354,6 +354,8 @@ bool translate_compute_natively(ComputeTranslation& tr) if (volume) slots.back().uav_dimension = D3D12_UAV_DIMENSION_TEXTURE3D; slots.back().half_typed_bytes = half_typed ? view.required_bytes : 0; slots.back().packed_d16_x = packed_x; + // An MTBUF byte window needs identity channel order, as on the published route (identity_dst_sel). + slots.back().requires_identity_dst_sel = view.requires_identity_dst_sel; if (x2w::accepts_cbv_window(view.kind)) slots.back().scalar_window = view.required_bytes; if (channels) { diff --git a/tests/native_global_srv_heap_replay_check.py b/tests/native_global_srv_heap_replay_check.py index d3608fc1cb..18c8d8a832 100644 --- a/tests/native_global_srv_heap_replay_check.py +++ b/tests/native_global_srv_heap_replay_check.py @@ -11,6 +11,7 @@ capability skip. """ import pathlib +import re import shutil import struct import subprocess @@ -474,6 +475,7 @@ def added(lo=ADD_LO, between=(), hi=ADD_HI, load_words=ADDED_LOAD): TYPED_RAW = "global SRV slot {n} has view type {t}, the shader needs typed_buffer" TYPED_ONLY = "a GPU-selected heap slot is read as a typed dword buffer SRV only" TYPED_OFFSETS = "formatted load requires zero or a single linear index" + TYPED_NOT_DWORD = "GPU-selected heap slot 3 is not a one-channel 32-bit typed buffer" def typed_program(load_words): program = list(words_list) @@ -550,6 +552,13 @@ def typed_compile(directory, typed_stem, out_name): "typed_dword_raw_slot": (TYPED, typed_views.replace("dword 3 1", "dword 0 1"), "global SRV view metadata: unreadable dword line"), "typed_dword_twice": (TYPED, typed_views + "dword 3 1\n", "global SRV view metadata: unreadable dword line"), + # global_srv_contract: each of channels 1, stride 4 and a whole-dword nonzero size is required on its own. + "typed_dword_2": (TYPED, typed_views.replace("dword 3 1", "dword 3 2"), TYPED_NOT_DWORD), + "typed_stride_8": (TYPED, re.sub(r"(?m)^slot 3 typed_buffer 4 ", "slot 3 typed_buffer 8 ", typed_views), + TYPED_NOT_DWORD), + "typed_bytes_odd": (TYPED, re.sub(r"(?m)^(slot 3 typed_buffer 4 )(\d+)$", lambda m: m[1] + str(int(m[2]) + 2), + typed_views), TYPED_NOT_DWORD), + "typed_bytes_zero": (TYPED, re.sub(r"(?m)^(slot 3 typed_buffer 4 )\d+$", r"\g<1>0", typed_views), TYPED_NOT_DWORD), "typed_dword_first": (TYPED, typed_views.replace("dword 3 1\n", "").replace("need typed_buffer\n", "need typed_buffer\ndword 3 1\n"), "global SRV view metadata: unreadable dword line"), } diff --git a/tests/startup_compute_mtbuf_window_check.py b/tests/startup_compute_mtbuf_window_check.py index 717c26588b..1403d5b45f 100644 --- a/tests/startup_compute_mtbuf_window_check.py +++ b/tests/startup_compute_mtbuf_window_check.py @@ -18,6 +18,7 @@ STATE = state_a((32, 1, 1), USER7 | TGID_X | TGID_Y | TGID_Z) IDENTITY = 0x0103efac SWAPPED_XY = 0x0103efa5 +SWAPPED_ZW = 0x0103edec # X and Y stay identity: a check of the low DST_SEL fields alone would accept it EXPECTED = INPUT[:10] + [0] * 14 + [SENTINEL] * (WORDS - 24) GUARDS = [SENTINEL] * WORDS VIEW = 'srv 0 buf table 1 0 identity_dst_sel' @@ -108,6 +109,18 @@ def main(cli, consumer, renderer, sdk, adapter): compare(got, GUARDS, result) refusal = 'Dispatch(3, 2, 2) refused: an MTBUF byte window requires identity DST_SEL' assert len(lines(result, refusal)) == 1, result.stderr[-3000:] + got, result = run(work, consumer, env, SWAPPED_ZW) + compare(got, GUARDS, result) + assert len(lines(result, refusal)) == 1, result.stderr[-3000:] + # The in-process route (X2W_NATIVE_SHADERS) translates the request itself and is tried before the published + # manifest: it must carry the same identity requirement. + native = dict(env, X2W_NATIVE_SHADERS=str(sdk), X2W_NATIVE_SHADERS_ONLY='1') + got, result = run(work, consumer, native, IDENTITY) + compare(got, EXPECTED, result) + assert not lines(result, 'refused: '), result.stderr[-3000:] + got, result = run(work, consumer, native, SWAPPED_XY) + compare(got, GUARDS, result) + assert len(lines(result, refusal)) == 1, result.stderr[-3000:] got, result = run(work, consumer, env, IDENTITY, mapping='identity') compare(got, EXPECTED, result) assert len(lines(result, 'Dispatch(3, 2, 2) translated')) == 1, result.stderr[-3000:] @@ -121,7 +134,8 @@ def main(cli, consumer, renderer, sdk, adapter): refusal = 'Dispatch(3, 2, 2) refused: an MTBUF byte window requires a buffer SRV' assert len(lines(result, refusal)) == 1, result.stderr[-3000:] print(f'{adapter}: identity readback matched five pairs, seven out-of-range pairs and all guards. ' - 'Both swaps and the CBV token refused. Cold and warm manifests matched.') + 'Both swaps, a Z/W swap and the CBV token refused, on the published and the in-process route. ' + 'Cold and warm manifests matched.') if __name__ == '__main__':