Flutter Impeller
impeller::compiler::Switches Struct Reference

#include <switches.h>

Public Member Functions

 Switches ()
 
 ~Switches ()
 
 Switches (const fml::CommandLine &command_line)
 
bool AreValid (std::ostream &explain) const
 

Static Public Member Functions

static void PrintHelp (std::ostream &stream)
 

Public Attributes

TargetPlatform target_platform = TargetPlatform::kUnknown
 
std::shared_ptr< fml::UniqueFD > working_directory = nullptr
 
std::vector< IncludeDirinclude_directories = {}
 
std::string source_file_name = ""
 
SourceType input_type = SourceType::kUnknown
 
std::string sl_file_name = ""
 
bool iplr = false
 
std::string spirv_file_name = ""
 
std::string reflection_json_name = ""
 
std::string reflection_header_name = ""
 
std::string reflection_cc_name = ""
 
std::string depfile_path = ""
 
std::vector< std::string > defines = {}
 
bool json_format = false
 
SourceLanguage source_language = SourceLanguage::kUnknown
 
uint32_t gles_language_version = 0
 
std::string metal_version = ""
 
std::string entry_point = ""
 
bool use_half_textures = false
 

Detailed Description

Definition at line 20 of file switches.h.

Constructor & Destructor Documentation

◆ Switches() [1/2]

impeller::compiler::Switches::Switches ( )
default

◆ ~Switches()

impeller::compiler::Switches::~Switches ( )
default

◆ Switches() [2/2]

impeller::compiler::Switches::Switches ( const fml::CommandLine &  command_line)

Definition at line 113 of file switches.cc.

115  working_directory(std::make_shared<fml::UniqueFD>(fml::OpenDirectory(
116  Utf8FromPath(std::filesystem::current_path()).c_str(),
117  false, // create if necessary,
118  fml::FilePermission::kRead))),
119  source_file_name(command_line.GetOptionValueWithDefault("input", "")),
120  input_type(SourceTypeFromCommandLine(command_line)),
121  sl_file_name(command_line.GetOptionValueWithDefault("sl", "")),
122  iplr(command_line.HasOption("iplr")),
123  spirv_file_name(command_line.GetOptionValueWithDefault("spirv", "")),
125  command_line.GetOptionValueWithDefault("reflection-json", "")),
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")),
133  stoi(command_line.GetOptionValueWithDefault("gles-language-version",
134  "0"))),
136  command_line.GetOptionValueWithDefault("metal-version", "1.2")),
137  entry_point(
138  command_line.GetOptionValueWithDefault("entry-point", "main")),
139  use_half_textures(command_line.HasOption("use-half-textures")) {
140  auto language =
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") {
148  }
149 
150  if (!working_directory || !working_directory->is_valid()) {
151  return;
152  }
153 
154  for (const auto& include_dir_path : command_line.GetOptionValues("include")) {
155  if (!include_dir_path.data()) {
156  continue;
157  }
158 
159  // fml::OpenDirectoryReadOnly for Windows doesn't handle relative paths
160  // beginning with `../` well, so we build an absolute path.
161 
162  // Get the current working directory as a utf8 encoded string.
163  // Note that the `include_dir_path` is already utf8 encoded, and so we
164  // mustn't attempt to double-convert it to utf8 lest multi-byte characters
165  // will become mangled.
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);
169  } else {
170  auto cwd = Utf8FromPath(std::filesystem::current_path());
171  include_dir_absolute = std::filesystem::absolute(
172  std::filesystem::path(cwd) / include_dir_path);
173  }
174 
175  auto dir = std::make_shared<fml::UniqueFD>(fml::OpenDirectoryReadOnly(
176  *working_directory, include_dir_absolute.string().c_str()));
177  if (!dir || !dir->is_valid()) {
178  continue;
179  }
180 
181  IncludeDir dir_entry;
182  dir_entry.name = include_dir_path;
183  dir_entry.dir = std::move(dir);
184 
185  include_directories.emplace_back(std::move(dir_entry));
186  }
187 
188  for (const auto& define : command_line.GetOptionValues("define")) {
189  defines.emplace_back(define);
190  }
191 }

References defines, impeller::compiler::IncludeDir::dir, include_directories, impeller::compiler::kGLSL, impeller::compiler::kHLSL, impeller::compiler::IncludeDir::name, source_language, impeller::compiler::Utf8FromPath(), and working_directory.

Member Function Documentation

◆ AreValid()

bool impeller::compiler::Switches::AreValid ( std::ostream &  explain) const

Definition at line 193 of file switches.cc.

193  {
194  bool valid = true;
196  explain << "The target platform (only one) was not specified." << std::endl;
197  valid = false;
198  }
199 
201  explain << "Invalid source language type." << std::endl;
202  valid = false;
203  }
204 
205  if (!working_directory || !working_directory->is_valid()) {
206  explain << "Could not open the working directory: \""
207  << Utf8FromPath(std::filesystem::current_path()).c_str() << "\""
208  << std::endl;
209  valid = false;
210  }
211 
212  if (source_file_name.empty()) {
213  explain << "Input file name was empty." << std::endl;
214  valid = false;
215  }
216 
217  if (sl_file_name.empty()) {
218  explain << "Target shading language file name was empty." << std::endl;
219  valid = false;
220  }
221 
222  if (spirv_file_name.empty()) {
223  explain << "Spirv file name was empty." << std::endl;
224  valid = false;
225  }
226  return valid;
227 }

References impeller::compiler::kUnknown, sl_file_name, source_file_name, source_language, spirv_file_name, target_platform, impeller::compiler::Utf8FromPath(), and working_directory.

Referenced by impeller::compiler::Main(), and impeller::compiler::testing::TEST().

◆ PrintHelp()

void impeller::compiler::Switches::PrintHelp ( std::ostream &  stream)
static

Definition at line 39 of file switches.cc.

39  {
40  stream << std::endl;
41  stream << "ImpellerC is an offline shader processor and reflection engine."
42  << std::endl;
43  stream << "---------------------------------------------------------------"
44  << std::endl;
45  stream << "Valid Argument are:" << std::endl;
46  stream << "One of [";
47  for (const auto& platform : kKnownPlatforms) {
48  stream << " --" << platform.first;
49  }
50  stream << " ]" << std::endl;
51  stream << "--input=<source_file>" << std::endl;
52  stream << "[optional] --input-type={";
53  for (const auto& source_type : kKnownSourceTypes) {
54  stream << source_type.first << ", ";
55  }
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)"
60  << std::endl;
61  stream << "[optional] --entry-point=<entry_point_name> (default: main; "
62  "ignored for glsl)"
63  << std::endl;
64  stream << "[optional] --iplr (causes --sl file to be emitted in iplr format)"
65  << std::endl;
66  stream << "[optional] --reflection-json=<reflection_json_file>" << std::endl;
67  stream << "[optional] --reflection-header=<reflection_header_file>"
68  << std::endl;
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 "
76  "targeting metal)"
77  << std::endl;
78 }

References impeller::compiler::kKnownPlatforms, and impeller::compiler::kKnownSourceTypes.

Referenced by impeller::compiler::Main().

Member Data Documentation

◆ defines

std::vector<std::string> impeller::compiler::Switches::defines = {}

Definition at line 33 of file switches.h.

Referenced by impeller::compiler::Main(), and Switches().

◆ depfile_path

std::string impeller::compiler::Switches::depfile_path = ""

Definition at line 32 of file switches.h.

Referenced by impeller::compiler::Main().

◆ entry_point

std::string impeller::compiler::Switches::entry_point = ""

Definition at line 38 of file switches.h.

Referenced by impeller::compiler::Main(), and impeller::compiler::testing::TEST().

◆ gles_language_version

uint32_t impeller::compiler::Switches::gles_language_version = 0

Definition at line 36 of file switches.h.

Referenced by impeller::compiler::Main().

◆ include_directories

std::vector<IncludeDir> impeller::compiler::Switches::include_directories = {}

◆ input_type

SourceType impeller::compiler::Switches::input_type = SourceType::kUnknown

Definition at line 25 of file switches.h.

Referenced by impeller::compiler::Main().

◆ iplr

bool impeller::compiler::Switches::iplr = false

Definition at line 27 of file switches.h.

Referenced by impeller::compiler::Main().

◆ json_format

bool impeller::compiler::Switches::json_format = false

Definition at line 34 of file switches.h.

Referenced by impeller::compiler::Main().

◆ metal_version

std::string impeller::compiler::Switches::metal_version = ""

Definition at line 37 of file switches.h.

Referenced by impeller::compiler::Main().

◆ reflection_cc_name

std::string impeller::compiler::Switches::reflection_cc_name = ""

Definition at line 31 of file switches.h.

Referenced by impeller::compiler::Main().

◆ reflection_header_name

std::string impeller::compiler::Switches::reflection_header_name = ""

Definition at line 30 of file switches.h.

Referenced by impeller::compiler::Main().

