1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker * drawElements Quality Program OpenGL (ES) Module
3*35238bceSAndroid Build Coastguard Worker * -----------------------------------------------
4*35238bceSAndroid Build Coastguard Worker *
5*35238bceSAndroid Build Coastguard Worker * Copyright 2014 The Android Open Source Project
6*35238bceSAndroid Build Coastguard Worker *
7*35238bceSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker *
11*35238bceSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker *
13*35238bceSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker *
19*35238bceSAndroid Build Coastguard Worker *//*!
20*35238bceSAndroid Build Coastguard Worker * \file
21*35238bceSAndroid Build Coastguard Worker * \brief Texture buffer test case
22*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker
24*35238bceSAndroid Build Coastguard Worker #include "glsTextureBufferCase.hpp"
25*35238bceSAndroid Build Coastguard Worker
26*35238bceSAndroid Build Coastguard Worker #include "tcuFormatUtil.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "tcuImageCompare.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "tcuStringTemplate.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "tcuSurface.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "tcuTextureUtil.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "tcuResultCollector.hpp"
34*35238bceSAndroid Build Coastguard Worker
35*35238bceSAndroid Build Coastguard Worker #include "rrRenderer.hpp"
36*35238bceSAndroid Build Coastguard Worker #include "rrShaders.hpp"
37*35238bceSAndroid Build Coastguard Worker
38*35238bceSAndroid Build Coastguard Worker #include "gluObjectWrapper.hpp"
39*35238bceSAndroid Build Coastguard Worker #include "gluPixelTransfer.hpp"
40*35238bceSAndroid Build Coastguard Worker #include "gluShaderProgram.hpp"
41*35238bceSAndroid Build Coastguard Worker #include "gluShaderUtil.hpp"
42*35238bceSAndroid Build Coastguard Worker #include "gluStrUtil.hpp"
43*35238bceSAndroid Build Coastguard Worker #include "gluTexture.hpp"
44*35238bceSAndroid Build Coastguard Worker #include "gluTextureUtil.hpp"
45*35238bceSAndroid Build Coastguard Worker
46*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
47*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
48*35238bceSAndroid Build Coastguard Worker
49*35238bceSAndroid Build Coastguard Worker #include "deRandom.hpp"
50*35238bceSAndroid Build Coastguard Worker #include "deStringUtil.hpp"
51*35238bceSAndroid Build Coastguard Worker #include "deUniquePtr.hpp"
52*35238bceSAndroid Build Coastguard Worker
53*35238bceSAndroid Build Coastguard Worker #include "deMemory.h"
54*35238bceSAndroid Build Coastguard Worker #include "deString.h"
55*35238bceSAndroid Build Coastguard Worker #include "deMath.h"
56*35238bceSAndroid Build Coastguard Worker
57*35238bceSAndroid Build Coastguard Worker #include <sstream>
58*35238bceSAndroid Build Coastguard Worker #include <string>
59*35238bceSAndroid Build Coastguard Worker #include <vector>
60*35238bceSAndroid Build Coastguard Worker
61*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
62*35238bceSAndroid Build Coastguard Worker
63*35238bceSAndroid Build Coastguard Worker using std::map;
64*35238bceSAndroid Build Coastguard Worker using std::string;
65*35238bceSAndroid Build Coastguard Worker using std::vector;
66*35238bceSAndroid Build Coastguard Worker
67*35238bceSAndroid Build Coastguard Worker using namespace deqp::gls::TextureBufferCaseUtil;
68*35238bceSAndroid Build Coastguard Worker
69*35238bceSAndroid Build Coastguard Worker namespace deqp
70*35238bceSAndroid Build Coastguard Worker {
71*35238bceSAndroid Build Coastguard Worker namespace gls
72*35238bceSAndroid Build Coastguard Worker {
73*35238bceSAndroid Build Coastguard Worker namespace
74*35238bceSAndroid Build Coastguard Worker {
75*35238bceSAndroid Build Coastguard Worker
76*35238bceSAndroid Build Coastguard Worker enum
77*35238bceSAndroid Build Coastguard Worker {
78*35238bceSAndroid Build Coastguard Worker MAX_VIEWPORT_WIDTH = 256,
79*35238bceSAndroid Build Coastguard Worker MAX_VIEWPORT_HEIGHT = 256,
80*35238bceSAndroid Build Coastguard Worker MIN_VIEWPORT_WIDTH = 64,
81*35238bceSAndroid Build Coastguard Worker MIN_VIEWPORT_HEIGHT = 64,
82*35238bceSAndroid Build Coastguard Worker };
83*35238bceSAndroid Build Coastguard Worker
extend2BitsToByte(uint8_t bits)84*35238bceSAndroid Build Coastguard Worker uint8_t extend2BitsToByte(uint8_t bits)
85*35238bceSAndroid Build Coastguard Worker {
86*35238bceSAndroid Build Coastguard Worker DE_ASSERT((bits & (~0x03u)) == 0);
87*35238bceSAndroid Build Coastguard Worker
88*35238bceSAndroid Build Coastguard Worker return (uint8_t)(bits | (bits << 2) | (bits << 4) | (bits << 6));
89*35238bceSAndroid Build Coastguard Worker }
90*35238bceSAndroid Build Coastguard Worker
genRandomCoords(de::Random rng,vector<uint8_t> & coords,size_t offset,size_t size)91*35238bceSAndroid Build Coastguard Worker void genRandomCoords(de::Random rng, vector<uint8_t> &coords, size_t offset, size_t size)
92*35238bceSAndroid Build Coastguard Worker {
93*35238bceSAndroid Build Coastguard Worker const uint8_t bits = 2;
94*35238bceSAndroid Build Coastguard Worker const uint8_t bitMask = uint8_t((0x1u << bits) - 1);
95*35238bceSAndroid Build Coastguard Worker
96*35238bceSAndroid Build Coastguard Worker coords.resize(size);
97*35238bceSAndroid Build Coastguard Worker
98*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)size; i++)
99*35238bceSAndroid Build Coastguard Worker {
100*35238bceSAndroid Build Coastguard Worker const uint8_t xBits = uint8_t(rng.getUint32() & bitMask);
101*35238bceSAndroid Build Coastguard Worker coords[i] = extend2BitsToByte(xBits);
102*35238bceSAndroid Build Coastguard Worker }
103*35238bceSAndroid Build Coastguard Worker
104*35238bceSAndroid Build Coastguard Worker // Fill indices with nice quad
105*35238bceSAndroid Build Coastguard Worker {
106*35238bceSAndroid Build Coastguard Worker const uint8_t indices[] = {extend2BitsToByte(0x0u), extend2BitsToByte(0x1u), extend2BitsToByte(0x2u),
107*35238bceSAndroid Build Coastguard Worker extend2BitsToByte(0x3u)};
108*35238bceSAndroid Build Coastguard Worker
109*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < DE_LENGTH_OF_ARRAY(indices); i++)
110*35238bceSAndroid Build Coastguard Worker {
111*35238bceSAndroid Build Coastguard Worker const uint8_t index = indices[i];
112*35238bceSAndroid Build Coastguard Worker const size_t posX = (size_t(index) * 2) + 0;
113*35238bceSAndroid Build Coastguard Worker const size_t posY = (size_t(index) * 2) + 1;
114*35238bceSAndroid Build Coastguard Worker
115*35238bceSAndroid Build Coastguard Worker if (posX >= offset && posX < offset + size)
116*35238bceSAndroid Build Coastguard Worker coords[posX - offset] = ((i % 2) == 0 ? extend2BitsToByte(0x0u) : extend2BitsToByte(0x3u));
117*35238bceSAndroid Build Coastguard Worker
118*35238bceSAndroid Build Coastguard Worker if (posY >= offset && posY < offset + size)
119*35238bceSAndroid Build Coastguard Worker coords[posY - offset] = ((i / 2) == 1 ? extend2BitsToByte(0x3u) : extend2BitsToByte(0x0u));
120*35238bceSAndroid Build Coastguard Worker }
121*35238bceSAndroid Build Coastguard Worker }
122*35238bceSAndroid Build Coastguard Worker
123*35238bceSAndroid Build Coastguard Worker // Fill beginning of buffer
124*35238bceSAndroid Build Coastguard Worker {
125*35238bceSAndroid Build Coastguard Worker const uint8_t indices[] = {extend2BitsToByte(0x0u), extend2BitsToByte(0x3u), extend2BitsToByte(0x1u),
126*35238bceSAndroid Build Coastguard Worker
127*35238bceSAndroid Build Coastguard Worker extend2BitsToByte(0x1u), extend2BitsToByte(0x2u), extend2BitsToByte(0x0u),
128*35238bceSAndroid Build Coastguard Worker
129*35238bceSAndroid Build Coastguard Worker extend2BitsToByte(0x0u), extend2BitsToByte(0x2u), extend2BitsToByte(0x1u),
130*35238bceSAndroid Build Coastguard Worker
131*35238bceSAndroid Build Coastguard Worker extend2BitsToByte(0x1u), extend2BitsToByte(0x3u), extend2BitsToByte(0x0u)};
132*35238bceSAndroid Build Coastguard Worker
133*35238bceSAndroid Build Coastguard Worker for (int i = (int)offset; i < DE_LENGTH_OF_ARRAY(indices) && i < (int)(offset + size); i++)
134*35238bceSAndroid Build Coastguard Worker coords[i - offset] = indices[i];
135*35238bceSAndroid Build Coastguard Worker }
136*35238bceSAndroid Build Coastguard Worker }
137*35238bceSAndroid Build Coastguard Worker
138*35238bceSAndroid Build Coastguard Worker class CoordVertexShader : public rr::VertexShader
139*35238bceSAndroid Build Coastguard Worker {
140*35238bceSAndroid Build Coastguard Worker public:
CoordVertexShader(void)141*35238bceSAndroid Build Coastguard Worker CoordVertexShader(void) : rr::VertexShader(1, 1)
142*35238bceSAndroid Build Coastguard Worker {
143*35238bceSAndroid Build Coastguard Worker m_inputs[0].type = rr::GENERICVECTYPE_FLOAT;
144*35238bceSAndroid Build Coastguard Worker m_outputs[0].type = rr::GENERICVECTYPE_FLOAT;
145*35238bceSAndroid Build Coastguard Worker }
146*35238bceSAndroid Build Coastguard Worker
shadeVertices(const rr::VertexAttrib * inputs,rr::VertexPacket * const * packets,const int numPackets) const147*35238bceSAndroid Build Coastguard Worker void shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets, const int numPackets) const
148*35238bceSAndroid Build Coastguard Worker {
149*35238bceSAndroid Build Coastguard Worker for (int packetNdx = 0; packetNdx < numPackets; packetNdx++)
150*35238bceSAndroid Build Coastguard Worker {
151*35238bceSAndroid Build Coastguard Worker rr::VertexPacket *const packet = packets[packetNdx];
152*35238bceSAndroid Build Coastguard Worker tcu::Vec4 position;
153*35238bceSAndroid Build Coastguard Worker
154*35238bceSAndroid Build Coastguard Worker readVertexAttrib(position, inputs[0], packet->instanceNdx, packet->vertexNdx);
155*35238bceSAndroid Build Coastguard Worker
156*35238bceSAndroid Build Coastguard Worker packet->outputs[0] = tcu::Vec4(1.0f);
157*35238bceSAndroid Build Coastguard Worker packet->position = tcu::Vec4(2.0f * (position.x() - 0.5f), 2.0f * (position.y() - 0.5f), 0.0f, 1.0f);
158*35238bceSAndroid Build Coastguard Worker }
159*35238bceSAndroid Build Coastguard Worker }
160*35238bceSAndroid Build Coastguard Worker };
161*35238bceSAndroid Build Coastguard Worker
162*35238bceSAndroid Build Coastguard Worker class TextureVertexShader : public rr::VertexShader
163*35238bceSAndroid Build Coastguard Worker {
164*35238bceSAndroid Build Coastguard Worker public:
TextureVertexShader(const tcu::ConstPixelBufferAccess & texture)165*35238bceSAndroid Build Coastguard Worker TextureVertexShader(const tcu::ConstPixelBufferAccess &texture) : rr::VertexShader(1, 1), m_texture(texture)
166*35238bceSAndroid Build Coastguard Worker {
167*35238bceSAndroid Build Coastguard Worker m_inputs[0].type = rr::GENERICVECTYPE_FLOAT;
168*35238bceSAndroid Build Coastguard Worker m_outputs[0].type = rr::GENERICVECTYPE_FLOAT;
169*35238bceSAndroid Build Coastguard Worker }
170*35238bceSAndroid Build Coastguard Worker
shadeVertices(const rr::VertexAttrib * inputs,rr::VertexPacket * const * packets,const int numPackets) const171*35238bceSAndroid Build Coastguard Worker void shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets, const int numPackets) const
172*35238bceSAndroid Build Coastguard Worker {
173*35238bceSAndroid Build Coastguard Worker for (int packetNdx = 0; packetNdx < numPackets; packetNdx++)
174*35238bceSAndroid Build Coastguard Worker {
175*35238bceSAndroid Build Coastguard Worker rr::VertexPacket *const packet = packets[packetNdx];
176*35238bceSAndroid Build Coastguard Worker tcu::Vec4 position;
177*35238bceSAndroid Build Coastguard Worker tcu::Vec4 texelValue;
178*35238bceSAndroid Build Coastguard Worker
179*35238bceSAndroid Build Coastguard Worker readVertexAttrib(position, inputs[0], packet->instanceNdx, packet->vertexNdx);
180*35238bceSAndroid Build Coastguard Worker
181*35238bceSAndroid Build Coastguard Worker texelValue = tcu::Vec4(m_texture.getPixel(de::clamp<int>((deRoundFloatToInt32(position.x() * 4) + 4) *
182*35238bceSAndroid Build Coastguard Worker (deRoundFloatToInt32(position.y() * 4) + 4),
183*35238bceSAndroid Build Coastguard Worker 0, m_texture.getWidth() - 1),
184*35238bceSAndroid Build Coastguard Worker 0));
185*35238bceSAndroid Build Coastguard Worker
186*35238bceSAndroid Build Coastguard Worker packet->outputs[0] = texelValue;
187*35238bceSAndroid Build Coastguard Worker packet->position = tcu::Vec4(2.0f * (position.x() - 0.5f), 2.0f * (position.y() - 0.5f), 0.0f, 1.0f);
188*35238bceSAndroid Build Coastguard Worker }
189*35238bceSAndroid Build Coastguard Worker }
190*35238bceSAndroid Build Coastguard Worker
191*35238bceSAndroid Build Coastguard Worker private:
192*35238bceSAndroid Build Coastguard Worker const tcu::ConstPixelBufferAccess m_texture;
193*35238bceSAndroid Build Coastguard Worker };
194*35238bceSAndroid Build Coastguard Worker
195*35238bceSAndroid Build Coastguard Worker class CoordFragmentShader : public rr::FragmentShader
196*35238bceSAndroid Build Coastguard Worker {
197*35238bceSAndroid Build Coastguard Worker public:
CoordFragmentShader(void)198*35238bceSAndroid Build Coastguard Worker CoordFragmentShader(void) : rr::FragmentShader(1, 1)
199*35238bceSAndroid Build Coastguard Worker {
200*35238bceSAndroid Build Coastguard Worker m_inputs[0].type = rr::GENERICVECTYPE_FLOAT;
201*35238bceSAndroid Build Coastguard Worker m_outputs[0].type = rr::GENERICVECTYPE_FLOAT;
202*35238bceSAndroid Build Coastguard Worker }
203*35238bceSAndroid Build Coastguard Worker
shadeFragments(rr::FragmentPacket * packets,const int numPackets,const rr::FragmentShadingContext & context) const204*35238bceSAndroid Build Coastguard Worker void shadeFragments(rr::FragmentPacket *packets, const int numPackets,
205*35238bceSAndroid Build Coastguard Worker const rr::FragmentShadingContext &context) const
206*35238bceSAndroid Build Coastguard Worker {
207*35238bceSAndroid Build Coastguard Worker for (int packetNdx = 0; packetNdx < numPackets; packetNdx++)
208*35238bceSAndroid Build Coastguard Worker {
209*35238bceSAndroid Build Coastguard Worker rr::FragmentPacket &packet = packets[packetNdx];
210*35238bceSAndroid Build Coastguard Worker
211*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 vtxColor0 = rr::readVarying<float>(packet, context, 0, 0);
212*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 vtxColor1 = rr::readVarying<float>(packet, context, 0, 1);
213*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 vtxColor2 = rr::readVarying<float>(packet, context, 0, 2);
214*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 vtxColor3 = rr::readVarying<float>(packet, context, 0, 3);
215*35238bceSAndroid Build Coastguard Worker
216*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 color0 = vtxColor0;
217*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 color1 = vtxColor1;
218*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 color2 = vtxColor2;
219*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 color3 = vtxColor3;
220*35238bceSAndroid Build Coastguard Worker
221*35238bceSAndroid Build Coastguard Worker rr::writeFragmentOutput(
222*35238bceSAndroid Build Coastguard Worker context, packetNdx, 0, 0,
223*35238bceSAndroid Build Coastguard Worker tcu::Vec4(color0.x() * color0.w(), color0.y() * color0.w(), color0.z() * color0.w(), 1.0f));
224*35238bceSAndroid Build Coastguard Worker rr::writeFragmentOutput(
225*35238bceSAndroid Build Coastguard Worker context, packetNdx, 1, 0,
226*35238bceSAndroid Build Coastguard Worker tcu::Vec4(color1.x() * color1.w(), color1.y() * color1.w(), color1.z() * color1.w(), 1.0f));
227*35238bceSAndroid Build Coastguard Worker rr::writeFragmentOutput(
228*35238bceSAndroid Build Coastguard Worker context, packetNdx, 2, 0,
229*35238bceSAndroid Build Coastguard Worker tcu::Vec4(color2.x() * color2.w(), color2.y() * color2.w(), color2.z() * color2.w(), 1.0f));
230*35238bceSAndroid Build Coastguard Worker rr::writeFragmentOutput(
231*35238bceSAndroid Build Coastguard Worker context, packetNdx, 3, 0,
232*35238bceSAndroid Build Coastguard Worker tcu::Vec4(color3.x() * color3.w(), color3.y() * color3.w(), color3.z() * color3.w(), 1.0f));
233*35238bceSAndroid Build Coastguard Worker }
234*35238bceSAndroid Build Coastguard Worker }
235*35238bceSAndroid Build Coastguard Worker };
236*35238bceSAndroid Build Coastguard Worker
237*35238bceSAndroid Build Coastguard Worker class TextureFragmentShader : public rr::FragmentShader
238*35238bceSAndroid Build Coastguard Worker {
239*35238bceSAndroid Build Coastguard Worker public:
TextureFragmentShader(const tcu::ConstPixelBufferAccess & texture)240*35238bceSAndroid Build Coastguard Worker TextureFragmentShader(const tcu::ConstPixelBufferAccess &texture) : rr::FragmentShader(1, 1), m_texture(texture)
241*35238bceSAndroid Build Coastguard Worker {
242*35238bceSAndroid Build Coastguard Worker m_inputs[0].type = rr::GENERICVECTYPE_FLOAT;
243*35238bceSAndroid Build Coastguard Worker m_outputs[0].type = rr::GENERICVECTYPE_FLOAT;
244*35238bceSAndroid Build Coastguard Worker }
245*35238bceSAndroid Build Coastguard Worker
shadeFragments(rr::FragmentPacket * packets,const int numPackets,const rr::FragmentShadingContext & context) const246*35238bceSAndroid Build Coastguard Worker void shadeFragments(rr::FragmentPacket *packets, const int numPackets,
247*35238bceSAndroid Build Coastguard Worker const rr::FragmentShadingContext &context) const
248*35238bceSAndroid Build Coastguard Worker {
249*35238bceSAndroid Build Coastguard Worker for (int packetNdx = 0; packetNdx < numPackets; packetNdx++)
250*35238bceSAndroid Build Coastguard Worker {
251*35238bceSAndroid Build Coastguard Worker rr::FragmentPacket &packet = packets[packetNdx];
252*35238bceSAndroid Build Coastguard Worker
253*35238bceSAndroid Build Coastguard Worker const tcu::IVec2 position0 = packet.position + tcu::IVec2(0, 0);
254*35238bceSAndroid Build Coastguard Worker const tcu::IVec2 position1 = packet.position + tcu::IVec2(1, 0);
255*35238bceSAndroid Build Coastguard Worker const tcu::IVec2 position2 = packet.position + tcu::IVec2(0, 1);
256*35238bceSAndroid Build Coastguard Worker const tcu::IVec2 position3 = packet.position + tcu::IVec2(1, 1);
257*35238bceSAndroid Build Coastguard Worker
258*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 texColor0 =
259*35238bceSAndroid Build Coastguard Worker m_texture.getPixel(de::clamp((position0.x() * position0.y()), 0, m_texture.getWidth() - 1), 0);
260*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 texColor1 =
261*35238bceSAndroid Build Coastguard Worker m_texture.getPixel(de::clamp((position1.x() * position1.y()), 0, m_texture.getWidth() - 1), 0);
262*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 texColor2 =
263*35238bceSAndroid Build Coastguard Worker m_texture.getPixel(de::clamp((position2.x() * position2.y()), 0, m_texture.getWidth() - 1), 0);
264*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 texColor3 =
265*35238bceSAndroid Build Coastguard Worker m_texture.getPixel(de::clamp((position3.x() * position3.y()), 0, m_texture.getWidth() - 1), 0);
266*35238bceSAndroid Build Coastguard Worker
267*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 vtxColor0 = rr::readVarying<float>(packet, context, 0, 0);
268*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 vtxColor1 = rr::readVarying<float>(packet, context, 0, 1);
269*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 vtxColor2 = rr::readVarying<float>(packet, context, 0, 2);
270*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 vtxColor3 = rr::readVarying<float>(packet, context, 0, 3);
271*35238bceSAndroid Build Coastguard Worker
272*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 color0 = 0.5f * (vtxColor0 + texColor0);
273*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 color1 = 0.5f * (vtxColor1 + texColor1);
274*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 color2 = 0.5f * (vtxColor2 + texColor2);
275*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 color3 = 0.5f * (vtxColor3 + texColor3);
276*35238bceSAndroid Build Coastguard Worker
277*35238bceSAndroid Build Coastguard Worker rr::writeFragmentOutput(
278*35238bceSAndroid Build Coastguard Worker context, packetNdx, 0, 0,
279*35238bceSAndroid Build Coastguard Worker tcu::Vec4(color0.x() * color0.w(), color0.y() * color0.w(), color0.z() * color0.w(), 1.0f));
280*35238bceSAndroid Build Coastguard Worker rr::writeFragmentOutput(
281*35238bceSAndroid Build Coastguard Worker context, packetNdx, 1, 0,
282*35238bceSAndroid Build Coastguard Worker tcu::Vec4(color1.x() * color1.w(), color1.y() * color1.w(), color1.z() * color1.w(), 1.0f));
283*35238bceSAndroid Build Coastguard Worker rr::writeFragmentOutput(
284*35238bceSAndroid Build Coastguard Worker context, packetNdx, 2, 0,
285*35238bceSAndroid Build Coastguard Worker tcu::Vec4(color2.x() * color2.w(), color2.y() * color2.w(), color2.z() * color2.w(), 1.0f));
286*35238bceSAndroid Build Coastguard Worker rr::writeFragmentOutput(
287*35238bceSAndroid Build Coastguard Worker context, packetNdx, 3, 0,
288*35238bceSAndroid Build Coastguard Worker tcu::Vec4(color3.x() * color3.w(), color3.y() * color3.w(), color3.z() * color3.w(), 1.0f));
289*35238bceSAndroid Build Coastguard Worker }
290*35238bceSAndroid Build Coastguard Worker }
291*35238bceSAndroid Build Coastguard Worker
292*35238bceSAndroid Build Coastguard Worker private:
293*35238bceSAndroid Build Coastguard Worker const tcu::ConstPixelBufferAccess m_texture;
294*35238bceSAndroid Build Coastguard Worker };
295*35238bceSAndroid Build Coastguard Worker
generateVertexShaderTemplate(RenderBits renderBits)296*35238bceSAndroid Build Coastguard Worker string generateVertexShaderTemplate(RenderBits renderBits)
297*35238bceSAndroid Build Coastguard Worker {
298*35238bceSAndroid Build Coastguard Worker std::ostringstream stream;
299*35238bceSAndroid Build Coastguard Worker
300*35238bceSAndroid Build Coastguard Worker stream << "${VERSION_HEADER}\n";
301*35238bceSAndroid Build Coastguard Worker
302*35238bceSAndroid Build Coastguard Worker if (renderBits & RENDERBITS_AS_VERTEX_TEXTURE)
303*35238bceSAndroid Build Coastguard Worker stream << "${TEXTURE_BUFFER_EXT}";
304*35238bceSAndroid Build Coastguard Worker
305*35238bceSAndroid Build Coastguard Worker stream << "${VTX_INPUT} layout(location = 0) ${HIGHP} vec2 i_coord;\n"
306*35238bceSAndroid Build Coastguard Worker "${VTX_OUTPUT} ${HIGHP} vec4 v_color;\n";
307*35238bceSAndroid Build Coastguard Worker
308*35238bceSAndroid Build Coastguard Worker if (renderBits & RENDERBITS_AS_VERTEX_TEXTURE)
309*35238bceSAndroid Build Coastguard Worker {
310*35238bceSAndroid Build Coastguard Worker stream << "uniform ${HIGHP} samplerBuffer u_vtxSampler;\n";
311*35238bceSAndroid Build Coastguard Worker }
312*35238bceSAndroid Build Coastguard Worker
313*35238bceSAndroid Build Coastguard Worker stream << "\n"
314*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
315*35238bceSAndroid Build Coastguard Worker "{\n";
316*35238bceSAndroid Build Coastguard Worker
317*35238bceSAndroid Build Coastguard Worker if (renderBits & RENDERBITS_AS_VERTEX_TEXTURE)
318*35238bceSAndroid Build Coastguard Worker stream << "\tv_color = texelFetch(u_vtxSampler, clamp((int(round(i_coord.x * 4.0)) + 4) * (int(round(i_coord.y "
319*35238bceSAndroid Build Coastguard Worker "* 4.0)) + 4), 0, textureSize(u_vtxSampler)-1));\n";
320*35238bceSAndroid Build Coastguard Worker else
321*35238bceSAndroid Build Coastguard Worker stream << "\tv_color = vec4(1.0);\n";
322*35238bceSAndroid Build Coastguard Worker
323*35238bceSAndroid Build Coastguard Worker stream << "\tgl_Position = vec4(2.0 * (i_coord - vec2(0.5)), 0.0, 1.0);\n"
324*35238bceSAndroid Build Coastguard Worker "}\n";
325*35238bceSAndroid Build Coastguard Worker
326*35238bceSAndroid Build Coastguard Worker return stream.str();
327*35238bceSAndroid Build Coastguard Worker }
328*35238bceSAndroid Build Coastguard Worker
generateFragmentShaderTemplate(RenderBits renderBits)329*35238bceSAndroid Build Coastguard Worker string generateFragmentShaderTemplate(RenderBits renderBits)
330*35238bceSAndroid Build Coastguard Worker {
331*35238bceSAndroid Build Coastguard Worker std::ostringstream stream;
332*35238bceSAndroid Build Coastguard Worker
333*35238bceSAndroid Build Coastguard Worker stream << "${VERSION_HEADER}\n";
334*35238bceSAndroid Build Coastguard Worker
335*35238bceSAndroid Build Coastguard Worker if (renderBits & RENDERBITS_AS_FRAGMENT_TEXTURE)
336*35238bceSAndroid Build Coastguard Worker stream << "${TEXTURE_BUFFER_EXT}";
337*35238bceSAndroid Build Coastguard Worker
338*35238bceSAndroid Build Coastguard Worker stream << "${FRAG_OUTPUT} layout(location = 0) ${HIGHP} vec4 dEQP_FragColor;\n"
339*35238bceSAndroid Build Coastguard Worker "${FRAG_INPUT} ${HIGHP} vec4 v_color;\n";
340*35238bceSAndroid Build Coastguard Worker
341*35238bceSAndroid Build Coastguard Worker if (renderBits & RENDERBITS_AS_FRAGMENT_TEXTURE)
342*35238bceSAndroid Build Coastguard Worker stream << "uniform ${HIGHP} samplerBuffer u_fragSampler;\n";
343*35238bceSAndroid Build Coastguard Worker
344*35238bceSAndroid Build Coastguard Worker stream << "\n"
345*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
346*35238bceSAndroid Build Coastguard Worker "{\n";
347*35238bceSAndroid Build Coastguard Worker
348*35238bceSAndroid Build Coastguard Worker if (renderBits & RENDERBITS_AS_FRAGMENT_TEXTURE)
349*35238bceSAndroid Build Coastguard Worker stream << "\t${HIGHP} vec4 color = 0.5 * (v_color + texelFetch(u_fragSampler, clamp(int(gl_FragCoord.x) * "
350*35238bceSAndroid Build Coastguard Worker "int(gl_FragCoord.y), 0, textureSize(u_fragSampler)-1)));\n";
351*35238bceSAndroid Build Coastguard Worker else
352*35238bceSAndroid Build Coastguard Worker stream << "\t${HIGHP} vec4 color = v_color;\n";
353*35238bceSAndroid Build Coastguard Worker
354*35238bceSAndroid Build Coastguard Worker stream << "\tdEQP_FragColor = vec4(color.xyz * color.w, 1.0);\n"
355*35238bceSAndroid Build Coastguard Worker "}\n";
356*35238bceSAndroid Build Coastguard Worker
357*35238bceSAndroid Build Coastguard Worker return stream.str();
358*35238bceSAndroid Build Coastguard Worker }
359*35238bceSAndroid Build Coastguard Worker
specializeShader(const string & shaderTemplateString,glu::GLSLVersion glslVersion)360*35238bceSAndroid Build Coastguard Worker string specializeShader(const string &shaderTemplateString, glu::GLSLVersion glslVersion)
361*35238bceSAndroid Build Coastguard Worker {
362*35238bceSAndroid Build Coastguard Worker const tcu::StringTemplate shaderTemplate(shaderTemplateString);
363*35238bceSAndroid Build Coastguard Worker map<string, string> parameters;
364*35238bceSAndroid Build Coastguard Worker
365*35238bceSAndroid Build Coastguard Worker parameters["VERSION_HEADER"] = glu::getGLSLVersionDeclaration(glslVersion);
366*35238bceSAndroid Build Coastguard Worker parameters["VTX_OUTPUT"] = "out";
367*35238bceSAndroid Build Coastguard Worker parameters["VTX_INPUT"] = "in";
368*35238bceSAndroid Build Coastguard Worker parameters["FRAG_INPUT"] = "in";
369*35238bceSAndroid Build Coastguard Worker parameters["FRAG_OUTPUT"] = "out";
370*35238bceSAndroid Build Coastguard Worker parameters["HIGHP"] = (glslVersion == glu::GLSL_VERSION_330 ? "" : "highp");
371*35238bceSAndroid Build Coastguard Worker parameters["TEXTURE_BUFFER_EXT"] =
372*35238bceSAndroid Build Coastguard Worker (glslVersion == glu::GLSL_VERSION_330 ? "" : "#extension GL_EXT_texture_buffer : enable\n");
373*35238bceSAndroid Build Coastguard Worker
374*35238bceSAndroid Build Coastguard Worker return shaderTemplate.specialize(parameters);
375*35238bceSAndroid Build Coastguard Worker }
376*35238bceSAndroid Build Coastguard Worker
createRenderProgram(glu::RenderContext & renderContext,RenderBits renderBits)377*35238bceSAndroid Build Coastguard Worker glu::ShaderProgram *createRenderProgram(glu::RenderContext &renderContext, RenderBits renderBits)
378*35238bceSAndroid Build Coastguard Worker {
379*35238bceSAndroid Build Coastguard Worker const string vertexShaderTemplate = generateVertexShaderTemplate(renderBits);
380*35238bceSAndroid Build Coastguard Worker const string fragmentShaderTemplate = generateFragmentShaderTemplate(renderBits);
381*35238bceSAndroid Build Coastguard Worker
382*35238bceSAndroid Build Coastguard Worker const glu::GLSLVersion glslVersion = glu::getContextTypeGLSLVersion(renderContext.getType());
383*35238bceSAndroid Build Coastguard Worker
384*35238bceSAndroid Build Coastguard Worker const string vertexShaderSource = specializeShader(vertexShaderTemplate, glslVersion);
385*35238bceSAndroid Build Coastguard Worker const string fragmentShaderSource = specializeShader(fragmentShaderTemplate, glslVersion);
386*35238bceSAndroid Build Coastguard Worker
387*35238bceSAndroid Build Coastguard Worker glu::ShaderProgram *const program =
388*35238bceSAndroid Build Coastguard Worker new glu::ShaderProgram(renderContext, glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
389*35238bceSAndroid Build Coastguard Worker
390*35238bceSAndroid Build Coastguard Worker return program;
391*35238bceSAndroid Build Coastguard Worker }
392*35238bceSAndroid Build Coastguard Worker
logModifications(TestLog & log,ModifyBits modifyBits)393*35238bceSAndroid Build Coastguard Worker void logModifications(TestLog &log, ModifyBits modifyBits)
394*35238bceSAndroid Build Coastguard Worker {
395*35238bceSAndroid Build Coastguard Worker tcu::ScopedLogSection section(log, "Modify Operations", "Modify Operations");
396*35238bceSAndroid Build Coastguard Worker
397*35238bceSAndroid Build Coastguard Worker const struct
398*35238bceSAndroid Build Coastguard Worker {
399*35238bceSAndroid Build Coastguard Worker ModifyBits bit;
400*35238bceSAndroid Build Coastguard Worker const char *str;
401*35238bceSAndroid Build Coastguard Worker } bitInfos[] = {{MODIFYBITS_BUFFERDATA, "Recreate buffer data with glBufferData()."},
402*35238bceSAndroid Build Coastguard Worker {MODIFYBITS_BUFFERSUBDATA, "Modify texture buffer with glBufferSubData()."},
403*35238bceSAndroid Build Coastguard Worker {MODIFYBITS_MAPBUFFER_WRITE, "Map buffer write-only and rewrite data."},
404*35238bceSAndroid Build Coastguard Worker {MODIFYBITS_MAPBUFFER_READWRITE, "Map buffer readw-write check and rewrite data."}};
405*35238bceSAndroid Build Coastguard Worker
406*35238bceSAndroid Build Coastguard Worker DE_ASSERT(modifyBits != 0);
407*35238bceSAndroid Build Coastguard Worker
408*35238bceSAndroid Build Coastguard Worker for (int infoNdx = 0; infoNdx < DE_LENGTH_OF_ARRAY(bitInfos); infoNdx++)
409*35238bceSAndroid Build Coastguard Worker {
410*35238bceSAndroid Build Coastguard Worker if (modifyBits & bitInfos[infoNdx].bit)
411*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << bitInfos[infoNdx].str << TestLog::EndMessage;
412*35238bceSAndroid Build Coastguard Worker }
413*35238bceSAndroid Build Coastguard Worker }
414*35238bceSAndroid Build Coastguard Worker
modifyBufferData(TestLog & log,de::Random & rng,glu::TextureBuffer & texture)415*35238bceSAndroid Build Coastguard Worker void modifyBufferData(TestLog &log, de::Random &rng, glu::TextureBuffer &texture)
416*35238bceSAndroid Build Coastguard Worker {
417*35238bceSAndroid Build Coastguard Worker vector<uint8_t> data;
418*35238bceSAndroid Build Coastguard Worker
419*35238bceSAndroid Build Coastguard Worker genRandomCoords(rng, data, 0, texture.getBufferSize());
420*35238bceSAndroid Build Coastguard Worker
421*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "BufferData, Size: " << data.size() << TestLog::EndMessage;
422*35238bceSAndroid Build Coastguard Worker
423*35238bceSAndroid Build Coastguard Worker {
424*35238bceSAndroid Build Coastguard Worker // replace getRefBuffer with a new buffer
425*35238bceSAndroid Build Coastguard Worker de::ArrayBuffer<uint8_t> buffer(&(data[0]), data.size());
426*35238bceSAndroid Build Coastguard Worker texture.getRefBuffer().swap(buffer);
427*35238bceSAndroid Build Coastguard Worker }
428*35238bceSAndroid Build Coastguard Worker
429*35238bceSAndroid Build Coastguard Worker texture.upload();
430*35238bceSAndroid Build Coastguard Worker }
431*35238bceSAndroid Build Coastguard Worker
modifyBufferSubData(TestLog & log,de::Random & rng,const glw::Functions & gl,glu::TextureBuffer & texture)432*35238bceSAndroid Build Coastguard Worker void modifyBufferSubData(TestLog &log, de::Random &rng, const glw::Functions &gl, glu::TextureBuffer &texture)
433*35238bceSAndroid Build Coastguard Worker {
434*35238bceSAndroid Build Coastguard Worker const size_t minSize = 4 * 16;
435*35238bceSAndroid Build Coastguard Worker const size_t size =
436*35238bceSAndroid Build Coastguard Worker de::max<size_t>(minSize, size_t((float)(texture.getSize() != 0 ? texture.getSize() : texture.getBufferSize()) *
437*35238bceSAndroid Build Coastguard Worker (0.7f + 0.3f * rng.getFloat())));
438*35238bceSAndroid Build Coastguard Worker const size_t minOffset = texture.getOffset();
439*35238bceSAndroid Build Coastguard Worker const size_t offset = minOffset + (rng.getUint32() % (texture.getBufferSize() - (size + minOffset)));
440*35238bceSAndroid Build Coastguard Worker vector<uint8_t> data;
441*35238bceSAndroid Build Coastguard Worker
442*35238bceSAndroid Build Coastguard Worker genRandomCoords(rng, data, offset, size);
443*35238bceSAndroid Build Coastguard Worker
444*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "BufferSubData, Offset: " << offset << ", Size: " << size << TestLog::EndMessage;
445*35238bceSAndroid Build Coastguard Worker
446*35238bceSAndroid Build Coastguard Worker gl.bindBuffer(GL_TEXTURE_BUFFER, texture.getGLBuffer());
447*35238bceSAndroid Build Coastguard Worker gl.bufferSubData(GL_TEXTURE_BUFFER, (glw::GLsizei)offset, (glw::GLsizei)data.size(), &(data[0]));
448*35238bceSAndroid Build Coastguard Worker gl.bindBuffer(GL_TEXTURE_BUFFER, 0);
449*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to update data with glBufferSubData()");
450*35238bceSAndroid Build Coastguard Worker
451*35238bceSAndroid Build Coastguard Worker deMemcpy((uint8_t *)texture.getRefBuffer().getPtr() + offset, &(data[0]), int(data.size()));
452*35238bceSAndroid Build Coastguard Worker }
453*35238bceSAndroid Build Coastguard Worker
modifyMapWrite(TestLog & log,de::Random & rng,const glw::Functions & gl,glu::TextureBuffer & texture)454*35238bceSAndroid Build Coastguard Worker void modifyMapWrite(TestLog &log, de::Random &rng, const glw::Functions &gl, glu::TextureBuffer &texture)
455*35238bceSAndroid Build Coastguard Worker {
456*35238bceSAndroid Build Coastguard Worker const size_t minSize = 4 * 16;
457*35238bceSAndroid Build Coastguard Worker const size_t size =
458*35238bceSAndroid Build Coastguard Worker de::max<size_t>(minSize, size_t((float)(texture.getSize() != 0 ? texture.getSize() : texture.getBufferSize()) *
459*35238bceSAndroid Build Coastguard Worker (0.7f + 0.3f * rng.getFloat())));
460*35238bceSAndroid Build Coastguard Worker const size_t minOffset = texture.getOffset();
461*35238bceSAndroid Build Coastguard Worker const size_t offset = minOffset + (rng.getUint32() % (texture.getBufferSize() - (size + minOffset)));
462*35238bceSAndroid Build Coastguard Worker vector<uint8_t> data;
463*35238bceSAndroid Build Coastguard Worker
464*35238bceSAndroid Build Coastguard Worker genRandomCoords(rng, data, offset, size);
465*35238bceSAndroid Build Coastguard Worker
466*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "glMapBufferRange, Write Only, Offset: " << offset << ", Size: " << size
467*35238bceSAndroid Build Coastguard Worker << TestLog::EndMessage;
468*35238bceSAndroid Build Coastguard Worker
469*35238bceSAndroid Build Coastguard Worker gl.bindBuffer(GL_TEXTURE_BUFFER, texture.getGLBuffer());
470*35238bceSAndroid Build Coastguard Worker {
471*35238bceSAndroid Build Coastguard Worker uint8_t *ptr =
472*35238bceSAndroid Build Coastguard Worker (uint8_t *)gl.mapBufferRange(GL_TEXTURE_BUFFER, (glw::GLsizei)offset, (glw::GLsizei)size, GL_MAP_WRITE_BIT);
473*35238bceSAndroid Build Coastguard Worker
474*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "glMapBufferRange()");
475*35238bceSAndroid Build Coastguard Worker TCU_CHECK(ptr);
476*35238bceSAndroid Build Coastguard Worker
477*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)data.size(); i++)
478*35238bceSAndroid Build Coastguard Worker ptr[i] = data[i];
479*35238bceSAndroid Build Coastguard Worker
480*35238bceSAndroid Build Coastguard Worker TCU_CHECK(gl.unmapBuffer(GL_TEXTURE_BUFFER));
481*35238bceSAndroid Build Coastguard Worker }
482*35238bceSAndroid Build Coastguard Worker gl.bindBuffer(GL_TEXTURE_BUFFER, 0);
483*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to update data with glMapBufferRange()");
484*35238bceSAndroid Build Coastguard Worker
485*35238bceSAndroid Build Coastguard Worker deMemcpy((uint8_t *)texture.getRefBuffer().getPtr() + offset, &(data[0]), int(data.size()));
486*35238bceSAndroid Build Coastguard Worker }
487*35238bceSAndroid Build Coastguard Worker
modifyMapReadWrite(TestLog & log,tcu::ResultCollector & resultCollector,de::Random & rng,const glw::Functions & gl,glu::TextureBuffer & texture)488*35238bceSAndroid Build Coastguard Worker void modifyMapReadWrite(TestLog &log, tcu::ResultCollector &resultCollector, de::Random &rng, const glw::Functions &gl,
489*35238bceSAndroid Build Coastguard Worker glu::TextureBuffer &texture)
490*35238bceSAndroid Build Coastguard Worker {
491*35238bceSAndroid Build Coastguard Worker const size_t minSize = 4 * 16;
492*35238bceSAndroid Build Coastguard Worker const size_t size =
493*35238bceSAndroid Build Coastguard Worker de::max<size_t>(minSize, size_t((float)(texture.getSize() != 0 ? texture.getSize() : texture.getBufferSize()) *
494*35238bceSAndroid Build Coastguard Worker (0.7f + 0.3f * rng.getFloat())));
495*35238bceSAndroid Build Coastguard Worker const size_t minOffset = texture.getOffset();
496*35238bceSAndroid Build Coastguard Worker const size_t offset = minOffset + (rng.getUint32() % (texture.getBufferSize() - (size + minOffset)));
497*35238bceSAndroid Build Coastguard Worker uint8_t *const refPtr = (uint8_t *)texture.getRefBuffer().getPtr() + offset;
498*35238bceSAndroid Build Coastguard Worker vector<uint8_t> data;
499*35238bceSAndroid Build Coastguard Worker
500*35238bceSAndroid Build Coastguard Worker genRandomCoords(rng, data, offset, size);
501*35238bceSAndroid Build Coastguard Worker
502*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "glMapBufferRange, Read Write, Offset: " << offset << ", Size: " << size
503*35238bceSAndroid Build Coastguard Worker << TestLog::EndMessage;
504*35238bceSAndroid Build Coastguard Worker
505*35238bceSAndroid Build Coastguard Worker gl.bindBuffer(GL_TEXTURE_BUFFER, texture.getGLBuffer());
506*35238bceSAndroid Build Coastguard Worker {
507*35238bceSAndroid Build Coastguard Worker size_t invalidBytes = 0;
508*35238bceSAndroid Build Coastguard Worker uint8_t *const ptr = (uint8_t *)gl.mapBufferRange(GL_TEXTURE_BUFFER, (glw::GLsizei)offset, (glw::GLsizei)size,
509*35238bceSAndroid Build Coastguard Worker GL_MAP_WRITE_BIT | GL_MAP_READ_BIT);
510*35238bceSAndroid Build Coastguard Worker
511*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "glMapBufferRange()");
512*35238bceSAndroid Build Coastguard Worker TCU_CHECK(ptr);
513*35238bceSAndroid Build Coastguard Worker
514*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)data.size(); i++)
515*35238bceSAndroid Build Coastguard Worker {
516*35238bceSAndroid Build Coastguard Worker if (ptr[i] != refPtr[i])
517*35238bceSAndroid Build Coastguard Worker {
518*35238bceSAndroid Build Coastguard Worker if (invalidBytes < 24)
519*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "Invalid byte in mapped buffer. "
520*35238bceSAndroid Build Coastguard Worker << tcu::Format::Hex<2>(data[i]).toString() << " at " << i << ", expected "
521*35238bceSAndroid Build Coastguard Worker << tcu::Format::Hex<2>(refPtr[i]).toString() << TestLog::EndMessage;
522*35238bceSAndroid Build Coastguard Worker
523*35238bceSAndroid Build Coastguard Worker invalidBytes++;
524*35238bceSAndroid Build Coastguard Worker }
525*35238bceSAndroid Build Coastguard Worker
526*35238bceSAndroid Build Coastguard Worker ptr[i] = data[i];
527*35238bceSAndroid Build Coastguard Worker }
528*35238bceSAndroid Build Coastguard Worker
529*35238bceSAndroid Build Coastguard Worker TCU_CHECK(gl.unmapBuffer(GL_TEXTURE_BUFFER));
530*35238bceSAndroid Build Coastguard Worker
531*35238bceSAndroid Build Coastguard Worker if (invalidBytes > 0)
532*35238bceSAndroid Build Coastguard Worker {
533*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "Total of " << invalidBytes << " invalid bytes." << TestLog::EndMessage;
534*35238bceSAndroid Build Coastguard Worker resultCollector.fail("Invalid data in mapped buffer");
535*35238bceSAndroid Build Coastguard Worker }
536*35238bceSAndroid Build Coastguard Worker }
537*35238bceSAndroid Build Coastguard Worker
538*35238bceSAndroid Build Coastguard Worker gl.bindBuffer(GL_TEXTURE_BUFFER, 0);
539*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to update data with glMapBufferRange()");
540*35238bceSAndroid Build Coastguard Worker
541*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)data.size(); i++)
542*35238bceSAndroid Build Coastguard Worker refPtr[i] = data[i];
543*35238bceSAndroid Build Coastguard Worker }
544*35238bceSAndroid Build Coastguard Worker
modify(TestLog & log,tcu::ResultCollector & resultCollector,glu::RenderContext & renderContext,ModifyBits modifyBits,de::Random & rng,glu::TextureBuffer & texture)545*35238bceSAndroid Build Coastguard Worker void modify(TestLog &log, tcu::ResultCollector &resultCollector, glu::RenderContext &renderContext,
546*35238bceSAndroid Build Coastguard Worker ModifyBits modifyBits, de::Random &rng, glu::TextureBuffer &texture)
547*35238bceSAndroid Build Coastguard Worker {
548*35238bceSAndroid Build Coastguard Worker const tcu::ScopedLogSection modifySection(log, "Modifying Texture buffer", "Modifying Texture Buffer");
549*35238bceSAndroid Build Coastguard Worker
550*35238bceSAndroid Build Coastguard Worker logModifications(log, modifyBits);
551*35238bceSAndroid Build Coastguard Worker
552*35238bceSAndroid Build Coastguard Worker if (modifyBits & MODIFYBITS_BUFFERDATA)
553*35238bceSAndroid Build Coastguard Worker modifyBufferData(log, rng, texture);
554*35238bceSAndroid Build Coastguard Worker
555*35238bceSAndroid Build Coastguard Worker if (modifyBits & MODIFYBITS_BUFFERSUBDATA)
556*35238bceSAndroid Build Coastguard Worker modifyBufferSubData(log, rng, renderContext.getFunctions(), texture);
557*35238bceSAndroid Build Coastguard Worker
558*35238bceSAndroid Build Coastguard Worker if (modifyBits & MODIFYBITS_MAPBUFFER_WRITE)
559*35238bceSAndroid Build Coastguard Worker modifyMapWrite(log, rng, renderContext.getFunctions(), texture);
560*35238bceSAndroid Build Coastguard Worker
561*35238bceSAndroid Build Coastguard Worker if (modifyBits & MODIFYBITS_MAPBUFFER_READWRITE)
562*35238bceSAndroid Build Coastguard Worker modifyMapReadWrite(log, resultCollector, rng, renderContext.getFunctions(), texture);
563*35238bceSAndroid Build Coastguard Worker }
564*35238bceSAndroid Build Coastguard Worker
renderGL(glu::RenderContext & renderContext,RenderBits renderBits,uint32_t coordSeed,int triangleCount,glu::ShaderProgram & program,glu::TextureBuffer & texture)565*35238bceSAndroid Build Coastguard Worker void renderGL(glu::RenderContext &renderContext, RenderBits renderBits, uint32_t coordSeed, int triangleCount,
566*35238bceSAndroid Build Coastguard Worker glu::ShaderProgram &program, glu::TextureBuffer &texture)
567*35238bceSAndroid Build Coastguard Worker {
568*35238bceSAndroid Build Coastguard Worker const glw::Functions &gl = renderContext.getFunctions();
569*35238bceSAndroid Build Coastguard Worker const glu::VertexArray vao(renderContext);
570*35238bceSAndroid Build Coastguard Worker const glu::Buffer coordBuffer(renderContext);
571*35238bceSAndroid Build Coastguard Worker
572*35238bceSAndroid Build Coastguard Worker gl.useProgram(program.getProgram());
573*35238bceSAndroid Build Coastguard Worker gl.bindVertexArray(*vao);
574*35238bceSAndroid Build Coastguard Worker
575*35238bceSAndroid Build Coastguard Worker gl.enableVertexAttribArray(0);
576*35238bceSAndroid Build Coastguard Worker
577*35238bceSAndroid Build Coastguard Worker if (renderBits & RENDERBITS_AS_VERTEX_ARRAY)
578*35238bceSAndroid Build Coastguard Worker {
579*35238bceSAndroid Build Coastguard Worker gl.bindBuffer(GL_ARRAY_BUFFER, texture.getGLBuffer());
580*35238bceSAndroid Build Coastguard Worker gl.vertexAttribPointer(0, 2, GL_UNSIGNED_BYTE, true, 0, DE_NULL);
581*35238bceSAndroid Build Coastguard Worker }
582*35238bceSAndroid Build Coastguard Worker else
583*35238bceSAndroid Build Coastguard Worker {
584*35238bceSAndroid Build Coastguard Worker de::Random rng(coordSeed);
585*35238bceSAndroid Build Coastguard Worker vector<uint8_t> coords;
586*35238bceSAndroid Build Coastguard Worker
587*35238bceSAndroid Build Coastguard Worker genRandomCoords(rng, coords, 0, 256 * 2);
588*35238bceSAndroid Build Coastguard Worker
589*35238bceSAndroid Build Coastguard Worker gl.bindBuffer(GL_ARRAY_BUFFER, *coordBuffer);
590*35238bceSAndroid Build Coastguard Worker gl.bufferData(GL_ARRAY_BUFFER, (glw::GLsizei)coords.size(), &(coords[0]), GL_STREAM_DRAW);
591*35238bceSAndroid Build Coastguard Worker gl.vertexAttribPointer(0, 2, GL_UNSIGNED_BYTE, true, 0, DE_NULL);
592*35238bceSAndroid Build Coastguard Worker }
593*35238bceSAndroid Build Coastguard Worker
594*35238bceSAndroid Build Coastguard Worker if (renderBits & RENDERBITS_AS_VERTEX_TEXTURE)
595*35238bceSAndroid Build Coastguard Worker {
596*35238bceSAndroid Build Coastguard Worker const int32_t location = gl.getUniformLocation(program.getProgram(), "u_vtxSampler");
597*35238bceSAndroid Build Coastguard Worker
598*35238bceSAndroid Build Coastguard Worker gl.activeTexture(GL_TEXTURE0);
599*35238bceSAndroid Build Coastguard Worker gl.bindTexture(GL_TEXTURE_BUFFER, texture.getGLTexture());
600*35238bceSAndroid Build Coastguard Worker gl.uniform1i(location, 0);
601*35238bceSAndroid Build Coastguard Worker }
602*35238bceSAndroid Build Coastguard Worker
603*35238bceSAndroid Build Coastguard Worker if (renderBits & RENDERBITS_AS_FRAGMENT_TEXTURE)
604*35238bceSAndroid Build Coastguard Worker {
605*35238bceSAndroid Build Coastguard Worker const int32_t location = gl.getUniformLocation(program.getProgram(), "u_fragSampler");
606*35238bceSAndroid Build Coastguard Worker
607*35238bceSAndroid Build Coastguard Worker gl.activeTexture(GL_TEXTURE1);
608*35238bceSAndroid Build Coastguard Worker gl.bindTexture(GL_TEXTURE_BUFFER, texture.getGLTexture());
609*35238bceSAndroid Build Coastguard Worker gl.uniform1i(location, 1);
610*35238bceSAndroid Build Coastguard Worker gl.activeTexture(GL_TEXTURE0);
611*35238bceSAndroid Build Coastguard Worker }
612*35238bceSAndroid Build Coastguard Worker
613*35238bceSAndroid Build Coastguard Worker if (renderBits & RENDERBITS_AS_INDEX_ARRAY)
614*35238bceSAndroid Build Coastguard Worker {
615*35238bceSAndroid Build Coastguard Worker gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, texture.getGLBuffer());
616*35238bceSAndroid Build Coastguard Worker gl.drawElements(GL_TRIANGLES, triangleCount * 3, GL_UNSIGNED_BYTE, DE_NULL);
617*35238bceSAndroid Build Coastguard Worker gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
618*35238bceSAndroid Build Coastguard Worker }
619*35238bceSAndroid Build Coastguard Worker else
620*35238bceSAndroid Build Coastguard Worker gl.drawArrays(GL_TRIANGLES, 0, triangleCount * 3);
621*35238bceSAndroid Build Coastguard Worker
622*35238bceSAndroid Build Coastguard Worker if (renderBits & RENDERBITS_AS_FRAGMENT_TEXTURE)
623*35238bceSAndroid Build Coastguard Worker {
624*35238bceSAndroid Build Coastguard Worker gl.activeTexture(GL_TEXTURE1);
625*35238bceSAndroid Build Coastguard Worker gl.bindTexture(GL_TEXTURE_BUFFER, 0);
626*35238bceSAndroid Build Coastguard Worker }
627*35238bceSAndroid Build Coastguard Worker
628*35238bceSAndroid Build Coastguard Worker if (renderBits & RENDERBITS_AS_VERTEX_TEXTURE)
629*35238bceSAndroid Build Coastguard Worker {
630*35238bceSAndroid Build Coastguard Worker gl.activeTexture(GL_TEXTURE0);
631*35238bceSAndroid Build Coastguard Worker gl.bindTexture(GL_TEXTURE_BUFFER, 0);
632*35238bceSAndroid Build Coastguard Worker }
633*35238bceSAndroid Build Coastguard Worker
634*35238bceSAndroid Build Coastguard Worker gl.bindBuffer(GL_ARRAY_BUFFER, 0);
635*35238bceSAndroid Build Coastguard Worker gl.disableVertexAttribArray(0);
636*35238bceSAndroid Build Coastguard Worker
637*35238bceSAndroid Build Coastguard Worker gl.bindVertexArray(0);
638*35238bceSAndroid Build Coastguard Worker gl.useProgram(0);
639*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "Rendering failed");
640*35238bceSAndroid Build Coastguard Worker }
641*35238bceSAndroid Build Coastguard Worker
renderReference(RenderBits renderBits,uint32_t coordSeed,int triangleCount,const glu::TextureBuffer & texture,int maxTextureBufferSize,const tcu::PixelBufferAccess & target,int subpixelBits)642*35238bceSAndroid Build Coastguard Worker void renderReference(RenderBits renderBits, uint32_t coordSeed, int triangleCount, const glu::TextureBuffer &texture,
643*35238bceSAndroid Build Coastguard Worker int maxTextureBufferSize, const tcu::PixelBufferAccess &target, int subpixelBits)
644*35238bceSAndroid Build Coastguard Worker {
645*35238bceSAndroid Build Coastguard Worker const tcu::ConstPixelBufferAccess effectiveAccess =
646*35238bceSAndroid Build Coastguard Worker glu::getTextureBufferEffectiveRefTexture(texture, maxTextureBufferSize);
647*35238bceSAndroid Build Coastguard Worker
648*35238bceSAndroid Build Coastguard Worker const CoordVertexShader coordVertexShader;
649*35238bceSAndroid Build Coastguard Worker const TextureVertexShader textureVertexShader(effectiveAccess);
650*35238bceSAndroid Build Coastguard Worker const rr::VertexShader *const vertexShader =
651*35238bceSAndroid Build Coastguard Worker (renderBits & RENDERBITS_AS_VERTEX_TEXTURE ? static_cast<const rr::VertexShader *>(&textureVertexShader) :
652*35238bceSAndroid Build Coastguard Worker &coordVertexShader);
653*35238bceSAndroid Build Coastguard Worker
654*35238bceSAndroid Build Coastguard Worker const CoordFragmentShader coordFragmmentShader;
655*35238bceSAndroid Build Coastguard Worker const TextureFragmentShader textureFragmentShader(effectiveAccess);
656*35238bceSAndroid Build Coastguard Worker const rr::FragmentShader *const fragmentShader =
657*35238bceSAndroid Build Coastguard Worker (renderBits & RENDERBITS_AS_FRAGMENT_TEXTURE ? static_cast<const rr::FragmentShader *>(&textureFragmentShader) :
658*35238bceSAndroid Build Coastguard Worker &coordFragmmentShader);
659*35238bceSAndroid Build Coastguard Worker
660*35238bceSAndroid Build Coastguard Worker const rr::Renderer renderer;
661*35238bceSAndroid Build Coastguard Worker const rr::RenderState renderState(
662*35238bceSAndroid Build Coastguard Worker rr::ViewportState(rr::WindowRectangle(0, 0, target.getWidth(), target.getHeight())), subpixelBits);
663*35238bceSAndroid Build Coastguard Worker const rr::RenderTarget renderTarget(rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(target));
664*35238bceSAndroid Build Coastguard Worker
665*35238bceSAndroid Build Coastguard Worker const rr::Program program(vertexShader, fragmentShader);
666*35238bceSAndroid Build Coastguard Worker
667*35238bceSAndroid Build Coastguard Worker rr::VertexAttrib vertexAttribs[1];
668*35238bceSAndroid Build Coastguard Worker vector<uint8_t> coords;
669*35238bceSAndroid Build Coastguard Worker
670*35238bceSAndroid Build Coastguard Worker if (renderBits & RENDERBITS_AS_VERTEX_ARRAY)
671*35238bceSAndroid Build Coastguard Worker {
672*35238bceSAndroid Build Coastguard Worker vertexAttribs[0].type = rr::VERTEXATTRIBTYPE_NONPURE_UNORM8;
673*35238bceSAndroid Build Coastguard Worker vertexAttribs[0].size = 2;
674*35238bceSAndroid Build Coastguard Worker vertexAttribs[0].pointer = texture.getRefBuffer().getPtr();
675*35238bceSAndroid Build Coastguard Worker }
676*35238bceSAndroid Build Coastguard Worker else
677*35238bceSAndroid Build Coastguard Worker {
678*35238bceSAndroid Build Coastguard Worker de::Random rng(coordSeed);
679*35238bceSAndroid Build Coastguard Worker
680*35238bceSAndroid Build Coastguard Worker genRandomCoords(rng, coords, 0, 256 * 2);
681*35238bceSAndroid Build Coastguard Worker
682*35238bceSAndroid Build Coastguard Worker vertexAttribs[0].type = rr::VERTEXATTRIBTYPE_NONPURE_UNORM8;
683*35238bceSAndroid Build Coastguard Worker vertexAttribs[0].size = 2;
684*35238bceSAndroid Build Coastguard Worker vertexAttribs[0].pointer = &(coords[0]);
685*35238bceSAndroid Build Coastguard Worker }
686*35238bceSAndroid Build Coastguard Worker
687*35238bceSAndroid Build Coastguard Worker if (renderBits & RENDERBITS_AS_INDEX_ARRAY)
688*35238bceSAndroid Build Coastguard Worker {
689*35238bceSAndroid Build Coastguard Worker const rr::PrimitiveList primitives(rr::PRIMITIVETYPE_TRIANGLES, triangleCount * 3,
690*35238bceSAndroid Build Coastguard Worker rr::DrawIndices(texture.getRefBuffer().getPtr(), rr::INDEXTYPE_UINT8));
691*35238bceSAndroid Build Coastguard Worker const rr::DrawCommand cmd(renderState, renderTarget, program, 1, vertexAttribs, primitives);
692*35238bceSAndroid Build Coastguard Worker
693*35238bceSAndroid Build Coastguard Worker renderer.draw(cmd);
694*35238bceSAndroid Build Coastguard Worker }
695*35238bceSAndroid Build Coastguard Worker else
696*35238bceSAndroid Build Coastguard Worker {
697*35238bceSAndroid Build Coastguard Worker const rr::PrimitiveList primitives(rr::PRIMITIVETYPE_TRIANGLES, triangleCount * 3, 0);
698*35238bceSAndroid Build Coastguard Worker const rr::DrawCommand cmd(renderState, renderTarget, program, 1, vertexAttribs, primitives);
699*35238bceSAndroid Build Coastguard Worker
700*35238bceSAndroid Build Coastguard Worker renderer.draw(cmd);
701*35238bceSAndroid Build Coastguard Worker }
702*35238bceSAndroid Build Coastguard Worker }
703*35238bceSAndroid Build Coastguard Worker
logRendering(TestLog & log,RenderBits renderBits)704*35238bceSAndroid Build Coastguard Worker void logRendering(TestLog &log, RenderBits renderBits)
705*35238bceSAndroid Build Coastguard Worker {
706*35238bceSAndroid Build Coastguard Worker const struct
707*35238bceSAndroid Build Coastguard Worker {
708*35238bceSAndroid Build Coastguard Worker RenderBits bit;
709*35238bceSAndroid Build Coastguard Worker const char *str;
710*35238bceSAndroid Build Coastguard Worker } bitInfos[] = {{RENDERBITS_AS_VERTEX_ARRAY, "vertex array"},
711*35238bceSAndroid Build Coastguard Worker {RENDERBITS_AS_INDEX_ARRAY, "index array"},
712*35238bceSAndroid Build Coastguard Worker {RENDERBITS_AS_VERTEX_TEXTURE, "vertex texture"},
713*35238bceSAndroid Build Coastguard Worker {RENDERBITS_AS_FRAGMENT_TEXTURE, "fragment texture"}};
714*35238bceSAndroid Build Coastguard Worker
715*35238bceSAndroid Build Coastguard Worker std::ostringstream stream;
716*35238bceSAndroid Build Coastguard Worker vector<const char *> usedAs;
717*35238bceSAndroid Build Coastguard Worker
718*35238bceSAndroid Build Coastguard Worker DE_ASSERT(renderBits != 0);
719*35238bceSAndroid Build Coastguard Worker
720*35238bceSAndroid Build Coastguard Worker for (int infoNdx = 0; infoNdx < DE_LENGTH_OF_ARRAY(bitInfos); infoNdx++)
721*35238bceSAndroid Build Coastguard Worker {
722*35238bceSAndroid Build Coastguard Worker if (renderBits & bitInfos[infoNdx].bit)
723*35238bceSAndroid Build Coastguard Worker usedAs.push_back(bitInfos[infoNdx].str);
724*35238bceSAndroid Build Coastguard Worker }
725*35238bceSAndroid Build Coastguard Worker
726*35238bceSAndroid Build Coastguard Worker stream << "Render using texture buffer as ";
727*35238bceSAndroid Build Coastguard Worker
728*35238bceSAndroid Build Coastguard Worker for (int asNdx = 0; asNdx < (int)usedAs.size(); asNdx++)
729*35238bceSAndroid Build Coastguard Worker {
730*35238bceSAndroid Build Coastguard Worker if (asNdx + 1 == (int)usedAs.size() && (int)usedAs.size() > 1)
731*35238bceSAndroid Build Coastguard Worker stream << " and ";
732*35238bceSAndroid Build Coastguard Worker else if (asNdx > 0)
733*35238bceSAndroid Build Coastguard Worker stream << ", ";
734*35238bceSAndroid Build Coastguard Worker
735*35238bceSAndroid Build Coastguard Worker stream << usedAs[asNdx];
736*35238bceSAndroid Build Coastguard Worker }
737*35238bceSAndroid Build Coastguard Worker
738*35238bceSAndroid Build Coastguard Worker stream << ".";
739*35238bceSAndroid Build Coastguard Worker
740*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << stream.str() << TestLog::EndMessage;
741*35238bceSAndroid Build Coastguard Worker }
742*35238bceSAndroid Build Coastguard Worker
render(TestLog & log,glu::RenderContext & renderContext,RenderBits renderBits,de::Random & rng,glu::ShaderProgram & program,glu::TextureBuffer & texture,const tcu::PixelBufferAccess & target)743*35238bceSAndroid Build Coastguard Worker void render(TestLog &log, glu::RenderContext &renderContext, RenderBits renderBits, de::Random &rng,
744*35238bceSAndroid Build Coastguard Worker glu::ShaderProgram &program, glu::TextureBuffer &texture, const tcu::PixelBufferAccess &target)
745*35238bceSAndroid Build Coastguard Worker {
746*35238bceSAndroid Build Coastguard Worker const tcu::ScopedLogSection renderSection(log, "Render Texture buffer", "Render Texture Buffer");
747*35238bceSAndroid Build Coastguard Worker const int triangleCount = 8;
748*35238bceSAndroid Build Coastguard Worker const uint32_t coordSeed = rng.getUint32();
749*35238bceSAndroid Build Coastguard Worker int maxTextureBufferSize = 0;
750*35238bceSAndroid Build Coastguard Worker
751*35238bceSAndroid Build Coastguard Worker renderContext.getFunctions().getIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &maxTextureBufferSize);
752*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(renderContext.getFunctions().getError(), "query GL_MAX_TEXTURE_BUFFER_SIZE");
753*35238bceSAndroid Build Coastguard Worker DE_ASSERT(maxTextureBufferSize > 0); // checked in init()
754*35238bceSAndroid Build Coastguard Worker
755*35238bceSAndroid Build Coastguard Worker logRendering(log, renderBits);
756*35238bceSAndroid Build Coastguard Worker
757*35238bceSAndroid Build Coastguard Worker renderGL(renderContext, renderBits, coordSeed, triangleCount, program, texture);
758*35238bceSAndroid Build Coastguard Worker
759*35238bceSAndroid Build Coastguard Worker int subpixelBits = 0;
760*35238bceSAndroid Build Coastguard Worker renderContext.getFunctions().getIntegerv(GL_SUBPIXEL_BITS, &subpixelBits);
761*35238bceSAndroid Build Coastguard Worker renderReference(renderBits, coordSeed, triangleCount, texture, maxTextureBufferSize, target, subpixelBits);
762*35238bceSAndroid Build Coastguard Worker }
763*35238bceSAndroid Build Coastguard Worker
verifyScreen(TestLog & log,tcu::ResultCollector & resultCollector,glu::RenderContext & renderContext,const tcu::ConstPixelBufferAccess & referenceTarget)764*35238bceSAndroid Build Coastguard Worker void verifyScreen(TestLog &log, tcu::ResultCollector &resultCollector, glu::RenderContext &renderContext,
765*35238bceSAndroid Build Coastguard Worker const tcu::ConstPixelBufferAccess &referenceTarget)
766*35238bceSAndroid Build Coastguard Worker {
767*35238bceSAndroid Build Coastguard Worker const tcu::ScopedLogSection verifySection(log, "Verify screen contents", "Verify screen contents");
768*35238bceSAndroid Build Coastguard Worker tcu::Surface screen(referenceTarget.getWidth(), referenceTarget.getHeight());
769*35238bceSAndroid Build Coastguard Worker
770*35238bceSAndroid Build Coastguard Worker glu::readPixels(renderContext, 0, 0, screen.getAccess());
771*35238bceSAndroid Build Coastguard Worker
772*35238bceSAndroid Build Coastguard Worker if (!tcu::fuzzyCompare(log, "Result of rendering", "Result of rendering", referenceTarget, screen.getAccess(),
773*35238bceSAndroid Build Coastguard Worker 0.05f, tcu::COMPARE_LOG_RESULT))
774*35238bceSAndroid Build Coastguard Worker resultCollector.fail("Rendering failed");
775*35238bceSAndroid Build Coastguard Worker }
776*35238bceSAndroid Build Coastguard Worker
logImplementationInfo(TestLog & log,glu::RenderContext & renderContext)777*35238bceSAndroid Build Coastguard Worker void logImplementationInfo(TestLog &log, glu::RenderContext &renderContext)
778*35238bceSAndroid Build Coastguard Worker {
779*35238bceSAndroid Build Coastguard Worker const tcu::ScopedLogSection section(log, "Implementation Values", "Implementation Values");
780*35238bceSAndroid Build Coastguard Worker de::UniquePtr<glu::ContextInfo> info(glu::ContextInfo::create(renderContext));
781*35238bceSAndroid Build Coastguard Worker const glw::Functions &gl = renderContext.getFunctions();
782*35238bceSAndroid Build Coastguard Worker
783*35238bceSAndroid Build Coastguard Worker if (glu::contextSupports(renderContext.getType(), glu::ApiType(3, 3, glu::PROFILE_CORE)))
784*35238bceSAndroid Build Coastguard Worker {
785*35238bceSAndroid Build Coastguard Worker int32_t maxTextureSize = 0;
786*35238bceSAndroid Build Coastguard Worker
787*35238bceSAndroid Build Coastguard Worker gl.getIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &maxTextureSize);
788*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE)");
789*35238bceSAndroid Build Coastguard Worker
790*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "GL_MAX_TEXTURE_BUFFER_SIZE : " << maxTextureSize << TestLog::EndMessage;
791*35238bceSAndroid Build Coastguard Worker }
792*35238bceSAndroid Build Coastguard Worker else if (glu::contextSupports(renderContext.getType(), glu::ApiType(3, 1, glu::PROFILE_ES)) &&
793*35238bceSAndroid Build Coastguard Worker info->isExtensionSupported("GL_EXT_texture_buffer"))
794*35238bceSAndroid Build Coastguard Worker {
795*35238bceSAndroid Build Coastguard Worker {
796*35238bceSAndroid Build Coastguard Worker int32_t maxTextureSize = 0;
797*35238bceSAndroid Build Coastguard Worker
798*35238bceSAndroid Build Coastguard Worker gl.getIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &maxTextureSize);
799*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE_EXT)");
800*35238bceSAndroid Build Coastguard Worker
801*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "GL_MAX_TEXTURE_BUFFER_SIZE_EXT : " << maxTextureSize << TestLog::EndMessage;
802*35238bceSAndroid Build Coastguard Worker }
803*35238bceSAndroid Build Coastguard Worker
804*35238bceSAndroid Build Coastguard Worker {
805*35238bceSAndroid Build Coastguard Worker int32_t textureBufferAlignment = 0;
806*35238bceSAndroid Build Coastguard Worker
807*35238bceSAndroid Build Coastguard Worker gl.getIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, &textureBufferAlignment);
808*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT_EXT)");
809*35238bceSAndroid Build Coastguard Worker
810*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT_EXT : " << textureBufferAlignment
811*35238bceSAndroid Build Coastguard Worker << TestLog::EndMessage;
812*35238bceSAndroid Build Coastguard Worker }
813*35238bceSAndroid Build Coastguard Worker }
814*35238bceSAndroid Build Coastguard Worker else
815*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
816*35238bceSAndroid Build Coastguard Worker }
817*35238bceSAndroid Build Coastguard Worker
logTextureInfo(TestLog & log,uint32_t format,size_t bufferSize,size_t offset,size_t size)818*35238bceSAndroid Build Coastguard Worker void logTextureInfo(TestLog &log, uint32_t format, size_t bufferSize, size_t offset, size_t size)
819*35238bceSAndroid Build Coastguard Worker {
820*35238bceSAndroid Build Coastguard Worker const tcu::ScopedLogSection section(log, "Texture Info", "Texture Info");
821*35238bceSAndroid Build Coastguard Worker
822*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "Texture format : " << glu::getTextureFormatStr(format) << TestLog::EndMessage;
823*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "Buffer size : " << bufferSize << TestLog::EndMessage;
824*35238bceSAndroid Build Coastguard Worker
825*35238bceSAndroid Build Coastguard Worker if (offset != 0 || size != 0)
826*35238bceSAndroid Build Coastguard Worker {
827*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "Buffer range offset: " << offset << TestLog::EndMessage;
828*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "Buffer range size: " << size << TestLog::EndMessage;
829*35238bceSAndroid Build Coastguard Worker }
830*35238bceSAndroid Build Coastguard Worker }
831*35238bceSAndroid Build Coastguard Worker
runTests(tcu::TestContext & testCtx,glu::RenderContext & renderContext,de::Random & rng,uint32_t format,size_t bufferSize,size_t offset,size_t size,RenderBits preRender,glu::ShaderProgram * preRenderProgram,ModifyBits modifyType,RenderBits postRender,glu::ShaderProgram * postRenderProgram)832*35238bceSAndroid Build Coastguard Worker void runTests(tcu::TestContext &testCtx, glu::RenderContext &renderContext, de::Random &rng, uint32_t format,
833*35238bceSAndroid Build Coastguard Worker size_t bufferSize, size_t offset, size_t size, RenderBits preRender, glu::ShaderProgram *preRenderProgram,
834*35238bceSAndroid Build Coastguard Worker ModifyBits modifyType, RenderBits postRender, glu::ShaderProgram *postRenderProgram)
835*35238bceSAndroid Build Coastguard Worker {
836*35238bceSAndroid Build Coastguard Worker const tcu::RenderTarget renderTarget(renderContext.getRenderTarget());
837*35238bceSAndroid Build Coastguard Worker const glw::Functions &gl = renderContext.getFunctions();
838*35238bceSAndroid Build Coastguard Worker
839*35238bceSAndroid Build Coastguard Worker const int width = de::min<int>(renderTarget.getWidth(), MAX_VIEWPORT_WIDTH);
840*35238bceSAndroid Build Coastguard Worker const int height = de::min<int>(renderTarget.getHeight(), MAX_VIEWPORT_HEIGHT);
841*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 clearColor(0.25f, 0.5f, 0.75f, 1.0f);
842*35238bceSAndroid Build Coastguard Worker
843*35238bceSAndroid Build Coastguard Worker TestLog &log = testCtx.getLog();
844*35238bceSAndroid Build Coastguard Worker tcu::ResultCollector resultCollector(log);
845*35238bceSAndroid Build Coastguard Worker
846*35238bceSAndroid Build Coastguard Worker logImplementationInfo(log, renderContext);
847*35238bceSAndroid Build Coastguard Worker logTextureInfo(log, format, bufferSize, offset, size);
848*35238bceSAndroid Build Coastguard Worker
849*35238bceSAndroid Build Coastguard Worker {
850*35238bceSAndroid Build Coastguard Worker tcu::Surface referenceTarget(width, height);
851*35238bceSAndroid Build Coastguard Worker vector<uint8_t> bufferData;
852*35238bceSAndroid Build Coastguard Worker
853*35238bceSAndroid Build Coastguard Worker genRandomCoords(rng, bufferData, 0, bufferSize);
854*35238bceSAndroid Build Coastguard Worker
855*35238bceSAndroid Build Coastguard Worker for (uint8_t i = 0; i < 4; i++)
856*35238bceSAndroid Build Coastguard Worker {
857*35238bceSAndroid Build Coastguard Worker const uint8_t val = extend2BitsToByte(i);
858*35238bceSAndroid Build Coastguard Worker
859*35238bceSAndroid Build Coastguard Worker if (val >= offset && val < offset + size)
860*35238bceSAndroid Build Coastguard Worker {
861*35238bceSAndroid Build Coastguard Worker bufferData[val * 2 + 0] = (i / 2 == 0 ? extend2BitsToByte(0x2u) : extend2BitsToByte(0x01u));
862*35238bceSAndroid Build Coastguard Worker bufferData[val * 2 + 1] = (i % 2 == 0 ? extend2BitsToByte(0x2u) : extend2BitsToByte(0x01u));
863*35238bceSAndroid Build Coastguard Worker }
864*35238bceSAndroid Build Coastguard Worker }
865*35238bceSAndroid Build Coastguard Worker
866*35238bceSAndroid Build Coastguard Worker {
867*35238bceSAndroid Build Coastguard Worker glu::TextureBuffer texture(renderContext, format, bufferSize, offset, size, &(bufferData[0]));
868*35238bceSAndroid Build Coastguard Worker
869*35238bceSAndroid Build Coastguard Worker TCU_CHECK_MSG(width >= MIN_VIEWPORT_WIDTH || height >= MIN_VIEWPORT_HEIGHT, "Too small viewport");
870*35238bceSAndroid Build Coastguard Worker
871*35238bceSAndroid Build Coastguard Worker DE_ASSERT(preRender == 0 || preRenderProgram);
872*35238bceSAndroid Build Coastguard Worker DE_ASSERT(postRender == 0 || postRenderProgram);
873*35238bceSAndroid Build Coastguard Worker
874*35238bceSAndroid Build Coastguard Worker gl.viewport(0, 0, width, height);
875*35238bceSAndroid Build Coastguard Worker gl.clearColor(clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w());
876*35238bceSAndroid Build Coastguard Worker gl.clear(GL_COLOR_BUFFER_BIT);
877*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "Screen setup failed");
878*35238bceSAndroid Build Coastguard Worker
879*35238bceSAndroid Build Coastguard Worker tcu::clear(referenceTarget.getAccess(), clearColor);
880*35238bceSAndroid Build Coastguard Worker
881*35238bceSAndroid Build Coastguard Worker texture.upload();
882*35238bceSAndroid Build Coastguard Worker
883*35238bceSAndroid Build Coastguard Worker if (preRender != 0)
884*35238bceSAndroid Build Coastguard Worker render(log, renderContext, preRender, rng, *preRenderProgram, texture, referenceTarget.getAccess());
885*35238bceSAndroid Build Coastguard Worker
886*35238bceSAndroid Build Coastguard Worker if (modifyType != 0)
887*35238bceSAndroid Build Coastguard Worker modify(log, resultCollector, renderContext, modifyType, rng, texture);
888*35238bceSAndroid Build Coastguard Worker
889*35238bceSAndroid Build Coastguard Worker if (postRender != 0)
890*35238bceSAndroid Build Coastguard Worker render(log, renderContext, postRender, rng, *postRenderProgram, texture, referenceTarget.getAccess());
891*35238bceSAndroid Build Coastguard Worker }
892*35238bceSAndroid Build Coastguard Worker
893*35238bceSAndroid Build Coastguard Worker verifyScreen(log, resultCollector, renderContext, referenceTarget.getAccess());
894*35238bceSAndroid Build Coastguard Worker
895*35238bceSAndroid Build Coastguard Worker resultCollector.setTestContextResult(testCtx);
896*35238bceSAndroid Build Coastguard Worker }
897*35238bceSAndroid Build Coastguard Worker }
898*35238bceSAndroid Build Coastguard Worker
899*35238bceSAndroid Build Coastguard Worker } // namespace
900*35238bceSAndroid Build Coastguard Worker
TextureBufferCase(tcu::TestContext & testCtx,glu::RenderContext & renderCtx,uint32_t format,size_t bufferSize,size_t offset,size_t size,RenderBits preRender,ModifyBits modify,RenderBits postRender,const char * name,const char * description)901*35238bceSAndroid Build Coastguard Worker TextureBufferCase::TextureBufferCase(tcu::TestContext &testCtx, glu::RenderContext &renderCtx, uint32_t format,
902*35238bceSAndroid Build Coastguard Worker size_t bufferSize, size_t offset, size_t size, RenderBits preRender,
903*35238bceSAndroid Build Coastguard Worker ModifyBits modify, RenderBits postRender, const char *name,
904*35238bceSAndroid Build Coastguard Worker const char *description)
905*35238bceSAndroid Build Coastguard Worker : tcu::TestCase(testCtx, name, description)
906*35238bceSAndroid Build Coastguard Worker , m_renderCtx(renderCtx)
907*35238bceSAndroid Build Coastguard Worker , m_format(format)
908*35238bceSAndroid Build Coastguard Worker , m_bufferSize(bufferSize)
909*35238bceSAndroid Build Coastguard Worker , m_offset(offset)
910*35238bceSAndroid Build Coastguard Worker , m_size(size)
911*35238bceSAndroid Build Coastguard Worker
912*35238bceSAndroid Build Coastguard Worker , m_preRender(preRender)
913*35238bceSAndroid Build Coastguard Worker , m_modify(modify)
914*35238bceSAndroid Build Coastguard Worker , m_postRender(postRender)
915*35238bceSAndroid Build Coastguard Worker
916*35238bceSAndroid Build Coastguard Worker , m_preRenderProgram(DE_NULL)
917*35238bceSAndroid Build Coastguard Worker , m_postRenderProgram(DE_NULL)
918*35238bceSAndroid Build Coastguard Worker {
919*35238bceSAndroid Build Coastguard Worker }
920*35238bceSAndroid Build Coastguard Worker
~TextureBufferCase(void)921*35238bceSAndroid Build Coastguard Worker TextureBufferCase::~TextureBufferCase(void)
922*35238bceSAndroid Build Coastguard Worker {
923*35238bceSAndroid Build Coastguard Worker TextureBufferCase::deinit();
924*35238bceSAndroid Build Coastguard Worker }
925*35238bceSAndroid Build Coastguard Worker
init(void)926*35238bceSAndroid Build Coastguard Worker void TextureBufferCase::init(void)
927*35238bceSAndroid Build Coastguard Worker {
928*35238bceSAndroid Build Coastguard Worker de::UniquePtr<glu::ContextInfo> info(glu::ContextInfo::create(m_renderCtx));
929*35238bceSAndroid Build Coastguard Worker
930*35238bceSAndroid Build Coastguard Worker if (!glu::contextSupports(m_renderCtx.getType(), glu::ApiType(3, 3, glu::PROFILE_CORE)) &&
931*35238bceSAndroid Build Coastguard Worker !(glu::contextSupports(m_renderCtx.getType(), glu::ApiType(3, 1, glu::PROFILE_ES)) &&
932*35238bceSAndroid Build Coastguard Worker info->isExtensionSupported("GL_EXT_texture_buffer")))
933*35238bceSAndroid Build Coastguard Worker throw tcu::NotSupportedError("Texture buffers not supported", "", __FILE__, __LINE__);
934*35238bceSAndroid Build Coastguard Worker
935*35238bceSAndroid Build Coastguard Worker {
936*35238bceSAndroid Build Coastguard Worker const int maxTextureBufferSize = info->getInt(GL_MAX_TEXTURE_BUFFER_SIZE);
937*35238bceSAndroid Build Coastguard Worker if (maxTextureBufferSize <= 0)
938*35238bceSAndroid Build Coastguard Worker TCU_THROW(NotSupportedError, "GL_MAX_TEXTURE_BUFFER_SIZE > 0 required");
939*35238bceSAndroid Build Coastguard Worker }
940*35238bceSAndroid Build Coastguard Worker
941*35238bceSAndroid Build Coastguard Worker if (m_preRender != 0)
942*35238bceSAndroid Build Coastguard Worker {
943*35238bceSAndroid Build Coastguard Worker TestLog &log = m_testCtx.getLog();
944*35238bceSAndroid Build Coastguard Worker const char *const sectionName = (m_postRender != 0 ? "Primary render program" : "Render program");
945*35238bceSAndroid Build Coastguard Worker const tcu::ScopedLogSection section(log, sectionName, sectionName);
946*35238bceSAndroid Build Coastguard Worker
947*35238bceSAndroid Build Coastguard Worker m_preRenderProgram = createRenderProgram(m_renderCtx, m_preRender);
948*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << (*m_preRenderProgram);
949*35238bceSAndroid Build Coastguard Worker
950*35238bceSAndroid Build Coastguard Worker TCU_CHECK(m_preRenderProgram->isOk());
951*35238bceSAndroid Build Coastguard Worker }
952*35238bceSAndroid Build Coastguard Worker
953*35238bceSAndroid Build Coastguard Worker if (m_postRender != 0)
954*35238bceSAndroid Build Coastguard Worker {
955*35238bceSAndroid Build Coastguard Worker // Reusing program
956*35238bceSAndroid Build Coastguard Worker if (m_preRender == m_postRender)
957*35238bceSAndroid Build Coastguard Worker {
958*35238bceSAndroid Build Coastguard Worker m_postRenderProgram = m_preRenderProgram;
959*35238bceSAndroid Build Coastguard Worker }
960*35238bceSAndroid Build Coastguard Worker else
961*35238bceSAndroid Build Coastguard Worker {
962*35238bceSAndroid Build Coastguard Worker TestLog &log = m_testCtx.getLog();
963*35238bceSAndroid Build Coastguard Worker const char *const sectionName = (m_preRender != 0 ? "Secondary render program" : "Render program");
964*35238bceSAndroid Build Coastguard Worker const tcu::ScopedLogSection section(log, sectionName, sectionName);
965*35238bceSAndroid Build Coastguard Worker
966*35238bceSAndroid Build Coastguard Worker m_postRenderProgram = createRenderProgram(m_renderCtx, m_postRender);
967*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << (*m_postRenderProgram);
968*35238bceSAndroid Build Coastguard Worker
969*35238bceSAndroid Build Coastguard Worker TCU_CHECK(m_postRenderProgram->isOk());
970*35238bceSAndroid Build Coastguard Worker }
971*35238bceSAndroid Build Coastguard Worker }
972*35238bceSAndroid Build Coastguard Worker }
973*35238bceSAndroid Build Coastguard Worker
deinit(void)974*35238bceSAndroid Build Coastguard Worker void TextureBufferCase::deinit(void)
975*35238bceSAndroid Build Coastguard Worker {
976*35238bceSAndroid Build Coastguard Worker if (m_preRenderProgram == m_postRenderProgram)
977*35238bceSAndroid Build Coastguard Worker m_postRenderProgram = DE_NULL;
978*35238bceSAndroid Build Coastguard Worker
979*35238bceSAndroid Build Coastguard Worker delete m_preRenderProgram;
980*35238bceSAndroid Build Coastguard Worker m_preRenderProgram = DE_NULL;
981*35238bceSAndroid Build Coastguard Worker
982*35238bceSAndroid Build Coastguard Worker delete m_postRenderProgram;
983*35238bceSAndroid Build Coastguard Worker m_postRenderProgram = DE_NULL;
984*35238bceSAndroid Build Coastguard Worker }
985*35238bceSAndroid Build Coastguard Worker
iterate(void)986*35238bceSAndroid Build Coastguard Worker tcu::TestCase::IterateResult TextureBufferCase::iterate(void)
987*35238bceSAndroid Build Coastguard Worker {
988*35238bceSAndroid Build Coastguard Worker de::Random rng(deInt32Hash(deStringHash(getName())));
989*35238bceSAndroid Build Coastguard Worker size_t offset;
990*35238bceSAndroid Build Coastguard Worker
991*35238bceSAndroid Build Coastguard Worker if (m_offset != 0)
992*35238bceSAndroid Build Coastguard Worker {
993*35238bceSAndroid Build Coastguard Worker const glw::Functions &gl = m_renderCtx.getFunctions();
994*35238bceSAndroid Build Coastguard Worker int32_t alignment = 0;
995*35238bceSAndroid Build Coastguard Worker
996*35238bceSAndroid Build Coastguard Worker gl.getIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, &alignment);
997*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT)");
998*35238bceSAndroid Build Coastguard Worker
999*35238bceSAndroid Build Coastguard Worker offset = m_offset * alignment;
1000*35238bceSAndroid Build Coastguard Worker }
1001*35238bceSAndroid Build Coastguard Worker else
1002*35238bceSAndroid Build Coastguard Worker offset = 0;
1003*35238bceSAndroid Build Coastguard Worker
1004*35238bceSAndroid Build Coastguard Worker runTests(m_testCtx, m_renderCtx, rng, m_format, m_bufferSize, offset, m_size, m_preRender, m_preRenderProgram,
1005*35238bceSAndroid Build Coastguard Worker m_modify, m_postRender, m_postRenderProgram);
1006*35238bceSAndroid Build Coastguard Worker
1007*35238bceSAndroid Build Coastguard Worker return STOP;
1008*35238bceSAndroid Build Coastguard Worker }
1009*35238bceSAndroid Build Coastguard Worker
1010*35238bceSAndroid Build Coastguard Worker } // namespace gls
1011*35238bceSAndroid Build Coastguard Worker } // namespace deqp
1012