Flutter Impeller
impeller::compiler Namespace Reference

Namespaces

 testing
 

Classes

class  AutoLogger
 
class  Compiler
 
struct  CompilerBackend
 
class  CompilerSkSL
 
struct  IncludeDir
 
class  Includer
 
struct  IncluderData
 
struct  KnownType
 
class  Reflector
 
class  RuntimeStageData
 
struct  SourceOptions
 
class  SPIRVCompiler
 
struct  SPIRVCompilerOptions
 
struct  SPIRVCompilerSourceProfile
 
struct  SPIRVCompilerTargetEnv
 
struct  StructMember
 
struct  Switches
 
struct  UniformDescription
 
class  UniqueIncluder
 Wraps a shared includer so unique includers may be created to satisfy the shaderc API. This is a simple proxy object and does nothing. More...
 
struct  VertexType
 

Enumerations

enum  SourceType {
  SourceType::kUnknown,
  SourceType::kVertexShader,
  SourceType::kFragmentShader,
  SourceType::kTessellationControlShader,
  SourceType::kTessellationEvaluationShader,
  SourceType::kComputeShader
}
 
enum  TargetPlatform {
  TargetPlatform::kUnknown,
  TargetPlatform::kMetalDesktop,
  TargetPlatform::kMetalIOS,
  TargetPlatform::kOpenGLES,
  TargetPlatform::kOpenGLDesktop,
  TargetPlatform::kVulkan,
  TargetPlatform::kRuntimeStageMetal,
  TargetPlatform::kRuntimeStageGLES,
  TargetPlatform::kRuntimeStageVulkan,
  TargetPlatform::kSkSL
}
 
enum  SourceLanguage {
  SourceLanguage::kUnknown,
  SourceLanguage::kGLSL,
  SourceLanguage::kHLSL
}
 

Functions

static uint32_t ParseMSLVersion (const std::string &msl_version)
 
static CompilerBackend CreateMSLCompiler (const spirv_cross::ParsedIR &ir, const SourceOptions &source_options, std::optional< uint32_t > msl_version_override={})
 
static CompilerBackend CreateVulkanCompiler (const spirv_cross::ParsedIR &ir, const SourceOptions &source_options)
 
static CompilerBackend CreateGLSLCompiler (const spirv_cross::ParsedIR &ir, const SourceOptions &source_options)
 
static CompilerBackend CreateSkSLCompiler (const spirv_cross::ParsedIR &ir, const SourceOptions &source_options)
 
static bool EntryPointMustBeNamedMain (TargetPlatform platform)
 
static CompilerBackend CreateCompiler (const spirv_cross::ParsedIR &ir, const SourceOptions &source_options)
 
static std::string JoinStrings (std::vector< std::string > items, const std::string &separator)
 
static bool SetPermissiveAccess (const std::filesystem::path &p)
 
bool Main (const fml::CommandLine &command_line)
 
static std::string BaseTypeToString (spirv_cross::SPIRType::BaseType type)
 
static std::string ExecutionModelToString (spv::ExecutionModel model)
 
static std::string StringToShaderStage (std::string str)
 
static std::string ToString (CompilerBackend::Type type)
 
static std::string TypeNameWithPaddingOfSize (size_t size)
 
static std::optional< KnownTypeReadKnownScalarType (spirv_cross::SPIRType::BaseType type)
 
static size_t GetReflectedStructSize (const std::vector< StructMember > &members)
 Get the reflected struct size. In the vast majority of the cases, this is the same as the declared struct size as given by the compiler. But, additional padding may need to be introduced after the end of the struct to keep in line with the alignment requirement of the individual struct members. This method figures out the actual size of the reflected struct that can be referenced in native code. More...
 
static VertexType VertexTypeFromInputResource (const spirv_cross::Compiler &compiler, const spirv_cross::Resource *resource)
 
static std::optional< fb::Stage > ToStage (spv::ExecutionModel stage)
 
static std::optional< uint32_t > ToJsonStage (spv::ExecutionModel stage)
 
static std::optional< fb::TargetPlatform > ToTargetPlatform (TargetPlatform platform)
 
static std::optional< uint32_t > ToJsonTargetPlatform (TargetPlatform platform)
 
static std::optional< fb::UniformDataType > ToType (spirv_cross::SPIRType::BaseType type)
 
static std::optional< uint32_t > ToJsonType (spirv_cross::SPIRType::BaseType type)
 
static void SetDefaultLimitations (shaderc::CompileOptions &compiler_opts)
 
static void SetBindingBaseOffset (shaderc::CompileOptions &options)
 
void report_and_exit (const std::string &msg)
 
static TargetPlatform TargetPlatformFromCommandLine (const fml::CommandLine &command_line)
 
static SourceType SourceTypeFromCommandLine (const fml::CommandLine &command_line)
 
static bool StringEndWith (const std::string &string, const std::string &suffix)
 
SourceType SourceTypeFromFileName (const std::string &file_name)
 
std::string TargetPlatformToString (TargetPlatform platform)
 
std::string SourceLanguageToString (SourceLanguage source_language)
 
std::string EntryPointFunctionNameFromSourceName (const std::string &file_name, SourceType type, SourceLanguage source_language, const std::string &entry_point_name)
 
bool TargetPlatformNeedsReflection (TargetPlatform platform)
 
std::string ShaderCErrorToString (shaderc_compilation_status status)
 
shaderc_shader_kind ToShaderCShaderKind (SourceType type)
 
spv::ExecutionModel ToExecutionModel (SourceType type)
 
spirv_cross::CompilerMSL::Options::Platform TargetPlatformToMSLPlatform (TargetPlatform platform)
 
std::string SourceTypeToString (SourceType type)
 
std::string TargetPlatformSLExtension (TargetPlatform platform)
 
bool TargetPlatformIsOpenGL (TargetPlatform platform)
 
bool TargetPlatformIsMetal (TargetPlatform platform)
 
bool TargetPlatformIsVulkan (TargetPlatform platform)
 
bool TargetPlatformBundlesSkSL (TargetPlatform platform)
 
std::string Utf8FromPath (const std::filesystem::path &path)
 Converts a native format path to a utf8 string. More...
 
std::string InferShaderNameFromPath (std::string_view path)
 
std::string ConvertToCamelCase (std::string_view string)
 
std::string ConvertToEntrypointName (std::string_view string)
 Ensure that the entrypoint name is a valid identifier in the target language. More...
 
bool StringStartsWith (const std::string &target, const std::string &prefix)
 

Variables

constexpr std::string_view kReflectionHeaderTemplate
 
constexpr std::string_view kReflectionCCTemplate
 
constexpr char kExternalTexturePrefix [] = "SAMPLER_EXTERNAL_OES_"
 
static const char * kStageKey = "stage"
 
static const char * kTargetPlatformKey = "target_platform"
 
static const char * kEntrypointKey = "entrypoint"
 
static const char * kUniformsKey = "uniforms"
 
static const char * kShaderKey = "sksl"
 
static const char * kUniformNameKey = "name"
 
static const char * kUniformLocationKey = "location"
 
static const char * kUniformTypeKey = "type"
 
static const char * kUniformRowsKey = "rows"
 
static const char * kUniformColumnsKey = "columns"
 
static const char * kUniformBitWidthKey = "bit_width"
 
static const char * kUniformArrayElementsKey = "array_elements"
 
static const std::map< std::string, TargetPlatformkKnownPlatforms
 
static const std::map< std::string, SourceTypekKnownSourceTypes
 

Enumeration Type Documentation

◆ SourceLanguage

Enumerator
kUnknown 
kGLSL 
kHLSL 

Definition at line 41 of file types.h.

41  {
42  kUnknown,
43  kGLSL,
44  kHLSL,
45 };

◆ SourceType

Enumerator
kUnknown 
kVertexShader 
kFragmentShader 
kTessellationControlShader 
kTessellationEvaluationShader 
kComputeShader 

Definition at line 19 of file types.h.

◆ TargetPlatform

Enumerator
kUnknown 
kMetalDesktop 
kMetalIOS 
kOpenGLES 
kOpenGLDesktop 
kVulkan 
kRuntimeStageMetal 
kRuntimeStageGLES 
kRuntimeStageVulkan 
kSkSL 

Definition at line 28 of file types.h.

28  {
29  kUnknown,
31  kMetalIOS,
32  kOpenGLES,
34  kVulkan,
38  kSkSL,
39 };

Function Documentation

◆ BaseTypeToString()

static std::string impeller::compiler::BaseTypeToString ( spirv_cross::SPIRType::BaseType  type)
static

Definition at line 29 of file reflector.cc.

29  {
30  using Type = spirv_cross::SPIRType::BaseType;
31  switch (type) {
32  case Type::Void:
33  return "ShaderType::kVoid";
34  case Type::Boolean:
35  return "ShaderType::kBoolean";
36  case Type::SByte:
37  return "ShaderType::kSignedByte";
38  case Type::UByte:
39  return "ShaderType::kUnsignedByte";
40  case Type::Short:
41  return "ShaderType::kSignedShort";
42  case Type::UShort:
43  return "ShaderType::kUnsignedShort";
44  case Type::Int:
45  return "ShaderType::kSignedInt";
46  case Type::UInt:
47  return "ShaderType::kUnsignedInt";
48  case Type::Int64:
49  return "ShaderType::kSignedInt64";
50  case Type::UInt64:
51  return "ShaderType::kUnsignedInt64";
52  case Type::AtomicCounter:
53  return "ShaderType::kAtomicCounter";
54  case Type::Half:
55  return "ShaderType::kHalfFloat";
56  case Type::Float:
57  return "ShaderType::kFloat";
58  case Type::Double:
59  return "ShaderType::kDouble";
60  case Type::Struct:
61  return "ShaderType::kStruct";
62  case Type::Image:
63  return "ShaderType::kImage";
64  case Type::SampledImage:
65  return "ShaderType::kSampledImage";
66  case Type::Sampler:
67  return "ShaderType::kSampler";
68  default:
69  return "ShaderType::kUnknown";
70  }
71 }

Referenced by VertexTypeFromInputResource().

◆ ConvertToCamelCase()

std::string impeller::compiler::ConvertToCamelCase ( std::string_view  string)

Definition at line 23 of file utilities.cc.

23  {
24  if (string.empty()) {
25  return "";
26  }
27 
28  std::stringstream stream;
29  bool next_upper = true;
30  for (size_t i = 0, count = string.length(); i < count; i++) {
31  auto ch = string.data()[i];
32  if (next_upper) {
33  next_upper = false;
34  stream << static_cast<char>(std::toupper(ch));
35  continue;
36  }
37  if (ch == '_') {
38  next_upper = true;
39  continue;
40  }
41  stream << ch;
42  }
43  return stream.str();
44 }

◆ ConvertToEntrypointName()

std::string impeller::compiler::ConvertToEntrypointName ( std::string_view  string)

Ensure that the entrypoint name is a valid identifier in the target language.

Definition at line 46 of file utilities.cc.

46  {
47  if (string.empty()) {
48  return "";
49  }
50  std::stringstream stream;
51  // Append a prefix if the first character is not a letter.
52  if (!std::isalpha(string.data()[0])) {
53  stream << "i_";
54  }
55  for (size_t i = 0, count = string.length(); i < count; i++) {
56  auto ch = string.data()[i];
57  if (std::isalnum(ch) || ch == '_') {
58  stream << ch;
59  }
60  }
61  return stream.str();
62 }

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

