From: Gert Wollny <gert.wol...@collabora.com> Correct the array index for TEXTURE_*1D_ARRAY, and TEXTURE_*2D_ARRAY
v2: - Don't apply texture offset correction for GATHER*O (corrects piglit failures reported by Dave Airlie) - unconditionally set the texture offset to 1 (=0.5) because the shader can't set an offset for the array index (Roland Scheidegger) v3: - Set texture offset also for GATHER*0 via SET_TEXTURE_OFFSET to be consistent for all GATHER operations (thanks Roland Scheidegger for pointing out this inconsistency). - Don't set the offset for GET_TEXTURE_RESINFO operations - correct typos (Roland) v4: - evaluate array index relying only on arithmetic used in the shaders (Roland pointed out that changing the texture state with respect to rounding might have unwanted effects) - make use of the newly introduced function for evaluating the index Fixes 325 tests from android/cts/master/gles3-master.txt: dEQP-GLES3.functional.shaders.texture_functions.texture.*sampler2darray* dEQP-GLES3.functional.shaders.texture_functions.textureoffset.*sampler2darray* dEQP-GLES3.functional.shaders.texture_functions.texturelod.sampler2darray* dEQP-GLES3.functional.shaders.texture_functions.texturelodoffset.*sampler2darray* dEQP-GLES3.functional.shaders.texture_functions.texturegrad.*sampler2darray* dEQP-GLES3.functional.shaders.texture_functions.texturegradoffset.*sampler2darray* dEQP-GLES3.functional.texture.filtering.2d_array.formats.* dEQP-GLES3.functional.texture.filtering.2d_array.sizes.* dEQP-GLES3.functional.texture.filtering.2d_array.combinations.* dEQP-GLES3.functional.texture.shadow.2d_array.* dEQP-GLES3.functional.texture.vertex.2d_array.* Acked-by: Roland Scheidegger <srol...@vmware.com> (v2) Signed-off-by: Gert Wollny <gert.wol...@collabora.com> --- src/gallium/drivers/r600/r600_shader.c | 38 +++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c index e2f44afc05..6f1e0b34f3 100644 --- a/src/gallium/drivers/r600/r600_shader.c +++ b/src/gallium/drivers/r600/r600_shader.c @@ -7512,6 +7512,7 @@ static int tgsi_tex(struct r600_shader_ctx *ctx) int8_t offset_x = 0, offset_y = 0, offset_z = 0; boolean has_txq_cube_array_z = false; unsigned sampler_index_mode; + int array_index_offset_channel = -1; if (inst->Instruction.Opcode == TGSI_OPCODE_TXQ && ((inst->Texture.Texture == TGSI_TEXTURE_CUBE_ARRAY || @@ -8307,7 +8308,14 @@ static int tgsi_tex(struct r600_shader_ctx *ctx) t->src_gpr = ctx->file_offset[inst->TexOffsets[0].File] + inst->TexOffsets[0].Index; t->src_sel_x = inst->TexOffsets[0].SwizzleX; t->src_sel_y = inst->TexOffsets[0].SwizzleY; - t->src_sel_z = inst->TexOffsets[0].SwizzleZ; + if (inst->Texture.Texture == TGSI_TEXTURE_2D_ARRAY || + inst->Texture.Texture == TGSI_TEXTURE_SHADOW2D_ARRAY) + /* make sure array index selector is 0, this is just a safety + * precaution because TGSI seems to emit offset Y also for Z */ + t->src_sel_z = 4; + else + t->src_sel_z = inst->TexOffsets[0].SwizzleZ; + t->src_sel_w = 4; t->dst_sel_x = 7; @@ -8463,19 +8471,39 @@ static int tgsi_tex(struct r600_shader_ctx *ctx) opcode == FETCH_OP_SAMPLE_C_LB) { /* the array index is read from Y */ tex.coord_type_y = 0; + array_index_offset_channel = tex.src_sel_y; } else { /* the array index is read from Z */ tex.coord_type_z = 0; tex.src_sel_z = tex.src_sel_y; + array_index_offset_channel = tex.src_sel_z; } } else if (inst->Texture.Texture == TGSI_TEXTURE_2D_ARRAY || - inst->Texture.Texture == TGSI_TEXTURE_SHADOW2D_ARRAY || - ((inst->Texture.Texture == TGSI_TEXTURE_CUBE_ARRAY || + inst->Texture.Texture == TGSI_TEXTURE_SHADOW2D_ARRAY) { + tex.coord_type_z = 0; + array_index_offset_channel = tex.src_sel_z; + } else if ((inst->Texture.Texture == TGSI_TEXTURE_CUBE_ARRAY || inst->Texture.Texture == TGSI_TEXTURE_SHADOWCUBE_ARRAY) && - (ctx->bc->chip_class >= EVERGREEN))) - /* the array index is read from Z */ + (ctx->bc->chip_class >= EVERGREEN)) + /* the array index is read from Z, coordinate will be corrected elsewhere */ tex.coord_type_z = 0; + /* We have array access to 1D or 2D ARRAY, the coordinates are not int -> + * evaluate the array index */ + if (array_index_offset_channel >= 0 && + opcode != FETCH_OP_LD && + opcode != FETCH_OP_GET_TEXTURE_RESINFO) { + memset(&alu, 0, sizeof(struct r600_bytecode_alu)); + alu.src[0].sel = tex.src_gpr; + alu.src[0].chan = array_index_offset_channel; + alu.src[0].rel = tex.src_rel; + r = r600_shader_evaluate_array_index(&alu, tex.src_gpr, + array_index_offset_channel, tex.src_rel, + ctx->bc); + if (r) + return r; + } + /* mask unused source components */ if (opcode == FETCH_OP_SAMPLE || opcode == FETCH_OP_GATHER4) { switch (inst->Texture.Texture) { -- 2.16.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev