From d4c879e69e2e54d3f422367a51dc4a4a82dddf22 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tapani=20P=C3=A4lli?= Date: Thu, 12 Mar 2020 08:16:28 +0200 Subject: [PATCH] iris: move existing image format fallback as a helper function MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Patch adds a helper function for determining image format and changes iris_set_shader_images to use it. v2: pass iris_context instead of pipe one, rename function, code cleanup (Nanley) Signed-off-by: Tapani Pälli Reviewed-by: Nanley Chery Part-of: --- src/gallium/drivers/iris/iris_resource.c | 26 ++++++++++++++++++++++++ src/gallium/drivers/iris/iris_resource.h | 2 ++ src/gallium/drivers/iris/iris_state.c | 26 ++++-------------------- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/gallium/drivers/iris/iris_resource.c b/src/gallium/drivers/iris/iris_resource.c index cec772c7178..6f182c6cc0c 100644 --- a/src/gallium/drivers/iris/iris_resource.c +++ b/src/gallium/drivers/iris/iris_resource.c @@ -214,6 +214,32 @@ pipe_bind_to_isl_usage(unsigned bindings) return usage; } +enum isl_format +iris_image_view_get_format(struct iris_context *ice, + const struct pipe_image_view *img) +{ + struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen; + const struct gen_device_info *devinfo = &screen->devinfo; + + isl_surf_usage_flags_t usage = ISL_SURF_USAGE_STORAGE_BIT; + enum isl_format isl_fmt = + iris_format_for_usage(devinfo, img->format, usage).fmt; + + if (img->shader_access & PIPE_IMAGE_ACCESS_READ) { + /* On Gen8, try to use typed surfaces reads (which support a + * limited number of formats), and if not possible, fall back + * to untyped reads. + */ + if (devinfo->gen == 8 && + !isl_has_matching_typed_storage_image_format(devinfo, isl_fmt)) + return ISL_FORMAT_RAW; + else + return isl_lower_storage_image_format(devinfo, isl_fmt); + } + + return isl_fmt; +} + struct pipe_resource * iris_resource_get_separate_stencil(struct pipe_resource *p_res) { diff --git a/src/gallium/drivers/iris/iris_resource.h b/src/gallium/drivers/iris/iris_resource.h index 6a55c387fe3..a8a7ab6890f 100644 --- a/src/gallium/drivers/iris/iris_resource.h +++ b/src/gallium/drivers/iris/iris_resource.h @@ -467,6 +467,8 @@ void iris_resource_prepare_texture(struct iris_context *ice, enum isl_aux_usage iris_image_view_aux_usage(struct iris_context *ice, const struct pipe_image_view *pview, const struct shader_info *info); +enum isl_format iris_image_view_get_format(struct iris_context *ice, + const struct pipe_image_view *img); static inline bool iris_resource_unfinished_aux_import(struct iris_resource *res) diff --git a/src/gallium/drivers/iris/iris_state.c b/src/gallium/drivers/iris/iris_state.c index eab934fb738..170562f926f 100644 --- a/src/gallium/drivers/iris/iris_state.c +++ b/src/gallium/drivers/iris/iris_state.c @@ -2680,7 +2680,6 @@ iris_set_shader_images(struct pipe_context *ctx, { struct iris_context *ice = (struct iris_context *) ctx; struct iris_screen *screen = (struct iris_screen *)ctx->screen; - const struct gen_device_info *devinfo = &screen->devinfo; gl_shader_stage stage = stage_from_pipe(p_stage); struct iris_shader_state *shs = &ice->state.shaders[stage]; #if GEN_GEN == 8 @@ -2704,25 +2703,7 @@ iris_set_shader_images(struct pipe_context *ctx, res->bind_history |= PIPE_BIND_SHADER_IMAGE; res->bind_stages |= 1 << stage; - isl_surf_usage_flags_t usage = ISL_SURF_USAGE_STORAGE_BIT; - enum isl_format isl_fmt = - iris_format_for_usage(devinfo, img->format, usage).fmt; - - bool untyped_fallback = false; - - if (img->shader_access & PIPE_IMAGE_ACCESS_READ) { - /* On Gen8, try to use typed surfaces reads (which support a - * limited number of formats), and if not possible, fall back - * to untyped reads. - */ - untyped_fallback = GEN_GEN == 8 && - !isl_has_matching_typed_storage_image_format(devinfo, isl_fmt); - - if (untyped_fallback) - isl_fmt = ISL_FORMAT_RAW; - else - isl_fmt = isl_lower_storage_image_format(devinfo, isl_fmt); - } + enum isl_format isl_fmt = iris_image_view_get_format(ice, img); alloc_surface_states(&iv->surface_state, 1 << ISL_AUX_USAGE_NONE); iv->surface_state.bo_address = res->bo->gtt_offset; @@ -2737,10 +2718,11 @@ iris_set_shader_images(struct pipe_context *ctx, .base_array_layer = img->u.tex.first_layer, .array_len = img->u.tex.last_layer - img->u.tex.first_layer + 1, .swizzle = ISL_SWIZZLE_IDENTITY, - .usage = usage, + .usage = ISL_SURF_USAGE_STORAGE_BIT, }; - if (untyped_fallback) { + /* If using untyped fallback. */ + if (isl_fmt == ISL_FORMAT_RAW) { fill_buffer_surface_state(&screen->isl_dev, res, map, isl_fmt, ISL_SWIZZLE_IDENTITY, 0, res->bo->size); -- 2.30.2