Fix multisample texture operations crashing HLSL generation
This includes a partial implementation of multisample texture
operations on the HLSL backend. It can't be fully tested yet, since
the API side isn't implemented.
BUG=angleproject:1442
TEST=dEQP-GLES31.functional.shaders.builtin_functions.texture_size.*
(successfully compiles instead of crashing)
Change-Id: Ief782db28388a3f8fd8113cc86ce3c4f500f322a
Reviewed-on: https://chromium-review.googlesource.com/443264
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/TextureFunctionHLSL.cpp b/src/compiler/translator/TextureFunctionHLSL.cpp
index 33d0985..1f3de5f 100644
--- a/src/compiler/translator/TextureFunctionHLSL.cpp
+++ b/src/compiler/translator/TextureFunctionHLSL.cpp
@@ -319,6 +319,8 @@
{
switch (textureFunction.coords)
{
+ case 0:
+ break; // textureSize(gSampler2DMS sampler)
case 1:
out << ", int lod";
break; // textureSize()
@@ -457,48 +459,56 @@
const TString &textureReference,
bool getDimensionsIgnoresBaseLevel)
{
- if (getDimensionsIgnoresBaseLevel)
+ if (IsSampler2DMS(textureFunction.sampler))
{
- out << "int baseLevel = samplerMetadata[samplerIndex].baseLevel;\n";
+ out << " uint width; uint height; uint samples;\n"
+ << " " << textureReference << ".GetDimensions(width, height, samples);\n";
}
else
{
- out << "int baseLevel = 0;\n";
- }
-
- if (IsSampler3D(textureFunction.sampler) || IsSamplerArray(textureFunction.sampler) ||
- (IsIntegerSampler(textureFunction.sampler) && IsSamplerCube(textureFunction.sampler)))
- {
- // "depth" stores either the number of layers in an array texture or 3D depth
- out << " uint width; uint height; uint depth; uint numberOfLevels;\n"
- << " " << textureReference
- << ".GetDimensions(baseLevel, width, height, depth, numberOfLevels);\n"
- << " width = max(width >> lod, 1);\n"
- << " height = max(height >> lod, 1);\n";
-
- if (!IsSamplerArray(textureFunction.sampler))
+ if (getDimensionsIgnoresBaseLevel)
{
- out << " depth = max(depth >> lod, 1);\n";
+ out << " int baseLevel = samplerMetadata[samplerIndex].baseLevel;\n";
}
+ else
+ {
+ out << " int baseLevel = 0;\n";
+ }
+
+ if (IsSampler3D(textureFunction.sampler) || IsSamplerArray(textureFunction.sampler) ||
+ (IsIntegerSampler(textureFunction.sampler) && IsSamplerCube(textureFunction.sampler)))
+ {
+ // "depth" stores either the number of layers in an array texture or 3D depth
+ out << " uint width; uint height; uint depth; uint numberOfLevels;\n"
+ << " " << textureReference
+ << ".GetDimensions(baseLevel, width, height, depth, numberOfLevels);\n"
+ << " width = max(width >> lod, 1);\n"
+ << " height = max(height >> lod, 1);\n";
+
+ if (!IsSamplerArray(textureFunction.sampler))
+ {
+ out << " depth = max(depth >> lod, 1);\n";
+ }
+ }
+ else if (IsSampler2D(textureFunction.sampler) || IsSamplerCube(textureFunction.sampler))
+ {
+ out << " uint width; uint height; uint numberOfLevels;\n"
+ << " " << textureReference
+ << ".GetDimensions(baseLevel, width, height, numberOfLevels);\n"
+ << " width = max(width >> lod, 1);\n"
+ << " height = max(height >> lod, 1);\n";
+ }
+ else
+ UNREACHABLE();
}
- else if (IsSampler2D(textureFunction.sampler) || IsSamplerCube(textureFunction.sampler))
- {
- out << " uint width; uint height; uint numberOfLevels;\n"
- << " " << textureReference
- << ".GetDimensions(baseLevel, width, height, numberOfLevels);\n"
- << " width = max(width >> lod, 1);\n"
- << " height = max(height >> lod, 1);\n";
- }
- else
- UNREACHABLE();
if (strcmp(textureFunction.getReturnType(), "int3") == 0)
{
- out << " return int3(width, height, depth);";
+ out << " return int3(width, height, depth);\n";
}
else
{
- out << " return int2(width, height);";
+ out << " return int2(width, height);\n";
}
}
@@ -1048,6 +1058,9 @@
case EbtUSamplerCube:
case EbtSamplerCubeShadow:
case EbtSamplerExternalOES:
+ case EbtSampler2DMS:
+ case EbtISampler2DMS:
+ case EbtUSampler2DMS:
return "int2";
case EbtSampler3D:
case EbtISampler3D: