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:
Diffstat (limited to 'runtime/shims/d3d12_com.cpp')
-rw-r--r--runtime/shims/d3d12_com.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/runtime/shims/d3d12_com.cpp b/runtime/shims/d3d12_com.cpp
index 6e718cee7..1ad12e432 100644
--- a/runtime/shims/d3d12_com.cpp
+++ b/runtime/shims/d3d12_com.cpp
@@ -12,8 +12,10 @@
12#include <array> 12#include <array>
13#include <atomic> 13#include <atomic>
14#include <bit> 14#include <bit>
15#include <chrono>
15#include <condition_variable> 16#include <condition_variable>
16#include <functional> 17#include <functional>
18#include <map>
17#include <memory> 19#include <memory>
18#include <optional> 20#include <optional>
19#include <cstdio> 21#include <cstdio>
@@ -200,7 +202,7 @@ public:
200 202
201 const leonida::CommandList& commands() const { return list_; } 203 const leonida::CommandList& commands() const { return list_; }
202 // The descriptor tables this recording binds (console VAs), for the scan before a submission. 204 // The descriptor tables this recording binds (console VAs), for the scan before a submission.
203 const std::vector<std::uint64_t>& tables() const { return tables_; } 205 const std::vector<std::pair<std::uint64_t, std::uint32_t>>& tables() const { return tables_; }
204 // The pipeline states and root signatures the recording names (it holds a reference to each until Reset). 206 // The pipeline states and root signatures the recording names (it holds a reference to each until Reset).
205 const std::vector<IUnknown*>& pinned() const { return held_; } 207 const std::vector<IUnknown*>& pinned() const { return held_; }
206 UINT front_stencil_ref() const { return front_stencil_ref_; } 208 UINT front_stencil_ref() const { return front_stencil_ref_; }
@@ -1176,8 +1178,8 @@ private:
1176 // of the layer's heaps: kept, and its buffer V#s are rewritten the same way before each submission. 1178 // of the layer's heaps: kept, and its buffer V#s are rewritten the same way before each submission.
1177 if (type == rt::rootsig::ParamType::Descriptor) 1179 if (type == rt::rootsig::ParamType::Descriptor)
1178 va = leonida::title_va_aliases().resolve(va, kRootViewBytes, leonida::TitleVaAliases::root_view); 1180 va = leonida::title_va_aliases().resolve(va, kRootViewBytes, leonida::TitleVaAliases::root_view);
1179 else if (va && (tables_.empty() || tables_.back() != va)) 1181 else if (va && p->table_descriptors && (tables_.empty() || tables_.back().first != va))
1180 tables_.push_back(va); 1182 tables_.push_back({va, p->table_descriptors});
1181 const std::uint32_t first = first_dword(state, *p); 1183 const std::uint32_t first = first_dword(state, *p);
1182 write(state, first, std::uint32_t(va)); 1184 write(state, first, std::uint32_t(va));
1183 // In the compute layout a descriptor table is one dword, the 32-bit VA of its first descriptor (the heaps 1185 // In the compute layout a descriptor table is one dword, the 32-bit VA of its first descriptor (the heaps
@@ -1202,7 +1204,8 @@ private:
1202 std::uint32_t topology_ = 0; // D3D_PRIMITIVE_TOPOLOGY_UNDEFINED 1204 std::uint32_t topology_ = 0; // D3D_PRIMITIVE_TOPOLOGY_UNDEFINED
1203 std::array<leonida::VertexBufferView, D3D12_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT> vertex_buffers_{}; 1205 std::array<leonida::VertexBufferView, D3D12_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT> vertex_buffers_{};
1204 leonida::IndexBufferView index_{}; 1206 leonida::IndexBufferView index_{};
1205 std::vector<std::uint64_t> tables_; // SetGraphicsRootDescriptorTable / SetComputeRootDescriptorTable VAs 1207 // SetGraphicsRootDescriptorTable / SetComputeRootDescriptorTable: VA, CBV/SRV/UAV slots the signature declares
1208 std::vector<std::pair<std::uint64_t, std::uint32_t>> tables_;
1206 // The span a root view may read: D3D12's largest constant buffer (4096 x 16 bytes). 1209 // The span a root view may read: D3D12's largest constant buffer (4096 x 16 bytes).
1207 static constexpr std::uint64_t kRootViewBytes = 65536; 1210 static constexpr std::uint64_t kRootViewBytes = 65536;
1208 leonida::Viewport viewport_{}; 1211 leonida::Viewport viewport_{};
@@ -1582,10 +1585,17 @@ public:
1582 // Buffer V#s the title wrote into a bound table itself may name its own memory: rewritten to a GPU copy's 1585 // Buffer V#s the title wrote into a bound table itself may name its own memory: rewritten to a GPU copy's
1583 // console VA before the copies are refreshed for this submission (src/title_va_alias.h). 1586 // console VA before the copies are refreshed for this submission (src/title_va_alias.h).
1584 { 1587 {
1585 std::set<std::uint64_t> scanned; 1588 std::map<std::uint64_t, std::uint32_t> tables; // each table once, with the most slots it was bound with
1586 for (const GraphicsCommandList* list : graphics) 1589 for (const GraphicsCommandList* list : graphics)
1587 for (const std::uint64_t table : list->tables()) 1590 for (const auto& [table, descriptors] : list->tables())
1588 if (scanned.insert(table).second) leonida::title_va_aliases().scan_table(table); 1591 tables[table] = std::max(tables[table], descriptors);
1592 if (!tables.empty()) {
1593 const auto start = std::chrono::steady_clock::now();
1594 for (const auto& [table, descriptors] : tables) leonida::title_va_aliases().scan_table(table, descriptors);
1595 leonida::title_va_aliases().note_scan(std::uint64_t(
1596 std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now() - start)
1597 .count()));
1598 }
1589 } 1599 }
1590 last_result_ = queue_.execute(recorded, [&graphics] { return pin_lists(graphics); }); 1600 last_result_ = queue_.execute(recorded, [&graphics] { return pin_lists(graphics); });
1591 d3d12_trace::record(method, last_result_ == leonida::ReplayResult::success ? "ok" : "failed"); 1601 d3d12_trace::record(method, last_result_ == leonida::ReplayResult::success ? "ok" : "failed");