• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include "src/gpu/ganesh/gl/GrGLGLSL.h"
9 #include "src/gpu/ganesh/gl/GrGLUtil.h"
10 #include "src/sksl/SkSLGLSL.h"
11 
GrGLGetGLSLGeneration(const GrGLDriverInfo & info,SkSL::GLSLGeneration * generation)12 bool GrGLGetGLSLGeneration(const GrGLDriverInfo& info, SkSL::GLSLGeneration* generation) {
13     SkASSERT(generation);
14     // Workaround for a bug on some Adreno 308 devices with Android 9. The driver reports a GL
15     // version of 3.0, and a GLSL version of 3.1. If we use version 310 shaders, the driver reports
16     // that it's not supported. To keep things simple, we pin the GLSL version to the GL version.
17     // Note that GLSL versions have an extra digit on their minor level, so we have to scale up
18     // the GL version's minor revision to get a comparable GLSL version. This logic can easily
19     // create invalid GLSL versions (older GL didn't keep the versions in sync), but the checks
20     // below will further pin the GLSL generation correctly.
21     // https://github.com/flutter/flutter/issues/36130
22     uint32_t glMajor = GR_GL_MAJOR_VER(info.fVersion),
23              glMinor = GR_GL_MINOR_VER(info.fVersion);
24     GrGLSLVersion ver = std::min(info.fGLSLVersion, GR_GLSL_VER(glMajor, 10 * glMinor));
25     if (info.fGLSLVersion == GR_GLSL_INVALID_VER) {
26         return false;
27     }
28 
29     if (GR_IS_GR_GL(info.fStandard)) {
30         SkASSERT(ver >= GR_GLSL_VER(1,10));
31         if (ver >= GR_GLSL_VER(4,20)) {
32             *generation = SkSL::GLSLGeneration::k420;
33         } else if (ver >= GR_GLSL_VER(4,00)) {
34             *generation = SkSL::GLSLGeneration::k400;
35         } else if (ver >= GR_GLSL_VER(3,30)) {
36             *generation = SkSL::GLSLGeneration::k330;
37         } else if (ver >= GR_GLSL_VER(1,50)) {
38             *generation = SkSL::GLSLGeneration::k150;
39         } else if (ver >= GR_GLSL_VER(1,40)) {
40             *generation = SkSL::GLSLGeneration::k140;
41         } else if (ver >= GR_GLSL_VER(1,30)) {
42             *generation = SkSL::GLSLGeneration::k130;
43         } else {
44             *generation = SkSL::GLSLGeneration::k110;
45         }
46         return true;
47     } else if (GR_IS_GR_GL_ES(info.fStandard)) {
48         SkASSERT(ver >= GR_GLSL_VER(1,00));
49         if (ver >= GR_GLSL_VER(3,20)) {
50             *generation = SkSL::GLSLGeneration::k320es;
51         } else if (ver >= GR_GLSL_VER(3,10)) {
52             *generation = SkSL::GLSLGeneration::k310es;
53         } else if (ver >= GR_GLSL_VER(3,00)) {
54             *generation = SkSL::GLSLGeneration::k300es;
55         } else {
56             *generation = SkSL::GLSLGeneration::k100es;
57         }
58         return true;
59     } else if (GR_IS_GR_WEBGL(info.fStandard)) {
60         SkASSERT(ver >= GR_GLSL_VER(1,0));
61         if (ver >= GR_GLSL_VER(2,0)) {
62             *generation = SkSL::GLSLGeneration::k300es;
63         } else {
64             *generation = SkSL::GLSLGeneration::k100es;
65         }
66         return true;
67     }
68     SK_ABORT("Unknown GL Standard");
69 }
70