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