12 #include "flutter/fml/file.h"
41 stream <<
"ImpellerC is an offline shader processor and reflection engine."
43 stream <<
"---------------------------------------------------------------"
45 stream <<
"Valid Argument are:" << std::endl;
48 stream <<
" --" << platform.first;
50 stream <<
" ]" << std::endl;
51 stream <<
"--input=<source_file>" << std::endl;
52 stream <<
"[optional] --input-type={";
54 stream << source_type.first <<
", ";
56 stream <<
"}" << std::endl;
57 stream <<
"--sl=<sl_output_file>" << std::endl;
58 stream <<
"--spirv=<spirv_output_file>" << std::endl;
59 stream <<
"[optional] --source-language=glsl|hlsl (default: glsl)"
61 stream <<
"[optional] --entry-point=<entry_point_name> (default: main; "
64 stream <<
"[optional] --iplr (causes --sl file to be emitted in iplr format)"
66 stream <<
"[optional] --reflection-json=<reflection_json_file>" << std::endl;
67 stream <<
"[optional] --reflection-header=<reflection_header_file>"
69 stream <<
"[optional] --reflection-cc=<reflection_cc_file>" << std::endl;
70 stream <<
"[optional,multiple] --include=<include_directory>" << std::endl;
71 stream <<
"[optional,multiple] --define=<define>" << std::endl;
72 stream <<
"[optional] --depfile=<depfile_path>" << std::endl;
73 stream <<
"[optional] --gles-language-version=<number>" << std::endl;
74 stream <<
"[optional] --json" << std::endl;
75 stream <<
"[optional] --use-half-textures (force openGL semantics when "
85 const fml::CommandLine& command_line) {
88 if (command_line.HasOption(platform.first)) {
95 target = platform.second;
103 const fml::CommandLine& command_line) {
104 auto source_type_option =
105 command_line.GetOptionValueWithDefault(
"input-type",
"");
110 return source_type_search->second;
115 working_directory(
std::make_shared<fml::UniqueFD>(fml::OpenDirectory(
118 fml::FilePermission::kRead))),
119 source_file_name(command_line.GetOptionValueWithDefault(
"input",
"")),
121 sl_file_name(command_line.GetOptionValueWithDefault(
"sl",
"")),
122 iplr(command_line.HasOption(
"iplr")),
123 spirv_file_name(command_line.GetOptionValueWithDefault(
"spirv",
"")),
124 reflection_json_name(
125 command_line.GetOptionValueWithDefault(
"reflection-json",
"")),
126 reflection_header_name(
127 command_line.GetOptionValueWithDefault(
"reflection-header",
"")),
129 command_line.GetOptionValueWithDefault(
"reflection-cc",
"")),
130 depfile_path(command_line.GetOptionValueWithDefault(
"depfile",
"")),
131 json_format(command_line.HasOption(
"json")),
132 gles_language_version(
133 stoi(command_line.GetOptionValueWithDefault(
"gles-language-version",
136 command_line.GetOptionValueWithDefault(
"metal-version",
"1.2")),
138 command_line.GetOptionValueWithDefault(
"entry-point",
"main")),
139 use_half_textures(command_line.HasOption(
"use-half-textures")) {
141 command_line.GetOptionValueWithDefault(
"source-language",
"glsl");
142 std::transform(language.begin(), language.end(), language.begin(),
143 [](
char x) { return std::tolower(x); });
144 if (language ==
"glsl") {
146 }
else if (language ==
"hlsl") {
154 for (
const auto& include_dir_path : command_line.GetOptionValues(
"include")) {
155 if (!include_dir_path.data()) {
166 std::filesystem::path include_dir_absolute;
167 if (std::filesystem::path(include_dir_path).is_absolute()) {
168 include_dir_absolute = std::filesystem::path(include_dir_path);
170 auto cwd =
Utf8FromPath(std::filesystem::current_path());
171 include_dir_absolute = std::filesystem::absolute(
172 std::filesystem::path(cwd) / include_dir_path);
175 auto dir = std::make_shared<fml::UniqueFD>(fml::OpenDirectoryReadOnly(
177 if (!dir || !dir->is_valid()) {
182 dir_entry.
name = include_dir_path;
183 dir_entry.
dir = std::move(dir);
188 for (
const auto& define : command_line.GetOptionValues(
"define")) {
196 explain <<
"The target platform (only one) was not specified." << std::endl;
201 explain <<
"Invalid source language type." << std::endl;
206 explain <<
"Could not open the working directory: \""
207 <<
Utf8FromPath(std::filesystem::current_path()).c_str() <<
"\""
213 explain <<
"Input file name was empty." << std::endl;
218 explain <<
"Target shading language file name was empty." << std::endl;
223 explain <<
"Spirv file name was empty." << std::endl;