vc4: Add miptree/texture state support for ETC1 compressed textures.
authorEric Anholt <eric@anholt.net>
Tue, 6 Jan 2015 21:35:21 +0000 (13:35 -0800)
committerEric Anholt <eric@anholt.net>
Fri, 4 Nov 2016 01:42:58 +0000 (18:42 -0700)
The format isn't flagged as enabled at runtime yet, because we need kernel
validation support.

src/gallium/drivers/vc4/kernel/vc4_validate.c
src/gallium/drivers/vc4/vc4_formats.c
src/gallium/drivers/vc4/vc4_resource.c
src/gallium/drivers/vc4/vc4_screen.c
src/gallium/drivers/vc4/vc4_state.c

index 4ef01108b797886c9ddd4b8e694ba29c0451d567..a9dce1fa3796c79d6cebb002702fdcb36aa09b5f 100644 (file)
@@ -640,6 +640,13 @@ reloc_tex(struct vc4_exec_info *exec,
                cpp = 1;
                break;
        case VC4_TEXTURE_TYPE_ETC1:
+               /* ETC1 is arranged as 64-bit blocks, where each block is 4x4
+                * pixels.
+                */
+               cpp = 8;
+               width = (width + 3) >> 2;
+               height = (height + 3) >> 2;
+               break;
        case VC4_TEXTURE_TYPE_BW1:
        case VC4_TEXTURE_TYPE_A4:
        case VC4_TEXTURE_TYPE_A1:
index dd700cdec7d7f5a9b9ac6afabb5fb5faa378fed8..42cdad115b2786646bf5dfd7950229e207a09701 100644 (file)
@@ -83,6 +83,8 @@ static const struct vc4_format vc4_format_table[] = {
 
         FORMAT(B5G6R5_UNORM, RGB565, RGB565, SWIZ(X, Y, Z, 1)),
 
+        FORMAT(ETC1_RGB8, NO, ETC1, SWIZ(X, Y, Z, 1)),
+
         /* Depth sampling will be handled by doing nearest filtering and not
          * unpacking the RGBA value.
          */
index 704cd71ea4b4ab168139bdab3f5f39998ffc4b39..e4784ff86e2ebe94e00035344cdbd2a8ff41e211 100644 (file)
@@ -283,6 +283,20 @@ vc4_resource_transfer_map(struct pipe_context *pctx,
                 if (usage & PIPE_TRANSFER_MAP_DIRECTLY)
                         return NULL;
 
+                if (format == PIPE_FORMAT_ETC1_RGB8) {
+                        /* ETC1 is arranged as 64-bit blocks, where each block
+                         * is 4x4 pixels.  Texture tiling operates on the
+                         * 64-bit block the way it would an uncompressed
+                         * pixels.
+                         */
+                        assert(!(ptrans->box.x & 3));
+                        assert(!(ptrans->box.y & 3));
+                        ptrans->box.x >>= 2;
+                        ptrans->box.y >>= 2;
+                        ptrans->box.width = (ptrans->box.width + 3) >> 2;
+                        ptrans->box.height = (ptrans->box.height + 3) >> 2;
+                }
+
                 /* We need to align the box to utile boundaries, since that's
                  * what load/store operates on.  This may cause us to need to
                  * read out the original contents in that border area.  Right
@@ -387,6 +401,11 @@ vc4_setup_slices(struct vc4_resource *rsc)
         struct pipe_resource *prsc = &rsc->base.b;
         uint32_t width = prsc->width0;
         uint32_t height = prsc->height0;
+        if (prsc->format == PIPE_FORMAT_ETC1_RGB8) {
+                width = (width + 3) >> 2;
+                height = (height + 3) >> 2;
+        }
+
         uint32_t pot_width = util_next_power_of_two(width);
         uint32_t pot_height = util_next_power_of_two(height);
         uint32_t offset = 0;
index 0f9ba541aab28721fb0df578d8d20aa7311bc354..9aa80cab873f52b60c58b1c1759fcf55cdab4d86 100644 (file)
@@ -486,7 +486,8 @@ vc4_screen_is_format_supported(struct pipe_screen *pscreen,
         }
 
         if ((usage & PIPE_BIND_SAMPLER_VIEW) &&
-            vc4_tex_format_supported(format)) {
+            vc4_tex_format_supported(format) &&
+            format != PIPE_FORMAT_ETC1_RGB8) {
                 retval |= PIPE_BIND_SAMPLER_VIEW;
         }
 
index 12471589510d221ae532d5db4f2b68f588454bb3..5403c34af96b2bafcdc26798cf712ad543bdf285 100644 (file)
@@ -615,6 +615,9 @@ vc4_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *prsc,
                  VC4_SET_FIELD(prsc->height0 & 2047, VC4_TEX_P1_HEIGHT) |
                  VC4_SET_FIELD(prsc->width0 & 2047, VC4_TEX_P1_WIDTH));
 
+        if (prsc->format == PIPE_FORMAT_ETC1_RGB8)
+                so->texture_p1 |= VC4_TEX_P1_ETCFLIP_MASK;
+
         return &so->base;
 }