Commit a977acc8 by Jiawei Shao Committed by Commit Bot

ES31: Support translating textureGather into HLSL - Part I

This patch is the first one in the series of supporting GLSL texture function textureGather/textureGatherOffset on D3D11. According to ESSL 3.1 SPEC (Chapter 8.9.3, Page 130), the definition of textureGather on sampler2D is: gvec4 textureGather (gsampler2D sampler, vec2 P[, int comp]) The parameter "comp" is optional, and if it is specified, the value of "comp" must be a constant integer expression with a value of 0, 1, 2, or 3, identifying the x, y, z, or w postswizzled component of the four-component vector lookup result for each texel, respectively. If comp is not specified, it is treated as 0. According to the definition above, textureGather is equivalent to Texture2D.Gather[Red|Green|Blue|Alpha] in HLSL, where we can use a switch-case expression to choose the right HLSL texture function. The features listed here will be implemented in the following patches: 1. Support textureGatherOffset 2. Support textureGather[Offset] on isamplers and usamplers 3. Support textureGather[Offset] on textures when swizzle is on 4. Support textureGather[Offset] on shadow samplers BUG=angleproject:2826 TEST=dEQP-GLES31.functional.texture.gather.basic.2d.rgba8.* dEQP-GLES31.functional.texture.gather.basic.cube.rgba8.* (without texture_swizzle) dEQP-GLES31.functional.texture.gather.basic.2d_array.rgba8.* (without texture_swizzle) Change-Id: Iff2ed4f8b65dad613cb0bafdfd19f8f0528e832c Reviewed-on: https://chromium-review.googlesource.com/1232980 Commit-Queue: Jiawei Shao <jiawei.shao@intel.com> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 4ce287e0
...@@ -381,6 +381,8 @@ void OutputTextureFunctionArgumentList(TInfoSinkBase &out, ...@@ -381,6 +381,8 @@ void OutputTextureFunctionArgumentList(TInfoSinkBase &out,
break; break;
case TextureFunctionHLSL::TextureFunction::GRAD: case TextureFunctionHLSL::TextureFunction::GRAD:
break; break;
case TextureFunctionHLSL::TextureFunction::GATHER:
break;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
...@@ -416,6 +418,10 @@ void OutputTextureFunctionArgumentList(TInfoSinkBase &out, ...@@ -416,6 +418,10 @@ void OutputTextureFunctionArgumentList(TInfoSinkBase &out,
{ {
out << ", float bias"; out << ", float bias";
} }
else if (textureFunction.method == TextureFunctionHLSL::TextureFunction::GATHER)
{
out << ", int comp = 0";
}
} }
void GetTextureReference(TInfoSinkBase &out, void GetTextureReference(TInfoSinkBase &out,
...@@ -812,6 +818,61 @@ void OutputIntegerTextureSampleFunctionComputations( ...@@ -812,6 +818,61 @@ void OutputIntegerTextureSampleFunctionComputations(
} }
} }
void OutputTextureGatherFunctionBody(TInfoSinkBase &out,
const TextureFunctionHLSL::TextureFunction &textureFunction,
ShShaderOutput outputType,
const ImmutableString &textureReference,
const ImmutableString &samplerReference,
const ImmutableString &texCoordX,
const ImmutableString &texCoordY,
const ImmutableString &texCoordZ)
{
const int hlslCoords = GetHLSLCoordCount(textureFunction, outputType);
ImmutableString samplerCoordTypeString(
GetSamplerCoordinateTypeString(textureFunction, hlslCoords));
ImmutableStringBuilder samplerCoordBuilder(
samplerCoordTypeString.length() + strlen("(") + texCoordX.length() + strlen(", ") +
texCoordY.length() + strlen(", ") + texCoordZ.length() + strlen(")"));
samplerCoordBuilder << samplerCoordTypeString << "(" << texCoordX << ", " << texCoordY;
if (hlslCoords >= 3)
{
if (textureFunction.coords < 3)
{
samplerCoordBuilder << ", 0";
}
else
{
samplerCoordBuilder << ", " << texCoordZ;
}
}
samplerCoordBuilder << ")";
ImmutableString samplerCoordString(samplerCoordBuilder);
out << " switch(comp)\n"
" {\n"
" case 0:\n"
" return "
<< textureReference << ".GatherRed(" << samplerReference << ", " << samplerCoordString
<< ");\n"
" case 1:\n"
" return "
<< textureReference << ".GatherGreen(" << samplerReference << ", " << samplerCoordString
<< ");\n"
" case 2:\n"
" return "
<< textureReference << ".GatherBlue(" << samplerReference << ", " << samplerCoordString
<< ");\n"
" case 3:\n"
" return "
<< textureReference << ".GatherAlpha(" << samplerReference << ", " << samplerCoordString
<< ");\n"
" default:\n"
" return float4(0.0, 0.0, 0.0, 1.0);\n"
" }\n";
}
void OutputTextureSampleFunctionReturnStatement( void OutputTextureSampleFunctionReturnStatement(
TInfoSinkBase &out, TInfoSinkBase &out,
const TextureFunctionHLSL::TextureFunction &textureFunction, const TextureFunctionHLSL::TextureFunction &textureFunction,
...@@ -1078,6 +1139,9 @@ ImmutableString TextureFunctionHLSL::TextureFunction::name() const ...@@ -1078,6 +1139,9 @@ ImmutableString TextureFunctionHLSL::TextureFunction::name() const
case GRAD: case GRAD:
name << "Grad"; name << "Grad";
break; break;
case GATHER:
name << "Gather";
break;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
...@@ -1252,6 +1316,10 @@ ImmutableString TextureFunctionHLSL::useTextureFunction(const ImmutableString &n ...@@ -1252,6 +1316,10 @@ ImmutableString TextureFunctionHLSL::useTextureFunction(const ImmutableString &n
textureFunction.proj = true; textureFunction.proj = true;
textureFunction.offset = true; textureFunction.offset = true;
} }
else if (name == "textureGather")
{
textureFunction.method = TextureFunction::GATHER;
}
else else
UNREACHABLE(); UNREACHABLE();
...@@ -1321,13 +1389,21 @@ void TextureFunctionHLSL::textureFunctionHeader(TInfoSinkBase &out, ...@@ -1321,13 +1389,21 @@ void TextureFunctionHLSL::textureFunctionHeader(TInfoSinkBase &out,
ImmutableString texCoordX("t.x"); ImmutableString texCoordX("t.x");
ImmutableString texCoordY("t.y"); ImmutableString texCoordY("t.y");
ImmutableString texCoordZ("t.z"); ImmutableString texCoordZ("t.z");
ProjectTextureCoordinates(textureFunction, &texCoordX, &texCoordY, &texCoordZ); if (textureFunction.method == TextureFunction::GATHER)
OutputIntegerTextureSampleFunctionComputations(out, textureFunction, outputType, {
textureReference, &texCoordX, &texCoordY, OutputTextureGatherFunctionBody(out, textureFunction, outputType, textureReference,
&texCoordZ); samplerReference, texCoordX, texCoordY, texCoordZ);
OutputTextureSampleFunctionReturnStatement(out, textureFunction, outputType, }
textureReference, samplerReference, else
texCoordX, texCoordY, texCoordZ); {
ProjectTextureCoordinates(textureFunction, &texCoordX, &texCoordY, &texCoordZ);
OutputIntegerTextureSampleFunctionComputations(out, textureFunction, outputType,
textureReference, &texCoordX,
&texCoordY, &texCoordZ);
OutputTextureSampleFunctionReturnStatement(out, textureFunction, outputType,
textureReference, samplerReference,
texCoordX, texCoordY, texCoordZ);
}
} }
out << "}\n" out << "}\n"
......
...@@ -37,7 +37,8 @@ class TextureFunctionHLSL final : angle::NonCopyable ...@@ -37,7 +37,8 @@ class TextureFunctionHLSL final : angle::NonCopyable
LOD0BIAS, LOD0BIAS,
SIZE, // textureSize() SIZE, // textureSize()
FETCH, FETCH,
GRAD GRAD,
GATHER
}; };
ImmutableString name() const; ImmutableString name() const;
......
...@@ -42,7 +42,6 @@ ...@@ -42,7 +42,6 @@
1442 OPENGL D3D11 : dEQP-GLES31.functional.program_interface_query.transform_feedback_varying.name_length.vertex_fragment.default_block_struct_member = SKIP 1442 OPENGL D3D11 : dEQP-GLES31.functional.program_interface_query.transform_feedback_varying.name_length.vertex_fragment.default_block_struct_member = SKIP
1442 OPENGL D3D11 : dEQP-GLES31.functional.program_interface_query.transform_feedback_varying.type.vertex_fragment.struct.* = SKIP 1442 OPENGL D3D11 : dEQP-GLES31.functional.program_interface_query.transform_feedback_varying.type.vertex_fragment.struct.* = SKIP
1442 D3D11 : dEQP-GLES31.functional.stencil_texturing.* = SKIP 1442 D3D11 : dEQP-GLES31.functional.stencil_texturing.* = SKIP
1442 D3D11 : dEQP-GLES31.functional.texture.gather.* = SKIP
// TODO(xinghua.cao@intel.com): FAIL expectation instead of SKIP should be sufficient for OpenGL, but the // TODO(xinghua.cao@intel.com): FAIL expectation instead of SKIP should be sufficient for OpenGL, but the
// test expectations parser doesn't support having FAIL for GL and SKIP for D3D with the same test filter. // test expectations parser doesn't support having FAIL for GL and SKIP for D3D with the same test filter.
1442 OPENGL D3D11 : dEQP-GLES31.functional.image_load_store.* = SKIP 1442 OPENGL D3D11 : dEQP-GLES31.functional.image_load_store.* = SKIP
...@@ -1568,6 +1567,18 @@ ...@@ -1568,6 +1567,18 @@
1941 D3D11 : dEQP-GLES31.functional.debug.negative_coverage.callbacks.shader_directive.geometry_shader = FAIL 1941 D3D11 : dEQP-GLES31.functional.debug.negative_coverage.callbacks.shader_directive.geometry_shader = FAIL
1941 D3D11 : dEQP-GLES31.functional.debug.negative_coverage.log.shader_directive.geometry_shader = FAIL 1941 D3D11 : dEQP-GLES31.functional.debug.negative_coverage.log.shader_directive.geometry_shader = FAIL
1941 D3D11 : dEQP-GLES31.functional.debug.negative_coverage.get_error.shader_directive.geometry_shader = FAIL 1941 D3D11 : dEQP-GLES31.functional.debug.negative_coverage.get_error.shader_directive.geometry_shader = FAIL
2826 D3D11 : dEQP-GLES31.functional.texture.gather.basic.2d.depth32f.* = FAIL
2826 D3D11 : dEQP-GLES31.functional.texture.gather.basic.2d.rgba8i.* = FAIL
2826 D3D11 : dEQP-GLES31.functional.texture.gather.basic.2d.rgba8ui.* = FAIL
2826 D3D11 : dEQP-GLES31.functional.texture.gather.basic.2d_array.depth32f.* = FAIL
2826 D3D11 : dEQP-GLES31.functional.texture.gather.basic.2d_array.rgba8.texture_swizzle.* = FAIL
2826 D3D11 : dEQP-GLES31.functional.texture.gather.basic.2d_array.rgba8i.* = FAIL
2826 D3D11 : dEQP-GLES31.functional.texture.gather.basic.2d_array.rgba8ui.* = FAIL
2826 D3D11 : dEQP-GLES31.functional.texture.gather.basic.cube.depth32f.* = FAIL
2826 D3D11 : dEQP-GLES31.functional.texture.gather.basic.cube.rgba8.texture_swizzle.* = FAIL
2826 D3D11 : dEQP-GLES31.functional.texture.gather.basic.cube.rgba8i.* = FAIL
2826 D3D11 : dEQP-GLES31.functional.texture.gather.basic.cube.rgba8ui.* = FAIL
2826 D3D11 : dEQP-GLES31.functional.texture.gather.offset.* = FAIL
// Recetly added tests failing on D3D11 Windows. // Recetly added tests failing on D3D11 Windows.
2619 D3D11 : dEQP-GLES31.functional.shaders.builtin_functions.uniform.findLSBMinusOne.highp_compute = FAIL 2619 D3D11 : dEQP-GLES31.functional.shaders.builtin_functions.uniform.findLSBMinusOne.highp_compute = FAIL
......
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