Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Member Functions | List of all members
SkSL::ModuleLoader Class Reference

#include <SkSLModuleLoader.h>

Classes

struct  Impl
 

Public Member Functions

 ModuleLoader (ModuleLoader::Impl &)
 
 ~ModuleLoader ()
 
const BuiltinTypesbuiltinTypes ()
 
const ModulerootModule ()
 
const ModuleloadSharedModule (SkSL::Compiler *compiler)
 
const ModuleloadGPUModule (SkSL::Compiler *compiler)
 
const ModuleloadVertexModule (SkSL::Compiler *compiler)
 
const ModuleloadFragmentModule (SkSL::Compiler *compiler)
 
const ModuleloadComputeModule (SkSL::Compiler *compiler)
 
const ModuleloadGraphiteVertexModule (SkSL::Compiler *compiler)
 
const ModuleloadGraphiteFragmentModule (SkSL::Compiler *compiler)
 
const ModuleloadGraphiteVertexES2Module (SkSL::Compiler *compiler)
 
const ModuleloadGraphiteFragmentES2Module (SkSL::Compiler *compiler)
 
const ModuleloadPublicModule (SkSL::Compiler *compiler)
 
const ModuleloadPrivateRTShaderModule (SkSL::Compiler *compiler)
 
void addPublicTypeAliases (const SkSL::Module *module)
 
void unloadModules ()
 

Static Public Member Functions

static ModuleLoader Get ()
 

Detailed Description

Definition at line 22 of file SkSLModuleLoader.h.

Constructor & Destructor Documentation

◆ ModuleLoader()

SkSL::ModuleLoader::ModuleLoader ( ModuleLoader::Impl m)

Definition at line 123 of file SkSLModuleLoader.cpp.

123 : fModuleLoader(m) {
124 fModuleLoader.fMutex.acquire();
125}

◆ ~ModuleLoader()

SkSL::ModuleLoader::~ModuleLoader ( )

Definition at line 127 of file SkSLModuleLoader.cpp.

127 {
128 fModuleLoader.fMutex.release();
129}

Member Function Documentation

◆ addPublicTypeAliases()

void SkSL::ModuleLoader::addPublicTypeAliases ( const SkSL::Module module)

Definition at line 199 of file SkSLModuleLoader.cpp.

