upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/test/d3d12_queue_wait_test.cpp
diff options
context:
space:
mode:
authorVonsek <45567075+Vonsek@users.noreply.github.com>2026-11-22 15:51:40 +0100
committerVonsek <45567075+Vonsek@users.noreply.github.com>2026-11-22 15:51:40 +0100
commitdf91c6624b69ee4e6c6eeca20ed68d331ed0e728 (patch)
tree323c88b9df89bf8abaa2b98d10808474ab675dc2 /runtime/test/d3d12_queue_wait_test.cpp
parentb40d8039a98f57b26bd05860febbabbe59b97873 (diff)
parent6a6704df1592e1dc4a3215ddf1423a78adb52045 (diff)
Merge main into test/valu-int-misc (#1492)
Conflicted files: runtime/test/shaders/check.py, scripts/run_gpu_tests.py AI-assisted.
Diffstat (limited to 'runtime/test/d3d12_queue_wait_test.cpp')
-rw-r--r--runtime/test/d3d12_queue_wait_test.cpp38
1 files changed, 28 insertions, 10 deletions
diff --git a/runtime/test/d3d12_queue_wait_test.cpp b/runtime/test/d3d12_queue_wait_test.cpp
index d1a868a25..3dfb1bad3 100644
--- a/runtime/test/d3d12_queue_wait_test.cpp
+++ b/runtime/test/d3d12_queue_wait_test.cpp
@@ -1,7 +1,9 @@
1// D3D-97: cross-queue Wait-before-Signal must make progress. No game files. 1// D3D-97: cross-queue Wait-before-Signal must make progress. No game files.
2#include "../shims/d3d12_com.h" 2#include "../shims/d3d12_com.h"
3 3
4#include <cstdlib>
4#include <cstdio> 5#include <cstdio>
6#include <cstring>
5 7
6namespace { 8namespace {
7template<class T> struct Ref { 9template<class T> struct Ref {
@@ -10,19 +12,35 @@ template<class T> struct Ref {
10 T* operator->() const { return p; } 12 T* operator->() const { return p; }
11}; 13};
12 14
13bool wait_for(ID3D12Fence* fence, UINT64 value) { 15bool wait_for(ID3D12Fence* fence, UINT64 value, DWORD timeout_ms = 3000) {
14 HANDLE event = CreateEventW(nullptr, FALSE, FALSE, nullptr); 16 HANDLE event = CreateEventW(nullptr, FALSE, FALSE, nullptr);
15 if (!event) return false; 17 if (!event) return false;
16 const bool complete = SUCCEEDED(fence->SetEventOnCompletion(value, event)) && 18 if (FAILED(fence->SetEventOnCompletion(value, event))) {
17 WaitForSingleObject(event, 3000) == WAIT_OBJECT_0; 19 CloseHandle(event); // no wait was registered
20 return false;
21 }
22 if (WaitForSingleObject(event, timeout_ms) != WAIT_OBJECT_0) {
23 // The fence dispatcher can still hold this event, and a queued GPU Wait can keep the queue destructor
24 // blocked forever. End the failed test without closing live handles or waiting for blocked queues.
25 std::fputs("cross-queue Wait-before-Signal timed out\n", stderr);
26 std::fflush(stderr);
27 std::_Exit(1);
28 }
18 CloseHandle(event); 29 CloseHandle(event);
19 return complete; 30 return true;
20} 31}
21} // namespace 32} // namespace
22 33
23int main() { 34int main(int argc, char** argv) {
24 Ref<ID3D12Device> device; 35 Ref<ID3D12Device> device;
25 if (FAILED(rt::d3d12::create_vulkan_device_standalone(IID_PPV_ARGS(&device.p)))) return 77; 36 if (FAILED(rt::d3d12::create_vulkan_device_standalone(IID_PPV_ARGS(&device.p)))) return 77;
37 if (argc == 2 && std::strcmp(argv[1], "--timeout-control") == 0) {
38 Ref<ID3D12Fence> never_signaled;
39 if (FAILED(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&never_signaled.p)))) return 1;
40 // Expected to leave the process with code 1 promptly, without destroying the pending event.
41 wait_for(never_signaled.p, 1, 20);
42 return 0; // a completed wait here means the control did not exercise the timeout path
43 }
26 D3D12_COMMAND_QUEUE_DESC desc{}; 44 D3D12_COMMAND_QUEUE_DESC desc{};
27 Ref<ID3D12CommandQueue> copy, compute, direct_a, direct_b; 45 Ref<ID3D12CommandQueue> copy, compute, direct_a, direct_b;
28 desc.Type = D3D12_COMMAND_LIST_TYPE_COPY; 46 desc.Type = D3D12_COMMAND_LIST_TYPE_COPY;
@@ -49,11 +67,11 @@ int main() {
49 const bool copy_complete = submitted && wait_for(done_copy.p, 1); 67 const bool copy_complete = submitted && wait_for(done_copy.p, 1);
50 const bool direct_complete = submitted && wait_for(done_direct.p, 1); 68 const bool direct_complete = submitted && wait_for(done_direct.p, 1);
51 if (!copy_complete || !direct_complete) { 69 if (!copy_complete || !direct_complete) {
52 // Unblock submitted waits before queue destructors call vkQueueWaitIdle. 70 // A failed submit can leave a GPU Wait pending. Gate 1 is not a valid fallback once queue signals
53 gate_copy->Signal(1); 71 // have claimed 2, so do not destroy queues or fences while their work may still be outstanding.
54 gate_direct->Signal(1); 72 std::fputs("cross-queue Wait-before-Signal did not complete\n", stderr);
55 std::fprintf(stderr, "cross-queue Wait-before-Signal did not complete\n"); 73 std::fflush(stderr);
56 return 1; 74 std::_Exit(1);
57 } 75 }
58 std::puts("copy/compute and direct/direct Wait-before-Signal completed"); 76 std::puts("copy/compute and direct/direct Wait-before-Signal completed");
59 return 0; 77 return 0;