Make sure readpixels work with 16bit fixed point surfaces
authorAri Suonpaa <ari.suonpaa@siru.fi>
Wed, 12 Feb 2020 11:28:47 +0000 (13:28 +0200)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Thu, 27 Feb 2020 11:18:16 +0000 (06:18 -0500)
Added FBO tests that use unsigned fixed point textures
as render target. Pixels are read from the FBO using
pixel type GL_UNSIGNED_SHORT since that was reported
to have problems on some implementations.

New tests:

dEQP-GLES31.functional.fbo.color.tex2d.r16
dEQP-GLES31.functional.fbo.color.tex2d.rg16
dEQP-GLES31.functional.fbo.color.tex2d.rgba16

Components: OpenGL ES

VK-GL-CTS issue: 2124

Change-Id: Icad477ae62ff6961f5989b097aa3ce73002b8dd8

android/cts/master/gles31-master.txt
external/openglcts/data/mustpass/gles/aosp_mustpass/3.2.5.x/gles31-master.txt
external/openglcts/data/mustpass/gles/aosp_mustpass/3.2.6.x/gles31-master.txt
external/openglcts/data/mustpass/gles/aosp_mustpass/master/gles31-master.txt
modules/gles31/functional/es31fFboColorbufferTests.cpp
modules/gles31/functional/es31fFboTestCase.cpp
modules/gles31/functional/es31fFboTestUtil.cpp

index f7a6300..414235b 100644 (file)
@@ -19907,6 +19907,9 @@ dEQP-GLES31.functional.fbo.color.texcubearray.rg16f
 dEQP-GLES31.functional.fbo.color.texcubearray.r32f
 dEQP-GLES31.functional.fbo.color.texcubearray.r16f
 dEQP-GLES31.functional.fbo.color.texcubearray.rgb16f
+dEQP-GLES31.functional.fbo.color.tex2d.r16
+dEQP-GLES31.functional.fbo.color.tex2d.rg16
+dEQP-GLES31.functional.fbo.color.tex2d.rgba16
 dEQP-GLES31.functional.fbo.no_attachments.size.16x16
 dEQP-GLES31.functional.fbo.no_attachments.size.16x64
 dEQP-GLES31.functional.fbo.no_attachments.size.16x256
index 889da6a..1c6b003 100644 (file)
@@ -19951,6 +19951,9 @@ dEQP-GLES31.functional.fbo.color.texcubearray.rg16f
 dEQP-GLES31.functional.fbo.color.texcubearray.r32f
 dEQP-GLES31.functional.fbo.color.texcubearray.r16f
 dEQP-GLES31.functional.fbo.color.texcubearray.rgb16f
+dEQP-GLES31.functional.fbo.color.tex2d.r16
+dEQP-GLES31.functional.fbo.color.tex2d.rg16
+dEQP-GLES31.functional.fbo.color.tex2d.rgba16
 dEQP-GLES31.functional.fbo.no_attachments.size.16x16
 dEQP-GLES31.functional.fbo.no_attachments.size.16x64
 dEQP-GLES31.functional.fbo.no_attachments.size.16x256
index ed1d2aa..8f6b995 100644 (file)
@@ -19955,6 +19955,9 @@ dEQP-GLES31.functional.fbo.color.texcubearray.rg16f
 dEQP-GLES31.functional.fbo.color.texcubearray.r32f
 dEQP-GLES31.functional.fbo.color.texcubearray.r16f
 dEQP-GLES31.functional.fbo.color.texcubearray.rgb16f
+dEQP-GLES31.functional.fbo.color.tex2d.r16
+dEQP-GLES31.functional.fbo.color.tex2d.rg16
+dEQP-GLES31.functional.fbo.color.tex2d.rgba16
 dEQP-GLES31.functional.fbo.no_attachments.size.16x16
 dEQP-GLES31.functional.fbo.no_attachments.size.16x64
 dEQP-GLES31.functional.fbo.no_attachments.size.16x256
