• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 Google LLC
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/sksl/SkSLSharedCompiler.h"
9 
10 #ifdef SK_ENABLE_SKSL
11 
12 namespace SkSL {
13 struct SharedCompiler::Impl {
ImplSkSL::SharedCompiler::Impl14     Impl() {
15         // These caps are configured to apply *no* workarounds. This avoids changes that are
16         // unnecessary (GLSL intrinsic rewrites), or possibly even incorrect.
17         // We may apply other "neutral" transformations to the user's SkSL, including inlining.
18         // Anything determined by the device caps is deferred to the GPU backend. The processor
19         // set produces the final program (including our re-emitted SkSL), and the backend's
20         // compiler resolves any necessary workarounds.
21         fCaps = ShaderCapsFactory::Standalone();
22         fCaps->fBuiltinFMASupport = true;
23         fCaps->fBuiltinDeterminantSupport = true;
24 
25         // SkSL created by the GPU backend is typically parsed, converted to a backend format,
26         // and the IR is immediately discarded. In that situation, it makes sense to use node
27         // pools to accelerate the IR allocations. Here, SkRuntimeEffect instances are often
28         // long-lived (especially those created internally for runtime FPs). In this situation,
29         // we're willing to pay for a slightly longer compile so that we don't waste huge
30         // amounts of memory.
31         fCaps->fUseNodePools = false;
32 
33         fCompiler = new SkSL::Compiler(fCaps.get());
34     }
35 
36     std::unique_ptr<SkSL::ShaderCaps> fCaps;
37     SkSL::Compiler*                   fCompiler;
38 };
39 
40 SharedCompiler::Impl* SharedCompiler::gImpl = nullptr;
41 
SharedCompiler()42 SharedCompiler::SharedCompiler() : fLock(compiler_mutex()) {
43     if (!gImpl) {
44         gImpl = new Impl();
45     }
46 }
47 
operator ->() const48 SkSL::Compiler* SharedCompiler::operator->() const { return gImpl->fCompiler; }
49 
compiler_mutex()50 SkMutex& SharedCompiler::compiler_mutex() {
51     static SkMutex& mutex = *(new SkMutex);
52     return mutex;
53 }
54 
55 }  // namespace SkSL
56 
57 #endif
58