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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/gfx1013_compute_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Document the newly supported single-heap root layouts

This enables previously refused single-flag root signatures, but the commit contains no public capability documentation update. docs/experiments/native-sampler-heap.md still describes entry binding as requiring 0xc00 (lines 23–25) and explicitly lists roots with only 0x800 as uncovered (line 117), so readers are still told that the newly supported sampler-only shape is unavailable. Add or update the relevant capability and reproduction documentation to describe independent heap flags and the exact remaining-user-SGPR requirement; AGENTS.md requires a documentation update when a public capability changes.

AGENTS.md reference: AGENTS.md:L329-L330

Useful? React with 👍 / 👎.

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.
Expand Down
30 changes: 20 additions & 10 deletions tests/native_sampler_heap_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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):
Expand All @@ -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")
Expand Down Expand Up @@ -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")

Expand Down
48 changes: 32 additions & 16 deletions tests/native_wave_request_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("<I", 0x196)
for flags, registers, group_x in ((views + " | SAMPLER_HEAP_DIRECTLY_INDEXED", sa, 12),
(views, sa_views, 11)):
source.write_text(f'#define SIG "RootFlags({flags}),'
'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)
root_blob = root.read_bytes()
for selector_offset in (0, 4):
marker = write_request(work, program(selector_offset, group_x), root_blob, registers)
result = subprocess.run([gpu, sdk, marker, work / "cache", "global-stride"], capture_output=True, text=True)
print("global-stride", flags, 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

# Keep the original twelve-SGPR program so its group ID is still valid at s12.
invalid = write_request(work, program(0, 12), root_blob, sa)
output = work / "invalid-direct-heap-count.cso"
result = subprocess.run([*cli_args, invalid, output], capture_output=True, text=True)
assert result.returncode and "direct descriptor address outside bound table" in result.stderr, result.stderr
assert not output.exists()


def main(cli, gpu, sdk):
Expand Down Expand Up @@ -250,7 +265,8 @@ def main(cli, gpu, sdk):
print(mode, result.stdout.strip(), flush=True)
sdwa_fixtures(args, gpu, sdk, work, root.read_bytes(), sa)
raw_offset_fixtures(args, gpu, sdk, work, root.read_bytes(), sa)
global_stride_fixtures(gpu, sdk, work, root, source, sa)
global_stride_fixtures([cli, sdk, work / "cache", "gfx1013-direct-cs@0"],
gpu, sdk, work, root, source, sa)
return 0


Expand Down
Loading