199 {
200 const SkSL::BuiltinTypes& types = this->builtinTypes();
201 SymbolTable* symbols = module->fSymbols.get();
202
203 // Add some aliases to the runtime effect modules so that it's friendlier, and more like GLSL.
204 symbols->addWithoutOwnershipOrDie(types.fVec2.get());
205 symbols->addWithoutOwnershipOrDie(types.fVec3.get());
206 symbols->addWithoutOwnershipOrDie(types.fVec4.get());
207
208 symbols->addWithoutOwnershipOrDie(types.fIVec2.get());
209 symbols->addWithoutOwnershipOrDie(types.fIVec3.get());
210 symbols->addWithoutOwnershipOrDie(types.fIVec4.get());
211
212 symbols->addWithoutOwnershipOrDie(types.fUVec2.get());
213 symbols->addWithoutOwnershipOrDie(types.fUVec3.get());
214 symbols->addWithoutOwnershipOrDie(types.fUVec4.get());
215
216 symbols->addWithoutOwnershipOrDie(types.fBVec2.get());
217 symbols->addWithoutOwnershipOrDie(types.fBVec3.get());
218 symbols->addWithoutOwnershipOrDie(types.fBVec4.get());
219
220 symbols->addWithoutOwnershipOrDie(types.fMat2.get());
221 symbols->addWithoutOwnershipOrDie(types.fMat3.get());
222 symbols->addWithoutOwnershipOrDie(types.fMat4.get());
223
224 symbols->addWithoutOwnershipOrDie(types.fMat2x2.get());
225 symbols->addWithoutOwnershipOrDie(types.fMat2x3.get());
226 symbols->addWithoutOwnershipOrDie(types.fMat2x4.get());
227 symbols->addWithoutOwnershipOrDie(types.fMat3x2.get());
228 symbols->addWithoutOwnershipOrDie(types.fMat3x3.get());
229 symbols->addWithoutOwnershipOrDie(types.fMat3x4.get());
230 symbols->addWithoutOwnershipOrDie(types.fMat4x2.get());
231 symbols->addWithoutOwnershipOrDie(types.fMat4x3.get());
232 symbols->addWithoutOwnershipOrDie(types.fMat4x4.get());
233
234 // Hide all the private symbols by aliasing them all to "invalid". This will prevent code from
235 // using built-in names like `sampler2D` as variable names.
236 for (BuiltinTypePtr privateType : kPrivateTypes) {
237 symbols->inject(Type::MakeAliasType((types.*privateType)->name(), *types.fInvalid));
238 }
239}
const std::unique_ptr< Type > fUVec3
const std::unique_ptr< Type > fMat4x4
const std::unique_ptr< Type > fMat4x2
const std::unique_ptr< Type > fUVec2
const std::unique_ptr< Type > fMat2x4
const std::unique_ptr< Type > fMat2
const std::unique_ptr< Type > fBVec2
const std::unique_ptr< Type > fMat4
const std::unique_ptr< Type > fMat4x3
const std::unique_ptr< Type > fMat2x2
const std::unique_ptr< Type > fInvalid
const std::unique_ptr< Type > fBVec3
const std::unique_ptr< Type > fBVec4
const std::unique_ptr< Type > fVec4
const std::unique_ptr< Type > fVec3
const std::unique_ptr< Type > fIVec3
const std::unique_ptr< Type > fIVec4
const std::unique_ptr< Type > fUVec4
const std::unique_ptr< Type > fIVec2
const std::unique_ptr< Type > fMat3
const std::unique_ptr< Type > fMat3x4
const std::unique_ptr< Type > fMat3x3
const std::unique_ptr< Type > fMat2x3
const std::unique_ptr< Type > fMat3x2
const std::unique_ptr< Type > fVec2
const BuiltinTypes & builtinTypes()
static std::unique_ptr< Type > MakeAliasType(std::string_view name, const Type &targetType)
const std::unique_ptr< Type > BuiltinTypes::* BuiltinTypePtr
static constexpr BuiltinTypePtr kPrivateTypes[]
std::unique_ptr< SymbolTable > fSymbols
Definition: SkSLCompiler.h:58

◆ builtinTypes()

const BuiltinTypes & SkSL::ModuleLoader::builtinTypes ( )

Definition at line 191 of file SkSLModuleLoader.cpp.

191 {
192 return fModuleLoader.fBuiltinTypes;
193}
const BuiltinTypes fBuiltinTypes

◆ Get()

ModuleLoader SkSL::ModuleLoader::Get ( )
static

Definition at line 118 of file SkSLModuleLoader.cpp.

118 {
119 static SkNoDestructor<ModuleLoader::Impl> sModuleLoaderImpl;
120 return ModuleLoader(*sModuleLoaderImpl);
121}
ModuleLoader(ModuleLoader::Impl &)

◆ loadComputeModule()

const Module * SkSL::ModuleLoader::loadComputeModule ( SkSL::Compiler compiler)

Definition at line 308 of file SkSLModuleLoader.cpp.

308 {
309 if (!fModuleLoader.fComputeModule) {
310 const Module* gpuModule = this->loadGPUModule(compiler);
313 MODULE_DATA(sksl_compute),
314 gpuModule);
315 }
316 return fModuleLoader.fComputeModule.get();
317}
#define MODULE_DATA(name)
const Module * loadGPUModule(SkSL::Compiler *compiler)
static std::unique_ptr< Module > compile_and_shrink(SkSL::Compiler *compiler, ProgramKind kind, const char *moduleName, std::string moduleSource, const Module *parent)
std::unique_ptr< const Module > fComputeModule