◆ CreateCompiler()

static CompilerBackend impeller::compiler::CreateCompiler ( const spirv_cross::ParsedIR &  ir,
const SourceOptions source_options 
)
static

Definition at line 200 of file compiler.cc.

201  {
202  CompilerBackend compiler;
203  switch (source_options.target_platform) {
204  case TargetPlatform::kMetalDesktop:
205  case TargetPlatform::kMetalIOS:
206  case TargetPlatform::kRuntimeStageMetal:
207  compiler = CreateMSLCompiler(ir, source_options);
208  break;
209  case TargetPlatform::kVulkan:
210  case TargetPlatform::kRuntimeStageVulkan:
211  compiler = CreateVulkanCompiler(ir, source_options);
212  break;
213  case TargetPlatform::kUnknown:
214  case TargetPlatform::kOpenGLES:
215  case TargetPlatform::kOpenGLDesktop:
216  case TargetPlatform::kRuntimeStageGLES:
217  compiler = CreateGLSLCompiler(ir, source_options);
218  break;
219  case TargetPlatform::kSkSL:
220  compiler = CreateSkSLCompiler(ir, source_options);
221  }
222  if (!compiler) {
223  return {};
224  }
225  auto* backend = compiler.GetCompiler();
226  if (!EntryPointMustBeNamedMain(source_options.target_platform) &&
227  source_options.source_language == SourceLanguage::kGLSL) {
228  backend->rename_entry_point("main", source_options.entry_point_name,
229  ToExecutionModel(source_options.type));
230  }
231  return compiler;
232 }

References CreateGLSLCompiler(), CreateMSLCompiler(), CreateSkSLCompiler(), CreateVulkanCompiler(), impeller::compiler::SourceOptions::entry_point_name, EntryPointMustBeNamedMain(), impeller::compiler::CompilerBackend::GetCompiler(), kGLSL, kMetalDesktop, kMetalIOS, kOpenGLDesktop, kOpenGLES, kRuntimeStageGLES, kRuntimeStageMetal, kRuntimeStageVulkan, kSkSL, kUnknown, kVulkan, impeller::compiler::SourceOptions::source_language, impeller::compiler::SourceOptions::target_platform, ToExecutionModel(), and impeller::compiler::SourceOptions::type.

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

◆ CreateGLSLCompiler()

static CompilerBackend impeller::compiler::CreateGLSLCompiler ( const spirv_cross::ParsedIR &  ir,
const SourceOptions source_options 
)
static

Definition at line 129 of file compiler.cc.

130  {
131  auto gl_compiler = std::make_shared<spirv_cross::CompilerGLSL>(ir);
132 
133  // Walk the variables and insert the external image extension if any of them
134  // begins with the external texture prefix. Unfortunately, we can't walk
135  // `gl_compiler->get_shader_resources().separate_samplers` until the compiler
136  // is further along.
137  //
138  // Unfortunately, we can't just let the shader author add this extension and
139  // use `samplerExternalOES` directly because compiling to spirv requires the
140  // source language profile to be at least 310 ES, but this extension is
141  // incompatible with ES 310+.
142  for (auto& id : ir.ids_for_constant_or_variable) {
143  if (StringStartsWith(ir.get_name(id), kExternalTexturePrefix)) {
144  gl_compiler->require_extension("GL_OES_EGL_image_external");
145  break;
146  }
147  }
148 
149  spirv_cross::CompilerGLSL::Options sl_options;
150  sl_options.force_zero_initialized_variables = true;
151  sl_options.vertex.fixup_clipspace = true;
152  if (source_options.target_platform == TargetPlatform::kOpenGLES ||
153  source_options.target_platform == TargetPlatform::kRuntimeStageGLES) {
154  sl_options.version = source_options.gles_language_version > 0
155  ? source_options.gles_language_version
156  : 100;
157  sl_options.es = true;
158  gl_compiler->set_variable_type_remap_callback(
159  [&](const spirv_cross::SPIRType& type, const std::string& var_name,
160  std::string& name_of_type) {
161  if (StringStartsWith(var_name, kExternalTexturePrefix)) {
162  name_of_type = "samplerExternalOES";
163  }
164  });
165  } else {
166  sl_options.version = source_options.gles_language_version > 0
167  ? source_options.gles_language_version
168  : 120;
169  sl_options.es = false;
170  }
171  gl_compiler->set_common_options(sl_options);
172  return CompilerBackend(gl_compiler);
173 }

References impeller::compiler::SourceOptions::gles_language_version, kExternalTexturePrefix, kOpenGLES, kRuntimeStageGLES, StringStartsWith(), and impeller::compiler::SourceOptions::target_platform.

Referenced by CreateCompiler().

◆ CreateMSLCompiler()

static CompilerBackend impeller::compiler::CreateMSLCompiler ( const spirv_cross::ParsedIR &  ir,
const SourceOptions source_options,
std::optional< uint32_t >  msl_version_override = {} 
)
static

Definition at line 50 of file compiler.cc.

53  {}) {
54  auto sl_compiler = std::make_shared<spirv_cross::CompilerMSL>(ir);
55  spirv_cross::CompilerMSL::Options sl_options;
56  sl_options.platform =
57  TargetPlatformToMSLPlatform(source_options.target_platform);
58  sl_options.msl_version = msl_version_override.value_or(
59  ParseMSLVersion(source_options.metal_version));
60  sl_options.ios_use_simdgroup_functions =
61  sl_options.is_ios() &&
62  sl_options.msl_version >=
63  spirv_cross::CompilerMSL::Options::make_msl_version(2, 4, 0);
64  sl_options.use_framebuffer_fetch_subpasses = true;
65  sl_compiler->set_msl_options(sl_options);
66 
67  // Sort the float and sampler uniforms according to their declared/decorated
68  // order. For user authored fragment shaders, the API for setting uniform
69  // values uses the index of the uniform in the declared order. By default, the
70  // metal backend of spirv-cross will order uniforms according to usage. To fix
71  // this, we use the sorted order and the add_msl_resource_binding API to force
72  // the ordering to match the declared order. Note that while this code runs
73  // for all compiled shaders, it will only affect fragment shaders due to the
74  // specified stage.
75  auto floats =
76  SortUniforms(&ir, sl_compiler.get(), spirv_cross::SPIRType::Float);
77  auto images =
78  SortUniforms(&ir, sl_compiler.get(), spirv_cross::SPIRType::SampledImage);
79 
80  uint32_t buffer_offset = 0;
81  uint32_t sampler_offset = 0;
82  for (auto& float_id : floats) {
83  sl_compiler->add_msl_resource_binding(
84  {.stage = spv::ExecutionModel::ExecutionModelFragment,
85  .basetype = spirv_cross::SPIRType::BaseType::Float,
86  .desc_set = sl_compiler->get_decoration(float_id,
87  spv::DecorationDescriptorSet),
88  .binding =
89  sl_compiler->get_decoration(float_id, spv::DecorationBinding),
90  .count = 1u,
91  .msl_buffer = buffer_offset});
92  buffer_offset++;
93  }
94  for (auto& image_id : images) {
95  sl_compiler->add_msl_resource_binding({
96  .stage = spv::ExecutionModel::ExecutionModelFragment,
97  .basetype = spirv_cross::SPIRType::BaseType::SampledImage,
98  .desc_set =
99  sl_compiler->get_decoration(image_id, spv::DecorationDescriptorSet),
100  .binding =
101  sl_compiler->get_decoration(image_id, spv::DecorationBinding),
102  .count = 1u,
103  // A sampled image is both an image and a sampler, so both
104  // offsets need to be set or depending on the partiular shader
105  // the bindings may be incorrect.
106  .msl_texture = sampler_offset,
107  .msl_sampler = sampler_offset,
108  });
109  sampler_offset++;
110  }
111 
112  return CompilerBackend(sl_compiler);
113 }

Referenced by CreateCompiler(), and CreateVulkanCompiler().

◆ CreateSkSLCompiler()

static CompilerBackend impeller::compiler::CreateSkSLCompiler ( const spirv_cross::ParsedIR &  ir,
const SourceOptions source_options 
)
static

Definition at line 175 of file compiler.cc.

176  {
177  auto sksl_compiler = std::make_shared<CompilerSkSL>(ir);
178  return CompilerBackend(sksl_compiler);
179 }

Referenced by CreateCompiler().

◆ CreateVulkanCompiler()

static CompilerBackend impeller::compiler::CreateVulkanCompiler ( const spirv_cross::ParsedIR &  ir,
const SourceOptions source_options 
)
static

Definition at line 115 of file compiler.cc.

117  {
118  // TODO(dnfield): It seems like what we'd want is a CompilerGLSL with
119  // vulkan_semantics set to true, but that has regressed some things on GLES
120  // somehow. In the mean time, go back to using CompilerMSL, but set the Metal
121  // Language version to something really high so that we don't get weird
122  // complaints about using Metal features while trying to build Vulkan shaders.
123  // https://github.com/flutter/flutter/issues/123795
124  return CreateMSLCompiler(
125  ir, source_options,
126  spirv_cross::CompilerMSL::Options::make_msl_version(3, 0, 0));
127 }

References CreateMSLCompiler().

Referenced by CreateCompiler().

◆ EntryPointFunctionNameFromSourceName()

std::string impeller::compiler::EntryPointFunctionNameFromSourceName ( const std::string &  file_name,
SourceType  type,
SourceLanguage  source_language,
const std::string &  entry_point_name 
)

Definition at line 90 of file types.cc.

94  {
95  if (source_language == SourceLanguage::kHLSL) {
96  return entry_point_name;
97  }
98 
99  std::stringstream stream;
100  std::filesystem::path file_path(file_name);
101  stream << ConvertToEntrypointName(Utf8FromPath(file_path.stem())) << "_";
102  switch (type) {
103  case SourceType::kUnknown:
104  stream << "unknown";
105  break;
106  case SourceType::kVertexShader:
107  stream << "vertex";
108  break;
109  case SourceType::kFragmentShader:
110  stream << "fragment";
111  break;
112  case SourceType::kTessellationControlShader:
113  stream << "tess_control";
114  break;
115  case SourceType::kTessellationEvaluationShader:
116  stream << "tess_eval";
117  break;
118  case SourceType::kComputeShader:
119  stream << "compute";
120  break;
121  }
122  stream << "_main";
123  return stream.str();
124 }

References ConvertToEntrypointName(), kComputeShader, kFragmentShader, kHLSL, kTessellationControlShader, kTessellationEvaluationShader, kUnknown, kVertexShader, and Utf8FromPath().

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

◆ EntryPointMustBeNamedMain()

static bool impeller::compiler::EntryPointMustBeNamedMain ( TargetPlatform  platform)
static

Definition at line 181 of file compiler.cc.

181  {
182  switch (platform) {
183  case TargetPlatform::kUnknown:
184  FML_UNREACHABLE();
185  case TargetPlatform::kMetalDesktop:
186  case TargetPlatform::kMetalIOS:
187  case TargetPlatform::kVulkan:
188  case TargetPlatform::kRuntimeStageMetal:
189  case TargetPlatform::kRuntimeStageVulkan:
190  return false;
191  case TargetPlatform::kSkSL:
192  case TargetPlatform::kOpenGLES:
193  case TargetPlatform::kOpenGLDesktop:
194  case TargetPlatform::kRuntimeStageGLES:
195  return true;
196  }
197  FML_UNREACHABLE();
198 }

