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";
} }
...@@ -1176,11 +1180,15 @@ void OutputHLSL::header() ...@@ -1176,11 +1180,15 @@ void OutputHLSL::header()
if (IsSamplerArray(textureFunction->sampler)) if (IsSamplerArray(textureFunction->sampler))
{ {
out << " float width; float height; float layers; float levels;\n"; out << " float width; float height; float layers; float levels;\n";
if (textureFunction->method == TextureFunction::LOD0) if (textureFunction->method == TextureFunction::LOD0)
{ {
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 ||
...@@ -1211,11 +1219,15 @@ void OutputHLSL::header() ...@@ -1211,11 +1219,15 @@ void OutputHLSL::header()
else else
{ {
out << " float width; float height; float levels;\n"; out << " float width; float height; float levels;\n";
if (textureFunction->method == TextureFunction::LOD0) if (textureFunction->method == TextureFunction::LOD0)
{ {
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 ||
...@@ -1251,11 +1263,15 @@ void OutputHLSL::header() ...@@ -1251,11 +1263,15 @@ void OutputHLSL::header()
else if (IsSampler3D(textureFunction->sampler)) else if (IsSampler3D(textureFunction->sampler))
{ {
out << " float width; float height; float depth; float levels;\n"; out << " float width; float height; float depth; float levels;\n";
if (textureFunction->method == TextureFunction::LOD0) if (textureFunction->method == TextureFunction::LOD0)
{ {
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();
} }
} }
...@@ -1428,9 +1446,10 @@ void OutputHLSL::header() ...@@ -1428,9 +1446,10 @@ void OutputHLSL::header()
{ {
switch(textureFunction->method) switch(textureFunction->method)
{ {
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,31 +2557,37 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -2537,31 +2557,37 @@ 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) unsigned int mandatoryArgumentCount = 2; // All functions have sampler and coordinate arguments
if (textureFunction.offset)
{ {
textureFunction.method = TextureFunction::LOD0; mandatoryArgumentCount++;
} }
else
{
unsigned int mandatoryArgumentCount = 2; // All functions have sampler and coordinate arguments
if (textureFunction.offset) bool bias = (arguments.size() > mandatoryArgumentCount); // Bias argument is optional
if (lod0 || mContext.shaderType == SH_VERTEX_SHADER)
{
if (bias)
{ {
mandatoryArgumentCount++; textureFunction.method = TextureFunction::LOD0BIAS;
} }
else
if (arguments.size() > mandatoryArgumentCount) // Bias argument is optional
{ {
textureFunction.method = TextureFunction::BIAS; textureFunction.method = TextureFunction::LOD0;
} }
} }
else if (bias)
{
textureFunction.method = TextureFunction::BIAS;
}
} }
mUsesTexture.insert(textureFunction); mUsesTexture.insert(textureFunction);
out << textureFunction.name(); out << textureFunction.name();
} }
for (TIntermSequence::iterator arg = arguments.begin(); arg != arguments.end(); arg++) for (TIntermSequence::iterator arg = arguments.begin(); arg != arguments.end(); arg++)
{ {
if (mOutputType == SH_HLSL11_OUTPUT && IsSampler((*arg)->getAsTyped()->getBasicType())) if (mOutputType == SH_HLSL11_OUTPUT && IsSampler((*arg)->getAsTyped()->getBasicType()))
......
...@@ -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