From 0d7dcabdac86bd4e5e4713b9d2a9d6894b29d22a Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 31 Jan 2022 12:42:46 +0000 Subject: [PATCH] Clamp version for vulkan 1.3 drivers that don't support BDA cap/replay --- .../driver/vulkan/wrappers/vk_get_funcs.cpp | 49 ++++++++++++++++++- util/test/demos/vk/vk_test.cpp | 3 +- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/renderdoc/driver/vulkan/wrappers/vk_get_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_get_funcs.cpp index c9eecc811..7e092062e 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_get_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_get_funcs.cpp @@ -44,6 +44,45 @@ void MakeFakeUUID() } } +void ClampPhysDevAPIVersion(VkPhysicalDeviceProperties *pProperties, VkPhysicalDevice physicalDevice) +{ + // for Vulkan 1.3 bufferDeviceAddress is core. If the bufferDeviceAddressCaptureReplay feature is + // not available, we can't support it so we must clamp to version 1.2 for that physical device. + if(pProperties->apiVersion >= VK_API_VERSION_1_3) + { + // for 1.1 this is core so we should definitely have this function. + if(ObjDisp(physicalDevice)->GetPhysicalDeviceFeatures2 != NULL) + { + VkPhysicalDeviceFeatures2 features = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; + + // similarly this struct must be valid if the device is 1.3 + VkPhysicalDeviceVulkan12Features vk12 = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES}; + + features.pNext = &vk12; + + ObjDisp(physicalDevice)->GetPhysicalDeviceFeatures2(Unwrap(physicalDevice), &features); + + if(vk12.bufferDeviceAddressCaptureReplay == VK_FALSE) + { + RDCWARN( + "Vulkan feature bufferDeviceAddressCaptureReplay is not available. Clamping physical " + "device %s from reported version %d.%d to 1.2", + pProperties->deviceName, VK_VERSION_MAJOR(pProperties->apiVersion), + VK_VERSION_MINOR(pProperties->apiVersion)); + + pProperties->apiVersion = VK_API_VERSION_1_2; + } + } + else + { + // if we don't have GPDP2 the application has not initialised the instance at 1.3+ + // let's clamp the version just to be safe since we can't check, and this will help protect + // against buggy applications + pProperties->apiVersion = VK_API_VERSION_1_2; + } + } +} + void WrappedVulkan::vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures *pFeatures) { @@ -194,6 +233,8 @@ void WrappedVulkan::vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevic MakeFakeUUID(); memcpy(pProperties->pipelineCacheUUID, fakeRenderDocUUID, VK_UUID_SIZE); + + ClampPhysDevAPIVersion(pProperties, physicalDevice); } void WrappedVulkan::vkGetPhysicalDeviceQueueFamilyProperties( @@ -765,7 +806,13 @@ void WrappedVulkan::vkGetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice void WrappedVulkan::vkGetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties2 *pProperties) { - return ObjDisp(physicalDevice)->GetPhysicalDeviceProperties2(Unwrap(physicalDevice), pProperties); + ObjDisp(physicalDevice)->GetPhysicalDeviceProperties2(Unwrap(physicalDevice), pProperties); + + MakeFakeUUID(); + + memcpy(pProperties->properties.pipelineCacheUUID, fakeRenderDocUUID, VK_UUID_SIZE); + + ClampPhysDevAPIVersion(&pProperties->properties, physicalDevice); } void WrappedVulkan::vkGetPhysicalDeviceQueueFamilyProperties2( diff --git a/util/test/demos/vk/vk_test.cpp b/util/test/demos/vk/vk_test.cpp index 270875af4..816ff38e0 100644 --- a/util/test/demos/vk/vk_test.cpp +++ b/util/test/demos/vk/vk_test.cpp @@ -659,7 +659,8 @@ bool VulkanGraphicsTest::Init() vmaCreateAllocator(&allocInfo, &allocator); - TEST_LOG("Running Vulkan test on %s", physProperties.deviceName); + TEST_LOG("Running Vulkan test on %s (version %d.%d)", physProperties.deviceName, + VK_VERSION_MAJOR(physProperties.apiVersion), VK_VERSION_MINOR(physProperties.apiVersion)); return true; }