References kMetalDesktop, kMetalIOS, kOpenGLDesktop, kOpenGLES, kRuntimeStageGLES, kRuntimeStageMetal, kRuntimeStageVulkan, kSkSL, kUnknown, and kVulkan.

Referenced by CreateCompiler().

◆ ExecutionModelToString()

static std::string impeller::compiler::ExecutionModelToString ( spv::ExecutionModel  model)
static

Definition at line 73 of file reflector.cc.

73  {
74  switch (model) {
75  case spv::ExecutionModel::ExecutionModelVertex:
76  return "vertex";
77  case spv::ExecutionModel::ExecutionModelFragment:
78  return "fragment";
79  case spv::ExecutionModel::ExecutionModelTessellationControl:
80  return "tessellation_control";
81  case spv::ExecutionModel::ExecutionModelTessellationEvaluation:
82  return "tessellation_evaluation";
83  case spv::ExecutionModel::ExecutionModelGLCompute:
84  return "compute";
85  default:
86  return "unsupported";
87  }
88 }

◆ GetReflectedStructSize()

static size_t impeller::compiler::GetReflectedStructSize ( const std::vector< StructMember > &  members)
static

Get the reflected struct size. In the vast majority of the cases, this is the same as the declared struct size as given by the compiler. But, additional padding may need to be introduced after the end of the struct to keep in line with the alignment requirement of the individual struct members. This method figures out the actual size of the reflected struct that can be referenced in native code.

Parameters
[in]membersThe members
Returns
The reflected structure size.

Definition at line 579 of file reflector.cc.

579  {
580  auto struct_size = 0u;
581  for (const auto& member : members) {
582  struct_size += member.byte_length;
583  }
584  return struct_size;
585 }

◆ InferShaderNameFromPath()

std::string impeller::compiler::InferShaderNameFromPath ( std::string_view  path)

Definition at line 18 of file utilities.cc.

18  {
19  auto p = std::filesystem::path{path}.stem();
20  return Utf8FromPath(p);
21 }

References Utf8FromPath().

Referenced by Main().

◆ JoinStrings()

static std::string impeller::compiler::JoinStrings ( std::vector< std::string >  items,
const std::string &  separator 
)
static

Definition at line 447 of file compiler.cc.

448  {
449  std::stringstream stream;
450  for (size_t i = 0, count = items.size(); i < count; i++) {
451  const auto is_last = (i == count - 1);
452 
453  stream << items[i];
454  if (!is_last) {
455  stream << separator;
456  }
457  }
458  return stream.str();
459 }

Referenced by impeller::compiler::Compiler::CreateDepfileContents().

◆ Main()

bool impeller::compiler::Main ( const fml::CommandLine &  command_line)

Definition at line 39 of file impellerc_main.cc.

39  {
40  fml::InstallCrashHandler();
41  if (command_line.HasOption("help")) {
42  Switches::PrintHelp(std::cout);
43  return true;
44  }
45 
46  Switches switches(command_line);
47  if (!switches.AreValid(std::cerr)) {
48  std::cerr << "Invalid flags specified." << std::endl;
49  Switches::PrintHelp(std::cerr);
50  return false;
51  }
52 
53  std::shared_ptr<fml::FileMapping> source_file_mapping =
54  fml::FileMapping::CreateReadOnly(switches.source_file_name);
55  if (!source_file_mapping) {
56  std::cerr << "Could not open input file." << std::endl;
57  return false;
58  }
59 
60  SourceOptions options;
61  options.target_platform = switches.target_platform;
62  options.source_language = switches.source_language;
63  if (switches.input_type == SourceType::kUnknown) {
64  options.type = SourceTypeFromFileName(switches.source_file_name);
65  } else {
66  options.type = switches.input_type;
67  }
68  options.working_directory = switches.working_directory;
69  options.file_name = switches.source_file_name;
70  options.include_dirs = switches.include_directories;
71  options.defines = switches.defines;
72  options.entry_point_name = EntryPointFunctionNameFromSourceName(
73  switches.source_file_name, options.type, options.source_language,
74  switches.entry_point);
75  options.json_format = switches.json_format;
76  options.gles_language_version = switches.gles_language_version;
77  options.metal_version = switches.metal_version;
78  options.use_half_textures = switches.use_half_textures;
79 
80  Reflector::Options reflector_options;
81  reflector_options.target_platform = switches.target_platform;
82  reflector_options.entry_point_name = options.entry_point_name;
83  reflector_options.shader_name =
84  InferShaderNameFromPath(switches.source_file_name);
85  reflector_options.header_file_name = Utf8FromPath(
86  std::filesystem::path{switches.reflection_header_name}.filename());
87 
88  // Generate SkSL if needed.
89  std::shared_ptr<fml::Mapping> sksl_mapping;
90  if (switches.iplr && TargetPlatformBundlesSkSL(switches.target_platform)) {
91  SourceOptions sksl_options = options;
92  sksl_options.target_platform = TargetPlatform::kSkSL;
93 
94  Reflector::Options sksl_reflector_options = reflector_options;
95  sksl_reflector_options.target_platform = TargetPlatform::kSkSL;
96 
97  Compiler sksl_compiler =
98  Compiler(source_file_mapping, sksl_options, sksl_reflector_options);
99  if (!sksl_compiler.IsValid()) {
100  std::cerr << "Compilation to SkSL failed." << std::endl;
101  std::cerr << sksl_compiler.GetErrorMessages() << std::endl;
102  return false;
103  }
104  sksl_mapping = sksl_compiler.GetSLShaderSource();
105  }
106 
107  Compiler compiler(source_file_mapping, options, reflector_options);
108  if (!compiler.IsValid()) {
109  std::cerr << "Compilation failed." << std::endl;
110  std::cerr << compiler.GetErrorMessages() << std::endl;
111  return false;
112  }
113 
114  auto spriv_file_name = std::filesystem::absolute(
115  std::filesystem::current_path() / switches.spirv_file_name);
116  if (!fml::WriteAtomically(*switches.working_directory,
117  Utf8FromPath(spriv_file_name).c_str(),
118  *compiler.GetSPIRVAssembly())) {
119  std::cerr << "Could not write file to " << switches.spirv_file_name
120  << std::endl;
121  return false;
122  }
123 
124  auto sl_file_name = std::filesystem::absolute(
125  std::filesystem::current_path() / switches.sl_file_name);
126  if (switches.iplr) {
127  auto reflector = compiler.GetReflector();
128  if (reflector == nullptr) {
129  std::cerr << "Could not create reflector." << std::endl;
130  return false;
131  }
132  auto stage_data = reflector->GetRuntimeStageData();
133  if (!stage_data) {
134  std::cerr << "Runtime stage information was nil." << std::endl;
135  return false;
136  }
137  if (sksl_mapping) {
138  stage_data->SetSkSLData(sksl_mapping);
139  }
140  auto stage_data_mapping = options.json_format
141  ? stage_data->CreateJsonMapping()
142  : stage_data->CreateMapping();
143  if (!stage_data_mapping) {
144  std::cerr << "Runtime stage data could not be created." << std::endl;
145  return false;
146  }
147  if (!fml::WriteAtomically(*switches.working_directory, //
148  Utf8FromPath(sl_file_name).c_str(), //
149  *stage_data_mapping //
150  )) {
151  std::cerr << "Could not write file to " << switches.sl_file_name
152  << std::endl;
153  return false;
154  }
155  // Tools that consume the runtime stage data expect the access mode to
156  // be 0644.
157  if (!SetPermissiveAccess(sl_file_name)) {
158  return false;
159  }
160  } else {
161  if (!fml::WriteAtomically(*switches.working_directory,
162  Utf8FromPath(sl_file_name).c_str(),
163  *compiler.GetSLShaderSource())) {
164  std::cerr << "Could not write file to " << switches.sl_file_name
165  << std::endl;
166  return false;
167  }
168  }
169 
170  if (TargetPlatformNeedsReflection(options.target_platform)) {
171  if (!switches.reflection_json_name.empty()) {
172  auto reflection_json_name = std::filesystem::absolute(
173  std::filesystem::current_path() / switches.reflection_json_name);
174  if (!fml::WriteAtomically(
175  *switches.working_directory,
176  Utf8FromPath(reflection_json_name).c_str(),
177  *compiler.GetReflector()->GetReflectionJSON())) {
178  std::cerr << "Could not write reflection json to "
179  << switches.reflection_json_name << std::endl;
180  return false;
181  }
182  }
183 
184  if (!switches.reflection_header_name.empty()) {
185  auto reflection_header_name =
186  std::filesystem::absolute(std::filesystem::current_path() /
187  switches.reflection_header_name.c_str());
188  if (!fml::WriteAtomically(
189  *switches.working_directory,
190  Utf8FromPath(reflection_header_name).c_str(),
191  *compiler.GetReflector()->GetReflectionHeader())) {
192  std::cerr << "Could not write reflection header to "
193  << switches.reflection_header_name << std::endl;
194  return false;
195  }
196  }
197 
198  if (!switches.reflection_cc_name.empty()) {
199  auto reflection_cc_name =
200  std::filesystem::absolute(std::filesystem::current_path() /
201  switches.reflection_cc_name.c_str());
202  if (!fml::WriteAtomically(*switches.working_directory,
203  Utf8FromPath(reflection_cc_name).c_str(),
204  *compiler.GetReflector()->GetReflectionCC())) {
205  std::cerr << "Could not write reflection CC to "
206  << switches.reflection_cc_name << std::endl;
207  return false;
208  }
209  }
210  }
211 
212  if (!switches.depfile_path.empty()) {
213  std::string result_file;
214  switch (switches.target_platform) {
215  case TargetPlatform::kMetalDesktop:
216  case TargetPlatform::kMetalIOS:
217  case TargetPlatform::kOpenGLES:
218  case TargetPlatform::kOpenGLDesktop:
219  case TargetPlatform::kRuntimeStageMetal:
220  case TargetPlatform::kRuntimeStageGLES:
221  case TargetPlatform::kRuntimeStageVulkan:
222  case TargetPlatform::kSkSL:
223  case TargetPlatform::kVulkan:
224  result_file = switches.sl_file_name;
225  break;
226  case TargetPlatform::kUnknown:
227  result_file = switches.spirv_file_name;
228  break;
229  }
230  auto depfile_path = std::filesystem::absolute(
231  std::filesystem::current_path() / switches.depfile_path.c_str());
232  if (!fml::WriteAtomically(*switches.working_directory,
233  Utf8FromPath(depfile_path).c_str(),
234  *compiler.CreateDepfileContents({result_file}))) {
235  std::cerr << "Could not write depfile to " << switches.depfile_path
236  << std::endl;
237  return false;
238  }
239  }
240 
241  return true;
242 }

