blob: d820b9d498b31f2c683676e0c259cfc1f97c8667 [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"
13#include "src/gpu/GrStencilSettings.h"
14#include "src/gpu/gl/GrGLDefines.h"
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +000015
commit-bot@chromium.org215a6822013-09-05 18:28:42 +000016class SkMatrix;
17
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +000018////////////////////////////////////////////////////////////////////////////////
19
20typedef uint32_t GrGLVersion;
21typedef uint32_t GrGLSLVersion;
Brian Salomon9a544bc2018-04-04 16:12:31 -040022typedef uint64_t GrGLDriverVersion;
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +000023
Brian Salomon9a544bc2018-04-04 16:12:31 -040024#define GR_GL_VER(major, minor) ((static_cast<uint32_t>(major) << 16) | \
25 static_cast<uint32_t>(minor))
26#define GR_GLSL_VER(major, minor) ((static_cast<uint32_t>(major) << 16) | \
27 static_cast<uint32_t>(minor))
28#define GR_GL_DRIVER_VER(major, minor, point) ((static_cast<uint64_t>(major) << 32) | \
29 (static_cast<uint64_t>(minor) << 16) | \
30 static_cast<uint64_t>(point))
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +000031
32#define GR_GL_INVALID_VER GR_GL_VER(0, 0)
cdalton1acea862015-06-02 13:05:52 -070033#define GR_GLSL_INVALID_VER GR_GLSL_VER(0, 0)
Brian Salomon9a544bc2018-04-04 16:12:31 -040034#define GR_GL_DRIVER_UNKNOWN_VER GR_GL_DRIVER_VER(0, 0, 0)
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +000035
bsalomon@google.com0b1e4812012-10-23 13:52:43 +000036/**
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000037 * The Vendor and Renderer enum values are lazily updated as required.
bsalomon@google.com0b1e4812012-10-23 13:52:43 +000038 */
39enum GrGLVendor {
bsalomon@google.com96966a52013-02-21 16:34:21 +000040 kARM_GrGLVendor,
Kevin Lubickda2b9f32018-06-05 16:05:58 -040041 kGoogle_GrGLVendor,
bsalomon@google.com3012ded2013-02-22 16:44:04 +000042 kImagination_GrGLVendor,
43 kIntel_GrGLVendor,
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +000044 kQualcomm_GrGLVendor,
bsalomone904c092014-07-17 10:50:59 -070045 kNVIDIA_GrGLVendor,
brianosman131ff132016-06-07 14:22:44 -070046 kATI_GrGLVendor,
bsalomon@google.com3012ded2013-02-22 16:44:04 +000047
48 kOther_GrGLVendor
bsalomon@google.com0b1e4812012-10-23 13:52:43 +000049};
50
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000051enum GrGLRenderer {
Chris Dalton0090ef62018-03-28 17:35:00 -060052 kTegra_PreK1_GrGLRenderer, // Legacy Tegra architecture (pre-K1).
53 kTegra_GrGLRenderer, // Tegra with the same architecture as NVIDIA desktop GPUs (K1+).
bsalomon63b21962014-11-05 07:05:34 -080054 kPowerVR54x_GrGLRenderer,
55 kPowerVRRogue_GrGLRenderer,
bsalomona8fcea02015-02-13 09:00:39 -080056 kAdreno3xx_GrGLRenderer,
Chris Dalton1214be92018-06-28 19:06:27 -060057 kAdreno430_GrGLRenderer,
58 kAdreno4xx_other_GrGLRenderer,
egdaniel7517e452016-09-20 13:00:26 -070059 kAdreno5xx_GrGLRenderer,
bsalomon40170072016-05-05 14:40:03 -070060 kOSMesa_GrGLRenderer,
Kevin Lubickda2b9f32018-06-05 16:05:58 -040061 kGoogleSwiftShader_GrGLRenderer,
Robert Phillipsa2fd62a2017-10-05 12:46:21 -040062 kIntelIrisPro_GrGLRenderer,
Chris Dalton4a6a7322017-10-06 14:28:11 -060063 /** Either HD 4xxx or Iris 4xxx */
64 kIntel4xxx_GrGLRenderer,
Brian Salomon028a9a52017-05-11 11:39:08 -040065 /** Either HD 6xxx or Iris 6xxx */
66 kIntel6xxx_GrGLRenderer,
Chris Dalton1c1391c2018-07-20 12:21:14 -060067 kIntelSandyBridge_GrGLRenderer,
Chris Daltonb70beea2018-07-23 12:17:10 -060068 kIntelBayTrail_GrGLRenderer,
Chris Daltonda40cd22018-04-16 13:19:58 -060069 kIntelSkylake_GrGLRenderer,
Greg Daniel25019172017-10-26 13:32:33 -040070 kGalliumLLVM_GrGLRenderer,
Brian Salomon5fba7ad2018-03-22 10:01:16 -040071 kMali4xx_GrGLRenderer,
Brian Osmanac1e4962017-05-25 11:34:38 -040072 /** T-6xx, T-7xx, or T-8xx */
73 kMaliT_GrGLRenderer,
Robert Phillipsbc712742017-06-02 11:20:37 -040074 kANGLE_GrGLRenderer,
Robert Phillipsdbfecd02017-10-18 15:44:08 -040075
Brian Salomon5fba7ad2018-03-22 10:01:16 -040076 kAMDRadeonHD7xxx_GrGLRenderer, // AMD Radeon HD 7000 Series
77 kAMDRadeonR9M4xx_GrGLRenderer, // AMD Radeon R9 M400 Series
Robert Phillipsdbfecd02017-10-18 15:44:08 -040078
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000079 kOther_GrGLRenderer
80};
81
cdalton1acea862015-06-02 13:05:52 -070082enum GrGLDriver {
83 kMesa_GrGLDriver,
84 kChromium_GrGLDriver,
85 kNVIDIA_GrGLDriver,
cdalton1dd05422015-06-12 09:01:18 -070086 kIntel_GrGLDriver,
bsalomon88c7b982015-07-31 11:20:16 -070087 kANGLE_GrGLDriver,
Kevin Lubickda2b9f32018-06-05 16:05:58 -040088 kSwiftShader_GrGLDriver,
Brian Salomonb52fa022017-06-07 09:42:52 -040089 kQualcomm_GrGLDriver,
cdalton1acea862015-06-02 13:05:52 -070090 kUnknown_GrGLDriver
91};
92
Brian Salomon266ef6d2017-09-22 11:27:42 -040093enum class GrGLANGLEBackend {
94 kUnknown,
95 kD3D9,
96 kD3D11,
97 kOpenGL
98};
99
100enum class GrGLANGLEVendor {
101 kUnknown,
Michael Ludwig8f5aeeb2019-02-01 21:53:11 +0000102 kIntel
Brian Salomon266ef6d2017-09-22 11:27:42 -0400103};
104
Chris Dalton0a94e4c2018-01-18 15:06:50 -0700105enum class GrGLANGLERenderer {
Brian Salomon266ef6d2017-09-22 11:27:42 -0400106 kUnknown,
Chris Dalton1c1391c2018-07-20 12:21:14 -0600107 kSandyBridge,
Chris Dalton0a94e4c2018-01-18 15:06:50 -0700108 kIvyBridge,
109 kSkylake
Brian Salomon266ef6d2017-09-22 11:27:42 -0400110};
111
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000112////////////////////////////////////////////////////////////////////////////////
113
114/**
115 * Some drivers want the var-int arg to be zero-initialized on input.
116 */
117#define GR_GL_INIT_ZERO 0
118#define GR_GL_GetIntegerv(gl, e, p) \
119 do { \
120 *(p) = GR_GL_INIT_ZERO; \
121 GR_GL_CALL(gl, GetIntegerv(e, p)); \
122 } while (0)
123
124#define GR_GL_GetFramebufferAttachmentParameteriv(gl, t, a, pname, p) \
125 do { \
126 *(p) = GR_GL_INIT_ZERO; \
127 GR_GL_CALL(gl, GetFramebufferAttachmentParameteriv(t, a, pname, p)); \
128 } while (0)
129
Greg Daniel81e7bf82017-07-19 14:47:42 -0400130#define GR_GL_GetInternalformativ(gl, t, f, n, s, p) \
131 do { \
132 *(p) = GR_GL_INIT_ZERO; \
133 GR_GL_CALL(gl, GetInternalformativ(t, f, n, s, p)); \
134 } while (0)
135
robertphillips7354a4b2015-12-16 05:08:27 -0800136#define GR_GL_GetNamedFramebufferAttachmentParameteriv(gl, fb, a, pname, p) \
137 do { \
138 *(p) = GR_GL_INIT_ZERO; \
139 GR_GL_CALL(gl, GetNamedFramebufferAttachmentParameteriv(fb, a, pname, p)); \
140 } while (0)
141
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000142#define GR_GL_GetRenderbufferParameteriv(gl, t, pname, p) \
143 do { \
144 *(p) = GR_GL_INIT_ZERO; \
145 GR_GL_CALL(gl, GetRenderbufferParameteriv(t, pname, p)); \
146 } while (0)
bsalomon17168df2014-12-09 09:00:49 -0800147
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000148#define GR_GL_GetTexLevelParameteriv(gl, t, l, pname, p) \
149 do { \
150 *(p) = GR_GL_INIT_ZERO; \
151 GR_GL_CALL(gl, GetTexLevelParameteriv(t, l, pname, p)); \
152 } while (0)
153
bsalomon17168df2014-12-09 09:00:49 -0800154#define GR_GL_GetShaderPrecisionFormat(gl, st, pt, range, precision) \
155 do { \
156 (range)[0] = GR_GL_INIT_ZERO; \
157 (range)[1] = GR_GL_INIT_ZERO; \
158 (*precision) = GR_GL_INIT_ZERO; \
159 GR_GL_CALL(gl, GetShaderPrecisionFormat(st, pt, range, precision)); \
160 } while (0)
161
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000162////////////////////////////////////////////////////////////////////////////////
163
164/**
165 * Helpers for glGetString()
166 */
167
168// these variants assume caller already has a string from glGetString()
169GrGLVersion GrGLGetVersionFromString(const char* versionString);
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000170GrGLStandard GrGLGetStandardInUseFromString(const char* versionString);
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000171GrGLSLVersion GrGLGetGLSLVersionFromString(const char* versionString);
bsalomon@google.com0b1e4812012-10-23 13:52:43 +0000172GrGLVendor GrGLGetVendorFromString(const char* vendorString);
Brian Salomon4470e342018-04-04 14:27:48 -0400173GrGLRenderer GrGLGetRendererFromStrings(const char* rendererString, const GrGLExtensions&);
Brian Salomon266ef6d2017-09-22 11:27:42 -0400174void GrGLGetANGLEInfoFromString(const char* rendererString, GrGLANGLEBackend*,
175 GrGLANGLEVendor*, GrGLANGLERenderer*);
cdalton1acea862015-06-02 13:05:52 -0700176
177void GrGLGetDriverInfo(GrGLStandard standard,
178 GrGLVendor vendor,
179 const char* rendererString,
180 const char* versionString,
181 GrGLDriver* outDriver,
182 GrGLDriverVersion* outVersion);
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000183
184// these variants call glGetString()
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000185GrGLVersion GrGLGetVersion(const GrGLInterface*);
186GrGLSLVersion GrGLGetGLSLVersion(const GrGLInterface*);
bsalomon@google.com0b1e4812012-10-23 13:52:43 +0000187GrGLVendor GrGLGetVendor(const GrGLInterface*);
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +0000188GrGLRenderer GrGLGetRenderer(const GrGLInterface*);
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000189
190/**
191 * Helpers for glGetError()
192 */
193
bsalomon@google.com2717d562012-05-07 19:10:52 +0000194void GrGLCheckErr(const GrGLInterface* gl,
195 const char* location,
196 const char* call);
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000197
bsalomon@google.com2717d562012-05-07 19:10:52 +0000198void GrGLClearErr(const GrGLInterface* gl);
199
200////////////////////////////////////////////////////////////////////////////////
201
202/**
203 * Macros for using GrGLInterface to make GL calls
204 */
205
206// internal macro to conditionally call glGetError based on compile-time and
207// run-time flags.
208#if GR_GL_CHECK_ERROR
209 extern bool gCheckErrorGL;
210 #define GR_GL_CHECK_ERROR_IMPL(IFACE, X) \
211 if (gCheckErrorGL) \
212 GrGLCheckErr(IFACE, GR_FILE_AND_LINE_STR, #X)
213#else
214 #define GR_GL_CHECK_ERROR_IMPL(IFACE, X)
215#endif
216
tfarina38406c82014-10-31 07:11:12 -0700217// internal macro to conditionally log the gl call using SkDebugf based on
bsalomon@google.com2717d562012-05-07 19:10:52 +0000218// compile-time and run-time flags.
219#if GR_GL_LOG_CALLS
220 extern bool gLogCallsGL;
221 #define GR_GL_LOG_CALLS_IMPL(X) \
222 if (gLogCallsGL) \
tfarina38406c82014-10-31 07:11:12 -0700223 SkDebugf(GR_FILE_AND_LINE_STR "GL: " #X "\n")
bsalomon@google.com2717d562012-05-07 19:10:52 +0000224#else
225 #define GR_GL_LOG_CALLS_IMPL(X)
226#endif
227
bsalomon@google.com2717d562012-05-07 19:10:52 +0000228// makes a GL call on the interface and does any error checking and logging
229#define GR_GL_CALL(IFACE, X) \
230 do { \
231 GR_GL_CALL_NOERRCHECK(IFACE, X); \
232 GR_GL_CHECK_ERROR_IMPL(IFACE, X); \
233 } while (false)
234
235// Variant of above that always skips the error check. This is useful when
236// the caller wants to do its own glGetError() call and examine the error value.
237#define GR_GL_CALL_NOERRCHECK(IFACE, X) \
238 do { \
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000239 (IFACE)->fFunctions.f##X; \
bsalomon@google.com2717d562012-05-07 19:10:52 +0000240 GR_GL_LOG_CALLS_IMPL(X); \
241 } while (false)
242
243// same as GR_GL_CALL but stores the return value of the gl call in RET
244#define GR_GL_CALL_RET(IFACE, RET, X) \
245 do { \
246 GR_GL_CALL_RET_NOERRCHECK(IFACE, RET, X); \
247 GR_GL_CHECK_ERROR_IMPL(IFACE, X); \
248 } while (false)
249
250// same as GR_GL_CALL_RET but always skips the error check.
251#define GR_GL_CALL_RET_NOERRCHECK(IFACE, RET, X) \
252 do { \
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000253 (RET) = (IFACE)->fFunctions.f##X; \
bsalomon@google.com2717d562012-05-07 19:10:52 +0000254 GR_GL_LOG_CALLS_IMPL(X); \
255 } while (false)
256
257// call glGetError without doing a redundant error check or logging.
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000258#define GR_GL_GET_ERROR(IFACE) (IFACE)->fFunctions.fGetError()
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000259
cdalton93a379b2016-05-11 13:58:08 -0700260GrGLenum GrToGLStencilFunc(GrStencilTest test);
kkinnunenccdaa042014-08-20 01:36:23 -0700261
Robert Phillips8043f322019-05-31 08:11:36 -0400262/**
263 * Returns true if the format is compressed.
264 */
265bool GrGLFormatIsCompressed(GrGLenum glFormat);
266
267/**
268 * Returns the data size for the given compressed format
269 */
270size_t GrGLFormatCompressedDataSize(GrGLenum glFormat, int width, int height);
271
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000272#endif