From 7a7e577d8e6b88cf8dc18ed2c73aabb20743cfd1 Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Sat, 7 Oct 2023 19:45:03 +0200 Subject: [PATCH] iris: Support parameter queries for main planes In order to return correct offsets, strides and possibly other parameters. This is relevant for formats like NV12 and P010 where the second plane, when produced by the Intel VAAPI decoder, uses the same FD like the first one, but with an offset. Right now there are only two modifiers with well defined indices of auxiliary planes for semi-planar formats according to the local copy of drm_fourcc.h, `I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS` and `I915_FORMAT_MOD_4_TILED_MTL_MC_CCS`, sharing the same layout. Assume that future `MC_CCS` modifiers will get defined accordingly for now. Cc: mesa-stable Tested-by: Nanley Chery Reviewed-by: Nanley Chery Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/9952 Part-of: --- src/gallium/drivers/iris/iris_resource.c | 45 ++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/src/gallium/drivers/iris/iris_resource.c b/src/gallium/drivers/iris/iris_resource.c index f14b2e5b944..1580701fce8 100644 --- a/src/gallium/drivers/iris/iris_resource.c +++ b/src/gallium/drivers/iris/iris_resource.c @@ -1434,6 +1434,19 @@ mod_plane_is_clear_color(uint64_t modifier, uint32_t plane) } } +static struct iris_resource * +get_resource_for_plane(struct pipe_resource *resource, + unsigned plane) +{ + unsigned count = 0; + for (struct pipe_resource *cur = resource; cur; cur = cur->next) { + if (count++ == plane) + return (struct iris_resource *)cur; + } + + return NULL; +} + static unsigned get_num_planes(const struct pipe_resource *resource) { @@ -1444,6 +1457,27 @@ get_num_planes(const struct pipe_resource *resource) return count; } +static unsigned +get_main_plane_for_plane(enum pipe_format format, + const struct isl_drm_modifier_info *mod_info, + unsigned plane) +{ + unsigned int n_planes = util_format_get_num_planes(format); + + if (n_planes == 1) + return 0; + + if (!mod_info) + return plane; + + if (mod_info->supports_media_compression) { + return plane % n_planes; + } else { + assert(!mod_info->supports_render_compression); + return plane; + } +} + static struct pipe_resource * iris_resource_from_handle(struct pipe_screen *pscreen, const struct pipe_resource *templ, @@ -1791,10 +1825,15 @@ iris_resource_get_param(struct pipe_screen *pscreen, uint64_t *value) { struct iris_screen *screen = (struct iris_screen *)pscreen; - struct iris_resource *res = (struct iris_resource *)resource; + struct iris_resource *base_res = (struct iris_resource *)resource; + unsigned main_plane = get_main_plane_for_plane(base_res->external_format, + base_res->mod_info, plane); + struct iris_resource *res = get_resource_for_plane(resource, main_plane); + assert(res); + bool mod_with_aux = res->mod_info && isl_drm_modifier_has_aux(res->mod_info->modifier); - bool wants_aux = mod_with_aux && plane > 0; + bool wants_aux = mod_with_aux && plane != main_plane; bool wants_cc = mod_with_aux && mod_plane_is_clear_color(res->mod_info->modifier, plane); bool result; @@ -1835,7 +1874,7 @@ iris_resource_get_param(struct pipe_screen *pscreen, return true; case PIPE_RESOURCE_PARAM_OFFSET: *value = wants_cc ? res->aux.clear_color_offset : - wants_aux ? res->aux.offset : 0; + wants_aux ? res->aux.offset : res->offset; return true; case PIPE_RESOURCE_PARAM_MODIFIER: *value = res->mod_info ? res->mod_info->modifier :