upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/shims/dxgi_com.cpp
diff options
context:
space:
mode:
authorbobcatchris <83428450+bobcatchris@users.noreply.github.com>2026-11-22 12:20:44 -0600
committerbobcatchris <83428450+bobcatchris@users.noreply.github.com>2026-11-22 17:37:54 -0600
commite17bea316fcb56a8c46e5f4b968340a38300c2a1 (patch)
tree5f2e403bf655b74b3609c130b85cc21a70215f30 /runtime/shims/dxgi_com.cpp
parentaa2988cc555bad7ecd508b48a702adbb32fe7c95 (diff)
dxgi: SetSourceSize stores the source region and refuses one too large
SetSourceSize answered S_OK and ignored its arguments, and GetSourceSize always reported the back-buffer size, so a game that scales its source region could not read back what it set. Host-measured on Windows 11 with the system DXGI (RX 7900 XTX): a fresh swapchain reports the back-buffer extent; SetSourceSize(64,32) round-trips while GetDesc1 keeps the buffer size; a region larger than either buffer dimension is DXGI_ERROR_INVALID_CALL and keeps the stored value; zero is accepted and stored; GetSourceSize needs both pointers; and ResizeBuffers resets the source size to the new back-buffer extent. Present still does not scale by the source region; that stays a documented difference and is not part of this change.
Diffstat (limited to 'runtime/shims/dxgi_com.cpp')
-rw-r--r--runtime/shims/dxgi_com.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/runtime/shims/dxgi_com.cpp b/runtime/shims/dxgi_com.cpp
index 734824e07..e199b15bc 100644
--- a/runtime/shims/dxgi_com.cpp
+++ b/runtime/shims/dxgi_com.cpp
@@ -145,6 +145,7 @@ public:
145 const std::uint32_t h = size.height; 145 const std::uint32_t h = size.height;
146 const bool allow_tearing = (flags_ & DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) != 0; 146 const bool allow_tearing = (flags_ & DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) != 0;
147 if (!swapchain_.create(hwnd, w, h, vk_fmt, desc.BufferCount, allow_tearing)) return false; 147 if (!swapchain_.create(hwnd, w, h, vk_fmt, desc.BufferCount, allow_tearing)) return false;
148 source_size_ = {w, h};
148 if (flags_ & DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT) { 149 if (flags_ & DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT) {
149 // DXGI: waitable swapchains default to maximum frame latency 1. 150 // DXGI: waitable swapchains default to maximum frame latency 1.
150 max_frame_latency_.store(1, std::memory_order_relaxed); 151 max_frame_latency_.store(1, std::memory_order_relaxed);
@@ -280,6 +281,7 @@ public:
280 const UINT next_flags = flags ? flags : flags_; 281 const UINT next_flags = flags ? flags : flags_;
281 const bool allow_tearing = (next_flags & DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) != 0; 282 const bool allow_tearing = (next_flags & DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) != 0;
282 if (!swapchain_.resize(w, h, vk_fmt, count, allow_tearing)) return E_FAIL; 283 if (!swapchain_.resize(w, h, vk_fmt, count, allow_tearing)) return E_FAIL;
284 source_size_ = {w, h}; // host-measured: ResizeBuffers resets the source region to the new back buffers
283 statistics_disjoint_.store(true, std::memory_order_relaxed); 285 statistics_disjoint_.store(true, std::memory_order_relaxed);
284 flags_ = next_flags; 286 flags_ = next_flags;
285 register_buffers(); 287 register_buffers();
@@ -389,10 +391,18 @@ public:
389 } 391 }
390 392
391 // IDXGISwapChain2 393 // IDXGISwapChain2
392 HRESULT STDMETHODCALLTYPE SetSourceSize(UINT, UINT) override { return S_OK; } 394 HRESULT STDMETHODCALLTYPE SetSourceSize(UINT width, UINT height) override {
395 // Host-measured: a region larger than either back-buffer dimension is refused and keeps the stored one;
396 // zero is accepted. Present does not scale by it yet (documented difference).
397 const VkExtent2D extent = swapchain_.extent();
398 if (width > extent.width || height > extent.height) return DXGI_ERROR_INVALID_CALL;
399 source_size_ = {width, height};
400 return S_OK;
401 }
393 HRESULT STDMETHODCALLTYPE GetSourceSize(UINT* w, UINT* h) override { 402 HRESULT STDMETHODCALLTYPE GetSourceSize(UINT* w, UINT* h) override {
394 if (w) *w = swapchain_.extent().width; 403 if (!w || !h) return DXGI_ERROR_INVALID_CALL; // host-measured: both are required
395 if (h) *h = swapchain_.extent().height; 404 *w = source_size_.width;
405 *h = source_size_.height;
396 return S_OK; 406 return S_OK;
397 } 407 }
398 HRESULT STDMETHODCALLTYPE SetMaximumFrameLatency(UINT max_latency) override { 408 HRESULT STDMETHODCALLTYPE SetMaximumFrameLatency(UINT max_latency) override {
@@ -497,6 +507,7 @@ private:
497 DXGI_RGBA background_color_{0, 0, 0, 0}; 507 DXGI_RGBA background_color_{0, 0, 0, 0};
498 DXGI_MATRIX_3X2_F matrix_transform_{1, 0, 0, 1, 0, 0}; 508 DXGI_MATRIX_3X2_F matrix_transform_{1, 0, 0, 1, 0, 0};
499 DXGI_MODE_ROTATION rotation_ = DXGI_MODE_ROTATION_IDENTITY; 509 DXGI_MODE_ROTATION rotation_ = DXGI_MODE_ROTATION_IDENTITY;
510 VkExtent2D source_size_{0, 0};
500}; 511};
501 512
502struct ReservationState { 513struct ReservationState {