tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/gl/GrGLGLSL.h" |
| 9 | #include "src/gpu/gl/GrGLUtil.h" |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 10 | |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 11 | bool GrGLGetGLSLGeneration(const GrGLInterface* gl, GrGLSLGeneration* generation) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 12 | SkASSERT(generation); |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 13 | GrGLSLVersion ver = GrGLGetGLSLVersion(gl); |
commit-bot@chromium.org | f4e67e3 | 2014-04-30 01:26:04 +0000 | [diff] [blame] | 14 | if (GR_GLSL_INVALID_VER == ver) { |
| 15 | return false; |
| 16 | } |
Brian Osman | ca8b07c | 2019-08-29 10:23:41 -0400 | [diff] [blame] | 17 | |
| 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 Lubick | 8aa203c | 2019-03-19 13:23:10 -0400 | [diff] [blame] | 31 | 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 Lubick | 3902628 | 2019-03-28 12:46:40 -0400 | [diff] [blame] | 49 | } else if (GR_IS_GR_GL_ES(gl->fStandard) || GR_IS_GR_WEBGL(gl->fStandard)) { |
Kevin Lubick | 8aa203c | 2019-03-19 13:23:10 -0400 | [diff] [blame] | 50 | 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.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 61 | } |
Kevin Lubick | 8aa203c | 2019-03-19 13:23:10 -0400 | [diff] [blame] | 62 | SK_ABORT("Unknown GL Standard"); |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 63 | } |