diff options
| author | Mumogg <104529023+Mumogg@users.noreply.github.com> | 2026-11-23 15:21:22 -0600 |
|---|---|---|
| committer | Mumogg <104529023+Mumogg@users.noreply.github.com> | 2026-11-23 15:21:22 -0600 |
| commit | f9896e0fe580d8d8933eaa1ae59bd000b0ed7940 (patch) | |
| tree | e7395fb9a0e4947826a4193c03def282886c028c /runtime/shims/d3d12_com.cpp | |
| parent | 237f9e0ba83c8b8e740dd7bcc0e10d311fddb897 (diff) | |
| parent | 6d1f046da6083c623bf78f2438f37c988df6b3f8 (diff) | |
local: merge #9137 (slot 133 kept as on ladder-frame)
Diffstat (limited to 'runtime/shims/d3d12_com.cpp')
| -rw-r--r-- | runtime/shims/d3d12_com.cpp | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/runtime/shims/d3d12_com.cpp b/runtime/shims/d3d12_com.cpp index ca28ac6da..bf51da8e0 100644 --- a/runtime/shims/d3d12_com.cpp +++ b/runtime/shims/d3d12_com.cpp | |||
| @@ -7,13 +7,16 @@ | |||
| 7 | #include "d3d12_trace.h" | 7 | #include "d3d12_trace.h" |
| 8 | #include "d3d12_xs_device.h" | 8 | #include "d3d12_xs_device.h" |
| 9 | #include "../src/gfx10_descriptors.h" | 9 | #include "../src/gfx10_descriptors.h" |
| 10 | #include "../src/title_va_alias.h" | ||
| 10 | 11 | ||
| 11 | #include <algorithm> | 12 | #include <algorithm> |
| 12 | #include <array> | 13 | #include <array> |
| 13 | #include <atomic> | 14 | #include <atomic> |
| 14 | #include <bit> | 15 | #include <bit> |
| 16 | #include <chrono> | ||
| 15 | #include <condition_variable> | 17 | #include <condition_variable> |
| 16 | #include <functional> | 18 | #include <functional> |
| 19 | #include <map> | ||
| 17 | #include <memory> | 20 | #include <memory> |
| 18 | #include <optional> | 21 | #include <optional> |
| 19 | #include <cstdio> | 22 | #include <cstdio> |
| @@ -199,6 +202,8 @@ public: | |||
| 199 | } | 202 | } |
| 200 | 203 | ||
| 201 | const leonida::CommandList& commands() const { return list_; } | 204 | const leonida::CommandList& commands() const { return list_; } |
| 205 | // The descriptor tables this recording binds (console VAs), for the scan before a submission. | ||
| 206 | const std::vector<std::pair<std::uint64_t, std::uint32_t>>& tables() const { return tables_; } | ||
| 202 | // The pipeline states and root signatures the recording names (it holds a reference to each until Reset). | 207 | // The pipeline states and root signatures the recording names (it holds a reference to each until Reset). |
| 203 | const std::vector<IUnknown*>& pinned() const { return held_; } | 208 | const std::vector<IUnknown*>& pinned() const { return held_; } |
| 204 | UINT front_stencil_ref() const { return front_stencil_ref_; } | 209 | UINT front_stencil_ref() const { return front_stencil_ref_; } |
| @@ -235,6 +240,7 @@ public: | |||
| 235 | record_into(command_allocator); | 240 | record_into(command_allocator); |
| 236 | invalid_ = false; | 241 | invalid_ = false; |
| 237 | calls_.clear(); | 242 | calls_.clear(); |
| 243 | tables_.clear(); | ||
| 238 | release_held(); // what the old recording used: it was replayed at ExecuteCommandLists | 244 | release_held(); // what the old recording used: it was replayed at ExecuteCommandLists |
| 239 | reset_state(state); // Reset returns every list state to its default | 245 | reset_state(state); // Reset returns every list state to its default |
| 240 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE) set_initial_pipeline(state); // reset_state holds it | 246 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE) set_initial_pipeline(state); // reset_state holds it |
| @@ -1257,6 +1263,13 @@ private: | |||
| 1257 | return; | 1263 | return; |
| 1258 | const RootArgumentLayout::Parameter* p = parameter(state, index, type); | 1264 | const RootArgumentLayout::Parameter* p = parameter(state, index, type); |
| 1259 | if (!p) return; | 1265 | if (!p) return; |
| 1266 | // A root view into the title's own memory (a slot-133 buffer, a constant ring) gets the console VA of a GPU | ||
| 1267 | // copy of it, so the shader's heap_base + VA reaches it (src/title_va_alias.h). A descriptor table is in one | ||
| 1268 | // of the layer's heaps: kept, and its buffer V#s are rewritten the same way before each submission. | ||
| 1269 | if (type == rt::rootsig::ParamType::Descriptor) | ||
| 1270 | va = leonida::title_va_aliases().resolve(va, kRootViewBytes, leonida::TitleVaAliases::root_view); | ||
| 1271 | else if (va && p->table_descriptors && (tables_.empty() || tables_.back().first != va)) | ||
| 1272 | tables_.push_back({va, p->table_descriptors}); | ||
| 1260 | const std::uint32_t first = first_dword(state, *p); | 1273 | const std::uint32_t first = first_dword(state, *p); |
| 1261 | write(state, first, std::uint32_t(va)); | 1274 | write(state, first, std::uint32_t(va)); |
| 1262 | // In the compute layout a descriptor table is one dword, the 32-bit VA of its first descriptor (the heaps | 1275 | // In the compute layout a descriptor table is one dword, the 32-bit VA of its first descriptor (the heaps |
| @@ -1281,6 +1294,10 @@ private: | |||
| 1281 | std::uint32_t topology_ = 0; // D3D_PRIMITIVE_TOPOLOGY_UNDEFINED | 1294 | std::uint32_t topology_ = 0; // D3D_PRIMITIVE_TOPOLOGY_UNDEFINED |
| 1282 | std::array<leonida::VertexBufferView, D3D12_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT> vertex_buffers_{}; | 1295 | std::array<leonida::VertexBufferView, D3D12_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT> vertex_buffers_{}; |
| 1283 | leonida::IndexBufferView index_{}; | 1296 | leonida::IndexBufferView index_{}; |
| 1297 | // SetGraphicsRootDescriptorTable / SetComputeRootDescriptorTable: VA, CBV/SRV/UAV slots the signature declares | ||
| 1298 | std::vector<std::pair<std::uint64_t, std::uint32_t>> tables_; | ||
| 1299 | // The span a root view may read: D3D12's largest constant buffer (4096 x 16 bytes). | ||
| 1300 | static constexpr std::uint64_t kRootViewBytes = 65536; | ||
| 1284 | leonida::Viewport viewport_{}; | 1301 | leonida::Viewport viewport_{}; |
| 1285 | leonida::Rect scissor_{}; | 1302 | leonida::Rect scissor_{}; |
| 1286 | std::array<leonida::TargetView, D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT> render_targets_{}; | 1303 | std::array<leonida::TargetView, D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT> render_targets_{}; |
| @@ -1395,13 +1412,16 @@ private: | |||
| 1395 | 1412 | ||
| 1396 | void set_vertex_buffers(UINT start, UINT count, const D3D12_VERTEX_BUFFER_VIEW* views) { | 1413 | void set_vertex_buffers(UINT start, UINT count, const D3D12_VERTEX_BUFFER_VIEW* views) { |
| 1397 | if (count) draw_views_stale_ = true; | 1414 | if (count) draw_views_stale_ = true; |
| 1398 | for (UINT i = 0; i < count; ++i) | 1415 | for (UINT i = 0; i < count; ++i) { |
| 1416 | if (views) leonida::title_va_aliases().note(views[i].BufferLocation, leonida::TitleVaAliases::vertex_view); | ||
| 1399 | vertex_buffers_[start + i] = views ? leonida::VertexBufferView{views[i].BufferLocation, views[i].SizeInBytes, | 1417 | vertex_buffers_[start + i] = views ? leonida::VertexBufferView{views[i].BufferLocation, views[i].SizeInBytes, |
| 1400 | views[i].StrideInBytes} | 1418 | views[i].StrideInBytes} |
| 1401 | : leonida::VertexBufferView{}; | 1419 | : leonida::VertexBufferView{}; |
| 1420 | } | ||
| 1402 | } | 1421 | } |
| 1403 | 1422 | ||
| 1404 | void set_index_buffer(const D3D12_INDEX_BUFFER_VIEW* view) { | 1423 | void set_index_buffer(const D3D12_INDEX_BUFFER_VIEW* view) { |
| 1424 | if (view) leonida::title_va_aliases().note(view->BufferLocation, leonida::TitleVaAliases::index_view); | ||
| 1405 | index_ = view ? leonida::IndexBufferView{view->BufferLocation, view->SizeInBytes, u(view->Format)} | 1425 | index_ = view ? leonida::IndexBufferView{view->BufferLocation, view->SizeInBytes, u(view->Format)} |
| 1406 | : leonida::IndexBufferView{}; | 1426 | : leonida::IndexBufferView{}; |
| 1407 | } | 1427 | } |
| @@ -1652,6 +1672,21 @@ public: | |||
| 1652 | recorded.push_back(&list->commands()); | 1672 | recorded.push_back(&list->commands()); |
| 1653 | graphics.push_back(list); | 1673 | graphics.push_back(list); |
| 1654 | } | 1674 | } |
| 1675 | // Buffer V#s the title wrote into a bound table itself may name its own memory: rewritten to a GPU copy's | ||
| 1676 | // console VA before the copies are refreshed for this submission (src/title_va_alias.h). | ||
| 1677 | { | ||
| 1678 | std::map<std::uint64_t, std::uint32_t> tables; // each table once, with the most slots it was bound with | ||
| 1679 | for (const GraphicsCommandList* list : graphics) | ||
| 1680 | for (const auto& [table, descriptors] : list->tables()) | ||
| 1681 | tables[table] = std::max(tables[table], descriptors); | ||
| 1682 | if (!tables.empty()) { | ||
| 1683 | const auto start = std::chrono::steady_clock::now(); | ||
| 1684 | for (const auto& [table, descriptors] : tables) leonida::title_va_aliases().scan_table(table, descriptors); | ||
| 1685 | leonida::title_va_aliases().note_scan(std::uint64_t( | ||
| 1686 | std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now() - start) | ||
| 1687 | .count())); | ||
| 1688 | } | ||
| 1689 | } | ||
| 1655 | last_result_ = queue_.execute(recorded, [&graphics] { return pin_lists(graphics); }); | 1690 | last_result_ = queue_.execute(recorded, [&graphics] { return pin_lists(graphics); }); |
| 1656 | d3d12_trace::record(method, last_result_ == leonida::ReplayResult::success ? "ok" : "failed"); | 1691 | d3d12_trace::record(method, last_result_ == leonida::ReplayResult::success ? "ok" : "failed"); |
| 1657 | if (last_result_ != leonida::ReplayResult::success) | 1692 | if (last_result_ != leonida::ReplayResult::success) |