ac/surface: adapt surf_size when modifying surf_pitch
authorPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Thu, 9 Jul 2020 12:10:51 +0000 (14:10 +0200)
committerMarge Bot <eric+marge@anholt.net>
Mon, 20 Jul 2020 10:32:44 +0000 (10:32 +0000)
Otherwise we might get VM_L2_PROTECTION_FAULT_STATUS errors.

Fixes: 8275dc1ed57 ("ac/surface: fix epitch when modifying surf_pitch")
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5841>

src/amd/common/ac_surface.c

index 41fb152d5a917dd299a5a5a0c5c78b7f5028832b..461fd503622fa974062247440e43052556a2d9a7 100644 (file)
@@ -1464,18 +1464,27 @@ static int gfx9_compute_miptree(struct ac_addrlib *addrlib,
 
        surf->u.gfx9.surf_slice_size = out.sliceSize;
        surf->u.gfx9.surf_pitch = out.pitch;
+       surf->u.gfx9.surf_height = out.height;
+       surf->surf_size = out.surfSize;
+       surf->surf_alignment = out.baseAlign;
+
        if (!compressed && surf->blk_w > 1 && out.pitch == out.pixelPitch &&
            surf->u.gfx9.surf.swizzle_mode == ADDR_SW_LINEAR) {
-               /* Adjust surf_pitch to be in elements units,
-                * not in pixels */
+               /* Adjust surf_pitch to be in elements units not in pixels */
                surf->u.gfx9.surf_pitch =
                        align(surf->u.gfx9.surf_pitch / surf->blk_w, 256 / surf->bpe);
                surf->u.gfx9.surf.epitch = MAX2(surf->u.gfx9.surf.epitch,
                                                surf->u.gfx9.surf_pitch * surf->blk_w - 1);
+               /* The surface is really a surf->bpe bytes per pixel surface even if we
+                * use it as a surf->bpe bytes per element one.
+                * Adjust surf_slice_size and surf_size to reflect the change
+                * made to surf_pitch.
+                */
+               surf->u.gfx9.surf_slice_size = MAX2(
+                       surf->u.gfx9.surf_slice_size,
+                       surf->u.gfx9.surf_pitch * out.height * surf->bpe * surf->blk_w);
+               surf->surf_size = surf->u.gfx9.surf_slice_size * in->numSlices;
        }
-       surf->u.gfx9.surf_height = out.height;
-       surf->surf_size = out.surfSize;
-       surf->surf_alignment = out.baseAlign;
 
        if (in->swizzleMode == ADDR_SW_LINEAR) {
                for (unsigned i = 0; i < in->numMipLevels; i++) {