panfrost: RGBA4 and RGB5_A1 framebuffer support
[mesa.git] / src / gallium / drivers / panfrost / pan_mfbd.c
index 2212f6a301fcf60f8115028c2304dc6343f4f336..41f21128198fe36624417877d772f43a8e87dea8 100644 (file)
@@ -31,9 +31,6 @@
 static struct mali_rt_format
 panfrost_mfbd_format(struct pipe_surface *surf)
 {
-        struct panfrost_device *dev = pan_device(surf->context->screen);
-        bool is_bifrost = dev->quirks & IS_BIFROST;
-
         /* Explode details on the format */
 
         const struct util_format_description *desc =
@@ -51,7 +48,6 @@ panfrost_mfbd_format(struct pipe_surface *surf)
                 .unk2 = 0x1,
                 .nr_channels = MALI_POSITIVE(desc->nr_channels),
                 .unk3 = 0x4,
-                .unk4 = is_bifrost,
                 .flags = 0x8,
                 .swizzle = panfrost_translate_swizzle_4(swizzle),
                 .no_preload = true
@@ -78,6 +74,7 @@ panfrost_mfbd_format(struct pipe_surface *surf)
 
         case PIPE_FORMAT_A4B4G4R4_UNORM:
         case PIPE_FORMAT_B4G4R4A4_UNORM:
+        case PIPE_FORMAT_R4G4B4A4_UNORM:
                 fmt.unk1 = 0x10000000;
                 fmt.unk3 = 0x5;
                 fmt.nr_channels = MALI_POSITIVE(1);
@@ -93,6 +90,7 @@ panfrost_mfbd_format(struct pipe_surface *surf)
                 break;
 
         case PIPE_FORMAT_B5G5R5A1_UNORM:
+        case PIPE_FORMAT_R5G5B5A1_UNORM:
         case PIPE_FORMAT_B5G5R5X1_UNORM:
                 fmt.unk1 = 0x18000000;
                 fmt.unk3 = 0x7;
@@ -205,6 +203,8 @@ panfrost_mfbd_set_cbuf(
         struct pipe_surface *surf)
 {
         struct panfrost_resource *rsrc = pan_resource(surf->texture);
+        struct panfrost_device *dev = pan_device(surf->context->screen);
+        bool is_bifrost = dev->quirks & IS_BIFROST;
 
         unsigned level = surf->u.tex.level;
         unsigned first_layer = surf->u.tex.first_layer;
@@ -218,11 +218,21 @@ panfrost_mfbd_set_cbuf(
         /* Now, we set the layout specific pieces */
 
         if (rsrc->layout == MALI_TEXTURE_LINEAR) {
-                rt->format.block = MALI_BLOCK_LINEAR;
+                if (is_bifrost) {
+                        rt->format.unk4 = 0x1;
+                } else {
+                        rt->format.block = MALI_BLOCK_LINEAR;
+                }
+
                 rt->framebuffer = base;
                 rt->framebuffer_stride = stride / 16;
         } else if (rsrc->layout == MALI_TEXTURE_TILED) {
-                rt->format.block = MALI_BLOCK_TILED;
+                if (is_bifrost) {
+                        rt->format.unk3 |= 0x8;
+                } else {
+                        rt->format.block = MALI_BLOCK_TILED;
+                }
+
                 rt->framebuffer = base;
                 rt->framebuffer_stride = stride;
         } else if (rsrc->layout == MALI_TEXTURE_AFBC) {
@@ -233,7 +243,13 @@ panfrost_mfbd_set_cbuf(
                 rt->framebuffer = base + header_size;
                 rt->afbc.metadata = base;
                 rt->afbc.stride = 0;
-                rt->afbc.unk = 0x30009;
+                rt->afbc.flags = MALI_AFBC_FLAGS;
+
+                unsigned components = util_format_get_nr_components(surf->format);
+
+                /* The "lossless colorspace transform" is lossy for R and RG formats */
+                if (components >= 3)
+                   rt->afbc.flags |= MALI_AFBC_YTR;
 
                 /* TODO: The blob sets this to something nonzero, but it's not
                  * clear what/how to calculate/if it matters */
@@ -277,7 +293,7 @@ panfrost_mfbd_set_zsbuf(
                 fbx->ds_afbc.depth_stencil_afbc_metadata = base;
                 fbx->ds_afbc.depth_stencil_afbc_stride = 0;
 
-                fbx->ds_afbc.zero1 = 0x10009;
+                fbx->ds_afbc.flags = MALI_AFBC_FLAGS;
                 fbx->ds_afbc.padding = 0x1000;
         } else if (rsrc->layout == MALI_TEXTURE_LINEAR || rsrc->layout == MALI_TEXTURE_TILED) {
                 /* TODO: Z32F(S8) support, which is always linear */
@@ -382,6 +398,25 @@ panfrost_mfbd_upload(struct panfrost_batch *batch,
 
 #undef UPLOAD
 
+/* Determines whether a framebuffer uses too much tilebuffer space (requiring
+ * us to scale up the tile at a performance penalty). This is conservative but
+ * afaict you get 128-bits per pixel normally */
+
+static bool
+pan_is_large_tib(struct panfrost_batch *batch)
+{
+        unsigned size = 0;
+
+        for (int cb = 0; cb < batch->key.nr_cbufs; ++cb) {
+                struct pipe_surface *surf = batch->key.cbufs[cb];
+                assert(surf);
+                unsigned bpp = util_format_get_blocksize(surf->format);
+                size += ALIGN_POT(bpp, 4);
+        }
+
+        return (size > 16);
+}
+
 static struct mali_framebuffer
 panfrost_emit_mfbd(struct panfrost_batch *batch, unsigned vertex_count)
 {
@@ -398,7 +433,8 @@ panfrost_emit_mfbd(struct panfrost_batch *batch, unsigned vertex_count)
                 .width2 = MALI_POSITIVE(width),
                 .height2 = MALI_POSITIVE(height),
 
-                .unk1 = 0x1080,
+                /* Seems to configure tib size */
+                .unk1 = pan_is_large_tib(batch) ? 0xc80 : 0x1080,
 
                 .rt_count_1 = MALI_POSITIVE(batch->key.nr_cbufs),
                 .rt_count_2 = 4,
@@ -529,7 +565,7 @@ panfrost_mfbd_fragment(struct panfrost_batch *batch, bool has_draws)
                         struct panfrost_slice *slice = &rsrc->slices[level];
 
                         fb.mfbd_flags |= MALI_MFBD_EXTRA;
-                        fbx.flags_lo |= MALI_EXTRA_PRESENT;
+                        fbx.flags_hi |= MALI_EXTRA_PRESENT;
                         fbx.checksum_stride = slice->checksum_stride;
                         if (slice->checksum_bo)
                                 fbx.checksum = slice->checksum_bo->gpu;