freedreno: Introduce a "cpp_shift" value for cpp divs/muls.
authorEric Anholt <eric@anholt.net>
Tue, 14 Apr 2020 21:35:05 +0000 (14:35 -0700)
committerMarge Bot <eric+marge@anholt.net>
Thu, 23 Apr 2020 16:37:50 +0000 (16:37 +0000)
This only converts part of the driver to use it, leaving the rest to the
following commit (which inspired this one).

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4558>

src/freedreno/fdl/fd6_layout.c
src/freedreno/fdl/freedreno_layout.c
src/freedreno/fdl/freedreno_layout.h
src/gallium/drivers/freedreno/a3xx/fd3_gmem.c
src/gallium/drivers/freedreno/a4xx/fd4_gmem.c
src/gallium/drivers/freedreno/a5xx/fd5_gmem.c
src/gallium/drivers/freedreno/freedreno_resource.c

index 3d4efb1d0a81f76b53bfa9de9295aee8c1e034be..0f8f14dfc2dd48cfc2b751878f4955bc773bdd4a 100644 (file)
@@ -93,6 +93,8 @@ fdl6_layout(struct fdl_layout *layout,
 
        layout->cpp = util_format_get_blocksize(format);
        layout->cpp *= nr_samples;
+       layout->cpp_shift = ffs(layout->cpp) - 1;
+
        layout->format = format;
        layout->nr_samples = nr_samples;
        layout->layer_first = !is_3d;
index 57f6388b69a9360bbf538a52b633cf10f7b55461..0c50608ff156b7530cb31b0b70d630fb3d20efb7 100644 (file)
@@ -36,6 +36,7 @@ fdl_layout_buffer(struct fdl_layout *layout, uint32_t size)
        layout->height0 = 1;
        layout->depth0 = 1;
        layout->cpp = 1;
+       layout->cpp_shift = 0;
        layout->size = size;
        layout->format = PIPE_FORMAT_R8_UINT;
        layout->nr_samples = 1;
index e9bc3bdb371dae91b9bde00725304e2fa29aa7bf..aa46859a2c30ef873d4f96d1401ea6e049fffb5c 100644 (file)
@@ -109,6 +109,12 @@ struct fdl_layout {
         */
        uint8_t cpp;
 
+       /**
+        * Left shift necessary to multiply by cpp.  Invalid for NPOT cpp, please
+        * use fdl_cpp_shift() to sanity check you aren't hitting that case.
+        */
+       uint8_t cpp_shift;
+
        uint32_t width0, height0, depth0;
        uint32_t nr_samples;
        enum pipe_format format;
@@ -117,6 +123,13 @@ struct fdl_layout {
        uint32_t base_align; /* Alignment of the base address, in bytes. */
 };
 
+static inline uint32_t
+fdl_cpp_shift(const struct fdl_layout *layout)
+{
+       assert(util_is_power_of_two_or_zero(layout->cpp));
+       return layout->cpp_shift;
+}
+
 static inline uint32_t
 fdl_layer_stride(const struct fdl_layout *layout, unsigned level)
 {
index 90c8b8bd49f54bcecf3bde44994e3bdcfa5470e9..ff9f4357368527e66483aa24229feed1f8910923 100644 (file)
@@ -94,7 +94,7 @@ emit_mrt(struct fd_ringbuffer *ring, unsigned nr_bufs,
                        swap = rsc->layout.tile_mode ? WZYX : fd3_pipe2swap(pformat);
 
                        if (bin_w) {
-                               stride = bin_w * rsc->layout.cpp;
+                               stride = bin_w << fdl_cpp_shift(&rsc->layout);
 
                                if (bases) {
                                        base = bases[i];
@@ -1009,11 +1009,13 @@ fd3_emit_tile_renderprep(struct fd_batch *batch, const struct fd_tile *tile)
        OUT_RING(ring, reg);
        if (pfb->zsbuf) {
                struct fd_resource *rsc = fd_resource(pfb->zsbuf->texture);
-               OUT_RING(ring, A3XX_RB_DEPTH_PITCH(rsc->layout.cpp * gmem->bin_w));
+               OUT_RING(ring, A3XX_RB_DEPTH_PITCH(gmem->bin_w <<
+                                               fdl_cpp_shift(&rsc->layout)));
                if (rsc->stencil) {
                        OUT_PKT0(ring, REG_A3XX_RB_STENCIL_INFO, 2);
                        OUT_RING(ring, A3XX_RB_STENCIL_INFO_STENCIL_BASE(gmem->zsbuf_base[1]));
-                       OUT_RING(ring, A3XX_RB_STENCIL_PITCH(rsc->stencil->layout.cpp * gmem->bin_w));
+                       OUT_RING(ring, A3XX_RB_STENCIL_PITCH(gmem->bin_w <<
+                                                       fdl_cpp_shift(&rsc->stencil->layout)));
                }
        } else {
                OUT_RING(ring, 0x00000000);
index 16e2ac0fbad19468ebd6e346c6032f878f6e55e0..5f565e08d656c3a8f0db7bfd1f7c27b019ae078b 100644 (file)
@@ -97,7 +97,7 @@ emit_mrt(struct fd_ringbuffer *ring, unsigned nr_bufs,
                                        psurf->u.tex.first_layer);
 
                        if (bin_w) {
-                               stride = bin_w * rsc->layout.cpp;
+                               stride = bin_w << fdl_cpp_shift(&rsc->layout);
 
                                if (bases) {
                                        base = bases[i];
index c6564669e468201932e4ed8b284fc4b765f35dfa..eb8b5404e8605fcef61c6e3ba4b1c00d8a109aa4 100644 (file)
@@ -498,7 +498,7 @@ emit_mem2gmem_surf(struct fd_batch *batch, uint32_t base,
                buf = BLIT_MRT0;
        }
 
-       stride = gmem->bin_w * rsc->layout.cpp;
+       stride = gmem->bin_w << fdl_cpp_shift(&rsc->layout);
        size = stride * gmem->bin_h;
 
        OUT_PKT4(ring, REG_A5XX_RB_BLIT_FLAG_DST_LO, 4);
index e7bf3d9ee9b59edbfe54040c857087cd15381925..7c61fb72911f75dea10a0c56a49a5523157ba0a0 100644 (file)
@@ -886,6 +886,7 @@ fd_resource_layout_init(struct pipe_resource *prsc)
 
        layout->cpp = util_format_get_blocksize(prsc->format);
        layout->cpp *= fd_resource_nr_samples(prsc);
+       layout->cpp_shift = ffs(layout->cpp) - 1;
 }
 
 /**