Flutter Impeller
shader_bundle.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_IMPELLER_COMPILER_SHADER_BUNDLE_H_
6 #define FLUTTER_IMPELLER_COMPILER_SHADER_BUNDLE_H_
7 
8 #include <set>
9 #include <string>
10 #include <string_view>
11 #include <vector>
12 
16 #include "impeller/shader_bundle/shader_bundle_flatbuffers.h"
17 
18 namespace impeller {
19 namespace compiler {
20 
21 /// @brief The platform-discriminating preprocessor defines injected when
22 /// compiling a bundled shader for `platform` (for example
23 /// `IMPELLER_TARGET_METAL`). These let bundled Flutter GPU shaders
24 /// specialize for the backend they will run on, matching the defines
25 /// that Impeller's own shaders receive from the build templates.
26 ///
27 /// @note Exposed only for testing purposes.
28 std::vector<std::string_view> GetShaderBundleTargetPlatformDefines(
29  TargetPlatform platform);
30 
31 /// @brief Parse a shader bundle configuration from a given JSON string.
32 ///
33 /// @note Exposed only for testing purposes. Use `GenerateShaderBundle`
34 /// directly.
35 std::optional<ShaderBundleConfig> ParseShaderBundleConfig(
36  const std::string& bundle_config_json,
37  std::ostream& error_stream);
38 
39 /// @brief Parses the JSON shader bundle configuration and invokes the
40 /// compiler multiple times to produce a shader bundle flatbuffer.
41 ///
42 /// @note Exposed only for testing purposes. Use `GenerateShaderBundle`
43 /// directly.
44 ///
45 /// @param out_dependencies Optional. When non-null, populated with the
46 /// set of source files (including transitive
47 /// `#include`s) that contributed to the
48 /// generated bundle. Used by `GenerateShaderBundle`
49 /// to emit a depfile when `--depfile` is set.
50 std::optional<fb::shaderbundle::ShaderBundleT> GenerateShaderBundleFlatbuffer(
51  const std::string& bundle_config_json,
52  const SourceOptions& options,
53  std::set<std::string>* out_dependencies = nullptr);
54 
55 /// @brief Parses the JSON shader bundle configuration and invokes the
56 /// compiler multiple times to produce a shader bundle flatbuffer, which
57 /// is then output to the `sl` file.
58 bool GenerateShaderBundle(Switches& switches);
59 
60 } // namespace compiler
61 } // namespace impeller
62 
63 #endif // FLUTTER_IMPELLER_COMPILER_SHADER_BUNDLE_H_
std::vector< std::string_view > GetShaderBundleTargetPlatformDefines(TargetPlatform platform)
The platform-discriminating preprocessor defines injected when compiling a bundled shader for platfor...
std::optional< fb::shaderbundle::ShaderBundleT > GenerateShaderBundleFlatbuffer(const std::string &bundle_config_json, const SourceOptions &options, std::set< std::string > *out_dependencies)
Parses the JSON shader bundle configuration and invokes the compiler multiple times to produce a shad...
bool GenerateShaderBundle(Switches &switches)
Parses the JSON shader bundle configuration and invokes the compiler multiple times to produce a shad...
std::optional< ShaderBundleConfig > ParseShaderBundleConfig(const std::string &bundle_config_json, std::ostream &error_stream)
Parse a shader bundle configuration from a given JSON string.