Fix division by zero errors
authorAri Suonpaa <ari.suonpaa@siru.fi>
Thu, 9 Dec 2021 08:24:18 +0000 (10:24 +0200)
committerMatthew Netsch <quic_mnetsch@quicinc.com>
Thu, 6 Jan 2022 22:46:29 +0000 (22:46 +0000)
Projection calculation had zero divisor in some cases that
didn't use the results. This division is now bypassed for
these cases to avoid UBSAN errors.

VK-GL-CTS Issue: 3352

Affects:

dEQP-GLES*.functional.shaders.texture_functions.*

Components: OpenGL ES
Change-Id: I64e5c53c668646dbdc915c2b3619700d83793009

modules/gles2/functional/es2fShaderTextureFunctionTests.cpp
modules/gles3/functional/es3fShaderTextureFunctionTests.cpp

index 7b51b72..eeea138 100644 (file)
@@ -323,8 +323,8 @@ void ShaderTextureFunctionCase::initTexture (void)
        tcu::TextureFormat              texFmt                  = glu::mapGLTransferFormat(m_textureSpec.format, m_textureSpec.dataType);
        tcu::TextureFormatInfo  fmtInfo                 = tcu::getTextureFormatInfo(texFmt);
        tcu::IVec2                              viewportSize    = getViewportSize();
-       bool                                    isProj                  = functionHasProj(m_lookupSpec.function);
-       float                                   proj                    = isProj ? 1.0f/m_lookupSpec.minCoord[m_lookupSpec.function == FUNCTION_TEXTUREPROJ3 ? 2 : 3] : 1.0f;
+       bool                                    useProj                 = functionHasProj(m_lookupSpec.function) && !functionHasLod(m_lookupSpec.function);
+       float                                   proj                    = useProj ? 1.0f / m_lookupSpec.minCoord[m_lookupSpec.function == FUNCTION_TEXTUREPROJ3 ? 2 : 3] : 1.0f;
 
        switch (m_textureSpec.type)
        {
index d00049c..7f8486a 100644 (file)
@@ -567,10 +567,10 @@ void ShaderTextureFunctionCase::initTexture (void)
        tcu::TextureFormat              texFmt                  = glu::mapGLInternalFormat(m_textureSpec.format);
        tcu::TextureFormatInfo  fmtInfo                 = tcu::getTextureFormatInfo(texFmt);
        tcu::IVec2                              viewportSize    = getViewportSize();
-       bool                                    isProj                  = functionHasProj(m_lookupSpec.function);
+       bool                                    useProj                 = functionHasProj(m_lookupSpec.function) && !functionHasGrad(m_lookupSpec.function) && !functionHasLod(m_lookupSpec.function);
        bool                                    isAutoLod               = functionHasAutoLod(m_isVertexCase ? glu::SHADERTYPE_VERTEX : glu::SHADERTYPE_FRAGMENT,
                                                                                                                                 m_lookupSpec.function); // LOD can vary significantly
-       float                                   proj                    = isProj ? 1.0f/m_lookupSpec.minCoord[m_lookupSpec.function == FUNCTION_TEXTUREPROJ3 ? 2 : 3] : 1.0f;
+       float                                   proj                    = useProj ? 1.0f / m_lookupSpec.minCoord[m_lookupSpec.function == FUNCTION_TEXTUREPROJ3 ? 2 : 3] : 1.0f;
 
        switch (m_textureSpec.type)
        {