Commit a5a1dfc6 by Zhenyao Mo Committed by Jamie Madill

Support precision for sampler types.

BUG= R=alokp@chromium.org Review URL: https://codereview.appspot.com/12833045
parent bc3f1ac6
...@@ -241,6 +241,11 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources) ...@@ -241,6 +241,11 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
floatingPoint.secondarySize = 1; floatingPoint.secondarySize = 1;
floatingPoint.array = false; floatingPoint.array = false;
TPublicType sampler;
sampler.primarySize = 1;
sampler.secondarySize = 1;
sampler.array = false;
switch(shaderType) switch(shaderType)
{ {
case SH_FRAGMENT_SHADER: case SH_FRAGMENT_SHADER:
...@@ -252,6 +257,13 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources) ...@@ -252,6 +257,13 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
break; break;
default: assert(false && "Language not supported"); default: assert(false && "Language not supported");
} }
// We set defaults for all the sampler types, even those that are
// only available if an extension exists.
for (int samplerType = EbtGuardSamplerBegin + 1;
samplerType < EbtGuardSamplerEnd; ++samplerType) {
sampler.type = static_cast<TBasicType>(samplerType);
symbolTable.setDefaultPrecision(sampler, EbpLow);
}
InsertBuiltInFunctions(shaderType, shaderSpec, resources, symbolTable); InsertBuiltInFunctions(shaderType, shaderSpec, resources, symbolTable);
......
...@@ -332,10 +332,8 @@ public: ...@@ -332,10 +332,8 @@ public:
void dump(TInfoSink &infoSink) const; void dump(TInfoSink &infoSink) const;
bool setDefaultPrecision(const TPublicType& type, TPrecision prec) { bool setDefaultPrecision(const TPublicType& type, TPrecision prec) {
if (IsSampler(type.type)) if (!supportsPrecision(type.type))
return true; // Skip sampler types for the time being return false;
if (type.type != EbtFloat && type.type != EbtInt)
return false; // Only set default precision for int/float
if (type.isAggregate()) if (type.isAggregate())
return false; // Not allowed to set for aggregate types return false; // Not allowed to set for aggregate types
int indexOfLastElement = static_cast<int>(precisionStack.size()) - 1; int indexOfLastElement = static_cast<int>(precisionStack.size()) - 1;
...@@ -346,19 +344,18 @@ public: ...@@ -346,19 +344,18 @@ public:
// Searches down the precisionStack for a precision qualifier for the specified TBasicType // Searches down the precisionStack for a precision qualifier for the specified TBasicType
TPrecision getDefaultPrecision( TBasicType type){ TPrecision getDefaultPrecision( TBasicType type){
// unsigned integers use the same precision as signed if (!supportsPrecision(type))
if (type == EbtUInt)
type = EbtInt;
if (type != EbtFloat && type != EbtInt)
return EbpUndefined; return EbpUndefined;
// unsigned integers use the same precision as signed
TBasicType baseType = (type == EbtUInt) ? EbtInt : type;
int level = static_cast<int>(precisionStack.size()) - 1; int level = static_cast<int>(precisionStack.size()) - 1;
assert(level >= 0); // Just to be safe. Should not happen. assert(level >= 0); // Just to be safe. Should not happen.
PrecisionStackLevel::iterator it; PrecisionStackLevel::iterator it;
TPrecision prec = EbpUndefined; // If we dont find anything we return this. Should we error check this? TPrecision prec = EbpUndefined; // If we dont find anything we return this. Should we error check this?
while (level >= 0) { while (level >= 0) {
it = precisionStack[level]->find(type); it = precisionStack[level]->find(baseType);
if (it != precisionStack[level]->end()) { if (it != precisionStack[level]->end()) {
prec = (*it).second; prec = (*it).second;
break; break;
...@@ -371,6 +368,11 @@ public: ...@@ -371,6 +368,11 @@ public:
private: private:
ESymbolLevel currentLevel() const { return static_cast<ESymbolLevel>(table.size() - 1); } ESymbolLevel currentLevel() const { return static_cast<ESymbolLevel>(table.size() - 1); }
bool supportsPrecision(TBasicType type) {
// Only supports precision for int, float, and sampler types.
return type == EbtFloat || type == EbtInt || type == EbtUInt || IsSampler(type);
}
std::vector<TSymbolTableLevel*> table; std::vector<TSymbolTableLevel*> table;
typedef TMap<TBasicType, TPrecision> PrecisionStackLevel; typedef TMap<TBasicType, TPrecision> PrecisionStackLevel;
std::vector< PrecisionStackLevel*> precisionStack; std::vector< PrecisionStackLevel*> precisionStack;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment