gallium: change pipe_sampler_view::first_element/last_element -> offset/size
[mesa.git] / src / gallium / drivers / freedreno / a3xx / fd3_texture.c
index 6f44ee3c08e8f89383fb05440ff13f57de80ab90..ea2d34177a297e8adf1ae4c1615ae72b911c5cd6 100644 (file)
@@ -36,7 +36,7 @@
 #include "fd3_format.h"
 
 static enum a3xx_tex_clamp
-tex_clamp(unsigned wrap, bool clamp_to_edge)
+tex_clamp(unsigned wrap, bool clamp_to_edge, bool *needs_border)
 {
        /* Hardware does not support _CLAMP, but we emulate it: */
        if (wrap == PIPE_TEX_WRAP_CLAMP) {
@@ -50,6 +50,7 @@ tex_clamp(unsigned wrap, bool clamp_to_edge)
        case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
                return A3XX_TEX_CLAMP_TO_EDGE;
        case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
+               *needs_border = true;
                return A3XX_TEX_CLAMP_TO_BORDER;
        case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
                /* only works for PoT.. need to emulate otherwise! */
@@ -113,15 +114,17 @@ fd3_sampler_state_create(struct pipe_context *pctx,
                so->saturate_r = (cso->wrap_r == PIPE_TEX_WRAP_CLAMP);
        }
 
+       so->needs_border = false;
        so->texsamp0 =
                        COND(!cso->normalized_coords, A3XX_TEX_SAMP_0_UNNORM_COORDS) |
+                       COND(!cso->seamless_cube_map, A3XX_TEX_SAMP_0_CUBEMAPSEAMLESSFILTOFF) |
                        COND(miplinear, A3XX_TEX_SAMP_0_MIPFILTER_LINEAR) |
                        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));
+                       A3XX_TEX_SAMP_0_WRAP_S(tex_clamp(cso->wrap_s, clamp_to_edge, &so->needs_border)) |
+                       A3XX_TEX_SAMP_0_WRAP_T(tex_clamp(cso->wrap_t, clamp_to_edge, &so->needs_border)) |
+                       A3XX_TEX_SAMP_0_WRAP_R(tex_clamp(cso->wrap_r, clamp_to_edge, &so->needs_border));
 
        if (cso->compare_mode)
                so->texsamp0 |= A3XX_TEX_SAMP_0_COMPARE_FUNC(cso->compare_func); /* maps 1:1 */
@@ -148,6 +151,9 @@ fd3_sampler_states_bind(struct pipe_context *pctx,
        uint16_t saturate_s = 0, saturate_t = 0, saturate_r = 0;
        unsigned i;
 
+       if (!hwcso)
+               nr = 0;
+
        for (i = 0; i < nr; i++) {
                if (hwcso[i]) {
                        struct fd3_sampler_stateobj *sampler =
@@ -210,8 +216,7 @@ fd3_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
 {
        struct fd3_pipe_sampler_view *so = CALLOC_STRUCT(fd3_pipe_sampler_view);
        struct fd_resource *rsc = fd_resource(prsc);
-       unsigned lvl = cso->u.tex.first_level;
-       unsigned miplevels = cso->u.tex.last_level - lvl;
+       unsigned lvl;
        uint32_t sz2 = 0;
 
        if (!so)
@@ -226,20 +231,33 @@ fd3_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
        so->texconst0 =
                        A3XX_TEX_CONST_0_TYPE(tex_type(prsc->target)) |
                        A3XX_TEX_CONST_0_FMT(fd3_pipe2tex(cso->format)) |
-                       A3XX_TEX_CONST_0_MIPLVLS(miplevels) |
                        fd3_tex_swiz(cso->format, cso->swizzle_r, cso->swizzle_g,
                                                cso->swizzle_b, cso->swizzle_a);
 
        if (util_format_is_srgb(cso->format))
                so->texconst0 |= A3XX_TEX_CONST_0_SRGB;
 
-       so->texconst1 =
+       if (prsc->target == PIPE_BUFFER) {
+               lvl = 0;
+               so->texconst1 =
+                       A3XX_TEX_CONST_1_FETCHSIZE(fd3_pipe2fetchsize(cso->format)) |
+                       A3XX_TEX_CONST_1_WIDTH(cso->u.buf.size / util_format_get_blocksize(cso->format)) |
+                       A3XX_TEX_CONST_1_HEIGHT(1);
+       } else {
+               unsigned miplevels;
+
+               lvl = fd_sampler_first_level(cso);
+               miplevels = fd_sampler_last_level(cso) - lvl;
+
+               so->texconst0 |= A3XX_TEX_CONST_0_MIPLVLS(miplevels);
+               so->texconst1 =
                        A3XX_TEX_CONST_1_FETCHSIZE(fd3_pipe2fetchsize(cso->format)) |
                        A3XX_TEX_CONST_1_WIDTH(u_minify(prsc->width0, lvl)) |
                        A3XX_TEX_CONST_1_HEIGHT(u_minify(prsc->height0, lvl));
+       }
        /* 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);
+                       A3XX_TEX_CONST_2_PITCH(fd3_pipe2nblocksx(cso->format, rsc->slices[lvl].pitch) * rsc->cpp);
        switch (prsc->target) {
        case PIPE_TEXTURE_1D_ARRAY:
        case PIPE_TEXTURE_2D_ARRAY:
@@ -263,44 +281,11 @@ fd3_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
        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;
+       pctx->set_sampler_views = fd_set_sampler_views;
 }