Merge pull request #1451 from KhronosGroup/shadow-forces-depth

GLSL/SPV: If a texture is used with a shadow sampler, force 'shadow'.
This commit is contained in:
John Kessenich
2018-07-23 16:41:00 -07:00
committed by GitHub
6 changed files with 288 additions and 345 deletions

View File

@@ -6246,7 +6246,8 @@ bool HlslParseContext::constructorError(const TSourceLoc& loc, TIntermNode* node
bool constructingMatrix = false;
switch (op) {
case EOpConstructTextureSampler:
return constructorTextureSamplerError(loc, function);
error(loc, "unhandled texture constructor", "constructor", "");
return true;
case EOpConstructMat2x2:
case EOpConstructMat2x3:
case EOpConstructMat2x4:
@@ -6438,67 +6439,6 @@ bool HlslParseContext::isScalarConstructor(const TIntermNode* node)
(node->getAsAggregate() == nullptr || node->getAsAggregate()->getOp() != EOpNull);
}
// Verify all the correct semantics for constructing a combined texture/sampler.
// Return true if the semantics are incorrect.
bool HlslParseContext::constructorTextureSamplerError(const TSourceLoc& loc, const TFunction& function)
{
TString constructorName = function.getType().getBasicTypeString(); // TODO: performance: should not be making copy; interface needs to change
const char* token = constructorName.c_str();
// exactly two arguments needed
if (function.getParamCount() != 2) {
error(loc, "sampler-constructor requires two arguments", token, "");
return true;
}
// For now, not allowing arrayed constructors, the rest of this function
// is set up to allow them, if this test is removed:
if (function.getType().isArray()) {
error(loc, "sampler-constructor cannot make an array of samplers", token, "");
return true;
}
// first argument
// * the constructor's first argument must be a texture type
// * the dimensionality (1D, 2D, 3D, Cube, Rect, Buffer, MS, and Array)
// of the texture type must match that of the constructed sampler type
// (that is, the suffixes of the type of the first argument and the
// type of the constructor will be spelled the same way)
if (function[0].type->getBasicType() != EbtSampler ||
! function[0].type->getSampler().isTexture() ||
function[0].type->isArray()) {
error(loc, "sampler-constructor first argument must be a scalar textureXXX type", token, "");
return true;
}
// simulate the first argument's impact on the result type, so it can be compared with the encapsulated operator!=()
TSampler texture = function.getType().getSampler();
texture.combined = false;
texture.shadow = false;
if (texture != function[0].type->getSampler()) {
error(loc, "sampler-constructor first argument must match type and dimensionality of constructor type", token, "");
return true;
}
// second argument
// * the constructor's second argument must be a scalar of type
// *sampler* or *samplerShadow*
// * the presence or absence of depth comparison (Shadow) must match
// between the constructed sampler type and the type of the second argument
if (function[1].type->getBasicType() != EbtSampler ||
! function[1].type->getSampler().isPureSampler() ||
function[1].type->isArray()) {
error(loc, "sampler-constructor second argument must be a scalar type 'sampler'", token, "");
return true;
}
if (function.getType().getSampler().shadow != function[1].type->getSampler().shadow) {
error(loc, "sampler-constructor second argument presence of shadow must match constructor presence of shadow",
token, "");
return true;
}
return false;
}
// Checks to see if a void variable has been declared and raise an error message for such a case
//
// returns true in case of an error
@@ -8175,8 +8115,6 @@ TIntermTyped* HlslParseContext::addConstructor(const TSourceLoc& loc, TIntermTyp
TIntermAggregate* aggrNode = node->getAsAggregate();
TOperator op = intermediate.mapTypeToConstructorOp(type);
// Combined texture-sampler constructors are completely semantic checked
// in constructorTextureSamplerError()
if (op == EOpConstructTextureSampler)
return intermediate.setAggregateOperator(aggrNode, op, type, loc);

View File

@@ -122,7 +122,6 @@ public:
void integerCheck(const TIntermTyped* node, const char* token);
void globalCheck(const TSourceLoc&, const char* token);
bool constructorError(const TSourceLoc&, TIntermNode*, TFunction&, TOperator, TType&);
bool constructorTextureSamplerError(const TSourceLoc&, const TFunction&);
void arraySizeCheck(const TSourceLoc&, TIntermTyped* expr, TArraySize&);
void arraySizeRequiredCheck(const TSourceLoc&, const TArraySizes&);
void structArrayCheck(const TSourceLoc&, const TType& structure);