xref: /aosp_15_r20/external/skia/src/sksl/SkSLModule.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2024 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_MODULE
9 #define SKSL_MODULE
10 
11 #include "src/sksl/ir/SkSLProgramElement.h"
12 #include "src/sksl/ir/SkSLSymbolTable.h"
13 
14 #include <cstdint>
15 #include <memory>
16 #include <string>
17 #include <vector>
18 
19 namespace SkSL {
20 
21 /**
22  * Documentation for modules in SkSL: http://go/modules-in-sksl
23  * https://docs.google.com/document/d/1P8LkkimNr-nPlxMimUsz3K_7qMM7-tZOxDCWZejPcWg/edit?usp=sharing
24  */
25 
26 // A list of modules used in SkSL.
27 // Using an X-Macro (https://en.wikipedia.org/wiki/X_Macro) to manage the list.
28 #define SKSL_MODULE_LIST(M)   \
29     M(sksl_shared)            \
30     M(sksl_compute)           \
31     M(sksl_frag)              \
32     M(sksl_gpu)               \
33     M(sksl_public)            \
34     M(sksl_rt_shader)         \
35     M(sksl_vert)              \
36     M(sksl_graphite_frag)     \
37     M(sksl_graphite_frag_es2) \
38     M(sksl_graphite_vert)     \
39     M(sksl_graphite_vert_es2)
40 
41 enum class ModuleType : int8_t {
42     // `program` code is not in a module at all.
43     program = 0,
44     // `unknown` code exists in a module outside of SKSL_MODULE_LIST.
45     unknown = 1,
46 #define M(type) type,
47     SKSL_MODULE_LIST(M)
48 #undef M
49 };
50 
51 struct Module {
52     const Module*                                fParent = nullptr;
53     std::unique_ptr<SymbolTable>                 fSymbols;
54     std::vector<std::unique_ptr<ProgramElement>> fElements;
55     ModuleType                                   fModuleType = ModuleType::unknown;
56 };
57 
58 // Given a ModuleType, returns its name.
59 const char* ModuleTypeToString(ModuleType type);
60 
61 std::string GetModuleData(ModuleType type, const char* filename);
62 
63 }  // namespace SkSL
64 
65 #endif  // SKSL_MODULE
66