freedreno/a4xx: use hardware RGTC texture samplers
authorIlia Mirkin <imirkin@alum.mit.edu>
Fri, 20 Nov 2015 23:34:03 +0000 (18:34 -0500)
committerIlia Mirkin <imirkin@alum.mit.edu>
Sat, 21 Nov 2015 00:46:21 +0000 (19:46 -0500)
a4xx hardware has real support for RGTC so there's no need to fake it
like we do on a3xx. Undo the hacks, and keep track of an "internal
format" of a resource, which on a3xx will be different, triggering the
transfer-time conversions to take place.

Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
src/gallium/drivers/freedreno/a4xx/a4xx.xml.h
src/gallium/drivers/freedreno/a4xx/fd4_format.c
src/gallium/drivers/freedreno/a4xx/fd4_format.h
src/gallium/drivers/freedreno/a4xx/fd4_texture.c
src/gallium/drivers/freedreno/freedreno_resource.c
src/gallium/drivers/freedreno/freedreno_resource.h

index e46a11e94fe5fc350903b0824b4830a1b32228cd..4436697aad4ba14d1cbe0d47dcf1258367f6ab2c 100644 (file)
@@ -207,6 +207,10 @@ enum a4xx_tex_fmt {
        TFMT4_DXT1 = 86,
        TFMT4_DXT3 = 87,
        TFMT4_DXT5 = 88,
+       TFMT4_RGTC1_UNORM = 90,
+       TFMT4_RGTC1_SNORM = 91,
+       TFMT4_RGTC2_UNORM = 94,
+       TFMT4_RGTC2_SNORM = 95,
        TFMT4_BPTC_UFLOAT = 97,
        TFMT4_BPTC_FLOAT = 98,
        TFMT4_BPTC = 99,
index d2a1aee68d312ded42ceaec9b533e0bcb97b9501..a97e01aa6c220e63459c078aaab78db7d5a7dcb2 100644 (file)
@@ -291,15 +291,14 @@ static struct fd4_format formats[PIPE_FORMAT_COUNT] = {
        _T(BPTC_RGB_FLOAT,  BPTC_FLOAT,  NONE, WZYX),
        _T(BPTC_RGB_UFLOAT, BPTC_UFLOAT, NONE, WZYX),
 
-       /* faked */
-       _T(RGTC1_UNORM, 8_8_8_8_UNORM, NONE, WZYX),
-       _T(RGTC1_SNORM, 8_8_8_8_SNORM, NONE, WZYX),
-       _T(RGTC2_UNORM, 8_8_8_8_UNORM, NONE, WZYX),
-       _T(RGTC2_SNORM, 8_8_8_8_SNORM, NONE, WZYX),
-       _T(LATC1_UNORM, 8_8_8_8_UNORM, NONE, WZYX),
-       _T(LATC1_SNORM, 8_8_8_8_SNORM, NONE, WZYX),
-       _T(LATC2_UNORM, 8_8_8_8_UNORM, NONE, WZYX),
-       _T(LATC2_SNORM, 8_8_8_8_SNORM, NONE, WZYX),
+       _T(RGTC1_UNORM, RGTC1_UNORM, NONE, WZYX),
+       _T(RGTC1_SNORM, RGTC1_SNORM, NONE, WZYX),
+       _T(RGTC2_UNORM, RGTC2_UNORM, NONE, WZYX),
+       _T(RGTC2_SNORM, RGTC2_SNORM, NONE, WZYX),
+       _T(LATC1_UNORM, RGTC1_UNORM, NONE, WZYX),
+       _T(LATC1_SNORM, RGTC1_SNORM, NONE, WZYX),
+       _T(LATC2_UNORM, RGTC2_UNORM, NONE, WZYX),
+       _T(LATC2_SNORM, RGTC2_SNORM, NONE, WZYX),
 };
 
 /* convert pipe format to vertex buffer format: */
@@ -342,8 +341,6 @@ fd4_pipe2fetchsize(enum pipe_format format)
 {
        if (format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT)
                format = PIPE_FORMAT_Z32_FLOAT;
-       else if (util_format_description(format)->layout == UTIL_FORMAT_LAYOUT_RGTC)
-               format = PIPE_FORMAT_R8G8B8A8_UNORM;
 
        switch (util_format_get_blocksizebits(format) / util_format_get_blockwidth(format)) {
        case 8:   return TFETCH4_1_BYTE;
@@ -359,14 +356,6 @@ fd4_pipe2fetchsize(enum pipe_format format)
        }
 }
 
-unsigned
-fd4_pipe2nblocksx(enum pipe_format format, unsigned width)
-{
-       if (util_format_description(format)->layout == UTIL_FORMAT_LAYOUT_RGTC)
-               format = PIPE_FORMAT_R8G8B8A8_UNORM;
-       return util_format_get_nblocksx(format, width);
-}
-
 /* we need to special case a bit the depth/stencil restore, because we are
  * using the texture sampler to blit into the depth/stencil buffer, *not*
  * into a color buffer.  Otherwise fd4_tex_swiz() will do the wrong thing,
index 8c365f081de6e2181c492ff03e58b89f04809eec..04837da650b0f7f6cc625279f0e10337e5d652ac 100644 (file)
@@ -38,7 +38,6 @@ enum a4xx_tex_fmt fd4_pipe2tex(enum pipe_format format);
 enum a4xx_color_fmt fd4_pipe2color(enum pipe_format format);
 enum pipe_format fd4_gmem_restore_format(enum pipe_format format);
 enum a3xx_color_swap fd4_pipe2swap(enum pipe_format format);
-unsigned fd4_pipe2nblocksx(enum pipe_format format, unsigned width);
 enum a4xx_tex_fetchsize fd4_pipe2fetchsize(enum pipe_format format);
 enum a4xx_depth_format fd4_pipe2depth(enum pipe_format format);
 
index 00c257b78e593d4975ceeea6394d55d37fa959cc..75b083b8ca0899ee9fd40d58a8744723f0bf8262 100644 (file)
@@ -240,7 +240,7 @@ fd4_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
        so->texconst2 =
                A4XX_TEX_CONST_2_FETCHSIZE(fd4_pipe2fetchsize(cso->format)) |
                A4XX_TEX_CONST_2_PITCH(
-                       fd4_pipe2nblocksx(
+                       util_format_get_nblocksx(
                                cso->format, rsc->slices[lvl].pitch) * rsc->cpp);
 
        switch (prsc->target) {
index 5b1cee8d18d17ca9d58abba2e30322616fc77e50..43b818f401407ebce0570ddd775af8c9036e4317 100644 (file)
@@ -388,7 +388,8 @@ fd_resource_transfer_map(struct pipe_context *pctx,
 
                buf = trans->staging;
                offset = 0;
-       } else if (util_format_description(format)->layout == UTIL_FORMAT_LAYOUT_RGTC) {
+       } else if (rsc->internal_format != format &&
+                          util_format_description(format)->layout == UTIL_FORMAT_LAYOUT_RGTC) {
                assert(trans->base.box.depth == 1);
 
                trans->base.stride = util_format_get_stride(
@@ -574,9 +575,10 @@ fd_resource_create(struct pipe_screen *pscreen,
 
        if (format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT)
                format = PIPE_FORMAT_Z32_FLOAT;
-       else if (util_format_description(format)->layout ==
-                        UTIL_FORMAT_LAYOUT_RGTC)
+       else if (fd_screen(pscreen)->gpu_id < 400 &&
+                        util_format_description(format)->layout == UTIL_FORMAT_LAYOUT_RGTC)
                format = PIPE_FORMAT_R8G8B8A8_UNORM;
+       rsc->internal_format = format;
        rsc->cpp = util_format_get_blocksize(format);
 
        assert(rsc->cpp);
index 10f5242da57a403dbb8306c7be646b7b3e06c3fb..9a9b0d08244a8905d0fbd61fd93b48d1f55b84c9 100644 (file)
@@ -73,6 +73,7 @@ struct fd_resource {
        struct u_resource base;
        struct fd_bo *bo;
        uint32_t cpp;
+       enum pipe_format internal_format;
        bool layer_first;        /* see above description */
        uint32_t layer_size;
        struct fd_resource_slice slices[MAX_MIP_LEVELS];