index d0985a0..0695f2a 100644 (file)
@@ -19986,6 +19986,9 @@ dEQP-GLES31.functional.fbo.color.texcubearray.rg16f
 dEQP-GLES31.functional.fbo.color.texcubearray.r32f
 dEQP-GLES31.functional.fbo.color.texcubearray.r16f
 dEQP-GLES31.functional.fbo.color.texcubearray.rgb16f
+dEQP-GLES31.functional.fbo.color.tex2d.r16
+dEQP-GLES31.functional.fbo.color.tex2d.rg16
+dEQP-GLES31.functional.fbo.color.tex2d.rgba16
 dEQP-GLES31.functional.fbo.no_attachments.size.16x16
 dEQP-GLES31.functional.fbo.no_attachments.size.16x64
 dEQP-GLES31.functional.fbo.no_attachments.size.16x256
index f2fbc7b..2aa857d 100644 (file)
@@ -111,6 +111,91 @@ protected:
        const deUint32  m_format;
 };
 
+class FboColorTex2DCase : public FboColorbufferCase
+{
+       public:
+               FboColorTex2DCase (Context& context, const char* name, const char* description, deUint32 texFmt, const IVec2& texSize)
+                       : FboColorbufferCase    (context, name, description, texFmt)
+                       , m_texFmt                              (texFmt)
+                       , m_texSize                             (texSize)
+       {
+       }
+
+       protected:
+               void preCheck (void)
+               {
+                       checkFormatSupport(m_texFmt);
+               }
+
+               void render (tcu::Surface& dst)
+               {
+                       tcu::TextureFormat              texFmt          = glu::mapGLInternalFormat(m_texFmt);
+                       tcu::TextureFormatInfo  fmtInfo         = tcu::getTextureFormatInfo(texFmt);
+
+                       Texture2DShader                 texToFboShader  (DataTypes() << glu::TYPE_SAMPLER_2D, getFragmentOutputType(texFmt), fmtInfo.valueMax-fmtInfo.valueMin, fmtInfo.valueMin);
+                       deUint32                                texToFboShaderID = getCurrentContext()->createProgram(&texToFboShader);
+                       deUint32                                fbo;
+                       deUint32                                tex;
+
+                       // Setup shader
+                       texToFboShader.setUniforms(*getCurrentContext(), texToFboShaderID);
+
+                       //  Generate fbo
+                       {
+                               glu::TransferFormat     transferFmt     = glu::getTransferFormat(texFmt);
+                               deUint32                        format          = m_texFmt;
+                               const IVec2&            size            = m_texSize;
+
+                               glGenFramebuffers(1, &fbo);
+                               glGenTextures(1, &tex);
+
+                               glBindTexture(GL_TEXTURE_2D, tex);
+                               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+                               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+                               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+                               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+                               glTexImage2D(GL_TEXTURE_2D, 0, format, size.x(), size.y(), 0, transferFmt.format, transferFmt.dataType, DE_NULL);
+
+                               glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+                               glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
+                               checkError();
+                               checkFramebufferStatus(GL_FRAMEBUFFER);
+                       }
+
+                       // Render texture to fbo
+                       {
+                               const deUint32          format          = GL_RGBA;
+                               const deUint32          dataType        = GL_UNSIGNED_BYTE;
+                               const int                       texW            = 128;
+                               const int                       texH            = 128;
+                               deUint32                        tmpTex          = 0;
+                               const IVec2&            viewport        = m_texSize;
+                               tcu::TextureLevel       data            (glu::mapGLTransferFormat(format, dataType), texW, texH, 1);
+
+                               tcu::fillWithComponentGradients(data.getAccess(), Vec4(0.0f), Vec4(1.0f));
+
+                               glGenTextures(1, &tmpTex);
+                               glBindTexture(GL_TEXTURE_2D, tmpTex);
+                               glTexParameteri(GL_TEXTURE_2D,  GL_TEXTURE_WRAP_S,              GL_CLAMP_TO_EDGE);
+                               glTexParameteri(GL_TEXTURE_2D,  GL_TEXTURE_WRAP_T,              GL_CLAMP_TO_EDGE);
+                               glTexParameteri(GL_TEXTURE_2D,  GL_TEXTURE_MIN_FILTER,  GL_LINEAR);
+                               glTexParameteri(GL_TEXTURE_2D,  GL_TEXTURE_MAG_FILTER,  GL_LINEAR);
+                               glTexImage2D(GL_TEXTURE_2D, 0, format, texW, texH, 0, format, dataType, data.getAccess().getDataPtr());
+
+                               glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+                               glViewport(0, 0, viewport.x(), viewport.y());
+                               sglr::drawQuad(*getCurrentContext(), texToFboShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
+                       }
+
+                       readPixels(dst, 0, 0, getWidth(), getHeight(), texFmt, fmtInfo.lookupScale, fmtInfo.lookupBias);
+                       checkError();
+               }
+
+       private:
+               deUint32        m_texFmt;
+               IVec2           m_texSize;
+};
+
 class FboColorTexCubeArrayCase : public FboColorbufferCase
 {
 public:
@@ -318,6 +403,13 @@ void FboColorTests::init (void)
                GL_RGB16F
        };
 
+       static const deUint32 unorm16ColorFormats[] =
+       {
+               GL_R16,
+               GL_RG16,
+               GL_RGBA16
+       };
+
        // .texcubearray
        {
                tcu::TestCaseGroup* texCubeArrayGroup = new tcu::TestCaseGroup(m_testCtx, "texcubearray", "Cube map array texture tests");
@@ -327,6 +419,15 @@ void FboColorTests::init (void)
                        texCubeArrayGroup->addChild(new FboColorTexCubeArrayCase(m_context, getFormatName(colorFormats[fmtNdx]), "",
                                                                                                                                         colorFormats[fmtNdx], IVec3(128, 128, 12)));
        }
+
+       // .tex2d
+       {
+               tcu::TestCaseGroup* tex2dGroup = new tcu::TestCaseGroup(m_testCtx, "tex2d", "Render to texture");
+               addChild(tex2dGroup);
+
+               for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(unorm16ColorFormats); ndx++)
+                       tex2dGroup->addChild(new FboColorTex2DCase(m_context, getFormatName(unorm16ColorFormats[ndx]), "", unorm16ColorFormats[ndx], IVec2(129, 117)));
+       }
 }
 
 } // Functional
