freedreno: fix samples=0 vs samples=1 confusion
[mesa.git] / src / gallium / drivers / freedreno / freedreno_texture.c
index f03b65b0ae522db5315e34604bba45bc5cf2499f..1487f7441c924d2ee001ef6490f7a22428d3dbde 100644 (file)
@@ -50,109 +50,62 @@ fd_sampler_view_destroy(struct pipe_context *pctx,
 }
 
 static void bind_sampler_states(struct fd_texture_stateobj *tex,
-               unsigned nr, void **hwcso)
+               unsigned start, unsigned nr, void **hwcso)
 {
        unsigned i;
-       unsigned new_nr = 0;
 
        for (i = 0; i < nr; i++) {
-               if (hwcso[i])
-                       new_nr = i + 1;
-               tex->samplers[i] = hwcso[i];
-               tex->dirty_samplers |= (1 << i);
-       }
-
-       for (; i < tex->num_samplers; i++) {
-               tex->samplers[i] = NULL;
-               tex->dirty_samplers |= (1 << i);
+               unsigned p = i + start;
+               tex->samplers[p] = hwcso[i];
+               if (tex->samplers[p])
+                       tex->valid_samplers |= (1 << p);
+               else
+                       tex->valid_samplers &= ~(1 << p);
        }
 
-       tex->num_samplers = new_nr;
+       tex->num_samplers = util_last_bit(tex->valid_samplers);
 }
 
 static void set_sampler_views(struct fd_texture_stateobj *tex,
-               unsigned nr, struct pipe_sampler_view **views)
+               unsigned start, unsigned nr, struct pipe_sampler_view **views)
 {
        unsigned i;
-       unsigned new_nr = 0;
 
        for (i = 0; i < nr; i++) {
-               if (views[i])
-                       new_nr = i + 1;
-               pipe_sampler_view_reference(&tex->textures[i], views[i]);
-               tex->dirty_samplers |= (1 << i);
+               struct pipe_sampler_view *view = views ? views[i] : NULL;
+               unsigned p = i + start;
+               pipe_sampler_view_reference(&tex->textures[p], view);
+               if (tex->textures[p])
+                       tex->valid_textures |= (1 << p);
+               else
+                       tex->valid_textures &= ~(1 << p);
        }
 
-       for (; i < tex->num_textures; i++) {
-               pipe_sampler_view_reference(&tex->textures[i], NULL);
-               tex->dirty_samplers |= (1 << i);
-       }
-
-       tex->num_textures = new_nr;
+       tex->num_textures = util_last_bit(tex->valid_textures);
 }
 
 void
 fd_sampler_states_bind(struct pipe_context *pctx,
-               unsigned shader, unsigned start,
+               enum pipe_shader_type shader, unsigned start,
                unsigned nr, void **hwcso)
 {
        struct fd_context *ctx = fd_context(pctx);
 
-       assert(start == 0);
-
-       if (shader == PIPE_SHADER_FRAGMENT) {
-               bind_sampler_states(&ctx->fragtex, nr, hwcso);
-               ctx->dirty |= FD_DIRTY_FRAGTEX;
-       }
-       else if (shader == PIPE_SHADER_VERTEX) {
-               bind_sampler_states(&ctx->verttex, nr, hwcso);
-               ctx->dirty |= FD_DIRTY_VERTTEX;
-       }
-}
-
-
-static void
-fd_fragtex_set_sampler_views(struct pipe_context *pctx, unsigned nr,
-               struct pipe_sampler_view **views)
-{
-       struct fd_context *ctx = fd_context(pctx);
-
-       /* on a2xx, since there is a flat address space for textures/samplers,
-        * a change in # of fragment textures/samplers will trigger patching and
-        * re-emitting the vertex shader:
-        */
-       if (nr != ctx->fragtex.num_textures)
-               ctx->dirty |= FD_DIRTY_TEXSTATE;
-
-       set_sampler_views(&ctx->fragtex, nr, views);
-       ctx->dirty |= FD_DIRTY_FRAGTEX;
+       bind_sampler_states(&ctx->tex[shader], start, nr, hwcso);
+       ctx->dirty_shader[shader] |= FD_DIRTY_SHADER_TEX;
+       ctx->dirty |= FD_DIRTY_TEX;
 }
 
-static void
-fd_verttex_set_sampler_views(struct pipe_context *pctx, unsigned nr,
+void
+fd_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);
-       set_sampler_views(&ctx->verttex, nr, views);
-       ctx->dirty |= FD_DIRTY_VERTTEX;
-}
 
-void
-fd_set_sampler_views(struct pipe_context *pctx, unsigned shader,
-                     unsigned start, unsigned nr,
-                     struct pipe_sampler_view **views)
-{
-   assert(start == 0);
-   switch (shader) {
-   case PIPE_SHADER_FRAGMENT:
-      fd_fragtex_set_sampler_views(pctx, nr, views);
-      break;
-   case PIPE_SHADER_VERTEX:
-      fd_verttex_set_sampler_views(pctx, nr, views);
-      break;
-   default:
-      ;
-   }
+       set_sampler_views(&ctx->tex[shader], start, nr, views);
+       ctx->dirty_shader[shader] |= FD_DIRTY_SHADER_TEX;
+       ctx->dirty |= FD_DIRTY_TEX;
 }
 
 void
@@ -197,37 +150,15 @@ fd_setup_border_colors(struct fd_texture_stateobj *tex, void *ptr,
                                        continue;
 
                                const struct util_format_channel_description *chan =
-                                               &desc->channel[desc->swizzle[j]];
-                               int size = chan->size;
-
-                               /* The Z16 texture format we use seems to look in the
-                                * 32-bit border color slots
-                                */
-                               if (desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS)
-                                       size = 32;
-
-                               /* Formats like R11G11B10 or RGB9_E5 don't specify
-                                * per-channel sizes properly.
-                                */
-                               if (desc->layout == UTIL_FORMAT_LAYOUT_OTHER)
-                                       size = 16;
-
-                               /* We fake RGTC as if it were RGBA8 */
-                               if (desc->layout == UTIL_FORMAT_LAYOUT_RGTC)
-                                       size = 8;
-
-                               if (chan->pure_integer && size > 16)
-                                       bcolor32[desc->swizzle[j] + 4] =
-                                                       sampler->border_color.i[j];
-                               else if (size > 16)
-                                       bcolor32[desc->swizzle[j]] =
-                                                       fui(sampler->border_color.f[j]);
-                               else if (chan->pure_integer)
-                                       bcolor[desc->swizzle[j] + 8] =
-                                                       sampler->border_color.i[j];
-                               else
+                                       &desc->channel[desc->swizzle[j]];
+                               if (chan->pure_integer) {
+                                       bcolor32[desc->swizzle[j] + 4] = sampler->border_color.i[j];
+                                       bcolor[desc->swizzle[j] + 8] = sampler->border_color.i[j];
+                               } else {
+                                       bcolor32[desc->swizzle[j]] = fui(sampler->border_color.f[j]);
                                        bcolor[desc->swizzle[j]] =
-                                                       util_float_to_half(sampler->border_color.f[j]);
+                                               util_float_to_half(sampler->border_color.f[j]);
+                               }
                        }
                }
        }