diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 23:13:01 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 23:13:01 -0500 |
| commit | c250b5858031d196ba72399abde1f139bbb9d6cf (patch) | |
| tree | 44053a3476f44ae761be785e3a4bc75ca44b0211 /runtime/shims/dxgi_com.cpp | |
| parent | 03e12003a841369d9aa7629d0616aaff1b834d4c (diff) | |
| parent | e27efbc11dca3b6a16ea9013a2316ed4ee9f3c4a (diff) | |
Merge pull request #4273 from Exopus
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/shims/dxgi_com.cpp')
| -rw-r--r-- | runtime/shims/dxgi_com.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/runtime/shims/dxgi_com.cpp b/runtime/shims/dxgi_com.cpp index 86be935a4..30f0f69a4 100644 --- a/runtime/shims/dxgi_com.cpp +++ b/runtime/shims/dxgi_com.cpp | |||
| @@ -1,6 +1,9 @@ | |||
| 1 | #include "dxgi_com.h" | 1 | #include "dxgi_com.h" |
| 2 | #include "d3d12_stubs.h" | 2 | #include "d3d12_stubs.h" |
| 3 | 3 | ||
| 4 | #include <winternl.h> // NTSTATUS, which d3dkmthk.h needs and WIN32_LEAN_AND_MEAN leaves out | ||
| 5 | #include <d3dkmthk.h> | ||
| 6 | |||
| 4 | #include <algorithm> | 7 | #include <algorithm> |
| 5 | #include <atomic> | 8 | #include <atomic> |
| 6 | #include <cstdint> | 9 | #include <cstdint> |
| @@ -1047,12 +1050,45 @@ private: | |||
| 1047 | 1050 | ||
| 1048 | // Vulkan-backed IDXGIAdapter3 reporting the physical device's name, IDs, LUID (matching | 1051 | // Vulkan-backed IDXGIAdapter3 reporting the physical device's name, IDs, LUID (matching |
| 1049 | // ID3D12Device::GetAdapterLuid), memory heap sizes, and video memory budget info. | 1052 | // ID3D12Device::GetAdapterLuid), memory heap sizes, and video memory budget info. |
| 1053 | |||
| 1054 | // The adapter's user-mode driver version, as DXGI's CheckInterfaceSupport(IDXGIDevice) reports it: what | ||
| 1055 | // D3DKMTQueryAdapterInfo(KMTQAITYPE_UMD_DRIVER_VERSION) gives for the adapter's LUID (measured equal to host DXGI on | ||
| 1056 | // an RTX 5060 Ti, 0x0020000000100842 for driver 621.14, and on WARP). gdi32's entry points are looked up at run | ||
| 1057 | // time and the host dxgi.dll isn't used; 0 when they are missing (Wine) or the query fails. | ||
| 1058 | LARGE_INTEGER umd_driver_version(LUID luid) { | ||
| 1059 | LARGE_INTEGER version{}; | ||
| 1060 | if (!luid.LowPart && !luid.HighPart) return version; | ||
| 1061 | HMODULE gdi32 = GetModuleHandleW(L"gdi32.dll"); | ||
| 1062 | if (!gdi32) gdi32 = LoadLibraryW(L"gdi32.dll"); | ||
| 1063 | if (!gdi32) return version; | ||
| 1064 | const auto open = reinterpret_cast<decltype(&D3DKMTOpenAdapterFromLuid)>( | ||
| 1065 | GetProcAddress(gdi32, "D3DKMTOpenAdapterFromLuid")); | ||
| 1066 | const auto query = reinterpret_cast<decltype(&D3DKMTQueryAdapterInfo)>( | ||
| 1067 | GetProcAddress(gdi32, "D3DKMTQueryAdapterInfo")); | ||
| 1068 | const auto close = reinterpret_cast<decltype(&D3DKMTCloseAdapter)>(GetProcAddress(gdi32, "D3DKMTCloseAdapter")); | ||
| 1069 | if (!open || !query || !close) return version; | ||
| 1070 | D3DKMT_OPENADAPTERFROMLUID adapter{}; | ||
| 1071 | adapter.AdapterLuid = luid; | ||
| 1072 | if (open(&adapter) != 0) return version; | ||
| 1073 | D3DKMT_UMD_DRIVER_VERSION umd{}; | ||
| 1074 | D3DKMT_QUERYADAPTERINFO info{}; | ||
| 1075 | info.hAdapter = adapter.hAdapter; | ||
| 1076 | info.Type = KMTQAITYPE_UMD_DRIVER_VERSION; | ||
| 1077 | info.pPrivateDriverData = &umd; | ||
| 1078 | info.PrivateDriverDataSize = sizeof(umd); | ||
| 1079 | if (query(&info) == 0) version = umd.DriverVersion; | ||
| 1080 | D3DKMT_CLOSEADAPTER closing{adapter.hAdapter}; | ||
| 1081 | close(&closing); | ||
| 1082 | return version; | ||
| 1083 | } | ||
| 1084 | |||
| 1050 | class Adapter final : public IDXGIAdapter3 { | 1085 | class Adapter final : public IDXGIAdapter3 { |
| 1051 | public: | 1086 | public: |
| 1052 | Adapter(IDXGIFactory4* parent, PFN_vkGetInstanceProcAddr gipa, VkInstance instance, VkPhysicalDevice physical) | 1087 | Adapter(IDXGIFactory4* parent, PFN_vkGetInstanceProcAddr gipa, VkInstance instance, VkPhysicalDevice physical) |
| 1053 | : parent_(parent), gipa_(gipa), instance_(instance), physical_(physical) { | 1088 | : parent_(parent), gipa_(gipa), instance_(instance), physical_(physical) { |
| 1054 | if (parent_) parent_->AddRef(); | 1089 | if (parent_) parent_->AddRef(); |
| 1055 | populate_desc(); | 1090 | populate_desc(); |
| 1091 | umd_version_ = umd_driver_version(desc_.AdapterLuid); | ||
| 1056 | reservations_ = adapter_reservation_state(desc_.AdapterLuid, physical_); | 1092 | reservations_ = adapter_reservation_state(desc_.AdapterLuid, physical_); |
| 1057 | } | 1093 | } |
| 1058 | 1094 | ||
| @@ -1122,7 +1158,7 @@ public: | |||
| 1122 | } | 1158 | } |
| 1123 | HRESULT STDMETHODCALLTYPE CheckInterfaceSupport(REFGUID interface_name, LARGE_INTEGER* umd_version) override { | 1159 | HRESULT STDMETHODCALLTYPE CheckInterfaceSupport(REFGUID interface_name, LARGE_INTEGER* umd_version) override { |
| 1124 | if (interface_name == __uuidof(IDXGIDevice)) { | 1160 | if (interface_name == __uuidof(IDXGIDevice)) { |
| 1125 | if (umd_version) umd_version->QuadPart = 0; | 1161 | if (umd_version) *umd_version = umd_version_; |
| 1126 | return S_OK; | 1162 | return S_OK; |
| 1127 | } | 1163 | } |
| 1128 | return DXGI_ERROR_UNSUPPORTED; | 1164 | return DXGI_ERROR_UNSUPPORTED; |
| @@ -1292,6 +1328,7 @@ private: | |||
| 1292 | VkInstance instance_ = VK_NULL_HANDLE; | 1328 | VkInstance instance_ = VK_NULL_HANDLE; |
| 1293 | VkPhysicalDevice physical_ = VK_NULL_HANDLE; | 1329 | VkPhysicalDevice physical_ = VK_NULL_HANDLE; |
| 1294 | DXGI_ADAPTER_DESC2 desc_{}; | 1330 | DXGI_ADAPTER_DESC2 desc_{}; |
| 1331 | LARGE_INTEGER umd_version_{}; // CheckInterfaceSupport(IDXGIDevice): the adapter's user-mode driver version | ||
| 1295 | bool has_memory_budget_ = false; | 1332 | bool has_memory_budget_ = false; |
| 1296 | std::shared_ptr<ReservationState> reservations_; | 1333 | std::shared_ptr<ReservationState> reservations_; |
| 1297 | }; | 1334 | }; |