Add texture gather functions (and extension check) for GLSL 400 and GL_ARB_texture_gather.

git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@23631 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
John Kessenich 2013-10-21 19:25:59 +00:00
parent a65dc63d46
commit 21a8770f92
11 changed files with 301 additions and 36 deletions

View file

@ -1397,6 +1397,11 @@ void TBuiltIns::initialize(int version, EProfile profile)
//
void TBuiltIns::add2ndGenerationSamplingImaging(int version, EProfile profile)
{
//
// In this function proper, enumerate the types, then calls the next set of functions
// to enumerate all the uses for that type.
//
TBasicType bTypes[3] = { EbtFloat, EbtInt, EbtUint };
// enumerate all the types
@ -1455,8 +1460,11 @@ void TBuiltIns::add2ndGenerationSamplingImaging(int version, EProfile profile)
if (image)
addImageFunctions(sampler, typeName, version, profile);
else
else {
addSamplingFunctions(sampler, typeName, version, profile);
if (version >= 130)
addGatherFunctions(sampler, typeName, version, profile);
}
}
}
}
@ -1469,6 +1477,8 @@ void TBuiltIns::add2ndGenerationSamplingImaging(int version, EProfile profile)
// Helper function for add2ndGenerationSamplingImaging(),
// when adding context-independent built-in functions.
//
// Add all the query functions for the given type.
//
void TBuiltIns::addQueryFunctions(TSampler sampler, TString& typeName, int version, EProfile profile)
{
//
@ -1502,6 +1512,8 @@ void TBuiltIns::addQueryFunctions(TSampler sampler, TString& typeName, int versi
// Helper function for add2ndGenerationSamplingImaging(),
// when adding context-independent built-in functions.
//
// Add all the image access functions for the given type.
//
void TBuiltIns::addImageFunctions(TSampler sampler, TString& typeName, int version, EProfile profile)
{
// TODO: 4.2 Functionality: imaging functions
@ -1511,6 +1523,8 @@ void TBuiltIns::addImageFunctions(TSampler sampler, TString& typeName, int versi
// Helper function for add2ndGenerationSamplingImaging(),
// when adding context-independent built-in functions.
//
// Add all the texture lookup functions for the given type.
//
void TBuiltIns::addSamplingFunctions(TSampler sampler, TString& typeName, int version, EProfile profile)
{
// make one string per stage to contain all functions of the passed-in type for that stage
@ -1690,6 +1704,89 @@ void TBuiltIns::addSamplingFunctions(TSampler sampler, TString& typeName, int ve
}
}
//
// Helper function for add2ndGenerationSamplingImaging(),
// when adding context-independent built-in functions.
//
// Add all the texture gather functions for the given type.
//
void TBuiltIns::addGatherFunctions(TSampler sampler, TString& typeName, int version, EProfile profile)
{
switch (sampler.dim) {
case Esd2D:
case EsdRect:
case EsdCube:
break;
default:
return;
}
if (sampler.ms)
return;
// make one string per stage to contain all functions of the passed-in type for that stage
TString functions[EShLangCount];
for (int offset = 0; offset < 3; ++offset) { // loop over three forms of offset in the call name: none, Offset, and Offsets
for (int comp = 0; comp < 2; ++comp) { // loop over presence of comp argument
if (comp > 0 && sampler.shadow)
continue;
if (offset > 0 && sampler.dim == EsdCube)
continue;
TString s;
// return type
s.append(prefixes[sampler.type]);
s.append("vec4 ");
// name
s.append("textureGather");
switch (offset) {
case 1:
s.append("Offset");
break;
case 2:
s.append("Offsets");
default:
break;
}
s.append("(");
// sampler type argument
s.append(typeName);
// P coordinate argument
s.append(",vec");
int totalDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0);
s.append(postfixes[totalDims]);
// refZ argument
if (sampler.shadow)
s.append(",float");
// offset argument
if (offset > 0) {
s.append(",ivec2");
if (offset == 2)
s.append("[4]");
}
// comp argument
if (comp)
s.append(",int");
s.append(");\n");
commonBuiltins.append(s);
//printf("%s", s.c_str());
}
}
}
//
// Add context-dependent built-in functions and variables that are present
// for the given version and profile. Share common ones across stages, otherwise

View file

@ -69,6 +69,7 @@ protected:
void addQueryFunctions(TSampler, TString& typeName, int version, EProfile profile);
void addImageFunctions(TSampler, TString& typeName, int version, EProfile profile);
void addSamplingFunctions(TSampler, TString& typeName, int version, EProfile profile);
void addGatherFunctions(TSampler, TString& typeName, int version, EProfile profile);
TString commonBuiltins;
TString stageBuiltins[EShLangCount];

View file

@ -867,10 +867,8 @@ TIntermTyped* TParseContext::handleFunctionCall(TSourceLoc loc, TFunction* fnCal
qualifierList.push_back(qual);
}
// built-in texturing functions get their return value precision from the precision of the sampler
if (builtIn && fnCandidate->getType().getQualifier().precision == EpqNone &&
fnCandidate->getParamCount() > 0 && (*fnCandidate)[0].type->getBasicType() == EbtSampler)
result->getQualifier().precision = result->getAsAggregate()->getSequence()[0]->getAsTyped()->getQualifier().precision;
if (builtIn)
nonOpBuiltInCheck(loc, *fnCandidate, result->getAsAggregate());
}
} else {
// error message was put out by PaFindFunction()
@ -892,6 +890,36 @@ TIntermTyped* TParseContext::handleFunctionCall(TSourceLoc loc, TFunction* fnCal
return result;
}
//
// Do additional checking of built-in function calls that were not mapped
// to built-in operations (e.g., texturing functions).
//
// Assumes there has been a semantically correct match to a built-in function.
//
void TParseContext::nonOpBuiltInCheck(TSourceLoc loc, const TFunction& fnCandidate, TIntermAggregate* callNode)
{
// built-in texturing functions get their return value precision from the precision of the sampler
if (fnCandidate.getType().getQualifier().precision == EpqNone &&
fnCandidate.getParamCount() > 0 && fnCandidate[0].type->getBasicType() == EbtSampler)
callNode->getQualifier().precision = callNode->getAsAggregate()->getSequence()[0]->getAsTyped()->getQualifier().precision;
if (fnCandidate.getName().compare(0, 13, "textureGather") == 0) {
const char* feature = "texture gather function";
requireProfile(loc, ~EEsProfile, feature);
profileRequires(loc, ~EEsProfile, 400, GL_ARB_texture_gather, feature);
int lastArgIndex = fnCandidate.getParamCount() - 1;
if (fnCandidate[lastArgIndex].type->getBasicType() == EbtInt && fnCandidate[lastArgIndex].type->isScalar()) {
// the last integral argument to a texture gather must be a constant int between 0 and 3
if (callNode->getSequence()[lastArgIndex]->getAsConstantUnion()) {
int value = callNode->getSequence()[lastArgIndex]->getAsConstantUnion()->getConstArray()[0].getIConst();
if (value < 0 || value > 3)
error(loc, "must be 0, 1, 2, or 3", "texture gather component", "");
} else
error(loc, "must be a constant", "texture gather component", "");
}
}
}
//
// Handle seeing a built-in-type constructor call in the grammar.
//

View file

@ -82,6 +82,7 @@ public:
TFunction* handleFunctionDeclarator(TSourceLoc loc, TFunction& function);
TIntermAggregate* handleFunctionPrototype(TSourceLoc, TFunction&);
TIntermTyped* handleFunctionCall(TSourceLoc, TFunction*, TIntermNode*, TIntermAggregate*);
void nonOpBuiltInCheck(TSourceLoc, const TFunction&, TIntermAggregate*);
TFunction* handleConstructorCall(TSourceLoc, TPublicType&);
bool parseVectorFields(TSourceLoc, const TString&, int vecSize, TVectorFields&);

View file

@ -138,9 +138,10 @@ namespace glslang {
//
void TParseContext::initializeExtensionBehavior()
{
extensionBehavior[GL_ARB_texture_rectangle] = EBhDisable;
extensionBehavior[GL_3DL_array_objects] = EBhDisable;
extensionBehavior[GL_ARB_texture_rectangle] = EBhDisable;
extensionBehavior[GL_3DL_array_objects] = EBhDisable;
extensionBehavior[GL_ARB_shading_language_420pack] = EBhDisable;
extensionBehavior[GL_ARB_texture_gather] = EBhDisable;
}
//

View file

@ -74,6 +74,7 @@ typedef enum {
const char* const GL_ARB_texture_rectangle = "GL_ARB_texture_rectangle";
const char* const GL_3DL_array_objects = "GL_3DL_array_objects";
const char* const GL_ARB_shading_language_420pack = "GL_ARB_shading_language_420pack";
const char* const GL_ARB_texture_gather = "GL_ARB_texture_gather";
} // end namespace glslang