broadcom/vc5: Lay out MSAA textures/renderbuffers as UIF scaled by 4.
authorEric Anholt <eric@anholt.net>
Wed, 25 Oct 2017 01:45:57 +0000 (18:45 -0700)
committerEric Anholt <eric@anholt.net>
Mon, 30 Oct 2017 20:31:27 +0000 (13:31 -0700)
We just need to multiply width/height by 2 each, and always set them up as
UIF tiling, since that's how the TLB will store them in raw (per-sample)
mode.

src/gallium/drivers/vc5/vc5_resource.c
src/gallium/drivers/vc5/vc5_state.c

index 45f94af034604c861a0094567906cc88bc98b352..e1ed46039a17ec7fe553eb100c50dba6ebc42b11 100644 (file)
@@ -367,7 +367,11 @@ vc5_setup_slices(struct vc5_resource *rsc, const char *caller)
         uint32_t utile_h = vc5_utile_height(rsc->cpp);
         uint32_t uif_block_w = utile_w * 2;
         uint32_t uif_block_h = utile_h * 2;
-        bool uif_top = false;
+        bool msaa = prsc->nr_samples > 1;
+        /* MSAA textures/renderbuffers are always laid out as single-level
+         * UIF.
+         */
+        bool uif_top = prsc->nr_samples > 1;
 
         for (int i = prsc->last_level; i >= 0; i--) {
                 struct vc5_resource_slice *slice = &rsc->slices[i];
@@ -381,13 +385,13 @@ vc5_setup_slices(struct vc5_resource *rsc, const char *caller)
                         level_height = u_minify(pot_height, i);
                 }
 
+                if (msaa) {
+                        level_width *= 2;
+                        level_height *= 2;
+                }
+
                 if (!rsc->tiled) {
                         slice->tiling = VC5_TILING_RASTER;
-                        if (prsc->nr_samples > 1) {
-                                /* MSAA (4x) surfaces are stored as raw tile buffer contents. */
-                                level_width = align(level_width, 32);
-                                level_height = align(level_height, 32);
-                        }
                 } else {
                         if ((i != 0 || !uif_top) &&
                             (level_width <= utile_w ||
@@ -416,8 +420,7 @@ vc5_setup_slices(struct vc5_resource *rsc, const char *caller)
                 }
 
                 slice->offset = offset;
-                slice->stride = (level_width * rsc->cpp *
-                                 MAX2(prsc->nr_samples, 1));
+                slice->stride = level_width * rsc->cpp;
                 slice->size = level_height * slice->stride;
 
                 offset += slice->size;
@@ -482,10 +485,28 @@ vc5_resource_setup(struct pipe_screen *pscreen,
         pipe_reference_init(&prsc->reference, 1);
         prsc->screen = pscreen;
 
-        if (prsc->nr_samples <= 1)
-                rsc->cpp = util_format_get_blocksize(tmpl->format);
-        else
-                rsc->cpp = sizeof(uint32_t);
+        if (prsc->nr_samples <= 1) {
+                rsc->cpp = util_format_get_blocksize(prsc->format);
+        } else {
+                assert(vc5_rt_format_supported(prsc->format));
+                uint32_t output_image_format = vc5_get_rt_format(prsc->format);
+                uint32_t internal_type;
+                uint32_t internal_bpp;
+                vc5_get_internal_type_bpp_for_output_format(output_image_format,
+                                                            &internal_type,
+                                                            &internal_bpp);
+                switch (internal_bpp) {
+                case INTERNAL_BPP_32:
+                        rsc->cpp = 4;
+                        break;
+                case INTERNAL_BPP_64:
+                        rsc->cpp = 8;
+                        break;
+                case INTERNAL_BPP_128:
+                        rsc->cpp = 16;
+                        break;
+                }
+        }
 
         assert(rsc->cpp);
 
index eebf94b4b9cedcd9613f3ffcd87400d9975346d2..817b6247d580dd618a03429c223d2c91643b815b 100644 (file)
@@ -562,11 +562,13 @@ vc5_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *prsc,
         so->base.reference.count = 1;
         so->base.context = pctx;
 
+        int msaa_scale = prsc->nr_samples > 1 ? 2 : 1;
+
         struct V3D33_TEXTURE_SHADER_STATE state_unpacked = {
                 cl_packet_header(TEXTURE_SHADER_STATE),
 
-                .image_width = prsc->width0,
-                .image_height = prsc->height0,
+                .image_width = prsc->width0 * msaa_scale,
+                .image_height = prsc->height0 * msaa_scale,
                 .image_depth = prsc->depth0,
 
                 .texture_type = rsc->tex_format,