Vulkan: correctly expose Vulkan entry points
This change fixes the advertisement of core Vulkan entry points as below:
1. GIPA returns a valid checked_proc for 1.1 core device APIs.
2. GDPA returns NULL for 1.1 core device APIs on a 1.0 physical device.
Bug: 134185757
Bug: 142266108
Test: dEQP-VK.memory.binding on 1.1 loader and 1.0 device ICD
Test: dEQP-VK.api.info.instance on 1.1 loader and 1.0 instance ICD
Change-Id: Ieb814516a4019f1a330178bfeb414e1450895c5c
Merged-In: I0a3e06dc04bade4f36a7e68ee2f53979c656ee4e
diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp
index 23506ba..c77fa06 100644
--- a/vulkan/libvulkan/driver.cpp
+++ b/vulkan/libvulkan/driver.cpp
@@ -104,6 +104,7 @@
VkResult Validate();
void DowngradeApiVersion();
+ void UpgradeDeviceCoreApiVersion(uint32_t api_version);
const std::bitset<ProcHook::EXTENSION_COUNT>& GetHookExtensions() const;
const std::bitset<ProcHook::EXTENSION_COUNT>& GetHalExtensions() const;
@@ -333,8 +334,12 @@
physical_dev_(VK_NULL_HANDLE),
instance_info_(create_info),
extension_filter_() {
- hook_extensions_.set(ProcHook::EXTENSION_CORE);
- hal_extensions_.set(ProcHook::EXTENSION_CORE);
+ // instance core versions need to match the loader api version
+ for (uint32_t i = ProcHook::EXTENSION_CORE_1_0;
+ i != ProcHook::EXTENSION_COUNT; ++i) {
+ hook_extensions_.set(i);
+ hal_extensions_.set(i);
+ }
}
CreateInfoWrapper::CreateInfoWrapper(VkPhysicalDevice physical_dev,
@@ -345,8 +350,9 @@
physical_dev_(physical_dev),
dev_info_(create_info),
extension_filter_() {
- hook_extensions_.set(ProcHook::EXTENSION_CORE);
- hal_extensions_.set(ProcHook::EXTENSION_CORE);
+ // initialize with baseline core API version
+ hook_extensions_.set(ProcHook::EXTENSION_CORE_1_0);
+ hal_extensions_.set(ProcHook::EXTENSION_CORE_1_0);
}
CreateInfoWrapper::~CreateInfoWrapper() {
@@ -545,7 +551,8 @@
case ProcHook::ANDROID_external_memory_android_hardware_buffer:
case ProcHook::ANDROID_native_buffer:
case ProcHook::GOOGLE_display_timing:
- case ProcHook::EXTENSION_CORE:
+ case ProcHook::EXTENSION_CORE_1_0:
+ case ProcHook::EXTENSION_CORE_1_1:
case ProcHook::EXTENSION_COUNT:
// Device and meta extensions. If we ever get here it's a bug in
// our code. But enumerating them lets us avoid having a default
@@ -593,7 +600,8 @@
case ProcHook::EXT_debug_report:
case ProcHook::EXT_swapchain_colorspace:
case ProcHook::ANDROID_native_buffer:
- case ProcHook::EXTENSION_CORE:
+ case ProcHook::EXTENSION_CORE_1_0:
+ case ProcHook::EXTENSION_CORE_1_1:
case ProcHook::EXTENSION_COUNT:
// Instance and meta extensions. If we ever get here it's a bug
// in our code. But enumerating them lets us avoid having a
@@ -641,6 +649,28 @@
}
}
+void CreateInfoWrapper::UpgradeDeviceCoreApiVersion(uint32_t api_version) {
+ ALOG_ASSERT(!is_instance_, "Device only API called by instance wrapper.");
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wold-style-cast"
+ api_version ^= VK_VERSION_PATCH(api_version);
+#pragma clang diagnostic pop
+ // cap the API version to the loader supported highest version
+ if (api_version > VK_API_VERSION_1_1)
+ api_version = VK_API_VERSION_1_1;
+ switch (api_version) {
+ case VK_API_VERSION_1_1:
+ hook_extensions_.set(ProcHook::EXTENSION_CORE_1_1);
+ hal_extensions_.set(ProcHook::EXTENSION_CORE_1_1);
+ [[clang::fallthrough]];
+ case VK_API_VERSION_1_0:
+ break;
+ default:
+ ALOGD("Unknown upgrade API version[%u]", api_version);
+ break;
+ }
+}
+
VKAPI_ATTR void* DefaultAllocate(void*,
size_t size,
size_t alignment,
@@ -776,7 +806,7 @@
: nullptr;
break;
case ProcHook::DEVICE:
- proc = (hook->extension == ProcHook::EXTENSION_CORE)
+ proc = (hook->extension == ProcHook::EXTENSION_CORE_1_0)
? hook->proc
: hook->checked_proc;
break;
@@ -1124,6 +1154,13 @@
if (!data)
return VK_ERROR_OUT_OF_HOST_MEMORY;
+ VkPhysicalDeviceProperties properties;
+ ATRACE_BEGIN("driver.GetPhysicalDeviceProperties");
+ instance_data.driver.GetPhysicalDeviceProperties(physicalDevice,
+ &properties);
+ ATRACE_END();
+
+ wrapper.UpgradeDeviceCoreApiVersion(properties.apiVersion);
data->hook_extensions |= wrapper.GetHookExtensions();
// call into the driver
@@ -1168,12 +1205,6 @@
return VK_ERROR_INCOMPATIBLE_DRIVER;
}
- VkPhysicalDeviceProperties properties;
- ATRACE_BEGIN("driver.GetPhysicalDeviceProperties");
- instance_data.driver.GetPhysicalDeviceProperties(physicalDevice,
- &properties);
- ATRACE_END();
-
if (properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_CPU) {
// Log that the app is hitting software Vulkan implementation
android::GraphicsEnv::getInstance().setCpuVulkanInUse();