diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 09:15:11 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 09:15:11 -0500 |
| commit | a0af2deb87c7fdc66ed9b99759c425826434ee72 (patch) | |
| tree | 1b4987b6259fa057c896f205b74131acaa068249 /runtime/shims/dxgi_com.cpp | |
| parent | e66286921e17153c7da0396b51108afc5be3c2e3 (diff) | |
| parent | 84016932e0a014707073a1e4b492623e9c0b6303 (diff) | |
Merge pull request #1766 from Ryderadzeee
Diffstat (limited to 'runtime/shims/dxgi_com.cpp')
| -rw-r--r-- | runtime/shims/dxgi_com.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/runtime/shims/dxgi_com.cpp b/runtime/shims/dxgi_com.cpp index 1e50bad2d..7c5d026c9 100644 --- a/runtime/shims/dxgi_com.cpp +++ b/runtime/shims/dxgi_com.cpp | |||
| @@ -22,6 +22,10 @@ void stub(const char* method) { | |||
| 22 | if (seen.insert(method).second) std::fprintf(stderr, "[rt] dxgi: unimplemented %s\n", method); | 22 | if (seen.insert(method).second) std::fprintf(stderr, "[rt] dxgi: unimplemented %s\n", method); |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | bool valid_flip_buffer_count(UINT count) { | ||
| 26 | return count >= 2 && count <= DXGI_MAX_SWAP_CHAIN_BUFFERS; | ||
| 27 | } | ||
| 28 | |||
| 25 | VkFormat dxgi_to_vk_format(DXGI_FORMAT fmt) { | 29 | VkFormat dxgi_to_vk_format(DXGI_FORMAT fmt) { |
| 26 | switch (fmt) { | 30 | switch (fmt) { |
| 27 | case DXGI_FORMAT_B8G8R8A8_UNORM: return VK_FORMAT_B8G8R8A8_UNORM; | 31 | case DXGI_FORMAT_B8G8R8A8_UNORM: return VK_FORMAT_B8G8R8A8_UNORM; |
| @@ -128,14 +132,13 @@ public: | |||
| 128 | const VkExtent2D size = size_or_client(desc.Width, desc.Height, {256u, 256u}); | 132 | const VkExtent2D size = size_or_client(desc.Width, desc.Height, {256u, 256u}); |
| 129 | const std::uint32_t w = size.width; | 133 | const std::uint32_t w = size.width; |
| 130 | const std::uint32_t h = size.height; | 134 | const std::uint32_t h = size.height; |
| 131 | const std::uint32_t count = desc.BufferCount ? desc.BufferCount : 2u; | ||
| 132 | VkFormat vk_fmt = VK_FORMAT_UNDEFINED; | 135 | VkFormat vk_fmt = VK_FORMAT_UNDEFINED; |
| 133 | if (desc.Format != DXGI_FORMAT_UNKNOWN) { | 136 | if (desc.Format != DXGI_FORMAT_UNKNOWN) { |
| 134 | vk_fmt = dxgi_to_vk_format(desc.Format); | 137 | vk_fmt = dxgi_to_vk_format(desc.Format); |
| 135 | if (vk_fmt == VK_FORMAT_UNDEFINED) return false; | 138 | if (vk_fmt == VK_FORMAT_UNDEFINED) return false; |
| 136 | } | 139 | } |
| 137 | const bool allow_tearing = (flags_ & DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) != 0; | 140 | const bool allow_tearing = (flags_ & DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) != 0; |
| 138 | if (!swapchain_.create(hwnd, w, h, vk_fmt, count, allow_tearing)) return false; | 141 | if (!swapchain_.create(hwnd, w, h, vk_fmt, desc.BufferCount, allow_tearing)) return false; |
| 139 | if (flags_ & DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT) { | 142 | if (flags_ & DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT) { |
| 140 | // DXGI: waitable swapchains default to maximum frame latency 1. | 143 | // DXGI: waitable swapchains default to maximum frame latency 1. |
| 141 | max_frame_latency_.store(1, std::memory_order_relaxed); | 144 | max_frame_latency_.store(1, std::memory_order_relaxed); |
| @@ -234,6 +237,7 @@ public: | |||
| 234 | } | 237 | } |
| 235 | 238 | ||
| 236 | HRESULT STDMETHODCALLTYPE ResizeBuffers(UINT count, UINT width, UINT height, DXGI_FORMAT fmt, UINT flags) override { | 239 | HRESULT STDMETHODCALLTYPE ResizeBuffers(UINT count, UINT width, UINT height, DXGI_FORMAT fmt, UINT flags) override { |
| 240 | if (count != 0 && !valid_flip_buffer_count(count)) return E_INVALIDARG; | ||
| 237 | VkFormat vk_fmt = VK_FORMAT_UNDEFINED; | 241 | VkFormat vk_fmt = VK_FORMAT_UNDEFINED; |
| 238 | if (fmt != DXGI_FORMAT_UNKNOWN) { | 242 | if (fmt != DXGI_FORMAT_UNKNOWN) { |
| 239 | vk_fmt = dxgi_to_vk_format(fmt); | 243 | vk_fmt = dxgi_to_vk_format(fmt); |
| @@ -782,6 +786,7 @@ public: | |||
| 782 | if (!out) return E_POINTER; | 786 | if (!out) return E_POINTER; |
| 783 | *out = nullptr; | 787 | *out = nullptr; |
| 784 | if (!hwnd || !desc) return E_INVALIDARG; | 788 | if (!hwnd || !desc) return E_INVALIDARG; |
| 789 | if (!valid_flip_buffer_count(desc->BufferCount)) return DXGI_ERROR_INVALID_CALL; | ||
| 785 | auto* sc = new SwapChain(this, device, context_, gipa_, instance_, physical_, gdpa_, queue_, queue_family_); | 790 | auto* sc = new SwapChain(this, device, context_, gipa_, instance_, physical_, gdpa_, queue_, queue_family_); |
| 786 | if (!sc->init(hwnd, *desc)) { | 791 | if (!sc->init(hwnd, *desc)) { |
| 787 | sc->Release(); | 792 | sc->Release(); |