upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/shims
diff options
context:
space:
mode:
authorItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 23:06:28 -0500
committerItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 23:06:28 -0500
commit95b2e2c8bd7d20019231eda0007628fa2f2b5350 (patch)
tree588294b0fe61c6a9d21ada1f56277d000a4d47d6 /runtime/shims
parent1af1f9e39344ca73bfec9a0e3536fa4254a00b13 (diff)
parent003baa94c1fcba61e324dbeb947e8bd401f4f837 (diff)
Merge pull request #2951 from AlxcBTW
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/shims')
-rw-r--r--runtime/shims/d3d12_com.cpp42
1 files changed, 37 insertions, 5 deletions
diff --git a/runtime/shims/d3d12_com.cpp b/runtime/shims/d3d12_com.cpp
index 77a5bed87..55f1cb65d 100644
--- a/runtime/shims/d3d12_com.cpp
+++ b/runtime/shims/d3d12_com.cpp
@@ -197,6 +197,8 @@ public:
197 } 197 }
198 198
199 const leonida::CommandList& commands() const { return list_; } 199 const leonida::CommandList& commands() const { return list_; }
200 // The pipeline states and root signatures the recording names (it holds a reference to each until Reset).
201 const std::vector<IUnknown*>& pinned() const { return held_; }
200 UINT front_stencil_ref() const { return front_stencil_ref_; } 202 UINT front_stencil_ref() const { return front_stencil_ref_; }
201 UINT back_stencil_ref() const { return back_stencil_ref_; } 203 UINT back_stencil_ref() const { return back_stencil_ref_; }
202 204
@@ -1263,6 +1265,30 @@ public:
1263 // {e1a85d76-0b3f-4c29-a7d4-58f2c6e0b913} 1265 // {e1a85d76-0b3f-4c29-a7d4-58f2c6e0b913}
1264 static constexpr GUID kTag{0xe1a85d76, 0x0b3f, 0x4c29, {0xa7, 0xd4, 0x58, 0xf2, 0xc6, 0xe0, 0xb9, 0x13}}; 1266 static constexpr GUID kTag{0xe1a85d76, 0x0b3f, 0x4c29, {0xa7, 0xd4, 0x58, 0xf2, 0xc6, 0xe0, 0xb9, 0x13}};
1265 1267
1268 // What a held batch (queue_holds.h) keeps alive until it has run: the pipeline states and root signatures its
1269 // lists name, which the application may release and Reset away as soon as ExecuteCommandLists returns. Resources
1270 // are not held (a D3D12 application keeps them until the fence it signals; the docs, section 4.4, list this).
1271 static std::shared_ptr<void> pin_lists(const std::vector<const GraphicsCommandList*>& lists) {
1272 auto objects = std::shared_ptr<std::vector<IUnknown*>>(new std::vector<IUnknown*>, [](auto* held) {
1273 for (IUnknown* object : *held) object->Release();
1274 delete held;
1275 });
1276 for (const GraphicsCommandList* list : lists)
1277 for (IUnknown* object : list->pinned()) {
1278 object->AddRef();
1279 objects->push_back(object);
1280 }
1281 return objects;
1282 }
1283
1284 // A D3D12 queue holds the fences it waits on and signals until the work has been submitted.
1285 static leonida::VulkanQueue::PinFn fence_pin(ID3D12Fence* fence) {
1286 return [fence]() -> std::shared_ptr<void> {
1287 fence->AddRef();
1288 return std::shared_ptr<void>(fence, [](void* held) { static_cast<ID3D12Fence*>(held)->Release(); });
1289 };
1290 }
1291
1266 static leonida::VulkanQueue::QueueKind queue_kind_for(D3D12_COMMAND_LIST_TYPE type) { 1292 static leonida::VulkanQueue::QueueKind queue_kind_for(D3D12_COMMAND_LIST_TYPE type) {
1267 if (type == D3D12_COMMAND_LIST_TYPE_COPY) return leonida::VulkanQueue::QueueKind::copy; 1293 if (type == D3D12_COMMAND_LIST_TYPE_COPY) return leonida::VulkanQueue::QueueKind::copy;
1268 if (type == D3D12_COMMAND_LIST_TYPE_COMPUTE) return leonida::VulkanQueue::QueueKind::compute; 1294 if (type == D3D12_COMMAND_LIST_TYPE_COMPUTE) return leonida::VulkanQueue::QueueKind::compute;
@@ -1283,7 +1309,11 @@ public:
1283 } 1309 }
1284 1310
1285 bool ok() const { return queue_.ok(); } 1311 bool ok() const { return queue_.ok(); }
1286 leonida::ReplayResult last_result() const { return last_result_; } 1312 leonida::ReplayResult last_result() {
1313 // A batch the queue held fails when it is released, after the call returned: the failure is the result.
1314 if (const auto held = queue_.take_held_failure(); held != leonida::ReplayResult::success) last_result_ = held;
1315 return last_result_;
1316 }
1287 1317
1288 D3D12_COMMAND_QUEUE_DESC STDMETHODCALLTYPE GetDesc() override { 1318 D3D12_COMMAND_QUEUE_DESC STDMETHODCALLTYPE GetDesc() override {
1289 d3d12_trace::record("ID3D12CommandQueue::GetDesc"); 1319 d3d12_trace::record("ID3D12CommandQueue::GetDesc");
@@ -1296,6 +1326,7 @@ public:
1296 constexpr auto method = "ID3D12CommandQueue::ExecuteCommandLists"; 1326 constexpr auto method = "ID3D12CommandQueue::ExecuteCommandLists";
1297 std::lock_guard lock(mutex_); 1327 std::lock_guard lock(mutex_);
1298 std::vector<const leonida::CommandList*> recorded; 1328 std::vector<const leonida::CommandList*> recorded;
1329 std::vector<const GraphicsCommandList*> graphics;
1299 for (UINT i = 0; i < count; ++i) { 1330 for (UINT i = 0; i < count; ++i) {
1300 const GraphicsCommandList* list = GraphicsCommandList::from(lists[i]); 1331 const GraphicsCommandList* list = GraphicsCommandList::from(lists[i]);
1301 if (!list || list->type() == D3D12_COMMAND_LIST_TYPE_BUNDLE) { 1332 if (!list || list->type() == D3D12_COMMAND_LIST_TYPE_BUNDLE) {
@@ -1310,8 +1341,9 @@ public:
1310 return; 1341 return;
1311 } 1342 }
1312 recorded.push_back(&list->commands()); 1343 recorded.push_back(&list->commands());
1344 graphics.push_back(list);
1313 } 1345 }
1314 last_result_ = queue_.execute(recorded); 1346 last_result_ = queue_.execute(recorded, [&graphics] { return pin_lists(graphics); });
1315 d3d12_trace::record(method, last_result_ == leonida::ReplayResult::success ? "ok" : "failed"); 1347 d3d12_trace::record(method, last_result_ == leonida::ReplayResult::success ? "ok" : "failed");
1316 if (last_result_ != leonida::ReplayResult::success) 1348 if (last_result_ != leonida::ReplayResult::success)
1317 std::fprintf(stderr, "[rt] d3d12: ExecuteCommandLists failed: %s; nothing was submitted\n", 1349 std::fprintf(stderr, "[rt] d3d12: ExecuteCommandLists failed: %s; nothing was submitted\n",
@@ -1369,7 +1401,7 @@ public:
1369 if (!f) return d3d12_trace::result(method, E_INVALIDARG); 1401 if (!f) return d3d12_trace::result(method, E_INVALIDARG);
1370 std::lock_guard lock(mutex_); 1402 std::lock_guard lock(mutex_);
1371 if (!f->claim(value, true)) return d3d12_trace::result(method, S_OK); 1403 if (!f->claim(value, true)) return d3d12_trace::result(method, S_OK);
1372 return d3d12_trace::result(method, queue_.signal(f->semaphore(), value) ? S_OK : E_FAIL); 1404 return d3d12_trace::result(method, queue_.signal(f->semaphore(), value, fence_pin(fence)) ? S_OK : E_FAIL);
1373 } 1405 }
1374 1406
1375 HRESULT STDMETHODCALLTYPE Wait(ID3D12Fence* fence, UINT64 value) override { 1407 HRESULT STDMETHODCALLTYPE Wait(ID3D12Fence* fence, UINT64 value) override {
@@ -1377,7 +1409,7 @@ public:
1377 Fence* f = Fence::from(fence); 1409 Fence* f = Fence::from(fence);
1378 if (!f) return d3d12_trace::result(method, E_INVALIDARG); 1410 if (!f) return d3d12_trace::result(method, E_INVALIDARG);
1379 std::lock_guard lock(mutex_); 1411 std::lock_guard lock(mutex_);
1380 queue_.wait(f->semaphore(), value); 1412 queue_.wait(f->semaphore(), value, fence_pin(fence));
1381 return d3d12_trace::result(method, S_OK); 1413 return d3d12_trace::result(method, S_OK);
1382 } 1414 }
1383 1415
@@ -1713,7 +1745,7 @@ bool command_signature_info(ID3D12CommandSignature* signature, leonida::Indirect
1713 1745
1714leonida::ReplayResult last_execute_result(ID3D12CommandQueue* queue) { 1746leonida::ReplayResult last_execute_result(ID3D12CommandQueue* queue) {
1715 if (ID3D12CommandQueue* real = d3d12_xs::queue_proxy_real_queue(queue)) queue = real; // the Xbox-ABI proxy 1747 if (ID3D12CommandQueue* real = d3d12_xs::queue_proxy_real_queue(queue)) queue = real; // the Xbox-ABI proxy
1716 const CommandQueue* q = CommandQueue::from(queue); 1748 CommandQueue* q = CommandQueue::from(queue);
1717 return q ? q->last_result() : leonida::ReplayResult::unsupported; 1749 return q ? q->last_result() : leonida::ReplayResult::unsupported;
1718} 1750}
1719 1751