index fcb488a..eef9b96 100644 (file)
@@ -250,6 +250,12 @@ static std::vector<std::string> getEnablingExtensions (deUint32 format, glu::Ren
                                out.push_back("GL_EXT_color_buffer_float");
                        break;
 
+               case GL_R16:
+               case GL_RG16:
+               case GL_RGBA16:
+                       out.push_back("GL_EXT_texture_norm16");
+                       break;
+
                default:
                        break;
        }
index 4d8ade1..c6173ce 100644 (file)
@@ -541,6 +541,9 @@ const char* getFormatName (deUint32 format)
                case GL_DEPTH_COMPONENT24:      return "depth_component24";
                case GL_DEPTH32F_STENCIL8:      return "depth32f_stencil8";
                case GL_DEPTH24_STENCIL8:       return "depth24_stencil8";
+               case GL_R16:                            return "r16";
+               case GL_RG16:                           return "rg16";
+               case GL_RGBA16:                         return "rgba16";
 
                default:
                        TCU_FAIL("Unknown format");
@@ -575,9 +578,14 @@ tcu::TextureFormat getFramebufferReadFormat (const tcu::TextureFormat& format)
                case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
                        return tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::FLOAT);
 
-               case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
+        case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
                case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
-                       return tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8);
+       {
+                       if (format.type == tcu::TextureFormat::UNORM_INT16 || format.type == tcu::TextureFormat::SNORM_INT16)
+                               return tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT16);
+                       else
+                               return tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8);
+               }
 
                case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
                        return tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNSIGNED_INT32);