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