From: Ben Widawsky <b...@bwidawsk.net> v2: move is_aux into if block. (Jason) Use else block instead of goto (Jason)
v3: Fix up logic for is_aux (Ben) Fix up size calculations and add FIXME (Ben) Cc: Jason Ekstrand <ja...@jlekstrand.net> Signed-off-by: Ben Widawsky <b...@bwidawsk.net> Acked-by: Daniel Stone <dani...@collabora.com> Signed-off-by: Daniel Stone <dani...@collabora.com> --- src/mesa/drivers/dri/i965/intel_screen.c | 98 +++++++++++++++++++++++++++----- 1 file changed, 83 insertions(+), 15 deletions(-) diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c index 9da5d4f5e5..f1307ffd02 100644 --- a/src/mesa/drivers/dri/i965/intel_screen.c +++ b/src/mesa/drivers/dri/i965/intel_screen.c @@ -294,6 +294,10 @@ static const struct { uint32_t tiling; uint64_t modifier; unsigned height_align; + unsigned aux_w_block; + unsigned aux_w_align; + unsigned aux_h_block; + unsigned aux_h_align; } tiling_modifier_map[] = { { .tiling = I915_TILING_NONE, .modifier = DRM_FORMAT_MOD_LINEAR, .height_align = 1 }, @@ -342,6 +346,57 @@ get_tiled_height(uint32_t tiling, unsigned height) unreachable("get_tiled_height received unknown tiling mode"); } +static unsigned +get_aux_width(uint64_t modifier, unsigned width) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(tiling_modifier_map); i++) { + if (tiling_modifier_map[i].modifier != modifier) + continue; + if (tiling_modifier_map[i].aux_w_block == 0) + return 0; + return ALIGN(DIV_ROUND_UP(width, tiling_modifier_map[i].aux_w_block), + tiling_modifier_map[i].aux_w_align); + } + + unreachable("get_aux_width received unknown modifier"); +} + +static unsigned +get_aux_stride(uint64_t modifier, unsigned stride) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(tiling_modifier_map); i++) { + if (tiling_modifier_map[i].modifier != modifier) + continue; + if (tiling_modifier_map[i].aux_w_block == 0) + return 0; + return ALIGN(stride / tiling_modifier_map[i].aux_w_block, + tiling_modifier_map[i].aux_w_align); + } + + unreachable("get_aux_stride received unknown modifier"); +} + +static unsigned +get_aux_height(uint64_t modifier, unsigned height) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(tiling_modifier_map); i++) { + if (tiling_modifier_map[i].modifier != modifier) + continue; + if (tiling_modifier_map[i].aux_h_block == 0) + return 0; + return ALIGN(DIV_ROUND_UP(height, tiling_modifier_map[i].aux_h_block), + tiling_modifier_map[i].aux_h_align); + } + + unreachable("get_aux_height received unknown modifier"); +} + static void intel_image_warn_if_unaligned(__DRIimage *image, const char *func) { @@ -759,7 +814,7 @@ intel_query_image(__DRIimage *image, int attrib, int *value) case __DRI_IMAGE_ATTRIB_FOURCC: return intel_lookup_fourcc(image->dri_format, value); case __DRI_IMAGE_ATTRIB_NUM_PLANES: - *value = 1; + *value = image->aux_offset ? 2: 1; return true; case __DRI_IMAGE_ATTRIB_OFFSET: *value = image->offset; @@ -966,20 +1021,33 @@ intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate) struct intel_image_format *f; __DRIimage *image; - if (parent == NULL || parent->planar_format == NULL) - return NULL; - - f = parent->planar_format; - - if (plane >= f->nplanes) - return NULL; - - width = parent->width >> f->planes[plane].width_shift; - height = parent->height >> f->planes[plane].height_shift; - dri_format = f->planes[plane].dri_format; - index = f->planes[plane].buffer_index; - offset = parent->offsets[index]; - stride = parent->strides[index]; + if (parent == NULL) { + return NULL; + } else if (parent->planar_format == NULL) { + const bool is_aux = parent->aux_offset && plane == 1; + if (!is_aux) + return NULL; + + width = get_aux_width(parent->modifier, parent->width); + height = get_aux_width(parent->modifier, parent->height); + stride = get_aux_stride(parent->modifier, parent->pitch); + dri_format = parent->dri_format; + offset = parent->aux_offset; + } else { + /* Planar formats don't support aux buffers/images */ + assert(!parent->aux_offset); + f = parent->planar_format; + + if (plane >= f->nplanes) + return NULL; + + width = parent->width >> f->planes[plane].width_shift; + height = parent->height >> f->planes[plane].height_shift; + dri_format = f->planes[plane].dri_format; + index = f->planes[plane].buffer_index; + offset = parent->offsets[index]; + stride = parent->strides[index]; + } image = intel_allocate_image(parent->screen, dri_format, loaderPrivate); if (image == NULL) -- 2.13.0 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev