Module: Mesa
Branch: staging/22.0
Commit: 45eb525fcf20c9171df129e907d2e4372625b288
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=45eb525fcf20c9171df129e907d2e4372625b288

Author: Emma Anholt <e...@anholt.net>
Date:   Wed Jan  5 15:45:37 2022 -0800

r600: Add a workaround and explanation for shadowcubearray TG4.

With the NIR-to-TGSI transition, we had fewer other immediates and would
end up dereffing past the end of the literals array.

Cc: mesa-stable
Reviewed-by: Gert Wollny <gert.wol...@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14429>
(cherry picked from commit 955883cf0aab6d955e6255cfba3a4dad5d7fda3e)

---

 .pick_status.json                      |  2 +-
 src/gallium/drivers/r600/r600_shader.c | 14 ++++++++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 20349b32583..a995c342777 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -404,7 +404,7 @@
         "description": "r600: Add a workaround and explanation for 
shadowcubearray TG4.",
         "nominated": true,
         "nomination_type": 0,
-        "resolution": 0,
+        "resolution": 1,
         "because_sha": null
     },
     {
diff --git a/src/gallium/drivers/r600/r600_shader.c 
b/src/gallium/drivers/r600/r600_shader.c
index c23adf2ea55..aa3e71fc551 100644
--- a/src/gallium/drivers/r600/r600_shader.c
+++ b/src/gallium/drivers/r600/r600_shader.c
@@ -8464,8 +8464,18 @@ static int tgsi_tex(struct r600_shader_ctx *ctx)
        }
 
        if (inst->Instruction.Opcode == TGSI_OPCODE_TG4) {
-               int8_t texture_component_select = ctx->literals[4 * 
inst->Src[1].Register.Index + inst->Src[1].Register.SwizzleX];
-               tex.inst_mod = texture_component_select;
+               if (inst->Src[1].Register.File != TGSI_FILE_IMMEDIATE) {
+                       /* TGSI doesn't have a spot to put the component for
+                        * shadowcubes, so it drops it on the floor.  Just
+                        * assume the user wanted component 0 (it's a shadow,
+                        * anything else would be absurd).
+                        */
+                       assert(inst->Texture.Texture == 
TGSI_TEXTURE_SHADOWCUBE_ARRAY);
+                       tex.inst_mod = 0;
+               } else {
+                       int8_t texture_component_select = ctx->literals[4 * 
inst->Src[1].Register.Index + inst->Src[1].Register.SwizzleX];
+                       tex.inst_mod = texture_component_select;
+               }
 
                if (ctx->bc->chip_class == CAYMAN) {
                        tex.dst_sel_x = (inst->Dst[0].Register.WriteMask & 1) ? 
0 : 7;

Reply via email to