Commit fc01454b by Nicolas Capens

Implement texelFetch and texelFetchOffset.

BUG=angle:564 Change-Id: I7ad3484061f5d6912d7842bdadc6297de3e82ef8 Reviewed-on: https://chromium-review.googlesource.com/186990Tested-by: 's avatarNicolas Capens <nicolascapens@chromium.org> Reviewed-by: 's avatarShannon Woods <shannonwoods@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 5c9a29ab
...@@ -503,6 +503,14 @@ void InsertBuiltInFunctions(ShShaderType type, ShShaderSpec spec, const ShBuiltI ...@@ -503,6 +503,14 @@ void InsertBuiltInFunctions(ShShaderType type, ShShaderSpec spec, const ShBuiltI
symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler3D, float4, float1, int3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler3D, float4, float1, int3);
symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLodOffset", sampler2DShadow, float4, float1, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLodOffset", sampler2DShadow, float4, float1, int2);
symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2D, int2, int1);
symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler3D, int3, int1);
symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2DArray, int3, int1);
symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2D, int2, int1, int2);
symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler3D, int3, int1, int3);
symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2DArray, int3, int1, int2);
// //
// Depth range in window coordinates // Depth range in window coordinates
// //
......
...@@ -60,6 +60,7 @@ TString OutputHLSL::TextureFunction::name() const ...@@ -60,6 +60,7 @@ TString OutputHLSL::TextureFunction::name() const
case LOD: name += "Lod"; break; case LOD: name += "Lod"; break;
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;
default: UNREACHABLE(); default: UNREACHABLE();
} }
...@@ -1000,14 +1001,26 @@ void OutputHLSL::header() ...@@ -1000,14 +1001,26 @@ void OutputHLSL::header()
} }
else UNREACHABLE(); else UNREACHABLE();
if (textureFunction->method == TextureFunction::FETCH) // Integer coordinates
{
switch(textureFunction->coords)
{
case 2: out << ", int2 t"; break;
case 3: out << ", int3 t"; break;
default: UNREACHABLE();
}
}
else // Floating-point coordinates (except textureSize)
{
switch(textureFunction->coords) switch(textureFunction->coords)
{ {
case 1: out << ", int lod"; break; case 1: out << ", int lod"; break; // textureSize()
case 2: out << ", float2 t"; break; case 2: out << ", float2 t"; break;
case 3: out << ", float3 t"; break; case 3: out << ", float3 t"; break;
case 4: out << ", float4 t"; break; case 4: out << ", float4 t"; break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
}
switch(textureFunction->method) switch(textureFunction->method)
{ {
...@@ -1016,6 +1029,7 @@ void OutputHLSL::header() ...@@ -1016,6 +1029,7 @@ void OutputHLSL::header()
case TextureFunction::LOD: out << ", float lod"; break; case TextureFunction::LOD: out << ", float lod"; break;
case TextureFunction::LOD0: break; case TextureFunction::LOD0: break;
case TextureFunction::SIZE: break; case TextureFunction::SIZE: break;
case TextureFunction::FETCH: out << ", int mip"; break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
...@@ -1103,7 +1117,8 @@ void OutputHLSL::header() ...@@ -1103,7 +1117,8 @@ void OutputHLSL::header()
} }
else else
{ {
if (IsIntegerSampler(textureFunction->sampler)) if (IsIntegerSampler(textureFunction->sampler) &&
textureFunction->method != TextureFunction::FETCH)
{ {
if (IsSampler2D(textureFunction->sampler)) if (IsSampler2D(textureFunction->sampler))
{ {
...@@ -1228,7 +1243,8 @@ void OutputHLSL::header() ...@@ -1228,7 +1243,8 @@ void OutputHLSL::header()
} }
else if (mOutputType == SH_HLSL11_OUTPUT) else if (mOutputType == SH_HLSL11_OUTPUT)
{ {
if (IsIntegerSampler(textureFunction->sampler)) if (IsIntegerSampler(textureFunction->sampler) ||
textureFunction->method == TextureFunction::FETCH)
{ {
out << "x.Load("; out << "x.Load(";
} }
...@@ -1256,7 +1272,8 @@ void OutputHLSL::header() ...@@ -1256,7 +1272,8 @@ void OutputHLSL::header()
TString addressz = ""; TString addressz = "";
TString close = ""; TString close = "";
if (IsIntegerSampler(textureFunction->sampler)) if (IsIntegerSampler(textureFunction->sampler) ||
textureFunction->method == TextureFunction::FETCH)
{ {
switch(hlslCoords) switch(hlslCoords)
{ {
...@@ -1265,6 +1282,9 @@ void OutputHLSL::header() ...@@ -1265,6 +1282,9 @@ void OutputHLSL::header()
default: UNREACHABLE(); default: UNREACHABLE();
} }
// Convert from normalized floating-point to integer
if (textureFunction->method != TextureFunction::FETCH)
{
addressx = "int(floor(width * frac(("; addressx = "int(floor(width * frac((";
addressy = "int(floor(height * frac(("; addressy = "int(floor(height * frac((";
...@@ -1279,6 +1299,7 @@ void OutputHLSL::header() ...@@ -1279,6 +1299,7 @@ void OutputHLSL::header()
close = "))))"; close = "))))";
} }
}
else else
{ {
switch(hlslCoords) switch(hlslCoords)
...@@ -1338,7 +1359,8 @@ void OutputHLSL::header() ...@@ -1338,7 +1359,8 @@ void OutputHLSL::header()
out << ", " + addressz + ("t.z" + proj) + close; out << ", " + addressz + ("t.z" + proj) + close;
} }
if (IsIntegerSampler(textureFunction->sampler)) if (IsIntegerSampler(textureFunction->sampler) ||
textureFunction->method == TextureFunction::FETCH)
{ {
out << ", mip)"; out << ", mip)";
} }
...@@ -2369,6 +2391,15 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -2369,6 +2391,15 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
textureFunction.proj = true; textureFunction.proj = true;
textureFunction.offset = true; textureFunction.offset = true;
} }
else if (name == "texelFetch")
{
textureFunction.method = TextureFunction::FETCH;
}
else if (name == "texelFetchOffset")
{
textureFunction.method = TextureFunction::FETCH;
textureFunction.offset = true;
}
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
......
...@@ -104,7 +104,8 @@ class OutputHLSL : public TIntermTraverser ...@@ -104,7 +104,8 @@ class OutputHLSL : public TIntermTraverser
BIAS, BIAS,
LOD, LOD,
LOD0, LOD0,
SIZE // textureSize() SIZE, // textureSize()
FETCH
}; };
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