1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker * drawElements Quality Program OpenGL ES 3.1 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 Internal format query tests
22*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker
24*35238bceSAndroid Build Coastguard Worker #include "es31fInternalFormatQueryTests.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "gluRenderContext.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "gluStrUtil.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "gluContextInfo.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
31*35238bceSAndroid Build Coastguard Worker
32*35238bceSAndroid Build Coastguard Worker namespace deqp
33*35238bceSAndroid Build Coastguard Worker {
34*35238bceSAndroid Build Coastguard Worker namespace gles31
35*35238bceSAndroid Build Coastguard Worker {
36*35238bceSAndroid Build Coastguard Worker namespace Functional
37*35238bceSAndroid Build Coastguard Worker {
38*35238bceSAndroid Build Coastguard Worker namespace
39*35238bceSAndroid Build Coastguard Worker {
40*35238bceSAndroid Build Coastguard Worker
41*35238bceSAndroid Build Coastguard Worker class FormatSamplesCase : public TestCase
42*35238bceSAndroid Build Coastguard Worker {
43*35238bceSAndroid Build Coastguard Worker public:
44*35238bceSAndroid Build Coastguard Worker enum FormatType
45*35238bceSAndroid Build Coastguard Worker {
46*35238bceSAndroid Build Coastguard Worker FORMAT_COLOR,
47*35238bceSAndroid Build Coastguard Worker FORMAT_INT,
48*35238bceSAndroid Build Coastguard Worker FORMAT_DEPTH_STENCIL
49*35238bceSAndroid Build Coastguard Worker };
50*35238bceSAndroid Build Coastguard Worker
51*35238bceSAndroid Build Coastguard Worker FormatSamplesCase(Context &ctx, const char *name, const char *desc, glw::GLenum texTarget,
52*35238bceSAndroid Build Coastguard Worker glw::GLenum internalFormat, FormatType type);
53*35238bceSAndroid Build Coastguard Worker
54*35238bceSAndroid Build Coastguard Worker private:
55*35238bceSAndroid Build Coastguard Worker void init(void);
56*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void);
57*35238bceSAndroid Build Coastguard Worker
58*35238bceSAndroid Build Coastguard Worker const glw::GLenum m_target;
59*35238bceSAndroid Build Coastguard Worker const glw::GLenum m_internalFormat;
60*35238bceSAndroid Build Coastguard Worker const FormatType m_type;
61*35238bceSAndroid Build Coastguard Worker };
62*35238bceSAndroid Build Coastguard Worker
FormatSamplesCase(Context & ctx,const char * name,const char * desc,glw::GLenum target,glw::GLenum internalFormat,FormatType type)63*35238bceSAndroid Build Coastguard Worker FormatSamplesCase::FormatSamplesCase(Context &ctx, const char *name, const char *desc, glw::GLenum target,
64*35238bceSAndroid Build Coastguard Worker glw::GLenum internalFormat, FormatType type)
65*35238bceSAndroid Build Coastguard Worker : TestCase(ctx, name, desc)
66*35238bceSAndroid Build Coastguard Worker , m_target(target)
67*35238bceSAndroid Build Coastguard Worker , m_internalFormat(internalFormat)
68*35238bceSAndroid Build Coastguard Worker , m_type(type)
69*35238bceSAndroid Build Coastguard Worker {
70*35238bceSAndroid Build Coastguard Worker DE_ASSERT(m_target == GL_TEXTURE_2D_MULTISAMPLE || m_target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY ||
71*35238bceSAndroid Build Coastguard Worker m_target == GL_RENDERBUFFER);
72*35238bceSAndroid Build Coastguard Worker }
73*35238bceSAndroid Build Coastguard Worker
init(void)74*35238bceSAndroid Build Coastguard Worker void FormatSamplesCase::init(void)
75*35238bceSAndroid Build Coastguard Worker {
76*35238bceSAndroid Build Coastguard Worker const bool isTextureTarget =
77*35238bceSAndroid Build Coastguard Worker (m_target == GL_TEXTURE_2D_MULTISAMPLE) || (m_target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY);
78*35238bceSAndroid Build Coastguard Worker auto ctxType = m_context.getRenderContext().getType();
79*35238bceSAndroid Build Coastguard Worker const bool isES32orGL45 = glu::contextSupports(ctxType, glu::ApiType::es(3, 2)) ||
80*35238bceSAndroid Build Coastguard Worker glu::contextSupports(ctxType, glu::ApiType::core(4, 5));
81*35238bceSAndroid Build Coastguard Worker
82*35238bceSAndroid Build Coastguard Worker if (!isES32orGL45 && m_target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY &&
83*35238bceSAndroid Build Coastguard Worker !m_context.getContextInfo().isExtensionSupported("GL_OES_texture_storage_multisample_2d_array"))
84*35238bceSAndroid Build Coastguard Worker TCU_THROW(NotSupportedError, "Test requires OES_texture_storage_multisample_2d_array extension or a context "
85*35238bceSAndroid Build Coastguard Worker "version equal or higher than 3.2");
86*35238bceSAndroid Build Coastguard Worker
87*35238bceSAndroid Build Coastguard Worker // stencil8 textures are not supported without GL_OES_texture_stencil8 extension
88*35238bceSAndroid Build Coastguard Worker if (!isES32orGL45 && isTextureTarget && m_internalFormat == GL_STENCIL_INDEX8 &&
89*35238bceSAndroid Build Coastguard Worker !m_context.getContextInfo().isExtensionSupported("GL_OES_texture_stencil8"))
90*35238bceSAndroid Build Coastguard Worker TCU_THROW(NotSupportedError,
91*35238bceSAndroid Build Coastguard Worker "Test requires GL_OES_texture_stencil8 extension or a context version equal or higher than 3.2");
92*35238bceSAndroid Build Coastguard Worker }
93*35238bceSAndroid Build Coastguard Worker
iterate(void)94*35238bceSAndroid Build Coastguard Worker FormatSamplesCase::IterateResult FormatSamplesCase::iterate(void)
95*35238bceSAndroid Build Coastguard Worker {
96*35238bceSAndroid Build Coastguard Worker const glw::Functions &gl = m_context.getRenderContext().getFunctions();
97*35238bceSAndroid Build Coastguard Worker bool isFloatFormat = false;
98*35238bceSAndroid Build Coastguard Worker bool error = false;
99*35238bceSAndroid Build Coastguard Worker glw::GLint maxSamples = 0;
100*35238bceSAndroid Build Coastguard Worker glw::GLint numSampleCounts = 0;
101*35238bceSAndroid Build Coastguard Worker auto ctxType = m_context.getRenderContext().getType();
102*35238bceSAndroid Build Coastguard Worker const bool isES32orGL45 = glu::contextSupports(ctxType, glu::ApiType::es(3, 2)) ||
103*35238bceSAndroid Build Coastguard Worker glu::contextSupports(ctxType, glu::ApiType::core(4, 5));
104*35238bceSAndroid Build Coastguard Worker
105*35238bceSAndroid Build Coastguard Worker if (!isES32orGL45)
106*35238bceSAndroid Build Coastguard Worker {
107*35238bceSAndroid Build Coastguard Worker if (m_internalFormat == GL_RGBA16F || m_internalFormat == GL_R32F || m_internalFormat == GL_RG32F ||
108*35238bceSAndroid Build Coastguard Worker m_internalFormat == GL_RGBA32F || m_internalFormat == GL_R16F || m_internalFormat == GL_RG16F ||
109*35238bceSAndroid Build Coastguard Worker m_internalFormat == GL_R11F_G11F_B10F)
110*35238bceSAndroid Build Coastguard Worker {
111*35238bceSAndroid Build Coastguard Worker TCU_THROW(NotSupportedError, "The internal format is not supported in a context lower than 3.2");
112*35238bceSAndroid Build Coastguard Worker }
113*35238bceSAndroid Build Coastguard Worker }
114*35238bceSAndroid Build Coastguard Worker else if (m_internalFormat == GL_RGBA16F || m_internalFormat == GL_R32F || m_internalFormat == GL_RG32F ||
115*35238bceSAndroid Build Coastguard Worker m_internalFormat == GL_RGBA32F)
116*35238bceSAndroid Build Coastguard Worker {
117*35238bceSAndroid Build Coastguard Worker isFloatFormat = true;
118*35238bceSAndroid Build Coastguard Worker }
119*35238bceSAndroid Build Coastguard Worker
120*35238bceSAndroid Build Coastguard Worker // Lowest limit
121*35238bceSAndroid Build Coastguard Worker {
122*35238bceSAndroid Build Coastguard Worker const glw::GLenum samplesEnum = (m_type == FORMAT_COLOR) ? (GL_MAX_COLOR_TEXTURE_SAMPLES) :
123*35238bceSAndroid Build Coastguard Worker (m_type == FORMAT_INT) ? (GL_MAX_INTEGER_SAMPLES) :
124*35238bceSAndroid Build Coastguard Worker (GL_MAX_DEPTH_TEXTURE_SAMPLES);
125*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "Format must support sample count of "
126*35238bceSAndroid Build Coastguard Worker << glu::getGettableStateStr(samplesEnum) << tcu::TestLog::EndMessage;
127*35238bceSAndroid Build Coastguard Worker
128*35238bceSAndroid Build Coastguard Worker gl.getIntegerv(samplesEnum, &maxSamples);
129*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "get MAX_*_SAMPLES");
130*35238bceSAndroid Build Coastguard Worker
131*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << glu::getGettableStateStr(samplesEnum) << " = " << maxSamples
132*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
133*35238bceSAndroid Build Coastguard Worker
134*35238bceSAndroid Build Coastguard Worker if (maxSamples < 1)
135*35238bceSAndroid Build Coastguard Worker {
136*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "ERROR: minimum value of "
137*35238bceSAndroid Build Coastguard Worker << glu::getGettableStateStr(samplesEnum) << " is 1" << tcu::TestLog::EndMessage;
138*35238bceSAndroid Build Coastguard Worker error = true;
139*35238bceSAndroid Build Coastguard Worker }
140*35238bceSAndroid Build Coastguard Worker }
141*35238bceSAndroid Build Coastguard Worker
142*35238bceSAndroid Build Coastguard Worker // Number of sample counts
143*35238bceSAndroid Build Coastguard Worker {
144*35238bceSAndroid Build Coastguard Worker gl.getInternalformativ(m_target, m_internalFormat, GL_NUM_SAMPLE_COUNTS, 1, &numSampleCounts);
145*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "get GL_NUM_SAMPLE_COUNTS");
146*35238bceSAndroid Build Coastguard Worker
147*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "GL_NUM_SAMPLE_COUNTS = " << numSampleCounts
148*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
149*35238bceSAndroid Build Coastguard Worker
150*35238bceSAndroid Build Coastguard Worker if (!isFloatFormat)
151*35238bceSAndroid Build Coastguard Worker {
152*35238bceSAndroid Build Coastguard Worker if (numSampleCounts < 1)
153*35238bceSAndroid Build Coastguard Worker {
154*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog()
155*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::Message
156*35238bceSAndroid Build Coastguard Worker << "ERROR: Format MUST support some multisample configuration, got GL_NUM_SAMPLE_COUNTS = "
157*35238bceSAndroid Build Coastguard Worker << numSampleCounts << tcu::TestLog::EndMessage;
158*35238bceSAndroid Build Coastguard Worker error = true;
159*35238bceSAndroid Build Coastguard Worker }
160*35238bceSAndroid Build Coastguard Worker }
161*35238bceSAndroid Build Coastguard Worker }
162*35238bceSAndroid Build Coastguard Worker
163*35238bceSAndroid Build Coastguard Worker // Sample counts
164*35238bceSAndroid Build Coastguard Worker {
165*35238bceSAndroid Build Coastguard Worker tcu::MessageBuilder samplesMsg(&m_testCtx.getLog());
166*35238bceSAndroid Build Coastguard Worker std::vector<glw::GLint> samples(numSampleCounts > 0 ? numSampleCounts : 1);
167*35238bceSAndroid Build Coastguard Worker
168*35238bceSAndroid Build Coastguard Worker if (numSampleCounts > 0 || isFloatFormat)
169*35238bceSAndroid Build Coastguard Worker {
170*35238bceSAndroid Build Coastguard Worker gl.getInternalformativ(m_target, m_internalFormat, GL_SAMPLES, numSampleCounts, &samples[0]);
171*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "get GL_SAMPLES");
172*35238bceSAndroid Build Coastguard Worker }
173*35238bceSAndroid Build Coastguard Worker else
174*35238bceSAndroid Build Coastguard Worker TCU_FAIL("glGetInternalFormativ() reported 0 supported sample counts");
175*35238bceSAndroid Build Coastguard Worker
176*35238bceSAndroid Build Coastguard Worker // make a pretty log
177*35238bceSAndroid Build Coastguard Worker
178*35238bceSAndroid Build Coastguard Worker samplesMsg << "GL_SAMPLES = [";
179*35238bceSAndroid Build Coastguard Worker for (size_t ndx = 0; ndx < samples.size(); ++ndx)
180*35238bceSAndroid Build Coastguard Worker {
181*35238bceSAndroid Build Coastguard Worker if (ndx)
182*35238bceSAndroid Build Coastguard Worker samplesMsg << ", ";
183*35238bceSAndroid Build Coastguard Worker samplesMsg << samples[ndx];
184*35238bceSAndroid Build Coastguard Worker }
185*35238bceSAndroid Build Coastguard Worker samplesMsg << "]" << tcu::TestLog::EndMessage;
186*35238bceSAndroid Build Coastguard Worker
187*35238bceSAndroid Build Coastguard Worker // Samples are in order
188*35238bceSAndroid Build Coastguard Worker for (size_t ndx = 1; ndx < samples.size(); ++ndx)
189*35238bceSAndroid Build Coastguard Worker {
190*35238bceSAndroid Build Coastguard Worker if (samples[ndx - 1] <= samples[ndx])
191*35238bceSAndroid Build Coastguard Worker {
192*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "ERROR: Samples must be ordered descending."
193*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
194*35238bceSAndroid Build Coastguard Worker error = true;
195*35238bceSAndroid Build Coastguard Worker break;
196*35238bceSAndroid Build Coastguard Worker }
197*35238bceSAndroid Build Coastguard Worker }
198*35238bceSAndroid Build Coastguard Worker
199*35238bceSAndroid Build Coastguard Worker // samples are positive
200*35238bceSAndroid Build Coastguard Worker for (size_t ndx = 1; ndx < samples.size(); ++ndx)
201*35238bceSAndroid Build Coastguard Worker {
202*35238bceSAndroid Build Coastguard Worker if (samples[ndx - 1] <= 0)
203*35238bceSAndroid Build Coastguard Worker {
204*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "ERROR: Only positive SAMPLES allowed."
205*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
206*35238bceSAndroid Build Coastguard Worker error = true;
207*35238bceSAndroid Build Coastguard Worker break;
208*35238bceSAndroid Build Coastguard Worker }
209*35238bceSAndroid Build Coastguard Worker }
210*35238bceSAndroid Build Coastguard Worker
211*35238bceSAndroid Build Coastguard Worker // maxSamples must be supported
212*35238bceSAndroid Build Coastguard Worker if (!isFloatFormat)
213*35238bceSAndroid Build Coastguard Worker {
214*35238bceSAndroid Build Coastguard Worker if (samples[0] < maxSamples)
215*35238bceSAndroid Build Coastguard Worker {
216*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "ERROR: MAX_*_SAMPLES must be supported."
217*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
218*35238bceSAndroid Build Coastguard Worker error = true;
219*35238bceSAndroid Build Coastguard Worker }
220*35238bceSAndroid Build Coastguard Worker }
221*35238bceSAndroid Build Coastguard Worker }
222*35238bceSAndroid Build Coastguard Worker
223*35238bceSAndroid Build Coastguard Worker // Result
224*35238bceSAndroid Build Coastguard Worker if (!error)
225*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
226*35238bceSAndroid Build Coastguard Worker else
227*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid value");
228*35238bceSAndroid Build Coastguard Worker
229*35238bceSAndroid Build Coastguard Worker return STOP;
230*35238bceSAndroid Build Coastguard Worker }
231*35238bceSAndroid Build Coastguard Worker
232*35238bceSAndroid Build Coastguard Worker class NumSampleCountsBufferCase : public TestCase
233*35238bceSAndroid Build Coastguard Worker {
234*35238bceSAndroid Build Coastguard Worker public:
235*35238bceSAndroid Build Coastguard Worker NumSampleCountsBufferCase(Context &ctx, const char *name, const char *desc);
236*35238bceSAndroid Build Coastguard Worker
237*35238bceSAndroid Build Coastguard Worker private:
238*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void);
239*35238bceSAndroid Build Coastguard Worker };
240*35238bceSAndroid Build Coastguard Worker
NumSampleCountsBufferCase(Context & ctx,const char * name,const char * desc)241*35238bceSAndroid Build Coastguard Worker NumSampleCountsBufferCase::NumSampleCountsBufferCase(Context &ctx, const char *name, const char *desc)
242*35238bceSAndroid Build Coastguard Worker : TestCase(ctx, name, desc)
243*35238bceSAndroid Build Coastguard Worker {
244*35238bceSAndroid Build Coastguard Worker }
245*35238bceSAndroid Build Coastguard Worker
iterate(void)246*35238bceSAndroid Build Coastguard Worker NumSampleCountsBufferCase::IterateResult NumSampleCountsBufferCase::iterate(void)
247*35238bceSAndroid Build Coastguard Worker {
248*35238bceSAndroid Build Coastguard Worker const glw::GLint defaultValue = -123; // queries always return positive values
249*35238bceSAndroid Build Coastguard Worker const glw::Functions &gl = m_context.getRenderContext().getFunctions();
250*35238bceSAndroid Build Coastguard Worker bool error = false;
251*35238bceSAndroid Build Coastguard Worker
252*35238bceSAndroid Build Coastguard Worker // Query to larger buffer
253*35238bceSAndroid Build Coastguard Worker {
254*35238bceSAndroid Build Coastguard Worker glw::GLint buffer[2] = {defaultValue, defaultValue};
255*35238bceSAndroid Build Coastguard Worker
256*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "Querying GL_NUM_SAMPLE_COUNTS to larger-than-needed buffer."
257*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
258*35238bceSAndroid Build Coastguard Worker gl.getInternalformativ(GL_TEXTURE_2D_MULTISAMPLE, GL_RGBA8, GL_NUM_SAMPLE_COUNTS, 2, buffer);
259*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "get GL_NUM_SAMPLE_COUNTS");
260*35238bceSAndroid Build Coastguard Worker
261*35238bceSAndroid Build Coastguard Worker if (buffer[1] != defaultValue)
262*35238bceSAndroid Build Coastguard Worker {
263*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "ERROR: trailing values were modified."
264*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
265*35238bceSAndroid Build Coastguard Worker error = true;
266*35238bceSAndroid Build Coastguard Worker }
267*35238bceSAndroid Build Coastguard Worker }
268*35238bceSAndroid Build Coastguard Worker
269*35238bceSAndroid Build Coastguard Worker // Query to empty buffer
270*35238bceSAndroid Build Coastguard Worker {
271*35238bceSAndroid Build Coastguard Worker glw::GLint buffer[1] = {defaultValue};
272*35238bceSAndroid Build Coastguard Worker
273*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "Querying GL_NUM_SAMPLE_COUNTS to zero-sized buffer."
274*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
275*35238bceSAndroid Build Coastguard Worker gl.getInternalformativ(GL_TEXTURE_2D_MULTISAMPLE, GL_RGBA8, GL_NUM_SAMPLE_COUNTS, 0, buffer);
276*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "get GL_NUM_SAMPLE_COUNTS");
277*35238bceSAndroid Build Coastguard Worker
278*35238bceSAndroid Build Coastguard Worker if (buffer[0] != defaultValue)
279*35238bceSAndroid Build Coastguard Worker {
280*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "ERROR: Query wrote over buffer bounds."
281*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
282*35238bceSAndroid Build Coastguard Worker error = true;
283*35238bceSAndroid Build Coastguard Worker }
284*35238bceSAndroid Build Coastguard Worker }
285*35238bceSAndroid Build Coastguard Worker
286*35238bceSAndroid Build Coastguard Worker // Result
287*35238bceSAndroid Build Coastguard Worker if (!error)
288*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
289*35238bceSAndroid Build Coastguard Worker else
290*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Unexpected buffer modification");
291*35238bceSAndroid Build Coastguard Worker
292*35238bceSAndroid Build Coastguard Worker return STOP;
293*35238bceSAndroid Build Coastguard Worker }
294*35238bceSAndroid Build Coastguard Worker
295*35238bceSAndroid Build Coastguard Worker class SamplesBufferCase : public TestCase
296*35238bceSAndroid Build Coastguard Worker {
297*35238bceSAndroid Build Coastguard Worker public:
298*35238bceSAndroid Build Coastguard Worker SamplesBufferCase(Context &ctx, const char *name, const char *desc);
299*35238bceSAndroid Build Coastguard Worker
300*35238bceSAndroid Build Coastguard Worker private:
301*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void);
302*35238bceSAndroid Build Coastguard Worker };
303*35238bceSAndroid Build Coastguard Worker
SamplesBufferCase(Context & ctx,const char * name,const char * desc)304*35238bceSAndroid Build Coastguard Worker SamplesBufferCase::SamplesBufferCase(Context &ctx, const char *name, const char *desc) : TestCase(ctx, name, desc)
305*35238bceSAndroid Build Coastguard Worker {
306*35238bceSAndroid Build Coastguard Worker }
307*35238bceSAndroid Build Coastguard Worker
iterate(void)308*35238bceSAndroid Build Coastguard Worker SamplesBufferCase::IterateResult SamplesBufferCase::iterate(void)
309*35238bceSAndroid Build Coastguard Worker {
310*35238bceSAndroid Build Coastguard Worker const glw::GLint defaultValue = -123; // queries always return positive values
311*35238bceSAndroid Build Coastguard Worker const glw::Functions &gl = m_context.getRenderContext().getFunctions();
312*35238bceSAndroid Build Coastguard Worker bool error = false;
313*35238bceSAndroid Build Coastguard Worker
314*35238bceSAndroid Build Coastguard Worker glw::GLint numSampleCounts = 0;
315*35238bceSAndroid Build Coastguard Worker
316*35238bceSAndroid Build Coastguard Worker // Number of sample counts
317*35238bceSAndroid Build Coastguard Worker {
318*35238bceSAndroid Build Coastguard Worker gl.getInternalformativ(GL_TEXTURE_2D_MULTISAMPLE, GL_RGBA8, GL_NUM_SAMPLE_COUNTS, 1, &numSampleCounts);
319*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "get GL_NUM_SAMPLE_COUNTS");
320*35238bceSAndroid Build Coastguard Worker
321*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "GL_NUM_SAMPLE_COUNTS = " << numSampleCounts
322*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
323*35238bceSAndroid Build Coastguard Worker }
324*35238bceSAndroid Build Coastguard Worker
325*35238bceSAndroid Build Coastguard Worker if (numSampleCounts < 1)
326*35238bceSAndroid Build Coastguard Worker {
327*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message
328*35238bceSAndroid Build Coastguard Worker << "ERROR: Format MUST support some multisample configuration, got GL_NUM_SAMPLE_COUNTS = "
329*35238bceSAndroid Build Coastguard Worker << numSampleCounts << tcu::TestLog::EndMessage;
330*35238bceSAndroid Build Coastguard Worker error = true;
331*35238bceSAndroid Build Coastguard Worker }
332*35238bceSAndroid Build Coastguard Worker else
333*35238bceSAndroid Build Coastguard Worker {
334*35238bceSAndroid Build Coastguard Worker // Query to larger buffer
335*35238bceSAndroid Build Coastguard Worker {
336*35238bceSAndroid Build Coastguard Worker std::vector<glw::GLint> buffer(numSampleCounts + 1, defaultValue);
337*35238bceSAndroid Build Coastguard Worker
338*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "Querying GL_SAMPLES to larger-than-needed buffer."
339*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
340*35238bceSAndroid Build Coastguard Worker gl.getInternalformativ(GL_TEXTURE_2D_MULTISAMPLE, GL_RGBA8, GL_SAMPLES, (glw::GLsizei)buffer.size(),
341*35238bceSAndroid Build Coastguard Worker &buffer[0]);
342*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "get GL_SAMPLES");
343*35238bceSAndroid Build Coastguard Worker
344*35238bceSAndroid Build Coastguard Worker if (buffer.back() != defaultValue)
345*35238bceSAndroid Build Coastguard Worker {
346*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "ERROR: trailing value was modified."
347*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
348*35238bceSAndroid Build Coastguard Worker error = true;
349*35238bceSAndroid Build Coastguard Worker }
350*35238bceSAndroid Build Coastguard Worker }
351*35238bceSAndroid Build Coastguard Worker
352*35238bceSAndroid Build Coastguard Worker // Query to smaller buffer
353*35238bceSAndroid Build Coastguard Worker if (numSampleCounts > 2)
354*35238bceSAndroid Build Coastguard Worker {
355*35238bceSAndroid Build Coastguard Worker glw::GLint buffer[3] = {defaultValue, defaultValue, defaultValue};
356*35238bceSAndroid Build Coastguard Worker
357*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "Querying GL_SAMPLES to buffer with bufSize=2."
358*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
359*35238bceSAndroid Build Coastguard Worker gl.getInternalformativ(GL_TEXTURE_2D_MULTISAMPLE, GL_RGBA8, GL_SAMPLES, 2, buffer);
360*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "get GL_SAMPLES");
361*35238bceSAndroid Build Coastguard Worker
362*35238bceSAndroid Build Coastguard Worker if (buffer[2] != defaultValue)
363*35238bceSAndroid Build Coastguard Worker {
364*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "ERROR: Query wrote over buffer bounds."
365*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
366*35238bceSAndroid Build Coastguard Worker error = true;
367*35238bceSAndroid Build Coastguard Worker }
368*35238bceSAndroid Build Coastguard Worker }
369*35238bceSAndroid Build Coastguard Worker
370*35238bceSAndroid Build Coastguard Worker // Query to empty buffer
371*35238bceSAndroid Build Coastguard Worker {
372*35238bceSAndroid Build Coastguard Worker glw::GLint buffer[1] = {defaultValue};
373*35238bceSAndroid Build Coastguard Worker
374*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "Querying GL_SAMPLES to zero-sized buffer."
375*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
376*35238bceSAndroid Build Coastguard Worker gl.getInternalformativ(GL_TEXTURE_2D_MULTISAMPLE, GL_RGBA8, GL_SAMPLES, 0, buffer);
377*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "get GL_SAMPLES");
378*35238bceSAndroid Build Coastguard Worker
379*35238bceSAndroid Build Coastguard Worker if (buffer[0] != defaultValue)
380*35238bceSAndroid Build Coastguard Worker {
381*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "ERROR: Query wrote over buffer bounds."
382*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
383*35238bceSAndroid Build Coastguard Worker error = true;
384*35238bceSAndroid Build Coastguard Worker }
385*35238bceSAndroid Build Coastguard Worker }
386*35238bceSAndroid Build Coastguard Worker }
387*35238bceSAndroid Build Coastguard Worker
388*35238bceSAndroid Build Coastguard Worker // Result
389*35238bceSAndroid Build Coastguard Worker if (!error)
390*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
391*35238bceSAndroid Build Coastguard Worker else
392*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Unexpected buffer modification");
393*35238bceSAndroid Build Coastguard Worker
394*35238bceSAndroid Build Coastguard Worker return STOP;
395*35238bceSAndroid Build Coastguard Worker }
396*35238bceSAndroid Build Coastguard Worker
397*35238bceSAndroid Build Coastguard Worker } // namespace
398*35238bceSAndroid Build Coastguard Worker
InternalFormatQueryTests(Context & context)399*35238bceSAndroid Build Coastguard Worker InternalFormatQueryTests::InternalFormatQueryTests(Context &context)
400*35238bceSAndroid Build Coastguard Worker : TestCaseGroup(context, "internal_format", "Internal format queries")
401*35238bceSAndroid Build Coastguard Worker {
402*35238bceSAndroid Build Coastguard Worker }
403*35238bceSAndroid Build Coastguard Worker
~InternalFormatQueryTests(void)404*35238bceSAndroid Build Coastguard Worker InternalFormatQueryTests::~InternalFormatQueryTests(void)
405*35238bceSAndroid Build Coastguard Worker {
406*35238bceSAndroid Build Coastguard Worker }
407*35238bceSAndroid Build Coastguard Worker
init(void)408*35238bceSAndroid Build Coastguard Worker void InternalFormatQueryTests::init(void)
409*35238bceSAndroid Build Coastguard Worker {
410*35238bceSAndroid Build Coastguard Worker static const struct InternalFormat
411*35238bceSAndroid Build Coastguard Worker {
412*35238bceSAndroid Build Coastguard Worker const char *name;
413*35238bceSAndroid Build Coastguard Worker glw::GLenum format;
414*35238bceSAndroid Build Coastguard Worker FormatSamplesCase::FormatType type;
415*35238bceSAndroid Build Coastguard Worker } internalFormats[] = {
416*35238bceSAndroid Build Coastguard Worker // color renderable
417*35238bceSAndroid Build Coastguard Worker {"r8", GL_R8, FormatSamplesCase::FORMAT_COLOR},
418*35238bceSAndroid Build Coastguard Worker {"rg8", GL_RG8, FormatSamplesCase::FORMAT_COLOR},
419*35238bceSAndroid Build Coastguard Worker {"rgb8", GL_RGB8, FormatSamplesCase::FORMAT_COLOR},
420*35238bceSAndroid Build Coastguard Worker {"rgb565", GL_RGB565, FormatSamplesCase::FORMAT_COLOR},
421*35238bceSAndroid Build Coastguard Worker {"rgba4", GL_RGBA4, FormatSamplesCase::FORMAT_COLOR},
422*35238bceSAndroid Build Coastguard Worker {"rgb5_a1", GL_RGB5_A1, FormatSamplesCase::FORMAT_COLOR},
423*35238bceSAndroid Build Coastguard Worker {"rgba8", GL_RGBA8, FormatSamplesCase::FORMAT_COLOR},
424*35238bceSAndroid Build Coastguard Worker {"rgb10_a2", GL_RGB10_A2, FormatSamplesCase::FORMAT_COLOR},
425*35238bceSAndroid Build Coastguard Worker {"rgb10_a2ui", GL_RGB10_A2UI, FormatSamplesCase::FORMAT_INT},
426*35238bceSAndroid Build Coastguard Worker {"srgb8_alpha8", GL_SRGB8_ALPHA8, FormatSamplesCase::FORMAT_COLOR},
427*35238bceSAndroid Build Coastguard Worker {"r8i", GL_R8I, FormatSamplesCase::FORMAT_INT},
428*35238bceSAndroid Build Coastguard Worker {"r8ui", GL_R8UI, FormatSamplesCase::FORMAT_INT},
429*35238bceSAndroid Build Coastguard Worker {"r16i", GL_R16I, FormatSamplesCase::FORMAT_INT},
430*35238bceSAndroid Build Coastguard Worker {"r16ui", GL_R16UI, FormatSamplesCase::FORMAT_INT},
431*35238bceSAndroid Build Coastguard Worker {"r32i", GL_R32I, FormatSamplesCase::FORMAT_INT},
432*35238bceSAndroid Build Coastguard Worker {"r32ui", GL_R32UI, FormatSamplesCase::FORMAT_INT},
433*35238bceSAndroid Build Coastguard Worker {"rg8i", GL_RG8I, FormatSamplesCase::FORMAT_INT},
434*35238bceSAndroid Build Coastguard Worker {"rg8ui", GL_RG8UI, FormatSamplesCase::FORMAT_INT},
435*35238bceSAndroid Build Coastguard Worker {"rg16i", GL_RG16I, FormatSamplesCase::FORMAT_INT},
436*35238bceSAndroid Build Coastguard Worker {"rg16ui", GL_RG16UI, FormatSamplesCase::FORMAT_INT},
437*35238bceSAndroid Build Coastguard Worker {"rg32i", GL_RG32I, FormatSamplesCase::FORMAT_INT},
438*35238bceSAndroid Build Coastguard Worker {"rg32ui", GL_RG32UI, FormatSamplesCase::FORMAT_INT},
439*35238bceSAndroid Build Coastguard Worker {"rgba8i", GL_RGBA8I, FormatSamplesCase::FORMAT_INT},
440*35238bceSAndroid Build Coastguard Worker {"rgba8ui", GL_RGBA8UI, FormatSamplesCase::FORMAT_INT},
441*35238bceSAndroid Build Coastguard Worker {"rgba16i", GL_RGBA16I, FormatSamplesCase::FORMAT_INT},
442*35238bceSAndroid Build Coastguard Worker {"rgba16ui", GL_RGBA16UI, FormatSamplesCase::FORMAT_INT},
443*35238bceSAndroid Build Coastguard Worker {"rgba32i", GL_RGBA32I, FormatSamplesCase::FORMAT_INT},
444*35238bceSAndroid Build Coastguard Worker {"rgba32ui", GL_RGBA32UI, FormatSamplesCase::FORMAT_INT},
445*35238bceSAndroid Build Coastguard Worker
446*35238bceSAndroid Build Coastguard Worker // float formats
447*35238bceSAndroid Build Coastguard Worker {"r16f", GL_R16F, FormatSamplesCase::FORMAT_COLOR},
448*35238bceSAndroid Build Coastguard Worker {"rg16f", GL_RG16F, FormatSamplesCase::FORMAT_COLOR},
449*35238bceSAndroid Build Coastguard Worker {"rgba16f", GL_RGBA16F, FormatSamplesCase::FORMAT_COLOR},
450*35238bceSAndroid Build Coastguard Worker {"r32f", GL_R32F, FormatSamplesCase::FORMAT_INT},
451*35238bceSAndroid Build Coastguard Worker {"rg32f", GL_RG32F, FormatSamplesCase::FORMAT_INT},
452*35238bceSAndroid Build Coastguard Worker {"rgba32f", GL_RGBA32F, FormatSamplesCase::FORMAT_INT},
453*35238bceSAndroid Build Coastguard Worker {"r11f_g11f_b10f", GL_R11F_G11F_B10F, FormatSamplesCase::FORMAT_COLOR},
454*35238bceSAndroid Build Coastguard Worker
455*35238bceSAndroid Build Coastguard Worker // depth renderable
456*35238bceSAndroid Build Coastguard Worker {"depth_component16", GL_DEPTH_COMPONENT16, FormatSamplesCase::FORMAT_DEPTH_STENCIL},
457*35238bceSAndroid Build Coastguard Worker {"depth_component24", GL_DEPTH_COMPONENT24, FormatSamplesCase::FORMAT_DEPTH_STENCIL},
458*35238bceSAndroid Build Coastguard Worker {"depth_component32f", GL_DEPTH_COMPONENT32F, FormatSamplesCase::FORMAT_DEPTH_STENCIL},
459*35238bceSAndroid Build Coastguard Worker {"depth24_stencil8", GL_DEPTH24_STENCIL8, FormatSamplesCase::FORMAT_DEPTH_STENCIL},
460*35238bceSAndroid Build Coastguard Worker {"depth32f_stencil8", GL_DEPTH32F_STENCIL8, FormatSamplesCase::FORMAT_DEPTH_STENCIL},
461*35238bceSAndroid Build Coastguard Worker
462*35238bceSAndroid Build Coastguard Worker // stencil renderable
463*35238bceSAndroid Build Coastguard Worker {"stencil_index8", GL_STENCIL_INDEX8, FormatSamplesCase::FORMAT_DEPTH_STENCIL}
464*35238bceSAndroid Build Coastguard Worker // DEPTH24_STENCIL8, duplicate
465*35238bceSAndroid Build Coastguard Worker // DEPTH32F_STENCIL8 duplicate
466*35238bceSAndroid Build Coastguard Worker };
467*35238bceSAndroid Build Coastguard Worker
468*35238bceSAndroid Build Coastguard Worker static const struct
469*35238bceSAndroid Build Coastguard Worker {
470*35238bceSAndroid Build Coastguard Worker const char *name;
471*35238bceSAndroid Build Coastguard Worker uint32_t target;
472*35238bceSAndroid Build Coastguard Worker } textureTargets[] = {
473*35238bceSAndroid Build Coastguard Worker {"renderbuffer", GL_RENDERBUFFER},
474*35238bceSAndroid Build Coastguard Worker {"texture_2d_multisample", GL_TEXTURE_2D_MULTISAMPLE},
475*35238bceSAndroid Build Coastguard Worker {"texture_2d_multisample_array", GL_TEXTURE_2D_MULTISAMPLE_ARRAY},
476*35238bceSAndroid Build Coastguard Worker };
477*35238bceSAndroid Build Coastguard Worker
478*35238bceSAndroid Build Coastguard Worker for (int groupNdx = 0; groupNdx < DE_LENGTH_OF_ARRAY(textureTargets); ++groupNdx)
479*35238bceSAndroid Build Coastguard Worker {
480*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *const group =
481*35238bceSAndroid Build Coastguard Worker new tcu::TestCaseGroup(m_testCtx, textureTargets[groupNdx].name,
482*35238bceSAndroid Build Coastguard Worker glu::getInternalFormatTargetName(textureTargets[groupNdx].target));
483*35238bceSAndroid Build Coastguard Worker const glw::GLenum texTarget = textureTargets[groupNdx].target;
484*35238bceSAndroid Build Coastguard Worker
485*35238bceSAndroid Build Coastguard Worker addChild(group);
486*35238bceSAndroid Build Coastguard Worker
487*35238bceSAndroid Build Coastguard Worker for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(internalFormats); ++caseNdx)
488*35238bceSAndroid Build Coastguard Worker {
489*35238bceSAndroid Build Coastguard Worker const std::string name = std::string(internalFormats[caseNdx].name) + "_samples";
490*35238bceSAndroid Build Coastguard Worker const std::string desc = std::string("Verify GL_SAMPLES of ") + internalFormats[caseNdx].name;
491*35238bceSAndroid Build Coastguard Worker
492*35238bceSAndroid Build Coastguard Worker group->addChild(new FormatSamplesCase(m_context, name.c_str(), desc.c_str(), texTarget,
493*35238bceSAndroid Build Coastguard Worker internalFormats[caseNdx].format, internalFormats[caseNdx].type));
494*35238bceSAndroid Build Coastguard Worker }
495*35238bceSAndroid Build Coastguard Worker }
496*35238bceSAndroid Build Coastguard Worker
497*35238bceSAndroid Build Coastguard Worker // Check buffer sizes are honored
498*35238bceSAndroid Build Coastguard Worker {
499*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *const group =
500*35238bceSAndroid Build Coastguard Worker new tcu::TestCaseGroup(m_testCtx, "partial_query", "Query data to too short a buffer");
501*35238bceSAndroid Build Coastguard Worker
502*35238bceSAndroid Build Coastguard Worker addChild(group);
503*35238bceSAndroid Build Coastguard Worker
504*35238bceSAndroid Build Coastguard Worker group->addChild(new NumSampleCountsBufferCase(m_context, "num_sample_counts",
505*35238bceSAndroid Build Coastguard Worker "Query GL_NUM_SAMPLE_COUNTS to too short a buffer"));
506*35238bceSAndroid Build Coastguard Worker group->addChild(new SamplesBufferCase(m_context, "samples", "Query GL_SAMPLES to too short a buffer"));
507*35238bceSAndroid Build Coastguard Worker }
508*35238bceSAndroid Build Coastguard Worker }
509*35238bceSAndroid Build Coastguard Worker
510*35238bceSAndroid Build Coastguard Worker } // namespace Functional
511*35238bceSAndroid Build Coastguard Worker } // namespace gles31
512*35238bceSAndroid Build Coastguard Worker } // namespace deqp
513