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:
Diffstat (limited to 'runtime/test/queue_proxy_test.cpp')
-rw-r--r--runtime/test/queue_proxy_test.cpp86
1 files changed, 65 insertions, 21 deletions
diff --git a/runtime/test/queue_proxy_test.cpp b/runtime/test/queue_proxy_test.cpp
index ece44f117..d1e09d39f 100644
--- a/runtime/test/queue_proxy_test.cpp
+++ b/runtime/test/queue_proxy_test.cpp
@@ -258,7 +258,9 @@ int check_slots(const Backend& b) {
258 } 258 }
259 } 259 }
260 260
261 // 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));
262 { 264 {
263 Ref<ID3D12CommandAllocator> allocator; 265 Ref<ID3D12CommandAllocator> allocator;
264 EXPECT(SUCCEEDED(device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, 266 EXPECT(SUCCEEDED(device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
@@ -273,6 +275,11 @@ int check_slots(const Backend& b) {
273 EXPECT(qhits(10) == before + 1); 275 EXPECT(qhits(10) == before + 1);
274 EXPECT(SUCCEEDED(queue->Signal(fence.p, 6))); 276 EXPECT(SUCCEEDED(queue->Signal(fence.p, 6)));
275 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;
276 if (b.vulkan) { 283 if (b.vulkan) {
277 // The layer's own helpers find their queue behind the proxy. 284 // The layer's own helpers find their queue behind the proxy.
278 EXPECT(rt::d3d12::last_execute_result(queue.p) == leonida::ReplayResult::success); 285 EXPECT(rt::d3d12::last_execute_result(queue.p) == leonida::ReplayResult::success);
@@ -294,17 +301,17 @@ int check_slots(const Backend& b) {
294 301
295 // 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.
296 before = qhits(14); 303 before = qhits(14);
297 EXPECT(SUCCEEDED(queue->Signal(fence.p, 7))); 304 EXPECT(SUCCEEDED(queue->Signal(fence.p, 8)));
298 EXPECT(qhits(14) == before + 1); 305 EXPECT(qhits(14) == before + 1);
299 if (wait_for(label, fence.p, 7)) return 1; 306 if (wait_for(label, fence.p, 8)) return 1;
300 before = qhits(15); 307 before = qhits(15);
301 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
302 EXPECT(qhits(15) == before + 1); 309 EXPECT(qhits(15) == before + 1);
303 EXPECT(SUCCEEDED(queue->Signal(second.p, 1))); 310 EXPECT(SUCCEEDED(queue->Signal(second.p, 1)));
304 Sleep(50); 311 Sleep(50);
305 EXPECT(second->GetCompletedValue() == 0); // still held by the Wait 312 EXPECT(second->GetCompletedValue() == 0); // still held by the Wait
306 before = fhits(10); 313 before = fhits(10);
307 EXPECT(SUCCEEDED(fence->Signal(8))); // fence 10, from the CPU 314 EXPECT(SUCCEEDED(fence->Signal(9))); // fence 10, from the CPU
308 EXPECT(fhits(10) == before + 1); 315 EXPECT(fhits(10) == before + 1);
309 if (wait_for(label, second.p, 1)) return 1; 316 if (wait_for(label, second.p, 1)) return 1;
310 317
@@ -360,12 +367,12 @@ int check_slots(const Backend& b) {
360 EXPECT(fhits(7) == before + 1); 367 EXPECT(fhits(7) == before + 1);
361 } 368 }
362 before = fhits(8); 369 before = fhits(8);
363 EXPECT(fence->GetCompletedValue() == 8); 370 EXPECT(fence->GetCompletedValue() == 9);
364 EXPECT(fhits(8) == before + 1); 371 EXPECT(fhits(8) == before + 1);
365 { 372 {
366 Event done; 373 Event done;
367 before = fhits(9); 374 before = fhits(9);
368 EXPECT(SUCCEEDED(fence->SetEventOnCompletion(8, done.h)) && done.set_within(5000)); 375 EXPECT(SUCCEEDED(fence->SetEventOnCompletion(9, done.h)) && done.set_within(5000));
369 EXPECT(fhits(9) == before + 1); 376 EXPECT(fhits(9) == before + 1);
370 } 377 }
371 if (fence_slots == 12) { 378 if (fence_slots == 12) {
@@ -390,10 +397,6 @@ int check_slots(const Backend& b) {
390 } 397 }
391 } 398 }
392 399
393 // The console queue tail answers S_OK instead of refusing: frame pacing flows through those
394 // methods, the contract xs_proxy_mock checks too. The two methods the proxy models — SignalX at
395 // 23 and PresentX at 30 on the older layout the 16/17 calls above pinned — are checked below.
396 // The fence tail below is still refused — nothing console-shaped was measured past its public chain.
397 // Fence slot 12 (value, descriptor, flags): the address of the completed value, which follows a queue's 400 // Fence slot 12 (value, descriptor, flags): the address of the completed value, which follows a queue's
398 // signal without another call (a wait on the real fence refreshes it). 401 // signal without another call (a wait on the real fence refreshes it).
399 { 402 {
@@ -410,9 +413,14 @@ int check_slots(const Backend& b) {
410 EXPECT(raw_call(fence.p, 12, 9, 0, 0) == reinterpret_cast<std::uint64_t>(completed)); 413 EXPECT(raw_call(fence.p, 12, 9, 0, 0) == reinterpret_cast<std::uint64_t>(completed));
411 } 414 }
412 415
413 // The refused tail: every slot from the end of the public chain to the end of the table, but fence slot 12. 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.
414 for (unsigned slot = 19; slot < xs::queue_proxy_table_size(); ++slot) { 422 for (unsigned slot = 19; slot < xs::queue_proxy_table_size(); ++slot) {
415 if (slot == 23 || slot == 30) continue; 423 if (slot == 23 || slot == 30 || xs::queue_slot_overridden(slot)) continue;
416 before = qhits(slot); 424 before = qhits(slot);
417 EXPECT(as_hr(call_slot(queue.p, slot)) == S_OK); 425 EXPECT(as_hr(call_slot(queue.p, slot)) == S_OK);
418 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));
@@ -441,10 +449,8 @@ int check_slots(const Backend& b) {
441 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);
442 } 450 }
443 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
444 std::printf("%s: every public queue and fence slot forwarded and counted; queue tail S_OK, fence tail "
445 "refused\n", label);
446 std::printf("%s: every public queue and fence slot forwarded and counted; fence slot 12 follows a queue " 452 std::printf("%s: every public queue and fence slot forwarded and counted; fence slot 12 follows a queue "
447 "signal; tail refused\n", label); 453 "signal; queue tail S_OK, fence tail refused\n", label);
448 return 0; 454 return 0;
449} 455}
450 456
@@ -1498,18 +1504,56 @@ int check_xbox_client(const Backend& b) {
1498 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
1499 } 1505 }
1500 1506
1501 // 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.
1502 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))));
1503 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));
1504 1548
1505 // 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.
1506 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))));
1507 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))));
1508 Sleep(50); 1552 Sleep(50);
1509 EXPECT(raw(second.p, 8) == 0); 1553 EXPECT(raw(second.p, 8) == 0);
1510 EXPECT(SUCCEEDED(as_hr(raw(fence.p, 10, 3)))); 1554 EXPECT(SUCCEEDED(as_hr(raw(fence.p, 10, 4))));
1511 ID3D12Fence* both[] = {fence.p, second.p}; 1555 ID3D12Fence* both[] = {fence.p, second.p};
1512 const UINT64 values[] = {3, 1}; 1556 const UINT64 values[] = {4, 1};
1513 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,
1514 word(done.h)))) && 1558 word(done.h)))) &&
1515 done.set_within(5000)); 1559 done.set_within(5000));