From 341a9fd3bbc81ca45d534165ff4c8081390a75f4 Mon Sep 17 00:00:00 2001 From: Kayotic1337 <264186126+Kayotic1337@users.noreply.github.com> Date: Fri, 27 Nov 2026 03:22:21 +0100 Subject: [PATCH] d3d12: give direct-indexed compute roots with tables the resource index map A compute root with descriptor tables and CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED kept the guest root when its tables matched, so once descriptors were paged every dispatch was skipped ("its root indexes the resource heap directly"). Its program can still pick resources by heap index, so it now takes the index map like a bindless root, when the map's root SRV still fits. Lanes: `bindless-table-compute` runs the `bindless-compute` program under such a root in the `lanes-bindless-compute` suite. It fails without this change. Co-Authored-By: Claude Opus 5.5 --- examples/lanes/README.md | 2 +- examples/lanes/selftest.cpp | 22 ++++++++++++++----- examples/lanes/shader_fixture.py | 12 ++++++++-- project_tuxbox/verify.py | 9 ++++++-- runtime/d3d12/src/device/compute_table.rs | 19 ++++++++++++++++ .../d3d12/src/tests/device/compute_table.rs | 12 ++++++++++ tests/test_lanes_bindless.py | 5 +++-- 7 files changed, 69 insertions(+), 12 deletions(-) diff --git a/examples/lanes/README.md b/examples/lanes/README.md index c3d7c4e2..27716b6c 100644 --- a/examples/lanes/README.md +++ b/examples/lanes/README.md @@ -180,4 +180,4 @@ all other guard words must match; stand-ins are disabled. python tuxbox.py verify --only lanes-compute-root-recovery --output build/lanes-compute-root-recovery.json ``` -The `lanes-bindless-compute` verification suite runs two native console programs under a direct-indexed root with no parameters, each with a roomy and a constrained paged resource heap (resident limit 64 in the constrained run). `bindless-compute` stores through the heap UAV at logical slot 80. `bindless-sampler` samples the heap texture at slot 90 with a linear sampler built from literal words, which the root does not declare, and stores the value through the UAV at slot 85. Each run requires a translation made against the pipeline's root, the paged map bind and disabled stand-ins. +The `lanes-bindless-compute` verification suite runs three native console programs under direct-indexed roots, each with a roomy and a constrained paged resource heap (resident limit 64 in the constrained run). `bindless-compute` stores through the heap UAV at logical slot 80. `bindless-sampler` samples the heap texture at slot 90 with a linear sampler built from literal words, which the root does not declare, and stores the value through the UAV at slot 85. `bindless-table-compute` is `bindless-compute` under a direct-indexed root that also has a bound table of four UAVs, which the program does not read. Each run requires a translation made against the pipeline's root, the paged map bind and disabled stand-ins. diff --git a/examples/lanes/selftest.cpp b/examples/lanes/selftest.cpp index fa083e68..1682e2d5 100644 --- a/examples/lanes/selftest.cpp +++ b/examples/lanes/selftest.cpp @@ -2344,11 +2344,17 @@ void descriptor_reclaim(ID3D12Device* device) { // A zero-parameter direct-indexed compute root, with the requested UAV at // logical slot 80. The paged trial caps native residency at 64 descriptors. -// Check the entire buffer, including decoys and guard words. -void bindless_compute(ID3D12Device* device) { +// Check the entire buffer, including decoys and guard words. With `table`, the +// root also has a bound table of four UAVs the program does not read. +void bindless_compute_with(ID3D12Device* device, bool table) { + D3D12_DESCRIPTOR_RANGE1 range{D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 4, 0, 0, D3D12_DESCRIPTOR_RANGE_FLAG_NONE, 0}; + D3D12_ROOT_PARAMETER1 parameter{}; + parameter.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; + parameter.DescriptorTable = {1, &range}; D3D12_VERSIONED_ROOT_SIGNATURE_DESC signature{}; signature.Version = D3D_ROOT_SIGNATURE_VERSION_1_1; - signature.Desc_1_1 = {0, nullptr, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED}; + signature.Desc_1_1 = {table ? 1u : 0u, table ? ¶meter : nullptr, 0, nullptr, + D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED}; ComPtr serialized; check(D3D12SerializeVersionedRootSignature(&signature, &serialized, nullptr), "serialize bindless compute root"); ComPtr root; @@ -2356,7 +2362,8 @@ void bindless_compute(ID3D12Device* device) { IID_PPV_ARGS(&root)), "create bindless compute root"); D3D12_COMPUTE_PIPELINE_STATE_DESC shader{}; shader.pRootSignature = root.Get(); - shader.CS = {bindless_compute_shader, sizeof(bindless_compute_shader)}; + shader.CS = table ? D3D12_SHADER_BYTECODE{bindless_table_compute_shader, sizeof(bindless_table_compute_shader)} + : D3D12_SHADER_BYTECODE{bindless_compute_shader, sizeof(bindless_compute_shader)}; ComPtr pipeline; check(method(device, device_create_compute)(device, &shader, 0, nullptr, IID_PPV_ARGS(&pipeline)), "create translated bindless compute pipeline"); @@ -2394,6 +2401,7 @@ void bindless_compute(ID3D12Device* device) { method(list, slot_bind_heaps)(list, 1, heaps); method(list, slot_compute_root)(list, root.Get()); list->SetPipelineState(pipeline.Get()); + if (table) method(list, slot_compute_table)(list, 0, {method(heap.Get(), 10)(heap.Get())}); list->Dispatch(1, 1, 1); compute_fixture::transition(list, output.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE); @@ -2410,6 +2418,9 @@ void bindless_compute(ID3D12Device* device) { if (got != words) throw std::runtime_error("bindless compute output or guard words differ"); } +void bindless_compute(ID3D12Device* device) { bindless_compute_with(device, false); } +void bindless_table_compute(ID3D12Device* device) { bindless_compute_with(device, true); } + // A direct-indexed compute program samples the heap texture with a linear clamp // sampler it builds from literal words, which the zero-parameter root does not // declare, and stores the value through a heap UAV (`shader_fixture.py`). The @@ -2528,6 +2539,7 @@ constexpr Scenario scenarios[] = { {L"compute-root-recovery", compute_root_recovery}, {L"bindless-compute", bindless_compute}, {L"bindless-sampler", bindless_sampler}, + {L"bindless-table-compute", bindless_table_compute}, }; // A fresh Scarlett device on the requested adapter. The factory is reached @@ -2584,7 +2596,7 @@ const wchar_t* const selftest_scenarios[] = {L"labels", L"cross-queue L"raster-tables", L"lane-spill-interp", L"wave-alloc", L"raster-samplers", L"compute-root", L"mesh-samplers", L"mesh-sampler-single", L"mesh-sampler-rootless", L"compute-root-recovery", L"bindless-compute", - L"bindless-sampler"}; + L"bindless-sampler", L"bindless-table-compute"}; const unsigned selftest_scenario_count = static_cast(std::size(selftest_scenarios)); static_assert(std::size(selftest_scenarios) == std::size(scenarios)); diff --git a/examples/lanes/shader_fixture.py b/examples/lanes/shader_fixture.py index 154a1ce0..8dc36e05 100644 --- a/examples/lanes/shader_fixture.py +++ b/examples/lanes/shader_fixture.py @@ -119,8 +119,12 @@ def recovered_root_shader(): BINDLESS_EXPECTED = 0x7AB1E002 -def bindless_compute_shader(): - """Direct-indexed raw UAV store at a guest index outside the paged limit.""" +def bindless_compute_shader(table=False): + """Direct-indexed raw UAV store at a guest index outside the paged limit. + + With `table` the root also has a descriptor table of four UAVs, which the + program does not read: it still picks its UAV by heap index. + """ code = [0xbe8403ff, BINDLESS_INDEX, 0x8f048504, 0xf4080205, 0x08000000, 0xbf8cc07f, 0x7e0002ff, BINDLESS_EXPECTED, 0xe0700000, 0x80020000, 0xbf810000] @@ -128,6 +132,9 @@ def bindless_compute_shader(): info[24] = 5 struct.pack_into("<3I", info, 36, 64, 1, 1) root = pack([2, 0, 24, 0, 24, 0x400]) + if table: + # One table parameter at 24, its header at 36 and one 1.1 range at 44. + root = pack([2, 1, 24, 0, 68, 0x400, 0, 0, 36, 1, 44, 1, 4, 0, 0, 0, 0]) return stage_container(0x50066, image(7, code, [(5, 0, 1, 0, 10)]), [ (b"SFI0", struct.pack(" bool { signature.flags & 0x400 != 0 && cost.is_some_and(|cost| cost <= 62) } +/// CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED with descriptor tables as well. Like a +/// bindless root it takes the index map, if its root SRV still fits: a table +/// costs one DWORD of 64, a root descriptor two. +fn heap_indexed_tabled_root(signature: &tuxbox_dxbc::rootsig::RootSig) -> bool { + let cost = signature.params.iter().fold(0u32, |cost, p| cost.saturating_add(match p.kind { + RootParamKind::Table(_) => 1, + RootParamKind::Constants { num32, .. } => num32, + RootParamKind::Descriptor { .. } => 2, + })); + signature.flags & 0x400 != 0 && cost <= 62 +} + /// Keep every embedded range and append FSSM slots the root left out. /// Shaders that already translate keep their parameter indexes. The game's /// descriptor-table handle still addresses the slot FSSM recorded. diff --git a/runtime/d3d12/src/tests/device/compute_table.rs b/runtime/d3d12/src/tests/device/compute_table.rs index 6b37fd4d..a7f579e3 100644 --- a/runtime/d3d12/src/tests/device/compute_table.rs +++ b/runtime/d3d12/src/tests/device/compute_table.rs @@ -40,3 +40,15 @@ fn bindless_compute_roots_have_no_tables_and_index_the_heap() { // A table keeps the existing reflected paths. assert!(!bindless_compute_root(&root(0x400, &[TABLE, CONSTANTS]))); } + +#[test] +fn tabled_compute_roots_that_index_the_heap_take_the_index_map() { + assert!(heap_indexed_tabled_root(&root(0x400, &[TABLE]))); + assert!(heap_indexed_tabled_root(&root(0x400, &[TABLE, TABLE, CONSTANTS]))); + assert!(!heap_indexed_tabled_root(&root(0, &[TABLE]))); + // 15 constant parameters of four and two tables leave exactly the map's + // two DWORDs; a third table leaves one. + let full = |extra: &[u32]| root(0x400, &[&[CONSTANTS; 15][..], extra].concat()); + assert!(heap_indexed_tabled_root(&full(&[TABLE, TABLE]))); + assert!(!heap_indexed_tabled_root(&full(&[TABLE, TABLE, TABLE]))); +} diff --git a/tests/test_lanes_bindless.py b/tests/test_lanes_bindless.py index 5fe24ada..966677c2 100644 --- a/tests/test_lanes_bindless.py +++ b/tests/test_lanes_bindless.py @@ -8,15 +8,16 @@ class BindlessCompute(unittest.TestCase): def test_suite_runs_in_the_normal_check_and_labels_every_gate(self): self.assertIn("lanes-bindless-compute", BASE_SUITES) - for scenario in ("compute", "sampler"): + for scenario in ("compute", "sampler", "table-compute"): for kind in ("wide", "constrained"): self.assertIn(f"lanes-bindless-{scenario}-{kind}", GATE_LABELS) def test_guest_header_declares_both_programs(self): text = header() - for name in ("bindless_compute_shader", "bindless_sampler_shader"): + for name in ("bindless_compute_shader", "bindless_sampler_shader", "bindless_table_compute_shader"): self.assertIn(f"constexpr unsigned char {name}[]", text) self.assertNotEqual(bindless_compute_shader(), bindless_sampler_shader()) + self.assertNotEqual(bindless_compute_shader(), bindless_compute_shader(table=True)) if __name__ == "__main__":