freedreno: fix layout pitchalign field not being set for imported buffers
authorJonathan Marek <jonathan@marek.ca>
Sat, 11 Jul 2020 17:49:51 +0000 (13:49 -0400)
committerJonathan Marek <jonathan@marek.ca>
Sat, 11 Jul 2020 17:53:13 +0000 (13:53 -0400)
The pitchalign value was being left to 0 and then wrapping around when
the base offset was subtracted in texture state.

Fixes: 979e7e3680792 ("freedreno/layout: layout simplifications and pitch from level 0 pitch")
Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5864>

src/gallium/drivers/freedreno/freedreno_resource.c

index fb5bb532e57d9039ac05f9762502930f3d68e771..07baa7d293b16f8bc7e4b5fc9dc6ab39838d9331 100644 (file)
@@ -1027,16 +1027,23 @@ fd_resource_from_handle(struct pipe_screen *pscreen,
        slice->offset = handle->offset;
        slice->size0 = handle->stride * prsc->height0;
 
-       uint32_t pitchalign = fd_screen(pscreen)->gmem_alignw * rsc->layout.cpp;
-
-       /* pitchalign is 64-bytes for linear formats on a6xx
-        * layout_resource_for_modifier will validate tiled pitch
+       /* use a pitchalign of gmem_alignw pixels, because GMEM resolve for
+        * lower alignments is not implemented (but possible for a6xx at least)
+        *
+        * for UBWC-enabled resources, layout_resource_for_modifier will further
+        * validate the pitch and set the right pitchalign
         */
-       if (is_a6xx(screen))
-               pitchalign = 64;
+       rsc->layout.pitchalign =
+               fdl_cpp_shift(&rsc->layout) + util_logbase2(screen->gmem_alignw);
+
+       /* apply the minimum pitchalign (note: actually 4 for a3xx but doesn't matter) */
+       if (is_a6xx(screen) || is_a5xx(screen))
+               rsc->layout.pitchalign = MAX2(rsc->layout.pitchalign, 6);
+       else
+               rsc->layout.pitchalign = MAX2(rsc->layout.pitchalign, 5);
 
-       if ((rsc->layout.pitch0 < align(prsc->width0 * rsc->layout.cpp, pitchalign)) ||
-                       (rsc->layout.pitch0 & (pitchalign - 1)))
+       if (rsc->layout.pitch0 < (prsc->width0 * rsc->layout.cpp) ||
+               fd_resource_pitch(rsc, 0) != rsc->layout.pitch0)
                goto fail;
 
        assert(rsc->layout.cpp);