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:
authorRyderadzeee <craftercrashonname@gmail.com>2026-11-22 22:59:57 +0400
committerRyderadzeee <craftercrashonname@gmail.com>2026-11-22 22:59:57 +0400
commited8528885b9b94361c341a8bdd8543f8d1bca373 (patch)
treea9528182c6e165041c920a9a6726204dc6e6cf02 /runtime/shims/dxgi_com.cpp
parent162821017ea3c286c8bec860f3ff94f037912061 (diff)
Validate DXGI ResizeBuffers1 node masks and presentation queues
Diffstat (limited to 'runtime/shims/dxgi_com.cpp')
-rw-r--r--runtime/shims/dxgi_com.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/runtime/shims/dxgi_com.cpp b/runtime/shims/dxgi_com.cpp
index 47a53f7a2..e5e90c913 100644
--- a/runtime/shims/dxgi_com.cpp
+++ b/runtime/shims/dxgi_com.cpp
@@ -1,6 +1,7 @@
1#include "dxgi_com.h" 1#include "dxgi_com.h"
2#include "d3d12_stubs.h" 2#include "d3d12_stubs.h"
3 3
4#include <algorithm>
4#include <atomic> 5#include <atomic>
5#include <cstdio> 6#include <cstdio>
6#include <cstring> 7#include <cstring>
@@ -26,6 +27,14 @@ bool valid_flip_buffer_count(UINT count) {
26 return count >= 2 && count <= DXGI_MAX_SWAP_CHAIN_BUFFERS; 27 return count >= 2 && count <= DXGI_MAX_SWAP_CHAIN_BUFFERS;
27} 28}
28 29
30bool is_direct_present_queue(IUnknown* candidate) {
31 ID3D12CommandQueue* queue = nullptr;
32 if (!candidate || FAILED(candidate->QueryInterface(IID_PPV_ARGS(&queue))) || !queue) return false;
33 const bool direct = queue->GetDesc().Type == D3D12_COMMAND_LIST_TYPE_DIRECT;
34 queue->Release();
35 return direct;
36}
37
29VkFormat dxgi_to_vk_format(DXGI_FORMAT fmt) { 38VkFormat dxgi_to_vk_format(DXGI_FORMAT fmt) {
30 switch (fmt) { 39 switch (fmt) {
31 case DXGI_FORMAT_B8G8R8A8_UNORM: return VK_FORMAT_B8G8R8A8_UNORM; 40 case DXGI_FORMAT_B8G8R8A8_UNORM: return VK_FORMAT_B8G8R8A8_UNORM;
@@ -230,6 +239,11 @@ public:
230 } 239 }
231 240
232 HRESULT STDMETHODCALLTYPE ResizeBuffers(UINT count, UINT width, UINT height, DXGI_FORMAT fmt, UINT flags) override { 241 HRESULT STDMETHODCALLTYPE ResizeBuffers(UINT count, UINT width, UINT height, DXGI_FORMAT fmt, UINT flags) override {
242 return resize_buffers(count, width, height, fmt, flags, nullptr, nullptr);
243 }
244
245 HRESULT resize_buffers(UINT count, UINT width, UINT height, DXGI_FORMAT fmt, UINT flags,
246 const UINT* node_masks, IUnknown* const* present_queues) {
233 if (count != 0 && !valid_flip_buffer_count(count)) return E_INVALIDARG; 247 if (count != 0 && !valid_flip_buffer_count(count)) return E_INVALIDARG;
234 VkFormat vk_fmt = VK_FORMAT_UNDEFINED; 248 VkFormat vk_fmt = VK_FORMAT_UNDEFINED;
235 if (fmt != DXGI_FORMAT_UNKNOWN) { 249 if (fmt != DXGI_FORMAT_UNKNOWN) {
@@ -242,6 +256,11 @@ public:
242 // DXGI refuses to resize while the app still holds a back buffer reference. 256 // DXGI refuses to resize while the app still holds a back buffer reference.
243 for (auto* bb : buffers_) 257 for (auto* bb : buffers_)
244 if (bb->held_by_app()) return DXGI_ERROR_INVALID_CALL; 258 if (bb->held_by_app()) return DXGI_ERROR_INVALID_CALL;
259 const std::size_t target_count = count ? count : buffers_.size();
260 if (node_masks && !std::all_of(node_masks, node_masks + target_count, [](UINT mask) { return mask <= 1; }))
261 return DXGI_ERROR_INVALID_CALL;
262 if (present_queues && !std::all_of(present_queues, present_queues + target_count, is_direct_present_queue))
263 return DXGI_ERROR_INVALID_CALL;
245 unregister_buffers(); 264 unregister_buffers();
246 const VkExtent2D size = size_or_client(width, height, swapchain_.extent()); 265 const VkExtent2D size = size_or_client(width, height, swapchain_.extent());
247 const std::uint32_t w = size.width; 266 const std::uint32_t w = size.width;
@@ -373,9 +392,9 @@ public:
373 return S_OK; 392 return S_OK;
374 } 393 }
375 HRESULT STDMETHODCALLTYPE SetColorSpace1(DXGI_COLOR_SPACE_TYPE) override { return S_OK; } 394 HRESULT STDMETHODCALLTYPE SetColorSpace1(DXGI_COLOR_SPACE_TYPE) override { return S_OK; }
376 HRESULT STDMETHODCALLTYPE ResizeBuffers1(UINT count, UINT w, UINT h, DXGI_FORMAT fmt, UINT flags, const UINT*, 395 HRESULT STDMETHODCALLTYPE ResizeBuffers1(UINT count, UINT w, UINT h, DXGI_FORMAT fmt, UINT flags,
377 IUnknown* const*) override { 396 const UINT* node_masks, IUnknown* const* present_queues) override {
378 return ResizeBuffers(count, w, h, fmt, flags); 397 return resize_buffers(count, w, h, fmt, flags, node_masks, present_queues);
379 } 398 }
380 399
381private: 400private: