xref: /aosp_15_r20/external/angle/src/tests/gl_tests/FormatPrintTest.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2019 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // FormatPrintTest:
7 //   Prints all format support info
8 //
9 
10 #include "common/gl_enum_utils.h"
11 #include "libANGLE/Context.h"
12 #include "libANGLE/Display.h"
13 #include "libANGLE/formatutils.h"
14 #include "test_utils/ANGLETest.h"
15 #include "test_utils/angle_test_instantiate.h"
16 #include "util/EGLWindow.h"
17 
18 using namespace angle;
19 
20 namespace
21 {
22 
23 class FormatPrintTest : public ANGLETest<>
24 {};
25 
26 // This test enumerates all sized and unsized GL formats and prints out support information
27 // This test omits unsupported formats
28 // The output is csv parseable and has a header and a new line.
29 // Each row consists of:
30 // (InternalFormat,Type,texturable,filterable,textureAttachmentSupported,renderBufferSupported)
TEST_P(FormatPrintTest,PrintAllSupportedFormats)31 TEST_P(FormatPrintTest, PrintAllSupportedFormats)
32 {
33     // Hack the angle!
34     egl::Display *display   = static_cast<egl::Display *>(getEGLWindow()->getDisplay());
35     gl::ContextID contextID = {
36         static_cast<GLuint>(reinterpret_cast<uintptr_t>(getEGLWindow()->getContext()))};
37     gl::Context *context                                 = display->getContext(contextID);
38     const gl::InternalFormatInfoMap &allSupportedFormats = gl::GetInternalFormatMap();
39 
40     std::cout << std::endl
41               << "InternalFormat,Type,Texturable,Filterable,Texture attachment,Renderbuffer"
42               << std::endl
43               << std::endl;
44 
45     for (const auto &internalFormat : allSupportedFormats)
46     {
47         for (const auto &typeFormatPair : internalFormat.second)
48         {
49             bool textureSupport = typeFormatPair.second.textureSupport(context->getClientVersion(),
50                                                                        context->getExtensions());
51             bool filterSupport  = typeFormatPair.second.filterSupport(context->getClientVersion(),
52                                                                       context->getExtensions());
53             bool textureAttachmentSupport = typeFormatPair.second.textureAttachmentSupport(
54                 context->getClientVersion(), context->getExtensions());
55             bool renderbufferSupport = typeFormatPair.second.renderbufferSupport(
56                 context->getClientVersion(), context->getExtensions());
57 
58             // Skip if not supported
59             // A format is not supported if the only feature bit enabled is "filterSupport"
60             if (!(textureSupport || textureAttachmentSupport || renderbufferSupport))
61             {
62                 continue;
63             }
64 
65             // Lookup enum strings from enum
66             std::stringstream resultStringStream;
67             gl::OutputGLenumString(resultStringStream, gl::GLESEnum::InternalFormat,
68                                    internalFormat.first);
69             resultStringStream << ",";
70             gl::OutputGLenumString(resultStringStream, gl::GLESEnum::PixelType,
71                                    typeFormatPair.first);
72             resultStringStream << ",";
73 
74             // able to be sampled from, see GLSL sampler variables
75             if (textureSupport)
76             {
77                 resultStringStream << "texturable";
78             }
79             resultStringStream << ",";
80 
81             // able to be linearly filtered (GL_LINEAR)
82             if (filterSupport)
83             {
84                 resultStringStream << "filterable";
85             }
86             resultStringStream << ",";
87 
88             // a texture with this can be used for glFramebufferTexture2D
89             if (textureAttachmentSupport)
90             {
91                 resultStringStream << "textureAttachmentSupported";
92             }
93             resultStringStream << ",";
94 
95             // usable with glFramebufferRenderbuffer, glRenderbufferStorage,
96             // glNamedRenderbufferStorage
97             if (renderbufferSupport)
98             {
99                 resultStringStream << "renderbufferSupported";
100             }
101 
102             std::cout << resultStringStream.str() << std::endl;
103         }
104     }
105 }
106 
107 ANGLE_INSTANTIATE_TEST(FormatPrintTest, ES2_VULKAN(), ES3_VULKAN());
108 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(FormatPrintTest);
109 
110 }  // anonymous namespace
111