diff options
| author | Codex <codex@users.noreply.github.com> | 2026-11-22 16:14:43 +0300 |
|---|---|---|
| committer | Codex <codex@users.noreply.github.com> | 2026-11-22 16:15:06 +0300 |
| commit | e633201e491a5679b3083b1e9e7999d3d4f3b398 (patch) | |
| tree | 574a024b6995d3aa14167773caac2ae4f44c88a4 /runtime/test/d3d12_queue_wait_test.cpp | |
| parent | a0acd33d77babe67a28e398b2936a9f735a50f5d (diff) | |
D3D-97: fail queue wait test safely on timeout
End a timed-out cross-queue test before the fence dispatcher can touch a closed event or queue teardown can wait forever. Add a deliberately unsignaled fence control so CTest covers the failure path. AI-assisted (Codex).
Diffstat (limited to 'runtime/test/d3d12_queue_wait_test.cpp')
| -rw-r--r-- | runtime/test/d3d12_queue_wait_test.cpp | 38 |
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 | ||
| 6 | namespace { | 8 | namespace { |
| 7 | template<class T> struct Ref { | 9 | template<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 | ||
| 13 | bool wait_for(ID3D12Fence* fence, UINT64 value) { | 15 | bool 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 | ||
| 23 | int main() { | 34 | int 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; |