Commit 9754ff4e by Zhenyao Mo

Support precision for sampler types.

BUG= R=alokp@chromium.org Review URL: https://codereview.appspot.com/12833045
parent a6829d57
...@@ -231,6 +231,11 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources) ...@@ -231,6 +231,11 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
floatingPoint.matrix = false; floatingPoint.matrix = false;
floatingPoint.array = false; floatingPoint.array = false;
TPublicType sampler;
sampler.size = 1;
sampler.matrix = false;
sampler.array = false;
switch(shaderType) switch(shaderType)
{ {
case SH_FRAGMENT_SHADER: case SH_FRAGMENT_SHADER:
...@@ -242,6 +247,13 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources) ...@@ -242,6 +247,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);
......
...@@ -337,10 +337,8 @@ public: ...@@ -337,10 +337,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.size != 1 || type.matrix || type.array) if (type.size != 1 || type.matrix || type.array)
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;
...@@ -350,9 +348,8 @@ public: ...@@ -350,9 +348,8 @@ 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) {
if (type != EbtFloat && type != EbtInt) if (!supportsPrecision(type))
return EbpUndefined; return EbpUndefined;
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;
...@@ -371,6 +368,11 @@ public: ...@@ -371,6 +368,11 @@ public:
private: private:
int currentLevel() const { return static_cast<int>(table.size()) - 1; } int currentLevel() const { return static_cast<int>(table.size()) - 1; }
bool supportsPrecision(TBasicType type) {
// Only supports precision for int, float, and sampler types.
return type == EbtFloat || type == EbtInt || IsSampler(type);
}
int uniqueId; // for unique identification in code generation int uniqueId; // for unique identification in code generation
std::vector<TSymbolTableLevel*> table; std::vector<TSymbolTableLevel*> table;
typedef TMap<TBasicType, TPrecision> PrecisionStackLevel; typedef TMap<TBasicType, TPrecision> PrecisionStackLevel;
......
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