References impeller::compiler::Switches::AreValid(), impeller::compiler::Compiler::CreateDepfileContents(), impeller::compiler::SourceOptions::defines, impeller::compiler::Switches::defines, impeller::compiler::Switches::depfile_path, impeller::compiler::Switches::entry_point, impeller::compiler::SourceOptions::entry_point_name, impeller::compiler::Reflector::Options::entry_point_name, EntryPointFunctionNameFromSourceName(), impeller::compiler::SourceOptions::file_name, impeller::compiler::Compiler::GetErrorMessages(), impeller::compiler::Reflector::GetReflectionCC(), impeller::compiler::Reflector::GetReflectionHeader(), impeller::compiler::Reflector::GetReflectionJSON(), impeller::compiler::Compiler::GetReflector(), impeller::compiler::Reflector::GetRuntimeStageData(), impeller::compiler::Compiler::GetSLShaderSource(), impeller::compiler::Compiler::GetSPIRVAssembly(), impeller::compiler::SourceOptions::gles_language_version, impeller::compiler::Switches::gles_language_version, impeller::compiler::Reflector::Options::header_file_name, impeller::compiler::Switches::include_directories, impeller::compiler::SourceOptions::include_dirs, InferShaderNameFromPath(), impeller::compiler::Switches::input_type, impeller::compiler::Switches::iplr, impeller::compiler::Compiler::IsValid(), impeller::compiler::SourceOptions::json_format, impeller::compiler::Switches::json_format, kMetalDesktop, kMetalIOS, kOpenGLDesktop, kOpenGLES, kRuntimeStageGLES, kRuntimeStageMetal, kRuntimeStageVulkan, kSkSL, kUnknown, kVulkan, impeller::compiler::SourceOptions::metal_version, impeller::compiler::Switches::metal_version, impeller::compiler::Switches::PrintHelp(), impeller::compiler::Switches::reflection_cc_name, impeller::compiler::Switches::reflection_header_name, impeller::compiler::Switches::reflection_json_name, SetPermissiveAccess(), impeller::compiler::Reflector::Options::shader_name, impeller::compiler::Switches::sl_file_name, impeller::compiler::Switches::source_file_name, impeller::compiler::SourceOptions::source_language, impeller::compiler::Switches::source_language, SourceTypeFromFileName(), impeller::compiler::Switches::spirv_file_name, impeller::compiler::Switches::target_platform, impeller::compiler::SourceOptions::target_platform, impeller::compiler::Reflector::Options::target_platform, TargetPlatformBundlesSkSL(), TargetPlatformNeedsReflection(), impeller::compiler::SourceOptions::type, impeller::compiler::SourceOptions::use_half_textures, impeller::compiler::Switches::use_half_textures, Utf8FromPath(), impeller::compiler::Switches::working_directory, and impeller::compiler::SourceOptions::working_directory.

Referenced by main().

◆ ParseMSLVersion()

static uint32_t impeller::compiler::ParseMSLVersion ( const std::string &  msl_version)
static

Definition at line 27 of file compiler.cc.

27  {
28  std::stringstream sstream(msl_version);
29  std::string version_part;
30  uint32_t major = 1;
31  uint32_t minor = 2;
32  uint32_t patch = 0;
33  if (std::getline(sstream, version_part, '.')) {
34  major = std::stoi(version_part);
35  if (std::getline(sstream, version_part, '.')) {
36  minor = std::stoi(version_part);
37  if (std::getline(sstream, version_part, '.')) {
38  patch = std::stoi(version_part);
39  }
40  }
41  }
42  if (major < 1 || (major == 1 && minor < 2)) {
43  std::cerr << "--metal-version version must be at least 1.2. Have "
44  << msl_version << std::endl;
45  }
46  return spirv_cross::CompilerMSL::Options::make_msl_version(major, minor,
47  patch);
48 }

◆ ReadKnownScalarType()

static std::optional<KnownType> impeller::compiler::ReadKnownScalarType ( spirv_cross::SPIRType::BaseType  type)
static

Definition at line 532 of file reflector.cc.

533  {
534  switch (type) {
535  case spirv_cross::SPIRType::BaseType::Boolean:
536  return KnownType{
537  .name = "bool",
538  .byte_size = sizeof(bool),
539  };
540  case spirv_cross::SPIRType::BaseType::Float:
541  return KnownType{
542  .name = "Scalar",
543  .byte_size = sizeof(Scalar),
544  };
545  case spirv_cross::SPIRType::BaseType::Half:
546  return KnownType{
547  .name = "Half",
548  .byte_size = sizeof(Half),
549  };
550  case spirv_cross::SPIRType::BaseType::UInt:
551  return KnownType{
552  .name = "uint32_t",
553  .byte_size = sizeof(uint32_t),
554  };
555  case spirv_cross::SPIRType::BaseType::Int:
556  return KnownType{
557  .name = "int32_t",
558  .byte_size = sizeof(int32_t),
559  };
560  default:
561  break;
562  }
563  return std::nullopt;
564 }

References impeller::compiler::KnownType::name.

◆ report_and_exit()

void impeller::compiler::report_and_exit ( const std::string &  msg)

Definition at line 16 of file spirv_sksl.cc.

16  {
17  fprintf(stderr, "There was a compiler error: %s\n", msg.c_str());
18  fflush(stderr);
19  exit(1);
20 }

◆ SetBindingBaseOffset()

static void impeller::compiler::SetBindingBaseOffset ( shaderc::CompileOptions &  options)
static

Definition at line 210 of file spirv_compiler.cc.

210  {
211  constexpr uint32_t kBindingBaseOffset = 64;
212  static const shaderc_uniform_kind kUniformKinds[] = {
213  shaderc_uniform_kind::shaderc_uniform_kind_sampler,
214  shaderc_uniform_kind::shaderc_uniform_kind_texture,
215  shaderc_uniform_kind::shaderc_uniform_kind_image,
216  shaderc_uniform_kind::shaderc_uniform_kind_buffer, // UBOs
217  shaderc_uniform_kind::shaderc_uniform_kind_storage_buffer, // SSBOs
218  };
219 
220  for (size_t i = 0u; i < sizeof(kUniformKinds) / sizeof(shaderc_uniform_kind);
221  i++) {
222  options.SetBindingBaseForStage(
223  shaderc_shader_kind::shaderc_fragment_shader, //
224  kUniformKinds[i], //
225  kBindingBaseOffset //
226  );
227  }
228 }

Referenced by impeller::compiler::SPIRVCompilerOptions::BuildShadercOptions().

◆ SetDefaultLimitations()

static void impeller::compiler::SetDefaultLimitations ( shaderc::CompileOptions &  compiler_opts)
static

Definition at line 92 of file spirv_compiler.cc.

92  {
93  using Limit = std::pair<shaderc_limit, int>;
94  static constexpr std::array<Limit, 83> limits = {
95  Limit{shaderc_limit::shaderc_limit_max_lights, 8},
96  Limit{shaderc_limit::shaderc_limit_max_clip_planes, 6},
97  Limit{shaderc_limit::shaderc_limit_max_texture_units, 2},
98  Limit{shaderc_limit::shaderc_limit_max_texture_coords, 8},
99  Limit{shaderc_limit::shaderc_limit_max_vertex_attribs, 16},
100  Limit{shaderc_limit::shaderc_limit_max_vertex_uniform_components, 4096},
101  Limit{shaderc_limit::shaderc_limit_max_varying_floats, 60},
102  Limit{shaderc_limit::shaderc_limit_max_vertex_texture_image_units, 16},
103  Limit{shaderc_limit::shaderc_limit_max_combined_texture_image_units, 80},
104  Limit{shaderc_limit::shaderc_limit_max_texture_image_units, 16},
105  Limit{shaderc_limit::shaderc_limit_max_fragment_uniform_components, 1024},
106  Limit{shaderc_limit::shaderc_limit_max_draw_buffers, 8},
107  Limit{shaderc_limit::shaderc_limit_max_vertex_uniform_vectors, 256},
108  Limit{shaderc_limit::shaderc_limit_max_varying_vectors, 15},
109  Limit{shaderc_limit::shaderc_limit_max_fragment_uniform_vectors, 256},
110  Limit{shaderc_limit::shaderc_limit_max_vertex_output_vectors, 16},
111  Limit{shaderc_limit::shaderc_limit_max_fragment_input_vectors, 15},
112  Limit{shaderc_limit::shaderc_limit_min_program_texel_offset, -8},
113  Limit{shaderc_limit::shaderc_limit_max_program_texel_offset, 7},
114  Limit{shaderc_limit::shaderc_limit_max_clip_distances, 8},
115  Limit{shaderc_limit::shaderc_limit_max_compute_work_group_count_x, 65535},
116  Limit{shaderc_limit::shaderc_limit_max_compute_work_group_count_y, 65535},
117  Limit{shaderc_limit::shaderc_limit_max_compute_work_group_count_z, 65535},
118  Limit{shaderc_limit::shaderc_limit_max_compute_work_group_size_x, 1024},
119  Limit{shaderc_limit::shaderc_limit_max_compute_work_group_size_y, 1024},
120  Limit{shaderc_limit::shaderc_limit_max_compute_work_group_size_z, 64},
121  Limit{shaderc_limit::shaderc_limit_max_compute_uniform_components, 512},
122  Limit{shaderc_limit::shaderc_limit_max_compute_texture_image_units, 16},
123  Limit{shaderc_limit::shaderc_limit_max_compute_image_uniforms, 8},
124  Limit{shaderc_limit::shaderc_limit_max_compute_atomic_counters, 8},
125  Limit{shaderc_limit::shaderc_limit_max_compute_atomic_counter_buffers, 1},
126  Limit{shaderc_limit::shaderc_limit_max_varying_components, 60},
127  Limit{shaderc_limit::shaderc_limit_max_vertex_output_components, 64},
128  Limit{shaderc_limit::shaderc_limit_max_geometry_input_components, 64},
129  Limit{shaderc_limit::shaderc_limit_max_geometry_output_components, 128},
130  Limit{shaderc_limit::shaderc_limit_max_fragment_input_components, 128},
131  Limit{shaderc_limit::shaderc_limit_max_image_units, 8},
132  Limit{shaderc_limit::
133  shaderc_limit_max_combined_image_units_and_fragment_outputs,
134  8},
135  Limit{shaderc_limit::shaderc_limit_max_combined_shader_output_resources,
136  8},
137  Limit{shaderc_limit::shaderc_limit_max_image_samples, 0},
138  Limit{shaderc_limit::shaderc_limit_max_vertex_image_uniforms, 0},
139  Limit{shaderc_limit::shaderc_limit_max_tess_control_image_uniforms, 0},
140  Limit{shaderc_limit::shaderc_limit_max_tess_evaluation_image_uniforms, 0},
141  Limit{shaderc_limit::shaderc_limit_max_geometry_image_uniforms, 0},
142  Limit{shaderc_limit::shaderc_limit_max_fragment_image_uniforms, 8},
143  Limit{shaderc_limit::shaderc_limit_max_combined_image_uniforms, 8},
144  Limit{shaderc_limit::shaderc_limit_max_geometry_texture_image_units, 16},
145  Limit{shaderc_limit::shaderc_limit_max_geometry_output_vertices, 256},
146  Limit{shaderc_limit::shaderc_limit_max_geometry_total_output_components,
147  1024},
148  Limit{shaderc_limit::shaderc_limit_max_geometry_uniform_components, 512},
149  Limit{shaderc_limit::shaderc_limit_max_geometry_varying_components, 60},
150  Limit{shaderc_limit::shaderc_limit_max_tess_control_input_components,
151  128},
152  Limit{shaderc_limit::shaderc_limit_max_tess_control_output_components,
153  128},
154  Limit{shaderc_limit::shaderc_limit_max_tess_control_texture_image_units,
155  16},
156  Limit{shaderc_limit::shaderc_limit_max_tess_control_uniform_components,
157  1024},
158  Limit{
159  shaderc_limit::shaderc_limit_max_tess_control_total_output_components,
160  4096},
161  Limit{shaderc_limit::shaderc_limit_max_tess_evaluation_input_components,
162  128},
163  Limit{shaderc_limit::shaderc_limit_max_tess_evaluation_output_components,
164  128},
165  Limit{
166  shaderc_limit::shaderc_limit_max_tess_evaluation_texture_image_units,
167  16},
168  Limit{shaderc_limit::shaderc_limit_max_tess_evaluation_uniform_components,
169  1024},
170  Limit{shaderc_limit::shaderc_limit_max_tess_patch_components, 120},
171  Limit{shaderc_limit::shaderc_limit_max_patch_vertices, 32},
172  Limit{shaderc_limit::shaderc_limit_max_tess_gen_level, 64},
173  Limit{shaderc_limit::shaderc_limit_max_viewports, 16},
174  Limit{shaderc_limit::shaderc_limit_max_vertex_atomic_counters, 0},
175  Limit{shaderc_limit::shaderc_limit_max_tess_control_atomic_counters, 0},
176  Limit{shaderc_limit::shaderc_limit_max_tess_evaluation_atomic_counters,
177  0},
178  Limit{shaderc_limit::shaderc_limit_max_geometry_atomic_counters, 0},
179  Limit{shaderc_limit::shaderc_limit_max_fragment_atomic_counters, 8},
180  Limit{shaderc_limit::shaderc_limit_max_combined_atomic_counters, 8},
181  Limit{shaderc_limit::shaderc_limit_max_atomic_counter_bindings, 1},
182  Limit{shaderc_limit::shaderc_limit_max_vertex_atomic_counter_buffers, 0},
183  Limit{
184  shaderc_limit::shaderc_limit_max_tess_control_atomic_counter_buffers,
185  0},
186  Limit{shaderc_limit::
187  shaderc_limit_max_tess_evaluation_atomic_counter_buffers,
188  0},
189  Limit{shaderc_limit::shaderc_limit_max_geometry_atomic_counter_buffers,
190  0},
191  Limit{shaderc_limit::shaderc_limit_max_fragment_atomic_counter_buffers,
192  0},
193  Limit{shaderc_limit::shaderc_limit_max_combined_atomic_counter_buffers,
194  1},
195  Limit{shaderc_limit::shaderc_limit_max_atomic_counter_buffer_size, 32},
196  Limit{shaderc_limit::shaderc_limit_max_transform_feedback_buffers, 4},
197  Limit{shaderc_limit::
198  shaderc_limit_max_transform_feedback_interleaved_components,
199  64},
200  Limit{shaderc_limit::shaderc_limit_max_cull_distances, 8},
201  Limit{shaderc_limit::shaderc_limit_max_combined_clip_and_cull_distances,
202  8},
203  Limit{shaderc_limit::shaderc_limit_max_samples, 4},
204  };
205  for (auto& [limit, value] : limits) {
206  compiler_opts.SetLimit(limit, value);
207  }
208 }

