diff options
| author | DenRakEiw <89697885+DenRakEiw@users.noreply.github.com> | 2026-11-23 20:50:57 +0100 |
|---|---|---|
| committer | DenRakEiw <89697885+DenRakEiw@users.noreply.github.com> | 2026-11-23 20:50:57 +0100 |
| commit | 89fd2e2f870ebc6df99113c6a70b947aa23562c4 (patch) | |
| tree | 302546b36c0ba12468b67ef23aa522af688dba9f /runtime/shims/dxgi_com.cpp | |
| parent | 867d922f09b86583859796a174df89555fb32da8 (diff) | |
dxgi_com: match host Windows 11 waitable swap chain frame-latency contract
Diffstat (limited to 'runtime/shims/dxgi_com.cpp')
| -rw-r--r-- | runtime/shims/dxgi_com.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/runtime/shims/dxgi_com.cpp b/runtime/shims/dxgi_com.cpp index 30f0f69a4..90cbbec6e 100644 --- a/runtime/shims/dxgi_com.cpp +++ b/runtime/shims/dxgi_com.cpp | |||
| @@ -529,6 +529,10 @@ public: | |||
| 529 | *h = source_size_.height; | 529 | *h = source_size_.height; |
| 530 | return S_OK; | 530 | return S_OK; |
| 531 | } | 531 | } |
| 532 | // Host-measured (Windows 11, RTX 5090 and WARP): the waitable object is a semaphore initialized to 1 with max 40. | ||
| 533 | // Increasing latency releases (max_latency - prev) tokens (if current + delta > 40, ReleaseSemaphore fails with | ||
| 534 | // ERROR_TOO_MANY_POSTS leaving count unchanged and SetMaximumFrameLatency still returns S_OK). Decreasing updates | ||
| 535 | // max_frame_latency_ without draining existing tokens. Present releases 1 token per non-test call up to max 40. | ||
| 532 | HRESULT STDMETHODCALLTYPE SetMaximumFrameLatency(UINT max_latency) override { | 536 | HRESULT STDMETHODCALLTYPE SetMaximumFrameLatency(UINT max_latency) override { |
| 533 | if (!waitable_ || max_latency == 0 || max_latency > max_waitable_frame_latency) | 537 | if (!waitable_ || max_latency == 0 || max_latency > max_waitable_frame_latency) |
| 534 | return DXGI_ERROR_INVALID_CALL; | 538 | return DXGI_ERROR_INVALID_CALL; |
| @@ -538,16 +542,18 @@ public: | |||
| 538 | return S_OK; | 542 | return S_OK; |
| 539 | } | 543 | } |
| 540 | HRESULT STDMETHODCALLTYPE GetMaximumFrameLatency(UINT* n) override { | 544 | HRESULT STDMETHODCALLTYPE GetMaximumFrameLatency(UINT* n) override { |
| 541 | if (!n) return E_INVALIDARG; | 545 | // Host-measured (Windows 11, RTX 5090 and WARP): null output returns DXGI_ERROR_INVALID_CALL on both |
| 542 | if (!waitable_) return DXGI_ERROR_INVALID_CALL; | 546 | // waitable and non-waitable swapchains. |
| 547 | if (!n || !waitable_) return DXGI_ERROR_INVALID_CALL; | ||
| 543 | *n = max_frame_latency_.load(std::memory_order_relaxed); | 548 | *n = max_frame_latency_.load(std::memory_order_relaxed); |
| 544 | return S_OK; | 549 | return S_OK; |
| 545 | } | 550 | } |
| 546 | HANDLE STDMETHODCALLTYPE GetFrameLatencyWaitableObject() override { | 551 | HANDLE STDMETHODCALLTYPE GetFrameLatencyWaitableObject() override { |
| 547 | if (!waitable_) return nullptr; | 552 | if (!waitable_) return nullptr; |
| 548 | HANDLE dup = nullptr; | 553 | HANDLE dup = nullptr; |
| 549 | if (!DuplicateHandle(GetCurrentProcess(), waitable_, GetCurrentProcess(), &dup, 0, FALSE, | 554 | // Host-measured (Windows 11, RTX 5090 and WARP): the returned handle grants SYNCHRONIZE only, so callers can |
| 550 | DUPLICATE_SAME_ACCESS)) | 555 | // wait on it and CloseHandle it, while ReleaseSemaphore fails with ERROR_ACCESS_DENIED. |
| 556 | if (!DuplicateHandle(GetCurrentProcess(), waitable_, GetCurrentProcess(), &dup, SYNCHRONIZE, FALSE, 0)) | ||
| 551 | return nullptr; | 557 | return nullptr; |
| 552 | return dup; | 558 | return dup; |
| 553 | } | 559 | } |