upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/shims/d3d12_com.cpp
diff options
context:
space:
mode:
authoriFeyz <62035583+iFeyz@users.noreply.github.com>2026-11-24 21:38:59 +0100
committeriFeyz <62035583+iFeyz@users.noreply.github.com>2026-11-24 21:38:59 +0100
commit9b8707c03dabb59ba2e29b9b0749d3c3eb1f3903 (patch)
treecdd1bea168e34a76fe6f382fe36651903d8d9b31 /runtime/shims/d3d12_com.cpp
parentbfe8d5c4d83f22570b604dbf70b80c226d3e91b0 (diff)
RT-DIRECT-HEAP-GRAPHICS: graphics draws supply the directly indexed heaps after their root arguments
With CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED / SAMPLER_HEAP_DIRECTLY_INDEXED a console program reads the resource heap's address in the dword after its root arguments and the sampler heap's in the next, from s8 in VS/PS/GS and s16 in mesh shaders (DadaCap, issue #14 comment 7143020922), as #1064 does for compute. DrawInstanced, DrawIndexedInstanced and DispatchMesh now record them at RootArgumentLayout::graphics_arguments_end; a mesh shader reads the same push dwords through the #974 window. Nothing is written for a signature with parameters in the argument block or under LEONIDA_GRAPHICS_ROOT_LAYOUT=pc (no slot is measured there); LEONIDA_GRAPHICS_DIRECT_HEAPS=0 restores the previous arguments. d3d12_mesh_test checks a vertex and a mesh draw, a rebind, a signature ending at s30 and a spilled one.
Diffstat (limited to 'runtime/shims/d3d12_com.cpp')
-rw-r--r--runtime/shims/d3d12_com.cpp42
1 files changed, 35 insertions, 7 deletions
diff --git a/runtime/shims/d3d12_com.cpp b/runtime/shims/d3d12_com.cpp
index 26d02f325..e3f758fae 100644
--- a/runtime/shims/d3d12_com.cpp
+++ b/runtime/shims/d3d12_com.cpp
@@ -492,7 +492,7 @@ public:
492 return check(false); 492 return check(false);
493 } 493 }
494 if (!(viewport_.width > 0) || !(viewport_.height > 0)) return; // as record_draw: nothing is rasterized 494 if (!(viewport_.width > 0) || !(viewport_.height > 0)) return; // as record_draw: nothing is rasterized
495 leonida::Draw draw{graphics_pipeline_, graphics_.data, draw_views(), depth_, {}, 0, viewport_, 495 leonida::Draw draw{graphics_pipeline_, graphics_user_data(), draw_views(), depth_, {}, 0, viewport_,
496 scissor_, blend_factor_, front_stencil_ref_, back_stencil_ref_, false, x, y, z, 0, 0}; 496 scissor_, blend_factor_, front_stencil_ref_, back_stencil_ref_, false, x, y, z, 0, 0};
497 draw.mesh = true; 497 draw.mesh = true;
498 check(list_.draw(std::move(draw))); 498 check(list_.draw(std::move(draw)));
@@ -1362,15 +1362,11 @@ private:
1362 if (!cbv_srv_uav_heap_) 1362 if (!cbv_srv_uav_heap_)
1363 note_once(compute ? "dispatch uses direct resource indexing with no CBV/SRV/UAV heap bound" 1363 note_once(compute ? "dispatch uses direct resource indexing with no CBV/SRV/UAV heap bound"
1364 : "draw uses direct resource indexing with no CBV/SRV/UAV heap bound"); 1364 : "draw uses direct resource indexing with no CBV/SRV/UAV heap bound");
1365 else if (!compute)
1366 note_once("draw uses direct resource indexing; graphics heap-base SGPR is not supplied");
1367 } 1365 }
1368 if (layout->flags & D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED) { 1366 if (layout->flags & D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED) {
1369 if (!sampler_heap_) 1367 if (!sampler_heap_)
1370 note_once(compute ? "dispatch uses direct sampler indexing with no sampler heap bound" 1368 note_once(compute ? "dispatch uses direct sampler indexing with no sampler heap bound"
1371 : "draw uses direct sampler indexing with no sampler heap bound"); 1369 : "draw uses direct sampler indexing with no sampler heap bound");
1372 else if (!compute)
1373 note_once("draw uses direct sampler indexing; graphics heap-base SGPR is not supplied");
1374 } 1370 }
1375 } 1371 }
1376 1372
@@ -1432,6 +1428,39 @@ private:
1432 return data; 1428 return data;
1433 } 1429 }
1434 1430
1431 // The graphics side of the same layout (RT-DIRECT-HEAP-GRAPHICS): with CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED the dword
1432 // after the graphics root arguments holds the resource heap's 32-bit address, and with
1433 // SAMPLER_HEAP_DIRECTLY_INDEXED the next one the sampler heap's; every directly indexed program of the retail
1434 // library reads them there, from s4 in compute, s8 in VS/PS/GS and s16 in mesh shaders (issue #14, comment
1435 // 7143020922). A mesh shader reads the same dwords through its window (+8). Not written when the signature has no
1436 // measured slot for them (graphics_arguments_end) or under LEONIDA_GRAPHICS_DIRECT_HEAPS=0.
1437 std::array<std::uint32_t, rt::rootsig::kMaxUserSgprs> graphics_user_data() const {
1438 note_direct_heap_indexing(graphics_.layout, false);
1439 auto data = graphics_.data;
1440 static const bool enabled = [] {
1441 char value[2]{};
1442 return GetEnvironmentVariableA("LEONIDA_GRAPHICS_DIRECT_HEAPS", value, 2) != 1 || value[0] != '0';
1443 }();
1444 const auto flags = graphics_.layout->flags;
1445 const bool direct = flags & (D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED |
1446 D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED);
1447 if (!enabled || !direct) return data;
1448 auto slot = graphics_.layout->graphics_arguments_end;
1449 if (slot == rt::rootsig::kNoSgpr) {
1450 note_once("draw uses direct heap indexing; its root signature has no measured slot for the heap addresses");
1451 return data;
1452 }
1453 if (flags & D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED) {
1454 if (slot < data.size()) data[slot++] = static_cast<std::uint32_t>(cbv_srv_uav_base_);
1455 else note_once("graphics root arguments leave no inline SGPR for the resource heap");
1456 }
1457 if (flags & D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED) {
1458 if (slot < data.size()) data[slot] = static_cast<std::uint32_t>(sampler_base_);
1459 else note_once("graphics root arguments leave no inline SGPR for the sampler heap");
1460 }
1461 return data;
1462 }
1463
1435 void record_dispatch(UINT x, UINT y, UINT z) { 1464 void record_dispatch(UINT x, UINT y, UINT z) {
1436 if (!compute_pipeline_ || !compute_.layout) return check(false); 1465 if (!compute_pipeline_ || !compute_.layout) return check(false);
1437 check(list_.dispatch({compute_pipeline_, compute_user_data(), x, y, z})); 1466 check(list_.dispatch({compute_pipeline_, compute_user_data(), x, y, z}));
@@ -1453,11 +1482,10 @@ private:
1453 // A draw needs a graphics pipeline, a graphics root signature and a topology. 1482 // A draw needs a graphics pipeline, a graphics root signature and a topology.
1454 void record_draw(bool indexed, UINT count, UINT instances, UINT first, INT base_vertex, UINT first_instance) { 1483 void record_draw(bool indexed, UINT count, UINT instances, UINT first, INT base_vertex, UINT first_instance) {
1455 if (!graphics_pipeline_ || !graphics_.layout || !topology_) return check(false); 1484 if (!graphics_pipeline_ || !graphics_.layout || !topology_) return check(false);
1456 note_direct_heap_indexing(graphics_.layout, false);
1457 // No viewport (never set, or unbound with RSSetViewports(0)) or an empty one: D3D12 rasterizes nothing, 1485 // No viewport (never set, or unbound with RSSetViewports(0)) or an empty one: D3D12 rasterizes nothing,
1458 // and Vulkan forbids a 0x0 viewport, so the draw is not recorded. 1486 // and Vulkan forbids a 0x0 viewport, so the draw is not recorded.
1459 if (!(viewport_.width > 0) || !(viewport_.height > 0)) return; 1487 if (!(viewport_.width > 0) || !(viewport_.height > 0)) return;
1460 leonida::Draw draw{graphics_pipeline_, graphics_.data, draw_views(), depth_, index_, topology_, viewport_, 1488 leonida::Draw draw{graphics_pipeline_, graphics_user_data(), draw_views(), depth_, index_, topology_, viewport_,
1461 scissor_, blend_factor_, front_stencil_ref_, back_stencil_ref_, indexed, count, instances, 1489 scissor_, blend_factor_, front_stencil_ref_, back_stencil_ref_, indexed, count, instances,
1462 first, base_vertex, first_instance}; 1490 first, base_vertex, first_instance};
1463 check(list_.draw(std::move(draw))); 1491 check(list_.draw(std::move(draw)));