Referenced by impeller::compiler::SPIRVCompilerOptions::BuildShadercOptions().

◆ SetPermissiveAccess()

static bool impeller::compiler::SetPermissiveAccess ( const std::filesystem::path &  p)
static

Definition at line 25 of file impellerc_main.cc.

25  {
26  auto permissions =
27  std::filesystem::perms::owner_read | std::filesystem::perms::owner_write |
28  std::filesystem::perms::group_read | std::filesystem::perms::others_read;
29  std::error_code error;
30  std::filesystem::permissions(p, permissions, error);
31  if (error) {
32  std::cerr << "Failed to set access on file '" << p
33  << "': " << error.message() << std::endl;
34  return false;
35  }
36  return true;
37 }

Referenced by Main().

◆ ShaderCErrorToString()

std::string impeller::compiler::ShaderCErrorToString ( shaderc_compilation_status  status)

Definition at line 144 of file types.cc.

144  {
145  using Status = shaderc_compilation_status;
146  switch (status) {
147  case Status::shaderc_compilation_status_success:
148  return "Success";
149  case Status::shaderc_compilation_status_invalid_stage:
150  return "Invalid shader stage specified";
151  case Status::shaderc_compilation_status_compilation_error:
152  return "Compilation error";
153  case Status::shaderc_compilation_status_internal_error:
154  return "Internal error";
155  case Status::shaderc_compilation_status_null_result_object:
156  return "Internal error. Null result object";
157  case Status::shaderc_compilation_status_invalid_assembly:
158  return "Invalid assembly";
159  case Status::shaderc_compilation_status_validation_error:
160  return "Validation error";
161  case Status::shaderc_compilation_status_transformation_error:
162  return "Transformation error";
163  case Status::shaderc_compilation_status_configuration_error:
164  return "Configuration error";
165  }
166  return "Unknown internal error";
167 }

Referenced by impeller::compiler::SPIRVCompiler::CompileToSPV().

◆ SourceLanguageToString()

std::string impeller::compiler::SourceLanguageToString ( SourceLanguage  source_language)

Definition at line 79 of file types.cc.

79  {
80  switch (source_language) {
81  case SourceLanguage::kUnknown:
82  return "Unknown";
83  case SourceLanguage::kGLSL:
84  return "GLSL";
85  case SourceLanguage::kHLSL:
86  return "HLSL";
87  }
88 }

References kGLSL, kHLSL, and kUnknown.

Referenced by impeller::compiler::SPIRVCompiler::CompileToSPV().

◆ SourceTypeFromCommandLine()

static SourceType impeller::compiler::SourceTypeFromCommandLine ( const fml::CommandLine &  command_line)
static

Definition at line 102 of file switches.cc.

103  {
104  auto source_type_option =
105  command_line.GetOptionValueWithDefault("input-type", "");
106  auto source_type_search = kKnownSourceTypes.find(source_type_option);
107  if (source_type_search == kKnownSourceTypes.end()) {
108  return SourceType::kUnknown;
109  }
110  return source_type_search->second;
111 }

References kKnownSourceTypes, and kUnknown.

◆ SourceTypeFromFileName()

SourceType impeller::compiler::SourceTypeFromFileName ( const std::string &  file_name)

Definition at line 29 of file types.cc.

29  {
30  if (StringEndWith(file_name, ".vert")) {
31  return SourceType::kVertexShader;
32  }
33 
34  if (StringEndWith(file_name, ".frag")) {
35  return SourceType::kFragmentShader;
36  }
37 
38  if (StringEndWith(file_name, ".tesc")) {
39  return SourceType::kTessellationControlShader;
40  }
41 
42  if (StringEndWith(file_name, ".tese")) {
43  return SourceType::kTessellationEvaluationShader;
44  }
45 
46  if (StringEndWith(file_name, ".comp")) {
47  return SourceType::kComputeShader;
48  }
49 
50  return SourceType::kUnknown;
51 }

References kComputeShader, kFragmentShader, kTessellationControlShader, kTessellationEvaluationShader, kUnknown, kVertexShader, and StringEndWith().

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

◆ SourceTypeToString()

std::string impeller::compiler::SourceTypeToString ( SourceType  type)

Definition at line 225 of file types.cc.

225  {
226  switch (type) {
227  case SourceType::kUnknown:
228  return "unknown";
229  case SourceType::kVertexShader:
230  return "vert";
231  case SourceType::kFragmentShader:
232  return "frag";
233  case SourceType::kTessellationControlShader:
234  return "tesc";
235  case SourceType::kTessellationEvaluationShader:
236  return "tese";
237  case SourceType::kComputeShader:
238  return "comp";
239  }
240  FML_UNREACHABLE();
241 }

References kComputeShader, kFragmentShader, kTessellationControlShader, kTessellationEvaluationShader, kUnknown, and kVertexShader.

◆ StringEndWith()

static bool impeller::compiler::StringEndWith ( const std::string &  string,
const std::string &  suffix 
)
static

Definition at line 16 of file types.cc.

17  {
18  if (suffix.size() > string.size()) {
19  return false;
20  }
21 
22  if (suffix.empty() || suffix.empty()) {
23  return false;
24  }
25 
26  return string.rfind(suffix) == (string.size() - suffix.size());
27 }

Referenced by SourceTypeFromFileName().

◆ StringStartsWith()

bool impeller::compiler::StringStartsWith ( const std::string &  target,
const std::string &  prefix 
)

Definition at line 64 of file utilities.cc.

64  {
65  if (prefix.length() > target.length()) {
66  return false;
67  }
68  for (size_t i = 0; i < prefix.length(); i++) {
69  if (target[i] != prefix[i]) {
70  return false;
71  }
72  }
73  return true;
74 }

Referenced by CreateGLSLCompiler().

◆ StringToShaderStage()

static std::string impeller::compiler::StringToShaderStage ( std::string  str)
static

Definition at line 90 of file reflector.cc.

90  {
91  if (str == "vertex") {
92  return "ShaderStage::kVertex";
93  }
94 
95  if (str == "fragment") {
96  return "ShaderStage::kFragment";
97  }
98 
99  if (str == "tessellation_control") {
100  return "ShaderStage::kTessellationControl";
101  }
102 
103  if (str == "tessellation_evaluation") {
104  return "ShaderStage::kTessellationEvaluation";
105  }
106 
107  if (str == "compute") {
108  return "ShaderStage::kCompute";
109  }
110 
111  return "ShaderStage::kUnknown";
112 }

◆ TargetPlatformBundlesSkSL()

bool impeller::compiler::TargetPlatformBundlesSkSL ( TargetPlatform  platform)

Definition at line 317 of file types.cc.

317  {
318  switch (platform) {
319  case TargetPlatform::kSkSL:
320  case TargetPlatform::kRuntimeStageMetal:
321  case TargetPlatform::kRuntimeStageGLES:
322  case TargetPlatform::kRuntimeStageVulkan:
323  return true;
324  case TargetPlatform::kMetalDesktop:
325  case TargetPlatform::kMetalIOS:
326  case TargetPlatform::kUnknown:
327  case TargetPlatform::kOpenGLES:
328  case TargetPlatform::kOpenGLDesktop:
329  case TargetPlatform::kVulkan:
330  return false;
331  }
332  FML_UNREACHABLE();
333 }

References kMetalDesktop, kMetalIOS, kOpenGLDesktop, kOpenGLES, kRuntimeStageGLES, kRuntimeStageMetal, kRuntimeStageVulkan, kSkSL, kUnknown, and kVulkan.

Referenced by Main().

◆ TargetPlatformFromCommandLine()

static TargetPlatform impeller::compiler::TargetPlatformFromCommandLine ( const fml::CommandLine &  command_line)
static

Definition at line 84 of file switches.cc.

85  {
86  auto target = TargetPlatform::kUnknown;
87  for (const auto& platform : kKnownPlatforms) {
88  if (command_line.HasOption(platform.first)) {
89  // If the platform has already been determined, the caller may have
90  // specified multiple platforms. This is an error and only one must be
91  // selected.
92  if (target != TargetPlatform::kUnknown) {
93  return TargetPlatform::kUnknown;
94  }
95  target = platform.second;
96  // Keep going to detect duplicates.
97  }
98  }
99  return target;
100 }

