Commit d4102f09 by Olli Etuaho Committed by Commit Bot

Refactor HLSL texture coordinate output to prepare for wrap modes

Wrap modes for integer textures need to be implemented in shaders in HLSL. This requires more complex transformations on the texture coordinates, so store the texture coordinate code for each texture coordinate in a string variable. BUG=angleproject:1244 TEST=dEQP-GLES3.functional.shaders.texture_functions.* (no regression), dEQP-GLES3.functional.texture.units.* (no regression) Change-Id: Iadd9617a7f906aa1d56dabfba6639f932152e6f1 Reviewed-on: https://chromium-review.googlesource.com/336637Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 54f8746e
......@@ -912,6 +912,32 @@ void OutputHLSL::header(TInfoSinkBase &out, const BuiltInFunctionEmulator *built
}
else
{
TString texCoordX("t.x");
TString texCoordY("t.y");
TString texCoordZ("t.z");
TString proj = "";
if (textureFunction->proj)
{
switch (textureFunction->coords)
{
case 3:
proj = " / t.z";
break;
case 4:
proj = " / t.w";
break;
default:
UNREACHABLE();
}
if (proj != "")
{
texCoordX = "(" + texCoordX + proj + ")";
texCoordY = "(" + texCoordY + proj + ")";
texCoordZ = "(" + texCoordZ + proj + ")";
}
}
if (IsIntegerSampler(textureFunction->sampler) && IsSamplerCube(textureFunction->sampler))
{
out << " float width; float height; float layers; float levels;\n";
......@@ -952,6 +978,11 @@ void OutputHLSL::header(TInfoSinkBase &out, const BuiltInFunctionEmulator *built
<< " " << textureReference
<< ".GetDimensions(mip, width, height, layers, levels);\n";
}
// Convert from normalized floating-point to integer
texCoordX = "int(floor(width * frac(" + texCoordX + ")))";
texCoordY = "int(floor(height * frac(" + texCoordY + ")))";
texCoordZ = "face";
}
else if (IsIntegerSampler(textureFunction->sampler) &&
textureFunction->method != TextureFunction::FETCH)
......@@ -1084,6 +1115,20 @@ void OutputHLSL::header(TInfoSinkBase &out, const BuiltInFunctionEmulator *built
<< ".GetDimensions(mip, width, height, depth, levels);\n";
}
else UNREACHABLE();
// Convert from normalized floating-point to integer
texCoordX = "int(floor(width * frac(" + texCoordX + ")))";
texCoordY = "int(floor(height * frac(" + texCoordY + ")))";
if (IsSamplerArray(textureFunction->sampler))
{
texCoordZ = "int(max(0, min(layers - 1, floor(0.5 + t.z))))";
}
else if (!IsSamplerCube(textureFunction->sampler) &&
!IsSampler2D(textureFunction->sampler))
{
texCoordZ = "int(floor(depth * frac(" + texCoordZ + ")))";
}
}
out << " return ";
......@@ -1197,12 +1242,6 @@ void OutputHLSL::header(TInfoSinkBase &out, const BuiltInFunctionEmulator *built
}
else UNREACHABLE();
// Integer sampling requires integer addresses
TString addressx = "";
TString addressy = "";
TString addressz = "";
TString close = "";
if (IsIntegerSampler(textureFunction->sampler) ||
textureFunction->method == TextureFunction::FETCH)
{
......@@ -1212,28 +1251,6 @@ void OutputHLSL::header(TInfoSinkBase &out, const BuiltInFunctionEmulator *built
case 3: out << "int4("; break;
default: UNREACHABLE();
}
// Convert from normalized floating-point to integer
if (textureFunction->method != TextureFunction::FETCH)
{
addressx = "int(floor(width * frac((";
addressy = "int(floor(height * frac((";
if (IsSamplerArray(textureFunction->sampler))
{
addressz = "int(max(0, min(layers - 1, floor(0.5 + ";
}
else if (IsSamplerCube(textureFunction->sampler))
{
addressz = "((((";
}
else
{
addressz = "int(floor(depth * frac((";
}
close = "))))";
}
}
else
{
......@@ -1246,19 +1263,7 @@ void OutputHLSL::header(TInfoSinkBase &out, const BuiltInFunctionEmulator *built
}
}
TString proj = ""; // Only used for projected textures
if (textureFunction->proj)
{
switch(textureFunction->coords)
{
case 3: proj = " / t.z"; break;
case 4: proj = " / t.w"; break;
default: UNREACHABLE();
}
}
out << addressx + ("t.x" + proj) + close + ", " + addressy + ("t.y" + proj) + close;
out << texCoordX << ", " << texCoordY;
if (mOutputType == SH_HLSL_3_0_OUTPUT)
{
......@@ -1270,7 +1275,7 @@ void OutputHLSL::header(TInfoSinkBase &out, const BuiltInFunctionEmulator *built
}
else
{
out << ", t.z" + proj;
out << ", t.z" << proj;
}
}
......@@ -1292,14 +1297,9 @@ void OutputHLSL::header(TInfoSinkBase &out, const BuiltInFunctionEmulator *built
{
if (hlslCoords >= 3)
{
if (IsIntegerSampler(textureFunction->sampler) && IsSamplerCube(textureFunction->sampler))
{
out << ", face";
}
else
{
out << ", " + addressz + ("t.z" + proj) + close;
}
ASSERT(!IsIntegerSampler(textureFunction->sampler) ||
!IsSamplerCube(textureFunction->sampler) || texCoordZ == "face");
out << ", " << texCoordZ;
}
if (textureFunction->method == TextureFunction::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