Generate correct image operand mask for Offset and ConstOffset(#77)
authorRex Xu <rex.xu@amd.com>
Sun, 11 Oct 2015 11:37:48 +0000 (19:37 +0800)
committerRex Xu <rex.xu@amd.com>
Sun, 11 Oct 2015 11:37:48 +0000 (19:37 +0800)
SPIRV/SpvBuilder.cpp
SPIRV/SpvBuilder.h

index 8b209b6..52c5a31 100755 (executable)
@@ -1188,7 +1188,10 @@ Id Builder::createTextureCall(Decoration precision, Id resultType, bool fetch, b
         xplicit = true;
     }
     if (parameters.offset) {
-        mask = (ImageOperandsMask)(mask | ImageOperandsOffsetMask);
+        if (isConstant(parameters.offset))
+            mask = (ImageOperandsMask)(mask | ImageOperandsConstOffsetMask);
+        else
+            mask = (ImageOperandsMask)(mask | ImageOperandsOffsetMask);
         texArgs[numArgs++] = parameters.offset;
     }
     // TBD: if Offset is constant, use ImageOperandsConstOffsetMask
index 1a6be6a..cadea66 100755 (executable)
@@ -136,6 +136,11 @@ public:
     bool isSamplerType(Id typeId)   const { return getTypeClass(typeId) == OpTypeSampler; }
     bool isSampledImageType(Id typeId)   const { return getTypeClass(typeId) == OpTypeSampledImage; }
 
+    bool isConstant(Id resultId) const
+    {
+        Op opCode = getOpCode(resultId);
+        return opCode == OpConstantTrue || opCode == OpConstantFalse || opCode == OpConstant || opCode == OpConstantComposite || opCode == OpConstantNull;
+    }
     bool isConstantScalar(Id resultId) const { return getOpCode(resultId) == OpConstant; }
     unsigned int getConstantScalar(Id resultId) const { return module.getInstruction(resultId)->getImmediateOperand(0); }