freedreno/a3xx: initial texture border-color
authorRob Clark <robclark@freedesktop.org>
Tue, 23 Sep 2014 21:24:27 +0000 (17:24 -0400)
committerRob Clark <robclark@freedesktop.org>
Wed, 24 Sep 2014 22:52:58 +0000 (18:52 -0400)
Still some open questions.. and at any rate, no additional piglit passes
due to various wrap modes that we need to emulate in at least some
cases :-(

But it does fix some mystery page-faults.. So add some comments in the
code where there are things that we need to emulate or do more r/e, and
push as-is.

Signed-off-by: Rob Clark <robclark@freedesktop.org>
src/gallium/drivers/freedreno/a2xx/fd2_draw.c
src/gallium/drivers/freedreno/a3xx/fd3_context.c
src/gallium/drivers/freedreno/a3xx/fd3_context.h
src/gallium/drivers/freedreno/a3xx/fd3_emit.c
src/gallium/drivers/freedreno/a3xx/fd3_texture.c
src/gallium/drivers/freedreno/freedreno_util.h

index 77fbf1af224fada1345ce16649d5879796bb2c27..bc7960a28a5cd2c1449318b9b15f291409c6cbde 100644 (file)
@@ -30,7 +30,6 @@
 #include "util/u_string.h"
 #include "util/u_memory.h"
 #include "util/u_prim.h"
-#include "util/u_pack_color.h"
 
 #include "freedreno_state.h"
 #include "freedreno_resource.h"
@@ -118,14 +117,6 @@ fd2_draw(struct fd_context *ctx, const struct pipe_draw_info *info)
 }
 
 
-static uint32_t
-pack_rgba(enum pipe_format format, const float *rgba)
-{
-       union util_color uc;
-       util_pack_color(rgba, format, &uc);
-       return uc.ui[0];
-}
-
 static void
 fd2_clear(struct fd_context *ctx, unsigned buffers,
                const union pipe_color_union *color, double depth, unsigned stencil)
index 847414ac08270c92a7fd37c6b00f69373cd755b2..f8f412e1a1ba46a12b5307929461c1d481bb7bb1 100644 (file)
@@ -137,5 +137,8 @@ fd3_context_create(struct pipe_screen *pscreen, void *priv)
 
        fd3_query_context_init(pctx);
 
+       fd3_ctx->border_color_uploader = u_upload_create(pctx, 4096,
+                       2 * PIPE_MAX_SAMPLERS * BORDERCOLOR_SIZE, 0);
+
        return pctx;
 }
index 26c8cc762b905a95a070f6743dd3bda115959a65..7d7663a28bcaad3b13142cca0f157242bb01af1f 100644 (file)
@@ -29,6 +29,8 @@
 #ifndef FD3_CONTEXT_H_
 #define FD3_CONTEXT_H_
 
+#include "util/u_upload_mgr.h"
+
 #include "freedreno_drmif.h"
 
 #include "freedreno_context.h"
@@ -56,6 +58,24 @@ struct fd3_context {
        /* vertex buf used for mem->gmem tex coords:
         */
        struct pipe_resource *blit_texcoord_vbuf;
+
+       /*
+        * Border color layout *appears* to be as arrays of 0x40 byte
+        * elements, with frag shader elements starting at (16 x 0x40).
+        * But at some point I should probably experiment more with
+        * samplers in vertex shaders to be sure.  Unclear about why
+        * there is this offset when there are separate VS and FS base
+        * addr regs.
+        *
+        * The first 8 bytes of each entry are the requested border
+        * color in fp16.  Unclear about the rest.. could be used for
+        * other formats, or could simply be for aligning the pitch
+        * to 32 pixels.
+        */
+#define BORDERCOLOR_SIZE 0x40
+
+       struct u_upload_mgr *border_color_uploader;
+       struct pipe_resource *border_color_buf;
 };
 
 static INLINE struct fd3_context *
