diff --git a/src/gfxstream/codegen/scripts/cereal/functable.py b/src/gfxstream/codegen/scripts/cereal/functable.py index a14bc92a743..28916f0f821 100644 --- a/src/gfxstream/codegen/scripts/cereal/functable.py +++ b/src/gfxstream/codegen/scripts/cereal/functable.py @@ -129,6 +129,7 @@ HANDWRITTEN_ENTRY_POINTS = [ # TODO: Make a codegen module (use deepcopy as reference) to make this more robust "vkAllocateMemory", "vkUpdateDescriptorSets", + "vkGetPhysicalDeviceFormatProperties2", ] # Handles that need to be translated to/from their corresponding gfxstream object types diff --git a/src/gfxstream/guest/vulkan/gfxstream_vk_device.cpp b/src/gfxstream/guest/vulkan/gfxstream_vk_device.cpp index 135022b9e75..3e2f81dc90b 100644 --- a/src/gfxstream/guest/vulkan/gfxstream_vk_device.cpp +++ b/src/gfxstream/guest/vulkan/gfxstream_vk_device.cpp @@ -71,6 +71,8 @@ static const char* const kGuestOnlyInstanceExtension[] = { static const char* const kGuestOnlyDeviceExtensions[] = { VK_KHR_SWAPCHAIN_EXTENSION_NAME, + VK_EXT_EXTERNAL_MEMORY_DMA_BUF_EXTENSION_NAME, + VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME, }; static VkResult SetupInstanceForProcess(void) { @@ -743,3 +745,29 @@ void gfxstream_vk_UpdateDescriptorSets(VkDevice device, uint32_t descriptorWrite internal_pDescriptorWrites.data(), descriptorCopyCount, pDescriptorCopies); } } + +void gfxstream_vk_GetPhysicalDeviceFormatProperties2(VkPhysicalDevice physicalDevice, + VkFormat format, + VkFormatProperties2* pFormatProperties) { + MESA_TRACE_SCOPE("vkGetPhysicalDeviceFormatProperties2"); + VK_FROM_HANDLE(gfxstream_vk_physical_device, gfxstream_physicalDevice, physicalDevice); + { + auto vkEnc = gfxstream::vk::ResourceTracker::getThreadLocalEncoder(); + vkEnc->vkGetPhysicalDeviceFormatProperties2(gfxstream_physicalDevice->internal_object, + format, pFormatProperties, true /* do lock */); + } + VkDrmFormatModifierPropertiesListEXT* drmFmtMod = + vk_find_struct(pFormatProperties, DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT); + if (drmFmtMod) { + drmFmtMod->drmFormatModifierCount = 1; + if (drmFmtMod->pDrmFormatModifierProperties) { + drmFmtMod->pDrmFormatModifierProperties[0] = { + .drmFormatModifier = 0, + .drmFormatModifierPlaneCount = 1, + .drmFormatModifierTilingFeatures = + VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | + VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT | + VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT}; + } + } +} \ No newline at end of file diff --git a/src/gfxstream/guest/vulkan_enc/ResourceTracker.cpp b/src/gfxstream/guest/vulkan_enc/ResourceTracker.cpp index bbdbec36884..810d0130272 100644 --- a/src/gfxstream/guest/vulkan_enc/ResourceTracker.cpp +++ b/src/gfxstream/guest/vulkan_enc/ResourceTracker.cpp @@ -4313,7 +4313,6 @@ VkResult ResourceTracker::on_vkCreateImage(void* context, VkResult, VkDevice dev } else { return VK_ERROR_VALIDATION_FAILED_EXT; } - return VK_ERROR_VALIDATION_FAILED_EXT; // stub constant } } @@ -6781,27 +6780,20 @@ VkResult ResourceTracker::on_vkGetPhysicalDeviceImageFormatProperties2_common( const VkPhysicalDeviceImageDrmFormatModifierInfoEXT* drmFmtMod = vk_find_struct_const(pImageFormatInfo, PHYSICAL_DEVICE_IMAGE_DRM_FORMAT_MODIFIER_INFO_EXT); 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, DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT); - - // Host doesn't support DRM format modifiers, try emulating. - 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; - } - } + if (drmFmtMod && + getHostDeviceExtensionIndex(VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME) == -1) { + if (drmFmtMod->drmFormatModifier != DRM_FORMAT_MOD_LINEAR) { + return VK_ERROR_FORMAT_NOT_SUPPORTED; } + mesa_logd("emulating DRM_FORMAT_MOD_LINEAR with VK_IMAGE_TILING_OPTIMAL"); + emulatedDrmFmtModPropsList = + vk_find_struct(pImageFormatProperties, DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT); + localImageFormatInfo.tiling = VK_IMAGE_TILING_LINEAR; + localImageFormatInfo.usage &= + ~(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT); + pImageFormatInfo = &localImageFormatInfo; + // Leave drmFormatMod in the input; it should be ignored when + // tiling is not VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT } #endif // LINUX_GUEST_BUILD @@ -6832,6 +6824,14 @@ VkResult ResourceTracker::on_vkGetPhysicalDeviceImageFormatProperties2_common( }; } } + if (ext_img_info && + ext_img_info->handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT) { + ext_img_properties->externalMemoryProperties.externalMemoryFeatures |= + VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT; + ext_img_properties->externalMemoryProperties.exportFromImportedHandleTypes = + ext_img_properties->externalMemoryProperties.compatibleHandleTypes = + VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT; + } #endif // LINUX_GUEST_BUILD #ifdef VK_USE_PLATFORM_FUCHSIA