OSDN Git Service

Inline GetPhysicalDeviceProperties2 into QueryPresentationProperties s-x86
authorChris Forbes <chrisforbes@google.com>
Thu, 22 Jul 2021 20:54:04 +0000 (13:54 -0700)
committerMauro Rossi <issor.oruam@gmail.com>
Mon, 24 Jul 2023 16:03:31 +0000 (18:03 +0200)
In general, we implement the 1.1 instance / physical device API as
preferring to call the native 1.1 function if available; otherwise
falling back to calling the equivalent GPDP2 function. If the
underlying driver supports *neither* then any caller of that function
has already invoked UB by calling it and so falling over is acceptable.

Unfortunately, the loader itself does call vkGetPhysicalDeviceProperties2
in one case, regardless of what the driver may support, in order to
determine whether the platform's swapchain implementation should expose
some features. On a 1.0 driver without the GPDP2 extension, this caused
trouble.

As a slight further wrinkle, vkGetPhysicalDeviceProperties2 "cannot
fail", making propagating a failure back up through the loader annoying.

As a workaround, inline the calls to GetPhysicalDeviceProperties2 and
GetPhysicalDeviceProperties2KHR into QueryPresentationProperties, where
we can handle our one special case of both function pointers being
missing but behavior being defined.

Bug: b/192130684
Change-Id: Iff2bae98b7931bed80fafd895cf57061becabd8d
(cherry picked from commit e056c12782125c3ad5876f3ac7528d9889808675)

vulkan/libvulkan/driver.cpp

index d7fdab5..cf774fd 100644 (file)
@@ -979,6 +979,8 @@ VkResult EnumerateInstanceExtensionProperties(
 void QueryPresentationProperties(
     VkPhysicalDevice physicalDevice,
     VkPhysicalDevicePresentationPropertiesANDROID* presentation_properties) {
+    ATRACE_CALL();
+
     // Request the android-specific presentation properties via GPDP2
     VkPhysicalDeviceProperties2 properties = {
         VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,
@@ -994,7 +996,17 @@ void QueryPresentationProperties(
     presentation_properties->pNext = nullptr;
     presentation_properties->sharedImage = VK_FALSE;
 
-    GetPhysicalDeviceProperties2(physicalDevice, &properties);
+    const auto& driver = GetData(physicalDevice).driver;
+
+    if (driver.GetPhysicalDeviceProperties2) {
+        // >= 1.1 driver, supports core GPDP2 entrypoint.
+        driver.GetPhysicalDeviceProperties2(physicalDevice, &properties);
+    } else if (driver.GetPhysicalDeviceProperties2KHR) {
+        // Old driver, but may support presentation properties
+        // if we have the GPDP2 extension. Otherwise, no presentation
+        // properties supported.
+        driver.GetPhysicalDeviceProperties2KHR(physicalDevice, &properties);
+    }
 }
 
 VkResult EnumerateDeviceExtensionProperties(