iris: move existing image format fallback as a helper function

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 <tapani.palli@intel.com>
Reviewed-by: Nanley Chery <nanley.g.chery@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4080>
This commit is contained in:
Tapani Pälli 2020-03-12 08:16:28 +02:00 committed by Marge Bot
parent fe2baf72e7
commit d4c879e69e
3 changed files with 32 additions and 22 deletions

View file

@ -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)
{

View file

@ -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)

View file

@ -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);