Commit 84cfa124 by Nicolas Capens

Fix Lod0 texture functions that take a bias parameter.

Texture functions that are in a divergent path can still take a bias parameter. Treat the bias parameter as an explicit lod. The logic behind this is that the implicit lod is considerd to be 0 like with other Lod0 functions, and then the bias is added to it. BUG=angle:604 Change-Id: I2dbc309c497d37e960209f08849f9d2bc9e1fbcc Reviewed-on: https://chromium-review.googlesource.com/194544Tested-by: 's avatarNicolas Capens <nicolascapens@chromium.org> Reviewed-by: 's avatarShannon Woods <shannonwoods@chromium.org>
parent 35adc099
...@@ -56,9 +56,10 @@ TString OutputHLSL::TextureFunction::name() const ...@@ -56,9 +56,10 @@ TString OutputHLSL::TextureFunction::name() const
switch(method) switch(method)
{ {
case IMPLICIT: break; case IMPLICIT: break;
case BIAS: break; case BIAS: break; // Extra parameter makes the signature unique
case LOD: name += "Lod"; break; case LOD: name += "Lod"; break;
case LOD0: name += "Lod0"; break; case LOD0: name += "Lod0"; break;
case LOD0BIAS: name += "Lod0"; break; // Extra parameter makes the signature unique
case SIZE: name += "Size"; break; case SIZE: name += "Size"; break;
case FETCH: name += "Fetch"; break; case FETCH: name += "Fetch"; break;
case GRAD: name += "Grad"; break; case GRAD: name += "Grad"; break;
...@@ -982,6 +983,7 @@ void OutputHLSL::header() ...@@ -982,6 +983,7 @@ void OutputHLSL::header()
case TextureFunction::BIAS: hlslCoords = 4; break; case TextureFunction::BIAS: hlslCoords = 4; break;
case TextureFunction::LOD: hlslCoords = 4; break; case TextureFunction::LOD: hlslCoords = 4; break;
case TextureFunction::LOD0: hlslCoords = 4; break; case TextureFunction::LOD0: hlslCoords = 4; break;
case TextureFunction::LOD0BIAS: hlslCoords = 4; break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
} }
...@@ -1060,9 +1062,10 @@ void OutputHLSL::header() ...@@ -1060,9 +1062,10 @@ void OutputHLSL::header()
switch(textureFunction->method) switch(textureFunction->method)
{ {
case TextureFunction::IMPLICIT: break; case TextureFunction::IMPLICIT: break;
case TextureFunction::BIAS: break; case TextureFunction::BIAS: break; // Comes after the offset parameter
case TextureFunction::LOD: out << ", float lod"; break; case TextureFunction::LOD: out << ", float lod"; break;
case TextureFunction::LOD0: break; case TextureFunction::LOD0: break;
case TextureFunction::LOD0BIAS: break; // Comes after the offset parameter
case TextureFunction::SIZE: break; case TextureFunction::SIZE: break;
case TextureFunction::FETCH: out << ", int mip"; break; case TextureFunction::FETCH: out << ", int mip"; break;
case TextureFunction::GRAD: break; case TextureFunction::GRAD: break;
...@@ -1088,7 +1091,8 @@ void OutputHLSL::header() ...@@ -1088,7 +1091,8 @@ void OutputHLSL::header()
} }
} }
if (textureFunction->method == TextureFunction::BIAS) if (textureFunction->method == TextureFunction::BIAS ||
textureFunction->method == TextureFunction::LOD0BIAS)
{ {
out << ", float bias"; out << ", float bias";
} }
...@@ -1181,6 +1185,10 @@ void OutputHLSL::header() ...@@ -1181,6 +1185,10 @@ void OutputHLSL::header()
{ {
out << " uint mip = 0;\n"; out << " uint mip = 0;\n";
} }
else if (textureFunction->method == TextureFunction::LOD0BIAS)
{
out << " uint mip = bias;\n";
}
else else
{ {
if (textureFunction->method == TextureFunction::IMPLICIT || if (textureFunction->method == TextureFunction::IMPLICIT ||
...@@ -1216,6 +1224,10 @@ void OutputHLSL::header() ...@@ -1216,6 +1224,10 @@ void OutputHLSL::header()
{ {
out << " uint mip = 0;\n"; out << " uint mip = 0;\n";
} }
else if (textureFunction->method == TextureFunction::LOD0BIAS)
{
out << " uint mip = bias;\n";
}
else else
{ {
if (textureFunction->method == TextureFunction::IMPLICIT || if (textureFunction->method == TextureFunction::IMPLICIT ||
...@@ -1256,6 +1268,10 @@ void OutputHLSL::header() ...@@ -1256,6 +1268,10 @@ void OutputHLSL::header()
{ {
out << " uint mip = 0;\n"; out << " uint mip = 0;\n";
} }
else if (textureFunction->method == TextureFunction::LOD0BIAS)
{
out << " uint mip = bias;\n";
}
else else
{ {
if (textureFunction->method == TextureFunction::IMPLICIT || if (textureFunction->method == TextureFunction::IMPLICIT ||
...@@ -1304,6 +1320,7 @@ void OutputHLSL::header() ...@@ -1304,6 +1320,7 @@ void OutputHLSL::header()
case TextureFunction::BIAS: out << "bias(s, "; break; case TextureFunction::BIAS: out << "bias(s, "; break;
case TextureFunction::LOD: out << "lod(s, "; break; case TextureFunction::LOD: out << "lod(s, "; break;
case TextureFunction::LOD0: out << "lod(s, "; break; case TextureFunction::LOD0: out << "lod(s, "; break;
case TextureFunction::LOD0BIAS: out << "lod(s, "; break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
} }
...@@ -1341,6 +1358,7 @@ void OutputHLSL::header() ...@@ -1341,6 +1358,7 @@ void OutputHLSL::header()
case TextureFunction::BIAS: out << "x.SampleBias(s, "; break; case TextureFunction::BIAS: out << "x.SampleBias(s, "; break;
case TextureFunction::LOD: out << "x.SampleLevel(s, "; break; case TextureFunction::LOD: out << "x.SampleLevel(s, "; break;
case TextureFunction::LOD0: out << "x.SampleLevel(s, "; break; case TextureFunction::LOD0: out << "x.SampleLevel(s, "; break;
case TextureFunction::LOD0BIAS: out << "x.SampleLevel(s, "; break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
} }
...@@ -1431,6 +1449,7 @@ void OutputHLSL::header() ...@@ -1431,6 +1449,7 @@ void OutputHLSL::header()
case TextureFunction::BIAS: out << ", bias"; break; case TextureFunction::BIAS: out << ", bias"; break;
case TextureFunction::LOD: out << ", lod"; break; case TextureFunction::LOD: out << ", lod"; break;
case TextureFunction::LOD0: out << ", 0"; break; case TextureFunction::LOD0: out << ", 0"; break;
case TextureFunction::LOD0BIAS: out << ", bias"; break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
} }
...@@ -1495,6 +1514,7 @@ void OutputHLSL::header() ...@@ -1495,6 +1514,7 @@ void OutputHLSL::header()
case TextureFunction::BIAS: out << "), bias"; break; case TextureFunction::BIAS: out << "), bias"; break;
case TextureFunction::LOD: out << "), lod"; break; case TextureFunction::LOD: out << "), lod"; break;
case TextureFunction::LOD0: out << "), 0"; break; case TextureFunction::LOD0: out << "), 0"; break;
case TextureFunction::LOD0BIAS: out << "), bias"; break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
} }
...@@ -2537,12 +2557,6 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -2537,12 +2557,6 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
if (textureFunction.method == TextureFunction::IMPLICIT) // Could require lod 0 or have a bias argument if (textureFunction.method == TextureFunction::IMPLICIT) // Could require lod 0 or have a bias argument
{ {
if (lod0 || mContext.shaderType == SH_VERTEX_SHADER)
{
textureFunction.method = TextureFunction::LOD0;
}
else
{
unsigned int mandatoryArgumentCount = 2; // All functions have sampler and coordinate arguments unsigned int mandatoryArgumentCount = 2; // All functions have sampler and coordinate arguments
if (textureFunction.offset) if (textureFunction.offset)
...@@ -2550,11 +2564,23 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -2550,11 +2564,23 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
mandatoryArgumentCount++; mandatoryArgumentCount++;
} }
if (arguments.size() > mandatoryArgumentCount) // Bias argument is optional bool bias = (arguments.size() > mandatoryArgumentCount); // Bias argument is optional
if (lod0 || mContext.shaderType == SH_VERTEX_SHADER)
{ {
textureFunction.method = TextureFunction::BIAS; if (bias)
{
textureFunction.method = TextureFunction::LOD0BIAS;
}
else
{
textureFunction.method = TextureFunction::LOD0;
} }
} }
else if (bias)
{
textureFunction.method = TextureFunction::BIAS;
}
} }
mUsesTexture.insert(textureFunction); mUsesTexture.insert(textureFunction);
......
...@@ -104,6 +104,7 @@ class OutputHLSL : public TIntermTraverser ...@@ -104,6 +104,7 @@ class OutputHLSL : public TIntermTraverser
BIAS, BIAS,
LOD, LOD,
LOD0, LOD0,
LOD0BIAS,
SIZE, // textureSize() SIZE, // textureSize()
FETCH, FETCH,
GRAD GRAD
......
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