MCPcopy Create free account
hub / github.com/AmelieHeinrich/Termina / Load

Method Load

Sources/Termina/Shader/ShaderFile.cpp:11–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9
10namespace Termina {
11 bool ShaderFile::Load(const std::string& path)
12 {
13 TN_INFO("Compiling shader file: %s", path.c_str());
14
15 std::string source = FileSystem::ReadStringFromDisk(path);
16
17 ShaderPreprocessor::Result preprocessResult = ShaderPreprocessor::Preprocess(source);
18
19 // Generate all permutation combinations (power set)
20 std::vector<std::vector<std::string>> allCombinations;
21
22 // Add DEFAULT variant (empty combination)
23 allCombinations.push_back({});
24
25 // Generate all non-empty subsets
26 uint64 numPermutations = preprocessResult.Permutations.size();
27 for (uint64 i = 1; i < (uint64)((1 << numPermutations)); ++i) {
28 std::vector<std::string> combination;
29 for (uint64 j = 0; j < numPermutations; ++j) {
30 if (i & (1 << j)) {
31 combination.push_back(preprocessResult.Permutations[j]);
32 }
33 }
34 allCombinations.push_back(combination);
35 }
36
37 // Compile each combination
38 for (const auto& combination : allCombinations) {
39 // Build variant key from combination
40 std::string variantKey;
41 if (combination.empty()) {
42 variantKey = "DEFAULT";
43 } else {
44 for (const auto& perm : combination) {
45 if (!variantKey.empty()) {
46 variantKey += "_";
47 }
48 variantKey += perm;
49 }
50 }
51
52 // Compile each entry point with this combination
53 for (auto& [entryPoint, type] : preprocessResult.EntryPoints) {
54 ShaderCompiler::Arguments args;
55 args.EntryPoint = entryPoint;
56 args.Path = path;
57 args.Source = preprocessResult.ProcessedSource; // Use processed source without pragmas
58 args.Type = type;
59 args.Defines = combination;
60 #if defined(TRMN_MACOS)
61 args.PostProcessCallback = MetalShaderConverter::Convert;
62 #endif
63
64 ShaderCompiler::Result compileResult = ShaderCompiler::Compile(args);
65 if (!compileResult.Success) {
66 return false;
67 }
68 Variants[variantKey].Bytecodes[type].first = entryPoint;

Callers 3

ShaderManagerMethod · 0.45
WatchPipelineMethod · 0.45

Calls 4

c_strMethod · 0.80
push_backMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected