diff options
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 47a53f7a2..e5a5fbcd3 100644 --- a/runtime/shims/dxgi_com.cpp +++ b/runtime/shims/dxgi_com.cpp | |||
| @@ -708,7 +708,7 @@ private: | |||
| 708 | std::shared_ptr<ReservationState> reservations_; | 708 | std::shared_ptr<ReservationState> reservations_; |
| 709 | }; | 709 | }; |
| 710 | 710 | ||
| 711 | class Factory final : public IDXGIFactory5 { | 711 | class Factory final : public IDXGIFactory7 { |
| 712 | public: | 712 | public: |
| 713 | Factory(leonida::VulkanContext& context, PFN_vkGetInstanceProcAddr gipa, VkInstance instance, | 713 | Factory(leonida::VulkanContext& context, PFN_vkGetInstanceProcAddr gipa, VkInstance instance, |
| 714 | VkPhysicalDevice physical, PFN_vkGetDeviceProcAddr gdpa, VkQueue queue, std::uint32_t queue_family) | 714 | VkPhysicalDevice physical, PFN_vkGetDeviceProcAddr gdpa, VkQueue queue, std::uint32_t queue_family) |
| @@ -727,8 +727,9 @@ public: | |||
| 727 | if (riid == __uuidof(IUnknown) || riid == __uuidof(IDXGIObject) || riid == __uuidof(IDXGIFactory) || | 727 | if (riid == __uuidof(IUnknown) || riid == __uuidof(IDXGIObject) || riid == __uuidof(IDXGIFactory) || |
| 728 | riid == __uuidof(IDXGIFactory1) || riid == __uuidof(IDXGIFactory2) || | 728 | riid == __uuidof(IDXGIFactory1) || riid == __uuidof(IDXGIFactory2) || |
| 729 | riid == __uuidof(IDXGIFactory3) || riid == __uuidof(IDXGIFactory4) || | 729 | riid == __uuidof(IDXGIFactory3) || riid == __uuidof(IDXGIFactory4) || |
| 730 | riid == __uuidof(IDXGIFactory5)) { | 730 | riid == __uuidof(IDXGIFactory5) || riid == __uuidof(IDXGIFactory6) || |
| 731 | *out = static_cast<IDXGIFactory5*>(this); | 731 | riid == __uuidof(IDXGIFactory7)) { |
| 732 | *out = static_cast<IDXGIFactory7*>(this); | ||
| 732 | AddRef(); | 733 | AddRef(); |
| 733 | return S_OK; | 734 | return S_OK; |
| 734 | } | 735 | } |
| @@ -870,6 +871,39 @@ public: | |||
| 870 | return E_INVALIDARG; | 871 | return E_INVALIDARG; |
| 871 | } | 872 | } |
| 872 | 873 | ||
| 874 | // IDXGIFactory6. The factory has one adapter, so every preference orders the same list. Measured on the host's | ||
| 875 | // dxgi.dll (Windows 11, RTX 3070): a preference outside the enum is accepted, a null `out` is | ||
| 876 | // DXGI_ERROR_INVALID_CALL, and an index past the end is DXGI_ERROR_NOT_FOUND with *out cleared. | ||
| 877 | HRESULT STDMETHODCALLTYPE EnumAdapterByGpuPreference(UINT index, DXGI_GPU_PREFERENCE, REFIID riid, | ||
| 878 | void** out) override { | ||
| 879 | if (!out) return DXGI_ERROR_INVALID_CALL; | ||
| 880 | *out = nullptr; | ||
| 881 | if (index != 0) return DXGI_ERROR_NOT_FOUND; | ||
| 882 | auto* adapter = new Adapter(this, gipa_, instance_, physical_); | ||
| 883 | const HRESULT hr = adapter->QueryInterface(riid, out); | ||
| 884 | adapter->Release(); | ||
| 885 | return hr; | ||
| 886 | } | ||
| 887 | |||
| 888 | // IDXGIFactory7. The adapter list never changes, so a registered event is never signalled; the registry only | ||
| 889 | // keeps the host's answers (same measurement): a null event or cookie and an event registered twice are | ||
| 890 | // DXGI_ERROR_INVALID_CALL, cookies start at 1 and are separate from the occlusion cookies, and an unknown | ||
| 891 | // cookie is DXGI_ERROR_NOT_FOUND. | ||
| 892 | HRESULT STDMETHODCALLTYPE RegisterAdaptersChangedEvent(HANDLE event, DWORD* cookie) override { | ||
| 893 | if (!event || !cookie) return DXGI_ERROR_INVALID_CALL; | ||
| 894 | std::lock_guard lock(adapters_changed_mutex_); | ||
| 895 | for (const auto& [registered_cookie, registered_event] : adapters_changed_events_) | ||
| 896 | if (registered_event == event) return DXGI_ERROR_INVALID_CALL; | ||
| 897 | const DWORD next = next_adapters_changed_cookie_++; | ||
| 898 | adapters_changed_events_.emplace(next, event); | ||
| 899 | *cookie = next; | ||
| 900 | return S_OK; | ||
| 901 | } | ||
| 902 | HRESULT STDMETHODCALLTYPE UnregisterAdaptersChangedEvent(DWORD cookie) override { | ||
| 903 | std::lock_guard lock(adapters_changed_mutex_); | ||
| 904 | return adapters_changed_events_.erase(cookie) ? S_OK : DXGI_ERROR_NOT_FOUND; | ||
| 905 | } | ||
| 906 | |||
| 873 | private: | 907 | private: |
| 874 | bool probe_immediate_present_mode() const { | 908 | bool probe_immediate_present_mode() const { |
| 875 | if (!gipa_ || !instance_ || !physical_) return false; | 909 | if (!gipa_ || !instance_ || !physical_) return false; |
| @@ -919,6 +953,9 @@ private: | |||
| 919 | mutable std::once_flag tearing_once_; | 953 | mutable std::once_flag tearing_once_; |
| 920 | bool tearing_supported_ = false; | 954 | bool tearing_supported_ = false; |
| 921 | std::atomic<DWORD> next_occlusion_cookie_{1}; | 955 | std::atomic<DWORD> next_occlusion_cookie_{1}; |
| 956 | std::mutex adapters_changed_mutex_; | ||
| 957 | std::map<DWORD, HANDLE> adapters_changed_events_; | ||
| 958 | DWORD next_adapters_changed_cookie_ = 1; | ||
| 922 | }; | 959 | }; |
| 923 | 960 | ||
| 924 | } // namespace | 961 | } // namespace |