Mesa (main): st/pbo: set layer coord for array textures
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Dec 3 16:10:52 UTC 2021
Module: Mesa
Branch: main
Commit: 5cd161164b8082d2c2066741c7ac566088230989
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=5cd161164b8082d2c2066741c7ac566088230989
Author: Juan A. Suarez Romero <jasuarez at igalia.com>
Date: Thu Oct 14 18:40:13 2021 +0200
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 at igalia.com>
Reviewed-by: Alejandro Piñeiro <apinheiro at igalia.com>
Reviewed-by: Iago Toral Quiroga <itoral at igalia.com>
Reviewed-by: Ilia Mirkin <imirkin at alum.mit.edu>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13409>
---
src/mesa/state_tracker/st_pbo.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/src/mesa/state_tracker/st_pbo.c b/src/mesa/state_tracker/st_pbo.c
index 51a29e8bcfa..f07f4163a44 100644
--- a/src/mesa/state_tracker/st_pbo.c
+++ b/src/mesa/state_tracker/st_pbo.c
@@ -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)));
More information about the mesa-commit
mailing list