13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL (ES) 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 Texture buffer test case 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glsTextureBufferCase.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuFormatUtil.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuImageCompare.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuRenderTarget.hpp" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuStringTemplate.hpp" 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuSurface.hpp" 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp" 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp" 33ab44fc6da25bb126919615ad2ded101695251161Jarkko Pöyry#include "tcuResultCollector.hpp" 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rrRenderer.hpp" 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rrShaders.hpp" 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluObjectWrapper.hpp" 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPixelTransfer.hpp" 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluShaderProgram.hpp" 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluShaderUtil.hpp" 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluStrUtil.hpp" 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTexture.hpp" 4412fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry#include "gluTextureUtil.hpp" 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp" 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp" 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deRandom.hpp" 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deStringUtil.hpp" 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deUniquePtr.hpp" 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMemory.h" 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deString.h" 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMath.h" 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <sstream> 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <string> 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector> 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog; 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::map; 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string; 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector; 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace deqp::gls::TextureBufferCaseUtil; 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gls 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MAX_VIEWPORT_WIDTH = 256, 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MAX_VIEWPORT_HEIGHT = 256, 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MIN_VIEWPORT_WIDTH = 64, 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MIN_VIEWPORT_HEIGHT = 64, 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 843c827367444ee418f129b2c238299f49d3264554Jarkko PoyrydeUint8 extend2BitsToByte (deUint8 bits) 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT((bits & (~0x03u)) == 0); 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 88c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry return (deUint8)(bits | (bits << 2) | (bits << 4) | (bits << 6)); 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid genRandomCoords (de::Random rng, vector<deUint8>& coords, size_t offset, size_t size) 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint8 bits = 2; 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint8 bitMask = deUint8((0x1u << bits) - 1); 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry coords.resize(size); 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < (int)size; i++) 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint8 xBits = deUint8(rng.getUint32() & bitMask); 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry coords[i] = extend2BitsToByte(xBits); 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Fill indices with nice quad 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint8 indices[] = 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x0u), 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x1u), 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x2u), 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x3u) 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < DE_LENGTH_OF_ARRAY(indices); i++) 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint8 index = indices[i]; 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t posX = (size_t(index) * 2) + 0; 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t posY = (size_t(index) * 2) + 1; 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (posX >= offset && posX < offset+size) 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry coords[posX - offset] = ((i % 2) == 0 ? extend2BitsToByte(0x0u) : extend2BitsToByte(0x3u)); 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (posY >= offset && posY < offset+size) 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry coords[posY - offset] = ((i / 2) == 1 ? extend2BitsToByte(0x3u) : extend2BitsToByte(0x0u)); 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Fill beginning of buffer 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint8 indices[] = 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x0u), 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x3u), 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x1u), 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x1u), 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x2u), 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x0u), 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x0u), 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x2u), 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x1u), 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x1u), 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x3u), 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extend2BitsToByte(0x0u) 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = (int)offset; i < DE_LENGTH_OF_ARRAY(indices) && i < (int)(offset + size); i++) 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry coords[i-offset] = indices[i]; 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass CoordVertexShader : public rr::VertexShader 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry CoordVertexShader (void) 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : rr::VertexShader(1, 1) 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_inputs[0].type = rr::GENERICVECTYPE_FLOAT; 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_outputs[0].type = rr::GENERICVECTYPE_FLOAT; 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int packetNdx = 0; packetNdx < numPackets; packetNdx++) 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::VertexPacket* const packet = packets[packetNdx]; 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4 position; 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry readVertexAttrib(position, inputs[0], packet->instanceNdx, packet->vertexNdx); 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry packet->outputs[0] = tcu::Vec4(1.0f); 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry packet->position = tcu::Vec4(2.0f * (position.x() - 0.5f), 2.0f * (position.y() - 0.5f), 0.0f, 1.0f); 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TextureVertexShader : public rr::VertexShader 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureVertexShader (const tcu::ConstPixelBufferAccess& texture) 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : rr::VertexShader (1, 1) 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_texture (texture) 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_inputs[0].type = rr::GENERICVECTYPE_FLOAT; 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_outputs[0].type = rr::GENERICVECTYPE_FLOAT; 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int packetNdx = 0; packetNdx < numPackets; packetNdx++) 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::VertexPacket* const packet = packets[packetNdx]; 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4 position; 1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4 texelValue; 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry readVertexAttrib(position, inputs[0], packet->instanceNdx, packet->vertexNdx); 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry texelValue = tcu::Vec4(m_texture.getPixel(de::clamp<int>((deRoundFloatToInt32(position.x() * 4) + 4) * (deRoundFloatToInt32(position.y() * 4) + 4), 0, m_texture.getWidth()-1), 0)); 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry packet->outputs[0] = texelValue; 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry packet->position = tcu::Vec4(2.0f * (position.x() - 0.5f), 2.0f * (position.y() - 0.5f), 0.0f, 1.0f); 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 20812fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry const tcu::ConstPixelBufferAccess m_texture; 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass CoordFragmentShader : public rr::FragmentShader 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry CoordFragmentShader (void) 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : rr::FragmentShader (1, 1) 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_inputs[0].type = rr::GENERICVECTYPE_FLOAT; 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_outputs[0].type = rr::GENERICVECTYPE_FLOAT; 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int packetNdx = 0; packetNdx < numPackets; packetNdx++) 2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::FragmentPacket& packet = packets[packetNdx]; 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 vtxColor0 = rr::readVarying<float>(packet, context, 0, 0); 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 vtxColor1 = rr::readVarying<float>(packet, context, 0, 1); 2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 vtxColor2 = rr::readVarying<float>(packet, context, 0, 2); 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 vtxColor3 = rr::readVarying<float>(packet, context, 0, 3); 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 color0 = vtxColor0; 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 color1 = vtxColor1; 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 color2 = vtxColor2; 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 color3 = vtxColor3; 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::writeFragmentOutput(context, packetNdx, 0, 0, tcu::Vec4(color0.x() * color0.w(), color0.y() * color0.w(), color0.z() * color0.w(), 1.0f)); 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::writeFragmentOutput(context, packetNdx, 1, 0, tcu::Vec4(color1.x() * color1.w(), color1.y() * color1.w(), color1.z() * color1.w(), 1.0f)); 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::writeFragmentOutput(context, packetNdx, 2, 0, tcu::Vec4(color2.x() * color2.w(), color2.y() * color2.w(), color2.z() * color2.w(), 1.0f)); 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::writeFragmentOutput(context, packetNdx, 3, 0, tcu::Vec4(color3.x() * color3.w(), color3.y() * color3.w(), color3.z() * color3.w(), 1.0f)); 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TextureFragmentShader : public rr::FragmentShader 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureFragmentShader (const tcu::ConstPixelBufferAccess& texture) 2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : rr::FragmentShader (1, 1) 2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_texture (texture) 2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_inputs[0].type = rr::GENERICVECTYPE_FLOAT; 2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_outputs[0].type = rr::GENERICVECTYPE_FLOAT; 2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const 2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int packetNdx = 0; packetNdx < numPackets; packetNdx++) 2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::FragmentPacket& packet = packets[packetNdx]; 2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::IVec2 position0 = packet.position + tcu::IVec2(0, 0); 2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::IVec2 position1 = packet.position + tcu::IVec2(1, 0); 2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::IVec2 position2 = packet.position + tcu::IVec2(0, 1); 2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::IVec2 position3 = packet.position + tcu::IVec2(1, 1); 2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 texColor0 = m_texture.getPixel(de::clamp((position0.x() * position0.y()), 0, m_texture.getWidth()-1), 0); 2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 texColor1 = m_texture.getPixel(de::clamp((position1.x() * position1.y()), 0, m_texture.getWidth()-1), 0); 2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 texColor2 = m_texture.getPixel(de::clamp((position2.x() * position2.y()), 0, m_texture.getWidth()-1), 0); 2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 texColor3 = m_texture.getPixel(de::clamp((position3.x() * position3.y()), 0, m_texture.getWidth()-1), 0); 2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 vtxColor0 = rr::readVarying<float>(packet, context, 0, 0); 2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 vtxColor1 = rr::readVarying<float>(packet, context, 0, 1); 2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 vtxColor2 = rr::readVarying<float>(packet, context, 0, 2); 2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 vtxColor3 = rr::readVarying<float>(packet, context, 0, 3); 2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 color0 = 0.5f * (vtxColor0 + texColor0); 2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 color1 = 0.5f * (vtxColor1 + texColor1); 2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 color2 = 0.5f * (vtxColor2 + texColor2); 2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 color3 = 0.5f * (vtxColor3 + texColor3); 2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::writeFragmentOutput(context, packetNdx, 0, 0, tcu::Vec4(color0.x() * color0.w(), color0.y() * color0.w(), color0.z() * color0.w(), 1.0f)); 2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::writeFragmentOutput(context, packetNdx, 1, 0, tcu::Vec4(color1.x() * color1.w(), color1.y() * color1.w(), color1.z() * color1.w(), 1.0f)); 2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::writeFragmentOutput(context, packetNdx, 2, 0, tcu::Vec4(color2.x() * color2.w(), color2.y() * color2.w(), color2.z() * color2.w(), 1.0f)); 2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::writeFragmentOutput(context, packetNdx, 3, 0, tcu::Vec4(color3.x() * color3.w(), color3.y() * color3.w(), color3.z() * color3.w(), 1.0f)); 2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 29112fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry const tcu::ConstPixelBufferAccess m_texture; 2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystring generateVertexShaderTemplate (RenderBits renderBits) 2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::ostringstream stream; 2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << 2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "${VERSION_HEADER}\n"; 3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_VERTEX_TEXTURE) 3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "${TEXTURE_BUFFER_EXT}"; 3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << 3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "${VTX_INPUT} layout(location = 0) ${HIGHP} vec2 i_coord;\n" 3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "${VTX_OUTPUT} ${HIGHP} vec4 v_color;\n"; 3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_VERTEX_TEXTURE) 3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << 3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "uniform ${HIGHP} samplerBuffer u_vtxSampler;\n"; 3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << 3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "\n" 3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main (void)\n" 3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n"; 3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_VERTEX_TEXTURE) 3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "\tv_color = texelFetch(u_vtxSampler, clamp((int(round(i_coord.x * 4.0)) + 4) * (int(round(i_coord.y * 4.0)) + 4), 0, textureSize(u_vtxSampler)-1));\n"; 3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "\tv_color = vec4(1.0);\n"; 3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << 3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "\tgl_Position = vec4(2.0 * (i_coord - vec2(0.5)), 0.0, 1.0);\n" 3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}\n"; 3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return stream.str(); 3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystring generateFragmentShaderTemplate (RenderBits renderBits) 3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::ostringstream stream; 3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << 3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "${VERSION_HEADER}\n"; 3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_FRAGMENT_TEXTURE) 3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "${TEXTURE_BUFFER_EXT}"; 3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << 3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "${FRAG_OUTPUT} layout(location = 0) ${HIGHP} vec4 dEQP_FragColor;\n" 3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "${FRAG_INPUT} ${HIGHP} vec4 v_color;\n"; 3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_FRAGMENT_TEXTURE) 3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "uniform ${HIGHP} samplerBuffer u_fragSampler;\n"; 3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << 3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "\n" 3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main (void)\n" 3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n"; 3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_FRAGMENT_TEXTURE) 3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "\t${HIGHP} vec4 color = 0.5 * (v_color + texelFetch(u_fragSampler, clamp(int(gl_FragCoord.x) * int(gl_FragCoord.y), 0, textureSize(u_fragSampler)-1)));\n"; 3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "\t${HIGHP} vec4 color = v_color;\n"; 3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << 3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "\tdEQP_FragColor = vec4(color.xyz * color.w, 1.0);\n" 3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}\n"; 3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return stream.str(); 3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystring specializeShader (const string& shaderTemplateString, glu::GLSLVersion glslVersion) 3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::StringTemplate shaderTemplate(shaderTemplateString); 3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry map<string, string> parameters; 3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry parameters["VERSION_HEADER"] = glu::getGLSLVersionDeclaration(glslVersion); 3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry parameters["VTX_OUTPUT"] = "out"; 3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry parameters["VTX_INPUT"] = "in"; 3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry parameters["FRAG_INPUT"] = "in"; 3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry parameters["FRAG_OUTPUT"] = "out"; 3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry parameters["HIGHP"] = (glslVersion == glu::GLSL_VERSION_330 ? "" : "highp"); 3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry parameters["TEXTURE_BUFFER_EXT"] = (glslVersion == glu::GLSL_VERSION_330 ? "" : "#extension GL_EXT_texture_buffer : enable\n"); 3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return shaderTemplate.specialize(parameters); 3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyryglu::ShaderProgram* createRenderProgram (glu::RenderContext& renderContext, 3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RenderBits renderBits) 3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const string vertexShaderTemplate = generateVertexShaderTemplate(renderBits); 3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const string fragmentShaderTemplate = generateFragmentShaderTemplate(renderBits); 3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glu::GLSLVersion glslVersion = glu::getContextTypeGLSLVersion(renderContext.getType()); 3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const string vertexShaderSource = specializeShader(vertexShaderTemplate, glslVersion); 3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const string fragmentShaderSource = specializeShader(fragmentShaderTemplate, glslVersion); 3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ShaderProgram* const program = new glu::ShaderProgram(renderContext, glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource)); 3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return program; 3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid logModifications (TestLog& log, ModifyBits modifyBits) 3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::ScopedLogSection section(log, "Modify Operations", "Modify Operations"); 4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const struct 4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ModifyBits bit; 4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* str; 4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } bitInfos[] = 4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { MODIFYBITS_BUFFERDATA, "Recreate buffer data with glBufferData()." }, 4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { MODIFYBITS_BUFFERSUBDATA, "Modify texture buffer with glBufferSubData()." }, 4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { MODIFYBITS_MAPBUFFER_WRITE, "Map buffer write-only and rewrite data." }, 4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { MODIFYBITS_MAPBUFFER_READWRITE, "Map buffer readw-write check and rewrite data." } 4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(modifyBits != 0); 4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int infoNdx = 0; infoNdx < DE_LENGTH_OF_ARRAY(bitInfos); infoNdx++) 4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (modifyBits & bitInfos[infoNdx].bit) 4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << bitInfos[infoNdx].str << TestLog::EndMessage; 4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid modifyBufferData (TestLog& log, 4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random& rng, 4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::TextureBuffer& texture) 4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<deUint8> data; 4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry genRandomCoords(rng, data, 0, texture.getBufferSize()); 4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "BufferData, Size: " << data.size() << TestLog::EndMessage; 4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 43212fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry { 43312fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry // replace getRefBuffer with a new buffer 43412fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry de::ArrayBuffer<deUint8> buffer(&(data[0]), data.size()); 43512fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry texture.getRefBuffer().swap(buffer); 43612fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry } 43712fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry 4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry texture.upload(); 4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid modifyBufferSubData (TestLog& log, 4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random& rng, 4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl, 4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::TextureBuffer& texture) 4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t minSize = 4*16; 447c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry const size_t size = de::max<size_t>(minSize, size_t((float)(texture.getSize() != 0 ? texture.getSize() : texture.getBufferSize()) * (0.7f + 0.3f * rng.getFloat()))); 4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t minOffset = texture.getOffset(); 4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t offset = minOffset + (rng.getUint32() % (texture.getBufferSize() - (size + minOffset))); 4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<deUint8> data; 4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry genRandomCoords(rng, data, offset, size); 4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "BufferSubData, Offset: " << offset << ", Size: " << size << TestLog::EndMessage; 4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_TEXTURE_BUFFER, texture.getGLBuffer()); 4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferSubData(GL_TEXTURE_BUFFER, (glw::GLsizei)offset, (glw::GLsizei)data.size(), &(data[0])); 4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_TEXTURE_BUFFER, 0); 4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to update data with glBufferSubData()"); 4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 46112fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry deMemcpy((deUint8*)texture.getRefBuffer().getPtr() + offset, &(data[0]), int(data.size())); 4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid modifyMapWrite (TestLog& log, 4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random& rng, 4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl, 4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::TextureBuffer& texture) 4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t minSize = 4*16; 470c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry const size_t size = de::max<size_t>(minSize, size_t((float)(texture.getSize() != 0 ? texture.getSize() : texture.getBufferSize()) * (0.7f + 0.3f * rng.getFloat()))); 4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t minOffset = texture.getOffset(); 4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t offset = minOffset + (rng.getUint32() % (texture.getBufferSize() - (size + minOffset))); 4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<deUint8> data; 4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry genRandomCoords(rng, data, offset, size); 4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "glMapBufferRange, Write Only, Offset: " << offset << ", Size: " << size << TestLog::EndMessage; 4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_TEXTURE_BUFFER, texture.getGLBuffer()); 4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint8* ptr = (deUint8*)gl.mapBufferRange(GL_TEXTURE_BUFFER, (glw::GLsizei)offset, (glw::GLsizei)size, GL_MAP_WRITE_BIT); 4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glMapBufferRange()"); 4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(ptr); 4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < (int)data.size(); i++) 4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ptr[i] = data[i]; 4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(gl.unmapBuffer(GL_TEXTURE_BUFFER)); 4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_TEXTURE_BUFFER, 0); 4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to update data with glMapBufferRange()"); 4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 49412fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry deMemcpy((deUint8*)texture.getRefBuffer().getPtr()+offset, &(data[0]), int(data.size())); 4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid modifyMapReadWrite (TestLog& log, 4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::ResultCollector& resultCollector, 4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random& rng, 5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl, 5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::TextureBuffer& texture) 5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t minSize = 4*16; 504c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry const size_t size = de::max<size_t>(minSize, size_t((float)(texture.getSize() != 0 ? texture.getSize() : texture.getBufferSize()) * (0.7f + 0.3f * rng.getFloat()))); 5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t minOffset = texture.getOffset(); 5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t offset = minOffset + (rng.getUint32() % (texture.getBufferSize() - (size + minOffset))); 50712fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry deUint8* const refPtr = (deUint8*)texture.getRefBuffer().getPtr() + offset; 5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<deUint8> data; 5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry genRandomCoords(rng, data, offset, size); 5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "glMapBufferRange, Read Write, Offset: " << offset << ", Size: " << size << TestLog::EndMessage; 5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_TEXTURE_BUFFER, texture.getGLBuffer()); 5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t invalidBytes = 0; 5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint8* const ptr = (deUint8*)gl.mapBufferRange(GL_TEXTURE_BUFFER, (glw::GLsizei)offset, (glw::GLsizei)size, GL_MAP_WRITE_BIT|GL_MAP_READ_BIT); 5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glMapBufferRange()"); 5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(ptr); 5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < (int)data.size(); i++) 5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 52412fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry if (ptr[i] != refPtr[i]) 5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (invalidBytes < 24) 52712fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry log << TestLog::Message << "Invalid byte in mapped buffer. " << tcu::Format::Hex<2>(data[i]).toString() << " at " << i << ", expected " << tcu::Format::Hex<2>(refPtr[i]).toString() << TestLog::EndMessage; 5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry invalidBytes++; 5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ptr[i] = data[i]; 5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(gl.unmapBuffer(GL_TEXTURE_BUFFER)); 5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (invalidBytes > 0) 5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "Total of " << invalidBytes << " invalid bytes." << TestLog::EndMessage; 5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry resultCollector.fail("Invalid data in mapped buffer"); 5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_TEXTURE_BUFFER, 0); 5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to update data with glMapBufferRange()"); 5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < (int)data.size(); i++) 54812fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry refPtr[i] = data[i]; 5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid modify (TestLog& log, 5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::ResultCollector& resultCollector, 5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::RenderContext& renderContext, 5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ModifyBits modifyBits, 5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random& rng, 5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::TextureBuffer& texture) 5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::ScopedLogSection modifySection(log, "Modifying Texture buffer", "Modifying Texture Buffer"); 5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry logModifications(log, modifyBits); 5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (modifyBits & MODIFYBITS_BUFFERDATA) 5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry modifyBufferData(log, rng, texture); 5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (modifyBits & MODIFYBITS_BUFFERSUBDATA) 5663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry modifyBufferSubData(log, rng, renderContext.getFunctions(), texture); 5673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (modifyBits & MODIFYBITS_MAPBUFFER_WRITE) 5693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry modifyMapWrite(log, rng, renderContext.getFunctions(), texture); 5703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (modifyBits & MODIFYBITS_MAPBUFFER_READWRITE) 5723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry modifyMapReadWrite(log, resultCollector, rng, renderContext.getFunctions(), texture); 5733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5753c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid renderGL (glu::RenderContext& renderContext, 5763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RenderBits renderBits, 5773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 coordSeed, 5783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int triangleCount, 5793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ShaderProgram& program, 5803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::TextureBuffer& texture) 5813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = renderContext.getFunctions(); 5833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glu::VertexArray vao (renderContext); 5843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glu::Buffer coordBuffer (renderContext); 5853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.useProgram(program.getProgram()); 5873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindVertexArray(*vao); 5883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.enableVertexAttribArray(0); 5903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_VERTEX_ARRAY) 5923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_ARRAY_BUFFER, texture.getGLBuffer()); 5943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.vertexAttribPointer(0, 2, GL_UNSIGNED_BYTE, true, 0, DE_NULL); 5953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 5973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random rng(coordSeed); 5993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<deUint8> coords; 6003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry genRandomCoords(rng, coords, 0, 256*2); 6023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_ARRAY_BUFFER, *coordBuffer); 6043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bufferData(GL_ARRAY_BUFFER, (glw::GLsizei)coords.size(), &(coords[0]), GL_STREAM_DRAW); 6053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.vertexAttribPointer(0, 2, GL_UNSIGNED_BYTE, true, 0, DE_NULL); 6063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_VERTEX_TEXTURE) 6093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deInt32 location = gl.getUniformLocation(program.getProgram(), "u_vtxSampler"); 6113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.activeTexture(GL_TEXTURE0); 6133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_BUFFER, texture.getGLTexture()); 6143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.uniform1i(location, 0); 6153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_FRAGMENT_TEXTURE) 6183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deInt32 location = gl.getUniformLocation(program.getProgram(), "u_fragSampler"); 6203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.activeTexture(GL_TEXTURE1); 6223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_BUFFER, texture.getGLTexture()); 6233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.uniform1i(location, 1); 6243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.activeTexture(GL_TEXTURE0); 6253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_INDEX_ARRAY) 6283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, texture.getGLBuffer()); 6303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.drawElements(GL_TRIANGLES, triangleCount * 3, GL_UNSIGNED_BYTE, DE_NULL); 6313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 6323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 6343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.drawArrays(GL_TRIANGLES, 0, triangleCount * 3); 6353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_FRAGMENT_TEXTURE) 6373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.activeTexture(GL_TEXTURE1); 6393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_BUFFER, 0); 6403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_VERTEX_TEXTURE) 6433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.activeTexture(GL_TEXTURE0); 6453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_BUFFER, 0); 6463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindBuffer(GL_ARRAY_BUFFER, 0); 6493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.disableVertexAttribArray(0); 6503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindVertexArray(0); 6523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.useProgram(0); 6533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Rendering failed"); 6543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6563c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid renderReference (RenderBits renderBits, 6573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 coordSeed, 6583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int triangleCount, 65912fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry const glu::TextureBuffer& texture, 66012fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry int maxTextureBufferSize, 6613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::PixelBufferAccess& target) 6623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 66312fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry const tcu::ConstPixelBufferAccess effectiveAccess = glu::getTextureBufferEffectiveRefTexture(texture, maxTextureBufferSize); 66412fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry 66512fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry const CoordVertexShader coordVertexShader; 66612fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry const TextureVertexShader textureVertexShader (effectiveAccess); 66712fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry const rr::VertexShader* const vertexShader = (renderBits & RENDERBITS_AS_VERTEX_TEXTURE ? static_cast<const rr::VertexShader*>(&textureVertexShader) : &coordVertexShader); 6683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 66912fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry const CoordFragmentShader coordFragmmentShader; 67012fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry const TextureFragmentShader textureFragmentShader (effectiveAccess); 67112fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry const rr::FragmentShader* const fragmentShader = (renderBits & RENDERBITS_AS_FRAGMENT_TEXTURE ? static_cast<const rr::FragmentShader*>(&textureFragmentShader) : &coordFragmmentShader); 6723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 67312fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry const rr::Renderer renderer; 67412fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry const rr::RenderState renderState(rr::ViewportState(rr::WindowRectangle(0, 0, target.getWidth(), target.getHeight()))); 67512fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry const rr::RenderTarget renderTarget(rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(target)); 6763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 67712fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry const rr::Program program(vertexShader, fragmentShader); 6783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 67912fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry rr::VertexAttrib vertexAttribs[1]; 68012fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry vector<deUint8> coords; 6813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_VERTEX_ARRAY) 6833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vertexAttribs[0].type = rr::VERTEXATTRIBTYPE_NONPURE_UNORM8; 6853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vertexAttribs[0].size = 2; 68612fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry vertexAttribs[0].pointer = texture.getRefBuffer().getPtr(); 6873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 6893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random rng(coordSeed); 6913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry genRandomCoords(rng, coords, 0, 256*2); 6933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vertexAttribs[0].type = rr::VERTEXATTRIBTYPE_NONPURE_UNORM8; 6953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vertexAttribs[0].size = 2; 6963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vertexAttribs[0].pointer = &(coords[0]); 6973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & RENDERBITS_AS_INDEX_ARRAY) 7003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 70112fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry const rr::PrimitiveList primitives(rr::PRIMITIVETYPE_TRIANGLES, triangleCount * 3, rr::DrawIndices(texture.getRefBuffer().getPtr(), rr::INDEXTYPE_UINT8)); 7023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const rr::DrawCommand cmd(renderState, renderTarget, program, 1, vertexAttribs, primitives); 7033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry renderer.draw(cmd); 7053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 7063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 7073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const rr::PrimitiveList primitives(rr::PRIMITIVETYPE_TRIANGLES, triangleCount * 3, 0); 7093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const rr::DrawCommand cmd(renderState, renderTarget, program, 1, vertexAttribs, primitives); 7103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry renderer.draw(cmd); 7123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 7133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7153c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid logRendering (TestLog& log, RenderBits renderBits) 7163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const struct 7183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RenderBits bit; 7203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* str; 7213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } bitInfos[] = 7223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { RENDERBITS_AS_VERTEX_ARRAY, "vertex array" }, 7243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { RENDERBITS_AS_INDEX_ARRAY, "index array" }, 7253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { RENDERBITS_AS_VERTEX_TEXTURE, "vertex texture" }, 7263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { RENDERBITS_AS_FRAGMENT_TEXTURE, "fragment texture" } 7273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 7283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::ostringstream stream; 7303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<const char*> usedAs; 7313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(renderBits != 0); 7333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int infoNdx = 0; infoNdx < DE_LENGTH_OF_ARRAY(bitInfos); infoNdx++) 7353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (renderBits & bitInfos[infoNdx].bit) 7373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry usedAs.push_back(bitInfos[infoNdx].str); 7383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 7393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "Render using texture buffer as "; 7413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int asNdx = 0; asNdx < (int)usedAs.size(); asNdx++) 7433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (asNdx+1 == (int)usedAs.size() && (int)usedAs.size() > 1) 7453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << " and "; 7463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (asNdx > 0) 7473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << ", "; 7483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << usedAs[asNdx]; 7503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 7513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry stream << "."; 7533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << stream.str() << TestLog::EndMessage; 7553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7573c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid render (TestLog& log, 7583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::RenderContext& renderContext, 7593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RenderBits renderBits, 7603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random& rng, 7613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ShaderProgram& program, 7623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::TextureBuffer& texture, 7633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::PixelBufferAccess& target) 7643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 76512fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry const tcu::ScopedLogSection renderSection (log, "Render Texture buffer", "Render Texture Buffer"); 76612fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry const int triangleCount = 8; 76712fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry const deUint32 coordSeed = rng.getUint32(); 76812fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry int maxTextureBufferSize = 0; 76912fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry 77012fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry renderContext.getFunctions().getIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &maxTextureBufferSize); 77112fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry GLU_EXPECT_NO_ERROR(renderContext.getFunctions().getError(), "query GL_MAX_TEXTURE_BUFFER_SIZE"); 77212fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry DE_ASSERT(maxTextureBufferSize > 0); // checked in init() 7733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry logRendering(log, renderBits); 7753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry renderGL(renderContext, renderBits, coordSeed, triangleCount, program, texture); 77712fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry renderReference(renderBits, coordSeed, triangleCount, texture, maxTextureBufferSize, target); 7783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7803c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid verifyScreen (TestLog& log, 7813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::ResultCollector& resultCollector, 7823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::RenderContext& renderContext, 7833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::ConstPixelBufferAccess& referenceTarget) 7843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::ScopedLogSection verifySection (log, "Verify screen contents", "Verify screen contents"); 7863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface screen (referenceTarget.getWidth(), referenceTarget.getHeight()); 7873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::readPixels(renderContext, 0, 0, screen.getAccess()); 7893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!tcu::fuzzyCompare(log, "Result of rendering", "Result of rendering", referenceTarget, screen.getAccess(), 0.05f, tcu::COMPARE_LOG_RESULT)) 7913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry resultCollector.fail("Rendering failed"); 7923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7943c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid logImplementationInfo (TestLog& log, glu::RenderContext& renderContext) 7953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::ScopedLogSection section (log, "Implementation Values", "Implementation Values"); 7973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::UniquePtr<glu::ContextInfo> info (glu::ContextInfo::create(renderContext)); 7983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = renderContext.getFunctions(); 7993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (glu::contextSupports(renderContext.getType(), glu::ApiType(3, 3, glu::PROFILE_CORE))) 8013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8027a2ea3f817e3acb0bcdc4d5e66e714d541bd648fJarkko Pöyry deInt32 maxTextureSize = 0; 8033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.getIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &maxTextureSize); 8053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE)"); 8063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "GL_MAX_TEXTURE_BUFFER_SIZE : " << maxTextureSize << TestLog::EndMessage; 8083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (glu::contextSupports(renderContext.getType(), glu::ApiType(3, 1, glu::PROFILE_ES)) && info->isExtensionSupported("GL_EXT_texture_buffer")) 8103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8127a2ea3f817e3acb0bcdc4d5e66e714d541bd648fJarkko Pöyry deInt32 maxTextureSize = 0; 8133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.getIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &maxTextureSize); 8153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE_EXT)"); 8163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "GL_MAX_TEXTURE_BUFFER_SIZE_EXT : " << maxTextureSize << TestLog::EndMessage; 8183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8217a2ea3f817e3acb0bcdc4d5e66e714d541bd648fJarkko Pöyry deInt32 textureBufferAlignment = 0; 8223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.getIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, &textureBufferAlignment); 8243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT_EXT)"); 8253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT_EXT : " << textureBufferAlignment << TestLog::EndMessage; 8273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 8303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(DE_FALSE); 8313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 8323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8333c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid logTextureInfo (TestLog& log, 8343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 format, 8353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t bufferSize, 8363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t offset, 8373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t size) 8383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 8393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::ScopedLogSection section(log, "Texture Info", "Texture Info"); 8403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 841b2e583dfcd8aa0d4ef254f841213fcf724b2b193Jarkko Pöyry log << TestLog::Message << "Texture format : " << glu::getTextureFormatStr(format) << TestLog::EndMessage; 8423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "Buffer size : " << bufferSize << TestLog::EndMessage; 8433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (offset != 0 || size != 0) 8453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "Buffer range offset: " << offset << TestLog::EndMessage; 8473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << "Buffer range size: " << size << TestLog::EndMessage; 8483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 8503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8513c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid runTests (tcu::TestContext& testCtx, 8523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::RenderContext& renderContext, 8533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random& rng, 8543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 format, 8553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t bufferSize, 8563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t offset, 8573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t size, 8583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RenderBits preRender, 8593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ShaderProgram* preRenderProgram, 8603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ModifyBits modifyType, 8613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RenderBits postRender, 8623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ShaderProgram* postRenderProgram) 8633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 8643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::RenderTarget renderTarget (renderContext.getRenderTarget()); 8653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = renderContext.getFunctions(); 8663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int width = de::min<int>(renderTarget.getWidth(), MAX_VIEWPORT_WIDTH); 8683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int height = de::min<int>(renderTarget.getHeight(), MAX_VIEWPORT_HEIGHT); 8693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 clearColor (0.25f, 0.5f, 0.75f, 1.0f); 8703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestLog& log = testCtx.getLog(); 8723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::ResultCollector resultCollector (log); 8733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry logImplementationInfo(log, renderContext); 8753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry logTextureInfo(log, format, bufferSize, offset, size); 8763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface referenceTarget (width, height); 8793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<deUint8> bufferData; 8803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry genRandomCoords(rng, bufferData, 0, bufferSize); 8823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (deUint8 i = 0; i < 4; i++) 8843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint8 val = extend2BitsToByte(i); 8863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (val >= offset && val < offset + size) 8883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bufferData[val*2 + 0] = (i / 2 == 0 ? extend2BitsToByte(0x2u) : extend2BitsToByte(0x01u)); 8903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bufferData[val*2 + 1] = (i % 2 == 0 ? extend2BitsToByte(0x2u) : extend2BitsToByte(0x01u)); 8913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::TextureBuffer texture (renderContext, format, bufferSize, offset, size, &(bufferData[0])); 8963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK_MSG(width >= MIN_VIEWPORT_WIDTH || height >= MIN_VIEWPORT_HEIGHT, "Too small viewport"); 8983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(preRender == 0 || preRenderProgram); 9003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(postRender == 0 || postRenderProgram); 9013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.viewport(0, 0, width, height); 9033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.clearColor(clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w()); 9043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.clear(GL_COLOR_BUFFER_BIT); 9053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Screen setup failed"); 9063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::clear(referenceTarget.getAccess(), clearColor); 9083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry texture.upload(); 9103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (preRender != 0) 9123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry render(log, renderContext, preRender, rng, *preRenderProgram, texture, referenceTarget.getAccess()); 9133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (modifyType != 0) 9153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry modify(log, resultCollector, renderContext, modifyType, rng, texture); 9163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (postRender != 0) 9183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry render(log, renderContext, postRender, rng, *postRenderProgram, texture, referenceTarget.getAccess()); 9193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry verifyScreen(log, resultCollector, renderContext, referenceTarget.getAccess()); 9223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry resultCollector.setTestContextResult(testCtx); 9243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 9263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // anonymous 9283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9293c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureBufferCase::TextureBufferCase (tcu::TestContext& testCtx, 9303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::RenderContext& renderCtx, 9313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 format, 9323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t bufferSize, 9333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t offset, 9343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t size, 9353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RenderBits preRender, 9363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ModifyBits modify, 9373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RenderBits postRender, 9383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* name, 9393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* description) 9403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : tcu::TestCase (testCtx, name, description) 9413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_renderCtx (renderCtx) 9423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (format) 9433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_bufferSize (bufferSize) 9443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_offset (offset) 9453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_size (size) 9463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_preRender (preRender) 9483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_modify (modify) 9493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_postRender (postRender) 9503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_preRenderProgram (DE_NULL) 9523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_postRenderProgram (DE_NULL) 9533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 9543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 9553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9563c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureBufferCase::~TextureBufferCase (void) 9573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 9583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureBufferCase::deinit(); 9593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 9603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9613c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureBufferCase::init (void) 9623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 9633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::UniquePtr<glu::ContextInfo> info (glu::ContextInfo::create(m_renderCtx)); 9643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!glu::contextSupports(m_renderCtx.getType(), glu::ApiType(3, 3, glu::PROFILE_CORE)) 9663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry && !(glu::contextSupports(m_renderCtx.getType(), glu::ApiType(3, 1, glu::PROFILE_ES)) && info->isExtensionSupported("GL_EXT_texture_buffer"))) 9673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("Texture buffers not supported", "", __FILE__, __LINE__); 9683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 96912fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry { 97012fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry const int maxTextureBufferSize = info->getInt(GL_MAX_TEXTURE_BUFFER_SIZE); 97112fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry if (maxTextureBufferSize <= 0) 97212fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry TCU_THROW(NotSupportedError, "GL_MAX_TEXTURE_BUFFER_SIZE > 0 required"); 97312fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry } 97412fea2ef01511716e0387c3e3dd8c4ba6ade0cc2Jarkko Pöyry 9753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_preRender != 0) 9763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestLog& log = m_testCtx.getLog(); 9783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* const sectionName = (m_postRender != 0 ? "Primary render program" : "Render program"); 9793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::ScopedLogSection section (log, sectionName, sectionName); 9803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_preRenderProgram = createRenderProgram(m_renderCtx, m_preRender); 9823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << (*m_preRenderProgram); 9833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(m_preRenderProgram->isOk()); 9853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_postRender != 0) 9883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Reusing program 9903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_preRender == m_postRender) 9913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_postRenderProgram = m_preRenderProgram; 9933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 9953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestLog& log = m_testCtx.getLog(); 9973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* const sectionName = (m_preRender!= 0 ? "Secondary render program" : "Render program"); 9983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::ScopedLogSection section (log, sectionName, sectionName); 9993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_postRenderProgram = createRenderProgram(m_renderCtx, m_postRender); 10013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << (*m_postRenderProgram); 10023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(m_postRenderProgram->isOk()); 10043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 10053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 10063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 10073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10083c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureBufferCase::deinit (void) 10093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 10103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_preRenderProgram == m_postRenderProgram) 10113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_postRenderProgram = DE_NULL; 10123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_preRenderProgram; 10143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_preRenderProgram = DE_NULL; 10153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_postRenderProgram; 10173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_postRenderProgram = DE_NULL; 10183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 10193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10203c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytcu::TestCase::IterateResult TextureBufferCase::iterate (void) 10213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 10223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random rng (deInt32Hash(deStringHash(getName()))); 10233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t offset; 10243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_offset != 0) 10263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 10273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_renderCtx.getFunctions(); 10283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deInt32 alignment = 0; 10293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.getIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, &alignment); 10313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT)"); 10323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry offset = m_offset * alignment; 10343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 10353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 10363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry offset = 0; 10373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry runTests(m_testCtx, m_renderCtx, rng, m_format, m_bufferSize, offset, m_size, m_preRender, m_preRenderProgram, m_modify, m_postRender, m_postRenderProgram); 10393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return STOP; 10413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 10423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gls 10443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp 1045