freedreno/ir3+a6xx: same VBO state for draw/binning
[mesa.git] / src / gallium / drivers / freedreno / a6xx / fd6_texture.c
index f2f7276aaa8f0f2e63e30c3492f4e38b267cfaeb..2cb69e01a2ee384cfadaeb30c69b330b29719818 100644 (file)
@@ -33,6 +33,7 @@
 #include "util/hash_table.h"
 
 #include "fd6_texture.h"
+#include "fd6_resource.h"
 #include "fd6_format.h"
 #include "fd6_emit.h"
 
@@ -220,11 +221,13 @@ fd6_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
        struct fd6_pipe_sampler_view *so = CALLOC_STRUCT(fd6_pipe_sampler_view);
        struct fd_resource *rsc = fd_resource(prsc);
        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;
@@ -237,16 +240,6 @@ 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)) |
-               A6XX_TEX_CONST_0_SAMPLES(fd_msaa_samples(prsc->nr_samples)) |
-               fd6_tex_swiz(prsc, cso->format, cso->swizzle_r, cso->swizzle_g,
-                               cso->swizzle_b, cso->swizzle_a);
-
-       if (util_format_is_srgb(format)) {
-               so->texconst0 |= A6XX_TEX_CONST_0_SRGB;
-       }
-
        if (cso->target == PIPE_BUFFER) {
                unsigned elements = cso->u.buf.size / util_format_get_blocksize(format);
 
@@ -260,17 +253,12 @@ fd6_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
                so->offset = cso->u.buf.offset;
        } else {
                unsigned miplevels;
-               enum a6xx_tile_mode tile_mode = TILE6_LINEAR;
 
                lvl = fd_sampler_first_level(cso);
                miplevels = fd_sampler_last_level(cso) - lvl;
                layers = cso->u.tex.last_layer - cso->u.tex.first_layer + 1;
 
-               if (!fd_resource_level_linear(prsc, lvl))
-                       tile_mode = fd_resource(prsc)->tile_mode;
-
-               so->texconst0 |= A6XX_TEX_CONST_0_MIPLVLS(miplevels) |
-                       A6XX_TEX_CONST_0_TILE_MODE(tile_mode);
+               so->texconst0 |= A6XX_TEX_CONST_0_MIPLVLS(miplevels);
                so->texconst1 =
                        A6XX_TEX_CONST_1_WIDTH(u_minify(prsc->width0, lvl)) |
                        A6XX_TEX_CONST_1_HEIGHT(u_minify(prsc->height0, lvl));
@@ -280,13 +268,17 @@ fd6_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
                                        util_format_get_nblocksx(
                                                        format, rsc->slices[lvl].pitch) * rsc->cpp);
                so->offset = fd_resource_offset(rsc, lvl, cso->u.tex.first_layer);
-
-               so->ubwc_enabled = rsc->ubwc_size && u_minify(prsc->width0, lvl) >= 16;
+               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);
+
        if (so->ubwc_enabled) {
-               so->texconst9 |= A6XX_TEX_CONST_9_FLAG_BUFFER_PITCH(rsc->ubwc_size);
-               so->texconst10 |= A6XX_TEX_CONST_10_FLAG_BUFFER_ARRAY_PITCH(rsc->ubwc_pitch);
+               so->texconst9 |= A6XX_TEX_CONST_9_FLAG_BUFFER_ARRAY_PITCH(rsc->ubwc_size);
+               so->texconst10 |= A6XX_TEX_CONST_10_FLAG_BUFFER_PITCH(rsc->ubwc_pitch);
        }
 
        so->texconst2 |= A6XX_TEX_CONST_2_TYPE(fd6_tex_type(cso->target));
@@ -325,6 +317,10 @@ fd6_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
                break;
        }
 
+       if (so->ubwc_enabled) {
+               so->texconst3 |= A6XX_TEX_CONST_3_FLAG | A6XX_TEX_CONST_3_UNK27;
+       }
+
        return &so->base;
 }
 
@@ -371,7 +367,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);
@@ -403,7 +399,8 @@ fd6_texture_state(struct fd_context *ctx, enum a6xx_state_block sb,
                needs_border |= sampler->needs_border;
        }
 
-       key.bcolor_offset = fd6_border_color_offset(ctx, sb, tex);
+       key.type = type;
+       key.bcolor_offset = fd6_border_color_offset(ctx, type, tex);
 
        uint32_t hash = key_hash(&key);
        struct hash_entry *entry =
@@ -419,8 +416,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,
-                       NULL, NULL, NULL);
+       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