blob: 9866ea3b9571cebbaa4511ff714f478874bf144a [file] [log] [blame]
JiangYizhoubddc46b2016-12-09 09:50:51 +08001//
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 Etuahodff32a02018-08-28 14:35:50 +030010
11#include "shader_utils.h"
JiangYizhoubddc46b2016-12-09 09:50:51 +080012#include "test_utils/gl_raii.h"
13
14using namespace angle;
15
16namespace
17{
Jiang0e1224c2017-12-26 14:11:15 +080018// Sample positions of d3d standard pattern. Some of the sample positions might not the same as
19// opengl.
20using SamplePositionsArray = std::array<float, 32>;
21static 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}}}};
JiangYizhoubddc46b2016-12-09 09:50:51 +080031
32class 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 Etuahofd162102018-08-27 16:14:57 +030067
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 Etuahodff32a02018-08-28 14:35:50 +030082
83 const char *blitArrayTextureLayerFragmentShader()
84 {
85 return R"(#version 310 es
86#extension GL_OES_texture_storage_multisample_2d_array : require
87precision highp float;
88precision highp int;
89
90uniform highp sampler2DMSArray tex;
91uniform int layer;
92uniform int sampleNum;
93
94in vec4 v_position;
95out vec4 my_FragColor;
96
97void 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
109precision highp float;
110precision highp int;
111
112uniform highp isampler2DMSArray tex;
113uniform int layer;
114uniform int sampleNum;
115
116in vec4 v_position;
117out vec4 my_FragColor;
118
119void 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 };
JiangYizhoubddc46b2016-12-09 09:50:51 +0800126};
127
128class TextureMultisampleTestES31 : public TextureMultisampleTest
129{
130 protected:
131 TextureMultisampleTestES31() : TextureMultisampleTest() {}
132};
133
Olli Etuahod310a432018-08-24 15:40:23 +0300134class 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 Etuaho064458a2018-08-30 14:02:02 +0300147 if (extensionRequestable("GL_OES_texture_storage_multisample_2d_array"))
Olli Etuahod310a432018-08-24 15:40:23 +0300148 {
Olli Etuaho064458a2018-08-30 14:02:02 +0300149 glRequestExtensionANGLE("GL_OES_texture_storage_multisample_2d_array");
Olli Etuahod310a432018-08-24 15:40:23 +0300150 }
151
Olli Etuaho064458a2018-08-30 14:02:02 +0300152 if (!extensionEnabled("GL_OES_texture_storage_multisample_2d_array"))
Olli Etuahod310a432018-08-24 15:40:23 +0300153 {
154 return false;
155 }
156 return true;
157 }
158};
159
JiangYizhoubddc46b2016-12-09 09:50:51 +0800160// Tests that if es version < 3.1, GL_TEXTURE_2D_MULTISAMPLE is not supported in
Olli Etuahod310a432018-08-24 15:40:23 +0300161// GetInternalformativ. Checks that the number of samples returned is valid in case of ES >= 3.1.
JiangYizhoubddc46b2016-12-09 09:50:51 +0800162TEST_P(TextureMultisampleTest, MultisampleTargetGetInternalFormativBase)
163{
Olli Etuahod310a432018-08-24 15:40:23 +0300164 // 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);
JiangYizhoubddc46b2016-12-09 09:50:51 +0800168 if (getClientMajorVersion() < 3 || getClientMinorVersion() < 1)
169 {
Olli Etuahod310a432018-08-24 15:40:23 +0300170 ASSERT_GL_ERROR(GL_INVALID_ENUM);
JiangYizhoubddc46b2016-12-09 09:50:51 +0800171 }
172 else
173 {
174 ASSERT_GL_NO_ERROR();
Olli Etuahod310a432018-08-24 15:40:23 +0300175
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);
JiangYizhoubddc46b2016-12-09 09:50:51 +0800184 }
185}
186
187// Tests that if es version < 3.1, GL_TEXTURE_2D_MULTISAMPLE is not supported in
188// FramebufferTexture2D.
189TEST_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.
217TEST_P(TextureMultisampleTestES31, ValidateTextureStorageMultisampleParameters)
218{
219 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTexture);
220 glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, GL_FALSE);
JiangYizhou461d9a32017-01-04 16:37:26 +0800221 ASSERT_GL_NO_ERROR();
222
JiangYizhoubddc46b2016-12-09 09:50:51 +0800223 GLint params = 0;
224 glGetTexParameteriv(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_IMMUTABLE_FORMAT, &params);
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
Shao5116d682017-08-02 12:39:44 +0800254// Tests the value of MAX_INTEGER_SAMPLES is no less than 1.
255// [OpenGL ES 3.1 SPEC Table 20.40]
256TEST_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]
266TEST_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]
276TEST_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
Jiang0e1224c2017-12-26 14:11:15 +0800284// The value of sample position should be equal to standard pattern on D3D.
285TEST_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 Etuahod310a432018-08-24 15:40:23 +0300318// Tests that GL_TEXTURE_2D_MULTISAMPLE_ARRAY is not supported in GetInternalformativ when the
319// extension is not supported.
320TEST_P(TextureMultisampleArrayWebGLTest, MultisampleArrayTargetGetInternalFormativWithoutExtension)
321{
322 GLint maxSamples = 0;
Olli Etuaho064458a2018-08-30 14:02:02 +0300323 glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_RGBA8, GL_SAMPLES, 1,
Olli Etuahod310a432018-08-24 15:40:23 +0300324 &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.
329TEST_P(TextureMultisampleArrayWebGLTest, BindMultisampleArrayTextureWithoutExtension)
330{
Olli Etuaho064458a2018-08-30 14:02:02 +0300331 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, mTexture);
Olli Etuahod310a432018-08-24 15:40:23 +0300332 ASSERT_GL_ERROR(GL_INVALID_ENUM);
333}
334
Olli Etuahodff32a02018-08-28 14:35:50 +0300335// Try to compile shaders using GL_OES_texture_storage_multisample_2d_array when the extension is
336// not enabled.
337TEST_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 Etuahod310a432018-08-24 15:40:23 +0300366// Tests that GL_TEXTURE_2D_MULTISAMPLE_ARRAY is supported in GetInternalformativ.
367TEST_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 Etuaho064458a2018-08-30 14:02:02 +0300374 glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_RGBA8, GL_SAMPLES, 1,
Olli Etuahod310a432018-08-24 15:40:23 +0300375 &maxSamplesRGBA8);
Olli Etuahofd162102018-08-27 16:14:57 +0300376 GLint maxSamplesDepth = 0;
Olli Etuaho064458a2018-08-30 14:02:02 +0300377 glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_DEPTH_COMPONENT24, GL_SAMPLES, 1,
378 &maxSamplesDepth);
Olli Etuahod310a432018-08-24 15:40:23 +0300379 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 Etuahofd162102018-08-27 16:14:57 +0300384 GLint maxDepthTextureSamples;
385 glGetIntegerv(GL_MAX_DEPTH_TEXTURE_SAMPLES, &maxDepthTextureSamples);
Olli Etuahod310a432018-08-24 15:40:23 +0300386 GLint maxSamples;
387 glGetIntegerv(GL_MAX_SAMPLES, &maxSamples);
Olli Etuahod310a432018-08-24 15:40:23 +0300388
Olli Etuahofd162102018-08-27 16:14:57 +0300389 GLint maxSamplesRGBA8Required = std::min(maxColorTextureSamples, maxSamples);
Olli Etuahod310a432018-08-24 15:40:23 +0300390 EXPECT_GE(maxSamplesRGBA8, maxSamplesRGBA8Required);
Olli Etuahofd162102018-08-27 16:14:57 +0300391
392 GLint maxSamplesDepthRequired = std::min(maxDepthTextureSamples, maxSamples);
393 EXPECT_GE(maxSamplesDepth, maxSamplesDepthRequired);
Olli Etuahod310a432018-08-24 15:40:23 +0300394}
395
396// Tests that TexImage3D call cannot be used for GL_TEXTURE_2D_MULTISAMPLE_ARRAY.
397TEST_P(TextureMultisampleArrayWebGLTest, MultiSampleArrayTexImage)
398{
399 ANGLE_SKIP_TEST_IF(!requestArrayExtension());
400
Olli Etuaho064458a2018-08-30 14:02:02 +0300401 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, mTexture);
Olli Etuahod310a432018-08-24 15:40:23 +0300402 ASSERT_GL_NO_ERROR();
403
Olli Etuaho064458a2018-08-30 14:02:02 +0300404 glTexImage3D(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA,
Olli Etuahod310a432018-08-24 15:40:23 +0300405 GL_UNSIGNED_BYTE, nullptr);
406 EXPECT_GL_ERROR(GL_INVALID_ENUM);
407}
408
409// Tests passing invalid parameters to TexStorage3DMultisample.
410TEST_P(TextureMultisampleArrayWebGLTest, InvalidTexStorage3DMultisample)
411{
412 ANGLE_SKIP_TEST_IF(!requestArrayExtension());
413
Olli Etuaho064458a2018-08-30 14:02:02 +0300414 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, mTexture);
Olli Etuahod310a432018-08-24 15:40:23 +0300415 ASSERT_GL_NO_ERROR();
416
417 // Invalid target
Olli Etuaho064458a2018-08-30 14:02:02 +0300418 glTexStorage3DMultisampleOES(GL_TEXTURE_2D_MULTISAMPLE, 2, GL_RGBA8, 1, 1, 1, GL_TRUE);
Olli Etuahod310a432018-08-24 15:40:23 +0300419 EXPECT_GL_ERROR(GL_INVALID_ENUM);
420
421 // Samples 0
Olli Etuaho064458a2018-08-30 14:02:02 +0300422 glTexStorage3DMultisampleOES(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 0, GL_RGBA8, 1, 1, 1,
423 GL_TRUE);
Olli Etuahod310a432018-08-24 15:40:23 +0300424 EXPECT_GL_ERROR(GL_INVALID_VALUE);
425
426 // Unsized internalformat
Olli Etuaho064458a2018-08-30 14:02:02 +0300427 glTexStorage3DMultisampleOES(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 2, GL_RGBA, 1, 1, 1, GL_TRUE);
Olli Etuahod310a432018-08-24 15:40:23 +0300428 EXPECT_GL_ERROR(GL_INVALID_ENUM);
429
430 // Width 0
Olli Etuaho064458a2018-08-30 14:02:02 +0300431 glTexStorage3DMultisampleOES(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 2, GL_RGBA8, 0, 1, 1,
432 GL_TRUE);
Olli Etuahod310a432018-08-24 15:40:23 +0300433 EXPECT_GL_ERROR(GL_INVALID_VALUE);
434
435 // Height 0
Olli Etuaho064458a2018-08-30 14:02:02 +0300436 glTexStorage3DMultisampleOES(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 2, GL_RGBA8, 1, 0, 1,
437 GL_TRUE);
Olli Etuahod310a432018-08-24 15:40:23 +0300438 EXPECT_GL_ERROR(GL_INVALID_VALUE);
439
440 // Depth 0
Olli Etuaho064458a2018-08-30 14:02:02 +0300441 glTexStorage3DMultisampleOES(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 2, GL_RGBA8, 1, 1, 0,
442 GL_TRUE);
Olli Etuahod310a432018-08-24 15:40:23 +0300443 EXPECT_GL_ERROR(GL_INVALID_VALUE);
444}
445
446// Tests passing invalid parameters to TexParameteri.
447TEST_P(TextureMultisampleArrayWebGLTest, InvalidTexParameteri)
448{
449 ANGLE_SKIP_TEST_IF(!requestArrayExtension());
450
Olli Etuaho064458a2018-08-30 14:02:02 +0300451 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, mTexture);
Olli Etuahod310a432018-08-24 15:40:23 +0300452 ASSERT_GL_NO_ERROR();
453
Olli Etuaho064458a2018-08-30 14:02:02 +0300454 // 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 Etuahod310a432018-08-24 15:40:23 +0300456 EXPECT_GL_ERROR(GL_INVALID_ENUM);
Olli Etuaho064458a2018-08-30 14:02:02 +0300457 glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Olli Etuahod310a432018-08-24 15:40:23 +0300458 EXPECT_GL_ERROR(GL_INVALID_ENUM);
459
Olli Etuaho064458a2018-08-30 14:02:02 +0300460 glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
Olli Etuahod310a432018-08-24 15:40:23 +0300461 EXPECT_GL_ERROR(GL_INVALID_ENUM);
Olli Etuaho064458a2018-08-30 14:02:02 +0300462 glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
Olli Etuahod310a432018-08-24 15:40:23 +0300463 EXPECT_GL_ERROR(GL_INVALID_ENUM);
Olli Etuaho064458a2018-08-30 14:02:02 +0300464 glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
Olli Etuahod310a432018-08-24 15:40:23 +0300465 EXPECT_GL_ERROR(GL_INVALID_ENUM);
466
Olli Etuaho064458a2018-08-30 14:02:02 +0300467 glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_TEXTURE_MIN_LOD, 0);
Olli Etuahod310a432018-08-24 15:40:23 +0300468 EXPECT_GL_ERROR(GL_INVALID_ENUM);
Olli Etuaho064458a2018-08-30 14:02:02 +0300469 glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_TEXTURE_MAX_LOD, 0);
Olli Etuahod310a432018-08-24 15:40:23 +0300470 EXPECT_GL_ERROR(GL_INVALID_ENUM);
471
Olli Etuaho064458a2018-08-30 14:02:02 +0300472 glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_TEXTURE_COMPARE_MODE, GL_NONE);
Olli Etuahod310a432018-08-24 15:40:23 +0300473 EXPECT_GL_ERROR(GL_INVALID_ENUM);
Olli Etuaho064458a2018-08-30 14:02:02 +0300474 glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_TEXTURE_COMPARE_FUNC, GL_ALWAYS);
Olli Etuahod310a432018-08-24 15:40:23 +0300475 EXPECT_GL_ERROR(GL_INVALID_ENUM);
476
Olli Etuaho064458a2018-08-30 14:02:02 +0300477 // 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 Etuahod310a432018-08-24 15:40:23 +0300479 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
480}
481
Olli Etuaho0c5a9e22018-08-27 14:36:23 +0300482// Test a valid TexStorage3DMultisample call and check that the queried texture level parameters
483// match. Does not do any drawing.
484TEST_P(TextureMultisampleArrayWebGLTest, TexStorage3DMultisample)
485{
486 ANGLE_SKIP_TEST_IF(!requestArrayExtension());
487
488 GLint maxSamplesRGBA8 = 0;
Olli Etuaho064458a2018-08-30 14:02:02 +0300489 glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_RGBA8, GL_SAMPLES, 1,
Olli Etuaho0c5a9e22018-08-27 14:36:23 +0300490 &maxSamplesRGBA8);
491
Olli Etuaho064458a2018-08-30 14:02:02 +0300492 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, mTexture);
Olli Etuaho0c5a9e22018-08-27 14:36:23 +0300493 ASSERT_GL_NO_ERROR();
494
Olli Etuaho064458a2018-08-30 14:02:02 +0300495 glTexStorage3DMultisampleOES(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, maxSamplesRGBA8, GL_RGBA8, 8,
496 4, 2, GL_TRUE);
Olli Etuaho0c5a9e22018-08-27 14:36:23 +0300497 ASSERT_GL_NO_ERROR();
498
499 GLint width = 0, height = 0, depth = 0, samples = 0;
Olli Etuaho064458a2018-08-30 14:02:02 +0300500 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 Etuaho0c5a9e22018-08-27 14:36:23 +0300504 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 Etuaho064458a2018-08-30 14:02:02 +0300512// Test for invalid FramebufferTextureLayer calls with GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES
Olli Etuahofd162102018-08-27 16:14:57 +0300513// textures.
514TEST_P(TextureMultisampleArrayWebGLTest, InvalidFramebufferTextureLayer)
515{
516 ANGLE_SKIP_TEST_IF(!requestArrayExtension());
517
518 GLint maxSamplesRGBA8 = 0;
Olli Etuaho064458a2018-08-30 14:02:02 +0300519 glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, GL_RGBA8, GL_SAMPLES, 1,
Olli Etuahofd162102018-08-27 16:14:57 +0300520 &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 Etuaho064458a2018-08-30 14:02:02 +0300526 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 Etuahofd162102018-08-27 16:14:57 +0300529 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.
549TEST_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 Etuaho064458a2018-08-30 14:02:02 +0300554 GLint samplesToUse = getSamplesToUse(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, testFormats);
Olli Etuahofd162102018-08-27 16:14:57 +0300555
556 // Test framebuffer status with just a color texture attached.
Olli Etuaho064458a2018-08-30 14:02:02 +0300557 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 Etuahofd162102018-08-27 16:14:57 +0300560 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 Etuaho064458a2018-08-30 14:02:02 +0300571 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 Etuahofd162102018-08-27 16:14:57 +0300574 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 Etuaho064458a2018-08-30 14:02:02 +0300584 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 Etuahofd162102018-08-27 16:14:57 +0300587 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.
599TEST_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 Etuaho064458a2018-08-30 14:02:02 +0300607 GLint samplesToUse = getSamplesToUse(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, testFormats);
Olli Etuahofd162102018-08-27 16:14:57 +0300608
Olli Etuaho064458a2018-08-30 14:02:02 +0300609 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 Etuahofd162102018-08-27 16:14:57 +0300612
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 Etuahodff32a02018-08-28 14:35:50 +0300638// Check the size of a multisample array texture in a shader.
639TEST_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.
678TEST_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.
737TEST_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
JiangYizhoubddc46b2016-12-09 09:50:51 +0800798ANGLE_INSTANTIATE_TEST(TextureMultisampleTest,
JiangYizhou34bc3152017-03-29 14:56:01 +0800799 ES31_D3D11(),
JiangYizhoubddc46b2016-12-09 09:50:51 +0800800 ES3_OPENGL(),
801 ES3_OPENGLES(),
802 ES31_OPENGL(),
803 ES31_OPENGLES());
JiangYizhou34bc3152017-03-29 14:56:01 +0800804ANGLE_INSTANTIATE_TEST(TextureMultisampleTestES31, ES31_D3D11(), ES31_OPENGL(), ES31_OPENGLES());
Olli Etuahod310a432018-08-24 15:40:23 +0300805ANGLE_INSTANTIATE_TEST(TextureMultisampleArrayWebGLTest,
806 ES31_D3D11(),
807 ES31_OPENGL(),
808 ES31_OPENGLES());
809
810} // anonymous namespace