Initialize gl_PointSize if the test draws points
authorAmy Liu <amy.liu@arm.com>
Tue, 14 Jan 2020 08:34:30 +0000 (16:34 +0800)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Mon, 27 Apr 2020 08:44:14 +0000 (04:44 -0400)
From GLSL specification: "If gl_PointSize is not written to,
its value is undefined in subsequent pipe stages"

Affects:

dEQP-GLES3.functional.primitive_restart.basic.points.*
dEQP-GLES3.functional.fragment_ops.scissor.partial_points

Components: AOSP

VK-GL-CTS issue: 2161

Change-Id: I3016287f7e55331522d6a7a8d562d8b57ab27e43
(cherry picked from commit 434240bf67d226947a3ccb73b10ea8e685f7aaaf)

modules/gles3/functional/es3fPrimitiveRestartTests.cpp
modules/glshared/glsScissorTests.cpp

index d926aecd39729529d5fdcef3e0306ffd2f18d9ef..d82ca34f5244d7de319dfb61112c5990bb8d363f 100644 (file)
@@ -215,15 +215,30 @@ void* PrimitiveRestartCase::getIndexPtr (int indexNdx)
 void PrimitiveRestartCase::init (void)
 {
        // Create shader program.
-
-       static const char* vertShaderSource =
-               "#version 300 es\n"
-               "in highp vec4 a_position;\n"
-               "\n"
-               "void main()\n"
-               "{\n"
-               "       gl_Position = a_position;\n"
-               "}\n";
+       std::string vertShaderSource;
+       if (m_primType == PRIMITIVE_POINTS)
+       {
+               vertShaderSource =
+                       "#version 300 es\n"
+                       "in highp vec4 a_position;\n"
+                       "\n"
+                       "void main()\n"
+                       "{\n"
+                       "       gl_Position = a_position;\n"
+                       "       gl_PointSize = 1.0f;\n"
+                       "}\n";
+       }
+       else
+       {
+               vertShaderSource =
+                       "#version 300 es\n"
+                       "in highp vec4 a_position;\n"
+                       "\n"
+                       "void main()\n"
+                       "{\n"
+                       "       gl_Position = a_position;\n"
+                       "}\n";
+       }
 
        static const char* fragShaderSource =
                "#version 300 es\n"
index 96cbeeaba791bdce995676c1457383bd4cbc0ab0..e11e7a3b94d8b80b22f77ecba0105a3eadc29155 100644 (file)
@@ -124,13 +124,27 @@ void clearEdges (const tcu::PixelBufferAccess& access, const T& color, const IVe
        }
 }
 
-glu::ProgramSources genShaders(glu::GLSLVersion version)
+glu::ProgramSources genShaders(glu::GLSLVersion version, bool isPoint)
 {
-       const string vtxSource = "${VERSION}\n"
-                                                        "${IN} highp vec4 a_position;\n"
-                                                        "void main(){\n"
-                                                        "      gl_Position = a_position;\n"
-                                                        "}\n";
+       string vtxSource;
+
+       if (isPoint)
+       {
+                vtxSource = "${VERSION}\n"
+                                        "${IN} highp vec4 a_position;\n"
+                                        "void main(){\n"
+                                        "      gl_Position = a_position;\n"
+                                        "      gl_PointSize = 1.0;\n"
+                                        "}\n";
+       }
+       else
+       {
+                vtxSource = "${VERSION}\n"
+                                        "${IN} highp vec4 a_position;\n"
+                                        "void main(){\n"
+                                        "      gl_Position = a_position;\n"
+                                        "}\n";
+       }
 
        const string frgSource = "${VERSION}\n"
                                                         "${OUT_DECL}"
@@ -177,6 +191,9 @@ public:
 protected:
        virtual void                    render                  (GLuint program, const IVec4& viewport) const = 0;
 
+       // Initialize gl_PointSize to 1.0f when drawing points, or the point size is undefined according to spec.
+       virtual bool                    isPoint                 (void) const = 0;
+
        glu::RenderContext&             m_renderCtx;
        const Vec4                              m_scissorArea;
 };
