diff options
| author | iFeyz <62035583+iFeyz@users.noreply.github.com> | 2026-11-24 21:16:09 +0100 |
|---|---|---|
| committer | iFeyz <62035583+iFeyz@users.noreply.github.com> | 2026-11-24 21:16:09 +0100 |
| commit | bfe8d5c4d83f22570b604dbf70b80c226d3e91b0 (patch) | |
| tree | 86300dee2d5886a2cbb101509b54062e677c97ec /runtime/shims/d3d12_com.cpp | |
| parent | 00fc23b9a9eeb1a75f1fec2b58024bea15c26663 (diff) | |
| parent | 7c47fd946ba19461ed7ff0b12383b55e23bf79c7 (diff) | |
Merge commit 'refs/pull/1064/head' of https://github.com/ubiquitarianism/leonida into feat/direct-heap-graphics
Diffstat (limited to 'runtime/shims/d3d12_com.cpp')
| -rw-r--r-- | runtime/shims/d3d12_com.cpp | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/runtime/shims/d3d12_com.cpp b/runtime/shims/d3d12_com.cpp index 4349a6a91..26d02f325 100644 --- a/runtime/shims/d3d12_com.cpp +++ b/runtime/shims/d3d12_com.cpp | |||
| @@ -863,7 +863,7 @@ public: | |||
| 863 | if (kind == leonida::IndirectKind::dispatch && max_command_count) { // the pipeline and root arguments a Dispatch would record | 863 | if (kind == leonida::IndirectKind::dispatch && max_command_count) { // the pipeline and root arguments a Dispatch would record |
| 864 | if (!compute_pipeline_ || !compute_.layout) return check(false); | 864 | if (!compute_pipeline_ || !compute_.layout) return check(false); |
| 865 | cmd.pipeline = compute_pipeline_; | 865 | cmd.pipeline = compute_pipeline_; |
| 866 | cmd.user_data = compute_.data; | 866 | cmd.user_data = compute_user_data(); |
| 867 | } | 867 | } |
| 868 | check(list_.execute_indirect(cmd)); | 868 | check(list_.execute_indirect(cmd)); |
| 869 | } | 869 | } |
| @@ -1357,19 +1357,20 @@ private: | |||
| 1357 | if ((cbv && cbv != cbv_srv_uav_heap_) || (smp && smp != sampler_heap_)) check(false); | 1357 | if ((cbv && cbv != cbv_srv_uav_heap_) || (smp && smp != sampler_heap_)) check(false); |
| 1358 | } | 1358 | } |
| 1359 | 1359 | ||
| 1360 | void note_direct_heap_indexing(const RootArgumentLayout* layout) const { | 1360 | void note_direct_heap_indexing(const RootArgumentLayout* layout, bool compute) const { |
| 1361 | if (!layout) return; | ||
| 1362 | if (layout->flags & D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED) { | 1361 | if (layout->flags & D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED) { |
| 1363 | if (!cbv_srv_uav_heap_) | 1362 | if (!cbv_srv_uav_heap_) |
| 1364 | note_once("draw/dispatch uses CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED with no CBV/SRV/UAV heap bound"); | 1363 | note_once(compute ? "dispatch uses direct resource indexing with no CBV/SRV/UAV heap bound" |
| 1365 | else | 1364 | : "draw uses direct resource indexing with no CBV/SRV/UAV heap bound"); |
| 1366 | note_once("CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED heap base tracked on list (SGPR slot open, section 3.4)"); | 1365 | else if (!compute) |
| 1366 | note_once("draw uses direct resource indexing; graphics heap-base SGPR is not supplied"); | ||
| 1367 | } | 1367 | } |
| 1368 | if (layout->flags & D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED) { | 1368 | if (layout->flags & D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED) { |
| 1369 | if (!sampler_heap_) | 1369 | if (!sampler_heap_) |
| 1370 | note_once("draw/dispatch uses SAMPLER_HEAP_DIRECTLY_INDEXED with no sampler heap bound"); | 1370 | note_once(compute ? "dispatch uses direct sampler indexing with no sampler heap bound" |
| 1371 | else | 1371 | : "draw uses direct sampler indexing with no sampler heap bound"); |
| 1372 | note_once("SAMPLER_HEAP_DIRECTLY_INDEXED heap base tracked on list (SGPR slot open, section 3.4)"); | 1372 | else if (!compute) |
| 1373 | note_once("draw uses direct sampler indexing; graphics heap-base SGPR is not supplied"); | ||
| 1373 | } | 1374 | } |
| 1374 | } | 1375 | } |
| 1375 | 1376 | ||
| @@ -1407,10 +1408,33 @@ private: | |||
| 1407 | : leonida::IndexBufferView{}; | 1408 | : leonida::IndexBufferView{}; |
| 1408 | } | 1409 | } |
| 1409 | 1410 | ||
| 1411 | // Section 3.4 documents the observed resource-heap slot. Appending flagged heaps in this | ||
| 1412 | // order is a working hypothesis for signatures without a matched program and layout. | ||
| 1413 | // Snapshot them for each command so rebinding a heap cannot change a recorded dispatch. | ||
| 1414 | std::array<std::uint32_t, rt::rootsig::kMaxUserSgprs> compute_user_data() const { | ||
| 1415 | note_direct_heap_indexing(compute_.layout, true); | ||
| 1416 | auto data = compute_.data; | ||
| 1417 | static const bool enabled = [] { | ||
| 1418 | char value[2]{}; | ||
| 1419 | return GetEnvironmentVariableA("LEONIDA_COMPUTE_DIRECT_HEAPS", value, 2) != 1 || value[0] != '0'; | ||
| 1420 | }(); | ||
| 1421 | if (!enabled) return data; | ||
| 1422 | const auto flags = compute_.layout->flags; | ||
| 1423 | auto slot = compute_.layout->compute_arguments_end; | ||
| 1424 | if (flags & D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED) { | ||
| 1425 | if (slot < data.size()) data[slot++] = static_cast<std::uint32_t>(cbv_srv_uav_base_); | ||
| 1426 | else note_once("compute root arguments leave no inline SGPR for the resource heap"); | ||
| 1427 | } | ||
| 1428 | if (flags & D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED) { | ||
| 1429 | if (slot < data.size()) data[slot] = static_cast<std::uint32_t>(sampler_base_); | ||
| 1430 | else note_once("compute root arguments leave no inline SGPR for the sampler heap"); | ||
| 1431 | } | ||
| 1432 | return data; | ||
| 1433 | } | ||
| 1434 | |||
| 1410 | void record_dispatch(UINT x, UINT y, UINT z) { | 1435 | void record_dispatch(UINT x, UINT y, UINT z) { |
| 1411 | if (!compute_pipeline_ || !compute_.layout) return check(false); | 1436 | if (!compute_pipeline_ || !compute_.layout) return check(false); |
| 1412 | note_direct_heap_indexing(compute_.layout); | 1437 | check(list_.dispatch({compute_pipeline_, compute_user_data(), x, y, z})); |
| 1413 | check(list_.dispatch({compute_pipeline_, compute_.data, x, y, z})); | ||
| 1414 | } | 1438 | } |
| 1415 | 1439 | ||
| 1416 | // The views block a draw records. Rebuilt only when the render targets or the bound vertex buffers change. | 1440 | // The views block a draw records. Rebuilt only when the render targets or the bound vertex buffers change. |
| @@ -1429,7 +1453,7 @@ private: | |||
| 1429 | // A draw needs a graphics pipeline, a graphics root signature and a topology. | 1453 | // A draw needs a graphics pipeline, a graphics root signature and a topology. |
| 1430 | void record_draw(bool indexed, UINT count, UINT instances, UINT first, INT base_vertex, UINT first_instance) { | 1454 | void record_draw(bool indexed, UINT count, UINT instances, UINT first, INT base_vertex, UINT first_instance) { |
| 1431 | if (!graphics_pipeline_ || !graphics_.layout || !topology_) return check(false); | 1455 | if (!graphics_pipeline_ || !graphics_.layout || !topology_) return check(false); |
| 1432 | note_direct_heap_indexing(graphics_.layout); | 1456 | note_direct_heap_indexing(graphics_.layout, false); |
| 1433 | // No viewport (never set, or unbound with RSSetViewports(0)) or an empty one: D3D12 rasterizes nothing, | 1457 | // No viewport (never set, or unbound with RSSetViewports(0)) or an empty one: D3D12 rasterizes nothing, |
| 1434 | // and Vulkan forbids a 0x0 viewport, so the draw is not recorded. | 1458 | // and Vulkan forbids a 0x0 viewport, so the draw is not recorded. |
| 1435 | if (!(viewport_.width > 0) || !(viewport_.height > 0)) return; | 1459 | if (!(viewport_.width > 0) || !(viewport_.height > 0)) return; |