From 3114bb156ef7523ffec69e4cc37ffeaf902041f4 Mon Sep 17 00:00:00 2001 From: tedin7 <110300616+tedin7@users.noreply.github.com> Date: Fri, 27 Nov 2026 22:54:05 +0100 Subject: [PATCH] native: bind a single directly indexed heap flag as a descriptor table --- src/gfx1013_compute_native.cpp | 17 +++++++---- tests/native_sampler_heap_check.py | 30 ++++++++++++------- tests/native_wave_request_check.py | 48 ++++++++++++++++++++---------- 3 files changed, 64 insertions(+), 31 deletions(-) diff --git a/src/gfx1013_compute_native.cpp b/src/gfx1013_compute_native.cpp index 8d2acf408c..4a30943693 100644 --- a/src/gfx1013_compute_native.cpp +++ b/src/gfx1013_compute_native.cpp @@ -1669,11 +1669,18 @@ static NativeComputeShader translate_program(const ComputeRequest &request, unsi } else refuse(entry, "root-address parameter"); } - // In this compute ABI the two directly indexed heaps follow the user root parameters. - // Require both flags and exactly two remaining user SGPRs, as in the matched native layouts. - if (!stage && (UINT(layout->Desc_1_1.Flags) & 0xc00u) == 0xc00u && next + 2 == user) { - initial[next] = {Symbol::Type::table, compute_resource_heap}; - initial[next + 1] = {Symbol::Type::table, compute_sampler_heap}; + // The enabled direct heaps follow the root parameters, resource heap first. + // Bind them only when they account for every remaining user SGPR. + const auto flags = layout->Desc_1_1.Flags; + const bool resource_heap = (flags & D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED) != 0; + const bool sampler_heap = (flags & D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED) != 0; + const unsigned heap_count = unsigned(resource_heap) + unsigned(sampler_heap); + if (!stage && heap_count && next + heap_count == user) { + unsigned slot = next; + if (resource_heap) + initial[slot++] = {Symbol::Type::table, compute_resource_heap}; + if (sampler_heap) + initial[slot] = {Symbol::Type::table, compute_sampler_heap}; } const bool wave64 = stage && !stage->wave32; // The byte-address rewrite of a GPU-selected heap descriptor is read only under the raw_buffer contract. diff --git a/tests/native_sampler_heap_check.py b/tests/native_sampler_heap_check.py index 2d20e2aa8f..94f53b475a 100644 --- a/tests/native_sampler_heap_check.py +++ b/tests/native_sampler_heap_check.py @@ -30,6 +30,7 @@ ROOT_RW = "RootFlags(CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED | SAMPLER_HEAP_DIRECTLY_INDEXED), DescriptorTable(SRV(t0), UAV(u0))" ROOT_VIEWS_ONLY = "RootFlags(CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED), DescriptorTable(SRV(t0), UAV(u0))" +ROOT_SAMPLERS_ONLY = "RootFlags(SAMPLER_HEAP_DIRECTLY_INDEXED), DescriptorTable(SRV(t0), UAV(u0))" REFUSALS = { "buffer": "scalar buffer load from the sampler heap is not translated", @@ -239,7 +240,6 @@ def run(command, expect_skip=False): with tempfile.TemporaryDirectory(prefix="x2w_sampler_heap_") as scratch: base = pathlib.Path(scratch) # Sampler heap content, texture and expectations are in the fixture; the requests are written here. - sa = struct.pack("<7I", 0, 0, 0, 32 | (1 << 16), 1, 0, 7 << 1) # group 32x1x1, 7 user SGPRs roots = {} def root(text): @@ -259,7 +259,15 @@ def request(name, root_text=ROOT_RW): counter += 1 folder = base / f"req_{counter}_{name}" folder.mkdir() - return write_request(folder, PROGRAMS[name], root(root_text), sa) + words = PROGRAMS[name] + user = 7 + if root_text == ROOT_SAMPLERS_ONLY: + assert name == "sample" + words = words.copy() + words[2] = 0xbe8a0305 # s_mov_b32 s10, s5 + user = 6 + sa = struct.pack("<7I", 0, 0, 0, 32 | (1 << 16), 1, 0, user << 1) + return write_request(folder, words, root(root_text), sa) def compile_request(marker, profile="gfx1013-direct-cs@0", cache=None): output = marker.with_suffix(".cso") @@ -293,17 +301,19 @@ def accepted(name, message): *[f"decoy {n} in place of entry 67 changes result 1" for n in range(3)], "1088 bytes}"], } - for mode, lines in expected_lines.items(): - marker = request(mode) - cache = base / f"cache_{mode}" + cases = [(mode, mode, ROOT_RW) for mode in expected_lines] + cases.append(("sampler_only", "sample", ROOT_SAMPLERS_ONLY)) + for name, mode, root_text in cases: + marker = request(mode, root_text) + cache = base / f"cache_{name}" cache.mkdir() code, out, err = run([fixture, sdk, cache, marker, adapter, mode], expect_skip=True) - require(code == 0, f"fixture mode {mode} exits 0") - for line in lines: - require(line in out, f"{mode}: {line}") + require(code == 0, f"fixture case {name} exits 0") + for line in expected_lines[mode]: + require(line in out, f"{name}: {line}") require("pass: prepare_direct_compute misses on a fresh cache and hits on the second call" in out, - f"{mode}: frontend cache round trip (miss, then hit)") - require("pass: pipeline has sampler_heap_indexed" in out, f"{mode}: pipeline asks for the sampler heap flag only") + f"{name}: frontend cache round trip (miss, then hit)") + require("pass: pipeline has sampler_heap_indexed" in out, f"{name}: pipeline asks for the sampler heap flag only") code, out, err = run([fixture, sdk, base / "cache_unbound", request("sample"), adapter, "unbound"], expect_skip=True) require(code == 0 and "bind without a sampler heap throws" in out, "bind without a sampler heap throws") diff --git a/tests/native_wave_request_check.py b/tests/native_wave_request_check.py index 0965e3e047..6f669b74a2 100644 --- a/tests/native_wave_request_check.py +++ b/tests/native_wave_request_check.py @@ -132,30 +132,45 @@ def scalar(op, dst, a, b): assert result.returncode and "needs offen" in result.stderr and not (work / "indexed.cso").exists() -def global_stride_fixtures(gpu, sdk, work, root, source, sa): - source.write_text('#define SIG "RootFlags(CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED | SAMPLER_HEAP_DIRECTLY_INDEXED),' - 'DescriptorTable(SRV(t0,numDescriptors=16)),DescriptorTable(UAV(u0,numDescriptors=16)),' - 'RootConstants(num32BitConstants=4,b0)"') - subprocess.run([Path(sdk) / "dxc.exe", "-T", "rootsig_1_1", "-E", "SIG", "-Fo", root, source], check=True) - # GPU input s[40:47] feeds s43. Select a heap slot, then extract descriptor word 1 bits 16..29. - # The table index is deliberately unbounded at compile time, and is overwritten before the extract. - for selector_offset in (0, 4): +def global_stride_fixtures(cli_args, gpu, sdk, work, root, source, sa): + def program(selector_offset, group_x): + # GPU input s[40:47] feeds s43. The unbounded index is overwritten before the stride extract. + group_y = group_x + 1 words = [0xbe940304, 0xbe950380, 0xbe960305, 0xbe970380, 0xf4080000 | (24 << 6) | 10, 0xfa000040, 0xf40c0000 | (56 << 6) | 11, 0xfa0000e0, - 0x80000000 | (0x1e << 23) | (20 << 16) | (133 << 8) | 12, + 0x80000000 | (0x1e << 23) | (20 << 16) | (133 << 8) | group_x, 0xf42c0000 | (40 << 6) | 12, (20 << 25) | selector_offset, 0xbe9e030a, 0xbe9f0380, 0x80000000 | (0x1e << 23) | (43 << 16) | (133 << 8) | 43, 0xf4080000 | (48 << 6) | 15, 43 << 25, 0xbeab0380, 0x93800000 | (28 << 16) | (255 << 8) | 49, 0x000e0010, - 0xd7460008, 12 | (133 << 9) | (256 << 18), 0x7e12020d] + 0xd7460008, group_x | (133 << 9) | (256 << 18), 0x7e120200 | group_y] words += [0x7e000000 | (v << 17) | (6 << 9) | 28 for v in range(2, 6)] words += [0xf0200f08, (14 << 16) | (2 << 8) | 8, 0xbf810000] - marker = write_request(work, words, root.read_bytes(), sa) - result = subprocess.run([gpu, sdk, marker, work / "cache", "global-stride"], capture_output=True, text=True) - print("global-stride", selector_offset, result.stdout.strip(), flush=True) - assert result.returncode == int(bool(selector_offset)), (result.stdout, result.stderr) - assert f"differing_components={8192 if selector_offset else 0} " in result.stdout + return words + + views = "CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED" + sa_views = sa[:-4] + struct.pack("