@@ -199,7 +216,7 @@ ScissorCase::IterateResult ScissorCase::iterate (void)
                                                                                                                                1u << de::max(0, 8 - renderFormat.greenBits),
                                                                                                                                1u << de::max(0, 8 - renderFormat.blueBits),
                                                                                                                                1u << de::max(0, 8 - renderFormat.alphaBits)).asFloat();
-       const glu::ShaderProgram        shader                  (m_renderCtx, genShaders(glu::getContextTypeGLSLVersion(m_renderCtx.getType())));
+       const glu::ShaderProgram        shader                  (m_renderCtx, genShaders(glu::getContextTypeGLSLVersion(m_renderCtx.getType()), isPoint()));
 
        const RandomViewport            viewport                (m_renderCtx.getRenderTarget(), 256, 256, deStringHash(getName()));
        const IVec4                                     relScissorArea  (int(m_scissorArea.x() * (float)viewport.width),
@@ -297,6 +314,7 @@ public:
 
 protected:
        virtual void                            render                                  (GLuint program, const IVec4& viewport) const;
+       virtual bool                            isPoint                                 (void) const;
 
 private:
        const Vec4                                      m_renderArea;
@@ -319,6 +337,11 @@ ScissorPrimitiveCase::ScissorPrimitiveCase (tcu::TestContext&              testCtx,
 {
 }
 
+bool ScissorPrimitiveCase::isPoint (void) const
+{
+       return (m_primitiveType == POINT);
+}
+
 void ScissorPrimitiveCase::render (GLuint program, const IVec4&) const
 {
        const glw::Functions&           gl                              = m_renderCtx.getFunctions();
@@ -410,6 +433,7 @@ public:
 
 protected:
        virtual void    render                          (GLuint program, const IVec4& viewport) const;
+       virtual bool    isPoint                         (void) const;
 
 private:
        const deUint32  m_clearMode; //!< Combination of the flags accepted by glClear
@@ -434,6 +458,11 @@ void ScissorClearCase::init (void)
                throw tcu::NotSupportedError("Cannot clear stencil; no stencil buffer present", "", __FILE__, __LINE__);
 }
 
+bool ScissorClearCase::isPoint (void) const
+{
+       return false;
+}
+
 void ScissorClearCase::render (GLuint program, const IVec4&) const
 {
        const glw::Functions&   gl              = m_renderCtx.getFunctions();
@@ -485,6 +514,7 @@ protected:
        enum {SIZE = 64};
 
        virtual void    render                                  (GLuint program, const IVec4& viewport) const;
+       virtual bool    isPoint                                 (void) const;
 
        FramebufferP    m_fbo;
 };
@@ -520,6 +550,11 @@ void FramebufferBlitCase::deinit (void)
        m_fbo.clear();
 }
 
+bool FramebufferBlitCase::isPoint (void) const
+{
+       return false;
+}
+
 void FramebufferBlitCase::render(GLuint program, const IVec4& viewport) const
 {
        const glw::Functions&   gl                                      = m_renderCtx.getFunctions();
@@ -578,6 +613,7 @@ private:
        static BufferFmtDesc    getBufferFormat                 (ClearType type);
 
        virtual void                    render                                  (GLuint program) const;
+       virtual bool                    isPoint                                 (void) const;
 
        glu::RenderContext&             m_renderCtx;
        const ClearType                 m_clearType;
@@ -609,7 +645,7 @@ FramebufferClearCase::IterateResult FramebufferClearCase::iterate (void)
 {
        TestLog&                                        log                             = m_testCtx.getLog();
        const glw::Functions&           gl                              = m_renderCtx.getFunctions();
-       const glu::ShaderProgram        shader                  (m_renderCtx, genShaders(glu::getContextTypeGLSLVersion(m_renderCtx.getType())));
+       const glu::ShaderProgram        shader                  (m_renderCtx, genShaders(glu::getContextTypeGLSLVersion(m_renderCtx.getType()), isPoint()));
 
        const glu::Framebuffer          fbo                             (gl);
        const glu::Renderbuffer         colorbuf                (gl);
@@ -834,6 +870,11 @@ void FramebufferClearCase::render (GLuint program) const
        }
 }
 
+bool FramebufferClearCase::isPoint (void) const
+{
+       return false;
+}
+
 } // Anonymous
 
 namespace ScissorTestInternal