From a163dec3ff7f67ba75c56e58ccec054cd0344cb7 Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Mon, 23 Feb 2026 01:30:13 +0100 Subject: [PATCH] lavapipe: enable dmabuf import for planar drm formats Like e.g. NV12. This just requires some minor fixes around offset handling. (cherry picked from commit 0b6340fd94e0cc946111df5304adf349de1d8680) Part-of: --- .pick_status.json | 2 +- src/gallium/frontends/lavapipe/lvp_device.c | 10 ++++++---- src/gallium/frontends/lavapipe/lvp_image.c | 11 +---------- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 8d61de7ed10..538159977f2 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -564,7 +564,7 @@ "description": "lavapipe: enable dmabuf import for planar drm formats", "nominated": false, "nomination_type": 0, - "resolution": 4, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/gallium/frontends/lavapipe/lvp_device.c b/src/gallium/frontends/lavapipe/lvp_device.c index f5f3e3f01cb..11b8b7083a5 100644 --- a/src/gallium/frontends/lavapipe/lvp_device.c +++ b/src/gallium/frontends/lavapipe/lvp_device.c @@ -2425,13 +2425,15 @@ lvp_image_plane_bind(struct lvp_device *device, struct lvp_image_plane *plane, struct lvp_device_memory *mem, VkDeviceSize memory_offset, - VkDeviceSize *plane_offset) + VkDeviceSize *min_plane_offset) { + VkDeviceSize plane_offset = MAX2(plane->plane_offset, *min_plane_offset); + if (!device->pscreen->resource_bind_backing(device->pscreen, plane->bo, mem->pmem, 0, 0, - memory_offset + *plane_offset)) { + memory_offset + plane_offset)) { /* This is probably caused by the texture being too large, so let's * report this as the *closest* allowed error-code. It's not ideal, * but it's unlikely that anyone will care too much. @@ -2440,8 +2442,8 @@ lvp_image_plane_bind(struct lvp_device *device, } plane->pmem = mem->pmem; plane->memory_offset = memory_offset; - plane->plane_offset = *plane_offset; - *plane_offset += plane->size; + plane->plane_offset = plane_offset; + *min_plane_offset = plane_offset + plane->size; return VK_SUCCESS; } diff --git a/src/gallium/frontends/lavapipe/lvp_image.c b/src/gallium/frontends/lavapipe/lvp_image.c index acbbacaa091..731e1127734 100644 --- a/src/gallium/frontends/lavapipe/lvp_image.c +++ b/src/gallium/frontends/lavapipe/lvp_image.c @@ -47,7 +47,6 @@ lvp_image_create(VkDevice _device, assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO); #ifdef HAVE_LIBDRM - unsigned num_layouts = 1; enum pipe_format pipe_format = lvp_vk_format_to_pipe_format(pCreateInfo->format); const VkImageDrmFormatModifierExplicitCreateInfoEXT *modinfo = (void*)vk_find_struct_const(pCreateInfo->pNext, IMAGE_DRM_FORMAT_MODIFIER_EXPLICIT_CREATE_INFO_EXT); @@ -55,17 +54,9 @@ lvp_image_create(VkDevice _device, if (modinfo && pCreateInfo->tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) { assert(modinfo->drmFormatModifier == DRM_FORMAT_MOD_LINEAR); assert(modinfo->drmFormatModifierPlaneCount == util_format_get_num_planes(pipe_format)); - num_layouts = modinfo->drmFormatModifierPlaneCount; layouts = modinfo->pPlaneLayouts; } - /* planar not supported yet */ - assert(num_layouts == 1); - if (num_layouts > 1) { - mesa_loge("lavapipe: planar drm formats are not supported"); - return VK_ERROR_OUT_OF_DEVICE_MEMORY; - } - modifier = DRM_FORMAT_MOD_LINEAR; #endif @@ -174,7 +165,7 @@ lvp_image_create(VkDevice _device, whandle.stride = layouts[p].rowPitch; whandle.array_stride = layouts[p].arrayPitch; whandle.image_stride = layouts[p].depthPitch; - image->offset = layouts[p].offset; + image->planes[p].plane_offset = layouts[p].offset; whandle.format = pCreateInfo->format; whandle.modifier = modifier; image->planes[p].bo = device->pscreen->resource_from_handle(device->pscreen,