blob: 4ba31495692f03aa7cbe4244887ebeed97aaf2cb [file] [log] [blame]
tomhudson@google.com086e5352011-12-08 14:44:10 +00001/*
2 * Copyright 2011 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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/gl/GrGLGLSL.h"
9#include "src/gpu/gl/GrGLUtil.h"
tomhudson@google.com086e5352011-12-08 14:44:10 +000010
jvanverthcba99b82015-06-24 06:59:57 -070011bool GrGLGetGLSLGeneration(const GrGLInterface* gl, GrGLSLGeneration* generation) {
bsalomon49f085d2014-09-05 13:34:00 -070012 SkASSERT(generation);
tomhudson@google.com086e5352011-12-08 14:44:10 +000013 GrGLSLVersion ver = GrGLGetGLSLVersion(gl);
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +000014 if (GR_GLSL_INVALID_VER == ver) {
15 return false;
16 }
Brian Osmanca8b07c2019-08-29 10:23:41 -040017
18 // Workaround for a bug on some Adreno 308 devices with Android 9. The driver reports a GL
19 // version of 3.0, and a GLSL version of 3.1. If we use version 310 shaders, the driver reports
20 // that it's not supported. To keep things simple, we pin the GLSL version to the GL version.
21 // Note that GLSL versions have an extra digit on their minor level, so we have to scale up
22 // the GL version's minor revision to get a comparable GLSL version. This logic can easily
23 // create invalid GLSL versions (older GL didn't keep the versions in sync), but the checks
24 // below will further pin the GLSL generation correctly.
25 // https://github.com/flutter/flutter/issues/36130
26 GrGLVersion glVer = GrGLGetVersion(gl);
27 uint32_t glMajor = GR_GL_MAJOR_VER(glVer),
28 glMinor = GR_GL_MINOR_VER(glVer);
29 ver = SkTMin(ver, GR_GLSL_VER(glMajor, 10 * glMinor));
30
Kevin Lubick8aa203c2019-03-19 13:23:10 -040031 if (GR_IS_GR_GL(gl->fStandard)) {
32 SkASSERT(ver >= GR_GLSL_VER(1,10));
33 if (ver >= GR_GLSL_VER(4,20)) {
34 *generation = k420_GrGLSLGeneration;
35 } else if (ver >= GR_GLSL_VER(4,00)) {
36 *generation = k400_GrGLSLGeneration;
37 } else if (ver >= GR_GLSL_VER(3,30)) {
38 *generation = k330_GrGLSLGeneration;
39 } else if (ver >= GR_GLSL_VER(1,50)) {
40 *generation = k150_GrGLSLGeneration;
41 } else if (ver >= GR_GLSL_VER(1,40)) {
42 *generation = k140_GrGLSLGeneration;
43 } else if (ver >= GR_GLSL_VER(1,30)) {
44 *generation = k130_GrGLSLGeneration;
45 } else {
46 *generation = k110_GrGLSLGeneration;
47 }
48 return true;
Kevin Lubick39026282019-03-28 12:46:40 -040049 } else if (GR_IS_GR_GL_ES(gl->fStandard) || GR_IS_GR_WEBGL(gl->fStandard)) {
Kevin Lubick8aa203c2019-03-19 13:23:10 -040050 SkASSERT(ver >= GR_GL_VER(1,00));
51 if (ver >= GR_GLSL_VER(3,20)) {
52 *generation = k320es_GrGLSLGeneration;
53 } else if (ver >= GR_GLSL_VER(3,10)) {
54 *generation = k310es_GrGLSLGeneration;
55 } else if (ver >= GR_GLSL_VER(3,00)) {
56 *generation = k330_GrGLSLGeneration;
57 } else {
58 *generation = k110_GrGLSLGeneration;
59 }
60 return true;
tomhudson@google.com086e5352011-12-08 14:44:10 +000061 }
Kevin Lubick8aa203c2019-03-19 13:23:10 -040062 SK_ABORT("Unknown GL Standard");
tomhudson@google.com086e5352011-12-08 14:44:10 +000063}