Module: Mesa
Branch: staging/21.3
Commit: 9a69658a98e9ece5ce3a3693f82cd138f194da28
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=9a69658a98e9ece5ce3a3693f82cd138f194da28

Author: Emma Anholt <[email protected]>
Date:   Mon Dec 20 12:09:28 2021 -0800

r300/vs: Allocate temps we see a use as a source, too.

This is a quick hack for a bunch of the fail in #5766.

Cc: mesa-stable
Reviewed-by: Marek Olšák <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14271>
(cherry picked from commit e41a53cd196ba4c3602a198d950bec2aa5fc23c9)

---

 .pick_status.json                                 |  2 +-
 src/gallium/drivers/r300/compiler/r3xx_vertprog.c | 40 ++++++++++++++---------
 2 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 8e002266b8d..8bc63694f7e 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -481,7 +481,7 @@
         "description": "r300/vs: Allocate temps we see a use as a source, 
too.",
         "nominated": true,
         "nomination_type": 0,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": null
     },
diff --git a/src/gallium/drivers/r300/compiler/r3xx_vertprog.c 
b/src/gallium/drivers/r300/compiler/r3xx_vertprog.c
index 88b8dfcd9fc..24121ca8fe4 100644
--- a/src/gallium/drivers/r300/compiler/r3xx_vertprog.c
+++ b/src/gallium/drivers/r300/compiler/r3xx_vertprog.c
@@ -22,6 +22,7 @@
 
 #include "radeon_compiler.h"
 
+#include <stdbool.h>
 #include <stdio.h>
 
 #include "r300_reg.h"
@@ -559,15 +560,33 @@ struct temporary_allocation {
        struct rc_instruction * LastRead;
 };
 
+static int get_reg(struct radeon_compiler *c, struct temporary_allocation *ta, 
bool *hwtemps,
+                   unsigned int orig)
+{
+    if (!ta[orig].Allocated) {
+        int j;
+        for (j = 0; j < c->max_temp_regs; ++j)
+        {
+            if (!hwtemps[j])
+                break;
+        }
+        ta[orig].Allocated = 1;
+        ta[orig].HwTemp = j;
+        hwtemps[ta[orig].HwTemp] = true;
+    }
+
+    return ta[orig].HwTemp;
+}
+
 static void allocate_temporary_registers(struct radeon_compiler *c, void *user)
 {
        struct r300_vertex_program_compiler *compiler = (struct 
r300_vertex_program_compiler*)c;
        struct rc_instruction *inst;
        struct rc_instruction *end_loop = NULL;
        unsigned int num_orig_temps = 0;
-       char hwtemps[RC_REGISTER_MAX_INDEX];
+       bool hwtemps[RC_REGISTER_MAX_INDEX];
        struct temporary_allocation * ta;
-       unsigned int i, j;
+       unsigned int i;
 
        memset(hwtemps, 0, sizeof(hwtemps));
 
@@ -638,28 +657,17 @@ static void allocate_temporary_registers(struct 
radeon_compiler *c, void *user)
                for (i = 0; i < opcode->NumSrcRegs; ++i) {
                        if (inst->U.I.SrcReg[i].File == RC_FILE_TEMPORARY) {
                                unsigned int orig = inst->U.I.SrcReg[i].Index;
-                               inst->U.I.SrcReg[i].Index = ta[orig].HwTemp;
+                               inst->U.I.SrcReg[i].Index = get_reg(c, ta, 
hwtemps, orig);
 
                                if (ta[orig].Allocated && inst == 
ta[orig].LastRead)
-                                       hwtemps[ta[orig].HwTemp] = 0;
+                                       hwtemps[ta[orig].HwTemp] = false;
                        }
                }
 
                if (opcode->HasDstReg) {
                        if (inst->U.I.DstReg.File == RC_FILE_TEMPORARY) {
                                unsigned int orig = inst->U.I.DstReg.Index;
-
-                               if (!ta[orig].Allocated) {
-                                       for(j = 0; j < c->max_temp_regs; ++j) {
-                                               if (!hwtemps[j])
-                                                       break;
-                                       }
-                                       ta[orig].Allocated = 1;
-                                       ta[orig].HwTemp = j;
-                                       hwtemps[ta[orig].HwTemp] = 1;
-                               }
-
-                               inst->U.I.DstReg.Index = ta[orig].HwTemp;
+                               inst->U.I.DstReg.Index = get_reg(c, ta, 
hwtemps, orig);
                        }
                }
        }

Reply via email to