1*c8dee2aaSAndroid Build Coastguard Worker /*
2*c8dee2aaSAndroid Build Coastguard Worker * Copyright 2016 Google Inc.
3*c8dee2aaSAndroid Build Coastguard Worker *
4*c8dee2aaSAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license that can be
5*c8dee2aaSAndroid Build Coastguard Worker * found in the LICENSE file.
6*c8dee2aaSAndroid Build Coastguard Worker */
7*c8dee2aaSAndroid Build Coastguard Worker
8*c8dee2aaSAndroid Build Coastguard Worker #include "src/sksl/SkSLUtil.h"
9*c8dee2aaSAndroid Build Coastguard Worker
10*c8dee2aaSAndroid Build Coastguard Worker #include "src/core/SkSLTypeShared.h"
11*c8dee2aaSAndroid Build Coastguard Worker #include "src/sksl/SkSLBuiltinTypes.h"
12*c8dee2aaSAndroid Build Coastguard Worker #include "src/sksl/SkSLContext.h"
13*c8dee2aaSAndroid Build Coastguard Worker #include "src/sksl/SkSLOutputStream.h"
14*c8dee2aaSAndroid Build Coastguard Worker #include "src/sksl/SkSLStringStream.h"
15*c8dee2aaSAndroid Build Coastguard Worker #include "src/sksl/ir/SkSLType.h"
16*c8dee2aaSAndroid Build Coastguard Worker
17*c8dee2aaSAndroid Build Coastguard Worker #include <string>
18*c8dee2aaSAndroid Build Coastguard Worker
19*c8dee2aaSAndroid Build Coastguard Worker namespace SkSL {
20*c8dee2aaSAndroid Build Coastguard Worker
21*c8dee2aaSAndroid Build Coastguard Worker // TODO: Once Graphite has its own GPU-caps system, SK_GRAPHITE should get its own mode.
22*c8dee2aaSAndroid Build Coastguard Worker // At the moment, it either mimics what GrShaderCaps reports, or it uses these hard-coded values
23*c8dee2aaSAndroid Build Coastguard Worker // depending on the build.
24*c8dee2aaSAndroid Build Coastguard Worker #if defined(SKSL_STANDALONE) || !defined(SK_GANESH)
MakeShaderCaps()25*c8dee2aaSAndroid Build Coastguard Worker std::unique_ptr<ShaderCaps> ShaderCapsFactory::MakeShaderCaps() {
26*c8dee2aaSAndroid Build Coastguard Worker std::unique_ptr<ShaderCaps> standalone = std::make_unique<ShaderCaps>();
27*c8dee2aaSAndroid Build Coastguard Worker standalone->fShaderDerivativeSupport = true;
28*c8dee2aaSAndroid Build Coastguard Worker standalone->fExplicitTextureLodSupport = true;
29*c8dee2aaSAndroid Build Coastguard Worker standalone->fFlatInterpolationSupport = true;
30*c8dee2aaSAndroid Build Coastguard Worker standalone->fNoPerspectiveInterpolationSupport = true;
31*c8dee2aaSAndroid Build Coastguard Worker standalone->fSampleMaskSupport = true;
32*c8dee2aaSAndroid Build Coastguard Worker standalone->fExternalTextureSupport = true;
33*c8dee2aaSAndroid Build Coastguard Worker return standalone;
34*c8dee2aaSAndroid Build Coastguard Worker }
35*c8dee2aaSAndroid Build Coastguard Worker #else
36*c8dee2aaSAndroid Build Coastguard Worker std::unique_ptr<ShaderCaps> ShaderCapsFactory::MakeShaderCaps() {
37*c8dee2aaSAndroid Build Coastguard Worker return std::make_unique<ShaderCaps>();
38*c8dee2aaSAndroid Build Coastguard Worker }
39*c8dee2aaSAndroid Build Coastguard Worker #endif // defined(SKSL_STANDALONE) || !defined(SK_GANESH)
40*c8dee2aaSAndroid Build Coastguard Worker
write_stringstream(const StringStream & s,OutputStream & out)41*c8dee2aaSAndroid Build Coastguard Worker void write_stringstream(const StringStream& s, OutputStream& out) {
42*c8dee2aaSAndroid Build Coastguard Worker out.write(s.str().c_str(), s.str().size());
43*c8dee2aaSAndroid Build Coastguard Worker }
44*c8dee2aaSAndroid Build Coastguard Worker
type_to_sksltype(const Context & context,const Type & type,SkSLType * outType)45*c8dee2aaSAndroid Build Coastguard Worker bool type_to_sksltype(const Context& context, const Type& type, SkSLType* outType) {
46*c8dee2aaSAndroid Build Coastguard Worker // If a new GrSL type is added, this function will need to be updated.
47*c8dee2aaSAndroid Build Coastguard Worker static_assert(kSkSLTypeCount == 41);
48*c8dee2aaSAndroid Build Coastguard Worker
49*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fVoid )) { *outType = SkSLType::kVoid; return true; }
50*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fBool )) { *outType = SkSLType::kBool; return true; }
51*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fBool2 )) { *outType = SkSLType::kBool2; return true; }
52*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fBool3 )) { *outType = SkSLType::kBool3; return true; }
53*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fBool4 )) { *outType = SkSLType::kBool4; return true; }
54*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fShort )) { *outType = SkSLType::kShort; return true; }
55*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fShort2 )) { *outType = SkSLType::kShort2; return true; }
56*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fShort3 )) { *outType = SkSLType::kShort3; return true; }
57*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fShort4 )) { *outType = SkSLType::kShort4; return true; }
58*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fUShort )) { *outType = SkSLType::kUShort; return true; }
59*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fUShort2 )) { *outType = SkSLType::kUShort2; return true; }
60*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fUShort3 )) { *outType = SkSLType::kUShort3; return true; }
61*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fUShort4 )) { *outType = SkSLType::kUShort4; return true; }
62*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fFloat )) { *outType = SkSLType::kFloat; return true; }
63*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fFloat2 )) { *outType = SkSLType::kFloat2; return true; }
64*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fFloat3 )) { *outType = SkSLType::kFloat3; return true; }
65*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fFloat4 )) { *outType = SkSLType::kFloat4; return true; }
66*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fFloat2x2)) { *outType = SkSLType::kFloat2x2; return true; }
67*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fFloat3x3)) { *outType = SkSLType::kFloat3x3; return true; }
68*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fFloat4x4)) { *outType = SkSLType::kFloat4x4; return true; }
69*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fHalf )) { *outType = SkSLType::kHalf; return true; }
70*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fHalf2 )) { *outType = SkSLType::kHalf2; return true; }
71*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fHalf3 )) { *outType = SkSLType::kHalf3; return true; }
72*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fHalf4 )) { *outType = SkSLType::kHalf4; return true; }
73*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fHalf2x2 )) { *outType = SkSLType::kHalf2x2; return true; }
74*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fHalf3x3 )) { *outType = SkSLType::kHalf3x3; return true; }
75*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fHalf4x4 )) { *outType = SkSLType::kHalf4x4; return true; }
76*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fInt )) { *outType = SkSLType::kInt; return true; }
77*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fInt2 )) { *outType = SkSLType::kInt2; return true; }
78*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fInt3 )) { *outType = SkSLType::kInt3; return true; }
79*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fInt4 )) { *outType = SkSLType::kInt4; return true; }
80*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fUInt )) { *outType = SkSLType::kUInt; return true; }
81*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fUInt2 )) { *outType = SkSLType::kUInt2; return true; }
82*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fUInt3 )) { *outType = SkSLType::kUInt3; return true; }
83*c8dee2aaSAndroid Build Coastguard Worker if (type.matches(*context.fTypes.fUInt4 )) { *outType = SkSLType::kUInt4; return true; }
84*c8dee2aaSAndroid Build Coastguard Worker return false;
85*c8dee2aaSAndroid Build Coastguard Worker }
86*c8dee2aaSAndroid Build Coastguard Worker
87*c8dee2aaSAndroid Build Coastguard Worker } // namespace SkSL
88