SPV legacy texturing: Smear result of Op*Dref* up to a vector to match

the expectations of old GLSL shadow*() lookups.
This commit is contained in:
John Kessenich
2015-09-14 22:08:12 -06:00
parent e770b3e6cf
commit 7355eebb18
3 changed files with 248 additions and 212 deletions

View File

@@ -1214,6 +1214,23 @@ Id Builder::createTextureCall(Decoration precision, Id resultType, bool fetch, b
}
}
// See if the result type is expecting a smeared result.
// This happens when a legacy shadow*() call is made, which
// gets a vec4 back instead of a float.
Id smearedType = resultType;
if (! isScalarType(resultType)) {
switch (opCode) {
case OpImageSampleDrefImplicitLod:
case OpImageSampleDrefExplicitLod:
case OpImageSampleProjDrefImplicitLod:
case OpImageSampleProjDrefExplicitLod:
resultType = getScalarTypeId(resultType);
break;
default:
break;
}
}
Instruction* textureInst = new Instruction(getUniqueId(), resultType, opCode);
for (int op = 0; op < optArgNum; ++op)
textureInst->addIdOperand(texArgs[op]);
@@ -1224,7 +1241,14 @@ Id Builder::createTextureCall(Decoration precision, Id resultType, bool fetch, b
setPrecision(textureInst->getResultId(), precision);
buildPoint->addInstruction(textureInst);
return textureInst->getResultId();
Id resultId = textureInst->getResultId();
// When a smear is needed, do it, as per what was computed
// above when resultType was changed to a scalar type.
if (resultType != smearedType)
resultId = smearScalar(precision, resultId, smearedType);
return resultId;
}
// Comments in header