From e137086383e5370cfc7880317fc3a1470762aacb Mon Sep 17 00:00:00 2001 From: Marcin Radomski Date: Wed, 7 Aug 2024 21:54:45 +0200 Subject: [PATCH] vkGetPhysicalDeviceImageFormatProperties2: support drm modifiers Passed via VkDrmFormatModifierPropertiesListEXT. When not supported by the host, emulate DRM_FORMAT_MODIFIER_LINEAR with VK_IMAGE_TILING_LINEAR. Reviewed-by: Aaron Ruby Acked-by: Yonggang Luo Acked-by: Adam Jackson Part-of: --- .../guest/vulkan_enc/ResourceTracker.cpp | 39 +++++++++++++++---- src/gfxstream/guest/vulkan_enc/vk_struct_id.h | 2 + 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/gfxstream/guest/vulkan_enc/ResourceTracker.cpp b/src/gfxstream/guest/vulkan_enc/ResourceTracker.cpp index e8b8aaf09d3..49effaffb65 100644 --- a/src/gfxstream/guest/vulkan_enc/ResourceTracker.cpp +++ b/src/gfxstream/guest/vulkan_enc/ResourceTracker.cpp @@ -6750,19 +6750,25 @@ VkResult ResourceTracker::on_vkGetPhysicalDeviceImageFormatProperties2_common( const VkPhysicalDeviceImageDrmFormatModifierInfoEXT* drmFmtMod = vk_find_struct(pImageFormatInfo); + VkDrmFormatModifierPropertiesListEXT* emulatedDrmFmtModPropsList = nullptr; if (drmFmtMod) { if (getHostDeviceExtensionIndex(VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME) != -1) { // Host supports DRM format modifiers => leave the input unchanged. } else { + mesa_logd("emulating DRM_FORMAT_MOD_LINEAR with VK_IMAGE_TILING_LINEAR"); + emulatedDrmFmtModPropsList = + vk_find_struct(pImageFormatProperties); + // Host doesn't support DRM format modifiers, try emulating. - if (drmFmtMod->drmFormatModifier == DRM_FORMAT_MOD_LINEAR) { - mesa_logd("emulating DRM_FORMAT_MOD_LINEAR with VK_IMAGE_TILING_LINEAR"); - localImageFormatInfo.tiling = VK_IMAGE_TILING_LINEAR; - pImageFormatInfo = &localImageFormatInfo; - // Leave drmFormatMod in the input; it should be ignored when - // tiling is not VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT - } else { - return VK_ERROR_FORMAT_NOT_SUPPORTED; + if (drmFmtMod) { + if (drmFmtMod->drmFormatModifier == DRM_FORMAT_MOD_LINEAR) { + localImageFormatInfo.tiling = VK_IMAGE_TILING_LINEAR; + pImageFormatInfo = &localImageFormatInfo; + // Leave drmFormatMod in the input; it should be ignored when + // tiling is not VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT + } else { + return VK_ERROR_FORMAT_NOT_SUPPORTED; + } } } } @@ -6780,6 +6786,23 @@ VkResult ResourceTracker::on_vkGetPhysicalDeviceImageFormatProperties2_common( if (hostRes != VK_SUCCESS) return hostRes; +#ifdef LINUX_GUEST_BUILD + if (emulatedDrmFmtModPropsList) { + VkFormatProperties formatProperties; + enc->vkGetPhysicalDeviceFormatProperties(physicalDevice, localImageFormatInfo.format, + &formatProperties, true /* do lock */); + + emulatedDrmFmtModPropsList->drmFormatModifierCount = 1; + if (emulatedDrmFmtModPropsList->pDrmFormatModifierProperties) { + emulatedDrmFmtModPropsList->pDrmFormatModifierProperties[0] = { + .drmFormatModifier = DRM_FORMAT_MOD_LINEAR, + .drmFormatModifierPlaneCount = 1, + .drmFormatModifierTilingFeatures = formatProperties.linearTilingFeatures, + }; + } + } +#endif // LINUX_GUEST_BUILD + #ifdef VK_USE_PLATFORM_FUCHSIA if (ext_img_properties) { if (ext_img_info) { diff --git a/src/gfxstream/guest/vulkan_enc/vk_struct_id.h b/src/gfxstream/guest/vulkan_enc/vk_struct_id.h index e47b7457726..212f2c321ee 100644 --- a/src/gfxstream/guest/vulkan_enc/vk_struct_id.h +++ b/src/gfxstream/guest/vulkan_enc/vk_struct_id.h @@ -140,6 +140,8 @@ REGISTER_VK_STRUCT_ID(VkImageDrmFormatModifierExplicitCreateInfoEXT, REGISTER_VK_STRUCT_ID(VkFormatProperties2, VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2); REGISTER_VK_STRUCT_ID(VkPhysicalDeviceImageDrmFormatModifierInfoEXT, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_DRM_FORMAT_MODIFIER_INFO_EXT); +REGISTER_VK_STRUCT_ID(VkDrmFormatModifierPropertiesListEXT, + VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT); #undef REGISTER_VK_STRUCT_ID