JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2017 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // TextureMultisampleTest: Tests of multisampled texture |
| 8 | |
| 9 | #include "test_utils/ANGLETest.h" |
Olli Etuaho | dff32a0 | 2018-08-28 14:35:50 +0300 | [diff] [blame] | 10 | |
| 11 | #include "shader_utils.h" |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 12 | #include "test_utils/gl_raii.h" |
| 13 | |
| 14 | using namespace angle; |
| 15 | |
| 16 | namespace |
| 17 | { |
Jiang | 0e1224c | 2017-12-26 14:11:15 +0800 | [diff] [blame] | 18 | // Sample positions of d3d standard pattern. Some of the sample positions might not the same as |
| 19 | // opengl. |
| 20 | using SamplePositionsArray = std::array<float, 32>; |
| 21 | static constexpr std::array<SamplePositionsArray, 5> kSamplePositions = { |
| 22 | {{{0.5f, 0.5f}}, |
| 23 | {{0.75f, 0.75f, 0.25f, 0.25f}}, |
| 24 | {{0.375f, 0.125f, 0.875f, 0.375f, 0.125f, 0.625f, 0.625f, 0.875f}}, |
| 25 | {{0.5625f, 0.3125f, 0.4375f, 0.6875f, 0.8125f, 0.5625f, 0.3125f, 0.1875f, 0.1875f, 0.8125f, |
| 26 | 0.0625f, 0.4375f, 0.6875f, 0.9375f, 0.9375f, 0.0625f}}, |
| 27 | {{0.5625f, 0.5625f, 0.4375f, 0.3125f, 0.3125f, 0.625f, 0.75f, 0.4375f, |
| 28 | 0.1875f, 0.375f, 0.625f, 0.8125f, 0.8125f, 0.6875f, 0.6875f, 0.1875f, |
| 29 | 0.375f, 0.875f, 0.5f, 0.0625f, 0.25f, 0.125f, 0.125f, 0.75f, |
| 30 | 0.0f, 0.5f, 0.9375f, 0.25f, 0.875f, 0.9375f, 0.0625f, 0.0f}}}}; |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 31 | |
| 32 | class TextureMultisampleTest : public ANGLETest |
| 33 | { |
| 34 | protected: |
| 35 | TextureMultisampleTest() |
| 36 | { |
| 37 | setWindowWidth(64); |
| 38 | setWindowHeight(64); |
| 39 | setConfigRedBits(8); |
| 40 | setConfigGreenBits(8); |
| 41 | setConfigBlueBits(8); |
| 42 | setConfigAlphaBits(8); |
| 43 | } |
| 44 | |
| 45 | void SetUp() override |
| 46 | { |
| 47 | ANGLETest::SetUp(); |
| 48 | |
| 49 | glGenFramebuffers(1, &mFramebuffer); |
| 50 | glGenTextures(1, &mTexture); |
| 51 | |
| 52 | ASSERT_GL_NO_ERROR(); |
| 53 | } |
| 54 | |
| 55 | void TearDown() override |
| 56 | { |
| 57 | glDeleteFramebuffers(1, &mFramebuffer); |
| 58 | mFramebuffer = 0; |
| 59 | glDeleteTextures(1, &mTexture); |
| 60 | mTexture = 0; |
| 61 | |
| 62 | ANGLETest::TearDown(); |
| 63 | } |
| 64 | |
| 65 | GLuint mFramebuffer = 0; |
| 66 | GLuint mTexture = 0; |
Olli Etuaho | fd16210 | 2018-08-27 16:14:57 +0300 | [diff] [blame] | 67 | |
| 68 | // Returns a sample count that can be used with the given texture target for all the given |
| 69 | // formats. Assumes that if format A supports a number of samples N and another format B |
| 70 | // supports a number of samples M > N then format B also supports number of samples N. |
| 71 | GLint getSamplesToUse(GLenum texTarget, const std::vector<GLenum> &formats) |
| 72 | { |
| 73 | GLint maxSamples = 65536; |
| 74 | for (GLenum format : formats) |
| 75 | { |
| 76 | GLint maxSamplesFormat = 0; |
| 77 | glGetInternalformativ(texTarget, format, GL_SAMPLES, 1, &maxSamplesFormat); |
| 78 | maxSamples = std::min(maxSamples, maxSamplesFormat); |
| 79 | } |
| 80 | return maxSamples; |
| 81 | } |
Olli Etuaho | dff32a0 | 2018-08-28 14:35:50 +0300 | [diff] [blame] | 82 | |
| 83 | const char *blitArrayTextureLayerFragmentShader() |
| 84 | { |
| 85 | return R"(#version 310 es |
| 86 | #extension GL_OES_texture_storage_multisample_2d_array : require |
| 87 | precision highp float; |
| 88 | precision highp int; |
| 89 | |
| 90 | uniform highp sampler2DMSArray tex; |
| 91 | uniform int layer; |
| 92 | uniform int sampleNum; |
| 93 | |
| 94 | in vec4 v_position; |
| 95 | out vec4 my_FragColor; |
| 96 | |
| 97 | void main() { |
| 98 | ivec3 texSize = textureSize(tex); |
| 99 | ivec2 sampleCoords = ivec2((v_position.xy * 0.5 + 0.5) * vec2(texSize.xy - 1)); |
| 100 | my_FragColor = texelFetch(tex, ivec3(sampleCoords, layer), sampleNum); |
| 101 | } |
| 102 | )"; |
| 103 | }; |
| 104 | |
| 105 | const char *blitIntArrayTextureLayerFragmentShader() |
| 106 | { |
| 107 | return R"(#version 310 es |
| 108 | #extension GL_OES_texture_storage_multisample_2d_array : require |
| 109 | precision highp float; |
| 110 | precision highp int; |
| 111 | |
| 112 | uniform highp isampler2DMSArray tex; |
| 113 | uniform int layer; |
| 114 | uniform int sampleNum; |
| 115 | |
| 116 | in vec4 v_position; |
| 117 | out vec4 my_FragColor; |
| 118 | |
| 119 | void main() { |
| 120 | ivec3 texSize = textureSize(tex); |
| 121 | ivec2 sampleCoords = ivec2((v_position.xy * 0.5 + 0.5) * vec2(texSize.xy - 1)); |
| 122 | my_FragColor = vec4(texelFetch(tex, ivec3(sampleCoords, layer), sampleNum)); |
| 123 | } |
| 124 | )"; |
| 125 | }; |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | class TextureMultisampleTestES31 : public TextureMultisampleTest |
| 129 | { |
| 130 | protected: |
| 131 | TextureMultisampleTestES31() : TextureMultisampleTest() {} |
| 132 | }; |
| 133 | |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 134 | class TextureMultisampleArrayWebGLTest : public TextureMultisampleTest |
| 135 | { |
| 136 | protected: |
| 137 | TextureMultisampleArrayWebGLTest() : TextureMultisampleTest() |
| 138 | { |
| 139 | // These tests run in WebGL mode so we can test with both extension off and on. |
| 140 | setWebGLCompatibilityEnabled(true); |
| 141 | } |
| 142 | |
| 143 | // Requests the ANGLE_texture_multisample_array extension and returns true if the operation |
| 144 | // succeeds. |
| 145 | bool requestArrayExtension() |
| 146 | { |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 147 | if (extensionRequestable("GL_OES_texture_storage_multisample_2d_array")) |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 148 | { |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 149 | glRequestExtensionANGLE("GL_OES_texture_storage_multisample_2d_array"); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 150 | } |
| 151 | |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 152 | if (!extensionEnabled("GL_OES_texture_storage_multisample_2d_array")) |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 153 | { |
| 154 | return false; |
| 155 | } |
| 156 | return true; |
| 157 | } |
| 158 | }; |
| 159 | |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 160 | // Tests that if es version < 3.1, GL_TEXTURE_2D_MULTISAMPLE is not supported in |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 161 | // GetInternalformativ. Checks that the number of samples returned is valid in case of ES >= 3.1. |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 162 | TEST_P(TextureMultisampleTest, MultisampleTargetGetInternalFormativBase) |
| 163 | { |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 164 | // This query returns supported sample counts in descending order. If only one sample count is |
| 165 | // queried, it should be the maximum one. |
| 166 | GLint maxSamplesR8 = 0; |
| 167 | glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE, GL_R8, GL_SAMPLES, 1, &maxSamplesR8); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 168 | if (getClientMajorVersion() < 3 || getClientMinorVersion() < 1) |
| 169 | { |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 170 | ASSERT_GL_ERROR(GL_INVALID_ENUM); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 171 | } |
| 172 | else |
| 173 | { |
| 174 | ASSERT_GL_NO_ERROR(); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 175 | |
| 176 | // GLES 3.1 section 19.3.1 specifies the required minimum of how many samples are supported. |
| 177 | GLint maxColorTextureSamples; |
| 178 | glGetIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, &maxColorTextureSamples); |
| 179 | GLint maxSamples; |
| 180 | glGetIntegerv(GL_MAX_SAMPLES, &maxSamples); |
| 181 | GLint maxSamplesR8Required = std::min(maxColorTextureSamples, maxSamples); |
| 182 | |
| 183 | EXPECT_GE(maxSamplesR8, maxSamplesR8Required); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | |
| 187 | // Tests that if es version < 3.1, GL_TEXTURE_2D_MULTISAMPLE is not supported in |
| 188 | // FramebufferTexture2D. |
| 189 | TEST_P(TextureMultisampleTest, MultisampleTargetFramebufferTexture2D) |
| 190 | { |
| 191 | GLint samples = 1; |
| 192 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTexture); |
| 193 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, GL_RGBA8, 64, 64, GL_FALSE); |
| 194 | if (getClientMajorVersion() < 3 || getClientMinorVersion() < 1) |
| 195 | { |
| 196 | ASSERT_GL_ERROR(GL_INVALID_ENUM); |
| 197 | } |
| 198 | else |
| 199 | { |
| 200 | ASSERT_GL_NO_ERROR(); |
| 201 | } |
| 202 | |
| 203 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); |
| 204 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, |
| 205 | mTexture, 0); |
| 206 | if (getClientMajorVersion() < 3 || getClientMinorVersion() < 1) |
| 207 | { |
| 208 | ASSERT_GL_ERROR(GL_INVALID_OPERATION); |
| 209 | } |
| 210 | else |
| 211 | { |
| 212 | ASSERT_GL_NO_ERROR(); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | // Tests basic functionality of glTexStorage2DMultisample. |
| 217 | TEST_P(TextureMultisampleTestES31, ValidateTextureStorageMultisampleParameters) |
| 218 | { |
| 219 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTexture); |
| 220 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, GL_FALSE); |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 221 | ASSERT_GL_NO_ERROR(); |
| 222 | |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 223 | GLint params = 0; |
| 224 | glGetTexParameteriv(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_IMMUTABLE_FORMAT, ¶ms); |
| 225 | EXPECT_EQ(1, params); |
| 226 | |
| 227 | glTexStorage2DMultisample(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1, GL_FALSE); |
| 228 | ASSERT_GL_ERROR(GL_INVALID_ENUM); |
| 229 | |
| 230 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 0, 0, GL_FALSE); |
| 231 | ASSERT_GL_ERROR(GL_INVALID_VALUE); |
| 232 | |
| 233 | GLint maxSize = 0; |
| 234 | glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize); |
| 235 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, maxSize + 1, 1, GL_FALSE); |
| 236 | ASSERT_GL_ERROR(GL_INVALID_VALUE); |
| 237 | |
| 238 | GLint maxSamples = 0; |
| 239 | glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE, GL_R8, GL_SAMPLES, 1, &maxSamples); |
| 240 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, maxSamples + 1, GL_RGBA8, 1, 1, GL_FALSE); |
| 241 | ASSERT_GL_ERROR(GL_INVALID_OPERATION); |
| 242 | |
| 243 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 0, GL_RGBA8, 1, 1, GL_FALSE); |
| 244 | ASSERT_GL_ERROR(GL_INVALID_VALUE); |
| 245 | |
| 246 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA, 0, 0, GL_FALSE); |
| 247 | ASSERT_GL_ERROR(GL_INVALID_VALUE); |
| 248 | |
| 249 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0); |
| 250 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, GL_FALSE); |
| 251 | ASSERT_GL_ERROR(GL_INVALID_OPERATION); |
| 252 | } |
| 253 | |
Shao | 5116d68 | 2017-08-02 12:39:44 +0800 | [diff] [blame] | 254 | // Tests the value of MAX_INTEGER_SAMPLES is no less than 1. |
| 255 | // [OpenGL ES 3.1 SPEC Table 20.40] |
| 256 | TEST_P(TextureMultisampleTestES31, MaxIntegerSamples) |
| 257 | { |
| 258 | GLint maxIntegerSamples; |
| 259 | glGetIntegerv(GL_MAX_INTEGER_SAMPLES, &maxIntegerSamples); |
| 260 | EXPECT_GE(maxIntegerSamples, 1); |
| 261 | EXPECT_NE(std::numeric_limits<GLint>::max(), maxIntegerSamples); |
| 262 | } |
| 263 | |
| 264 | // Tests the value of MAX_COLOR_TEXTURE_SAMPLES is no less than 1. |
| 265 | // [OpenGL ES 3.1 SPEC Table 20.40] |
| 266 | TEST_P(TextureMultisampleTestES31, MaxColorTextureSamples) |
| 267 | { |
| 268 | GLint maxColorTextureSamples; |
| 269 | glGetIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, &maxColorTextureSamples); |
| 270 | EXPECT_GE(maxColorTextureSamples, 1); |
| 271 | EXPECT_NE(std::numeric_limits<GLint>::max(), maxColorTextureSamples); |
| 272 | } |
| 273 | |
| 274 | // Tests the value of MAX_DEPTH_TEXTURE_SAMPLES is no less than 1. |
| 275 | // [OpenGL ES 3.1 SPEC Table 20.40] |
| 276 | TEST_P(TextureMultisampleTestES31, MaxDepthTextureSamples) |
| 277 | { |
| 278 | GLint maxDepthTextureSamples; |
| 279 | glGetIntegerv(GL_MAX_DEPTH_TEXTURE_SAMPLES, &maxDepthTextureSamples); |
| 280 | EXPECT_GE(maxDepthTextureSamples, 1); |
| 281 | EXPECT_NE(std::numeric_limits<GLint>::max(), maxDepthTextureSamples); |
| 282 | } |
| 283 | |
Jiang | 0e1224c | 2017-12-26 14:11:15 +0800 | [diff] [blame] | 284 | // The value of sample position should be equal to standard pattern on D3D. |
| 285 | TEST_P(TextureMultisampleTestES31, CheckSamplePositions) |
| 286 | { |
| 287 | ANGLE_SKIP_TEST_IF(!IsD3D11()); |
| 288 | |
| 289 | GLsizei maxSamples = 0; |
| 290 | glGetIntegerv(GL_MAX_SAMPLES, &maxSamples); |
| 291 | |
| 292 | GLfloat samplePosition[2]; |
| 293 | |
| 294 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mFramebuffer); |
| 295 | |
| 296 | for (int sampleCount = 1; sampleCount <= maxSamples; sampleCount++) |
| 297 | { |
| 298 | GLTexture texture; |
| 299 | size_t indexKey = static_cast<size_t>(ceil(log2(sampleCount))); |
| 300 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, texture); |
| 301 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, sampleCount, GL_RGBA8, 1, 1, GL_TRUE); |
| 302 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, |
| 303 | texture, 0); |
| 304 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 305 | ASSERT_GL_NO_ERROR(); |
| 306 | |
| 307 | for (int sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++) |
| 308 | { |
| 309 | glGetMultisamplefv(GL_SAMPLE_POSITION, sampleIndex, samplePosition); |
| 310 | EXPECT_EQ(samplePosition[0], kSamplePositions[indexKey][2 * sampleIndex]); |
| 311 | EXPECT_EQ(samplePosition[1], kSamplePositions[indexKey][2 * sampleIndex + 1]); |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | ASSERT_GL_NO_ERROR(); |
| 316 | } |
| 317 | |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 318 | // Tests that GL_TEXTURE_2D_MULTISAMPLE_ARRAY is not supported in GetInternalformativ when the |
| 319 | // extension is not supported. |
| 320 | TEST_P(TextureMultisampleArrayWebGLTest, MultisampleArrayTargetGetInternalFormativWithoutExtension) |
| 321 | { |
| 322 | GLint maxSamples = 0; |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 323 | glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_RGBA8, GL_SAMPLES, 1, |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 324 | &maxSamples); |
| 325 | ASSERT_GL_ERROR(GL_INVALID_ENUM); |
| 326 | } |
| 327 | |
| 328 | // Attempt to bind a texture to multisample array binding point when extension is not supported. |
| 329 | TEST_P(TextureMultisampleArrayWebGLTest, BindMultisampleArrayTextureWithoutExtension) |
| 330 | { |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 331 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, mTexture); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 332 | ASSERT_GL_ERROR(GL_INVALID_ENUM); |
| 333 | } |
| 334 | |
Olli Etuaho | dff32a0 | 2018-08-28 14:35:50 +0300 | [diff] [blame] | 335 | // Try to compile shaders using GL_OES_texture_storage_multisample_2d_array when the extension is |
| 336 | // not enabled. |
| 337 | TEST_P(TextureMultisampleArrayWebGLTest, ShaderWithoutExtension) |
| 338 | { |
| 339 | const std::string &fragmentShaderRequireExtension = R"(#version 310 es |
| 340 | #extension GL_OES_texture_storage_multisample_2d_array : require |
| 341 | out highp vec4 my_FragColor; |
| 342 | |
| 343 | void main() { |
| 344 | my_FragColor = vec4(0.0); |
| 345 | } |
| 346 | )"; |
| 347 | |
| 348 | GLuint program = CompileProgram(essl31_shaders::vs::Simple(), fragmentShaderRequireExtension); |
| 349 | EXPECT_EQ(0u, program); |
| 350 | |
| 351 | const std::string &fragmentShaderEnableAndUseExtension = R"(#version 310 es |
| 352 | #extension GL_OES_texture_storage_multisample_2d_array : enable |
| 353 | |
| 354 | uniform highp sampler2DMSArray tex; |
| 355 | out highp ivec4 outSize; |
| 356 | |
| 357 | void main() { |
| 358 | outSize = ivec4(textureSize(tex), 0); |
| 359 | } |
| 360 | )"; |
| 361 | |
| 362 | program = CompileProgram(essl31_shaders::vs::Simple(), fragmentShaderEnableAndUseExtension); |
| 363 | EXPECT_EQ(0u, program); |
| 364 | } |
| 365 | |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 366 | // Tests that GL_TEXTURE_2D_MULTISAMPLE_ARRAY is supported in GetInternalformativ. |
| 367 | TEST_P(TextureMultisampleArrayWebGLTest, MultisampleArrayTargetGetInternalFormativ) |
| 368 | { |
| 369 | ANGLE_SKIP_TEST_IF(!requestArrayExtension()); |
| 370 | |
| 371 | // This query returns supported sample counts in descending order. If only one sample count is |
| 372 | // queried, it should be the maximum one. |
| 373 | GLint maxSamplesRGBA8 = 0; |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 374 | glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_RGBA8, GL_SAMPLES, 1, |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 375 | &maxSamplesRGBA8); |
Olli Etuaho | fd16210 | 2018-08-27 16:14:57 +0300 | [diff] [blame] | 376 | GLint maxSamplesDepth = 0; |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 377 | glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_DEPTH_COMPONENT24, GL_SAMPLES, 1, |
| 378 | &maxSamplesDepth); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 379 | ASSERT_GL_NO_ERROR(); |
| 380 | |
| 381 | // GLES 3.1 section 19.3.1 specifies the required minimum of how many samples are supported. |
| 382 | GLint maxColorTextureSamples; |
| 383 | glGetIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, &maxColorTextureSamples); |
Olli Etuaho | fd16210 | 2018-08-27 16:14:57 +0300 | [diff] [blame] | 384 | GLint maxDepthTextureSamples; |
| 385 | glGetIntegerv(GL_MAX_DEPTH_TEXTURE_SAMPLES, &maxDepthTextureSamples); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 386 | GLint maxSamples; |
| 387 | glGetIntegerv(GL_MAX_SAMPLES, &maxSamples); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 388 | |
Olli Etuaho | fd16210 | 2018-08-27 16:14:57 +0300 | [diff] [blame] | 389 | GLint maxSamplesRGBA8Required = std::min(maxColorTextureSamples, maxSamples); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 390 | EXPECT_GE(maxSamplesRGBA8, maxSamplesRGBA8Required); |
Olli Etuaho | fd16210 | 2018-08-27 16:14:57 +0300 | [diff] [blame] | 391 | |
| 392 | GLint maxSamplesDepthRequired = std::min(maxDepthTextureSamples, maxSamples); |
| 393 | EXPECT_GE(maxSamplesDepth, maxSamplesDepthRequired); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | // Tests that TexImage3D call cannot be used for GL_TEXTURE_2D_MULTISAMPLE_ARRAY. |
| 397 | TEST_P(TextureMultisampleArrayWebGLTest, MultiSampleArrayTexImage) |
| 398 | { |
| 399 | ANGLE_SKIP_TEST_IF(!requestArrayExtension()); |
| 400 | |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 401 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, mTexture); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 402 | ASSERT_GL_NO_ERROR(); |
| 403 | |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 404 | glTexImage3D(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 405 | GL_UNSIGNED_BYTE, nullptr); |
| 406 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 407 | } |
| 408 | |
| 409 | // Tests passing invalid parameters to TexStorage3DMultisample. |
| 410 | TEST_P(TextureMultisampleArrayWebGLTest, InvalidTexStorage3DMultisample) |
| 411 | { |
| 412 | ANGLE_SKIP_TEST_IF(!requestArrayExtension()); |
| 413 | |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 414 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, mTexture); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 415 | ASSERT_GL_NO_ERROR(); |
| 416 | |
| 417 | // Invalid target |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 418 | glTexStorage3DMultisampleOES(GL_TEXTURE_2D_MULTISAMPLE, 2, GL_RGBA8, 1, 1, 1, GL_TRUE); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 419 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 420 | |
| 421 | // Samples 0 |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 422 | glTexStorage3DMultisampleOES(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 0, GL_RGBA8, 1, 1, 1, |
| 423 | GL_TRUE); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 424 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 425 | |
| 426 | // Unsized internalformat |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 427 | glTexStorage3DMultisampleOES(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 2, GL_RGBA, 1, 1, 1, GL_TRUE); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 428 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 429 | |
| 430 | // Width 0 |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 431 | glTexStorage3DMultisampleOES(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 2, GL_RGBA8, 0, 1, 1, |
| 432 | GL_TRUE); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 433 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 434 | |
| 435 | // Height 0 |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 436 | glTexStorage3DMultisampleOES(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 2, GL_RGBA8, 1, 0, 1, |
| 437 | GL_TRUE); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 438 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 439 | |
| 440 | // Depth 0 |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 441 | glTexStorage3DMultisampleOES(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 2, GL_RGBA8, 1, 1, 0, |
| 442 | GL_TRUE); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 443 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 444 | } |
| 445 | |
| 446 | // Tests passing invalid parameters to TexParameteri. |
| 447 | TEST_P(TextureMultisampleArrayWebGLTest, InvalidTexParameteri) |
| 448 | { |
| 449 | ANGLE_SKIP_TEST_IF(!requestArrayExtension()); |
| 450 | |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 451 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, mTexture); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 452 | ASSERT_GL_NO_ERROR(); |
| 453 | |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 454 | // None of the sampler parameters can be set on GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES. |
| 455 | glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 456 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 457 | glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 458 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 459 | |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 460 | glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 461 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 462 | glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 463 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 464 | glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 465 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 466 | |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 467 | glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_TEXTURE_MIN_LOD, 0); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 468 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 469 | glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_TEXTURE_MAX_LOD, 0); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 470 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 471 | |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 472 | glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_TEXTURE_COMPARE_MODE, GL_NONE); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 473 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 474 | glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_TEXTURE_COMPARE_FUNC, GL_ALWAYS); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 475 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 476 | |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 477 | // Only valid base level on GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES is 0. |
| 478 | glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_TEXTURE_BASE_LEVEL, 1); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 479 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 480 | } |
| 481 | |
Olli Etuaho | 0c5a9e2 | 2018-08-27 14:36:23 +0300 | [diff] [blame] | 482 | // Test a valid TexStorage3DMultisample call and check that the queried texture level parameters |
| 483 | // match. Does not do any drawing. |
| 484 | TEST_P(TextureMultisampleArrayWebGLTest, TexStorage3DMultisample) |
| 485 | { |
| 486 | ANGLE_SKIP_TEST_IF(!requestArrayExtension()); |
| 487 | |
| 488 | GLint maxSamplesRGBA8 = 0; |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 489 | glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_RGBA8, GL_SAMPLES, 1, |
Olli Etuaho | 0c5a9e2 | 2018-08-27 14:36:23 +0300 | [diff] [blame] | 490 | &maxSamplesRGBA8); |
| 491 | |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 492 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, mTexture); |
Olli Etuaho | 0c5a9e2 | 2018-08-27 14:36:23 +0300 | [diff] [blame] | 493 | ASSERT_GL_NO_ERROR(); |
| 494 | |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 495 | glTexStorage3DMultisampleOES(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, maxSamplesRGBA8, GL_RGBA8, 8, |
| 496 | 4, 2, GL_TRUE); |
Olli Etuaho | 0c5a9e2 | 2018-08-27 14:36:23 +0300 | [diff] [blame] | 497 | ASSERT_GL_NO_ERROR(); |
| 498 | |
| 499 | GLint width = 0, height = 0, depth = 0, samples = 0; |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 500 | glGetTexLevelParameteriv(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 0, GL_TEXTURE_WIDTH, &width); |
| 501 | glGetTexLevelParameteriv(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 0, GL_TEXTURE_HEIGHT, &height); |
| 502 | glGetTexLevelParameteriv(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 0, GL_TEXTURE_DEPTH, &depth); |
| 503 | glGetTexLevelParameteriv(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 0, GL_TEXTURE_SAMPLES, &samples); |
Olli Etuaho | 0c5a9e2 | 2018-08-27 14:36:23 +0300 | [diff] [blame] | 504 | ASSERT_GL_NO_ERROR(); |
| 505 | |
| 506 | EXPECT_EQ(8, width); |
| 507 | EXPECT_EQ(4, height); |
| 508 | EXPECT_EQ(2, depth); |
| 509 | EXPECT_EQ(maxSamplesRGBA8, samples); |
| 510 | } |
| 511 | |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 512 | // Test for invalid FramebufferTextureLayer calls with GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES |
Olli Etuaho | fd16210 | 2018-08-27 16:14:57 +0300 | [diff] [blame] | 513 | // textures. |
| 514 | TEST_P(TextureMultisampleArrayWebGLTest, InvalidFramebufferTextureLayer) |
| 515 | { |
| 516 | ANGLE_SKIP_TEST_IF(!requestArrayExtension()); |
| 517 | |
| 518 | GLint maxSamplesRGBA8 = 0; |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 519 | glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_RGBA8, GL_SAMPLES, 1, |
Olli Etuaho | fd16210 | 2018-08-27 16:14:57 +0300 | [diff] [blame] | 520 | &maxSamplesRGBA8); |
| 521 | |
| 522 | GLint maxArrayTextureLayers; |
| 523 | glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &maxArrayTextureLayers); |
| 524 | |
| 525 | // Test framebuffer status with just a color texture attached. |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 526 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, mTexture); |
| 527 | glTexStorage3DMultisampleOES(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, maxSamplesRGBA8, GL_RGBA8, 4, |
| 528 | 4, 2, GL_TRUE); |
Olli Etuaho | fd16210 | 2018-08-27 16:14:57 +0300 | [diff] [blame] | 529 | ASSERT_GL_NO_ERROR(); |
| 530 | |
| 531 | // Test with mip level 1 and -1 (only level 0 is valid for multisample textures). |
| 532 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); |
| 533 | glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTexture, 1, 0); |
| 534 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 535 | glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTexture, -1, 0); |
| 536 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 537 | |
| 538 | // Test with layer -1 and layer == MAX_ARRAY_TEXTURE_LAYERS |
| 539 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); |
| 540 | glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTexture, 0, -1); |
| 541 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 542 | glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTexture, 0, |
| 543 | maxArrayTextureLayers); |
| 544 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 545 | } |
| 546 | |
| 547 | // Attach layers of TEXTURE_2D_MULTISAMPLE_ARRAY textures to a framebuffer and check for |
| 548 | // completeness. |
| 549 | TEST_P(TextureMultisampleArrayWebGLTest, FramebufferCompleteness) |
| 550 | { |
| 551 | ANGLE_SKIP_TEST_IF(!requestArrayExtension()); |
| 552 | |
| 553 | std::vector<GLenum> testFormats = {{GL_RGBA8, GL_DEPTH_COMPONENT24, GL_DEPTH24_STENCIL8}}; |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 554 | GLint samplesToUse = getSamplesToUse(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, testFormats); |
Olli Etuaho | fd16210 | 2018-08-27 16:14:57 +0300 | [diff] [blame] | 555 | |
| 556 | // Test framebuffer status with just a color texture attached. |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 557 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, mTexture); |
| 558 | glTexStorage3DMultisampleOES(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, samplesToUse, GL_RGBA8, 4, 4, |
| 559 | 2, GL_TRUE); |
Olli Etuaho | fd16210 | 2018-08-27 16:14:57 +0300 | [diff] [blame] | 560 | ASSERT_GL_NO_ERROR(); |
| 561 | |
| 562 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); |
| 563 | glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTexture, 0, 0); |
| 564 | ASSERT_GL_NO_ERROR(); |
| 565 | |
| 566 | GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); |
| 567 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, status); |
| 568 | |
| 569 | // Test framebuffer status with both color and depth textures attached. |
| 570 | GLTexture depthTexture; |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 571 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, depthTexture); |
| 572 | glTexStorage3DMultisampleOES(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, samplesToUse, |
| 573 | GL_DEPTH_COMPONENT24, 4, 4, 2, GL_TRUE); |
Olli Etuaho | fd16210 | 2018-08-27 16:14:57 +0300 | [diff] [blame] | 574 | ASSERT_GL_NO_ERROR(); |
| 575 | |
| 576 | glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthTexture, 0, 0); |
| 577 | ASSERT_GL_NO_ERROR(); |
| 578 | |
| 579 | status = glCheckFramebufferStatus(GL_FRAMEBUFFER); |
| 580 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, status); |
| 581 | |
| 582 | // Test with color and depth/stencil textures attached. |
| 583 | GLTexture depthStencilTexture; |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 584 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, depthStencilTexture); |
| 585 | glTexStorage3DMultisampleOES(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, samplesToUse, |
| 586 | GL_DEPTH24_STENCIL8, 4, 4, 2, GL_TRUE); |
Olli Etuaho | fd16210 | 2018-08-27 16:14:57 +0300 | [diff] [blame] | 587 | ASSERT_GL_NO_ERROR(); |
| 588 | |
| 589 | glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, depthStencilTexture, 0, |
| 590 | 0); |
| 591 | ASSERT_GL_NO_ERROR(); |
| 592 | |
| 593 | status = glCheckFramebufferStatus(GL_FRAMEBUFFER); |
| 594 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, status); |
| 595 | } |
| 596 | |
| 597 | // Attach a layer of TEXTURE_2D_MULTISAMPLE_ARRAY texture to a framebuffer, clear it, and resolve by |
| 598 | // blitting. |
| 599 | TEST_P(TextureMultisampleArrayWebGLTest, FramebufferColorClearAndBlit) |
| 600 | { |
| 601 | ANGLE_SKIP_TEST_IF(!requestArrayExtension()); |
| 602 | |
| 603 | const GLsizei kWidth = 4; |
| 604 | const GLsizei kHeight = 4; |
| 605 | |
| 606 | std::vector<GLenum> testFormats = {GL_RGBA8}; |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 607 | GLint samplesToUse = getSamplesToUse(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, testFormats); |
Olli Etuaho | fd16210 | 2018-08-27 16:14:57 +0300 | [diff] [blame] | 608 | |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 609 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, mTexture); |
| 610 | glTexStorage3DMultisampleOES(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, samplesToUse, GL_RGBA8, |
| 611 | kWidth, kHeight, 2, GL_TRUE); |
Olli Etuaho | fd16210 | 2018-08-27 16:14:57 +0300 | [diff] [blame] | 612 | |
| 613 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); |
| 614 | glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTexture, 0, 0); |
| 615 | |
| 616 | GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); |
| 617 | ASSERT_GL_NO_ERROR(); |
| 618 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, status); |
| 619 | |
| 620 | glClearColor(0.0f, 1.0f, 0.0f, 1.0f); |
| 621 | glClear(GL_COLOR_BUFFER_BIT); |
| 622 | |
| 623 | GLFramebuffer resolveFramebuffer; |
| 624 | GLTexture resolveTexture; |
| 625 | glBindTexture(GL_TEXTURE_2D, resolveTexture); |
| 626 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, kWidth, kHeight); |
| 627 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resolveFramebuffer); |
| 628 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, resolveTexture, |
| 629 | 0); |
| 630 | glBlitFramebuffer(0, 0, kWidth, kHeight, 0, 0, kWidth, kHeight, GL_COLOR_BUFFER_BIT, |
| 631 | GL_NEAREST); |
| 632 | ASSERT_GL_NO_ERROR(); |
| 633 | |
| 634 | glBindFramebuffer(GL_READ_FRAMEBUFFER, resolveFramebuffer); |
| 635 | EXPECT_PIXEL_RECT_EQ(0, 0, kWidth, kHeight, GLColor::green); |
| 636 | } |
| 637 | |
Olli Etuaho | dff32a0 | 2018-08-28 14:35:50 +0300 | [diff] [blame] | 638 | // Check the size of a multisample array texture in a shader. |
| 639 | TEST_P(TextureMultisampleArrayWebGLTest, TextureSizeInShader) |
| 640 | { |
| 641 | ANGLE_SKIP_TEST_IF(!requestArrayExtension()); |
| 642 | |
| 643 | const std::string &fragmentShader = R"(#version 310 es |
| 644 | #extension GL_OES_texture_storage_multisample_2d_array : require |
| 645 | |
| 646 | uniform highp sampler2DMSArray tex; |
| 647 | out highp vec4 my_FragColor; |
| 648 | |
| 649 | void main() { |
| 650 | my_FragColor = (textureSize(tex) == ivec3(8, 4, 2)) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1); |
| 651 | } |
| 652 | )"; |
| 653 | |
| 654 | ANGLE_GL_PROGRAM(texSizeProgram, essl31_shaders::vs::Simple(), fragmentShader); |
| 655 | |
| 656 | GLint texLocation = glGetUniformLocation(texSizeProgram, "tex"); |
| 657 | ASSERT_GE(texLocation, 0); |
| 658 | |
| 659 | const GLsizei kWidth = 8; |
| 660 | const GLsizei kHeight = 4; |
| 661 | |
| 662 | std::vector<GLenum> testFormats = {GL_RGBA8}; |
| 663 | GLint samplesToUse = getSamplesToUse(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, testFormats); |
| 664 | |
| 665 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, mTexture); |
| 666 | glTexStorage3DMultisampleOES(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, samplesToUse, GL_RGBA8, |
| 667 | kWidth, kHeight, 2, GL_TRUE); |
| 668 | ASSERT_GL_NO_ERROR(); |
| 669 | |
| 670 | drawQuad(texSizeProgram, essl31_shaders::PositionAttrib(), 0.5f, 1.0f, true); |
| 671 | ASSERT_GL_NO_ERROR(); |
| 672 | |
| 673 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 674 | } |
| 675 | |
| 676 | // Clear the layers of a multisample array texture, and then sample all the samples from all the |
| 677 | // layers in a shader. |
| 678 | TEST_P(TextureMultisampleArrayWebGLTest, SimpleTexelFetch) |
| 679 | { |
| 680 | ANGLE_SKIP_TEST_IF(!requestArrayExtension()); |
| 681 | |
| 682 | ANGLE_GL_PROGRAM(texelFetchProgram, essl31_shaders::vs::Passthrough(), |
| 683 | blitArrayTextureLayerFragmentShader()); |
| 684 | |
| 685 | GLint texLocation = glGetUniformLocation(texelFetchProgram, "tex"); |
| 686 | ASSERT_GE(texLocation, 0); |
| 687 | GLint layerLocation = glGetUniformLocation(texelFetchProgram, "layer"); |
| 688 | ASSERT_GE(layerLocation, 0); |
| 689 | GLint sampleNumLocation = glGetUniformLocation(texelFetchProgram, "sampleNum"); |
| 690 | ASSERT_GE(layerLocation, 0); |
| 691 | |
| 692 | const GLsizei kWidth = 4; |
| 693 | const GLsizei kHeight = 4; |
| 694 | const GLsizei kLayerCount = 2; |
| 695 | |
| 696 | std::vector<GLenum> testFormats = {GL_RGBA8}; |
| 697 | GLint samplesToUse = getSamplesToUse(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, testFormats); |
| 698 | |
| 699 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, mTexture); |
| 700 | glTexStorage3DMultisampleOES(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, samplesToUse, GL_RGBA8, |
| 701 | kWidth, kHeight, kLayerCount, GL_TRUE); |
| 702 | ASSERT_GL_NO_ERROR(); |
| 703 | |
| 704 | // Clear layer zero to green and layer one to blue. |
| 705 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); |
| 706 | std::vector<GLColor> clearColors = {{GLColor::green, GLColor::blue}}; |
| 707 | for (GLint i = 0; static_cast<GLsizei>(i) < kLayerCount; ++i) |
| 708 | { |
| 709 | glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTexture, 0, i); |
| 710 | GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); |
| 711 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, status); |
| 712 | const GLColor &clearColor = clearColors[i]; |
| 713 | glClearColor(clearColor.R / 255.0f, clearColor.G / 255.0f, clearColor.B / 255.0f, |
| 714 | clearColor.A / 255.0f); |
| 715 | glClear(GL_COLOR_BUFFER_BIT); |
| 716 | ASSERT_GL_NO_ERROR(); |
| 717 | } |
| 718 | |
| 719 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 720 | glUseProgram(texelFetchProgram); |
| 721 | glViewport(0, 0, kWidth, kHeight); |
| 722 | for (GLint layer = 0; static_cast<GLsizei>(layer) < kLayerCount; ++layer) |
| 723 | { |
| 724 | glUniform1i(layerLocation, layer); |
| 725 | for (GLint sampleNum = 0; sampleNum < samplesToUse; ++sampleNum) |
| 726 | { |
| 727 | glUniform1i(sampleNumLocation, sampleNum); |
| 728 | drawQuad(texelFetchProgram, essl31_shaders::PositionAttrib(), 0.5f, 1.0f, true); |
| 729 | ASSERT_GL_NO_ERROR(); |
| 730 | EXPECT_PIXEL_RECT_EQ(0, 0, kWidth, kHeight, clearColors[layer]); |
| 731 | } |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | // Clear the layers of an integer multisample array texture, and then sample all the samples from |
| 736 | // all the layers in a shader. |
| 737 | TEST_P(TextureMultisampleArrayWebGLTest, IntegerTexelFetch) |
| 738 | { |
| 739 | ANGLE_SKIP_TEST_IF(!requestArrayExtension()); |
| 740 | |
| 741 | ANGLE_GL_PROGRAM(texelFetchProgram, essl31_shaders::vs::Passthrough(), |
| 742 | blitIntArrayTextureLayerFragmentShader()); |
| 743 | |
| 744 | GLint texLocation = glGetUniformLocation(texelFetchProgram, "tex"); |
| 745 | ASSERT_GE(texLocation, 0); |
| 746 | GLint layerLocation = glGetUniformLocation(texelFetchProgram, "layer"); |
| 747 | ASSERT_GE(layerLocation, 0); |
| 748 | GLint sampleNumLocation = glGetUniformLocation(texelFetchProgram, "sampleNum"); |
| 749 | ASSERT_GE(layerLocation, 0); |
| 750 | |
| 751 | const GLsizei kWidth = 4; |
| 752 | const GLsizei kHeight = 4; |
| 753 | const GLsizei kLayerCount = 2; |
| 754 | |
| 755 | std::vector<GLenum> testFormats = {GL_RGBA8I}; |
| 756 | GLint samplesToUse = getSamplesToUse(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, testFormats); |
| 757 | |
| 758 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, mTexture); |
| 759 | glTexStorage3DMultisampleOES(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, samplesToUse, GL_RGBA8I, |
| 760 | kWidth, kHeight, kLayerCount, GL_TRUE); |
| 761 | ASSERT_GL_NO_ERROR(); |
| 762 | |
| 763 | // Clear layer zero to green and layer one to blue. |
| 764 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); |
| 765 | std::vector<GLColor> clearColors = {{GLColor::green, GLColor::blue}}; |
| 766 | for (GLint i = 0; static_cast<GLsizei>(i) < kLayerCount; ++i) |
| 767 | { |
| 768 | glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTexture, 0, i); |
| 769 | GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); |
| 770 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, status); |
| 771 | std::array<GLint, 4> intColor; |
| 772 | for (size_t j = 0; j < intColor.size(); ++j) |
| 773 | { |
| 774 | intColor[j] = clearColors[i][j] / 255; |
| 775 | } |
| 776 | glClearBufferiv(GL_COLOR, 0, intColor.data()); |
| 777 | ASSERT_GL_NO_ERROR(); |
| 778 | } |
| 779 | |
| 780 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 781 | glUseProgram(texelFetchProgram); |
| 782 | glViewport(0, 0, kWidth, kHeight); |
| 783 | for (GLint layer = 0; static_cast<GLsizei>(layer) < kLayerCount; ++layer) |
| 784 | { |
| 785 | glUniform1i(layerLocation, layer); |
| 786 | for (GLint sampleNum = 0; sampleNum < samplesToUse; ++sampleNum) |
| 787 | { |
| 788 | glClearColor(1.0f, 0.0f, 0.0f, 1.0f); |
| 789 | glClear(GL_COLOR_BUFFER_BIT); |
| 790 | glUniform1i(sampleNumLocation, sampleNum); |
| 791 | drawQuad(texelFetchProgram, essl31_shaders::PositionAttrib(), 0.5f, 1.0f, true); |
| 792 | ASSERT_GL_NO_ERROR(); |
| 793 | EXPECT_PIXEL_RECT_EQ(0, 0, kWidth, kHeight, clearColors[layer]); |
| 794 | } |
| 795 | } |
| 796 | } |
| 797 | |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 798 | ANGLE_INSTANTIATE_TEST(TextureMultisampleTest, |
JiangYizhou | 34bc315 | 2017-03-29 14:56:01 +0800 | [diff] [blame] | 799 | ES31_D3D11(), |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 800 | ES3_OPENGL(), |
| 801 | ES3_OPENGLES(), |
| 802 | ES31_OPENGL(), |
| 803 | ES31_OPENGLES()); |
JiangYizhou | 34bc315 | 2017-03-29 14:56:01 +0800 | [diff] [blame] | 804 | ANGLE_INSTANTIATE_TEST(TextureMultisampleTestES31, ES31_D3D11(), ES31_OPENGL(), ES31_OPENGLES()); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 805 | ANGLE_INSTANTIATE_TEST(TextureMultisampleArrayWebGLTest, |
| 806 | ES31_D3D11(), |
| 807 | ES31_OPENGL(), |
| 808 | ES31_OPENGLES()); |
| 809 | |
| 810 | } // anonymous namespace |