st/pbo: set layer coord for array textures

Even for drivers not supporting layers, we need to include the layer
coordinate (zero in this case) when using array textures in the
download/upload FS.

Otherwise we are missing a component to get the texture, which ends up
in a malformed NIR shader.

v5 (Ilia):
 - Do not emit needless layer code.

v6 (Ilia):
 - Add comment clarifying the code logic behind.

Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com>
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Reviewed-by: Ilia Mirkin <imirkin@alum.mit.edu>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13409>
This commit is contained in:
Juan A. Suarez Romero
2021-10-14 18:40:13 +02:00
committed by Marge Bot
parent fd47c939f4
commit 5cd161164b

View File

@@ -437,13 +437,19 @@ create_fs(struct st_context *st, bool download,
: VARYING_SLOT_POS;
nir_ssa_def *coord = nir_load_var(&b, fragcoord);
/* When st->pbo.layers == false, it is guaranteed we only have a single
* layer. But we still need the "layer" variable to add the "array"
* coordinate to the texture. Hence we set layer to zero when array texture
* is used in case only a single layer is required.
*/
nir_ssa_def *layer = NULL;
if (st->pbo.layers && (!download || target == PIPE_TEXTURE_1D_ARRAY ||
target == PIPE_TEXTURE_2D_ARRAY ||
target == PIPE_TEXTURE_3D ||
target == PIPE_TEXTURE_CUBE ||
target == PIPE_TEXTURE_CUBE_ARRAY)) {
if (!download || target == PIPE_TEXTURE_1D_ARRAY ||
target == PIPE_TEXTURE_2D_ARRAY ||
target == PIPE_TEXTURE_3D ||
target == PIPE_TEXTURE_CUBE ||
target == PIPE_TEXTURE_CUBE_ARRAY) {
if (need_layer) {
assert(st->pbo.layers);
nir_variable *var = nir_variable_create(b.shader, nir_var_shader_in,
glsl_int_type(), "gl_Layer");
var->data.location = VARYING_SLOT_LAYER;
@@ -465,7 +471,7 @@ create_fs(struct st_context *st, bool download,
nir_iadd(&b, nir_channel(&b, offset_pos, 0),
nir_imul(&b, nir_channel(&b, offset_pos, 1),
nir_channel(&b, param, 2)));
if (layer) {
if (layer && layer != zero) {
/* pbo_addr += image_height * layer */
pbo_addr = nir_iadd(&b, pbo_addr,
nir_imul(&b, layer, nir_channel(&b, param, 3)));