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 <aruby@blackberry.com>
Acked-by: Yonggang Luo <luoyonggang@gmail.com>
Acked-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27246>
This commit is contained in:
Marcin Radomski 2024-08-07 21:54:45 +02:00 committed by Marge Bot
parent 19cbe451ce
commit e137086383
2 changed files with 33 additions and 8 deletions

View file

@ -6750,19 +6750,25 @@ VkResult ResourceTracker::on_vkGetPhysicalDeviceImageFormatProperties2_common(
const VkPhysicalDeviceImageDrmFormatModifierInfoEXT* drmFmtMod =
vk_find_struct<VkPhysicalDeviceImageDrmFormatModifierInfoEXT>(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<VkDrmFormatModifierPropertiesListEXT>(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) {

View file

@ -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