blob: 332cdddde9391d653ddffe357aae02c11f7d5ebd [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,
Robert Phillipsa2fd62a2017-10-05 12:46:21 -040063 kIntelIrisPro_GrGLRenderer,
Chris Dalton4a6a7322017-10-06 14:28:11 -060064 /** Either HD 4xxx or Iris 4xxx */
65 kIntel4xxx_GrGLRenderer,
Brian Salomon028a9a52017-05-11 11:39:08 -040066 /** Either HD 6xxx or Iris 6xxx */
67 kIntel6xxx_GrGLRenderer,
Chris Dalton1c1391c2018-07-20 12:21:14 -060068 kIntelSandyBridge_GrGLRenderer,
Chris Daltonb70beea2018-07-23 12:17:10 -060069 kIntelBayTrail_GrGLRenderer,
Chris Daltonda40cd22018-04-16 13:19:58 -060070 kIntelSkylake_GrGLRenderer,
Greg Daniel25019172017-10-26 13:32:33 -040071 kGalliumLLVM_GrGLRenderer,
Brian Salomon5fba7ad2018-03-22 10:01:16 -040072 kMali4xx_GrGLRenderer,
Brian Osmanac1e4962017-05-25 11:34:38 -040073 /** T-6xx, T-7xx, or T-8xx */
74 kMaliT_GrGLRenderer,
Robert Phillipsbc712742017-06-02 11:20:37 -040075 kANGLE_GrGLRenderer,
Robert Phillipsdbfecd02017-10-18 15:44:08 -040076
Brian Salomon5fba7ad2018-03-22 10:01:16 -040077 kAMDRadeonHD7xxx_GrGLRenderer, // AMD Radeon HD 7000 Series
78 kAMDRadeonR9M4xx_GrGLRenderer, // AMD Radeon R9 M400 Series
Robert Phillipsdbfecd02017-10-18 15:44:08 -040079
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000080 kOther_GrGLRenderer
81};
82
cdalton1acea862015-06-02 13:05:52 -070083enum GrGLDriver {
84 kMesa_GrGLDriver,
85 kChromium_GrGLDriver,
86 kNVIDIA_GrGLDriver,
cdalton1dd05422015-06-12 09:01:18 -070087 kIntel_GrGLDriver,
bsalomon88c7b982015-07-31 11:20:16 -070088 kANGLE_GrGLDriver,
Kevin Lubickda2b9f32018-06-05 16:05:58 -040089 kSwiftShader_GrGLDriver,
Brian Salomonb52fa022017-06-07 09:42:52 -040090 kQualcomm_GrGLDriver,
cdalton1acea862015-06-02 13:05:52 -070091 kUnknown_GrGLDriver
92};
93
Brian Salomon266ef6d2017-09-22 11:27:42 -040094enum class GrGLANGLEBackend {
95 kUnknown,
96 kD3D9,
97 kD3D11,
98 kOpenGL
99};
100
101enum class GrGLANGLEVendor {
102 kUnknown,
Michael Ludwig8f5aeeb2019-02-01 21:53:11 +0000103 kIntel
Brian Salomon266ef6d2017-09-22 11:27:42 -0400104};
105
Chris Dalton0a94e4c2018-01-18 15:06:50 -0700106enum class GrGLANGLERenderer {
Brian Salomon266ef6d2017-09-22 11:27:42 -0400107 kUnknown,
Chris Dalton1c1391c2018-07-20 12:21:14 -0600108 kSandyBridge,
Chris Dalton0a94e4c2018-01-18 15:06:50 -0700109 kIvyBridge,
110 kSkylake
Brian Salomon266ef6d2017-09-22 11:27:42 -0400111};
112
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000113////////////////////////////////////////////////////////////////////////////////
114
115/**
116 * Some drivers want the var-int arg to be zero-initialized on input.
117 */
118#define GR_GL_INIT_ZERO 0
119#define GR_GL_GetIntegerv(gl, e, p) \
120 do { \
121 *(p) = GR_GL_INIT_ZERO; \
122 GR_GL_CALL(gl, GetIntegerv(e, p)); \
123 } while (0)
124
125#define GR_GL_GetFramebufferAttachmentParameteriv(gl, t, a, pname, p) \
126 do { \
127 *(p) = GR_GL_INIT_ZERO; \
128 GR_GL_CALL(gl, GetFramebufferAttachmentParameteriv(t, a, pname, p)); \
129 } while (0)
130
Greg Daniel81e7bf82017-07-19 14:47:42 -0400131#define GR_GL_GetInternalformativ(gl, t, f, n, s, p) \
132 do { \
133 *(p) = GR_GL_INIT_ZERO; \
134 GR_GL_CALL(gl, GetInternalformativ(t, f, n, s, p)); \
135 } while (0)
136
robertphillips7354a4b2015-12-16 05:08:27 -0800137#define GR_GL_GetNamedFramebufferAttachmentParameteriv(gl, fb, a, pname, p) \
138 do { \
139 *(p) = GR_GL_INIT_ZERO; \
140 GR_GL_CALL(gl, GetNamedFramebufferAttachmentParameteriv(fb, a, pname, p)); \
141 } while (0)
142
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000143#define GR_GL_GetRenderbufferParameteriv(gl, t, pname, p) \
144 do { \
145 *(p) = GR_GL_INIT_ZERO; \
146 GR_GL_CALL(gl, GetRenderbufferParameteriv(t, pname, p)); \
147 } while (0)
bsalomon17168df2014-12-09 09:00:49 -0800148
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000149#define GR_GL_GetTexLevelParameteriv(gl, t, l, pname, p) \
150 do { \
151 *(p) = GR_GL_INIT_ZERO; \
152 GR_GL_CALL(gl, GetTexLevelParameteriv(t, l, pname, p)); \
153 } while (0)
154
bsalomon17168df2014-12-09 09:00:49 -0800155#define GR_GL_GetShaderPrecisionFormat(gl, st, pt, range, precision) \
156 do { \
157 (range)[0] = GR_GL_INIT_ZERO; \
158 (range)[1] = GR_GL_INIT_ZERO; \
159 (*precision) = GR_GL_INIT_ZERO; \
160 GR_GL_CALL(gl, GetShaderPrecisionFormat(st, pt, range, precision)); \
161 } while (0)
162
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000163////////////////////////////////////////////////////////////////////////////////
164
165/**
166 * Helpers for glGetString()
167 */
168
169// these variants assume caller already has a string from glGetString()
170GrGLVersion GrGLGetVersionFromString(const char* versionString);
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000171GrGLStandard GrGLGetStandardInUseFromString(const char* versionString);
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000172GrGLSLVersion GrGLGetGLSLVersionFromString(const char* versionString);
bsalomon@google.com0b1e4812012-10-23 13:52:43 +0000173GrGLVendor GrGLGetVendorFromString(const char* vendorString);
Brian Salomon4470e342018-04-04 14:27:48 -0400174GrGLRenderer GrGLGetRendererFromStrings(const char* rendererString, const GrGLExtensions&);
Brian Salomon266ef6d2017-09-22 11:27:42 -0400175void GrGLGetANGLEInfoFromString(const char* rendererString, GrGLANGLEBackend*,
176 GrGLANGLEVendor*, GrGLANGLERenderer*);
cdalton1acea862015-06-02 13:05:52 -0700177
178void GrGLGetDriverInfo(GrGLStandard standard,
179 GrGLVendor vendor,
180 const char* rendererString,
181 const char* versionString,
182 GrGLDriver* outDriver,
183 GrGLDriverVersion* outVersion);
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000184
185// these variants call glGetString()
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000186GrGLVersion GrGLGetVersion(const GrGLInterface*);
187GrGLSLVersion GrGLGetGLSLVersion(const GrGLInterface*);
bsalomon@google.com0b1e4812012-10-23 13:52:43 +0000188GrGLVendor GrGLGetVendor(const GrGLInterface*);
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +0000189GrGLRenderer GrGLGetRenderer(const GrGLInterface*);
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000190
191/**
192 * Helpers for glGetError()
193 */
194
bsalomon@google.com2717d562012-05-07 19:10:52 +0000195void GrGLCheckErr(const GrGLInterface* gl,
196 const char* location,
197 const char* call);
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000198
bsalomon@google.com2717d562012-05-07 19:10:52 +0000199void GrGLClearErr(const GrGLInterface* gl);
200
201////////////////////////////////////////////////////////////////////////////////
202
203/**
204 * Macros for using GrGLInterface to make GL calls
205 */
206
207// internal macro to conditionally call glGetError based on compile-time and
208// run-time flags.
209#if GR_GL_CHECK_ERROR
210 extern bool gCheckErrorGL;
211 #define GR_GL_CHECK_ERROR_IMPL(IFACE, X) \
212 if (gCheckErrorGL) \
213 GrGLCheckErr(IFACE, GR_FILE_AND_LINE_STR, #X)
214#else
215 #define GR_GL_CHECK_ERROR_IMPL(IFACE, X)
216#endif
217
tfarina38406c82014-10-31 07:11:12 -0700218// internal macro to conditionally log the gl call using SkDebugf based on
bsalomon@google.com2717d562012-05-07 19:10:52 +0000219// compile-time and run-time flags.
220#if GR_GL_LOG_CALLS
221 extern bool gLogCallsGL;
222 #define GR_GL_LOG_CALLS_IMPL(X) \
223 if (gLogCallsGL) \
tfarina38406c82014-10-31 07:11:12 -0700224 SkDebugf(GR_FILE_AND_LINE_STR "GL: " #X "\n")
bsalomon@google.com2717d562012-05-07 19:10:52 +0000225#else
226 #define GR_GL_LOG_CALLS_IMPL(X)
227#endif
228
bsalomon@google.com2717d562012-05-07 19:10:52 +0000229// makes a GL call on the interface and does any error checking and logging
230#define GR_GL_CALL(IFACE, X) \
231 do { \
232 GR_GL_CALL_NOERRCHECK(IFACE, X); \
233 GR_GL_CHECK_ERROR_IMPL(IFACE, X); \
234 } while (false)
235
236// Variant of above that always skips the error check. This is useful when
237// the caller wants to do its own glGetError() call and examine the error value.
238#define GR_GL_CALL_NOERRCHECK(IFACE, X) \
239 do { \
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000240 (IFACE)->fFunctions.f##X; \
bsalomon@google.com2717d562012-05-07 19:10:52 +0000241 GR_GL_LOG_CALLS_IMPL(X); \
242 } while (false)
243
244// same as GR_GL_CALL but stores the return value of the gl call in RET
245#define GR_GL_CALL_RET(IFACE, RET, X) \
246 do { \
247 GR_GL_CALL_RET_NOERRCHECK(IFACE, RET, X); \
248 GR_GL_CHECK_ERROR_IMPL(IFACE, X); \
249 } while (false)
250
251// same as GR_GL_CALL_RET but always skips the error check.
252#define GR_GL_CALL_RET_NOERRCHECK(IFACE, RET, X) \
253 do { \
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000254 (RET) = (IFACE)->fFunctions.f##X; \
bsalomon@google.com2717d562012-05-07 19:10:52 +0000255 GR_GL_LOG_CALLS_IMPL(X); \
256 } while (false)
257
258// call glGetError without doing a redundant error check or logging.
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +0000259#define GR_GL_GET_ERROR(IFACE) (IFACE)->fFunctions.fGetError()
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000260
cdalton93a379b2016-05-11 13:58:08 -0700261GrGLenum GrToGLStencilFunc(GrStencilTest test);
kkinnunenccdaa042014-08-20 01:36:23 -0700262
Robert Phillips8043f322019-05-31 08:11:36 -0400263/**
264 * Returns true if the format is compressed.
265 */
266bool GrGLFormatIsCompressed(GrGLenum glFormat);
267
268/**
Robert Phillips28a5a432019-06-07 12:46:21 -0400269 * Maps a gl format into the GrCompressed enum.
270 */
271GrCompression GrGLFormat2Compression(GrGLenum glFormat);
272
273/**
Robert Phillips8043f322019-05-31 08:11:36 -0400274 * Returns the data size for the given compressed format
275 */
276size_t GrGLFormatCompressedDataSize(GrGLenum glFormat, int width, int height);
277
Robert Phillipsfe18de52019-06-06 17:21:50 -0400278size_t GrGLBytesPerFormat(GrGLenum glFormat);
279
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +0000280#endif