[Mesa-dev] [PATCH v8 12/33] nvir/nir: add loadFrom and storeTo helpler

Karol Herbst kherbst at redhat.com
Fri Jun 29 22:31:59 UTC 2018


v8: don't require C++11 features

Signed-off-by: Karol Herbst <kherbst at redhat.com>
---
 .../nouveau/codegen/nv50_ir_from_nir.cpp      | 72 +++++++++++++++++++
 1 file changed, 72 insertions(+)

diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp
index c4fcc603861..aa484df8fea 100644
--- a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp
+++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp
@@ -74,6 +74,13 @@ private:
                        bool centroid,
                        unsigned semantics);
 
+   Instruction *loadFrom(DataFile, uint8_t, DataType, Value *def, uint32_t base,
+                         uint8_t c, Value *indirect0 = NULL,
+                         Value *indirect1 = NULL, bool patch = false);
+   void storeTo(nir_intrinsic_instr *, DataFile, operation, DataType,
+                Value *src, uint8_t idx, uint8_t c, Value *indirect0 = NULL,
+                Value *indirect1 = NULL);
+
    bool isFloatType(nir_alu_type);
    bool isSignedType(nir_alu_type);
    bool isResultFloat(nir_op);
@@ -922,6 +929,71 @@ Converter::getSlotAddress(nir_intrinsic_instr *insn, uint8_t idx, uint8_t slot)
    return vary[idx].slot[slot] * 4;
 }
 
+Instruction *
+Converter::loadFrom(DataFile file, uint8_t i, DataType ty, Value *def,
+                    uint32_t base, uint8_t c, Value *indirect0,
+                    Value *indirect1, bool patch)
+{
+   unsigned int tySize = typeSizeof(ty);
+
+   if (tySize == 8 &&
+       (file == FILE_MEMORY_CONST || file == FILE_MEMORY_BUFFER || indirect0)) {
+      Value *lo = getSSA();
+      Value *hi = getSSA();
+
+      Instruction *loi =
+         mkLoad(TYPE_U32, lo,
+                mkSymbol(file, i, TYPE_U32, base + c * tySize),
+                indirect0);
+      loi->setIndirect(0, 1, indirect1);
+      loi->perPatch = patch;
+
+      Instruction *hii =
+         mkLoad(TYPE_U32, hi,
+                mkSymbol(file, i, TYPE_U32, base + c * tySize + 4),
+                indirect0);
+      hii->setIndirect(0, 1, indirect1);
+      hii->perPatch = patch;
+
+      return mkOp2(OP_MERGE, ty, def, lo, hi);
+   } else {
+      Instruction *ld =
+         mkLoad(ty, def, mkSymbol(file, i, ty, base + c * tySize), indirect0);
+      ld->setIndirect(0, 1, indirect1);
+      ld->perPatch = patch;
+      return ld;
+   }
+}
+
+void
+Converter::storeTo(nir_intrinsic_instr *insn, DataFile file, operation op,
+                   DataType ty, Value *src, uint8_t idx, uint8_t c,
+                   Value *indirect0, Value *indirect1)
+{
+   uint8_t size = typeSizeof(ty);
+   uint32_t address = getSlotAddress(insn, idx, c);
+
+   if (size == 8 && indirect0) {
+      Value *split[2];
+      mkSplit(split, 4, src);
+
+      if (op == OP_EXPORT) {
+         split[0] = mkMov(getSSA(), split[0], ty)->getDef(0);
+         split[1] = mkMov(getSSA(), split[1], ty)->getDef(0);
+      }
+
+      mkStore(op, TYPE_U32, mkSymbol(file, 0, TYPE_U32, address), indirect0,
+              split[0])->perPatch = info->out[idx].patch;
+      mkStore(op, TYPE_U32, mkSymbol(file, 0, TYPE_U32, address + 4), indirect0,
+              split[1])->perPatch = info->out[idx].patch;
+   } else {
+      if (op == OP_EXPORT)
+         src = mkMov(getSSA(size), src, ty)->getDef(0);
+      mkStore(op, ty, mkSymbol(file, 0, ty, address), indirect0,
+              src)->perPatch = info->out[idx].patch;
+   }
+}
+
 bool
 Converter::run()
 {
-- 
2.17.1



More information about the mesa-dev mailing list