◆ reflection_json_name

std::string impeller::compiler::Switches::reflection_json_name = ""

Definition at line 29 of file switches.h.

Referenced by impeller::compiler::Main().

◆ sl_file_name

std::string impeller::compiler::Switches::sl_file_name = ""

Definition at line 26 of file switches.h.

Referenced by AreValid(), and impeller::compiler::Main().

◆ source_file_name

std::string impeller::compiler::Switches::source_file_name = ""

Definition at line 24 of file switches.h.

Referenced by AreValid(), and impeller::compiler::Main().

◆ source_language

SourceLanguage impeller::compiler::Switches::source_language = SourceLanguage::kUnknown

◆ spirv_file_name

std::string impeller::compiler::Switches::spirv_file_name = ""

Definition at line 28 of file switches.h.

Referenced by AreValid(), and impeller::compiler::Main().

◆ target_platform

TargetPlatform impeller::compiler::Switches::target_platform = TargetPlatform::kUnknown

Definition at line 21 of file switches.h.

Referenced by AreValid(), and impeller::compiler::Main().

◆ use_half_textures

bool impeller::compiler::Switches::use_half_textures = false

Definition at line 39 of file switches.h.

Referenced by impeller::compiler::Main().

◆ working_directory

std::shared_ptr<fml::UniqueFD> impeller::compiler::Switches::working_directory = nullptr

Definition at line 22 of file switches.h.

Referenced by AreValid(), impeller::compiler::Main(), and Switches().


The documentation for this struct was generated from the following files:
impeller::compiler::Switches::gles_language_version
uint32_t gles_language_version
Definition: switches.h:36
impeller::compiler::Switches::defines
std::vector< std::string > defines
Definition: switches.h:33
impeller::compiler::Switches::entry_point
std::string entry_point
Definition: switches.h:38
impeller::compiler::Switches::target_platform
TargetPlatform target_platform
Definition: switches.h:21
impeller::compiler::Switches::metal_version
std::string metal_version
Definition: switches.h:37
impeller::compiler::Switches::working_directory
std::shared_ptr< fml::UniqueFD > working_directory
Definition: switches.h:22
impeller::compiler::Switches::include_directories
std::vector< IncludeDir > include_directories
Definition: switches.h:23
impeller::compiler::Switches::reflection_cc_name
std::string reflection_cc_name
Definition: switches.h:31
impeller::compiler::kKnownPlatforms
static const std::map< std::string, TargetPlatform > kKnownPlatforms
Definition: switches.cc:19
impeller::compiler::SourceLanguage::kGLSL
@ kGLSL
impeller::compiler::Switches::input_type
SourceType input_type
Definition: switches.h:25
impeller::compiler::Switches::source_file_name
std::string source_file_name
Definition: switches.h:24
impeller::compiler::TargetPlatformFromCommandLine
static TargetPlatform TargetPlatformFromCommandLine(const fml::CommandLine &command_line)
Definition: switches.cc:84
impeller::compiler::SourceLanguage::kHLSL
@ kHLSL
impeller::compiler::Switches::spirv_file_name
std::string spirv_file_name
Definition: switches.h:28
impeller::compiler::Switches::source_language
SourceLanguage source_language
Definition: switches.h:35
impeller::compiler::SourceLanguage::kUnknown
@ kUnknown
impeller::compiler::Switches::depfile_path
std::string depfile_path
Definition: switches.h:32
impeller::compiler::SourceTypeFromCommandLine
static SourceType SourceTypeFromCommandLine(const fml::CommandLine &command_line)
Definition: switches.cc:102
impeller::compiler::Switches::sl_file_name
std::string sl_file_name
Definition: switches.h:26
impeller::compiler::TargetPlatform::kUnknown
@ kUnknown
impeller::compiler::Switches::reflection_json_name
std::string reflection_json_name
Definition: switches.h:29
impeller::compiler::kKnownSourceTypes
static const std::map< std::string, SourceType > kKnownSourceTypes
Definition: switches.cc:31
impeller::compiler::Utf8FromPath
std::string Utf8FromPath(const std::filesystem::path &path)
Converts a native format path to a utf8 string.
Definition: utilities.cc:14
impeller::compiler::Switches::use_half_textures
bool use_half_textures
Definition: switches.h:39
impeller::compiler::Switches::iplr
bool iplr
Definition: switches.h:27
impeller::compiler::Switches::json_format
bool json_format
Definition: switches.h:34
impeller::compiler::Switches::reflection_header_name
std::string reflection_header_name
Definition: switches.h:30