Commit d11d549f by Nicolas Capens

Implement textureGrad.

BUG=angle:564 Change-Id: I95dcd95a274f6d560250c197be0d6e64a5b23516 Reviewed-on: https://chromium-review.googlesource.com/187081Tested-by: 's avatarNicolas Capens <nicolascapens@chromium.org> Reviewed-by: 's avatarShannon Woods <shannonwoods@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 373d7937
...@@ -511,6 +511,14 @@ void InsertBuiltInFunctions(ShShaderType type, ShShaderSpec spec, const ShBuiltI ...@@ -511,6 +511,14 @@ void InsertBuiltInFunctions(ShShaderType type, ShShaderSpec spec, const ShBuiltI
symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler3D, int3, int1, int3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler3D, int3, int1, int3);
symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2DArray, int3, int1, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2DArray, int3, int1, int2);
symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2D, float2, float2, float2);
symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler3D, float3, float3, float3);
symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsamplerCube, float3, float3, float3);
symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DShadow, float3, float2, float2);
symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", samplerCubeShadow, float4, float3, float3);
symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2DArray, float3, float2, float2);
symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DArrayShadow, float4, float2, float2);
// //
// Depth range in window coordinates // Depth range in window coordinates
// //
......
...@@ -61,6 +61,7 @@ TString OutputHLSL::TextureFunction::name() const ...@@ -61,6 +61,7 @@ TString OutputHLSL::TextureFunction::name() const
case LOD0: name += "Lod0"; break; case LOD0: name += "Lod0"; break;
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;
default: UNREACHABLE(); default: UNREACHABLE();
} }
...@@ -1022,6 +1023,33 @@ void OutputHLSL::header() ...@@ -1022,6 +1023,33 @@ void OutputHLSL::header()
} }
} }
if (textureFunction->method == TextureFunction::GRAD)
{
switch(textureFunction->sampler)
{
case EbtSampler2D:
case EbtISampler2D:
case EbtUSampler2D:
case EbtSampler2DArray:
case EbtISampler2DArray:
case EbtUSampler2DArray:
case EbtSampler2DShadow:
case EbtSampler2DArrayShadow:
out << ", float2 ddx, float2 ddy";
break;
case EbtSampler3D:
case EbtISampler3D:
case EbtUSampler3D:
case EbtSamplerCube:
case EbtISamplerCube:
case EbtUSamplerCube:
case EbtSamplerCubeShadow:
out << ", float3 ddx, float3 ddy";
break;
default: UNREACHABLE();
}
}
switch(textureFunction->method) switch(textureFunction->method)
{ {
case TextureFunction::IMPLICIT: break; case TextureFunction::IMPLICIT: break;
...@@ -1030,6 +1058,7 @@ void OutputHLSL::header() ...@@ -1030,6 +1058,7 @@ void OutputHLSL::header()
case TextureFunction::LOD0: break; case TextureFunction::LOD0: break;
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;
default: UNREACHABLE(); default: UNREACHABLE();
} }
...@@ -1146,6 +1175,11 @@ void OutputHLSL::header() ...@@ -1146,6 +1175,11 @@ void OutputHLSL::header()
out << " lod += bias;\n"; out << " lod += bias;\n";
} }
} }
else if (textureFunction->method == TextureFunction::GRAD)
{
out << " x.GetDimensions(0, width, height, layers, levels);\n"
" float lod = log2(max(length(ddx), length(ddy)));\n";
}
out << " uint mip = uint(min(max(round(lod), 0), levels - 1));\n"; out << " uint mip = uint(min(max(round(lod), 0), levels - 1));\n";
} }
...@@ -1180,6 +1214,11 @@ void OutputHLSL::header() ...@@ -1180,6 +1214,11 @@ void OutputHLSL::header()
{ {
out << " x.GetDimensions(0, width, height, levels);\n"; out << " x.GetDimensions(0, width, height, levels);\n";
} }
else if (textureFunction->method == TextureFunction::GRAD)
{
out << " x.GetDimensions(0, width, height, levels);\n"
" float lod = log2(max(length(ddx), length(ddy)));\n";
}
out << " uint mip = uint(min(max(round(lod), 0), levels - 1));\n"; out << " uint mip = uint(min(max(round(lod), 0), levels - 1));\n";
} }
...@@ -1211,6 +1250,11 @@ void OutputHLSL::header() ...@@ -1211,6 +1250,11 @@ void OutputHLSL::header()
out << " lod += bias;\n"; out << " lod += bias;\n";
} }
} }
else if (textureFunction->method == TextureFunction::GRAD)
{
out << " x.GetDimensions(0, width, height, depth, levels);\n"
" float lod = log2(max(length(ddx), length(ddy)));\n";
}
out << " uint mip = uint(min(max(round(lod), 0), levels - 1));\n"; out << " uint mip = uint(min(max(round(lod), 0), levels - 1));\n";
} }
...@@ -1243,7 +1287,22 @@ void OutputHLSL::header() ...@@ -1243,7 +1287,22 @@ void OutputHLSL::header()
} }
else if (mOutputType == SH_HLSL11_OUTPUT) else if (mOutputType == SH_HLSL11_OUTPUT)
{ {
if (IsIntegerSampler(textureFunction->sampler) || if (textureFunction->method == TextureFunction::GRAD)
{
if (IsIntegerSampler(textureFunction->sampler))
{
out << "x.Load(";
}
else if (IsShadowSampler(textureFunction->sampler))
{
out << "x.SampleCmpLevelZero(s, ";
}
else
{
out << "x.SampleGrad(s, ";
}
}
else if (IsIntegerSampler(textureFunction->sampler) ||
textureFunction->method == TextureFunction::FETCH) textureFunction->method == TextureFunction::FETCH)
{ {
out << "x.Load("; out << "x.Load(";
...@@ -1359,7 +1418,28 @@ void OutputHLSL::header() ...@@ -1359,7 +1418,28 @@ void OutputHLSL::header()
out << ", " + addressz + ("t.z" + proj) + close; out << ", " + addressz + ("t.z" + proj) + close;
} }
if (IsIntegerSampler(textureFunction->sampler) || if (textureFunction->method == TextureFunction::GRAD)
{
if (IsIntegerSampler(textureFunction->sampler))
{
out << ", mip)";
}
else if (IsShadowSampler(textureFunction->sampler))
{
// Compare value
switch(textureFunction->coords)
{
case 3: out << "), t.z"; break;
case 4: out << "), t.w"; break;
default: UNREACHABLE();
}
}
else
{
out << "), ddx, ddy";
}
}
else if (IsIntegerSampler(textureFunction->sampler) ||
textureFunction->method == TextureFunction::FETCH) textureFunction->method == TextureFunction::FETCH)
{ {
out << ", mip)"; out << ", mip)";
...@@ -2400,6 +2480,10 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -2400,6 +2480,10 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
textureFunction.method = TextureFunction::FETCH; textureFunction.method = TextureFunction::FETCH;
textureFunction.offset = true; textureFunction.offset = true;
} }
else if (name == "textureGrad")
{
textureFunction.method = TextureFunction::GRAD;
}
else UNREACHABLE(); else UNREACHABLE();
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
......
...@@ -105,7 +105,8 @@ class OutputHLSL : public TIntermTraverser ...@@ -105,7 +105,8 @@ class OutputHLSL : public TIntermTraverser
LOD, LOD,
LOD0, LOD0,
SIZE, // textureSize() SIZE, // textureSize()
FETCH FETCH,
GRAD
}; };
TBasicType sampler; TBasicType sampler;
......
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