From 62a3192112f07ee002b735b7f5e635b17e4e7a92 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 4 Dec 2018 14:25:22 -0800 Subject: [PATCH] v3d: Split most of TEXTURE_SHADER_STATE setup out of sampler views. For shader image load/store, we want most of this logic to be shared. --- src/gallium/drivers/v3d/v3dx_state.c | 127 +++++++++++++++------------ 1 file changed, 69 insertions(+), 58 deletions(-) diff --git a/src/gallium/drivers/v3d/v3dx_state.c b/src/gallium/drivers/v3d/v3dx_state.c index 980d755755c..2980547f1d6 100644 --- a/src/gallium/drivers/v3d/v3dx_state.c +++ b/src/gallium/drivers/v3d/v3dx_state.c @@ -676,6 +676,69 @@ translate_swizzle(unsigned char pipe_swizzle) } #endif +static void +v3d_setup_texture_shader_state(struct V3DX(TEXTURE_SHADER_STATE) *tex, + struct pipe_resource *prsc, + int base_level, int last_level, + int first_layer, int last_layer) +{ + struct v3d_resource *rsc = v3d_resource(prsc); + int msaa_scale = prsc->nr_samples > 1 ? 2 : 1; + + tex->image_width = prsc->width0 * msaa_scale; + tex->image_height = prsc->height0 * msaa_scale; + +#if V3D_VERSION >= 40 + /* On 4.x, the height of a 1D texture is redefined to be the + * upper 14 bits of the width (which is only usable with txf). + */ + if (prsc->target == PIPE_TEXTURE_1D || + prsc->target == PIPE_TEXTURE_1D_ARRAY) { + tex->image_height = tex->image_width >> 14; + } +#endif + + if (prsc->target == PIPE_TEXTURE_3D) { + tex->image_depth = prsc->depth0; + } else { + tex->image_depth = (last_layer - first_layer) + 1; + } + + tex->base_level = base_level; +#if V3D_VERSION >= 40 + tex->max_level = last_level; + /* Note that we don't have a job to reference the texture's sBO + * at state create time, so any time this sampler view is used + * we need to add the texture to the job. + */ + tex->texture_base_pointer = + cl_address(NULL, + rsc->bo->offset + + v3d_layer_offset(prsc, 0, first_layer)); +#endif + tex->array_stride_64_byte_aligned = rsc->cube_map_stride / 64; + + /* Since other platform devices may produce UIF images even + * when they're not big enough for V3D to assume they're UIF, + * we force images with level 0 as UIF to be always treated + * that way. + */ + tex->level_0_is_strictly_uif = + (rsc->slices[0].tiling == VC5_TILING_UIF_XOR || + rsc->slices[0].tiling == VC5_TILING_UIF_NO_XOR); + tex->level_0_xor_enable = (rsc->slices[0].tiling == VC5_TILING_UIF_XOR); + + if (tex->level_0_is_strictly_uif) + tex->level_0_ub_pad = rsc->slices[0].ub_pad; + +#if V3D_VERSION >= 40 + if (tex->uif_xor_disable || + tex->level_0_is_strictly_uif) { + tex->extended = true; + } +#endif /* V3D_VERSION >= 40 */ +} + static struct pipe_sampler_view * v3d_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *prsc, const struct pipe_sampler_view *cso) @@ -683,7 +746,6 @@ v3d_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *prsc, struct v3d_context *v3d = v3d_context(pctx); struct v3d_screen *screen = v3d->screen; struct v3d_sampler_view *so = CALLOC_STRUCT(v3d_sampler_view); - struct v3d_resource *rsc = v3d_resource(prsc); if (!so) return NULL; @@ -710,8 +772,6 @@ v3d_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *prsc, so->base.reference.count = 1; so->base.context = pctx; - int msaa_scale = prsc->nr_samples > 1 ? 2 : 1; - void *map; #if V3D_VERSION >= 40 so->bo = v3d_bo_alloc(v3d->screen, @@ -724,47 +784,20 @@ v3d_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *prsc, #endif v3dx_pack(map, TEXTURE_SHADER_STATE, tex) { - tex.image_width = prsc->width0 * msaa_scale; - tex.image_height = prsc->height0 * msaa_scale; - -#if V3D_VERSION >= 40 - /* On 4.x, the height of a 1D texture is redefined to be the - * upper 14 bits of the width (which is only usable with txf). - */ - if (prsc->target == PIPE_TEXTURE_1D || - prsc->target == PIPE_TEXTURE_1D_ARRAY) { - tex.image_height = tex.image_width >> 14; - } -#endif - - if (prsc->target == PIPE_TEXTURE_3D) { - tex.image_depth = prsc->depth0; - } else { - tex.image_depth = (cso->u.tex.last_layer - - cso->u.tex.first_layer) + 1; - } + v3d_setup_texture_shader_state(&tex, prsc, + cso->u.tex.first_level, + cso->u.tex.last_level, + cso->u.tex.first_layer, + cso->u.tex.last_layer); tex.srgb = util_format_is_srgb(cso->format); - tex.base_level = cso->u.tex.first_level; #if V3D_VERSION >= 40 - tex.max_level = cso->u.tex.last_level; - /* Note that we don't have a job to reference the texture's sBO - * at state create time, so any time this sampler view is used - * we need to add the texture to the job. - */ - tex.texture_base_pointer = - cl_address(NULL, - rsc->bo->offset + - v3d_layer_offset(prsc, 0, - cso->u.tex.first_layer)); - tex.swizzle_r = translate_swizzle(so->swizzle[0]); tex.swizzle_g = translate_swizzle(so->swizzle[1]); tex.swizzle_b = translate_swizzle(so->swizzle[2]); tex.swizzle_a = translate_swizzle(so->swizzle[3]); #endif - tex.array_stride_64_byte_aligned = rsc->cube_map_stride / 64; if (prsc->nr_samples > 1 && V3D_VERSION < 40) { /* Using texture views to reinterpret formats on our @@ -811,30 +844,8 @@ v3d_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *prsc, tex.srgb = false; } else { tex.texture_type = v3d_get_tex_format(&screen->devinfo, - cso->format); + cso->format); } - - /* Since other platform devices may produce UIF images even - * when they're not big enough for V3D to assume they're UIF, - * we force images with level 0 as UIF to be always treated - * that way. - */ - tex.level_0_is_strictly_uif = (rsc->slices[0].tiling == - VC5_TILING_UIF_XOR || - rsc->slices[0].tiling == - VC5_TILING_UIF_NO_XOR); - tex.level_0_xor_enable = (rsc->slices[0].tiling == - VC5_TILING_UIF_XOR); - - if (tex.level_0_is_strictly_uif) - tex.level_0_ub_pad = rsc->slices[0].ub_pad; - -#if V3D_VERSION >= 40 - if (tex.uif_xor_disable || - tex.level_0_is_strictly_uif) { - tex.extended = true; - } -#endif /* V3D_VERSION >= 40 */ }; return &so->base;