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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/lanes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
22 changes: 17 additions & 5 deletions examples/lanes/selftest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2344,19 +2344,26 @@ 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 ? &parameter : nullptr, 0, nullptr,
D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED};
ComPtr<ID3DBlob> serialized;
check(D3D12SerializeVersionedRootSignature(&signature, &serialized, nullptr), "serialize bindless compute root");
ComPtr<ID3D12RootSignature> root;
check(device->CreateRootSignature(0, serialized->GetBufferPointer(), serialized->GetBufferSize(),
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<ID3D12PipelineState> pipeline;
check(method<CreateComputePipeline>(device, device_create_compute)(device, &shader, 0, nullptr,
IID_PPV_ARGS(&pipeline)), "create translated bindless compute pipeline");
Expand Down Expand Up @@ -2394,6 +2401,7 @@ void bindless_compute(ID3D12Device* device) {
method<BindHeaps>(list, slot_bind_heaps)(list, 1, heaps);
method<SetRoot>(list, slot_compute_root)(list, root.Get());
list->SetPipelineState(pipeline.Get());
if (table) method<SetTable>(list, slot_compute_table)(list, 0, {method<GpuHandle>(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);
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<unsigned>(std::size(selftest_scenarios));
static_assert(std::size(selftest_scenarios) == std::size(scenarios));

Expand Down
12 changes: 10 additions & 2 deletions examples/lanes/shader_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,22 @@ 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]
info = bytearray(48)
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("<Q", 1 << 25)),
(b"PSV0", pack([48]) + info + pack([0])),
Expand Down Expand Up @@ -190,6 +197,7 @@ def header():
+ f"constexpr unsigned wave_shader_expected[] = {{{words}}};\n"
+ declaration("recovered_root_shader", recovered_root_shader())
+ declaration("bindless_compute_shader", bindless_compute_shader())
+ declaration("bindless_table_compute_shader", bindless_compute_shader(table=True))
+ f"constexpr unsigned bindless_index = {BINDLESS_INDEX};\nconstexpr unsigned bindless_expected = {BINDLESS_EXPECTED:#x};\n"
+ declaration("bindless_sampler_shader", bindless_sampler_shader())
+ f"constexpr unsigned bindless_texture = {BINDLESS_TEXTURE}, bindless_output = {BINDLESS_OUTPUT};\n"
Expand Down
9 changes: 7 additions & 2 deletions project_tuxbox/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,10 @@ def lanes_bindless_compute(host, check, gpu_args, pci, memory_symbols):
"""Dispatch the Lanes direct-indexed compute programs with a paged resource heap.
One stores through a heap UAV; the other also samples a heap texture with a
literal sampler. Each runs with a roomy and a constrained resident limit.
literal sampler. A third stores like the first from a root that also has a
descriptor table. Each runs with a roomy and a constrained resident limit.
"""
from functools import partial
from examples.lanes.shader_fixture import bindless_compute_shader, bindless_sampler_shader
from .runtime_shaders import shader_session
from .shader_prep import SOURCE_CACHE
Expand All @@ -498,7 +500,8 @@ def lanes_bindless_compute(host, check, gpu_args, pci, memory_symbols):
try:
trials = [(scenario, hashlib.sha256(build()).hexdigest(), kind, limit)
for scenario, build in (("bindless-compute", bindless_compute_shader),
("bindless-sampler", bindless_sampler_shader))
("bindless-sampler", bindless_sampler_shader),
("bindless-table-compute", partial(bindless_compute_shader, table=True)))
for kind, limit in (("wide", "1000000"), ("constrained", "64"))]
for scenario, original, kind, limit in trials:
messages = []
Expand Down Expand Up @@ -1174,6 +1177,8 @@ def exports_receipt(_imports):
"lanes-bindless-compute-constrained": "The same with fewer resident descriptors than the index it uses",
"lanes-bindless-sampler-wide": "A direct-indexed compute program's literal sampler, added to its paged root",
"lanes-bindless-sampler-constrained": "The same with fewer resident descriptors than the indices it uses",
"lanes-bindless-table-compute-wide": "A direct-indexed compute program's heap UAV when its root also has a table",
"lanes-bindless-table-compute-constrained": "The same with fewer resident descriptors than the index it uses",
"lanes-package-replay": "Lanes gameplay replay (earlier guest with desktop graphics)", "cpu-replay": "8,388,608-move CPU replay",
}

Expand Down
19 changes: 19 additions & 0 deletions runtime/d3d12/src/device/compute_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ fn reflected_root(
if !simple && !extended {
return Ok(TableLayout::Unsupported);
}
// The program can still pick resources by heap index. Without the
// map the root stays the guest's and its dispatch is skipped once
// descriptors are paged.
if heap_indexed_tabled_root(&signature) {
scalar_index = Some((0, 0));
index_map_visibility = D3D12_SHADER_VISIBILITY_ALL;
}
if signature.static_samplers.is_empty() && signature.flags & 0x800 == 0 {
recovered_samplers = tuxbox_dxbc::inline_sampler::private(shader, 5).unwrap_or_default();
} else {
Expand Down Expand Up @@ -544,6 +551,18 @@ fn bindless_compute_root(signature: &tuxbox_dxbc::rootsig::RootSig) -> 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.
Expand Down
12 changes: 12 additions & 0 deletions runtime/d3d12/src/tests/device/compute_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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])));
}
5 changes: 3 additions & 2 deletions tests/test_lanes_bindless.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down