Explicit vkImage create to wrap video frame

This uses VkImageDrmFormatModifierExplicitCreateInfoEXT instead of
VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_LIST_CREATE_INFO_EXT to
import mulit-planar external images.
More discussions about this change can be found at this Mesa issue:
https://gitlab.freedesktop.org/mesa/mesa/-/issues/6530

Bug: chromium:1258986

Change-Id: Ifde3d89e7ddf37d6a295c9d7fcc7c762f8da1e81
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91940
Reviewed-by: Jie A Chen <jie.a.chen@intel.com>
Commit-Queue: Jie A Chen <jie.a.chen@intel.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Loko Kung <lokokung@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
jchen10 2022-06-01 01:10:29 +00:00 committed by Dawn LUCI CQ
parent 37d92ca244
commit 238716e833
3 changed files with 45 additions and 23 deletions

View File

@ -17,6 +17,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include <array>
#include <vector> #include <vector>
#include "dawn/dawn_wsi.h" #include "dawn/dawn_wsi.h"
@ -92,11 +93,20 @@ struct DAWN_NATIVE_EXPORT ExternalImageDescriptorOpaqueFD : ExternalImageDescrip
uint32_t memoryTypeIndex; // Must match VkMemoryAllocateInfo from image creation uint32_t memoryTypeIndex; // Must match VkMemoryAllocateInfo from image creation
}; };
// The plane-wise offset and stride.
struct DAWN_NATIVE_EXPORT PlaneLayout {
uint64_t offset;
uint32_t stride;
};
// Descriptor for dma-buf file descriptor image import // Descriptor for dma-buf file descriptor image import
struct DAWN_NATIVE_EXPORT ExternalImageDescriptorDmaBuf : ExternalImageDescriptorFD { struct DAWN_NATIVE_EXPORT ExternalImageDescriptorDmaBuf : ExternalImageDescriptorFD {
ExternalImageDescriptorDmaBuf(); ExternalImageDescriptorDmaBuf();
// To be removed after chromium's switch to planeLayouts.
uint32_t stride = 0u; // Stride of the buffer in bytes
uint32_t stride; // Stride of the buffer in bytes static constexpr uint32_t kMaxPlanes = 3;
std::array<PlaneLayout, kMaxPlanes> planeLayouts;
uint64_t drmModifier; // DRM modifier of the buffer uint64_t drmModifier; // DRM modifier of the buffer
}; };

View File

