From 3420cd78ac18867e18f7b60a0e653e8367fe8785 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Fri, 17 May 2024 21:07:37 +0200 Subject: [PATCH] [dxvk] Use new Version helper to deal with driver version numbers --- src/d3d9/d3d9_options.cpp | 4 +- src/dxvk/dxvk_adapter.cpp | 69 ++++++++++++++++++---------------- src/dxvk/dxvk_adapter.h | 15 +++++++- src/dxvk/dxvk_device.cpp | 12 +++--- src/dxvk/dxvk_device_info.h | 3 ++ src/dxvk/hud/dxvk_hud_item.cpp | 8 +--- 6 files changed, 63 insertions(+), 48 deletions(-) diff --git a/src/d3d9/d3d9_options.cpp b/src/d3d9/d3d9_options.cpp index fc3d0b48..1845daab 100644 --- a/src/d3d9/d3d9_options.cpp +++ b/src/d3d9/d3d9_options.cpp @@ -90,8 +90,8 @@ namespace dxvk { d3d9FloatEmulation = D3D9FloatEmulation::Enabled; } else { bool hasMulz = adapter != nullptr - && (adapter->matchesDriver(VK_DRIVER_ID_MESA_RADV, 0, 0) - || adapter->matchesDriver(VK_DRIVER_ID_MESA_NVK, 0, 0)); + && (adapter->matchesDriver(VK_DRIVER_ID_MESA_RADV) + || adapter->matchesDriver(VK_DRIVER_ID_MESA_NVK)); d3d9FloatEmulation = hasMulz ? D3D9FloatEmulation::Strict : D3D9FloatEmulation::Enabled; } diff --git a/src/dxvk/dxvk_adapter.cpp b/src/dxvk/dxvk_adapter.cpp index 182f7f03..4866465d 100644 --- a/src/dxvk/dxvk_adapter.cpp +++ b/src/dxvk/dxvk_adapter.cpp @@ -415,7 +415,7 @@ namespace dxvk { m_deviceFeatures.khrPresentWait.presentWait; // Unless we're on an Nvidia driver where these extensions are known to be broken - if (matchesDriver(VK_DRIVER_ID_NVIDIA_PROPRIETARY, 0, VK_MAKE_VERSION(535, 0, 0))) { + if (matchesDriver(VK_DRIVER_ID_NVIDIA_PROPRIETARY, Version(), Version(535, 0, 0))) { enabledFeatures.khrPresentId.presentId = VK_FALSE; enabledFeatures.khrPresentWait.presentWait = VK_FALSE; } @@ -430,10 +430,7 @@ namespace dxvk { // Log feature support info an extension list Logger::info(str::format("Device properties:" "\n Device : ", m_deviceInfo.core.properties.deviceName, - "\n Driver : ", m_deviceInfo.vk12.driverName, " ", - VK_VERSION_MAJOR(m_deviceInfo.core.properties.driverVersion), ".", - VK_VERSION_MINOR(m_deviceInfo.core.properties.driverVersion), ".", - VK_VERSION_PATCH(m_deviceInfo.core.properties.driverVersion))); + "\n Driver : ", m_deviceInfo.vk12.driverName, " ", m_deviceInfo.driverVersion.toString())); Logger::info("Enabled device extensions:"); this->logNameList(extensionNameList); @@ -631,9 +628,7 @@ namespace dxvk { Logger::info(str::format("Device properties:" "\n Device name: ", m_deviceInfo.core.properties.deviceName, "\n Driver: ", m_deviceInfo.vk12.driverName, " ", - VK_VERSION_MAJOR(m_deviceInfo.core.properties.driverVersion), ".", - VK_VERSION_MINOR(m_deviceInfo.core.properties.driverVersion), ".", - VK_VERSION_PATCH(m_deviceInfo.core.properties.driverVersion))); + m_deviceInfo.driverVersion.toString())); Logger::info("Enabled device extensions:"); this->logNameList(extensionNameList); @@ -669,26 +664,29 @@ namespace dxvk { bool DxvkAdapter::matchesDriver( VkDriverIdKHR driver, - uint32_t minVer, - uint32_t maxVer) const { + Version minVer, + Version maxVer) const { bool driverMatches = driver == m_deviceInfo.vk12.driverID; - if (minVer) driverMatches &= m_deviceInfo.core.properties.driverVersion >= minVer; - if (maxVer) driverMatches &= m_deviceInfo.core.properties.driverVersion < maxVer; + if (minVer) driverMatches &= m_deviceInfo.driverVersion >= minVer; + if (maxVer) driverMatches &= m_deviceInfo.driverVersion < maxVer; return driverMatches; } + bool DxvkAdapter::matchesDriver( + VkDriverIdKHR driver) const { + return driver == m_deviceInfo.vk12.driverID; + } + + void DxvkAdapter::logAdapterInfo() const { const auto deviceInfo = this->devicePropertiesExt(); const auto memoryInfo = this->memoryProperties(); Logger::info(str::format(deviceInfo.core.properties.deviceName, ":", - "\n Driver : ", deviceInfo.vk12.driverName, " ", - VK_VERSION_MAJOR(deviceInfo.core.properties.driverVersion), ".", - VK_VERSION_MINOR(deviceInfo.core.properties.driverVersion), ".", - VK_VERSION_PATCH(deviceInfo.core.properties.driverVersion))); + "\n Driver : ", deviceInfo.vk12.driverName, " ", deviceInfo.driverVersion.toString())); for (uint32_t i = 0; i < memoryInfo.memoryHeapCount; i++) { constexpr VkDeviceSize mib = 1024 * 1024; @@ -790,22 +788,8 @@ namespace dxvk { m_vki->vkGetPhysicalDeviceProperties2(m_handle, &m_deviceInfo.core); // Some drivers reports the driver version in a slightly different format - switch (m_deviceInfo.vk12.driverID) { - case VK_DRIVER_ID_NVIDIA_PROPRIETARY: - m_deviceInfo.core.properties.driverVersion = VK_MAKE_VERSION( - (m_deviceInfo.core.properties.driverVersion >> 22) & 0x3ff, - (m_deviceInfo.core.properties.driverVersion >> 14) & 0x0ff, - (m_deviceInfo.core.properties.driverVersion >> 6) & 0x0ff); - break; - - case VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS: - m_deviceInfo.core.properties.driverVersion = VK_MAKE_VERSION( - m_deviceInfo.core.properties.driverVersion >> 14, - m_deviceInfo.core.properties.driverVersion & 0x3fff, 0); - break; - - default:; - } + m_deviceInfo.driverVersion = decodeDriverVersion( + m_deviceInfo.vk12.driverID, m_deviceInfo.core.properties.driverVersion); } @@ -1321,4 +1305,25 @@ namespace dxvk { "\n Sparse : ", queues.sparse != VK_QUEUE_FAMILY_IGNORED ? str::format(queues.sparse) : "n/a")); } + + Version DxvkAdapter::decodeDriverVersion(VkDriverId driverId, uint32_t version) { + switch (driverId) { + case VK_DRIVER_ID_NVIDIA_PROPRIETARY: + return Version( + (version >> 22) & 0x3ff, + (version >> 14) & 0x0ff, + (version >> 6) & 0x0ff); + break; + + case VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS: + return Version(version >> 14, version & 0x3fff, 0); + + default: + return Version( + VK_API_VERSION_MAJOR(version), + VK_API_VERSION_MINOR(version), + VK_API_VERSION_PATCH(version)); + } + } + } diff --git a/src/dxvk/dxvk_adapter.h b/src/dxvk/dxvk_adapter.h index ad3ca23c..04c9c9ba 100644 --- a/src/dxvk/dxvk_adapter.h +++ b/src/dxvk/dxvk_adapter.h @@ -255,8 +255,17 @@ namespace dxvk { */ bool matchesDriver( VkDriverIdKHR driver, - uint32_t minVer, - uint32_t maxVer) const; + Version minVer, + Version maxVer) const; + + /** + * \brief Tests if the driver matches certain criteria + * + * \param [in] driver Driver ID + * \returns \c True if the driver matches these criteria + */ + bool matchesDriver( + VkDriverIdKHR driver) const; /** * \brief Logs DXVK adapter info @@ -343,6 +352,8 @@ namespace dxvk { static void logFeatures(const DxvkDeviceFeatures& features); static void logQueueFamilies(const DxvkAdapterQueueIndices& queues); + static Version decodeDriverVersion(VkDriverId driverId, uint32_t version); + }; } diff --git a/src/dxvk/dxvk_device.cpp b/src/dxvk/dxvk_device.cpp index 9a053791..226596f0 100644 --- a/src/dxvk/dxvk_device.cpp +++ b/src/dxvk/dxvk_device.cpp @@ -82,7 +82,7 @@ namespace dxvk { // Disable lifetime tracking for drivers that do not have any // significant issues with 32-bit address space to begin with - if (m_adapter->matchesDriver(VK_DRIVER_ID_MESA_RADV_KHR, 0, 0)) + if (m_adapter->matchesDriver(VK_DRIVER_ID_MESA_RADV_KHR)) return false; return true; @@ -325,12 +325,12 @@ namespace dxvk { DxvkDevicePerfHints DxvkDevice::getPerfHints() { DxvkDevicePerfHints hints; hints.preferFbDepthStencilCopy = m_features.extShaderStencilExport - && (m_adapter->matchesDriver(VK_DRIVER_ID_MESA_RADV_KHR, 0, 0) - || m_adapter->matchesDriver(VK_DRIVER_ID_AMD_OPEN_SOURCE_KHR, 0, 0) - || m_adapter->matchesDriver(VK_DRIVER_ID_AMD_PROPRIETARY_KHR, 0, 0)); + && (m_adapter->matchesDriver(VK_DRIVER_ID_MESA_RADV_KHR) + || m_adapter->matchesDriver(VK_DRIVER_ID_AMD_OPEN_SOURCE_KHR) + || m_adapter->matchesDriver(VK_DRIVER_ID_AMD_PROPRIETARY_KHR)); hints.preferFbResolve = m_features.amdShaderFragmentMask - && (m_adapter->matchesDriver(VK_DRIVER_ID_AMD_OPEN_SOURCE_KHR, 0, 0) - || m_adapter->matchesDriver(VK_DRIVER_ID_AMD_PROPRIETARY_KHR, 0, 0)); + && (m_adapter->matchesDriver(VK_DRIVER_ID_AMD_OPEN_SOURCE_KHR) + || m_adapter->matchesDriver(VK_DRIVER_ID_AMD_PROPRIETARY_KHR)); return hints; } diff --git a/src/dxvk/dxvk_device_info.h b/src/dxvk/dxvk_device_info.h index c1da783a..a629c01e 100644 --- a/src/dxvk/dxvk_device_info.h +++ b/src/dxvk/dxvk_device_info.h @@ -2,6 +2,8 @@ #include "dxvk_include.h" +#include "../util/util_version.h" + namespace dxvk { /** @@ -13,6 +15,7 @@ namespace dxvk { * so before using them, check whether they are supported. */ struct DxvkDeviceInfo { + Version driverVersion; VkPhysicalDeviceProperties2 core; VkPhysicalDeviceVulkan11Properties vk11; VkPhysicalDeviceVulkan12Properties vk12; diff --git a/src/dxvk/hud/dxvk_hud_item.cpp b/src/dxvk/hud/dxvk_hud_item.cpp index cbabd658..699262ea 100644 --- a/src/dxvk/hud/dxvk_hud_item.cpp +++ b/src/dxvk/hud/dxvk_hud_item.cpp @@ -129,12 +129,8 @@ namespace dxvk::hud { std::string driverInfo = props.vk12.driverInfo; - if (driverInfo.empty()) { - driverInfo = str::format( - VK_VERSION_MAJOR(props.core.properties.driverVersion), ".", - VK_VERSION_MINOR(props.core.properties.driverVersion), ".", - VK_VERSION_PATCH(props.core.properties.driverVersion)); - } + if (driverInfo.empty()) + driverInfo = props.driverVersion.toString(); m_deviceName = props.core.properties.deviceName; m_driverName = str::format("Driver: ", props.vk12.driverName);