diff options
author | Kenneth Graunke <[email protected]> | 2018-10-07 20:31:09 -0700 |
---|---|---|
committer | Kenneth Graunke <[email protected]> | 2019-02-21 10:26:09 -0800 |
commit | 94569a645837df895e889c7e451e35b8e31556fd (patch) | |
tree | 88d80702025a8ecd32cf938187164b597d3c9d4d /src | |
parent | b9eeed3e8f964f1ee8b169497299b9e76c076154 (diff) |
iris: rework format translation apis
Diffstat (limited to 'src')
-rw-r--r-- | src/gallium/drivers/iris/iris_blit.c | 32 | ||||
-rw-r--r-- | src/gallium/drivers/iris/iris_formats.c | 14 | ||||
-rw-r--r-- | src/gallium/drivers/iris/iris_resource.c | 18 | ||||
-rw-r--r-- | src/gallium/drivers/iris/iris_resource.h | 12 | ||||
-rw-r--r-- | src/gallium/drivers/iris/iris_state.c | 58 |
5 files changed, 81 insertions, 53 deletions
diff --git a/src/gallium/drivers/iris/iris_blit.c b/src/gallium/drivers/iris/iris_blit.c index a3515bc6d39..ec381b95f1f 100644 --- a/src/gallium/drivers/iris/iris_blit.c +++ b/src/gallium/drivers/iris/iris_blit.c @@ -55,19 +55,6 @@ iris_blorp_surf_for_resource(struct blorp_surf *surf, assert(surf->aux_usage == ISL_AUX_USAGE_NONE); } -static enum isl_format -iris_get_blorp_format(enum pipe_format pf) -{ - switch (pf) { - case PIPE_FORMAT_Z24_UNORM_S8_UINT: - return ISL_FORMAT_R24_UNORM_X8_TYPELESS; - case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT: - return ISL_FORMAT_R32_FLOAT; - default: - return iris_isl_format_for_pipe_format(pf); - } -} - /** * The pipe->blit() driver hook. * @@ -78,16 +65,21 @@ static void iris_blit(struct pipe_context *ctx, const struct pipe_blit_info *info) { struct iris_context *ice = (void *) ctx; + struct iris_screen *screen = (struct iris_screen *)ctx->screen; + const struct gen_device_info *devinfo = &screen->devinfo; + struct blorp_surf src_surf, dst_surf; iris_blorp_surf_for_resource(&src_surf, info->src.resource, ISL_AUX_USAGE_NONE, false); iris_blorp_surf_for_resource(&dst_surf, info->dst.resource, ISL_AUX_USAGE_NONE, true); - enum isl_format src_isl_format = iris_get_blorp_format(info->src.format); - enum isl_format dst_isl_format = iris_get_blorp_format(info->dst.format); - - struct isl_swizzle src_isl_swizzle = ISL_SWIZZLE_IDENTITY; + struct iris_format_info src_fmt = + iris_format_for_usage(devinfo, info->src.format, + ISL_SURF_USAGE_TEXTURE_BIT); + struct iris_format_info dst_fmt = + iris_format_for_usage(devinfo, info->dst.format, + ISL_SURF_USAGE_RENDER_TARGET_BIT); int src_x0 = info->src.box.x; int src_x1 = info->src.box.x + info->src.box.width; @@ -157,9 +149,9 @@ iris_blit(struct pipe_context *ctx, const struct pipe_blit_info *info) blorp_blit(&blorp_batch, &src_surf, info->src.level, info->src.box.z + slice, - src_isl_format, src_isl_swizzle, + src_fmt.fmt, src_fmt.swizzle, &dst_surf, info->dst.level, info->dst.box.z + slice, - dst_isl_format, ISL_SWIZZLE_IDENTITY, + dst_fmt.fmt, ISL_SWIZZLE_IDENTITY, src_x0, src_y0, src_x1, src_y1, dst_x0, dst_y0, dst_x1, dst_y1, filter, mirror_x, mirror_y); @@ -180,7 +172,7 @@ iris_blit(struct pipe_context *ctx, const struct pipe_blit_info *info) blorp_blit(&blorp_batch, &src_surf, info->src.level, info->src.box.z + slice, - ISL_FORMAT_R8_UINT, src_isl_swizzle, + ISL_FORMAT_R8_UINT, ISL_SWIZZLE_IDENTITY, &dst_surf, info->dst.level, info->dst.box.z + slice, ISL_FORMAT_R8_UINT, ISL_SWIZZLE_IDENTITY, src_x0, src_y0, src_x1, src_y1, diff --git a/src/gallium/drivers/iris/iris_formats.c b/src/gallium/drivers/iris/iris_formats.c index 0ea6be810b3..2c726cb5fde 100644 --- a/src/gallium/drivers/iris/iris_formats.c +++ b/src/gallium/drivers/iris/iris_formats.c @@ -34,7 +34,7 @@ #include "iris_resource.h" #include "iris_screen.h" -enum isl_format +static enum isl_format iris_isl_format_for_pipe_format(enum pipe_format pf) { static const enum isl_format table[PIPE_FORMAT_COUNT] = { @@ -400,11 +400,13 @@ iris_isl_format_for_pipe_format(enum pipe_format pf) return table[pf]; } -enum isl_format -iris_isl_format_for_usage(const struct gen_device_info *devinfo, - enum pipe_format pformat, - isl_surf_usage_flags_t usage) +struct iris_format_info +iris_format_for_usage(const struct gen_device_info *devinfo, + enum pipe_format pformat, + isl_surf_usage_flags_t usage) { + struct isl_swizzle swizzle = ISL_SWIZZLE_IDENTITY; + enum isl_format format = iris_isl_format_for_pipe_format(pformat); /* Convert RGBX into RGBA for rendering or typed image access. */ @@ -417,7 +419,7 @@ iris_isl_format_for_usage(const struct gen_device_info *devinfo, format = isl_format_rgbx_to_rgba(format); } - return format; + return (struct iris_format_info) { .fmt = format, .swizzle = swizzle }; } /** diff --git a/src/gallium/drivers/iris/iris_resource.c b/src/gallium/drivers/iris/iris_resource.c index 34908d85a10..02828115890 100644 --- a/src/gallium/drivers/iris/iris_resource.c +++ b/src/gallium/drivers/iris/iris_resource.c @@ -298,13 +298,13 @@ iris_resource_create_with_modifiers(struct pipe_screen *pscreen, /* Should be handled by u_transfer_helper */ assert(!util_format_is_depth_and_stencil(pfmt)); - enum isl_format isl_format = iris_isl_format_for_pipe_format(pfmt); - assert(isl_format != ISL_FORMAT_UNSUPPORTED); + struct iris_format_info fmt = iris_format_for_usage(devinfo, pfmt, usage); + assert(fmt.fmt != ISL_FORMAT_UNSUPPORTED); UNUSED const bool isl_surf_created_successfully = isl_surf_init(&screen->isl_dev, &res->surf, .dim = target_to_isl_surf_dim(templ->target), - .format = isl_format, + .format = fmt.fmt, .width = templ->width0, .height = templ->height0, .depth = templ->depth0, @@ -371,6 +371,7 @@ iris_resource_from_user_memory(struct pipe_screen *pscreen, void *user_memory) { struct iris_screen *screen = (struct iris_screen *)pscreen; + struct gen_device_info *devinfo = &screen->devinfo; struct iris_bufmgr *bufmgr = screen->bufmgr; struct iris_resource *res = iris_alloc_resource(pscreen, templ); if (!res) @@ -389,9 +390,12 @@ iris_resource_from_user_memory(struct pipe_screen *pscreen, // XXX: usage... isl_surf_usage_flags_t isl_usage = 0; + const struct iris_format_info fmt = + iris_format_for_usage(devinfo, templ->format, isl_usage); + isl_surf_init(&screen->isl_dev, &res->surf, .dim = target_to_isl_surf_dim(templ->target), - .format = iris_isl_format_for_pipe_format(templ->format), + .format = fmt.fmt, .width = templ->width0, .height = templ->height0, .depth = templ->depth0, @@ -415,6 +419,7 @@ iris_resource_from_handle(struct pipe_screen *pscreen, unsigned usage) { struct iris_screen *screen = (struct iris_screen *)pscreen; + struct gen_device_info *devinfo = &screen->devinfo; struct iris_bufmgr *bufmgr = screen->bufmgr; struct iris_resource *res = iris_alloc_resource(pscreen, templ); if (!res) @@ -451,9 +456,12 @@ iris_resource_from_handle(struct pipe_screen *pscreen, // XXX: usage... isl_surf_usage_flags_t isl_usage = ISL_SURF_USAGE_DISPLAY_BIT; + const struct iris_format_info fmt = + iris_format_for_usage(devinfo, templ->format, isl_usage); + isl_surf_init(&screen->isl_dev, &res->surf, .dim = target_to_isl_surf_dim(templ->target), - .format = iris_isl_format_for_pipe_format(templ->format), + .format = fmt.fmt, .width = templ->width0, .height = templ->height0, .depth = templ->depth0, diff --git a/src/gallium/drivers/iris/iris_resource.h b/src/gallium/drivers/iris/iris_resource.h index 6aa16c09d4c..14a780a9011 100644 --- a/src/gallium/drivers/iris/iris_resource.h +++ b/src/gallium/drivers/iris/iris_resource.h @@ -27,6 +27,11 @@ #include "util/u_inlines.h" #include "intel/isl/isl.h" +struct iris_format_info { + enum isl_format fmt; + struct isl_swizzle swizzle; +}; + #define IRIS_RESOURCE_FLAG_SHADER_MEMZONE (PIPE_RESOURCE_FLAG_DRV_PRIV << 0) #define IRIS_RESOURCE_FLAG_SURFACE_MEMZONE (PIPE_RESOURCE_FLAG_DRV_PRIV << 1) #define IRIS_RESOURCE_FLAG_DYNAMIC_MEMZONE (PIPE_RESOURCE_FLAG_DRV_PRIV << 2) @@ -110,10 +115,9 @@ iris_resource_bo(struct pipe_resource *p_res) return res->bo; } -enum isl_format iris_isl_format_for_pipe_format(enum pipe_format pf); -enum isl_format iris_isl_format_for_usage(const struct gen_device_info *, - enum pipe_format, - isl_surf_usage_flags_t usage); +struct iris_format_info iris_format_for_usage(const struct gen_device_info *, + enum pipe_format pf, + isl_surf_usage_flags_t usage); struct pipe_resource *iris_resource_get_separate_stencil(struct pipe_resource *); diff --git a/src/gallium/drivers/iris/iris_state.c b/src/gallium/drivers/iris/iris_state.c index c443b16749b..0f6177eb953 100644 --- a/src/gallium/drivers/iris/iris_state.c +++ b/src/gallium/drivers/iris/iris_state.c @@ -1289,6 +1289,20 @@ iris_bind_sampler_states(struct pipe_context *ctx, ice->state.dirty |= IRIS_DIRTY_SAMPLER_STATES_VS << stage; } +static enum isl_channel_select +fmt_swizzle(const struct iris_format_info *fmt, enum pipe_swizzle swz) +{ + switch (swz) { + case PIPE_SWIZZLE_X: return fmt->swizzle.r; + case PIPE_SWIZZLE_Y: return fmt->swizzle.g; + case PIPE_SWIZZLE_Z: return fmt->swizzle.b; + case PIPE_SWIZZLE_W: return fmt->swizzle.a; + case PIPE_SWIZZLE_1: return SCS_ONE; + case PIPE_SWIZZLE_0: return SCS_ZERO; + default: unreachable("invalid swizzle"); + } +} + /** * The pipe->create_sampler_view() driver hook. */ @@ -1299,6 +1313,7 @@ iris_create_sampler_view(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; struct iris_sampler_view *isv = calloc(1, sizeof(struct iris_sampler_view)); if (!isv) @@ -1331,17 +1346,22 @@ iris_create_sampler_view(struct pipe_context *ctx, isv->res = (struct iris_resource *) tex; - /* XXX: do we need brw_get_texture_swizzle hacks here? */ + isl_surf_usage_flags_t usage = + ISL_SURF_USAGE_TEXTURE_BIT | + (isv->res->surf.usage & ISL_SURF_USAGE_CUBE_BIT); + + const struct iris_format_info fmt = + iris_format_for_usage(devinfo, tmpl->format, usage); + isv->view = (struct isl_view) { - .format = iris_isl_format_for_pipe_format(tmpl->format), + .format = fmt.fmt, .swizzle = (struct isl_swizzle) { - .r = pipe_swizzle_to_isl_channel(tmpl->swizzle_r), - .g = pipe_swizzle_to_isl_channel(tmpl->swizzle_g), - .b = pipe_swizzle_to_isl_channel(tmpl->swizzle_b), - .a = pipe_swizzle_to_isl_channel(tmpl->swizzle_a), + .r = fmt_swizzle(&fmt, tmpl->swizzle_r), + .g = fmt_swizzle(&fmt, tmpl->swizzle_g), + .b = fmt_swizzle(&fmt, tmpl->swizzle_b), + .a = fmt_swizzle(&fmt, tmpl->swizzle_a), }, - .usage = ISL_SURF_USAGE_TEXTURE_BIT | - (isv->res->surf.usage & ISL_SURF_USAGE_CUBE_BIT), + .usage = usage, }; /* Fill out SURFACE_STATE for this view. */ @@ -1427,11 +1447,11 @@ iris_create_surface(struct pipe_context *ctx, else usage = ISL_SURF_USAGE_RENDER_TARGET_BIT; - enum isl_format isl_format = - iris_isl_format_for_usage(devinfo, psurf->format, usage); + const struct iris_format_info fmt = + iris_format_for_usage(devinfo, psurf->format, usage); if ((usage & ISL_SURF_USAGE_RENDER_TARGET_BIT) && - !isl_format_supports_rendering(devinfo, isl_format)) { + !isl_format_supports_rendering(devinfo, fmt.fmt)) { /* Framebuffer validation will reject this invalid case, but it * hasn't had the opportunity yet. In the meantime, we need to * avoid hitting ISL asserts about unsupported formats below. @@ -1441,7 +1461,7 @@ iris_create_surface(struct pipe_context *ctx, } surf->view = (struct isl_view) { - .format = isl_format, + .format = fmt.fmt, .base_level = tmpl->u.tex.level, .levels = 1, .base_array_layer = tmpl->u.tex.first_layer, @@ -2050,6 +2070,8 @@ iris_create_vertex_elements(struct pipe_context *ctx, unsigned count, const struct pipe_vertex_element *state) { + struct iris_screen *screen = (struct iris_screen *)ctx->screen; + const struct gen_device_info *devinfo = &screen->devinfo; struct iris_vertex_element_state *cso = malloc(sizeof(struct iris_vertex_element_state)); @@ -2083,25 +2105,25 @@ iris_create_vertex_elements(struct pipe_context *ctx, } for (int i = 0; i < count; i++) { - enum isl_format isl_format = - iris_isl_format_for_pipe_format(state[i].src_format); + const struct iris_format_info fmt = + iris_format_for_usage(devinfo, state[i].src_format, 0); unsigned comp[4] = { VFCOMP_STORE_SRC, VFCOMP_STORE_SRC, VFCOMP_STORE_SRC, VFCOMP_STORE_SRC }; - switch (isl_format_get_num_channels(isl_format)) { + switch (isl_format_get_num_channels(fmt.fmt)) { case 0: comp[0] = VFCOMP_STORE_0; case 1: comp[1] = VFCOMP_STORE_0; case 2: comp[2] = VFCOMP_STORE_0; case 3: - comp[3] = isl_format_has_int_channel(isl_format) ? VFCOMP_STORE_1_INT - : VFCOMP_STORE_1_FP; + comp[3] = isl_format_has_int_channel(fmt.fmt) ? VFCOMP_STORE_1_INT + : VFCOMP_STORE_1_FP; break; } iris_pack_state(GENX(VERTEX_ELEMENT_STATE), ve_pack_dest, ve) { ve.VertexBufferIndex = state[i].vertex_buffer_index; ve.Valid = true; ve.SourceElementOffset = state[i].src_offset; - ve.SourceElementFormat = isl_format; + ve.SourceElementFormat = fmt.fmt; ve.Component0Control = comp[0]; ve.Component1Control = comp[1]; ve.Component2Control = comp[2]; |