1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 3.1 Module
3 * -------------------------------------------------
5 * Copyright 2017 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Texture format tests.
22 *//*--------------------------------------------------------------------*/
24 #include "es31fSRGBDecodeTests.hpp"
25 #include "gluContextInfo.hpp"
26 #include "gluCallLogWrapper.hpp"
27 #include "gluRenderContext.hpp"
28 #include "gluTexture.hpp"
29 #include "glsTextureTestUtil.hpp"
30 #include "tcuPixelFormat.hpp"
31 #include "tcuTestContext.hpp"
32 #include "tcuRenderTarget.hpp"
33 #include "gluTextureUtil.hpp"
34 #include "tcuTextureUtil.hpp"
35 #include "glwFunctions.hpp"
36 #include "gluDefs.hpp"
37 #include "glwEnums.hpp"
38 #include "deUniquePtr.hpp"
39 #include "gluPixelTransfer.hpp"
40 #include "tcuDefs.hpp"
41 #include "tcuVectorUtil.hpp"
42 #include "gluObjectWrapper.hpp"
43 #include "gluStrUtil.hpp"
44 #include "tcuTestLog.hpp"
55 using glu::TextureTestUtil::TEXTURETYPE_2D;
59 SRGBDECODE_SKIP_DECODE = 0,
61 SRGBDECODE_DECODE_DEFAULT
66 SHADEROUTPUTS_ONE = 1,
72 SHADERUNIFORMS_ONE = 1,
76 enum ShaderSamplingGroup
78 SHADERSAMPLINGGROUP_TEXTURE = 0,
79 SHADERSAMPLINGGROUP_TEXEL_FETCH
82 enum ShaderSamplingType
84 TEXTURESAMPLING_TEXTURE = 0,
85 TEXTURESAMPLING_TEXTURE_LOD,
86 TEXTURESAMPLING_TEXTURE_GRAD,
87 TEXTURESAMPLING_TEXTURE_OFFSET,
88 TEXTURESAMPLING_TEXTURE_PROJ,
89 TEXTURESAMPLING_TEXELFETCH,
90 TEXTURESAMPLING_TEXELFETCH_OFFSET,
92 // ranges required for looping mechanism in a case nodes iteration function
93 TEXTURESAMPLING_TEXTURE_START = TEXTURESAMPLING_TEXTURE,
94 TEXTURESAMPLING_TEXTURE_END = TEXTURESAMPLING_TEXTURE_PROJ + 1,
95 TEXTURESAMPLING_TEXELFETCH_START = TEXTURESAMPLING_TEXELFETCH,
96 TEXTURESAMPLING_TEXELFETCH_END = TEXTURESAMPLING_TEXELFETCH_OFFSET + 1
99 enum FunctionParameters
101 FUNCTIONPARAMETERS_ONE = 1,
102 FUNCTIONPARAMETERS_TWO
107 BLENDING_REQUIRED = 0,
108 BLENDING_NOT_REQUIRED
113 TOGGLING_REQUIRED = 0,
114 TOGGLING_NOT_REQUIRED
117 tcu::Vec4 getColorReferenceLinear (void)
119 return tcu::Vec4(0.2f, 0.3f, 0.4f, 1.0f);
122 tcu::Vec4 getColorReferenceSRGB (void)
124 return tcu::linearToSRGB(tcu::Vec4(0.2f, 0.3f, 0.4f, 1.0f));
127 tcu::Vec4 getColorGreenPass (void)
129 return tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f);
132 namespace TestDimensions
134 const int WIDTH = 128;
135 const int HEIGHT = 128;
136 } // global test texture dimensions
138 namespace TestSamplingPositions
142 } // global test sampling positions
144 const char* getFunctionDefinitionSRGBToLinearCheck (void)
146 static const char* functionDefinition =
147 "mediump vec4 srgbToLinearCheck(in mediump vec4 texelSRGBA, in mediump vec4 texelLinear) \n"
149 " const int NUM_CHANNELS = 4;"
150 " mediump vec4 texelSRGBAConverted; \n"
151 " mediump vec4 epsilonErr = vec4(0.005); \n"
152 " mediump vec4 testResult; \n"
153 " for (int idx = 0; idx < NUM_CHANNELS; idx++) \n"
155 " texelSRGBAConverted[idx] = pow( (texelSRGBA[idx] + 0.055) / 1.055, 1.0 / 0.4116); \n"
157 " if ( all(lessThan(abs(texelSRGBAConverted - texelLinear), epsilonErr)) || all(equal(texelSRGBAConverted, texelLinear)) ) \n"
159 " return testResult = vec4(0.0, 1.0, 0.0, 1.0); \n"
163 " return testResult = vec4(1.0, 0.0, 0.0, 1.0); \n"
167 return functionDefinition;
170 const char* getFunctionDefinitionEqualCheck (void)
172 static const char* functionDefinition =
173 "mediump vec4 colorsEqualCheck(in mediump vec4 colorA, in mediump vec4 colorB) \n"
175 " mediump vec4 epsilonErr = vec4(0.005); \n"
176 " mediump vec4 testResult; \n"
177 " if ( all(lessThan(abs(colorA - colorB), epsilonErr)) || all(equal(colorA, colorB)) ) \n"
179 " return testResult = vec4(0.0, 1.0, 0.0, 1.0); \n"
183 " return testResult = vec4(1.0, 0.0, 0.0, 1.0); \n"
187 return functionDefinition;
190 namespace EpsilonError
192 const float CPU = 0.005f;
195 struct TestGroupConfig
197 TestGroupConfig (const char* groupName, const char* groupDescription, const tcu::TextureFormat groupInternalFormat)
199 , description (groupDescription)
200 , internalFormat (groupInternalFormat) {}
202 ~TestGroupConfig (void) {};
205 const char* description;
206 const tcu::TextureFormat internalFormat;
211 UniformData (glw::GLuint uniformLocation, const std::string& uniformName)
212 : location (uniformLocation)
214 , toggleDecode (false) {}
216 ~UniformData (void) {}
218 glw::GLuint location;
223 struct UniformToToggle
225 UniformToToggle (const int uniformProgramIdx, const std::string& uniformName)
226 : programIdx (uniformProgramIdx)
227 , name (uniformName) {}
229 ~UniformToToggle (void) {}
235 struct ComparisonFunction
237 ComparisonFunction (const std::string& funcName, const FunctionParameters funcParameters, const std::string& funcImplementation)
239 , parameters (funcParameters)
240 , implementation (funcImplementation) {}
242 ~ComparisonFunction (void) {}
245 FunctionParameters parameters;
246 std::string implementation;
249 struct FragmentShaderParameters
251 FragmentShaderParameters (const ShaderOutputs outputTotal,
252 const ShaderUniforms uniformTotal,
253 ComparisonFunction* comparisonFunction,
254 Blending blendRequired,
255 Toggling toggleRequired);
257 ~FragmentShaderParameters (void);
259 ShaderOutputs outputTotal;
260 ShaderUniforms uniformTotal;
261 ShaderSamplingType samplingType;
262 std::string functionName;
263 FunctionParameters functionParameters;
264 std::string functionImplementation;
266 Blending blendRequired;
267 Toggling toggleRequired;
268 std::vector<std::string> uniformsToToggle;
271 FragmentShaderParameters::FragmentShaderParameters (const ShaderOutputs paramsOutputTotal,
272 const ShaderUniforms paramsUniformTotal,
273 ComparisonFunction* paramsComparisonFunction,
274 Blending paramsBlendRequired,
275 Toggling paramsToggleRequired)
276 : outputTotal (paramsOutputTotal)
277 , uniformTotal (paramsUniformTotal)
278 , blendRequired (paramsBlendRequired)
279 , toggleRequired (paramsToggleRequired)
281 if (paramsComparisonFunction != DE_NULL)
283 functionName = paramsComparisonFunction->name;
284 functionParameters = paramsComparisonFunction->parameters;
285 functionImplementation = paramsComparisonFunction->implementation;
295 FragmentShaderParameters::~FragmentShaderParameters (void)
299 class SRGBTestSampler
302 SRGBTestSampler (Context& context,
303 const tcu::Sampler::WrapMode wrapS,
304 const tcu::Sampler::WrapMode wrapT,
305 const tcu::Sampler::FilterMode minFilter,
306 const tcu::Sampler::FilterMode magFilter,
307 const SRGBDecode decoding);
308 ~SRGBTestSampler (void);
310 void setDecode (const SRGBDecode decoding);
311 void setTextureUnit (const deUint32 textureUnit);
312 void setIsActive (const bool isActive);
314 deUint32 getHandle (void) const;
315 bool getIsActive (void) const;
317 void bindToTexture (void);
318 void unbindFromTexture (void);
321 const glw::Functions* m_gl;
322 deUint32 m_samplerHandle;
323 tcu::Sampler::WrapMode m_wrapS;
324 tcu::Sampler::WrapMode m_wrapT;
325 tcu::Sampler::FilterMode m_minFilter;
326 tcu::Sampler::FilterMode m_magFilter;
327 SRGBDecode m_decoding;
328 deUint32 m_textureUnit;
332 SRGBTestSampler::SRGBTestSampler (Context& context,
333 const tcu::Sampler::WrapMode wrapS,
334 const tcu::Sampler::WrapMode wrapT,
335 const tcu::Sampler::FilterMode minFilter,
336 const tcu::Sampler::FilterMode magFilter,
337 const SRGBDecode decoding)
338 : m_gl (&context.getRenderContext().getFunctions())
341 , m_minFilter (minFilter)
342 , m_magFilter (magFilter)
345 m_gl->genSamplers(1, &m_samplerHandle);
347 m_gl->samplerParameteri(m_samplerHandle, GL_TEXTURE_WRAP_S, glu::getGLWrapMode(m_wrapS));
348 m_gl->samplerParameteri(m_samplerHandle, GL_TEXTURE_WRAP_T, glu::getGLWrapMode(m_wrapT));
349 m_gl->samplerParameteri(m_samplerHandle, GL_TEXTURE_MIN_FILTER, glu::getGLFilterMode(m_minFilter));
350 m_gl->samplerParameteri(m_samplerHandle, GL_TEXTURE_MAG_FILTER, glu::getGLFilterMode(m_magFilter));
352 this->setDecode(decoding);
355 SRGBTestSampler::~SRGBTestSampler (void)
357 m_gl->deleteSamplers(1, &m_samplerHandle);
360 void SRGBTestSampler::setDecode (const SRGBDecode decoding)
362 if (decoding == SRGBDECODE_SKIP_DECODE)
364 m_gl->samplerParameteri(m_samplerHandle, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT);
365 GLU_EXPECT_NO_ERROR(m_gl->getError(), "samplerParameteri(m_samplerID, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT)");
367 else if (decoding == SRGBDECODE_DECODE)
369 m_gl->samplerParameteri(m_samplerHandle, GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT);
370 GLU_EXPECT_NO_ERROR(m_gl->getError(), "samplerParameteri(m_samplerID, GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT)");
374 DE_FATAL("sRGB texture sampler must have either GL_SKIP_DECODE_EXT or GL_DECODE_EXT settings");
377 m_decoding = decoding;
380 void SRGBTestSampler::setTextureUnit (const deUint32 textureUnit)
382 m_textureUnit = textureUnit;
385 void SRGBTestSampler::setIsActive (const bool isActive)
387 m_isActive = isActive;
390 deUint32 SRGBTestSampler::getHandle (void) const
392 return m_samplerHandle;
395 bool SRGBTestSampler::getIsActive (void) const
400 void SRGBTestSampler::bindToTexture (void)
402 m_gl->bindSampler(m_textureUnit, m_samplerHandle);
405 void SRGBTestSampler::unbindFromTexture (void)
407 m_gl->bindSampler(m_textureUnit, 0);
410 class SRGBTestTexture
413 SRGBTestTexture (Context& context,
414 const glu::TextureTestUtil::TextureType targetType,
415 const tcu::TextureFormat internalFormat,
418 const tcu::Vec4 color,
419 const tcu::Sampler::WrapMode wrapS,
420 const tcu::Sampler::WrapMode wrapT,
421 const tcu::Sampler::FilterMode minFilter,
422 const tcu::Sampler::FilterMode magFilter,
423 const SRGBDecode decoding);
424 ~SRGBTestTexture (void);
426 void setParameters (void);
427 void setDecode (const SRGBDecode decoding);
428 void setHasSampler (const bool hasSampler);
430 deUint32 getHandle (void) const;
431 deUint32 getGLTargetType (void) const;
432 SRGBDecode getDecode (void) const;
433 bool getHasSampler (void) const;
438 void setColor (void);
441 glu::Texture2D m_source;
442 glu::TextureTestUtil::TextureType m_targetType;
443 const tcu::TextureFormat m_internalFormat;
447 tcu::Sampler::WrapMode m_wrapS;
448 tcu::Sampler::WrapMode m_wrapT;
449 tcu::Sampler::FilterMode m_minFilter;
450 tcu::Sampler::FilterMode m_magFilter;
451 SRGBDecode m_decoding;
455 SRGBTestTexture::SRGBTestTexture (Context& context,
456 const glu::TextureTestUtil::TextureType targetType,
457 const tcu::TextureFormat internalFormat,
460 const tcu::Vec4 color,
461 const tcu::Sampler::WrapMode wrapS,
462 const tcu::Sampler::WrapMode wrapT,
463 const tcu::Sampler::FilterMode minFilter,
464 const tcu::Sampler::FilterMode magFilter,
466 : m_context (context)
467 , m_source (context.getRenderContext(), glu::getInternalFormat(internalFormat), width, height)
468 , m_targetType (targetType)
469 , m_internalFormat (internalFormat)
475 , m_minFilter (minFilter)
476 , m_magFilter (magFilter)
477 , m_decoding (decoding)
478 , m_hasSampler (false)
483 SRGBTestTexture::~SRGBTestTexture (void)
487 void SRGBTestTexture::setParameters (void)
489 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
491 gl.bindTexture(this->getGLTargetType(), this->getHandle());
493 gl.texParameteri(this->getGLTargetType(), GL_TEXTURE_WRAP_S, glu::getGLWrapMode(m_wrapS));
494 gl.texParameteri(this->getGLTargetType(), GL_TEXTURE_WRAP_T, glu::getGLWrapMode(m_wrapT));
495 gl.texParameteri(this->getGLTargetType(), GL_TEXTURE_MIN_FILTER, glu::getGLFilterMode(m_minFilter));
496 gl.texParameteri(this->getGLTargetType(), GL_TEXTURE_MAG_FILTER, glu::getGLFilterMode(m_magFilter));
498 gl.bindTexture(this->getGLTargetType(), 0);
500 setDecode(m_decoding);
503 void SRGBTestTexture::setDecode (const SRGBDecode decoding)
505 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
507 gl.bindTexture(this->getGLTargetType(), this->getHandle());
511 case SRGBDECODE_SKIP_DECODE:
513 gl.texParameteri(this->getGLTargetType(), GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT);
514 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri(this->getGLTargetType(), GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT)");
517 case SRGBDECODE_DECODE:
519 gl.texParameteri(this->getGLTargetType(), GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT);
520 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri(this->getGLTargetType(), GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT)");
523 case SRGBDECODE_DECODE_DEFAULT:
525 // do not use srgb decode options. Set to default
529 DE_FATAL("Error: Decoding option not recognised");
532 gl.bindTexture(this->getGLTargetType(), 0);
534 m_decoding = decoding;
537 void SRGBTestTexture::setHasSampler (const bool hasSampler)
539 m_hasSampler = hasSampler;
542 deUint32 SRGBTestTexture::getHandle (void) const
544 return m_source.getGLTexture();
547 deUint32 SRGBTestTexture::getGLTargetType (void) const
549 switch (m_targetType)
553 return GL_TEXTURE_2D;
557 DE_FATAL("Error: Target type not recognised");
563 SRGBDecode SRGBTestTexture::getDecode (void) const
568 bool SRGBTestTexture::getHasSampler (void) const
573 void SRGBTestTexture::upload (void)
578 void SRGBTestTexture::setColor (void)
580 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
582 gl.bindTexture(this->getGLTargetType(), this->getHandle());
584 m_source.getRefTexture().allocLevel(0);
586 for (int py = 0; py < m_height; py++)
588 for (int px = 0; px < m_width; px++)
590 m_source.getRefTexture().getLevel(0).setPixel(m_color, px, py);
594 gl.bindTexture(this->getGLTargetType(), 0);
597 class SRGBTestProgram
600 SRGBTestProgram (Context& context, const FragmentShaderParameters& shaderParameters);
601 ~SRGBTestProgram (void);
603 void setBlendRequired (bool blendRequired);
604 void setToggleRequired (bool toggleRequired);
605 void setUniformToggle (int location, bool toggleDecodeValue);
607 int getUniformTotal (void) const;
608 const std::vector<UniformData>& getUniformDataList (void) const;
609 const UniformData& getUniformAtLocation (int location) const;
610 int getUniformLocation (const std::string& name);
611 deUint32 getHandle (void) const;
612 bool getBlendRequired (void) const;
613 bool getToggleRequired (void) const;
614 const std::string& getFragmentShader (void) const;
617 std::string genFunctionCall (ShaderSamplingType samplingType, const int uniformIdx);
618 void genFragmentShader (void);
621 de::MovePtr<glu::ShaderProgram> m_program;
622 FragmentShaderParameters m_shaderFragmentParameters;
623 std::string m_shaderVertex;
624 std::string m_shaderFragment;
625 std::vector<UniformData> m_uniformDataList;
626 bool m_blendRequired;
627 bool m_toggleRequired;
630 SRGBTestProgram::SRGBTestProgram (Context& context, const FragmentShaderParameters& shaderParameters)
631 : m_context (context)
632 , m_shaderFragmentParameters (shaderParameters)
633 , m_blendRequired (false)
634 , m_toggleRequired (false)
636 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
637 tcu::TestLog& log = m_context.getTestContext().getLog();
638 glu::ShaderProgramInfo buildInfo;
639 const int totalShaderStages = 2;
641 // default vertex shader used in all tests
642 m_shaderVertex = "#version 310 es \n"
643 "layout (location = 0) in mediump vec3 aPosition; \n"
644 "layout (location = 1) in mediump vec2 aTexCoord; \n"
645 "out mediump vec2 vs_aTexCoord; \n"
648 " gl_Position = vec4(aPosition, 1.0); \n"
649 " vs_aTexCoord = aTexCoord; \n"
652 this->genFragmentShader();
654 m_program = de::MovePtr<glu::ShaderProgram>(new glu::ShaderProgram(m_context.getRenderContext(), glu::makeVtxFragSources(m_shaderVertex, m_shaderFragment)));
656 if (!m_program->isOk())
658 TCU_FAIL("Failed to compile shaders and link program");
661 glw::GLint activeUniforms, maxLen;
662 glw::GLint size, location;
665 gl.getProgramiv(this->getHandle(), GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLen);
666 gl.getProgramiv(this->getHandle(), GL_ACTIVE_UNIFORMS, &activeUniforms);
668 std::vector<glw::GLchar> uniformName(static_cast<int>(maxLen));
669 for (int idx = 0; idx < activeUniforms; idx++)
671 gl.getActiveUniform(this->getHandle(), idx, maxLen, NULL, &size, &type, &uniformName[0]);
672 location = gl.getUniformLocation(this->getHandle(), &uniformName[0]);
674 UniformData uniformData(location, std::string(&uniformName[0], strlen(&uniformName[0])));
675 m_uniformDataList.push_back(uniformData);
678 // log shader program info. Only vertex and fragment shaders included
679 buildInfo.program = m_program->getProgramInfo();
680 for (int shaderIdx = 0; shaderIdx < totalShaderStages; shaderIdx++)
682 glu::ShaderInfo shaderInfo = m_program->getShaderInfo(static_cast<glu::ShaderType>(static_cast<int>(glu::SHADERTYPE_VERTEX) + static_cast<int>(shaderIdx)), 0);
683 buildInfo.shaders.push_back(shaderInfo);
689 SRGBTestProgram::~SRGBTestProgram (void)
691 m_program = de::MovePtr<glu::ShaderProgram>(DE_NULL);
694 void SRGBTestProgram::setBlendRequired (bool blendRequired)
696 m_blendRequired = blendRequired;
699 void SRGBTestProgram::setToggleRequired (bool toggleRequired)
701 m_toggleRequired = toggleRequired;
704 void SRGBTestProgram::setUniformToggle (int location, bool toggleDecodeValue)
706 if ( (m_uniformDataList.empty() == false) && (location >= 0) && (location <= (int)m_uniformDataList.size()) )
708 m_uniformDataList[location].toggleDecode = toggleDecodeValue;
712 TCU_THROW(TestError, "Error: Uniform location not found. glGetActiveUniforms returned uniforms incorrectly ");
716 int SRGBTestProgram::getUniformTotal (void) const
718 return (int)m_uniformDataList.size();
721 const std::vector<UniformData>& SRGBTestProgram::getUniformDataList (void) const
723 return m_uniformDataList;
726 const UniformData& SRGBTestProgram::getUniformAtLocation (int location) const
728 return m_uniformDataList[location];
731 int SRGBTestProgram::getUniformLocation (const std::string& name)
733 for (std::size_t idx = 0; idx < m_uniformDataList.size(); idx++)
735 if (m_uniformDataList[idx].name == name)
737 return m_uniformDataList[idx].location;
741 TCU_THROW(TestError, "Error: If name correctly requested then glGetActiveUniforms() returned active uniform data incorrectly");
745 glw::GLuint SRGBTestProgram::getHandle (void) const
747 return m_program->getProgram();
750 bool SRGBTestProgram::getBlendRequired (void) const
752 return m_blendRequired;
755 bool SRGBTestProgram::getToggleRequired (void) const
757 return m_toggleRequired;
760 const std::string& SRGBTestProgram::getFragmentShader (void) const
762 return m_shaderFragment;
765 std::string SRGBTestProgram::genFunctionCall (ShaderSamplingType samplingType, const int uniformIdx)
767 std::ostringstream functionCall;
769 functionCall << " mediump vec4 texelColor" << uniformIdx << " = ";
771 switch (samplingType)
773 case TEXTURESAMPLING_TEXTURE:
775 functionCall << "texture(uTexture" << uniformIdx << ", vs_aTexCoord); \n";
778 case TEXTURESAMPLING_TEXTURE_LOD:
780 functionCall << "textureLod(uTexture" << uniformIdx << ", vs_aTexCoord, 0.0); \n";
783 case TEXTURESAMPLING_TEXTURE_GRAD:
785 functionCall << "textureGrad(uTexture" << uniformIdx << ", vs_aTexCoord, vec2(0.0, 0.0), vec2(0.0, 0.0)); \n";
788 case TEXTURESAMPLING_TEXTURE_OFFSET:
790 functionCall << "textureOffset(uTexture" << uniformIdx << ", vs_aTexCoord, ivec2(0.0, 0.0)); \n";
793 case TEXTURESAMPLING_TEXTURE_PROJ:
795 functionCall << "textureProj(uTexture" << uniformIdx << ", vec3(vs_aTexCoord, 1.0)); \n";
798 case TEXTURESAMPLING_TEXELFETCH:
800 functionCall << "texelFetch(uTexture" << uniformIdx << ", ivec2(vs_aTexCoord), 0); \n";
803 case TEXTURESAMPLING_TEXELFETCH_OFFSET:
805 functionCall << "texelFetchOffset(uTexture" << uniformIdx << ", ivec2(vs_aTexCoord), 0, ivec2(0.0, 0.0)); \n";
810 DE_FATAL("Error: Sampling type not recognised");
814 return functionCall.str();
817 void SRGBTestProgram::genFragmentShader (void)
819 std::ostringstream source;
820 std::ostringstream sampleTexture;
821 std::ostringstream functionParameters;
822 std::ostringstream shaderOutputs;
824 // if comparison function is present resulting shader requires precisely one output
825 DE_ASSERT( !(m_shaderFragmentParameters.hasFunction && (static_cast<int>(m_shaderFragmentParameters.outputTotal) != static_cast<int>(SHADEROUTPUTS_ONE))) );
827 // function parameters must equal the number of uniforms i.e. textures passed into the function
828 DE_ASSERT( !(m_shaderFragmentParameters.hasFunction && (static_cast<int>(m_shaderFragmentParameters.uniformTotal) != static_cast<int>(m_shaderFragmentParameters.functionParameters))) );
830 // fragment shader cannot contain more outputs than the number of texture uniforms
831 DE_ASSERT( !(static_cast<int>(m_shaderFragmentParameters.outputTotal) > static_cast<int>(m_shaderFragmentParameters.uniformTotal)) ) ;
833 source << "#version 310 es \n"
834 << "in mediump vec2 vs_aTexCoord; \n";
836 for (int output = 0; output < m_shaderFragmentParameters.outputTotal; output++)
838 source << "layout (location = " << output << ") out mediump vec4 fs_aColor" << output << "; \n";
841 for (int uniform = 0; uniform < m_shaderFragmentParameters.uniformTotal; uniform++)
843 source << "uniform sampler2D uTexture" << uniform << "; \n";
846 if (m_shaderFragmentParameters.hasFunction == true)
848 source << m_shaderFragmentParameters.functionImplementation;
851 source << "void main () \n"
854 for (int uniformIdx = 0; uniformIdx < m_shaderFragmentParameters.uniformTotal; uniformIdx++)
856 source << this->genFunctionCall(m_shaderFragmentParameters.samplingType, uniformIdx);
859 if (m_shaderFragmentParameters.hasFunction == true)
861 switch ( static_cast<FunctionParameters>(m_shaderFragmentParameters.functionParameters) )
863 case FUNCTIONPARAMETERS_ONE:
865 functionParameters << "(texelColor0)";
868 case FUNCTIONPARAMETERS_TWO:
870 functionParameters << "(texelColor0, texelColor1)";
875 DE_FATAL("Error: Number of comparison function parameters invalid");
879 shaderOutputs << " fs_aColor0 = " << m_shaderFragmentParameters.functionName << functionParameters.str() << "; \n";
883 for (int output = 0; output < m_shaderFragmentParameters.outputTotal; output++)
885 shaderOutputs << " fs_aColor" << output << " = texelColor" << output << "; \n";
889 source << shaderOutputs.str();
892 m_shaderFragment = source.str();
895 class SRGBTestCase : public TestCase
898 SRGBTestCase (Context& context, const char* name, const char* description, const tcu::TextureFormat internalFormat);
899 ~SRGBTestCase (void);
903 virtual IterateResult iterate (void);
905 void setSamplingGroup (const ShaderSamplingGroup samplingGroup);
906 void setSamplingLocations (const int px, const int py);
907 void setShaderProgramBlendRequired (const int programIdx, const bool blend);
908 void setShaderProgramToggleRequired (const int programIdx, const bool toggle);
909 void setUniformToggle (const int programIdx, const std::string& uniformName, bool toggleDecode);
911 deUint32 getShaderProgramHandle (const int programIdx) const;
912 deUint32 getTextureHandle (const int textureIdx) const;
914 void addTexture (const glu::TextureTestUtil::TextureType targetType,
917 const tcu::Vec4 color,
918 const tcu::Sampler::WrapMode wrapS,
919 const tcu::Sampler::WrapMode wrapT,
920 const tcu::Sampler::FilterMode minFilter,
921 const tcu::Sampler::FilterMode magFilter,
922 const SRGBDecode decoding);
923 void addSampler (const tcu::Sampler::WrapMode wrapS,
924 const tcu::Sampler::WrapMode wrapT,
925 const tcu::Sampler::FilterMode minFilter,
926 const tcu::Sampler::FilterMode magFilter,
927 const SRGBDecode decoding);
928 void addShaderProgram (const FragmentShaderParameters& shaderParameters);
930 void genShaderPrograms (ShaderSamplingType samplingType);
931 void deleteShaderPrograms (void);
933 void readResultTextures (void);
934 void storeResultPixels (std::vector<tcu::Vec4>& resultPixelData);
936 void toggleDecode (const std::vector<UniformData>& uniformDataList);
937 void bindSamplerToTexture (const int samplerIdx, const int textureIdx, const deUint32 textureUnit);
938 void activateSampler (const int samplerIdx, const bool active);
939 void logColor (const std::string& colorLogMessage, int colorIdx, tcu::Vec4 color) const;
940 tcu::Vec4 formatReferenceColor (tcu::Vec4 referenceColor);
942 // render function has a default implentation. Can be overriden for special cases
943 virtual void render (void);
945 // following functions must be overidden to perform individual test cases
946 virtual void setupTest (void) = 0;
947 virtual bool verifyResult (void) = 0;
950 de::MovePtr<glu::Framebuffer> m_framebuffer;
951 std::vector<SRGBTestTexture*> m_textureSourceList;
952 std::vector<SRGBTestSampler*> m_samplerList;
953 std::vector<glw::GLuint> m_renderBufferList;
954 const tcu::Vec4 m_epsilonError;
955 std::vector<tcu::TextureLevel> m_textureResultList;
956 int m_resultOutputTotal;
957 tcu::TextureFormat m_resultTextureFormat;
959 glw::GLuint m_vertexDataID;
960 std::vector<FragmentShaderParameters> m_shaderParametersList;
961 std::vector<SRGBTestProgram*> m_shaderProgramList;
962 ShaderSamplingGroup m_samplingGroup;
965 const tcu::TextureFormat m_internalFormat;
968 void uploadTextures (void);
969 void initFrameBuffer (void);
970 void initVertexData (void);
972 SRGBTestCase (const SRGBTestCase&);
973 SRGBTestCase& operator= (const SRGBTestCase&);
976 SRGBTestCase::SRGBTestCase (Context& context, const char* name, const char* description, const tcu::TextureFormat internalFormat)
977 : TestCase (context, name, description)
978 , m_epsilonError (EpsilonError::CPU)
979 , m_resultTextureFormat (tcu::TextureFormat(tcu::TextureFormat::sRGBA, tcu::TextureFormat::UNORM_INT8))
982 , m_samplingGroup (SHADERSAMPLINGGROUP_TEXTURE)
983 , m_internalFormat (internalFormat)
987 SRGBTestCase::~SRGBTestCase (void)
992 void SRGBTestCase::init (void)
994 // extension requirements for test
995 if ( (glu::getInternalFormat(m_internalFormat) == GL_SRGB8_ALPHA8) && !m_context.getContextInfo().isExtensionSupported("GL_EXT_texture_sRGB_decode") )
997 throw tcu::NotSupportedError("Test requires GL_EXT_texture_sRGB_decode extension");
1000 if ( (glu::getInternalFormat(m_internalFormat) == GL_SR8_EXT) && !(m_context.getContextInfo().isExtensionSupported("GL_EXT_texture_sRGB_R8")) )
1002 throw tcu::NotSupportedError("Test requires GL_EXT_texture_sRGB_R8 extension");
1005 m_framebuffer = de::MovePtr<glu::Framebuffer>(new glu::Framebuffer(m_context.getRenderContext()));
1008 void SRGBTestCase::deinit (void)
1010 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1012 m_framebuffer = de::MovePtr<glu::Framebuffer>(DE_NULL);
1014 for (std::size_t renderBufferIdx = 0; renderBufferIdx < m_renderBufferList.size(); renderBufferIdx++)
1016 gl.deleteRenderbuffers(1, &m_renderBufferList[renderBufferIdx]);
1018 m_renderBufferList.clear();
1020 for (std::size_t textureSourceIdx = 0; textureSourceIdx < m_textureSourceList.size(); textureSourceIdx++)
1022 delete m_textureSourceList[textureSourceIdx];
1024 m_textureSourceList.clear();
1026 for (std::size_t samplerIdx = 0; samplerIdx < m_samplerList.size(); samplerIdx++)
1028 delete m_samplerList[samplerIdx];
1030 m_samplerList.clear();
1034 gl.deleteVertexArrays(1, &m_vaoID);
1038 if (m_vertexDataID != 0)
1040 gl.deleteBuffers(1, &m_vertexDataID);
1045 SRGBTestCase::IterateResult SRGBTestCase::iterate (void)
1053 if (m_samplingGroup == SHADERSAMPLINGGROUP_TEXTURE)
1055 startIdx = static_cast<int>(TEXTURESAMPLING_TEXTURE_START);
1056 endIdx = static_cast<int>(TEXTURESAMPLING_TEXTURE_END);
1058 else if (m_samplingGroup == SHADERSAMPLINGGROUP_TEXEL_FETCH)
1060 startIdx = static_cast<int>(TEXTURESAMPLING_TEXELFETCH_START);
1061 endIdx = static_cast<int>(TEXTURESAMPLING_TEXELFETCH_END);
1065 DE_FATAL("Error: Sampling group not defined");
1068 this->initVertexData();
1069 this->initFrameBuffer();
1071 // loop through all sampling types in the required sampling group, performing individual tests for each
1072 for (int samplingTypeIdx = startIdx; samplingTypeIdx < endIdx; samplingTypeIdx++)
1074 this->genShaderPrograms(static_cast<ShaderSamplingType>(samplingTypeIdx));
1075 this->uploadTextures();
1078 result = this->verifyResult();
1080 this->deleteShaderPrograms();
1084 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1088 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Result verification failed");
1096 void SRGBTestCase::setSamplingGroup (const ShaderSamplingGroup samplingGroup)
1098 m_samplingGroup = samplingGroup;
1101 void SRGBTestCase::setSamplingLocations (const int px, const int py)
1107 void SRGBTestCase::setShaderProgramBlendRequired (const int programIdx, const bool blend)
1109 m_shaderProgramList[programIdx]->setBlendRequired(blend);
1112 void SRGBTestCase::setShaderProgramToggleRequired (const int programIdx, const bool toggle)
1114 m_shaderProgramList[programIdx]->setToggleRequired(toggle);
1117 void SRGBTestCase::setUniformToggle (const int programIdx, const std::string& uniformName, bool toggleDecodeValue)
1119 int uniformLocation = m_shaderProgramList[programIdx]->getUniformLocation(uniformName);
1120 m_shaderProgramList[programIdx]->setUniformToggle(uniformLocation, toggleDecodeValue);
1123 deUint32 SRGBTestCase::getShaderProgramHandle (const int programIdx) const
1125 return m_shaderProgramList[programIdx]->getHandle();
1128 deUint32 SRGBTestCase::getTextureHandle (const int textureIdx) const
1130 return m_textureSourceList[textureIdx]->getHandle();
1133 void SRGBTestCase::addTexture ( const glu::TextureTestUtil::TextureType targetType,
1136 const tcu::Vec4 color,
1137 const tcu::Sampler::WrapMode wrapS,
1138 const tcu::Sampler::WrapMode wrapT,
1139 const tcu::Sampler::FilterMode minFilter,
1140 const tcu::Sampler::FilterMode magFilter,
1141 const SRGBDecode decoding)
1143 SRGBTestTexture* texture = new SRGBTestTexture(m_context, targetType, m_internalFormat, width, height, color, wrapS, wrapT, minFilter, magFilter, decoding);
1144 m_textureSourceList.push_back(texture);
1147 void SRGBTestCase::addSampler ( const tcu::Sampler::WrapMode wrapS,
1148 const tcu::Sampler::WrapMode wrapT,
1149 const tcu::Sampler::FilterMode minFilter,
1150 const tcu::Sampler::FilterMode magFilter,
1151 const SRGBDecode decoding)
1153 SRGBTestSampler *sampler = new SRGBTestSampler(m_context, wrapS, wrapT, minFilter, magFilter, decoding);
1154 m_samplerList.push_back(sampler);
1157 void SRGBTestCase::addShaderProgram (const FragmentShaderParameters& shaderParameters)
1159 m_shaderParametersList.push_back(shaderParameters);
1160 m_resultOutputTotal = shaderParameters.outputTotal;
1163 void SRGBTestCase::genShaderPrograms (ShaderSamplingType samplingType)
1165 for (int shaderParamsIdx = 0; shaderParamsIdx < (int)m_shaderParametersList.size(); shaderParamsIdx++)
1167 m_shaderParametersList[shaderParamsIdx].samplingType = samplingType;
1168 SRGBTestProgram* shaderProgram = new SRGBTestProgram(m_context, m_shaderParametersList[shaderParamsIdx]);
1170 if (m_shaderParametersList[shaderParamsIdx].blendRequired == BLENDING_REQUIRED)
1172 shaderProgram->setBlendRequired(true);
1175 if (m_shaderParametersList[shaderParamsIdx].toggleRequired == TOGGLING_REQUIRED)
1177 shaderProgram->setToggleRequired(true);
1178 std::vector<std::string> uniformsToToggle = m_shaderParametersList[shaderParamsIdx].uniformsToToggle;
1180 for (int uniformNameIdx = 0; uniformNameIdx < (int)uniformsToToggle.size(); uniformNameIdx++)
1182 shaderProgram->setUniformToggle(shaderProgram->getUniformLocation(uniformsToToggle[uniformNameIdx]), true);
1186 m_shaderProgramList.push_back(shaderProgram);
1190 void SRGBTestCase::deleteShaderPrograms (void)
1192 for (std::size_t idx = 0; idx < m_shaderProgramList.size(); idx++)
1194 delete m_shaderProgramList[idx];
1196 m_shaderProgramList.clear();
1199 void SRGBTestCase::readResultTextures (void)
1201 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1202 int width = m_context.getRenderContext().getRenderTarget().getWidth();
1203 int height = m_context.getRenderContext().getRenderTarget().getHeight();
1205 gl.bindFramebuffer(GL_FRAMEBUFFER, **m_framebuffer);
1207 m_textureResultList.resize(m_renderBufferList.size());
1209 for (std::size_t renderBufferIdx = 0; renderBufferIdx < m_renderBufferList.size(); renderBufferIdx++)
1211 gl.readBuffer(GL_COLOR_ATTACHMENT0 + (glw::GLenum)renderBufferIdx);
1212 m_textureResultList[renderBufferIdx].setStorage(m_resultTextureFormat, width, height);
1213 glu::readPixels(m_context.getRenderContext(), 0, 0, m_textureResultList[renderBufferIdx].getAccess());
1214 GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels()");
1217 gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
1220 void SRGBTestCase::storeResultPixels (std::vector<tcu::Vec4>& resultPixelData)
1222 tcu::TestLog& log = m_context.getTestContext().getLog();
1223 std::ostringstream message;
1224 int width = m_context.getRenderContext().getRenderTarget().getWidth();
1225 int height = m_context.getRenderContext().getRenderTarget().getHeight();
1227 // ensure result sampling coordinates are within range of the result color attachment
1228 DE_ASSERT((m_px >= 0) && (m_px < width));
1229 DE_ASSERT((m_py >= 0) && (m_py < height));
1230 DE_UNREF(width && height);
1232 for (int idx = 0; idx < (int)m_textureResultList.size(); idx++)
1234 resultPixelData.push_back(m_textureResultList[idx].getAccess().getPixel(m_px, m_py));
1235 this->logColor(std::string("Result color: "), idx, resultPixelData[idx]);
1238 // log error rate (threshold)
1239 message << m_epsilonError;
1240 log << tcu::TestLog::Message << std::string("Epsilon error: ") << message.str() << tcu::TestLog::EndMessage;
1243 void SRGBTestCase::toggleDecode (const std::vector<UniformData>& uniformDataList)
1245 DE_ASSERT( uniformDataList.size() <= m_textureSourceList.size() );
1247 for (int uniformIdx = 0; uniformIdx < (int)uniformDataList.size(); uniformIdx++)
1249 if (uniformDataList[uniformIdx].toggleDecode == true)
1251 if (m_textureSourceList[uniformIdx]->getDecode() == SRGBDECODE_DECODE_DEFAULT)
1253 // cannot toggle default
1257 // toggle sRGB decode values (ignoring value if set to default)
1258 m_textureSourceList[uniformIdx]->setDecode((SRGBDecode)((m_textureSourceList[uniformIdx]->getDecode() + 1) % SRGBDECODE_DECODE_DEFAULT));
1263 void SRGBTestCase::bindSamplerToTexture (const int samplerIdx, const int textureIdx, const deUint32 textureUnit)
1265 deUint32 enumConversion = textureUnit - GL_TEXTURE0;
1266 m_textureSourceList[textureIdx]->setHasSampler(true);
1267 m_samplerList[samplerIdx]->setTextureUnit(enumConversion);
1270 void SRGBTestCase::activateSampler (const int samplerIdx, const bool active)
1272 m_samplerList[samplerIdx]->setIsActive(active);
1275 void SRGBTestCase::logColor (const std::string& colorLogMessage, int colorIdx, tcu::Vec4 color) const
1277 tcu::TestLog& log = m_context.getTestContext().getLog();
1278 std::ostringstream message;
1280 message << colorLogMessage << colorIdx << " = (" << color.x() << ", " << color.y() << ", " << color.z() << ", " << color.w() << ")";
1281 log << tcu::TestLog::Message << message.str() << tcu::TestLog::EndMessage;
1284 tcu::Vec4 SRGBTestCase::formatReferenceColor (tcu::Vec4 referenceColor)
1286 switch (glu::getInternalFormat(m_internalFormat))
1288 case GL_SRGB8_ALPHA8:
1290 return referenceColor;
1294 // zero unwanted color channels
1295 referenceColor.y() = 0;
1296 referenceColor.z() = 0;
1297 return referenceColor;
1301 DE_FATAL("Error: Internal format not recognised");
1302 return referenceColor;
1307 void SRGBTestCase::render (void)
1309 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1311 // default rendering only uses one program
1312 gl.bindFramebuffer(GL_FRAMEBUFFER, **m_framebuffer);
1313 gl.bindVertexArray(m_vaoID);
1315 gl.useProgram(m_shaderProgramList[0]->getHandle());
1317 for (int textureSourceIdx = 0; textureSourceIdx < (int)m_textureSourceList.size(); textureSourceIdx++)
1319 gl.activeTexture(GL_TEXTURE0 + (glw::GLenum)textureSourceIdx);
1320 gl.bindTexture(m_textureSourceList[textureSourceIdx]->getGLTargetType(), m_textureSourceList[textureSourceIdx]->getHandle());
1321 glw::GLuint samplerUniformLocationID = gl.getUniformLocation(m_shaderProgramList[0]->getHandle(), m_shaderProgramList[0]->getUniformAtLocation(textureSourceIdx).name.c_str());
1322 TCU_CHECK(samplerUniformLocationID != (glw::GLuint)-1);
1323 gl.uniform1i(samplerUniformLocationID, (glw::GLenum)textureSourceIdx);
1326 for (int samplerIdx = 0; samplerIdx < (int)m_samplerList.size(); samplerIdx++)
1328 if (m_samplerList[samplerIdx]->getIsActive() == true)
1330 m_samplerList[samplerIdx]->bindToTexture();
1334 gl.drawArrays(GL_TRIANGLES, 0, 6);
1336 for (std::size_t textureSourceIdx = 0; textureSourceIdx < m_textureSourceList.size(); textureSourceIdx++)
1338 gl.bindTexture(m_textureSourceList[textureSourceIdx]->getGLTargetType(), 0);
1340 gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
1341 gl.bindVertexArray(0);
1342 gl.bindBuffer(GL_ARRAY_BUFFER, 0);
1345 void SRGBTestCase::uploadTextures (void)
1347 for (std::size_t idx = 0; idx < m_textureSourceList.size(); idx++)
1349 m_textureSourceList[idx]->upload();
1350 m_textureSourceList[idx]->setParameters();
1354 void SRGBTestCase::initFrameBuffer (void)
1356 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1357 int width = m_context.getRenderContext().getRenderTarget().getWidth();
1358 int height = m_context.getRenderContext().getRenderTarget().getHeight();
1360 if (m_resultOutputTotal == 0)
1362 throw std::invalid_argument("SRGBTestExecutor must have at least 1 rendered result");
1365 gl.bindFramebuffer(GL_FRAMEBUFFER, **m_framebuffer);
1367 DE_ASSERT(m_renderBufferList.empty());
1368 for (int outputIdx = 0; outputIdx < m_resultOutputTotal; outputIdx++)
1370 glw::GLuint renderBuffer = -1;
1371 m_renderBufferList.push_back(renderBuffer);
1374 for (std::size_t renderBufferIdx = 0; renderBufferIdx < m_renderBufferList.size(); renderBufferIdx++)
1376 gl.genRenderbuffers(1, &m_renderBufferList[renderBufferIdx]);
1377 gl.bindRenderbuffer(GL_RENDERBUFFER, m_renderBufferList[renderBufferIdx]);
1378 gl.renderbufferStorage(GL_RENDERBUFFER, glu::getInternalFormat(m_resultTextureFormat), width, height);
1379 gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + (glw::GLenum)renderBufferIdx, GL_RENDERBUFFER, m_renderBufferList[renderBufferIdx]);
1380 GLU_EXPECT_NO_ERROR(gl.getError(), "Create and setup renderbuffer object");
1382 TCU_CHECK(gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
1384 std::vector<glw::GLenum> renderBufferTargets(m_renderBufferList.size());
1385 for (std::size_t renderBufferIdx = 0; renderBufferIdx < m_renderBufferList.size(); renderBufferIdx++)
1387 renderBufferTargets[renderBufferIdx] = GL_COLOR_ATTACHMENT0 + (glw::GLenum)renderBufferIdx;
1389 gl.drawBuffers((glw::GLsizei)renderBufferTargets.size(), &renderBufferTargets[0]);
1390 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawBuffer()");
1392 gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
1395 void SRGBTestCase::initVertexData (void)
1397 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1399 static const glw::GLfloat squareVertexData[] =
1401 // position // texcoord
1402 -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, // bottom left corner
1403 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, // bottom right corner
1404 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, // Top right corner
1406 -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, // top left corner
1407 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, // Top right corner
1408 -1.0f, -1.0f, 0.0f, 0.0f, 0.0f // bottom left corner
1411 DE_ASSERT(m_vaoID == 0);
1412 gl.genVertexArrays(1, &m_vaoID);
1413 gl.bindVertexArray(m_vaoID);
1415 gl.genBuffers(1, &m_vertexDataID);
1416 gl.bindBuffer(GL_ARRAY_BUFFER, m_vertexDataID);
1417 gl.bufferData(GL_ARRAY_BUFFER, (glw::GLsizei)sizeof(squareVertexData), squareVertexData, GL_STATIC_DRAW);
1419 gl.vertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * (glw::GLsizei)sizeof(GL_FLOAT), (glw::GLvoid *)0);
1420 gl.enableVertexAttribArray(0);
1421 gl.vertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * (glw::GLsizei)sizeof(GL_FLOAT), (glw::GLvoid *)(3 * sizeof(GL_FLOAT)));
1422 gl.enableVertexAttribArray(1);
1424 gl.bindVertexArray(0);
1425 gl.bindBuffer(GL_ARRAY_BUFFER, 0);
1428 class TextureDecodeSkippedCase : public SRGBTestCase
1431 TextureDecodeSkippedCase (Context& context, const char* name, const char* description, const tcu::TextureFormat internalFormat)
1432 : SRGBTestCase (context, name, description, internalFormat) {}
1434 ~TextureDecodeSkippedCase (void) {}
1436 void setupTest (void);
1437 bool verifyResult (void);
1440 void TextureDecodeSkippedCase::setupTest (void)
1443 // - create and set texture to DECODE_SKIP_EXT
1444 // - store texture on GPU
1445 // - in fragment shader, sample the texture using texture*() and render texel values to a color attachment in the FBO
1446 // - on the host, read back the pixel values into a tcu::TextureLevel
1447 // - analyse the texel values, expecting them in sRGB format i.e. linear space decoding was skipped
1449 FragmentShaderParameters shaderParameters(SHADEROUTPUTS_ONE, SHADERUNIFORMS_ONE, NULL, BLENDING_NOT_REQUIRED, TOGGLING_NOT_REQUIRED);
1451 this->addTexture( TEXTURETYPE_2D,
1452 TestDimensions::WIDTH,
1453 TestDimensions::HEIGHT,
1454 getColorReferenceLinear(),
1455 tcu::Sampler::MIRRORED_REPEAT_GL,
1456 tcu::Sampler::MIRRORED_REPEAT_GL,
1457 tcu::Sampler::LINEAR,
1458 tcu::Sampler::LINEAR,
1459 SRGBDECODE_SKIP_DECODE);
1461 this->addShaderProgram(shaderParameters);
1462 this->setSamplingLocations(TestSamplingPositions::X_POS, TestSamplingPositions::Y_POS);
1464 this->setSamplingGroup(SHADERSAMPLINGGROUP_TEXTURE);
1467 bool TextureDecodeSkippedCase::verifyResult (void)
1469 tcu::TestLog& log = m_context.getTestContext().getLog();
1470 const int resultColorIdx = 0;
1471 std::vector<tcu::Vec4> pixelResultList;
1472 tcu::Vec4 pixelConverted;
1473 tcu::Vec4 pixelReference;
1474 tcu::Vec4 pixelExpected;
1476 this->readResultTextures();
1477 this->storeResultPixels(pixelResultList);
1479 pixelConverted = tcu::sRGBToLinear(pixelResultList[resultColorIdx]);
1480 pixelReference = this->formatReferenceColor(getColorReferenceLinear());
1481 pixelExpected = this->formatReferenceColor(getColorReferenceSRGB());
1483 this->formatReferenceColor(pixelReference);
1484 this->logColor(std::string("Expected color: "), resultColorIdx, pixelExpected);
1486 // result color 0 should be sRGB. Compare with linear reference color
1487 if ( (tcu::boolAll(tcu::lessThan(tcu::abs(pixelConverted - pixelReference), m_epsilonError))) || (tcu::boolAll(tcu::equal(pixelConverted, pixelReference))) )
1489 log << tcu::TestLog::Message << std::string("sRGB as expected") << tcu::TestLog::EndMessage;
1494 log << tcu::TestLog::Message << std::string("not sRGB as expected") << tcu::TestLog::EndMessage;
1499 class TextureDecodeEnabledCase : public SRGBTestCase
1502 TextureDecodeEnabledCase (Context& context, const char* name, const char* description, const tcu::TextureFormat internalFormat)
1503 : SRGBTestCase (context, name, description, internalFormat) {}
1505 ~TextureDecodeEnabledCase (void) {}
1507 void setupTest (void);
1508 bool verifyResult (void);
1511 void TextureDecodeEnabledCase::setupTest (void)
1514 // - create and set texture to DECODE_EXT
1515 // - store texture on GPU
1516 // - in fragment shader, sample the texture using texture*() and render texel values to a color attachment in the FBO
1517 // - on the host, read back the pixel values into a tcu::TextureLevel
1518 // - analyse the texel values, expecting them in lRGB format i.e. linear space decoding was enabled
1520 FragmentShaderParameters shaderParameters(SHADEROUTPUTS_ONE, SHADERUNIFORMS_ONE, NULL, BLENDING_NOT_REQUIRED, TOGGLING_NOT_REQUIRED);
1522 this->addTexture( TEXTURETYPE_2D,
1523 TestDimensions::WIDTH,
1524 TestDimensions::HEIGHT,
1525 getColorReferenceLinear(),
1526 tcu::Sampler::MIRRORED_REPEAT_GL,
1527 tcu::Sampler::MIRRORED_REPEAT_GL,
1528 tcu::Sampler::LINEAR,
1529 tcu::Sampler::LINEAR,
1532 this->addShaderProgram(shaderParameters);
1534 this->setSamplingLocations(TestSamplingPositions::X_POS, TestSamplingPositions::Y_POS);
1536 this->setSamplingGroup(SHADERSAMPLINGGROUP_TEXTURE);
1539 bool TextureDecodeEnabledCase::verifyResult (void)
1541 tcu::TestLog& log = m_context.getTestContext().getLog();
1542 const int resultColorIdx = 0;
1543 std::vector<tcu::Vec4> pixelResultList;
1544 tcu::Vec4 pixelConverted;
1545 tcu::Vec4 pixelReference;
1546 tcu::Vec4 pixelExpected;
1548 this->readResultTextures();
1549 this->storeResultPixels(pixelResultList);
1551 pixelConverted = tcu::linearToSRGB(pixelResultList[resultColorIdx]);
1552 pixelReference = this->formatReferenceColor(getColorReferenceSRGB());
1553 pixelExpected = this->formatReferenceColor(getColorReferenceLinear());
1555 this->logColor(std::string("Expected color: "), resultColorIdx, pixelExpected);
1557 // result color 0 should be SRGB. Compare with sRGB reference color
1558 if ( (tcu::boolAll(tcu::lessThan(tcu::abs(pixelConverted - pixelReference), m_epsilonError))) || (tcu::boolAll(tcu::equal(pixelConverted, pixelReference))) )
1560 log << tcu::TestLog::Message << std::string("linear as expected") << tcu::TestLog::EndMessage;
1565 log << tcu::TestLog::Message << std::string("not linear as expected") << tcu::TestLog::EndMessage;
1570 class TexelFetchDecodeSkippedcase : public SRGBTestCase
1573 TexelFetchDecodeSkippedcase (Context& context, const char* name, const char* description, const tcu::TextureFormat internalFormat)
1574 : SRGBTestCase (context, name, description, internalFormat) {}
1576 ~TexelFetchDecodeSkippedcase (void) {}
1578 void setupTest (void);
1579 bool verifyResult (void);
1582 void TexelFetchDecodeSkippedcase::setupTest (void)
1585 // - create and set texture to DECODE_SKIP_EXT
1586 // - store texture on GPU
1587 // - in fragment shader, sample the texture using texelFetch*() and render texel values to a color attachment in the FBO
1588 // - on the host, read back the pixel values into a tcu::TextureLevel
1589 // - analyse the texel values, expecting them in lRGB format i.e. linear space decoding is always enabled with texelFetch*()
1591 FragmentShaderParameters shaderParameters(SHADEROUTPUTS_ONE, SHADERUNIFORMS_ONE, NULL, BLENDING_NOT_REQUIRED, TOGGLING_NOT_REQUIRED);
1593 this->addTexture( TEXTURETYPE_2D,
1594 TestDimensions::WIDTH,
1595 TestDimensions::HEIGHT,
1596 getColorReferenceLinear(),
1597 tcu::Sampler::MIRRORED_REPEAT_GL,
1598 tcu::Sampler::MIRRORED_REPEAT_GL,
1599 tcu::Sampler::LINEAR,
1600 tcu::Sampler::LINEAR,
1601 SRGBDECODE_SKIP_DECODE);
1603 this->addShaderProgram(shaderParameters);
1605 this->setSamplingLocations(TestSamplingPositions::X_POS, TestSamplingPositions::Y_POS);
1607 this->setSamplingGroup(SHADERSAMPLINGGROUP_TEXEL_FETCH);
1610 bool TexelFetchDecodeSkippedcase::verifyResult (void)
1612 tcu::TestLog& log = m_context.getTestContext().getLog();
1613 const int resultColorIdx = 0;
1614 std::vector<tcu::Vec4> pixelResultList;
1615 tcu::Vec4 pixelReference;
1616 tcu::Vec4 pixelExpected;
1618 this->readResultTextures();
1619 this->storeResultPixels(pixelResultList);
1621 pixelReference = pixelExpected = this->formatReferenceColor(getColorReferenceLinear());
1623 this->logColor(std::string("Expected color: "), resultColorIdx, pixelExpected);
1625 // result color 0 should be linear due to automatic conversion via texelFetch*(). Compare with linear reference color
1626 if ( (tcu::boolAll(tcu::lessThan(tcu::abs(pixelResultList[0] - pixelReference), m_epsilonError))) || (tcu::boolAll(tcu::equal(pixelResultList[0], pixelReference))) )
1628 log << tcu::TestLog::Message << std::string("linear as expected") << tcu::TestLog::EndMessage;
1633 log << tcu::TestLog::Message << std::string("not linear as expected") << tcu::TestLog::EndMessage;
1638 class GPUConversionDecodeEnabledCase : public SRGBTestCase
1641 GPUConversionDecodeEnabledCase (Context& context, const char* name, const char* description, const tcu::TextureFormat internalFormat)
1642 : SRGBTestCase (context, name, description, internalFormat) {}
1644 ~GPUConversionDecodeEnabledCase (void) {}
1646 void setupTest (void);
1647 bool verifyResult (void);
1650 void GPUConversionDecodeEnabledCase::setupTest (void)
1653 // - create and set texture_a to DECODE_SKIP_EXT and texture_b to default
1654 // - store textures on GPU
1655 // - in fragment shader, sample both textures using texture*() and manually perform sRGB to lRGB conversion on texture_b
1656 // - in fragment shader, compare converted texture_b with texture_a
1657 // - render green image for pass or red for fail
1659 ComparisonFunction comparisonFunction("srgbToLinearCheck", FUNCTIONPARAMETERS_TWO, getFunctionDefinitionSRGBToLinearCheck());
1661 FragmentShaderParameters shaderParameters(SHADEROUTPUTS_ONE, SHADERUNIFORMS_TWO, &comparisonFunction, BLENDING_NOT_REQUIRED, TOGGLING_NOT_REQUIRED);
1663 this->addTexture( TEXTURETYPE_2D,
1664 TestDimensions::WIDTH,
1665 TestDimensions::HEIGHT,
1666 getColorReferenceLinear(),
1667 tcu::Sampler::MIRRORED_REPEAT_GL,
1668 tcu::Sampler::MIRRORED_REPEAT_GL,
1669 tcu::Sampler::LINEAR,
1670 tcu::Sampler::LINEAR,
1671 SRGBDECODE_SKIP_DECODE);
1673 this->addTexture( TEXTURETYPE_2D,
1674 TestDimensions::WIDTH,
1675 TestDimensions::HEIGHT,
1676 getColorReferenceLinear(),
1677 tcu::Sampler::MIRRORED_REPEAT_GL,
1678 tcu::Sampler::MIRRORED_REPEAT_GL,
1679 tcu::Sampler::LINEAR,
1680 tcu::Sampler::LINEAR,
1681 SRGBDECODE_DECODE_DEFAULT);
1683 this->addShaderProgram(shaderParameters);
1685 this->setSamplingLocations(TestSamplingPositions::X_POS, TestSamplingPositions::Y_POS);
1687 this->setSamplingGroup(SHADERSAMPLINGGROUP_TEXTURE);
1690 bool GPUConversionDecodeEnabledCase::verifyResult (void)
1692 tcu::TestLog& log = m_context.getTestContext().getLog();
1693 const int resultColorIdx = 0;
1694 std::vector<tcu::Vec4> pixelResultList;
1696 this->readResultTextures();
1697 this->storeResultPixels(pixelResultList);
1698 this->logColor(std::string("Expected color: "), resultColorIdx, getColorGreenPass());
1700 // result color returned from GPU is either green (pass) or fail (red)
1701 if ( tcu::boolAll(tcu::equal(pixelResultList[resultColorIdx], getColorGreenPass())) )
1703 log << tcu::TestLog::Message << std::string("returned pass color from GPU") << tcu::TestLog::EndMessage;
1708 log << tcu::TestLog::Message << std::string("returned fail color from GPU") << tcu::TestLog::EndMessage;
1713 class DecodeToggledCase : public SRGBTestCase
1716 DecodeToggledCase (Context& context, const char* name, const char* description, const tcu::TextureFormat internalFormat)
1717 : SRGBTestCase (context, name, description, internalFormat) {}
1719 ~DecodeToggledCase (void) {}
1722 void setupTest (void);
1723 bool verifyResult (void);
1726 void DecodeToggledCase::render (void)
1728 // override the base SRGBTestCase render function with the purpose of switching between shader programs,
1729 // toggling texture sRGB decode state between draw calls
1730 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1732 gl.bindFramebuffer(GL_FRAMEBUFFER, **m_framebuffer);
1733 gl.bindVertexArray(m_vaoID);
1735 for (std::size_t programIdx = 0; programIdx < m_shaderProgramList.size(); programIdx++)
1737 gl.useProgram(m_shaderProgramList[programIdx]->getHandle());
1739 this->toggleDecode(m_shaderProgramList[programIdx]->getUniformDataList());
1741 for (int textureSourceIdx = 0; textureSourceIdx < (int)m_textureSourceList.size(); textureSourceIdx++)
1743 gl.activeTexture(GL_TEXTURE0 + (glw::GLenum)textureSourceIdx);
1744 gl.bindTexture(m_textureSourceList[textureSourceIdx]->getGLTargetType(), m_textureSourceList[textureSourceIdx]->getHandle());
1745 glw::GLuint samplerUniformLocationID = gl.getUniformLocation(m_shaderProgramList[programIdx]->getHandle(), m_shaderProgramList[programIdx]->getUniformAtLocation(textureSourceIdx).name.c_str());
1746 TCU_CHECK(samplerUniformLocationID != (glw::GLuint) - 1);
1747 gl.uniform1i(samplerUniformLocationID, (glw::GLenum)textureSourceIdx);
1750 for (int samplerIdx = 0; samplerIdx < (int)m_samplerList.size(); samplerIdx++)
1752 if (m_samplerList[samplerIdx]->getIsActive() == true)
1754 m_samplerList[samplerIdx]->bindToTexture();
1758 if (m_shaderProgramList[programIdx]->getBlendRequired() == true)
1760 gl.enable(GL_BLEND);
1761 gl.blendEquation(GL_MAX);
1762 gl.blendFunc(GL_ONE, GL_ONE);
1766 gl.disable(GL_BLEND);
1769 gl.drawArrays(GL_TRIANGLES, 0, 6);
1771 // reset sRGB decode state on textures
1772 this->toggleDecode(m_shaderProgramList[programIdx]->getUniformDataList());
1775 for (std::size_t textureSourceIdx = 0; textureSourceIdx < m_textureSourceList.size(); textureSourceIdx++)
1777 gl.bindTexture(m_textureSourceList[textureSourceIdx]->getGLTargetType(), 0);
1779 gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
1780 gl.bindVertexArray(0);
1781 gl.bindBuffer(GL_ARRAY_BUFFER, 0);
1784 void DecodeToggledCase::setupTest (void)
1787 // - create and set texture_a to DECODE_SKIP_EXT and texture_b to DECODE_EXT
1788 // - create and use two seperate shader programs, program_a and program_b, each using different fragment shaders
1789 // - store texture_a and texture_b on GPU
1792 // - in fragment shader, sample both textures using texture*() and manually perform sRGB to lRGB conversion on texture_a
1793 // - in fragment shader, test converted texture_a value with texture_b
1794 // - render green image for pass or red for fail
1795 // - store result in a color attachement 0
1797 // - during rendering, toggle texture_a from DECODE_SKIP_EXT to DECODE_EXT
1800 // - in fragment shader, sample both textures using texture*() and manually perform equality check. Both should be linear
1801 // - blend first pass result with second pass. Anything but a green result equals fail
1803 ComparisonFunction srgbToLinearFunction("srgbToLinearCheck", FUNCTIONPARAMETERS_TWO, getFunctionDefinitionSRGBToLinearCheck());
1804 ComparisonFunction colorsEqualFunction("colorsEqualCheck", FUNCTIONPARAMETERS_TWO, getFunctionDefinitionEqualCheck());
1806 FragmentShaderParameters shaderParametersA(SHADEROUTPUTS_ONE, SHADERUNIFORMS_TWO, &srgbToLinearFunction, BLENDING_NOT_REQUIRED, TOGGLING_NOT_REQUIRED);
1807 FragmentShaderParameters shaderParametersB(SHADEROUTPUTS_ONE, SHADERUNIFORMS_TWO, &colorsEqualFunction, BLENDING_REQUIRED, TOGGLING_REQUIRED);
1809 // need to specify which texture uniform to toggle DECODE_EXT/SKIP_DECODE_EXT
1810 shaderParametersB.uniformsToToggle.push_back("uTexture0");
1812 this->addTexture( TEXTURETYPE_2D,
1813 TestDimensions::WIDTH,
1814 TestDimensions::HEIGHT,
1815 getColorReferenceLinear(),
1816 tcu::Sampler::MIRRORED_REPEAT_GL,
1817 tcu::Sampler::MIRRORED_REPEAT_GL,
1818 tcu::Sampler::LINEAR,
1819 tcu::Sampler::LINEAR,
1820 SRGBDECODE_SKIP_DECODE);
1822 this->addTexture( TEXTURETYPE_2D,
1823 TestDimensions::WIDTH,
1824 TestDimensions::HEIGHT,
1825 getColorReferenceLinear(),
1826 tcu::Sampler::MIRRORED_REPEAT_GL,
1827 tcu::Sampler::MIRRORED_REPEAT_GL,
1828 tcu::Sampler::LINEAR,
1829 tcu::Sampler::LINEAR,
1832 this->addShaderProgram(shaderParametersA);
1833 this->addShaderProgram(shaderParametersB);
1835 this->setSamplingLocations(TestSamplingPositions::X_POS, TestSamplingPositions::Y_POS);
1836 this->setSamplingGroup(SHADERSAMPLINGGROUP_TEXTURE);
1839 bool DecodeToggledCase::verifyResult (void)
1841 tcu::TestLog& log = m_context.getTestContext().getLog();
1842 const int resultColorIdx = 0;
1843 std::vector<tcu::Vec4> pixelResultList;
1845 this->readResultTextures();
1846 this->storeResultPixels(pixelResultList);
1847 this->logColor(std::string("Expected color: "), resultColorIdx, getColorGreenPass());
1849 // result color is either green (pass) or fail (red)
1850 if ( tcu::boolAll(tcu::equal(pixelResultList[resultColorIdx], getColorGreenPass())) )
1852 log << tcu::TestLog::Message << std::string("returned pass color from GPU") << tcu::TestLog::EndMessage;
1857 log << tcu::TestLog::Message << std::string("returned fail color from GPU") << tcu::TestLog::EndMessage;
1862 class DecodeMultipleTexturesCase : public SRGBTestCase
1865 DecodeMultipleTexturesCase (Context& context, const char* name, const char* description, const tcu::TextureFormat internalFormat)
1866 : SRGBTestCase (context, name, description, internalFormat) {}
1868 ~DecodeMultipleTexturesCase (void) {}
1870 void setupTest (void);
1871 bool verifyResult (void);
1874 void DecodeMultipleTexturesCase::setupTest (void)
1877 // - create and set texture_a to DECODE_SKIP_EXT and texture_b to DECODE_EXT
1878 // - upload textures to the GPU and bind to seperate uniform variables
1879 // - sample both textures using texture*()
1880 // - read texel values back to the CPU
1881 // - compare the texel values, both should be different from each other
1883 FragmentShaderParameters shaderParameters(SHADEROUTPUTS_TWO, SHADERUNIFORMS_TWO, NULL, BLENDING_NOT_REQUIRED, TOGGLING_NOT_REQUIRED);
1885 this->addTexture( TEXTURETYPE_2D,
1886 TestDimensions::WIDTH,
1887 TestDimensions::HEIGHT,
1888 getColorReferenceLinear(),
1889 tcu::Sampler::MIRRORED_REPEAT_GL,
1890 tcu::Sampler::MIRRORED_REPEAT_GL,
1891 tcu::Sampler::LINEAR,
1892 tcu::Sampler::LINEAR,
1893 SRGBDECODE_SKIP_DECODE);
1895 this->addTexture( TEXTURETYPE_2D,
1896 TestDimensions::WIDTH,
1897 TestDimensions::HEIGHT,
1898 getColorReferenceLinear(),
1899 tcu::Sampler::MIRRORED_REPEAT_GL,
1900 tcu::Sampler::MIRRORED_REPEAT_GL,
1901 tcu::Sampler::LINEAR,
1902 tcu::Sampler::LINEAR,
1905 this->addShaderProgram(shaderParameters);
1907 this->setSamplingLocations(TestSamplingPositions::X_POS, TestSamplingPositions::Y_POS);
1908 this->setSamplingGroup(SHADERSAMPLINGGROUP_TEXTURE);
1911 bool DecodeMultipleTexturesCase::verifyResult (void)
1913 tcu::TestLog& log = m_context.getTestContext().getLog();
1914 const int resultColorIdx = 0;
1915 std::vector<tcu::Vec4> pixelResultList;
1916 tcu::Vec4 pixelExpected0;
1917 tcu::Vec4 pixelExpected1;
1919 this->readResultTextures();
1920 this->storeResultPixels(pixelResultList);
1922 pixelExpected0 = this->formatReferenceColor(getColorReferenceSRGB());
1923 pixelExpected1 = this->formatReferenceColor(getColorReferenceLinear());
1925 this->logColor(std::string("Expected color: "), resultColorIdx, pixelExpected0);
1926 this->logColor(std::string("Expected color: "), resultColorIdx +1, pixelExpected1);
1928 // check if the two textures have different values i.e. uTexture0 = sRGB and uTexture1 = linear
1929 if ( !(tcu::boolAll(tcu::equal(pixelResultList[resultColorIdx], pixelResultList[resultColorIdx +1]))) )
1931 log << tcu::TestLog::Message << std::string("texel values are different") << tcu::TestLog::EndMessage;
1936 log << tcu::TestLog::Message << std::string("texel values are equal") << tcu::TestLog::EndMessage;
1941 class DecodeSamplerCase : public SRGBTestCase
1944 DecodeSamplerCase (Context& context, const char* name, const char* description, const tcu::TextureFormat internalFormat)
1945 : SRGBTestCase (context, name, description, internalFormat) {}
1947 ~DecodeSamplerCase (void) {}
1949 void setupTest (void);
1950 bool verifyResult (void);
1953 void DecodeSamplerCase::setupTest (void)
1956 // - create and set texture_a to DECODE_SKIP_EXT
1957 // - upload texture to the GPU and bind to sampler
1958 // - sample texture using texture*()
1959 // - read texel values back to the CPU
1960 // - compare the texel values, should be in sampler format (linear)
1962 FragmentShaderParameters shaderParameters(SHADEROUTPUTS_ONE, SHADERUNIFORMS_ONE, NULL, BLENDING_NOT_REQUIRED, TOGGLING_NOT_REQUIRED);
1964 this->addTexture( TEXTURETYPE_2D,
1965 TestDimensions::WIDTH,
1966 TestDimensions::HEIGHT,
1967 getColorReferenceLinear(),
1968 tcu::Sampler::MIRRORED_REPEAT_GL,
1969 tcu::Sampler::MIRRORED_REPEAT_GL,
1970 tcu::Sampler::LINEAR,
1971 tcu::Sampler::LINEAR,
1972 SRGBDECODE_SKIP_DECODE);
1974 this->addSampler( tcu::Sampler::MIRRORED_REPEAT_GL,
1975 tcu::Sampler::MIRRORED_REPEAT_GL,
1976 tcu::Sampler::LINEAR,
1977 tcu::Sampler::LINEAR,
1980 this->addShaderProgram(shaderParameters);
1982 this->bindSamplerToTexture(0, 0, GL_TEXTURE0);
1983 this->activateSampler(0, true);
1985 this->setSamplingLocations(TestSamplingPositions::X_POS, TestSamplingPositions::Y_POS);
1986 this->setSamplingGroup(SHADERSAMPLINGGROUP_TEXTURE);
1989 bool DecodeSamplerCase::verifyResult (void)
1991 tcu::TestLog& log = m_context.getTestContext().getLog();
1992 const int resultColorIdx = 0;
1993 std::vector<tcu::Vec4> pixelResultList;
1994 tcu::Vec4 pixelConverted;
1995 tcu::Vec4 pixelReference;
1996 tcu::Vec4 pixelExpected;
1998 this->readResultTextures();
1999 this->storeResultPixels(pixelResultList);
2001 pixelConverted = tcu::linearToSRGB(pixelResultList[resultColorIdx]);
2002 pixelReference = this->formatReferenceColor(getColorReferenceSRGB());
2003 pixelExpected = this->formatReferenceColor(getColorReferenceLinear());
2005 this->logColor(std::string("Expected color: "), resultColorIdx, pixelExpected);
2007 // texture was rendered using a sampler object with setting DECODE_EXT, therefore, results should be linear
2008 if ( (tcu::boolAll(tcu::lessThan(tcu::abs(pixelConverted - pixelReference), m_epsilonError))) || (tcu::boolAll(tcu::equal(pixelConverted, pixelReference))) )
2010 log << tcu::TestLog::Message << std::string("linear as expected") << tcu::TestLog::EndMessage;
2015 log << tcu::TestLog::Message << std::string("not linear as expected") << tcu::TestLog::EndMessage;
2022 SRGBDecodeTests::SRGBDecodeTests (Context& context)
2023 : TestCaseGroup (context, "skip_decode", "sRGB skip decode tests")
2027 SRGBDecodeTests::~SRGBDecodeTests (void)
2031 void SRGBDecodeTests::init (void)
2033 const TestGroupConfig testGroupConfigList[] =
2035 TestGroupConfig("srgba8", "srgb decode tests using srgba internal format", tcu::TextureFormat(tcu::TextureFormat::sRGBA, tcu::TextureFormat::UNORM_INT8)),
2036 TestGroupConfig("sr8", "srgb decode tests using sr8 internal format", tcu::TextureFormat(tcu::TextureFormat::sR, tcu::TextureFormat::UNORM_INT8))
2039 // create groups for all desired internal formats, adding test cases to each
2040 for (std::size_t idx = 0; idx < DE_LENGTH_OF_ARRAY(testGroupConfigList); idx++)
2042 tcu::TestCaseGroup* const testGroup = new tcu::TestCaseGroup(m_testCtx, testGroupConfigList[idx].name, testGroupConfigList[idx].description);
2043 tcu::TestNode::addChild(testGroup);
2045 testGroup->addChild(new TextureDecodeSkippedCase (m_context, "skipped", "testing for sRGB color values with sRGB texture decoding skipped", testGroupConfigList[idx].internalFormat));
2046 testGroup->addChild(new TextureDecodeEnabledCase (m_context, "enabled", "testing for linear color values with sRGB texture decoding enabled", testGroupConfigList[idx].internalFormat));
2047 testGroup->addChild(new TexelFetchDecodeSkippedcase (m_context, "texel_fetch", "testing for linear color values with sRGB texture decoding skipped", testGroupConfigList[idx].internalFormat));
2048 testGroup->addChild(new GPUConversionDecodeEnabledCase (m_context, "conversion_gpu", "sampling linear values and performing conversion on the gpu", testGroupConfigList[idx].internalFormat));
2049 testGroup->addChild(new DecodeToggledCase (m_context, "toggled", "toggle the sRGB decoding between draw calls", testGroupConfigList[idx].internalFormat));
2050 testGroup->addChild(new DecodeMultipleTexturesCase (m_context, "multiple_textures","upload multiple textures with different sRGB decode values and sample",testGroupConfigList[idx].internalFormat));
2051 testGroup->addChild(new DecodeSamplerCase (m_context, "using_sampler", "testing that sampler object takes priority over texture state", testGroupConfigList[idx].internalFormat));