st/pbo_compute: fix z coords for compute pbos
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Thu, 26 May 2022 18:19:15 +0000 (14:19 -0400)
committerMarge Bot <emma+marge@anholt.net>
Tue, 31 May 2022 20:05:49 +0000 (20:05 +0000)
without manually taking the value from the global_id vec, this will
end up being offset.y again, which breaks z-indexing

Fixes: e7b95619596 ("gallium: implement compute pbo download")

Reviewed-by: Jason Ekstrand <jason.ekstrand@collabora.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16728>

src/mesa/state_tracker/st_pbo_compute.c

index a52233f..ade0143 100644 (file)
@@ -620,10 +620,19 @@ create_conversion_shader(struct st_context *st, enum pipe_texture_target target,
    nir_ssa_def *iid = nir_load_local_invocation_id(&b);
    nir_ssa_def *tile = nir_imul(&b, wid, bsize);
    nir_ssa_def *global_id = nir_iadd(&b, tile, iid);
-   nir_ssa_def *start = nir_iadd(&b, global_id, sd.offset);
-
-   nir_ssa_def *coord = nir_channels(&b, start, (1<<coord_components)-1);
-   nir_ssa_def *max = nir_iadd(&b, sd.offset, sd.range);
+   nir_ssa_def *start = nir_iadd(&b, nir_trim_vector(&b, global_id, 2), sd.offset);
+
+   nir_ssa_def *coord;
+   if (coord_components < 3)
+      coord = start;
+   else {
+      /* pad offset vec with global_id to get correct z offset */
+      assert(coord_components == 3);
+      coord = nir_vec3(&b, nir_channel(&b, start, 0),
+                           nir_channel(&b, start, 1),
+                           nir_channel(&b, global_id, 2));
+   }
+   nir_ssa_def *max = nir_iadd(&b, nir_pad_vector_imm_int(&b, sd.offset, 0, 3), sd.range);
    nir_push_if(&b, nir_ball(&b, nir_ilt(&b, coord, nir_trim_vector(&b, max, coord_components))));
    nir_tex_instr *txf = nir_tex_instr_create(b.shader, 3);
    txf->is_array = glsl_sampler_type_is_array(sampler->type);