aux/tc: fix address calc for segmented texture subdata
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Tue, 12 Sep 2023 12:49:52 +0000 (08:49 -0400)
committerMarge Bot <emma+marge@anholt.net>
Tue, 12 Sep 2023 13:53:32 +0000 (13:53 +0000)
this fixes all dimension/array uses for the rp tracking path

Fixes: 51ad269198e ("aux/tc: handle stride mismatch during rp-optimized subdata")

Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25180>

src/gallium/auxiliary/util/u_threaded_context.c

index 8006fff..e0f0049 100644 (file)
@@ -3162,10 +3162,9 @@ tc_texture_subdata(struct pipe_context *_pipe,
             tc->base.resource_copy_region(&tc->base, resource, level, box->x, box->y, box->z, pres, 0, &src_box);
          } else {
             /* if stride doesn't match, inline util_copy_box on the GPU and assume the driver will optimize */
-            unsigned src_offset = 0;
             src_box.depth = 1;
-            for (unsigned z = 0; z < box->depth; ++z) {
-               unsigned dst_x = box->x, dst_y = box->y, width = box->width, height = box->height;
+            for (unsigned z = 0; z < box->depth; ++z, src_box.x = z * layer_stride) {
+               unsigned dst_x = box->x, dst_y = box->y, width = box->width, height = box->height, dst_z = box->z + z;
                int blocksize = util_format_get_blocksize(format);
                int blockwidth = util_format_get_blockwidth(format);
                int blockheight = util_format_get_blockheight(format);
@@ -3185,20 +3184,15 @@ tc_texture_subdata(struct pipe_context *_pipe,
                   uint64_t size = (uint64_t)height * width;
 
                   assert(size <= SIZE_MAX);
-                  src_box.x = src_offset;
                   assert(dst_x + src_box.width < u_minify(pres->width0, level));
                   assert(dst_y + src_box.height < u_minify(pres->height0, level));
                   assert(pres->target != PIPE_TEXTURE_3D ||  z + src_box.depth < u_minify(pres->depth0, level));
-                  tc->base.resource_copy_region(&tc->base, resource, level, dst_x, dst_y, z, pres, 0, &src_box);
+                  tc->base.resource_copy_region(&tc->base, resource, level, dst_x, dst_y, dst_z, pres, 0, &src_box);
                } else {
                   src_box.height = 1;
-                  for (unsigned i = 0; i < height; i++, dst_y++) {
-                     src_box.x = src_offset;
-                     tc->base.resource_copy_region(&tc->base, resource, level, dst_x, dst_y, z, pres, 0, &src_box);
-                     src_offset += stride;
-                  }
+                  for (unsigned i = 0; i < height; i++, dst_y++, src_box.x += stride)
+                     tc->base.resource_copy_region(&tc->base, resource, level, dst_x, dst_y, dst_z, pres, 0, &src_box);
                }
-               src_offset += layer_stride;
             }
          }