Fix invalid generated sampling functions in HLSL output
In some generated shaders, "levels" would be read before it is assigned
by GetDimensions when clamping mip level to valid range. Fix these cases.
BUG=angleproject:1092
TEST=dEQP-GLES3.functional.shaders.texture_functions.*
(12 tests start passing)
Change-Id: I9fce8d378606738e5172673d222bce7968e26789
Reviewed-on: https://chromium-review.googlesource.com/312022
Tryjob-Request: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Tested-by: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/OutputHLSL.cpp b/src/compiler/translator/OutputHLSL.cpp
index dea6fc6..7e8302f 100644
--- a/src/compiler/translator/OutputHLSL.cpp
+++ b/src/compiler/translator/OutputHLSL.cpp
@@ -924,11 +924,12 @@
}
else
{
+
+ out << " x.GetDimensions(0, width, height, layers, levels);\n";
if (textureFunction->method == TextureFunction::IMPLICIT ||
textureFunction->method == TextureFunction::BIAS)
{
- out << " x.GetDimensions(0, width, height, layers, levels);\n"
- " float2 tSized = float2(t.x * width, t.y * height);\n"
+ out << " float2 tSized = float2(t.x * width, t.y * height);\n"
" float dx = length(ddx(tSized));\n"
" float dy = length(ddy(tSized));\n"
" float lod = log2(max(dx, dy));\n";
@@ -940,8 +941,7 @@
}
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 << " float lod = log2(max(length(ddx), length(ddy)));\n";
}
out << " uint mip = uint(min(max(round(lod), 0), levels - 1));\n";
@@ -963,11 +963,12 @@
}
else
{
+ out << " x.GetDimensions(0, width, height, levels);\n";
+
if (textureFunction->method == TextureFunction::IMPLICIT ||
textureFunction->method == TextureFunction::BIAS)
{
- out << " x.GetDimensions(0, width, height, levels);\n"
- " float2 tSized = float2(t.x * width, t.y * height);\n"
+ out << " float2 tSized = float2(t.x * width, t.y * height);\n"
" float dx = length(ddx(tSized));\n"
" float dy = length(ddy(tSized));\n"
" float lod = log2(max(dx, dy));\n";
@@ -977,14 +978,9 @@
out << " lod += bias;\n";
}
}
- else if (textureFunction->method == TextureFunction::LOD)
- {
- 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 << " float lod = log2(max(length(ddx), length(ddy)));\n";
}
out << " uint mip = uint(min(max(round(lod), 0), levels - 1));\n";
@@ -1007,11 +1003,13 @@
}
else
{
+ out << " x.GetDimensions(0, width, height, depth, levels);\n";
+
if (textureFunction->method == TextureFunction::IMPLICIT ||
textureFunction->method == TextureFunction::BIAS)
{
- out << " x.GetDimensions(0, width, height, depth, levels);\n"
- " float3 tSized = float3(t.x * width, t.y * height, t.z * depth);\n"
+ out << " float3 tSized = float3(t.x * width, t.y * height, t.z * "
+ "depth);\n"
" float dx = length(ddx(tSized));\n"
" float dy = length(ddy(tSized));\n"
" float lod = log2(max(dx, dy));\n";
@@ -1023,8 +1021,7 @@
}
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 << " float lod = log2(max(length(ddx), length(ddy)));\n";
}
out << " uint mip = uint(min(max(round(lod), 0), levels - 1));\n";