xref: /aosp_15_r20/external/deqp/modules/gles31/functional/es31fSRGBDecodeTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program OpenGL ES 3.1 Module
3*35238bceSAndroid Build Coastguard Worker  * -------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  *
5*35238bceSAndroid Build Coastguard Worker  * Copyright 2017 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 format tests.
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "es31fSRGBDecodeTests.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "gluContextInfo.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "gluCallLogWrapper.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "gluRenderContext.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "gluTexture.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "glsTextureTestUtil.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "tcuPixelFormat.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "tcuTestContext.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "gluTextureUtil.hpp"
34*35238bceSAndroid Build Coastguard Worker #include "tcuTextureUtil.hpp"
35*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
36*35238bceSAndroid Build Coastguard Worker #include "gluDefs.hpp"
37*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
38*35238bceSAndroid Build Coastguard Worker #include "deUniquePtr.hpp"
39*35238bceSAndroid Build Coastguard Worker #include "gluPixelTransfer.hpp"
40*35238bceSAndroid Build Coastguard Worker #include "tcuDefs.hpp"
41*35238bceSAndroid Build Coastguard Worker #include "tcuVectorUtil.hpp"
42*35238bceSAndroid Build Coastguard Worker #include "gluObjectWrapper.hpp"
43*35238bceSAndroid Build Coastguard Worker #include "gluStrUtil.hpp"
44*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
45*35238bceSAndroid Build Coastguard Worker #include "deStringUtil.hpp"
46*35238bceSAndroid Build Coastguard Worker 
47*35238bceSAndroid Build Coastguard Worker namespace deqp
48*35238bceSAndroid Build Coastguard Worker {
49*35238bceSAndroid Build Coastguard Worker namespace gles31
50*35238bceSAndroid Build Coastguard Worker {
51*35238bceSAndroid Build Coastguard Worker namespace Functional
52*35238bceSAndroid Build Coastguard Worker {
53*35238bceSAndroid Build Coastguard Worker namespace
54*35238bceSAndroid Build Coastguard Worker {
55*35238bceSAndroid Build Coastguard Worker 
56*35238bceSAndroid Build Coastguard Worker using glu::TextureTestUtil::TEXTURETYPE_2D;
57*35238bceSAndroid Build Coastguard Worker 
58*35238bceSAndroid Build Coastguard Worker enum SRGBDecode
59*35238bceSAndroid Build Coastguard Worker {
60*35238bceSAndroid Build Coastguard Worker     SRGBDECODE_SKIP_DECODE = 0,
61*35238bceSAndroid Build Coastguard Worker     SRGBDECODE_DECODE,
62*35238bceSAndroid Build Coastguard Worker     SRGBDECODE_DECODE_DEFAULT
63*35238bceSAndroid Build Coastguard Worker };
64*35238bceSAndroid Build Coastguard Worker 
65*35238bceSAndroid Build Coastguard Worker enum ShaderOutputs
66*35238bceSAndroid Build Coastguard Worker {
67*35238bceSAndroid Build Coastguard Worker     SHADEROUTPUTS_ONE = 1,
68*35238bceSAndroid Build Coastguard Worker     SHADEROUTPUTS_TWO,
69*35238bceSAndroid Build Coastguard Worker };
70*35238bceSAndroid Build Coastguard Worker 
71*35238bceSAndroid Build Coastguard Worker enum ShaderUniforms
72*35238bceSAndroid Build Coastguard Worker {
73*35238bceSAndroid Build Coastguard Worker     SHADERUNIFORMS_ONE = 1,
74*35238bceSAndroid Build Coastguard Worker     SHADERUNIFORMS_TWO,
75*35238bceSAndroid Build Coastguard Worker };
76*35238bceSAndroid Build Coastguard Worker 
77*35238bceSAndroid Build Coastguard Worker enum ShaderSamplingGroup
78*35238bceSAndroid Build Coastguard Worker {
79*35238bceSAndroid Build Coastguard Worker     SHADERSAMPLINGGROUP_TEXTURE = 0,
80*35238bceSAndroid Build Coastguard Worker     SHADERSAMPLINGGROUP_TEXEL_FETCH
81*35238bceSAndroid Build Coastguard Worker };
82*35238bceSAndroid Build Coastguard Worker 
83*35238bceSAndroid Build Coastguard Worker enum ShaderSamplingType
84*35238bceSAndroid Build Coastguard Worker {
85*35238bceSAndroid Build Coastguard Worker     TEXTURESAMPLING_TEXTURE = 0,
86*35238bceSAndroid Build Coastguard Worker     TEXTURESAMPLING_TEXTURE_LOD,
87*35238bceSAndroid Build Coastguard Worker     TEXTURESAMPLING_TEXTURE_GRAD,
88*35238bceSAndroid Build Coastguard Worker     TEXTURESAMPLING_TEXTURE_OFFSET,
89*35238bceSAndroid Build Coastguard Worker     TEXTURESAMPLING_TEXTURE_PROJ,
90*35238bceSAndroid Build Coastguard Worker     TEXTURESAMPLING_TEXELFETCH,
91*35238bceSAndroid Build Coastguard Worker     TEXTURESAMPLING_TEXELFETCH_OFFSET,
92*35238bceSAndroid Build Coastguard Worker 
93*35238bceSAndroid Build Coastguard Worker     // ranges required for looping mechanism in a case nodes iteration function
94*35238bceSAndroid Build Coastguard Worker     TEXTURESAMPLING_TEXTURE_START    = TEXTURESAMPLING_TEXTURE,
95*35238bceSAndroid Build Coastguard Worker     TEXTURESAMPLING_TEXTURE_END      = TEXTURESAMPLING_TEXTURE_PROJ + 1,
96*35238bceSAndroid Build Coastguard Worker     TEXTURESAMPLING_TEXELFETCH_START = TEXTURESAMPLING_TEXELFETCH,
97*35238bceSAndroid Build Coastguard Worker     TEXTURESAMPLING_TEXELFETCH_END   = TEXTURESAMPLING_TEXELFETCH_OFFSET + 1
98*35238bceSAndroid Build Coastguard Worker };
99*35238bceSAndroid Build Coastguard Worker 
100*35238bceSAndroid Build Coastguard Worker enum FunctionParameters
101*35238bceSAndroid Build Coastguard Worker {
102*35238bceSAndroid Build Coastguard Worker     FUNCTIONPARAMETERS_ONE = 1,
103*35238bceSAndroid Build Coastguard Worker     FUNCTIONPARAMETERS_TWO
104*35238bceSAndroid Build Coastguard Worker };
105*35238bceSAndroid Build Coastguard Worker 
106*35238bceSAndroid Build Coastguard Worker enum Blending
107*35238bceSAndroid Build Coastguard Worker {
108*35238bceSAndroid Build Coastguard Worker     BLENDING_REQUIRED = 0,
109*35238bceSAndroid Build Coastguard Worker     BLENDING_NOT_REQUIRED
110*35238bceSAndroid Build Coastguard Worker };
111*35238bceSAndroid Build Coastguard Worker 
112*35238bceSAndroid Build Coastguard Worker enum Toggling
113*35238bceSAndroid Build Coastguard Worker {
114*35238bceSAndroid Build Coastguard Worker     TOGGLING_REQUIRED = 0,
115*35238bceSAndroid Build Coastguard Worker     TOGGLING_NOT_REQUIRED
116*35238bceSAndroid Build Coastguard Worker };
117*35238bceSAndroid Build Coastguard Worker 
getColorReferenceLinear(void)118*35238bceSAndroid Build Coastguard Worker tcu::Vec4 getColorReferenceLinear(void)
119*35238bceSAndroid Build Coastguard Worker {
120*35238bceSAndroid Build Coastguard Worker     return tcu::Vec4(0.2f, 0.3f, 0.4f, 1.0f);
121*35238bceSAndroid Build Coastguard Worker }
122*35238bceSAndroid Build Coastguard Worker 
getColorReferenceSRGB(void)123*35238bceSAndroid Build Coastguard Worker tcu::Vec4 getColorReferenceSRGB(void)
124*35238bceSAndroid Build Coastguard Worker {
125*35238bceSAndroid Build Coastguard Worker     return tcu::linearToSRGB(tcu::Vec4(0.2f, 0.3f, 0.4f, 1.0f));
126*35238bceSAndroid Build Coastguard Worker }
127*35238bceSAndroid Build Coastguard Worker 
getColorGreenPass(void)128*35238bceSAndroid Build Coastguard Worker tcu::Vec4 getColorGreenPass(void)
129*35238bceSAndroid Build Coastguard Worker {
130*35238bceSAndroid Build Coastguard Worker     return tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f);
131*35238bceSAndroid Build Coastguard Worker }
132*35238bceSAndroid Build Coastguard Worker 
133*35238bceSAndroid Build Coastguard Worker namespace TestDimensions
134*35238bceSAndroid Build Coastguard Worker {
135*35238bceSAndroid Build Coastguard Worker const int WIDTH  = 128;
136*35238bceSAndroid Build Coastguard Worker const int HEIGHT = 128;
137*35238bceSAndroid Build Coastguard Worker } // namespace TestDimensions
138*35238bceSAndroid Build Coastguard Worker 
139*35238bceSAndroid Build Coastguard Worker namespace TestSamplingPositions
140*35238bceSAndroid Build Coastguard Worker {
141*35238bceSAndroid Build Coastguard Worker const int X_POS = 0;
142*35238bceSAndroid Build Coastguard Worker const int Y_POS = 0;
143*35238bceSAndroid Build Coastguard Worker } // namespace TestSamplingPositions
144*35238bceSAndroid Build Coastguard Worker 
getFunctionDefinitionSRGBToLinearCheck(void)145*35238bceSAndroid Build Coastguard Worker const char *getFunctionDefinitionSRGBToLinearCheck(void)
146*35238bceSAndroid Build Coastguard Worker {
147*35238bceSAndroid Build Coastguard Worker     static const char *functionDefinition =
148*35238bceSAndroid Build Coastguard Worker         "mediump vec4 srgbToLinearCheck(in mediump vec4 texelSRGBA, in mediump vec4 texelLinear) \n"
149*35238bceSAndroid Build Coastguard Worker         "{ \n"
150*35238bceSAndroid Build Coastguard Worker         "    const int NUM_CHANNELS = 4;"
151*35238bceSAndroid Build Coastguard Worker         "    mediump vec4 texelSRGBAConverted; \n"
152*35238bceSAndroid Build Coastguard Worker         "    mediump vec4 epsilonErr = vec4(0.005); \n"
153*35238bceSAndroid Build Coastguard Worker         "    mediump vec4 testResult; \n"
154*35238bceSAndroid Build Coastguard Worker         "    for (int idx = 0; idx < NUM_CHANNELS; idx++) \n"
155*35238bceSAndroid Build Coastguard Worker         "    { \n"
156*35238bceSAndroid Build Coastguard Worker         "        texelSRGBAConverted[idx] = pow( (texelSRGBA[idx] + 0.055) / 1.055, 1.0 / 0.4116); \n"
157*35238bceSAndroid Build Coastguard Worker         "    } \n"
158*35238bceSAndroid Build Coastguard Worker         "    if ( all(lessThan(abs(texelSRGBAConverted - texelLinear), epsilonErr)) || all(equal(texelSRGBAConverted, "
159*35238bceSAndroid Build Coastguard Worker         "texelLinear)) ) \n"
160*35238bceSAndroid Build Coastguard Worker         "    { \n"
161*35238bceSAndroid Build Coastguard Worker         "        return testResult = vec4(0.0, 1.0, 0.0, 1.0); \n"
162*35238bceSAndroid Build Coastguard Worker         "    } \n"
163*35238bceSAndroid Build Coastguard Worker         "    else \n"
164*35238bceSAndroid Build Coastguard Worker         "    { \n"
165*35238bceSAndroid Build Coastguard Worker         "        return testResult = vec4(1.0, 0.0, 0.0, 1.0); \n"
166*35238bceSAndroid Build Coastguard Worker         "    } \n"
167*35238bceSAndroid Build Coastguard Worker         "} \n";
168*35238bceSAndroid Build Coastguard Worker 
169*35238bceSAndroid Build Coastguard Worker     return functionDefinition;
170*35238bceSAndroid Build Coastguard Worker }
171*35238bceSAndroid Build Coastguard Worker 
getFunctionDefinitionEqualCheck(void)172*35238bceSAndroid Build Coastguard Worker const char *getFunctionDefinitionEqualCheck(void)
173*35238bceSAndroid Build Coastguard Worker {
174*35238bceSAndroid Build Coastguard Worker     static const char *functionDefinition =
175*35238bceSAndroid Build Coastguard Worker         "mediump vec4 colorsEqualCheck(in mediump vec4 colorA, in mediump vec4 colorB) \n"
176*35238bceSAndroid Build Coastguard Worker         "{ \n"
177*35238bceSAndroid Build Coastguard Worker         "    mediump vec4 epsilonErr = vec4(0.005); \n"
178*35238bceSAndroid Build Coastguard Worker         "    mediump vec4 testResult; \n"
179*35238bceSAndroid Build Coastguard Worker         "    if ( all(lessThan(abs(colorA - colorB), epsilonErr)) || all(equal(colorA, colorB)) ) \n"
180*35238bceSAndroid Build Coastguard Worker         "    { \n"
181*35238bceSAndroid Build Coastguard Worker         "        return testResult = vec4(0.0, 1.0, 0.0, 1.0); \n"
182*35238bceSAndroid Build Coastguard Worker         "    } \n"
183*35238bceSAndroid Build Coastguard Worker         "    else \n"
184*35238bceSAndroid Build Coastguard Worker         "    { \n"
185*35238bceSAndroid Build Coastguard Worker         "        return testResult = vec4(1.0, 0.0, 0.0, 1.0); \n"
186*35238bceSAndroid Build Coastguard Worker         "    } \n"
187*35238bceSAndroid Build Coastguard Worker         "} \n";
188*35238bceSAndroid Build Coastguard Worker 
189*35238bceSAndroid Build Coastguard Worker     return functionDefinition;
190*35238bceSAndroid Build Coastguard Worker }
191*35238bceSAndroid Build Coastguard Worker 
192*35238bceSAndroid Build Coastguard Worker namespace EpsilonError
193*35238bceSAndroid Build Coastguard Worker {
194*35238bceSAndroid Build Coastguard Worker const float CPU = 0.005f;
195*35238bceSAndroid Build Coastguard Worker }
196*35238bceSAndroid Build Coastguard Worker 
197*35238bceSAndroid Build Coastguard Worker struct TestGroupConfig
198*35238bceSAndroid Build Coastguard Worker {
TestGroupConfigdeqp::gles31::Functional::__anonb0efe2200111::TestGroupConfig199*35238bceSAndroid Build Coastguard Worker     TestGroupConfig(const char *groupName, const char *groupDescription, const tcu::TextureFormat groupInternalFormat)
200*35238bceSAndroid Build Coastguard Worker         : name(groupName)
201*35238bceSAndroid Build Coastguard Worker         , description(groupDescription)
202*35238bceSAndroid Build Coastguard Worker         , internalFormat(groupInternalFormat)
203*35238bceSAndroid Build Coastguard Worker     {
204*35238bceSAndroid Build Coastguard Worker     }
205*35238bceSAndroid Build Coastguard Worker 
~TestGroupConfigdeqp::gles31::Functional::__anonb0efe2200111::TestGroupConfig206*35238bceSAndroid Build Coastguard Worker     ~TestGroupConfig(void)
207*35238bceSAndroid Build Coastguard Worker     {
208*35238bceSAndroid Build Coastguard Worker     }
209*35238bceSAndroid Build Coastguard Worker 
210*35238bceSAndroid Build Coastguard Worker     const char *name;
211*35238bceSAndroid Build Coastguard Worker     const char *description;
212*35238bceSAndroid Build Coastguard Worker     const tcu::TextureFormat internalFormat;
213*35238bceSAndroid Build Coastguard Worker };
214*35238bceSAndroid Build Coastguard Worker 
215*35238bceSAndroid Build Coastguard Worker struct UniformData
216*35238bceSAndroid Build Coastguard Worker {
UniformDatadeqp::gles31::Functional::__anonb0efe2200111::UniformData217*35238bceSAndroid Build Coastguard Worker     UniformData(glw::GLuint uniformLocation, const std::string &uniformName)
218*35238bceSAndroid Build Coastguard Worker         : location(uniformLocation)
219*35238bceSAndroid Build Coastguard Worker         , name(uniformName)
220*35238bceSAndroid Build Coastguard Worker         , toggleDecode(false)
221*35238bceSAndroid Build Coastguard Worker     {
222*35238bceSAndroid Build Coastguard Worker     }
223*35238bceSAndroid Build Coastguard Worker 
~UniformDatadeqp::gles31::Functional::__anonb0efe2200111::UniformData224*35238bceSAndroid Build Coastguard Worker     ~UniformData(void)
225*35238bceSAndroid Build Coastguard Worker     {
226*35238bceSAndroid Build Coastguard Worker     }
227*35238bceSAndroid Build Coastguard Worker 
228*35238bceSAndroid Build Coastguard Worker     glw::GLuint location;
229*35238bceSAndroid Build Coastguard Worker     std::string name;
230*35238bceSAndroid Build Coastguard Worker     bool toggleDecode;
231*35238bceSAndroid Build Coastguard Worker };
232*35238bceSAndroid Build Coastguard Worker 
233*35238bceSAndroid Build Coastguard Worker struct UniformToToggle
234*35238bceSAndroid Build Coastguard Worker {
UniformToToggledeqp::gles31::Functional::__anonb0efe2200111::UniformToToggle235*35238bceSAndroid Build Coastguard Worker     UniformToToggle(const int uniformProgramIdx, const std::string &uniformName)
236*35238bceSAndroid Build Coastguard Worker         : programIdx(uniformProgramIdx)
237*35238bceSAndroid Build Coastguard Worker         , name(uniformName)
238*35238bceSAndroid Build Coastguard Worker     {
239*35238bceSAndroid Build Coastguard Worker     }
240*35238bceSAndroid Build Coastguard Worker 
~UniformToToggledeqp::gles31::Functional::__anonb0efe2200111::UniformToToggle241*35238bceSAndroid Build Coastguard Worker     ~UniformToToggle(void)
242*35238bceSAndroid Build Coastguard Worker     {
243*35238bceSAndroid Build Coastguard Worker     }
244*35238bceSAndroid Build Coastguard Worker 
245*35238bceSAndroid Build Coastguard Worker     int programIdx;
246*35238bceSAndroid Build Coastguard Worker     std::string name;
247*35238bceSAndroid Build Coastguard Worker };
248*35238bceSAndroid Build Coastguard Worker 
249*35238bceSAndroid Build Coastguard Worker struct ComparisonFunction
250*35238bceSAndroid Build Coastguard Worker {
ComparisonFunctiondeqp::gles31::Functional::__anonb0efe2200111::ComparisonFunction251*35238bceSAndroid Build Coastguard Worker     ComparisonFunction(const std::string &funcName, const FunctionParameters funcParameters,
252*35238bceSAndroid Build Coastguard Worker                        const std::string &funcImplementation)
253*35238bceSAndroid Build Coastguard Worker         : name(funcName)
254*35238bceSAndroid Build Coastguard Worker         , parameters(funcParameters)
255*35238bceSAndroid Build Coastguard Worker         , implementation(funcImplementation)
256*35238bceSAndroid Build Coastguard Worker     {
257*35238bceSAndroid Build Coastguard Worker     }
258*35238bceSAndroid Build Coastguard Worker 
~ComparisonFunctiondeqp::gles31::Functional::__anonb0efe2200111::ComparisonFunction259*35238bceSAndroid Build Coastguard Worker     ~ComparisonFunction(void)
260*35238bceSAndroid Build Coastguard Worker     {
261*35238bceSAndroid Build Coastguard Worker     }
262*35238bceSAndroid Build Coastguard Worker 
263*35238bceSAndroid Build Coastguard Worker     std::string name;
264*35238bceSAndroid Build Coastguard Worker     FunctionParameters parameters;
265*35238bceSAndroid Build Coastguard Worker     std::string implementation;
266*35238bceSAndroid Build Coastguard Worker };
267*35238bceSAndroid Build Coastguard Worker 
268*35238bceSAndroid Build Coastguard Worker struct FragmentShaderParameters
269*35238bceSAndroid Build Coastguard Worker {
270*35238bceSAndroid Build Coastguard Worker     FragmentShaderParameters(const ShaderOutputs outputTotal, const ShaderUniforms uniformTotal,
271*35238bceSAndroid Build Coastguard Worker                              ComparisonFunction *comparisonFunction, Blending blendRequired, Toggling toggleRequired);
272*35238bceSAndroid Build Coastguard Worker 
273*35238bceSAndroid Build Coastguard Worker     ~FragmentShaderParameters(void);
274*35238bceSAndroid Build Coastguard Worker 
275*35238bceSAndroid Build Coastguard Worker     ShaderOutputs outputTotal;
276*35238bceSAndroid Build Coastguard Worker     ShaderUniforms uniformTotal;
277*35238bceSAndroid Build Coastguard Worker     ShaderSamplingType samplingType;
278*35238bceSAndroid Build Coastguard Worker     std::string functionName;
279*35238bceSAndroid Build Coastguard Worker     FunctionParameters functionParameters;
280*35238bceSAndroid Build Coastguard Worker     std::string functionImplementation;
281*35238bceSAndroid Build Coastguard Worker     bool hasFunction;
282*35238bceSAndroid Build Coastguard Worker     Blending blendRequired;
283*35238bceSAndroid Build Coastguard Worker     Toggling toggleRequired;
284*35238bceSAndroid Build Coastguard Worker     std::vector<std::string> uniformsToToggle;
285*35238bceSAndroid Build Coastguard Worker };
286*35238bceSAndroid Build Coastguard Worker 
FragmentShaderParameters(const ShaderOutputs paramsOutputTotal,const ShaderUniforms paramsUniformTotal,ComparisonFunction * paramsComparisonFunction,Blending paramsBlendRequired,Toggling paramsToggleRequired)287*35238bceSAndroid Build Coastguard Worker FragmentShaderParameters::FragmentShaderParameters(const ShaderOutputs paramsOutputTotal,
288*35238bceSAndroid Build Coastguard Worker                                                    const ShaderUniforms paramsUniformTotal,
289*35238bceSAndroid Build Coastguard Worker                                                    ComparisonFunction *paramsComparisonFunction,
290*35238bceSAndroid Build Coastguard Worker                                                    Blending paramsBlendRequired, Toggling paramsToggleRequired)
291*35238bceSAndroid Build Coastguard Worker     : outputTotal(paramsOutputTotal)
292*35238bceSAndroid Build Coastguard Worker     , uniformTotal(paramsUniformTotal)
293*35238bceSAndroid Build Coastguard Worker     , samplingType(TEXTURESAMPLING_TEXTURE)
294*35238bceSAndroid Build Coastguard Worker     , blendRequired(paramsBlendRequired)
295*35238bceSAndroid Build Coastguard Worker     , toggleRequired(paramsToggleRequired)
296*35238bceSAndroid Build Coastguard Worker {
297*35238bceSAndroid Build Coastguard Worker     if (paramsComparisonFunction != DE_NULL)
298*35238bceSAndroid Build Coastguard Worker     {
299*35238bceSAndroid Build Coastguard Worker         functionName           = paramsComparisonFunction->name;
300*35238bceSAndroid Build Coastguard Worker         functionParameters     = paramsComparisonFunction->parameters;
301*35238bceSAndroid Build Coastguard Worker         functionImplementation = paramsComparisonFunction->implementation;
302*35238bceSAndroid Build Coastguard Worker 
303*35238bceSAndroid Build Coastguard Worker         hasFunction = true;
304*35238bceSAndroid Build Coastguard Worker     }
305*35238bceSAndroid Build Coastguard Worker     else
306*35238bceSAndroid Build Coastguard Worker     {
307*35238bceSAndroid Build Coastguard Worker         hasFunction = false;
308*35238bceSAndroid Build Coastguard Worker     }
309*35238bceSAndroid Build Coastguard Worker }
310*35238bceSAndroid Build Coastguard Worker 
~FragmentShaderParameters(void)311*35238bceSAndroid Build Coastguard Worker FragmentShaderParameters::~FragmentShaderParameters(void)
312*35238bceSAndroid Build Coastguard Worker {
313*35238bceSAndroid Build Coastguard Worker }
314*35238bceSAndroid Build Coastguard Worker 
315*35238bceSAndroid Build Coastguard Worker class SRGBTestSampler
316*35238bceSAndroid Build Coastguard Worker {
317*35238bceSAndroid Build Coastguard Worker public:
318*35238bceSAndroid Build Coastguard Worker     SRGBTestSampler(Context &context, const tcu::Sampler::WrapMode wrapS, const tcu::Sampler::WrapMode wrapT,
319*35238bceSAndroid Build Coastguard Worker                     const tcu::Sampler::FilterMode minFilter, const tcu::Sampler::FilterMode magFilter,
320*35238bceSAndroid Build Coastguard Worker                     const SRGBDecode decoding);
321*35238bceSAndroid Build Coastguard Worker     ~SRGBTestSampler(void);
322*35238bceSAndroid Build Coastguard Worker 
323*35238bceSAndroid Build Coastguard Worker     void setDecode(const SRGBDecode decoding);
324*35238bceSAndroid Build Coastguard Worker     void setTextureUnit(const uint32_t textureUnit);
325*35238bceSAndroid Build Coastguard Worker     void setIsActive(const bool isActive);
326*35238bceSAndroid Build Coastguard Worker 
327*35238bceSAndroid Build Coastguard Worker     bool getIsActive(void) const;
328*35238bceSAndroid Build Coastguard Worker 
329*35238bceSAndroid Build Coastguard Worker     void bindToTexture(void);
330*35238bceSAndroid Build Coastguard Worker 
331*35238bceSAndroid Build Coastguard Worker private:
332*35238bceSAndroid Build Coastguard Worker     const glw::Functions *m_gl;
333*35238bceSAndroid Build Coastguard Worker     uint32_t m_samplerHandle;
334*35238bceSAndroid Build Coastguard Worker     tcu::Sampler::WrapMode m_wrapS;
335*35238bceSAndroid Build Coastguard Worker     tcu::Sampler::WrapMode m_wrapT;
336*35238bceSAndroid Build Coastguard Worker     tcu::Sampler::FilterMode m_minFilter;
337*35238bceSAndroid Build Coastguard Worker     tcu::Sampler::FilterMode m_magFilter;
338*35238bceSAndroid Build Coastguard Worker     SRGBDecode m_decoding;
339*35238bceSAndroid Build Coastguard Worker     uint32_t m_textureUnit;
340*35238bceSAndroid Build Coastguard Worker     bool m_isActive;
341*35238bceSAndroid Build Coastguard Worker };
342*35238bceSAndroid Build Coastguard Worker 
SRGBTestSampler(Context & context,const tcu::Sampler::WrapMode wrapS,const tcu::Sampler::WrapMode wrapT,const tcu::Sampler::FilterMode minFilter,const tcu::Sampler::FilterMode magFilter,const SRGBDecode decoding)343*35238bceSAndroid Build Coastguard Worker SRGBTestSampler::SRGBTestSampler(Context &context, const tcu::Sampler::WrapMode wrapS,
344*35238bceSAndroid Build Coastguard Worker                                  const tcu::Sampler::WrapMode wrapT, const tcu::Sampler::FilterMode minFilter,
345*35238bceSAndroid Build Coastguard Worker                                  const tcu::Sampler::FilterMode magFilter, const SRGBDecode decoding)
346*35238bceSAndroid Build Coastguard Worker     : m_gl(&context.getRenderContext().getFunctions())
347*35238bceSAndroid Build Coastguard Worker     , m_wrapS(wrapS)
348*35238bceSAndroid Build Coastguard Worker     , m_wrapT(wrapT)
349*35238bceSAndroid Build Coastguard Worker     , m_minFilter(minFilter)
350*35238bceSAndroid Build Coastguard Worker     , m_magFilter(magFilter)
351*35238bceSAndroid Build Coastguard Worker     , m_isActive(false)
352*35238bceSAndroid Build Coastguard Worker {
353*35238bceSAndroid Build Coastguard Worker     m_gl->genSamplers(1, &m_samplerHandle);
354*35238bceSAndroid Build Coastguard Worker 
355*35238bceSAndroid Build Coastguard Worker     m_gl->samplerParameteri(m_samplerHandle, GL_TEXTURE_WRAP_S, glu::getGLWrapMode(m_wrapS));
356*35238bceSAndroid Build Coastguard Worker     m_gl->samplerParameteri(m_samplerHandle, GL_TEXTURE_WRAP_T, glu::getGLWrapMode(m_wrapT));
357*35238bceSAndroid Build Coastguard Worker     m_gl->samplerParameteri(m_samplerHandle, GL_TEXTURE_MIN_FILTER, glu::getGLFilterMode(m_minFilter));
358*35238bceSAndroid Build Coastguard Worker     m_gl->samplerParameteri(m_samplerHandle, GL_TEXTURE_MAG_FILTER, glu::getGLFilterMode(m_magFilter));
359*35238bceSAndroid Build Coastguard Worker 
360*35238bceSAndroid Build Coastguard Worker     this->setDecode(decoding);
361*35238bceSAndroid Build Coastguard Worker }
362*35238bceSAndroid Build Coastguard Worker 
~SRGBTestSampler(void)363*35238bceSAndroid Build Coastguard Worker SRGBTestSampler::~SRGBTestSampler(void)
364*35238bceSAndroid Build Coastguard Worker {
365*35238bceSAndroid Build Coastguard Worker     m_gl->deleteSamplers(1, &m_samplerHandle);
366*35238bceSAndroid Build Coastguard Worker }
367*35238bceSAndroid Build Coastguard Worker 
setDecode(const SRGBDecode decoding)368*35238bceSAndroid Build Coastguard Worker void SRGBTestSampler::setDecode(const SRGBDecode decoding)
369*35238bceSAndroid Build Coastguard Worker {
370*35238bceSAndroid Build Coastguard Worker     if (decoding == SRGBDECODE_SKIP_DECODE)
371*35238bceSAndroid Build Coastguard Worker     {
372*35238bceSAndroid Build Coastguard Worker         m_gl->samplerParameteri(m_samplerHandle, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT);
373*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(m_gl->getError(),
374*35238bceSAndroid Build Coastguard Worker                             "samplerParameteri(m_samplerID, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT)");
375*35238bceSAndroid Build Coastguard Worker     }
376*35238bceSAndroid Build Coastguard Worker     else if (decoding == SRGBDECODE_DECODE)
377*35238bceSAndroid Build Coastguard Worker     {
378*35238bceSAndroid Build Coastguard Worker         m_gl->samplerParameteri(m_samplerHandle, GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT);
379*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(m_gl->getError(),
380*35238bceSAndroid Build Coastguard Worker                             "samplerParameteri(m_samplerID, GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT)");
381*35238bceSAndroid Build Coastguard Worker     }
382*35238bceSAndroid Build Coastguard Worker     else
383*35238bceSAndroid Build Coastguard Worker     {
384*35238bceSAndroid Build Coastguard Worker         DE_FATAL("sRGB texture sampler must have either GL_SKIP_DECODE_EXT or GL_DECODE_EXT settings");
385*35238bceSAndroid Build Coastguard Worker     }
386*35238bceSAndroid Build Coastguard Worker 
387*35238bceSAndroid Build Coastguard Worker     m_decoding = decoding;
388*35238bceSAndroid Build Coastguard Worker }
389*35238bceSAndroid Build Coastguard Worker 
setTextureUnit(const uint32_t textureUnit)390*35238bceSAndroid Build Coastguard Worker void SRGBTestSampler::setTextureUnit(const uint32_t textureUnit)
391*35238bceSAndroid Build Coastguard Worker {
392*35238bceSAndroid Build Coastguard Worker     m_textureUnit = textureUnit;
393*35238bceSAndroid Build Coastguard Worker }
394*35238bceSAndroid Build Coastguard Worker 
setIsActive(const bool isActive)395*35238bceSAndroid Build Coastguard Worker void SRGBTestSampler::setIsActive(const bool isActive)
396*35238bceSAndroid Build Coastguard Worker {
397*35238bceSAndroid Build Coastguard Worker     m_isActive = isActive;
398*35238bceSAndroid Build Coastguard Worker }
399*35238bceSAndroid Build Coastguard Worker 
getIsActive(void) const400*35238bceSAndroid Build Coastguard Worker bool SRGBTestSampler::getIsActive(void) const
401*35238bceSAndroid Build Coastguard Worker {
402*35238bceSAndroid Build Coastguard Worker     return m_isActive;
403*35238bceSAndroid Build Coastguard Worker }
404*35238bceSAndroid Build Coastguard Worker 
bindToTexture(void)405*35238bceSAndroid Build Coastguard Worker void SRGBTestSampler::bindToTexture(void)
406*35238bceSAndroid Build Coastguard Worker {
407*35238bceSAndroid Build Coastguard Worker     m_gl->bindSampler(m_textureUnit, m_samplerHandle);
408*35238bceSAndroid Build Coastguard Worker }
409*35238bceSAndroid Build Coastguard Worker 
410*35238bceSAndroid Build Coastguard Worker class SRGBTestTexture
411*35238bceSAndroid Build Coastguard Worker {
412*35238bceSAndroid Build Coastguard Worker public:
413*35238bceSAndroid Build Coastguard Worker     SRGBTestTexture(Context &context, const glu::TextureTestUtil::TextureType targetType,
414*35238bceSAndroid Build Coastguard Worker                     const tcu::TextureFormat internalFormat, const int width, const int height, const tcu::Vec4 color,
415*35238bceSAndroid Build Coastguard Worker                     const tcu::Sampler::WrapMode wrapS, const tcu::Sampler::WrapMode wrapT,
416*35238bceSAndroid Build Coastguard Worker                     const tcu::Sampler::FilterMode minFilter, const tcu::Sampler::FilterMode magFilter,
417*35238bceSAndroid Build Coastguard Worker                     const SRGBDecode decoding);
418*35238bceSAndroid Build Coastguard Worker     ~SRGBTestTexture(void);
419*35238bceSAndroid Build Coastguard Worker 
420*35238bceSAndroid Build Coastguard Worker     void setParameters(void);
421*35238bceSAndroid Build Coastguard Worker     void setDecode(const SRGBDecode decoding);
422*35238bceSAndroid Build Coastguard Worker     void setHasSampler(const bool hasSampler);
423*35238bceSAndroid Build Coastguard Worker 
424*35238bceSAndroid Build Coastguard Worker     uint32_t getHandle(void) const;
425*35238bceSAndroid Build Coastguard Worker     uint32_t getGLTargetType(void) const;
426*35238bceSAndroid Build Coastguard Worker     SRGBDecode getDecode(void) const;
427*35238bceSAndroid Build Coastguard Worker 
428*35238bceSAndroid Build Coastguard Worker     void upload(void);
429*35238bceSAndroid Build Coastguard Worker 
430*35238bceSAndroid Build Coastguard Worker private:
431*35238bceSAndroid Build Coastguard Worker     void setColor(void);
432*35238bceSAndroid Build Coastguard Worker 
433*35238bceSAndroid Build Coastguard Worker     Context &m_context;
434*35238bceSAndroid Build Coastguard Worker     glu::Texture2D m_source;
435*35238bceSAndroid Build Coastguard Worker     glu::TextureTestUtil::TextureType m_targetType;
436*35238bceSAndroid Build Coastguard Worker     const tcu::TextureFormat m_internalFormat;
437*35238bceSAndroid Build Coastguard Worker     const int m_width;
438*35238bceSAndroid Build Coastguard Worker     const int m_height;
439*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 m_color;
440*35238bceSAndroid Build Coastguard Worker     tcu::Sampler::WrapMode m_wrapS;
441*35238bceSAndroid Build Coastguard Worker     tcu::Sampler::WrapMode m_wrapT;
442*35238bceSAndroid Build Coastguard Worker     tcu::Sampler::FilterMode m_minFilter;
443*35238bceSAndroid Build Coastguard Worker     tcu::Sampler::FilterMode m_magFilter;
444*35238bceSAndroid Build Coastguard Worker     SRGBDecode m_decoding;
445*35238bceSAndroid Build Coastguard Worker     bool m_hasSampler;
446*35238bceSAndroid Build Coastguard Worker };
447*35238bceSAndroid Build Coastguard Worker 
SRGBTestTexture(Context & context,const glu::TextureTestUtil::TextureType targetType,const tcu::TextureFormat internalFormat,const int width,const int height,const tcu::Vec4 color,const tcu::Sampler::WrapMode wrapS,const tcu::Sampler::WrapMode wrapT,const tcu::Sampler::FilterMode minFilter,const tcu::Sampler::FilterMode magFilter,SRGBDecode decoding)448*35238bceSAndroid Build Coastguard Worker SRGBTestTexture::SRGBTestTexture(Context &context, const glu::TextureTestUtil::TextureType targetType,
449*35238bceSAndroid Build Coastguard Worker                                  const tcu::TextureFormat internalFormat, const int width, const int height,
450*35238bceSAndroid Build Coastguard Worker                                  const tcu::Vec4 color, const tcu::Sampler::WrapMode wrapS,
451*35238bceSAndroid Build Coastguard Worker                                  const tcu::Sampler::WrapMode wrapT, const tcu::Sampler::FilterMode minFilter,
452*35238bceSAndroid Build Coastguard Worker                                  const tcu::Sampler::FilterMode magFilter, SRGBDecode decoding)
453*35238bceSAndroid Build Coastguard Worker     : m_context(context)
454*35238bceSAndroid Build Coastguard Worker     , m_source(context.getRenderContext(), glu::getInternalFormat(internalFormat), width, height)
455*35238bceSAndroid Build Coastguard Worker     , m_targetType(targetType)
456*35238bceSAndroid Build Coastguard Worker     , m_internalFormat(internalFormat)
457*35238bceSAndroid Build Coastguard Worker     , m_width(width)
458*35238bceSAndroid Build Coastguard Worker     , m_height(height)
459*35238bceSAndroid Build Coastguard Worker     , m_color(color)
460*35238bceSAndroid Build Coastguard Worker     , m_wrapS(wrapS)
461*35238bceSAndroid Build Coastguard Worker     , m_wrapT(wrapT)
462*35238bceSAndroid Build Coastguard Worker     , m_minFilter(minFilter)
463*35238bceSAndroid Build Coastguard Worker     , m_magFilter(magFilter)
464*35238bceSAndroid Build Coastguard Worker     , m_decoding(decoding)
465*35238bceSAndroid Build Coastguard Worker     , m_hasSampler(false)
466*35238bceSAndroid Build Coastguard Worker {
467*35238bceSAndroid Build Coastguard Worker     this->setColor();
468*35238bceSAndroid Build Coastguard Worker }
469*35238bceSAndroid Build Coastguard Worker 
~SRGBTestTexture(void)470*35238bceSAndroid Build Coastguard Worker SRGBTestTexture::~SRGBTestTexture(void)
471*35238bceSAndroid Build Coastguard Worker {
472*35238bceSAndroid Build Coastguard Worker }
473*35238bceSAndroid Build Coastguard Worker 
setParameters(void)474*35238bceSAndroid Build Coastguard Worker void SRGBTestTexture::setParameters(void)
475*35238bceSAndroid Build Coastguard Worker {
476*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
477*35238bceSAndroid Build Coastguard Worker 
478*35238bceSAndroid Build Coastguard Worker     gl.bindTexture(this->getGLTargetType(), this->getHandle());
479*35238bceSAndroid Build Coastguard Worker 
480*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(this->getGLTargetType(), GL_TEXTURE_WRAP_S, glu::getGLWrapMode(m_wrapS));
481*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(this->getGLTargetType(), GL_TEXTURE_WRAP_T, glu::getGLWrapMode(m_wrapT));
482*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(this->getGLTargetType(), GL_TEXTURE_MIN_FILTER, glu::getGLFilterMode(m_minFilter));
483*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(this->getGLTargetType(), GL_TEXTURE_MAG_FILTER, glu::getGLFilterMode(m_magFilter));
484*35238bceSAndroid Build Coastguard Worker 
485*35238bceSAndroid Build Coastguard Worker     gl.bindTexture(this->getGLTargetType(), 0);
486*35238bceSAndroid Build Coastguard Worker 
487*35238bceSAndroid Build Coastguard Worker     setDecode(m_decoding);
488*35238bceSAndroid Build Coastguard Worker }
489*35238bceSAndroid Build Coastguard Worker 
setDecode(const SRGBDecode decoding)490*35238bceSAndroid Build Coastguard Worker void SRGBTestTexture::setDecode(const SRGBDecode decoding)
491*35238bceSAndroid Build Coastguard Worker {
492*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
493*35238bceSAndroid Build Coastguard Worker 
494*35238bceSAndroid Build Coastguard Worker     gl.bindTexture(this->getGLTargetType(), this->getHandle());
495*35238bceSAndroid Build Coastguard Worker 
496*35238bceSAndroid Build Coastguard Worker     switch (decoding)
497*35238bceSAndroid Build Coastguard Worker     {
498*35238bceSAndroid Build Coastguard Worker     case SRGBDECODE_SKIP_DECODE:
499*35238bceSAndroid Build Coastguard Worker     {
500*35238bceSAndroid Build Coastguard Worker         gl.texParameteri(this->getGLTargetType(), GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT);
501*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(),
502*35238bceSAndroid Build Coastguard Worker                             "glTexParameteri(this->getGLTargetType(), GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT)");
503*35238bceSAndroid Build Coastguard Worker         break;
504*35238bceSAndroid Build Coastguard Worker     }
505*35238bceSAndroid Build Coastguard Worker     case SRGBDECODE_DECODE:
506*35238bceSAndroid Build Coastguard Worker     {
507*35238bceSAndroid Build Coastguard Worker         gl.texParameteri(this->getGLTargetType(), GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT);
508*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(),
509*35238bceSAndroid Build Coastguard Worker                             "glTexParameteri(this->getGLTargetType(), GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT)");
510*35238bceSAndroid Build Coastguard Worker         break;
511*35238bceSAndroid Build Coastguard Worker     }
512*35238bceSAndroid Build Coastguard Worker     case SRGBDECODE_DECODE_DEFAULT:
513*35238bceSAndroid Build Coastguard Worker     {
514*35238bceSAndroid Build Coastguard Worker         // do not use srgb decode options. Set to default
515*35238bceSAndroid Build Coastguard Worker         break;
516*35238bceSAndroid Build Coastguard Worker     }
517*35238bceSAndroid Build Coastguard Worker     default:
518*35238bceSAndroid Build Coastguard Worker         DE_FATAL("Error: Decoding option not recognised");
519*35238bceSAndroid Build Coastguard Worker     }
520*35238bceSAndroid Build Coastguard Worker 
521*35238bceSAndroid Build Coastguard Worker     gl.bindTexture(this->getGLTargetType(), 0);
522*35238bceSAndroid Build Coastguard Worker 
523*35238bceSAndroid Build Coastguard Worker     m_decoding = decoding;
524*35238bceSAndroid Build Coastguard Worker }
525*35238bceSAndroid Build Coastguard Worker 
setHasSampler(const bool hasSampler)526*35238bceSAndroid Build Coastguard Worker void SRGBTestTexture::setHasSampler(const bool hasSampler)
527*35238bceSAndroid Build Coastguard Worker {
528*35238bceSAndroid Build Coastguard Worker     m_hasSampler = hasSampler;
529*35238bceSAndroid Build Coastguard Worker }
530*35238bceSAndroid Build Coastguard Worker 
getHandle(void) const531*35238bceSAndroid Build Coastguard Worker uint32_t SRGBTestTexture::getHandle(void) const
532*35238bceSAndroid Build Coastguard Worker {
533*35238bceSAndroid Build Coastguard Worker     return m_source.getGLTexture();
534*35238bceSAndroid Build Coastguard Worker }
535*35238bceSAndroid Build Coastguard Worker 
getGLTargetType(void) const536*35238bceSAndroid Build Coastguard Worker uint32_t SRGBTestTexture::getGLTargetType(void) const
537*35238bceSAndroid Build Coastguard Worker {
538*35238bceSAndroid Build Coastguard Worker     switch (m_targetType)
539*35238bceSAndroid Build Coastguard Worker     {
540*35238bceSAndroid Build Coastguard Worker     case TEXTURETYPE_2D:
541*35238bceSAndroid Build Coastguard Worker     {
542*35238bceSAndroid Build Coastguard Worker         return GL_TEXTURE_2D;
543*35238bceSAndroid Build Coastguard Worker     }
544*35238bceSAndroid Build Coastguard Worker     default:
545*35238bceSAndroid Build Coastguard Worker     {
546*35238bceSAndroid Build Coastguard Worker         DE_FATAL("Error: Target type not recognised");
547*35238bceSAndroid Build Coastguard Worker         return -1;
548*35238bceSAndroid Build Coastguard Worker     }
549*35238bceSAndroid Build Coastguard Worker     }
550*35238bceSAndroid Build Coastguard Worker }
551*35238bceSAndroid Build Coastguard Worker 
getDecode(void) const552*35238bceSAndroid Build Coastguard Worker SRGBDecode SRGBTestTexture::getDecode(void) const
553*35238bceSAndroid Build Coastguard Worker {
554*35238bceSAndroid Build Coastguard Worker     return m_decoding;
555*35238bceSAndroid Build Coastguard Worker }
556*35238bceSAndroid Build Coastguard Worker 
upload(void)557*35238bceSAndroid Build Coastguard Worker void SRGBTestTexture::upload(void)
558*35238bceSAndroid Build Coastguard Worker {
559*35238bceSAndroid Build Coastguard Worker     m_source.upload();
560*35238bceSAndroid Build Coastguard Worker }
561*35238bceSAndroid Build Coastguard Worker 
setColor(void)562*35238bceSAndroid Build Coastguard Worker void SRGBTestTexture::setColor(void)
563*35238bceSAndroid Build Coastguard Worker {
564*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
565*35238bceSAndroid Build Coastguard Worker 
566*35238bceSAndroid Build Coastguard Worker     gl.bindTexture(this->getGLTargetType(), this->getHandle());
567*35238bceSAndroid Build Coastguard Worker 
568*35238bceSAndroid Build Coastguard Worker     m_source.getRefTexture().allocLevel(0);
569*35238bceSAndroid Build Coastguard Worker 
570*35238bceSAndroid Build Coastguard Worker     for (int py = 0; py < m_height; py++)
571*35238bceSAndroid Build Coastguard Worker     {
572*35238bceSAndroid Build Coastguard Worker         for (int px = 0; px < m_width; px++)
573*35238bceSAndroid Build Coastguard Worker         {
574*35238bceSAndroid Build Coastguard Worker             m_source.getRefTexture().getLevel(0).setPixel(m_color, px, py);
575*35238bceSAndroid Build Coastguard Worker         }
576*35238bceSAndroid Build Coastguard Worker     }
577*35238bceSAndroid Build Coastguard Worker 
578*35238bceSAndroid Build Coastguard Worker     gl.bindTexture(this->getGLTargetType(), 0);
579*35238bceSAndroid Build Coastguard Worker }
580*35238bceSAndroid Build Coastguard Worker 
581*35238bceSAndroid Build Coastguard Worker class SRGBTestProgram
582*35238bceSAndroid Build Coastguard Worker {
583*35238bceSAndroid Build Coastguard Worker public:
584*35238bceSAndroid Build Coastguard Worker     SRGBTestProgram(Context &context, const FragmentShaderParameters &shaderParameters);
585*35238bceSAndroid Build Coastguard Worker     ~SRGBTestProgram(void);
586*35238bceSAndroid Build Coastguard Worker 
587*35238bceSAndroid Build Coastguard Worker     void setBlendRequired(bool blendRequired);
588*35238bceSAndroid Build Coastguard Worker     void setToggleRequired(bool toggleRequired);
589*35238bceSAndroid Build Coastguard Worker     void setUniformToggle(int location, bool toggleDecodeValue);
590*35238bceSAndroid Build Coastguard Worker 
591*35238bceSAndroid Build Coastguard Worker     const std::vector<UniformData> &getUniformDataList(void) const;
592*35238bceSAndroid Build Coastguard Worker     int getUniformLocation(const std::string &name);
593*35238bceSAndroid Build Coastguard Worker     uint32_t getHandle(void) const;
594*35238bceSAndroid Build Coastguard Worker     bool getBlendRequired(void) const;
595*35238bceSAndroid Build Coastguard Worker 
596*35238bceSAndroid Build Coastguard Worker private:
597*35238bceSAndroid Build Coastguard Worker     std::string genFunctionCall(ShaderSamplingType samplingType, const int uniformIdx);
598*35238bceSAndroid Build Coastguard Worker     void genFragmentShader(void);
599*35238bceSAndroid Build Coastguard Worker 
600*35238bceSAndroid Build Coastguard Worker     Context &m_context;
601*35238bceSAndroid Build Coastguard Worker     de::MovePtr<glu::ShaderProgram> m_program;
602*35238bceSAndroid Build Coastguard Worker     FragmentShaderParameters m_shaderFragmentParameters;
603*35238bceSAndroid Build Coastguard Worker     std::string m_shaderVertex;
604*35238bceSAndroid Build Coastguard Worker     std::string m_shaderFragment;
605*35238bceSAndroid Build Coastguard Worker     std::vector<UniformData> m_uniformDataList;
606*35238bceSAndroid Build Coastguard Worker     bool m_blendRequired;
607*35238bceSAndroid Build Coastguard Worker     bool m_toggleRequired;
608*35238bceSAndroid Build Coastguard Worker };
609*35238bceSAndroid Build Coastguard Worker 
SRGBTestProgram(Context & context,const FragmentShaderParameters & shaderParameters)610*35238bceSAndroid Build Coastguard Worker SRGBTestProgram::SRGBTestProgram(Context &context, const FragmentShaderParameters &shaderParameters)
611*35238bceSAndroid Build Coastguard Worker     : m_context(context)
612*35238bceSAndroid Build Coastguard Worker     , m_shaderFragmentParameters(shaderParameters)
613*35238bceSAndroid Build Coastguard Worker     , m_blendRequired(false)
614*35238bceSAndroid Build Coastguard Worker     , m_toggleRequired(false)
615*35238bceSAndroid Build Coastguard Worker {
616*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
617*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log        = m_context.getTestContext().getLog();
618*35238bceSAndroid Build Coastguard Worker     glu::ShaderProgramInfo buildInfo;
619*35238bceSAndroid Build Coastguard Worker     const int totalShaderStages = 2;
620*35238bceSAndroid Build Coastguard Worker 
621*35238bceSAndroid Build Coastguard Worker     // default vertex shader used in all tests
622*35238bceSAndroid Build Coastguard Worker     std::string ver(glu::isContextTypeGLCore(m_context.getRenderContext().getType()) ? "#version 450\n" :
623*35238bceSAndroid Build Coastguard Worker                                                                                        "#version 310 es\n");
624*35238bceSAndroid Build Coastguard Worker     m_shaderVertex = ver + "layout (location = 0) in mediump vec3 aPosition; \n"
625*35238bceSAndroid Build Coastguard Worker                            "layout (location = 1) in mediump vec2 aTexCoord; \n"
626*35238bceSAndroid Build Coastguard Worker                            "out mediump vec2 vs_aTexCoord; \n"
627*35238bceSAndroid Build Coastguard Worker                            "void main () \n"
628*35238bceSAndroid Build Coastguard Worker                            "{ \n"
629*35238bceSAndroid Build Coastguard Worker                            "    gl_Position = vec4(aPosition, 1.0); \n"
630*35238bceSAndroid Build Coastguard Worker                            "    vs_aTexCoord = aTexCoord; \n"
631*35238bceSAndroid Build Coastguard Worker                            "} \n";
632*35238bceSAndroid Build Coastguard Worker 
633*35238bceSAndroid Build Coastguard Worker     this->genFragmentShader();
634*35238bceSAndroid Build Coastguard Worker 
635*35238bceSAndroid Build Coastguard Worker     m_program = de::MovePtr<glu::ShaderProgram>(new glu::ShaderProgram(
636*35238bceSAndroid Build Coastguard Worker         m_context.getRenderContext(), glu::makeVtxFragSources(m_shaderVertex, m_shaderFragment)));
637*35238bceSAndroid Build Coastguard Worker 
638*35238bceSAndroid Build Coastguard Worker     if (!m_program->isOk())
639*35238bceSAndroid Build Coastguard Worker     {
640*35238bceSAndroid Build Coastguard Worker         TCU_FAIL("Failed to compile shaders and link program");
641*35238bceSAndroid Build Coastguard Worker     }
642*35238bceSAndroid Build Coastguard Worker 
643*35238bceSAndroid Build Coastguard Worker     glw::GLint activeUniforms, maxLen;
644*35238bceSAndroid Build Coastguard Worker     glw::GLint size, location;
645*35238bceSAndroid Build Coastguard Worker     glw::GLenum type;
646*35238bceSAndroid Build Coastguard Worker 
647*35238bceSAndroid Build Coastguard Worker     gl.getProgramiv(this->getHandle(), GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLen);
648*35238bceSAndroid Build Coastguard Worker     gl.getProgramiv(this->getHandle(), GL_ACTIVE_UNIFORMS, &activeUniforms);
649*35238bceSAndroid Build Coastguard Worker 
650*35238bceSAndroid Build Coastguard Worker     std::vector<glw::GLchar> uniformName(static_cast<int>(maxLen));
651*35238bceSAndroid Build Coastguard Worker     for (int idx = 0; idx < activeUniforms; idx++)
652*35238bceSAndroid Build Coastguard Worker     {
653*35238bceSAndroid Build Coastguard Worker         gl.getActiveUniform(this->getHandle(), idx, maxLen, NULL, &size, &type, &uniformName[0]);
654*35238bceSAndroid Build Coastguard Worker         location = gl.getUniformLocation(this->getHandle(), &uniformName[0]);
655*35238bceSAndroid Build Coastguard Worker 
656*35238bceSAndroid Build Coastguard Worker         UniformData uniformData(location, std::string(&uniformName[0], strlen(&uniformName[0])));
657*35238bceSAndroid Build Coastguard Worker         m_uniformDataList.push_back(uniformData);
658*35238bceSAndroid Build Coastguard Worker     }
659*35238bceSAndroid Build Coastguard Worker 
660*35238bceSAndroid Build Coastguard Worker     // log shader program info. Only vertex and fragment shaders included
661*35238bceSAndroid Build Coastguard Worker     buildInfo.program = m_program->getProgramInfo();
662*35238bceSAndroid Build Coastguard Worker     for (int shaderIdx = 0; shaderIdx < totalShaderStages; shaderIdx++)
663*35238bceSAndroid Build Coastguard Worker     {
664*35238bceSAndroid Build Coastguard Worker         glu::ShaderInfo shaderInfo = m_program->getShaderInfo(
665*35238bceSAndroid Build Coastguard Worker             static_cast<glu::ShaderType>(static_cast<int>(glu::SHADERTYPE_VERTEX) + static_cast<int>(shaderIdx)), 0);
666*35238bceSAndroid Build Coastguard Worker         buildInfo.shaders.push_back(shaderInfo);
667*35238bceSAndroid Build Coastguard Worker     }
668*35238bceSAndroid Build Coastguard Worker 
669*35238bceSAndroid Build Coastguard Worker     log << buildInfo;
670*35238bceSAndroid Build Coastguard Worker }
671*35238bceSAndroid Build Coastguard Worker 
~SRGBTestProgram(void)672*35238bceSAndroid Build Coastguard Worker SRGBTestProgram::~SRGBTestProgram(void)
673*35238bceSAndroid Build Coastguard Worker {
674*35238bceSAndroid Build Coastguard Worker     m_program = de::MovePtr<glu::ShaderProgram>(DE_NULL);
675*35238bceSAndroid Build Coastguard Worker }
676*35238bceSAndroid Build Coastguard Worker 
setBlendRequired(bool blendRequired)677*35238bceSAndroid Build Coastguard Worker void SRGBTestProgram::setBlendRequired(bool blendRequired)
678*35238bceSAndroid Build Coastguard Worker {
679*35238bceSAndroid Build Coastguard Worker     m_blendRequired = blendRequired;
680*35238bceSAndroid Build Coastguard Worker }
681*35238bceSAndroid Build Coastguard Worker 
setToggleRequired(bool toggleRequired)682*35238bceSAndroid Build Coastguard Worker void SRGBTestProgram::setToggleRequired(bool toggleRequired)
683*35238bceSAndroid Build Coastguard Worker {
684*35238bceSAndroid Build Coastguard Worker     m_toggleRequired = toggleRequired;
685*35238bceSAndroid Build Coastguard Worker }
686*35238bceSAndroid Build Coastguard Worker 
setUniformToggle(int location,bool toggleDecodeValue)687*35238bceSAndroid Build Coastguard Worker void SRGBTestProgram::setUniformToggle(int location, bool toggleDecodeValue)
688*35238bceSAndroid Build Coastguard Worker {
689*35238bceSAndroid Build Coastguard Worker     if ((m_uniformDataList.empty() == false) && (location >= 0) && (location <= (int)m_uniformDataList.size()))
690*35238bceSAndroid Build Coastguard Worker     {
691*35238bceSAndroid Build Coastguard Worker         m_uniformDataList[location].toggleDecode = toggleDecodeValue;
692*35238bceSAndroid Build Coastguard Worker     }
693*35238bceSAndroid Build Coastguard Worker     else
694*35238bceSAndroid Build Coastguard Worker     {
695*35238bceSAndroid Build Coastguard Worker         TCU_THROW(TestError, "Error: Uniform location not found. glGetActiveUniforms returned uniforms incorrectly ");
696*35238bceSAndroid Build Coastguard Worker     }
697*35238bceSAndroid Build Coastguard Worker }
698*35238bceSAndroid Build Coastguard Worker 
getUniformDataList(void) const699*35238bceSAndroid Build Coastguard Worker const std::vector<UniformData> &SRGBTestProgram::getUniformDataList(void) const
700*35238bceSAndroid Build Coastguard Worker {
701*35238bceSAndroid Build Coastguard Worker     return m_uniformDataList;
702*35238bceSAndroid Build Coastguard Worker }
703*35238bceSAndroid Build Coastguard Worker 
getUniformLocation(const std::string & name)704*35238bceSAndroid Build Coastguard Worker int SRGBTestProgram::getUniformLocation(const std::string &name)
705*35238bceSAndroid Build Coastguard Worker {
706*35238bceSAndroid Build Coastguard Worker     for (std::size_t idx = 0; idx < m_uniformDataList.size(); idx++)
707*35238bceSAndroid Build Coastguard Worker     {
708*35238bceSAndroid Build Coastguard Worker         if (m_uniformDataList[idx].name == name)
709*35238bceSAndroid Build Coastguard Worker         {
710*35238bceSAndroid Build Coastguard Worker             return m_uniformDataList[idx].location;
711*35238bceSAndroid Build Coastguard Worker         }
712*35238bceSAndroid Build Coastguard Worker     }
713*35238bceSAndroid Build Coastguard Worker 
714*35238bceSAndroid Build Coastguard Worker     TCU_THROW(TestError,
715*35238bceSAndroid Build Coastguard Worker               "Error: If name correctly requested then glGetActiveUniforms() returned active uniform data incorrectly");
716*35238bceSAndroid Build Coastguard Worker     return -1;
717*35238bceSAndroid Build Coastguard Worker }
718*35238bceSAndroid Build Coastguard Worker 
getHandle(void) const719*35238bceSAndroid Build Coastguard Worker glw::GLuint SRGBTestProgram::getHandle(void) const
720*35238bceSAndroid Build Coastguard Worker {
721*35238bceSAndroid Build Coastguard Worker     return m_program->getProgram();
722*35238bceSAndroid Build Coastguard Worker }
723*35238bceSAndroid Build Coastguard Worker 
getBlendRequired(void) const724*35238bceSAndroid Build Coastguard Worker bool SRGBTestProgram::getBlendRequired(void) const
725*35238bceSAndroid Build Coastguard Worker {
726*35238bceSAndroid Build Coastguard Worker     return m_blendRequired;
727*35238bceSAndroid Build Coastguard Worker }
728*35238bceSAndroid Build Coastguard Worker 
genFunctionCall(ShaderSamplingType samplingType,const int uniformIdx)729*35238bceSAndroid Build Coastguard Worker std::string SRGBTestProgram::genFunctionCall(ShaderSamplingType samplingType, const int uniformIdx)
730*35238bceSAndroid Build Coastguard Worker {
731*35238bceSAndroid Build Coastguard Worker     std::ostringstream functionCall;
732*35238bceSAndroid Build Coastguard Worker 
733*35238bceSAndroid Build Coastguard Worker     functionCall << "    mediump vec4 texelColor" << uniformIdx << " = ";
734*35238bceSAndroid Build Coastguard Worker 
735*35238bceSAndroid Build Coastguard Worker     switch (samplingType)
736*35238bceSAndroid Build Coastguard Worker     {
737*35238bceSAndroid Build Coastguard Worker     case TEXTURESAMPLING_TEXTURE:
738*35238bceSAndroid Build Coastguard Worker     {
739*35238bceSAndroid Build Coastguard Worker         functionCall << "texture(uTexture" << uniformIdx << ", vs_aTexCoord); \n";
740*35238bceSAndroid Build Coastguard Worker         break;
741*35238bceSAndroid Build Coastguard Worker     }
742*35238bceSAndroid Build Coastguard Worker     case TEXTURESAMPLING_TEXTURE_LOD:
743*35238bceSAndroid Build Coastguard Worker     {
744*35238bceSAndroid Build Coastguard Worker         functionCall << "textureLod(uTexture" << uniformIdx << ", vs_aTexCoord, 0.0); \n";
745*35238bceSAndroid Build Coastguard Worker         break;
746*35238bceSAndroid Build Coastguard Worker     }
747*35238bceSAndroid Build Coastguard Worker     case TEXTURESAMPLING_TEXTURE_GRAD:
748*35238bceSAndroid Build Coastguard Worker     {
749*35238bceSAndroid Build Coastguard Worker         functionCall << "textureGrad(uTexture" << uniformIdx << ", vs_aTexCoord, vec2(0.0, 0.0), vec2(0.0, 0.0)); \n";
750*35238bceSAndroid Build Coastguard Worker         break;
751*35238bceSAndroid Build Coastguard Worker     }
752*35238bceSAndroid Build Coastguard Worker     case TEXTURESAMPLING_TEXTURE_OFFSET:
753*35238bceSAndroid Build Coastguard Worker     {
754*35238bceSAndroid Build Coastguard Worker         functionCall << "textureOffset(uTexture" << uniformIdx << ", vs_aTexCoord, ivec2(0.0, 0.0)); \n";
755*35238bceSAndroid Build Coastguard Worker         break;
756*35238bceSAndroid Build Coastguard Worker     }
757*35238bceSAndroid Build Coastguard Worker     case TEXTURESAMPLING_TEXTURE_PROJ:
758*35238bceSAndroid Build Coastguard Worker     {
759*35238bceSAndroid Build Coastguard Worker         functionCall << "textureProj(uTexture" << uniformIdx << ", vec3(vs_aTexCoord, 1.0)); \n";
760*35238bceSAndroid Build Coastguard Worker         break;
761*35238bceSAndroid Build Coastguard Worker     }
762*35238bceSAndroid Build Coastguard Worker     case TEXTURESAMPLING_TEXELFETCH:
763*35238bceSAndroid Build Coastguard Worker     {
764*35238bceSAndroid Build Coastguard Worker         functionCall << "texelFetch(uTexture" << uniformIdx << ", ivec2(vs_aTexCoord), 0); \n";
765*35238bceSAndroid Build Coastguard Worker         break;
766*35238bceSAndroid Build Coastguard Worker     }
767*35238bceSAndroid Build Coastguard Worker     case TEXTURESAMPLING_TEXELFETCH_OFFSET:
768*35238bceSAndroid Build Coastguard Worker     {
769*35238bceSAndroid Build Coastguard Worker         functionCall << "texelFetchOffset(uTexture" << uniformIdx << ", ivec2(vs_aTexCoord), 0, ivec2(0.0, 0.0)); \n";
770*35238bceSAndroid Build Coastguard Worker         break;
771*35238bceSAndroid Build Coastguard Worker     }
772*35238bceSAndroid Build Coastguard Worker     default:
773*35238bceSAndroid Build Coastguard Worker     {
774*35238bceSAndroid Build Coastguard Worker         DE_FATAL("Error: Sampling type not recognised");
775*35238bceSAndroid Build Coastguard Worker     }
776*35238bceSAndroid Build Coastguard Worker     }
777*35238bceSAndroid Build Coastguard Worker 
778*35238bceSAndroid Build Coastguard Worker     return functionCall.str();
779*35238bceSAndroid Build Coastguard Worker }
780*35238bceSAndroid Build Coastguard Worker 
genFragmentShader(void)781*35238bceSAndroid Build Coastguard Worker void SRGBTestProgram::genFragmentShader(void)
782*35238bceSAndroid Build Coastguard Worker {
783*35238bceSAndroid Build Coastguard Worker     std::ostringstream source;
784*35238bceSAndroid Build Coastguard Worker     std::ostringstream sampleTexture;
785*35238bceSAndroid Build Coastguard Worker     std::ostringstream functionParameters;
786*35238bceSAndroid Build Coastguard Worker     std::ostringstream shaderOutputs;
787*35238bceSAndroid Build Coastguard Worker 
788*35238bceSAndroid Build Coastguard Worker     // if comparison function is present resulting shader requires precisely one output
789*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(!(m_shaderFragmentParameters.hasFunction &&
790*35238bceSAndroid Build Coastguard Worker                 (static_cast<int>(m_shaderFragmentParameters.outputTotal) != static_cast<int>(SHADEROUTPUTS_ONE))));
791*35238bceSAndroid Build Coastguard Worker 
792*35238bceSAndroid Build Coastguard Worker     // function parameters must equal the number of uniforms i.e. textures passed into the function
793*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(
794*35238bceSAndroid Build Coastguard Worker         !(m_shaderFragmentParameters.hasFunction && (static_cast<int>(m_shaderFragmentParameters.uniformTotal) !=
795*35238bceSAndroid Build Coastguard Worker                                                      static_cast<int>(m_shaderFragmentParameters.functionParameters))));
796*35238bceSAndroid Build Coastguard Worker 
797*35238bceSAndroid Build Coastguard Worker     // fragment shader cannot contain more outputs than the number of texture uniforms
798*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(!(static_cast<int>(m_shaderFragmentParameters.outputTotal) >
799*35238bceSAndroid Build Coastguard Worker                 static_cast<int>(m_shaderFragmentParameters.uniformTotal)));
800*35238bceSAndroid Build Coastguard Worker 
801*35238bceSAndroid Build Coastguard Worker     source << (glu::isContextTypeGLCore(m_context.getRenderContext().getType()) ? "#version 450\n" :
802*35238bceSAndroid Build Coastguard Worker                                                                                   "#version 310 es\n")
803*35238bceSAndroid Build Coastguard Worker            << "in mediump vec2 vs_aTexCoord; \n";
804*35238bceSAndroid Build Coastguard Worker 
805*35238bceSAndroid Build Coastguard Worker     for (int output = 0; output < m_shaderFragmentParameters.outputTotal; output++)
806*35238bceSAndroid Build Coastguard Worker     {
807*35238bceSAndroid Build Coastguard Worker         source << "layout (location = " << output << ") out mediump vec4 fs_aColor" << output << "; \n";
808*35238bceSAndroid Build Coastguard Worker     }
809*35238bceSAndroid Build Coastguard Worker 
810*35238bceSAndroid Build Coastguard Worker     for (int uniform = 0; uniform < m_shaderFragmentParameters.uniformTotal; uniform++)
811*35238bceSAndroid Build Coastguard Worker     {
812*35238bceSAndroid Build Coastguard Worker         source << "uniform sampler2D uTexture" << uniform << "; \n";
813*35238bceSAndroid Build Coastguard Worker     }
814*35238bceSAndroid Build Coastguard Worker 
815*35238bceSAndroid Build Coastguard Worker     if (m_shaderFragmentParameters.hasFunction == true)
816*35238bceSAndroid Build Coastguard Worker     {
817*35238bceSAndroid Build Coastguard Worker         source << m_shaderFragmentParameters.functionImplementation;
818*35238bceSAndroid Build Coastguard Worker     }
819*35238bceSAndroid Build Coastguard Worker 
820*35238bceSAndroid Build Coastguard Worker     source << "void main () \n"
821*35238bceSAndroid Build Coastguard Worker            << "{ \n";
822*35238bceSAndroid Build Coastguard Worker 
823*35238bceSAndroid Build Coastguard Worker     for (int uniformIdx = 0; uniformIdx < m_shaderFragmentParameters.uniformTotal; uniformIdx++)
824*35238bceSAndroid Build Coastguard Worker     {
825*35238bceSAndroid Build Coastguard Worker         source << this->genFunctionCall(m_shaderFragmentParameters.samplingType, uniformIdx);
826*35238bceSAndroid Build Coastguard Worker     }
827*35238bceSAndroid Build Coastguard Worker 
828*35238bceSAndroid Build Coastguard Worker     if (m_shaderFragmentParameters.hasFunction == true)
829*35238bceSAndroid Build Coastguard Worker     {
830*35238bceSAndroid Build Coastguard Worker         switch (static_cast<FunctionParameters>(m_shaderFragmentParameters.functionParameters))
831*35238bceSAndroid Build Coastguard Worker         {
832*35238bceSAndroid Build Coastguard Worker         case FUNCTIONPARAMETERS_ONE:
833*35238bceSAndroid Build Coastguard Worker         {
834*35238bceSAndroid Build Coastguard Worker             functionParameters << "(texelColor0)";
835*35238bceSAndroid Build Coastguard Worker             break;
836*35238bceSAndroid Build Coastguard Worker         }
837*35238bceSAndroid Build Coastguard Worker         case FUNCTIONPARAMETERS_TWO:
838*35238bceSAndroid Build Coastguard Worker         {
839*35238bceSAndroid Build Coastguard Worker             functionParameters << "(texelColor0, texelColor1)";
840*35238bceSAndroid Build Coastguard Worker             break;
841*35238bceSAndroid Build Coastguard Worker         }
842*35238bceSAndroid Build Coastguard Worker         default:
843*35238bceSAndroid Build Coastguard Worker         {
844*35238bceSAndroid Build Coastguard Worker             DE_FATAL("Error: Number of comparison function parameters invalid");
845*35238bceSAndroid Build Coastguard Worker         }
846*35238bceSAndroid Build Coastguard Worker         }
847*35238bceSAndroid Build Coastguard Worker 
848*35238bceSAndroid Build Coastguard Worker         shaderOutputs << "    fs_aColor0 = " << m_shaderFragmentParameters.functionName << functionParameters.str()
849*35238bceSAndroid Build Coastguard Worker                       << "; \n";
850*35238bceSAndroid Build Coastguard Worker     }
851*35238bceSAndroid Build Coastguard Worker     else
852*35238bceSAndroid Build Coastguard Worker     {
853*35238bceSAndroid Build Coastguard Worker         for (int output = 0; output < m_shaderFragmentParameters.outputTotal; output++)
854*35238bceSAndroid Build Coastguard Worker         {
855*35238bceSAndroid Build Coastguard Worker             shaderOutputs << "    fs_aColor" << output << " = texelColor" << output << "; \n";
856*35238bceSAndroid Build Coastguard Worker         }
857*35238bceSAndroid Build Coastguard Worker     }
858*35238bceSAndroid Build Coastguard Worker 
859*35238bceSAndroid Build Coastguard Worker     source << shaderOutputs.str();
860*35238bceSAndroid Build Coastguard Worker     source << "} \n";
861*35238bceSAndroid Build Coastguard Worker 
862*35238bceSAndroid Build Coastguard Worker     m_shaderFragment = source.str();
863*35238bceSAndroid Build Coastguard Worker }
864*35238bceSAndroid Build Coastguard Worker 
865*35238bceSAndroid Build Coastguard Worker class SRGBTestCase : public TestCase
866*35238bceSAndroid Build Coastguard Worker {
867*35238bceSAndroid Build Coastguard Worker public:
868*35238bceSAndroid Build Coastguard Worker     SRGBTestCase(Context &context, const char *name, const char *description, const tcu::TextureFormat internalFormat);
869*35238bceSAndroid Build Coastguard Worker     ~SRGBTestCase(void);
870*35238bceSAndroid Build Coastguard Worker 
871*35238bceSAndroid Build Coastguard Worker     void init(void);
872*35238bceSAndroid Build Coastguard Worker     void deinit(void);
873*35238bceSAndroid Build Coastguard Worker     virtual IterateResult iterate(void);
874*35238bceSAndroid Build Coastguard Worker 
875*35238bceSAndroid Build Coastguard Worker     void setSamplingGroup(const ShaderSamplingGroup samplingGroup);
876*35238bceSAndroid Build Coastguard Worker     void setSamplingLocations(const int px, const int py);
877*35238bceSAndroid Build Coastguard Worker     void setUniformToggle(const int programIdx, const std::string &uniformName, bool toggleDecode);
878*35238bceSAndroid Build Coastguard Worker 
879*35238bceSAndroid Build Coastguard Worker     void addTexture(const glu::TextureTestUtil::TextureType targetType, const int width, const int height,
880*35238bceSAndroid Build Coastguard Worker                     const tcu::Vec4 color, const tcu::Sampler::WrapMode wrapS, const tcu::Sampler::WrapMode wrapT,
881*35238bceSAndroid Build Coastguard Worker                     const tcu::Sampler::FilterMode minFilter, const tcu::Sampler::FilterMode magFilter,
882*35238bceSAndroid Build Coastguard Worker                     const SRGBDecode decoding);
883*35238bceSAndroid Build Coastguard Worker     void addSampler(const tcu::Sampler::WrapMode wrapS, const tcu::Sampler::WrapMode wrapT,
884*35238bceSAndroid Build Coastguard Worker                     const tcu::Sampler::FilterMode minFilter, const tcu::Sampler::FilterMode magFilter,
885*35238bceSAndroid Build Coastguard Worker                     const SRGBDecode decoding);
886*35238bceSAndroid Build Coastguard Worker     void addShaderProgram(const FragmentShaderParameters &shaderParameters);
887*35238bceSAndroid Build Coastguard Worker 
888*35238bceSAndroid Build Coastguard Worker     void genShaderPrograms(ShaderSamplingType samplingType);
889*35238bceSAndroid Build Coastguard Worker     void deleteShaderPrograms(void);
890*35238bceSAndroid Build Coastguard Worker 
891*35238bceSAndroid Build Coastguard Worker     void readResultTextures(void);
892*35238bceSAndroid Build Coastguard Worker     void storeResultPixels(std::vector<tcu::Vec4> &resultPixelData);
893*35238bceSAndroid Build Coastguard Worker 
894*35238bceSAndroid Build Coastguard Worker     void toggleDecode(const std::vector<UniformData> &uniformDataList);
895*35238bceSAndroid Build Coastguard Worker     void bindSamplerToTexture(const int samplerIdx, const int textureIdx, const uint32_t textureUnit);
896*35238bceSAndroid Build Coastguard Worker     void activateSampler(const int samplerIdx, const bool active);
897*35238bceSAndroid Build Coastguard Worker     void logColor(const std::string &colorLogMessage, int colorIdx, tcu::Vec4 color) const;
898*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 formatReferenceColor(tcu::Vec4 referenceColor);
899*35238bceSAndroid Build Coastguard Worker 
900*35238bceSAndroid Build Coastguard Worker     // render function has a default implentation. Can be overriden for special cases
901*35238bceSAndroid Build Coastguard Worker     virtual void render(void);
902*35238bceSAndroid Build Coastguard Worker 
903*35238bceSAndroid Build Coastguard Worker     // following functions must be overidden to perform individual test cases
904*35238bceSAndroid Build Coastguard Worker     virtual void setupTest(void)    = 0;
905*35238bceSAndroid Build Coastguard Worker     virtual bool verifyResult(void) = 0;
906*35238bceSAndroid Build Coastguard Worker 
907*35238bceSAndroid Build Coastguard Worker protected:
908*35238bceSAndroid Build Coastguard Worker     de::MovePtr<glu::Framebuffer> m_framebuffer;
909*35238bceSAndroid Build Coastguard Worker     std::vector<SRGBTestTexture *> m_textureSourceList;
910*35238bceSAndroid Build Coastguard Worker     std::vector<SRGBTestSampler *> m_samplerList;
911*35238bceSAndroid Build Coastguard Worker     std::vector<glw::GLuint> m_renderBufferList;
912*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 m_epsilonError;
913*35238bceSAndroid Build Coastguard Worker     std::vector<tcu::TextureLevel> m_textureResultList;
914*35238bceSAndroid Build Coastguard Worker     int m_resultOutputTotal;
915*35238bceSAndroid Build Coastguard Worker     tcu::TextureFormat m_resultTextureFormat;
916*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_vaoID;
917*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_vertexDataID;
918*35238bceSAndroid Build Coastguard Worker     std::vector<FragmentShaderParameters> m_shaderParametersList;
919*35238bceSAndroid Build Coastguard Worker     std::vector<SRGBTestProgram *> m_shaderProgramList;
920*35238bceSAndroid Build Coastguard Worker     ShaderSamplingGroup m_samplingGroup;
921*35238bceSAndroid Build Coastguard Worker     int m_px;
922*35238bceSAndroid Build Coastguard Worker     int m_py;
923*35238bceSAndroid Build Coastguard Worker     const tcu::TextureFormat m_internalFormat;
924*35238bceSAndroid Build Coastguard Worker 
925*35238bceSAndroid Build Coastguard Worker private:
926*35238bceSAndroid Build Coastguard Worker     void uploadTextures(void);
927*35238bceSAndroid Build Coastguard Worker     void initFrameBuffer(void);
928*35238bceSAndroid Build Coastguard Worker     void initVertexData(void);
929*35238bceSAndroid Build Coastguard Worker 
930*35238bceSAndroid Build Coastguard Worker     SRGBTestCase(const SRGBTestCase &);
931*35238bceSAndroid Build Coastguard Worker     SRGBTestCase &operator=(const SRGBTestCase &);
932*35238bceSAndroid Build Coastguard Worker };
933*35238bceSAndroid Build Coastguard Worker 
SRGBTestCase(Context & context,const char * name,const char * description,const tcu::TextureFormat internalFormat)934*35238bceSAndroid Build Coastguard Worker SRGBTestCase::SRGBTestCase(Context &context, const char *name, const char *description,
935*35238bceSAndroid Build Coastguard Worker                            const tcu::TextureFormat internalFormat)
936*35238bceSAndroid Build Coastguard Worker     : TestCase(context, name, description)
937*35238bceSAndroid Build Coastguard Worker     , m_epsilonError(EpsilonError::CPU)
938*35238bceSAndroid Build Coastguard Worker     , m_resultOutputTotal(0)
939*35238bceSAndroid Build Coastguard Worker     , m_resultTextureFormat(tcu::TextureFormat(tcu::TextureFormat::sRGBA, tcu::TextureFormat::UNORM_INT8))
940*35238bceSAndroid Build Coastguard Worker     , m_vaoID(0)
941*35238bceSAndroid Build Coastguard Worker     , m_vertexDataID(0)
942*35238bceSAndroid Build Coastguard Worker     , m_samplingGroup(SHADERSAMPLINGGROUP_TEXTURE)
943*35238bceSAndroid Build Coastguard Worker     , m_px(0)
944*35238bceSAndroid Build Coastguard Worker     , m_py(0)
945*35238bceSAndroid Build Coastguard Worker     , m_internalFormat(internalFormat)
946*35238bceSAndroid Build Coastguard Worker {
947*35238bceSAndroid Build Coastguard Worker }
948*35238bceSAndroid Build Coastguard Worker 
~SRGBTestCase(void)949*35238bceSAndroid Build Coastguard Worker SRGBTestCase::~SRGBTestCase(void)
950*35238bceSAndroid Build Coastguard Worker {
951*35238bceSAndroid Build Coastguard Worker     deinit();
952*35238bceSAndroid Build Coastguard Worker }
953*35238bceSAndroid Build Coastguard Worker 
init(void)954*35238bceSAndroid Build Coastguard Worker void SRGBTestCase::init(void)
955*35238bceSAndroid Build Coastguard Worker {
956*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
957*35238bceSAndroid Build Coastguard Worker 
958*35238bceSAndroid Build Coastguard Worker     // extension requirements for test
959*35238bceSAndroid Build Coastguard Worker     if ((glu::getInternalFormat(m_internalFormat) == GL_SRGB8_ALPHA8) &&
960*35238bceSAndroid Build Coastguard Worker         !m_context.getContextInfo().isExtensionSupported("GL_EXT_texture_sRGB_decode"))
961*35238bceSAndroid Build Coastguard Worker     {
962*35238bceSAndroid Build Coastguard Worker         throw tcu::NotSupportedError("Test requires GL_EXT_texture_sRGB_decode extension");
963*35238bceSAndroid Build Coastguard Worker     }
964*35238bceSAndroid Build Coastguard Worker 
965*35238bceSAndroid Build Coastguard Worker     if ((glu::getInternalFormat(m_internalFormat) == GL_SRG8_EXT) &&
966*35238bceSAndroid Build Coastguard Worker         !(m_context.getContextInfo().isExtensionSupported("GL_EXT_texture_sRGB_RG8")))
967*35238bceSAndroid Build Coastguard Worker     {
968*35238bceSAndroid Build Coastguard Worker         throw tcu::NotSupportedError("Test requires GL_EXT_texture_sRGB_RG8 extension");
969*35238bceSAndroid Build Coastguard Worker     }
970*35238bceSAndroid Build Coastguard Worker 
971*35238bceSAndroid Build Coastguard Worker     if ((glu::getInternalFormat(m_internalFormat) == GL_SR8_EXT) &&
972*35238bceSAndroid Build Coastguard Worker         !(m_context.getContextInfo().isExtensionSupported("GL_EXT_texture_sRGB_R8")))
973*35238bceSAndroid Build Coastguard Worker     {
974*35238bceSAndroid Build Coastguard Worker         throw tcu::NotSupportedError("Test requires GL_EXT_texture_sRGB_R8 extension");
975*35238bceSAndroid Build Coastguard Worker     }
976*35238bceSAndroid Build Coastguard Worker 
977*35238bceSAndroid Build Coastguard Worker     m_framebuffer = de::MovePtr<glu::Framebuffer>(new glu::Framebuffer(m_context.getRenderContext()));
978*35238bceSAndroid Build Coastguard Worker 
979*35238bceSAndroid Build Coastguard Worker     if (glu::isContextTypeGLCore(m_context.getRenderContext().getType()))
980*35238bceSAndroid Build Coastguard Worker     {
981*35238bceSAndroid Build Coastguard Worker         gl.enable(GL_FRAMEBUFFER_SRGB);
982*35238bceSAndroid Build Coastguard Worker     }
983*35238bceSAndroid Build Coastguard Worker }
984*35238bceSAndroid Build Coastguard Worker 
deinit(void)985*35238bceSAndroid Build Coastguard Worker void SRGBTestCase::deinit(void)
986*35238bceSAndroid Build Coastguard Worker {
987*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
988*35238bceSAndroid Build Coastguard Worker 
989*35238bceSAndroid Build Coastguard Worker     m_framebuffer = de::MovePtr<glu::Framebuffer>(DE_NULL);
990*35238bceSAndroid Build Coastguard Worker 
991*35238bceSAndroid Build Coastguard Worker     for (std::size_t renderBufferIdx = 0; renderBufferIdx < m_renderBufferList.size(); renderBufferIdx++)
992*35238bceSAndroid Build Coastguard Worker     {
993*35238bceSAndroid Build Coastguard Worker         gl.deleteRenderbuffers(1, &m_renderBufferList[renderBufferIdx]);
994*35238bceSAndroid Build Coastguard Worker     }
995*35238bceSAndroid Build Coastguard Worker     m_renderBufferList.clear();
996*35238bceSAndroid Build Coastguard Worker 
997*35238bceSAndroid Build Coastguard Worker     if (glu::isContextTypeGLCore(m_context.getRenderContext().getType()))
998*35238bceSAndroid Build Coastguard Worker     {
999*35238bceSAndroid Build Coastguard Worker         gl.disable(GL_FRAMEBUFFER_SRGB);
1000*35238bceSAndroid Build Coastguard Worker     }
1001*35238bceSAndroid Build Coastguard Worker 
1002*35238bceSAndroid Build Coastguard Worker     for (std::size_t textureSourceIdx = 0; textureSourceIdx < m_textureSourceList.size(); textureSourceIdx++)
1003*35238bceSAndroid Build Coastguard Worker     {
1004*35238bceSAndroid Build Coastguard Worker         delete m_textureSourceList[textureSourceIdx];
1005*35238bceSAndroid Build Coastguard Worker     }
1006*35238bceSAndroid Build Coastguard Worker     m_textureSourceList.clear();
1007*35238bceSAndroid Build Coastguard Worker 
1008*35238bceSAndroid Build Coastguard Worker     for (std::size_t samplerIdx = 0; samplerIdx < m_samplerList.size(); samplerIdx++)
1009*35238bceSAndroid Build Coastguard Worker     {
1010*35238bceSAndroid Build Coastguard Worker         delete m_samplerList[samplerIdx];
1011*35238bceSAndroid Build Coastguard Worker     }
1012*35238bceSAndroid Build Coastguard Worker     m_samplerList.clear();
1013*35238bceSAndroid Build Coastguard Worker 
1014*35238bceSAndroid Build Coastguard Worker     if (m_vaoID != 0)
1015*35238bceSAndroid Build Coastguard Worker     {
1016*35238bceSAndroid Build Coastguard Worker         gl.deleteVertexArrays(1, &m_vaoID);
1017*35238bceSAndroid Build Coastguard Worker         m_vaoID = 0;
1018*35238bceSAndroid Build Coastguard Worker     }
1019*35238bceSAndroid Build Coastguard Worker 
1020*35238bceSAndroid Build Coastguard Worker     if (m_vertexDataID != 0)
1021*35238bceSAndroid Build Coastguard Worker     {
1022*35238bceSAndroid Build Coastguard Worker         gl.deleteBuffers(1, &m_vertexDataID);
1023*35238bceSAndroid Build Coastguard Worker         m_vertexDataID = 0;
1024*35238bceSAndroid Build Coastguard Worker     }
1025*35238bceSAndroid Build Coastguard Worker }
1026*35238bceSAndroid Build Coastguard Worker 
iterate(void)1027*35238bceSAndroid Build Coastguard Worker SRGBTestCase::IterateResult SRGBTestCase::iterate(void)
1028*35238bceSAndroid Build Coastguard Worker {
1029*35238bceSAndroid Build Coastguard Worker     bool result;
1030*35238bceSAndroid Build Coastguard Worker     int startIdx = -1;
1031*35238bceSAndroid Build Coastguard Worker     int endIdx   = -1;
1032*35238bceSAndroid Build Coastguard Worker 
1033*35238bceSAndroid Build Coastguard Worker     this->setupTest();
1034*35238bceSAndroid Build Coastguard Worker 
1035*35238bceSAndroid Build Coastguard Worker     if (m_samplingGroup == SHADERSAMPLINGGROUP_TEXTURE)
1036*35238bceSAndroid Build Coastguard Worker     {
1037*35238bceSAndroid Build Coastguard Worker         startIdx = static_cast<int>(TEXTURESAMPLING_TEXTURE_START);
1038*35238bceSAndroid Build Coastguard Worker         endIdx   = static_cast<int>(TEXTURESAMPLING_TEXTURE_END);
1039*35238bceSAndroid Build Coastguard Worker     }
1040*35238bceSAndroid Build Coastguard Worker     else if (m_samplingGroup == SHADERSAMPLINGGROUP_TEXEL_FETCH)
1041*35238bceSAndroid Build Coastguard Worker     {
1042*35238bceSAndroid Build Coastguard Worker         startIdx = static_cast<int>(TEXTURESAMPLING_TEXELFETCH_START);
1043*35238bceSAndroid Build Coastguard Worker         endIdx   = static_cast<int>(TEXTURESAMPLING_TEXELFETCH_END);
1044*35238bceSAndroid Build Coastguard Worker     }
1045*35238bceSAndroid Build Coastguard Worker     else
1046*35238bceSAndroid Build Coastguard Worker     {
1047*35238bceSAndroid Build Coastguard Worker         DE_FATAL("Error: Sampling group not defined");
1048*35238bceSAndroid Build Coastguard Worker     }
1049*35238bceSAndroid Build Coastguard Worker 
1050*35238bceSAndroid Build Coastguard Worker     this->initVertexData();
1051*35238bceSAndroid Build Coastguard Worker     this->initFrameBuffer();
1052*35238bceSAndroid Build Coastguard Worker 
1053*35238bceSAndroid Build Coastguard Worker     // loop through all sampling types in the required sampling group, performing individual tests for each
1054*35238bceSAndroid Build Coastguard Worker     for (int samplingTypeIdx = startIdx; samplingTypeIdx < endIdx; samplingTypeIdx++)
1055*35238bceSAndroid Build Coastguard Worker     {
1056*35238bceSAndroid Build Coastguard Worker         this->genShaderPrograms(static_cast<ShaderSamplingType>(samplingTypeIdx));
1057*35238bceSAndroid Build Coastguard Worker         this->uploadTextures();
1058*35238bceSAndroid Build Coastguard Worker         this->render();
1059*35238bceSAndroid Build Coastguard Worker 
1060*35238bceSAndroid Build Coastguard Worker         result = this->verifyResult();
1061*35238bceSAndroid Build Coastguard Worker 
1062*35238bceSAndroid Build Coastguard Worker         this->deleteShaderPrograms();
1063*35238bceSAndroid Build Coastguard Worker 
1064*35238bceSAndroid Build Coastguard Worker         if (result == true)
1065*35238bceSAndroid Build Coastguard Worker         {
1066*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1067*35238bceSAndroid Build Coastguard Worker         }
1068*35238bceSAndroid Build Coastguard Worker         else
1069*35238bceSAndroid Build Coastguard Worker         {
1070*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Result verification failed");
1071*35238bceSAndroid Build Coastguard Worker             return STOP;
1072*35238bceSAndroid Build Coastguard Worker         }
1073*35238bceSAndroid Build Coastguard Worker     }
1074*35238bceSAndroid Build Coastguard Worker 
1075*35238bceSAndroid Build Coastguard Worker     return STOP;
1076*35238bceSAndroid Build Coastguard Worker }
1077*35238bceSAndroid Build Coastguard Worker 
setSamplingGroup(const ShaderSamplingGroup samplingGroup)1078*35238bceSAndroid Build Coastguard Worker void SRGBTestCase::setSamplingGroup(const ShaderSamplingGroup samplingGroup)
1079*35238bceSAndroid Build Coastguard Worker {
1080*35238bceSAndroid Build Coastguard Worker     m_samplingGroup = samplingGroup;
1081*35238bceSAndroid Build Coastguard Worker }
1082*35238bceSAndroid Build Coastguard Worker 
setSamplingLocations(const int px,const int py)1083*35238bceSAndroid Build Coastguard Worker void SRGBTestCase::setSamplingLocations(const int px, const int py)
1084*35238bceSAndroid Build Coastguard Worker {
1085*35238bceSAndroid Build Coastguard Worker     m_px = px;
1086*35238bceSAndroid Build Coastguard Worker     m_py = py;
1087*35238bceSAndroid Build Coastguard Worker }
1088*35238bceSAndroid Build Coastguard Worker 
addTexture(const glu::TextureTestUtil::TextureType targetType,const int width,const int height,const tcu::Vec4 color,const tcu::Sampler::WrapMode wrapS,const tcu::Sampler::WrapMode wrapT,const tcu::Sampler::FilterMode minFilter,const tcu::Sampler::FilterMode magFilter,const SRGBDecode decoding)1089*35238bceSAndroid Build Coastguard Worker void SRGBTestCase::addTexture(const glu::TextureTestUtil::TextureType targetType, const int width, const int height,
1090*35238bceSAndroid Build Coastguard Worker                               const tcu::Vec4 color, const tcu::Sampler::WrapMode wrapS,
1091*35238bceSAndroid Build Coastguard Worker                               const tcu::Sampler::WrapMode wrapT, const tcu::Sampler::FilterMode minFilter,
1092*35238bceSAndroid Build Coastguard Worker                               const tcu::Sampler::FilterMode magFilter, const SRGBDecode decoding)
1093*35238bceSAndroid Build Coastguard Worker {
1094*35238bceSAndroid Build Coastguard Worker     SRGBTestTexture *texture = new SRGBTestTexture(m_context, targetType, m_internalFormat, width, height, color, wrapS,
1095*35238bceSAndroid Build Coastguard Worker                                                    wrapT, minFilter, magFilter, decoding);
1096*35238bceSAndroid Build Coastguard Worker     m_textureSourceList.push_back(texture);
1097*35238bceSAndroid Build Coastguard Worker }
1098*35238bceSAndroid Build Coastguard Worker 
addSampler(const tcu::Sampler::WrapMode wrapS,const tcu::Sampler::WrapMode wrapT,const tcu::Sampler::FilterMode minFilter,const tcu::Sampler::FilterMode magFilter,const SRGBDecode decoding)1099*35238bceSAndroid Build Coastguard Worker void SRGBTestCase::addSampler(const tcu::Sampler::WrapMode wrapS, const tcu::Sampler::WrapMode wrapT,
1100*35238bceSAndroid Build Coastguard Worker                               const tcu::Sampler::FilterMode minFilter, const tcu::Sampler::FilterMode magFilter,
1101*35238bceSAndroid Build Coastguard Worker                               const SRGBDecode decoding)
1102*35238bceSAndroid Build Coastguard Worker {
1103*35238bceSAndroid Build Coastguard Worker     SRGBTestSampler *sampler = new SRGBTestSampler(m_context, wrapS, wrapT, minFilter, magFilter, decoding);
1104*35238bceSAndroid Build Coastguard Worker     m_samplerList.push_back(sampler);
1105*35238bceSAndroid Build Coastguard Worker }
1106*35238bceSAndroid Build Coastguard Worker 
addShaderProgram(const FragmentShaderParameters & shaderParameters)1107*35238bceSAndroid Build Coastguard Worker void SRGBTestCase::addShaderProgram(const FragmentShaderParameters &shaderParameters)
1108*35238bceSAndroid Build Coastguard Worker {
1109*35238bceSAndroid Build Coastguard Worker     m_shaderParametersList.push_back(shaderParameters);
1110*35238bceSAndroid Build Coastguard Worker     m_resultOutputTotal = shaderParameters.outputTotal;
1111*35238bceSAndroid Build Coastguard Worker }
1112*35238bceSAndroid Build Coastguard Worker 
genShaderPrograms(ShaderSamplingType samplingType)1113*35238bceSAndroid Build Coastguard Worker void SRGBTestCase::genShaderPrograms(ShaderSamplingType samplingType)
1114*35238bceSAndroid Build Coastguard Worker {
1115*35238bceSAndroid Build Coastguard Worker     for (int shaderParamsIdx = 0; shaderParamsIdx < (int)m_shaderParametersList.size(); shaderParamsIdx++)
1116*35238bceSAndroid Build Coastguard Worker     {
1117*35238bceSAndroid Build Coastguard Worker         m_shaderParametersList[shaderParamsIdx].samplingType = samplingType;
1118*35238bceSAndroid Build Coastguard Worker         SRGBTestProgram *shaderProgram = new SRGBTestProgram(m_context, m_shaderParametersList[shaderParamsIdx]);
1119*35238bceSAndroid Build Coastguard Worker 
1120*35238bceSAndroid Build Coastguard Worker         if (m_shaderParametersList[shaderParamsIdx].blendRequired == BLENDING_REQUIRED)
1121*35238bceSAndroid Build Coastguard Worker         {
1122*35238bceSAndroid Build Coastguard Worker             shaderProgram->setBlendRequired(true);
1123*35238bceSAndroid Build Coastguard Worker         }
1124*35238bceSAndroid Build Coastguard Worker 
1125*35238bceSAndroid Build Coastguard Worker         if (m_shaderParametersList[shaderParamsIdx].toggleRequired == TOGGLING_REQUIRED)
1126*35238bceSAndroid Build Coastguard Worker         {
1127*35238bceSAndroid Build Coastguard Worker             shaderProgram->setToggleRequired(true);
1128*35238bceSAndroid Build Coastguard Worker             std::vector<std::string> uniformsToToggle = m_shaderParametersList[shaderParamsIdx].uniformsToToggle;
1129*35238bceSAndroid Build Coastguard Worker 
1130*35238bceSAndroid Build Coastguard Worker             for (int uniformNameIdx = 0; uniformNameIdx < (int)uniformsToToggle.size(); uniformNameIdx++)
1131*35238bceSAndroid Build Coastguard Worker             {
1132*35238bceSAndroid Build Coastguard Worker                 shaderProgram->setUniformToggle(shaderProgram->getUniformLocation(uniformsToToggle[uniformNameIdx]),
1133*35238bceSAndroid Build Coastguard Worker                                                 true);
1134*35238bceSAndroid Build Coastguard Worker             }
1135*35238bceSAndroid Build Coastguard Worker         }
1136*35238bceSAndroid Build Coastguard Worker 
1137*35238bceSAndroid Build Coastguard Worker         m_shaderProgramList.push_back(shaderProgram);
1138*35238bceSAndroid Build Coastguard Worker     }
1139*35238bceSAndroid Build Coastguard Worker }
1140*35238bceSAndroid Build Coastguard Worker 
deleteShaderPrograms(void)1141*35238bceSAndroid Build Coastguard Worker void SRGBTestCase::deleteShaderPrograms(void)
1142*35238bceSAndroid Build Coastguard Worker {
1143*35238bceSAndroid Build Coastguard Worker     for (std::size_t idx = 0; idx < m_shaderProgramList.size(); idx++)
1144*35238bceSAndroid Build Coastguard Worker     {
1145*35238bceSAndroid Build Coastguard Worker         delete m_shaderProgramList[idx];
1146*35238bceSAndroid Build Coastguard Worker     }
1147*35238bceSAndroid Build Coastguard Worker     m_shaderProgramList.clear();
1148*35238bceSAndroid Build Coastguard Worker }
1149*35238bceSAndroid Build Coastguard Worker 
readResultTextures(void)1150*35238bceSAndroid Build Coastguard Worker void SRGBTestCase::readResultTextures(void)
1151*35238bceSAndroid Build Coastguard Worker {
1152*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1153*35238bceSAndroid Build Coastguard Worker     int width                = m_context.getRenderContext().getRenderTarget().getWidth();
1154*35238bceSAndroid Build Coastguard Worker     int height               = m_context.getRenderContext().getRenderTarget().getHeight();
1155*35238bceSAndroid Build Coastguard Worker 
1156*35238bceSAndroid Build Coastguard Worker     gl.bindFramebuffer(GL_FRAMEBUFFER, **m_framebuffer);
1157*35238bceSAndroid Build Coastguard Worker 
1158*35238bceSAndroid Build Coastguard Worker     m_textureResultList.resize(m_renderBufferList.size());
1159*35238bceSAndroid Build Coastguard Worker 
1160*35238bceSAndroid Build Coastguard Worker     for (std::size_t renderBufferIdx = 0; renderBufferIdx < m_renderBufferList.size(); renderBufferIdx++)
1161*35238bceSAndroid Build Coastguard Worker     {
1162*35238bceSAndroid Build Coastguard Worker         gl.readBuffer(GL_COLOR_ATTACHMENT0 + (glw::GLenum)renderBufferIdx);
1163*35238bceSAndroid Build Coastguard Worker         m_textureResultList[renderBufferIdx].setStorage(m_resultTextureFormat, width, height);
1164*35238bceSAndroid Build Coastguard Worker         glu::readPixels(m_context.getRenderContext(), 0, 0, m_textureResultList[renderBufferIdx].getAccess());
1165*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels()");
1166*35238bceSAndroid Build Coastguard Worker     }
1167*35238bceSAndroid Build Coastguard Worker 
1168*35238bceSAndroid Build Coastguard Worker     gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
1169*35238bceSAndroid Build Coastguard Worker }
1170*35238bceSAndroid Build Coastguard Worker 
storeResultPixels(std::vector<tcu::Vec4> & resultPixelData)1171*35238bceSAndroid Build Coastguard Worker void SRGBTestCase::storeResultPixels(std::vector<tcu::Vec4> &resultPixelData)
1172*35238bceSAndroid Build Coastguard Worker {
1173*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log = m_context.getTestContext().getLog();
1174*35238bceSAndroid Build Coastguard Worker     std::ostringstream message;
1175*35238bceSAndroid Build Coastguard Worker     int width  = m_context.getRenderContext().getRenderTarget().getWidth();
1176*35238bceSAndroid Build Coastguard Worker     int height = m_context.getRenderContext().getRenderTarget().getHeight();
1177*35238bceSAndroid Build Coastguard Worker 
1178*35238bceSAndroid Build Coastguard Worker     // ensure result sampling coordinates are within range of the result color attachment
1179*35238bceSAndroid Build Coastguard Worker     DE_ASSERT((m_px >= 0) && (m_px < width));
1180*35238bceSAndroid Build Coastguard Worker     DE_ASSERT((m_py >= 0) && (m_py < height));
1181*35238bceSAndroid Build Coastguard Worker     DE_UNREF(width && height);
1182*35238bceSAndroid Build Coastguard Worker 
1183*35238bceSAndroid Build Coastguard Worker     for (int idx = 0; idx < (int)m_textureResultList.size(); idx++)
1184*35238bceSAndroid Build Coastguard Worker     {
1185*35238bceSAndroid Build Coastguard Worker         resultPixelData.push_back(m_textureResultList[idx].getAccess().getPixel(m_px, m_py));
1186*35238bceSAndroid Build Coastguard Worker         this->logColor(std::string("Result color: "), idx, resultPixelData[idx]);
1187*35238bceSAndroid Build Coastguard Worker     }
1188*35238bceSAndroid Build Coastguard Worker 
1189*35238bceSAndroid Build Coastguard Worker     // log error rate (threshold)
1190*35238bceSAndroid Build Coastguard Worker     message << m_epsilonError;
1191*35238bceSAndroid Build Coastguard Worker     log << tcu::TestLog::Message << std::string("Epsilon error: ") << message.str() << tcu::TestLog::EndMessage;
1192*35238bceSAndroid Build Coastguard Worker }
1193*35238bceSAndroid Build Coastguard Worker 
toggleDecode(const std::vector<UniformData> & uniformDataList)1194*35238bceSAndroid Build Coastguard Worker void SRGBTestCase::toggleDecode(const std::vector<UniformData> &uniformDataList)
1195*35238bceSAndroid Build Coastguard Worker {
1196*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(uniformDataList.size() <= m_textureSourceList.size());
1197*35238bceSAndroid Build Coastguard Worker 
1198*35238bceSAndroid Build Coastguard Worker     for (int uniformIdx = 0; uniformIdx < (int)uniformDataList.size(); uniformIdx++)
1199*35238bceSAndroid Build Coastguard Worker     {
1200*35238bceSAndroid Build Coastguard Worker         if (uniformDataList[uniformIdx].toggleDecode == true)
1201*35238bceSAndroid Build Coastguard Worker         {
1202*35238bceSAndroid Build Coastguard Worker             if (m_textureSourceList[uniformIdx]->getDecode() == SRGBDECODE_DECODE_DEFAULT)
1203*35238bceSAndroid Build Coastguard Worker             {
1204*35238bceSAndroid Build Coastguard Worker                 // cannot toggle default
1205*35238bceSAndroid Build Coastguard Worker                 continue;
1206*35238bceSAndroid Build Coastguard Worker             }
1207*35238bceSAndroid Build Coastguard Worker 
1208*35238bceSAndroid Build Coastguard Worker             // toggle sRGB decode values (ignoring value if set to default)
1209*35238bceSAndroid Build Coastguard Worker             m_textureSourceList[uniformIdx]->setDecode(
1210*35238bceSAndroid Build Coastguard Worker                 (SRGBDecode)((m_textureSourceList[uniformIdx]->getDecode() + 1) % SRGBDECODE_DECODE_DEFAULT));
1211*35238bceSAndroid Build Coastguard Worker         }
1212*35238bceSAndroid Build Coastguard Worker     }
1213*35238bceSAndroid Build Coastguard Worker }
1214*35238bceSAndroid Build Coastguard Worker 
bindSamplerToTexture(const int samplerIdx,const int textureIdx,const uint32_t textureUnit)1215*35238bceSAndroid Build Coastguard Worker void SRGBTestCase::bindSamplerToTexture(const int samplerIdx, const int textureIdx, const uint32_t textureUnit)
1216*35238bceSAndroid Build Coastguard Worker {
1217*35238bceSAndroid Build Coastguard Worker     uint32_t enumConversion = textureUnit - GL_TEXTURE0;
1218*35238bceSAndroid Build Coastguard Worker     m_textureSourceList[textureIdx]->setHasSampler(true);
1219*35238bceSAndroid Build Coastguard Worker     m_samplerList[samplerIdx]->setTextureUnit(enumConversion);
1220*35238bceSAndroid Build Coastguard Worker }
1221*35238bceSAndroid Build Coastguard Worker 
activateSampler(const int samplerIdx,const bool active)1222*35238bceSAndroid Build Coastguard Worker void SRGBTestCase::activateSampler(const int samplerIdx, const bool active)
1223*35238bceSAndroid Build Coastguard Worker {
1224*35238bceSAndroid Build Coastguard Worker     m_samplerList[samplerIdx]->setIsActive(active);
1225*35238bceSAndroid Build Coastguard Worker }
1226*35238bceSAndroid Build Coastguard Worker 
logColor(const std::string & colorLogMessage,int colorIdx,tcu::Vec4 color) const1227*35238bceSAndroid Build Coastguard Worker void SRGBTestCase::logColor(const std::string &colorLogMessage, int colorIdx, tcu::Vec4 color) const
1228*35238bceSAndroid Build Coastguard Worker {
1229*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log = m_context.getTestContext().getLog();
1230*35238bceSAndroid Build Coastguard Worker     std::ostringstream message;
1231*35238bceSAndroid Build Coastguard Worker 
1232*35238bceSAndroid Build Coastguard Worker     message << colorLogMessage << colorIdx << " = (" << color.x() << ", " << color.y() << ", " << color.z() << ", "
1233*35238bceSAndroid Build Coastguard Worker             << color.w() << ")";
1234*35238bceSAndroid Build Coastguard Worker     log << tcu::TestLog::Message << message.str() << tcu::TestLog::EndMessage;
1235*35238bceSAndroid Build Coastguard Worker }
1236*35238bceSAndroid Build Coastguard Worker 
formatReferenceColor(tcu::Vec4 referenceColor)1237*35238bceSAndroid Build Coastguard Worker tcu::Vec4 SRGBTestCase::formatReferenceColor(tcu::Vec4 referenceColor)
1238*35238bceSAndroid Build Coastguard Worker {
1239*35238bceSAndroid Build Coastguard Worker     switch (glu::getInternalFormat(m_internalFormat))
1240*35238bceSAndroid Build Coastguard Worker     {
1241*35238bceSAndroid Build Coastguard Worker     case GL_SRGB8_ALPHA8:
1242*35238bceSAndroid Build Coastguard Worker     {
1243*35238bceSAndroid Build Coastguard Worker         return referenceColor;
1244*35238bceSAndroid Build Coastguard Worker     }
1245*35238bceSAndroid Build Coastguard Worker     case GL_SRG8_EXT:
1246*35238bceSAndroid Build Coastguard Worker     {
1247*35238bceSAndroid Build Coastguard Worker         // zero unwanted color channels
1248*35238bceSAndroid Build Coastguard Worker         referenceColor.z() = 0;
1249*35238bceSAndroid Build Coastguard Worker         return referenceColor;
1250*35238bceSAndroid Build Coastguard Worker     }
1251*35238bceSAndroid Build Coastguard Worker     case GL_SR8_EXT:
1252*35238bceSAndroid Build Coastguard Worker     {
1253*35238bceSAndroid Build Coastguard Worker         // zero unwanted color channels
1254*35238bceSAndroid Build Coastguard Worker         referenceColor.y() = 0;
1255*35238bceSAndroid Build Coastguard Worker         referenceColor.z() = 0;
1256*35238bceSAndroid Build Coastguard Worker         return referenceColor;
1257*35238bceSAndroid Build Coastguard Worker     }
1258*35238bceSAndroid Build Coastguard Worker     default:
1259*35238bceSAndroid Build Coastguard Worker     {
1260*35238bceSAndroid Build Coastguard Worker         DE_FATAL("Error: Internal format not recognised");
1261*35238bceSAndroid Build Coastguard Worker         return referenceColor;
1262*35238bceSAndroid Build Coastguard Worker     }
1263*35238bceSAndroid Build Coastguard Worker     }
1264*35238bceSAndroid Build Coastguard Worker }
1265*35238bceSAndroid Build Coastguard Worker 
render(void)1266*35238bceSAndroid Build Coastguard Worker void SRGBTestCase::render(void)
1267*35238bceSAndroid Build Coastguard Worker {
1268*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1269*35238bceSAndroid Build Coastguard Worker 
1270*35238bceSAndroid Build Coastguard Worker     // default rendering only uses one program
1271*35238bceSAndroid Build Coastguard Worker     gl.bindFramebuffer(GL_FRAMEBUFFER, **m_framebuffer);
1272*35238bceSAndroid Build Coastguard Worker     gl.bindVertexArray(m_vaoID);
1273*35238bceSAndroid Build Coastguard Worker 
1274*35238bceSAndroid Build Coastguard Worker     gl.useProgram(m_shaderProgramList[0]->getHandle());
1275*35238bceSAndroid Build Coastguard Worker 
1276*35238bceSAndroid Build Coastguard Worker     for (int textureSourceIdx = 0; textureSourceIdx < (int)m_textureSourceList.size(); textureSourceIdx++)
1277*35238bceSAndroid Build Coastguard Worker     {
1278*35238bceSAndroid Build Coastguard Worker         gl.activeTexture(GL_TEXTURE0 + (glw::GLenum)textureSourceIdx);
1279*35238bceSAndroid Build Coastguard Worker         gl.bindTexture(m_textureSourceList[textureSourceIdx]->getGLTargetType(),
1280*35238bceSAndroid Build Coastguard Worker                        m_textureSourceList[textureSourceIdx]->getHandle());
1281*35238bceSAndroid Build Coastguard Worker         glw::GLuint samplerUniformLocationID = gl.getUniformLocation(
1282*35238bceSAndroid Build Coastguard Worker             m_shaderProgramList[0]->getHandle(), (std::string("uTexture") + de::toString(textureSourceIdx)).c_str());
1283*35238bceSAndroid Build Coastguard Worker         TCU_CHECK(samplerUniformLocationID != (glw::GLuint)-1);
1284*35238bceSAndroid Build Coastguard Worker         gl.uniform1i(samplerUniformLocationID, (glw::GLenum)textureSourceIdx);
1285*35238bceSAndroid Build Coastguard Worker     }
1286*35238bceSAndroid Build Coastguard Worker 
1287*35238bceSAndroid Build Coastguard Worker     for (int samplerIdx = 0; samplerIdx < (int)m_samplerList.size(); samplerIdx++)
1288*35238bceSAndroid Build Coastguard Worker     {
1289*35238bceSAndroid Build Coastguard Worker         if (m_samplerList[samplerIdx]->getIsActive() == true)
1290*35238bceSAndroid Build Coastguard Worker         {
1291*35238bceSAndroid Build Coastguard Worker             m_samplerList[samplerIdx]->bindToTexture();
1292*35238bceSAndroid Build Coastguard Worker         }
1293*35238bceSAndroid Build Coastguard Worker     }
1294*35238bceSAndroid Build Coastguard Worker 
1295*35238bceSAndroid Build Coastguard Worker     gl.drawArrays(GL_TRIANGLES, 0, 6);
1296*35238bceSAndroid Build Coastguard Worker 
1297*35238bceSAndroid Build Coastguard Worker     for (std::size_t textureSourceIdx = 0; textureSourceIdx < m_textureSourceList.size(); textureSourceIdx++)
1298*35238bceSAndroid Build Coastguard Worker     {
1299*35238bceSAndroid Build Coastguard Worker         gl.bindTexture(m_textureSourceList[textureSourceIdx]->getGLTargetType(), 0);
1300*35238bceSAndroid Build Coastguard Worker     }
1301*35238bceSAndroid Build Coastguard Worker     gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
1302*35238bceSAndroid Build Coastguard Worker     gl.bindVertexArray(0);
1303*35238bceSAndroid Build Coastguard Worker     gl.bindBuffer(GL_ARRAY_BUFFER, 0);
1304*35238bceSAndroid Build Coastguard Worker }
1305*35238bceSAndroid Build Coastguard Worker 
uploadTextures(void)1306*35238bceSAndroid Build Coastguard Worker void SRGBTestCase::uploadTextures(void)
1307*35238bceSAndroid Build Coastguard Worker {
1308*35238bceSAndroid Build Coastguard Worker     for (std::size_t idx = 0; idx < m_textureSourceList.size(); idx++)
1309*35238bceSAndroid Build Coastguard Worker     {
1310*35238bceSAndroid Build Coastguard Worker         m_textureSourceList[idx]->upload();
1311*35238bceSAndroid Build Coastguard Worker         m_textureSourceList[idx]->setParameters();
1312*35238bceSAndroid Build Coastguard Worker     }
1313*35238bceSAndroid Build Coastguard Worker }
1314*35238bceSAndroid Build Coastguard Worker 
initFrameBuffer(void)1315*35238bceSAndroid Build Coastguard Worker void SRGBTestCase::initFrameBuffer(void)
1316*35238bceSAndroid Build Coastguard Worker {
1317*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1318*35238bceSAndroid Build Coastguard Worker     int width                = m_context.getRenderContext().getRenderTarget().getWidth();
1319*35238bceSAndroid Build Coastguard Worker     int height               = m_context.getRenderContext().getRenderTarget().getHeight();
1320*35238bceSAndroid Build Coastguard Worker 
1321*35238bceSAndroid Build Coastguard Worker     if (m_resultOutputTotal == 0)
1322*35238bceSAndroid Build Coastguard Worker     {
1323*35238bceSAndroid Build Coastguard Worker         throw std::invalid_argument("SRGBTestExecutor must have at least 1 rendered result");
1324*35238bceSAndroid Build Coastguard Worker     }
1325*35238bceSAndroid Build Coastguard Worker 
1326*35238bceSAndroid Build Coastguard Worker     gl.bindFramebuffer(GL_FRAMEBUFFER, **m_framebuffer);
1327*35238bceSAndroid Build Coastguard Worker 
1328*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(m_renderBufferList.empty());
1329*35238bceSAndroid Build Coastguard Worker     for (int outputIdx = 0; outputIdx < m_resultOutputTotal; outputIdx++)
1330*35238bceSAndroid Build Coastguard Worker     {
1331*35238bceSAndroid Build Coastguard Worker         glw::GLuint renderBuffer = -1;
1332*35238bceSAndroid Build Coastguard Worker         m_renderBufferList.push_back(renderBuffer);
1333*35238bceSAndroid Build Coastguard Worker     }
1334*35238bceSAndroid Build Coastguard Worker 
1335*35238bceSAndroid Build Coastguard Worker     for (std::size_t renderBufferIdx = 0; renderBufferIdx < m_renderBufferList.size(); renderBufferIdx++)
1336*35238bceSAndroid Build Coastguard Worker     {
1337*35238bceSAndroid Build Coastguard Worker         gl.genRenderbuffers(1, &m_renderBufferList[renderBufferIdx]);
1338*35238bceSAndroid Build Coastguard Worker         gl.bindRenderbuffer(GL_RENDERBUFFER, m_renderBufferList[renderBufferIdx]);
1339*35238bceSAndroid Build Coastguard Worker         gl.renderbufferStorage(GL_RENDERBUFFER, glu::getInternalFormat(m_resultTextureFormat), width, height);
1340*35238bceSAndroid Build Coastguard Worker         gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + (glw::GLenum)renderBufferIdx, GL_RENDERBUFFER,
1341*35238bceSAndroid Build Coastguard Worker                                    m_renderBufferList[renderBufferIdx]);
1342*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "Create and setup renderbuffer object");
1343*35238bceSAndroid Build Coastguard Worker     }
1344*35238bceSAndroid Build Coastguard Worker     TCU_CHECK(gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
1345*35238bceSAndroid Build Coastguard Worker 
1346*35238bceSAndroid Build Coastguard Worker     std::vector<glw::GLenum> renderBufferTargets(m_renderBufferList.size());
1347*35238bceSAndroid Build Coastguard Worker     for (std::size_t renderBufferIdx = 0; renderBufferIdx < m_renderBufferList.size(); renderBufferIdx++)
1348*35238bceSAndroid Build Coastguard Worker     {
1349*35238bceSAndroid Build Coastguard Worker         renderBufferTargets[renderBufferIdx] = GL_COLOR_ATTACHMENT0 + (glw::GLenum)renderBufferIdx;
1350*35238bceSAndroid Build Coastguard Worker     }
1351*35238bceSAndroid Build Coastguard Worker     gl.drawBuffers((glw::GLsizei)renderBufferTargets.size(), &renderBufferTargets[0]);
1352*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawBuffer()");
1353*35238bceSAndroid Build Coastguard Worker 
1354*35238bceSAndroid Build Coastguard Worker     gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
1355*35238bceSAndroid Build Coastguard Worker }
1356*35238bceSAndroid Build Coastguard Worker 
initVertexData(void)1357*35238bceSAndroid Build Coastguard Worker void SRGBTestCase::initVertexData(void)
1358*35238bceSAndroid Build Coastguard Worker {
1359*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1360*35238bceSAndroid Build Coastguard Worker 
1361*35238bceSAndroid Build Coastguard Worker     static const glw::GLfloat squareVertexData[] = {
1362*35238bceSAndroid Build Coastguard Worker         // position                // texcoord
1363*35238bceSAndroid Build Coastguard Worker         -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, // bottom left corner
1364*35238bceSAndroid Build Coastguard Worker         1.0f,  -1.0f, 0.0f, 1.0f, 0.0f, // bottom right corner
1365*35238bceSAndroid Build Coastguard Worker         1.0f,  1.0f,  0.0f, 1.0f, 1.0f, // Top right corner
1366*35238bceSAndroid Build Coastguard Worker 
1367*35238bceSAndroid Build Coastguard Worker         -1.0f, 1.0f,  0.0f, 0.0f, 1.0f, // top left corner
1368*35238bceSAndroid Build Coastguard Worker         1.0f,  1.0f,  0.0f, 1.0f, 1.0f, // Top right corner
1369*35238bceSAndroid Build Coastguard Worker         -1.0f, -1.0f, 0.0f, 0.0f, 0.0f  // bottom left corner
1370*35238bceSAndroid Build Coastguard Worker     };
1371*35238bceSAndroid Build Coastguard Worker 
1372*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(m_vaoID == 0);
1373*35238bceSAndroid Build Coastguard Worker     gl.genVertexArrays(1, &m_vaoID);
1374*35238bceSAndroid Build Coastguard Worker     gl.bindVertexArray(m_vaoID);
1375*35238bceSAndroid Build Coastguard Worker 
1376*35238bceSAndroid Build Coastguard Worker     gl.genBuffers(1, &m_vertexDataID);
1377*35238bceSAndroid Build Coastguard Worker     gl.bindBuffer(GL_ARRAY_BUFFER, m_vertexDataID);
1378*35238bceSAndroid Build Coastguard Worker     gl.bufferData(GL_ARRAY_BUFFER, (glw::GLsizei)sizeof(squareVertexData), squareVertexData, GL_STATIC_DRAW);
1379*35238bceSAndroid Build Coastguard Worker 
1380*35238bceSAndroid Build Coastguard Worker     gl.vertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * (glw::GLsizei)sizeof(float), (glw::GLvoid *)0);
1381*35238bceSAndroid Build Coastguard Worker     gl.enableVertexAttribArray(0);
1382*35238bceSAndroid Build Coastguard Worker     gl.vertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * (glw::GLsizei)sizeof(float),
1383*35238bceSAndroid Build Coastguard Worker                            (glw::GLvoid *)(3 * sizeof(float)));
1384*35238bceSAndroid Build Coastguard Worker     gl.enableVertexAttribArray(1);
1385*35238bceSAndroid Build Coastguard Worker 
1386*35238bceSAndroid Build Coastguard Worker     gl.bindVertexArray(0);
1387*35238bceSAndroid Build Coastguard Worker     gl.bindBuffer(GL_ARRAY_BUFFER, 0);
1388*35238bceSAndroid Build Coastguard Worker }
1389*35238bceSAndroid Build Coastguard Worker 
1390*35238bceSAndroid Build Coastguard Worker class TextureDecodeSkippedCase : public SRGBTestCase
1391*35238bceSAndroid Build Coastguard Worker {
1392*35238bceSAndroid Build Coastguard Worker public:
TextureDecodeSkippedCase(Context & context,const char * name,const char * description,const tcu::TextureFormat internalFormat)1393*35238bceSAndroid Build Coastguard Worker     TextureDecodeSkippedCase(Context &context, const char *name, const char *description,
1394*35238bceSAndroid Build Coastguard Worker                              const tcu::TextureFormat internalFormat)
1395*35238bceSAndroid Build Coastguard Worker         : SRGBTestCase(context, name, description, internalFormat)
1396*35238bceSAndroid Build Coastguard Worker     {
1397*35238bceSAndroid Build Coastguard Worker     }
1398*35238bceSAndroid Build Coastguard Worker 
~TextureDecodeSkippedCase(void)1399*35238bceSAndroid Build Coastguard Worker     ~TextureDecodeSkippedCase(void)
1400*35238bceSAndroid Build Coastguard Worker     {
1401*35238bceSAndroid Build Coastguard Worker     }
1402*35238bceSAndroid Build Coastguard Worker 
1403*35238bceSAndroid Build Coastguard Worker     void setupTest(void);
1404*35238bceSAndroid Build Coastguard Worker     bool verifyResult(void);
1405*35238bceSAndroid Build Coastguard Worker };
1406*35238bceSAndroid Build Coastguard Worker 
setupTest(void)1407*35238bceSAndroid Build Coastguard Worker void TextureDecodeSkippedCase::setupTest(void)
1408*35238bceSAndroid Build Coastguard Worker {
1409*35238bceSAndroid Build Coastguard Worker     // TEST STEPS:
1410*35238bceSAndroid Build Coastguard Worker     //    - create and set texture to DECODE_SKIP_EXT
1411*35238bceSAndroid Build Coastguard Worker     //    - store texture on GPU
1412*35238bceSAndroid Build Coastguard Worker     //    - in fragment shader, sample the texture using texture*() and render texel values to a color attachment in the FBO
1413*35238bceSAndroid Build Coastguard Worker     //    - on the host, read back the pixel values into a tcu::TextureLevel
1414*35238bceSAndroid Build Coastguard Worker     //    - analyse the texel values, expecting them in sRGB format i.e. linear space decoding was skipped
1415*35238bceSAndroid Build Coastguard Worker 
1416*35238bceSAndroid Build Coastguard Worker     FragmentShaderParameters shaderParameters(SHADEROUTPUTS_ONE, SHADERUNIFORMS_ONE, NULL, BLENDING_NOT_REQUIRED,
1417*35238bceSAndroid Build Coastguard Worker                                               TOGGLING_NOT_REQUIRED);
1418*35238bceSAndroid Build Coastguard Worker 
1419*35238bceSAndroid Build Coastguard Worker     this->addTexture(TEXTURETYPE_2D, TestDimensions::WIDTH, TestDimensions::HEIGHT, getColorReferenceLinear(),
1420*35238bceSAndroid Build Coastguard Worker                      tcu::Sampler::MIRRORED_REPEAT_GL, tcu::Sampler::MIRRORED_REPEAT_GL, tcu::Sampler::LINEAR,
1421*35238bceSAndroid Build Coastguard Worker                      tcu::Sampler::LINEAR, SRGBDECODE_SKIP_DECODE);
1422*35238bceSAndroid Build Coastguard Worker 
1423*35238bceSAndroid Build Coastguard Worker     this->addShaderProgram(shaderParameters);
1424*35238bceSAndroid Build Coastguard Worker     this->setSamplingLocations(TestSamplingPositions::X_POS, TestSamplingPositions::Y_POS);
1425*35238bceSAndroid Build Coastguard Worker 
1426*35238bceSAndroid Build Coastguard Worker     this->setSamplingGroup(SHADERSAMPLINGGROUP_TEXTURE);
1427*35238bceSAndroid Build Coastguard Worker }
1428*35238bceSAndroid Build Coastguard Worker 
verifyResult(void)1429*35238bceSAndroid Build Coastguard Worker bool TextureDecodeSkippedCase::verifyResult(void)
1430*35238bceSAndroid Build Coastguard Worker {
1431*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log        = m_context.getTestContext().getLog();
1432*35238bceSAndroid Build Coastguard Worker     const int resultColorIdx = 0;
1433*35238bceSAndroid Build Coastguard Worker     std::vector<tcu::Vec4> pixelResultList;
1434*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 pixelConverted;
1435*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 pixelReference;
1436*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 pixelExpected;
1437*35238bceSAndroid Build Coastguard Worker 
1438*35238bceSAndroid Build Coastguard Worker     this->readResultTextures();
1439*35238bceSAndroid Build Coastguard Worker     this->storeResultPixels(pixelResultList);
1440*35238bceSAndroid Build Coastguard Worker 
1441*35238bceSAndroid Build Coastguard Worker     pixelConverted = tcu::sRGBToLinear(pixelResultList[resultColorIdx]);
1442*35238bceSAndroid Build Coastguard Worker     pixelReference = this->formatReferenceColor(getColorReferenceLinear());
1443*35238bceSAndroid Build Coastguard Worker     pixelExpected  = this->formatReferenceColor(getColorReferenceSRGB());
1444*35238bceSAndroid Build Coastguard Worker 
1445*35238bceSAndroid Build Coastguard Worker     this->formatReferenceColor(pixelReference);
1446*35238bceSAndroid Build Coastguard Worker     this->logColor(std::string("Expected color: "), resultColorIdx, pixelExpected);
1447*35238bceSAndroid Build Coastguard Worker 
1448*35238bceSAndroid Build Coastguard Worker     // result color 0 should be sRGB. Compare with linear reference color
1449*35238bceSAndroid Build Coastguard Worker     if ((tcu::boolAll(tcu::lessThan(tcu::abs(pixelConverted - pixelReference), m_epsilonError))) ||
1450*35238bceSAndroid Build Coastguard Worker         (tcu::boolAll(tcu::equal(pixelConverted, pixelReference))))
1451*35238bceSAndroid Build Coastguard Worker     {
1452*35238bceSAndroid Build Coastguard Worker         log << tcu::TestLog::Message << std::string("sRGB as expected") << tcu::TestLog::EndMessage;
1453*35238bceSAndroid Build Coastguard Worker         return true;
1454*35238bceSAndroid Build Coastguard Worker     }
1455*35238bceSAndroid Build Coastguard Worker     else
1456*35238bceSAndroid Build Coastguard Worker     {
1457*35238bceSAndroid Build Coastguard Worker         log << tcu::TestLog::Message << std::string("not sRGB as expected") << tcu::TestLog::EndMessage;
1458*35238bceSAndroid Build Coastguard Worker         return false;
1459*35238bceSAndroid Build Coastguard Worker     }
1460*35238bceSAndroid Build Coastguard Worker }
1461*35238bceSAndroid Build Coastguard Worker 
1462*35238bceSAndroid Build Coastguard Worker class TextureDecodeEnabledCase : public SRGBTestCase
1463*35238bceSAndroid Build Coastguard Worker {
1464*35238bceSAndroid Build Coastguard Worker public:
TextureDecodeEnabledCase(Context & context,const char * name,const char * description,const tcu::TextureFormat internalFormat)1465*35238bceSAndroid Build Coastguard Worker     TextureDecodeEnabledCase(Context &context, const char *name, const char *description,
1466*35238bceSAndroid Build Coastguard Worker                              const tcu::TextureFormat internalFormat)
1467*35238bceSAndroid Build Coastguard Worker         : SRGBTestCase(context, name, description, internalFormat)
1468*35238bceSAndroid Build Coastguard Worker     {
1469*35238bceSAndroid Build Coastguard Worker     }
1470*35238bceSAndroid Build Coastguard Worker 
~TextureDecodeEnabledCase(void)1471*35238bceSAndroid Build Coastguard Worker     ~TextureDecodeEnabledCase(void)
1472*35238bceSAndroid Build Coastguard Worker     {
1473*35238bceSAndroid Build Coastguard Worker     }
1474*35238bceSAndroid Build Coastguard Worker 
1475*35238bceSAndroid Build Coastguard Worker     void setupTest(void);
1476*35238bceSAndroid Build Coastguard Worker     bool verifyResult(void);
1477*35238bceSAndroid Build Coastguard Worker };
1478*35238bceSAndroid Build Coastguard Worker 
setupTest(void)1479*35238bceSAndroid Build Coastguard Worker void TextureDecodeEnabledCase::setupTest(void)
1480*35238bceSAndroid Build Coastguard Worker {
1481*35238bceSAndroid Build Coastguard Worker     // TEST STEPS:
1482*35238bceSAndroid Build Coastguard Worker     //    - create and set texture to DECODE_EXT
1483*35238bceSAndroid Build Coastguard Worker     //    - store texture on GPU
1484*35238bceSAndroid Build Coastguard Worker     //    - in fragment shader, sample the texture using texture*() and render texel values to a color attachment in the FBO
1485*35238bceSAndroid Build Coastguard Worker     //    - on the host, read back the pixel values into a tcu::TextureLevel
1486*35238bceSAndroid Build Coastguard Worker     //    - analyse the texel values, expecting them in lRGB format i.e. linear space decoding was enabled
1487*35238bceSAndroid Build Coastguard Worker 
1488*35238bceSAndroid Build Coastguard Worker     FragmentShaderParameters shaderParameters(SHADEROUTPUTS_ONE, SHADERUNIFORMS_ONE, NULL, BLENDING_NOT_REQUIRED,
1489*35238bceSAndroid Build Coastguard Worker                                               TOGGLING_NOT_REQUIRED);
1490*35238bceSAndroid Build Coastguard Worker 
1491*35238bceSAndroid Build Coastguard Worker     this->addTexture(TEXTURETYPE_2D, TestDimensions::WIDTH, TestDimensions::HEIGHT, getColorReferenceLinear(),
1492*35238bceSAndroid Build Coastguard Worker                      tcu::Sampler::MIRRORED_REPEAT_GL, tcu::Sampler::MIRRORED_REPEAT_GL, tcu::Sampler::LINEAR,
1493*35238bceSAndroid Build Coastguard Worker                      tcu::Sampler::LINEAR, SRGBDECODE_DECODE);
1494*35238bceSAndroid Build Coastguard Worker 
1495*35238bceSAndroid Build Coastguard Worker     this->addShaderProgram(shaderParameters);
1496*35238bceSAndroid Build Coastguard Worker 
1497*35238bceSAndroid Build Coastguard Worker     this->setSamplingLocations(TestSamplingPositions::X_POS, TestSamplingPositions::Y_POS);
1498*35238bceSAndroid Build Coastguard Worker 
1499*35238bceSAndroid Build Coastguard Worker     this->setSamplingGroup(SHADERSAMPLINGGROUP_TEXTURE);
1500*35238bceSAndroid Build Coastguard Worker }
1501*35238bceSAndroid Build Coastguard Worker 
verifyResult(void)1502*35238bceSAndroid Build Coastguard Worker bool TextureDecodeEnabledCase::verifyResult(void)
1503*35238bceSAndroid Build Coastguard Worker {
1504*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log        = m_context.getTestContext().getLog();
1505*35238bceSAndroid Build Coastguard Worker     const int resultColorIdx = 0;
1506*35238bceSAndroid Build Coastguard Worker     std::vector<tcu::Vec4> pixelResultList;
1507*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 pixelConverted;
1508*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 pixelReference;
1509*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 pixelExpected;
1510*35238bceSAndroid Build Coastguard Worker 
1511*35238bceSAndroid Build Coastguard Worker     this->readResultTextures();
1512*35238bceSAndroid Build Coastguard Worker     this->storeResultPixels(pixelResultList);
1513*35238bceSAndroid Build Coastguard Worker 
1514*35238bceSAndroid Build Coastguard Worker     pixelConverted = tcu::linearToSRGB(pixelResultList[resultColorIdx]);
1515*35238bceSAndroid Build Coastguard Worker     pixelReference = this->formatReferenceColor(getColorReferenceSRGB());
1516*35238bceSAndroid Build Coastguard Worker     pixelExpected  = this->formatReferenceColor(getColorReferenceLinear());
1517*35238bceSAndroid Build Coastguard Worker 
1518*35238bceSAndroid Build Coastguard Worker     this->logColor(std::string("Expected color: "), resultColorIdx, pixelExpected);
1519*35238bceSAndroid Build Coastguard Worker 
1520*35238bceSAndroid Build Coastguard Worker     // result color 0 should be SRGB. Compare with sRGB reference color
1521*35238bceSAndroid Build Coastguard Worker     if ((tcu::boolAll(tcu::lessThan(tcu::abs(pixelConverted - pixelReference), m_epsilonError))) ||
1522*35238bceSAndroid Build Coastguard Worker         (tcu::boolAll(tcu::equal(pixelConverted, pixelReference))))
1523*35238bceSAndroid Build Coastguard Worker     {
1524*35238bceSAndroid Build Coastguard Worker         log << tcu::TestLog::Message << std::string("linear as expected") << tcu::TestLog::EndMessage;
1525*35238bceSAndroid Build Coastguard Worker         return true;
1526*35238bceSAndroid Build Coastguard Worker     }
1527*35238bceSAndroid Build Coastguard Worker     else
1528*35238bceSAndroid Build Coastguard Worker     {
1529*35238bceSAndroid Build Coastguard Worker         log << tcu::TestLog::Message << std::string("not linear as expected") << tcu::TestLog::EndMessage;
1530*35238bceSAndroid Build Coastguard Worker         return false;
1531*35238bceSAndroid Build Coastguard Worker     }
1532*35238bceSAndroid Build Coastguard Worker }
1533*35238bceSAndroid Build Coastguard Worker 
1534*35238bceSAndroid Build Coastguard Worker class TexelFetchDecodeSkippedcase : public SRGBTestCase
1535*35238bceSAndroid Build Coastguard Worker {
1536*35238bceSAndroid Build Coastguard Worker public:
TexelFetchDecodeSkippedcase(Context & context,const char * name,const char * description,const tcu::TextureFormat internalFormat)1537*35238bceSAndroid Build Coastguard Worker     TexelFetchDecodeSkippedcase(Context &context, const char *name, const char *description,
1538*35238bceSAndroid Build Coastguard Worker                                 const tcu::TextureFormat internalFormat)
1539*35238bceSAndroid Build Coastguard Worker         : SRGBTestCase(context, name, description, internalFormat)
1540*35238bceSAndroid Build Coastguard Worker     {
1541*35238bceSAndroid Build Coastguard Worker     }
1542*35238bceSAndroid Build Coastguard Worker 
~TexelFetchDecodeSkippedcase(void)1543*35238bceSAndroid Build Coastguard Worker     ~TexelFetchDecodeSkippedcase(void)
1544*35238bceSAndroid Build Coastguard Worker     {
1545*35238bceSAndroid Build Coastguard Worker     }
1546*35238bceSAndroid Build Coastguard Worker 
1547*35238bceSAndroid Build Coastguard Worker     void setupTest(void);
1548*35238bceSAndroid Build Coastguard Worker     bool verifyResult(void);
1549*35238bceSAndroid Build Coastguard Worker };
1550*35238bceSAndroid Build Coastguard Worker 
setupTest(void)1551*35238bceSAndroid Build Coastguard Worker void TexelFetchDecodeSkippedcase::setupTest(void)
1552*35238bceSAndroid Build Coastguard Worker {
1553*35238bceSAndroid Build Coastguard Worker     // TEST STEPS:
1554*35238bceSAndroid Build Coastguard Worker     //    - create and set texture to DECODE_SKIP_EXT
1555*35238bceSAndroid Build Coastguard Worker     //    - store texture on GPU
1556*35238bceSAndroid Build Coastguard Worker     //    - in fragment shader, sample the texture using texelFetch*() and render texel values to a color attachment in the FBO
1557*35238bceSAndroid Build Coastguard Worker     //    - on the host, read back the pixel values into a tcu::TextureLevel
1558*35238bceSAndroid Build Coastguard Worker     //    - analyse the texel values, expecting them in lRGB format i.e. linear space decoding is always enabled with texelFetch*()
1559*35238bceSAndroid Build Coastguard Worker 
1560*35238bceSAndroid Build Coastguard Worker     FragmentShaderParameters shaderParameters(SHADEROUTPUTS_ONE, SHADERUNIFORMS_ONE, NULL, BLENDING_NOT_REQUIRED,
1561*35238bceSAndroid Build Coastguard Worker                                               TOGGLING_NOT_REQUIRED);
1562*35238bceSAndroid Build Coastguard Worker 
1563*35238bceSAndroid Build Coastguard Worker     this->addTexture(TEXTURETYPE_2D, TestDimensions::WIDTH, TestDimensions::HEIGHT, getColorReferenceLinear(),
1564*35238bceSAndroid Build Coastguard Worker                      tcu::Sampler::MIRRORED_REPEAT_GL, tcu::Sampler::MIRRORED_REPEAT_GL, tcu::Sampler::LINEAR,
1565*35238bceSAndroid Build Coastguard Worker                      tcu::Sampler::LINEAR, SRGBDECODE_SKIP_DECODE);
1566*35238bceSAndroid Build Coastguard Worker 
1567*35238bceSAndroid Build Coastguard Worker     this->addShaderProgram(shaderParameters);
1568*35238bceSAndroid Build Coastguard Worker 
1569*35238bceSAndroid Build Coastguard Worker     this->setSamplingLocations(TestSamplingPositions::X_POS, TestSamplingPositions::Y_POS);
1570*35238bceSAndroid Build Coastguard Worker 
1571*35238bceSAndroid Build Coastguard Worker     this->setSamplingGroup(SHADERSAMPLINGGROUP_TEXEL_FETCH);
1572*35238bceSAndroid Build Coastguard Worker }
1573*35238bceSAndroid Build Coastguard Worker 
verifyResult(void)1574*35238bceSAndroid Build Coastguard Worker bool TexelFetchDecodeSkippedcase::verifyResult(void)
1575*35238bceSAndroid Build Coastguard Worker {
1576*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log        = m_context.getTestContext().getLog();
1577*35238bceSAndroid Build Coastguard Worker     const int resultColorIdx = 0;
1578*35238bceSAndroid Build Coastguard Worker     std::vector<tcu::Vec4> pixelResultList;
1579*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 pixelReference;
1580*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 pixelExpected;
1581*35238bceSAndroid Build Coastguard Worker 
1582*35238bceSAndroid Build Coastguard Worker     this->readResultTextures();
1583*35238bceSAndroid Build Coastguard Worker     this->storeResultPixels(pixelResultList);
1584*35238bceSAndroid Build Coastguard Worker 
1585*35238bceSAndroid Build Coastguard Worker     pixelReference = pixelExpected = this->formatReferenceColor(getColorReferenceLinear());
1586*35238bceSAndroid Build Coastguard Worker 
1587*35238bceSAndroid Build Coastguard Worker     this->logColor(std::string("Expected color: "), resultColorIdx, pixelExpected);
1588*35238bceSAndroid Build Coastguard Worker 
1589*35238bceSAndroid Build Coastguard Worker     // result color 0 should be linear due to automatic conversion via texelFetch*(). Compare with linear reference color
1590*35238bceSAndroid Build Coastguard Worker     if ((tcu::boolAll(tcu::lessThan(tcu::abs(pixelResultList[0] - pixelReference), m_epsilonError))) ||
1591*35238bceSAndroid Build Coastguard Worker         (tcu::boolAll(tcu::equal(pixelResultList[0], pixelReference))))
1592*35238bceSAndroid Build Coastguard Worker     {
1593*35238bceSAndroid Build Coastguard Worker         log << tcu::TestLog::Message << std::string("linear as expected") << tcu::TestLog::EndMessage;
1594*35238bceSAndroid Build Coastguard Worker         return true;
1595*35238bceSAndroid Build Coastguard Worker     }
1596*35238bceSAndroid Build Coastguard Worker     else
1597*35238bceSAndroid Build Coastguard Worker     {
1598*35238bceSAndroid Build Coastguard Worker         log << tcu::TestLog::Message << std::string("not linear as expected") << tcu::TestLog::EndMessage;
1599*35238bceSAndroid Build Coastguard Worker         return false;
1600*35238bceSAndroid Build Coastguard Worker     }
1601*35238bceSAndroid Build Coastguard Worker }
1602*35238bceSAndroid Build Coastguard Worker 
1603*35238bceSAndroid Build Coastguard Worker class GPUConversionDecodeEnabledCase : public SRGBTestCase
1604*35238bceSAndroid Build Coastguard Worker {
1605*35238bceSAndroid Build Coastguard Worker public:
GPUConversionDecodeEnabledCase(Context & context,const char * name,const char * description,const tcu::TextureFormat internalFormat)1606*35238bceSAndroid Build Coastguard Worker     GPUConversionDecodeEnabledCase(Context &context, const char *name, const char *description,
1607*35238bceSAndroid Build Coastguard Worker                                    const tcu::TextureFormat internalFormat)
1608*35238bceSAndroid Build Coastguard Worker         : SRGBTestCase(context, name, description, internalFormat)
1609*35238bceSAndroid Build Coastguard Worker     {
1610*35238bceSAndroid Build Coastguard Worker     }
1611*35238bceSAndroid Build Coastguard Worker 
~GPUConversionDecodeEnabledCase(void)1612*35238bceSAndroid Build Coastguard Worker     ~GPUConversionDecodeEnabledCase(void)
1613*35238bceSAndroid Build Coastguard Worker     {
1614*35238bceSAndroid Build Coastguard Worker     }
1615*35238bceSAndroid Build Coastguard Worker 
1616*35238bceSAndroid Build Coastguard Worker     void setupTest(void);
1617*35238bceSAndroid Build Coastguard Worker     bool verifyResult(void);
1618*35238bceSAndroid Build Coastguard Worker };
1619*35238bceSAndroid Build Coastguard Worker 
setupTest(void)1620*35238bceSAndroid Build Coastguard Worker void GPUConversionDecodeEnabledCase::setupTest(void)
1621*35238bceSAndroid Build Coastguard Worker {
1622*35238bceSAndroid Build Coastguard Worker     // TEST STEPS:
1623*35238bceSAndroid Build Coastguard Worker     //    - create and set texture_a to DECODE_SKIP_EXT and texture_b to default
1624*35238bceSAndroid Build Coastguard Worker     //    - store textures on GPU
1625*35238bceSAndroid Build Coastguard Worker     //    - in fragment shader, sample both textures using texture*() and manually perform sRGB to lRGB conversion on texture_b
1626*35238bceSAndroid Build Coastguard Worker     //    - in fragment shader, compare converted texture_b with texture_a
1627*35238bceSAndroid Build Coastguard Worker     //    - render green image for pass or red for fail
1628*35238bceSAndroid Build Coastguard Worker 
1629*35238bceSAndroid Build Coastguard Worker     ComparisonFunction comparisonFunction("srgbToLinearCheck", FUNCTIONPARAMETERS_TWO,
1630*35238bceSAndroid Build Coastguard Worker                                           getFunctionDefinitionSRGBToLinearCheck());
1631*35238bceSAndroid Build Coastguard Worker 
1632*35238bceSAndroid Build Coastguard Worker     FragmentShaderParameters shaderParameters(SHADEROUTPUTS_ONE, SHADERUNIFORMS_TWO, &comparisonFunction,
1633*35238bceSAndroid Build Coastguard Worker                                               BLENDING_NOT_REQUIRED, TOGGLING_NOT_REQUIRED);
1634*35238bceSAndroid Build Coastguard Worker 
1635*35238bceSAndroid Build Coastguard Worker     this->addTexture(TEXTURETYPE_2D, TestDimensions::WIDTH, TestDimensions::HEIGHT, getColorReferenceLinear(),
1636*35238bceSAndroid Build Coastguard Worker                      tcu::Sampler::MIRRORED_REPEAT_GL, tcu::Sampler::MIRRORED_REPEAT_GL, tcu::Sampler::LINEAR,
1637*35238bceSAndroid Build Coastguard Worker                      tcu::Sampler::LINEAR, SRGBDECODE_SKIP_DECODE);
1638*35238bceSAndroid Build Coastguard Worker 
1639*35238bceSAndroid Build Coastguard Worker     this->addTexture(TEXTURETYPE_2D, TestDimensions::WIDTH, TestDimensions::HEIGHT, getColorReferenceLinear(),
1640*35238bceSAndroid Build Coastguard Worker                      tcu::Sampler::MIRRORED_REPEAT_GL, tcu::Sampler::MIRRORED_REPEAT_GL, tcu::Sampler::LINEAR,
1641*35238bceSAndroid Build Coastguard Worker                      tcu::Sampler::LINEAR, SRGBDECODE_DECODE_DEFAULT);
1642*35238bceSAndroid Build Coastguard Worker 
1643*35238bceSAndroid Build Coastguard Worker     this->addShaderProgram(shaderParameters);
1644*35238bceSAndroid Build Coastguard Worker 
1645*35238bceSAndroid Build Coastguard Worker     this->setSamplingLocations(TestSamplingPositions::X_POS, TestSamplingPositions::Y_POS);
1646*35238bceSAndroid Build Coastguard Worker 
1647*35238bceSAndroid Build Coastguard Worker     this->setSamplingGroup(SHADERSAMPLINGGROUP_TEXTURE);
1648*35238bceSAndroid Build Coastguard Worker }
1649*35238bceSAndroid Build Coastguard Worker 
verifyResult(void)1650*35238bceSAndroid Build Coastguard Worker bool GPUConversionDecodeEnabledCase::verifyResult(void)
1651*35238bceSAndroid Build Coastguard Worker {
1652*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log        = m_context.getTestContext().getLog();
1653*35238bceSAndroid Build Coastguard Worker     const int resultColorIdx = 0;
1654*35238bceSAndroid Build Coastguard Worker     std::vector<tcu::Vec4> pixelResultList;
1655*35238bceSAndroid Build Coastguard Worker 
1656*35238bceSAndroid Build Coastguard Worker     this->readResultTextures();
1657*35238bceSAndroid Build Coastguard Worker     this->storeResultPixels(pixelResultList);
1658*35238bceSAndroid Build Coastguard Worker     this->logColor(std::string("Expected color: "), resultColorIdx, getColorGreenPass());
1659*35238bceSAndroid Build Coastguard Worker 
1660*35238bceSAndroid Build Coastguard Worker     // result color returned from GPU is either green (pass) or fail (red)
1661*35238bceSAndroid Build Coastguard Worker     if (tcu::boolAll(tcu::equal(pixelResultList[resultColorIdx], getColorGreenPass())))
1662*35238bceSAndroid Build Coastguard Worker     {
1663*35238bceSAndroid Build Coastguard Worker         log << tcu::TestLog::Message << std::string("returned pass color from GPU") << tcu::TestLog::EndMessage;
1664*35238bceSAndroid Build Coastguard Worker         return true;
1665*35238bceSAndroid Build Coastguard Worker     }
1666*35238bceSAndroid Build Coastguard Worker     else
1667*35238bceSAndroid Build Coastguard Worker     {
1668*35238bceSAndroid Build Coastguard Worker         log << tcu::TestLog::Message << std::string("returned fail color from GPU") << tcu::TestLog::EndMessage;
1669*35238bceSAndroid Build Coastguard Worker         return false;
1670*35238bceSAndroid Build Coastguard Worker     }
1671*35238bceSAndroid Build Coastguard Worker }
1672*35238bceSAndroid Build Coastguard Worker 
1673*35238bceSAndroid Build Coastguard Worker class DecodeToggledCase : public SRGBTestCase
1674*35238bceSAndroid Build Coastguard Worker {
1675*35238bceSAndroid Build Coastguard Worker public:
DecodeToggledCase(Context & context,const char * name,const char * description,const tcu::TextureFormat internalFormat)1676*35238bceSAndroid Build Coastguard Worker     DecodeToggledCase(Context &context, const char *name, const char *description,
1677*35238bceSAndroid Build Coastguard Worker                       const tcu::TextureFormat internalFormat)
1678*35238bceSAndroid Build Coastguard Worker         : SRGBTestCase(context, name, description, internalFormat)
1679*35238bceSAndroid Build Coastguard Worker     {
1680*35238bceSAndroid Build Coastguard Worker     }
1681*35238bceSAndroid Build Coastguard Worker 
~DecodeToggledCase(void)1682*35238bceSAndroid Build Coastguard Worker     ~DecodeToggledCase(void)
1683*35238bceSAndroid Build Coastguard Worker     {
1684*35238bceSAndroid Build Coastguard Worker     }
1685*35238bceSAndroid Build Coastguard Worker 
1686*35238bceSAndroid Build Coastguard Worker     void render(void);
1687*35238bceSAndroid Build Coastguard Worker     void setupTest(void);
1688*35238bceSAndroid Build Coastguard Worker     bool verifyResult(void);
1689*35238bceSAndroid Build Coastguard Worker };
1690*35238bceSAndroid Build Coastguard Worker 
render(void)1691*35238bceSAndroid Build Coastguard Worker void DecodeToggledCase::render(void)
1692*35238bceSAndroid Build Coastguard Worker {
1693*35238bceSAndroid Build Coastguard Worker     // override the base SRGBTestCase render function with the purpose of switching between shader programs,
1694*35238bceSAndroid Build Coastguard Worker     // toggling texture sRGB decode state between draw calls
1695*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1696*35238bceSAndroid Build Coastguard Worker 
1697*35238bceSAndroid Build Coastguard Worker     gl.bindFramebuffer(GL_FRAMEBUFFER, **m_framebuffer);
1698*35238bceSAndroid Build Coastguard Worker     gl.bindVertexArray(m_vaoID);
1699*35238bceSAndroid Build Coastguard Worker 
1700*35238bceSAndroid Build Coastguard Worker     for (std::size_t programIdx = 0; programIdx < m_shaderProgramList.size(); programIdx++)
1701*35238bceSAndroid Build Coastguard Worker     {
1702*35238bceSAndroid Build Coastguard Worker         gl.useProgram(m_shaderProgramList[programIdx]->getHandle());
1703*35238bceSAndroid Build Coastguard Worker 
1704*35238bceSAndroid Build Coastguard Worker         this->toggleDecode(m_shaderProgramList[programIdx]->getUniformDataList());
1705*35238bceSAndroid Build Coastguard Worker 
1706*35238bceSAndroid Build Coastguard Worker         for (int textureSourceIdx = 0; textureSourceIdx < (int)m_textureSourceList.size(); textureSourceIdx++)
1707*35238bceSAndroid Build Coastguard Worker         {
1708*35238bceSAndroid Build Coastguard Worker             gl.activeTexture(GL_TEXTURE0 + (glw::GLenum)textureSourceIdx);
1709*35238bceSAndroid Build Coastguard Worker             gl.bindTexture(m_textureSourceList[textureSourceIdx]->getGLTargetType(),
1710*35238bceSAndroid Build Coastguard Worker                            m_textureSourceList[textureSourceIdx]->getHandle());
1711*35238bceSAndroid Build Coastguard Worker             glw::GLuint samplerUniformLocationID =
1712*35238bceSAndroid Build Coastguard Worker                 gl.getUniformLocation(m_shaderProgramList[programIdx]->getHandle(),
1713*35238bceSAndroid Build Coastguard Worker                                       (std::string("uTexture") + de::toString(textureSourceIdx)).c_str());
1714*35238bceSAndroid Build Coastguard Worker             TCU_CHECK(samplerUniformLocationID != (glw::GLuint)-1);
1715*35238bceSAndroid Build Coastguard Worker             gl.uniform1i(samplerUniformLocationID, (glw::GLenum)textureSourceIdx);
1716*35238bceSAndroid Build Coastguard Worker         }
1717*35238bceSAndroid Build Coastguard Worker 
1718*35238bceSAndroid Build Coastguard Worker         for (int samplerIdx = 0; samplerIdx < (int)m_samplerList.size(); samplerIdx++)
1719*35238bceSAndroid Build Coastguard Worker         {
1720*35238bceSAndroid Build Coastguard Worker             if (m_samplerList[samplerIdx]->getIsActive() == true)
1721*35238bceSAndroid Build Coastguard Worker             {
1722*35238bceSAndroid Build Coastguard Worker                 m_samplerList[samplerIdx]->bindToTexture();
1723*35238bceSAndroid Build Coastguard Worker             }
1724*35238bceSAndroid Build Coastguard Worker         }
1725*35238bceSAndroid Build Coastguard Worker 
1726*35238bceSAndroid Build Coastguard Worker         if (m_shaderProgramList[programIdx]->getBlendRequired() == true)
1727*35238bceSAndroid Build Coastguard Worker         {
1728*35238bceSAndroid Build Coastguard Worker             gl.enable(GL_BLEND);
1729*35238bceSAndroid Build Coastguard Worker             gl.blendEquation(GL_MAX);
1730*35238bceSAndroid Build Coastguard Worker             gl.blendFunc(GL_ONE, GL_ONE);
1731*35238bceSAndroid Build Coastguard Worker         }
1732*35238bceSAndroid Build Coastguard Worker         else
1733*35238bceSAndroid Build Coastguard Worker         {
1734*35238bceSAndroid Build Coastguard Worker             gl.disable(GL_BLEND);
1735*35238bceSAndroid Build Coastguard Worker         }
1736*35238bceSAndroid Build Coastguard Worker 
1737*35238bceSAndroid Build Coastguard Worker         gl.drawArrays(GL_TRIANGLES, 0, 6);
1738*35238bceSAndroid Build Coastguard Worker 
1739*35238bceSAndroid Build Coastguard Worker         // reset sRGB decode state on textures
1740*35238bceSAndroid Build Coastguard Worker         this->toggleDecode(m_shaderProgramList[programIdx]->getUniformDataList());
1741*35238bceSAndroid Build Coastguard Worker     }
1742*35238bceSAndroid Build Coastguard Worker 
1743*35238bceSAndroid Build Coastguard Worker     for (std::size_t textureSourceIdx = 0; textureSourceIdx < m_textureSourceList.size(); textureSourceIdx++)
1744*35238bceSAndroid Build Coastguard Worker     {
1745*35238bceSAndroid Build Coastguard Worker         gl.bindTexture(m_textureSourceList[textureSourceIdx]->getGLTargetType(), 0);
1746*35238bceSAndroid Build Coastguard Worker     }
1747*35238bceSAndroid Build Coastguard Worker     gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
1748*35238bceSAndroid Build Coastguard Worker     gl.bindVertexArray(0);
1749*35238bceSAndroid Build Coastguard Worker     gl.bindBuffer(GL_ARRAY_BUFFER, 0);
1750*35238bceSAndroid Build Coastguard Worker }
1751*35238bceSAndroid Build Coastguard Worker 
setupTest(void)1752*35238bceSAndroid Build Coastguard Worker void DecodeToggledCase::setupTest(void)
1753*35238bceSAndroid Build Coastguard Worker {
1754*35238bceSAndroid Build Coastguard Worker     // TEST STEPS:
1755*35238bceSAndroid Build Coastguard Worker     //    - create and set texture_a to DECODE_SKIP_EXT and texture_b to DECODE_EXT
1756*35238bceSAndroid Build Coastguard Worker     //    - create and use two seperate shader programs, program_a and program_b, each using different fragment shaders
1757*35238bceSAndroid Build Coastguard Worker     //    - store texture_a and texture_b on GPU
1758*35238bceSAndroid Build Coastguard Worker     // FIRST PASS:
1759*35238bceSAndroid Build Coastguard Worker     //    - use program_a
1760*35238bceSAndroid Build Coastguard Worker     //    - in fragment shader, sample both textures using texture*() and manually perform sRGB to lRGB conversion on texture_a
1761*35238bceSAndroid Build Coastguard Worker     //    - in fragment shader, test converted texture_a value with texture_b
1762*35238bceSAndroid Build Coastguard Worker     //    - render green image for pass or red for fail
1763*35238bceSAndroid Build Coastguard Worker     //    - store result in a color attachement 0
1764*35238bceSAndroid Build Coastguard Worker     // TOGGLE STAGE
1765*35238bceSAndroid Build Coastguard Worker     //    - during rendering, toggle texture_a from DECODE_SKIP_EXT to DECODE_EXT
1766*35238bceSAndroid Build Coastguard Worker     // SECOND PASS:
1767*35238bceSAndroid Build Coastguard Worker     //    - use program_b
1768*35238bceSAndroid Build Coastguard Worker     //    - in fragment shader, sample both textures using texture*() and manually perform equality check. Both should be linear
1769*35238bceSAndroid Build Coastguard Worker     //    - blend first pass result with second pass. Anything but a green result equals fail
1770*35238bceSAndroid Build Coastguard Worker 
1771*35238bceSAndroid Build Coastguard Worker     ComparisonFunction srgbToLinearFunction("srgbToLinearCheck", FUNCTIONPARAMETERS_TWO,
1772*35238bceSAndroid Build Coastguard Worker                                             getFunctionDefinitionSRGBToLinearCheck());
1773*35238bceSAndroid Build Coastguard Worker     ComparisonFunction colorsEqualFunction("colorsEqualCheck", FUNCTIONPARAMETERS_TWO,
1774*35238bceSAndroid Build Coastguard Worker                                            getFunctionDefinitionEqualCheck());
1775*35238bceSAndroid Build Coastguard Worker 
1776*35238bceSAndroid Build Coastguard Worker     FragmentShaderParameters shaderParametersA(SHADEROUTPUTS_ONE, SHADERUNIFORMS_TWO, &srgbToLinearFunction,
1777*35238bceSAndroid Build Coastguard Worker                                                BLENDING_NOT_REQUIRED, TOGGLING_NOT_REQUIRED);
1778*35238bceSAndroid Build Coastguard Worker     FragmentShaderParameters shaderParametersB(SHADEROUTPUTS_ONE, SHADERUNIFORMS_TWO, &colorsEqualFunction,
1779*35238bceSAndroid Build Coastguard Worker                                                BLENDING_REQUIRED, TOGGLING_REQUIRED);
1780*35238bceSAndroid Build Coastguard Worker 
1781*35238bceSAndroid Build Coastguard Worker     // need to specify which texture uniform to toggle DECODE_EXT/SKIP_DECODE_EXT
1782*35238bceSAndroid Build Coastguard Worker     shaderParametersB.uniformsToToggle.push_back("uTexture0");
1783*35238bceSAndroid Build Coastguard Worker 
1784*35238bceSAndroid Build Coastguard Worker     this->addTexture(TEXTURETYPE_2D, TestDimensions::WIDTH, TestDimensions::HEIGHT, getColorReferenceLinear(),
1785*35238bceSAndroid Build Coastguard Worker                      tcu::Sampler::MIRRORED_REPEAT_GL, tcu::Sampler::MIRRORED_REPEAT_GL, tcu::Sampler::LINEAR,
1786*35238bceSAndroid Build Coastguard Worker                      tcu::Sampler::LINEAR, SRGBDECODE_SKIP_DECODE);
1787*35238bceSAndroid Build Coastguard Worker 
1788*35238bceSAndroid Build Coastguard Worker     this->addTexture(TEXTURETYPE_2D, TestDimensions::WIDTH, TestDimensions::HEIGHT, getColorReferenceLinear(),
1789*35238bceSAndroid Build Coastguard Worker                      tcu::Sampler::MIRRORED_REPEAT_GL, tcu::Sampler::MIRRORED_REPEAT_GL, tcu::Sampler::LINEAR,
1790*35238bceSAndroid Build Coastguard Worker                      tcu::Sampler::LINEAR, SRGBDECODE_DECODE);
1791*35238bceSAndroid Build Coastguard Worker 
1792*35238bceSAndroid Build Coastguard Worker     this->addShaderProgram(shaderParametersA);
1793*35238bceSAndroid Build Coastguard Worker     this->addShaderProgram(shaderParametersB);
1794*35238bceSAndroid Build Coastguard Worker 
1795*35238bceSAndroid Build Coastguard Worker     this->setSamplingLocations(TestSamplingPositions::X_POS, TestSamplingPositions::Y_POS);
1796*35238bceSAndroid Build Coastguard Worker     this->setSamplingGroup(SHADERSAMPLINGGROUP_TEXTURE);
1797*35238bceSAndroid Build Coastguard Worker }
1798*35238bceSAndroid Build Coastguard Worker 
verifyResult(void)1799*35238bceSAndroid Build Coastguard Worker bool DecodeToggledCase::verifyResult(void)
1800*35238bceSAndroid Build Coastguard Worker {
1801*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log        = m_context.getTestContext().getLog();
1802*35238bceSAndroid Build Coastguard Worker     const int resultColorIdx = 0;
1803*35238bceSAndroid Build Coastguard Worker     std::vector<tcu::Vec4> pixelResultList;
1804*35238bceSAndroid Build Coastguard Worker 
1805*35238bceSAndroid Build Coastguard Worker     this->readResultTextures();
1806*35238bceSAndroid Build Coastguard Worker     this->storeResultPixels(pixelResultList);
1807*35238bceSAndroid Build Coastguard Worker     this->logColor(std::string("Expected color: "), resultColorIdx, getColorGreenPass());
1808*35238bceSAndroid Build Coastguard Worker 
1809*35238bceSAndroid Build Coastguard Worker     //    result color is either green (pass) or fail (red)
1810*35238bceSAndroid Build Coastguard Worker     if (tcu::boolAll(tcu::equal(pixelResultList[resultColorIdx], getColorGreenPass())))
1811*35238bceSAndroid Build Coastguard Worker     {
1812*35238bceSAndroid Build Coastguard Worker         log << tcu::TestLog::Message << std::string("returned pass color from GPU") << tcu::TestLog::EndMessage;
1813*35238bceSAndroid Build Coastguard Worker         return true;
1814*35238bceSAndroid Build Coastguard Worker     }
1815*35238bceSAndroid Build Coastguard Worker     else
1816*35238bceSAndroid Build Coastguard Worker     {
1817*35238bceSAndroid Build Coastguard Worker         log << tcu::TestLog::Message << std::string("returned fail color from GPU") << tcu::TestLog::EndMessage;
1818*35238bceSAndroid Build Coastguard Worker         return false;
1819*35238bceSAndroid Build Coastguard Worker     }
1820*35238bceSAndroid Build Coastguard Worker }
1821*35238bceSAndroid Build Coastguard Worker 
1822*35238bceSAndroid Build Coastguard Worker class DecodeMultipleTexturesCase : public SRGBTestCase
1823*35238bceSAndroid Build Coastguard Worker {
1824*35238bceSAndroid Build Coastguard Worker public:
DecodeMultipleTexturesCase(Context & context,const char * name,const char * description,const tcu::TextureFormat internalFormat)1825*35238bceSAndroid Build Coastguard Worker     DecodeMultipleTexturesCase(Context &context, const char *name, const char *description,
1826*35238bceSAndroid Build Coastguard Worker                                const tcu::TextureFormat internalFormat)
1827*35238bceSAndroid Build Coastguard Worker         : SRGBTestCase(context, name, description, internalFormat)
1828*35238bceSAndroid Build Coastguard Worker     {
1829*35238bceSAndroid Build Coastguard Worker     }
1830*35238bceSAndroid Build Coastguard Worker 
~DecodeMultipleTexturesCase(void)1831*35238bceSAndroid Build Coastguard Worker     ~DecodeMultipleTexturesCase(void)
1832*35238bceSAndroid Build Coastguard Worker     {
1833*35238bceSAndroid Build Coastguard Worker     }
1834*35238bceSAndroid Build Coastguard Worker 
1835*35238bceSAndroid Build Coastguard Worker     void setupTest(void);
1836*35238bceSAndroid Build Coastguard Worker     bool verifyResult(void);
1837*35238bceSAndroid Build Coastguard Worker };
1838*35238bceSAndroid Build Coastguard Worker 
setupTest(void)1839*35238bceSAndroid Build Coastguard Worker void DecodeMultipleTexturesCase::setupTest(void)
1840*35238bceSAndroid Build Coastguard Worker {
1841*35238bceSAndroid Build Coastguard Worker     // TEST STEPS:
1842*35238bceSAndroid Build Coastguard Worker     //    - create and set texture_a to DECODE_SKIP_EXT and texture_b to DECODE_EXT
1843*35238bceSAndroid Build Coastguard Worker     //    - upload textures to the GPU and bind to seperate uniform variables
1844*35238bceSAndroid Build Coastguard Worker     //    - sample both textures using texture*()
1845*35238bceSAndroid Build Coastguard Worker     //    - read texel values back to the CPU
1846*35238bceSAndroid Build Coastguard Worker     //    - compare the texel values, both should be different from each other
1847*35238bceSAndroid Build Coastguard Worker 
1848*35238bceSAndroid Build Coastguard Worker     FragmentShaderParameters shaderParameters(SHADEROUTPUTS_TWO, SHADERUNIFORMS_TWO, NULL, BLENDING_NOT_REQUIRED,
1849*35238bceSAndroid Build Coastguard Worker                                               TOGGLING_NOT_REQUIRED);
1850*35238bceSAndroid Build Coastguard Worker 
1851*35238bceSAndroid Build Coastguard Worker     this->addTexture(TEXTURETYPE_2D, TestDimensions::WIDTH, TestDimensions::HEIGHT, getColorReferenceLinear(),
1852*35238bceSAndroid Build Coastguard Worker                      tcu::Sampler::MIRRORED_REPEAT_GL, tcu::Sampler::MIRRORED_REPEAT_GL, tcu::Sampler::LINEAR,
1853*35238bceSAndroid Build Coastguard Worker                      tcu::Sampler::LINEAR, SRGBDECODE_SKIP_DECODE);
1854*35238bceSAndroid Build Coastguard Worker 
1855*35238bceSAndroid Build Coastguard Worker     this->addTexture(TEXTURETYPE_2D, TestDimensions::WIDTH, TestDimensions::HEIGHT, getColorReferenceLinear(),
1856*35238bceSAndroid Build Coastguard Worker                      tcu::Sampler::MIRRORED_REPEAT_GL, tcu::Sampler::MIRRORED_REPEAT_GL, tcu::Sampler::LINEAR,
1857*35238bceSAndroid Build Coastguard Worker                      tcu::Sampler::LINEAR, SRGBDECODE_DECODE);
1858*35238bceSAndroid Build Coastguard Worker 
1859*35238bceSAndroid Build Coastguard Worker     this->addShaderProgram(shaderParameters);
1860*35238bceSAndroid Build Coastguard Worker 
1861*35238bceSAndroid Build Coastguard Worker     this->setSamplingLocations(TestSamplingPositions::X_POS, TestSamplingPositions::Y_POS);
1862*35238bceSAndroid Build Coastguard Worker     this->setSamplingGroup(SHADERSAMPLINGGROUP_TEXTURE);
1863*35238bceSAndroid Build Coastguard Worker }
1864*35238bceSAndroid Build Coastguard Worker 
verifyResult(void)1865*35238bceSAndroid Build Coastguard Worker bool DecodeMultipleTexturesCase::verifyResult(void)
1866*35238bceSAndroid Build Coastguard Worker {
1867*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log        = m_context.getTestContext().getLog();
1868*35238bceSAndroid Build Coastguard Worker     const int resultColorIdx = 0;
1869*35238bceSAndroid Build Coastguard Worker     std::vector<tcu::Vec4> pixelResultList;
1870*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 pixelExpected0;
1871*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 pixelExpected1;
1872*35238bceSAndroid Build Coastguard Worker 
1873*35238bceSAndroid Build Coastguard Worker     this->readResultTextures();
1874*35238bceSAndroid Build Coastguard Worker     this->storeResultPixels(pixelResultList);
1875*35238bceSAndroid Build Coastguard Worker 
1876*35238bceSAndroid Build Coastguard Worker     pixelExpected0 = this->formatReferenceColor(getColorReferenceSRGB());
1877*35238bceSAndroid Build Coastguard Worker     pixelExpected1 = this->formatReferenceColor(getColorReferenceLinear());
1878*35238bceSAndroid Build Coastguard Worker 
1879*35238bceSAndroid Build Coastguard Worker     this->logColor(std::string("Expected color: "), resultColorIdx, pixelExpected0);
1880*35238bceSAndroid Build Coastguard Worker     this->logColor(std::string("Expected color: "), resultColorIdx + 1, pixelExpected1);
1881*35238bceSAndroid Build Coastguard Worker 
1882*35238bceSAndroid Build Coastguard Worker     //    check if the two textures have different values i.e. uTexture0 = sRGB and uTexture1 = linear
1883*35238bceSAndroid Build Coastguard Worker     if (!(tcu::boolAll(tcu::equal(pixelResultList[resultColorIdx], pixelResultList[resultColorIdx + 1]))))
1884*35238bceSAndroid Build Coastguard Worker     {
1885*35238bceSAndroid Build Coastguard Worker         log << tcu::TestLog::Message << std::string("texel values are different") << tcu::TestLog::EndMessage;
1886*35238bceSAndroid Build Coastguard Worker         return true;
1887*35238bceSAndroid Build Coastguard Worker     }
1888*35238bceSAndroid Build Coastguard Worker     else
1889*35238bceSAndroid Build Coastguard Worker     {
1890*35238bceSAndroid Build Coastguard Worker         log << tcu::TestLog::Message << std::string("texel values are equal") << tcu::TestLog::EndMessage;
1891*35238bceSAndroid Build Coastguard Worker         return false;
1892*35238bceSAndroid Build Coastguard Worker     }
1893*35238bceSAndroid Build Coastguard Worker }
1894*35238bceSAndroid Build Coastguard Worker 
1895*35238bceSAndroid Build Coastguard Worker class DecodeSamplerCase : public SRGBTestCase
1896*35238bceSAndroid Build Coastguard Worker {
1897*35238bceSAndroid Build Coastguard Worker public:
DecodeSamplerCase(Context & context,const char * name,const char * description,const tcu::TextureFormat internalFormat)1898*35238bceSAndroid Build Coastguard Worker     DecodeSamplerCase(Context &context, const char *name, const char *description,
1899*35238bceSAndroid Build Coastguard Worker                       const tcu::TextureFormat internalFormat)
1900*35238bceSAndroid Build Coastguard Worker         : SRGBTestCase(context, name, description, internalFormat)
1901*35238bceSAndroid Build Coastguard Worker     {
1902*35238bceSAndroid Build Coastguard Worker     }
1903*35238bceSAndroid Build Coastguard Worker 
~DecodeSamplerCase(void)1904*35238bceSAndroid Build Coastguard Worker     ~DecodeSamplerCase(void)
1905*35238bceSAndroid Build Coastguard Worker     {
1906*35238bceSAndroid Build Coastguard Worker     }
1907*35238bceSAndroid Build Coastguard Worker 
1908*35238bceSAndroid Build Coastguard Worker     void setupTest(void);
1909*35238bceSAndroid Build Coastguard Worker     bool verifyResult(void);
1910*35238bceSAndroid Build Coastguard Worker };
1911*35238bceSAndroid Build Coastguard Worker 
setupTest(void)1912*35238bceSAndroid Build Coastguard Worker void DecodeSamplerCase::setupTest(void)
1913*35238bceSAndroid Build Coastguard Worker {
1914*35238bceSAndroid Build Coastguard Worker     // TEST STEPS:
1915*35238bceSAndroid Build Coastguard Worker     //    - create and set texture_a to DECODE_SKIP_EXT
1916*35238bceSAndroid Build Coastguard Worker     //    - upload texture to the GPU and bind to sampler
1917*35238bceSAndroid Build Coastguard Worker     //    - sample texture using texture*()
1918*35238bceSAndroid Build Coastguard Worker     //    - read texel values back to the CPU
1919*35238bceSAndroid Build Coastguard Worker     //    - compare the texel values, should be in sampler format (linear)
1920*35238bceSAndroid Build Coastguard Worker 
1921*35238bceSAndroid Build Coastguard Worker     FragmentShaderParameters shaderParameters(SHADEROUTPUTS_ONE, SHADERUNIFORMS_ONE, NULL, BLENDING_NOT_REQUIRED,
1922*35238bceSAndroid Build Coastguard Worker                                               TOGGLING_NOT_REQUIRED);
1923*35238bceSAndroid Build Coastguard Worker 
1924*35238bceSAndroid Build Coastguard Worker     this->addTexture(TEXTURETYPE_2D, TestDimensions::WIDTH, TestDimensions::HEIGHT, getColorReferenceLinear(),
1925*35238bceSAndroid Build Coastguard Worker                      tcu::Sampler::MIRRORED_REPEAT_GL, tcu::Sampler::MIRRORED_REPEAT_GL, tcu::Sampler::LINEAR,
1926*35238bceSAndroid Build Coastguard Worker                      tcu::Sampler::LINEAR, SRGBDECODE_SKIP_DECODE);
1927*35238bceSAndroid Build Coastguard Worker 
1928*35238bceSAndroid Build Coastguard Worker     this->addSampler(tcu::Sampler::MIRRORED_REPEAT_GL, tcu::Sampler::MIRRORED_REPEAT_GL, tcu::Sampler::LINEAR,
1929*35238bceSAndroid Build Coastguard Worker                      tcu::Sampler::LINEAR, SRGBDECODE_DECODE);
1930*35238bceSAndroid Build Coastguard Worker 
1931*35238bceSAndroid Build Coastguard Worker     this->addShaderProgram(shaderParameters);
1932*35238bceSAndroid Build Coastguard Worker 
1933*35238bceSAndroid Build Coastguard Worker     this->bindSamplerToTexture(0, 0, GL_TEXTURE0);
1934*35238bceSAndroid Build Coastguard Worker     this->activateSampler(0, true);
1935*35238bceSAndroid Build Coastguard Worker 
1936*35238bceSAndroid Build Coastguard Worker     this->setSamplingLocations(TestSamplingPositions::X_POS, TestSamplingPositions::Y_POS);
1937*35238bceSAndroid Build Coastguard Worker     this->setSamplingGroup(SHADERSAMPLINGGROUP_TEXTURE);
1938*35238bceSAndroid Build Coastguard Worker }
1939*35238bceSAndroid Build Coastguard Worker 
verifyResult(void)1940*35238bceSAndroid Build Coastguard Worker bool DecodeSamplerCase::verifyResult(void)
1941*35238bceSAndroid Build Coastguard Worker {
1942*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log        = m_context.getTestContext().getLog();
1943*35238bceSAndroid Build Coastguard Worker     const int resultColorIdx = 0;
1944*35238bceSAndroid Build Coastguard Worker     std::vector<tcu::Vec4> pixelResultList;
1945*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 pixelConverted;
1946*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 pixelReference;
1947*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 pixelExpected;
1948*35238bceSAndroid Build Coastguard Worker 
1949*35238bceSAndroid Build Coastguard Worker     this->readResultTextures();
1950*35238bceSAndroid Build Coastguard Worker     this->storeResultPixels(pixelResultList);
1951*35238bceSAndroid Build Coastguard Worker 
1952*35238bceSAndroid Build Coastguard Worker     pixelConverted = tcu::linearToSRGB(pixelResultList[resultColorIdx]);
1953*35238bceSAndroid Build Coastguard Worker     pixelReference = this->formatReferenceColor(getColorReferenceSRGB());
1954*35238bceSAndroid Build Coastguard Worker     pixelExpected  = this->formatReferenceColor(getColorReferenceLinear());
1955*35238bceSAndroid Build Coastguard Worker 
1956*35238bceSAndroid Build Coastguard Worker     this->logColor(std::string("Expected color: "), resultColorIdx, pixelExpected);
1957*35238bceSAndroid Build Coastguard Worker 
1958*35238bceSAndroid Build Coastguard Worker     //    texture was rendered using a sampler object with setting DECODE_EXT, therefore, results should be linear
1959*35238bceSAndroid Build Coastguard Worker     if ((tcu::boolAll(tcu::lessThan(tcu::abs(pixelConverted - pixelReference), m_epsilonError))) ||
1960*35238bceSAndroid Build Coastguard Worker         (tcu::boolAll(tcu::equal(pixelConverted, pixelReference))))
1961*35238bceSAndroid Build Coastguard Worker     {
1962*35238bceSAndroid Build Coastguard Worker         log << tcu::TestLog::Message << std::string("linear as expected") << tcu::TestLog::EndMessage;
1963*35238bceSAndroid Build Coastguard Worker         return true;
1964*35238bceSAndroid Build Coastguard Worker     }
1965*35238bceSAndroid Build Coastguard Worker     else
1966*35238bceSAndroid Build Coastguard Worker     {
1967*35238bceSAndroid Build Coastguard Worker         log << tcu::TestLog::Message << std::string("not linear as expected") << tcu::TestLog::EndMessage;
1968*35238bceSAndroid Build Coastguard Worker         return false;
1969*35238bceSAndroid Build Coastguard Worker     }
1970*35238bceSAndroid Build Coastguard Worker }
1971*35238bceSAndroid Build Coastguard Worker 
1972*35238bceSAndroid Build Coastguard Worker } // namespace
1973*35238bceSAndroid Build Coastguard Worker 
SRGBDecodeTests(Context & context)1974*35238bceSAndroid Build Coastguard Worker SRGBDecodeTests::SRGBDecodeTests(Context &context) : TestCaseGroup(context, "skip_decode", "sRGB skip decode tests")
1975*35238bceSAndroid Build Coastguard Worker {
1976*35238bceSAndroid Build Coastguard Worker }
1977*35238bceSAndroid Build Coastguard Worker 
~SRGBDecodeTests(void)1978*35238bceSAndroid Build Coastguard Worker SRGBDecodeTests::~SRGBDecodeTests(void)
1979*35238bceSAndroid Build Coastguard Worker {
1980*35238bceSAndroid Build Coastguard Worker }
1981*35238bceSAndroid Build Coastguard Worker 
init(void)1982*35238bceSAndroid Build Coastguard Worker void SRGBDecodeTests::init(void)
1983*35238bceSAndroid Build Coastguard Worker {
1984*35238bceSAndroid Build Coastguard Worker     const TestGroupConfig testGroupConfigList[] = {
1985*35238bceSAndroid Build Coastguard Worker         TestGroupConfig("srgba8", "srgb decode tests using srgba internal format",
1986*35238bceSAndroid Build Coastguard Worker                         tcu::TextureFormat(tcu::TextureFormat::sRGBA, tcu::TextureFormat::UNORM_INT8)),
1987*35238bceSAndroid Build Coastguard Worker         TestGroupConfig("srg8", "srgb decode tests using srg8 internal format",
1988*35238bceSAndroid Build Coastguard Worker                         tcu::TextureFormat(tcu::TextureFormat::sRG, tcu::TextureFormat::UNORM_INT8)),
1989*35238bceSAndroid Build Coastguard Worker         TestGroupConfig("sr8", "srgb decode tests using sr8 internal format",
1990*35238bceSAndroid Build Coastguard Worker                         tcu::TextureFormat(tcu::TextureFormat::sR, tcu::TextureFormat::UNORM_INT8))};
1991*35238bceSAndroid Build Coastguard Worker 
1992*35238bceSAndroid Build Coastguard Worker     // create groups for all desired internal formats, adding test cases to each
1993*35238bceSAndroid Build Coastguard Worker     for (std::size_t idx = 0; idx < DE_LENGTH_OF_ARRAY(testGroupConfigList); idx++)
1994*35238bceSAndroid Build Coastguard Worker     {
1995*35238bceSAndroid Build Coastguard Worker         tcu::TestCaseGroup *const testGroup =
1996*35238bceSAndroid Build Coastguard Worker             new tcu::TestCaseGroup(m_testCtx, testGroupConfigList[idx].name, testGroupConfigList[idx].description);
1997*35238bceSAndroid Build Coastguard Worker         tcu::TestNode::addChild(testGroup);
1998*35238bceSAndroid Build Coastguard Worker 
1999*35238bceSAndroid Build Coastguard Worker         testGroup->addChild(new TextureDecodeSkippedCase(
2000*35238bceSAndroid Build Coastguard Worker             m_context, "skipped", "testing for sRGB color values with sRGB texture decoding skipped",
2001*35238bceSAndroid Build Coastguard Worker             testGroupConfigList[idx].internalFormat));
2002*35238bceSAndroid Build Coastguard Worker         testGroup->addChild(new TextureDecodeEnabledCase(
2003*35238bceSAndroid Build Coastguard Worker             m_context, "enabled", "testing for linear color values with sRGB texture decoding enabled",
2004*35238bceSAndroid Build Coastguard Worker             testGroupConfigList[idx].internalFormat));
2005*35238bceSAndroid Build Coastguard Worker         testGroup->addChild(new TexelFetchDecodeSkippedcase(
2006*35238bceSAndroid Build Coastguard Worker             m_context, "texel_fetch", "testing for linear color values with sRGB texture decoding skipped",
2007*35238bceSAndroid Build Coastguard Worker             testGroupConfigList[idx].internalFormat));
2008*35238bceSAndroid Build Coastguard Worker         testGroup->addChild(new GPUConversionDecodeEnabledCase(
2009*35238bceSAndroid Build Coastguard Worker             m_context, "conversion_gpu", "sampling linear values and performing conversion on the gpu",
2010*35238bceSAndroid Build Coastguard Worker             testGroupConfigList[idx].internalFormat));
2011*35238bceSAndroid Build Coastguard Worker         testGroup->addChild(new DecodeToggledCase(m_context, "toggled", "toggle the sRGB decoding between draw calls",
2012*35238bceSAndroid Build Coastguard Worker                                                   testGroupConfigList[idx].internalFormat));
2013*35238bceSAndroid Build Coastguard Worker         testGroup->addChild(new DecodeMultipleTexturesCase(
2014*35238bceSAndroid Build Coastguard Worker             m_context, "multiple_textures", "upload multiple textures with different sRGB decode values and sample",
2015*35238bceSAndroid Build Coastguard Worker             testGroupConfigList[idx].internalFormat));
2016*35238bceSAndroid Build Coastguard Worker         testGroup->addChild(new DecodeSamplerCase(m_context, "using_sampler",
2017*35238bceSAndroid Build Coastguard Worker                                                   "testing that sampler object takes priority over texture state",
2018*35238bceSAndroid Build Coastguard Worker                                                   testGroupConfigList[idx].internalFormat));
2019*35238bceSAndroid Build Coastguard Worker     }
2020*35238bceSAndroid Build Coastguard Worker }
2021*35238bceSAndroid Build Coastguard Worker 
2022*35238bceSAndroid Build Coastguard Worker } // namespace Functional
2023*35238bceSAndroid Build Coastguard Worker } // namespace gles31
2024*35238bceSAndroid Build Coastguard Worker } // namespace deqp
2025