index 62e02bc6b2dbdf95c64328b82b3dd9f7a95b60b4..73a28dda5e6f1565285d48962225fa4993c2f64e 100644 (file)
@@ -152,9 +152,8 @@ emit_constants(struct fd_ringbuffer *ring,
 #define BASETABLE_SZ    A3XX_MAX_MIP_LEVELS
 
 static void
-emit_textures(struct fd_ringbuffer *ring,
-               enum adreno_state_block sb,
-               struct fd_texture_stateobj *tex)
+emit_textures(struct fd_context *ctx, struct fd_ringbuffer *ring,
+               enum adreno_state_block sb, struct fd_texture_stateobj *tex)
 {
        static const unsigned tex_off[] = {
                        [SB_VERT_TEX] = VERT_TEX_OFF,
@@ -164,7 +163,18 @@ emit_textures(struct fd_ringbuffer *ring,
                        [SB_VERT_TEX] = SB_VERT_MIPADDR,
                        [SB_FRAG_TEX] = SB_FRAG_MIPADDR,
        };
-       unsigned i, j;
+       static const uint32_t bcolor_reg[] = {
+                       [SB_VERT_TEX] = REG_A3XX_TPL1_TP_VS_BORDER_COLOR_BASE_ADDR,
+                       [SB_FRAG_TEX] = REG_A3XX_TPL1_TP_FS_BORDER_COLOR_BASE_ADDR,
+       };
+       struct fd3_context *fd3_ctx = fd3_context(ctx);
+       unsigned i, j, off;
+       void *ptr;
+
+       u_upload_alloc(fd3_ctx->border_color_uploader,
+                       0, 2 * PIPE_MAX_SAMPLERS * BORDERCOLOR_SIZE, &off,
+                       &fd3_ctx->border_color_buf,
+                       &ptr);
 
        if (tex->num_samplers > 0) {
                /* output sampler state: */
@@ -180,6 +190,16 @@ emit_textures(struct fd_ringbuffer *ring,
                        const struct fd3_sampler_stateobj *sampler = tex->samplers[i] ?
                                        fd3_sampler_stateobj(tex->samplers[i]) :
                                        &dummy_sampler;
+                       uint16_t *bcolor = (uint16_t *)((uint8_t *)ptr +
+                                       (BORDERCOLOR_SIZE * tex_off[sb]) +
+                                       (BORDERCOLOR_SIZE * i));
+
+                       /* TODO not quite sure if bcolor is pre or post swizzle: */
+                       for (j = 0; j < 4; j++) {
+                               bcolor[j] =
+                                       util_float_to_half(sampler->base.border_color.f[j]);
+                       }
+
                        OUT_RING(ring, sampler->texsamp0);
                        OUT_RING(ring, sampler->texsamp1);
                }
@@ -237,6 +257,11 @@ emit_textures(struct fd_ringbuffer *ring,
                        }
                }
        }
+
+       OUT_PKT0(ring, bcolor_reg[sb], 1);
+       OUT_RELOC(ring, fd_resource(fd3_ctx->border_color_buf)->bo, off, 0, 0);
+
+       u_upload_unmap(fd3_ctx->border_color_uploader);
 }
 
 /* emit texture state for mem->gmem restore operation.. eventually it would
@@ -553,14 +578,14 @@ fd3_emit_state(struct fd_context *ctx, struct fd_ringbuffer *ring,
 
        if (dirty & FD_DIRTY_VERTTEX) {
                if (vp->has_samp)
-                       emit_textures(ring, SB_VERT_TEX, &ctx->verttex);
+                       emit_textures(ctx, ring, SB_VERT_TEX, &ctx->verttex);
                else
                        dirty &= ~FD_DIRTY_VERTTEX;
        }
 
        if (dirty & FD_DIRTY_FRAGTEX) {
                if (fp->has_samp)
-                       emit_textures(ring, SB_FRAG_TEX, &ctx->fragtex);
+                       emit_textures(ctx, ring, SB_FRAG_TEX, &ctx->fragtex);
                else
                        dirty &= ~FD_DIRTY_FRAGTEX;
        }
index 36a877dcd927f9c5c2a58e8e14486ee921c5819f..8308674178d83ad1de967ab562ae2ca98b0aba51 100644 (file)
@@ -54,7 +54,9 @@ tex_clamp(unsigned wrap)
                return A3XX_TEX_CLAMP_TO_BORDER;
        case PIPE_TEX_WRAP_MIRROR_CLAMP:
        case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
+               /* these two we should emulate! */
        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;
index d676f80d71bbba212638c8e7482b60caaf74c784..a762c8f05755723c5ed4e546fc8ad60c29903cee 100644 (file)
@@ -38,6 +38,7 @@
 #include "util/u_math.h"
 #include "util/u_half.h"
 #include "util/u_dynarray.h"
+#include "util/u_pack_color.h"
 
 #include "adreno_common.xml.h"
 #include "adreno_pm4.xml.h"
@@ -250,4 +251,12 @@ static inline uint32_t env2u(const char *envvar)
        return 0;
 }
 
+static inline uint32_t
+pack_rgba(enum pipe_format format, const float *rgba)
+{
+       union util_color uc;
+       util_pack_color(rgba, format, &uc);
+       return uc.ui[0];
+}
+
 #endif /* FREEDRENO_UTIL_H_ */