Mesa (master): gallium/tgsi_exec: Refactor to fix CS local memory overflow checks.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jan 6 01:03:38 UTC 2021


Module: Mesa
Branch: master
Commit: 911bb08314a71116b1b2fbf4291d475f40ef53e6
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=911bb08314a71116b1b2fbf4291d475f40ef53e6

Author: Eric Anholt <eric at anholt.net>
Date:   Tue Jan  5 11:12:11 2021 -0800

gallium/tgsi_exec: Refactor to fix CS local memory overflow checks.

It was OK because right now we only execute in the first channel of the
CS, but if you wanted to extend that then you'd need to check each
channel.  We already had what we needed for SSBOs, so just reuse it.

Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8196>

---

 src/gallium/auxiliary/tgsi/tgsi_exec.c | 58 +++++++++++-----------------------
 1 file changed, 19 insertions(+), 39 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c b/src/gallium/auxiliary/tgsi/tgsi_exec.c
index b5fa1d8f263..f17d61c2c7c 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_exec.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c
@@ -3897,12 +3897,26 @@ exec_load_img(struct tgsi_exec_machine *mach,
 }
 
 static void
-exec_load_buf(struct tgsi_exec_machine *mach,
-              const struct tgsi_full_instruction *inst)
+exec_load_membuf(struct tgsi_exec_machine *mach,
+                 const struct tgsi_full_instruction *inst)
 {
    uint32_t unit = fetch_sampler_unit(mach, inst, 0);
+
    uint32_t size;
-   char *ptr = mach->Buffer->lookup(mach->Buffer, unit, &size);
+   char *ptr;
+   switch (inst->Src[0].Register.File) {
+   case TGSI_FILE_MEMORY:
+      ptr = mach->LocalMem;
+      size = mach->LocalMemSize;
+      break;
+
+   case TGSI_FILE_BUFFER:
+      ptr = mach->Buffer->lookup(mach->Buffer, unit, &size);
+      break;
+
+   default:
+      unreachable("unsupported TGSI_OPCODE_LOAD file");
+   }
 
    union tgsi_exec_channel offset;
    IFETCH(&offset, 1, TGSI_CHAN_X);
@@ -3926,48 +3940,14 @@ exec_load_buf(struct tgsi_exec_machine *mach,
    }
 }
 
-static void
-exec_load_mem(struct tgsi_exec_machine *mach,
-              const struct tgsi_full_instruction *inst)
-{
-   union tgsi_exec_channel r[4];
-   uint chan;
-   char *ptr = mach->LocalMem;
-   uint32_t offset;
-   int j;
-
-   IFETCH(&r[0], 1, TGSI_CHAN_X);
-   if (r[0].u[0] >= mach->LocalMemSize)
-      return;
-
-   offset = r[0].u[0];
-   ptr += offset;
-
-   for (j = 0; j < TGSI_QUAD_SIZE; j++) {
-      for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
-         if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
-            memcpy(&r[chan].u[j], ptr + (4 * chan), 4);
-         }
-      }
-   }
-
-   for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
-      if (inst->Dst[0].Register.WriteMask & (1 << chan)) {
-         store_dest(mach, &r[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
-      }
-   }
-}
-
 static void
 exec_load(struct tgsi_exec_machine *mach,
           const struct tgsi_full_instruction *inst)
 {
    if (inst->Src[0].Register.File == TGSI_FILE_IMAGE)
       exec_load_img(mach, inst);
-   else if (inst->Src[0].Register.File == TGSI_FILE_BUFFER)
-      exec_load_buf(mach, inst);
-   else if (inst->Src[0].Register.File == TGSI_FILE_MEMORY)
-      exec_load_mem(mach, inst);
+   else
+      exec_load_membuf(mach, inst);
 }
 
 static uint



More information about the mesa-commit mailing list