xref: /aosp_15_r20/external/deqp/modules/gles3/functional/es3fFboTestCase.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program OpenGL ES 3.0 Module
3*35238bceSAndroid Build Coastguard Worker  * -------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  *
5*35238bceSAndroid Build Coastguard Worker  * Copyright 2014 The Android Open Source Project
6*35238bceSAndroid Build Coastguard Worker  *
7*35238bceSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker  *
11*35238bceSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker  *
13*35238bceSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker  * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker  *
19*35238bceSAndroid Build Coastguard Worker  *//*!
20*35238bceSAndroid Build Coastguard Worker  * \file
21*35238bceSAndroid Build Coastguard Worker  * \brief Base class for FBO tests.
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "es3fFboTestCase.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "es3fFboTestUtil.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "tcuImageCompare.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "sglrGLContext.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "sglrReferenceContext.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "gluStrUtil.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "gluContextInfo.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "deRandom.hpp"
34*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
35*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
36*35238bceSAndroid Build Coastguard Worker 
37*35238bceSAndroid Build Coastguard Worker #include <algorithm>
38*35238bceSAndroid Build Coastguard Worker 
39*35238bceSAndroid Build Coastguard Worker namespace deqp
40*35238bceSAndroid Build Coastguard Worker {
41*35238bceSAndroid Build Coastguard Worker namespace gles3
42*35238bceSAndroid Build Coastguard Worker {
43*35238bceSAndroid Build Coastguard Worker namespace Functional
44*35238bceSAndroid Build Coastguard Worker {
45*35238bceSAndroid Build Coastguard Worker 
46*35238bceSAndroid Build Coastguard Worker using std::string;
47*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
48*35238bceSAndroid Build Coastguard Worker 
FboTestCase(Context & context,const char * name,const char * description,bool useScreenSizedViewport)49*35238bceSAndroid Build Coastguard Worker FboTestCase::FboTestCase(Context &context, const char *name, const char *description, bool useScreenSizedViewport)
50*35238bceSAndroid Build Coastguard Worker     : TestCase(context, name, description)
51*35238bceSAndroid Build Coastguard Worker     , m_viewportWidth(useScreenSizedViewport ? context.getRenderTarget().getWidth() : 128)
52*35238bceSAndroid Build Coastguard Worker     , m_viewportHeight(useScreenSizedViewport ? context.getRenderTarget().getHeight() : 128)
53*35238bceSAndroid Build Coastguard Worker {
54*35238bceSAndroid Build Coastguard Worker }
55*35238bceSAndroid Build Coastguard Worker 
~FboTestCase(void)56*35238bceSAndroid Build Coastguard Worker FboTestCase::~FboTestCase(void)
57*35238bceSAndroid Build Coastguard Worker {
58*35238bceSAndroid Build Coastguard Worker }
59*35238bceSAndroid Build Coastguard Worker 
iterate(void)60*35238bceSAndroid Build Coastguard Worker FboTestCase::IterateResult FboTestCase::iterate(void)
61*35238bceSAndroid Build Coastguard Worker {
62*35238bceSAndroid Build Coastguard Worker     glu::RenderContext &renderCtx         = TestCase::m_context.getRenderContext();
63*35238bceSAndroid Build Coastguard Worker     const tcu::RenderTarget &renderTarget = renderCtx.getRenderTarget();
64*35238bceSAndroid Build Coastguard Worker     TestLog &log                          = m_testCtx.getLog();
65*35238bceSAndroid Build Coastguard Worker 
66*35238bceSAndroid Build Coastguard Worker     // Viewport.
67*35238bceSAndroid Build Coastguard Worker     de::Random rnd(deStringHash(getName()));
68*35238bceSAndroid Build Coastguard Worker     int width  = deMin32(renderTarget.getWidth(), m_viewportWidth);
69*35238bceSAndroid Build Coastguard Worker     int height = deMin32(renderTarget.getHeight(), m_viewportHeight);
70*35238bceSAndroid Build Coastguard Worker     int x      = rnd.getInt(0, renderTarget.getWidth() - width);
71*35238bceSAndroid Build Coastguard Worker     int y      = rnd.getInt(0, renderTarget.getHeight() - height);
72*35238bceSAndroid Build Coastguard Worker 
73*35238bceSAndroid Build Coastguard Worker     // Surface format and storage is choosen by render().
74*35238bceSAndroid Build Coastguard Worker     tcu::Surface reference;
75*35238bceSAndroid Build Coastguard Worker     tcu::Surface result;
76*35238bceSAndroid Build Coastguard Worker 
77*35238bceSAndroid Build Coastguard Worker     // Call preCheck() that can throw exception if some requirement is not met.
78*35238bceSAndroid Build Coastguard Worker     preCheck();
79*35238bceSAndroid Build Coastguard Worker 
80*35238bceSAndroid Build Coastguard Worker     // Render using GLES3.
81*35238bceSAndroid Build Coastguard Worker     try
82*35238bceSAndroid Build Coastguard Worker     {
83*35238bceSAndroid Build Coastguard Worker         sglr::GLContext context(renderCtx, log, sglr::GLCONTEXT_LOG_CALLS, tcu::IVec4(x, y, width, height));
84*35238bceSAndroid Build Coastguard Worker         setContext(&context);
85*35238bceSAndroid Build Coastguard Worker         render(result);
86*35238bceSAndroid Build Coastguard Worker 
87*35238bceSAndroid Build Coastguard Worker         // Check error.
88*35238bceSAndroid Build Coastguard Worker         uint32_t err = glGetError();
89*35238bceSAndroid Build Coastguard Worker         if (err != GL_NO_ERROR)
90*35238bceSAndroid Build Coastguard Worker             throw glu::Error(err, glu::getErrorStr(err).toString().c_str(), DE_NULL, __FILE__, __LINE__);
91*35238bceSAndroid Build Coastguard Worker 
92*35238bceSAndroid Build Coastguard Worker         setContext(DE_NULL);
93*35238bceSAndroid Build Coastguard Worker     }
94*35238bceSAndroid Build Coastguard Worker     catch (const FboTestUtil::FboIncompleteException &e)
95*35238bceSAndroid Build Coastguard Worker     {
96*35238bceSAndroid Build Coastguard Worker         if (e.getReason() == GL_FRAMEBUFFER_UNSUPPORTED)
97*35238bceSAndroid Build Coastguard Worker         {
98*35238bceSAndroid Build Coastguard Worker             log << e;
99*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not supported");
100*35238bceSAndroid Build Coastguard Worker             return STOP;
101*35238bceSAndroid Build Coastguard Worker         }
102*35238bceSAndroid Build Coastguard Worker         else
103*35238bceSAndroid Build Coastguard Worker             throw;
104*35238bceSAndroid Build Coastguard Worker     }
105*35238bceSAndroid Build Coastguard Worker 
106*35238bceSAndroid Build Coastguard Worker     // Render reference.
107*35238bceSAndroid Build Coastguard Worker     {
108*35238bceSAndroid Build Coastguard Worker         sglr::ReferenceContextBuffers buffers(
109*35238bceSAndroid Build Coastguard Worker             tcu::PixelFormat(8, 8, 8, renderTarget.getPixelFormat().alphaBits ? 8 : 0), renderTarget.getDepthBits(),
110*35238bceSAndroid Build Coastguard Worker             renderTarget.getStencilBits(), width, height);
111*35238bceSAndroid Build Coastguard Worker         sglr::ReferenceContext context(sglr::ReferenceContextLimits(renderCtx), buffers.getColorbuffer(),
112*35238bceSAndroid Build Coastguard Worker                                        buffers.getDepthbuffer(), buffers.getStencilbuffer());
113*35238bceSAndroid Build Coastguard Worker 
114*35238bceSAndroid Build Coastguard Worker         setContext(&context);
115*35238bceSAndroid Build Coastguard Worker         render(reference);
116*35238bceSAndroid Build Coastguard Worker         setContext(DE_NULL);
117*35238bceSAndroid Build Coastguard Worker     }
118*35238bceSAndroid Build Coastguard Worker 
119*35238bceSAndroid Build Coastguard Worker     bool isOk = compare(reference, result);
120*35238bceSAndroid Build Coastguard Worker     m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
121*35238bceSAndroid Build Coastguard Worker                             isOk ? "Pass" : "Image comparison failed");
122*35238bceSAndroid Build Coastguard Worker     return STOP;
123*35238bceSAndroid Build Coastguard Worker }
124*35238bceSAndroid Build Coastguard Worker 
compare(const tcu::Surface & reference,const tcu::Surface & result)125*35238bceSAndroid Build Coastguard Worker bool FboTestCase::compare(const tcu::Surface &reference, const tcu::Surface &result)
126*35238bceSAndroid Build Coastguard Worker {
127*35238bceSAndroid Build Coastguard Worker     return tcu::fuzzyCompare(m_testCtx.getLog(), "Result", "Image comparison result", reference, result, 0.05f,
128*35238bceSAndroid Build Coastguard Worker                              tcu::COMPARE_LOG_RESULT);
129*35238bceSAndroid Build Coastguard Worker }
130*35238bceSAndroid Build Coastguard Worker 
readPixels(tcu::Surface & dst,int x,int y,int width,int height,const tcu::TextureFormat & format,const tcu::Vec4 & scale,const tcu::Vec4 & bias)131*35238bceSAndroid Build Coastguard Worker void FboTestCase::readPixels(tcu::Surface &dst, int x, int y, int width, int height, const tcu::TextureFormat &format,
132*35238bceSAndroid Build Coastguard Worker                              const tcu::Vec4 &scale, const tcu::Vec4 &bias)
133*35238bceSAndroid Build Coastguard Worker {
134*35238bceSAndroid Build Coastguard Worker     FboTestUtil::readPixels(*getCurrentContext(), dst, x, y, width, height, format, scale, bias);
135*35238bceSAndroid Build Coastguard Worker }
136*35238bceSAndroid Build Coastguard Worker 
readPixels(tcu::Surface & dst,int x,int y,int width,int height)137*35238bceSAndroid Build Coastguard Worker void FboTestCase::readPixels(tcu::Surface &dst, int x, int y, int width, int height)
138*35238bceSAndroid Build Coastguard Worker {
139*35238bceSAndroid Build Coastguard Worker     getCurrentContext()->readPixels(dst, x, y, width, height);
140*35238bceSAndroid Build Coastguard Worker }
141*35238bceSAndroid Build Coastguard Worker 
checkFramebufferStatus(uint32_t target)142*35238bceSAndroid Build Coastguard Worker void FboTestCase::checkFramebufferStatus(uint32_t target)
143*35238bceSAndroid Build Coastguard Worker {
144*35238bceSAndroid Build Coastguard Worker     uint32_t status = glCheckFramebufferStatus(target);
145*35238bceSAndroid Build Coastguard Worker     if (status != GL_FRAMEBUFFER_COMPLETE)
146*35238bceSAndroid Build Coastguard Worker         throw FboTestUtil::FboIncompleteException(status, __FILE__, __LINE__);
147*35238bceSAndroid Build Coastguard Worker }
148*35238bceSAndroid Build Coastguard Worker 
checkError(void)149*35238bceSAndroid Build Coastguard Worker void FboTestCase::checkError(void)
150*35238bceSAndroid Build Coastguard Worker {
151*35238bceSAndroid Build Coastguard Worker     uint32_t err = glGetError();
152*35238bceSAndroid Build Coastguard Worker     if (err != GL_NO_ERROR)
153*35238bceSAndroid Build Coastguard Worker         throw glu::Error((int)err, (string("Got ") + glu::getErrorStr(err).toString()).c_str(), DE_NULL, __FILE__,
154*35238bceSAndroid Build Coastguard Worker                          __LINE__);
155*35238bceSAndroid Build Coastguard Worker }
156*35238bceSAndroid Build Coastguard Worker 
isRequiredFormat(uint32_t format,glu::RenderContext & renderContext)157*35238bceSAndroid Build Coastguard Worker static bool isRequiredFormat(uint32_t format, glu::RenderContext &renderContext)
158*35238bceSAndroid Build Coastguard Worker {
159*35238bceSAndroid Build Coastguard Worker     switch (format)
160*35238bceSAndroid Build Coastguard Worker     {
161*35238bceSAndroid Build Coastguard Worker     // Color-renderable formats
162*35238bceSAndroid Build Coastguard Worker     case GL_RGBA32I:
163*35238bceSAndroid Build Coastguard Worker     case GL_RGBA32UI:
164*35238bceSAndroid Build Coastguard Worker     case GL_RGBA16I:
165*35238bceSAndroid Build Coastguard Worker     case GL_RGBA16UI:
166*35238bceSAndroid Build Coastguard Worker     case GL_RGBA8:
167*35238bceSAndroid Build Coastguard Worker     case GL_RGBA8I:
168*35238bceSAndroid Build Coastguard Worker     case GL_RGBA8UI:
169*35238bceSAndroid Build Coastguard Worker     case GL_SRGB8_ALPHA8:
170*35238bceSAndroid Build Coastguard Worker     case GL_RGB10_A2:
171*35238bceSAndroid Build Coastguard Worker     case GL_RGB10_A2UI:
172*35238bceSAndroid Build Coastguard Worker     case GL_RGBA4:
173*35238bceSAndroid Build Coastguard Worker     case GL_RGB5_A1:
174*35238bceSAndroid Build Coastguard Worker     case GL_RGB8:
175*35238bceSAndroid Build Coastguard Worker     case GL_RGB565:
176*35238bceSAndroid Build Coastguard Worker     case GL_RG32I:
177*35238bceSAndroid Build Coastguard Worker     case GL_RG32UI:
178*35238bceSAndroid Build Coastguard Worker     case GL_RG16I:
179*35238bceSAndroid Build Coastguard Worker     case GL_RG16UI:
180*35238bceSAndroid Build Coastguard Worker     case GL_RG8:
181*35238bceSAndroid Build Coastguard Worker     case GL_RG8I:
182*35238bceSAndroid Build Coastguard Worker     case GL_RG8UI:
183*35238bceSAndroid Build Coastguard Worker     case GL_R32I:
184*35238bceSAndroid Build Coastguard Worker     case GL_R32UI:
185*35238bceSAndroid Build Coastguard Worker     case GL_R16I:
186*35238bceSAndroid Build Coastguard Worker     case GL_R16UI:
187*35238bceSAndroid Build Coastguard Worker     case GL_R8:
188*35238bceSAndroid Build Coastguard Worker     case GL_R8I:
189*35238bceSAndroid Build Coastguard Worker     case GL_R8UI:
190*35238bceSAndroid Build Coastguard Worker         return true;
191*35238bceSAndroid Build Coastguard Worker 
192*35238bceSAndroid Build Coastguard Worker     // Depth formats
193*35238bceSAndroid Build Coastguard Worker     case GL_DEPTH_COMPONENT32F:
194*35238bceSAndroid Build Coastguard Worker     case GL_DEPTH_COMPONENT24:
195*35238bceSAndroid Build Coastguard Worker     case GL_DEPTH_COMPONENT16:
196*35238bceSAndroid Build Coastguard Worker         return true;
197*35238bceSAndroid Build Coastguard Worker 
198*35238bceSAndroid Build Coastguard Worker     // Depth+stencil formats
199*35238bceSAndroid Build Coastguard Worker     case GL_DEPTH32F_STENCIL8:
200*35238bceSAndroid Build Coastguard Worker     case GL_DEPTH24_STENCIL8:
201*35238bceSAndroid Build Coastguard Worker         return true;
202*35238bceSAndroid Build Coastguard Worker 
203*35238bceSAndroid Build Coastguard Worker     // Stencil formats
204*35238bceSAndroid Build Coastguard Worker     case GL_STENCIL_INDEX8:
205*35238bceSAndroid Build Coastguard Worker         return true;
206*35238bceSAndroid Build Coastguard Worker 
207*35238bceSAndroid Build Coastguard Worker     // Float formats
208*35238bceSAndroid Build Coastguard Worker     case GL_RGBA32F:
209*35238bceSAndroid Build Coastguard Worker     case GL_RGB32F:
210*35238bceSAndroid Build Coastguard Worker     case GL_R11F_G11F_B10F:
211*35238bceSAndroid Build Coastguard Worker     case GL_RG32F:
212*35238bceSAndroid Build Coastguard Worker     case GL_R32F:
213*35238bceSAndroid Build Coastguard Worker         return glu::contextSupports(renderContext.getType(), glu::ApiType::es(3, 2));
214*35238bceSAndroid Build Coastguard Worker 
215*35238bceSAndroid Build Coastguard Worker     default:
216*35238bceSAndroid Build Coastguard Worker         return false;
217*35238bceSAndroid Build Coastguard Worker     }
218*35238bceSAndroid Build Coastguard Worker }
219*35238bceSAndroid Build Coastguard Worker 
getEnablingExtensions(uint32_t format,glu::RenderContext & renderContext)220*35238bceSAndroid Build Coastguard Worker static std::vector<std::string> getEnablingExtensions(uint32_t format, glu::RenderContext &renderContext)
221*35238bceSAndroid Build Coastguard Worker {
222*35238bceSAndroid Build Coastguard Worker     const bool isES32 = glu::contextSupports(renderContext.getType(), glu::ApiType::es(3, 2));
223*35238bceSAndroid Build Coastguard Worker     std::vector<std::string> out;
224*35238bceSAndroid Build Coastguard Worker 
225*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(!isRequiredFormat(format, renderContext));
226*35238bceSAndroid Build Coastguard Worker 
227*35238bceSAndroid Build Coastguard Worker     switch (format)
228*35238bceSAndroid Build Coastguard Worker     {
229*35238bceSAndroid Build Coastguard Worker     case GL_RGB16F:
230*35238bceSAndroid Build Coastguard Worker         out.push_back("GL_EXT_color_buffer_half_float");
231*35238bceSAndroid Build Coastguard Worker         break;
232*35238bceSAndroid Build Coastguard Worker 
233*35238bceSAndroid Build Coastguard Worker     case GL_RGBA16F:
234*35238bceSAndroid Build Coastguard Worker     case GL_RG16F:
235*35238bceSAndroid Build Coastguard Worker     case GL_R16F:
236*35238bceSAndroid Build Coastguard Worker         out.push_back("GL_EXT_color_buffer_half_float");
237*35238bceSAndroid Build Coastguard Worker         // Fallthrough
238*35238bceSAndroid Build Coastguard Worker 
239*35238bceSAndroid Build Coastguard Worker     case GL_RGBA32F:
240*35238bceSAndroid Build Coastguard Worker     case GL_RGB32F:
241*35238bceSAndroid Build Coastguard Worker     case GL_R11F_G11F_B10F:
242*35238bceSAndroid Build Coastguard Worker     case GL_RG32F:
243*35238bceSAndroid Build Coastguard Worker     case GL_R32F:
244*35238bceSAndroid Build Coastguard Worker         if (!isES32)
245*35238bceSAndroid Build Coastguard Worker             out.push_back("GL_EXT_color_buffer_float");
246*35238bceSAndroid Build Coastguard Worker         break;
247*35238bceSAndroid Build Coastguard Worker 
248*35238bceSAndroid Build Coastguard Worker     default:
249*35238bceSAndroid Build Coastguard Worker         break;
250*35238bceSAndroid Build Coastguard Worker     }
251*35238bceSAndroid Build Coastguard Worker 
252*35238bceSAndroid Build Coastguard Worker     return out;
253*35238bceSAndroid Build Coastguard Worker }
254*35238bceSAndroid Build Coastguard Worker 
isAnyExtensionSupported(Context & context,const std::vector<std::string> & requiredExts)255*35238bceSAndroid Build Coastguard Worker static bool isAnyExtensionSupported(Context &context, const std::vector<std::string> &requiredExts)
256*35238bceSAndroid Build Coastguard Worker {
257*35238bceSAndroid Build Coastguard Worker     for (std::vector<std::string>::const_iterator iter = requiredExts.begin(); iter != requiredExts.end(); iter++)
258*35238bceSAndroid Build Coastguard Worker     {
259*35238bceSAndroid Build Coastguard Worker         const std::string &extension = *iter;
260*35238bceSAndroid Build Coastguard Worker 
261*35238bceSAndroid Build Coastguard Worker         if (context.getContextInfo().isExtensionSupported(extension.c_str()))
262*35238bceSAndroid Build Coastguard Worker             return true;
263*35238bceSAndroid Build Coastguard Worker     }
264*35238bceSAndroid Build Coastguard Worker 
265*35238bceSAndroid Build Coastguard Worker     return false;
266*35238bceSAndroid Build Coastguard Worker }
267*35238bceSAndroid Build Coastguard Worker 
checkFormatSupport(uint32_t sizedFormat)268*35238bceSAndroid Build Coastguard Worker void FboTestCase::checkFormatSupport(uint32_t sizedFormat)
269*35238bceSAndroid Build Coastguard Worker {
270*35238bceSAndroid Build Coastguard Worker     const bool isCoreFormat = isRequiredFormat(sizedFormat, m_context.getRenderContext());
271*35238bceSAndroid Build Coastguard Worker     const std::vector<std::string> requiredExts =
272*35238bceSAndroid Build Coastguard Worker         (!isCoreFormat) ? getEnablingExtensions(sizedFormat, m_context.getRenderContext()) : std::vector<std::string>();
273*35238bceSAndroid Build Coastguard Worker 
274*35238bceSAndroid Build Coastguard Worker     // Check that we don't try to use invalid formats.
275*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(isCoreFormat || !requiredExts.empty());
276*35238bceSAndroid Build Coastguard Worker 
277*35238bceSAndroid Build Coastguard Worker     if (!requiredExts.empty() && !isAnyExtensionSupported(m_context, requiredExts))
278*35238bceSAndroid Build Coastguard Worker         throw tcu::NotSupportedError("Format not supported");
279*35238bceSAndroid Build Coastguard Worker }
280*35238bceSAndroid Build Coastguard Worker 
getMinimumSampleCount(uint32_t format)281*35238bceSAndroid Build Coastguard Worker static int getMinimumSampleCount(uint32_t format)
282*35238bceSAndroid Build Coastguard Worker {
283*35238bceSAndroid Build Coastguard Worker     switch (format)
284*35238bceSAndroid Build Coastguard Worker     {
285*35238bceSAndroid Build Coastguard Worker     // Core formats
286*35238bceSAndroid Build Coastguard Worker     case GL_RGBA32I:
287*35238bceSAndroid Build Coastguard Worker     case GL_RGBA32UI:
288*35238bceSAndroid Build Coastguard Worker     case GL_RGBA16I:
289*35238bceSAndroid Build Coastguard Worker     case GL_RGBA16UI:
290*35238bceSAndroid Build Coastguard Worker     case GL_RGBA8:
291*35238bceSAndroid Build Coastguard Worker     case GL_RGBA8I:
292*35238bceSAndroid Build Coastguard Worker     case GL_RGBA8UI:
293*35238bceSAndroid Build Coastguard Worker     case GL_SRGB8_ALPHA8:
294*35238bceSAndroid Build Coastguard Worker     case GL_RGB10_A2:
295*35238bceSAndroid Build Coastguard Worker     case GL_RGB10_A2UI:
296*35238bceSAndroid Build Coastguard Worker     case GL_RGBA4:
297*35238bceSAndroid Build Coastguard Worker     case GL_RGB5_A1:
298*35238bceSAndroid Build Coastguard Worker     case GL_RGB8:
299*35238bceSAndroid Build Coastguard Worker     case GL_RGB565:
300*35238bceSAndroid Build Coastguard Worker     case GL_RG32I:
301*35238bceSAndroid Build Coastguard Worker     case GL_RG32UI:
302*35238bceSAndroid Build Coastguard Worker     case GL_RG16I:
303*35238bceSAndroid Build Coastguard Worker     case GL_RG16UI:
304*35238bceSAndroid Build Coastguard Worker     case GL_RG8:
305*35238bceSAndroid Build Coastguard Worker     case GL_RG8I:
306*35238bceSAndroid Build Coastguard Worker     case GL_RG8UI:
307*35238bceSAndroid Build Coastguard Worker     case GL_R32I:
308*35238bceSAndroid Build Coastguard Worker     case GL_R32UI:
309*35238bceSAndroid Build Coastguard Worker     case GL_R16I:
310*35238bceSAndroid Build Coastguard Worker     case GL_R16UI:
311*35238bceSAndroid Build Coastguard Worker     case GL_R8:
312*35238bceSAndroid Build Coastguard Worker     case GL_R8I:
313*35238bceSAndroid Build Coastguard Worker     case GL_R8UI:
314*35238bceSAndroid Build Coastguard Worker     case GL_DEPTH_COMPONENT32F:
315*35238bceSAndroid Build Coastguard Worker     case GL_DEPTH_COMPONENT24:
316*35238bceSAndroid Build Coastguard Worker     case GL_DEPTH_COMPONENT16:
317*35238bceSAndroid Build Coastguard Worker     case GL_DEPTH32F_STENCIL8:
318*35238bceSAndroid Build Coastguard Worker     case GL_DEPTH24_STENCIL8:
319*35238bceSAndroid Build Coastguard Worker     case GL_STENCIL_INDEX8:
320*35238bceSAndroid Build Coastguard Worker         return 4;
321*35238bceSAndroid Build Coastguard Worker 
322*35238bceSAndroid Build Coastguard Worker     // GL_EXT_color_buffer_float
323*35238bceSAndroid Build Coastguard Worker     case GL_R11F_G11F_B10F:
324*35238bceSAndroid Build Coastguard Worker     case GL_RG16F:
325*35238bceSAndroid Build Coastguard Worker     case GL_R16F:
326*35238bceSAndroid Build Coastguard Worker         return 4;
327*35238bceSAndroid Build Coastguard Worker 
328*35238bceSAndroid Build Coastguard Worker     case GL_RGBA32F:
329*35238bceSAndroid Build Coastguard Worker     case GL_RGBA16F:
330*35238bceSAndroid Build Coastguard Worker     case GL_RG32F:
331*35238bceSAndroid Build Coastguard Worker     case GL_R32F:
332*35238bceSAndroid Build Coastguard Worker         return 0;
333*35238bceSAndroid Build Coastguard Worker 
334*35238bceSAndroid Build Coastguard Worker     // GL_EXT_color_buffer_half_float
335*35238bceSAndroid Build Coastguard Worker     case GL_RGB16F:
336*35238bceSAndroid Build Coastguard Worker         return 0;
337*35238bceSAndroid Build Coastguard Worker 
338*35238bceSAndroid Build Coastguard Worker     default:
339*35238bceSAndroid Build Coastguard Worker         DE_FATAL("Unknown format");
340*35238bceSAndroid Build Coastguard Worker         return 0;
341*35238bceSAndroid Build Coastguard Worker     }
342*35238bceSAndroid Build Coastguard Worker }
343*35238bceSAndroid Build Coastguard Worker 
querySampleCounts(const glw::Functions & gl,uint32_t format)344*35238bceSAndroid Build Coastguard Worker static std::vector<int> querySampleCounts(const glw::Functions &gl, uint32_t format)
345*35238bceSAndroid Build Coastguard Worker {
346*35238bceSAndroid Build Coastguard Worker     int numSampleCounts = 0;
347*35238bceSAndroid Build Coastguard Worker     std::vector<int> sampleCounts;
348*35238bceSAndroid Build Coastguard Worker 
349*35238bceSAndroid Build Coastguard Worker     gl.getInternalformativ(GL_RENDERBUFFER, format, GL_NUM_SAMPLE_COUNTS, 1, &numSampleCounts);
350*35238bceSAndroid Build Coastguard Worker 
351*35238bceSAndroid Build Coastguard Worker     if (numSampleCounts > 0)
352*35238bceSAndroid Build Coastguard Worker     {
353*35238bceSAndroid Build Coastguard Worker         sampleCounts.resize(numSampleCounts);
354*35238bceSAndroid Build Coastguard Worker         gl.getInternalformativ(GL_RENDERBUFFER, format, GL_SAMPLES, (glw::GLsizei)sampleCounts.size(),
355*35238bceSAndroid Build Coastguard Worker                                &sampleCounts[0]);
356*35238bceSAndroid Build Coastguard Worker     }
357*35238bceSAndroid Build Coastguard Worker 
358*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to query sample counts for format");
359*35238bceSAndroid Build Coastguard Worker 
360*35238bceSAndroid Build Coastguard Worker     return sampleCounts;
361*35238bceSAndroid Build Coastguard Worker }
362*35238bceSAndroid Build Coastguard Worker 
checkSampleCount(uint32_t sizedFormat,int numSamples)363*35238bceSAndroid Build Coastguard Worker void FboTestCase::checkSampleCount(uint32_t sizedFormat, int numSamples)
364*35238bceSAndroid Build Coastguard Worker {
365*35238bceSAndroid Build Coastguard Worker     const int minSampleCount = getMinimumSampleCount(sizedFormat);
366*35238bceSAndroid Build Coastguard Worker 
367*35238bceSAndroid Build Coastguard Worker     if (numSamples > minSampleCount)
368*35238bceSAndroid Build Coastguard Worker     {
369*35238bceSAndroid Build Coastguard Worker         // Exceeds spec-mandated minimum - need to check.
370*35238bceSAndroid Build Coastguard Worker         const std::vector<int> supportedSampleCounts =
371*35238bceSAndroid Build Coastguard Worker             querySampleCounts(m_context.getRenderContext().getFunctions(), sizedFormat);
372*35238bceSAndroid Build Coastguard Worker 
373*35238bceSAndroid Build Coastguard Worker         if (std::find(supportedSampleCounts.begin(), supportedSampleCounts.end(), numSamples) ==
374*35238bceSAndroid Build Coastguard Worker             supportedSampleCounts.end())
375*35238bceSAndroid Build Coastguard Worker             throw tcu::NotSupportedError("Sample count not supported");
376*35238bceSAndroid Build Coastguard Worker     }
377*35238bceSAndroid Build Coastguard Worker }
378*35238bceSAndroid Build Coastguard Worker 
clearColorBuffer(const tcu::TextureFormat & format,const tcu::Vec4 & value)379*35238bceSAndroid Build Coastguard Worker void FboTestCase::clearColorBuffer(const tcu::TextureFormat &format, const tcu::Vec4 &value)
380*35238bceSAndroid Build Coastguard Worker {
381*35238bceSAndroid Build Coastguard Worker     FboTestUtil::clearColorBuffer(*getCurrentContext(), format, value);
382*35238bceSAndroid Build Coastguard Worker }
383*35238bceSAndroid Build Coastguard Worker 
384*35238bceSAndroid Build Coastguard Worker } // namespace Functional
385*35238bceSAndroid Build Coastguard Worker } // namespace gles3
386*35238bceSAndroid Build Coastguard Worker } // namespace deqp
387