12 #include "flutter/fml/file.h"
13 #include "fml/command_line.h"
28 static const std::vector<std::pair<std::string, TargetPlatform>>
45 const std::string optional_prefix =
"[optional] ";
46 const std::string optional_multiple_prefix =
"[optional,multiple] ";
50 stream <<
"ImpellerC is an offline shader processor and reflection engine."
52 stream <<
"---------------------------------------------------------------"
54 stream <<
"Expected invocation is:" << std::endl << std::endl;
55 stream <<
"./impellerc <One platform or multiple runtime stages> "
56 "--input=<source_file> --sl=<sl_output_file> <optional arguments>"
60 stream <<
"Valid platforms are:" << std::endl << std::endl;
63 stream <<
" --" << platform.first;
65 stream <<
" ]" << std::endl << std::endl;
67 stream <<
"Valid runtime stages are:" << std::endl << std::endl;
68 stream <<
"At least one of [";
70 stream <<
" --" << platform.first;
72 stream <<
" ]" << std::endl << std::endl;
74 stream <<
"Optional arguments:" << std::endl << std::endl;
75 stream << optional_prefix
76 <<
"--spirv=<spirv_output_file> (ignored for --shader-bundle)"
78 stream << optional_prefix <<
"--input-type={";
80 stream << source_type.first <<
", ";
82 stream <<
"}" << std::endl;
83 stream << optional_prefix <<
"--source-language=glsl|hlsl (default: glsl)"
85 stream << optional_prefix
86 <<
"--entry-point=<entry_point_name> (default: main; "
89 stream << optional_prefix
90 <<
"--entry-point-prefix=<entry_point_prefix> (default: empty)"
92 stream << optional_prefix
93 <<
"--iplr (causes --sl file to be emitted in "
96 stream << optional_prefix
97 <<
"--shader-bundle=<bundle_spec> (causes --sl "
99 "emitted in Flutter GPU's shader bundle format)"
101 stream << optional_prefix <<
"--reflection-json=<reflection_json_file>"
103 stream << optional_prefix <<
"--reflection-header=<reflection_header_file>"
105 stream << optional_prefix <<
"--reflection-cc=<reflection_cc_file>"
107 stream << optional_multiple_prefix <<
"--include=<include_directory>"
109 stream << optional_multiple_prefix <<
"--define=<define>" << std::endl;
110 stream << optional_prefix <<
"--depfile=<depfile_path>" << std::endl;
111 stream << optional_prefix <<
"--gles-language-version=<number>" << std::endl;
112 stream << optional_prefix <<
"--json" << std::endl;
113 stream << optional_prefix
114 <<
"--use-half-textures (force openGL semantics when "
117 stream << optional_prefix <<
"--require-framebuffer-fetch" << std::endl;
118 stream << optional_prefix
119 <<
"--verbose (output full error messages in stderr. If not set, long "
120 "error messages are written to a file, and a truncated version is "
130 const fml::CommandLine& command_line) {
133 if (command_line.HasOption(platform.first)) {
140 target = platform.second;
148 const fml::CommandLine& command_line) {
149 std::vector<TargetPlatform> stages;
151 if (command_line.HasOption(platform.first)) {
152 stages.push_back(platform.second);
159 const fml::CommandLine& command_line) {
160 auto source_type_option =
161 command_line.GetOptionValueWithDefault(
"input-type",
"");
166 return source_type_search->second;
172 const fml::CommandLine& command_line,
174 std::string
value = command_line.GetOptionValueWithDefault(arg,
"");
175 return std::filesystem::path(std::u8string(
value.begin(),
value.end()));
179 : working_directory(
std::make_shared<
fml::UniqueFD>(
fml::OpenDirectory(
182 fml::FilePermission::kRead))),
186 iplr(command_line.HasOption(
"iplr")),
188 command_line.GetOptionValueWithDefault(
"shader-bundle",
"")),
190 reflection_json_name(
GetOptionAsPath(command_line,
"reflection-json")),
191 reflection_header_name(
195 json_format(command_line.HasOption(
"json")),
196 gles_language_version(
197 stoi(command_line.GetOptionValueWithDefault(
"gles-language-version",
200 command_line.GetOptionValueWithDefault(
"metal-version",
"1.2")),
202 command_line.GetOptionValueWithDefault(
"entry-point",
"main")),
204 command_line.GetOptionValueWithDefault(
"entry-point-prefix",
"")),
205 use_half_textures(command_line.HasOption(
"use-half-textures")),
206 require_framebuffer_fetch(
207 command_line.HasOption(
"require-framebuffer-fetch")),
208 verbose(command_line.HasOption(
"verbose")),
212 command_line.GetOptionValueWithDefault(
"source-language",
"glsl"));
220 for (
const auto& include_dir_path : command_line.GetOptionValues(
"include")) {
221 if (!include_dir_path.data()) {
232 std::filesystem::path include_dir_absolute;
233 if (std::filesystem::path(include_dir_path).is_absolute()) {
234 include_dir_absolute = std::filesystem::path(include_dir_path);
236 auto cwd =
Utf8FromPath(std::filesystem::current_path());
237 include_dir_absolute = std::filesystem::absolute(
238 std::filesystem::path(cwd) / include_dir_path);
241 auto dir = std::make_shared<fml::UniqueFD>(fml::OpenDirectoryReadOnly(
243 if (!dir || !dir->is_valid()) {
248 dir_entry.
name = include_dir_path;
249 dir_entry.
dir = std::move(dir);
254 for (
const auto& define : command_line.GetOptionValues(
"define")) {
268 !shader_bundle_mode) {
269 explain <<
"Either a target platform was not specified, or no runtime "
270 "stages were specified."
276 explain <<
"Invalid source language type." << std::endl;
281 explain <<
"Could not open the working directory: \""
282 <<
Utf8FromPath(std::filesystem::current_path()).c_str() <<
"\""
288 explain <<
"Input file name was empty." << std::endl;
293 explain <<
"Target shading language file name was empty." << std::endl;
298 explain <<
"Spirv file name was empty." << std::endl;
302 if (
iplr && shader_bundle_mode) {
303 explain <<
"--iplr and --shader-bundle flag cannot be specified at the "
314 return runtime_stages_;
316 return {target_platform_};
bool require_framebuffer_fetch
std::vector< TargetPlatform > PlatformsToCompile() const
A vector containing at least one valid platform.
std::string entry_point_prefix
std::filesystem::path sl_file_name
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
bool AreValid(std::ostream &explain) const
static void PrintHelp(std::ostream &stream)
SourceOptions CreateSourceOptions() const
std::filesystem::path spirv_file_name
std::vector< IncludeDir > include_directories
std::filesystem::path source_file_name
std::string ToLowerCase(std::string_view string)
static const std::map< std::string, TargetPlatform > kKnownPlatforms
SourceType SourceTypeFromFileName(const std::filesystem::path &file_name)
static std::filesystem::path GetOptionAsPath(const fml::CommandLine &command_line, const char *arg)
static std::vector< TargetPlatform > RuntimeStagesFromCommandLine(const fml::CommandLine &command_line)
std::string EntryPointFunctionNameFromSourceName(const std::filesystem::path &file_name, SourceType type, SourceLanguage source_language, const std::string &entry_point_name)
std::string Utf8FromPath(const std::filesystem::path &path)
Converts a native format path to a utf8 string.
static const std::vector< std::pair< std::string, TargetPlatform > > kKnownRuntimeStages
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
std::filesystem::path file_name
bool require_framebuffer_fetch
Whether the GLSL framebuffer fetch extension will be required.
std::string entry_point_name
std::shared_ptr< fml::UniqueFD > working_directory
std::string metal_version
std::vector< std::string > defines