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