References kKnownPlatforms, and kUnknown.

◆ TargetPlatformIsMetal()

bool impeller::compiler::TargetPlatformIsMetal ( TargetPlatform  platform)

Definition at line 281 of file types.cc.

281  {
282  switch (platform) {
283  case TargetPlatform::kMetalDesktop:
284  case TargetPlatform::kMetalIOS:
285  case TargetPlatform::kRuntimeStageMetal:
286  return true;
287  case TargetPlatform::kUnknown:
288  case TargetPlatform::kSkSL:
289  case TargetPlatform::kOpenGLES:
290  case TargetPlatform::kOpenGLDesktop:
291  case TargetPlatform::kRuntimeStageGLES:
292  case TargetPlatform::kRuntimeStageVulkan:
293  case TargetPlatform::kVulkan:
294  return false;
295  }
296  FML_UNREACHABLE();
297 }

References kMetalDesktop, kMetalIOS, kOpenGLDesktop, kOpenGLES, kRuntimeStageGLES, kRuntimeStageMetal, kRuntimeStageVulkan, kSkSL, kUnknown, and kVulkan.

Referenced by impeller::compiler::testing::TEST_P().

◆ TargetPlatformIsOpenGL()

bool impeller::compiler::TargetPlatformIsOpenGL ( TargetPlatform  platform)

Definition at line 263 of file types.cc.

263  {
264  switch (platform) {
265  case TargetPlatform::kOpenGLES:
266  case TargetPlatform::kOpenGLDesktop:
267  case TargetPlatform::kRuntimeStageGLES:
268  return true;
269  case TargetPlatform::kMetalDesktop:
270  case TargetPlatform::kRuntimeStageMetal:
271  case TargetPlatform::kRuntimeStageVulkan:
272  case TargetPlatform::kMetalIOS:
273  case TargetPlatform::kUnknown:
274  case TargetPlatform::kSkSL:
275  case TargetPlatform::kVulkan:
276  return false;
277  }
278  FML_UNREACHABLE();
279 }

References kMetalDesktop, kMetalIOS, kOpenGLDesktop, kOpenGLES, kRuntimeStageGLES, kRuntimeStageMetal, kRuntimeStageVulkan, kSkSL, kUnknown, and kVulkan.

◆ TargetPlatformIsVulkan()

bool impeller::compiler::TargetPlatformIsVulkan ( TargetPlatform  platform)

Definition at line 299 of file types.cc.

299  {
300  switch (platform) {
301  case TargetPlatform::kRuntimeStageVulkan:
302  case TargetPlatform::kVulkan:
303  return true;
304  case TargetPlatform::kMetalDesktop:
305  case TargetPlatform::kMetalIOS:
306  case TargetPlatform::kRuntimeStageMetal:
307  case TargetPlatform::kUnknown:
308  case TargetPlatform::kSkSL:
309  case TargetPlatform::kOpenGLES:
310  case TargetPlatform::kOpenGLDesktop:
311  case TargetPlatform::kRuntimeStageGLES:
312  return false;
313  }
314  FML_UNREACHABLE();
315 }

References kMetalDesktop, kMetalIOS, kOpenGLDesktop, kOpenGLES, kRuntimeStageGLES, kRuntimeStageMetal, kRuntimeStageVulkan, kSkSL, kUnknown, and kVulkan.

Referenced by impeller::compiler::testing::TEST_P().

◆ TargetPlatformNeedsReflection()

bool impeller::compiler::TargetPlatformNeedsReflection ( TargetPlatform  platform)

Definition at line 126 of file types.cc.

126  {
127  switch (platform) {
128  case TargetPlatform::kMetalIOS:
129  case TargetPlatform::kMetalDesktop:
130  case TargetPlatform::kOpenGLES:
131  case TargetPlatform::kOpenGLDesktop:
132  case TargetPlatform::kRuntimeStageMetal:
133  case TargetPlatform::kRuntimeStageGLES:
134  case TargetPlatform::kRuntimeStageVulkan:
135  case TargetPlatform::kVulkan:
136  return true;
137  case TargetPlatform::kUnknown:
138  case TargetPlatform::kSkSL:
139  return false;
140  }
141  FML_UNREACHABLE();
142 }

References kMetalDesktop, kMetalIOS, kOpenGLDesktop, kOpenGLES, kRuntimeStageGLES, kRuntimeStageMetal, kRuntimeStageVulkan, kSkSL, kUnknown, and kVulkan.

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

◆ TargetPlatformSLExtension()

std::string impeller::compiler::TargetPlatformSLExtension ( TargetPlatform  platform)

Definition at line 243 of file types.cc.

243  {
244  switch (platform) {
245  case TargetPlatform::kUnknown:
246  return "unknown";
247  case TargetPlatform::kMetalDesktop:
248  case TargetPlatform::kMetalIOS:
249  case TargetPlatform::kRuntimeStageMetal:
250  return "metal";
251  case TargetPlatform::kSkSL:
252  case TargetPlatform::kOpenGLES:
253  case TargetPlatform::kOpenGLDesktop:
254  case TargetPlatform::kRuntimeStageGLES:
255  return "glsl";
256  case TargetPlatform::kVulkan:
257  case TargetPlatform::kRuntimeStageVulkan:
258  return "vk.spirv";
259  }
260  FML_UNREACHABLE();
261 }

References kMetalDesktop, kMetalIOS, kOpenGLDesktop, kOpenGLES, kRuntimeStageGLES, kRuntimeStageMetal, kRuntimeStageVulkan, kSkSL, kUnknown, and kVulkan.

Referenced by impeller::compiler::testing::SLFileName().

◆ TargetPlatformToMSLPlatform()

spirv_cross::CompilerMSL::Options::Platform impeller::compiler::TargetPlatformToMSLPlatform ( TargetPlatform  platform)

Definition at line 205 of file types.cc.

206  {
207  switch (platform) {
208  case TargetPlatform::kMetalIOS:
209  case TargetPlatform::kRuntimeStageMetal:
210  return spirv_cross::CompilerMSL::Options::Platform::iOS;
211  case TargetPlatform::kMetalDesktop:
212  return spirv_cross::CompilerMSL::Options::Platform::macOS;
213  case TargetPlatform::kSkSL:
214  case TargetPlatform::kOpenGLES:
215  case TargetPlatform::kOpenGLDesktop:
216  case TargetPlatform::kRuntimeStageGLES:
217  case TargetPlatform::kRuntimeStageVulkan:
218  case TargetPlatform::kVulkan:
219  case TargetPlatform::kUnknown:
220  return spirv_cross::CompilerMSL::Options::Platform::macOS;
221  }
222  FML_UNREACHABLE();
223 }

References kMetalDesktop, kMetalIOS, kOpenGLDesktop, kOpenGLES, kRuntimeStageGLES, kRuntimeStageMetal, kRuntimeStageVulkan, kSkSL, kUnknown, and kVulkan.

◆ TargetPlatformToString()

std::string impeller::compiler::TargetPlatformToString ( TargetPlatform  platform)

Definition at line 53 of file types.cc.

53  {
54  switch (platform) {
55  case TargetPlatform::kUnknown:
56  return "Unknown";
57  case TargetPlatform::kMetalDesktop:
58  return "MetalDesktop";
59  case TargetPlatform::kMetalIOS:
60  return "MetaliOS";
61  case TargetPlatform::kOpenGLES:
62  return "OpenGLES";
63  case TargetPlatform::kOpenGLDesktop:
64  return "OpenGLDesktop";
65  case TargetPlatform::kVulkan:
66  return "Vulkan";
67  case TargetPlatform::kRuntimeStageMetal:
68  return "RuntimeStageMetal";
69  case TargetPlatform::kRuntimeStageGLES:
70  return "RuntimeStageGLES";
71  case TargetPlatform::kRuntimeStageVulkan:
72  return "RuntimeStageVulkan";
73  case TargetPlatform::kSkSL:
74  return "SkSL";
75  }
76  FML_UNREACHABLE();
77 }

References kMetalDesktop, kMetalIOS, kOpenGLDesktop, kOpenGLES, kRuntimeStageGLES, kRuntimeStageMetal, kRuntimeStageVulkan, kSkSL, kUnknown, and kVulkan.

◆ ToExecutionModel()

spv::ExecutionModel impeller::compiler::ToExecutionModel ( SourceType  type)

Definition at line 187 of file types.cc.

187  {
188  switch (type) {
189  case SourceType::kVertexShader:
190  return spv::ExecutionModel::ExecutionModelVertex;
191  case SourceType::kFragmentShader:
192  return spv::ExecutionModel::ExecutionModelFragment;
193  case SourceType::kTessellationControlShader:
194  return spv::ExecutionModel::ExecutionModelTessellationControl;
195  case SourceType::kTessellationEvaluationShader:
196  return spv::ExecutionModel::ExecutionModelTessellationEvaluation;
197  case SourceType::kComputeShader:
198  return spv::ExecutionModel::ExecutionModelGLCompute;
199  case SourceType::kUnknown:
200  break;
201  }
202  return spv::ExecutionModel::ExecutionModelMax;
203 }

References kComputeShader, kFragmentShader, kTessellationControlShader, kTessellationEvaluationShader, kUnknown, and kVertexShader.

Referenced by CreateCompiler().

◆ ToJsonStage()

static std::optional<uint32_t> impeller::compiler::ToJsonStage ( spv::ExecutionModel  stage)
static

Definition at line 57 of file runtime_stage_data.cc.

57  {
58  switch (stage) {
59  case spv::ExecutionModel::ExecutionModelVertex:
60  return 0; // fb::Stage::kVertex;
61  case spv::ExecutionModel::ExecutionModelFragment:
62  return 1; // fb::Stage::kFragment;
63  case spv::ExecutionModel::ExecutionModelGLCompute:
64  return 2; // fb::Stage::kCompute;
65  case spv::ExecutionModel::ExecutionModelTessellationControl:
66  return 3; // fb::Stage::kTessellationControl;
67  case spv::ExecutionModel::ExecutionModelTessellationEvaluation:
68  return 4; // fb::Stage::kTessellationEvaluation;
69  default:
70  return std::nullopt;
71  }
72  FML_UNREACHABLE();
73 }

Referenced by impeller::compiler::RuntimeStageData::CreateJsonMapping().

◆ ToJsonTargetPlatform()

static std::optional<uint32_t> impeller::compiler::ToJsonTargetPlatform ( TargetPlatform  platform)
static

Definition at line 97 of file runtime_stage_data.cc.

97  {
98  switch (platform) {
99  case TargetPlatform::kUnknown:
100  case TargetPlatform::kMetalDesktop:
101  case TargetPlatform::kMetalIOS:
102  case TargetPlatform::kOpenGLES:
103  case TargetPlatform::kOpenGLDesktop:
104  case TargetPlatform::kVulkan:
105  return std::nullopt;
106  case TargetPlatform::kSkSL:
107  return static_cast<uint32_t>(fb::TargetPlatform::kSkSL);
108  case TargetPlatform::kRuntimeStageMetal:
109  return static_cast<uint32_t>(fb::TargetPlatform::kMetal);
110  case TargetPlatform::kRuntimeStageGLES:
111  return static_cast<uint32_t>(fb::TargetPlatform::kOpenGLES);
112  case TargetPlatform::kRuntimeStageVulkan:
113  return static_cast<uint32_t>(fb::TargetPlatform::kVulkan);
114  }
115  FML_UNREACHABLE();
116 }

