xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/gl/renderergl_utils.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2012 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 
7 // renderergl_utils.h: Conversion functions and other utility routines
8 // specific to the OpenGL renderer.
9 
10 #ifndef LIBANGLE_RENDERER_GL_RENDERERGLUTILS_H_
11 #define LIBANGLE_RENDERER_GL_RENDERERGLUTILS_H_
12 
13 #include "common/debug.h"
14 #include "libANGLE/Caps.h"
15 #include "libANGLE/Error.h"
16 #include "libANGLE/Version.h"
17 #include "libANGLE/angletypes.h"
18 #include "libANGLE/renderer/driver_utils.h"
19 #include "libANGLE/renderer/gl/functionsgl_typedefs.h"
20 
21 #include <string>
22 #include <vector>
23 
24 namespace angle
25 {
26 struct FeaturesGL;
27 struct FrontendFeatures;
28 }  // namespace angle
29 
30 namespace gl
31 {
32 struct Caps;
33 class TextureCapsMap;
34 struct Extensions;
35 struct Version;
36 }  // namespace gl
37 
38 namespace rx
39 {
40 class BlitGL;
41 class ClearMultiviewGL;
42 class ContextGL;
43 class FunctionsGL;
44 class StateManagerGL;
45 enum class MultiviewImplementationTypeGL
46 {
47     NV_VIEWPORT_ARRAY2,
48     UNSPECIFIED
49 };
50 
51 // State-tracking data for the swap control to allow DisplayGL to remember per
52 // drawable information for swap control.
53 struct SwapControlData
54 {
55     SwapControlData();
56 
57     // Set by the drawable
58     int targetSwapInterval;
59 
60     // DisplayGL-side state-tracking
61     int maxSwapInterval;
62     int currentSwapInterval;
63 };
64 
65 VendorID GetVendorID(const FunctionsGL *functions);
66 ShShaderOutput GetShaderOutputType(const FunctionsGL *functions);
67 
68 // Helpers for extracting the GL helper objects out of a context
69 const FunctionsGL *GetFunctionsGL(const gl::Context *context);
70 StateManagerGL *GetStateManagerGL(const gl::Context *context);
71 BlitGL *GetBlitGL(const gl::Context *context);
72 ClearMultiviewGL *GetMultiviewClearer(const gl::Context *context);
73 const angle::FeaturesGL &GetFeaturesGL(const gl::Context *context);
74 
75 // Clear all errors on the stored context, emits console warnings
76 void ClearErrors(const gl::Context *context,
77                  const char *file,
78                  const char *function,
79                  unsigned int line);
80 void ClearErrors(const FunctionsGL *functions,
81                  const char *file,
82                  const char *function,
83                  unsigned int line);
84 
85 // Check for a single error
86 angle::Result CheckError(const gl::Context *context,
87                          const char *call,
88                          const char *file,
89                          const char *function,
90                          unsigned int line);
91 // Propagates a single error, marking it as handled, and checks for more errors.
92 angle::Result HandleError(const gl::Context *context,
93                           GLenum error,
94                           const char *call,
95                           const char *file,
96                           const char *function,
97                           unsigned int line);
98 
99 #define ANGLE_GL_TRY_ALWAYS_CHECK(context, call)                      \
100     (ClearErrors(context, __FILE__, __FUNCTION__, __LINE__), (call)); \
101     ANGLE_TRY(CheckError(context, #call, __FILE__, __FUNCTION__, __LINE__))
102 
103 #define ANGLE_GL_CLEAR_ERRORS(functions) ClearErrors(functions, __FILE__, __FUNCTION__, __LINE__)
104 
105 #if defined(ANGLE_ENABLE_ASSERTS)
106 #    define ANGLE_GL_TRY(context, call) ANGLE_GL_TRY_ALWAYS_CHECK(context, call)
107 #else
108 #    define ANGLE_GL_TRY(context, call) call
109 #endif
110 
111 namespace nativegl_gl
112 {
113 
114 void GenerateCaps(const FunctionsGL *functions,
115                   const angle::FeaturesGL &features,
116                   gl::Caps *caps,
117                   gl::TextureCapsMap *textureCapsMap,
118                   gl::Extensions *extensions,
119                   gl::Limitations *limitations,
120                   gl::Version *maxSupportedESVersion,
121                   MultiviewImplementationTypeGL *multiviewImplementationType,
122                   ShPixelLocalStorageOptions *);
123 
124 void InitializeFeatures(const FunctionsGL *functions, angle::FeaturesGL *features);
125 void InitializeFrontendFeatures(const FunctionsGL *functions, angle::FrontendFeatures *features);
126 void ReInitializeFeaturesAtGPUSwitch(const FunctionsGL *functions, angle::FeaturesGL *features);
127 }  // namespace nativegl_gl
128 
129 namespace nativegl
130 {
131 bool SupportsVertexArrayObjects(const FunctionsGL *functions);
132 bool CanUseDefaultVertexArrayObject(const FunctionsGL *functions);
133 bool CanUseClientSideArrays(const FunctionsGL *functions, GLuint vao);
134 bool SupportsCompute(const FunctionsGL *functions);
135 bool SupportsFenceSync(const FunctionsGL *functions);
136 bool SupportsOcclusionQueries(const FunctionsGL *functions);
137 bool SupportsNativeRendering(const FunctionsGL *functions,
138                              gl::TextureType type,
139                              GLenum internalFormat);
140 bool SupportsTexImage(gl::TextureType type);
141 bool UseTexImage2D(gl::TextureType textureType);
142 bool UseTexImage3D(gl::TextureType textureType);
143 GLenum GetTextureBindingQuery(gl::TextureType textureType);
144 GLenum GetTextureBindingTarget(gl::TextureType textureType);
145 GLenum GetTextureBindingTarget(gl::TextureTarget textureTarget);
146 GLenum GetBufferBindingQuery(gl::BufferBinding bufferBinding);
147 std::string GetBufferBindingString(gl::BufferBinding bufferBinding);
148 gl::TextureType GetNativeTextureType(gl::TextureType type);
149 gl::TextureTarget GetNativeTextureTarget(gl::TextureTarget target);
150 }  // namespace nativegl
151 
152 bool CanMapBufferForRead(const FunctionsGL *functions);
153 uint8_t *MapBufferRangeWithFallback(const FunctionsGL *functions,
154                                     GLenum target,
155                                     size_t offset,
156                                     size_t length,
157                                     GLbitfield access);
158 
159 angle::Result ShouldApplyLastRowPaddingWorkaround(ContextGL *contextGL,
160                                                   const gl::Extents &size,
161                                                   const gl::PixelStoreStateBase &state,
162                                                   const gl::Buffer *pixelBuffer,
163                                                   GLenum format,
164                                                   GLenum type,
165                                                   bool is3D,
166                                                   const void *pixels,
167                                                   bool *shouldApplyOut);
168 
169 struct ContextCreationTry
170 {
171     enum class Type
172     {
173         DESKTOP_CORE,
174         DESKTOP_LEGACY,
175         ES,
176     };
177 
ContextCreationTryContextCreationTry178     ContextCreationTry(EGLint displayType, Type type, gl::Version version)
179         : displayType(displayType), type(type), version(version)
180     {}
181 
182     EGLint displayType;
183     Type type;
184     gl::Version version;
185 };
186 
187 std::vector<ContextCreationTry> GenerateContextCreationToTry(EGLint requestedType, bool isMesaGLX);
188 
189 std::string GetRendererString(const FunctionsGL *functions);
190 std::string GetVendorString(const FunctionsGL *functions);
191 std::string GetVersionString(const FunctionsGL *functions);
192 
193 }  // namespace rx
194 
195 #endif  // LIBANGLE_RENDERER_GL_RENDERERGLUTILS_H_
196