blob: cf0b52199222e58caba78c42bf092d2ecfd5c8a8 [file]
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_IMPELLER_COMPILER_SHADER_BUNDLE_H_
#define FLUTTER_IMPELLER_COMPILER_SHADER_BUNDLE_H_
#include <set>
#include <string>
#include <string_view>
#include <vector>
#include "impeller/compiler/source_options.h"
#include "impeller/compiler/switches.h"
#include "impeller/compiler/types.h"
#include "impeller/shader_bundle/shader_bundle_flatbuffers.h"
namespace impeller {
namespace compiler {
/// @brief The platform-discriminating preprocessor defines injected when
/// compiling a bundled shader for `platform` (for example
/// `IMPELLER_TARGET_METAL`). These let bundled Flutter GPU shaders
/// specialize for the backend they will run on, matching the defines
/// that Impeller's own shaders receive from the build templates.
///
/// @note Exposed only for testing purposes.
std::vector<std::string_view> GetShaderBundleTargetPlatformDefines(
TargetPlatform platform);
/// @brief Parse a shader bundle configuration from a given JSON string.
///
/// @note Exposed only for testing purposes. Use `GenerateShaderBundle`
/// directly.
std::optional<ShaderBundleConfig> ParseShaderBundleConfig(
const std::string& bundle_config_json,
std::ostream& error_stream);
/// @brief Parses the JSON shader bundle configuration and invokes the
/// compiler multiple times to produce a shader bundle flatbuffer.
///
/// @note Exposed only for testing purposes. Use `GenerateShaderBundle`
/// directly.
///
/// @param out_dependencies Optional. When non-null, populated with the
/// set of source files (including transitive
/// `#include`s) that contributed to the
/// generated bundle. Used by `GenerateShaderBundle`
/// to emit a depfile when `--depfile` is set.
std::optional<fb::shaderbundle::ShaderBundleT> GenerateShaderBundleFlatbuffer(
const std::string& bundle_config_json,
const SourceOptions& options,
std::set<std::string>* out_dependencies = nullptr);
/// @brief Parses the JSON shader bundle configuration and invokes the
/// compiler multiple times to produce a shader bundle flatbuffer, which
/// is then output to the `sl` file.
bool GenerateShaderBundle(Switches& switches);
} // namespace compiler
} // namespace impeller
#endif // FLUTTER_IMPELLER_COMPILER_SHADER_BUNDLE_H_