diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 15:16:16 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 15:16:16 -0500 |
| commit | 237d590237be07befb0be34a45e7619d1bbae9ad (patch) | |
| tree | 97d6d985b138eb493eadd1a141ddcaae1c35101a /runtime/shims/dxgi_com.cpp | |
| parent | 5d8b04502a5fc601cb8ca9f957be07dbf88e9c7f (diff) | |
| parent | afd0d4c62205c74b43a11086f49abfcb76df0fc2 (diff) | |
Merge pull request #3259 from Vyral1978
Diffstat (limited to 'runtime/shims/dxgi_com.cpp')
| -rw-r--r-- | runtime/shims/dxgi_com.cpp | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/runtime/shims/dxgi_com.cpp b/runtime/shims/dxgi_com.cpp index e41f81e9f..a563136d7 100644 --- a/runtime/shims/dxgi_com.cpp +++ b/runtime/shims/dxgi_com.cpp | |||
| @@ -768,7 +768,7 @@ private: | |||
| 768 | std::shared_ptr<ReservationState> reservations_; | 768 | std::shared_ptr<ReservationState> reservations_; |
| 769 | }; | 769 | }; |
| 770 | 770 | ||
| 771 | class Factory final : public IDXGIFactory5 { | 771 | class Factory final : public IDXGIFactory7 { |
| 772 | public: | 772 | public: |
| 773 | Factory(leonida::VulkanContext& context, PFN_vkGetInstanceProcAddr gipa, VkInstance instance, | 773 | Factory(leonida::VulkanContext& context, PFN_vkGetInstanceProcAddr gipa, VkInstance instance, |
| 774 | VkPhysicalDevice physical, PFN_vkGetDeviceProcAddr gdpa, VkQueue queue, std::uint32_t queue_family) | 774 | VkPhysicalDevice physical, PFN_vkGetDeviceProcAddr gdpa, VkQueue queue, std::uint32_t queue_family) |
| @@ -787,8 +787,9 @@ public: | |||
| 787 | if (riid == __uuidof(IUnknown) || riid == __uuidof(IDXGIObject) || riid == __uuidof(IDXGIFactory) || | 787 | if (riid == __uuidof(IUnknown) || riid == __uuidof(IDXGIObject) || riid == __uuidof(IDXGIFactory) || |
| 788 | riid == __uuidof(IDXGIFactory1) || riid == __uuidof(IDXGIFactory2) || | 788 | riid == __uuidof(IDXGIFactory1) || riid == __uuidof(IDXGIFactory2) || |
| 789 | riid == __uuidof(IDXGIFactory3) || riid == __uuidof(IDXGIFactory4) || | 789 | riid == __uuidof(IDXGIFactory3) || riid == __uuidof(IDXGIFactory4) || |
| 790 | riid == __uuidof(IDXGIFactory5)) { | 790 | riid == __uuidof(IDXGIFactory5) || riid == __uuidof(IDXGIFactory6) || |
| 791 | *out = static_cast<IDXGIFactory5*>(this); | 791 | riid == __uuidof(IDXGIFactory7)) { |
| 792 | *out = static_cast<IDXGIFactory7*>(this); | ||
| 792 | AddRef(); | 793 | AddRef(); |
| 793 | return S_OK; | 794 | return S_OK; |
| 794 | } | 795 | } |
| @@ -967,6 +968,39 @@ public: | |||
| 967 | return E_INVALIDARG; | 968 | return E_INVALIDARG; |
| 968 | } | 969 | } |
| 969 | 970 | ||
| 971 | // IDXGIFactory6. The factory has one adapter, so every preference orders the same list. Measured on the host's | ||
| 972 | // dxgi.dll (Windows 11, RTX 3070): a preference outside the enum is accepted, a null `out` is | ||
| 973 | // DXGI_ERROR_INVALID_CALL, and an index past the end is DXGI_ERROR_NOT_FOUND with *out cleared. | ||
| 974 | HRESULT STDMETHODCALLTYPE EnumAdapterByGpuPreference(UINT index, DXGI_GPU_PREFERENCE, REFIID riid, | ||
| 975 | void** out) override { | ||
| 976 | if (!out) return DXGI_ERROR_INVALID_CALL; | ||
| 977 | *out = nullptr; | ||
| 978 | if (index != 0) return DXGI_ERROR_NOT_FOUND; | ||
| 979 | auto* adapter = new Adapter(this, gipa_, instance_, physical_); | ||
| 980 | const HRESULT hr = adapter->QueryInterface(riid, out); | ||
| 981 | adapter->Release(); | ||
| 982 | return hr; | ||
| 983 | } | ||
| 984 | |||
| 985 | // IDXGIFactory7. The adapter list never changes, so a registered event is never signalled; the registry only | ||
| 986 | // keeps the host's answers (same measurement): a null event or cookie and an event registered twice are | ||
| 987 | // DXGI_ERROR_INVALID_CALL, cookies start at 1 and are separate from the occlusion cookies, and an unknown | ||
| 988 | // cookie is DXGI_ERROR_NOT_FOUND. | ||
| 989 | HRESULT STDMETHODCALLTYPE RegisterAdaptersChangedEvent(HANDLE event, DWORD* cookie) override { | ||
| 990 | if (!event || !cookie) return DXGI_ERROR_INVALID_CALL; | ||
| 991 | std::lock_guard lock(adapters_changed_mutex_); | ||
| 992 | for (const auto& [registered_cookie, registered_event] : adapters_changed_events_) | ||
| 993 | if (registered_event == event) return DXGI_ERROR_INVALID_CALL; | ||
| 994 | const DWORD next = next_adapters_changed_cookie_++; | ||
| 995 | adapters_changed_events_.emplace(next, event); | ||
| 996 | *cookie = next; | ||
| 997 | return S_OK; | ||
| 998 | } | ||
| 999 | HRESULT STDMETHODCALLTYPE UnregisterAdaptersChangedEvent(DWORD cookie) override { | ||
| 1000 | std::lock_guard lock(adapters_changed_mutex_); | ||
| 1001 | return adapters_changed_events_.erase(cookie) ? S_OK : DXGI_ERROR_NOT_FOUND; | ||
| 1002 | } | ||
| 1003 | |||
| 970 | private: | 1004 | private: |
| 971 | bool probe_immediate_present_mode() const { | 1005 | bool probe_immediate_present_mode() const { |
| 972 | if (!gipa_ || !instance_ || !physical_) return false; | 1006 | if (!gipa_ || !instance_ || !physical_) return false; |
| @@ -1016,6 +1050,9 @@ private: | |||
| 1016 | mutable std::once_flag tearing_once_; | 1050 | mutable std::once_flag tearing_once_; |
| 1017 | bool tearing_supported_ = false; | 1051 | bool tearing_supported_ = false; |
| 1018 | std::atomic<DWORD> next_occlusion_cookie_{1}; | 1052 | std::atomic<DWORD> next_occlusion_cookie_{1}; |
| 1053 | std::mutex adapters_changed_mutex_; | ||
| 1054 | std::map<DWORD, HANDLE> adapters_changed_events_; | ||
| 1055 | DWORD next_adapters_changed_cookie_ = 1; | ||
| 1019 | }; | 1056 | }; |
| 1020 | 1057 | ||
| 1021 | } // namespace | 1058 | } // namespace |