bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #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.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 15 | |
commit-bot@chromium.org | 215a682 | 2013-09-05 18:28:42 +0000 | [diff] [blame] | 16 | class SkMatrix; |
| 17 | |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 18 | //////////////////////////////////////////////////////////////////////////////// |
| 19 | |
| 20 | typedef uint32_t GrGLVersion; |
| 21 | typedef uint32_t GrGLSLVersion; |
Brian Salomon | 9a544bc | 2018-04-04 16:12:31 -0400 | [diff] [blame] | 22 | typedef uint64_t GrGLDriverVersion; |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 23 | |
Brian Salomon | 9a544bc | 2018-04-04 16:12:31 -0400 | [diff] [blame] | 24 | #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.org | f4e67e3 | 2014-04-30 01:26:04 +0000 | [diff] [blame] | 31 | |
| 32 | #define GR_GL_INVALID_VER GR_GL_VER(0, 0) |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 33 | #define GR_GLSL_INVALID_VER GR_GLSL_VER(0, 0) |
Brian Salomon | 9a544bc | 2018-04-04 16:12:31 -0400 | [diff] [blame] | 34 | #define GR_GL_DRIVER_UNKNOWN_VER GR_GL_DRIVER_VER(0, 0, 0) |
commit-bot@chromium.org | f4e67e3 | 2014-04-30 01:26:04 +0000 | [diff] [blame] | 35 | |
bsalomon@google.com | 0b1e481 | 2012-10-23 13:52:43 +0000 | [diff] [blame] | 36 | /** |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 37 | * The Vendor and Renderer enum values are lazily updated as required. |
bsalomon@google.com | 0b1e481 | 2012-10-23 13:52:43 +0000 | [diff] [blame] | 38 | */ |
| 39 | enum GrGLVendor { |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 40 | kARM_GrGLVendor, |
Kevin Lubick | da2b9f3 | 2018-06-05 16:05:58 -0400 | [diff] [blame] | 41 | kGoogle_GrGLVendor, |
bsalomon@google.com | 3012ded | 2013-02-22 16:44:04 +0000 | [diff] [blame] | 42 | kImagination_GrGLVendor, |
| 43 | kIntel_GrGLVendor, |
commit-bot@chromium.org | 7a434a2 | 2013-08-21 14:01:56 +0000 | [diff] [blame] | 44 | kQualcomm_GrGLVendor, |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 45 | kNVIDIA_GrGLVendor, |
brianosman | 131ff13 | 2016-06-07 14:22:44 -0700 | [diff] [blame] | 46 | kATI_GrGLVendor, |
bsalomon@google.com | 3012ded | 2013-02-22 16:44:04 +0000 | [diff] [blame] | 47 | |
| 48 | kOther_GrGLVendor |
bsalomon@google.com | 0b1e481 | 2012-10-23 13:52:43 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 51 | enum GrGLRenderer { |
Chris Dalton | 0090ef6 | 2018-03-28 17:35:00 -0600 | [diff] [blame] | 52 | kTegra_PreK1_GrGLRenderer, // Legacy Tegra architecture (pre-K1). |
| 53 | kTegra_GrGLRenderer, // Tegra with the same architecture as NVIDIA desktop GPUs (K1+). |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 54 | kPowerVR54x_GrGLRenderer, |
| 55 | kPowerVRRogue_GrGLRenderer, |
bsalomon | a8fcea0 | 2015-02-13 09:00:39 -0800 | [diff] [blame] | 56 | kAdreno3xx_GrGLRenderer, |
Chris Dalton | 1214be9 | 2018-06-28 19:06:27 -0600 | [diff] [blame] | 57 | kAdreno430_GrGLRenderer, |
| 58 | kAdreno4xx_other_GrGLRenderer, |
egdaniel | 7517e45 | 2016-09-20 13:00:26 -0700 | [diff] [blame] | 59 | kAdreno5xx_GrGLRenderer, |
bsalomon | 4017007 | 2016-05-05 14:40:03 -0700 | [diff] [blame] | 60 | kOSMesa_GrGLRenderer, |
Kevin Lubick | da2b9f3 | 2018-06-05 16:05:58 -0400 | [diff] [blame] | 61 | kGoogleSwiftShader_GrGLRenderer, |
Robert Phillips | a2fd62a | 2017-10-05 12:46:21 -0400 | [diff] [blame] | 62 | kIntelIrisPro_GrGLRenderer, |
Chris Dalton | 4a6a732 | 2017-10-06 14:28:11 -0600 | [diff] [blame] | 63 | /** Either HD 4xxx or Iris 4xxx */ |
| 64 | kIntel4xxx_GrGLRenderer, |
Brian Salomon | 028a9a5 | 2017-05-11 11:39:08 -0400 | [diff] [blame] | 65 | /** Either HD 6xxx or Iris 6xxx */ |
| 66 | kIntel6xxx_GrGLRenderer, |
Chris Dalton | 1c1391c | 2018-07-20 12:21:14 -0600 | [diff] [blame] | 67 | kIntelSandyBridge_GrGLRenderer, |
Chris Dalton | b70beea | 2018-07-23 12:17:10 -0600 | [diff] [blame] | 68 | kIntelBayTrail_GrGLRenderer, |
Chris Dalton | da40cd2 | 2018-04-16 13:19:58 -0600 | [diff] [blame] | 69 | kIntelSkylake_GrGLRenderer, |
Greg Daniel | 2501917 | 2017-10-26 13:32:33 -0400 | [diff] [blame] | 70 | kGalliumLLVM_GrGLRenderer, |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 71 | kMali4xx_GrGLRenderer, |
Brian Osman | ac1e496 | 2017-05-25 11:34:38 -0400 | [diff] [blame] | 72 | /** T-6xx, T-7xx, or T-8xx */ |
| 73 | kMaliT_GrGLRenderer, |
Robert Phillips | bc71274 | 2017-06-02 11:20:37 -0400 | [diff] [blame] | 74 | kANGLE_GrGLRenderer, |
Robert Phillips | dbfecd0 | 2017-10-18 15:44:08 -0400 | [diff] [blame] | 75 | |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 76 | kAMDRadeonHD7xxx_GrGLRenderer, // AMD Radeon HD 7000 Series |
| 77 | kAMDRadeonR9M4xx_GrGLRenderer, // AMD Radeon R9 M400 Series |
Robert Phillips | dbfecd0 | 2017-10-18 15:44:08 -0400 | [diff] [blame] | 78 | |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 79 | kOther_GrGLRenderer |
| 80 | }; |
| 81 | |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 82 | enum GrGLDriver { |
| 83 | kMesa_GrGLDriver, |
| 84 | kChromium_GrGLDriver, |
| 85 | kNVIDIA_GrGLDriver, |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 86 | kIntel_GrGLDriver, |
bsalomon | 88c7b98 | 2015-07-31 11:20:16 -0700 | [diff] [blame] | 87 | kANGLE_GrGLDriver, |
Kevin Lubick | da2b9f3 | 2018-06-05 16:05:58 -0400 | [diff] [blame] | 88 | kSwiftShader_GrGLDriver, |
Brian Salomon | b52fa02 | 2017-06-07 09:42:52 -0400 | [diff] [blame] | 89 | kQualcomm_GrGLDriver, |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 90 | kUnknown_GrGLDriver |
| 91 | }; |
| 92 | |
Brian Salomon | 266ef6d | 2017-09-22 11:27:42 -0400 | [diff] [blame] | 93 | enum class GrGLANGLEBackend { |
| 94 | kUnknown, |
| 95 | kD3D9, |
| 96 | kD3D11, |
| 97 | kOpenGL |
| 98 | }; |
| 99 | |
| 100 | enum class GrGLANGLEVendor { |
| 101 | kUnknown, |
Michael Ludwig | 8f5aeeb | 2019-02-01 21:53:11 +0000 | [diff] [blame] | 102 | kIntel |
Brian Salomon | 266ef6d | 2017-09-22 11:27:42 -0400 | [diff] [blame] | 103 | }; |
| 104 | |
Chris Dalton | 0a94e4c | 2018-01-18 15:06:50 -0700 | [diff] [blame] | 105 | enum class GrGLANGLERenderer { |
Brian Salomon | 266ef6d | 2017-09-22 11:27:42 -0400 | [diff] [blame] | 106 | kUnknown, |
Chris Dalton | 1c1391c | 2018-07-20 12:21:14 -0600 | [diff] [blame] | 107 | kSandyBridge, |
Chris Dalton | 0a94e4c | 2018-01-18 15:06:50 -0700 | [diff] [blame] | 108 | kIvyBridge, |
| 109 | kSkylake |
Brian Salomon | 266ef6d | 2017-09-22 11:27:42 -0400 | [diff] [blame] | 110 | }; |
| 111 | |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 112 | //////////////////////////////////////////////////////////////////////////////// |
| 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 Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 130 | #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 | |
robertphillips | 7354a4b | 2015-12-16 05:08:27 -0800 | [diff] [blame] | 136 | #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.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 142 | #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) |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 147 | |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 148 | #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 | |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 154 | #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.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 162 | //////////////////////////////////////////////////////////////////////////////// |
| 163 | |
| 164 | /** |
| 165 | * Helpers for glGetString() |
| 166 | */ |
| 167 | |
| 168 | // these variants assume caller already has a string from glGetString() |
| 169 | GrGLVersion GrGLGetVersionFromString(const char* versionString); |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 170 | GrGLStandard GrGLGetStandardInUseFromString(const char* versionString); |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 171 | GrGLSLVersion GrGLGetGLSLVersionFromString(const char* versionString); |
bsalomon@google.com | 0b1e481 | 2012-10-23 13:52:43 +0000 | [diff] [blame] | 172 | GrGLVendor GrGLGetVendorFromString(const char* vendorString); |
Brian Salomon | 4470e34 | 2018-04-04 14:27:48 -0400 | [diff] [blame] | 173 | GrGLRenderer GrGLGetRendererFromStrings(const char* rendererString, const GrGLExtensions&); |
Brian Salomon | 266ef6d | 2017-09-22 11:27:42 -0400 | [diff] [blame] | 174 | void GrGLGetANGLEInfoFromString(const char* rendererString, GrGLANGLEBackend*, |
| 175 | GrGLANGLEVendor*, GrGLANGLERenderer*); |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 176 | |
| 177 | void GrGLGetDriverInfo(GrGLStandard standard, |
| 178 | GrGLVendor vendor, |
| 179 | const char* rendererString, |
| 180 | const char* versionString, |
| 181 | GrGLDriver* outDriver, |
| 182 | GrGLDriverVersion* outVersion); |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 183 | |
| 184 | // these variants call glGetString() |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 185 | GrGLVersion GrGLGetVersion(const GrGLInterface*); |
| 186 | GrGLSLVersion GrGLGetGLSLVersion(const GrGLInterface*); |
bsalomon@google.com | 0b1e481 | 2012-10-23 13:52:43 +0000 | [diff] [blame] | 187 | GrGLVendor GrGLGetVendor(const GrGLInterface*); |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 188 | GrGLRenderer GrGLGetRenderer(const GrGLInterface*); |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 189 | |
| 190 | /** |
| 191 | * Helpers for glGetError() |
| 192 | */ |
| 193 | |
bsalomon@google.com | 2717d56 | 2012-05-07 19:10:52 +0000 | [diff] [blame] | 194 | void GrGLCheckErr(const GrGLInterface* gl, |
| 195 | const char* location, |
| 196 | const char* call); |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 197 | |
bsalomon@google.com | 2717d56 | 2012-05-07 19:10:52 +0000 | [diff] [blame] | 198 | void 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 | |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 217 | // internal macro to conditionally log the gl call using SkDebugf based on |
bsalomon@google.com | 2717d56 | 2012-05-07 19:10:52 +0000 | [diff] [blame] | 218 | // 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) \ |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 223 | SkDebugf(GR_FILE_AND_LINE_STR "GL: " #X "\n") |
bsalomon@google.com | 2717d56 | 2012-05-07 19:10:52 +0000 | [diff] [blame] | 224 | #else |
| 225 | #define GR_GL_LOG_CALLS_IMPL(X) |
| 226 | #endif |
| 227 | |
bsalomon@google.com | 2717d56 | 2012-05-07 19:10:52 +0000 | [diff] [blame] | 228 | // 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.org | c72425a | 2014-01-21 16:09:18 +0000 | [diff] [blame] | 239 | (IFACE)->fFunctions.f##X; \ |
bsalomon@google.com | 2717d56 | 2012-05-07 19:10:52 +0000 | [diff] [blame] | 240 | 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.org | c72425a | 2014-01-21 16:09:18 +0000 | [diff] [blame] | 253 | (RET) = (IFACE)->fFunctions.f##X; \ |
bsalomon@google.com | 2717d56 | 2012-05-07 19:10:52 +0000 | [diff] [blame] | 254 | GR_GL_LOG_CALLS_IMPL(X); \ |
| 255 | } while (false) |
| 256 | |
| 257 | // call glGetError without doing a redundant error check or logging. |
commit-bot@chromium.org | c72425a | 2014-01-21 16:09:18 +0000 | [diff] [blame] | 258 | #define GR_GL_GET_ERROR(IFACE) (IFACE)->fFunctions.fGetError() |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 259 | |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 260 | GrGLenum GrToGLStencilFunc(GrStencilTest test); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 261 | |
Robert Phillips | 8043f32 | 2019-05-31 08:11:36 -0400 | [diff] [blame] | 262 | /** |
| 263 | * Returns true if the format is compressed. |
| 264 | */ |
| 265 | bool GrGLFormatIsCompressed(GrGLenum glFormat); |
| 266 | |
| 267 | /** |
| 268 | * Returns the data size for the given compressed format |
| 269 | */ |
| 270 | size_t GrGLFormatCompressedDataSize(GrGLenum glFormat, int width, int height); |
| 271 | |
Robert Phillips | fe18de5 | 2019-06-06 17:21:50 -0400 | [diff] [blame] | 272 | size_t GrGLBytesPerFormat(GrGLenum glFormat); |
| 273 | |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 274 | #endif |