From: Gert Wollny <gert.wol...@collabora.com>

Correct the array index for TEXTURE_*1D_ARRAY, and TEXTURE_*2D_ARRAY
The standard says the array index is evaluated according to

   floor(z + 0.5)

but RNDNE is sufficient also for the test cases were z is close to 1.5
and it is likely to hit 1.5, the corner case were RNDNE gives a result
different from above formula.

v5: - Use RNDNE instead of ADD 0.5 and FLOOR (Ilia Mirkin)
    - update commit message

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.*

Signed-off-by: Gert Wollny <gert.wol...@collabora.com>
---
 src/gallium/drivers/r600/r600_shader.c | 42 ++++++++++++++++++++++++++++++----
 1 file changed, 37 insertions(+), 5 deletions(-)

diff --git a/src/gallium/drivers/r600/r600_shader.c 
b/src/gallium/drivers/r600/r600_shader.c
index 6655b000aa..15e35f006c 100644
--- a/src/gallium/drivers/r600/r600_shader.c
+++ b/src/gallium/drivers/r600/r600_shader.c
@@ -7478,6 +7478,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 ||
@@ -8273,7 +8274,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
+                        * precausion because TGSI seems to emit something 
strange here */
+                       t->src_sel_z = 4;
+               else
+                       t->src_sel_z = inst->TexOffsets[0].SwizzleZ;
+
                t->src_sel_w = 4;
 
                t->dst_sel_x = 7;
@@ -8429,19 +8437,43 @@ 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;
+               alu.op = ALU_OP1_RNDNE;
+               alu.dst.sel = tex.src_gpr;
+               alu.dst.chan = array_index_offset_channel;
+               alu.dst.rel = tex.src_rel;
+               alu.dst.write = 1;
+               alu.last = 1;
+               r = r600_bytecode_add_alu(ctx->bc, &alu);
+               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

Reply via email to