◆ loadFragmentModule()

const Module * SkSL::ModuleLoader::loadFragmentModule ( SkSL::Compiler compiler)

Definition at line 286 of file SkSLModuleLoader.cpp.

286 {
287 if (!fModuleLoader.fFragmentModule) {
288 const Module* gpuModule = this->loadGPUModule(compiler);
291 MODULE_DATA(sksl_frag),
292 gpuModule);
293 }
294 return fModuleLoader.fFragmentModule.get();
295}
std::unique_ptr< const Module > fFragmentModule

◆ loadGPUModule()

const Module * SkSL::ModuleLoader::loadGPUModule ( SkSL::Compiler compiler)

Definition at line 275 of file SkSLModuleLoader.cpp.

275 {
276 if (!fModuleLoader.fGPUModule) {
277 const Module* sharedModule = this->loadSharedModule(compiler);
278 fModuleLoader.fGPUModule = compile_and_shrink(compiler,
280 MODULE_DATA(sksl_gpu),
281 sharedModule);
282 }
283 return fModuleLoader.fGPUModule.get();
284}
const Module * loadSharedModule(SkSL::Compiler *compiler)
std::unique_ptr< const Module > fGPUModule

◆ loadGraphiteFragmentES2Module()

const Module * SkSL::ModuleLoader::loadGraphiteFragmentES2Module ( SkSL::Compiler compiler)

Definition at line 334 of file SkSLModuleLoader.cpp.

334 {
335#if defined(SK_GRAPHITE)
336 if (!fModuleLoader.fGraphiteFragmentES2Module) {
337 const Module* fragmentModule = this->loadFragmentModule(compiler);
338 fModuleLoader.fGraphiteFragmentES2Module =
341 MODULE_DATA(sksl_graphite_frag_es2),
342 fragmentModule);
343 }
344 return fModuleLoader.fGraphiteFragmentES2Module.get();
345#else
346 return this->loadFragmentModule(compiler);
347#endif
348}
const Module * loadFragmentModule(SkSL::Compiler *compiler)
std::unique_ptr< const Module > fGraphiteFragmentES2Module

◆ loadGraphiteFragmentModule()

const Module * SkSL::ModuleLoader::loadGraphiteFragmentModule ( SkSL::Compiler compiler)

Definition at line 319 of file SkSLModuleLoader.cpp.

319 {
320#if defined(SK_GRAPHITE)
321 if (!fModuleLoader.fGraphiteFragmentModule) {
322 const Module* fragmentModule = this->loadFragmentModule(compiler);
325 MODULE_DATA(sksl_graphite_frag),
326 fragmentModule);
327 }
328 return fModuleLoader.fGraphiteFragmentModule.get();
329#else
330 return this->loadFragmentModule(compiler);
331#endif
332}
std::unique_ptr< const Module > fGraphiteFragmentModule

◆ loadGraphiteVertexES2Module()

const Module * SkSL::ModuleLoader::loadGraphiteVertexES2Module ( SkSL::Compiler compiler)

Definition at line 365 of file SkSLModuleLoader.cpp.

365 {
366#if defined(SK_GRAPHITE)
367 if (!fModuleLoader.fGraphiteVertexES2Module) {
368 const Module* vertexModule = this->loadVertexModule(compiler);
369 fModuleLoader.fGraphiteVertexES2Module =
372 MODULE_DATA(sksl_graphite_vert_es2),
373 vertexModule);
374 }
375 return fModuleLoader.fGraphiteVertexES2Module.get();
376#else
377 return this->loadVertexModule(compiler);
378#endif
379}
const Module * loadVertexModule(SkSL::Compiler *compiler)
std::unique_ptr< const Module > fGraphiteVertexES2Module

◆ loadGraphiteVertexModule()

const Module * SkSL::ModuleLoader::loadGraphiteVertexModule ( SkSL::Compiler compiler)