@ -311,37 +311,37 @@ ResultOrError<VkImage> Service::CreateImage(const ExternalImageDescriptor* descr
createInfoChain.Add(&externalMemoryImageCreateInfo, createInfoChain.Add(&externalMemoryImageCreateInfo,
VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO); VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO);
VkSubresourceLayout planeLayouts[ExternalImageDescriptorDmaBuf::kMaxPlanes];
for (uint32_t plane = 0u; plane < planeCount; ++plane) {
planeLayouts[plane].offset = dmaBufDescriptor->planeLayouts[plane].offset;
planeLayouts[plane].size = 0; // VK_EXT_image_drm_format_modifier mandates size = 0.
planeLayouts[plane].rowPitch = dmaBufDescriptor->planeLayouts[plane].stride;
planeLayouts[plane].arrayPitch = 0; // Not an array texture
planeLayouts[plane].depthPitch = 0; // Not a depth texture
}
// For single plane formats. // For single plane formats.
VkSubresourceLayout planeLayout = {}; // To be Removed after chromium's switch to planeLayouts.
planeLayout.offset = 0; if (dmaBufDescriptor->stride != 0) {
planeLayout.size = 0; // VK_EXT_image_drm_format_modifier mandates size = 0. planeLayouts[0].offset = 0;
planeLayout.rowPitch = dmaBufDescriptor->stride; planeLayouts[0].size = 0; // VK_EXT_image_drm_format_modifier mandates size = 0.
planeLayout.arrayPitch = 0; // Not an array texture planeLayouts[0].rowPitch = dmaBufDescriptor->stride;
planeLayout.depthPitch = 0; // Not a depth texture planeLayouts[0].arrayPitch = 0; // Not an array texture
planeLayouts[0].depthPitch = 0; // Not a depth texture
}
VkImageDrmFormatModifierExplicitCreateInfoEXT explicitCreateInfo = {}; VkImageDrmFormatModifierExplicitCreateInfoEXT explicitCreateInfo = {};
explicitCreateInfo.drmFormatModifier = dmaBufDescriptor->drmModifier; explicitCreateInfo.drmFormatModifier = dmaBufDescriptor->drmModifier;
explicitCreateInfo.drmFormatModifierPlaneCount = 1; explicitCreateInfo.drmFormatModifierPlaneCount = planeCount;
explicitCreateInfo.pPlaneLayouts = &planeLayout; explicitCreateInfo.pPlaneLayouts = &planeLayouts[0];
// For multi-planar formats, we can't explicitly specify VkSubresourceLayout for each plane
// due to the lack of knowledge about the required 'offset'. Alternatively
// VkImageDrmFormatModifierListCreateInfoEXT can be used to create image with the DRM format
// modifier.
VkImageDrmFormatModifierListCreateInfoEXT listCreateInfo = {};
listCreateInfo.drmFormatModifierCount = 1;
listCreateInfo.pDrmFormatModifiers = &dmaBufDescriptor->drmModifier;
if (planeCount > 1) { if (planeCount > 1) {
// For multi-planar formats, VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT specifies that a // For multi-planar formats, VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT specifies that a
// VkImageView can be plane's format which might differ from the image's format. // VkImageView can be plane's format which might differ from the image's format.
createInfo.flags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; createInfo.flags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
createInfoChain.Add(&listCreateInfo, }
VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_LIST_CREATE_INFO_EXT);
} else {
createInfoChain.Add(&explicitCreateInfo, createInfoChain.Add(&explicitCreateInfo,
VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_EXPLICIT_CREATE_INFO_EXT); VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_EXPLICIT_CREATE_INFO_EXT);
}
// Create a new VkImage with tiling equal to the DRM format modifier. // Create a new VkImage with tiling equal to the DRM format modifier.
VkImage image; VkImage image;

View File

@ -32,6 +32,10 @@
#define GBM_BO_USE_HW_VIDEO_DECODER (1 << 13) #define GBM_BO_USE_HW_VIDEO_DECODER (1 << 13)
#endif #endif
#ifndef DRM_FORMAT_MOD_LINEAR
#define DRM_FORMAT_MOD_LINEAR 0
#endif
class PlatformTextureGbm : public VideoViewsTestBackend::PlatformTexture { class PlatformTextureGbm : public VideoViewsTestBackend::PlatformTexture {
public: public:
PlatformTextureGbm(wgpu::Texture&& texture, gbm_bo* gbmBo) PlatformTextureGbm(wgpu::Texture&& texture, gbm_bo* gbmBo)
@ -40,6 +44,11 @@ class PlatformTextureGbm : public VideoViewsTestBackend::PlatformTexture {
// TODO(chromium:1258986): Add DISJOINT vkImage support for multi-plannar formats. // TODO(chromium:1258986): Add DISJOINT vkImage support for multi-plannar formats.
bool CanWrapAsWGPUTexture() override { bool CanWrapAsWGPUTexture() override {
// TODO(chromium:1258986): Figure out the failure incurred by the change to explicit vkImage
// create when importing.
if (gbm_bo_get_modifier(mGbmBo) == DRM_FORMAT_MOD_LINEAR) {
return false;
}
ASSERT(mGbmBo != nullptr); ASSERT(mGbmBo != nullptr);
// Checks if all plane handles of a multi-planar gbm_bo are same. // Checks if all plane handles of a multi-planar gbm_bo are same.
gbm_bo_handle plane0Handle = gbm_bo_get_handle_for_plane(mGbmBo, 0); gbm_bo_handle plane0Handle = gbm_bo_get_handle_for_plane(mGbmBo, 0);
@ -174,7 +183,10 @@ class VideoViewsTestBackendGbm : public VideoViewsTestBackend {
descriptor.isInitialized = true; descriptor.isInitialized = true;
descriptor.memoryFD = gbm_bo_get_fd(gbmBo); descriptor.memoryFD = gbm_bo_get_fd(gbmBo);
descriptor.stride = gbm_bo_get_stride(gbmBo); for (int plane = 0; plane < gbm_bo_get_plane_count(gbmBo); ++plane) {
descriptor.planeLayouts[plane].stride = gbm_bo_get_stride_for_plane(gbmBo, plane);
descriptor.planeLayouts[plane].offset = gbm_bo_get_offset(gbmBo, plane);
}
descriptor.drmModifier = gbm_bo_get_modifier(gbmBo); descriptor.drmModifier = gbm_bo_get_modifier(gbmBo);
descriptor.waitFDs = {}; descriptor.waitFDs = {};