X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fdrivers%2Ffreedreno%2Fa3xx%2Ffd3_texture.c;h=6f44ee3c08e8f89383fb05440ff13f57de80ab90;hb=6cdb29d52fc51e3d904b50bb7003c9fa38bb7896;hp=b0e5efb10a456d81dc4bee951f14e183a8592334;hpb=bd3b0964675d36e753e273d5667b922cc9baac4a;p=mesa.git diff --git a/src/gallium/drivers/freedreno/a3xx/fd3_texture.c b/src/gallium/drivers/freedreno/a3xx/fd3_texture.c index b0e5efb10a4..6f44ee3c08e 100644 --- a/src/gallium/drivers/freedreno/a3xx/fd3_texture.c +++ b/src/gallium/drivers/freedreno/a3xx/fd3_texture.c @@ -33,31 +33,34 @@ #include "util/u_format.h" #include "fd3_texture.h" -#include "fd3_util.h" +#include "fd3_format.h" static enum a3xx_tex_clamp -tex_clamp(unsigned wrap) +tex_clamp(unsigned wrap, bool clamp_to_edge) { - /* hardware probably supports more, but we can't coax all the - * wrap/clamp modes out of the GLESv2 blob driver. - * - * TODO once we have basics working, go back and just try - * different values and see what happens - */ + /* Hardware does not support _CLAMP, but we emulate it: */ + if (wrap == PIPE_TEX_WRAP_CLAMP) { + wrap = (clamp_to_edge) ? + PIPE_TEX_WRAP_CLAMP_TO_EDGE : PIPE_TEX_WRAP_CLAMP_TO_BORDER; + } + switch (wrap) { case PIPE_TEX_WRAP_REPEAT: return A3XX_TEX_REPEAT; - case PIPE_TEX_WRAP_CLAMP: case PIPE_TEX_WRAP_CLAMP_TO_EDGE: return A3XX_TEX_CLAMP_TO_EDGE; case PIPE_TEX_WRAP_CLAMP_TO_BORDER: return A3XX_TEX_CLAMP_TO_BORDER; - case PIPE_TEX_WRAP_MIRROR_CLAMP: - case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: + /* only works for PoT.. need to emulate otherwise! */ return A3XX_TEX_MIRROR_CLAMP; case PIPE_TEX_WRAP_MIRROR_REPEAT: return A3XX_TEX_MIRROR_REPEAT; + case PIPE_TEX_WRAP_MIRROR_CLAMP: + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: + /* these two we could perhaps emulate, but we currently + * just don't advertise PIPE_CAP_TEXTURE_MIRROR_CLAMP + */ default: DBG("invalid wrap: %u", wrap); return 0; @@ -65,13 +68,13 @@ tex_clamp(unsigned wrap) } static enum a3xx_tex_filter -tex_filter(unsigned filter) +tex_filter(unsigned filter, bool aniso) { switch (filter) { case PIPE_TEX_FILTER_NEAREST: return A3XX_TEX_NEAREST; case PIPE_TEX_FILTER_LINEAR: - return A3XX_TEX_LINEAR; + return aniso ? A3XX_TEX_ANISO : A3XX_TEX_LINEAR; default: DBG("invalid filter: %u", filter); return 0; @@ -83,7 +86,9 @@ fd3_sampler_state_create(struct pipe_context *pctx, const struct pipe_sampler_state *cso) { struct fd3_sampler_stateobj *so = CALLOC_STRUCT(fd3_sampler_stateobj); + unsigned aniso = util_last_bit(MIN2(cso->max_anisotropy >> 1, 8)); bool miplinear = false; + bool clamp_to_edge; if (!so) return NULL; @@ -93,20 +98,37 @@ fd3_sampler_state_create(struct pipe_context *pctx, so->base = *cso; + /* + * For nearest filtering, _CLAMP means _CLAMP_TO_EDGE; for linear + * filtering, _CLAMP means _CLAMP_TO_BORDER while additionally + * clamping the texture coordinates to [0.0, 1.0]. + * + * The clamping will be taken care of in the shaders. There are two + * filters here, but let the minification one has a say. + */ + clamp_to_edge = (cso->min_img_filter == PIPE_TEX_FILTER_NEAREST); + if (!clamp_to_edge) { + so->saturate_s = (cso->wrap_s == PIPE_TEX_WRAP_CLAMP); + so->saturate_t = (cso->wrap_t == PIPE_TEX_WRAP_CLAMP); + so->saturate_r = (cso->wrap_r == PIPE_TEX_WRAP_CLAMP); + } + so->texsamp0 = COND(!cso->normalized_coords, A3XX_TEX_SAMP_0_UNNORM_COORDS) | COND(miplinear, A3XX_TEX_SAMP_0_MIPFILTER_LINEAR) | - A3XX_TEX_SAMP_0_XY_MAG(tex_filter(cso->mag_img_filter)) | - A3XX_TEX_SAMP_0_XY_MIN(tex_filter(cso->min_img_filter)) | - A3XX_TEX_SAMP_0_WRAP_S(tex_clamp(cso->wrap_s)) | - A3XX_TEX_SAMP_0_WRAP_T(tex_clamp(cso->wrap_t)) | - A3XX_TEX_SAMP_0_WRAP_R(tex_clamp(cso->wrap_r)); + A3XX_TEX_SAMP_0_XY_MAG(tex_filter(cso->mag_img_filter, aniso)) | + A3XX_TEX_SAMP_0_XY_MIN(tex_filter(cso->min_img_filter, aniso)) | + A3XX_TEX_SAMP_0_ANISO(aniso) | + A3XX_TEX_SAMP_0_WRAP_S(tex_clamp(cso->wrap_s, clamp_to_edge)) | + A3XX_TEX_SAMP_0_WRAP_T(tex_clamp(cso->wrap_t, clamp_to_edge)) | + A3XX_TEX_SAMP_0_WRAP_R(tex_clamp(cso->wrap_r, clamp_to_edge)); if (cso->compare_mode) so->texsamp0 |= A3XX_TEX_SAMP_0_COMPARE_FUNC(cso->compare_func); /* maps 1:1 */ if (cso->min_mip_filter != PIPE_TEX_MIPFILTER_NONE) { so->texsamp1 = + A3XX_TEX_SAMP_1_LOD_BIAS(cso->lod_bias) | A3XX_TEX_SAMP_1_MIN_LOD(cso->min_lod) | A3XX_TEX_SAMP_1_MAX_LOD(cso->max_lod); } else { @@ -116,6 +138,50 @@ fd3_sampler_state_create(struct pipe_context *pctx, return so; } +static void +fd3_sampler_states_bind(struct pipe_context *pctx, + unsigned shader, unsigned start, + unsigned nr, void **hwcso) +{ + struct fd_context *ctx = fd_context(pctx); + struct fd3_context *fd3_ctx = fd3_context(ctx); + uint16_t saturate_s = 0, saturate_t = 0, saturate_r = 0; + unsigned i; + + for (i = 0; i < nr; i++) { + if (hwcso[i]) { + struct fd3_sampler_stateobj *sampler = + fd3_sampler_stateobj(hwcso[i]); + if (sampler->saturate_s) + saturate_s |= (1 << i); + if (sampler->saturate_t) + saturate_t |= (1 << i); + if (sampler->saturate_r) + saturate_r |= (1 << i); + } + } + + fd_sampler_states_bind(pctx, shader, start, nr, hwcso); + + if (shader == PIPE_SHADER_FRAGMENT) { + fd3_ctx->fsaturate = + (saturate_s != 0) || + (saturate_t != 0) || + (saturate_r != 0); + fd3_ctx->fsaturate_s = saturate_s; + fd3_ctx->fsaturate_t = saturate_t; + fd3_ctx->fsaturate_r = saturate_r; + } else if (shader == PIPE_SHADER_VERTEX) { + fd3_ctx->vsaturate = + (saturate_s != 0) || + (saturate_t != 0) || + (saturate_r != 0); + fd3_ctx->vsaturate_s = saturate_s; + fd3_ctx->vsaturate_t = saturate_t; + fd3_ctx->vsaturate_r = saturate_r; + } +} + static enum a3xx_tex_type tex_type(unsigned target) { @@ -146,6 +212,7 @@ fd3_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc, struct fd_resource *rsc = fd_resource(prsc); unsigned lvl = cso->u.tex.first_level; unsigned miplevels = cso->u.tex.last_level - lvl; + uint32_t sz2 = 0; if (!so) return NULL; @@ -156,8 +223,6 @@ fd3_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc, so->base.reference.count = 1; so->base.context = pctx; - so->tex_resource = rsc; - so->texconst0 = A3XX_TEX_CONST_0_TYPE(tex_type(prsc->target)) | A3XX_TEX_CONST_0_FMT(fd3_pipe2tex(cso->format)) | @@ -175,14 +240,67 @@ fd3_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc, /* when emitted, A3XX_TEX_CONST_2_INDX() must be OR'd in: */ so->texconst2 = A3XX_TEX_CONST_2_PITCH(rsc->slices[lvl].pitch * rsc->cpp); - so->texconst3 = 0x00000000; /* ??? */ + switch (prsc->target) { + case PIPE_TEXTURE_1D_ARRAY: + case PIPE_TEXTURE_2D_ARRAY: + so->texconst3 = + A3XX_TEX_CONST_3_DEPTH(prsc->array_size - 1) | + A3XX_TEX_CONST_3_LAYERSZ1(rsc->slices[0].size0); + break; + case PIPE_TEXTURE_3D: + so->texconst3 = + A3XX_TEX_CONST_3_DEPTH(u_minify(prsc->depth0, lvl)) | + A3XX_TEX_CONST_3_LAYERSZ1(rsc->slices[lvl].size0); + while (lvl < cso->u.tex.last_level && sz2 != rsc->slices[lvl+1].size0) + sz2 = rsc->slices[++lvl].size0; + so->texconst3 |= A3XX_TEX_CONST_3_LAYERSZ2(sz2); + break; + default: + so->texconst3 = 0x00000000; + break; + } return &so->base; } +static void +fd3_set_sampler_views(struct pipe_context *pctx, unsigned shader, + unsigned start, unsigned nr, + struct pipe_sampler_view **views) +{ + struct fd_context *ctx = fd_context(pctx); + struct fd3_context *fd3_ctx = fd3_context(ctx); + struct fd_texture_stateobj *tex; + uint16_t integer_s = 0, *ptr; + int i; + + fd_set_sampler_views(pctx, shader, start, nr, views); + + switch (shader) { + case PIPE_SHADER_FRAGMENT: + tex = &ctx->fragtex; + ptr = &fd3_ctx->finteger_s; + break; + case PIPE_SHADER_VERTEX: + tex = &ctx->verttex; + ptr = &fd3_ctx->vinteger_s; + break; + default: + return; + } + + for (i = 0; i < tex->num_textures; i++) + if (util_format_is_pure_integer(tex->textures[i]->format)) + integer_s |= 1 << i; + *ptr = integer_s; +} + + void fd3_texture_init(struct pipe_context *pctx) { pctx->create_sampler_state = fd3_sampler_state_create; + pctx->bind_sampler_states = fd3_sampler_states_bind; pctx->create_sampler_view = fd3_sampler_view_create; + pctx->set_sampler_views = fd3_set_sampler_views; }