diff options
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 734824e07..4362328d3 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 <cstdio> | 9 | #include <cstdio> |
| @@ -538,12 +541,45 @@ std::uint32_t primary_device_local_heap(const VkPhysicalDeviceMemoryProperties& | |||
| 538 | 541 | ||
| 539 | // Vulkan-backed IDXGIAdapter3 reporting the physical device's name, IDs, LUID (matching | 542 | // Vulkan-backed IDXGIAdapter3 reporting the physical device's name, IDs, LUID (matching |
| 540 | // ID3D12Device::GetAdapterLuid), memory heap sizes, and video memory budget info. | 543 | // ID3D12Device::GetAdapterLuid), memory heap sizes, and video memory budget info. |
| 544 | |||
| 545 | // The adapter's user-mode driver version, as DXGI's CheckInterfaceSupport(IDXGIDevice) reports it: what | ||
| 546 | // D3DKMTQueryAdapterInfo(KMTQAITYPE_UMD_DRIVER_VERSION) gives for the adapter's LUID (measured equal to host DXGI on | ||
| 547 | // an RTX 5060 Ti, 0x0020000000100842 for driver 621.14, and on WARP). gdi32's entry points are looked up at run | ||
| 548 | // time and the host dxgi.dll isn't used; 0 when they are missing (Wine) or the query fails. | ||
| 549 | LARGE_INTEGER umd_driver_version(LUID luid) { | ||
| 550 | LARGE_INTEGER version{}; | ||
| 551 | if (!luid.LowPart && !luid.HighPart) return version; | ||
| 552 | HMODULE gdi32 = GetModuleHandleW(L"gdi32.dll"); | ||
| 553 | if (!gdi32) gdi32 = LoadLibraryW(L"gdi32.dll"); | ||
| 554 | if (!gdi32) return version; | ||
| 555 | const auto open = reinterpret_cast<decltype(&D3DKMTOpenAdapterFromLuid)>( | ||
| 556 | GetProcAddress(gdi32, "D3DKMTOpenAdapterFromLuid")); | ||
| 557 | const auto query = reinterpret_cast<decltype(&D3DKMTQueryAdapterInfo)>( | ||
| 558 | GetProcAddress(gdi32, "D3DKMTQueryAdapterInfo")); | ||
| 559 | const auto close = reinterpret_cast<decltype(&D3DKMTCloseAdapter)>(GetProcAddress(gdi32, "D3DKMTCloseAdapter")); | ||
| 560 | if (!open || !query || !close) return version; | ||
| 561 | D3DKMT_OPENADAPTERFROMLUID adapter{}; | ||
| 562 | adapter.AdapterLuid = luid; | ||
| 563 | if (open(&adapter) != 0) return version; | ||
| 564 | D3DKMT_UMD_DRIVER_VERSION umd{}; | ||
| 565 | D3DKMT_QUERYADAPTERINFO info{}; | ||
| 566 | info.hAdapter = adapter.hAdapter; | ||
| 567 | info.Type = KMTQAITYPE_UMD_DRIVER_VERSION; | ||
| 568 | info.pPrivateDriverData = &umd; | ||
| 569 | info.PrivateDriverDataSize = sizeof(umd); | ||
| 570 | if (query(&info) == 0) version = umd.DriverVersion; | ||
| 571 | D3DKMT_CLOSEADAPTER closing{adapter.hAdapter}; | ||
| 572 | close(&closing); | ||
| 573 | return version; | ||
| 574 | } | ||
| 575 | |||
| 541 | class Adapter final : public IDXGIAdapter3 { | 576 | class Adapter final : public IDXGIAdapter3 { |
| 542 | public: | 577 | public: |
| 543 | Adapter(IDXGIFactory4* parent, PFN_vkGetInstanceProcAddr gipa, VkInstance instance, VkPhysicalDevice physical) | 578 | Adapter(IDXGIFactory4* parent, PFN_vkGetInstanceProcAddr gipa, VkInstance instance, VkPhysicalDevice physical) |
| 544 | : parent_(parent), gipa_(gipa), instance_(instance), physical_(physical) { | 579 | : parent_(parent), gipa_(gipa), instance_(instance), physical_(physical) { |
| 545 | if (parent_) parent_->AddRef(); | 580 | if (parent_) parent_->AddRef(); |
| 546 | populate_desc(); | 581 | populate_desc(); |
| 582 | umd_version_ = umd_driver_version(desc_.AdapterLuid); | ||
| 547 | reservations_ = adapter_reservation_state(desc_.AdapterLuid, physical_); | 583 | reservations_ = adapter_reservation_state(desc_.AdapterLuid, physical_); |
| 548 | } | 584 | } |
| 549 | 585 | ||
| @@ -603,7 +639,7 @@ public: | |||
| 603 | } | 639 | } |
| 604 | HRESULT STDMETHODCALLTYPE CheckInterfaceSupport(REFGUID interface_name, LARGE_INTEGER* umd_version) override { | 640 | HRESULT STDMETHODCALLTYPE CheckInterfaceSupport(REFGUID interface_name, LARGE_INTEGER* umd_version) override { |
| 605 | if (interface_name == __uuidof(IDXGIDevice)) { | 641 | if (interface_name == __uuidof(IDXGIDevice)) { |
| 606 | if (umd_version) umd_version->QuadPart = 0; | 642 | if (umd_version) *umd_version = umd_version_; |
| 607 | return S_OK; | 643 | return S_OK; |
| 608 | } | 644 | } |
| 609 | return DXGI_ERROR_UNSUPPORTED; | 645 | return DXGI_ERROR_UNSUPPORTED; |
| @@ -772,6 +808,7 @@ private: | |||
| 772 | VkInstance instance_ = VK_NULL_HANDLE; | 808 | VkInstance instance_ = VK_NULL_HANDLE; |
| 773 | VkPhysicalDevice physical_ = VK_NULL_HANDLE; | 809 | VkPhysicalDevice physical_ = VK_NULL_HANDLE; |
| 774 | DXGI_ADAPTER_DESC2 desc_{}; | 810 | DXGI_ADAPTER_DESC2 desc_{}; |
| 811 | LARGE_INTEGER umd_version_{}; // CheckInterfaceSupport(IDXGIDevice): the adapter's user-mode driver version | ||
| 775 | bool has_memory_budget_ = false; | 812 | bool has_memory_budget_ = false; |
| 776 | std::shared_ptr<ReservationState> reservations_; | 813 | std::shared_ptr<ReservationState> reservations_; |
| 777 | }; | 814 | }; |