12 #include "flutter/fml/file.h"
13 #include "fml/command_line.h"
44 const std::string optional_prefix =
"[optional] ";
45 const std::string optional_multiple_prefix =
"[optional,multiple] ";
49 stream <<
"ImpellerC is an offline shader processor and reflection engine."
51 stream <<
"---------------------------------------------------------------"
53 stream <<
"Expected invocation is:" << std::endl << std::endl;
54 stream <<
"./impellerc <One platform or multiple runtime stages> "
55 "--input=<source_file> --sl=<sl_output_file> <optional arguments>"
59 stream <<
"Valid platforms are:" << std::endl << std::endl;
62 stream <<
" --" << platform.first;
64 stream <<
" ]" << std::endl << std::endl;
66 stream <<
"Valid runtime stages are:" << std::endl << std::endl;
67 stream <<
"At least one of [";
69 stream <<
" --" << platform.first;
71 stream <<
" ]" << std::endl << std::endl;
73 stream <<
"Optional arguments:" << std::endl << std::endl;
74 stream << optional_prefix
75 <<
"--spirv=<spirv_output_file> (ignored for --shader-bundle)"
77 stream << optional_prefix <<
"--input-type={";
79 stream << source_type.first <<
", ";
81 stream <<
"}" << std::endl;
82 stream << optional_prefix <<
"--source-language=glsl|hlsl (default: glsl)"
84 stream << optional_prefix
85 <<
"--entry-point=<entry_point_name> (default: main; "
88 stream << optional_prefix
89 <<
"--iplr (causes --sl file to be emitted in "
92 stream << optional_prefix
93 <<
"--shader-bundle=<bundle_spec> (causes --sl "
95 "emitted in Flutter GPU's shader bundle format)"
97 stream << optional_prefix <<
"--reflection-json=<reflection_json_file>"
99 stream << optional_prefix <<
"--reflection-header=<reflection_header_file>"
101 stream << optional_prefix <<
"--reflection-cc=<reflection_cc_file>"
103 stream << optional_multiple_prefix <<
"--include=<include_directory>"
105 stream << optional_multiple_prefix <<
"--define=<define>" << std::endl;
106 stream << optional_prefix <<
"--depfile=<depfile_path>" << std::endl;
107 stream << optional_prefix <<
"--gles-language-version=<number>" << std::endl;
108 stream << optional_prefix <<
"--json" << std::endl;
109 stream << optional_prefix
110 <<
"--use-half-textures (force openGL semantics when "
113 stream << optional_prefix <<
"--require-framebuffer-fetch" << std::endl;
121 const fml::CommandLine& command_line) {
124 if (command_line.HasOption(platform.first)) {
131 target = platform.second;
139 const fml::CommandLine& command_line) {
140 std::vector<TargetPlatform> stages;
142 if (command_line.HasOption(platform.first)) {
143 stages.push_back(platform.second);
150 const fml::CommandLine& command_line) {
151 auto source_type_option =
152 command_line.GetOptionValueWithDefault(
"input-type",
"");
157 return source_type_search->second;
161 : working_directory(
std::make_shared<
fml::UniqueFD>(
fml::OpenDirectory(
164 fml::FilePermission::kRead))),
165 source_file_name(command_line.GetOptionValueWithDefault(
"input",
"")),
167 sl_file_name(command_line.GetOptionValueWithDefault(
"sl",
"")),
168 iplr(command_line.HasOption(
"iplr")),
170 command_line.GetOptionValueWithDefault(
"shader-bundle",
"")),
171 spirv_file_name(command_line.GetOptionValueWithDefault(
"spirv",
"")),
172 reflection_json_name(
173 command_line.GetOptionValueWithDefault(
"reflection-json",
"")),
174 reflection_header_name(
175 command_line.GetOptionValueWithDefault(
"reflection-header",
"")),
177 command_line.GetOptionValueWithDefault(
"reflection-cc",
"")),
178 depfile_path(command_line.GetOptionValueWithDefault(
"depfile",
"")),
179 json_format(command_line.HasOption(
"json")),
180 gles_language_version(
181 stoi(command_line.GetOptionValueWithDefault(
"gles-language-version",
184 command_line.GetOptionValueWithDefault(
"metal-version",
"1.2")),
186 command_line.GetOptionValueWithDefault(
"entry-point",
"main")),
187 use_half_textures(command_line.HasOption(
"use-half-textures")),
188 require_framebuffer_fetch(
189 command_line.HasOption(
"require-framebuffer-fetch")),
193 command_line.GetOptionValueWithDefault(
"source-language",
"glsl"));
201 for (
const auto& include_dir_path : command_line.GetOptionValues(
"include")) {
202 if (!include_dir_path.data()) {
213 std::filesystem::path include_dir_absolute;
214 if (std::filesystem::path(include_dir_path).is_absolute()) {
215 include_dir_absolute = std::filesystem::path(include_dir_path);
217 auto cwd =
Utf8FromPath(std::filesystem::current_path());
218 include_dir_absolute = std::filesystem::absolute(
219 std::filesystem::path(cwd) / include_dir_path);
222 auto dir = std::make_shared<fml::UniqueFD>(fml::OpenDirectoryReadOnly(
224 if (!dir || !dir->is_valid()) {
229 dir_entry.
name = include_dir_path;
230 dir_entry.
dir = std::move(dir);
235 for (
const auto& define : command_line.GetOptionValues(
"define")) {
249 !shader_bundle_mode) {
250 explain <<
"Either a target platform was not specified, or no runtime "
251 "stages were specified."
257 explain <<
"Invalid source language type." << std::endl;
262 explain <<
"Could not open the working directory: \""
263 <<
Utf8FromPath(std::filesystem::current_path()).c_str() <<
"\""
269 explain <<
"Input file name was empty." << std::endl;
274 explain <<
"Target shading language file name was empty." << std::endl;
279 explain <<
"Spirv file name was empty." << std::endl;
283 if (
iplr && shader_bundle_mode) {
284 explain <<
"--iplr and --shader-bundle flag cannot be specified at the "
295 return runtime_stages_;
297 return {target_platform_};
302 !runtime_stages_.empty()) {
303 return runtime_stages_.front();
305 return target_platform_;
309 std::optional<TargetPlatform> target_platform)
const {
bool require_framebuffer_fetch
std::vector< TargetPlatform > PlatformsToCompile() const
A vector containing at least one valid platform.
SourceLanguage source_language
std::string metal_version
uint32_t gles_language_version
std::string shader_bundle
std::vector< std::string > defines
std::shared_ptr< fml::UniqueFD > working_directory
SourceOptions CreateSourceOptions(std::optional< TargetPlatform > target_platform=std::nullopt) const
std::string spirv_file_name
bool AreValid(std::ostream &explain) const
static void PrintHelp(std::ostream &stream)
std::string source_file_name
std::vector< IncludeDir > include_directories
TargetPlatform SelectDefaultTargetPlatform() const
std::string ToLowerCase(std::string_view string)
static const std::map< std::string, TargetPlatform > kKnownPlatforms
static std::vector< TargetPlatform > RuntimeStagesFromCommandLine(const fml::CommandLine &command_line)
SourceType SourceTypeFromFileName(const std::string &file_name)
std::string EntryPointFunctionNameFromSourceName(const std::string &file_name, SourceType type, SourceLanguage source_language, const std::string &entry_point_name)
static const std::map< std::string, TargetPlatform > kKnownRuntimeStages
std::string Utf8FromPath(const std::filesystem::path &path)
Converts a native format path to a utf8 string.
static TargetPlatform TargetPlatformFromCommandLine(const fml::CommandLine &command_line)
SourceLanguage ToSourceLanguage(const std::string &source_language)
static const std::map< std::string, SourceType > kKnownSourceTypes
static SourceType SourceTypeFromCommandLine(const fml::CommandLine &command_line)
std::shared_ptr< fml::UniqueFD > dir
uint32_t gles_language_version
bool use_half_textures
Whether half-precision textures should be supported, requiring opengl semantics. Only used on metal t...
SourceLanguage source_language
std::vector< IncludeDir > include_dirs
bool require_framebuffer_fetch
Whether the GLSL framebuffer fetch extension will be required.
std::string entry_point_name
TargetPlatform target_platform
std::shared_ptr< fml::UniqueFD > working_directory
std::string metal_version
std::vector< std::string > defines