1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 3.1 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 Shader state query tests
22 *//*--------------------------------------------------------------------*/
23
24 #include "es31fShaderStateQueryTests.hpp"
25 #include "es31fInfoLogQueryShared.hpp"
26 #include "glsStateQueryUtil.hpp"
27 #include "tcuTestLog.hpp"
28 #include "tcuStringTemplate.hpp"
29 #include "gluShaderProgram.hpp"
30 #include "gluRenderContext.hpp"
31 #include "gluCallLogWrapper.hpp"
32 #include "gluContextInfo.hpp"
33 #include "gluStrUtil.hpp"
34 #include "glwFunctions.hpp"
35 #include "glwEnums.hpp"
36
37 namespace deqp
38 {
39 namespace gles31
40 {
41 namespace Functional
42 {
43 namespace
44 {
45
brokenShaderSource(const glu::ContextType & contextType)46 static inline std::string brokenShaderSource(const glu::ContextType &contextType)
47 {
48 const std::string glslVersionDecl = glu::getGLSLVersionDeclaration(glu::getContextTypeGLSLVersion(contextType));
49
50 return glslVersionDecl + "\n"
51 "broken, this should not compile,\n"
52 "{";
53 }
54
55 class BaseTypeCase : public TestCase
56 {
57 public:
58 struct TestTypeInfo
59 {
60 glw::GLenum glType;
61 const char *declarationStr;
62 const char *accessStr;
63 };
64
65 BaseTypeCase(Context &ctx, const char *name, const char *desc, const char *extension);
66
67 private:
68 IterateResult iterate(void);
69 virtual std::vector<TestTypeInfo> getInfos(void) const = 0;
70 virtual void checkRequirements(void) const;
71
72 const char *const m_extension;
73 };
74
BaseTypeCase(Context & ctx,const char * name,const char * desc,const char * extension)75 BaseTypeCase::BaseTypeCase(Context &ctx, const char *name, const char *desc, const char *extension)
76 : TestCase(ctx, name, desc)
77 , m_extension(extension)
78 {
79 }
80
iterate(void)81 BaseTypeCase::IterateResult BaseTypeCase::iterate(void)
82 {
83 static const char *const vertexSourceTemplate = "${VERSIONDECL}\n"
84 "in highp vec4 a_position;\n"
85 "void main(void)\n"
86 "{\n"
87 " gl_Position = a_position;\n"
88 "}\n";
89 static const char *const fragmentSourceTemplate = "${VERSIONDECL}\n"
90 "${EXTENSIONSTATEMENT}"
91 "${DECLARATIONSTR};\n"
92 "layout(location = 0) out highp vec4 dEQP_FragColor;\n"
93 "void main(void)\n"
94 "{\n"
95 " dEQP_FragColor = vec4(${ACCESSSTR});\n"
96 "}\n";
97
98 tcu::ResultCollector result(m_testCtx.getLog());
99 std::vector<TestTypeInfo> samplerTypes = getInfos();
100 auto ctxType = m_context.getRenderContext().getType();
101 const bool isES32orGL45 = glu::contextSupports(ctxType, glu::ApiType::es(3, 2)) ||
102 glu::contextSupports(ctxType, glu::ApiType::core(4, 5));
103
104 if (m_extension && !isES32orGL45 && !m_context.getContextInfo().isExtensionSupported(m_extension))
105 throw tcu::NotSupportedError("Test requires " + std::string(m_extension));
106 checkRequirements();
107
108 for (int typeNdx = 0; typeNdx < (int)samplerTypes.size(); ++typeNdx)
109 {
110 const tcu::ScopedLogSection section(
111 m_testCtx.getLog(), std::string(glu::getShaderVarTypeStr(samplerTypes[typeNdx].glType).toString()),
112 "Uniform type " + glu::getShaderVarTypeStr(samplerTypes[typeNdx].glType).toString());
113
114 std::map<std::string, std::string> shaderArgs;
115 shaderArgs["DECLARATIONSTR"] = samplerTypes[typeNdx].declarationStr;
116 shaderArgs["ACCESSSTR"] = samplerTypes[typeNdx].accessStr;
117 shaderArgs["EXTENSIONSTATEMENT"] =
118 (m_extension && !isES32orGL45) ? (std::string() + "#extension " + m_extension + " : require\n") : ("");
119 shaderArgs["VERSIONDECL"] = glu::getGLSLVersionDeclaration(glu::getContextTypeGLSLVersion(ctxType));
120
121 const std::string fragmentSource = tcu::StringTemplate(fragmentSourceTemplate).specialize(shaderArgs);
122 const std::string vertexSource = tcu::StringTemplate(vertexSourceTemplate).specialize(shaderArgs);
123 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
124 glu::ShaderProgram program(m_context.getRenderContext(), glu::ProgramSources()
125 << glu::VertexSource(vertexSource)
126 << glu::FragmentSource(fragmentSource));
127
128 m_testCtx.getLog() << tcu::TestLog::Message << "Building program with uniform sampler of type "
129 << glu::getShaderVarTypeStr(samplerTypes[typeNdx].glType) << tcu::TestLog::EndMessage;
130
131 if (!program.isOk())
132 {
133 m_testCtx.getLog() << program;
134 result.fail("could not build shader");
135 }
136 else
137 {
138 // only one uniform -- uniform at index 0
139 int uniforms = 0;
140 gl.getProgramiv(program.getProgram(), GL_ACTIVE_UNIFORMS, &uniforms);
141
142 if (uniforms != 1)
143 result.fail("Unexpected GL_ACTIVE_UNIFORMS, expected 1");
144 else
145 {
146 // check type
147 const glw::GLuint uniformIndex = 0;
148 glw::GLint type = 0;
149
150 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying uniform type." << tcu::TestLog::EndMessage;
151 gl.getActiveUniformsiv(program.getProgram(), 1, &uniformIndex, GL_UNIFORM_TYPE, &type);
152
153 if (type != (glw::GLint)samplerTypes[typeNdx].glType)
154 {
155 std::ostringstream buf;
156 buf << "Invalid type, expected " << samplerTypes[typeNdx].glType << ", got " << type;
157 result.fail(buf.str());
158 }
159 }
160 }
161
162 GLU_EXPECT_NO_ERROR(gl.getError(), "");
163 }
164
165 result.setTestContextResult(m_testCtx);
166 return STOP;
167 }
168
checkRequirements(void) const169 void BaseTypeCase::checkRequirements(void) const
170 {
171 }
172
173 class CoreSamplerTypeCase : public BaseTypeCase
174 {
175 public:
176 CoreSamplerTypeCase(Context &ctx, const char *name, const char *desc);
177
178 private:
179 std::vector<TestTypeInfo> getInfos(void) const;
180 };
181
CoreSamplerTypeCase(Context & ctx,const char * name,const char * desc)182 CoreSamplerTypeCase::CoreSamplerTypeCase(Context &ctx, const char *name, const char *desc)
183 : BaseTypeCase(ctx, name, desc, DE_NULL)
184 {
185 }
186
getInfos(void) const187 std::vector<BaseTypeCase::TestTypeInfo> CoreSamplerTypeCase::getInfos(void) const
188 {
189 static const TestTypeInfo samplerTypes[] = {
190 {GL_SAMPLER_2D_MULTISAMPLE, "uniform highp sampler2DMS u_sampler",
191 "texelFetch(u_sampler, ivec2(gl_FragCoord.xy), 0)"},
192 {GL_INT_SAMPLER_2D_MULTISAMPLE, "uniform highp isampler2DMS u_sampler",
193 "texelFetch(u_sampler, ivec2(gl_FragCoord.xy), 0)"},
194 {GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE, "uniform highp usampler2DMS u_sampler",
195 "texelFetch(u_sampler, ivec2(gl_FragCoord.xy), 0)"},
196 };
197
198 std::vector<TestTypeInfo> infos;
199 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(samplerTypes); ++ndx)
200 infos.push_back(samplerTypes[ndx]);
201
202 return infos;
203 }
204
205 class MSArraySamplerTypeCase : public BaseTypeCase
206 {
207 public:
208 MSArraySamplerTypeCase(Context &ctx, const char *name, const char *desc);
209
210 private:
211 std::vector<TestTypeInfo> getInfos(void) const;
212 };
213
MSArraySamplerTypeCase(Context & ctx,const char * name,const char * desc)214 MSArraySamplerTypeCase::MSArraySamplerTypeCase(Context &ctx, const char *name, const char *desc)
215 : BaseTypeCase(ctx, name, desc, "GL_OES_texture_storage_multisample_2d_array")
216 {
217 }
218
getInfos(void) const219 std::vector<BaseTypeCase::TestTypeInfo> MSArraySamplerTypeCase::getInfos(void) const
220 {
221 static const TestTypeInfo samplerTypes[] = {
222 {GL_SAMPLER_2D_MULTISAMPLE_ARRAY, "uniform highp sampler2DMSArray u_sampler",
223 "texelFetch(u_sampler, ivec3(gl_FragCoord.xyz), 0)"},
224 {GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY, "uniform highp isampler2DMSArray u_sampler",
225 "texelFetch(u_sampler, ivec3(gl_FragCoord.xyz), 0)"},
226 {GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY, "uniform highp usampler2DMSArray u_sampler",
227 "texelFetch(u_sampler, ivec3(gl_FragCoord.xyz), 0)"},
228 };
229
230 std::vector<TestTypeInfo> infos;
231 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(samplerTypes); ++ndx)
232 infos.push_back(samplerTypes[ndx]);
233
234 return infos;
235 }
236
237 class TextureBufferSamplerTypeCase : public BaseTypeCase
238 {
239 public:
240 TextureBufferSamplerTypeCase(Context &ctx, const char *name, const char *desc);
241
242 private:
243 std::vector<TestTypeInfo> getInfos(void) const;
244 };
245
TextureBufferSamplerTypeCase(Context & ctx,const char * name,const char * desc)246 TextureBufferSamplerTypeCase::TextureBufferSamplerTypeCase(Context &ctx, const char *name, const char *desc)
247 : BaseTypeCase(ctx, name, desc, "GL_EXT_texture_buffer")
248 {
249 }
250
getInfos(void) const251 std::vector<BaseTypeCase::TestTypeInfo> TextureBufferSamplerTypeCase::getInfos(void) const
252 {
253 static const TestTypeInfo samplerTypes[] = {
254 {GL_SAMPLER_BUFFER, "uniform highp samplerBuffer u_sampler", "texelFetch(u_sampler, int(gl_FragCoord.x))"},
255 {GL_INT_SAMPLER_BUFFER, "uniform highp isamplerBuffer u_sampler", "texelFetch(u_sampler, int(gl_FragCoord.x))"},
256 {GL_UNSIGNED_INT_SAMPLER_BUFFER, "uniform highp usamplerBuffer u_sampler",
257 "texelFetch(u_sampler, int(gl_FragCoord.x))"},
258 };
259
260 std::vector<TestTypeInfo> infos;
261 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(samplerTypes); ++ndx)
262 infos.push_back(samplerTypes[ndx]);
263
264 return infos;
265 }
266
267 class TextureBufferImageTypeCase : public BaseTypeCase
268 {
269 public:
270 TextureBufferImageTypeCase(Context &ctx, const char *name, const char *desc);
271
272 private:
273 std::vector<TestTypeInfo> getInfos(void) const;
274 void checkRequirements(void) const;
275 };
276
TextureBufferImageTypeCase(Context & ctx,const char * name,const char * desc)277 TextureBufferImageTypeCase::TextureBufferImageTypeCase(Context &ctx, const char *name, const char *desc)
278 : BaseTypeCase(ctx, name, desc, "GL_EXT_texture_buffer")
279 {
280 }
281
getInfos(void) const282 std::vector<BaseTypeCase::TestTypeInfo> TextureBufferImageTypeCase::getInfos(void) const
283 {
284 static const TestTypeInfo samplerTypes[] = {
285 {GL_IMAGE_BUFFER, "layout(binding=0, rgba8) readonly uniform highp imageBuffer u_image",
286 "imageLoad(u_image, int(gl_FragCoord.x))"},
287 {GL_INT_IMAGE_BUFFER, "layout(binding=0, r32i) readonly uniform highp iimageBuffer u_image",
288 "imageLoad(u_image, int(gl_FragCoord.x))"},
289 {GL_UNSIGNED_INT_IMAGE_BUFFER, "layout(binding=0, r32ui) readonly uniform highp uimageBuffer u_image",
290 "imageLoad(u_image, int(gl_FragCoord.x))"},
291 };
292
293 std::vector<TestTypeInfo> infos;
294 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(samplerTypes); ++ndx)
295 infos.push_back(samplerTypes[ndx]);
296
297 return infos;
298 }
299
checkRequirements(void) const300 void TextureBufferImageTypeCase::checkRequirements(void) const
301 {
302 if (m_context.getContextInfo().getInt(GL_MAX_FRAGMENT_IMAGE_UNIFORMS) < 1)
303 throw tcu::NotSupportedError("Test requires fragment images");
304 }
305
306 class CubeArraySamplerTypeCase : public BaseTypeCase
307 {
308 public:
309 CubeArraySamplerTypeCase(Context &ctx, const char *name, const char *desc);
310
311 private:
312 std::vector<TestTypeInfo> getInfos(void) const;
313 };
314
CubeArraySamplerTypeCase(Context & ctx,const char * name,const char * desc)315 CubeArraySamplerTypeCase::CubeArraySamplerTypeCase(Context &ctx, const char *name, const char *desc)
316 : BaseTypeCase(ctx, name, desc, "GL_EXT_texture_cube_map_array")
317 {
318 }
319
getInfos(void) const320 std::vector<BaseTypeCase::TestTypeInfo> CubeArraySamplerTypeCase::getInfos(void) const
321 {
322 static const TestTypeInfo samplerTypes[] = {
323 {GL_SAMPLER_CUBE_MAP_ARRAY, "uniform highp samplerCubeArray u_sampler",
324 "texture(u_sampler, gl_FragCoord.xxyz)"},
325 {GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW, "uniform highp samplerCubeArrayShadow u_sampler",
326 "texture(u_sampler, gl_FragCoord.xxyz, 0.5)"},
327 {GL_INT_SAMPLER_CUBE_MAP_ARRAY, "uniform highp isamplerCubeArray u_sampler",
328 "texture(u_sampler, gl_FragCoord.xxyz)"},
329 {GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY, "uniform highp usamplerCubeArray u_sampler",
330 "texture(u_sampler, gl_FragCoord.xxyz)"},
331 };
332
333 std::vector<TestTypeInfo> infos;
334 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(samplerTypes); ++ndx)
335 infos.push_back(samplerTypes[ndx]);
336
337 return infos;
338 }
339
340 class CubeArrayImageTypeCase : public BaseTypeCase
341 {
342 public:
343 CubeArrayImageTypeCase(Context &ctx, const char *name, const char *desc);
344
345 private:
346 std::vector<TestTypeInfo> getInfos(void) const;
347 void checkRequirements(void) const;
348 };
349
CubeArrayImageTypeCase(Context & ctx,const char * name,const char * desc)350 CubeArrayImageTypeCase::CubeArrayImageTypeCase(Context &ctx, const char *name, const char *desc)
351 : BaseTypeCase(ctx, name, desc, "GL_EXT_texture_cube_map_array")
352 {
353 }
354
getInfos(void) const355 std::vector<BaseTypeCase::TestTypeInfo> CubeArrayImageTypeCase::getInfos(void) const
356 {
357 static const TestTypeInfo samplerTypes[] = {
358 {GL_IMAGE_CUBE_MAP_ARRAY, "layout(binding=0, rgba8) readonly uniform highp imageCubeArray u_image",
359 "imageLoad(u_image, ivec3(gl_FragCoord.xyx))"},
360 {GL_INT_IMAGE_CUBE_MAP_ARRAY, "layout(binding=0, r32i) readonly uniform highp iimageCubeArray u_image",
361 "imageLoad(u_image, ivec3(gl_FragCoord.xyx))"},
362 {GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY,
363 "layout(binding=0, r32ui) readonly uniform highp uimageCubeArray u_image",
364 "imageLoad(u_image, ivec3(gl_FragCoord.xyx))"},
365 };
366
367 std::vector<TestTypeInfo> infos;
368 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(samplerTypes); ++ndx)
369 infos.push_back(samplerTypes[ndx]);
370
371 return infos;
372 }
373
checkRequirements(void) const374 void CubeArrayImageTypeCase::checkRequirements(void) const
375 {
376 if (m_context.getContextInfo().getInt(GL_MAX_FRAGMENT_IMAGE_UNIFORMS) < 1)
377 throw tcu::NotSupportedError("Test requires fragment images");
378 }
379
380 class ShaderLogCase : public TestCase
381 {
382 public:
383 ShaderLogCase(Context &ctx, const char *name, const char *desc, glu::ShaderType shaderType);
384
385 private:
386 void init(void);
387 IterateResult iterate(void);
388
389 const glu::ShaderType m_shaderType;
390 };
391
ShaderLogCase(Context & ctx,const char * name,const char * desc,glu::ShaderType shaderType)392 ShaderLogCase::ShaderLogCase(Context &ctx, const char *name, const char *desc, glu::ShaderType shaderType)
393 : TestCase(ctx, name, desc)
394 , m_shaderType(shaderType)
395 {
396 }
397
init(void)398 void ShaderLogCase::init(void)
399 {
400 auto ctxType = m_context.getRenderContext().getType();
401 const bool isES32orGL45 = glu::contextSupports(ctxType, glu::ApiType::es(3, 2)) ||
402 glu::contextSupports(ctxType, glu::ApiType::core(4, 5));
403
404 switch (m_shaderType)
405 {
406 case glu::SHADERTYPE_VERTEX:
407 case glu::SHADERTYPE_FRAGMENT:
408 case glu::SHADERTYPE_COMPUTE:
409 break;
410
411 case glu::SHADERTYPE_GEOMETRY:
412 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader") && !isES32orGL45)
413 throw tcu::NotSupportedError(
414 "Test requires GL_EXT_geometry_shader extension or an OpenGL ES 3.2 or higher context.");
415 break;
416
417 case glu::SHADERTYPE_TESSELLATION_CONTROL:
418 case glu::SHADERTYPE_TESSELLATION_EVALUATION:
419 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_tessellation_shader") && !isES32orGL45)
420 throw tcu::NotSupportedError(
421 "Test requires GL_EXT_tessellation_shader extension or an OpenGL ES 3.2 or higher context.");
422 break;
423
424 default:
425 DE_ASSERT(false);
426 break;
427 }
428 }
429
iterate(void)430 ShaderLogCase::IterateResult ShaderLogCase::iterate(void)
431 {
432 using gls::StateQueryUtil::StateQueryMemoryWriteGuard;
433
434 tcu::ResultCollector result(m_testCtx.getLog());
435 glu::CallLogWrapper gl(m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
436 uint32_t shader = 0;
437 const std::string source = brokenShaderSource(m_context.getRenderContext().getType());
438 const char *const brokenSource = source.c_str();
439 StateQueryMemoryWriteGuard<glw::GLint> logLen;
440
441 gl.enableLogging(true);
442
443 m_testCtx.getLog() << tcu::TestLog::Message << "Trying to compile broken shader source."
444 << tcu::TestLog::EndMessage;
445
446 shader = gl.glCreateShader(glu::getGLShaderType(m_shaderType));
447 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "create shader");
448
449 gl.glShaderSource(shader, 1, &brokenSource, DE_NULL);
450 gl.glCompileShader(shader);
451 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "compile");
452
453 gl.glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLen);
454 logLen.verifyValidity(result);
455
456 if (!logLen.isUndefined())
457 verifyInfoLogQuery(result, gl, logLen, shader, &glu::CallLogWrapper::glGetShaderInfoLog, "glGetShaderInfoLog");
458
459 gl.glDeleteShader(shader);
460 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "delete");
461
462 result.setTestContextResult(m_testCtx);
463 return STOP;
464 }
465
466 } // namespace
467
ShaderStateQueryTests(Context & context)468 ShaderStateQueryTests::ShaderStateQueryTests(Context &context)
469 : TestCaseGroup(context, "shader", "Shader state query tests")
470 {
471 }
472
~ShaderStateQueryTests(void)473 ShaderStateQueryTests::~ShaderStateQueryTests(void)
474 {
475 }
476
init(void)477 void ShaderStateQueryTests::init(void)
478 {
479 addChild(new CoreSamplerTypeCase(m_context, "sampler_type", "Sampler type cases"));
480 addChild(new MSArraySamplerTypeCase(m_context, "sampler_type_multisample_array", "MSAA array sampler type cases"));
481 addChild(new TextureBufferSamplerTypeCase(m_context, "sampler_type_texture_buffer",
482 "Texture buffer sampler type cases"));
483 addChild(new TextureBufferImageTypeCase(m_context, "image_type_texture_buffer", "Texture buffer image type cases"));
484 addChild(new CubeArraySamplerTypeCase(m_context, "sampler_type_cube_array", "Cube array sampler type cases"));
485 addChild(new CubeArrayImageTypeCase(m_context, "image_type_cube_array", "Cube array image type cases"));
486
487 // shader info log tests
488 // \note, there exists similar tests in gles3 module. However, the gles31 could use a different
489 // shader compiler with different INFO_LOG bugs.
490 {
491 static const struct
492 {
493 const char *caseName;
494 glu::ShaderType caseType;
495 } shaderTypes[] = {
496 {"info_log_vertex", glu::SHADERTYPE_VERTEX},
497 {"info_log_fragment", glu::SHADERTYPE_FRAGMENT},
498 {"info_log_geometry", glu::SHADERTYPE_GEOMETRY},
499 {"info_log_tess_ctrl", glu::SHADERTYPE_TESSELLATION_CONTROL},
500 {"info_log_tess_eval", glu::SHADERTYPE_TESSELLATION_EVALUATION},
501 {"info_log_compute", glu::SHADERTYPE_COMPUTE},
502 };
503
504 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(shaderTypes); ++ndx)
505 addChild(new ShaderLogCase(m_context, shaderTypes[ndx].caseName, "", shaderTypes[ndx].caseType));
506 }
507 }
508
509 } // namespace Functional
510 } // namespace gles31
511 } // namespace deqp
512