diff options
| author | aslan2142 <jan.trencansky@protonmail.com> | 2026-11-25 04:26:54 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-25 04:26:54 +0100 |
| commit | bfef489cb6307fa4e1dc6ed2c40bfc0ce120d066 (patch) | |
| tree | 19e2f01d50809de00ecba664b4044eed1aad2c36 /runtime/test | |
| parent | 98efc22ca3d2841b985eb36d4afbe7d434628670 (diff) | |
| parent | 3ee0037fd3accba459d0d5ecd8acad831174d4d7 (diff) | |
Merge pull request #1232 from iFeyz/feat/direct-heap-graphics
d3d12: graphics draws supply the directly indexed heaps after their root arguments (RT-DIRECT-HEAP-GRAPHICS)
Diffstat (limited to 'runtime/test')
| -rw-r--r-- | runtime/test/d3d12_mesh_test.cpp | 67 |
1 files changed, 65 insertions, 2 deletions
diff --git a/runtime/test/d3d12_mesh_test.cpp b/runtime/test/d3d12_mesh_test.cpp index e59414a01..2d9bc5212 100644 --- a/runtime/test/d3d12_mesh_test.cpp +++ b/runtime/test/d3d12_mesh_test.cpp | |||
| @@ -188,13 +188,14 @@ int main(int argc, char** argv) { | |||
| 188 | }; | 188 | }; |
| 189 | // Twenty constants: s8..s27 for a pixel shader, but past a mesh shader's 16-dword window (s16..s31). Thirty: | 189 | // Twenty constants: s8..s27 for a pixel shader, but past a mesh shader's 16-dword window (s16..s31). Thirty: |
| 190 | // past the graphics window (24 from s8) and the compute one (28 from s4) too, as a retail start-up signature is. | 190 | // past the graphics window (24 from s8) and the compute one (28 from s4) too, as a retail start-up signature is. |
| 191 | const auto wide_root_signature = [&](ID3D12Device* device, Ref<ID3D12RootSignature>& root, UINT values = 20) { | 191 | const auto wide_root_signature = [&](ID3D12Device* device, Ref<ID3D12RootSignature>& root, UINT values = 20, |
| 192 | D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) { | ||
| 192 | D3D12_ROOT_PARAMETER param{}; | 193 | D3D12_ROOT_PARAMETER param{}; |
| 193 | param.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS; | 194 | param.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS; |
| 194 | param.Constants = {0, 0, values}; | 195 | param.Constants = {0, 0, values}; |
| 195 | D3D12_VERSIONED_ROOT_SIGNATURE_DESC root_desc{}; | 196 | D3D12_VERSIONED_ROOT_SIGNATURE_DESC root_desc{}; |
| 196 | root_desc.Version = D3D_ROOT_SIGNATURE_VERSION_1_0; | 197 | root_desc.Version = D3D_ROOT_SIGNATURE_VERSION_1_0; |
| 197 | root_desc.Desc_1_0 = {1, ¶m, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE}; | 198 | root_desc.Desc_1_0 = {1, ¶m, 0, nullptr, flags}; |
| 198 | const auto blob = serialize_root_signature(root_desc); | 199 | const auto blob = serialize_root_signature(root_desc); |
| 199 | return !blob.empty() && | 200 | return !blob.empty() && |
| 200 | SUCCEEDED(device->CreateRootSignature(0, blob.data(), blob.size(), IID_PPV_ARGS(&root.p))); | 201 | SUCCEEDED(device->CreateRootSignature(0, blob.data(), blob.size(), IID_PPV_ARGS(&root.p))); |
| @@ -526,6 +527,68 @@ int main(int argc, char** argv) { | |||
| 526 | list->RSSetViewports(1, &viewport); | 527 | list->RSSetViewports(1, &viewport); |
| 527 | list6->DispatchMesh(1, 1, 1); | 528 | list6->DispatchMesh(1, 1, 1); |
| 528 | EXPECT(SUCCEEDED(list->Close())); | 529 | EXPECT(SUCCEEDED(list->Close())); |
| 530 | |||
| 531 | // RT-DIRECT-HEAP-GRAPHICS: with the directly-indexed flags, the dword after the graphics root arguments | ||
| 532 | // holds the resource heap's 32-bit address and the next one the sampler heap's, for vertex and mesh draws | ||
| 533 | // alike (a mesh shader reads them through its window). 4 constants take s8..s11, so the heaps are at 12 | ||
| 534 | // and 13; 23 constants leave room for the resource heap only (s31); a signature past the graphics window | ||
| 535 | // (30 constants) keeps pack()'s s0 layout, which has no measured slot, so nothing is written. | ||
| 536 | const auto direct = static_cast<D3D12_ROOT_SIGNATURE_FLAGS>( | ||
| 537 | D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED | | ||
| 538 | D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED); | ||
| 539 | Ref<ID3D12RootSignature> direct4, direct23, direct30; | ||
| 540 | EXPECT(wide_root_signature(device.p, direct4, 4, direct)); | ||
| 541 | EXPECT(wide_root_signature(device.p, direct23, 23, direct)); | ||
| 542 | EXPECT(wide_root_signature(device.p, direct30, 30, direct)); | ||
| 543 | D3D12_DESCRIPTOR_HEAP_DESC resources_desc{D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 8, | ||
| 544 | D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE, 0}; | ||
| 545 | auto samplers_desc = resources_desc; | ||
| 546 | samplers_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER; | ||
| 547 | Ref<ID3D12DescriptorHeap> resources, samplers; | ||
| 548 | EXPECT(SUCCEEDED(device->CreateDescriptorHeap(&resources_desc, IID_PPV_ARGS(&resources.p)))); | ||
| 549 | EXPECT(SUCCEEDED(device->CreateDescriptorHeap(&samplers_desc, IID_PPV_ARGS(&samplers.p)))); | ||
| 550 | const std::uint64_t res_va = reinterpret_cast<XboxHeapHandleFn>(slot(resources.p, 10))(resources.p); | ||
| 551 | const std::uint64_t smp_va = reinterpret_cast<XboxHeapHandleFn>(slot(samplers.p, 10))(samplers.p); | ||
| 552 | EXPECT(res_va && res_va < (1ull << 32) && smp_va && smp_va < (1ull << 32)); | ||
| 553 | const std::array<std::uint32_t, 4> four{1, 2, 3, 4}; | ||
| 554 | ID3D12DescriptorHeap* both[] = {resources.p, samplers.p}; | ||
| 555 | EXPECT(SUCCEEDED(list->Reset(allocator.p, vs_pso.p))); | ||
| 556 | list->SetDescriptorHeaps(2, both); | ||
| 557 | list->SetGraphicsRootSignature(direct4.p); | ||
| 558 | list->SetGraphicsRoot32BitConstants(0, 4, four.data(), 0); | ||
| 559 | list->RSSetViewports(1, &viewport); | ||
| 560 | list->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); | ||
| 561 | list->DrawInstanced(3, 1, 0, 0); | ||
| 562 | list->SetPipelineState(mesh_pso.p); | ||
| 563 | list6->DispatchMesh(1, 1, 1); | ||
| 564 | list->SetPipelineState(vs_pso.p); | ||
| 565 | list->SetDescriptorHeaps(1, &resources.p); // rebinding only the resource heap unbinds the sampler heap | ||
| 566 | list->DrawInstanced(3, 1, 0, 0); | ||
| 567 | list->SetDescriptorHeaps(2, both); | ||
| 568 | list->SetGraphicsRootSignature(direct23.p); | ||
| 569 | list->SetGraphicsRoot32BitConstant(0, 77, 22); | ||
| 570 | list->DrawInstanced(3, 1, 0, 0); | ||
| 571 | list->SetGraphicsRootSignature(direct30.p); | ||
| 572 | list->DrawInstanced(3, 1, 0, 0); | ||
| 573 | EXPECT(SUCCEEDED(list->Close())); | ||
| 574 | std::vector<leonida::Command> commands; | ||
| 575 | EXPECT(rt::d3d12::recorded_commands(list.p, commands)); | ||
| 576 | std::vector<const leonida::Draw*> draws; | ||
| 577 | for (const auto& command : commands) | ||
| 578 | if (const auto* recorded = std::get_if<leonida::Draw>(&command)) draws.push_back(recorded); | ||
| 579 | EXPECT(draws.size() == 5); | ||
| 580 | char setting[2]{}; | ||
| 581 | const bool enabled = GetEnvironmentVariableA("LEONIDA_GRAPHICS_DIRECT_HEAPS", setting, 2) != 1 || | ||
| 582 | setting[0] != '0'; | ||
| 583 | const auto res = enabled ? std::uint32_t(res_va) : 0u, smp = enabled ? std::uint32_t(smp_va) : 0u; | ||
| 584 | const auto& vertex = draws[0]->user_data; | ||
| 585 | EXPECT(vertex[8] == 1 && vertex[11] == 4 && vertex[12] == res && vertex[13] == smp); | ||
| 586 | EXPECT(draws[1]->mesh && draws[1]->user_data == vertex); // the mesh draw: the same dwords | ||
| 587 | EXPECT(draws[2]->user_data[12] == res && draws[2]->user_data[13] == 0); | ||
| 588 | EXPECT(draws[3]->user_data[30] == 77 && draws[3]->user_data[31] == res); | ||
| 589 | for (std::uint32_t k = 0; k < 32; ++k) EXPECT(draws[4]->user_data[k] == 0); | ||
| 590 | std::printf("direct heaps on graphics draws: resource heap at s%u, sampler heap at s%u%s\n", 12u, 13u, | ||
| 591 | enabled ? "" : " (LEONIDA_GRAPHICS_DIRECT_HEAPS=0: not written)"); | ||
| 529 | } | 592 | } |
| 530 | // A DISPATCH_MESH command signature (D3D12_DISPATCH_MESH_ARGUMENTS, 12 bytes) is created; a stride below its | 593 | // A DISPATCH_MESH command signature (D3D12_DISPATCH_MESH_ARGUMENTS, 12 bytes) is created; a stride below its |
| 531 | // 12 bytes is refused as the PC runtime refuses it. ExecuteIndirect with it records nothing yet (#3777 replays | 594 | // 12 bytes is refused as the PC runtime refuses it. ExecuteIndirect with it records nothing yet (#3777 replays |