upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/test/queue_proxy_test.cpp
diff options
context:
space:
mode:
authorqhukz13 <v.onashchuk@gmail.com>2026-11-26 01:56:17 +0200
committerqhukz13 <v.onashchuk@gmail.com>2026-11-26 01:56:17 +0200
commit091d1095fe93bd19dad55c8977a55f09cd5ac2da (patch)
treefaa53d107182b1ce128887de9f05ae3cdb7a1592 /runtime/test/queue_proxy_test.cpp
parent93dc391dcaf2c3960fa61c83fa8036a878fe342d (diff)
parent33bd07cf86bb42236635c27341359b3fe841d1d5 (diff)
Merge main into cont/interp-ij-cfg
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/test/queue_proxy_test.cpp')
-rw-r--r--runtime/test/queue_proxy_test.cpp118
1 files changed, 100 insertions, 18 deletions
diff --git a/runtime/test/queue_proxy_test.cpp b/runtime/test/queue_proxy_test.cpp
index 3f46567f8..d1e09d39f 100644
--- a/runtime/test/queue_proxy_test.cpp
+++ b/runtime/test/queue_proxy_test.cpp
@@ -8,8 +8,9 @@
8// - heap, queue and fence proxies are unwrapped where the real runtime receives them (Signal/Wait, 8// - heap, queue and fence proxies are unwrapped where the real runtime receives them (Signal/Wait,
9// SetEventOnMultipleFenceCompletion, MakeResident/Evict/SetResidencyPriority/EnqueueMakeResident, 9// SetEventOnMultipleFenceCompletion, MakeResident/Evict/SetResidencyPriority/EnqueueMakeResident,
10// CreateSharedHandle), and OpenSharedHandle wraps a shared fence; 10// CreateSharedHandle), and OpenSharedHandle wraps a shared fence;
11// - slots past the public chain are refused (E_NOTIMPL) up to the end of the table, and a slot past the table 11// - slots past the public chain answer the console contract — a queue slot returns S_OK having signalled
12// faults on the vtable read in the guard region and is counted; 12// nothing (frame pacing flows through those methods), a fence slot is refused with E_NOTIMPL — and a
13// slot past either table faults on the vtable read in the guard region and is counted;
13// - calls from eight threads at once, and repeated device, queue and fence creation without leaks; 14// - calls from eight threads at once, and repeated device, queue and fence creation without leaks;
14// - the child-process runner of the differential check itself: large output, hangs, crashes, failed starts. 15// - the child-process runner of the differential check itself: large output, hangs, crashes, failed starts.
15// No shaders, game data or Xbox DLLs. LEONIDA_VK_VALIDATION=1 runs the Vulkan device under 16// No shaders, game data or Xbox DLLs. LEONIDA_VK_VALIDATION=1 runs the Vulkan device under
@@ -257,7 +258,9 @@ int check_slots(const Backend& b) {
257 } 258 }
258 } 259 }
259 260
260 // 10: ExecuteCommandLists passes the (real, not wrapped) command lists through. 261 // 10 and console slot 35: ExecuteCommandLists passes the (real, not wrapped) command lists through.
262 EXPECT(xs::queue_slot_overridden(35) && xs::queue_slot_overridden(14) && xs::queue_slot_overridden(15));
263 EXPECT(!xs::queue_slot_overridden(10) && !xs::queue_slot_overridden(34));
261 { 264 {
262 Ref<ID3D12CommandAllocator> allocator; 265 Ref<ID3D12CommandAllocator> allocator;
263 EXPECT(SUCCEEDED(device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, 266 EXPECT(SUCCEEDED(device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
@@ -272,6 +275,11 @@ int check_slots(const Backend& b) {
272 EXPECT(qhits(10) == before + 1); 275 EXPECT(qhits(10) == before + 1);
273 EXPECT(SUCCEEDED(queue->Signal(fence.p, 6))); 276 EXPECT(SUCCEEDED(queue->Signal(fence.p, 6)));
274 if (wait_for(label, fence.p, 6)) return 1; 277 if (wait_for(label, fence.p, 6)) return 1;
278 const std::uint64_t before35 = qhits(35);
279 EXPECT(raw_call(queue.p, 35, 1, reinterpret_cast<std::uint64_t>(lists)) == 0);
280 EXPECT(qhits(35) == before35 + 1 && xs::queue_slot_first_call_seen(35));
281 EXPECT(SUCCEEDED(queue->Signal(fence.p, 7)));
282 if (wait_for(label, fence.p, 7)) return 1;
275 if (b.vulkan) { 283 if (b.vulkan) {
276 // The layer's own helpers find their queue behind the proxy. 284 // The layer's own helpers find their queue behind the proxy.
277 EXPECT(rt::d3d12::last_execute_result(queue.p) == leonida::ReplayResult::success); 285 EXPECT(rt::d3d12::last_execute_result(queue.p) == leonida::ReplayResult::success);
@@ -293,17 +301,17 @@ int check_slots(const Backend& b) {
293 301
294 // 14/15: Signal and Wait take fence proxies; the real queue gets the real fences. 302 // 14/15: Signal and Wait take fence proxies; the real queue gets the real fences.
295 before = qhits(14); 303 before = qhits(14);
296 EXPECT(SUCCEEDED(queue->Signal(fence.p, 7))); 304 EXPECT(SUCCEEDED(queue->Signal(fence.p, 8)));
297 EXPECT(qhits(14) == before + 1); 305 EXPECT(qhits(14) == before + 1);
298 if (wait_for(label, fence.p, 7)) return 1; 306 if (wait_for(label, fence.p, 8)) return 1;
299 before = qhits(15); 307 before = qhits(15);
300 EXPECT(SUCCEEDED(queue->Wait(fence.p, 8))); // the queue waits until the CPU signals 8 308 EXPECT(SUCCEEDED(queue->Wait(fence.p, 9))); // the queue waits until the CPU signals 9
301 EXPECT(qhits(15) == before + 1); 309 EXPECT(qhits(15) == before + 1);
302 EXPECT(SUCCEEDED(queue->Signal(second.p, 1))); 310 EXPECT(SUCCEEDED(queue->Signal(second.p, 1)));
303 Sleep(50); 311 Sleep(50);
304 EXPECT(second->GetCompletedValue() == 0); // still held by the Wait 312 EXPECT(second->GetCompletedValue() == 0); // still held by the Wait
305 before = fhits(10); 313 before = fhits(10);
306 EXPECT(SUCCEEDED(fence->Signal(8))); // fence 10, from the CPU 314 EXPECT(SUCCEEDED(fence->Signal(9))); // fence 10, from the CPU
307 EXPECT(fhits(10) == before + 1); 315 EXPECT(fhits(10) == before + 1);
308 if (wait_for(label, second.p, 1)) return 1; 316 if (wait_for(label, second.p, 1)) return 1;
309 317
@@ -359,12 +367,12 @@ int check_slots(const Backend& b) {
359 EXPECT(fhits(7) == before + 1); 367 EXPECT(fhits(7) == before + 1);
360 } 368 }
361 before = fhits(8); 369 before = fhits(8);
362 EXPECT(fence->GetCompletedValue() == 8); 370 EXPECT(fence->GetCompletedValue() == 9);
363 EXPECT(fhits(8) == before + 1); 371 EXPECT(fhits(8) == before + 1);
364 { 372 {
365 Event done; 373 Event done;
366 before = fhits(9); 374 before = fhits(9);
367 EXPECT(SUCCEEDED(fence->SetEventOnCompletion(8, done.h)) && done.set_within(5000)); 375 EXPECT(SUCCEEDED(fence->SetEventOnCompletion(9, done.h)) && done.set_within(5000));
368 EXPECT(fhits(9) == before + 1); 376 EXPECT(fhits(9) == before + 1);
369 } 377 }
370 if (fence_slots == 12) { 378 if (fence_slots == 12) {
@@ -389,24 +397,60 @@ int check_slots(const Backend& b) {
389 } 397 }
390 } 398 }
391 399
392 // The refused tail: every slot from the end of the public chain to the end of the table. 400 // Fence slot 12 (value, descriptor, flags): the address of the completed value, which follows a queue's
401 // signal without another call (a wait on the real fence refreshes it).
402 {
403 before = fhits(12);
404 const auto* completed = reinterpret_cast<const volatile UINT64*>(raw_call(fence.p, 12, 9, 0, 0));
405 EXPECT(completed && *completed == fence->GetCompletedValue() && fhits(12) == before + 1);
406 EXPECT(SUCCEEDED(queue->Signal(fence.p, 9)));
407 bool seen = false;
408 for (int i = 0; i < 5000 && !seen; ++i) {
409 seen = *completed == 9;
410 if (!seen) Sleep(1);
411 }
412 EXPECT(seen);
413 EXPECT(raw_call(fence.p, 12, 9, 0, 0) == reinterpret_cast<std::uint64_t>(completed));
414 }
415
416 // The console queue tail answers S_OK instead of refusing: frame pacing flows through those
417 // methods, the contract xs_proxy_mock checks too. The two methods the proxy models — SignalX at
418 // 23 and PresentX at 30 on the older layout the 16/17 calls above pinned — are checked below.
419 // The fence tail below is still refused — nothing console-shaped was measured past its public chain.
420 // (Fence slot 12 is not part of that tail: it is served, above.)
421 // Queue slot 35 (the console ExecuteCommandLists variant) is not part of the tail either.
393 for (unsigned slot = 19; slot < xs::queue_proxy_table_size(); ++slot) { 422 for (unsigned slot = 19; slot < xs::queue_proxy_table_size(); ++slot) {
423 if (slot == 23 || slot == 30 || xs::queue_slot_overridden(slot)) continue;
394 before = qhits(slot); 424 before = qhits(slot);
395 EXPECT(as_hr(call_slot(queue.p, slot)) == E_NOTIMPL); 425 EXPECT(as_hr(call_slot(queue.p, slot)) == S_OK);
396 EXPECT(qhits(slot) == before + 1 && xs::queue_slot_first_call_seen(slot)); 426 EXPECT(qhits(slot) == before + 1 && xs::queue_slot_first_call_seen(slot));
397 } 427 }
428 // SignalX forwards to the real queue's Signal with the extra word dropped: the fence reaching 9
429 // proves the call was forwarded rather than swallowed by the console-tail answer.
430 before = qhits(23);
431 EXPECT(as_hr(raw_call(queue.p, 23, reinterpret_cast<std::uint64_t>(fence.p), 9)) == S_OK);
432 EXPECT(qhits(23) == before + 1 && xs::queue_slot_first_call_seen(23));
433 if (wait_for(label, fence.p, 9)) return 1;
434 // PresentX is handled by the presentation front end, not refused: its status is the swapchain's
435 // (a black frame on the test window, or S_OK where it cannot present), so anything but E_NOTIMPL
436 // shows the modelled path ran.
437 before = qhits(30);
438 EXPECT(as_hr(call_slot(queue.p, 30)) != E_NOTIMPL);
439 EXPECT(qhits(30) == before + 1 && xs::queue_slot_first_call_seen(30));
398 for (unsigned slot = fence_slots; slot < xs::fence_proxy_table_size(); ++slot) { 440 for (unsigned slot = fence_slots; slot < xs::fence_proxy_table_size(); ++slot) {
441 if (slot == 12) continue;
399 before = fhits(slot); 442 before = fhits(slot);
400 EXPECT(as_hr(call_slot(fence.p, slot)) == E_NOTIMPL); 443 EXPECT(as_hr(call_slot(fence.p, slot)) == E_NOTIMPL);
401 EXPECT(fhits(slot) == before + 1 && xs::fence_slot_first_call_seen(slot)); 444 EXPECT(fhits(slot) == before + 1 && xs::fence_slot_first_call_seen(slot));
402 } 445 }
403 // The objects still work after refused calls. 446 // The objects still work after the console-only calls.
404 EXPECT(SUCCEEDED(queue->Signal(fence.p, 10))); 447 EXPECT(SUCCEEDED(queue->Signal(fence.p, 10)));
405 if (wait_for(label, fence.p, 10)) return 1; 448 if (wait_for(label, fence.p, 10)) return 1;
406 EXPECT(xs::command_object_proxy_ref_count(queue.p) == 1 && xs::command_object_proxy_ref_count(fence.p) == 1); 449 EXPECT(xs::command_object_proxy_ref_count(queue.p) == 1 && xs::command_object_proxy_ref_count(fence.p) == 1);
407 } 450 }
408 EXPECT(xs::device_proxy_ref_count(device) == device_refs); // every queue and fence gave its reference back 451 EXPECT(xs::device_proxy_ref_count(device) == device_refs); // every queue and fence gave its reference back
409 std::printf("%s: every public queue and fence slot forwarded and counted; tail refused\n", label); 452 std::printf("%s: every public queue and fence slot forwarded and counted; fence slot 12 follows a queue "
453 "signal; queue tail S_OK, fence tail refused\n", label);
410 return 0; 454 return 0;
411} 455}
412 456
@@ -1460,18 +1504,56 @@ int check_xbox_client(const Backend& b) {
1460 EXPECT(same); // the GPU really ran the list the queue proxy submitted 1504 EXPECT(same); // the GPU really ran the list the queue proxy submitted
1461 } 1505 }
1462 1506
1463 // Device slot 50: EnqueueMakeResident with the objects and a fence proxy to signal. 1507 // Second copy with fresh bytes, submitted through console ExecuteCommandLists slot 35.
1464 EXPECT(SUCCEEDED(as_hr(raw(device, 50, D3D12_RESIDENCY_FLAG_NONE, 4, word(pageables), word(fence.p), 2)))); 1508 {
1509 std::uint8_t* bytes = nullptr;
1510 EXPECT(SUCCEEDED(upload->Map(0, nullptr, reinterpret_cast<void**>(&bytes))));
1511 for (UINT64 i = 0; i < kBytes; ++i) bytes[i] = static_cast<std::uint8_t>(i * 11 + 5);
1512 upload->Unmap(0, nullptr);
1513 }
1514 EXPECT(SUCCEEDED(allocator->Reset()));
1515 EXPECT(SUCCEEDED(list->Reset(allocator.p, nullptr)));
1516 D3D12_RESOURCE_BARRIER to_dest{};
1517 to_dest.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
1518 to_dest.Transition.pResource = gpu.p;
1519 to_dest.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
1520 to_dest.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_SOURCE;
1521 to_dest.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_DEST;
1522 list->ResourceBarrier(1, &to_dest);
1523 list->CopyBufferRegion(gpu.p, 0, upload.p, 0, kBytes);
1524 D3D12_RESOURCE_BARRIER to_source = to_dest;
1525 to_source.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST;
1526 to_source.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_SOURCE;
1527 list->ResourceBarrier(1, &to_source);
1528 list->CopyBufferRegion(readback.p, 0, gpu.p, 0, kBytes);
1529 EXPECT(SUCCEEDED(list->Close()));
1530 EXPECT(raw(queue.p, 35, 1, word(lists)) == 0);
1531 EXPECT(SUCCEEDED(as_hr(raw(queue.p, 14, word(fence.p), 2))));
1465 EXPECT(SUCCEEDED(as_hr(raw(fence.p, 9, 2, word(done.h)))) && done.set_within(5000)); 1532 EXPECT(SUCCEEDED(as_hr(raw(fence.p, 9, 2, word(done.h)))) && done.set_within(5000));
1533 EXPECT(raw(fence.p, 8) >= 2);
1534 {
1535 std::uint8_t* bytes = nullptr;
1536 const D3D12_RANGE read_range{0, kBytes};
1537 EXPECT(SUCCEEDED(readback->Map(0, &read_range, reinterpret_cast<void**>(&bytes))));
1538 bool same = true;
1539 for (UINT64 i = 0; i < kBytes; ++i) same = same && bytes[i] == static_cast<std::uint8_t>(i * 11 + 5);
1540 const D3D12_RANGE nothing{0, 0};
1541 readback->Unmap(0, &nothing);
1542 EXPECT(same); // the GPU really ran the list submitted via queue slot 35
1543 }
1544
1545 // Device slot 50: EnqueueMakeResident with the objects and a fence proxy to signal.
1546 EXPECT(SUCCEEDED(as_hr(raw(device, 50, D3D12_RESIDENCY_FLAG_NONE, 4, word(pageables), word(fence.p), 3))));
1547 EXPECT(SUCCEEDED(as_hr(raw(fence.p, 9, 3, word(done.h)))) && done.set_within(5000));
1466 1548
1467 // Queue slot 15 holds the queue until the CPU (fence slot 10) signals; device slot 45 then sees both fences. 1549 // Queue slot 15 holds the queue until the CPU (fence slot 10) signals; device slot 45 then sees both fences.
1468 EXPECT(SUCCEEDED(as_hr(raw(queue.p, 15, word(fence.p), 3)))); 1550 EXPECT(SUCCEEDED(as_hr(raw(queue.p, 15, word(fence.p), 4))));
1469 EXPECT(SUCCEEDED(as_hr(raw(queue.p, 14, word(second.p), 1)))); 1551 EXPECT(SUCCEEDED(as_hr(raw(queue.p, 14, word(second.p), 1))));
1470 Sleep(50); 1552 Sleep(50);
1471 EXPECT(raw(second.p, 8) == 0); 1553 EXPECT(raw(second.p, 8) == 0);
1472 EXPECT(SUCCEEDED(as_hr(raw(fence.p, 10, 3)))); 1554 EXPECT(SUCCEEDED(as_hr(raw(fence.p, 10, 4))));
1473 ID3D12Fence* both[] = {fence.p, second.p}; 1555 ID3D12Fence* both[] = {fence.p, second.p};
1474 const UINT64 values[] = {3, 1}; 1556 const UINT64 values[] = {4, 1};
1475 EXPECT(SUCCEEDED(as_hr(raw(device, 45, word(both), word(values), 2, D3D12_MULTIPLE_FENCE_WAIT_FLAG_ALL, 1557 EXPECT(SUCCEEDED(as_hr(raw(device, 45, word(both), word(values), 2, D3D12_MULTIPLE_FENCE_WAIT_FLAG_ALL,
1476 word(done.h)))) && 1558 word(done.h)))) &&
1477 done.set_within(5000)); 1559 done.set_within(5000));