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 <<
"--entry-point-prefix=<entry_point_prefix> (default: empty)"
91 stream << optional_prefix
92 <<
"--iplr (causes --sl file to be emitted in "
95 stream << optional_prefix
96 <<
"--shader-bundle=<bundle_spec> (causes --sl "
98 "emitted in Flutter GPU's shader bundle format)"
100 stream << optional_prefix <<
"--reflection-json=<reflection_json_file>"
102 stream << optional_prefix <<
"--reflection-header=<reflection_header_file>"
104 stream << optional_prefix <<
"--reflection-cc=<reflection_cc_file>"
106 stream << optional_multiple_prefix <<
"--include=<include_directory>"
108 stream << optional_multiple_prefix <<
"--define=<define>" << std::endl;
109 stream << optional_prefix <<
"--depfile=<depfile_path>" << std::endl;
110 stream << optional_prefix <<
"--gles-language-version=<number>" << std::endl;
111 stream << optional_prefix <<
"--json" << std::endl;
112 stream << optional_prefix
113 <<
"--use-half-textures (force openGL semantics when "
116 stream << optional_prefix <<
"--require-framebuffer-fetch" << std::endl;
127 if (command_line.
HasOption(platform.first)) {
143 std::vector<TargetPlatform> stages;
145 if (command_line.
HasOption(platform.first)) {
146 stages.push_back(platform.second);
154 auto source_type_option =
160 return source_type_search->second;
169 return std::filesystem::path(std::u8string(
value.begin(),
value.end()));
173 : working_directory(
std::make_shared<
fml::UniqueFD>(
fml::OpenDirectory(
176 fml::FilePermission::kRead))),
180 iplr(command_line.HasOption(
"iplr")),
182 command_line.GetOptionValueWithDefault(
"shader-bundle",
"")),
184 reflection_json_name(
GetOptionAsPath(command_line,
"reflection-json")),
185 reflection_header_name(
189 json_format(command_line.HasOption(
"json")),
190 gles_language_version(
191 stoi(command_line.GetOptionValueWithDefault(
"gles-language-version",
194 command_line.GetOptionValueWithDefault(
"metal-version",
"1.2")),
196 command_line.GetOptionValueWithDefault(
"entry-point",
"main")),
198 command_line.GetOptionValueWithDefault(
"entry-point-prefix",
"")),
199 use_half_textures(command_line.HasOption(
"use-half-textures")),
200 require_framebuffer_fetch(
201 command_line.HasOption(
"require-framebuffer-fetch")),
213 for (
const auto& include_dir_path : command_line.
GetOptionValues(
"include")) {
214 if (!include_dir_path.data()) {
225 std::filesystem::path include_dir_absolute;
226 if (std::filesystem::path(include_dir_path).is_absolute()) {
227 include_dir_absolute = std::filesystem::path(include_dir_path);
229 auto cwd =
Utf8FromPath(std::filesystem::current_path());
230 include_dir_absolute = std::filesystem::absolute(
231 std::filesystem::path(cwd) / include_dir_path);
236 if (!dir || !dir->is_valid()) {
241 dir_entry.
name = include_dir_path;
242 dir_entry.
dir = std::move(dir);
261 !shader_bundle_mode) {
262 explain <<
"Either a target platform was not specified, or no runtime "
263 "stages were specified."
269 explain <<
"Invalid source language type." << std::endl;
274 explain <<
"Could not open the working directory: \""
275 <<
Utf8FromPath(std::filesystem::current_path()).c_str() <<
"\""
281 explain <<
"Input file name was empty." << std::endl;
286 explain <<
"Target shading language file name was empty." << std::endl;
291 explain <<
"Spirv file name was empty." << std::endl;
295 if (
iplr && shader_bundle_mode) {
296 explain <<
"--iplr and --shader-bundle flag cannot be specified at the "
307 return runtime_stages_;
309 return {target_platform_};
314 !runtime_stages_.empty()) {
315 return runtime_stages_.front();
317 return target_platform_;
321 std::optional<TargetPlatform> target_platform)
const {
std::vector< std::string_view > GetOptionValues(std::string_view name) const
std::string GetOptionValueWithDefault(std::string_view name, std::string_view default_value) const
bool HasOption(std::string_view name, size_t *index=nullptr) const
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
SourceOptions CreateSourceOptions(std::optional< TargetPlatform > target_platform=std::nullopt) const
bool AreValid(std::ostream &explain) const
static void PrintHelp(std::ostream &stream)
std::filesystem::path spirv_file_name
std::vector< IncludeDir > include_directories
std::filesystem::path source_file_name
TargetPlatform SelectDefaultTargetPlatform() const
fml::UniqueFD OpenDirectoryReadOnly(const fml::UniqueFD &base_directory, const char *path)
std::string ToLowerCase(std::string_view string)
static std::vector< TargetPlatform > RuntimeStagesFromCommandLine(const fml::CommandLine &command_line)
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)
std::string EntryPointFunctionNameFromSourceName(const std::filesystem::path &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
std::filesystem::path file_name
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