References kMetalDesktop, kMetalIOS, kOpenGLDesktop, kOpenGLES, kRuntimeStageGLES, kRuntimeStageMetal, kRuntimeStageVulkan, kSkSL, kUnknown, and kVulkan.

Referenced by impeller::compiler::RuntimeStageData::CreateJsonMapping().

◆ ToJsonType()

static std::optional<uint32_t> impeller::compiler::ToJsonType ( spirv_cross::SPIRType::BaseType  type)
static

Definition at line 163 of file runtime_stage_data.cc.

164  {
165  switch (type) {
166  case spirv_cross::SPIRType::Boolean:
167  return 0; // fb::UniformDataType::kBoolean;
168  case spirv_cross::SPIRType::SByte:
169  return 1; // fb::UniformDataType::kSignedByte;
170  case spirv_cross::SPIRType::UByte:
171  return 2; // fb::UniformDataType::kUnsignedByte;
172  case spirv_cross::SPIRType::Short:
173  return 3; // fb::UniformDataType::kSignedShort;
174  case spirv_cross::SPIRType::UShort:
175  return 4; // fb::UniformDataType::kUnsignedShort;
176  case spirv_cross::SPIRType::Int:
177  return 5; // fb::UniformDataType::kSignedInt;
178  case spirv_cross::SPIRType::UInt:
179  return 6; // fb::UniformDataType::kUnsignedInt;
180  case spirv_cross::SPIRType::Int64:
181  return 7; // fb::UniformDataType::kSignedInt64;
182  case spirv_cross::SPIRType::UInt64:
183  return 8; // fb::UniformDataType::kUnsignedInt64;
184  case spirv_cross::SPIRType::Half:
185  return 9; // b::UniformDataType::kHalfFloat;
186  case spirv_cross::SPIRType::Float:
187  return 10; // fb::UniformDataType::kFloat;
188  case spirv_cross::SPIRType::Double:
189  return 11; // fb::UniformDataType::kDouble;
190  case spirv_cross::SPIRType::SampledImage:
191  return 12; // fb::UniformDataType::kSampledImage;
192  case spirv_cross::SPIRType::AccelerationStructure:
193  case spirv_cross::SPIRType::AtomicCounter:
194  case spirv_cross::SPIRType::Char:
195  case spirv_cross::SPIRType::ControlPointArray:
196  case spirv_cross::SPIRType::Image:
197  case spirv_cross::SPIRType::Interpolant:
198  case spirv_cross::SPIRType::RayQuery:
199  case spirv_cross::SPIRType::Sampler:
200  case spirv_cross::SPIRType::Struct:
201  case spirv_cross::SPIRType::Unknown:
202  case spirv_cross::SPIRType::Void:
203  return std::nullopt;
204  }
205  FML_UNREACHABLE();
206 }

Referenced by impeller::compiler::RuntimeStageData::CreateJsonMapping().

◆ ToShaderCShaderKind()

shaderc_shader_kind impeller::compiler::ToShaderCShaderKind ( SourceType  type)

Definition at line 169 of file types.cc.

169  {
170  switch (type) {
171  case SourceType::kVertexShader:
172  return shaderc_shader_kind::shaderc_vertex_shader;
173  case SourceType::kFragmentShader:
174  return shaderc_shader_kind::shaderc_fragment_shader;
175  case SourceType::kTessellationControlShader:
176  return shaderc_shader_kind::shaderc_tess_control_shader;
177  case SourceType::kTessellationEvaluationShader:
178  return shaderc_shader_kind::shaderc_tess_evaluation_shader;
179  case SourceType::kComputeShader:
180  return shaderc_shader_kind::shaderc_compute_shader;
181  case SourceType::kUnknown:
182  break;
183  }
184  return shaderc_shader_kind::shaderc_glsl_infer_from_source;
185 }

References kComputeShader, kFragmentShader, kTessellationControlShader, kTessellationEvaluationShader, kUnknown, and kVertexShader.

Referenced by impeller::compiler::SPIRVCompiler::CompileToSPV().

◆ ToStage()

static std::optional<fb::Stage> impeller::compiler::ToStage ( spv::ExecutionModel  stage)
static

Definition at line 39 of file runtime_stage_data.cc.

39  {
40  switch (stage) {
41  case spv::ExecutionModel::ExecutionModelVertex:
42  return fb::Stage::kVertex;
43  case spv::ExecutionModel::ExecutionModelFragment:
44  return fb::Stage::kFragment;
45  case spv::ExecutionModel::ExecutionModelGLCompute:
46  return fb::Stage::kCompute;
47  case spv::ExecutionModel::ExecutionModelTessellationControl:
48  return fb::Stage::kTessellationControl;
49  case spv::ExecutionModel::ExecutionModelTessellationEvaluation:
50  return fb::Stage::kTessellationEvaluation;
51  default:
52  return std::nullopt;
53  }
54  FML_UNREACHABLE();
55 }

Referenced by impeller::compiler::RuntimeStageData::CreateMapping().

◆ ToString()

static std::string impeller::compiler::ToString ( CompilerBackend::Type  type)
static

Definition at line 368 of file reflector.cc.

368  {
369  switch (type) {
370  case CompilerBackend::Type::kMSL:
371  return "Metal Shading Language";
372  case CompilerBackend::Type::kGLSL:
373  return "OpenGL Shading Language";
374  case CompilerBackend::Type::kSkSL:
375  return "SkSL Shading Language";
376  }
377  FML_UNREACHABLE();
378 }

References impeller::compiler::CompilerBackend::kGLSL, impeller::compiler::CompilerBackend::kMSL, and impeller::compiler::CompilerBackend::kSkSL.

◆ ToTargetPlatform()

static std::optional<fb::TargetPlatform> impeller::compiler::ToTargetPlatform ( TargetPlatform  platform)
static

Definition at line 75 of file runtime_stage_data.cc.

76  {
77  switch (platform) {
78  case TargetPlatform::kUnknown:
79  case TargetPlatform::kMetalDesktop:
80  case TargetPlatform::kMetalIOS:
81  case TargetPlatform::kOpenGLES:
82  case TargetPlatform::kOpenGLDesktop:
83  case TargetPlatform::kVulkan:
84  return std::nullopt;
85  case TargetPlatform::kSkSL:
86  return fb::TargetPlatform::kSkSL;
87  case TargetPlatform::kRuntimeStageMetal:
88  return fb::TargetPlatform::kMetal;
89  case TargetPlatform::kRuntimeStageGLES:
90  return fb::TargetPlatform::kOpenGLES;
91  case TargetPlatform::kRuntimeStageVulkan:
92  return fb::TargetPlatform::kVulkan;
93  }
94  FML_UNREACHABLE();
95 }

References kMetalDesktop, kMetalIOS, kOpenGLDesktop, kOpenGLES, kRuntimeStageGLES, kRuntimeStageMetal, kRuntimeStageVulkan, kSkSL, kUnknown, and kVulkan.

Referenced by impeller::compiler::RuntimeStageData::CreateMapping().

◆ ToType()

static std::optional<fb::UniformDataType> impeller::compiler::ToType ( spirv_cross::SPIRType::BaseType  type)
static

Definition at line 118 of file runtime_stage_data.cc.

119  {
120  switch (type) {
121  case spirv_cross::SPIRType::Boolean:
123  case spirv_cross::SPIRType::SByte:
125  case spirv_cross::SPIRType::UByte:
127  case spirv_cross::SPIRType::Short:
129  case spirv_cross::SPIRType::UShort:
131  case spirv_cross::SPIRType::Int:
133  case spirv_cross::SPIRType::UInt:
135  case spirv_cross::SPIRType::Int64:
137  case spirv_cross::SPIRType::UInt64:
139  case spirv_cross::SPIRType::Half:
141  case spirv_cross::SPIRType::Float:
143  case spirv_cross::SPIRType::Double:
145  case spirv_cross::SPIRType::SampledImage:
147  case spirv_cross::SPIRType::AccelerationStructure:
148  case spirv_cross::SPIRType::AtomicCounter:
149  case spirv_cross::SPIRType::Char:
150  case spirv_cross::SPIRType::ControlPointArray:
151  case spirv_cross::SPIRType::Image:
152  case spirv_cross::SPIRType::Interpolant:
153  case spirv_cross::SPIRType::RayQuery:
154  case spirv_cross::SPIRType::Sampler:
155  case spirv_cross::SPIRType::Struct:
156  case spirv_cross::SPIRType::Unknown:
157  case spirv_cross::SPIRType::Void:
158  return std::nullopt;
159  }
160  FML_UNREACHABLE();
161 }

References impeller::kBoolean, impeller::kDouble, impeller::kFloat, impeller::kHalfFloat, impeller::kSampledImage, impeller::kSignedByte, impeller::kSignedInt, impeller::kSignedInt64, impeller::kSignedShort, impeller::kUnsignedByte, impeller::kUnsignedInt, impeller::kUnsignedInt64, and impeller::kUnsignedShort.

Referenced by impeller::compiler::RuntimeStageData::CreateMapping().

◆ TypeNameWithPaddingOfSize()

static std::string impeller::compiler::TypeNameWithPaddingOfSize ( size_t  size)
static

Definition at line 521 of file reflector.cc.

521  {
522  std::stringstream stream;
523  stream << "Padding<" << size << ">";
524  return stream.str();
525 }

Referenced by VertexTypeFromInputResource().

◆ Utf8FromPath()

std::string impeller::compiler::Utf8FromPath ( const std::filesystem::path &  path)

Converts a native format path to a utf8 string.

    This utility uses `path::u8string()` to convert native paths to
    utf8. If the given path doesn't match the underlying native path
    format, and the native path format isn't utf8 (i.e. Windows, which
    has utf16 paths), the path will get mangled. 

Definition at line 14 of file utilities.cc.

14  {
15  return reinterpret_cast<const char*>(path.u8string().c_str());
16 }

Referenced by impeller::compiler::Switches::AreValid(), EntryPointFunctionNameFromSourceName(), InferShaderNameFromPath(), Main(), impeller::scene::importer::Main(), and impeller::compiler::Switches::Switches().

◆ VertexTypeFromInputResource()

static VertexType impeller::compiler::VertexTypeFromInputResource ( const spirv_cross::Compiler &  compiler,
const spirv_cross::Resource *  resource 
)
static

Definition at line 980 of file reflector.cc.

