1 /*-------------------------------------------------------------------------
2 * OpenGL Conformance Test Suite
3 * -----------------------------
5 * Copyright (c) 2014-2017 The Khronos Group Inc.
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.
20 * \file gl4cShaderBallotTests.cpp
21 * \brief Conformance tests for the ARB_shader_ballot functionality.
22 */ /*-------------------------------------------------------------------*/
24 #include "gl4cShaderBallotTests.hpp"
26 #include "glcContext.hpp"
27 #include "gluContextInfo.hpp"
28 #include "gluDefs.hpp"
29 #include "gluDrawUtil.hpp"
30 #include "gluObjectWrapper.hpp"
31 #include "gluProgramInterfaceQuery.hpp"
32 #include "gluShaderProgram.hpp"
33 #include "glwEnums.hpp"
34 #include "glwFunctions.hpp"
35 #include "tcuRenderTarget.hpp"
40 ShaderBallotBaseTestCase::ShaderPipeline::ShaderPipeline(glu::ShaderType testedShader,
41 const std::string& contentSnippet,
42 std::map<std::string, std::string> specMap)
43 : m_programRender(NULL), m_programCompute(NULL), m_testedShader(testedShader), m_specializationMap(specMap)
45 std::string testedHeadPart = "#extension GL_ARB_shader_ballot : enable\n"
46 "#extension GL_ARB_gpu_shader_int64 : enable\n";
48 std::string testedContentPart = contentSnippet;
50 // vertex shader parts
52 m_shaders[glu::SHADERTYPE_VERTEX].push_back("#version 450 core\n");
53 m_shaders[glu::SHADERTYPE_VERTEX].push_back(m_testedShader == glu::SHADERTYPE_VERTEX ? testedHeadPart : "");
54 m_shaders[glu::SHADERTYPE_VERTEX].push_back("in highp vec2 inPosition;\n"
55 "in highp vec4 inColor;\n"
56 "out highp vec3 vsPosition;\n"
57 "out highp vec4 vsColor;\n"
60 " gl_Position = vec4(inPosition, 0.0, 1.0);\n"
61 " vsPosition = vec3(inPosition, 0.0);\n"
62 " vec4 outColor = vec4(0.0); \n");
63 m_shaders[glu::SHADERTYPE_VERTEX].push_back(m_testedShader == glu::SHADERTYPE_VERTEX ? testedContentPart :
64 " outColor = inColor;\n");
65 m_shaders[glu::SHADERTYPE_VERTEX].push_back(" vsColor = outColor;\n"
68 // fragment shader parts
70 m_shaders[glu::SHADERTYPE_FRAGMENT].push_back("#version 450 core\n");
71 m_shaders[glu::SHADERTYPE_FRAGMENT].push_back(m_testedShader == glu::SHADERTYPE_FRAGMENT ? testedHeadPart : "");
72 m_shaders[glu::SHADERTYPE_FRAGMENT].push_back("in highp vec4 gsColor;\n"
73 "out highp vec4 fsColor;\n"
76 " vec4 outColor = vec4(0.0); \n");
77 m_shaders[glu::SHADERTYPE_FRAGMENT].push_back(
78 m_testedShader == glu::SHADERTYPE_FRAGMENT ? testedContentPart : " outColor = gsColor;\n");
79 m_shaders[glu::SHADERTYPE_FRAGMENT].push_back(" fsColor = outColor;\n"
82 // tessellation control shader parts
84 m_shaders[glu::SHADERTYPE_TESSELLATION_CONTROL].push_back("#version 450 core\n");
85 m_shaders[glu::SHADERTYPE_TESSELLATION_CONTROL].push_back(
86 m_testedShader == glu::SHADERTYPE_TESSELLATION_CONTROL ? testedHeadPart : "");
87 m_shaders[glu::SHADERTYPE_TESSELLATION_CONTROL].push_back(
88 "layout(vertices = 3) out;\n"
89 "in highp vec4 vsColor[];\n"
90 "in highp vec3 vsPosition[];\n"
91 "out highp vec3 tcsPosition[];\n"
92 "out highp vec4 tcsColor[];\n"
95 " tcsPosition[gl_InvocationID] = vsPosition[gl_InvocationID];\n"
96 " vec4 outColor = vec4(0.0);\n");
97 m_shaders[glu::SHADERTYPE_TESSELLATION_CONTROL].push_back(m_testedShader == glu::SHADERTYPE_TESSELLATION_CONTROL ?
99 " outColor = vsColor[gl_InvocationID];\n");
100 m_shaders[glu::SHADERTYPE_TESSELLATION_CONTROL].push_back(" tcsColor[gl_InvocationID] = outColor;\n"
101 " gl_TessLevelInner[0] = 3;\n"
102 " gl_TessLevelOuter[0] = 3;\n"
103 " gl_TessLevelOuter[1] = 3;\n"
104 " gl_TessLevelOuter[2] = 3;\n"
107 // tessellation evaluation shader parts
109 m_shaders[glu::SHADERTYPE_TESSELLATION_EVALUATION].push_back("#version 450 core\n");
110 m_shaders[glu::SHADERTYPE_TESSELLATION_EVALUATION].push_back(
111 m_testedShader == glu::SHADERTYPE_TESSELLATION_EVALUATION ? testedHeadPart : "");
112 m_shaders[glu::SHADERTYPE_TESSELLATION_EVALUATION].push_back("layout(triangles, equal_spacing, cw) in;\n"
113 "in highp vec3 tcsPosition[];\n"
114 "in highp vec4 tcsColor[];\n"
115 "out highp vec4 tesColor;\n"
118 " vec3 p0 = gl_TessCoord.x * tcsPosition[0];\n"
119 " vec3 p1 = gl_TessCoord.y * tcsPosition[1];\n"
120 " vec3 p2 = gl_TessCoord.z * tcsPosition[2];\n"
121 " vec4 outColor = vec4(0.0);\n");
122 m_shaders[glu::SHADERTYPE_TESSELLATION_EVALUATION].push_back(
123 m_testedShader == glu::SHADERTYPE_TESSELLATION_EVALUATION ? testedContentPart : " outColor = tcsColor[0];\n");
124 m_shaders[glu::SHADERTYPE_TESSELLATION_EVALUATION].push_back(" tesColor = outColor;\n"
125 " gl_Position = vec4(normalize(p0 + p1 + p2), 1.0);\n"
128 // geometry shader parts
130 m_shaders[glu::SHADERTYPE_GEOMETRY].push_back("#version 450 core\n");
131 m_shaders[glu::SHADERTYPE_GEOMETRY].push_back(m_testedShader == glu::SHADERTYPE_GEOMETRY ? testedHeadPart : "");
132 m_shaders[glu::SHADERTYPE_GEOMETRY].push_back("layout(triangles) in;\n"
133 "layout(triangle_strip, max_vertices = 3) out;\n"
134 "in highp vec4 tesColor[];\n"
135 "out highp vec4 gsColor;\n"
138 " for (int i = 0; i<3; i++)\n"
140 " gl_Position = gl_in[i].gl_Position;\n"
141 " vec4 outColor = vec4(0.0);\n");
142 m_shaders[glu::SHADERTYPE_GEOMETRY].push_back(
143 m_testedShader == glu::SHADERTYPE_GEOMETRY ? testedContentPart : " outColor = tesColor[i];\n");
144 m_shaders[glu::SHADERTYPE_GEOMETRY].push_back(" gsColor = outColor;\n"
150 // compute shader parts
152 m_shaders[glu::SHADERTYPE_COMPUTE].push_back("#version 450 core\n");
153 m_shaders[glu::SHADERTYPE_COMPUTE].push_back(m_testedShader == glu::SHADERTYPE_COMPUTE ? testedHeadPart : "");
154 m_shaders[glu::SHADERTYPE_COMPUTE].push_back(
155 "layout(rgba32f, binding = 1) writeonly uniform highp image2D destImage;\n"
156 "layout (local_size_x = 16, local_size_y = 16) in;\n"
159 "vec4 outColor = vec4(0.0);\n");
160 m_shaders[glu::SHADERTYPE_COMPUTE].push_back(m_testedShader == glu::SHADERTYPE_COMPUTE ? testedContentPart : "");
161 m_shaders[glu::SHADERTYPE_COMPUTE].push_back("imageStore(destImage, ivec2(gl_GlobalInvocationID.xy), outColor);\n"
164 // create shader chunks
166 for (unsigned int shaderType = 0; shaderType <= glu::SHADERTYPE_COMPUTE; ++shaderType)
168 m_shaderChunks[shaderType] = new char*[m_shaders[shaderType].size()];
169 for (unsigned int i = 0; i < m_shaders[i].size(); ++i)
171 m_shaderChunks[shaderType][i] = (char*)m_shaders[shaderType][i].data();
176 ShaderBallotBaseTestCase::ShaderPipeline::~ShaderPipeline()
180 delete m_programRender;
183 if (m_programCompute)
185 delete m_programCompute;
188 for (unsigned int shaderType = 0; shaderType <= glu::SHADERTYPE_COMPUTE; ++shaderType)
190 delete[] m_shaderChunks[shaderType];
194 const char* const* ShaderBallotBaseTestCase::ShaderPipeline::getShaderParts(glu::ShaderType shaderType) const
196 return m_shaderChunks[shaderType];
199 unsigned int ShaderBallotBaseTestCase::ShaderPipeline::getShaderPartsCount(glu::ShaderType shaderType) const
201 return m_shaders[shaderType].size();
204 void ShaderBallotBaseTestCase::ShaderPipeline::renderQuad(deqp::Context& context)
206 const glw::Functions& gl = context.getRenderContext().getFunctions();
208 deUint16 const quadIndices[] = { 0, 1, 2, 2, 1, 3 };
210 float const position[] = { -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f };
212 glu::VertexArrayBinding vertexArrays[] = { glu::va::Float("inPosition", 2, 4, 0, position) };
216 glu::PrimitiveList primitiveList = glu::pr::Patches(DE_LENGTH_OF_ARRAY(quadIndices), quadIndices);
218 glu::draw(context.getRenderContext(), m_programRender->getProgram(), DE_LENGTH_OF_ARRAY(vertexArrays), vertexArrays,
221 GLU_EXPECT_NO_ERROR(gl.getError(), "glu::draw error");
224 void ShaderBallotBaseTestCase::ShaderPipeline::executeComputeShader(deqp::Context& context)
226 const glw::Functions& gl = context.getRenderContext().getFunctions();
228 const glu::Texture outputTexture(context.getRenderContext());
230 gl.useProgram(m_programCompute->getProgram());
233 gl.bindTexture(GL_TEXTURE_2D, *outputTexture);
234 gl.texStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32UI, 16, 16);
235 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
236 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
237 GLU_EXPECT_NO_ERROR(gl.getError(), "Uploading image data failed");
240 gl.bindImageTexture(1, *outputTexture, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32UI);
241 GLU_EXPECT_NO_ERROR(gl.getError(), "Image setup failed");
244 gl.dispatchCompute(1, 1, 1);
245 GLU_EXPECT_NO_ERROR(gl.getError(), "glDispatchCompute()");
247 gl.memoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT);
248 GLU_EXPECT_NO_ERROR(gl.getError(), "glMemoryBarrier()");
250 // render output texture
252 std::string vs = "#version 450 core\n"
253 "in highp vec2 position;\n"
254 "in vec2 inTexcoord;\n"
255 "out vec2 texcoord;\n"
258 " texcoord = inTexcoord;\n"
259 " gl_Position = vec4(position, 0.0, 1.0);\n"
262 std::string fs = "#version 450 core\n"
263 "uniform sampler2D sampler;\n"
264 "in vec2 texcoord;\n"
268 " color = texture(sampler, texcoord);\n"
271 glu::ProgramSources sources;
272 sources.sources[glu::SHADERTYPE_VERTEX].push_back(vs);
273 sources.sources[glu::SHADERTYPE_FRAGMENT].push_back(fs);
274 glu::ShaderProgram renderShader(context.getRenderContext(), sources);
276 if (!m_programRender->isOk())
278 TCU_FAIL("Shader compilation failed");
281 gl.bindTexture(GL_TEXTURE_2D, *outputTexture);
282 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture() call failed.");
284 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
285 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
287 gl.useProgram(renderShader.getProgram());
289 gl.uniform1i(gl.getUniformLocation(renderShader.getProgram(), "sampler"), 0);
290 GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i failed");
292 deUint16 const quadIndices[] = { 0, 1, 2, 2, 1, 3 };
294 float const position[] = { -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f };
296 float const texCoord[] = { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f };
298 glu::VertexArrayBinding vertexArrays[] = { glu::va::Float("position", 2, 4, 0, position),
299 glu::va::Float("inTexcoord", 2, 4, 0, texCoord) };
301 glu::draw(context.getRenderContext(), renderShader.getProgram(), DE_LENGTH_OF_ARRAY(vertexArrays), vertexArrays,
302 glu::pr::TriangleStrip(DE_LENGTH_OF_ARRAY(quadIndices), quadIndices));
304 GLU_EXPECT_NO_ERROR(gl.getError(), "glu::draw error");
307 void ShaderBallotBaseTestCase::ShaderPipeline::use(deqp::Context& context)
309 const glw::Functions& gl = context.getRenderContext().getFunctions();
310 gl.useProgram(m_programRender->getProgram());
311 GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram failed");
314 void ShaderBallotBaseTestCase::ShaderPipeline::test(deqp::Context& context)
316 if (m_testedShader == glu::SHADERTYPE_COMPUTE)
318 executeComputeShader(context);
326 void ShaderBallotBaseTestCase::createShaderPrograms(ShaderPipeline& pipeline)
328 glu::ProgramSources sourcesRender;
330 for (unsigned int i = 0; i < glu::SHADERTYPE_COMPUTE; ++i)
332 glu::ShaderType shaderType = (glu::ShaderType)i;
334 std::map<std::string, std::string>::const_iterator mapIter;
335 for (mapIter = pipeline.getSpecializationMap().begin(); mapIter != pipeline.getSpecializationMap().end();
337 m_specializationMap[mapIter->first] = mapIter->second;
340 specializeShader(pipeline.getShaderPartsCount(shaderType), pipeline.getShaderParts(shaderType));
341 sourcesRender.sources[i].push_back(shader);
344 glu::ShaderProgram* programRender = new glu::ShaderProgram(m_context.getRenderContext(), sourcesRender);
346 if (!programRender->isOk())
348 TCU_FAIL("Shader compilation failed");
351 glu::ProgramSources sourcesCompute;
353 m_specializationMap.insert(pipeline.getSpecializationMap().begin(), pipeline.getSpecializationMap().end());
354 std::string shaderCompute = specializeShader(pipeline.getShaderPartsCount(glu::SHADERTYPE_COMPUTE),
355 pipeline.getShaderParts(glu::SHADERTYPE_COMPUTE));
356 sourcesCompute.sources[glu::SHADERTYPE_COMPUTE].push_back(shaderCompute);
358 glu::ShaderProgram* programCompute = new glu::ShaderProgram(m_context.getRenderContext(), sourcesCompute);
360 if (!programCompute->isOk())
362 TCU_FAIL("Shader compilation failed");
365 pipeline.setShaderPrograms(programRender, programCompute);
368 ShaderBallotBaseTestCase::~ShaderBallotBaseTestCase()
370 for (ShaderPipelineIter iter = m_shaderPipelines.begin(); iter != m_shaderPipelines.end(); ++iter)
376 bool ShaderBallotBaseTestCase::validateScreenPixels(deqp::Context& context, tcu::Vec4 desiredColor,
377 tcu::Vec4 ignoredColor)
379 const glw::Functions& gl = context.getRenderContext().getFunctions();
380 const tcu::RenderTarget renderTarget = context.getRenderContext().getRenderTarget();
381 tcu::IVec2 size(renderTarget.getWidth(), renderTarget.getHeight());
383 glw::GLfloat* pixels = new glw::GLfloat[size.x() * size.y() * 4];
386 for (int x = 0; x < size.x(); ++x)
388 for (int y = 0; y < size.y(); ++y)
390 int mappedPixelPosition = y * size.x() + x;
392 pixels[mappedPixelPosition * 4 + 0] = -1.0f;
393 pixels[mappedPixelPosition * 4 + 1] = -1.0f;
394 pixels[mappedPixelPosition * 4 + 2] = -1.0f;
395 pixels[mappedPixelPosition * 4 + 3] = -1.0f;
400 gl.readPixels(0, 0, size.x(), size.y(), GL_RGBA, GL_FLOAT, pixels);
403 bool rendered = false;
404 for (int x = 0; x < size.x(); ++x)
406 for (int y = 0; y < size.y(); ++y)
408 int mappedPixelPosition = y * size.x() + x;
410 tcu::Vec4 color(pixels[mappedPixelPosition * 4 + 0], pixels[mappedPixelPosition * 4 + 1],
411 pixels[mappedPixelPosition * 4 + 2], pixels[mappedPixelPosition * 4 + 3]);
413 if (!ShaderBallotBaseTestCase::validateColor(color, ignoredColor))
416 if (!ShaderBallotBaseTestCase::validateColor(color, desiredColor))
429 bool ShaderBallotBaseTestCase::validateScreenPixelsSameColor(deqp::Context& context, tcu::Vec4 ignoredColor)
431 const glw::Functions& gl = context.getRenderContext().getFunctions();
432 const tcu::RenderTarget renderTarget = context.getRenderContext().getRenderTarget();
433 tcu::IVec2 size(renderTarget.getWidth(), renderTarget.getHeight());
435 glw::GLfloat* centerPixel = new glw::GLfloat[4];
436 centerPixel[0] = -1.0f;
437 centerPixel[1] = -1.0f;
438 centerPixel[2] = -1.0f;
439 centerPixel[3] = -1.0f;
442 gl.readPixels(size.x() / 2, size.y() / 2, 1, 1, GL_RGBA, GL_FLOAT, centerPixel);
444 tcu::Vec4 desiredColor(centerPixel[0], centerPixel[1], centerPixel[2], centerPixel[3]);
446 delete[] centerPixel;
449 return ShaderBallotBaseTestCase::validateScreenPixels(context, desiredColor, ignoredColor);
452 bool ShaderBallotBaseTestCase::validateColor(tcu::Vec4 testedColor, tcu::Vec4 desiredColor)
454 const float epsilon = 0.008f;
455 return de::abs(testedColor.x() - desiredColor.x()) < epsilon &&
456 de::abs(testedColor.y() - desiredColor.y()) < epsilon &&
457 de::abs(testedColor.z() - desiredColor.z()) < epsilon &&
458 de::abs(testedColor.w() - desiredColor.w()) < epsilon;
463 * @param context Rendering context
465 ShaderBallotAvailabilityTestCase::ShaderBallotAvailabilityTestCase(deqp::Context& context)
466 : ShaderBallotBaseTestCase(context, "ShaderBallotAvailability",
467 "Implements verification of availability for new build-in features")
469 std::string colorShaderSnippet =
470 " float red = gl_SubGroupSizeARB / 64.0f;\n"
471 " float green = 1.0f - (gl_SubGroupInvocationARB / float(gl_SubGroupSizeARB));\n"
472 " float blue = float(ballotARB(true) % 256) / 256.0f;\n"
473 " outColor = readInvocationARB(vec4(red, green, blue, 1.0f), gl_SubGroupInvocationARB);\n";
475 for (unsigned int i = 0; i <= glu::SHADERTYPE_COMPUTE; ++i)
477 m_shaderPipelines.push_back(new ShaderPipeline((glu::ShaderType)i, colorShaderSnippet));
481 /** Initializes the test
483 void ShaderBallotAvailabilityTestCase::init()
487 /** Executes test iteration.
489 * @return Returns STOP when test has finished executing, CONTINUE if more iterations are needed.
491 tcu::TestNode::IterateResult ShaderBallotAvailabilityTestCase::iterate()
493 if (!m_context.getContextInfo().isExtensionSupported("GL_ARB_shader_ballot") ||
494 !m_context.getContextInfo().isExtensionSupported("GL_ARB_gpu_shader_int64"))
496 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not supported");
500 for (ShaderPipelineIter iter = m_shaderPipelines.begin(); iter != m_shaderPipelines.end(); ++iter)
502 createShaderPrograms(**iter);
505 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
507 for (ShaderPipelineIter pipelineIter = m_shaderPipelines.begin(); pipelineIter != m_shaderPipelines.end();
510 gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
511 gl.clear(GL_COLOR_BUFFER_BIT);
513 (*pipelineIter)->test(m_context);
518 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
524 * @param context Rendering context
526 ShaderBallotBitmasksTestCase::ShaderBallotBitmasksTestCase(deqp::Context& context)
527 : ShaderBallotBaseTestCase(context, "ShaderBallotBitmasks",
528 "Implements verification of values of gl_SubGroup*MaskARB variables")
530 m_maskVars["gl_SubGroupEqMaskARB"] = "==";
531 m_maskVars["gl_SubGroupGeMaskARB"] = ">=";
532 m_maskVars["gl_SubGroupGtMaskARB"] = ">";
533 m_maskVars["gl_SubGroupLeMaskARB"] = "<=";
534 m_maskVars["gl_SubGroupLtMaskARB"] = "<";
536 std::string colorShaderSnippet = " uint64_t mask = 0;\n"
537 " for(uint i = 0; i < gl_SubGroupSizeARB; ++i)\n"
539 " if(i ${MASK_OPERATOR} gl_SubGroupInvocationARB)\n"
540 " mask = mask | (1ul << i);\n"
542 " float color = (${MASK_VAR} ^ mask) == 0ul ? 1.0 : 0.0;\n"
543 " outColor = vec4(color, color, color, 1.0);\n";
545 for (MaskVarIter maskIter = m_maskVars.begin(); maskIter != m_maskVars.end(); maskIter++)
547 for (unsigned int i = 0; i <= glu::SHADERTYPE_COMPUTE; ++i)
549 std::map<std::string, std::string> specMap;
550 specMap["MASK_VAR"] = maskIter->first;
551 specMap["MASK_OPERATOR"] = maskIter->second;
552 m_shaderPipelines.push_back(new ShaderPipeline((glu::ShaderType)i, colorShaderSnippet, specMap));
557 /** Initializes the test
559 void ShaderBallotBitmasksTestCase::init()
563 /** Executes test iteration.
565 * @return Returns STOP when test has finished executing, CONTINUE if more iterations are needed.
567 tcu::TestNode::IterateResult ShaderBallotBitmasksTestCase::iterate()
569 if (!m_context.getContextInfo().isExtensionSupported("GL_ARB_shader_ballot") ||
570 !m_context.getContextInfo().isExtensionSupported("GL_ARB_gpu_shader_int64"))
572 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not supported");
576 for (ShaderPipelineIter iter = m_shaderPipelines.begin(); iter != m_shaderPipelines.end(); ++iter)
578 createShaderPrograms(**iter);
581 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
583 for (ShaderPipelineIter pipelineIter = m_shaderPipelines.begin(); pipelineIter != m_shaderPipelines.end();
586 gl.clearColor(1.0f, 0.0f, 0.0f, 1.0f);
587 gl.clear(GL_COLOR_BUFFER_BIT);
589 (*pipelineIter)->test(m_context);
593 bool validationResult = ShaderBallotBaseTestCase::validateScreenPixels(
594 m_context, tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f), tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
595 TCU_CHECK_MSG(validationResult, "Bitmask value is not correct");
598 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
604 * @param context Rendering context
606 ShaderBallotFunctionBallotTestCase::ShaderBallotFunctionBallotTestCase(deqp::Context& context)
607 : ShaderBallotBaseTestCase(context, "ShaderBallotFunctionBallot",
608 "Implements verification of ballotARB calls and returned results")
610 std::string ballotFalseSnippet = " uint64_t result = ballotARB(false);\n"
611 " float color = result == 0ul ? 1.0 : 0.0;\n"
612 " outColor = vec4(color, color, color, 1.0);\n";
614 std::string ballotTrueSnippet = " uint64_t result = ballotARB(true);\n"
615 " float color = result != 0ul ? 1.0 : 0.0;\n"
616 " uint64_t invocationBit = 1ul << gl_SubGroupInvocationARB;\n"
617 " color *= float(invocationBit & result);\n"
618 " outColor = vec4(color, color, color, 1.0);\n";
620 std::string ballotMixedSnippet = " bool param = (gl_SubGroupInvocationARB % 2) == 0ul;\n"
621 " uint64_t result = ballotARB(param);\n"
622 " float color = (param && result != 0ul) || !param ? 1.0 : 0.0;\n"
623 " outColor = vec4(color, color, color, 1.0);\n";
625 for (unsigned int i = 0; i <= glu::SHADERTYPE_COMPUTE; ++i)
627 m_shaderPipelines.push_back(new ShaderPipeline((glu::ShaderType)i, ballotFalseSnippet));
628 m_shaderPipelines.push_back(new ShaderPipeline((glu::ShaderType)i, ballotTrueSnippet));
629 m_shaderPipelines.push_back(new ShaderPipeline((glu::ShaderType)i, ballotMixedSnippet));
633 /** Initializes the test
635 void ShaderBallotFunctionBallotTestCase::init()
639 /** Executes test iteration.
641 * @return Returns STOP when test has finished executing, CONTINUE if more iterations are needed.
643 tcu::TestNode::IterateResult ShaderBallotFunctionBallotTestCase::iterate()
645 if (!m_context.getContextInfo().isExtensionSupported("GL_ARB_shader_ballot") ||
646 !m_context.getContextInfo().isExtensionSupported("GL_ARB_gpu_shader_int64"))
648 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not supported");
652 for (ShaderPipelineIter iter = m_shaderPipelines.begin(); iter != m_shaderPipelines.end(); ++iter)
654 createShaderPrograms(**iter);
657 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
659 for (ShaderPipelineIter pipelineIter = m_shaderPipelines.begin(); pipelineIter != m_shaderPipelines.end();
662 gl.clearColor(1.0f, 0.0f, 0.0f, 1.0f);
663 gl.clear(GL_COLOR_BUFFER_BIT);
665 (*pipelineIter)->test(m_context);
669 bool validationResult = ShaderBallotBaseTestCase::validateScreenPixels(
670 m_context, tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f), tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
671 TCU_CHECK_MSG(validationResult, "Value returned from ballotARB function is not correct");
674 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
680 * @param context Rendering context
682 ShaderBallotFunctionReadTestCase::ShaderBallotFunctionReadTestCase(deqp::Context& context)
683 : ShaderBallotBaseTestCase(context, "ShaderBallotFunctionRead",
684 "Implements verification of readInvocationARB and readFirstInvocationARB function calls")
686 std::string readFirstInvSnippet = "float color = 1.0f - (gl_SubGroupInvocationARB / float(gl_SubGroupSizeARB));\n"
687 "outColor = readFirstInvocationARB(vec4(color, color, color, 1.0f));\n";
689 std::string readInvSnippet = "float color = 1.0 - (gl_SubGroupInvocationARB / float(gl_SubGroupSizeARB));\n"
690 "uvec2 parts = unpackUint2x32(ballotARB(true));\n"
692 "if (parts.x != 0) {\n"
693 " invocation = findLSB(parts.x);\n"
695 " invocation = findLSB(parts.y) + 32;\n"
697 "outColor = readInvocationARB(vec4(color, color, color, 1.0f), invocation);\n";
699 for (unsigned int i = 0; i <= glu::SHADERTYPE_COMPUTE; ++i)
701 m_shaderPipelines.push_back(new ShaderPipeline((glu::ShaderType)i, readFirstInvSnippet));
702 m_shaderPipelines.push_back(new ShaderPipeline((glu::ShaderType)i, readInvSnippet));
706 /** Initializes the test
708 void ShaderBallotFunctionReadTestCase::init()
712 /** Executes test iteration.
714 * @return Returns STOP when test has finished executing, CONTINUE if more iterations are needed.
716 tcu::TestNode::IterateResult ShaderBallotFunctionReadTestCase::iterate()
718 if (!m_context.getContextInfo().isExtensionSupported("GL_ARB_shader_ballot") ||
719 !m_context.getContextInfo().isExtensionSupported("GL_ARB_gpu_shader_int64"))
721 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not supported");
725 for (ShaderPipelineIter iter = m_shaderPipelines.begin(); iter != m_shaderPipelines.end(); ++iter)
727 createShaderPrograms(**iter);
730 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
731 const tcu::RenderTarget renderTarget = m_context.getRenderContext().getRenderTarget();
733 gl.clearColor(1.0f, 0.0f, 0.0f, 1.0f);
734 gl.viewport(renderTarget.getWidth() / 2 - 1, renderTarget.getHeight() / 2 - 1, 2, 2);
736 for (ShaderPipelineIter pipelineIter = m_shaderPipelines.begin(); pipelineIter != m_shaderPipelines.end();
739 gl.clear(GL_COLOR_BUFFER_BIT);
741 (*pipelineIter)->test(m_context);
745 bool validationResult =
746 ShaderBallotBaseTestCase::validateScreenPixelsSameColor(m_context, tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
747 TCU_CHECK_MSG(validationResult, "Read functions result is not correct");
750 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
756 * @param context Rendering context.
758 ShaderBallotTests::ShaderBallotTests(deqp::Context& context)
759 : TestCaseGroup(context, "shader_ballot_tests", "Verify conformance of CTS_ARB_shader_ballot implementation")
763 /** Initializes the shader_ballot test group.
766 void ShaderBallotTests::init(void)
768 addChild(new ShaderBallotAvailabilityTestCase(m_context));
769 addChild(new ShaderBallotBitmasksTestCase(m_context));
770 addChild(new ShaderBallotFunctionBallotTestCase(m_context));
771 addChild(new ShaderBallotFunctionReadTestCase(m_context));
773 } /* glcts namespace */