mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-04-28 19:30:47 +02:00
venus: use VK_EXT_image_drm_format_modifier
This commit contains a hack to retrieve extended buffer info, which will be fixed by moving the logic into gralloc HAL implementation. With this hack, the rendering result is correct. Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org> Reviewed-by: Chia-I Wu <olvaffe@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10259>
This commit is contained in:
parent
34f37fb780
commit
95844b0978
3 changed files with 57 additions and 15 deletions
|
|
@ -11,6 +11,7 @@
|
|||
#include "vn_android.h"
|
||||
#include "vn_common.h"
|
||||
|
||||
#include <drm/drm_fourcc.h>
|
||||
#include <hardware/hwvulkan.h>
|
||||
#include <vndk/hardware_buffer.h>
|
||||
#include <vulkan/vk_icd.h>
|
||||
|
|
@ -138,19 +139,6 @@ vn_image_from_anb(struct vn_device *dev,
|
|||
int dma_buf_fd = -1;
|
||||
int dup_fd = -1;
|
||||
|
||||
/* encoder will strip the Android specific pNext structs */
|
||||
result = vn_image_create(dev, image_info, alloc, &img);
|
||||
if (result != VK_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
image = vn_image_to_handle(img);
|
||||
VkMemoryRequirements mem_req;
|
||||
vn_GetImageMemoryRequirements(device, image, &mem_req);
|
||||
if (!mem_req.memoryTypeBits) {
|
||||
result = VK_ERROR_INVALID_EXTERNAL_HANDLE;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (anb_info->handle->numFds != 1) {
|
||||
if (VN_DEBUG(WSI))
|
||||
vn_log(dev->instance, "handle->numFds is %d, expected 1",
|
||||
|
|
@ -165,6 +153,55 @@ vn_image_from_anb(struct vn_device *dev,
|
|||
goto fail;
|
||||
}
|
||||
|
||||
/* XXX fix this!!!!! */
|
||||
uint32_t offset = 0;
|
||||
uint32_t bpp = 0;
|
||||
switch (image_info->format) {
|
||||
case VK_FORMAT_R8G8B8A8_UNORM:
|
||||
case VK_FORMAT_R8G8B8A8_SRGB:
|
||||
bpp = 4;
|
||||
break;
|
||||
case VK_FORMAT_R5G6B5_UNORM_PACK16:
|
||||
bpp = 2;
|
||||
break;
|
||||
default:
|
||||
result = VK_ERROR_INVALID_EXTERNAL_HANDLE;
|
||||
goto fail;
|
||||
};
|
||||
uint32_t stride = align(image_info->extent.width * bpp, 512);
|
||||
uint64_t modifier = I915_FORMAT_MOD_X_TILED;
|
||||
|
||||
const VkSubresourceLayout layout = {
|
||||
.offset = offset,
|
||||
.size = 0,
|
||||
.rowPitch = stride,
|
||||
.arrayPitch = 0,
|
||||
.depthPitch = 0,
|
||||
};
|
||||
const VkImageDrmFormatModifierExplicitCreateInfoEXT drm_mod_info = {
|
||||
.sType =
|
||||
VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_EXPLICIT_CREATE_INFO_EXT,
|
||||
.pNext = image_info->pNext,
|
||||
.drmFormatModifier = modifier,
|
||||
.drmFormatModifierPlaneCount = 1,
|
||||
.pPlaneLayouts = &layout,
|
||||
};
|
||||
VkImageCreateInfo local_image_info = *image_info;
|
||||
local_image_info.pNext = &drm_mod_info;
|
||||
local_image_info.tiling = VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT;
|
||||
/* encoder will strip the Android specific pNext structs */
|
||||
result = vn_image_create(dev, &local_image_info, alloc, &img);
|
||||
if (result != VK_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
image = vn_image_to_handle(img);
|
||||
VkMemoryRequirements mem_req;
|
||||
vn_GetImageMemoryRequirements(device, image, &mem_req);
|
||||
if (!mem_req.memoryTypeBits) {
|
||||
result = VK_ERROR_INVALID_EXTERNAL_HANDLE;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
VkMemoryFdPropertiesKHR fd_prop = {
|
||||
.sType = VK_STRUCTURE_TYPE_MEMORY_FD_PROPERTIES_KHR,
|
||||
.pNext = NULL,
|
||||
|
|
|
|||
|
|
@ -2967,8 +2967,12 @@ vn_device_fix_create_info(const struct vn_device *dev,
|
|||
uint32_t extra_count = 0;
|
||||
uint32_t block_count = 0;
|
||||
|
||||
if (dev->physical_device->wsi_device.supports_modifiers)
|
||||
extra_exts[extra_count++] = "VK_EXT_image_drm_format_modifier";
|
||||
#if defined(VN_USE_WSI_PLATFORM) || defined(ANDROID)
|
||||
if (dev->physical_device->base.base.supported_extensions
|
||||
.EXT_image_drm_format_modifier)
|
||||
extra_exts[extra_count++] =
|
||||
VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME;
|
||||
#endif
|
||||
|
||||
if (dev->base.base.enabled_extensions.ANDROID_native_buffer)
|
||||
block_exts[block_count++] = VK_ANDROID_NATIVE_BUFFER_EXTENSION_NAME;
|
||||
|
|
|
|||
|
|
@ -225,6 +225,7 @@ vn_AllocateMemory(VkDevice device,
|
|||
}
|
||||
vn_instance_roundtrip(dev->instance);
|
||||
|
||||
/* XXX fix VkImportMemoryResourceInfoMESA to support memory planes */
|
||||
const VkImportMemoryResourceInfoMESA import_memory_resource_info = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_RESOURCE_INFO_MESA,
|
||||
.pNext = pAllocateInfo->pNext,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue