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)
floatingPoint.secondarySize = 1;
floatingPoint.array = false;
TPublicType sampler;
sampler.primarySize = 1;
sampler.secondarySize = 1;
sampler.array = false;
switch(shaderType)
{
case SH_FRAGMENT_SHADER:
......@@ -252,6 +257,13 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
break;
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);
......
......@@ -332,10 +332,8 @@ public:
void dump(TInfoSink &infoSink) const;
bool setDefaultPrecision(const TPublicType& type, TPrecision prec) {
if (IsSampler(type.type))
return true; // Skip sampler types for the time being
if (type.type != EbtFloat && type.type != EbtInt)
return false; // Only set default precision for int/float
if (!supportsPrecision(type.type))
return false;
if (type.isAggregate())
return false; // Not allowed to set for aggregate types
int indexOfLastElement = static_cast<int>(precisionStack.size()) - 1;
......@@ -346,19 +344,18 @@ public:
// Searches down the precisionStack for a precision qualifier for the specified TBasicType
TPrecision getDefaultPrecision( TBasicType type){
// unsigned integers use the same precision as signed
if (type == EbtUInt)
type = EbtInt;
if (type != EbtFloat && type != EbtInt)
if (!supportsPrecision(type))
return EbpUndefined;
// unsigned integers use the same precision as signed
TBasicType baseType = (type == EbtUInt) ? EbtInt : type;
int level = static_cast<int>(precisionStack.size()) - 1;
assert(level >= 0); // Just to be safe. Should not happen.
PrecisionStackLevel::iterator it;
TPrecision prec = EbpUndefined; // If we dont find anything we return this. Should we error check this?
while (level >= 0) {
it = precisionStack[level]->find(type);
it = precisionStack[level]->find(baseType);
if (it != precisionStack[level]->end()) {
prec = (*it).second;
break;
......@@ -371,6 +368,11 @@ public:
private:
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;
typedef TMap<TBasicType, TPrecision> PrecisionStackLevel;
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