ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | */ |
Mike Klein | 6ad9909 | 2016-10-26 10:35:22 -0400 | [diff] [blame] | 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/sksl/SkSLCompiler.h" |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 9 | |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 10 | #include <memory> |
John Stiles | b8e010c | 2020-08-11 18:05:39 -0400 | [diff] [blame] | 11 | #include <unordered_set> |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 12 | |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 13 | #include "include/sksl/DSLCore.h" |
Leon Scroggins | b66214e | 2021-02-11 17:14:18 -0500 | [diff] [blame] | 14 | #include "src/core/SkTraceEvent.h" |
John Stiles | f3a28db | 2021-03-10 23:00:47 -0500 | [diff] [blame] | 15 | #include "src/sksl/SkSLConstantFolder.h" |
Ethan Nicholas | dd2fdea | 2021-07-20 15:23:04 -0400 | [diff] [blame] | 16 | #include "src/sksl/SkSLDSLParser.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "src/sksl/SkSLIRGenerator.h" |
Ethan Nicholas | 58014fa | 2021-09-29 17:18:18 -0400 | [diff] [blame] | 18 | #include "src/sksl/SkSLIntrinsicMap.h" |
Brian Osman | 0018501 | 2021-02-04 16:07:11 -0500 | [diff] [blame] | 19 | #include "src/sksl/SkSLOperators.h" |
John Stiles | 270cec2 | 2021-02-17 12:59:36 -0500 | [diff] [blame] | 20 | #include "src/sksl/SkSLProgramSettings.h" |
Ethan Nicholas | c18bb51 | 2020-07-28 14:46:53 -0400 | [diff] [blame] | 21 | #include "src/sksl/SkSLRehydrator.h" |
John Stiles | 3738ef5 | 2021-04-13 10:41:57 -0400 | [diff] [blame] | 22 | #include "src/sksl/codegen/SkSLGLSLCodeGenerator.h" |
John Stiles | 3738ef5 | 2021-04-13 10:41:57 -0400 | [diff] [blame] | 23 | #include "src/sksl/codegen/SkSLMetalCodeGenerator.h" |
| 24 | #include "src/sksl/codegen/SkSLSPIRVCodeGenerator.h" |
| 25 | #include "src/sksl/codegen/SkSLSPIRVtoHLSL.h" |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 26 | #include "src/sksl/dsl/priv/DSLWriter.h" |
| 27 | #include "src/sksl/dsl/priv/DSL_priv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 28 | #include "src/sksl/ir/SkSLExpression.h" |
| 29 | #include "src/sksl/ir/SkSLExpressionStatement.h" |
| 30 | #include "src/sksl/ir/SkSLFunctionCall.h" |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame] | 31 | #include "src/sksl/ir/SkSLLiteral.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 32 | #include "src/sksl/ir/SkSLModifiersDeclaration.h" |
| 33 | #include "src/sksl/ir/SkSLNop.h" |
| 34 | #include "src/sksl/ir/SkSLSymbolTable.h" |
| 35 | #include "src/sksl/ir/SkSLTernaryExpression.h" |
| 36 | #include "src/sksl/ir/SkSLUnresolvedFunction.h" |
| 37 | #include "src/sksl/ir/SkSLVarDeclarations.h" |
Ethan Nicholas | 1780755 | 2021-10-01 09:42:36 -0400 | [diff] [blame] | 38 | #include "src/sksl/transform/SkSLProgramWriter.h" |
John Stiles | 7176637 | 2021-10-06 15:54:55 -0400 | [diff] [blame^] | 39 | #include "src/sksl/transform/SkSLTransform.h" |
John Stiles | e615000 | 2020-10-05 12:03:53 -0400 | [diff] [blame] | 40 | #include "src/utils/SkBitSet.h" |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 41 | |
Ethan Nicholas | b33fa3f | 2020-08-06 13:00:19 -0400 | [diff] [blame] | 42 | #include <fstream> |
| 43 | |
Ethan Nicholas | a11035b | 2019-11-26 16:27:47 -0500 | [diff] [blame] | 44 | #if !defined(SKSL_STANDALONE) & SK_SUPPORT_GPU |
| 45 | #include "include/gpu/GrContextOptions.h" |
| 46 | #include "src/gpu/GrShaderCaps.h" |
| 47 | #endif |
| 48 | |
Ethan Nicholas | a6ae1f7 | 2017-03-16 09:56:54 -0400 | [diff] [blame] | 49 | #ifdef SK_ENABLE_SPIRV_VALIDATION |
| 50 | #include "spirv-tools/libspirv.hpp" |
| 51 | #endif |
| 52 | |
Brian Osman | 3d87e9f | 2020-10-08 11:50:22 -0400 | [diff] [blame] | 53 | #if defined(SKSL_STANDALONE) |
Ethan Nicholas | c18bb51 | 2020-07-28 14:46:53 -0400 | [diff] [blame] | 54 | |
Brian Osman | 3d87e9f | 2020-10-08 11:50:22 -0400 | [diff] [blame] | 55 | // In standalone mode, we load the textual sksl source files. GN generates or copies these files |
| 56 | // to the skslc executable directory. The "data" in this mode is just the filename. |
| 57 | #define MODULE_DATA(name) MakeModulePath("sksl_" #name ".sksl") |
| 58 | |
| 59 | #else |
| 60 | |
| 61 | // At runtime, we load the dehydrated sksl data files. The data is a (pointer, size) pair. |
Ethan Nicholas | c18bb51 | 2020-07-28 14:46:53 -0400 | [diff] [blame] | 62 | #include "src/sksl/generated/sksl_frag.dehydrated.sksl" |
Ethan Nicholas | c18bb51 | 2020-07-28 14:46:53 -0400 | [diff] [blame] | 63 | #include "src/sksl/generated/sksl_gpu.dehydrated.sksl" |
Brian Osman | b06301e | 2020-11-06 11:45:36 -0500 | [diff] [blame] | 64 | #include "src/sksl/generated/sksl_public.dehydrated.sksl" |
Brian Osman | cbb60bd | 2021-04-12 09:49:20 -0400 | [diff] [blame] | 65 | #include "src/sksl/generated/sksl_rt_shader.dehydrated.sksl" |
Ethan Nicholas | c18bb51 | 2020-07-28 14:46:53 -0400 | [diff] [blame] | 66 | #include "src/sksl/generated/sksl_vert.dehydrated.sksl" |
| 67 | |
Brian Osman | 3d87e9f | 2020-10-08 11:50:22 -0400 | [diff] [blame] | 68 | #define MODULE_DATA(name) MakeModuleData(SKSL_INCLUDE_sksl_##name,\ |
| 69 | SKSL_INCLUDE_sksl_##name##_LENGTH) |
Ethan Nicholas | c18bb51 | 2020-07-28 14:46:53 -0400 | [diff] [blame] | 70 | |
| 71 | #endif |
Ethan Nicholas | 0d99766 | 2019-04-08 09:46:01 -0400 | [diff] [blame] | 72 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 73 | namespace SkSL { |
| 74 | |
John Stiles | 7247b48 | 2021-03-08 10:40:35 -0500 | [diff] [blame] | 75 | // These flags allow tools like Viewer or Nanobench to override the compiler's ProgramSettings. |
John Stiles | 2ee4d7a | 2021-03-30 10:30:47 -0400 | [diff] [blame] | 76 | Compiler::OverrideFlag Compiler::sOptimizer = OverrideFlag::kDefault; |
| 77 | Compiler::OverrideFlag Compiler::sInliner = OverrideFlag::kDefault; |
John Stiles | 8ef4d6c | 2021-03-05 16:01:45 -0500 | [diff] [blame] | 78 | |
John Stiles | 47c0a74 | 2021-02-09 09:30:35 -0500 | [diff] [blame] | 79 | using RefKind = VariableReference::RefKind; |
| 80 | |
Brian Osman | 88cda17 | 2020-10-09 12:05:16 -0400 | [diff] [blame] | 81 | class AutoSource { |
| 82 | public: |
Ethan Nicholas | b449fff | 2021-08-04 15:06:37 -0400 | [diff] [blame] | 83 | AutoSource(Compiler* compiler, const char* source) |
John Stiles | a289ac2 | 2021-05-06 07:35:35 -0400 | [diff] [blame] | 84 | : fCompiler(compiler) { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 85 | SkASSERT(!fCompiler->errorReporter().source()); |
| 86 | fCompiler->errorReporter().setSource(source); |
Brian Osman | 88cda17 | 2020-10-09 12:05:16 -0400 | [diff] [blame] | 87 | } |
| 88 | |
John Stiles | a289ac2 | 2021-05-06 07:35:35 -0400 | [diff] [blame] | 89 | ~AutoSource() { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 90 | fCompiler->errorReporter().setSource(nullptr); |
John Stiles | a289ac2 | 2021-05-06 07:35:35 -0400 | [diff] [blame] | 91 | } |
Brian Osman | 88cda17 | 2020-10-09 12:05:16 -0400 | [diff] [blame] | 92 | |
| 93 | Compiler* fCompiler; |
Brian Osman | 88cda17 | 2020-10-09 12:05:16 -0400 | [diff] [blame] | 94 | }; |
| 95 | |
John Stiles | a935c3f | 2021-02-25 10:35:49 -0500 | [diff] [blame] | 96 | class AutoProgramConfig { |
| 97 | public: |
| 98 | AutoProgramConfig(std::shared_ptr<Context>& context, ProgramConfig* config) |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 99 | : fContext(context.get()) |
| 100 | , fOldConfig(fContext->fConfig) { |
John Stiles | a935c3f | 2021-02-25 10:35:49 -0500 | [diff] [blame] | 101 | fContext->fConfig = config; |
| 102 | } |
| 103 | |
| 104 | ~AutoProgramConfig() { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 105 | fContext->fConfig = fOldConfig; |
John Stiles | a935c3f | 2021-02-25 10:35:49 -0500 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | Context* fContext; |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 109 | ProgramConfig* fOldConfig; |
John Stiles | a935c3f | 2021-02-25 10:35:49 -0500 | [diff] [blame] | 110 | }; |
| 111 | |
John Stiles | 10d39d9 | 2021-05-04 16:13:14 -0400 | [diff] [blame] | 112 | class AutoModifiersPool { |
| 113 | public: |
| 114 | AutoModifiersPool(std::shared_ptr<Context>& context, ModifiersPool* modifiersPool) |
| 115 | : fContext(context.get()) { |
| 116 | SkASSERT(!fContext->fModifiersPool); |
| 117 | fContext->fModifiersPool = modifiersPool; |
| 118 | } |
| 119 | |
| 120 | ~AutoModifiersPool() { |
| 121 | fContext->fModifiersPool = nullptr; |
| 122 | } |
| 123 | |
| 124 | Context* fContext; |
| 125 | }; |
| 126 | |
John Stiles | d6a5f449 | 2021-02-11 15:46:11 -0500 | [diff] [blame] | 127 | Compiler::Compiler(const ShaderCapsClass* caps) |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 128 | : fErrorReporter(this) |
John Stiles | 2dda4b6 | 2021-09-16 13:18:10 -0400 | [diff] [blame] | 129 | , fContext(std::make_shared<Context>(fErrorReporter, *caps, fMangler)) |
John Stiles | a47b351 | 2021-05-04 16:15:00 -0400 | [diff] [blame] | 130 | , fInliner(fContext.get()) { |
John Stiles | c1a98b8 | 2021-02-24 13:35:02 -0500 | [diff] [blame] | 131 | SkASSERT(caps); |
John Stiles | b624b72 | 2021-08-13 12:16:13 -0400 | [diff] [blame] | 132 | fRootModule.fSymbols = this->makeRootSymbolTable(); |
| 133 | fPrivateModule.fSymbols = this->makePrivateSymbolTable(fRootModule.fSymbols); |
John Stiles | c1a98b8 | 2021-02-24 13:35:02 -0500 | [diff] [blame] | 134 | fIRGenerator = std::make_unique<IRGenerator>(fContext.get()); |
John Stiles | b624b72 | 2021-08-13 12:16:13 -0400 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | Compiler::~Compiler() {} |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 138 | |
John Stiles | 54e7c05 | 2021-01-11 14:22:36 -0500 | [diff] [blame] | 139 | #define TYPE(t) fContext->fTypes.f ## t .get() |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 140 | |
John Stiles | b624b72 | 2021-08-13 12:16:13 -0400 | [diff] [blame] | 141 | std::shared_ptr<SymbolTable> Compiler::makeRootSymbolTable() { |
Ethan Nicholas | c7774a7 | 2021-08-27 15:34:05 -0400 | [diff] [blame] | 142 | auto rootSymbolTable = std::make_shared<SymbolTable>(*fContext, /*builtin=*/true); |
John Stiles | b624b72 | 2021-08-13 12:16:13 -0400 | [diff] [blame] | 143 | |
Brian Osman | b06301e | 2020-11-06 11:45:36 -0500 | [diff] [blame] | 144 | const SkSL::Symbol* rootTypes[] = { |
| 145 | TYPE(Void), |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 146 | |
Brian Osman | b06301e | 2020-11-06 11:45:36 -0500 | [diff] [blame] | 147 | TYPE( Float), TYPE( Float2), TYPE( Float3), TYPE( Float4), |
| 148 | TYPE( Half), TYPE( Half2), TYPE( Half3), TYPE( Half4), |
| 149 | TYPE( Int), TYPE( Int2), TYPE( Int3), TYPE( Int4), |
John Stiles | 823c504 | 2021-08-17 12:09:00 -0400 | [diff] [blame] | 150 | TYPE( UInt), TYPE( UInt2), TYPE( UInt3), TYPE( UInt4), |
| 151 | TYPE( Short), TYPE( Short2), TYPE( Short3), TYPE( Short4), |
| 152 | TYPE(UShort), TYPE(UShort2), TYPE(UShort3), TYPE(UShort4), |
Brian Osman | b06301e | 2020-11-06 11:45:36 -0500 | [diff] [blame] | 153 | TYPE( Bool), TYPE( Bool2), TYPE( Bool3), TYPE( Bool4), |
Brian Salomon | 2a51de8 | 2016-11-16 12:06:01 -0500 | [diff] [blame] | 154 | |
John Stiles | 823c504 | 2021-08-17 12:09:00 -0400 | [diff] [blame] | 155 | TYPE(Float2x2), TYPE(Float2x3), TYPE(Float2x4), |
| 156 | TYPE(Float3x2), TYPE(Float3x3), TYPE(Float3x4), |
| 157 | TYPE(Float4x2), TYPE(Float4x3), TYPE(Float4x4), |
| 158 | |
| 159 | TYPE(Half2x2), TYPE(Half2x3), TYPE(Half2x4), |
| 160 | TYPE(Half3x2), TYPE(Half3x3), TYPE(Half3x4), |
| 161 | TYPE(Half4x2), TYPE(Half4x3), TYPE(Half4x4), |
Greg Daniel | 64773e6 | 2016-11-22 09:44:03 -0500 | [diff] [blame] | 162 | |
Brian Osman | c63f431 | 2020-12-23 11:44:14 -0500 | [diff] [blame] | 163 | TYPE(SquareMat), TYPE(SquareHMat), |
John Stiles | 823c504 | 2021-08-17 12:09:00 -0400 | [diff] [blame] | 164 | TYPE(Mat), TYPE(HMat), |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 165 | |
John Stiles | 823c504 | 2021-08-17 12:09:00 -0400 | [diff] [blame] | 166 | // TODO(skia:12349): generic short/ushort |
| 167 | TYPE(GenType), TYPE(GenIType), TYPE(GenUType), |
| 168 | TYPE(GenHType), /* (GenSType) (GenUSType) */ |
| 169 | TYPE(GenBType), |
| 170 | |
| 171 | TYPE(Vec), TYPE(IVec), TYPE(UVec), |
| 172 | TYPE(HVec), TYPE(SVec), TYPE(USVec), |
| 173 | TYPE(BVec), |
Brian Osman | b06301e | 2020-11-06 11:45:36 -0500 | [diff] [blame] | 174 | |
Brian Osman | 14d0096 | 2021-04-02 17:04:35 -0400 | [diff] [blame] | 175 | TYPE(ColorFilter), |
| 176 | TYPE(Shader), |
John Stiles | bb2ef92 | 2021-07-26 08:32:07 -0400 | [diff] [blame] | 177 | TYPE(Blender), |
Brian Osman | b06301e | 2020-11-06 11:45:36 -0500 | [diff] [blame] | 178 | }; |
| 179 | |
John Stiles | b624b72 | 2021-08-13 12:16:13 -0400 | [diff] [blame] | 180 | for (const SkSL::Symbol* type : rootTypes) { |
| 181 | rootSymbolTable->addWithoutOwnership(type); |
| 182 | } |
| 183 | |
| 184 | return rootSymbolTable; |
| 185 | } |
| 186 | |
| 187 | std::shared_ptr<SymbolTable> Compiler::makePrivateSymbolTable(std::shared_ptr<SymbolTable> parent) { |
| 188 | auto privateSymbolTable = std::make_shared<SymbolTable>(parent, /*builtin=*/true); |
| 189 | |
Brian Osman | b06301e | 2020-11-06 11:45:36 -0500 | [diff] [blame] | 190 | const SkSL::Symbol* privateTypes[] = { |
| 191 | TYPE(Sampler1D), TYPE(Sampler2D), TYPE(Sampler3D), |
| 192 | TYPE(SamplerExternalOES), |
Brian Osman | b06301e | 2020-11-06 11:45:36 -0500 | [diff] [blame] | 193 | TYPE(Sampler2DRect), |
Brian Osman | b06301e | 2020-11-06 11:45:36 -0500 | [diff] [blame] | 194 | |
| 195 | TYPE(ISampler2D), |
Brian Osman | b06301e | 2020-11-06 11:45:36 -0500 | [diff] [blame] | 196 | TYPE(SubpassInput), TYPE(SubpassInputMS), |
| 197 | |
Brian Osman | b06301e | 2020-11-06 11:45:36 -0500 | [diff] [blame] | 198 | TYPE(Sampler), |
| 199 | TYPE(Texture2D), |
| 200 | }; |
| 201 | |
Brian Osman | b06301e | 2020-11-06 11:45:36 -0500 | [diff] [blame] | 202 | for (const SkSL::Symbol* type : privateTypes) { |
John Stiles | b624b72 | 2021-08-13 12:16:13 -0400 | [diff] [blame] | 203 | privateSymbolTable->addWithoutOwnership(type); |
Brian Osman | b06301e | 2020-11-06 11:45:36 -0500 | [diff] [blame] | 204 | } |
| 205 | |
Brian Osman | 3887a01 | 2020-09-30 13:22:27 -0400 | [diff] [blame] | 206 | // sk_Caps is "builtin", but all references to it are resolved to Settings, so we don't need to |
| 207 | // treat it as builtin (ie, no need to clone it into the Program). |
Ethan Nicholas | 89cfde1 | 2021-09-27 11:20:34 -0400 | [diff] [blame] | 208 | privateSymbolTable->add(std::make_unique<Variable>(/*line=*/-1, |
John Stiles | b624b72 | 2021-08-13 12:16:13 -0400 | [diff] [blame] | 209 | fCoreModifiers.add(Modifiers{}), |
| 210 | "sk_Caps", |
| 211 | fContext->fTypes.fSkCaps.get(), |
| 212 | /*builtin=*/false, |
| 213 | Variable::Storage::kGlobal)); |
Ethan Nicholas | 3605ace | 2016-11-21 15:59:48 -0500 | [diff] [blame] | 214 | |
John Stiles | b624b72 | 2021-08-13 12:16:13 -0400 | [diff] [blame] | 215 | return privateSymbolTable; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 216 | } |
| 217 | |
John Stiles | b624b72 | 2021-08-13 12:16:13 -0400 | [diff] [blame] | 218 | #undef TYPE |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 219 | |
Brian Osman | 5626998 | 2020-11-20 12:38:07 -0500 | [diff] [blame] | 220 | const ParsedModule& Compiler::loadGPUModule() { |
| 221 | if (!fGPUModule.fSymbols) { |
John Stiles | dbd4e6f | 2021-02-16 13:29:15 -0500 | [diff] [blame] | 222 | fGPUModule = this->parseModule(ProgramKind::kFragment, MODULE_DATA(gpu), fPrivateModule); |
Brian Osman | 5626998 | 2020-11-20 12:38:07 -0500 | [diff] [blame] | 223 | } |
| 224 | return fGPUModule; |
| 225 | } |
| 226 | |
| 227 | const ParsedModule& Compiler::loadFragmentModule() { |
| 228 | if (!fFragmentModule.fSymbols) { |
John Stiles | dbd4e6f | 2021-02-16 13:29:15 -0500 | [diff] [blame] | 229 | fFragmentModule = this->parseModule(ProgramKind::kFragment, MODULE_DATA(frag), |
Brian Osman | 5626998 | 2020-11-20 12:38:07 -0500 | [diff] [blame] | 230 | this->loadGPUModule()); |
| 231 | } |
| 232 | return fFragmentModule; |
| 233 | } |
| 234 | |
| 235 | const ParsedModule& Compiler::loadVertexModule() { |
| 236 | if (!fVertexModule.fSymbols) { |
John Stiles | dbd4e6f | 2021-02-16 13:29:15 -0500 | [diff] [blame] | 237 | fVertexModule = this->parseModule(ProgramKind::kVertex, MODULE_DATA(vert), |
Brian Osman | 5626998 | 2020-11-20 12:38:07 -0500 | [diff] [blame] | 238 | this->loadGPUModule()); |
| 239 | } |
| 240 | return fVertexModule; |
| 241 | } |
| 242 | |
Brian Osman | cbb60bd | 2021-04-12 09:49:20 -0400 | [diff] [blame] | 243 | static void add_glsl_type_aliases(SkSL::SymbolTable* symbols, const SkSL::BuiltinTypes& types) { |
| 244 | // Add some aliases to the runtime effect modules so that it's friendlier, and more like GLSL |
| 245 | symbols->addAlias("vec2", types.fFloat2.get()); |
| 246 | symbols->addAlias("vec3", types.fFloat3.get()); |
| 247 | symbols->addAlias("vec4", types.fFloat4.get()); |
| 248 | |
| 249 | symbols->addAlias("ivec2", types.fInt2.get()); |
| 250 | symbols->addAlias("ivec3", types.fInt3.get()); |
| 251 | symbols->addAlias("ivec4", types.fInt4.get()); |
| 252 | |
| 253 | symbols->addAlias("bvec2", types.fBool2.get()); |
| 254 | symbols->addAlias("bvec3", types.fBool3.get()); |
| 255 | symbols->addAlias("bvec4", types.fBool4.get()); |
| 256 | |
| 257 | symbols->addAlias("mat2", types.fFloat2x2.get()); |
| 258 | symbols->addAlias("mat3", types.fFloat3x3.get()); |
| 259 | symbols->addAlias("mat4", types.fFloat4x4.get()); |
| 260 | } |
| 261 | |
Brian Osman | a8b897b | 2021-08-30 16:40:44 -0400 | [diff] [blame] | 262 | const ParsedModule& Compiler::loadPublicModule() { |
| 263 | if (!fPublicModule.fSymbols) { |
| 264 | fPublicModule = this->parseModule(ProgramKind::kGeneric, MODULE_DATA(public), fRootModule); |
| 265 | add_glsl_type_aliases(fPublicModule.fSymbols.get(), fContext->fTypes); |
Brian Osman | cbb60bd | 2021-04-12 09:49:20 -0400 | [diff] [blame] | 266 | } |
Brian Osman | a8b897b | 2021-08-30 16:40:44 -0400 | [diff] [blame] | 267 | return fPublicModule; |
Brian Osman | cbb60bd | 2021-04-12 09:49:20 -0400 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | const ParsedModule& Compiler::loadRuntimeShaderModule() { |
| 271 | if (!fRuntimeShaderModule.fSymbols) { |
| 272 | fRuntimeShaderModule = this->parseModule( |
| 273 | ProgramKind::kRuntimeShader, MODULE_DATA(rt_shader), this->loadPublicModule()); |
Brian Osman | cbb60bd | 2021-04-12 09:49:20 -0400 | [diff] [blame] | 274 | } |
| 275 | return fRuntimeShaderModule; |
| 276 | } |
| 277 | |
John Stiles | dbd4e6f | 2021-02-16 13:29:15 -0500 | [diff] [blame] | 278 | const ParsedModule& Compiler::moduleForProgramKind(ProgramKind kind) { |
Brian Osman | 88cda17 | 2020-10-09 12:05:16 -0400 | [diff] [blame] | 279 | switch (kind) { |
Brian Osman | a8b897b | 2021-08-30 16:40:44 -0400 | [diff] [blame] | 280 | case ProgramKind::kVertex: return this->loadVertexModule(); break; |
| 281 | case ProgramKind::kFragment: return this->loadFragmentModule(); break; |
| 282 | case ProgramKind::kRuntimeColorFilter: return this->loadPublicModule(); break; |
| 283 | case ProgramKind::kRuntimeShader: return this->loadRuntimeShaderModule(); break; |
| 284 | case ProgramKind::kRuntimeBlender: return this->loadPublicModule(); break; |
| 285 | case ProgramKind::kGeneric: return this->loadPublicModule(); break; |
Brian Osman | 88cda17 | 2020-10-09 12:05:16 -0400 | [diff] [blame] | 286 | } |
| 287 | SkUNREACHABLE; |
Ethan Nicholas | c18bb51 | 2020-07-28 14:46:53 -0400 | [diff] [blame] | 288 | } |
| 289 | |
John Stiles | dbd4e6f | 2021-02-16 13:29:15 -0500 | [diff] [blame] | 290 | LoadedModule Compiler::loadModule(ProgramKind kind, |
Brian Osman | 3d87e9f | 2020-10-08 11:50:22 -0400 | [diff] [blame] | 291 | ModuleData data, |
John Stiles | a935c3f | 2021-02-25 10:35:49 -0500 | [diff] [blame] | 292 | std::shared_ptr<SymbolTable> base, |
| 293 | bool dehydrate) { |
| 294 | if (dehydrate) { |
| 295 | // NOTE: This is a workaround. When dehydrating includes, skslc doesn't know which module |
| 296 | // it's preparing, nor what the correct base module is. We can't use 'Root', because many |
| 297 | // GPU intrinsics reference private types, like samplers or textures. Today, 'Private' does |
| 298 | // contain the union of all known types, so this is safe. If we ever have types that only |
| 299 | // exist in 'Public' (for example), this logic needs to be smarter (by choosing the correct |
| 300 | // base for the module we're compiling). |
John Stiles | b624b72 | 2021-08-13 12:16:13 -0400 | [diff] [blame] | 301 | base = fPrivateModule.fSymbols; |
Brian Osman | 3d87e9f | 2020-10-08 11:50:22 -0400 | [diff] [blame] | 302 | } |
John Stiles | a935c3f | 2021-02-25 10:35:49 -0500 | [diff] [blame] | 303 | SkASSERT(base); |
| 304 | |
John Stiles | a47b351 | 2021-05-04 16:15:00 -0400 | [diff] [blame] | 305 | // Put the core-module modifier pool into the context. |
| 306 | AutoModifiersPool autoPool(fContext, &fCoreModifiers); |
John Stiles | 10d39d9 | 2021-05-04 16:13:14 -0400 | [diff] [blame] | 307 | |
John Stiles | a935c3f | 2021-02-25 10:35:49 -0500 | [diff] [blame] | 308 | // Built-in modules always use default program settings. |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 309 | Program::Settings settings; |
| 310 | settings.fReplaceSettings = !dehydrate; |
Brian Osman | 3d87e9f | 2020-10-08 11:50:22 -0400 | [diff] [blame] | 311 | |
| 312 | #if defined(SKSL_STANDALONE) |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 313 | SkASSERT(this->errorCount() == 0); |
Brian Osman | 3d87e9f | 2020-10-08 11:50:22 -0400 | [diff] [blame] | 314 | SkASSERT(data.fPath); |
| 315 | std::ifstream in(data.fPath); |
John Stiles | d51c979 | 2021-03-18 11:40:14 -0400 | [diff] [blame] | 316 | String text{std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>()}; |
Ethan Nicholas | b33fa3f | 2020-08-06 13:00:19 -0400 | [diff] [blame] | 317 | if (in.rdstate()) { |
Brian Osman | 3d87e9f | 2020-10-08 11:50:22 -0400 | [diff] [blame] | 318 | printf("error reading %s\n", data.fPath); |
Ethan Nicholas | b33fa3f | 2020-08-06 13:00:19 -0400 | [diff] [blame] | 319 | abort(); |
| 320 | } |
Brian Osman | 88cda17 | 2020-10-09 12:05:16 -0400 | [diff] [blame] | 321 | ParsedModule baseModule = {base, /*fIntrinsics=*/nullptr}; |
Ethan Nicholas | 051aeb7 | 2021-09-24 16:39:19 -0400 | [diff] [blame] | 322 | LoadedModule result = DSLParser(this, settings, kind, |
| 323 | std::move(text)).moduleInheritingFrom(std::move(baseModule)); |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 324 | if (this->errorCount()) { |
Ethan Nicholas | 8da1e65 | 2019-05-24 11:01:59 -0400 | [diff] [blame] | 325 | printf("Unexpected errors: %s\n", this->fErrorText.c_str()); |
Brian Osman | 3d87e9f | 2020-10-08 11:50:22 -0400 | [diff] [blame] | 326 | SkDEBUGFAILF("%s %s\n", data.fPath, this->fErrorText.c_str()); |
Ethan Nicholas | 8da1e65 | 2019-05-24 11:01:59 -0400 | [diff] [blame] | 327 | } |
Brian Osman | 3d87e9f | 2020-10-08 11:50:22 -0400 | [diff] [blame] | 328 | #else |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 329 | ProgramConfig config; |
John Stiles | c876489 | 2021-10-04 11:56:30 -0400 | [diff] [blame] | 330 | config.fIsBuiltinCode = true; |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 331 | config.fKind = kind; |
| 332 | config.fSettings = settings; |
| 333 | AutoProgramConfig autoConfig(fContext, &config); |
Brian Osman | 3d87e9f | 2020-10-08 11:50:22 -0400 | [diff] [blame] | 334 | SkASSERT(data.fData && (data.fSize != 0)); |
John Stiles | 10d39d9 | 2021-05-04 16:13:14 -0400 | [diff] [blame] | 335 | Rehydrator rehydrator(fContext.get(), base, data.fData, data.fSize); |
Ethan Nicholas | 051aeb7 | 2021-09-24 16:39:19 -0400 | [diff] [blame] | 336 | LoadedModule result = { kind, rehydrator.symbolTable(), rehydrator.elements() }; |
Brian Osman | 3d87e9f | 2020-10-08 11:50:22 -0400 | [diff] [blame] | 337 | #endif |
| 338 | |
Ethan Nicholas | 051aeb7 | 2021-09-24 16:39:19 -0400 | [diff] [blame] | 339 | return result; |
Brian Osman | 3d87e9f | 2020-10-08 11:50:22 -0400 | [diff] [blame] | 340 | } |
| 341 | |
John Stiles | dbd4e6f | 2021-02-16 13:29:15 -0500 | [diff] [blame] | 342 | ParsedModule Compiler::parseModule(ProgramKind kind, ModuleData data, const ParsedModule& base) { |
John Stiles | a935c3f | 2021-02-25 10:35:49 -0500 | [diff] [blame] | 343 | LoadedModule module = this->loadModule(kind, data, base.fSymbols, /*dehydrate=*/false); |
Brian Osman | 0006ad0 | 2020-11-18 15:38:39 -0500 | [diff] [blame] | 344 | this->optimize(module); |
Brian Osman | 3d87e9f | 2020-10-08 11:50:22 -0400 | [diff] [blame] | 345 | |
| 346 | // For modules that just declare (but don't define) intrinsic functions, there will be no new |
| 347 | // program elements. In that case, we can share our parent's intrinsic map: |
Brian Osman | 0006ad0 | 2020-11-18 15:38:39 -0500 | [diff] [blame] | 348 | if (module.fElements.empty()) { |
John Stiles | 10d39d9 | 2021-05-04 16:13:14 -0400 | [diff] [blame] | 349 | return ParsedModule{module.fSymbols, base.fIntrinsics}; |
Brian Osman | 3d87e9f | 2020-10-08 11:50:22 -0400 | [diff] [blame] | 350 | } |
| 351 | |
Ethan Nicholas | 58014fa | 2021-09-29 17:18:18 -0400 | [diff] [blame] | 352 | auto intrinsics = std::make_shared<IntrinsicMap>(base.fIntrinsics.get()); |
Brian Osman | 3d87e9f | 2020-10-08 11:50:22 -0400 | [diff] [blame] | 353 | |
| 354 | // Now, transfer all of the program elements to an intrinsic map. This maps certain types of |
| 355 | // global objects to the declaring ProgramElement. |
Brian Osman | 0006ad0 | 2020-11-18 15:38:39 -0500 | [diff] [blame] | 356 | for (std::unique_ptr<ProgramElement>& element : module.fElements) { |
Brian Osman | 3d87e9f | 2020-10-08 11:50:22 -0400 | [diff] [blame] | 357 | switch (element->kind()) { |
| 358 | case ProgramElement::Kind::kFunction: { |
| 359 | const FunctionDefinition& f = element->as<FunctionDefinition>(); |
Ethan Nicholas | 0a5d096 | 2020-10-14 13:33:18 -0400 | [diff] [blame] | 360 | SkASSERT(f.declaration().isBuiltin()); |
| 361 | intrinsics->insertOrDie(f.declaration().description(), std::move(element)); |
Brian Osman | 3d87e9f | 2020-10-08 11:50:22 -0400 | [diff] [blame] | 362 | break; |
| 363 | } |
John Stiles | 569249b | 2020-11-03 12:18:22 -0500 | [diff] [blame] | 364 | case ProgramElement::Kind::kFunctionPrototype: { |
| 365 | // These are already in the symbol table. |
| 366 | break; |
| 367 | } |
Brian Osman | 3d87e9f | 2020-10-08 11:50:22 -0400 | [diff] [blame] | 368 | case ProgramElement::Kind::kGlobalVar: { |
Ethan Nicholas | c51f33e | 2020-10-13 13:49:44 -0400 | [diff] [blame] | 369 | const GlobalVarDeclaration& global = element->as<GlobalVarDeclaration>(); |
| 370 | const Variable& var = global.declaration()->as<VarDeclaration>().var(); |
| 371 | SkASSERT(var.isBuiltin()); |
Ethan Nicholas | d2e0960 | 2021-06-10 11:21:59 -0400 | [diff] [blame] | 372 | intrinsics->insertOrDie(String(var.name()), std::move(element)); |
Brian Osman | 3d87e9f | 2020-10-08 11:50:22 -0400 | [diff] [blame] | 373 | break; |
| 374 | } |
| 375 | case ProgramElement::Kind::kInterfaceBlock: { |
Ethan Nicholas | eaf4788 | 2020-10-15 10:10:08 -0400 | [diff] [blame] | 376 | const Variable& var = element->as<InterfaceBlock>().variable(); |
| 377 | SkASSERT(var.isBuiltin()); |
Ethan Nicholas | d2e0960 | 2021-06-10 11:21:59 -0400 | [diff] [blame] | 378 | intrinsics->insertOrDie(String(var.name()), std::move(element)); |
Brian Osman | 3d87e9f | 2020-10-08 11:50:22 -0400 | [diff] [blame] | 379 | break; |
| 380 | } |
| 381 | default: |
| 382 | printf("Unsupported element: %s\n", element->description().c_str()); |
| 383 | SkASSERT(false); |
| 384 | break; |
| 385 | } |
| 386 | } |
| 387 | |
John Stiles | 10d39d9 | 2021-05-04 16:13:14 -0400 | [diff] [blame] | 388 | return ParsedModule{module.fSymbols, std::move(intrinsics)}; |
Ethan Nicholas | 8da1e65 | 2019-05-24 11:01:59 -0400 | [diff] [blame] | 389 | } |
| 390 | |
John Stiles | c876489 | 2021-10-04 11:56:30 -0400 | [diff] [blame] | 391 | std::unique_ptr<Program> Compiler::convertProgram(ProgramKind kind, |
| 392 | String text, |
| 393 | Program::Settings settings) { |
Brian Osman | 7a20b5c | 2021-03-15 16:23:33 -0400 | [diff] [blame] | 394 | TRACE_EVENT0("skia.shaders", "SkSL::Compiler::convertProgram"); |
Leon Scroggins | b66214e | 2021-02-11 17:14:18 -0500 | [diff] [blame] | 395 | |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 396 | SkASSERT(!settings.fExternalFunctions || (kind == ProgramKind::kGeneric)); |
Ethan Nicholas | 91164d1 | 2019-05-15 15:29:54 -0400 | [diff] [blame] | 397 | |
John Stiles | 2ee4d7a | 2021-03-30 10:30:47 -0400 | [diff] [blame] | 398 | // Honor our optimization-override flags. |
| 399 | switch (sOptimizer) { |
| 400 | case OverrideFlag::kDefault: |
| 401 | break; |
| 402 | case OverrideFlag::kOff: |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 403 | settings.fOptimize = false; |
John Stiles | 2ee4d7a | 2021-03-30 10:30:47 -0400 | [diff] [blame] | 404 | break; |
| 405 | case OverrideFlag::kOn: |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 406 | settings.fOptimize = true; |
John Stiles | 2ee4d7a | 2021-03-30 10:30:47 -0400 | [diff] [blame] | 407 | break; |
| 408 | } |
| 409 | |
| 410 | switch (sInliner) { |
| 411 | case OverrideFlag::kDefault: |
| 412 | break; |
| 413 | case OverrideFlag::kOff: |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 414 | settings.fInlineThreshold = 0; |
John Stiles | 2ee4d7a | 2021-03-30 10:30:47 -0400 | [diff] [blame] | 415 | break; |
| 416 | case OverrideFlag::kOn: |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 417 | if (settings.fInlineThreshold == 0) { |
| 418 | settings.fInlineThreshold = kDefaultInlineThreshold; |
John Stiles | 2ee4d7a | 2021-03-30 10:30:47 -0400 | [diff] [blame] | 419 | } |
| 420 | break; |
| 421 | } |
John Stiles | 7247b48 | 2021-03-08 10:40:35 -0500 | [diff] [blame] | 422 | |
| 423 | // Disable optimization settings that depend on a parent setting which has been disabled. |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 424 | settings.fInlineThreshold *= (int)settings.fOptimize; |
| 425 | settings.fRemoveDeadFunctions &= settings.fOptimize; |
| 426 | settings.fRemoveDeadVariables &= settings.fOptimize; |
John Stiles | 7247b48 | 2021-03-08 10:40:35 -0500 | [diff] [blame] | 427 | |
John Stiles | addccaf | 2021-08-02 19:03:30 -0400 | [diff] [blame] | 428 | // Runtime effects always allow narrowing conversions. |
| 429 | if (ProgramConfig::IsRuntimeEffect(kind)) { |
| 430 | settings.fAllowNarrowingConversions = true; |
| 431 | } |
| 432 | |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 433 | this->resetErrors(); |
John Stiles | 10d39d9 | 2021-05-04 16:13:14 -0400 | [diff] [blame] | 434 | fInliner.reset(); |
Brian Osman | 88cda17 | 2020-10-09 12:05:16 -0400 | [diff] [blame] | 435 | |
Ethan Nicholas | dd2fdea | 2021-07-20 15:23:04 -0400 | [diff] [blame] | 436 | settings.fDSLMangling = false; |
Ethan Nicholas | 051aeb7 | 2021-09-24 16:39:19 -0400 | [diff] [blame] | 437 | return DSLParser(this, settings, kind, std::move(text)).program(); |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 438 | } |
| 439 | |
Brian Osman | 0006ad0 | 2020-11-18 15:38:39 -0500 | [diff] [blame] | 440 | bool Compiler::optimize(LoadedModule& module) { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 441 | SkASSERT(!this->errorCount()); |
Brian Osman | 0006ad0 | 2020-11-18 15:38:39 -0500 | [diff] [blame] | 442 | |
John Stiles | 270cec2 | 2021-02-17 12:59:36 -0500 | [diff] [blame] | 443 | // Create a temporary program configuration with default settings. |
| 444 | ProgramConfig config; |
John Stiles | c876489 | 2021-10-04 11:56:30 -0400 | [diff] [blame] | 445 | config.fIsBuiltinCode = true; |
John Stiles | 270cec2 | 2021-02-17 12:59:36 -0500 | [diff] [blame] | 446 | config.fKind = module.fKind; |
John Stiles | a935c3f | 2021-02-25 10:35:49 -0500 | [diff] [blame] | 447 | AutoProgramConfig autoConfig(fContext, &config); |
John Stiles | 270cec2 | 2021-02-17 12:59:36 -0500 | [diff] [blame] | 448 | |
John Stiles | d120464 | 2021-02-17 16:30:02 -0500 | [diff] [blame] | 449 | // Reset the Inliner. |
John Stiles | 10d39d9 | 2021-05-04 16:13:14 -0400 | [diff] [blame] | 450 | fInliner.reset(); |
John Stiles | 270cec2 | 2021-02-17 12:59:36 -0500 | [diff] [blame] | 451 | |
| 452 | std::unique_ptr<ProgramUsage> usage = Analysis::GetUsage(module); |
Brian Osman | 0006ad0 | 2020-11-18 15:38:39 -0500 | [diff] [blame] | 453 | |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 454 | while (this->errorCount() == 0) { |
Brian Osman | 0006ad0 | 2020-11-18 15:38:39 -0500 | [diff] [blame] | 455 | // Perform inline-candidate analysis and inline any functions deemed suitable. |
John Stiles | 3ff77f4 | 2021-09-06 22:17:58 -0400 | [diff] [blame] | 456 | if (!this->runInliner(module.fElements, module.fSymbols, usage.get())) { |
Brian Osman | 0006ad0 | 2020-11-18 15:38:39 -0500 | [diff] [blame] | 457 | break; |
| 458 | } |
| 459 | } |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 460 | return this->errorCount() == 0; |
Brian Osman | 0006ad0 | 2020-11-18 15:38:39 -0500 | [diff] [blame] | 461 | } |
| 462 | |
John Stiles | 0bfeae6 | 2021-03-11 09:09:42 -0500 | [diff] [blame] | 463 | bool Compiler::removeDeadFunctions(Program& program, ProgramUsage* usage) { |
| 464 | bool madeChanges = false; |
| 465 | |
| 466 | if (program.fConfig->fSettings.fRemoveDeadFunctions) { |
| 467 | auto isDeadFunction = [&](const ProgramElement* element) { |
| 468 | if (!element->is<FunctionDefinition>()) { |
| 469 | return false; |
| 470 | } |
| 471 | const FunctionDefinition& fn = element->as<FunctionDefinition>(); |
John Stiles | e8da4d2 | 2021-03-24 09:19:45 -0400 | [diff] [blame] | 472 | if (fn.declaration().isMain() || usage->get(fn.declaration()) > 0) { |
John Stiles | 0bfeae6 | 2021-03-11 09:09:42 -0500 | [diff] [blame] | 473 | return false; |
| 474 | } |
| 475 | usage->remove(*element); |
| 476 | madeChanges = true; |
| 477 | return true; |
| 478 | }; |
| 479 | |
| 480 | program.fElements.erase(std::remove_if(program.fElements.begin(), |
| 481 | program.fElements.end(), |
| 482 | [&](const std::unique_ptr<ProgramElement>& element) { |
| 483 | return isDeadFunction(element.get()); |
| 484 | }), |
| 485 | program.fElements.end()); |
| 486 | program.fSharedElements.erase(std::remove_if(program.fSharedElements.begin(), |
| 487 | program.fSharedElements.end(), |
| 488 | isDeadFunction), |
| 489 | program.fSharedElements.end()); |
| 490 | } |
| 491 | return madeChanges; |
| 492 | } |
| 493 | |
| 494 | bool Compiler::removeDeadGlobalVariables(Program& program, ProgramUsage* usage) { |
| 495 | bool madeChanges = false; |
| 496 | |
| 497 | if (program.fConfig->fSettings.fRemoveDeadVariables) { |
| 498 | auto isDeadVariable = [&](const ProgramElement* element) { |
| 499 | if (!element->is<GlobalVarDeclaration>()) { |
| 500 | return false; |
| 501 | } |
| 502 | const GlobalVarDeclaration& global = element->as<GlobalVarDeclaration>(); |
| 503 | const VarDeclaration& varDecl = global.declaration()->as<VarDeclaration>(); |
| 504 | if (!usage->isDead(varDecl.var())) { |
| 505 | return false; |
| 506 | } |
| 507 | madeChanges = true; |
| 508 | return true; |
| 509 | }; |
| 510 | |
| 511 | program.fElements.erase(std::remove_if(program.fElements.begin(), |
| 512 | program.fElements.end(), |
| 513 | [&](const std::unique_ptr<ProgramElement>& element) { |
| 514 | return isDeadVariable(element.get()); |
| 515 | }), |
| 516 | program.fElements.end()); |
| 517 | program.fSharedElements.erase(std::remove_if(program.fSharedElements.begin(), |
| 518 | program.fSharedElements.end(), |
| 519 | isDeadVariable), |
| 520 | program.fSharedElements.end()); |
| 521 | } |
| 522 | return madeChanges; |
| 523 | } |
| 524 | |
John Stiles | 2654187 | 2021-03-16 12:19:54 -0400 | [diff] [blame] | 525 | bool Compiler::removeDeadLocalVariables(Program& program, ProgramUsage* usage) { |
| 526 | class DeadLocalVariableEliminator : public ProgramWriter { |
| 527 | public: |
| 528 | DeadLocalVariableEliminator(const Context& context, ProgramUsage* usage) |
| 529 | : fContext(context) |
| 530 | , fUsage(usage) {} |
| 531 | |
| 532 | using ProgramWriter::visitProgramElement; |
| 533 | |
| 534 | bool visitExpressionPtr(std::unique_ptr<Expression>& expr) override { |
| 535 | // We don't need to look inside expressions at all. |
| 536 | return false; |
| 537 | } |
| 538 | |
| 539 | bool visitStatementPtr(std::unique_ptr<Statement>& stmt) override { |
| 540 | if (stmt->is<VarDeclaration>()) { |
| 541 | VarDeclaration& varDecl = stmt->as<VarDeclaration>(); |
| 542 | const Variable* var = &varDecl.var(); |
| 543 | ProgramUsage::VariableCounts* counts = fUsage->fVariableCounts.find(var); |
| 544 | SkASSERT(counts); |
| 545 | SkASSERT(counts->fDeclared); |
| 546 | if (CanEliminate(var, *counts)) { |
| 547 | if (var->initialValue()) { |
| 548 | // The variable has an initial-value expression, which might have side |
| 549 | // effects. ExpressionStatement::Make will preserve side effects, but |
| 550 | // replaces pure expressions with Nop. |
| 551 | fUsage->remove(stmt.get()); |
| 552 | stmt = ExpressionStatement::Make(fContext, std::move(varDecl.value())); |
| 553 | fUsage->add(stmt.get()); |
| 554 | } else { |
| 555 | // The variable has no initial-value and can be cleanly eliminated. |
| 556 | fUsage->remove(stmt.get()); |
| 557 | stmt = std::make_unique<Nop>(); |
| 558 | } |
| 559 | fMadeChanges = true; |
| 560 | } |
| 561 | return false; |
| 562 | } |
| 563 | return INHERITED::visitStatementPtr(stmt); |
| 564 | } |
| 565 | |
| 566 | static bool CanEliminate(const Variable* var, const ProgramUsage::VariableCounts& counts) { |
| 567 | if (!counts.fDeclared || counts.fRead || var->storage() != VariableStorage::kLocal) { |
| 568 | return false; |
| 569 | } |
| 570 | if (var->initialValue()) { |
| 571 | SkASSERT(counts.fWrite >= 1); |
| 572 | return counts.fWrite == 1; |
| 573 | } else { |
| 574 | return counts.fWrite == 0; |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | bool fMadeChanges = false; |
| 579 | const Context& fContext; |
| 580 | ProgramUsage* fUsage; |
| 581 | |
| 582 | using INHERITED = ProgramWriter; |
| 583 | }; |
| 584 | |
| 585 | DeadLocalVariableEliminator visitor{*fContext, usage}; |
| 586 | |
| 587 | if (program.fConfig->fSettings.fRemoveDeadVariables) { |
| 588 | for (auto& [var, counts] : usage->fVariableCounts) { |
| 589 | if (DeadLocalVariableEliminator::CanEliminate(var, counts)) { |
| 590 | // This program contains at least one dead local variable. |
| 591 | // Scan the program for any dead local variables and eliminate them all. |
| 592 | for (std::unique_ptr<ProgramElement>& pe : program.ownedElements()) { |
| 593 | if (pe->is<FunctionDefinition>()) { |
| 594 | visitor.visitProgramElement(*pe); |
| 595 | } |
| 596 | } |
| 597 | break; |
| 598 | } |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | return visitor.fMadeChanges; |
| 603 | } |
| 604 | |
John Stiles | 25be58e | 2021-05-20 14:38:40 -0400 | [diff] [blame] | 605 | void Compiler::removeUnreachableCode(Program& program, ProgramUsage* usage) { |
John Stiles | 25be58e | 2021-05-20 14:38:40 -0400 | [diff] [blame] | 606 | for (std::unique_ptr<ProgramElement>& pe : program.ownedElements()) { |
| 607 | if (pe->is<FunctionDefinition>()) { |
John Stiles | 7176637 | 2021-10-06 15:54:55 -0400 | [diff] [blame^] | 608 | Transform::EliminateUnreachableCode(pe->as<FunctionDefinition>().body(), usage); |
John Stiles | 25be58e | 2021-05-20 14:38:40 -0400 | [diff] [blame] | 609 | } |
| 610 | } |
| 611 | } |
| 612 | |
Ethan Nicholas | 0054311 | 2018-07-31 09:44:36 -0400 | [diff] [blame] | 613 | bool Compiler::optimize(Program& program) { |
John Stiles | 7247b48 | 2021-03-08 10:40:35 -0500 | [diff] [blame] | 614 | // The optimizer only needs to run when it is enabled. |
| 615 | if (!program.fConfig->fSettings.fOptimize) { |
| 616 | return true; |
| 617 | } |
| 618 | |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 619 | SkASSERT(!this->errorCount()); |
Brian Osman | 010ce6a | 2020-10-19 16:34:10 -0400 | [diff] [blame] | 620 | ProgramUsage* usage = program.fUsage.get(); |
John Stiles | 7954d6c | 2020-09-01 10:53:02 -0400 | [diff] [blame] | 621 | |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 622 | if (this->errorCount() == 0) { |
John Stiles | 87fc657 | 2021-04-01 14:56:34 +0000 | [diff] [blame] | 623 | // Run the inliner only once; it is expensive! Multiple passes can occasionally shake out |
| 624 | // more wins, but it's diminishing returns. |
John Stiles | 3ff77f4 | 2021-09-06 22:17:58 -0400 | [diff] [blame] | 625 | this->runInliner(program.ownedElements(), program.fSymbols, usage); |
Ethan Nicholas | 34b19c5 | 2020-09-14 11:33:47 -0400 | [diff] [blame] | 626 | |
John Stiles | 8097076 | 2021-09-18 12:42:10 -0400 | [diff] [blame] | 627 | // Unreachable code can confuse some drivers, so it's worth removing. (skia:12012) |
| 628 | this->removeUnreachableCode(program, usage); |
| 629 | |
John Stiles | b666458 | 2021-03-19 09:46:00 -0400 | [diff] [blame] | 630 | while (this->removeDeadFunctions(program, usage)) { |
| 631 | // Removing dead functions may cause more functions to become unreferenced. Try again. |
Ethan Nicholas | 34b19c5 | 2020-09-14 11:33:47 -0400 | [diff] [blame] | 632 | } |
John Stiles | b666458 | 2021-03-19 09:46:00 -0400 | [diff] [blame] | 633 | while (this->removeDeadLocalVariables(program, usage)) { |
| 634 | // Removing dead variables may cause more variables to become unreferenced. Try again. |
| 635 | } |
John Stiles | 25be58e | 2021-05-20 14:38:40 -0400 | [diff] [blame] | 636 | |
Brian Osman | 8c26479 | 2021-07-01 16:41:27 -0400 | [diff] [blame] | 637 | this->removeDeadGlobalVariables(program, usage); |
Ethan Nicholas | 0054311 | 2018-07-31 09:44:36 -0400 | [diff] [blame] | 638 | } |
John Stiles | bb1505f | 2021-02-12 09:17:53 -0500 | [diff] [blame] | 639 | |
John Stiles | 2ecc595 | 2021-09-01 14:41:36 -0400 | [diff] [blame] | 640 | return this->errorCount() == 0; |
| 641 | } |
| 642 | |
John Stiles | 3ff77f4 | 2021-09-06 22:17:58 -0400 | [diff] [blame] | 643 | bool Compiler::runInliner(const std::vector<std::unique_ptr<ProgramElement>>& elements, |
| 644 | std::shared_ptr<SymbolTable> symbols, |
| 645 | ProgramUsage* usage) { |
| 646 | // The program's SymbolTable was taken out of the IRGenerator when the program was bundled, but |
| 647 | // the inliner relies (indirectly) on having a valid SymbolTable in the IRGenerator. |
| 648 | // In particular, inlining can turn a non-optimizable expression like `normalize(myVec)` into |
| 649 | // `normalize(vec2(7))`, which is now optimizable. The optimizer can use DSL to simplify this |
| 650 | // expression--e.g., in the case of normalize, using DSL's Length(). The DSL relies on |
| 651 | // irGenerator.convertIdentifier() to look up `length`. convertIdentifier() needs a valid symbol |
| 652 | // table to find the declaration of `length`. To allow this chain of events to succeed, we |
| 653 | // re-insert the program's symbol table back into the IRGenerator temporarily. |
| 654 | SkASSERT(!fIRGenerator->fSymbolTable); |
| 655 | fIRGenerator->fSymbolTable = symbols; |
| 656 | |
| 657 | bool result = fInliner.analyze(elements, symbols, usage); |
| 658 | |
| 659 | fIRGenerator->fSymbolTable = nullptr; |
| 660 | return result; |
| 661 | } |
| 662 | |
John Stiles | 2ecc595 | 2021-09-01 14:41:36 -0400 | [diff] [blame] | 663 | bool Compiler::finalize(Program& program) { |
| 664 | // Do a pass looking for @if/@switch statements that didn't optimize away, or dangling |
| 665 | // FunctionReference or TypeReference expressions. Report these as errors. |
| 666 | Analysis::VerifyStaticTestsAndExpressions(program); |
| 667 | |
John Stiles | 9d82e61 | 2021-09-03 08:39:54 -0400 | [diff] [blame] | 668 | // Verify that the program conforms to ES2 limitations. |
John Stiles | 2ecc595 | 2021-09-01 14:41:36 -0400 | [diff] [blame] | 669 | if (fContext->fConfig->strictES2Mode() && this->errorCount() == 0) { |
John Stiles | 9d82e61 | 2021-09-03 08:39:54 -0400 | [diff] [blame] | 670 | // Enforce Appendix A, Section 5 of the GLSL ES 1.00 spec -- Indexing. This logic assumes |
| 671 | // that all loops meet the criteria of Section 4, and if they don't, could crash. |
John Stiles | 2ecc595 | 2021-09-01 14:41:36 -0400 | [diff] [blame] | 672 | for (const auto& pe : program.ownedElements()) { |
| 673 | Analysis::ValidateIndexingForES2(*pe, this->errorReporter()); |
| 674 | } |
John Stiles | 9d82e61 | 2021-09-03 08:39:54 -0400 | [diff] [blame] | 675 | // Verify that the program size is reasonable after unrolling and inlining. This also |
| 676 | // issues errors for static recursion and overly-deep function-call chains. |
John Stiles | 61e5e20 | 2021-09-02 09:56:31 -0400 | [diff] [blame] | 677 | Analysis::CheckProgramUnrolledSize(program); |
John Stiles | bb1505f | 2021-02-12 09:17:53 -0500 | [diff] [blame] | 678 | } |
| 679 | |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 680 | return this->errorCount() == 0; |
Ethan Nicholas | 0054311 | 2018-07-31 09:44:36 -0400 | [diff] [blame] | 681 | } |
| 682 | |
Brian Osman | fb32ddf | 2019-06-18 10:14:20 -0400 | [diff] [blame] | 683 | #if defined(SKSL_STANDALONE) || SK_SUPPORT_GPU |
| 684 | |
Ethan Nicholas | 0054311 | 2018-07-31 09:44:36 -0400 | [diff] [blame] | 685 | bool Compiler::toSPIRV(Program& program, OutputStream& out) { |
Brian Osman | 7a20b5c | 2021-03-15 16:23:33 -0400 | [diff] [blame] | 686 | TRACE_EVENT0("skia.shaders", "SkSL::Compiler::toSPIRV"); |
Ethan Nicholas | b449fff | 2021-08-04 15:06:37 -0400 | [diff] [blame] | 687 | AutoSource as(this, program.fSource->c_str()); |
Brian Salomon | d8d85b9 | 2021-07-07 09:41:17 -0400 | [diff] [blame] | 688 | ProgramSettings settings; |
| 689 | settings.fDSLUseMemoryPool = false; |
| 690 | dsl::Start(this, program.fConfig->fKind, settings); |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 691 | dsl::SetErrorReporter(&fErrorReporter); |
Brian Salomon | d8d85b9 | 2021-07-07 09:41:17 -0400 | [diff] [blame] | 692 | dsl::DSLWriter::IRGenerator().fSymbolTable = program.fSymbols; |
Ethan Nicholas | a6ae1f7 | 2017-03-16 09:56:54 -0400 | [diff] [blame] | 693 | #ifdef SK_ENABLE_SPIRV_VALIDATION |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 694 | StringStream buffer; |
Ethan Nicholas | 3abc6c6 | 2021-08-13 11:20:09 -0400 | [diff] [blame] | 695 | SPIRVCodeGenerator cg(fContext.get(), &program, &buffer); |
Ethan Nicholas | a6ae1f7 | 2017-03-16 09:56:54 -0400 | [diff] [blame] | 696 | bool result = cg.generateCode(); |
John Stiles | 270cec2 | 2021-02-17 12:59:36 -0500 | [diff] [blame] | 697 | if (result && program.fConfig->fSettings.fValidateSPIRV) { |
Ethan Nicholas | a6ae1f7 | 2017-03-16 09:56:54 -0400 | [diff] [blame] | 698 | spvtools::SpirvTools tools(SPV_ENV_VULKAN_1_0); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 699 | const String& data = buffer.str(); |
Ethan Nicholas | d9d33c3 | 2018-06-12 11:05:59 -0400 | [diff] [blame] | 700 | SkASSERT(0 == data.size() % 4); |
Brian Osman | 8d09d4a | 2020-11-24 15:51:06 -0500 | [diff] [blame] | 701 | String errors; |
| 702 | auto dumpmsg = [&errors](spv_message_level_t, const char*, const spv_position_t&, |
| 703 | const char* m) { |
| 704 | errors.appendf("SPIR-V validation error: %s\n", m); |
Ethan Nicholas | a6ae1f7 | 2017-03-16 09:56:54 -0400 | [diff] [blame] | 705 | }; |
| 706 | tools.SetMessageConsumer(dumpmsg); |
Brian Osman | 8d09d4a | 2020-11-24 15:51:06 -0500 | [diff] [blame] | 707 | |
| 708 | // Verify that the SPIR-V we produced is valid. At runtime, we will abort() with a message |
| 709 | // explaining the error. In standalone mode (skslc), we will send the message, plus the |
| 710 | // entire disassembled SPIR-V (for easier context & debugging) as *our* error message. |
| 711 | result = tools.Validate((const uint32_t*) data.c_str(), data.size() / 4); |
| 712 | |
| 713 | if (!result) { |
| 714 | #if defined(SKSL_STANDALONE) |
| 715 | // Convert the string-stream to a SPIR-V disassembly. |
| 716 | std::string disassembly; |
| 717 | if (tools.Disassemble((const uint32_t*)data.data(), data.size() / 4, &disassembly)) { |
| 718 | errors.append(disassembly); |
| 719 | } |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 720 | this->errorReporter().error(-1, errors); |
Ethan Nicholas | c973d26 | 2021-09-17 16:10:29 -0400 | [diff] [blame] | 721 | this->errorReporter().reportPendingErrors(PositionInfo()); |
Brian Osman | 8d09d4a | 2020-11-24 15:51:06 -0500 | [diff] [blame] | 722 | #else |
| 723 | SkDEBUGFAILF("%s", errors.c_str()); |
| 724 | #endif |
| 725 | } |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 726 | out.write(data.c_str(), data.size()); |
Ethan Nicholas | a6ae1f7 | 2017-03-16 09:56:54 -0400 | [diff] [blame] | 727 | } |
| 728 | #else |
Ethan Nicholas | 3abc6c6 | 2021-08-13 11:20:09 -0400 | [diff] [blame] | 729 | SPIRVCodeGenerator cg(fContext.get(), &program, &out); |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 730 | bool result = cg.generateCode(); |
Ethan Nicholas | a6ae1f7 | 2017-03-16 09:56:54 -0400 | [diff] [blame] | 731 | #endif |
Brian Salomon | d8d85b9 | 2021-07-07 09:41:17 -0400 | [diff] [blame] | 732 | dsl::End(); |
Ethan Nicholas | ce33f10 | 2016-12-09 17:22:59 -0500 | [diff] [blame] | 733 | return result; |
| 734 | } |
| 735 | |
Ethan Nicholas | 0054311 | 2018-07-31 09:44:36 -0400 | [diff] [blame] | 736 | bool Compiler::toSPIRV(Program& program, String* out) { |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 737 | StringStream buffer; |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 738 | bool result = this->toSPIRV(program, buffer); |
| 739 | if (result) { |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 740 | *out = buffer.str(); |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 741 | } |
| 742 | return result; |
| 743 | } |
| 744 | |
Ethan Nicholas | 0054311 | 2018-07-31 09:44:36 -0400 | [diff] [blame] | 745 | bool Compiler::toGLSL(Program& program, OutputStream& out) { |
Brian Osman | 7a20b5c | 2021-03-15 16:23:33 -0400 | [diff] [blame] | 746 | TRACE_EVENT0("skia.shaders", "SkSL::Compiler::toGLSL"); |
Ethan Nicholas | b449fff | 2021-08-04 15:06:37 -0400 | [diff] [blame] | 747 | AutoSource as(this, program.fSource->c_str()); |
Ethan Nicholas | 3abc6c6 | 2021-08-13 11:20:09 -0400 | [diff] [blame] | 748 | GLSLCodeGenerator cg(fContext.get(), &program, &out); |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 749 | bool result = cg.generateCode(); |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 750 | return result; |
| 751 | } |
| 752 | |
Ethan Nicholas | 0054311 | 2018-07-31 09:44:36 -0400 | [diff] [blame] | 753 | bool Compiler::toGLSL(Program& program, String* out) { |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 754 | StringStream buffer; |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 755 | bool result = this->toGLSL(program, buffer); |
| 756 | if (result) { |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 757 | *out = buffer.str(); |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 758 | } |
| 759 | return result; |
| 760 | } |
| 761 | |
Brian Osman | c024391 | 2020-02-19 15:35:26 -0500 | [diff] [blame] | 762 | bool Compiler::toHLSL(Program& program, String* out) { |
| 763 | String spirv; |
| 764 | if (!this->toSPIRV(program, &spirv)) { |
| 765 | return false; |
| 766 | } |
| 767 | |
| 768 | return SPIRVtoHLSL(spirv, out); |
| 769 | } |
| 770 | |
Ethan Nicholas | 0054311 | 2018-07-31 09:44:36 -0400 | [diff] [blame] | 771 | bool Compiler::toMetal(Program& program, OutputStream& out) { |
Brian Osman | 7a20b5c | 2021-03-15 16:23:33 -0400 | [diff] [blame] | 772 | TRACE_EVENT0("skia.shaders", "SkSL::Compiler::toMetal"); |
Ethan Nicholas | b449fff | 2021-08-04 15:06:37 -0400 | [diff] [blame] | 773 | AutoSource as(this, program.fSource->c_str()); |
Ethan Nicholas | 3abc6c6 | 2021-08-13 11:20:09 -0400 | [diff] [blame] | 774 | MetalCodeGenerator cg(fContext.get(), &program, &out); |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 775 | bool result = cg.generateCode(); |
Ethan Nicholas | cc30577 | 2017-10-13 16:17:45 -0400 | [diff] [blame] | 776 | return result; |
| 777 | } |
| 778 | |
Ethan Nicholas | 0054311 | 2018-07-31 09:44:36 -0400 | [diff] [blame] | 779 | bool Compiler::toMetal(Program& program, String* out) { |
Timothy Liang | b8eeb80 | 2018-07-23 16:46:16 -0400 | [diff] [blame] | 780 | StringStream buffer; |
| 781 | bool result = this->toMetal(program, buffer); |
| 782 | if (result) { |
| 783 | *out = buffer.str(); |
| 784 | } |
| 785 | return result; |
| 786 | } |
| 787 | |
Ethan Nicholas | 2a479a5 | 2020-08-18 16:29:45 -0400 | [diff] [blame] | 788 | #endif // defined(SKSL_STANDALONE) || SK_SUPPORT_GPU |
Brian Osman | 2e29ab5 | 2019-09-20 12:19:11 -0400 | [diff] [blame] | 789 | |
Ethan Nicholas | 3272412 | 2021-09-07 13:49:07 -0400 | [diff] [blame] | 790 | void Compiler::handleError(skstd::string_view msg, PositionInfo pos) { |
Ethan Nicholas | a40ddcd | 2021-08-06 09:17:18 -0400 | [diff] [blame] | 791 | fErrorText += "error: " + (pos.line() >= 1 ? to_string(pos.line()) + ": " : "") + msg + "\n"; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 792 | } |
| 793 | |
Ethan Nicholas | 9504614 | 2021-01-07 10:57:27 -0500 | [diff] [blame] | 794 | String Compiler::errorText(bool showCount) { |
| 795 | if (showCount) { |
| 796 | this->writeErrorCount(); |
| 797 | } |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 798 | String result = fErrorText; |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 799 | this->resetErrors(); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 800 | return result; |
| 801 | } |
| 802 | |
| 803 | void Compiler::writeErrorCount() { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 804 | int count = this->errorCount(); |
| 805 | if (count) { |
| 806 | fErrorText += to_string(count) + " error"; |
| 807 | if (count > 1) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 808 | fErrorText += "s"; |
| 809 | } |
| 810 | fErrorText += "\n"; |
| 811 | } |
| 812 | } |
| 813 | |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 814 | } // namespace SkSL |