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