SPV constants and constOffsets completion: isConstant() and disassembler to see results.

Expand to full isConstant() implementation.
Fix disassembler to generate texture look-up masks.
This commit is contained in:
John Kessenich
2015-10-13 10:39:19 -06:00
parent d4a7a8e721
commit 716312771c
7 changed files with 74 additions and 57 deletions

View File

@@ -500,6 +500,27 @@ Id Builder::findScalarConstant(Op typeClass, Id typeId, unsigned v1, unsigned v2
return 0;
}
bool Builder::isConstantOpCode(Op opcode) const
{
switch (opcode) {
case OpUndef:
case OpConstantTrue:
case OpConstantFalse:
case OpConstant:
case OpConstantComposite:
case OpConstantSampler:
case OpConstantNull:
case OpSpecConstantTrue:
case OpSpecConstantFalse:
case OpSpecConstant:
case OpSpecConstantComposite:
case OpSpecConstantOp:
return true;
default:
return false;
}
}
Id Builder::makeBoolConstant(bool b)
{
Id typeId = makeBoolType();
@@ -1194,7 +1215,6 @@ Id Builder::createTextureCall(Decoration precision, Id resultType, bool fetch, b
mask = (ImageOperandsMask)(mask | ImageOperandsOffsetMask);
texArgs[numArgs++] = parameters.offset;
}
// TBD: if Offset is constant, use ImageOperandsConstOffsetMask
if (parameters.offsets) {
mask = (ImageOperandsMask)(mask | ImageOperandsConstOffsetsMask);
texArgs[numArgs++] = parameters.offsets;

View File

@@ -136,11 +136,8 @@ 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 isConstantOpCode(Op opcode) const;
bool isConstant(Id resultId) const { return isConstantOpCode(getOpCode(resultId)); }
bool isConstantScalar(Id resultId) const { return getOpCode(resultId) == OpConstant; }
unsigned int getConstantScalar(Id resultId) const { return module.getInstruction(resultId)->getImmediateOperand(0); }

View File

@@ -398,7 +398,7 @@ void SpirvStream::disassembleInstruction(Id resultId, Id /*typeId*/, Op opCode,
disassembleIds(numOperands);
return;
case OperandOptionalImage:
outputMask(operandClass, stream[word++]);
outputMask(OperandImageOperands, stream[word++]);
--numOperands;
disassembleIds(numOperands);
return;