xref: /aosp_15_r20/external/skia/src/sksl/SkSLModuleLoader.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1*c8dee2aaSAndroid Build Coastguard Worker /*
2*c8dee2aaSAndroid Build Coastguard Worker  * Copyright 2022 Google LLC
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 #ifndef SKSL_MODULELOADER
9*c8dee2aaSAndroid Build Coastguard Worker #define SKSL_MODULELOADER
10*c8dee2aaSAndroid Build Coastguard Worker 
11*c8dee2aaSAndroid Build Coastguard Worker #include "src/sksl/SkSLBuiltinTypes.h"
12*c8dee2aaSAndroid Build Coastguard Worker #include <memory>
13*c8dee2aaSAndroid Build Coastguard Worker 
14*c8dee2aaSAndroid Build Coastguard Worker namespace SkSL {
15*c8dee2aaSAndroid Build Coastguard Worker 
16*c8dee2aaSAndroid Build Coastguard Worker class Compiler;
17*c8dee2aaSAndroid Build Coastguard Worker struct Module;
18*c8dee2aaSAndroid Build Coastguard Worker class Type;
19*c8dee2aaSAndroid Build Coastguard Worker 
20*c8dee2aaSAndroid Build Coastguard Worker using BuiltinTypePtr = const std::unique_ptr<Type> BuiltinTypes::*;
21*c8dee2aaSAndroid Build Coastguard Worker 
22*c8dee2aaSAndroid Build Coastguard Worker /**
23*c8dee2aaSAndroid Build Coastguard Worker  * Documentation for modules in SkSL: http://go/modules-in-sksl
24*c8dee2aaSAndroid Build Coastguard Worker  * https://docs.google.com/document/d/1P8LkkimNr-nPlxMimUsz3K_7qMM7-tZOxDCWZejPcWg/edit?usp=sharing
25*c8dee2aaSAndroid Build Coastguard Worker  */
26*c8dee2aaSAndroid Build Coastguard Worker class ModuleLoader {
27*c8dee2aaSAndroid Build Coastguard Worker private:
28*c8dee2aaSAndroid Build Coastguard Worker     struct Impl;
29*c8dee2aaSAndroid Build Coastguard Worker     Impl& fModuleLoader;
30*c8dee2aaSAndroid Build Coastguard Worker 
31*c8dee2aaSAndroid Build Coastguard Worker public:
32*c8dee2aaSAndroid Build Coastguard Worker     ModuleLoader(ModuleLoader::Impl&);
33*c8dee2aaSAndroid Build Coastguard Worker     ~ModuleLoader();
34*c8dee2aaSAndroid Build Coastguard Worker 
35*c8dee2aaSAndroid Build Coastguard Worker     // Acquires a mutex-locked reference to the singleton ModuleLoader. When the ModuleLoader is
36*c8dee2aaSAndroid Build Coastguard Worker     // allowed to fall out of scope, the mutex will be released.
37*c8dee2aaSAndroid Build Coastguard Worker     static ModuleLoader Get();
38*c8dee2aaSAndroid Build Coastguard Worker 
39*c8dee2aaSAndroid Build Coastguard Worker     // The built-in types and root module are universal, immutable, and shared by every Compiler.
40*c8dee2aaSAndroid Build Coastguard Worker     // They are created when the ModuleLoader is instantiated and never change.
41*c8dee2aaSAndroid Build Coastguard Worker     const BuiltinTypes& builtinTypes();
42*c8dee2aaSAndroid Build Coastguard Worker     const Module* rootModule();
43*c8dee2aaSAndroid Build Coastguard Worker 
44*c8dee2aaSAndroid Build Coastguard Worker     // These modules are loaded on demand; once loaded, they are kept for the lifetime of the
45*c8dee2aaSAndroid Build Coastguard Worker     // process.
46*c8dee2aaSAndroid Build Coastguard Worker     const Module* loadSharedModule(SkSL::Compiler* compiler);
47*c8dee2aaSAndroid Build Coastguard Worker     const Module* loadGPUModule(SkSL::Compiler* compiler);
48*c8dee2aaSAndroid Build Coastguard Worker     const Module* loadVertexModule(SkSL::Compiler* compiler);
49*c8dee2aaSAndroid Build Coastguard Worker     const Module* loadFragmentModule(SkSL::Compiler* compiler);
50*c8dee2aaSAndroid Build Coastguard Worker     const Module* loadComputeModule(SkSL::Compiler* compiler);
51*c8dee2aaSAndroid Build Coastguard Worker     const Module* loadGraphiteVertexModule(SkSL::Compiler* compiler);
52*c8dee2aaSAndroid Build Coastguard Worker     const Module* loadGraphiteFragmentModule(SkSL::Compiler* compiler);
53*c8dee2aaSAndroid Build Coastguard Worker     const Module* loadGraphiteVertexES2Module(SkSL::Compiler* compiler);
54*c8dee2aaSAndroid Build Coastguard Worker     const Module* loadGraphiteFragmentES2Module(SkSL::Compiler* compiler);
55*c8dee2aaSAndroid Build Coastguard Worker 
56*c8dee2aaSAndroid Build Coastguard Worker     const Module* loadPublicModule(SkSL::Compiler* compiler);
57*c8dee2aaSAndroid Build Coastguard Worker     const Module* loadPrivateRTShaderModule(SkSL::Compiler* compiler);
58*c8dee2aaSAndroid Build Coastguard Worker 
59*c8dee2aaSAndroid Build Coastguard Worker     // This updates an existing Module's symbol table to match Runtime Effect rules. GLSL types like
60*c8dee2aaSAndroid Build Coastguard Worker     // `vec4` are added; SkSL private types like `sampler2D` are replaced with an invalid type.
61*c8dee2aaSAndroid Build Coastguard Worker     void addPublicTypeAliases(const SkSL::Module* module);
62*c8dee2aaSAndroid Build Coastguard Worker 
63*c8dee2aaSAndroid Build Coastguard Worker     // This unloads every module. It's useful primarily for benchmarking purposes.
64*c8dee2aaSAndroid Build Coastguard Worker     void unloadModules();
65*c8dee2aaSAndroid Build Coastguard Worker };
66*c8dee2aaSAndroid Build Coastguard Worker 
67*c8dee2aaSAndroid Build Coastguard Worker }  // namespace SkSL
68*c8dee2aaSAndroid Build Coastguard Worker 
69*c8dee2aaSAndroid Build Coastguard Worker #endif  // SKSL_MODULELOADER
70