xref: /aosp_15_r20/external/deqp/modules/gles2/functional/es2fMultisampledRenderToTextureTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program OpenGL ES 2.0 Module
3*35238bceSAndroid Build Coastguard Worker  * -------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  *
5*35238bceSAndroid Build Coastguard Worker  * Copyright 2018 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 GL_EXT_multisample_render_to_texture tests.
22*35238bceSAndroid Build Coastguard Worker  */ /*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "es2fMultisampledRenderToTextureTests.hpp"
25*35238bceSAndroid Build Coastguard Worker 
26*35238bceSAndroid Build Coastguard Worker #include "deString.h"
27*35238bceSAndroid Build Coastguard Worker #include "deStringUtil.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "gluContextInfo.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "gluPixelTransfer.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "gluShaderProgram.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "glw.h"
32*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
34*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
35*35238bceSAndroid Build Coastguard Worker #include "tcuSurface.hpp"
36*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
37*35238bceSAndroid Build Coastguard Worker #include "tcuVector.hpp"
38*35238bceSAndroid Build Coastguard Worker 
39*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
40*35238bceSAndroid Build Coastguard Worker using tcu::Vec4;
41*35238bceSAndroid Build Coastguard Worker 
42*35238bceSAndroid Build Coastguard Worker namespace deqp
43*35238bceSAndroid Build Coastguard Worker {
44*35238bceSAndroid Build Coastguard Worker namespace gles2
45*35238bceSAndroid Build Coastguard Worker {
46*35238bceSAndroid Build Coastguard Worker namespace Functional
47*35238bceSAndroid Build Coastguard Worker {
48*35238bceSAndroid Build Coastguard Worker 
49*35238bceSAndroid Build Coastguard Worker class MultisampledRenderToTextureReadPixelsCase : public TestCase
50*35238bceSAndroid Build Coastguard Worker {
51*35238bceSAndroid Build Coastguard Worker public:
52*35238bceSAndroid Build Coastguard Worker     MultisampledRenderToTextureReadPixelsCase(Context &context, const char *name, const char *description);
53*35238bceSAndroid Build Coastguard Worker     ~MultisampledRenderToTextureReadPixelsCase();
54*35238bceSAndroid Build Coastguard Worker     void init();
55*35238bceSAndroid Build Coastguard Worker     IterateResult iterate();
56*35238bceSAndroid Build Coastguard Worker 
57*35238bceSAndroid Build Coastguard Worker private:
58*35238bceSAndroid Build Coastguard Worker     MultisampledRenderToTextureReadPixelsCase(const MultisampledRenderToTextureReadPixelsCase &other);
59*35238bceSAndroid Build Coastguard Worker     MultisampledRenderToTextureReadPixelsCase &operator=(const MultisampledRenderToTextureReadPixelsCase &other);
60*35238bceSAndroid Build Coastguard Worker };
61*35238bceSAndroid Build Coastguard Worker 
MultisampledRenderToTextureReadPixelsCase(Context & context,const char * name,const char * description)62*35238bceSAndroid Build Coastguard Worker MultisampledRenderToTextureReadPixelsCase::MultisampledRenderToTextureReadPixelsCase(Context &context, const char *name,
63*35238bceSAndroid Build Coastguard Worker                                                                                      const char *description)
64*35238bceSAndroid Build Coastguard Worker     : TestCase(context, name, description)
65*35238bceSAndroid Build Coastguard Worker {
66*35238bceSAndroid Build Coastguard Worker }
67*35238bceSAndroid Build Coastguard Worker 
~MultisampledRenderToTextureReadPixelsCase()68*35238bceSAndroid Build Coastguard Worker MultisampledRenderToTextureReadPixelsCase::~MultisampledRenderToTextureReadPixelsCase()
69*35238bceSAndroid Build Coastguard Worker {
70*35238bceSAndroid Build Coastguard Worker }
71*35238bceSAndroid Build Coastguard Worker 
init()72*35238bceSAndroid Build Coastguard Worker void MultisampledRenderToTextureReadPixelsCase::init()
73*35238bceSAndroid Build Coastguard Worker {
74*35238bceSAndroid Build Coastguard Worker     const glu::ContextInfo &contextInfo = m_context.getContextInfo();
75*35238bceSAndroid Build Coastguard Worker     if (!contextInfo.isExtensionSupported("GL_EXT_multisampled_render_to_texture"))
76*35238bceSAndroid Build Coastguard Worker     {
77*35238bceSAndroid Build Coastguard Worker         TCU_THROW(NotSupportedError, "EXT_multisampled_render_to_texture is not supported");
78*35238bceSAndroid Build Coastguard Worker     }
79*35238bceSAndroid Build Coastguard Worker }
80*35238bceSAndroid Build Coastguard Worker 
iterate()81*35238bceSAndroid Build Coastguard Worker MultisampledRenderToTextureReadPixelsCase::IterateResult MultisampledRenderToTextureReadPixelsCase::iterate()
82*35238bceSAndroid Build Coastguard Worker {
83*35238bceSAndroid Build Coastguard Worker     // Test for a bug where ReadPixels fails on multisampled textures.
84*35238bceSAndroid Build Coastguard Worker     // See http://crbug.com/890002
85*35238bceSAndroid Build Coastguard Worker     // Note that this does not test whether multisampling is working properly,
86*35238bceSAndroid Build Coastguard Worker     // only that ReadPixels is able to read from the texture.
87*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
88*35238bceSAndroid Build Coastguard Worker     // Create a framebuffer with a multisampled texture and a depth-stencil
89*35238bceSAndroid Build Coastguard Worker     // renderbuffer.
90*35238bceSAndroid Build Coastguard Worker     GLuint framebuffer = 0;
91*35238bceSAndroid Build Coastguard Worker     GLuint texture     = 0;
92*35238bceSAndroid Build Coastguard Worker     gl.genFramebuffers(1, &framebuffer);
93*35238bceSAndroid Build Coastguard Worker     gl.genTextures(1, &texture);
94*35238bceSAndroid Build Coastguard Worker     gl.bindFramebuffer(GL_FRAMEBUFFER, framebuffer);
95*35238bceSAndroid Build Coastguard Worker     gl.bindTexture(GL_TEXTURE_2D, texture);
96*35238bceSAndroid Build Coastguard Worker     gl.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
97*35238bceSAndroid Build Coastguard Worker     GLint max_samples = 0;
98*35238bceSAndroid Build Coastguard Worker     gl.getIntegerv(GL_MAX_SAMPLES_EXT, &max_samples);
99*35238bceSAndroid Build Coastguard Worker     gl.framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0, max_samples);
100*35238bceSAndroid Build Coastguard Worker     GLuint depthStencil = 0;
101*35238bceSAndroid Build Coastguard Worker     gl.genRenderbuffers(1, &depthStencil);
102*35238bceSAndroid Build Coastguard Worker     gl.bindRenderbuffer(GL_RENDERBUFFER, depthStencil);
103*35238bceSAndroid Build Coastguard Worker     gl.renderbufferStorageMultisampleEXT(GL_RENDERBUFFER, max_samples, GL_DEPTH24_STENCIL8, 1, 1);
104*35238bceSAndroid Build Coastguard Worker     gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthStencil);
105*35238bceSAndroid Build Coastguard Worker     gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthStencil);
106*35238bceSAndroid Build Coastguard Worker     if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
107*35238bceSAndroid Build Coastguard Worker     {
108*35238bceSAndroid Build Coastguard Worker         TCU_THROW(NotSupportedError, "Framebuffer format not supported.");
109*35238bceSAndroid Build Coastguard Worker     }
110*35238bceSAndroid Build Coastguard Worker     gl.clearColor(1, 0, 1, 0);
111*35238bceSAndroid Build Coastguard Worker     gl.clear(GL_COLOR_BUFFER_BIT);
112*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "init");
113*35238bceSAndroid Build Coastguard Worker 
114*35238bceSAndroid Build Coastguard Worker     // ReadPixels should implicitly resolve the multisampled buffer.
115*35238bceSAndroid Build Coastguard Worker     GLubyte pixel[4] = {0, 1, 0, 1};
116*35238bceSAndroid Build Coastguard Worker     gl.readPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
117*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "ReadPixels");
118*35238bceSAndroid Build Coastguard Worker 
119*35238bceSAndroid Build Coastguard Worker     if (pixel[0] != 255 || pixel[1] != 0 || pixel[2] != 255 || pixel[3] != 0)
120*35238bceSAndroid Build Coastguard Worker     {
121*35238bceSAndroid Build Coastguard Worker         std::ostringstream msg;
122*35238bceSAndroid Build Coastguard Worker         msg << "ReadPixels read incorrect values: [" << (int)pixel[0] << ", " << (int)pixel[1] << ", " << (int)pixel[2]
123*35238bceSAndroid Build Coastguard Worker             << ", " << (int)pixel[3] << "]";
124*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, msg.str().c_str());
125*35238bceSAndroid Build Coastguard Worker     }
126*35238bceSAndroid Build Coastguard Worker     else
127*35238bceSAndroid Build Coastguard Worker     {
128*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
129*35238bceSAndroid Build Coastguard Worker     }
130*35238bceSAndroid Build Coastguard Worker 
131*35238bceSAndroid Build Coastguard Worker     gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
132*35238bceSAndroid Build Coastguard Worker     gl.bindTexture(GL_TEXTURE_2D, 0);
133*35238bceSAndroid Build Coastguard Worker     gl.bindRenderbuffer(GL_RENDERBUFFER, 0);
134*35238bceSAndroid Build Coastguard Worker     gl.deleteFramebuffers(1, &framebuffer);
135*35238bceSAndroid Build Coastguard Worker     gl.deleteRenderbuffers(1, &depthStencil);
136*35238bceSAndroid Build Coastguard Worker     gl.deleteTextures(1, &texture);
137*35238bceSAndroid Build Coastguard Worker     return STOP;
138*35238bceSAndroid Build Coastguard Worker }
139*35238bceSAndroid Build Coastguard Worker 
MultisampledRenderToTextureTests(Context & context)140*35238bceSAndroid Build Coastguard Worker MultisampledRenderToTextureTests::MultisampledRenderToTextureTests(Context &context)
141*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, "multisampled_render_to_texture", "EXT_multisampled_render_to_texture tests")
142*35238bceSAndroid Build Coastguard Worker {
143*35238bceSAndroid Build Coastguard Worker }
144*35238bceSAndroid Build Coastguard Worker 
~MultisampledRenderToTextureTests()145*35238bceSAndroid Build Coastguard Worker MultisampledRenderToTextureTests::~MultisampledRenderToTextureTests()
146*35238bceSAndroid Build Coastguard Worker {
147*35238bceSAndroid Build Coastguard Worker }
148*35238bceSAndroid Build Coastguard Worker 
init()149*35238bceSAndroid Build Coastguard Worker void MultisampledRenderToTextureTests::init()
150*35238bceSAndroid Build Coastguard Worker {
151*35238bceSAndroid Build Coastguard Worker     addChild(new MultisampledRenderToTextureReadPixelsCase(m_context, "readpixels",
152*35238bceSAndroid Build Coastguard Worker                                                            "Test ReadPixels with EXT_multisampled_render_to_texture"));
153*35238bceSAndroid Build Coastguard Worker }
154*35238bceSAndroid Build Coastguard Worker 
155*35238bceSAndroid Build Coastguard Worker } // namespace Functional
156*35238bceSAndroid Build Coastguard Worker } // namespace gles2
157*35238bceSAndroid Build Coastguard Worker } // namespace deqp
158