982  {
983  VertexType result;
984  result.variable_name = resource->name;
985  const auto type = compiler.get_type(resource->type_id);
986  result.base_type_name = BaseTypeToString(type.basetype);
987  const auto total_size = type.columns * type.vecsize * type.width / 8u;
988  result.byte_length = total_size;
989 
990  if (type.basetype == spirv_cross::SPIRType::BaseType::Float &&
991  type.columns == 1u && type.vecsize == 2u &&
992  type.width == sizeof(float) * 8u) {
993  result.type_name = "Point";
994  } else if (type.basetype == spirv_cross::SPIRType::BaseType::Float &&
995  type.columns == 1u && type.vecsize == 4u &&
996  type.width == sizeof(float) * 8u) {
997  result.type_name = "Vector4";
998  } else if (type.basetype == spirv_cross::SPIRType::BaseType::Float &&
999  type.columns == 1u && type.vecsize == 3u &&
1000  type.width == sizeof(float) * 8u) {
1001  result.type_name = "Vector3";
1002  } else if (type.basetype == spirv_cross::SPIRType::BaseType::Float &&
1003  type.columns == 1u && type.vecsize == 1u &&
1004  type.width == sizeof(float) * 8u) {
1005  result.type_name = "Scalar";
1006  } else if (type.basetype == spirv_cross::SPIRType::BaseType::Int &&
1007  type.columns == 1u && type.vecsize == 1u &&
1008  type.width == sizeof(int32_t) * 8u) {
1009  result.type_name = "int32_t";
1010  } else {
1011  // Catch all unknown padding.
1012  result.type_name = TypeNameWithPaddingOfSize(total_size);
1013  }
1014 
1015  return result;
1016 }

References impeller::compiler::VertexType::base_type_name, BaseTypeToString(), impeller::compiler::VertexType::byte_length, impeller::compiler::VertexType::type_name, TypeNameWithPaddingOfSize(), and impeller::compiler::VertexType::variable_name.

Variable Documentation

◆ kEntrypointKey

const char* impeller::compiler::kEntrypointKey = "entrypoint"
static

Definition at line 210 of file runtime_stage_data.cc.

◆ kExternalTexturePrefix

constexpr char impeller::compiler::kExternalTexturePrefix[] = "SAMPLER_EXTERNAL_OES_"
constexpr

Definition at line 10 of file constants.h.

Referenced by CreateGLSLCompiler().

◆ kKnownPlatforms

const std::map<std::string, TargetPlatform> impeller::compiler::kKnownPlatforms
static
Initial value:
= {
{"metal-desktop", TargetPlatform::kMetalDesktop},
{"metal-ios", TargetPlatform::kMetalIOS},
{"vulkan", TargetPlatform::kVulkan},
{"opengl-es", TargetPlatform::kOpenGLES},
{"opengl-desktop", TargetPlatform::kOpenGLDesktop},
{"sksl", TargetPlatform::kSkSL},
{"runtime-stage-metal", TargetPlatform::kRuntimeStageMetal},
{"runtime-stage-gles", TargetPlatform::kRuntimeStageGLES},
{"runtime-stage-vulkan", TargetPlatform::kRuntimeStageVulkan},
}

Definition at line 19 of file switches.cc.

Referenced by impeller::compiler::Switches::PrintHelp(), and TargetPlatformFromCommandLine().

◆ kKnownSourceTypes

const std::map<std::string, SourceType> impeller::compiler::kKnownSourceTypes
static
Initial value:
= {
{"vert", SourceType::kVertexShader},
{"frag", SourceType::kFragmentShader},
{"tesc", SourceType::kTessellationControlShader},
{"tese", SourceType::kTessellationEvaluationShader},
{"comp", SourceType::kComputeShader},
}

Definition at line 31 of file switches.cc.

Referenced by impeller::compiler::Switches::PrintHelp(), and SourceTypeFromCommandLine().

◆ kReflectionCCTemplate

constexpr std::string_view impeller::compiler::kReflectionCCTemplate
constexpr

Definition at line 198 of file code_gen_template.h.

◆ kReflectionHeaderTemplate

constexpr std::string_view impeller::compiler::kReflectionHeaderTemplate
constexpr

Definition at line 10 of file code_gen_template.h.

◆ kShaderKey

const char* impeller::compiler::kShaderKey = "sksl"
static

◆ kStageKey

const char* impeller::compiler::kStageKey = "stage"
static

◆ kTargetPlatformKey

const char* impeller::compiler::kTargetPlatformKey = "target_platform"
static

◆ kUniformArrayElementsKey

const char* impeller::compiler::kUniformArrayElementsKey = "array_elements"
static

◆ kUniformBitWidthKey

const char* impeller::compiler::kUniformBitWidthKey = "bit_width"
static

◆ kUniformColumnsKey

const char* impeller::compiler::kUniformColumnsKey = "columns"
static

◆ kUniformLocationKey

const char* impeller::compiler::kUniformLocationKey = "location"
static

◆ kUniformNameKey

const char* impeller::compiler::kUniformNameKey = "name"
static

◆ kUniformRowsKey

const char* impeller::compiler::kUniformRowsKey = "rows"
static

◆ kUniformsKey

const char* impeller::compiler::kUniformsKey = "uniforms"
static

◆ kUniformTypeKey

const char* impeller::compiler::kUniformTypeKey = "type"
static
impeller::kBoolean
@ kBoolean
Definition: runtime_types.h:14
impeller::kFloat
@ kFloat
Definition: runtime_types.h:24
impeller::compiler::CreateVulkanCompiler
static CompilerBackend CreateVulkanCompiler(const spirv_cross::ParsedIR &ir, const SourceOptions &source_options)
Definition: compiler.cc:115
impeller::Scalar
float Scalar
Definition: scalar.h:15
impeller::kUnsignedShort
@ kUnsignedShort
Definition: runtime_types.h:18
impeller::compiler::CreateSkSLCompiler
static CompilerBackend CreateSkSLCompiler(const spirv_cross::ParsedIR &ir, const SourceOptions &source_options)
Definition: compiler.cc:175
impeller::compiler::ConvertToEntrypointName
std::string ConvertToEntrypointName(std::string_view string)
Ensure that the entrypoint name is a valid identifier in the target language.
Definition: utilities.cc:46
impeller::compiler::SourceType::kUnknown
@ kUnknown
impeller::compiler::EntryPointMustBeNamedMain
static bool EntryPointMustBeNamedMain(TargetPlatform platform)
Definition: compiler.cc:181
impeller::compiler::ParseMSLVersion
static uint32_t ParseMSLVersion(const std::string &msl_version)
Definition: compiler.cc:27
impeller::compiler::TargetPlatform::kMetalDesktop
@ kMetalDesktop
impeller::kSignedByte
@ kSignedByte
Definition: runtime_types.h:15
impeller::compiler::TargetPlatformToMSLPlatform
spirv_cross::CompilerMSL::Options::Platform TargetPlatformToMSLPlatform(TargetPlatform platform)
Definition: types.cc:205
impeller::kSampledImage
@ kSampledImage
Definition: runtime_types.h:26
impeller::compiler::CreateGLSLCompiler
static CompilerBackend CreateGLSLCompiler(const spirv_cross::ParsedIR &ir, const SourceOptions &source_options)
Definition: compiler.cc:129
impeller::compiler::TargetPlatformNeedsReflection
bool TargetPlatformNeedsReflection(TargetPlatform platform)
Definition: types.cc:126
impeller::compiler::InferShaderNameFromPath
std::string InferShaderNameFromPath(std::string_view path)
Definition: utilities.cc:18
impeller::compiler::TargetPlatform::kMetalIOS
@ kMetalIOS
impeller::compiler::SourceType::kTessellationControlShader
@ kTessellationControlShader
impeller::compiler::kKnownPlatforms
static const std::map< std::string, TargetPlatform > kKnownPlatforms
Definition: switches.cc:19
impeller::compiler::SourceLanguage::kGLSL
@ kGLSL
impeller::compiler::StringEndWith
static bool StringEndWith(const std::string &string, const std::string &suffix)
Definition: types.cc:16
impeller::kSignedInt
@ kSignedInt
Definition: runtime_types.h:19
impeller::compiler::kExternalTexturePrefix
constexpr char kExternalTexturePrefix[]
Definition: constants.h:10
impeller::SortUniforms
std::vector< spirv_cross::ID > SortUniforms(const spirv_cross::ParsedIR *ir, const spirv_cross::Compiler *compiler, std::optional< spirv_cross::SPIRType::BaseType > type_filter, bool include)
Sorts uniform declarations in an IR according to decoration order.
Definition: uniform_sorter.cc:9
impeller::compiler::SourceLanguage::kHLSL
@ kHLSL
impeller::compiler::TargetPlatform::kVulkan
@ kVulkan
impeller::compiler::SourceType::kFragmentShader
@ kFragmentShader
impeller::compiler::TargetPlatform::kRuntimeStageVulkan
@ kRuntimeStageVulkan
impeller::compiler::SourceType::kComputeShader
@ kComputeShader
impeller::compiler::EntryPointFunctionNameFromSourceName
std::string EntryPointFunctionNameFromSourceName(const std::string &file_name, SourceType type, SourceLanguage source_language, const std::string &entry_point_name)
Definition: types.cc:90
impeller::scene::importer::kKnownSourceTypes
static const std::map< std::string, SourceType > kKnownSourceTypes
Definition: switches.cc:20
impeller::compiler::SetPermissiveAccess
static bool SetPermissiveAccess(const std::filesystem::path &p)
Definition: impellerc_main.cc:25
impeller::kUnsignedByte
@ kUnsignedByte
Definition: runtime_types.h:16
impeller::kUnsignedInt64
@ kUnsignedInt64
Definition: runtime_types.h:22
impeller::kHalfFloat
@ kHalfFloat
Definition: runtime_types.h:23
impeller::kUnsignedInt
@ kUnsignedInt
Definition: runtime_types.h:20
impeller::compiler::ToExecutionModel
spv::ExecutionModel ToExecutionModel(SourceType type)
Definition: types.cc:187
impeller::kSignedShort
@ kSignedShort
Definition: runtime_types.h:17
impeller::compiler::SourceTypeFromFileName
SourceType SourceTypeFromFileName(const std::string &file_name)
Definition: types.cc:29
impeller::kDouble
@ kDouble
Definition: runtime_types.h:25
impeller::compiler::TargetPlatform::kOpenGLDesktop
@ kOpenGLDesktop
impeller::kSignedInt64
@ kSignedInt64
Definition: runtime_types.h:21
impeller::compiler::TargetPlatform::kOpenGLES
@ kOpenGLES
impeller::compiler::CreateMSLCompiler
static CompilerBackend CreateMSLCompiler(const spirv_cross::ParsedIR &ir, const SourceOptions &source_options, std::optional< uint32_t > msl_version_override={})
Definition: compiler.cc:50
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::TargetPlatform::kRuntimeStageMetal
@ kRuntimeStageMetal
impeller::compiler::BaseTypeToString
static std::string BaseTypeToString(spirv_cross::SPIRType::BaseType type)
Definition: reflector.cc:29
impeller::compiler::SourceType::kVertexShader
@ kVertexShader
impeller::compiler::StringStartsWith
bool StringStartsWith(const std::string &target, const std::string &prefix)
Definition: utilities.cc:64
impeller::compiler::TargetPlatformBundlesSkSL
bool TargetPlatformBundlesSkSL(TargetPlatform platform)
Definition: types.cc:317
impeller::compiler::SourceType::kTessellationEvaluationShader
@ kTessellationEvaluationShader
impeller::compiler::TypeNameWithPaddingOfSize
static std::string TypeNameWithPaddingOfSize(size_t size)
Definition: reflector.cc:521
impeller::compiler::TargetPlatform::kSkSL
@ kSkSL
impeller::compiler::TargetPlatform::kRuntimeStageGLES
@ kRuntimeStageGLES