1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL (ES) Module
3 * -----------------------------------------------
4 *
5 * Copyright 2014 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief Framebuffer completeness tests.
22 *//*--------------------------------------------------------------------*/
23
24 #include "es3fFboCompletenessTests.hpp"
25
26 #include "glsFboCompletenessTests.hpp"
27 #include "deUniquePtr.hpp"
28 #include <sstream>
29
30 using namespace glw;
31 using deqp::gls::Range;
32 using namespace deqp::gls::FboUtil;
33 using namespace deqp::gls::FboUtil::config;
34 namespace fboc = deqp::gls::fboc;
35 typedef tcu::TestCase::IterateResult IterateResult;
36 using std::string;
37 using std::ostringstream;
38
39 namespace deqp
40 {
41 namespace gles3
42 {
43 namespace Functional
44 {
45
46 static const FormatKey s_es3ColorRenderables[] =
47 {
48 // GLES3, 4.4.4: "An internal format is color-renderable if it is one of
49 // the formats from table 3.12 noted as color-renderable..."
50 GL_R8, GL_RG8, GL_RGB8, GL_RGB565, GL_RGBA4, GL_RGB5_A1, GL_RGBA8,
51 GL_RGB10_A2, GL_RGB10_A2UI, GL_SRGB8_ALPHA8,
52 GL_R8I, GL_R8UI, GL_R16I, GL_R16UI, GL_R32I, GL_R32UI,
53 GL_RG8I, GL_RG8UI, GL_RG16I, GL_RG16UI, GL_RG32I, GL_RG32UI,
54 GL_RGBA8I, GL_RGBA8UI, GL_RGBA16I, GL_RGBA16UI, GL_RGBA32I, GL_RGBA32UI,
55 };
56
57 static const FormatKey s_es3UnsizedColorRenderables[] =
58 {
59 // "...or if it is unsized format RGBA or RGB."
60 // See Table 3.3 in GLES3.
61 GLS_UNSIZED_FORMATKEY(GL_RGBA, GL_UNSIGNED_BYTE),
62 GLS_UNSIZED_FORMATKEY(GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4),
63 GLS_UNSIZED_FORMATKEY(GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1),
64 GLS_UNSIZED_FORMATKEY(GL_RGB, GL_UNSIGNED_BYTE),
65 GLS_UNSIZED_FORMATKEY(GL_RGB, GL_UNSIGNED_SHORT_5_6_5),
66 };
67
68 static const FormatKey s_es3DepthRenderables[] =
69 {
70 // GLES3, 4.4.4: "An internal format is depth-renderable if it is one of
71 // the formats from table 3.13."
72 GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT32F,
73 GL_DEPTH24_STENCIL8, GL_DEPTH32F_STENCIL8,
74 };
75
76 static const FormatKey s_es3StencilRboRenderables[] =
77 {
78 // GLES3, 4.4.4: "An internal format is stencil-renderable if it is
79 // STENCIL_INDEX8..."
80 GL_STENCIL_INDEX8,
81 };
82
83 static const FormatKey s_es3StencilRenderables[] =
84 {
85 // "...or one of the formats from table 3.13 whose base internal format is
86 // DEPTH_STENCIL."
87 GL_DEPTH24_STENCIL8, GL_DEPTH32F_STENCIL8,
88 };
89
90 static const FormatKey s_es3TextureFloatFormats[] =
91 {
92 GL_RGBA32F, GL_RGBA16F, GL_R11F_G11F_B10F,
93 GL_RG32F, GL_RG16F, GL_R32F, GL_R16F,
94 GL_RGBA16F, GL_RGB16F, GL_RG16F, GL_R16F,
95 };
96
97 static const FormatKey s_es3NotRenderableTextureFormats[] =
98 {
99 GL_R8_SNORM, GL_RG8_SNORM, GL_RGB8_SNORM, GL_RGBA8_SNORM,
100 GL_RGB9_E5, GL_SRGB8,
101 GL_RGB8I, GL_RGB16I, GL_RGB32I,
102 GL_RGB8UI, GL_RGB16UI,GL_RGB32UI,
103 };
104
105 static const FormatEntry s_es3Formats[] =
106 {
107 // Renderbuffers don't support unsized formats
108 { REQUIRED_RENDERABLE | COLOR_RENDERABLE | TEXTURE_VALID,
109 GLS_ARRAY_RANGE(s_es3UnsizedColorRenderables) },
110 { REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID | TEXTURE_VALID,
111 GLS_ARRAY_RANGE(s_es3ColorRenderables) },
112 { REQUIRED_RENDERABLE | DEPTH_RENDERABLE | RENDERBUFFER_VALID | TEXTURE_VALID,
113 GLS_ARRAY_RANGE(s_es3DepthRenderables) },
114 { REQUIRED_RENDERABLE | STENCIL_RENDERABLE | RENDERBUFFER_VALID,
115 GLS_ARRAY_RANGE(s_es3StencilRboRenderables) },
116 { REQUIRED_RENDERABLE | STENCIL_RENDERABLE | RENDERBUFFER_VALID | TEXTURE_VALID,
117 GLS_ARRAY_RANGE(s_es3StencilRenderables) },
118 { TEXTURE_VALID,
119 GLS_ARRAY_RANGE(s_es3NotRenderableTextureFormats) },
120
121 // These are not color-renderable in vanilla ES3, but we need to mark them
122 // as valid for textures, since EXT_color_buffer_(half_)float brings in
123 // color-renderability and only renderbuffer-validity.
124 { TEXTURE_VALID,
125 GLS_ARRAY_RANGE(s_es3TextureFloatFormats) },
126 };
127
128 // GL_EXT_color_buffer_float
129 static const FormatKey s_extColorBufferFloatFormats[] =
130 {
131 GL_RGBA32F, GL_RGBA16F, GL_R11F_G11F_B10F, GL_RG32F, GL_RG16F, GL_R32F, GL_R16F,
132 };
133
134 // GL_QCOM_render_shared_exponent
135 static const FormatKey s_qcomRenderSharedExponent[] =
136 {
137 GL_RGB9_E5,
138 };
139 // GL_OES_texture_stencil8
140 static const FormatKey s_extOESTextureStencil8[] =
141 {
142 GL_STENCIL_INDEX8,
143 };
144
145 // GL_EXT_render_snorm
146 static const FormatKey s_extRenderSnorm[] =
147 {
148 GL_R8_SNORM, GL_RG8_SNORM, GL_RGBA8_SNORM,
149 };
150
151 static const FormatExtEntry s_es3ExtFormats[] =
152 {
153 {
154 "GL_EXT_color_buffer_float",
155 // These are already texture-valid in ES3, the extension just adds RBO
156 // support and makes them color-renderable.
157 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
158 GLS_ARRAY_RANGE(s_extColorBufferFloatFormats)
159 },
160 {
161 "GL_OES_texture_stencil8",
162 // \note: es3 RBO tests actually cover the first two requirements
163 // - kept here for completeness
164 (deUint32)(REQUIRED_RENDERABLE | STENCIL_RENDERABLE | TEXTURE_VALID),
165 GLS_ARRAY_RANGE(s_extOESTextureStencil8)
166 },
167
168 // Since GLES31 is backwards compatible to GLES3, we might actually be running on a GLES31.
169 // Add rule changes of GLES31 that have no corresponding GLES3 extension.
170 //
171 // \note Not all feature changes are listed here but only those that alter GLES3 subset of
172 // the formats
173 {
174 "DEQP_gles31_core_compatible GL_EXT_render_snorm",
175 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | TEXTURE_VALID | RENDERBUFFER_VALID),
176 GLS_ARRAY_RANGE(s_extRenderSnorm)
177 },
178
179 {
180 "GL_QCOM_render_shared_exponent",
181 // This is already texture-valid in ES3, the extension just adds RBO
182 // support to RGB9_E5 and make it color-renderable.
183 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID | TEXTURE_VALID),
184 GLS_ARRAY_RANGE(s_qcomRenderSharedExponent)
185 },
186 };
187
188 class ES3Checker : public Checker
189 {
190 public:
ES3Checker(const glu::RenderContext & ctx,const FormatDB & formats)191 ES3Checker (const glu::RenderContext& ctx, const FormatDB& formats)
192 : Checker (ctx, formats)
193 , m_ctxInfo (glu::ContextInfo::create(ctx))
194 , m_numSamples (-1)
195 , m_depthStencilImage (0)
196 , m_depthStencilType (GL_NONE) {}
197 void check (GLenum attPoint, const Attachment& att, const Image* image);
198
199 private:
200 de::UniquePtr<glu::ContextInfo> m_ctxInfo;
201
202 //! The common number of samples of images.
203 GLsizei m_numSamples;
204
205 //! The common image for depth and stencil attachments.
206 GLuint m_depthStencilImage;
207 GLenum m_depthStencilType;
208 ImageFormat m_depthStencilFormat;
209 };
210
check(GLenum attPoint,const Attachment & att,const Image * image)211 void ES3Checker::check (GLenum attPoint, const Attachment& att, const Image* image)
212 {
213 GLsizei imgSamples = imageNumSamples(*image);
214
215 if (m_numSamples == -1)
216 {
217 m_numSamples = imgSamples;
218 }
219 else
220 {
221 // GLES3: "The value of RENDERBUFFER_SAMPLES is the same for all attached
222 // renderbuffers and, if the attached images are a mix of renderbuffers
223 // and textures, the value of RENDERBUFFER_SAMPLES is zero."
224 //
225 // On creating a renderbuffer: "If _samples_ is zero, then
226 // RENDERBUFFER_SAMPLES is set to zero. Otherwise [...] the resulting
227 // value for RENDERBUFFER_SAMPLES is guaranteed to be greater than or
228 // equal to _samples_ and no more than the next larger sample count
229 // supported by the implementation."
230
231 // Either all attachments are zero-sample renderbuffers and/or
232 // textures, or none of them are.
233 if ((m_numSamples == 0) != (imgSamples == 0))
234 addFBOStatus(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, "Mixed multi- and single-sampled attachments");
235
236 // If the attachments requested a different number of samples, the
237 // implementation is allowed to report this as incomplete. However, it
238 // is also possible that despite the different requests, the
239 // implementation allocated the same number of samples to both. Hence
240 // reporting the framebuffer as complete is also legal.
241 if (m_numSamples != imgSamples)
242 addPotentialFBOStatus(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, "Number of samples differ");
243 }
244
245 if (attPoint == GL_DEPTH_ATTACHMENT || attPoint == GL_STENCIL_ATTACHMENT)
246 {
247 if (m_depthStencilImage == 0)
248 {
249 m_depthStencilImage = att.imageName;
250 m_depthStencilType = attachmentType(att);
251 m_depthStencilFormat = image->internalFormat;
252 }
253 else if (m_depthStencilImage != att.imageName || m_depthStencilType != attachmentType(att))
254 {
255 // "Depth and stencil attachments, if present, are the same image."
256 if (!m_ctxInfo->isExtensionSupported("GL_EXT_separate_depth_stencil"))
257 addFBOStatus(GL_FRAMEBUFFER_UNSUPPORTED, "Depth and stencil attachments are not the same image");
258
259 // "The combination of internal formats of the attached images does not violate
260 // an implementation-dependent set of restrictions."
261 ImageFormat depthFormat = attPoint == GL_DEPTH_ATTACHMENT ? image->internalFormat : m_depthStencilFormat;
262 ImageFormat stencilFormat = attPoint == GL_STENCIL_ATTACHMENT ? image->internalFormat : m_depthStencilFormat;
263 if (m_formats.getFormatInfo(depthFormat) & STENCIL_RENDERABLE)
264 addPotentialFBOStatus(GL_FRAMEBUFFER_UNSUPPORTED, "Separate depth attachment has combined depth and stencil format");
265 if (m_formats.getFormatInfo(stencilFormat) & DEPTH_RENDERABLE)
266 addPotentialFBOStatus(GL_FRAMEBUFFER_UNSUPPORTED, "Separate stencil attachment has combined depth and stencil format");
267 }
268 }
269 }
270
271 struct NumLayersParams
272 {
273 GLenum textureKind; //< GL_TEXTURE_3D or GL_TEXTURE_2D_ARRAY
274 GLsizei numLayers; //< Number of layers in texture
275 GLsizei attachmentLayer; //< Layer referenced by attachment
276
277 static string getName (const NumLayersParams& params);
278 static string getDescription (const NumLayersParams& params);
279 };
280
getName(const NumLayersParams & params)281 string NumLayersParams::getName (const NumLayersParams& params)
282 {
283 ostringstream os;
284 const string kindStr = params.textureKind == GL_TEXTURE_3D ? "3d" : "2darr";
285 os << kindStr << "_" << params.numLayers << "_" << params.attachmentLayer;
286 return os.str();
287 }
288
getDescription(const NumLayersParams & params)289 string NumLayersParams::getDescription (const NumLayersParams& params)
290 {
291 ostringstream os;
292 const string kindStr = (params.textureKind == GL_TEXTURE_3D
293 ? "3D Texture"
294 : "2D Array Texture");
295 os << kindStr + ", "
296 << params.numLayers << " layers, "
297 << "attached layer " << params.attachmentLayer << ".";
298 return os.str();
299 }
300
301 class NumLayersTest : public fboc::ParamTest<NumLayersParams>
302 {
303 public:
NumLayersTest(fboc::Context & ctx,NumLayersParams param)304 NumLayersTest (fboc::Context& ctx, NumLayersParams param)
305 : fboc::ParamTest<NumLayersParams> (ctx, param) {}
306
307 IterateResult build (FboBuilder& builder);
308 };
309
build(FboBuilder & builder)310 IterateResult NumLayersTest::build (FboBuilder& builder)
311 {
312 TextureLayered* texCfg = DE_NULL;
313 const GLenum target = GL_COLOR_ATTACHMENT0;
314
315 switch (m_params.textureKind)
316 {
317 case GL_TEXTURE_3D:
318 texCfg = &builder.makeConfig<Texture3D>();
319 break;
320 case GL_TEXTURE_2D_ARRAY:
321 texCfg = &builder.makeConfig<Texture2DArray>();
322 break;
323 default:
324 DE_FATAL("Impossible case");
325 }
326 texCfg->internalFormat = getDefaultFormat(target, GL_TEXTURE);
327 texCfg->width = 64;
328 texCfg->height = 64;
329 texCfg->numLayers = m_params.numLayers;
330 const GLuint tex = builder.glCreateTexture(*texCfg);
331
332 TextureLayerAttachment* att = &builder.makeConfig<TextureLayerAttachment>();
333 att->layer = m_params.attachmentLayer;
334 att->imageName = tex;
335
336 builder.glAttach(target, att);
337
338 return STOP;
339 }
340
341 enum
342 {
343 SAMPLES_NONE = -2,
344 SAMPLES_TEXTURE = -1
345 };
346 struct NumSamplesParams
347 {
348 // >= 0: renderbuffer with N samples, -1: texture, -2: no attachment
349 GLsizei numSamples[3];
350
351 static string getName (const NumSamplesParams& params);
352 static string getDescription (const NumSamplesParams& params);
353 };
354
getName(const NumSamplesParams & params)355 string NumSamplesParams::getName (const NumSamplesParams& params)
356 {
357 ostringstream os;
358 bool first = true;
359 for (const GLsizei* ns = DE_ARRAY_BEGIN(params.numSamples);
360 ns != DE_ARRAY_END(params.numSamples);
361 ns++)
362 {
363 if (first)
364 first = false;
365 else
366 os << "_";
367
368 if (*ns == SAMPLES_NONE)
369 os << "none";
370 else if (*ns == SAMPLES_TEXTURE)
371 os << "tex";
372 else
373 os << "rbo" << *ns;
374 }
375 return os.str();
376 }
377
getDescription(const NumSamplesParams & params)378 string NumSamplesParams::getDescription (const NumSamplesParams& params)
379 {
380 ostringstream os;
381 bool first = true;
382 static const char* const s_names[] = { "color", "depth", "stencil" };
383 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_names) == DE_LENGTH_OF_ARRAY(params.numSamples));
384
385 for (int i = 0; i < DE_LENGTH_OF_ARRAY(s_names); i++)
386 {
387 GLsizei ns = params.numSamples[i];
388
389 if (ns == SAMPLES_NONE)
390 continue;
391
392 if (first)
393 first = false;
394 else
395 os << ", ";
396
397 if (ns == SAMPLES_TEXTURE)
398 os << "texture " << s_names[i] << " attachment";
399 else
400 os << ns << "-sample renderbuffer " << s_names[i] << " attachment";
401 }
402 return os.str();
403 }
404
405 class NumSamplesTest : public fboc::ParamTest<NumSamplesParams>
406 {
407 public:
NumSamplesTest(fboc::Context & ctx,NumSamplesParams param)408 NumSamplesTest (fboc::Context& ctx, NumSamplesParams param)
409 : fboc::ParamTest<NumSamplesParams> (ctx, param) {}
410
411 IterateResult build (FboBuilder& builder);
412 };
413
build(FboBuilder & builder)414 IterateResult NumSamplesTest::build (FboBuilder& builder)
415 {
416 static const GLenum s_targets[] =
417 {
418 GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_DEPTH_ATTACHMENT,
419 };
420 // Non-integer formats for each attachment type.
421 // \todo [2013-12-17 lauri] Add fixed/floating/integer metadata for formats so
422 // we can pick one smartly or maybe try several.
423 static const GLenum s_formats[] =
424 {
425 GL_RGBA8, GL_RGB565, GL_DEPTH_COMPONENT24,
426 };
427 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_targets) == DE_LENGTH_OF_ARRAY(m_params.numSamples));
428
429 for (int i = 0; i < DE_LENGTH_OF_ARRAY(s_targets); i++)
430 {
431 const GLenum target = s_targets[i];
432 const ImageFormat fmt = { s_formats[i], GL_NONE };
433
434 const GLsizei ns = m_params.numSamples[i];
435 if (ns == -2)
436 continue;
437
438 if (ns == -1)
439 {
440 attachTargetToNew(target, GL_TEXTURE, fmt, 64, 64, builder);
441 }
442 else
443 {
444 Renderbuffer& rboCfg = builder.makeConfig<Renderbuffer>();
445 rboCfg.internalFormat = fmt;
446 rboCfg.width = rboCfg.height = 64;
447 rboCfg.numSamples = ns;
448
449 const GLuint rbo = builder.glCreateRbo(rboCfg);
450 // Implementations do not necessarily support sample sizes greater than 1.
451 TCU_CHECK_AND_THROW(NotSupportedError,
452 builder.getError() != GL_INVALID_OPERATION,
453 "Unsupported number of samples");
454 RenderbufferAttachment& att = builder.makeConfig<RenderbufferAttachment>();
455 att.imageName = rbo;
456 builder.glAttach(target, &att);
457 }
458 }
459
460 return STOP;
461 }
462
463 class ES3CheckerFactory : public CheckerFactory
464 {
465 public:
createChecker(const glu::RenderContext & ctx,const FormatDB & formats)466 Checker* createChecker (const glu::RenderContext& ctx, const FormatDB& formats) { return new ES3Checker(ctx, formats); }
467 };
468
469 class TestGroup : public TestCaseGroup
470 {
471 public:
472 TestGroup (Context& context);
473 void init (void);
474 private:
475 ES3CheckerFactory m_checkerFactory;
476 fboc::Context m_fboc;
477 };
478
init(void)479 void TestGroup::init (void)
480 {
481 addChild(m_fboc.createRenderableTests());
482 addChild(m_fboc.createAttachmentTests());
483 addChild(m_fboc.createSizeTests());
484
485 TestCaseGroup* layerTests = new TestCaseGroup(
486 getContext(), "layer", "Tests for layer attachments");
487
488 static const NumLayersParams s_layersParams[] =
489 { // textureKind numLayers attachmentKind
490 { GL_TEXTURE_2D_ARRAY, 1, 0 },
491 { GL_TEXTURE_2D_ARRAY, 1, 3 },
492 { GL_TEXTURE_2D_ARRAY, 4, 3 },
493 { GL_TEXTURE_2D_ARRAY, 4, 15 },
494 { GL_TEXTURE_3D, 1, 0 },
495 { GL_TEXTURE_3D, 1, 15 },
496 { GL_TEXTURE_3D, 4, 15 },
497 { GL_TEXTURE_3D, 64, 15 },
498 };
499
500 for (const NumLayersParams* lp = DE_ARRAY_BEGIN(s_layersParams);
501 lp != DE_ARRAY_END(s_layersParams);
502 ++lp)
503 layerTests->addChild(new NumLayersTest(m_fboc, *lp));
504
505 addChild(layerTests);
506
507 TestCaseGroup* sampleTests = new TestCaseGroup(
508 getContext(), "samples", "Tests for multisample attachments");
509
510 static const NumSamplesParams s_samplesParams[] =
511 {
512 { { 0, SAMPLES_NONE, SAMPLES_NONE } },
513 { { 1, SAMPLES_NONE, SAMPLES_NONE } },
514 { { 2, SAMPLES_NONE, SAMPLES_NONE } },
515 { { 0, SAMPLES_TEXTURE, SAMPLES_NONE } },
516 { { 1, SAMPLES_TEXTURE, SAMPLES_NONE } },
517 { { 2, SAMPLES_TEXTURE, SAMPLES_NONE } },
518 { { 2, 1, SAMPLES_NONE } },
519 { { 2, 2, SAMPLES_NONE } },
520 { { 0, 0, SAMPLES_TEXTURE } },
521 { { 1, 2, 0 } },
522 { { 2, 2, 0 } },
523 { { 1, 1, 1 } },
524 { { 1, 2, 4 } },
525 };
526
527 for (const NumSamplesParams* lp = DE_ARRAY_BEGIN(s_samplesParams);
528 lp != DE_ARRAY_END(s_samplesParams);
529 ++lp)
530 sampleTests->addChild(new NumSamplesTest(m_fboc, *lp));
531
532 addChild(sampleTests);
533 }
534
TestGroup(Context & ctx)535 TestGroup::TestGroup (Context& ctx)
536 : TestCaseGroup (ctx, "completeness", "Completeness tests")
537 , m_checkerFactory ()
538 , m_fboc (ctx.getTestContext(), ctx.getRenderContext(), m_checkerFactory)
539 {
540 const FormatEntries stdRange = GLS_ARRAY_RANGE(s_es3Formats);
541 const FormatExtEntries extRange = GLS_ARRAY_RANGE(s_es3ExtFormats);
542
543 m_fboc.addFormats(stdRange);
544 m_fboc.addExtFormats(extRange);
545 m_fboc.setHaveMulticolorAtts(true); // Vanilla ES3 has multiple color attachments
546 }
547
createFboCompletenessTests(Context & context)548 tcu::TestCaseGroup* createFboCompletenessTests (Context& context)
549 {
550 return new TestGroup(context);
551 }
552
553 } // Functional
554 } // gles3
555 } // deqp
556