1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 3.1 Module
3 * -------------------------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Shader state query tests
22 *//*--------------------------------------------------------------------*/
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"
46 static const char* const s_brokenSource = "#version 310 es\n"
47 "broken, this should not compile,\n"
50 class BaseTypeCase : public TestCase
56 const char* declarationStr;
57 const char* accessStr;
60 BaseTypeCase (Context& ctx, const char* name, const char* desc, const char* extension);
63 IterateResult iterate (void);
64 virtual std::vector<TestTypeInfo> getInfos (void) const = 0;
65 virtual void checkRequirements (void) const;
67 const char* const m_extension;
70 BaseTypeCase::BaseTypeCase (Context& ctx, const char* name, const char* desc, const char* extension)
71 : TestCase (ctx, name, desc)
72 , m_extension (extension)
76 BaseTypeCase::IterateResult BaseTypeCase::iterate (void)
78 static const char* const vertexSource = "#version 310 es\n"
79 "in highp vec4 a_position;\n"
82 " gl_Position = a_position;\n"
84 static const char* const fragmentSourceTemplate = "#version 310 es\n"
85 "${EXTENSIONSTATEMENT}"
86 "${DECLARATIONSTR};\n"
87 "layout(location = 0) out highp vec4 dEQP_FragColor;\n"
90 " dEQP_FragColor = vec4(${ACCESSSTR});\n"
93 tcu::ResultCollector result (m_testCtx.getLog());
94 std::vector<TestTypeInfo> samplerTypes = getInfos();
96 if (m_extension && !m_context.getContextInfo().isExtensionSupported(m_extension))
97 throw tcu::NotSupportedError("Test requires " + std::string(m_extension));
100 for (int typeNdx = 0; typeNdx < (int)samplerTypes.size(); ++typeNdx)
102 const tcu::ScopedLogSection section (m_testCtx.getLog(),
103 std::string(glu::getShaderVarTypeStr(samplerTypes[typeNdx].glType).toString()),
104 "Uniform type " + glu::getShaderVarTypeStr(samplerTypes[typeNdx].glType).toString());
106 std::map<std::string, std::string> shaderArgs;
107 shaderArgs["DECLARATIONSTR"] = samplerTypes[typeNdx].declarationStr;
108 shaderArgs["ACCESSSTR"] = samplerTypes[typeNdx].accessStr;
109 shaderArgs["EXTENSIONSTATEMENT"] = (m_extension) ? (std::string() + "#extension " + m_extension + " : require\n") : ("");
111 const std::string fragmentSource = tcu::StringTemplate(fragmentSourceTemplate).specialize(shaderArgs);
112 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
113 glu::ShaderProgram program (m_context.getRenderContext(), glu::ProgramSources() << glu::VertexSource(vertexSource) << glu::FragmentSource(fragmentSource));
115 m_testCtx.getLog() << tcu::TestLog::Message << "Building program with uniform sampler of type " << glu::getShaderVarTypeStr(samplerTypes[typeNdx].glType) << tcu::TestLog::EndMessage;
119 m_testCtx.getLog() << program;
120 result.fail("could not build shader");
124 // only one uniform -- uniform at index 0
126 gl.getProgramiv(program.getProgram(), GL_ACTIVE_UNIFORMS, &uniforms);
129 result.fail("Unexpected GL_ACTIVE_UNIFORMS, expected 1");
133 const glw::GLuint uniformIndex = 0;
136 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying uniform type." << tcu::TestLog::EndMessage;
137 gl.getActiveUniformsiv(program.getProgram(), 1, &uniformIndex, GL_UNIFORM_TYPE, &type);
139 if (type != (glw::GLint)samplerTypes[typeNdx].glType)
141 std::ostringstream buf;
142 buf << "Invalid type, expected " << samplerTypes[typeNdx].glType << ", got " << type;
143 result.fail(buf.str());
148 GLU_EXPECT_NO_ERROR(gl.getError(), "");
151 result.setTestContextResult(m_testCtx);
155 void BaseTypeCase::checkRequirements (void) const
159 class CoreSamplerTypeCase : public BaseTypeCase
162 CoreSamplerTypeCase (Context& ctx, const char* name, const char* desc);
165 std::vector<TestTypeInfo> getInfos (void) const;
168 CoreSamplerTypeCase::CoreSamplerTypeCase (Context& ctx, const char* name, const char* desc)
169 : BaseTypeCase(ctx, name, desc, DE_NULL)
173 std::vector<BaseTypeCase::TestTypeInfo> CoreSamplerTypeCase::getInfos (void) const
175 static const TestTypeInfo samplerTypes[] =
177 { GL_SAMPLER_2D_MULTISAMPLE, "uniform highp sampler2DMS u_sampler", "texelFetch(u_sampler, ivec2(gl_FragCoord.xy), 0)" },
178 { GL_INT_SAMPLER_2D_MULTISAMPLE, "uniform highp isampler2DMS u_sampler", "texelFetch(u_sampler, ivec2(gl_FragCoord.xy), 0)" },
179 { GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE, "uniform highp usampler2DMS u_sampler", "texelFetch(u_sampler, ivec2(gl_FragCoord.xy), 0)" },
182 std::vector<TestTypeInfo> infos;
183 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(samplerTypes); ++ndx)
184 infos.push_back(samplerTypes[ndx]);
189 class MSArraySamplerTypeCase : public BaseTypeCase
192 MSArraySamplerTypeCase (Context& ctx, const char* name, const char* desc);
195 std::vector<TestTypeInfo> getInfos (void) const;
198 MSArraySamplerTypeCase::MSArraySamplerTypeCase (Context& ctx, const char* name, const char* desc)
199 : BaseTypeCase(ctx, name, desc, "GL_OES_texture_storage_multisample_2d_array")
203 std::vector<BaseTypeCase::TestTypeInfo> MSArraySamplerTypeCase::getInfos (void) const
205 static const TestTypeInfo samplerTypes[] =
207 { GL_SAMPLER_2D_MULTISAMPLE_ARRAY, "uniform highp sampler2DMSArray u_sampler", "texelFetch(u_sampler, ivec3(gl_FragCoord.xyz), 0)" },
208 { GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY, "uniform highp isampler2DMSArray u_sampler", "texelFetch(u_sampler, ivec3(gl_FragCoord.xyz), 0)" },
209 { GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY, "uniform highp usampler2DMSArray u_sampler", "texelFetch(u_sampler, ivec3(gl_FragCoord.xyz), 0)" },
212 std::vector<TestTypeInfo> infos;
213 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(samplerTypes); ++ndx)
214 infos.push_back(samplerTypes[ndx]);
219 class TextureBufferSamplerTypeCase : public BaseTypeCase
222 TextureBufferSamplerTypeCase (Context& ctx, const char* name, const char* desc);
225 std::vector<TestTypeInfo> getInfos (void) const;
228 TextureBufferSamplerTypeCase::TextureBufferSamplerTypeCase (Context& ctx, const char* name, const char* desc)
229 : BaseTypeCase(ctx, name, desc, "GL_EXT_texture_buffer")
233 std::vector<BaseTypeCase::TestTypeInfo> TextureBufferSamplerTypeCase::getInfos (void) const
235 static const TestTypeInfo samplerTypes[] =
237 { GL_SAMPLER_BUFFER, "uniform highp samplerBuffer u_sampler", "texelFetch(u_sampler, int(gl_FragCoord.x))" },
238 { GL_INT_SAMPLER_BUFFER, "uniform highp isamplerBuffer u_sampler", "texelFetch(u_sampler, int(gl_FragCoord.x))" },
239 { GL_UNSIGNED_INT_SAMPLER_BUFFER, "uniform highp usamplerBuffer u_sampler", "texelFetch(u_sampler, int(gl_FragCoord.x))" },
242 std::vector<TestTypeInfo> infos;
243 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(samplerTypes); ++ndx)
244 infos.push_back(samplerTypes[ndx]);
249 class TextureBufferImageTypeCase : public BaseTypeCase
252 TextureBufferImageTypeCase (Context& ctx, const char* name, const char* desc);
255 std::vector<TestTypeInfo> getInfos (void) const;
256 void checkRequirements (void) const;
259 TextureBufferImageTypeCase::TextureBufferImageTypeCase (Context& ctx, const char* name, const char* desc)
260 : BaseTypeCase(ctx, name, desc, "GL_EXT_texture_buffer")
264 std::vector<BaseTypeCase::TestTypeInfo> TextureBufferImageTypeCase::getInfos (void) const
266 static const TestTypeInfo samplerTypes[] =
268 { GL_IMAGE_BUFFER, "layout(binding=0, rgba8) readonly uniform highp imageBuffer u_image", "imageLoad(u_image, int(gl_FragCoord.x))" },
269 { GL_INT_IMAGE_BUFFER, "layout(binding=0, r32i) readonly uniform highp iimageBuffer u_image", "imageLoad(u_image, int(gl_FragCoord.x))" },
270 { GL_UNSIGNED_INT_IMAGE_BUFFER, "layout(binding=0, r32ui) readonly uniform highp uimageBuffer u_image", "imageLoad(u_image, int(gl_FragCoord.x))" },
273 std::vector<TestTypeInfo> infos;
274 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(samplerTypes); ++ndx)
275 infos.push_back(samplerTypes[ndx]);
280 void TextureBufferImageTypeCase::checkRequirements (void) const
282 if (m_context.getContextInfo().getInt(GL_MAX_FRAGMENT_IMAGE_UNIFORMS) < 1)
283 throw tcu::NotSupportedError("Test requires fragment images");
286 class CubeArraySamplerTypeCase : public BaseTypeCase
289 CubeArraySamplerTypeCase (Context& ctx, const char* name, const char* desc);
292 std::vector<TestTypeInfo> getInfos (void) const;
295 CubeArraySamplerTypeCase::CubeArraySamplerTypeCase (Context& ctx, const char* name, const char* desc)
296 : BaseTypeCase(ctx, name, desc, "GL_EXT_texture_cube_map_array")
300 std::vector<BaseTypeCase::TestTypeInfo> CubeArraySamplerTypeCase::getInfos (void) const
302 static const TestTypeInfo samplerTypes[] =
304 { GL_SAMPLER_CUBE_MAP_ARRAY, "uniform highp samplerCubeArray u_sampler", "texture(u_sampler, gl_FragCoord.xxyz)" },
305 { GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW, "uniform highp samplerCubeArrayShadow u_sampler", "texture(u_sampler, gl_FragCoord.xxyz, 0.5)" },
306 { GL_INT_SAMPLER_CUBE_MAP_ARRAY, "uniform highp isamplerCubeArray u_sampler", "texture(u_sampler, gl_FragCoord.xxyz)" },
307 { GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY, "uniform highp usamplerCubeArray u_sampler", "texture(u_sampler, gl_FragCoord.xxyz)" },
310 std::vector<TestTypeInfo> infos;
311 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(samplerTypes); ++ndx)
312 infos.push_back(samplerTypes[ndx]);
317 class CubeArrayImageTypeCase : public BaseTypeCase
320 CubeArrayImageTypeCase (Context& ctx, const char* name, const char* desc);
323 std::vector<TestTypeInfo> getInfos (void) const;
324 void checkRequirements (void) const;
327 CubeArrayImageTypeCase::CubeArrayImageTypeCase (Context& ctx, const char* name, const char* desc)
328 : BaseTypeCase(ctx, name, desc, "GL_EXT_texture_cube_map_array")
332 std::vector<BaseTypeCase::TestTypeInfo> CubeArrayImageTypeCase::getInfos (void) const
334 static const TestTypeInfo samplerTypes[] =
336 { GL_IMAGE_CUBE_MAP_ARRAY, "layout(binding=0, rgba8) readonly uniform highp imageCubeArray u_image", "imageLoad(u_image, ivec3(gl_FragCoord.xyx))" },
337 { GL_INT_IMAGE_CUBE_MAP_ARRAY, "layout(binding=0, r32i) readonly uniform highp iimageCubeArray u_image", "imageLoad(u_image, ivec3(gl_FragCoord.xyx))" },
338 { GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY, "layout(binding=0, r32ui) readonly uniform highp uimageCubeArray u_image", "imageLoad(u_image, ivec3(gl_FragCoord.xyx))" },
341 std::vector<TestTypeInfo> infos;
342 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(samplerTypes); ++ndx)
343 infos.push_back(samplerTypes[ndx]);
348 void CubeArrayImageTypeCase::checkRequirements (void) const
350 if (m_context.getContextInfo().getInt(GL_MAX_FRAGMENT_IMAGE_UNIFORMS) < 1)
351 throw tcu::NotSupportedError("Test requires fragment images");
354 class ShaderLogCase : public TestCase
357 ShaderLogCase (Context& ctx, const char* name, const char* desc, glu::ShaderType shaderType);
361 IterateResult iterate (void);
363 const glu::ShaderType m_shaderType;
366 ShaderLogCase::ShaderLogCase (Context& ctx, const char* name, const char* desc, glu::ShaderType shaderType)
367 : TestCase (ctx, name, desc)
368 , m_shaderType (shaderType)
372 void ShaderLogCase::init (void)
374 switch (m_shaderType)
376 case glu::SHADERTYPE_VERTEX:
377 case glu::SHADERTYPE_FRAGMENT:
378 case glu::SHADERTYPE_COMPUTE:
381 case glu::SHADERTYPE_GEOMETRY:
382 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
383 throw tcu::NotSupportedError("Test requires GL_EXT_geometry_shader extension");
386 case glu::SHADERTYPE_TESSELLATION_CONTROL:
387 case glu::SHADERTYPE_TESSELLATION_EVALUATION:
388 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_tessellation_shader"))
389 throw tcu::NotSupportedError("Test requires GL_EXT_tessellation_shader extension");
398 ShaderLogCase::IterateResult ShaderLogCase::iterate (void)
400 using gls::StateQueryUtil::StateQueryMemoryWriteGuard;
402 tcu::ResultCollector result (m_testCtx.getLog());
403 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
405 StateQueryMemoryWriteGuard<glw::GLint> logLen;
407 gl.enableLogging(true);
409 m_testCtx.getLog() << tcu::TestLog::Message << "Trying to compile broken shader source." << tcu::TestLog::EndMessage;
411 shader = gl.glCreateShader(glu::getGLShaderType(m_shaderType));
412 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "create shader");
414 gl.glShaderSource(shader, 1, &s_brokenSource, DE_NULL);
415 gl.glCompileShader(shader);
416 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "compile");
418 gl.glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLen);
419 logLen.verifyValidity(result);
421 if (!logLen.isUndefined())
422 verifyInfoLogQuery(result, gl, logLen, shader, &glu::CallLogWrapper::glGetShaderInfoLog, "glGetShaderInfoLog");
424 gl.glDeleteShader(shader);
425 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "delete");
427 result.setTestContextResult(m_testCtx);
433 ShaderStateQueryTests::ShaderStateQueryTests (Context& context)
434 : TestCaseGroup(context, "shader", "Shader state query tests")
438 ShaderStateQueryTests::~ShaderStateQueryTests (void)
442 void ShaderStateQueryTests::init (void)
444 addChild(new CoreSamplerTypeCase (m_context, "sampler_type", "Sampler type cases"));
445 addChild(new MSArraySamplerTypeCase (m_context, "sampler_type_multisample_array", "MSAA array sampler type cases"));
446 addChild(new TextureBufferSamplerTypeCase (m_context, "sampler_type_texture_buffer", "Texture buffer sampler type cases"));
447 addChild(new TextureBufferImageTypeCase (m_context, "image_type_texture_buffer", "Texture buffer image type cases"));
448 addChild(new CubeArraySamplerTypeCase (m_context, "sampler_type_cube_array", "Cube array sampler type cases"));
449 addChild(new CubeArrayImageTypeCase (m_context, "image_type_cube_array", "Cube array image type cases"));
451 // shader info log tests
452 // \note, there exists similar tests in gles3 module. However, the gles31 could use a different
453 // shader compiler with different INFO_LOG bugs.
457 const char* caseName;
458 glu::ShaderType caseType;
461 { "info_log_vertex", glu::SHADERTYPE_VERTEX },
462 { "info_log_fragment", glu::SHADERTYPE_FRAGMENT },
463 { "info_log_geometry", glu::SHADERTYPE_GEOMETRY },
464 { "info_log_tess_ctrl", glu::SHADERTYPE_TESSELLATION_CONTROL },
465 { "info_log_tess_eval", glu::SHADERTYPE_TESSELLATION_EVALUATION },
466 { "info_log_compute", glu::SHADERTYPE_COMPUTE },
469 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(shaderTypes); ++ndx)
470 addChild(new ShaderLogCase(m_context, shaderTypes[ndx].caseName, "", shaderTypes[ndx].caseType));