upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authortotonii <totonicontato@gmail.com>2026-11-22 07:54:34 -0300
committertotonii <totonicontato@gmail.com>2026-11-22 08:15:47 -0300
commita6daa4cffffa5a77fbda1aa80185d980d6bbdee7 (patch)
treec37e65c120006f74c387aa814750061ba1602b3b /runtime
parentc2967a5e60060e4068fb992196d8f4b494a5046c (diff)
fix(dxgi): reject Get/SetMaximumFrameLatency on non-waitable swapchains with DXGI_ERROR_INVALID_CALL
Diffstat (limited to 'runtime')
-rw-r--r--runtime/shims/dxgi_com.cpp4
-rw-r--r--runtime/test/dxgi_swapchain_test.cpp26
2 files changed, 19 insertions, 11 deletions
diff --git a/runtime/shims/dxgi_com.cpp b/runtime/shims/dxgi_com.cpp
index b270f084c..e61b7d392 100644
--- a/runtime/shims/dxgi_com.cpp
+++ b/runtime/shims/dxgi_com.cpp
@@ -296,14 +296,16 @@ public:
296 return S_OK; 296 return S_OK;
297 } 297 }
298 HRESULT STDMETHODCALLTYPE SetMaximumFrameLatency(UINT max_latency) override { 298 HRESULT STDMETHODCALLTYPE SetMaximumFrameLatency(UINT max_latency) override {
299 if (!waitable_) return DXGI_ERROR_INVALID_CALL;
299 if (max_latency == 0 || max_latency > 16) return E_INVALIDARG; 300 if (max_latency == 0 || max_latency > 16) return E_INVALIDARG;
300 const UINT prev = max_frame_latency_.exchange(max_latency, std::memory_order_relaxed); 301 const UINT prev = max_frame_latency_.exchange(max_latency, std::memory_order_relaxed);
301 if (waitable_ && max_latency > prev) 302 if (max_latency > prev)
302 ReleaseSemaphore(waitable_, static_cast<LONG>(max_latency - prev), nullptr); 303 ReleaseSemaphore(waitable_, static_cast<LONG>(max_latency - prev), nullptr);
303 return S_OK; 304 return S_OK;
304 } 305 }
305 HRESULT STDMETHODCALLTYPE GetMaximumFrameLatency(UINT* n) override { 306 HRESULT STDMETHODCALLTYPE GetMaximumFrameLatency(UINT* n) override {
306 if (!n) return E_INVALIDARG; 307 if (!n) return E_INVALIDARG;
308 if (!waitable_) return DXGI_ERROR_INVALID_CALL;
307 *n = max_frame_latency_.load(std::memory_order_relaxed); 309 *n = max_frame_latency_.load(std::memory_order_relaxed);
308 return S_OK; 310 return S_OK;
309 } 311 }
diff --git a/runtime/test/dxgi_swapchain_test.cpp b/runtime/test/dxgi_swapchain_test.cpp
index d5c3d6804..e1f1142ec 100644
--- a/runtime/test/dxgi_swapchain_test.cpp
+++ b/runtime/test/dxgi_swapchain_test.cpp
@@ -544,19 +544,20 @@ int main() {
544 return fail("GetLastPresentCount(nullptr) should return E_INVALIDARG"); 544 return fail("GetLastPresentCount(nullptr) should return E_INVALIDARG");
545 } 545 }
546 546
547 // SwapChain::GetParent and SetMaximumFrameLatency/GetMaximumFrameLatency. 547 // SwapChain::GetParent and non-waitable SetMaximumFrameLatency/GetMaximumFrameLatency (host DXGI returns
548 // DXGI_ERROR_INVALID_CALL and leaves the output untouched when DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT
549 // was not set).
548 { 550 {
549 IDXGIFactory4* parent = nullptr; 551 IDXGIFactory4* parent = nullptr;
550 if (FAILED(sc->GetParent(IID_PPV_ARGS(&parent))) || parent != factory) 552 if (FAILED(sc->GetParent(IID_PPV_ARGS(&parent))) || parent != factory)
551 return fail("SwapChain::GetParent did not return the parent factory"); 553 return fail("SwapChain::GetParent did not return the parent factory");
552 parent->Release(); 554 parent->Release();
553 UINT lat = 0; 555 UINT sentinel = 0xdeadbeefu;
554 if (FAILED(sc->GetMaximumFrameLatency(&lat)) || lat != 2) 556 if (sc->GetMaximumFrameLatency(&sentinel) != DXGI_ERROR_INVALID_CALL || sentinel != 0xdeadbeefu)
555 return fail("Default GetMaximumFrameLatency should be 2"); 557 return fail("Non-waitable GetMaximumFrameLatency should return DXGI_ERROR_INVALID_CALL without writing output");
556 if (sc->SetMaximumFrameLatency(0) != E_INVALIDARG || sc->SetMaximumFrameLatency(17) != E_INVALIDARG) 558 if (sc->SetMaximumFrameLatency(3) != DXGI_ERROR_INVALID_CALL ||
557 return fail("SetMaximumFrameLatency should reject 0 and > 16 with E_INVALIDARG"); 559 sc->SetMaximumFrameLatency(1) != DXGI_ERROR_INVALID_CALL)
558 if (FAILED(sc->SetMaximumFrameLatency(3)) || FAILED(sc->GetMaximumFrameLatency(&lat)) || lat != 3) 560 return fail("Non-waitable SetMaximumFrameLatency should return DXGI_ERROR_INVALID_CALL");
559 return fail("SetMaximumFrameLatency(3) round-trip failed");
560 } 561 }
561 562
562 // IDXGIFactory4 adapter enumeration, IDXGIAdapter3 descriptors, EnumAdapterByLuid, and QueryVideoMemoryInfo. 563 // IDXGIFactory4 adapter enumeration, IDXGIAdapter3 descriptors, EnumAdapterByLuid, and QueryVideoMemoryInfo.
@@ -746,10 +747,15 @@ int main() {
746 UINT lat = 0; 747 UINT lat = 0;
747 if (FAILED(wsc->GetMaximumFrameLatency(&lat)) || lat != 1) 748 if (FAILED(wsc->GetMaximumFrameLatency(&lat)) || lat != 1)
748 return fail("Waitable swapchain default GetMaximumFrameLatency should be 1"); 749 return fail("Waitable swapchain default GetMaximumFrameLatency should be 1");
750 if (wsc->SetMaximumFrameLatency(0) != E_INVALIDARG || wsc->SetMaximumFrameLatency(17) != E_INVALIDARG)
751 return fail("Waitable SetMaximumFrameLatency should reject 0 and > 16 with E_INVALIDARG");
752 if (FAILED(wsc->SetMaximumFrameLatency(2)) || FAILED(wsc->GetMaximumFrameLatency(&lat)) || lat != 2)
753 return fail("Waitable SetMaximumFrameLatency(2) round-trip failed");
749 HANDLE waitable = wsc->GetFrameLatencyWaitableObject(); 754 HANDLE waitable = wsc->GetFrameLatencyWaitableObject();
750 if (!waitable) return fail("Waitable swapchain returned null handle"); 755 if (!waitable) return fail("Waitable swapchain returned null handle");
751 if (WaitForSingleObject(waitable, 5000) != WAIT_OBJECT_0) 756 if (WaitForSingleObject(waitable, 5000) != WAIT_OBJECT_0 ||
752 return fail("Initial WaitForSingleObject on waitable swapchain failed"); 757 WaitForSingleObject(waitable, 5000) != WAIT_OBJECT_0)
758 return fail("Initial WaitForSingleObject on latency-2 waitable swapchain failed");
753 if (wsc->Present(1, DXGI_PRESENT_ALLOW_TEARING) != DXGI_ERROR_INVALID_CALL) 759 if (wsc->Present(1, DXGI_PRESENT_ALLOW_TEARING) != DXGI_ERROR_INVALID_CALL)
754 return fail("Present(1, ALLOW_TEARING) should return DXGI_ERROR_INVALID_CALL"); 760 return fail("Present(1, ALLOW_TEARING) should return DXGI_ERROR_INVALID_CALL");
755 if (FAILED(wsc->Present(0, DXGI_PRESENT_ALLOW_TEARING))) 761 if (FAILED(wsc->Present(0, DXGI_PRESENT_ALLOW_TEARING)))