blob: 1c13eccfedda43a4dfe4c0d88d549a2f46d5ba84 [file] [log] [blame]
jvanverthcba99b82015-06-24 06:59:57 -07001/*
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
Brian Salomon94efbf52016-11-29 13:43:05 -05008#include "GrShaderCaps.h"
jvanverthcba99b82015-06-24 06:59:57 -07009#include "SkString.h"
Brian Salomon94efbf52016-11-29 13:43:05 -050010#include "../private/GrGLSL.h"
jvanverthcba99b82015-06-24 06:59:57 -070011
12bool GrGLSLSupportsNamedFragmentShaderOutputs(GrGLSLGeneration gen) {
13 switch (gen) {
14 case k110_GrGLSLGeneration:
15 return false;
16 case k130_GrGLSLGeneration:
17 case k140_GrGLSLGeneration:
18 case k150_GrGLSLGeneration:
19 case k330_GrGLSLGeneration:
cdalton33ad7012016-02-22 07:55:44 -080020 case k400_GrGLSLGeneration:
Brian Salomond327e8c2016-11-15 13:26:08 -050021 case k420_GrGLSLGeneration:
jvanverthcba99b82015-06-24 06:59:57 -070022 case k310es_GrGLSLGeneration:
cdalton33ad7012016-02-22 07:55:44 -080023 case k320es_GrGLSLGeneration:
jvanverthcba99b82015-06-24 06:59:57 -070024 return true;
25 }
26 return false;
27}
Brian Salomon1d816b92017-08-17 11:07:59 -040028
Robert Phillips8296e752017-08-25 08:45:21 -040029const char* GrGLSLTypeString(const GrShaderCaps* shaderCaps, GrSLType t) {
30 switch (t) {
31 case kVoid_GrSLType:
32 return "void";
Ethan Nicholasf7b88202017-09-18 14:10:39 -040033 case kHalf_GrSLType:
34 return "half";
35 case kHalf2_GrSLType:
36 return "half2";
37 case kHalf3_GrSLType:
38 return "half3";
39 case kHalf4_GrSLType:
40 return "half4";
Ethan Nicholas8aa45692017-09-20 11:24:15 -040041 case kFloat_GrSLType:
42 return "float";
43 case kFloat2_GrSLType:
44 return "float2";
45 case kFloat3_GrSLType:
46 return "float3";
47 case kFloat4_GrSLType:
48 return "float4";
Ethan Nicholasf7b88202017-09-18 14:10:39 -040049 case kUint2_GrSLType:
Chris Dalton51ebd662017-10-24 16:10:48 -060050 return "uint2";
Ethan Nicholasf7b88202017-09-18 14:10:39 -040051 case kInt2_GrSLType:
Robert Phillips8296e752017-08-25 08:45:21 -040052 return "int2";
Ethan Nicholasf7b88202017-09-18 14:10:39 -040053 case kInt3_GrSLType:
Robert Phillips8296e752017-08-25 08:45:21 -040054 return "int3";
Ethan Nicholasf7b88202017-09-18 14:10:39 -040055 case kInt4_GrSLType:
Robert Phillips8296e752017-08-25 08:45:21 -040056 return "int4";
Ethan Nicholas8aa45692017-09-20 11:24:15 -040057 case kFloat2x2_GrSLType:
58 return "float2x2";
59 case kFloat3x3_GrSLType:
60 return "float3x3";
61 case kFloat4x4_GrSLType:
62 return "float4x4";
Ethan Nicholasf7b88202017-09-18 14:10:39 -040063 case kHalf2x2_GrSLType:
64 return "half2x2";
65 case kHalf3x3_GrSLType:
66 return "half3x3";
67 case kHalf4x4_GrSLType:
68 return "half4x4";
Robert Phillips8296e752017-08-25 08:45:21 -040069 case kTexture2DSampler_GrSLType:
70 return "sampler2D";
71 case kITexture2DSampler_GrSLType:
72 return "isampler2D";
73 case kTextureExternalSampler_GrSLType:
74 return "samplerExternalOES";
75 case kTexture2DRectSampler_GrSLType:
76 return "sampler2DRect";
77 case kBufferSampler_GrSLType:
78 return "samplerBuffer";
79 case kBool_GrSLType:
80 return "bool";
81 case kInt_GrSLType:
82 return "int";
83 case kUint_GrSLType:
84 return "uint";
Ethan Nicholasf7b88202017-09-18 14:10:39 -040085 case kShort_GrSLType:
86 return "short";
Chris Dalton51ebd662017-10-24 16:10:48 -060087 case kShort2_GrSLType:
88 return "short2";
89 case kShort3_GrSLType:
90 return "short3";
91 case kShort4_GrSLType:
92 return "short4";
Ethan Nicholasf7b88202017-09-18 14:10:39 -040093 case kUShort_GrSLType:
94 return "ushort";
Chris Dalton51ebd662017-10-24 16:10:48 -060095 case kUShort2_GrSLType:
96 if (shaderCaps->integerSupport()) {
97 return "ushort2";
98 } else {
99 // uint2 (aka uvec2) isn't supported in GLSL ES 1.00/GLSL 1.20
100 // FIXME: this should be handled by the client code rather than relying on
101 // unconventional ushort2 behavior.
102 return "float2";
103 }
104 case kUShort3_GrSLType:
105 return "ushort3";
106 case kUShort4_GrSLType:
107 return "ushort4";
Robert Phillips8296e752017-08-25 08:45:21 -0400108 case kTexture2D_GrSLType:
109 return "texture2D";
110 case kSampler_GrSLType:
111 return "sampler";
112 case kImageStorage2D_GrSLType:
113 return "image2D";
114 case kIImageStorage2D_GrSLType:
115 return "iimage2D";
116 }
117 SK_ABORT("Unknown shader var type.");
118 return ""; // suppress warning
119}
120
Brian Salomon1d816b92017-08-17 11:07:59 -0400121void GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision p,
122 const GrShaderCaps& shaderCaps,
123 SkString* out) {
124 if (shaderCaps.usesPrecisionModifiers()) {
125 switch (p) {
126 case kHigh_GrSLPrecision:
127 out->append("precision highp float;\n");
128 break;
129 case kMedium_GrSLPrecision:
130 out->append("precision mediump float;\n");
131 break;
132 case kLow_GrSLPrecision:
133 out->append("precision lowp float;\n");
134 break;
135 default:
136 SK_ABORT("Unknown precision value.");
137 }
138 }
139}