Mesa (main): aco: add more validation rules for SDWA operands

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Aug 23 10:48:49 UTC 2021


Module: Mesa
Branch: main
Commit: 77ffdf41b12b6ef9bc147af1d5014379ad4c182b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=77ffdf41b12b6ef9bc147af1d5014379ad4c182b

Author: Daniel Schürmann <daniel at schuermann.dev>
Date:   Wed Aug 18 21:42:15 2021 +0200

aco: add more validation rules for SDWA operands

Reviewed-by: Rhys Perry <pendingchaos02 at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12364>

---

 src/amd/compiler/aco_validate.cpp | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/amd/compiler/aco_validate.cpp b/src/amd/compiler/aco_validate.cpp
index 602c4367348..0eb81753297 100644
--- a/src/amd/compiler/aco_validate.cpp
+++ b/src/amd/compiler/aco_validate.cpp
@@ -165,6 +165,15 @@ validate_ir(Program* program)
                      "SDWA+VOPC definition must be fixed to vcc on GFX8", instr.get());
             }
 
+            for (unsigned i = 0; i < std::min<unsigned>(2, instr->operands.size()); i++) {
+               const Operand& op = instr->operands[i];
+               check(op.bytes() <= 4, "SDWA operands must not be larger than 4 bytes", instr.get());
+               if (sdwa.sel[i] & sdwa_isra)
+                  check(op.bytes() >= (sdwa.sel[i] & sdwa_rasize),
+                        "SDWA selection size must be at most operand size", instr.get());
+               else
+                  check(op.bytes() == 4, "SDWA selection needs dword operand", instr.get());
+            }
             if (instr->operands.size() >= 3) {
                check(instr->operands[2].isFixed() && instr->operands[2].physReg() == vcc,
                      "3rd operand must be fixed to vcc with SDWA", instr.get());
@@ -681,8 +690,8 @@ validate_subdword_operand(chip_class chip, const aco_ptr<Instruction>& instr, un
    if (instr->isPseudo() && chip >= GFX8)
       return true;
    if (instr->isSDWA()) {
-      unsigned sel = instr->sdwa().sel[index] & sdwa_asuint;
-      return (sel & sdwa_isra) && (sel & sdwa_rasize) <= op.bytes();
+      unsigned size = instr->sdwa().sel[index] & sdwa_rasize;
+      return byte % size == 0;
    }
    if (byte == 2 && can_use_opsel(chip, instr->opcode, index, 1))
       return true;



More information about the mesa-commit mailing list