1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 2.0 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 control statement performance tests.
22 *//*--------------------------------------------------------------------*/
24 #include "es2pShaderControlStatementTests.hpp"
25 #include "glsShaderPerformanceCase.hpp"
26 #include "tcuTestLog.hpp"
28 #include "glwEnums.hpp"
29 #include "glwFunctions.hpp"
42 using namespace glw; // GL types
48 // Writes the workload expression used in conditional tests.
49 static void writeConditionalWorkload (std::ostringstream& stream, const char* resultName, const char* operandName)
51 const int numMultiplications = 64;
53 stream << resultName << " = ";
55 for (int i = 0; i < numMultiplications; i++)
60 stream << operandName;
66 // Writes the workload expression used in loop tests (one iteration).
67 static void writeLoopWorkload (std::ostringstream& stream, const char* resultName, const char* operandName)
69 const int numMultiplications = 8;
71 stream << resultName << " = ";
73 for (int i = 0; i < numMultiplications; i++)
78 stream << "(" << resultName << " + " << operandName << ")";
84 // The type of decision to be made in a conditional expression.
85 // \note In fragment cases with DECISION_ATTRIBUTE, the value in the expression will actually be a varying.
95 class ControlStatementCase : public ShaderPerformanceCase
98 ControlStatementCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* name, const char* description, gls::PerfCaseType caseType)
99 : ShaderPerformanceCase(testCtx, renderCtx, name, description, caseType)
105 m_testCtx.getLog() << TestLog::Message << "Using additive blending." << TestLog::EndMessage;
106 ShaderPerformanceCase::init();
109 void setupRenderState (void)
111 const glw::Functions& gl = m_renderCtx.getFunctions();
114 gl.blendEquation(GL_FUNC_ADD);
115 gl.blendFunc(GL_ONE, GL_ONE);
119 class ConditionalCase : public ControlStatementCase
131 enum WorkloadDivision
133 WORKLOAD_DIVISION_EVEN = 0, //! Both true and false branches contain same amount of computation.
134 WORKLOAD_DIVISION_TRUE_HEAVY, //! True branch contains more computation.
135 WORKLOAD_DIVISION_FALSE_HEAVY, //! False branch contains more computation.
137 WORKLOAD_DIVISION_LAST
140 ConditionalCase (Context& context, const char* name, const char* description, DecisionType decisionType, BranchResult branchType, WorkloadDivision workloadDivision, bool isVertex);
141 ~ConditionalCase (void);
145 void setupProgram (deUint32 program);
148 DecisionType m_decisionType;
149 BranchResult m_branchType;
150 WorkloadDivision m_workloadDivision;
152 vector<float> m_comparisonValueArray; // Will contain per-vertex comparison values if using mixed branch type in vertex case.
153 deUint32 m_arrayBuffer;
156 ConditionalCase::ConditionalCase (Context& context, const char* name, const char* description, DecisionType decisionType, BranchResult branchType, WorkloadDivision workloadDivision, bool isVertex)
157 : ControlStatementCase (context.getTestContext(), context.getRenderContext(), name, description, isVertex ? CASETYPE_VERTEX : CASETYPE_FRAGMENT)
158 , m_decisionType (decisionType)
159 , m_branchType (branchType)
160 , m_workloadDivision (workloadDivision)
165 void ConditionalCase::init (void)
167 bool isVertexCase = m_caseType == CASETYPE_VERTEX;
169 bool isStaticCase = m_decisionType == DECISION_STATIC;
170 bool isUniformCase = m_decisionType == DECISION_UNIFORM;
171 bool isAttributeCase = m_decisionType == DECISION_ATTRIBUTE;
173 DE_ASSERT(isStaticCase || isUniformCase || isAttributeCase);
175 bool isConditionTrue = m_branchType == BRANCH_TRUE;
176 bool isConditionFalse = m_branchType == BRANCH_FALSE;
177 bool isConditionMixed = m_branchType == BRANCH_MIXED;
179 DE_ASSERT(isConditionTrue || isConditionFalse || isConditionMixed);
180 DE_UNREF(isConditionFalse);
182 DE_ASSERT(isAttributeCase || !isConditionMixed); // The branch taken can vary between executions only if using attribute input.
184 const char* staticCompareValueStr = isConditionTrue ? "1.0" : "-1.0";
185 const char* compareValueStr = isStaticCase ? staticCompareValueStr :
186 isUniformCase ? "u_compareValue" :
187 isVertexCase ? "a_compareValue" :
190 std::ostringstream vtx;
191 std::ostringstream frag;
192 std::ostringstream& op = isVertexCase ? vtx : frag;
194 vtx << "attribute highp vec4 a_position;\n"; // Position attribute.
195 vtx << "attribute mediump vec4 a_value0;\n"; // Input for workload calculations of "true" branch.
196 vtx << "attribute mediump vec4 a_value1;\n"; // Input for workload calculations of "false" branch.
198 // Value to be used in the conditional expression.
200 vtx << "attribute mediump float a_compareValue;\n";
201 else if (isUniformCase)
202 op << "uniform mediump float u_compareValue;\n";
207 vtx << "varying mediump vec4 v_color;\n";
208 frag << "varying mediump vec4 v_color;\n";
212 vtx << "varying mediump vec4 v_value0;\n";
213 vtx << "varying mediump vec4 v_value1;\n";
214 frag << "varying mediump vec4 v_value0;\n";
215 frag << "varying mediump vec4 v_value1;\n";
219 vtx << "varying mediump float v_compareValue;\n";
220 frag << "varying mediump float v_compareValue;\n";
225 vtx << "void main()\n";
227 vtx << " gl_Position = a_position;\n";
230 frag << "void main()\n";
233 op << " mediump vec4 res;\n";
237 if (isConditionMixed && !isVertexCase)
238 condition = string("") + "fract(" + compareValueStr + ") < 0.5"; // Comparison result varies with high frequency.
240 condition = string("") + compareValueStr + " > 0.0";
242 op << " if (" << condition << ")\n";
246 if (m_workloadDivision == WORKLOAD_DIVISION_EVEN || m_workloadDivision == WORKLOAD_DIVISION_TRUE_HEAVY)
247 writeConditionalWorkload(op, "res", isVertexCase ? "a_value0" : "v_value0"); // Workload calculation for the "true" branch.
249 op << "res = " << (isVertexCase ? "a_value0" : "v_value0") << ";";
257 if (m_workloadDivision == WORKLOAD_DIVISION_EVEN || m_workloadDivision == WORKLOAD_DIVISION_FALSE_HEAVY)
258 writeConditionalWorkload(op, "res", isVertexCase ? "a_value1" : "v_value1"); // Workload calculations for the "false" branch.
260 op << "res = " << (isVertexCase ? "a_value1" : "v_value1") << ";";
267 // Put result to color variable.
268 vtx << " v_color = res;\n";
269 frag << " gl_FragColor = v_color;\n";
273 // Transfer inputs to fragment shader through varyings.
275 vtx << " v_compareValue = a_compareValue;\n";
276 vtx << " v_value0 = a_value0;\n";
277 vtx << " v_value1 = a_value1;\n";
279 frag << " gl_FragColor = res;\n"; // Put result to color variable.
285 m_vertShaderSource = vtx.str();
286 m_fragShaderSource = frag.str();
290 if (!isConditionMixed)
292 // Every execution takes the same branch.
294 float value = isConditionTrue ? +1.0f : -1.0f;
295 m_attributes.push_back(AttribSpec("a_compareValue", Vec4(value, 0.0f, 0.0f, 0.0f),
296 Vec4(value, 0.0f, 0.0f, 0.0f),
297 Vec4(value, 0.0f, 0.0f, 0.0f),
298 Vec4(value, 0.0f, 0.0f, 0.0f)));
300 else if (isVertexCase)
302 // Vertex case, not every execution takes the same branch.
304 const int numComponents = 4;
305 int numVertices = (getGridWidth() + 1) * (getGridHeight() + 1);
307 // setupProgram() will later bind this array as an attribute.
308 m_comparisonValueArray.resize(numVertices * numComponents);
310 // Make every second vertex take the true branch, and every second the false branch.
311 for (int i = 0; i < (int)m_comparisonValueArray.size(); i++)
313 if (i % numComponents == 0)
314 m_comparisonValueArray[i] = (i / numComponents) % 2 == 0 ? +1.0f : -1.0f;
316 m_comparisonValueArray[i] = 0.0f;
319 else // isConditionMixed && !isVertexCase
321 // Fragment case, not every execution takes the same branch.
322 // \note fract(a_compareValue) < 0.5 will be true for every second column of fragments.
324 float minValue = 0.0f;
325 float maxValue = (float)getViewportWidth()*0.5f;
326 m_attributes.push_back(AttribSpec("a_compareValue", Vec4(minValue, 0.0f, 0.0f, 0.0f),
327 Vec4(maxValue, 0.0f, 0.0f, 0.0f),
328 Vec4(minValue, 0.0f, 0.0f, 0.0f),
329 Vec4(maxValue, 0.0f, 0.0f, 0.0f)));
333 m_attributes.push_back(AttribSpec("a_value0", Vec4(0.0f, 0.1f, 0.2f, 0.3f),
334 Vec4(0.4f, 0.5f, 0.6f, 0.7f),
335 Vec4(0.8f, 0.9f, 1.0f, 1.1f),
336 Vec4(1.2f, 1.3f, 1.4f, 1.5f)));
338 m_attributes.push_back(AttribSpec("a_value1", Vec4(0.0f, 0.1f, 0.2f, 0.3f),
339 Vec4(0.4f, 0.5f, 0.6f, 0.7f),
340 Vec4(0.8f, 0.9f, 1.0f, 1.1f),
341 Vec4(1.2f, 1.3f, 1.4f, 1.5f)));
343 ControlStatementCase::init();
346 void ConditionalCase::setupProgram (deUint32 program)
348 const glw::Functions& gl = m_renderCtx.getFunctions();
350 if (m_decisionType == DECISION_UNIFORM)
352 int location = gl.getUniformLocation(program, "u_compareValue");
353 gl.uniform1f(location, m_branchType == BRANCH_TRUE ? +1.0f : -1.0f);
355 else if (m_decisionType == DECISION_ATTRIBUTE && m_branchType == BRANCH_MIXED && m_caseType == CASETYPE_VERTEX)
357 // Setup per-vertex comparison values calculated in init().
359 const int numComponents = 4;
360 int compareAttribLocation = gl.getAttribLocation(program, "a_compareValue");
362 DE_ASSERT((int)m_comparisonValueArray.size() == numComponents * (getGridWidth() + 1) * (getGridHeight() + 1));
364 gl.genBuffers(1, &m_arrayBuffer);
365 gl.bindBuffer(GL_ARRAY_BUFFER, m_arrayBuffer);
366 gl.bufferData(GL_ARRAY_BUFFER, (GLsizeiptr)(m_comparisonValueArray.size()*sizeof(float)), &m_comparisonValueArray[0], GL_STATIC_DRAW);
367 gl.enableVertexAttribArray(compareAttribLocation);
368 gl.vertexAttribPointer(compareAttribLocation, (GLint)numComponents, GL_FLOAT, GL_FALSE, 0, DE_NULL);
371 GLU_EXPECT_NO_ERROR(gl.getError(), "Setup program state");
374 ConditionalCase::~ConditionalCase (void)
376 const glw::Functions& gl = m_renderCtx.getFunctions();
378 if (m_arrayBuffer != 0)
380 gl.deleteBuffers(1, &m_arrayBuffer);
385 void ConditionalCase::deinit (void)
387 const glw::Functions& gl = m_renderCtx.getFunctions();
389 m_comparisonValueArray.clear();
391 if (m_arrayBuffer != 0)
393 gl.deleteBuffers(1, &m_arrayBuffer);
397 ShaderPerformanceCase::deinit();
400 class LoopCase : public ControlStatementCase
411 LoopCase (Context& context, const char* name, const char* description, LoopType type, DecisionType decisionType, bool isLoopBoundStable, bool isVertex);
416 void setupProgram (deUint32 program);
419 DecisionType m_decisionType;
422 bool m_isLoopBoundStable; // Whether loop bound is same in all executions.
423 vector<float> m_boundArray; // Will contain per-vertex loop bounds if using non-stable attribute in vertex case.
424 deUint32 m_arrayBuffer;
427 LoopCase::LoopCase (Context& context, const char* name, const char* description, LoopType type, DecisionType decisionType, bool isLoopBoundStable, bool isVertex)
428 : ControlStatementCase (context.getTestContext(), context.getRenderContext(), name, description, isVertex ? CASETYPE_VERTEX : CASETYPE_FRAGMENT)
429 , m_decisionType (decisionType)
431 , m_isLoopBoundStable (isLoopBoundStable)
436 void LoopCase::init (void)
438 bool isVertexCase = m_caseType == CASETYPE_VERTEX;
440 bool isStaticCase = m_decisionType == DECISION_STATIC;
441 bool isUniformCase = m_decisionType == DECISION_UNIFORM;
442 bool isAttributeCase = m_decisionType == DECISION_ATTRIBUTE;
444 DE_ASSERT(isStaticCase || isUniformCase || isAttributeCase);
446 DE_ASSERT(m_type == LOOP_FOR ||
447 m_type == LOOP_WHILE ||
448 m_type == LOOP_DO_WHILE);
450 DE_ASSERT(isAttributeCase || m_isLoopBoundStable); // The loop bound count can vary between executions only if using attribute input.
452 // \note The fractional part is .5 (instead of .0) so that these can be safely used as loop bounds.
453 const float loopBound = 10.5f;
454 const float unstableBoundLow = 5.5f;
455 const float unstableBoundHigh = 15.5f;
456 static const char* loopBoundStr = "10.5";
457 static const char* unstableBoundLowStr = "5.5";
458 static const char* unstableBoundHighStr = "15.5";
460 const char* boundValueStr = isStaticCase ? loopBoundStr :
461 isUniformCase ? "u_bound" :
462 isVertexCase ? "a_bound" :
463 m_isLoopBoundStable ? "v_bound" :
466 std::ostringstream vtx;
467 std::ostringstream frag;
468 std::ostringstream& op = isVertexCase ? vtx : frag;
470 vtx << "attribute highp vec4 a_position;\n"; // Position attribute.
471 vtx << "attribute mediump vec4 a_value;\n"; // Input for workload calculations.
473 // Value to be used as the loop iteration count.
475 vtx << "attribute mediump float a_bound;\n";
476 else if (isUniformCase)
477 op << "uniform mediump float u_bound;\n";
482 vtx << "varying mediump vec4 v_color;\n";
483 frag << "varying mediump vec4 v_color;\n";
487 vtx << "varying mediump vec4 v_value;\n";
488 frag << "varying mediump vec4 v_value;\n";
492 vtx << "varying mediump float v_bound;\n";
493 frag << "varying mediump float v_bound;\n";
498 vtx << "void main()\n";
500 vtx << " gl_Position = a_position;\n";
503 frag << "void main()\n";
506 op << " mediump vec4 res = vec4(0.0);\n";
508 if (!m_isLoopBoundStable && !isVertexCase)
510 // Choose the actual loop bound based on v_bound.
511 // \note Loop bound will vary with high frequency between fragment columns, given appropriate range for v_bound.
512 op << " mediump float loopBound = fract(v_bound) < 0.5 ? " << unstableBoundLowStr << " : " << unstableBoundHighStr << ";\n";
515 // Start a for, while or do-while loop.
516 if (m_type == LOOP_FOR)
517 op << " for (mediump float i = 0.0; i < " << boundValueStr << "; i++)\n";
520 op << " mediump float i = 0.0;\n";
521 if (m_type == LOOP_WHILE)
522 op << " while (i < " << boundValueStr << ")\n";
523 else // LOOP_DO_WHILE
528 // Workload calculations inside the loop.
530 writeLoopWorkload(op, "res", isVertexCase ? "a_value" : "v_value");
533 // Only "for" has counter increment in the loop head.
534 if (m_type != LOOP_FOR)
538 if (m_type == LOOP_DO_WHILE)
539 op << " } while (i < " << boundValueStr << ");\n";
545 // Put result to color variable.
546 vtx << " v_color = res;\n";
547 frag << " gl_FragColor = v_color;\n";
551 // Transfer inputs to fragment shader through varyings.
553 vtx << " v_bound = a_bound;\n";
554 vtx << " v_value = a_value;\n";
556 frag << " gl_FragColor = res;\n"; // Put result to color variable.
562 m_vertShaderSource = vtx.str();
563 m_fragShaderSource = frag.str();
567 if (m_isLoopBoundStable)
569 // Every execution has same number of iterations.
571 m_attributes.push_back(AttribSpec("a_bound", Vec4(loopBound, 0.0f, 0.0f, 0.0f),
572 Vec4(loopBound, 0.0f, 0.0f, 0.0f),
573 Vec4(loopBound, 0.0f, 0.0f, 0.0f),
574 Vec4(loopBound, 0.0f, 0.0f, 0.0f)));
576 else if (isVertexCase)
578 // Vertex case, with non-constant number of iterations.
580 const int numComponents = 4;
581 int numVertices = (getGridWidth() + 1) * (getGridHeight() + 1);
583 // setupProgram() will later bind this array as an attribute.
584 m_boundArray.resize(numVertices * numComponents);
586 // Vary between low and high loop bounds; they should average to loopBound however.
587 for (int i = 0; i < (int)m_boundArray.size(); i++)
589 if (i % numComponents == 0)
590 m_boundArray[i] = (i / numComponents) % 2 == 0 ? unstableBoundLow : unstableBoundHigh;
592 m_boundArray[i] = 0.0f;
595 else // !m_isLoopBoundStable && !isVertexCase
597 // Fragment case, with non-constant number of iterations.
598 // \note fract(a_bound) < 0.5 will be true for every second fragment.
600 float minValue = 0.0f;
601 float maxValue = (float)getViewportWidth()*0.5f;
602 m_attributes.push_back(AttribSpec("a_bound", Vec4(minValue, 0.0f, 0.0f, 0.0f),
603 Vec4(maxValue, 0.0f, 0.0f, 0.0f),
604 Vec4(minValue, 0.0f, 0.0f, 0.0f),
605 Vec4(maxValue, 0.0f, 0.0f, 0.0f)));
609 m_attributes.push_back(AttribSpec("a_value", Vec4(0.0f, 0.1f, 0.2f, 0.3f),
610 Vec4(0.4f, 0.5f, 0.6f, 0.7f),
611 Vec4(0.8f, 0.9f, 1.0f, 1.1f),
612 Vec4(1.2f, 1.3f, 1.4f, 1.5f)));
614 ControlStatementCase::init();
617 void LoopCase::setupProgram (deUint32 program)
619 const glw::Functions& gl = m_renderCtx.getFunctions();
621 if (m_decisionType == DECISION_UNIFORM)
623 const float loopBound = 10.5f;
625 int location = gl.getUniformLocation(program, "u_bound");
626 gl.uniform1f(location, loopBound);
628 else if (m_decisionType == DECISION_ATTRIBUTE && !m_isLoopBoundStable && m_caseType == CASETYPE_VERTEX)
630 // Setup per-vertex loop bounds calculated in init().
632 const int numComponents = 4;
633 int boundAttribLocation = gl.getAttribLocation(program, "a_bound");
635 DE_ASSERT((int)m_boundArray.size() == numComponents * (getGridWidth() + 1) * (getGridHeight() + 1));
637 gl.genBuffers(1, &m_arrayBuffer);
638 gl.bindBuffer(GL_ARRAY_BUFFER, m_arrayBuffer);
639 gl.bufferData(GL_ARRAY_BUFFER, (GLsizeiptr)(m_boundArray.size()*sizeof(float)), &m_boundArray[0], GL_STATIC_DRAW);
640 gl.enableVertexAttribArray(boundAttribLocation);
641 gl.vertexAttribPointer(boundAttribLocation, (GLint)numComponents, GL_FLOAT, GL_FALSE, 0, DE_NULL);
644 GLU_EXPECT_NO_ERROR(gl.getError(), "Setup program state");
647 LoopCase::~LoopCase (void)
649 const glw::Functions& gl = m_renderCtx.getFunctions();
653 gl.deleteBuffers(1, &m_arrayBuffer);
658 void LoopCase::deinit (void)
660 const glw::Functions& gl = m_renderCtx.getFunctions();
662 m_boundArray.clear();
666 gl.deleteBuffers(1, &m_arrayBuffer);
670 ShaderPerformanceCase::deinit();
673 // A reference case, same calculations as the actual tests but without control statements.
674 class WorkloadReferenceCase : public ControlStatementCase
677 WorkloadReferenceCase (Context& context, const char* name, const char* description, bool isVertex);
682 virtual void writeWorkload (std::ostringstream& dst, const char* resultVariableName, const char* inputVariableName) const = 0;
685 WorkloadReferenceCase::WorkloadReferenceCase (Context& context, const char* name, const char* description, bool isVertex)
686 : ControlStatementCase(context.getTestContext(), context.getRenderContext(), name, description, isVertex ? CASETYPE_VERTEX : CASETYPE_FRAGMENT)
690 void WorkloadReferenceCase::init (void)
692 bool isVertexCase = m_caseType == CASETYPE_VERTEX;
694 std::ostringstream vtx;
695 std::ostringstream frag;
696 std::ostringstream& op = isVertexCase ? vtx : frag;
698 vtx << "attribute highp vec4 a_position;\n"; // Position attribute.
699 vtx << "attribute mediump vec4 a_value;\n"; // Value for workload calculations.
704 vtx << "varying mediump vec4 v_color;\n";
705 frag << "varying mediump vec4 v_color;\n";
709 vtx << "varying mediump vec4 v_value;\n";
710 frag << "varying mediump vec4 v_value;\n";
714 vtx << "void main()\n";
716 vtx << " gl_Position = a_position;\n";
719 frag << "void main()\n";
722 op << "\tmediump vec4 res;\n";
723 writeWorkload(op, "res", isVertexCase ? "a_value" : "v_value");
727 // Put result to color variable.
728 vtx << " v_color = res;\n";
729 frag << " gl_FragColor = v_color;\n";
733 vtx << " v_value = a_value;\n"; // Transfer input to fragment shader through varying.
734 frag << " gl_FragColor = res;\n"; // Put result to color variable.
740 m_vertShaderSource = vtx.str();
741 m_fragShaderSource = frag.str();
743 m_attributes.push_back(AttribSpec("a_value", Vec4(0.0f, 0.1f, 0.2f, 0.3f),
744 Vec4(0.4f, 0.5f, 0.6f, 0.7f),
745 Vec4(0.8f, 0.9f, 1.0f, 1.1f),
746 Vec4(1.2f, 1.3f, 1.4f, 1.5f)));
748 ControlStatementCase::init();
751 class LoopWorkloadReferenceCase : public WorkloadReferenceCase
754 LoopWorkloadReferenceCase (Context& context, const char* name, const char* description, bool isAttributeStable, bool isVertex)
755 : WorkloadReferenceCase (context, name, description, isVertex)
756 , m_isAttributeStable (isAttributeStable)
761 void writeWorkload (std::ostringstream& dst, const char* resultVariableName, const char* inputVariableName) const;
764 bool m_isAttributeStable;
767 void LoopWorkloadReferenceCase::writeWorkload (std::ostringstream& dst, const char* resultVariableName, const char* inputVariableName) const
769 const int loopIterations = 11;
770 bool isVertexCase = m_caseType == CASETYPE_VERTEX;
772 dst << "\t" << resultVariableName << " = vec4(0.0);\n";
774 for (int i = 0; i < loopIterations; i++)
777 writeLoopWorkload(dst, resultVariableName, inputVariableName);
781 if (!isVertexCase && !m_isAttributeStable)
783 // Corresponds to the fract() done in a real test's fragment case with non-stable attribute.
784 dst << " res.x = fract(res.x);\n";
788 class ConditionalWorkloadReferenceCase : public WorkloadReferenceCase
791 ConditionalWorkloadReferenceCase (Context& context, const char* name, const char* description, bool isAttributeStable, bool isVertex)
792 : WorkloadReferenceCase (context, name, description, isVertex)
793 , m_isAttributeStable (isAttributeStable)
798 void writeWorkload (std::ostringstream& dst, const char* resultVariableName, const char* inputVariableName) const;
801 bool m_isAttributeStable;
804 void ConditionalWorkloadReferenceCase::writeWorkload (std::ostringstream& dst, const char* resultVariableName, const char* inputVariableName) const
806 bool isVertexCase = m_caseType == CASETYPE_VERTEX;
809 writeConditionalWorkload(dst, resultVariableName, inputVariableName);
812 if (!isVertexCase && !m_isAttributeStable)
814 // Corresponds to the fract() done in a real test's fragment case with non-stable attribute.
815 dst << " res.x = fract(res.x);\n";
819 // A workload reference case for e.g. a conditional case with a branch with no computation.
820 class EmptyWorkloadReferenceCase : public WorkloadReferenceCase
823 EmptyWorkloadReferenceCase (Context& context, const char* name, const char* description, bool isVertex)
824 : WorkloadReferenceCase (context, name, description, isVertex)
829 void writeWorkload (std::ostringstream& dst, const char* resultVariableName, const char* inputVariableName) const
831 dst << "\t" << resultVariableName << " = " << inputVariableName << ";\n";
835 ShaderControlStatementTests::ShaderControlStatementTests (Context& context)
836 : TestCaseGroup(context, "control_statement", "Control Statement Performance Tests")
840 ShaderControlStatementTests::~ShaderControlStatementTests (void)
844 void ShaderControlStatementTests::init (void)
846 // Conditional cases (if-else).
848 tcu::TestCaseGroup* ifElseGroup = new tcu::TestCaseGroup(m_testCtx, "if_else", "if-else Conditional Performance Tests");
849 addChild(ifElseGroup);
851 for (int isFrag = 0; isFrag <= 1; isFrag++)
853 bool isVertex = isFrag == 0;
854 ShaderPerformanceCaseGroup* vertexOrFragmentGroup = new ShaderPerformanceCaseGroup(m_testCtx, isVertex ? "vertex" : "fragment", "");
855 ifElseGroup->addChild(vertexOrFragmentGroup);
857 DE_STATIC_ASSERT(DECISION_STATIC == 0);
858 for (int decisionType = (int)DECISION_STATIC; decisionType < (int)DECISION_LAST; decisionType++)
860 const char* decisionName = decisionType == (int)DECISION_STATIC ? "static" :
861 decisionType == (int)DECISION_UNIFORM ? "uniform" :
862 decisionType == (int)DECISION_ATTRIBUTE ? (isVertex ? "attribute" : "varying") :
864 DE_ASSERT(decisionName != DE_NULL);
866 for (int workloadDivision = 0; workloadDivision < ConditionalCase::WORKLOAD_DIVISION_LAST; workloadDivision++)
868 const char* workloadDivisionSuffix = workloadDivision == (int)ConditionalCase::WORKLOAD_DIVISION_EVEN ? "" :
869 workloadDivision == (int)ConditionalCase::WORKLOAD_DIVISION_TRUE_HEAVY ? "_with_heavier_true" :
870 workloadDivision == (int)ConditionalCase::WORKLOAD_DIVISION_FALSE_HEAVY ? "_with_heavier_false" :
872 DE_ASSERT(workloadDivisionSuffix != DE_NULL);
874 DE_STATIC_ASSERT(ConditionalCase::BRANCH_TRUE == 0);
875 for (int branchResult = (int)ConditionalCase::BRANCH_TRUE; branchResult < (int)ConditionalCase::BRANCH_LAST; branchResult++)
877 if (decisionType != (int)DECISION_ATTRIBUTE && branchResult == (int)ConditionalCase::BRANCH_MIXED)
880 const char* branchResultName = branchResult == (int)ConditionalCase::BRANCH_TRUE ? "true" :
881 branchResult == (int)ConditionalCase::BRANCH_FALSE ? "false" :
882 branchResult == (int)ConditionalCase::BRANCH_MIXED ? "mixed" :
884 DE_ASSERT(branchResultName != DE_NULL);
886 string caseName = string("") + decisionName + "_" + branchResultName + workloadDivisionSuffix;
888 vertexOrFragmentGroup->addChild(new ConditionalCase(m_context, caseName.c_str(), "",
889 (DecisionType)decisionType, (ConditionalCase::BranchResult)branchResult,
890 (ConditionalCase::WorkloadDivision)workloadDivision, isVertex));
896 vertexOrFragmentGroup->addChild(new ConditionalWorkloadReferenceCase(m_context, "reference", "", true, isVertex));
899 // Only fragment case with BRANCH_MIXED has an additional fract() call.
900 vertexOrFragmentGroup->addChild(new ConditionalWorkloadReferenceCase(m_context, "reference_unmixed", "", true, isVertex));
901 vertexOrFragmentGroup->addChild(new ConditionalWorkloadReferenceCase(m_context, "reference_mixed", "", false, isVertex));
904 vertexOrFragmentGroup->addChild(new EmptyWorkloadReferenceCase(m_context, "reference_empty", "", isVertex));
911 LoopCase::LoopType type;
913 const char* description;
916 {LoopCase::LOOP_FOR, "for", "for Loop Performance Tests"},
917 {LoopCase::LOOP_WHILE, "while", "while Loop Performance Tests"},
918 {LoopCase::LOOP_DO_WHILE, "do_while", "do-while Loop Performance Tests"}
921 for (int groupNdx = 0; groupNdx < DE_LENGTH_OF_ARRAY(loopGroups); groupNdx++)
923 tcu::TestCaseGroup* currentLoopGroup = new tcu::TestCaseGroup(m_testCtx, loopGroups[groupNdx].name, loopGroups[groupNdx].description);
924 addChild(currentLoopGroup);
926 for (int isFrag = 0; isFrag <= 1; isFrag++)
928 bool isVertex = isFrag == 0;
929 ShaderPerformanceCaseGroup* vertexOrFragmentGroup = new ShaderPerformanceCaseGroup(m_testCtx, isVertex ? "vertex" : "fragment", "");
930 currentLoopGroup->addChild(vertexOrFragmentGroup);
932 DE_STATIC_ASSERT(DECISION_STATIC == 0);
933 for (int decisionType = (int)DECISION_STATIC; decisionType < (int)DECISION_LAST; decisionType++)
935 const char* decisionName = decisionType == (int)DECISION_STATIC ? "static" :
936 decisionType == (int)DECISION_UNIFORM ? "uniform" :
937 decisionType == (int)DECISION_ATTRIBUTE ? (isVertex ? "attribute" : "varying") :
939 DE_ASSERT(decisionName != DE_NULL);
941 if (decisionType == (int)DECISION_ATTRIBUTE)
943 vertexOrFragmentGroup->addChild(new LoopCase(m_context, (string(decisionName) + "_stable").c_str(), "", loopGroups[groupNdx].type, (DecisionType)decisionType, true, isVertex));
944 vertexOrFragmentGroup->addChild(new LoopCase(m_context, (string(decisionName) + "_unstable").c_str(), "", loopGroups[groupNdx].type, (DecisionType)decisionType, false, isVertex));
947 vertexOrFragmentGroup->addChild(new LoopCase(m_context, decisionName, "", loopGroups[groupNdx].type, (DecisionType)decisionType, true, isVertex));
952 vertexOrFragmentGroup->addChild(new LoopWorkloadReferenceCase(m_context, "reference", "", true, isVertex));
955 // Only fragment case with unstable attribute has an additional fract() call.
956 vertexOrFragmentGroup->addChild(new LoopWorkloadReferenceCase(m_context, "reference_stable", "", true, isVertex));
957 vertexOrFragmentGroup->addChild(new LoopWorkloadReferenceCase(m_context, "reference_unstable", "", false, isVertex));