| 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 |
/** |
| 23 |
* Documentation for modules in SkSL: http://go/modules-in-sksl |
| 24 |
* https://docs.google.com/document/d/1P8LkkimNr-nPlxMimUsz3K_7qMM7-tZOxDCWZejPcWg/edit?usp=sharing |
| 25 |
*/ |
| 26 |
class ModuleLoader { |
| 27 |
private: |
| 28 |
struct Impl; |
| 29 |
Impl& fModuleLoader; |
| 30 |
|
| 31 |
public: |
| 32 |
ModuleLoader(ModuleLoader::Impl&); |
| 33 |
~ModuleLoader(); |
| 34 |
|
| 35 |
// Acquires a mutex-locked reference to the singleton ModuleLoader. When the ModuleLoader is |
| 36 |
// allowed to fall out of scope, the mutex will be released. |
| 37 |
static ModuleLoader Get(); |
| 38 |
|
| 39 |
// The built-in types and root module are universal, immutable, and shared by every Compiler. |
| 40 |
// They are created when the ModuleLoader is instantiated and never change. |
| 41 |
const BuiltinTypes& builtinTypes(); |
| 42 |
const Module* rootModule(); |
| 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 |