Definition at line 350 of file SkSLModuleLoader.cpp.

350 {
351#if defined(SK_GRAPHITE)
352 if (!fModuleLoader.fGraphiteVertexModule) {
353 const Module* vertexModule = this->loadVertexModule(compiler);
356 MODULE_DATA(sksl_graphite_vert),
357 vertexModule);
358 }
359 return fModuleLoader.fGraphiteVertexModule.get();
360#else
361 return this->loadVertexModule(compiler);
362#endif
363}
std::unique_ptr< const Module > fGraphiteVertexModule

◆ loadPrivateRTShaderModule()

const Module * SkSL::ModuleLoader::loadPrivateRTShaderModule ( SkSL::Compiler compiler)

Definition at line 253 of file SkSLModuleLoader.cpp.

253 {
254 if (!fModuleLoader.fRuntimeShaderModule) {
255 const Module* publicModule = this->loadPublicModule(compiler);
258 MODULE_DATA(sksl_rt_shader),
259 publicModule);
260 }
261 return fModuleLoader.fRuntimeShaderModule.get();
262}
const Module * loadPublicModule(SkSL::Compiler *compiler)
std::unique_ptr< const Module > fRuntimeShaderModule

◆ loadPublicModule()

const Module * SkSL::ModuleLoader::loadPublicModule ( SkSL::Compiler compiler)

Definition at line 241 of file SkSLModuleLoader.cpp.

241 {
242 if (!fModuleLoader.fPublicModule) {
243 const Module* sharedModule = this->loadSharedModule(compiler);
246 MODULE_DATA(sksl_public),
247 sharedModule);
248 this->addPublicTypeAliases(fModuleLoader.fPublicModule.get());
249 }
250 return fModuleLoader.fPublicModule.get();
251}
void addPublicTypeAliases(const SkSL::Module *module)
std::unique_ptr< const Module > fPublicModule

◆ loadSharedModule()

const Module * SkSL::ModuleLoader::loadSharedModule ( SkSL::Compiler compiler)

Definition at line 264 of file SkSLModuleLoader.cpp.

264 {
265 if (!fModuleLoader.fSharedModule) {
266 const Module* rootModule = this->rootModule();
269 MODULE_DATA(sksl_shared),
270 rootModule);
271 }
272 return fModuleLoader.fSharedModule.get();
273}
const Module * rootModule()
std::unique_ptr< const Module > fSharedModule

◆ loadVertexModule()

const Module * SkSL::ModuleLoader::loadVertexModule ( SkSL::Compiler compiler)

Definition at line 297 of file SkSLModuleLoader.cpp.

297 {
298 if (!fModuleLoader.fVertexModule) {
299 const Module* gpuModule = this->loadGPUModule(compiler);
302 MODULE_DATA(sksl_vert),
303 gpuModule);
304 }
305 return fModuleLoader.fVertexModule.get();
306}
std::unique_ptr< const Module > fVertexModule

◆ rootModule()

const Module * SkSL::ModuleLoader::rootModule ( )

Definition at line 195 of file SkSLModuleLoader.cpp.

195 {
196 return fModuleLoader.fRootModule.get();
197}
std::unique_ptr< const Module > fRootModule

◆ unloadModules()

void SkSL::ModuleLoader::unloadModules ( )

Definition at line 131 of file SkSLModuleLoader.cpp.

131 {
132 fModuleLoader.fSharedModule = nullptr;
133 fModuleLoader.fGPUModule = nullptr;
134 fModuleLoader.fVertexModule = nullptr;
135 fModuleLoader.fFragmentModule = nullptr;
136 fModuleLoader.fComputeModule = nullptr;
137 fModuleLoader.fGraphiteVertexModule = nullptr;
138 fModuleLoader.fGraphiteFragmentModule = nullptr;
139 fModuleLoader.fPublicModule = nullptr;
140 fModuleLoader.fRuntimeShaderModule = nullptr;
141}

The documentation for this class was generated from the following files: