blob: 967077653af60e3f5a4d5f6c17ac8fd96104b1e4 [file] [log] [blame]
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef GrGLUtil_DEFINED
9#define GrGLUtil_DEFINED
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/gpu/gl/GrGLInterface.h"
12#include "include/private/GrTypesPriv.h"
Robert Phillips28a5a432019-06-07 12:46:21 -040013#include "src/gpu/GrDataUtils.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/GrStencilSettings.h"
15#include "src/gpu/gl/GrGLDefines.h"
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +000016
commit-bot@chromium.org215a6822013-09-05 18:28:42 +000017class SkMatrix;
18
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +000019////////////////////////////////////////////////////////////////////////////////
20
21typedef uint32_t GrGLVersion;
22typedef uint32_t GrGLSLVersion;
Brian Salomon9a544bc2018-04-04 16:12:31 -040023typedef uint64_t GrGLDriverVersion;
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +000024
Brian Salomon9a544bc2018-04-04 16:12:31 -040025#define GR_GL_VER(major, minor) ((static_cast<uint32_t>(major) << 16) | \
26 static_cast<uint32_t>(minor))
27#define GR_GLSL_VER(major, minor) ((static_cast<uint32_t>(major) << 16) | \
28 static_cast<uint32_t>(minor))
29#define GR_GL_DRIVER_VER(major, minor, point) ((static_cast<uint64_t>(major) << 32) | \
30 (static_cast<uint64_t>(minor) << 16) | \
31 static_cast<uint64_t>(point))
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +000032
33#define GR_GL_INVALID_VER GR_GL_VER(0, 0)
cdalton1acea862015-06-02 13:05:52 -070034#define GR_GLSL_INVALID_VER GR_GLSL_VER(0, 0)
Brian Salomon9a544bc2018-04-04 16:12:31 -040035#define GR_GL_DRIVER_UNKNOWN_VER GR_GL_DRIVER_VER(0, 0, 0)
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +000036
bsalomon@google.com0b1e4812012-10-23 13:52:43 +000037/**
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000038 * The Vendor and Renderer enum values are lazily updated as required.
bsalomon@google.com0b1e4812012-10-23 13:52:43 +000039 */
40enum GrGLVendor {
bsalomon@google.com96966a52013-02-21 16:34:21 +000041 kARM_GrGLVendor,
Kevin Lubickda2b9f32018-06-05 16:05:58 -040042 kGoogle_GrGLVendor,
bsalomon@google.com3012ded2013-02-22 16:44:04 +000043 kImagination_GrGLVendor,
44 kIntel_GrGLVendor,
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +000045 kQualcomm_GrGLVendor,
bsalomone904c092014-07-17 10:50:59 -070046 kNVIDIA_GrGLVendor,
brianosman131ff132016-06-07 14:22:44 -070047 kATI_GrGLVendor,
bsalomon@google.com3012ded2013-02-22 16:44:04 +000048
49 kOther_GrGLVendor
bsalomon@google.com0b1e4812012-10-23 13:52:43 +000050};
51
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000052enum GrGLRenderer {
Chris Dalton0090ef62018-03-28 17:35:00 -060053 kTegra_PreK1_GrGLRenderer, // Legacy Tegra architecture (pre-K1).
54 kTegra_GrGLRenderer, // Tegra with the same architecture as NVIDIA desktop GPUs (K1+).
bsalomon63b21962014-11-05 07:05:34 -080055 kPowerVR54x_GrGLRenderer,
56 kPowerVRRogue_GrGLRenderer,
bsalomona8fcea02015-02-13 09:00:39 -080057 kAdreno3xx_GrGLRenderer,
Chris Dalton1214be92018-06-28 19:06:27 -060058 kAdreno430_GrGLRenderer,
59 kAdreno4xx_other_GrGLRenderer,
egdaniel7517e452016-09-20 13:00:26 -070060 kAdreno5xx_GrGLRenderer,
bsalomon40170072016-05-05 14:40:03 -070061 kOSMesa_GrGLRenderer,
Kevin Lubickda2b9f32018-06-05 16:05:58 -040062 kGoogleSwiftShader_GrGLRenderer,
Brian Osmand6b53d52019-06-25 15:37:14 -040063
64 /** Intel GPU families, ordered by generation **/
65 // 6th gen
Chris Dalton1c1391c2018-07-20 12:21:14 -060066 kIntelSandyBridge_GrGLRenderer,
Brian Osmand6b53d52019-06-25 15:37:14 -040067
68 // 7th gen
69 kIntelIvyBridge_GrGLRenderer,
70 kIntelValleyView_GrGLRenderer, // aka BayTrail
71 kIntelHaswell_GrGLRenderer,
72
73 // 8th gen
74 kIntelCherryView_GrGLRenderer, // aka Braswell
75 kIntelBroadwell_GrGLRenderer,
76
77 // 9th gen
78 kIntelApolloLake_GrGLRenderer,
79 kIntelSkyLake_GrGLRenderer,
80 kIntelGeminiLake_GrGLRenderer,
81 kIntelKabyLake_GrGLRenderer,
82 kIntelCoffeeLake_GrGLRenderer,
83
84 // 11th gen
85 kIntelIceLake_GrGLRenderer,
86
Greg Daniel25019172017-10-26 13:32:33 -040087 kGalliumLLVM_GrGLRenderer,
Brian Salomon5fba7ad2018-03-22 10:01:16 -040088 kMali4xx_GrGLRenderer,
Brian Osmanac1e4962017-05-25 11:34:38 -040089 /** T-6xx, T-7xx, or T-8xx */
90 kMaliT_GrGLRenderer,
Robert Phillipsbc712742017-06-02 11:20:37 -040091 kANGLE_GrGLRenderer,
Robert Phillipsdbfecd02017-10-18 15:44:08 -040092
Brian Salomon5fba7ad2018-03-22 10:01:16 -040093 kAMDRadeonHD7xxx_GrGLRenderer, // AMD Radeon HD 7000 Series
94 kAMDRadeonR9M4xx_GrGLRenderer, // AMD Radeon R9 M400 Series
Robert Phillipsdbfecd02017-10-18 15:44:08 -040095
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000096 kOther_GrGLRenderer
97};
98
cdalton1acea862015-06-02 13:05:52 -070099enum GrGLDriver {
100 kMesa_GrGLDriver,
101 kChromium_GrGLDriver,
102 kNVIDIA_GrGLDriver,
cdalton1dd05422015-06-12 09:01:18 -0700103 kIntel_GrGLDriver,
bsalomon88c7b982015-07-31 11:20:16 -0700104 kANGLE_GrGLDriver,
Kevin Lubickda2b9f32018-06-05 16:05:58 -0400105 kSwiftShader_GrGLDriver,
Brian Salomonb52fa022017-06-07 09:42:52 -0400106 kQualcomm_GrGLDriver,
cdalton1acea862015-06-02 13:05:52 -0700107 kUnknown_GrGLDriver
108};
109
Brian Salomon266ef6d2017-09-22 11:27:42 -0400110enum class GrGLANGLEBackend {
111 kUnknown,
112 kD3D9,
113 kD3D11,
114 kOpenGL
115};
116
117enum class GrGLANGLEVendor {
118 kUnknown,
Michael Ludwig8f5aeeb2019-02-01 21:53:11 +0000119 kIntel
Brian Salomon266ef6d2017-09-22 11:27:42 -0400120};
121
Chris Dalton0a94e4c2018-01-18 15:06:50 -0700122enum class GrGLANGLERenderer {
Brian Salomon266ef6d2017-09-22 11:27:42 -0400123 kUnknown,
Chris Dalton1c1391c2018-07-20 12:21:14 -0600124 kSandyBridge,
Chris Dalton0a94e4c2018-01-18 15:06:50 -0700125 kIvyBridge,
126 kSkylake
Brian Salomon266ef6d2017-09-22 11:27:42 -0400127};
128
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000129////////////////////////////////////////////////////////////////////////////////
130
131/**
132 * Some drivers want the var-int arg to be zero-initialized on input.
133 */
134#define GR_GL_INIT_ZERO 0
135#define GR_GL_GetIntegerv(gl, e, p) \
136 do { \
137 *(p) = GR_GL_INIT_ZERO; \
138 GR_GL_CALL(gl, GetIntegerv(e, p)); \
139 } while (0)
140
141#define GR_GL_GetFramebufferAttachmentParameteriv(gl, t, a, pname, p) \
142 do { \
143 *(p) = GR_GL_INIT_ZERO; \
144 GR_GL_CALL(gl, GetFramebufferAttachmentParameteriv(t, a, pname, p)); \
145 } while (0)
146
Greg Daniel81e7bf82017-07-19 14:47:42 -0400147#define GR_GL_GetInternalformativ(gl, t, f, n, s, p) \
148 do { \
149 *(p) = GR_GL_INIT_ZERO; \
150 GR_GL_CALL(gl, GetInternalformativ(t, f, n, s, p)); \
151 } while (0)
152
robertphillips7354a4b2015-12-16 05:08:27 -0800153#define GR_GL_GetNamedFramebufferAttachmentParameteriv(gl, fb, a, pname, p) \
154 do { \
155 *(p) = GR_GL_INIT_ZERO; \
156 GR_GL_CALL(gl, GetNamedFramebufferAttachmentParameteriv(fb, a, pname, p)); \
157 } while (0)
158
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000159#define GR_GL_GetRenderbufferParameteriv(gl, t, pname, p) \
160 do { \
161 *(p) = GR_GL_INIT_ZERO; \
162 GR_GL_CALL(gl, GetRenderbufferParameteriv(t, pname, p)); \
163 } while (0)
bsalomon17168df2014-12-09 09:00:49 -0800164
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000165#define GR_GL_GetTexLevelParameteriv(gl, t, l, pname, p) \
166 do { \
167 *(p) = GR_GL_INIT_ZERO; \
168 GR_GL_CALL(gl, GetTexLevelParameteriv(t, l, pname, p)); \
169 } while (0)
170
bsalomon17168df2014-12-09 09:00:49 -0800171#define GR_GL_GetShaderPrecisionFormat(gl, st, pt, range, precision) \
172 do { \
173 (range)[0] = GR_GL_INIT_ZERO; \
174 (range)[1] = GR_GL_INIT_ZERO; \
175 (*precision) = GR_GL_INIT_ZERO; \
176 GR_GL_CALL(gl, GetShaderPrecisionFormat(st, pt, range, precision)); \
177 } while (0)
178
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000179////////////////////////////////////////////////////////////////////////////////
180
181/**
182 * Helpers for glGetString()
183 */
184
185// these variants assume caller already has a string from glGetString()
186GrGLVersion GrGLGetVersionFromString(const char* versionString);
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000187GrGLStandard GrGLGetStandardInUseFromString(const char* versionString);
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000188GrGLSLVersion GrGLGetGLSLVersionFromString(const char* versionString);
bsalomon@google.com0b1e4812012-10-23 13:52:43 +0000189GrGLVendor GrGLGetVendorFromString(const char* vendorString);
Brian Salomon4470e342018-04-04 14:27:48 -0400190GrGLRenderer GrGLGetRendererFromStrings(const char* rendererString, const GrGLExtensions&);
Brian Salomon266ef6d2017-09-22 11:27:42 -0400191void GrGLGetANGLEInfoFromString(const char* rendererString, GrGLANGLEBackend*,
192 GrGLANGLEVendor*, GrGLANGLERenderer*);
cdalton1acea862015-06-02 13:05:52 -0700193
194void GrGLGetDriverInfo(GrGLStandard standard,
195 GrGLVendor vendor,
196 const char* rendererString,
197 const char* versionString,
198 GrGLDriver* outDriver,
199 GrGLDriverVersion* outVersion);
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000200
201// these variants call glGetString()
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000202GrGLVersion GrGLGetVersion(const GrGLInterface*);
203GrGLSLVersion GrGLGetGLSLVersion(const GrGLInterface*);
bsalomon@google.com0b1e4812012-10-23 13:52:43 +0000204GrGLVendor GrGLGetVendor(const GrGLInterface*);
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +0000205GrGLRenderer GrGLGetRenderer(const GrGLInterface*);
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000206
207/**
208 * Helpers for glGetError()
209 */
210
bsalomon@google.com2717d562012-05-07 19:10:52 +0000211void GrGLCheckErr(const GrGLInterface* gl,
212 const char* location,
213 const char* call);
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000214
bsalomon@google.com2717d562012-05-07 19:10:52 +0000215void GrGLClearErr(const GrGLInterface* gl);
216
217////////////////////////////////////////////////////////////////////////////////
218
219/**
220 * Macros for using GrGLInterface to make GL calls
221 */
222
223// internal macro to conditionally call glGetError based on compile-time and
224// run-time flags.
225#if GR_GL_CHECK_ERROR
226 extern bool gCheckErrorGL;
227 #define GR_GL_CHECK_ERROR_IMPL(IFACE, X) \
228 if (gCheckErrorGL) \
229 GrGLCheckErr(IFACE, GR_FILE_AND_LINE_STR, #X)
230#else
231 #define GR_GL_CHECK_ERROR_IMPL(IFACE, X)
232#endif
233
tfarina38406c82014-10-31 07:11:12 -0700234// internal macro to conditionally log the gl call using SkDebugf based on
bsalomon@google.com2717d562012-05-07 19:10:52 +0000235// compile-time and run-time flags.
236#if GR_GL_LOG_CALLS
237 extern bool gLogCallsGL;
238 #define GR_GL_LOG_CALLS_IMPL(X) \
239 if (gLogCallsGL) \
tfarina38406c82014-10-31 07:11:12 -0700240 SkDebugf(GR_FILE_AND_LINE_STR "GL: " #X "\n")
bsalomon@google.com2717d562012-05-07 19:10:52 +0000241#else
242 #define GR_GL_LOG_CALLS_IMPL(X)
243#endif
244
bsalomon@google.com2717d562012-05-07 19:10:52 +0000245// makes a GL call on the interface and does any error checking and logging
246#define GR_GL_CALL(IFACE, X) \
247 do { \
248 GR_GL_CALL_NOERRCHECK(IFACE, X); \
249 GR_GL_CHECK_ERROR_IMPL(IFACE, X); \
250 } while (false)
251
252// Variant of above that always skips the error check. This is useful when
253// the caller wants to do its own glGetError() call and examine the error value.
254#define GR_GL_CALL_NOERRCHECK(IFACE, X) \
255 do { \
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000256 (IFACE)->fFunctions.f##X; \
bsalomon@google.com2717d562012-05-07 19:10:52 +0000257 GR_GL_LOG_CALLS_IMPL(X); \
258 } while (false)
259
260// same as GR_GL_CALL but stores the return value of the gl call in RET
261#define GR_GL_CALL_RET(IFACE, RET, X) \
262 do { \
263 GR_GL_CALL_RET_NOERRCHECK(IFACE, RET, X); \
264 GR_GL_CHECK_ERROR_IMPL(IFACE, X); \
265 } while (false)
266
267// same as GR_GL_CALL_RET but always skips the error check.
268#define GR_GL_CALL_RET_NOERRCHECK(IFACE, RET, X) \
269 do { \
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000270 (RET) = (IFACE)->fFunctions.f##X; \
bsalomon@google.com2717d562012-05-07 19:10:52 +0000271 GR_GL_LOG_CALLS_IMPL(X); \
272 } while (false)
273
274// call glGetError without doing a redundant error check or logging.
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000275#define GR_GL_GET_ERROR(IFACE) (IFACE)->fFunctions.fGetError()
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000276
cdalton93a379b2016-05-11 13:58:08 -0700277GrGLenum GrToGLStencilFunc(GrStencilTest test);
kkinnunenccdaa042014-08-20 01:36:23 -0700278
Robert Phillips8043f322019-05-31 08:11:36 -0400279/**
280 * Returns true if the format is compressed.
281 */
282bool GrGLFormatIsCompressed(GrGLenum glFormat);
283
284/**
Brian Salomonbb8dde82019-06-27 10:52:13 -0400285 * Maps a gl format into the CompressionType enum if appropriate.
Robert Phillips28a5a432019-06-07 12:46:21 -0400286 */
Brian Salomonbb8dde82019-06-27 10:52:13 -0400287bool GrGLFormatToCompressionType(GrGLenum glFormat, SkImage::CompressionType*);
Robert Phillips8043f322019-05-31 08:11:36 -0400288
Robert Phillipsfe18de52019-06-06 17:21:50 -0400289size_t GrGLBytesPerFormat(GrGLenum glFormat);
290
Robert Phillipsf209e882019-06-25 15:59:50 -0400291bool GrGLFormatIsSupported(GrGLenum format);
292
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000293#endif