13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL ES 3.1 Module 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ------------------------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Drawing tests. 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es31fDrawTests.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deRandom.hpp" 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deStringUtil.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMemory.h" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuRenderTarget.hpp" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuVectorUtil.hpp" 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "sglrGLContext.hpp" 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glsDrawTest.hpp" 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluStrUtil.hpp" 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPixelTransfer.hpp" 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluCallLogWrapper.hpp" 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp" 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp" 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <set> 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles31 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum TestIterationType 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TYPE_DRAW_COUNT, // !< test with 1, 5, and 25 primitives 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TYPE_INSTANCE_COUNT, // !< test with 1, 4, and 11 instances 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TYPE_LAST 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char* s_commonVertexShaderSource = "#version 310 es\n" 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "in highp vec4 a_position;\n" 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main (void)\n" 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n" 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " gl_Position = a_position;\n" 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}\n"; 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char* s_commonFragmentShaderSource = "#version 310 es\n" 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "layout(location = 0) out highp vec4 fragColor;\n" 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main (void)\n" 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n" 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}\n"; 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char* s_colorVertexShaderSource = "#version 310 es\n" 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "in highp vec4 a_position;\n" 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "in highp vec4 a_color;\n" 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "out highp vec4 v_color;\n" 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main (void)\n" 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n" 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " gl_Position = a_position;\n" 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " v_color = a_color;\n" 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}\n"; 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char* s_colorFragmentShaderSource = "#version 310 es\n" 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "layout(location = 0) out highp vec4 fragColor;\n" 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "in highp vec4 v_color;\n" 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main (void)\n" 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n" 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " fragColor = v_color;\n" 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}\n"; 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct DrawElementsCommand 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 count; 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 primCount; 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 firstIndex; 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deInt32 baseVertex; 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 reservedMustBeZero; 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 953c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDE_STATIC_ASSERT(5 * sizeof(deUint32) == sizeof(DrawElementsCommand)); // tight packing 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct DrawArraysCommand 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 count; 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 primCount; 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 first; 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 reservedMustBeZero; 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1043c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDE_STATIC_ASSERT(4 * sizeof(deUint32) == sizeof(DrawArraysCommand)); // tight packing 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Verifies image contains only yellow or greeen, or a linear combination 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// of these colors. 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic bool verifyImageYellowGreen (const tcu::Surface& image, tcu::TestLog& log) 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry using tcu::TestLog; 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int colorThreshold = 20; 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface error (image.getWidth(), image.getHeight()); 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isOk = true; 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < image.getHeight(); y++) 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < image.getWidth(); x++) 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::RGBA pixel = image.getPixel(x, y); 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool pixelOk = true; 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Any pixel with !(G ~= 255) is faulty (not a linear combinations of green and yellow) 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (de::abs(pixel.getGreen() - 255) > colorThreshold) 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry pixelOk = false; 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Any pixel with !(B ~= 0) is faulty (not a linear combinations of green and yellow) 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (de::abs(pixel.getBlue() - 0) > colorThreshold) 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry pixelOk = false; 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry error.setPixel(x, y, (pixelOk) ? (tcu::RGBA(0, 255, 0, 255)) : (tcu::RGBA(255, 0, 0, 255))); 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry isOk = isOk && pixelOk; 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!isOk) 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "Image verification failed." << TestLog::EndMessage; 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::ImageSet("Verfication result", "Result of rendering") 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << TestLog::Image("Result", "Result", image) 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << TestLog::Image("ErrorMask", "Error mask", error) 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << TestLog::EndImageSet; 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::ImageSet("Verfication result", "Result of rendering") 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << TestLog::Image("Result", "Result", image) 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << TestLog::EndImageSet; 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return isOk; 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void addTestIterations (gls::DrawTest* test, gls::DrawTestSpec& spec, TestIterationType type) 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (type == TYPE_DRAW_COUNT) 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.primitiveCount = 1; 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry test->addIteration(spec, "draw count = 1"); 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.primitiveCount = 5; 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry test->addIteration(spec, "draw count = 5"); 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.primitiveCount = 25; 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry test->addIteration(spec, "draw count = 25"); 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (type == TYPE_INSTANCE_COUNT) 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.instanceCount = 1; 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry test->addIteration(spec, "instance count = 1"); 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.instanceCount = 4; 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry test->addIteration(spec, "instance count = 4"); 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.instanceCount = 11; 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry test->addIteration(spec, "instance count = 11"); 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(false); 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void genBasicSpec (gls::DrawTestSpec& spec, gls::DrawTestSpec::DrawMethod method) 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.apiType = glu::ApiType::es(3,1); 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.primitive = gls::DrawTestSpec::PRIMITIVE_TRIANGLES; 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.primitiveCount = 5; 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.drawMethod = method; 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexType = gls::DrawTestSpec::INDEXTYPE_LAST; 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexPointerOffset = 0; 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexStorage = gls::DrawTestSpec::STORAGE_LAST; 1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.first = 0; 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexMin = 0; 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexMax = 0; 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.instanceCount = 1; 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indirectOffset = 0; 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs.resize(2); 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].inputType = gls::DrawTestSpec::INPUTTYPE_FLOAT; 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].outputType = gls::DrawTestSpec::OUTPUTTYPE_VEC2; 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].storage = gls::DrawTestSpec::STORAGE_BUFFER; 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].usage = gls::DrawTestSpec::USAGE_STATIC_DRAW; 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].componentCount = 4; 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].offset = 0; 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].stride = 0; 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].normalize = false; 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].instanceDivisor = 0; 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].useDefaultAttribute = false; 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].inputType = gls::DrawTestSpec::INPUTTYPE_FLOAT; 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].outputType = gls::DrawTestSpec::OUTPUTTYPE_VEC2; 2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].storage = gls::DrawTestSpec::STORAGE_BUFFER; 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].usage = gls::DrawTestSpec::USAGE_STATIC_DRAW; 2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].componentCount = 2; 2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].offset = 0; 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].stride = 0; 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].normalize = false; 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].instanceDivisor = 0; 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].useDefaultAttribute = false; 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic std::string sizeToString (int size) 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (size < 1024) 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return de::toString(size) + " byte(s)"; 2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (size < 1024*1024) 2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return de::toString(size / 1024) + " KB"; 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return de::toString(size / 1024 / 1024) + " MB"; 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass AttributeGroup : public TestCaseGroup 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry AttributeGroup (Context& context, const char* name, const char* descr, gls::DrawTestSpec::DrawMethod drawMethod, gls::DrawTestSpec::Primitive primitive, gls::DrawTestSpec::IndexType indexType, gls::DrawTestSpec::Storage indexStorage); 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~AttributeGroup (void); 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::DrawMethod m_method; 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::Primitive m_primitive; 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::IndexType m_indexType; 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::Storage m_indexStorage; 2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2453c827367444ee418f129b2c238299f49d3264554Jarkko PoyryAttributeGroup::AttributeGroup (Context& context, const char* name, const char* descr, gls::DrawTestSpec::DrawMethod drawMethod, gls::DrawTestSpec::Primitive primitive, gls::DrawTestSpec::IndexType indexType, gls::DrawTestSpec::Storage indexStorage) 2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCaseGroup (context, name, descr) 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_method (drawMethod) 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_primitive (primitive) 2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_indexType (indexType) 2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_indexStorage (indexStorage) 2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2543c827367444ee418f129b2c238299f49d3264554Jarkko PoyryAttributeGroup::~AttributeGroup (void) 2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid AttributeGroup::init (void) 2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Single attribute 2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTest* test = new gls::DrawTest(m_testCtx, m_context.getRenderContext(), "single_attribute", "Single attribute array."); 2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec spec; 2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.apiType = glu::ApiType::es(3,1); 2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.primitive = m_primitive; 2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.primitiveCount = 5; 2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.drawMethod = m_method; 2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexType = m_indexType; 2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexPointerOffset = 0; 2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexStorage = m_indexStorage; 2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.first = 0; 2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexMin = 0; 2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexMax = 0; 2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.instanceCount = 1; 2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indirectOffset = 0; 2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs.resize(1); 2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].inputType = gls::DrawTestSpec::INPUTTYPE_FLOAT; 2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].outputType = gls::DrawTestSpec::OUTPUTTYPE_VEC2; 2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].storage = gls::DrawTestSpec::STORAGE_BUFFER; 2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].usage = gls::DrawTestSpec::USAGE_STATIC_DRAW; 2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].componentCount = 2; 2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].offset = 0; 2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].stride = 0; 2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].normalize = false; 2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].instanceDivisor = 0; 2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].useDefaultAttribute = false; 2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addTestIterations(test, spec, TYPE_DRAW_COUNT); 2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry this->addChild(test); 2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Multiple attribute 2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTest* test = new gls::DrawTest(m_testCtx, m_context.getRenderContext(), "multiple_attributes", "Multiple attribute arrays."); 2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec spec; 3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.apiType = glu::ApiType::es(3,1); 3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.primitive = m_primitive; 3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.primitiveCount = 5; 3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.drawMethod = m_method; 3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexType = m_indexType; 3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexPointerOffset = 0; 3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexStorage = m_indexStorage; 3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.first = 0; 3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexMin = 0; 3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexMax = 0; 3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.instanceCount = 1; 3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indirectOffset = 0; 3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs.resize(2); 3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].inputType = gls::DrawTestSpec::INPUTTYPE_FLOAT; 3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].outputType = gls::DrawTestSpec::OUTPUTTYPE_VEC2; 3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].storage = gls::DrawTestSpec::STORAGE_BUFFER; 3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].usage = gls::DrawTestSpec::USAGE_STATIC_DRAW; 3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].componentCount = 4; 3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].offset = 0; 3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].stride = 0; 3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].normalize = false; 3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].instanceDivisor = 0; 3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].useDefaultAttribute = false; 3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].inputType = gls::DrawTestSpec::INPUTTYPE_FLOAT; 3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].outputType = gls::DrawTestSpec::OUTPUTTYPE_VEC2; 3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].storage = gls::DrawTestSpec::STORAGE_BUFFER; 3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].usage = gls::DrawTestSpec::USAGE_STATIC_DRAW; 3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].componentCount = 2; 3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].offset = 0; 3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].stride = 0; 3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].normalize = false; 3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].instanceDivisor = 0; 3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].useDefaultAttribute = false; 3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addTestIterations(test, spec, TYPE_DRAW_COUNT); 3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry this->addChild(test); 3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Multiple attribute, second one divided 3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTest* test = new gls::DrawTest(m_testCtx, m_context.getRenderContext(), "instanced_attributes", "Instanced attribute array."); 3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec spec; 3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.apiType = glu::ApiType::es(3,1); 3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.primitive = m_primitive; 3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.primitiveCount = 5; 3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.drawMethod = m_method; 3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexType = m_indexType; 3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexPointerOffset = 0; 3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexStorage = m_indexStorage; 3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.first = 0; 3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexMin = 0; 3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexMax = 0; 3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.instanceCount = 1; 3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indirectOffset = 0; 3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs.resize(3); 3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].inputType = gls::DrawTestSpec::INPUTTYPE_FLOAT; 3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].outputType = gls::DrawTestSpec::OUTPUTTYPE_VEC2; 3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].storage = gls::DrawTestSpec::STORAGE_BUFFER; 3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].usage = gls::DrawTestSpec::USAGE_STATIC_DRAW; 3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].componentCount = 4; 3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].offset = 0; 3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].stride = 0; 3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].normalize = false; 3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].instanceDivisor = 0; 3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].useDefaultAttribute = false; 3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Add another position component so the instances wont be drawn on each other 3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].inputType = gls::DrawTestSpec::INPUTTYPE_FLOAT; 3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].outputType = gls::DrawTestSpec::OUTPUTTYPE_VEC2; 3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].storage = gls::DrawTestSpec::STORAGE_BUFFER; 3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].usage = gls::DrawTestSpec::USAGE_STATIC_DRAW; 3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].componentCount = 2; 3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].offset = 0; 3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].stride = 0; 3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].normalize = false; 3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].instanceDivisor = 1; 3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].useDefaultAttribute = false; 3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].additionalPositionAttribute = true; 3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Instanced color 3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[2].inputType = gls::DrawTestSpec::INPUTTYPE_FLOAT; 3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[2].outputType = gls::DrawTestSpec::OUTPUTTYPE_VEC2; 3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[2].storage = gls::DrawTestSpec::STORAGE_BUFFER; 3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[2].usage = gls::DrawTestSpec::USAGE_STATIC_DRAW; 3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[2].componentCount = 3; 3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[2].offset = 0; 3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[2].stride = 0; 3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[2].normalize = false; 3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[2].instanceDivisor = 1; 3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[2].useDefaultAttribute = false; 3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addTestIterations(test, spec, TYPE_INSTANCE_COUNT); 4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry this->addChild(test); 4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Multiple attribute, second one default 4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTest* test = new gls::DrawTest(m_testCtx, m_context.getRenderContext(), "default_attribute", "Attribute specified with glVertexAttrib*."); 4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec spec; 4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.apiType = glu::ApiType::es(3,1); 4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.primitive = m_primitive; 4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.primitiveCount = 5; 4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.drawMethod = m_method; 4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexType = m_indexType; 4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexPointerOffset = 0; 4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexStorage = m_indexStorage; 4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.first = 0; 4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexMin = 0; 4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexMax = 0; 4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.instanceCount = 1; 4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indirectOffset = 0; 4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs.resize(2); 4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].inputType = gls::DrawTestSpec::INPUTTYPE_FLOAT; 4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].outputType = gls::DrawTestSpec::OUTPUTTYPE_VEC2; 4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].storage = gls::DrawTestSpec::STORAGE_BUFFER; 4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].usage = gls::DrawTestSpec::USAGE_STATIC_DRAW; 4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].componentCount = 2; 4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].offset = 0; 4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].stride = 0; 4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].normalize = false; 4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].instanceDivisor = 0; 4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].useDefaultAttribute = false; 4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry struct IOPair 4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::InputType input; 4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::OutputType output; 4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int componentCount; 4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } iopairs[] = 4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { gls::DrawTestSpec::INPUTTYPE_FLOAT, gls::DrawTestSpec::OUTPUTTYPE_VEC2, 4 }, 4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { gls::DrawTestSpec::INPUTTYPE_FLOAT, gls::DrawTestSpec::OUTPUTTYPE_VEC4, 2 }, 4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { gls::DrawTestSpec::INPUTTYPE_INT, gls::DrawTestSpec::OUTPUTTYPE_IVEC3, 4 }, 4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { gls::DrawTestSpec::INPUTTYPE_UNSIGNED_INT, gls::DrawTestSpec::OUTPUTTYPE_UVEC2, 4 }, 4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ioNdx = 0; ioNdx < DE_LENGTH_OF_ARRAY(iopairs); ++ioNdx) 4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string desc = gls::DrawTestSpec::inputTypeToString(iopairs[ioNdx].input) + de::toString(iopairs[ioNdx].componentCount) + " to " + gls::DrawTestSpec::outputTypeToString(iopairs[ioNdx].output); 4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].inputType = iopairs[ioNdx].input; 4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].outputType = iopairs[ioNdx].output; 4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].storage = gls::DrawTestSpec::STORAGE_BUFFER; 4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].usage = gls::DrawTestSpec::USAGE_STATIC_DRAW; 4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].componentCount = iopairs[ioNdx].componentCount; 4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].offset = 0; 4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].stride = 0; 4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].normalize = false; 4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].instanceDivisor = 0; 4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[1].useDefaultAttribute = true; 4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry test->addIteration(spec, desc.c_str()); 4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry this->addChild(test); 4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass IndexGroup : public TestCaseGroup 4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IndexGroup (Context& context, const char* name, const char* descr, gls::DrawTestSpec::DrawMethod drawMethod); 4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~IndexGroup (void); 4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::DrawMethod m_method; 4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4823c827367444ee418f129b2c238299f49d3264554Jarkko PoyryIndexGroup::IndexGroup (Context& context, const char* name, const char* descr, gls::DrawTestSpec::DrawMethod drawMethod) 4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCaseGroup (context, name, descr) 4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_method (drawMethod) 4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4883c827367444ee418f129b2c238299f49d3264554Jarkko PoyryIndexGroup::~IndexGroup (void) 4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid IndexGroup::init (void) 4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry struct IndexTest 4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::IndexType type; 4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int offsets[3]; 4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const IndexTest tests[] = 5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { gls::DrawTestSpec::INDEXTYPE_BYTE, { 0, 1, -1 } }, 5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { gls::DrawTestSpec::INDEXTYPE_SHORT, { 0, 2, -1 } }, 5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { gls::DrawTestSpec::INDEXTYPE_INT, { 0, 4, -1 } }, 5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec spec; 5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry genBasicSpec(spec, m_method); 5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexStorage = gls::DrawTestSpec::STORAGE_BUFFER; 5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int testNdx = 0; testNdx < DE_LENGTH_OF_ARRAY(tests); ++testNdx) 5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const IndexTest& indexTest = tests[testNdx]; 5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string name = std::string("index_") + gls::DrawTestSpec::indexTypeToString(indexTest.type); 5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string desc = std::string("index ") + gls::DrawTestSpec::indexTypeToString(indexTest.type); 5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTest* test = new gls::DrawTest(m_testCtx, m_context.getRenderContext(), name.c_str(), desc.c_str()); 5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexType = indexTest.type; 5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int iterationNdx = 0; iterationNdx < DE_LENGTH_OF_ARRAY(indexTest.offsets) && indexTest.offsets[iterationNdx] != -1; ++iterationNdx) 5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string iterationDesc = std::string("first vertex ") + de::toString(indexTest.offsets[iterationNdx] / gls::DrawTestSpec::indexTypeSize(indexTest.type)); 5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexPointerOffset = indexTest.offsets[iterationNdx]; 5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry test->addIteration(spec, iterationDesc.c_str()); 5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(test); 5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass BaseVertexGroup : public TestCaseGroup 5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry BaseVertexGroup (Context& context, const char* name, const char* descr, gls::DrawTestSpec::DrawMethod drawMethod); 5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~BaseVertexGroup (void); 5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::DrawMethod m_method; 5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5453c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBaseVertexGroup::BaseVertexGroup (Context& context, const char* name, const char* descr, gls::DrawTestSpec::DrawMethod drawMethod) 5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCaseGroup (context, name, descr) 5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_method (drawMethod) 5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5513c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBaseVertexGroup::~BaseVertexGroup (void) 5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BaseVertexGroup::init (void) 5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry struct IndexTest 5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool positiveBase; 5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::IndexType type; 5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int baseVertex[2]; 5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const IndexTest tests[] = 5653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { true, gls::DrawTestSpec::INDEXTYPE_BYTE, { 1, 2 } }, 5673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { true, gls::DrawTestSpec::INDEXTYPE_SHORT, { 1, 2 } }, 5683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { true, gls::DrawTestSpec::INDEXTYPE_INT, { 1, 2 } }, 5693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { false, gls::DrawTestSpec::INDEXTYPE_BYTE, { -1, -2 } }, 5703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { false, gls::DrawTestSpec::INDEXTYPE_SHORT, { -1, -2 } }, 5713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { false, gls::DrawTestSpec::INDEXTYPE_INT, { -1, -2 } }, 5723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 5733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec spec; 5753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry genBasicSpec(spec, m_method); 5763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexStorage = gls::DrawTestSpec::STORAGE_BUFFER; 5783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int testNdx = 0; testNdx < DE_LENGTH_OF_ARRAY(tests); ++testNdx) 5803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const IndexTest& indexTest = tests[testNdx]; 5823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string name = std::string("index_") + (indexTest.positiveBase ? "" : "neg_") + gls::DrawTestSpec::indexTypeToString(indexTest.type); 5843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string desc = std::string("index ") + gls::DrawTestSpec::indexTypeToString(indexTest.type); 5853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTest* test = new gls::DrawTest(m_testCtx, m_context.getRenderContext(), name.c_str(), desc.c_str()); 5863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexType = indexTest.type; 5883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int iterationNdx = 0; iterationNdx < DE_LENGTH_OF_ARRAY(indexTest.baseVertex); ++iterationNdx) 5903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string iterationDesc = std::string("base vertex ") + de::toString(indexTest.baseVertex[iterationNdx]); 5923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.baseVertex = indexTest.baseVertex[iterationNdx]; 5933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry test->addIteration(spec, iterationDesc.c_str()); 5943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(test); 5973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6003c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass FirstGroup : public TestCaseGroup 6013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6023c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 6033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FirstGroup (Context& context, const char* name, const char* descr, gls::DrawTestSpec::DrawMethod drawMethod); 6043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~FirstGroup (void); 6053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 6073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6083c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 6093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::DrawMethod m_method; 6103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 6113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6123c827367444ee418f129b2c238299f49d3264554Jarkko PoyryFirstGroup::FirstGroup (Context& context, const char* name, const char* descr, gls::DrawTestSpec::DrawMethod drawMethod) 6133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCaseGroup (context, name, descr) 6143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_method (drawMethod) 6153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6183c827367444ee418f129b2c238299f49d3264554Jarkko PoyryFirstGroup::~FirstGroup (void) 6193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6223c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid FirstGroup::init (void) 6233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int firsts[] = 6253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1, 3, 17 6273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 6283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec spec; 6303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry genBasicSpec(spec, m_method); 6313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int firstNdx = 0; firstNdx < DE_LENGTH_OF_ARRAY(firsts); ++firstNdx) 6333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string name = std::string("first_") + de::toString(firsts[firstNdx]); 6353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string desc = std::string("first ") + de::toString(firsts[firstNdx]); 6363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTest* test = new gls::DrawTest(m_testCtx, m_context.getRenderContext(), name.c_str(), desc.c_str()); 6373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.first = firsts[firstNdx]; 6393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addTestIterations(test, spec, TYPE_DRAW_COUNT); 6413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry this->addChild(test); 6433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass MethodGroup : public TestCaseGroup 6473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6483c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 6493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MethodGroup (Context& context, const char* name, const char* descr, gls::DrawTestSpec::DrawMethod drawMethod); 6503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~MethodGroup (void); 6513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 6533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6543c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 6553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::DrawMethod m_method; 6563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 6573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6583c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMethodGroup::MethodGroup (Context& context, const char* name, const char* descr, gls::DrawTestSpec::DrawMethod drawMethod) 6593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCaseGroup (context, name, descr) 6603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_method (drawMethod) 6613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6643c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMethodGroup::~MethodGroup (void) 6653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6683c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid MethodGroup::init (void) 6693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool indexed = (m_method == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_INDIRECT); 6713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool hasFirst = (m_method == gls::DrawTestSpec::DRAWMETHOD_DRAWARRAYS_INDIRECT); 6723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const gls::DrawTestSpec::Primitive primitive[] = 6743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::PRIMITIVE_POINTS, 6763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::PRIMITIVE_TRIANGLES, 6773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::PRIMITIVE_TRIANGLE_FAN, 6783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::PRIMITIVE_TRIANGLE_STRIP, 6793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::PRIMITIVE_LINES, 6803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::PRIMITIVE_LINE_STRIP, 6813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::PRIMITIVE_LINE_LOOP 6823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 6833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (hasFirst) 6853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // First-tests 6873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry this->addChild(new FirstGroup(m_context, "first", "First tests", m_method)); 6883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (indexed) 6913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Index-tests 6933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry this->addChild(new IndexGroup(m_context, "indices", "Index tests", m_method)); 6943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry this->addChild(new BaseVertexGroup(m_context, "base_vertex", "Base vertex tests", m_method)); 6953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(primitive); ++ndx) 6983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string name = gls::DrawTestSpec::primitiveToString(primitive[ndx]); 7003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string desc = gls::DrawTestSpec::primitiveToString(primitive[ndx]); 7013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry this->addChild(new AttributeGroup(m_context, name.c_str(), desc.c_str(), m_method, primitive[ndx], gls::DrawTestSpec::INDEXTYPE_SHORT, gls::DrawTestSpec::STORAGE_BUFFER)); 7033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 7043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7063c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass GridProgram : public sglr::ShaderProgram 7073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7083c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 7093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GridProgram (void); 7103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const; 7123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const; 7133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 7143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7153c827367444ee418f129b2c238299f49d3264554Jarkko PoyryGridProgram::GridProgram (void) 7163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : sglr::ShaderProgram(sglr::pdec::ShaderProgramDeclaration() 7173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT) 7183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << sglr::pdec::VertexAttribute("a_offset", rr::GENERICVECTYPE_FLOAT) 7193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << sglr::pdec::VertexAttribute("a_color", rr::GENERICVECTYPE_FLOAT) 7203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << sglr::pdec::VertexToFragmentVarying(rr::GENERICVECTYPE_FLOAT) 7213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT) 7223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << sglr::pdec::VertexSource("#version 310 es\n" 7233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "in highp vec4 a_position;\n" 7243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "in highp vec4 a_offset;\n" 7253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "in highp vec4 a_color;\n" 7263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "out highp vec4 v_color;\n" 7273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main(void)\n" 7283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n" 7293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " gl_Position = a_position + a_offset;\n" 7303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " v_color = a_color;\n" 7313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}\n") 7323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << sglr::pdec::FragmentSource( 7333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "#version 310 es\n" 7343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "layout(location = 0) out highp vec4 dEQP_FragColor;\n" 7353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "in highp vec4 v_color;\n" 7363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main(void)\n" 7373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n" 7383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " dEQP_FragColor = v_color;\n" 7393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}\n")) 7403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7433c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid GridProgram::shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const 7443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < numPackets; ++ndx) 7463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry packets[ndx]->position = rr::readVertexAttribFloat(inputs[0], packets[ndx]->instanceNdx, packets[ndx]->vertexNdx) + rr::readVertexAttribFloat(inputs[1], packets[ndx]->instanceNdx, packets[ndx]->vertexNdx); 7483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry packets[ndx]->outputs[0] = rr::readVertexAttribFloat(inputs[2], packets[ndx]->instanceNdx, packets[ndx]->vertexNdx); 7493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 7503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7523c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid GridProgram::shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const 7533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx) 7553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int fragNdx = 0; fragNdx < 4; ++fragNdx) 7563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, rr::readTriangleVarying<float>(packets[packetNdx], context, 0, fragNdx)); 7573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7593c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass InstancedGridRenderTest : public TestCase 7603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7613c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 7623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry InstancedGridRenderTest (Context& context, const char* name, const char* desc, int gridSide, bool useIndices); 7633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~InstancedGridRenderTest (void); 7643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IterateResult iterate (void); 7663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7673c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 7683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void renderTo (sglr::Context& ctx, sglr::ShaderProgram& program, tcu::Surface& dst); 7693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int m_gridSide; 7713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool m_useIndices; 7723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 7733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7743c827367444ee418f129b2c238299f49d3264554Jarkko PoyryInstancedGridRenderTest::InstancedGridRenderTest (Context& context, const char* name, const char* desc, int gridSide, bool useIndices) 7753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCase (context, name, desc) 7763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_gridSide (gridSide) 7773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_useIndices (useIndices) 7783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7813c827367444ee418f129b2c238299f49d3264554Jarkko PoyryInstancedGridRenderTest::~InstancedGridRenderTest (void) 7823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7853c827367444ee418f129b2c238299f49d3264554Jarkko PoyryInstancedGridRenderTest::IterateResult InstancedGridRenderTest::iterate (void) 7863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int renderTargetWidth = de::min(1024, m_context.getRenderTarget().getWidth()); 7883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int renderTargetHeight = de::min(1024, m_context.getRenderTarget().getHeight()); 7893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sglr::GLContext ctx (m_context.getRenderContext(), m_testCtx.getLog(), sglr::GLCONTEXT_LOG_CALLS | sglr::GLCONTEXT_LOG_PROGRAMS, tcu::IVec4(0, 0, renderTargetWidth, renderTargetHeight)); 7913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface surface (renderTargetWidth, renderTargetHeight); 7923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GridProgram program; 7933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // render 7953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry renderTo(ctx, program, surface); 7973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // verify image 7993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \note the green/yellow pattern is only for clarity. The test will only verify that all instances were drawn by looking for anything non-green/yellow. 8003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (verifyImageYellowGreen(surface, m_testCtx.getLog())) 8013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 8023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 8033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Result image invalid"); 8043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return STOP; 8053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 8063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8073c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid InstancedGridRenderTest::renderTo (sglr::Context& ctx, sglr::ShaderProgram& program, tcu::Surface& dst) 8083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 8093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 green (0, 1, 0, 1); 8103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 yellow (1, 1, 0, 1); 8113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 vaoID = 0; 8133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 positionBuf = 0; 8143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 offsetBuf = 0; 8153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 colorBuf = 0; 8163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 indexBuf = 0; 8173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 drawIndirectBuf= 0; 8183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 programID = ctx.createProgram(&program); 8193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deInt32 posLocation = ctx.getAttribLocation(programID, "a_position"); 8203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deInt32 offsetLocation = ctx.getAttribLocation(programID, "a_offset"); 8213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deInt32 colorLocation = ctx.getAttribLocation(programID, "a_color"); 8223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8237a161d243743d8d12e12669d7464c360de1b5e97Jarkko Pöyry float cellW = 2.0f / (float)m_gridSide; 8247a161d243743d8d12e12669d7464c360de1b5e97Jarkko Pöyry float cellH = 2.0f / (float)m_gridSide; 8253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 vertexPositions[] = 8263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(0, 0, 0, 1), 8283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(cellW, 0, 0, 1), 8293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(0, cellH, 0, 1), 8303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(0, cellH, 0, 1), 8323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(cellW, 0, 0, 1), 8333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(cellW, cellH, 0, 1), 8343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 8353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint16 indices[] = 8373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 0, 4, 3, 8393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2, 1, 5 8403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 8413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<tcu::Vec4> offsets; 8433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < m_gridSide; ++x) 8443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < m_gridSide; ++y) 8457a161d243743d8d12e12669d7464c360de1b5e97Jarkko Pöyry offsets.push_back(tcu::Vec4((float)x * cellW - 1.0f, (float)y * cellW - 1.0f, 0, 0)); 8463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<tcu::Vec4> colors; 8483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < m_gridSide; ++x) 8493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < m_gridSide; ++y) 8503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry colors.push_back(((x + y) % 2 == 0) ? (green) : (yellow)); 8513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.genVertexArrays(1, &vaoID); 8533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.bindVertexArray(vaoID); 8543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.genBuffers(1, &positionBuf); 8563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.bindBuffer(GL_ARRAY_BUFFER, positionBuf); 8573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.bufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW); 8583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.vertexAttribPointer(posLocation, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL); 8593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.vertexAttribDivisor(posLocation, 0); 8603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.enableVertexAttribArray(posLocation); 8613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.genBuffers(1, &offsetBuf); 8633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.bindBuffer(GL_ARRAY_BUFFER, offsetBuf); 8643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.bufferData(GL_ARRAY_BUFFER, offsets.size() * sizeof(tcu::Vec4), &offsets[0], GL_STATIC_DRAW); 8653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.vertexAttribPointer(offsetLocation, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL); 8663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.vertexAttribDivisor(offsetLocation, 1); 8673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.enableVertexAttribArray(offsetLocation); 8683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.genBuffers(1, &colorBuf); 8703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.bindBuffer(GL_ARRAY_BUFFER, colorBuf); 8713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.bufferData(GL_ARRAY_BUFFER, colors.size() * sizeof(tcu::Vec4), &colors[0], GL_STATIC_DRAW); 8723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.vertexAttribPointer(colorLocation, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL); 8733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.vertexAttribDivisor(colorLocation, 1); 8743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.enableVertexAttribArray(colorLocation); 8753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_useIndices) 8773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.genBuffers(1, &indexBuf); 8793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuf); 8803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.bufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); 8813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.genBuffers(1, &drawIndirectBuf); 8843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.bindBuffer(GL_DRAW_INDIRECT_BUFFER, drawIndirectBuf); 8853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_useIndices) 8873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DrawElementsCommand command; 8893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry command.count = 6; 8903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry command.primCount = m_gridSide * m_gridSide; 8913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry command.firstIndex = 0; 8923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry command.baseVertex = 0; 8933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry command.reservedMustBeZero = 0; 8943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.bufferData(GL_DRAW_INDIRECT_BUFFER, sizeof(command), &command, GL_STATIC_DRAW); 8963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 8983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DrawArraysCommand command; 9003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry command.count = 6; 9013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry command.primCount = m_gridSide * m_gridSide; 9023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry command.first = 0; 9033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry command.reservedMustBeZero = 0; 9043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.bufferData(GL_DRAW_INDIRECT_BUFFER, sizeof(command), &command, GL_STATIC_DRAW); 9063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.clearColor(0, 0, 0, 1); 9093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.clear(GL_COLOR_BUFFER_BIT); 9103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.viewport(0, 0, dst.getWidth(), dst.getHeight()); 9123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.useProgram(programID); 9143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_useIndices) 9153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.drawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, DE_NULL); 9163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 9173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.drawArraysIndirect(GL_TRIANGLES, DE_NULL); 9183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.useProgram(0); 9193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(ctx.getError(), "", __FILE__, __LINE__); 9213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.deleteBuffers(1, &drawIndirectBuf); 9233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_useIndices) 9243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.deleteBuffers(1, &indexBuf); 9253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.deleteBuffers(1, &colorBuf); 9263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.deleteBuffers(1, &offsetBuf); 9273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.deleteBuffers(1, &positionBuf); 9283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.deleteVertexArrays(1, &vaoID); 9293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.deleteProgram(programID); 9303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.finish(); 9323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.readPixels(dst, 0, 0, dst.getWidth(), dst.getHeight()); 9333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(ctx.getError(), "", __FILE__, __LINE__); 9353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 9363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9373c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass InstancingGroup : public TestCaseGroup 9383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 9393c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 9403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry InstancingGroup (Context& context, const char* name, const char* descr); 9413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~InstancingGroup (void); 9423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 9443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 9453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9463c827367444ee418f129b2c238299f49d3264554Jarkko PoyryInstancingGroup::InstancingGroup (Context& context, const char* name, const char* descr) 9473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCaseGroup (context, name, descr) 9483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 9493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 9503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9513c827367444ee418f129b2c238299f49d3264554Jarkko PoyryInstancingGroup::~InstancingGroup (void) 9523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 9533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 9543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9553c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid InstancingGroup::init (void) 9563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 9573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int gridWidths[] = 9583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2, 9603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5, 9613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10, 9623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 32, 9633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 100, 9643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 9653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // drawArrays 9673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(gridWidths); ++ndx) 9683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string name = std::string("draw_arrays_indirect_grid_") + de::toString(gridWidths[ndx]) + "x" + de::toString(gridWidths[ndx]); 9703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string desc = std::string("DrawArraysIndirect, Grid size ") + de::toString(gridWidths[ndx]) + "x" + de::toString(gridWidths[ndx]); 9713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry this->addChild(new InstancedGridRenderTest(m_context, name.c_str(), desc.c_str(), gridWidths[ndx], false)); 9733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // drawElements 9763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(gridWidths); ++ndx) 9773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string name = std::string("draw_elements_indirect_grid_") + de::toString(gridWidths[ndx]) + "x" + de::toString(gridWidths[ndx]); 9793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string desc = std::string("DrawElementsIndirect, Grid size ") + de::toString(gridWidths[ndx]) + "x" + de::toString(gridWidths[ndx]); 9803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry this->addChild(new InstancedGridRenderTest(m_context, name.c_str(), desc.c_str(), gridWidths[ndx], true)); 9823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 9843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9853c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ComputeShaderGeneratedCase : public TestCase 9863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 9873c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 9883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enum DrawMethod 9893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DRAWMETHOD_DRAWARRAYS, 9913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DRAWMETHOD_DRAWELEMENTS, 9923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DRAWMETHOD_LAST 9933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 9943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ComputeShaderGeneratedCase (Context& context, const char* name, const char* desc, DrawMethod method, bool computeCmd, bool computeData, bool computeIndices, int gridSize, int drawCallCount); 9963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~ComputeShaderGeneratedCase (void); 9973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 9983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void deinit (void); 9993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IterateResult iterate (void); 10013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::string genComputeSource (bool computeCmd, bool computeData, bool computeIndices) const; 10023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10033c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 10043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void createDrawCommand (void); 10053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void createDrawData (void); 10063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void createDrawIndices (void); 10073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual void runComputeShader (void) = 0; 10093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void renderTo (tcu::Surface& image); 10103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10113c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected: 10123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 calcDrawBufferSize (void) const; 10133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 calcIndexBufferSize (void) const; 10143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const DrawMethod m_drawMethod; 10163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool m_computeCmd; 10173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool m_computeData; 10183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool m_computeIndices; 10193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int m_commandSize; 10203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int m_numDrawCmds; 10213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int m_gridSize; 10223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glw::GLuint m_cmdBufferID; 10243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glw::GLuint m_dataBufferID; 10253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glw::GLuint m_indexBufferID; 10263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10273c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 10283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ShaderProgram* m_shaderProgram; 10293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 10303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10313c827367444ee418f129b2c238299f49d3264554Jarkko PoyryComputeShaderGeneratedCase::ComputeShaderGeneratedCase (Context& context, const char* name, const char* desc, DrawMethod method, bool computeCmd, bool computeData, bool computeIndices, int gridSize, int drawCallCount) 10323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCase (context, name, desc) 10333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_drawMethod (method) 10343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_computeCmd (computeCmd) 10353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_computeData (computeData) 10363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_computeIndices (computeIndices) 10377a161d243743d8d12e12669d7464c360de1b5e97Jarkko Pöyry , m_commandSize ((method==DRAWMETHOD_DRAWARRAYS) ? ((int)sizeof(DrawArraysCommand)) : ((int)sizeof(DrawElementsCommand))) 10383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_numDrawCmds (drawCallCount) 10393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_gridSize (gridSize) 10403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_cmdBufferID (0) 10413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_dataBufferID (0) 10423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_indexBufferID (0) 10433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_shaderProgram (DE_NULL) 10443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 10453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int triangleCount = m_gridSize * m_gridSize * 2; 10463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(method < DRAWMETHOD_LAST); 10483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(!computeIndices || method == DRAWMETHOD_DRAWELEMENTS); 10493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(triangleCount % m_numDrawCmds == 0); 10503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_UNREF(triangleCount); 10513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 10523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10533c827367444ee418f129b2c238299f49d3264554Jarkko PoyryComputeShaderGeneratedCase::~ComputeShaderGeneratedCase (void) 10543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 10553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deinit(); 10563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 10573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10583c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ComputeShaderGeneratedCase::init (void) 10593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 10603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 10613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // generate basic shader 10633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_shaderProgram = new glu::ShaderProgram(m_context.getRenderContext(), glu::ProgramSources() << glu::VertexSource(s_colorVertexShaderSource) << glu::FragmentSource(s_colorFragmentShaderSource)); 10653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << *m_shaderProgram; 10663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!m_shaderProgram->isOk()) 10683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::TestError("Failed to compile shader."); 10693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // gen buffers 10713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genBuffers(1, &m_cmdBufferID); 10723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genBuffers(1, &m_dataBufferID); 10733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genBuffers(1, &m_indexBufferID); 10743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // check the SSBO buffers are of legal size 10763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1077271c2654cc44f23492888c7ef40c36c2fd810c77Jarkko Pöyry const deUint64 drawBufferElementSize = sizeof(tcu::Vec4); 1078271c2654cc44f23492888c7ef40c36c2fd810c77Jarkko Pöyry const deUint64 indexBufferElementSize = sizeof(deUint32); 1079271c2654cc44f23492888c7ef40c36c2fd810c77Jarkko Pöyry const int commandBufferSize = m_commandSize * m_numDrawCmds; 1080271c2654cc44f23492888c7ef40c36c2fd810c77Jarkko Pöyry deInt64 maxSSBOSize = 0; 10813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.getInteger64v(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &maxSSBOSize); 10833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1084271c2654cc44f23492888c7ef40c36c2fd810c77Jarkko Pöyry if (m_computeData && (deUint64)calcDrawBufferSize()*drawBufferElementSize > (deUint64)maxSSBOSize) 10853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("GL_MAX_SHADER_STORAGE_BLOCK_SIZE is too small for vertex attrib buffers"); 1086271c2654cc44f23492888c7ef40c36c2fd810c77Jarkko Pöyry if (m_computeIndices && (deUint64)calcIndexBufferSize()*indexBufferElementSize > (deUint64)maxSSBOSize) 10873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("GL_MAX_SHADER_STORAGE_BLOCK_SIZE is too small for index buffers"); 1088271c2654cc44f23492888c7ef40c36c2fd810c77Jarkko Pöyry if (m_computeCmd && (deUint64)commandBufferSize > (deUint64)maxSSBOSize) 10893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("GL_MAX_SHADER_STORAGE_BLOCK_SIZE is too small for command buffers"); 10903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 10913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 10923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10933c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ComputeShaderGeneratedCase::deinit (void) 10943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 10953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_cmdBufferID) 10963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 10973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_cmdBufferID); 10983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_cmdBufferID = 0; 10993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 11003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_dataBufferID) 11013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 11023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_dataBufferID); 11033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_dataBufferID = 0; 11043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 11053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_indexBufferID) 11063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 11073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_indexBufferID); 11083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_indexBufferID = 0; 11093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 11103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 11113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_shaderProgram) 11123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 11133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_shaderProgram; 11143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_shaderProgram = DE_NULL; 11153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 11163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 11173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 11183c827367444ee418f129b2c238299f49d3264554Jarkko PoyryComputeShaderGeneratedCase::IterateResult ComputeShaderGeneratedCase::iterate (void) 11193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 11203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int renderTargetWidth = de::min(1024, m_context.getRenderTarget().getWidth()); 11213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int renderTargetHeight = de::min(1024, m_context.getRenderTarget().getHeight()); 11223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 11233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface surface (renderTargetWidth, renderTargetHeight); 11243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 11253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Preparing to draw " << m_gridSize << " x " << m_gridSize << " grid." << tcu::TestLog::EndMessage; 11263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 11273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry try 11283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 11293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Gen command buffer 11303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!m_computeCmd) 11313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 11323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Uploading draw command buffer." << tcu::TestLog::EndMessage; 11333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry createDrawCommand(); 11343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 11353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 11363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Gen data buffer 11373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!m_computeData) 11383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 11393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Uploading draw data buffer." << tcu::TestLog::EndMessage; 11403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry createDrawData(); 11413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 11423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 11433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Gen index buffer 11443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!m_computeIndices && m_drawMethod == DRAWMETHOD_DRAWELEMENTS) 11453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 11463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Uploading draw index buffer." << tcu::TestLog::EndMessage; 11473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry createDrawIndices(); 11483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 11493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 11503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Run compute shader 11513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 11523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() 11533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << tcu::TestLog::Message << "Filling following buffers using compute shader:\n" 11543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << ((m_computeCmd) ? ("\tcommand buffer\n") : ("")) 11553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << ((m_computeData) ? ("\tdata buffer\n") : ("")) 11563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << ((m_computeIndices) ? ("\tindex buffer\n") : ("")) 11573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << tcu::TestLog::EndMessage; 11583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry runComputeShader(); 11593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 11603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 11613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Ensure data is written to the buffers before we try to read it 11623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 11633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::GLuint barriers = ((m_computeCmd) ? (GL_COMMAND_BARRIER_BIT) : (0)) | 11643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ((m_computeData) ? (GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT) : (0)) | 11653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ((m_computeIndices) ? (GL_ELEMENT_ARRAY_BARRIER_BIT) : (0)); 11663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 11673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Memory barrier. Barriers = " << glu::getMemoryBarrierFlagsStr(barriers) << tcu::TestLog::EndMessage; 11683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.memoryBarrier(barriers); 11693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 11703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 11713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Draw from buffers 11723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 11733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Drawing from buffers with " << m_numDrawCmds << " draw call(s)." << tcu::TestLog::EndMessage; 11743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry renderTo(surface); 11753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 11763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry catch (glu::OutOfMemoryError&) 11773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 11783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Got GL_OUT_OF_MEMORY." << tcu::TestLog::EndMessage; 11793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Got GL_OUT_OF_MEMORY"); 11808d83d91e1b85fa69359aed7ea15358f770f9eb82Jarkko Pöyry m_testCtx.setTerminateAfter(true); // Do not rely on implementation to be able to recover from OOM 11813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return STOP; 11823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 11833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 11843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 11853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // verify image 11863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \note the green/yellow pattern is only for clarity. The test will only verify that all grid cells were drawn by looking for anything non-green/yellow. 11873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (verifyImageYellowGreen(surface, m_testCtx.getLog())) 11883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 11893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 11903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Result image invalid"); 11913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return STOP; 11923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 11933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 11943c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystd::string ComputeShaderGeneratedCase::genComputeSource (bool computeCmd, bool computeData, bool computeIndices) const 11953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 11963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int cmdLayoutBinding = 0; 11973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int dataLayoutBinding = (computeCmd) ? (1) : (0); 11983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int indexLayoutBinding = (computeCmd && computeData) ? (2) : (computeCmd || computeData) ? (1) : (0); 11993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 12003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::ostringstream buf; 12013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 12023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << "#version 310 es\n\n" 12033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << "precision highp int;\n" 12043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << "precision highp float;\n\n"; 12053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 12063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (computeCmd && m_drawMethod==DRAWMETHOD_DRAWARRAYS) 12073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << "struct DrawArraysIndirectCommand {\n" 12083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " uint count;\n" 12093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " uint primCount;\n" 12103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " uint first;\n" 12113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " uint reservedMustBeZero;\n" 12123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << "};\n\n"; 12133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (computeCmd && m_drawMethod==DRAWMETHOD_DRAWELEMENTS) 12143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << "struct DrawElementsIndirectCommand {\n" 12153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " uint count;\n" 12163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " uint primCount;\n" 12173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " uint firstIndex;\n" 12183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " int baseVertex;\n" 12193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " uint reservedMustBeZero;\n" 12203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << "};\n\n"; 12213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 12223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << "layout(local_size_x = 1, local_size_y = 1) in;\n" 12233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << "layout(std430) buffer;\n\n"; 12243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 12253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (computeCmd) 12263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << "layout(binding = " << cmdLayoutBinding << ") writeonly buffer CommandBuffer {\n" 12273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " " << ((m_drawMethod==DRAWMETHOD_DRAWARRAYS) ? ("DrawArraysIndirectCommand") : ("DrawElementsIndirectCommand")) << " commands[];\n" 12283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << "};\n"; 12293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (computeData) 12303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << "layout(binding = " << dataLayoutBinding << ") writeonly buffer DataBuffer {\n" 12313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " vec4 attribs[];\n" 12323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << "};\n"; 12333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (computeIndices) 12343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << "layout(binding = " << indexLayoutBinding << ") writeonly buffer IndexBuffer {\n" 12353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " uint indices[];\n" 12363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << "};\n"; 12373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 12383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << "\n" 12393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << "void main() {\n" 12403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " const uint gridSize = " << m_gridSize << "u;\n" 12413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " const uint triangleCount = gridSize * gridSize * 2u;\n" 12423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << "\n"; 12433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 12443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (computeCmd) 12453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 12463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << " // command\n" 12473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " if (gl_GlobalInvocationID.x < " << m_numDrawCmds << "u && gl_GlobalInvocationID.y == 0u && gl_GlobalInvocationID.z == 0u) {\n" 12483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " const uint numDrawCallTris = triangleCount / " << m_numDrawCmds << "u;\n" 12493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " uint firstTri = gl_GlobalInvocationID.x * numDrawCallTris;\n\n" 12503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " commands[gl_GlobalInvocationID.x].count = numDrawCallTris*3u;\n" 12513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " commands[gl_GlobalInvocationID.x].primCount = 1u;\n"; 12523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 12533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_drawMethod==DRAWMETHOD_DRAWARRAYS) 12543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 12553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << " commands[gl_GlobalInvocationID.x].first = firstTri*3u;\n"; 12563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 12573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (m_drawMethod==DRAWMETHOD_DRAWELEMENTS) 12583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 12593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << " commands[gl_GlobalInvocationID.x].firstIndex = firstTri*3u;\n"; 12603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << " commands[gl_GlobalInvocationID.x].baseVertex = 0;\n"; 12613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 12623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 12633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << " commands[gl_GlobalInvocationID.x].reservedMustBeZero = 0u;\n" 12643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " }\n" 12653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << "\n"; 12663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 12673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 12683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (computeData) 12693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 12703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << " // vertex attribs\n" 12713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " const vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n" 12723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " const vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"; 12733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 12743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_drawMethod == DRAWMETHOD_DRAWARRAYS) 12753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 12763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << " if (gl_GlobalInvocationID.x < gridSize && gl_GlobalInvocationID.y < gridSize && gl_GlobalInvocationID.z == 0u) {\n" 12773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " uint y = gl_GlobalInvocationID.x;\n" 12783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " uint x = gl_GlobalInvocationID.y;\n" 1279a7c3d7520284ac140233d3fb16644e71fa65b359Anders Frostad Pedersen << " float posX = (float(x) / float(gridSize)) * 2.0 - 1.0;\n" 1280a7c3d7520284ac140233d3fb16644e71fa65b359Anders Frostad Pedersen << " float posXp1 = (float(x+1u) / float(gridSize)) * 2.0 - 1.0;\n" 1281a7c3d7520284ac140233d3fb16644e71fa65b359Anders Frostad Pedersen << " float posY = (float(y) / float(gridSize)) * 2.0 - 1.0;\n" 1282a7c3d7520284ac140233d3fb16644e71fa65b359Anders Frostad Pedersen << " float posYp1 = (float(y+1u) / float(gridSize)) * 2.0 - 1.0;\n" 12833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " vec4 color = ((x + y)%2u != 0u) ? (yellow) : (green);\n" 12843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << "\n" 1285a7c3d7520284ac140233d3fb16644e71fa65b359Anders Frostad Pedersen << " attribs[((y * gridSize + x) * 6u + 0u) * 2u + 0u] = vec4(posX, posY, 0.0, 1.0);\n" 1286a7c3d7520284ac140233d3fb16644e71fa65b359Anders Frostad Pedersen << " attribs[((y * gridSize + x) * 6u + 1u) * 2u + 0u] = vec4(posXp1, posY, 0.0, 1.0);\n" 1287a7c3d7520284ac140233d3fb16644e71fa65b359Anders Frostad Pedersen << " attribs[((y * gridSize + x) * 6u + 2u) * 2u + 0u] = vec4(posXp1, posYp1, 0.0, 1.0);\n" 1288a7c3d7520284ac140233d3fb16644e71fa65b359Anders Frostad Pedersen << " attribs[((y * gridSize + x) * 6u + 3u) * 2u + 0u] = vec4(posX, posY, 0.0, 1.0);\n" 1289a7c3d7520284ac140233d3fb16644e71fa65b359Anders Frostad Pedersen << " attribs[((y * gridSize + x) * 6u + 4u) * 2u + 0u] = vec4(posXp1, posYp1, 0.0, 1.0);\n" 1290a7c3d7520284ac140233d3fb16644e71fa65b359Anders Frostad Pedersen << " attribs[((y * gridSize + x) * 6u + 5u) * 2u + 0u] = vec4(posX, posYp1, 0.0, 1.0);\n" 12913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << "\n" 12923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " attribs[((y * gridSize + x) * 6u + 0u) * 2u + 1u] = color;\n" 12933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " attribs[((y * gridSize + x) * 6u + 1u) * 2u + 1u] = color;\n" 12943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " attribs[((y * gridSize + x) * 6u + 2u) * 2u + 1u] = color;\n" 12953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " attribs[((y * gridSize + x) * 6u + 3u) * 2u + 1u] = color;\n" 12963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " attribs[((y * gridSize + x) * 6u + 4u) * 2u + 1u] = color;\n" 12973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " attribs[((y * gridSize + x) * 6u + 5u) * 2u + 1u] = color;\n" 12983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " }\n"; 12993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 13003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (m_drawMethod == DRAWMETHOD_DRAWELEMENTS) 13013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 13023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << " if (gl_GlobalInvocationID.x < gridSize+1u && gl_GlobalInvocationID.y < gridSize+1u && gl_GlobalInvocationID.z == 0u) {\n" 13033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " uint y = gl_GlobalInvocationID.x;\n" 13043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " uint x = gl_GlobalInvocationID.y;\n" 13053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " float posX = (float(x) / float(gridSize)) * 2.0 - 1.0;\n" 13063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " float posY = (float(y) / float(gridSize)) * 2.0 - 1.0;\n" 13073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << "\n" 13083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " attribs[(y * (gridSize+1u) + x) * 4u + 0u] = vec4(posX, posY, 0.0, 1.0);\n" 13093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " attribs[(y * (gridSize+1u) + x) * 4u + 1u] = green;\n" 13103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " attribs[(y * (gridSize+1u) + x) * 4u + 2u] = vec4(posX, posY, 0.0, 1.0);\n" 13113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " attribs[(y * (gridSize+1u) + x) * 4u + 3u] = yellow;\n" 13123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " }\n"; 13133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 13143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 13153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << "\n"; 13163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 13173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 13183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (computeIndices) 13193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 13203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << " // indices\n" 13213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " if (gl_GlobalInvocationID.x < gridSize && gl_GlobalInvocationID.y < gridSize && gl_GlobalInvocationID.z == 0u) {\n" 13223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " uint y = gl_GlobalInvocationID.x;\n" 13233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " uint x = gl_GlobalInvocationID.y;\n" 13243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " uint color = ((x + y)%2u);\n" 13253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << "\n" 13263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " indices[(y * gridSize + x) * 6u + 0u] = ((y+0u) * (gridSize+1u) + (x+0u)) * 2u + color;\n" 13273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " indices[(y * gridSize + x) * 6u + 1u] = ((y+1u) * (gridSize+1u) + (x+0u)) * 2u + color;\n" 13283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " indices[(y * gridSize + x) * 6u + 2u] = ((y+1u) * (gridSize+1u) + (x+1u)) * 2u + color;\n" 13293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " indices[(y * gridSize + x) * 6u + 3u] = ((y+0u) * (gridSize+1u) + (x+0u)) * 2u + color;\n" 13303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " indices[(y * gridSize + x) * 6u + 4u] = ((y+1u) * (gridSize+1u) + (x+1u)) * 2u + color;\n" 13313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " indices[(y * gridSize + x) * 6u + 5u] = ((y+0u) * (gridSize+1u) + (x+1u)) * 2u + color;\n" 13323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " }\n" 13333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << "\n"; 13343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 13353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 13363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buf << "}\n"; 13373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 13383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return buf.str(); 13393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 13403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 13413c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ComputeShaderGeneratedCase::createDrawCommand (void) 13423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 13433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 13443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int triangleCount = m_gridSize * m_gridSize * 2; 13453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 numDrawCallTris = triangleCount / m_numDrawCmds; 13463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 13473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_drawMethod == DRAWMETHOD_DRAWARRAYS) 13483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 13493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<DrawArraysCommand> cmds; 13503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 13513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < m_numDrawCmds; ++ndx) 13523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 13533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 firstTri = ndx * numDrawCallTris; 13543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DrawArraysCommand data; 13553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 13563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry data.count = numDrawCallTris*3; 13573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry data.primCount = 1; 13583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry data.first = firstTri*3; 13593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry data.reservedMustBeZero = 0; 13603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 13613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry cmds.push_back(data); 13623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 13633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 13643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT((int)(sizeof(DrawArraysCommand)*cmds.size()) == m_numDrawCmds * m_commandSize); 13653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 13663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_DRAW_INDIRECT_BUFFER, m_cmdBufferID); 13673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_DRAW_INDIRECT_BUFFER, (glw::GLsizeiptr)(sizeof(DrawArraysCommand)*cmds.size()), &cmds[0], GL_STATIC_DRAW); 13683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 13693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (m_drawMethod == DRAWMETHOD_DRAWELEMENTS) 13703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 13713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<DrawElementsCommand> cmds; 13723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 13733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < m_numDrawCmds; ++ndx) 13743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 13753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 firstTri = ndx * numDrawCallTris; 13763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DrawElementsCommand data; 13773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 13783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry data.count = numDrawCallTris*3; 13793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry data.primCount = 1; 13803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry data.firstIndex = firstTri*3; 13813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry data.baseVertex = 0; 13823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry data.reservedMustBeZero = 0; 13833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 13843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry cmds.push_back(data); 13853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 13863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 13873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT((int)(sizeof(DrawElementsCommand)*cmds.size()) == m_numDrawCmds * m_commandSize); 13883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 13893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_DRAW_INDIRECT_BUFFER, m_cmdBufferID); 13903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_DRAW_INDIRECT_BUFFER, (glw::GLsizeiptr)(sizeof(DrawElementsCommand)*cmds.size()), &cmds[0], GL_STATIC_DRAW); 13913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 13923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 13933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(false); 13943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 13953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "create draw command", __FILE__, __LINE__); 13963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 13973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 13983c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ComputeShaderGeneratedCase::createDrawData (void) 13993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 14003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 yellow (1.0f, 1.0f, 0.0f, 1.0f); 14013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 green (0.0f, 1.0f, 0.0f, 1.0f); 14023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 14033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 14043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_drawMethod == DRAWMETHOD_DRAWARRAYS) 14053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 14063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Store elements in the order they are drawn. Interleave color. 14073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<tcu::Vec4> buffer(m_gridSize*m_gridSize*6*2); 14083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 14093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(buffer.size() == calcDrawBufferSize()); 14103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 14113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < m_gridSize; ++y) 14123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < m_gridSize; ++x) 14133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1414653ad0e8a4209754304cbd5b5ceb4fdc7b29c01aPyry Haulos const float posX = ((float)x / (float)m_gridSize) * 2.0f - 1.0f; 1415653ad0e8a4209754304cbd5b5ceb4fdc7b29c01aPyry Haulos const float posY = ((float)y / (float)m_gridSize) * 2.0f - 1.0f; 14163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float cellSize = 2.0f / (float)m_gridSize; 14173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4& color = ((x + y)%2) ? (yellow) : (green); 14183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 14193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buffer[((y * m_gridSize + x) * 6 + 0) * 2 + 0] = tcu::Vec4(posX, posY, 0.0f, 1.0f); 14203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buffer[((y * m_gridSize + x) * 6 + 1) * 2 + 0] = tcu::Vec4(posX + cellSize, posY, 0.0f, 1.0f); 14213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buffer[((y * m_gridSize + x) * 6 + 2) * 2 + 0] = tcu::Vec4(posX + cellSize, posY + cellSize, 0.0f, 1.0f); 14223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buffer[((y * m_gridSize + x) * 6 + 3) * 2 + 0] = tcu::Vec4(posX, posY, 0.0f, 1.0f); 14233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buffer[((y * m_gridSize + x) * 6 + 4) * 2 + 0] = tcu::Vec4(posX + cellSize, posY + cellSize, 0.0f, 1.0f); 14243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buffer[((y * m_gridSize + x) * 6 + 5) * 2 + 0] = tcu::Vec4(posX, posY + cellSize, 0.0f, 1.0f); 14253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 14263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buffer[((y * m_gridSize + x) * 6 + 0) * 2 + 1] = color; 14273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buffer[((y * m_gridSize + x) * 6 + 1) * 2 + 1] = color; 14283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buffer[((y * m_gridSize + x) * 6 + 2) * 2 + 1] = color; 14293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buffer[((y * m_gridSize + x) * 6 + 3) * 2 + 1] = color; 14303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buffer[((y * m_gridSize + x) * 6 + 4) * 2 + 1] = color; 14313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buffer[((y * m_gridSize + x) * 6 + 5) * 2 + 1] = color; 14323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 14333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 14343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_ARRAY_BUFFER, m_dataBufferID); 14353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_ARRAY_BUFFER, (int)(buffer.size() * sizeof(tcu::Vec4)), buffer[0].getPtr(), GL_STATIC_DRAW); 14363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 14373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (m_drawMethod == DRAWMETHOD_DRAWELEMENTS) 14383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 14393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Elements are indexed by index buffer. Interleave color. Two vertices per position since 2 colors 14403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 14413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<tcu::Vec4> buffer((m_gridSize+1)*(m_gridSize+1)*4); 14423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 14433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(buffer.size() == calcDrawBufferSize()); 14443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 14453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < m_gridSize+1; ++y) 14463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < m_gridSize+1; ++x) 14473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1448653ad0e8a4209754304cbd5b5ceb4fdc7b29c01aPyry Haulos const float posX = ((float)x / (float)m_gridSize) * 2.0f - 1.0f; 1449653ad0e8a4209754304cbd5b5ceb4fdc7b29c01aPyry Haulos const float posY = ((float)y / (float)m_gridSize) * 2.0f - 1.0f; 14503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 14513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buffer[(y * (m_gridSize+1) + x) * 4 + 0] = tcu::Vec4(posX, posY, 0.0f, 1.0f); 14523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buffer[(y * (m_gridSize+1) + x) * 4 + 1] = green; 14533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buffer[(y * (m_gridSize+1) + x) * 4 + 2] = tcu::Vec4(posX, posY, 0.0f, 1.0f); 14543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buffer[(y * (m_gridSize+1) + x) * 4 + 3] = yellow; 14553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 14563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 14573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_ARRAY_BUFFER, m_dataBufferID); 14583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_ARRAY_BUFFER, (int)(buffer.size() * sizeof(tcu::Vec4)), buffer[0].getPtr(), GL_STATIC_DRAW); 14593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 14603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 14613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(false); 14623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 14633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "", __FILE__, __LINE__); 14643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 14653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 14663c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ComputeShaderGeneratedCase::createDrawIndices (void) 14673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 14683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(m_drawMethod == DRAWMETHOD_DRAWELEMENTS); 14693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 14703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 14713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<deUint32> buffer (m_gridSize*m_gridSize*6); 14723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 14733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(buffer.size() == calcIndexBufferSize()); 14743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 14753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < m_gridSize; ++y) 14763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < m_gridSize; ++x) 14773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 14783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int color = ((x + y)%2); 14793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 14803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buffer[(y * m_gridSize + x) * 6 + 0] = ((y+0) * (m_gridSize+1) + (x+0)) * 2 + color; 14813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buffer[(y * m_gridSize + x) * 6 + 1] = ((y+1) * (m_gridSize+1) + (x+0)) * 2 + color; 14823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buffer[(y * m_gridSize + x) * 6 + 2] = ((y+1) * (m_gridSize+1) + (x+1)) * 2 + color; 14833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buffer[(y * m_gridSize + x) * 6 + 3] = ((y+0) * (m_gridSize+1) + (x+0)) * 2 + color; 14843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buffer[(y * m_gridSize + x) * 6 + 4] = ((y+1) * (m_gridSize+1) + (x+1)) * 2 + color; 14853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry buffer[(y * m_gridSize + x) * 6 + 5] = ((y+0) * (m_gridSize+1) + (x+1)) * 2 + color; 14863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 14873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 14883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBufferID); 14893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, (int)(buffer.size() * sizeof(deUint32)), &buffer[0], GL_STATIC_DRAW); 14903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "", __FILE__, __LINE__); 14913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 14923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 14933c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ComputeShaderGeneratedCase::renderTo (tcu::Surface& dst) 14943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 14953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 14963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deInt32 positionLoc = gl.getAttribLocation(m_shaderProgram->getProgram(), "a_position"); 14973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deInt32 colorLoc = gl.getAttribLocation(m_shaderProgram->getProgram(), "a_color"); 14983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 vaoID = 0; 14993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 15003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genVertexArrays(1, &vaoID); 15013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindVertexArray(vaoID); 15023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 15033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Setup buffers 15043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 15053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_ARRAY_BUFFER, m_dataBufferID); 15067a161d243743d8d12e12669d7464c360de1b5e97Jarkko Pöyry gl.vertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, 8 * (int)sizeof(float), DE_NULL); 15077a161d243743d8d12e12669d7464c360de1b5e97Jarkko Pöyry gl.vertexAttribPointer(colorLoc, 4, GL_FLOAT, GL_FALSE, 8 * (int)sizeof(float), ((const deUint8*)DE_NULL) + 4*sizeof(float)); 15083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.enableVertexAttribArray(positionLoc); 15093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.enableVertexAttribArray(colorLoc); 15103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 15113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(positionLoc != -1); 15123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(colorLoc != -1); 15133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 15143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_drawMethod == DRAWMETHOD_DRAWELEMENTS) 15153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBufferID); 15163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 15173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_DRAW_INDIRECT_BUFFER, m_cmdBufferID); 15183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 15193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // draw 15203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 15213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.clearColor(0, 0, 0, 1); 15223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.clear(GL_COLOR_BUFFER_BIT); 15233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.viewport(0, 0, dst.getWidth(), dst.getHeight()); 15243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 15253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.useProgram(m_shaderProgram->getProgram()); 15263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int drawCmdNdx = 0; drawCmdNdx < m_numDrawCmds; ++drawCmdNdx) 15273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 15283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const void* offset = ((deUint8*)DE_NULL) + drawCmdNdx*m_commandSize; 15293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 15303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_drawMethod == DRAWMETHOD_DRAWELEMENTS) 15313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.drawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, offset); 15323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (m_drawMethod == DRAWMETHOD_DRAWARRAYS) 15333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.drawArraysIndirect(GL_TRIANGLES, offset); 15343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 15353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(DE_FALSE); 15363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 15373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.useProgram(0); 15383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 15393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // free 15403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 15413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.deleteVertexArrays(1, &vaoID); 154290563f0686a0925e19cc52251dd28d6ef81e9abaJarkko Pöyry glu::checkError(gl.getError(), "", __FILE__, __LINE__); 15433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 15443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.finish(); 154590563f0686a0925e19cc52251dd28d6ef81e9abaJarkko Pöyry glu::checkError(gl.getError(), "", __FILE__, __LINE__); 15463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 154790563f0686a0925e19cc52251dd28d6ef81e9abaJarkko Pöyry glu::readPixels(m_context.getRenderContext(), 0, 0, dst.getAccess()); 15483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "", __FILE__, __LINE__); 15493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 15503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 15513c827367444ee418f129b2c238299f49d3264554Jarkko PoyrydeUint32 ComputeShaderGeneratedCase::calcDrawBufferSize (void) const 15523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 15533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // returns size in "vec4"s 15543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_drawMethod == DRAWMETHOD_DRAWARRAYS) 15553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return m_gridSize*m_gridSize*6*2; 15563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (m_drawMethod == DRAWMETHOD_DRAWELEMENTS) 15573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return (m_gridSize+1)*(m_gridSize+1)*4; 15583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 15593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(DE_FALSE); 15603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 15613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return 0; 15623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 15633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 15643c827367444ee418f129b2c238299f49d3264554Jarkko PoyrydeUint32 ComputeShaderGeneratedCase::calcIndexBufferSize (void) const 15653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 15663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_drawMethod == DRAWMETHOD_DRAWELEMENTS) 15673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return m_gridSize*m_gridSize*6; 15683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 15693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return 0; 15703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 15713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 15723c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ComputeShaderGeneratedCombinedCase : public ComputeShaderGeneratedCase 15733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 15743c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 15753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ComputeShaderGeneratedCombinedCase (Context& context, const char* name, const char* desc, DrawMethod method, bool computeCmd, bool computeData, bool computeIndices, int gridSize, int numDrawCalls); 15763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~ComputeShaderGeneratedCombinedCase (void); 15773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 15783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 15793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void deinit (void); 15803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 15813c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 15823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void runComputeShader (void); 15833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 15843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ShaderProgram* m_computeProgram; 15853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 15863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 15873c827367444ee418f129b2c238299f49d3264554Jarkko PoyryComputeShaderGeneratedCombinedCase::ComputeShaderGeneratedCombinedCase (Context& context, const char* name, const char* desc, DrawMethod method, bool computeCmd, bool computeData, bool computeIndices, int gridSize, int numDrawCalls) 15883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : ComputeShaderGeneratedCase(context, name, desc, method, computeCmd, computeData, computeIndices, gridSize, numDrawCalls) 15893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_computeProgram (DE_NULL) 15903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 15913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 15923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 15933c827367444ee418f129b2c238299f49d3264554Jarkko PoyryComputeShaderGeneratedCombinedCase::~ComputeShaderGeneratedCombinedCase (void) 15943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 15953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deinit(); 15963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 15973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 15983c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ComputeShaderGeneratedCombinedCase::init (void) 15993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 16003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // generate compute shader 16013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_computeProgram = new glu::ShaderProgram(m_context.getRenderContext(), glu::ProgramSources() << glu::ComputeSource(genComputeSource(m_computeCmd, m_computeData, m_computeIndices))); 16033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << *m_computeProgram; 16043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!m_computeProgram->isOk()) 16063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::TestError("Failed to compile compute shader."); 16073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // init parent 16093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ComputeShaderGeneratedCase::init(); 16103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 16113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16123c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ComputeShaderGeneratedCombinedCase::deinit (void) 16133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 16143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // deinit parent 16153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ComputeShaderGeneratedCase::deinit(); 16163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_computeProgram) 16183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 16193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_computeProgram; 16203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_computeProgram = DE_NULL; 16213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 16223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 16233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16243c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ComputeShaderGeneratedCombinedCase::runComputeShader (void) 16253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 16263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 16273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool indexed = (m_drawMethod == DRAWMETHOD_DRAWELEMENTS); 16283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::IVec3 nullSize (0, 0, 0); 16293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::IVec3 commandDispatchSize = (m_computeCmd) ? (tcu::IVec3(m_numDrawCmds, 1, 1)) : (nullSize); 16303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::IVec3 drawElementsDataBufferDispatchSize = (m_computeData) ? (tcu::IVec3(m_gridSize+1, m_gridSize+1, 1)) : (nullSize); 16313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::IVec3 drawArraysDataBufferDispatchSize = (m_computeData) ? (tcu::IVec3(m_gridSize, m_gridSize, 1)) : (nullSize); 16323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::IVec3 indexBufferDispatchSize = (m_computeIndices && indexed) ? (tcu::IVec3(m_gridSize, m_gridSize, 1)) : (nullSize); 16333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::IVec3 dataBufferDispatchSize = (m_drawMethod == DRAWMETHOD_DRAWELEMENTS) ? (drawElementsDataBufferDispatchSize) : (drawArraysDataBufferDispatchSize); 16353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::IVec3 dispatchSize = tcu::max(tcu::max(commandDispatchSize, dataBufferDispatchSize), indexBufferDispatchSize); 16363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.useProgram(m_computeProgram->getProgram()); 16383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "use compute shader", __FILE__, __LINE__); 16393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // setup buffers 16413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_computeCmd) 16433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 16443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int bindingPoint = 0; 16453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int bufferSize = m_commandSize * m_numDrawCmds; 16463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Binding command buffer to binding point " << bindingPoint << tcu::TestLog::EndMessage; 16483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBufferBase(GL_SHADER_STORAGE_BUFFER, bindingPoint, m_cmdBufferID); 16493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Allocating memory for command buffer, size " << sizeToString(bufferSize) << "." << tcu::TestLog::EndMessage; 16513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_SHADER_STORAGE_BUFFER, bufferSize, DE_NULL, GL_DYNAMIC_DRAW); 16523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 16533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_computeData) 16553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 16563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int bindingPoint = (m_computeCmd) ? (1) : (0); 16573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int bufferSize = (int)(calcDrawBufferSize()*sizeof(tcu::Vec4)); 16583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Binding data buffer to binding point " << bindingPoint << tcu::TestLog::EndMessage; 16603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBufferBase(GL_SHADER_STORAGE_BUFFER, bindingPoint, m_dataBufferID); 16613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Allocating memory for data buffer, size " << sizeToString(bufferSize) << "." << tcu::TestLog::EndMessage; 16633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_SHADER_STORAGE_BUFFER, bufferSize, DE_NULL, GL_DYNAMIC_DRAW); 16643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 16653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_computeIndices) 16673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 16683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int bindingPoint = (m_computeCmd && m_computeData) ? (2) : (m_computeCmd || m_computeData) ? (1) : (0); 16693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int bufferSize = (int)(calcIndexBufferSize()*sizeof(deUint32)); 16703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Binding index buffer to binding point " << bindingPoint << tcu::TestLog::EndMessage; 16723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBufferBase(GL_SHADER_STORAGE_BUFFER, bindingPoint, m_indexBufferID); 16733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Allocating memory for index buffer, size " << sizeToString(bufferSize) << "." << tcu::TestLog::EndMessage; 16753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_SHADER_STORAGE_BUFFER, bufferSize, DE_NULL, GL_DYNAMIC_DRAW); 16763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 16773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "setup buffers", __FILE__, __LINE__); 16793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // calculate 16813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Dispatching compute, size = " << dispatchSize << tcu::TestLog::EndMessage; 16833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.dispatchCompute(dispatchSize.x(), dispatchSize.y(), dispatchSize.z()); 16843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "calculate", __FILE__, __LINE__); 16863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 16873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16883c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ComputeShaderGeneratedSeparateCase : public ComputeShaderGeneratedCase 16893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 16903c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 16913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ComputeShaderGeneratedSeparateCase (Context& context, const char* name, const char* desc, DrawMethod method, bool computeCmd, bool computeData, bool computeIndices, int gridSize, int numDrawCalls); 16923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~ComputeShaderGeneratedSeparateCase (void); 16933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 16953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void deinit (void); 16963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16973c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 16983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::string genCmdComputeSource (void); 16993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::string genDataComputeSource (void); 17003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::string genIndexComputeSource (void); 17013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void runComputeShader (void); 17023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 17033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ShaderProgram* m_computeCmdProgram; 17043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ShaderProgram* m_computeDataProgram; 17053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ShaderProgram* m_computeIndicesProgram; 17063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 17073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 17083c827367444ee418f129b2c238299f49d3264554Jarkko PoyryComputeShaderGeneratedSeparateCase::ComputeShaderGeneratedSeparateCase (Context& context, const char* name, const char* desc, DrawMethod method, bool computeCmd, bool computeData, bool computeIndices, int gridSize, int numDrawCalls) 17093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : ComputeShaderGeneratedCase (context, name, desc, method, computeCmd, computeData, computeIndices, gridSize, numDrawCalls) 17103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_computeCmdProgram (DE_NULL) 17113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_computeDataProgram (DE_NULL) 17123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_computeIndicesProgram (DE_NULL) 17133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 17143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 17153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 17163c827367444ee418f129b2c238299f49d3264554Jarkko PoyryComputeShaderGeneratedSeparateCase::~ComputeShaderGeneratedSeparateCase (void) 17173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 17183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deinit(); 17193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 17203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 17213c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ComputeShaderGeneratedSeparateCase::init (void) 17223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 17233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // generate cmd compute shader 17243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 17253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_computeCmd) 17263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 17273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_computeCmdProgram = new glu::ShaderProgram(m_context.getRenderContext(), glu::ProgramSources() << glu::ComputeSource(genCmdComputeSource())); 17283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << *m_computeCmdProgram; 17293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 17303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!m_computeCmdProgram->isOk()) 17313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::TestError("Failed to compile command compute shader."); 17323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 17333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 17343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // generate data compute shader 17353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 17363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_computeData) 17373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 17383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_computeDataProgram = new glu::ShaderProgram(m_context.getRenderContext(), glu::ProgramSources() << glu::ComputeSource(genDataComputeSource())); 17393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << *m_computeDataProgram; 17403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 17413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!m_computeDataProgram->isOk()) 17423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::TestError("Failed to compile data compute shader."); 17433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 17443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 17453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // generate index compute shader 17463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 17473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_computeIndices) 17483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 17493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_computeIndicesProgram = new glu::ShaderProgram(m_context.getRenderContext(), glu::ProgramSources() << glu::ComputeSource(genIndexComputeSource())); 17503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << *m_computeIndicesProgram; 17513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 17523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!m_computeIndicesProgram->isOk()) 17533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::TestError("Failed to compile data compute shader."); 17543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 17553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 17563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // init parent 17573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ComputeShaderGeneratedCase::init(); 17583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 17593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 17603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ComputeShaderGeneratedSeparateCase::deinit (void) 17613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 17623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // deinit parent 17633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ComputeShaderGeneratedCase::deinit(); 17643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 17653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_computeCmdProgram) 17663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 17673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_computeCmdProgram; 17683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_computeCmdProgram = DE_NULL; 17693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 17703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_computeDataProgram) 17713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 17723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_computeDataProgram; 17733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_computeDataProgram = DE_NULL; 17743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 17753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_computeIndicesProgram) 17763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 17773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_computeIndicesProgram; 17783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_computeIndicesProgram = DE_NULL; 17793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 17803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 17813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 17823c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystd::string ComputeShaderGeneratedSeparateCase::genCmdComputeSource (void) 17833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 17843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return ComputeShaderGeneratedCase::genComputeSource(true, false, false); 17853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 17863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 17873c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystd::string ComputeShaderGeneratedSeparateCase::genDataComputeSource (void) 17883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 17893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return ComputeShaderGeneratedCase::genComputeSource(false, true, false); 17903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 17913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 17923c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystd::string ComputeShaderGeneratedSeparateCase::genIndexComputeSource (void) 17933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 17943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return ComputeShaderGeneratedCase::genComputeSource(false, false, true); 17953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 17963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 17973c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ComputeShaderGeneratedSeparateCase::runComputeShader (void) 17983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 17993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 18003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Compute command 18023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_computeCmd) 18043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 18053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int bindingPoint = 0; 18063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::IVec3 commandDispatchSize (m_numDrawCmds, 1, 1); 18073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int bufferSize = m_commandSize * m_numDrawCmds; 18083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.useProgram(m_computeCmdProgram->getProgram()); 18103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // setup buffers 18123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Binding command buffer to binding point " << bindingPoint << tcu::TestLog::EndMessage; 18143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBufferBase(GL_SHADER_STORAGE_BUFFER, bindingPoint, m_cmdBufferID); 18153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Allocating memory for command buffer, size " << sizeToString(bufferSize) << "." << tcu::TestLog::EndMessage; 18173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_SHADER_STORAGE_BUFFER, bufferSize, DE_NULL, GL_DYNAMIC_DRAW); 18183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // calculate 18203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Dispatching command compute, size = " << commandDispatchSize << tcu::TestLog::EndMessage; 18223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.dispatchCompute(commandDispatchSize.x(), commandDispatchSize.y(), commandDispatchSize.z()); 18233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "calculate cmd", __FILE__, __LINE__); 18253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 18263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Compute data 18283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_computeData) 18303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 18313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int bindingPoint = 0; 18323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::IVec3 drawElementsDataBufferDispatchSize (m_gridSize+1, m_gridSize+1, 1); 18333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::IVec3 drawArraysDataBufferDispatchSize (m_gridSize, m_gridSize, 1); 18343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::IVec3 dataBufferDispatchSize = (m_drawMethod == DRAWMETHOD_DRAWELEMENTS) ? (drawElementsDataBufferDispatchSize) : (drawArraysDataBufferDispatchSize); 18353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int bufferSize = (int)(calcDrawBufferSize()*sizeof(tcu::Vec4)); 18363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.useProgram(m_computeDataProgram->getProgram()); 18383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // setup buffers 18403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Binding data buffer to binding point " << bindingPoint << tcu::TestLog::EndMessage; 18423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBufferBase(GL_SHADER_STORAGE_BUFFER, bindingPoint, m_dataBufferID); 18433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Allocating memory for data buffer, size " << sizeToString(bufferSize) << "." << tcu::TestLog::EndMessage; 18453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_SHADER_STORAGE_BUFFER, bufferSize, DE_NULL, GL_DYNAMIC_DRAW); 18463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // calculate 18483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Dispatching data compute, size = " << dataBufferDispatchSize << tcu::TestLog::EndMessage; 18503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.dispatchCompute(dataBufferDispatchSize.x(), dataBufferDispatchSize.y(), dataBufferDispatchSize.z()); 18513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "calculate data", __FILE__, __LINE__); 18533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 18543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Compute indices 18563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_computeIndices) 18583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 18593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int bindingPoint = 0; 18603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::IVec3 indexBufferDispatchSize (m_gridSize, m_gridSize, 1); 18613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int bufferSize = (int)(calcIndexBufferSize()*sizeof(deUint32)); 18623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(m_drawMethod == DRAWMETHOD_DRAWELEMENTS); 18643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.useProgram(m_computeIndicesProgram->getProgram()); 18663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // setup buffers 18683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Binding index buffer to binding point " << bindingPoint << tcu::TestLog::EndMessage; 18703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBufferBase(GL_SHADER_STORAGE_BUFFER, bindingPoint, m_indexBufferID); 18713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Allocating memory for index buffer, size " << sizeToString(bufferSize) << "." << tcu::TestLog::EndMessage; 18733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_SHADER_STORAGE_BUFFER, bufferSize, DE_NULL, GL_DYNAMIC_DRAW); 18743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // calculate 18763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Dispatching index compute, size = " << indexBufferDispatchSize << tcu::TestLog::EndMessage; 18783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.dispatchCompute(indexBufferDispatchSize.x(), indexBufferDispatchSize.y(), indexBufferDispatchSize.z()); 18793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "calculate indices", __FILE__, __LINE__); 18813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 18823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "post dispatch", __FILE__, __LINE__); 18843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 18853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18863c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ComputeShaderGeneratedGroup : public TestCaseGroup 18873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 18883c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 18893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ComputeShaderGeneratedGroup (Context& context, const char* name, const char* descr); 18903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~ComputeShaderGeneratedGroup (void); 18913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 18933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 18943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 18953c827367444ee418f129b2c238299f49d3264554Jarkko PoyryComputeShaderGeneratedGroup::ComputeShaderGeneratedGroup (Context& context, const char* name, const char* descr) 18963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCaseGroup (context, name, descr) 18973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 18983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 18993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 19003c827367444ee418f129b2c238299f49d3264554Jarkko PoyryComputeShaderGeneratedGroup::~ComputeShaderGeneratedGroup (void) 19013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 19023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 19033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 19043c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ComputeShaderGeneratedGroup::init (void) 19053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 19063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int gridSize = 8; 19073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TestCaseGroup* const separateGroup = new tcu::TestCaseGroup(m_testCtx, "separate", "Use separate compute shaders for each buffer"); 19083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TestCaseGroup* const combinedGroup = new tcu::TestCaseGroup(m_testCtx, "combined", "Use combined compute shader for all buffers"); 19093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TestCaseGroup* const largeGroup = new tcu::TestCaseGroup(m_testCtx, "large", "Draw shapes with large buffers"); 19103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 19113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry this->addChild(separateGroup); 19123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry this->addChild(combinedGroup); 19133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry this->addChild(largeGroup); 19143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 19153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // .separate 19163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 19173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry separateGroup->addChild(new ComputeShaderGeneratedSeparateCase(m_context, "drawarrays_compute_cmd", "Command from compute shader", ComputeShaderGeneratedCase::DRAWMETHOD_DRAWARRAYS, true, false, false, gridSize, 1)); 19183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry separateGroup->addChild(new ComputeShaderGeneratedSeparateCase(m_context, "drawarrays_compute_data", "Data from compute shader", ComputeShaderGeneratedCase::DRAWMETHOD_DRAWARRAYS, false, true, false, gridSize, 1)); 19193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry separateGroup->addChild(new ComputeShaderGeneratedSeparateCase(m_context, "drawarrays_compute_cmd_and_data", "Command and data from compute shader", ComputeShaderGeneratedCase::DRAWMETHOD_DRAWARRAYS, true, true, false, gridSize, 1)); 19203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 19213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry separateGroup->addChild(new ComputeShaderGeneratedSeparateCase(m_context, "drawelements_compute_cmd", "Command from compute shader", ComputeShaderGeneratedCase::DRAWMETHOD_DRAWELEMENTS, true, false, false, gridSize, 1)); 19223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry separateGroup->addChild(new ComputeShaderGeneratedSeparateCase(m_context, "drawelements_compute_data", "Data from compute shader", ComputeShaderGeneratedCase::DRAWMETHOD_DRAWELEMENTS, false, true, false, gridSize, 1)); 19233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry separateGroup->addChild(new ComputeShaderGeneratedSeparateCase(m_context, "drawelements_compute_indices", "Indices from compute shader", ComputeShaderGeneratedCase::DRAWMETHOD_DRAWELEMENTS, false, false, true, gridSize, 1)); 19243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry separateGroup->addChild(new ComputeShaderGeneratedSeparateCase(m_context, "drawelements_compute_cmd_and_data", "Command and data from compute shader", ComputeShaderGeneratedCase::DRAWMETHOD_DRAWELEMENTS, true, true, false, gridSize, 1)); 19253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry separateGroup->addChild(new ComputeShaderGeneratedSeparateCase(m_context, "drawelements_compute_cmd_and_indices", "Command and indices from compute shader", ComputeShaderGeneratedCase::DRAWMETHOD_DRAWELEMENTS, true, false, true, gridSize, 1)); 19263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry separateGroup->addChild(new ComputeShaderGeneratedSeparateCase(m_context, "drawelements_compute_data_and_indices", "Data and indices from compute shader", ComputeShaderGeneratedCase::DRAWMETHOD_DRAWELEMENTS, false, true, true, gridSize, 1)); 19273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry separateGroup->addChild(new ComputeShaderGeneratedSeparateCase(m_context, "drawelements_compute_cmd_and_data_and_indices", "Command, data and indices from compute shader", ComputeShaderGeneratedCase::DRAWMETHOD_DRAWELEMENTS, true, true, true, gridSize, 1)); 19283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 19293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 19303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // .combined 19313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 19323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry combinedGroup->addChild(new ComputeShaderGeneratedCombinedCase(m_context, "drawarrays_compute_cmd_and_data", "Command and data from compute shader", ComputeShaderGeneratedCase::DRAWMETHOD_DRAWARRAYS, true, true, false, gridSize, 1)); 19333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry combinedGroup->addChild(new ComputeShaderGeneratedCombinedCase(m_context, "drawelements_compute_cmd_and_data", "Command and data from compute shader", ComputeShaderGeneratedCase::DRAWMETHOD_DRAWELEMENTS, true, true, false, gridSize, 1)); 19343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry combinedGroup->addChild(new ComputeShaderGeneratedCombinedCase(m_context, "drawelements_compute_cmd_and_indices", "Command and indices from compute shader", ComputeShaderGeneratedCase::DRAWMETHOD_DRAWELEMENTS, true, false, true, gridSize, 1)); 19353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry combinedGroup->addChild(new ComputeShaderGeneratedCombinedCase(m_context, "drawelements_compute_data_and_indices", "Data and indices from compute shader", ComputeShaderGeneratedCase::DRAWMETHOD_DRAWELEMENTS, false, true, true, gridSize, 1)); 19363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry combinedGroup->addChild(new ComputeShaderGeneratedCombinedCase(m_context, "drawelements_compute_cmd_and_data_and_indices", "Command, data and indices from compute shader", ComputeShaderGeneratedCase::DRAWMETHOD_DRAWELEMENTS, true, true, true, gridSize, 1)); 19373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 19383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 19393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // .large 19403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 19413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry struct TestSpec 19423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 19433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int gridSize; 19443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int numDrawCommands; 19453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 19463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry struct TestMethod 19473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 19483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ComputeShaderGeneratedCase::DrawMethod method; 19493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool separateCompute; 19503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 19513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 19523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const TestSpec specs[] = 19533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 19543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 100, 1 }, // !< drawArrays array size ~ 1.9 MB 19553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 200, 1 }, // !< drawArrays array size ~ 7.7 MB 19563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 500, 1 }, // !< drawArrays array size ~ 48 MB 19573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1000, 1 }, // !< drawArrays array size ~ 192 MB 19583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1200, 1 }, // !< drawArrays array size ~ 277 MB 19593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1500, 1 }, // !< drawArrays array size ~ 430 MB 19603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 19613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 100, 8 }, // !< drawArrays array size ~ 1.9 MB 19623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 200, 8 }, // !< drawArrays array size ~ 7.7 MB 19633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 500, 8 }, // !< drawArrays array size ~ 48 MB 19643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1000, 8 }, // !< drawArrays array size ~ 192 MB 19653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1200, 8 }, // !< drawArrays array size ~ 277 MB 19663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1500, 8 }, // !< drawArrays array size ~ 430 MB 19673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 19683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 100, 200 }, // !< 50 cells per draw call 19693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 200, 800 }, // !< 50 cells per draw call 19703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 500, 2500 }, // !< 100 cells per draw call 19713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1000, 5000 }, // !< 250 cells per draw call 19723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 19733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const TestMethod methods[] = 19743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 19753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { ComputeShaderGeneratedCase::DRAWMETHOD_DRAWARRAYS, true }, 19763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { ComputeShaderGeneratedCase::DRAWMETHOD_DRAWARRAYS, false }, 19773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { ComputeShaderGeneratedCase::DRAWMETHOD_DRAWELEMENTS, true }, 19783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { ComputeShaderGeneratedCase::DRAWMETHOD_DRAWELEMENTS, false }, 19793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 19803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 19813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int methodNdx = 0; methodNdx < DE_LENGTH_OF_ARRAY(methods); ++methodNdx) 19823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int specNdx = 0; specNdx < DE_LENGTH_OF_ARRAY(specs); ++specNdx) 19833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 19843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string name = std::string("") 19853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry + ((methods[methodNdx].method == ComputeShaderGeneratedCase::DRAWMETHOD_DRAWARRAYS) ? ("drawarrays") : ("drawelements")) 19863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry + ((methods[methodNdx].separateCompute) ? ("_separate") : ("_combined")) 19873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry + "_grid_" + de::toString(specs[specNdx].gridSize) + "x" + de::toString(specs[specNdx].gridSize) 19883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry + "_drawcount_" + de::toString(specs[specNdx].numDrawCommands); 19893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 19903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string desc = std::string("Draw grid with ") 19913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry + ((methods[methodNdx].method == ComputeShaderGeneratedCase::DRAWMETHOD_DRAWARRAYS) ? ("drawarrays indirect") : ("drawelements indirect")) 19923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry + " calculating buffers in " + ((methods[methodNdx].separateCompute) ? ("separate") : ("combined")) + " compute shader." 19933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry + " Grid size is " + de::toString(specs[specNdx].gridSize) + "x" + de::toString(specs[specNdx].gridSize) 19943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry + ", draw count is " + de::toString(specs[specNdx].numDrawCommands); 19953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 19963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool computeIndices = (methods[methodNdx].method == ComputeShaderGeneratedCase::DRAWMETHOD_DRAWELEMENTS); 19973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 19983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (methods[methodNdx].separateCompute) 19993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry largeGroup->addChild(new ComputeShaderGeneratedSeparateCase(m_context, name.c_str(), desc.c_str(), methods[methodNdx].method, false, true, computeIndices, specs[specNdx].gridSize, specs[specNdx].numDrawCommands)); 20003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 20013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry largeGroup->addChild(new ComputeShaderGeneratedCombinedCase(m_context, name.c_str(), desc.c_str(), methods[methodNdx].method, false, true, computeIndices, specs[specNdx].gridSize, specs[specNdx].numDrawCommands)); 20023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 20033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 20043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 20053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 20063c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass RandomGroup : public TestCaseGroup 20073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 20083c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 20093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RandomGroup (Context& context, const char* name, const char* descr); 20103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~RandomGroup (void); 20113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 20123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 20133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 20143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 20153c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <int SIZE> 20163c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct UniformWeightArray 20173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 20183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float weights[SIZE]; 20193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 20203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry UniformWeightArray (void) 20213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 20223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i=0; i<SIZE; ++i) 20233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry weights[i] = 1.0f; 20243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 20253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 20263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 20273c827367444ee418f129b2c238299f49d3264554Jarkko PoyryRandomGroup::RandomGroup (Context& context, const char* name, const char* descr) 20283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCaseGroup (context, name, descr) 20293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 20303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 20313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 20323c827367444ee418f129b2c238299f49d3264554Jarkko PoyryRandomGroup::~RandomGroup (void) 20333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 20343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 20353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 20363c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RandomGroup::init (void) 20373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 20383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int numAttempts = 100; 20393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 20403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int attribCounts[] = { 1, 2, 5 }; 20413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float attribWeights[] = { 30, 10, 1 }; 20423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int primitiveCounts[] = { 1, 5, 64 }; 20433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float primitiveCountWeights[] = { 20, 10, 1 }; 20443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int indexOffsets[] = { 0, 7, 13 }; 20453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float indexOffsetWeights[] = { 20, 20, 1 }; 20463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int firsts[] = { 0, 7, 13 }; 20473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float firstWeights[] = { 20, 20, 1 }; 20483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 20493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int instanceCounts[] = { 1, 2, 16, 17 }; 20503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float instanceWeights[] = { 20, 10, 5, 1 }; 20513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int indexMins[] = { 0, 1, 3, 8 }; 20523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int indexMaxs[] = { 4, 8, 128, 257 }; 20533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float indexWeights[] = { 50, 50, 50, 50 }; 20543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int offsets[] = { 0, 1, 5, 12 }; 20553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float offsetWeights[] = { 50, 10, 10, 10 }; 20563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int strides[] = { 0, 7, 16, 17 }; 20573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float strideWeights[] = { 50, 10, 10, 10 }; 20583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int instanceDivisors[] = { 0, 1, 3, 129 }; 20593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float instanceDivisorWeights[]= { 70, 30, 10, 10 }; 20603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 20613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int indirectOffsets[] = { 0, 1, 2 }; 20623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float indirectOffsetWeigths[] = { 2, 1, 1 }; 20633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int baseVertices[] = { 0, 1, -2, 4, 3 }; 20643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float baseVertexWeigths[] = { 4, 1, 1, 1, 1 }; 20653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 20663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::Primitive primitives[] = 20673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 20683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::PRIMITIVE_POINTS, 20693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::PRIMITIVE_TRIANGLES, 20703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::PRIMITIVE_TRIANGLE_FAN, 20713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::PRIMITIVE_TRIANGLE_STRIP, 20723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::PRIMITIVE_LINES, 20733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::PRIMITIVE_LINE_STRIP, 20743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::PRIMITIVE_LINE_LOOP 20753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 20763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const UniformWeightArray<DE_LENGTH_OF_ARRAY(primitives)> primitiveWeights; 20773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 20783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::DrawMethod drawMethods[] = 20793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 20803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::DRAWMETHOD_DRAWARRAYS_INDIRECT, 20813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_INDIRECT, 20823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 20833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const UniformWeightArray<DE_LENGTH_OF_ARRAY(drawMethods)> drawMethodWeights; 20843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 20853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::IndexType indexTypes[] = 20863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 20873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::INDEXTYPE_BYTE, 20883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::INDEXTYPE_SHORT, 20893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::INDEXTYPE_INT, 20903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 20913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const UniformWeightArray<DE_LENGTH_OF_ARRAY(indexTypes)> indexTypeWeights; 20923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 20933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::InputType inputTypes[] = 20943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 20953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::INPUTTYPE_FLOAT, 20963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::INPUTTYPE_FIXED, 20973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::INPUTTYPE_BYTE, 20983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::INPUTTYPE_SHORT, 20993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::INPUTTYPE_UNSIGNED_BYTE, 21003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::INPUTTYPE_UNSIGNED_SHORT, 21013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::INPUTTYPE_INT, 21023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::INPUTTYPE_UNSIGNED_INT, 21033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::INPUTTYPE_HALF, 21043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::INPUTTYPE_UNSIGNED_INT_2_10_10_10, 21053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::INPUTTYPE_INT_2_10_10_10, 21063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 21073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const UniformWeightArray<DE_LENGTH_OF_ARRAY(inputTypes)> inputTypeWeights; 21083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 21093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::OutputType outputTypes[] = 21103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 21113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::OUTPUTTYPE_FLOAT, 21123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::OUTPUTTYPE_VEC2, 21133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::OUTPUTTYPE_VEC3, 21143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::OUTPUTTYPE_VEC4, 21153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::OUTPUTTYPE_INT, 21163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::OUTPUTTYPE_UINT, 21173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::OUTPUTTYPE_IVEC2, 21183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::OUTPUTTYPE_IVEC3, 21193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::OUTPUTTYPE_IVEC4, 21203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::OUTPUTTYPE_UVEC2, 21213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::OUTPUTTYPE_UVEC3, 21223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::OUTPUTTYPE_UVEC4, 21233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 21243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const UniformWeightArray<DE_LENGTH_OF_ARRAY(outputTypes)> outputTypeWeights; 21253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 21263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::Usage usages[] = 21273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 21283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::USAGE_DYNAMIC_DRAW, 21293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::USAGE_STATIC_DRAW, 21303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::USAGE_STREAM_DRAW, 21313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::USAGE_STREAM_READ, 21323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::USAGE_STREAM_COPY, 21333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::USAGE_STATIC_READ, 21343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::USAGE_STATIC_COPY, 21353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::USAGE_DYNAMIC_READ, 21363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::USAGE_DYNAMIC_COPY, 21373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 21383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const UniformWeightArray<DE_LENGTH_OF_ARRAY(usages)> usageWeights; 21393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 21403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::set<deUint32> insertedHashes; 21413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t insertedCount = 0; 21423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 21433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < numAttempts; ++ndx) 21443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 21453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random random(0xc551393 + ndx); // random does not depend on previous cases 21463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 21473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int attributeCount = random.chooseWeighted<int, const int*, const float*>(DE_ARRAY_BEGIN(attribCounts), DE_ARRAY_END(attribCounts), attribWeights); 21483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int drawCommandSize; 21493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec spec; 21503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 21513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.apiType = glu::ApiType::es(3,1); 21523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.primitive = random.chooseWeighted<gls::DrawTestSpec::Primitive> (DE_ARRAY_BEGIN(primitives), DE_ARRAY_END(primitives), primitiveWeights.weights); 21533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.primitiveCount = random.chooseWeighted<int, const int*, const float*> (DE_ARRAY_BEGIN(primitiveCounts), DE_ARRAY_END(primitiveCounts), primitiveCountWeights); 21543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.drawMethod = random.chooseWeighted<gls::DrawTestSpec::DrawMethod> (DE_ARRAY_BEGIN(drawMethods), DE_ARRAY_END(drawMethods), drawMethodWeights.weights); 21553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 21563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (spec.drawMethod == gls::DrawTestSpec::DRAWMETHOD_DRAWARRAYS_INDIRECT) 21573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry drawCommandSize = sizeof(deUint32[4]); 21583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (spec.drawMethod == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_INDIRECT) 21593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry drawCommandSize = sizeof(deUint32[5]); 21603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 21613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 21623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(DE_FALSE); 21633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return; 21643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 21653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 21663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexType = random.chooseWeighted<gls::DrawTestSpec::IndexType> (DE_ARRAY_BEGIN(indexTypes), DE_ARRAY_END(indexTypes), indexTypeWeights.weights); 21673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexPointerOffset = random.chooseWeighted<int, const int*, const float*> (DE_ARRAY_BEGIN(indexOffsets), DE_ARRAY_END(indexOffsets), indexOffsetWeights); 21683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexStorage = gls::DrawTestSpec::STORAGE_BUFFER; 21693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.first = random.chooseWeighted<int, const int*, const float*> (DE_ARRAY_BEGIN(firsts), DE_ARRAY_END(firsts), firstWeights); 21703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexMin = random.chooseWeighted<int, const int*, const float*> (DE_ARRAY_BEGIN(indexMins), DE_ARRAY_END(indexMins), indexWeights); 21713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indexMax = random.chooseWeighted<int, const int*, const float*> (DE_ARRAY_BEGIN(indexMaxs), DE_ARRAY_END(indexMaxs), indexWeights); 21723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.instanceCount = random.chooseWeighted<int, const int*, const float*> (DE_ARRAY_BEGIN(instanceCounts), DE_ARRAY_END(instanceCounts), instanceWeights); 21733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.indirectOffset = random.chooseWeighted<int, const int*, const float*> (DE_ARRAY_BEGIN(indirectOffsets), DE_ARRAY_END(indirectOffsets), indirectOffsetWeigths) * drawCommandSize; 21743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.baseVertex = random.chooseWeighted<int, const int*, const float*> (DE_ARRAY_BEGIN(baseVertices), DE_ARRAY_END(baseVertices), baseVertexWeigths); 21753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 21763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // check spec is legal 21773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!spec.valid()) 21783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry continue; 21793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 21803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int attrNdx = 0; attrNdx < attributeCount;) 21813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 21823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool valid; 21833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::AttributeSpec attribSpec; 21843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 21853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry attribSpec.inputType = random.chooseWeighted<gls::DrawTestSpec::InputType> (DE_ARRAY_BEGIN(inputTypes), DE_ARRAY_END(inputTypes), inputTypeWeights.weights); 21863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry attribSpec.outputType = random.chooseWeighted<gls::DrawTestSpec::OutputType> (DE_ARRAY_BEGIN(outputTypes), DE_ARRAY_END(outputTypes), outputTypeWeights.weights); 21873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry attribSpec.storage = gls::DrawTestSpec::STORAGE_BUFFER; 21883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry attribSpec.usage = random.chooseWeighted<gls::DrawTestSpec::Usage> (DE_ARRAY_BEGIN(usages), DE_ARRAY_END(usages), usageWeights.weights); 21893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry attribSpec.componentCount = random.getInt(1, 4); 21903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry attribSpec.offset = random.chooseWeighted<int, const int*, const float*>(DE_ARRAY_BEGIN(offsets), DE_ARRAY_END(offsets), offsetWeights); 21913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry attribSpec.stride = random.chooseWeighted<int, const int*, const float*>(DE_ARRAY_BEGIN(strides), DE_ARRAY_END(strides), strideWeights); 21923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry attribSpec.normalize = random.getBool(); 21933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry attribSpec.instanceDivisor = random.chooseWeighted<int, const int*, const float*>(DE_ARRAY_BEGIN(instanceDivisors), DE_ARRAY_END(instanceDivisors), instanceDivisorWeights); 21943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry attribSpec.useDefaultAttribute = random.getBool(); 21953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 21963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // check spec is legal 21973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry valid = attribSpec.valid(spec.apiType); 21983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 21993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // we do not want interleaved elements. (Might result in some weird floating point values) 22003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (attribSpec.stride && attribSpec.componentCount * gls::DrawTestSpec::inputTypeSize(attribSpec.inputType) > attribSpec.stride) 22013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry valid = false; 22023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 22033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // try again if not valid 22043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (valid) 22053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 22063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs.push_back(attribSpec); 22073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ++attrNdx; 22083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 22093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 22103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 22113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Do not collapse all vertex positions to a single positions 22123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (spec.primitive != gls::DrawTestSpec::PRIMITIVE_POINTS) 22133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.attribs[0].instanceDivisor = 0; 22143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 22153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Is render result meaningful? 22163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 22173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Only one vertex 22183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (spec.drawMethod == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED && spec.indexMin == spec.indexMax && spec.primitive != gls::DrawTestSpec::PRIMITIVE_POINTS) 22193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry continue; 22203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (spec.attribs[0].useDefaultAttribute && spec.primitive != gls::DrawTestSpec::PRIMITIVE_POINTS) 22213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry continue; 22223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 22233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Triangle only on one axis 22243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (spec.primitive == gls::DrawTestSpec::PRIMITIVE_TRIANGLES || spec.primitive == gls::DrawTestSpec::PRIMITIVE_TRIANGLE_FAN || spec.primitive == gls::DrawTestSpec::PRIMITIVE_TRIANGLE_STRIP) 22253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 22263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (spec.attribs[0].componentCount == 1) 22273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry continue; 22283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (spec.attribs[0].outputType == gls::DrawTestSpec::OUTPUTTYPE_FLOAT || spec.attribs[0].outputType == gls::DrawTestSpec::OUTPUTTYPE_INT || spec.attribs[0].outputType == gls::DrawTestSpec::OUTPUTTYPE_UINT) 22293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry continue; 22303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (spec.drawMethod == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED && (spec.indexMax - spec.indexMin) < 2) 22313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry continue; 22323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 22333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 22343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 22353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Add case 22363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 22373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 hash = spec.hash(); 22383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int attrNdx = 0; attrNdx < attributeCount; ++attrNdx) 22393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry hash = (hash << 2) ^ (deUint32)spec.attribs[attrNdx].hash(); 22403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 22413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (insertedHashes.find(hash) == insertedHashes.end()) 22423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 22433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Only aligned cases 22443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (spec.isCompatibilityTest() != gls::DrawTestSpec::COMPATIBILITY_UNALIGNED_OFFSET && 22453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spec.isCompatibilityTest() != gls::DrawTestSpec::COMPATIBILITY_UNALIGNED_STRIDE) 22463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry this->addChild(new gls::DrawTest(m_testCtx, m_context.getRenderContext(), spec, de::toString(insertedCount).c_str(), spec.getDesc().c_str())); 22473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry insertedHashes.insert(hash); 22483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 22493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ++insertedCount; 22503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 22513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 22523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 22533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 22543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 22553c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass BadCommandBufferCase : public TestCase 22563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 22573c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 22583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enum 22593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 22603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry CommandSize = 20 22613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 22623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 22633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry BadCommandBufferCase (Context& context, const char* name, const char* desc, deUint32 alignment, deUint32 bufferSize, bool writeCommandToBuffer, deUint32 m_expectedError); 22643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~BadCommandBufferCase (void); 22653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 22663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IterateResult iterate (void); 22673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 22683c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 22693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 m_alignment; 22703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 m_bufferSize; 22713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool m_writeCommandToBuffer; 22723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 m_expectedError; 22733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 22743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 22753c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBadCommandBufferCase::BadCommandBufferCase (Context& context, const char* name, const char* desc, deUint32 alignment, deUint32 bufferSize, bool writeCommandToBuffer, deUint32 expectedError) 22763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCase (context, name, desc) 22773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_alignment (alignment) 22783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_bufferSize (bufferSize) 22793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_writeCommandToBuffer (writeCommandToBuffer) 22803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_expectedError (expectedError) 22813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 22823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 22833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 22843c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBadCommandBufferCase::~BadCommandBufferCase (void) 22853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 22863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 22873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 22883c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBadCommandBufferCase::IterateResult BadCommandBufferCase::iterate (void) 22893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 22903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 vertexPositions[] = 22913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 22923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(0, 0, 0, 1), 22933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(1, 0, 0, 1), 22943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(0, 1, 0, 1), 22953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 22963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 22973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint16 indices[] = 22983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 22993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 0, 2, 1, 23003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 23013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_STATIC_ASSERT(CommandSize == sizeof(DrawElementsCommand)); 23033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sglr::GLContext gl(m_context.getRenderContext(), m_testCtx.getLog(), sglr::GLCONTEXT_LOG_CALLS, tcu::IVec4(0, 0, 1, 1)); 23053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 vaoID = 0; 23073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 positionBuf = 0; 23083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 indexBuf = 0; 23093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 drawIndirectBuf= 0; 23103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 error; 23113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ShaderProgram program (m_context.getRenderContext(), glu::ProgramSources() << glu::VertexSource(s_commonVertexShaderSource) << glu::FragmentSource(s_commonFragmentShaderSource)); 23133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 programID = program.getProgram(); 23143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deInt32 posLocation = gl.getAttribLocation(programID, "a_position"); 23153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DrawElementsCommand drawCommand; 23173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry drawCommand.count = 3; 23183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry drawCommand.primCount = 1; 23193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry drawCommand.firstIndex = 0; 23203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry drawCommand.baseVertex = 0; 23213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry drawCommand.reservedMustBeZero = 0; 23223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<deInt8> drawCommandBuffer; 23243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry drawCommandBuffer.resize(m_bufferSize); 23253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deMemset(&drawCommandBuffer[0], 0, (int)drawCommandBuffer.size()); 23273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_writeCommandToBuffer) 23293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 23303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(drawCommandBuffer.size() >= sizeof(drawCommand) + m_alignment); 23313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deMemcpy(&drawCommandBuffer[m_alignment], &drawCommand, sizeof(drawCommand)); 23323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 23333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "", __FILE__, __LINE__); 23353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genVertexArrays(1, &vaoID); 23363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindVertexArray(vaoID); 23373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genBuffers(1, &positionBuf); 23393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_ARRAY_BUFFER, positionBuf); 23403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW); 23413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.vertexAttribPointer(posLocation, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL); 23423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.vertexAttribDivisor(posLocation, 0); 23433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.enableVertexAttribArray(posLocation); 23443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "", __FILE__, __LINE__); 23453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genBuffers(1, &indexBuf); 23473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuf); 23483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); 23493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "", __FILE__, __LINE__); 23503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genBuffers(1, &drawIndirectBuf); 23523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_DRAW_INDIRECT_BUFFER, drawIndirectBuf); 23533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_DRAW_INDIRECT_BUFFER, drawCommandBuffer.size(), &drawCommandBuffer[0], GL_STATIC_DRAW); 23543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "", __FILE__, __LINE__); 23553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.viewport(0, 0, 1, 1); 23573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.useProgram(programID); 23593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.drawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, (const void*)(deUintptr)m_alignment); 23603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry error = gl.getError(); 23623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.useProgram(0); 23643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.deleteBuffers(1, &drawIndirectBuf); 23663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.deleteBuffers(1, &indexBuf); 23673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.deleteBuffers(1, &positionBuf); 23683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.deleteVertexArrays(1, &vaoID); 23693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "drawElementsIndirect generated " << glu::getErrorStr(error) << ", expecting " << glu::getErrorStr(m_expectedError) << "." << tcu::TestLog::EndMessage; 23713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (error == m_expectedError) 23733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 23743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 23753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 23763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "\tUnexpected error." << tcu::TestLog::EndMessage; 23773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got unexpected error."); 23783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 23793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return STOP; 23813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 23823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23833c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass BadAlignmentCase : public BadCommandBufferCase 23843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 23853c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 23863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry BadAlignmentCase (Context& context, const char* name, const char* desc, deUint32 alignment); 23873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~BadAlignmentCase (void); 23883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 23893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23903c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBadAlignmentCase::BadAlignmentCase (Context& context, const char* name, const char* desc, deUint32 alignment) 23913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : BadCommandBufferCase(context, name, desc, alignment, CommandSize+alignment, true, GL_INVALID_VALUE) 23923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 23933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 23943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23953c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBadAlignmentCase::~BadAlignmentCase (void) 23963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 23973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 23983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23993c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass BadBufferRangeCase : public BadCommandBufferCase 24003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 24013c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 24023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry BadBufferRangeCase (Context& context, const char* name, const char* desc, deUint32 offset); 24033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~BadBufferRangeCase (void); 24043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 24053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 24063c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBadBufferRangeCase::BadBufferRangeCase (Context& context, const char* name, const char* desc, deUint32 offset) 24073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : BadCommandBufferCase(context, name, desc, offset, CommandSize, false, GL_INVALID_OPERATION) 24083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 24093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 24103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 24113c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBadBufferRangeCase::~BadBufferRangeCase (void) 24123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 24133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 24143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 24153c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass BadStateCase : public TestCase 24163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 24173c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 24183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enum CaseType 24193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 24203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry CASE_CLIENT_BUFFER_VERTEXATTR = 0, 24213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry CASE_CLIENT_BUFFER_COMMAND, 24223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry CASE_DEFAULT_VAO, 24233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 24243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry CASE_CLIENT_LAST 24253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 24263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 24273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry BadStateCase (Context& context, const char* name, const char* desc, CaseType type); 24283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~BadStateCase (void); 24293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 24303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 24313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void deinit (void); 24323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IterateResult iterate (void); 24333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 24343c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 24353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const CaseType m_caseType; 24363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 24373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 24383c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBadStateCase::BadStateCase (Context& context, const char* name, const char* desc, CaseType type) 24393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCase (context, name, desc) 24403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_caseType (type) 24413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 24423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(type < CASE_CLIENT_LAST); 24433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 24443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 24453c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBadStateCase::~BadStateCase (void) 24463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 24473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deinit(); 24483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 24493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 24503c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BadStateCase::init (void) 24513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 24523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 24533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 24543c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BadStateCase::deinit (void) 24553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 24563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 24573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 24583c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBadStateCase::IterateResult BadStateCase::iterate (void) 24593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 24603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 vertexPositions[] = 24613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 24623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), 24633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), 24643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), 24653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 24663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 24673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint16 indices[] = 24683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 24693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 0, 2, 1, 24703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 24713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 24723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sglr::GLContext gl(m_context.getRenderContext(), m_testCtx.getLog(), sglr::GLCONTEXT_LOG_CALLS, tcu::IVec4(0, 0, 1, 1)); 24733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 24743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 error; 24753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ShaderProgram program (m_context.getRenderContext(), glu::ProgramSources() << glu::VertexSource(s_commonVertexShaderSource) << glu::FragmentSource(s_commonFragmentShaderSource)); 24763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 vaoID = 0; 24773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 dataBufferID = 0; 24783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 indexBufferID = 0; 24793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 cmdBufferID = 0; 24803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 24813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 programID = program.getProgram(); 24823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deInt32 posLocation = gl.getAttribLocation(programID, "a_position"); 24833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 24843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DrawElementsCommand drawCommand; 24853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry drawCommand.count = 3; 24863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry drawCommand.primCount = 1; 24873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry drawCommand.firstIndex = 0; 24883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry drawCommand.baseVertex = 0; 24893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry drawCommand.reservedMustBeZero = 0; 24903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 24913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "", __FILE__, __LINE__); 24923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 24933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_caseType == CASE_CLIENT_BUFFER_VERTEXATTR) 24943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 24953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \note We use default VAO since we use client pointers. Trying indirect draw with default VAO is also an error. => This test does two illegal operations 24963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 24973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.vertexAttribPointer(posLocation, 4, GL_FLOAT, GL_FALSE, 0, vertexPositions); 24983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.enableVertexAttribArray(posLocation); 24993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "", __FILE__, __LINE__); 25003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 25013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (m_caseType == CASE_CLIENT_BUFFER_COMMAND) 25023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 25033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genVertexArrays(1, &vaoID); 25043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindVertexArray(vaoID); 25053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 25063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genBuffers(1, &dataBufferID); 25073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_ARRAY_BUFFER, dataBufferID); 25083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW); 25093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.vertexAttribPointer(posLocation, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL); 25103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.enableVertexAttribArray(posLocation); 25113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "", __FILE__, __LINE__); 25123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 25133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (m_caseType == CASE_DEFAULT_VAO) 25143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 25153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genBuffers(1, &dataBufferID); 25163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_ARRAY_BUFFER, dataBufferID); 25173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW); 25183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.vertexAttribPointer(posLocation, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL); 25193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.enableVertexAttribArray(posLocation); 25203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "", __FILE__, __LINE__); 25213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 25223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 25233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(DE_FALSE); 25243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 25253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genBuffers(1, &indexBufferID); 25263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferID); 25273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); 25283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "", __FILE__, __LINE__); 25293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 25303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_caseType != CASE_CLIENT_BUFFER_COMMAND) 25313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 25323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genBuffers(1, &cmdBufferID); 25333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_DRAW_INDIRECT_BUFFER, cmdBufferID); 25343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_DRAW_INDIRECT_BUFFER, sizeof(drawCommand), &drawCommand, GL_STATIC_DRAW); 25353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "", __FILE__, __LINE__); 25363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 25373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 25383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.viewport(0, 0, 1, 1); 25393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 25403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.useProgram(programID); 25413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.drawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, (m_caseType != CASE_CLIENT_BUFFER_COMMAND) ? (DE_NULL) : (&drawCommand)); 25423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 25433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry error = gl.getError(); 25443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 25453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindVertexArray(0); 25463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.useProgram(0); 25473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 25483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (error == GL_INVALID_OPERATION) 25493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 25503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 25513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 25523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Unexpected error. Expected GL_INVALID_OPERATION, got " << glu::getErrorStr(error) << tcu::TestLog::EndMessage; 25533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got unexpected error."); 25543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 25553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 25563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return STOP; 25573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 25583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 25593c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass BadDrawModeCase : public TestCase 25603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 25613c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 25623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enum DrawType 25633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 25643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DRAW_ARRAYS = 0, 25653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DRAW_ELEMENTS, 25663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DRAW_ELEMENTS_BAD_INDEX, 25673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 25683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DRAW_LAST 25693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 25703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 25713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry BadDrawModeCase (Context& context, const char* name, const char* desc, DrawType type); 25723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~BadDrawModeCase(void); 25733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 25743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 25753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void deinit (void); 25763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IterateResult iterate (void); 25773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 25783c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 25793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const DrawType m_drawType; 25803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 25813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 25823c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBadDrawModeCase::BadDrawModeCase (Context& context, const char* name, const char* desc, DrawType type) 25833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCase (context, name, desc) 25843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_drawType (type) 25853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 25863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(type < DRAW_LAST); 25873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 25883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 25893c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBadDrawModeCase::~BadDrawModeCase (void) 25903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 25913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deinit(); 25923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 25933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 25943c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BadDrawModeCase::init (void) 25953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 25963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 25973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 25983c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BadDrawModeCase::deinit (void) 25993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 26003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 26013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 26023c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBadDrawModeCase::IterateResult BadDrawModeCase::iterate (void) 26033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 26043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 vertexPositions[] = 26053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 26063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), 26073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), 26083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), 26093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 26103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 26113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint16 indices[] = 26123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 26133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 0, 2, 1, 26143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 26153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 26168852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry sglr::GLContext gl (m_context.getRenderContext(), m_testCtx.getLog(), sglr::GLCONTEXT_LOG_CALLS, tcu::IVec4(0, 0, 1, 1)); 26173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 26183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 error; 26193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ShaderProgram program (m_context.getRenderContext(), glu::ProgramSources() << glu::VertexSource(s_commonVertexShaderSource) << glu::FragmentSource(s_commonFragmentShaderSource)); 26203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 vaoID = 0; 26213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 dataBufferID = 0; 26223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 indexBufferID = 0; 26233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 cmdBufferID = 0; 26243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 26253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 programID = program.getProgram(); 26263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deInt32 posLocation = gl.getAttribLocation(programID, "a_position"); 26273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::GLenum mode = (m_drawType == DRAW_ELEMENTS_BAD_INDEX) ? (GL_TRIANGLES) : (0x123); 26283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::GLenum indexType = (m_drawType == DRAW_ELEMENTS_BAD_INDEX) ? (0x123) : (GL_UNSIGNED_SHORT); 26293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 26303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "", __FILE__, __LINE__); 26313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 26323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // vao 26333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 26343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genVertexArrays(1, &vaoID); 26353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindVertexArray(vaoID); 26363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 26373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // va 26383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 26393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genBuffers(1, &dataBufferID); 26403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_ARRAY_BUFFER, dataBufferID); 26413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW); 26423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.vertexAttribPointer(posLocation, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL); 26433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.enableVertexAttribArray(posLocation); 26443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "", __FILE__, __LINE__); 26453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 26463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // index 26473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 26488852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry if (m_drawType == DRAW_ELEMENTS || m_drawType == DRAW_ELEMENTS_BAD_INDEX) 26493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 26503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genBuffers(1, &indexBufferID); 26513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferID); 26523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); 26533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "", __FILE__, __LINE__); 26543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 26553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 26563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // cmd 26573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 26583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genBuffers(1, &cmdBufferID); 26593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_DRAW_INDIRECT_BUFFER, cmdBufferID); 26603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_drawType == DRAW_ELEMENTS || m_drawType == DRAW_ELEMENTS_BAD_INDEX) 26613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 26623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DrawElementsCommand drawCommand; 26633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry drawCommand.count = 3; 26643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry drawCommand.primCount = 1; 26653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry drawCommand.firstIndex = 0; 26663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry drawCommand.baseVertex = 0; 26673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry drawCommand.reservedMustBeZero = 0; 26683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 26693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_DRAW_INDIRECT_BUFFER, sizeof(drawCommand), &drawCommand, GL_STATIC_DRAW); 26703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 26713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (m_drawType == DRAW_ARRAYS) 26723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 26733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DrawArraysCommand drawCommand; 26743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry drawCommand.count = 3; 26753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry drawCommand.primCount = 1; 26763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry drawCommand.first = 0; 26773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry drawCommand.reservedMustBeZero = 0; 26783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 26793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_DRAW_INDIRECT_BUFFER, sizeof(drawCommand), &drawCommand, GL_STATIC_DRAW); 26803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 26813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 26823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(DE_FALSE); 26833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::checkError(gl.getError(), "", __FILE__, __LINE__); 26843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 26853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.viewport(0, 0, 1, 1); 26863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.useProgram(programID); 26873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_drawType == DRAW_ELEMENTS || m_drawType == DRAW_ELEMENTS_BAD_INDEX) 26883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.drawElementsIndirect(mode, indexType, DE_NULL); 26893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (m_drawType == DRAW_ARRAYS) 26903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.drawArraysIndirect(mode, DE_NULL); 26913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 26923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(DE_FALSE); 26933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 26943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry error = gl.getError(); 26953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.useProgram(0); 26963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 26973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (error == GL_INVALID_ENUM) 26983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 26993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 27003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 27013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Unexpected error. Expected GL_INVALID_ENUM, got " << glu::getErrorStr(error) << tcu::TestLog::EndMessage; 27023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got unexpected error."); 27033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 27043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return STOP; 27063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 27073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27083c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass NegativeGroup : public TestCaseGroup 27093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 27103c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 27113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry NegativeGroup (Context& context, const char* name, const char* descr); 27123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~NegativeGroup (void); 27133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 27153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 27163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27173c827367444ee418f129b2c238299f49d3264554Jarkko PoyryNegativeGroup::NegativeGroup (Context& context, const char* name, const char* descr) 27183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCaseGroup (context, name, descr) 27193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 27203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 27213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27223c827367444ee418f129b2c238299f49d3264554Jarkko PoyryNegativeGroup::~NegativeGroup (void) 27233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 27243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 27253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27263c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid NegativeGroup::init (void) 27273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 27283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // invalid alignment 27293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new BadAlignmentCase (m_context, "command_bad_alignment_1", "Bad command alignment", 1)); 27303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new BadAlignmentCase (m_context, "command_bad_alignment_2", "Bad command alignment", 2)); 27313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new BadAlignmentCase (m_context, "command_bad_alignment_3", "Bad command alignment", 3)); 27323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // command only partially or not at all in the buffer 27343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new BadBufferRangeCase (m_context, "command_offset_partially_in_buffer", "Command not fully in the buffer range", BadBufferRangeCase::CommandSize - 16)); 27353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new BadBufferRangeCase (m_context, "command_offset_not_in_buffer", "Command not in the buffer range", BadBufferRangeCase::CommandSize)); 27363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new BadBufferRangeCase (m_context, "command_offset_not_in_buffer_unsigned32_wrap", "Command not in the buffer range", 0xFFFFFFFC)); 27373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new BadBufferRangeCase (m_context, "command_offset_not_in_buffer_signed32_wrap", "Command not in the buffer range", 0x7FFFFFFC)); 27383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // use with client data and default vao 27403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new BadStateCase (m_context, "client_vertex_attrib_array", "Vertex attrib array in the client memory", BadStateCase::CASE_CLIENT_BUFFER_VERTEXATTR)); 27413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new BadStateCase (m_context, "client_command_array", "Command array in the client memory", BadStateCase::CASE_CLIENT_BUFFER_COMMAND)); 27423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new BadStateCase (m_context, "default_vao", "Use with default vao", BadStateCase::CASE_DEFAULT_VAO)); 27433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // invalid mode & type 27453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new BadDrawModeCase (m_context, "invalid_mode_draw_arrays", "Call DrawArraysIndirect with bad mode", BadDrawModeCase::DRAW_ARRAYS)); 27463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new BadDrawModeCase (m_context, "invalid_mode_draw_elements", "Call DrawelementsIndirect with bad mode", BadDrawModeCase::DRAW_ELEMENTS)); 27473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new BadDrawModeCase (m_context, "invalid_type_draw_elements", "Call DrawelementsIndirect with bad type", BadDrawModeCase::DRAW_ELEMENTS_BAD_INDEX)); 27483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 27493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // anonymous 27513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27523c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDrawTests::DrawTests (Context& context) 27533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCaseGroup(context, "draw_indirect", "Indirect drawing tests") 27543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 27553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 27563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27573c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDrawTests::~DrawTests (void) 27583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 27593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 27603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27613c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid DrawTests::init (void) 27623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 27633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Basic 27643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 27653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const gls::DrawTestSpec::DrawMethod basicMethods[] = 27663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 27673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::DRAWMETHOD_DRAWARRAYS_INDIRECT, 27683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_INDIRECT, 27693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 27703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(basicMethods); ++ndx) 27723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 27733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string name = gls::DrawTestSpec::drawMethodToString(basicMethods[ndx]); 27743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string desc = gls::DrawTestSpec::drawMethodToString(basicMethods[ndx]); 27753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry this->addChild(new MethodGroup(m_context, name.c_str(), desc.c_str(), basicMethods[ndx])); 27773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 27783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 27793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // extreme instancing 27813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry this->addChild(new InstancingGroup(m_context, "instancing", "draw tests with a large instance count.")); 27833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // compute shader generated commands 27853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry this->addChild(new ComputeShaderGeneratedGroup(m_context, "compute_interop", "draw tests with a draw command generated in compute shader.")); 27873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Random 27893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry this->addChild(new RandomGroup(m_context, "random", "random draw commands.")); 27913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // negative 27933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry this->addChild(new NegativeGroup(m_context, "negative", "invalid draw commands with defined error codes.")); 27953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 27963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 27973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional 27983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles31 27993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp 2800