X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fdrivers%2Ffreedreno%2Fa6xx%2Ffd6_texture.c;h=e0883815ca989c3bfbcb94629ce2cba79903ac43;hb=36612c96bd2a354b4c31eeb331d2f4bbad2f210e;hp=0fa20e01e67334e9b7350a690fa0157e2fb27e26;hpb=bb84fa146f2252f22999205a2904d8a948bffd3b;p=mesa.git diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_texture.c b/src/gallium/drivers/freedreno/a6xx/fd6_texture.c index 0fa20e01e67..e0883815ca9 100644 --- a/src/gallium/drivers/freedreno/a6xx/fd6_texture.c +++ b/src/gallium/drivers/freedreno/a6xx/fd6_texture.c @@ -29,10 +29,11 @@ #include "util/u_string.h" #include "util/u_memory.h" #include "util/u_inlines.h" -#include "util/u_format.h" +#include "util/format/u_format.h" #include "util/hash_table.h" #include "fd6_texture.h" +#include "fd6_resource.h" #include "fd6_format.h" #include "fd6_emit.h" @@ -129,15 +130,15 @@ fd6_sampler_state_create(struct pipe_context *pctx, A6XX_TEX_SAMP_0_WRAP_R(tex_clamp(cso->wrap_r, clamp_to_edge, &so->needs_border)); so->texsamp1 = + COND(cso->min_mip_filter == PIPE_TEX_MIPFILTER_NONE, + A6XX_TEX_SAMP_1_MIPFILTER_LINEAR_FAR) | COND(!cso->seamless_cube_map, A6XX_TEX_SAMP_1_CUBEMAPSEAMLESSFILTOFF) | COND(!cso->normalized_coords, A6XX_TEX_SAMP_1_UNNORM_COORDS); - if (cso->min_mip_filter != PIPE_TEX_MIPFILTER_NONE) { - so->texsamp0 |= A6XX_TEX_SAMP_0_LOD_BIAS(cso->lod_bias); - so->texsamp1 |= - A6XX_TEX_SAMP_1_MIN_LOD(cso->min_lod) | - A6XX_TEX_SAMP_1_MAX_LOD(cso->max_lod); - } + so->texsamp0 |= A6XX_TEX_SAMP_0_LOD_BIAS(cso->lod_bias); + so->texsamp1 |= + A6XX_TEX_SAMP_1_MIN_LOD(cso->min_lod) | + A6XX_TEX_SAMP_1_MAX_LOD(cso->max_lod); if (cso->compare_mode) so->texsamp1 |= A6XX_TEX_SAMP_1_COMPARE_FUNC(cso->compare_func); /* maps 1:1 */ @@ -213,24 +214,21 @@ fd6_sampler_states_bind(struct pipe_context *pctx, } } -static bool -use_astc_srgb_workaround(struct pipe_context *pctx, enum pipe_format format) -{ - return false; // TODO check if this is still needed on a5xx -} - static struct pipe_sampler_view * fd6_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc, const struct pipe_sampler_view *cso) { struct fd6_pipe_sampler_view *so = CALLOC_STRUCT(fd6_pipe_sampler_view); struct fd_resource *rsc = fd_resource(prsc); + struct fdl_slice *slice = NULL; enum pipe_format format = cso->format; - unsigned lvl, layers; + unsigned lvl, layers = 0; if (!so) return NULL; + fd6_validate_format(fd_context(pctx), rsc, format); + if (format == PIPE_FORMAT_X32_S8X24_UINT) { rsc = rsc->stencil; format = rsc->base.format; @@ -243,45 +241,22 @@ fd6_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc, so->base.context = pctx; so->seqno = ++fd6_context(fd_context(pctx))->tex_seqno; - so->texconst0 = - A6XX_TEX_CONST_0_FMT(fd6_pipe2tex(format)) | - fd6_tex_swiz(format, cso->swizzle_r, cso->swizzle_g, - cso->swizzle_b, cso->swizzle_a); - - /* NOTE: since we sample z24s8 using 8888_UINT format, the swizzle - * we get isn't quite right. Use SWAP(XYZW) as a cheap and cheerful - * way to re-arrange things so stencil component is where the swiz - * expects. - * - * Note that gallium expects stencil sampler to return (s,s,s,s) - * which isn't quite true. To make that happen we'd have to massage - * the swizzle. But in practice only the .x component is used. - */ - if (format == PIPE_FORMAT_X24S8_UINT) { - so->texconst0 |= A6XX_TEX_CONST_0_SWAP(XYZW); - } - - if (util_format_is_srgb(format)) { - if (use_astc_srgb_workaround(pctx, format)) - so->astc_srgb = true; - so->texconst0 |= A6XX_TEX_CONST_0_SRGB; - } - if (cso->target == PIPE_BUFFER) { unsigned elements = cso->u.buf.size / util_format_get_blocksize(format); lvl = 0; so->texconst1 = - A6XX_TEX_CONST_1_WIDTH(elements) | - A6XX_TEX_CONST_1_HEIGHT(1); + A6XX_TEX_CONST_1_WIDTH(elements & MASK(15)) | + A6XX_TEX_CONST_1_HEIGHT(elements >> 15); so->texconst2 = - A6XX_TEX_CONST_2_FETCHSIZE(fd6_pipe2fetchsize(format)) | - A6XX_TEX_CONST_2_PITCH(elements * rsc->cpp); + A6XX_TEX_CONST_2_UNK4 | + A6XX_TEX_CONST_2_UNK31; so->offset = cso->u.buf.offset; } else { unsigned miplevels; lvl = fd_sampler_first_level(cso); + slice = fd_resource_slice(rsc, lvl); miplevels = fd_sampler_last_level(cso) - lvl; layers = cso->u.tex.last_layer - cso->u.tex.first_layer + 1; @@ -292,11 +267,16 @@ fd6_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc, so->texconst2 = A6XX_TEX_CONST_2_FETCHSIZE(fd6_pipe2fetchsize(format)) | A6XX_TEX_CONST_2_PITCH( - util_format_get_nblocksx( - format, rsc->slices[lvl].pitch) * rsc->cpp); + util_format_get_nblocksx(format, slice->pitch) * rsc->layout.cpp); so->offset = fd_resource_offset(rsc, lvl, cso->u.tex.first_layer); + so->ubwc_offset = fd_resource_ubwc_offset(rsc, lvl, cso->u.tex.first_layer); + so->ubwc_enabled = fd_resource_ubwc_enabled(rsc, lvl); } + so->texconst0 |= fd6_tex_const_0(prsc, lvl, cso->format, + cso->swizzle_r, cso->swizzle_g, + cso->swizzle_b, cso->swizzle_a); + so->texconst2 |= A6XX_TEX_CONST_2_TYPE(fd6_tex_type(cso->target)); switch (cso->target) { @@ -304,35 +284,50 @@ fd6_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc, case PIPE_TEXTURE_1D: case PIPE_TEXTURE_2D: so->texconst3 = - A6XX_TEX_CONST_3_ARRAY_PITCH(rsc->layer_size); + A6XX_TEX_CONST_3_ARRAY_PITCH(rsc->layout.layer_size); so->texconst5 = A6XX_TEX_CONST_5_DEPTH(1); break; case PIPE_TEXTURE_1D_ARRAY: case PIPE_TEXTURE_2D_ARRAY: so->texconst3 = - A6XX_TEX_CONST_3_ARRAY_PITCH(rsc->layer_size); + A6XX_TEX_CONST_3_ARRAY_PITCH(rsc->layout.layer_size); so->texconst5 = A6XX_TEX_CONST_5_DEPTH(layers); break; case PIPE_TEXTURE_CUBE: case PIPE_TEXTURE_CUBE_ARRAY: so->texconst3 = - A6XX_TEX_CONST_3_ARRAY_PITCH(rsc->layer_size); + A6XX_TEX_CONST_3_ARRAY_PITCH(rsc->layout.layer_size); so->texconst5 = A6XX_TEX_CONST_5_DEPTH(layers / 6); break; case PIPE_TEXTURE_3D: so->texconst3 = - A6XX_TEX_CONST_3_ARRAY_PITCH(rsc->slices[lvl].size0); + A6XX_TEX_CONST_3_MIN_LAYERSZ( + fd_resource_slice(rsc, prsc->last_level)->size0) | + A6XX_TEX_CONST_3_ARRAY_PITCH(slice->size0); so->texconst5 = A6XX_TEX_CONST_5_DEPTH(u_minify(prsc->depth0, lvl)); break; default: - so->texconst3 = 0x00000000; break; } + if (so->ubwc_enabled) { + struct fdl_slice *ubwc_base_slice = &rsc->layout.ubwc_slices[lvl]; + + uint32_t block_width, block_height; + fdl6_get_ubwc_blockwidth(&rsc->layout, &block_width, &block_height); + + so->texconst3 |= A6XX_TEX_CONST_3_FLAG | A6XX_TEX_CONST_3_TILE_ALL; + so->texconst9 |= A6XX_TEX_CONST_9_FLAG_BUFFER_ARRAY_PITCH(rsc->layout.ubwc_layer_size >> 2); + so->texconst10 |= + A6XX_TEX_CONST_10_FLAG_BUFFER_PITCH(ubwc_base_slice->pitch) | + A6XX_TEX_CONST_10_FLAG_BUFFER_LOGW(util_logbase2_ceil(DIV_ROUND_UP(u_minify(prsc->width0, lvl), block_width))) | + A6XX_TEX_CONST_10_FLAG_BUFFER_LOGH(util_logbase2_ceil(DIV_ROUND_UP(u_minify(prsc->height0, lvl), block_height))); + } + return &so->base; } @@ -360,34 +355,6 @@ fd6_sampler_view_destroy(struct pipe_context *pctx, free(view); } -static void -fd6_set_sampler_views(struct pipe_context *pctx, enum pipe_shader_type shader, - unsigned start, unsigned nr, - struct pipe_sampler_view **views) -{ - struct fd_context *ctx = fd_context(pctx); - struct fd6_context *fd6_ctx = fd6_context(ctx); - uint16_t astc_srgb = 0; - unsigned i; - - for (i = 0; i < nr; i++) { - if (views[i]) { - struct fd6_pipe_sampler_view *view = - fd6_pipe_sampler_view(views[i]); - if (view->astc_srgb) - astc_srgb |= (1 << i); - } - } - - fd_set_sampler_views(pctx, shader, start, nr, views); - - if (shader == PIPE_SHADER_FRAGMENT) { - fd6_ctx->fastc_srgb = astc_srgb; - } else if (shader == PIPE_SHADER_VERTEX) { - fd6_ctx->vastc_srgb = astc_srgb; - } -} - static uint32_t key_hash(const void *_key) @@ -407,7 +374,7 @@ key_equals(const void *_a, const void *_b) } struct fd6_texture_state * -fd6_texture_state(struct fd_context *ctx, enum a6xx_state_block sb, +fd6_texture_state(struct fd_context *ctx, enum pipe_shader_type type, struct fd_texture_stateobj *tex) { struct fd6_context *fd6_ctx = fd6_context(ctx); @@ -439,19 +406,8 @@ fd6_texture_state(struct fd_context *ctx, enum a6xx_state_block sb, needs_border |= sampler->needs_border; } - /* This will need update for HS/DS/GS: */ - if (unlikely(needs_border && (sb == SB6_FS_TEX))) { - /* TODO we could probably use fixed offsets for each shader - * stage and avoid the need for # of VS samplers to be part - * of the FS tex state.. but I don't think our handling of - * BCOLOR_OFFSET is actually correct, and trying to use a - * hard coded offset of 16 breaks things. - * - * Note that when this changes, then a corresponding change - * in emit_border_color() is also needed. - */ - key.bcolor_offset = ctx->tex[PIPE_SHADER_VERTEX].num_samplers; - } + key.type = type; + key.bcolor_offset = fd6_border_color_offset(ctx, type, tex); uint32_t hash = key_hash(&key); struct hash_entry *entry = @@ -467,7 +423,8 @@ fd6_texture_state(struct fd_context *ctx, enum a6xx_state_block sb, state->stateobj = fd_ringbuffer_new_object(ctx->pipe, 0x1000); state->needs_border = needs_border; - fd6_emit_textures(ctx->pipe, state->stateobj, sb, tex, key.bcolor_offset); + fd6_emit_textures(ctx->pipe, state->stateobj, type, tex, key.bcolor_offset, + NULL, NULL); /* NOTE: uses copy of key in state obj, because pointer passed by caller * is probably on the stack @@ -496,7 +453,7 @@ fd6_texture_init(struct pipe_context *pctx) pctx->create_sampler_view = fd6_sampler_view_create; pctx->sampler_view_destroy = fd6_sampler_view_destroy; - pctx->set_sampler_views = fd6_set_sampler_views; + pctx->set_sampler_views = fd_set_sampler_views; fd6_ctx->tex_cache = _mesa_hash_table_create(NULL, key_hash, key_equals); }