| Flutter Impeller |

Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
impeller::compiler Namespace Reference

## Namespaces
| testing

## Classes
class | AutoLogger
class | Compiler
struct | CompilerBackend
class | CompilerSkSL
struct | IncludeDir
class | Includer
struct | IncluderData
struct | InputDescription
struct | KnownType
class | Reflector
class | RuntimeStageData
struct | ShaderConfig
| A shader config parsed as part of a ShaderBundleConfig. More...
struct | SourceOptions
class | SPIRVCompiler
struct | SPIRVCompilerOptions
struct | SPIRVCompilerSourceProfile
struct | SPIRVCompilerTargetEnv
struct | StructMember
class | 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

## Typedefs
using | ShaderBundleConfig = std::unordered_map< std::string, ShaderConfig >

## Enumerations
enum | SourceType { SourceType::kUnknown, SourceType::kVertexShader, SourceType::kFragmentShader, 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 Reflector::Options | CreateReflectorOptions (const SourceOptions &options, const Switches &switches)
static std::shared_ptr< RuntimeStageData::Shader > | CompileSkSL (std::shared_ptr< fml::Mapping > source_file_mapping, const Switches &switches)
static bool | OutputIPLR (const Switches &switches, const std::shared_ptr< fml::Mapping > &source_file_mapping)
static bool | OutputSLFile (const Compiler &compiler, const Switches &switches)
static bool | OutputReflectionData (const Compiler &compiler, const Switches &switches, const SourceOptions &options)
static bool | OutputDepfile (const Compiler &compiler, const Switches &switches)
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 (const std::string &str)
static std::optional< RuntimeStageBackend > | GetRuntimeStageBackend (TargetPlatform target_platform)
static std::string | ToString (CompilerBackend::Type type)
static std::string | TypeNameWithPaddingOfSize (size_t size)
static std::optional< KnownType > | ReadKnownScalarType (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< fb::Stage > | ToJsonStage (spv::ExecutionModel stage)
static std::optional< fb::UniformDataType > | ToUniformType (spirv_cross::SPIRType::BaseType type)
static std::optional< fb::InputDataType > | ToInputType (spirv_cross::SPIRType::BaseType type)
static std::optional< uint32_t > | ToJsonType (spirv_cross::SPIRType::BaseType type)
static std::string | RuntimeStageBackendToString (RuntimeStageBackend backend)
std::optional< ShaderBundleConfig > | ParseShaderBundleConfig (const std::string &bundle_config_json, std::ostream &error_stream)
| Parse a shader bundle configuration from a given JSON string. More...
static std::unique_ptr< fb::ShaderT > | GenerateShaderFB (SourceOptions options, const std::string &shader_name, const ShaderConfig &shader_config)
std::optional< fb::ShaderBundleT > | GenerateShaderBundleFlatbuffer (const std::string &bundle_config_json, const SourceOptions &options)
| Parses the JSON shader bundle configuration and invokes the compiler multiple times to produce a shader bundle flatbuffer. More...
bool | GenerateShaderBundle (Switches &switches)
| Parses the JSON shader bundle configuration and invokes the compiler multiple times to produce a shader bundle flatbuffer, which is then output to the `sl` file. More...
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 std::vector< TargetPlatform > | RuntimeStagesFromCommandLine (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)
SourceType | SourceTypeFromString (std::string name)
SourceLanguage | ToSourceLanguage (const std::string &source_language)
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)
bool | SetPermissiveAccess (const std::filesystem::path &p)
| Sets the file access mode of the file at path 'p' to 0644. More...
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 | ToCamelCase (std::string_view string)
std::string | ToLowerCase (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 = "shader"
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, TargetPlatform > | kKnownPlatforms
static const std::map< std::string, TargetPlatform > | kKnownRuntimeStages
static const std::map< std::string, SourceType > | kKnownSourceTypes

## Typedef Documentation

## ◆ ShaderBundleConfig

using impeller::compiler::ShaderBundleConfig = typedef std::unordered_map<std::string, ShaderConfig>

Definition at line 55 of file types.h.

## Enumeration Type Documentation

## ◆ SourceLanguage

enum impeller::compiler::SourceLanguage
| strong

Enumerator
kUnknown |
kGLSL |
kHLSL |

Definition at line 41 of file types.h.

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

## ◆ SourceType

enum impeller::compiler::SourceType
| strong

Enumerator
kUnknown |
kVertexShader |
kFragmentShader |
kComputeShader |

Definition at line 21 of file types.h.

21 {
22 kUnknown,
23 kVertexShader,
24 kFragmentShader,
25 kComputeShader,
26 };

## ◆ TargetPlatform

enum impeller::compiler::TargetPlatform
| strong

Enumerator
kUnknown |
kMetalDesktop |
kMetalIOS |
kOpenGLES |
kOpenGLDesktop |
kVulkan |
kRuntimeStageMetal |
kRuntimeStageGLES |
kRuntimeStageVulkan |
kSkSL |

Definition at line 28 of file types.h.

28 {
29 kUnknown,
30 kMetalDesktop,
31 kMetalIOS,
32 kOpenGLES,
33 kOpenGLDesktop,
34 kVulkan,
35 kRuntimeStageMetal,
36 kRuntimeStageGLES,
37 kRuntimeStageVulkan,
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().

## ◆ CompileSkSL()

static std::shared_ptr<RuntimeStageData::Shader> impeller::compiler::CompileSkSL | ( | std::shared_ptr< fml::Mapping > | source_file_mapping,
|  | const Switches & | switches
| ) |  |
| static

Run the shader compiler to geneate SkSL reflection data. If there is an error, prints error text and returns `nullptr`.

Definition at line 37 of file impellerc_main.cc.

39 {
40 auto options = switches.CreateSourceOptions(TargetPlatform::kSkSL);
41
42 Reflector::Options sksl_reflector_options =
43 CreateReflectorOptions(options, switches);
44 sksl_reflector_options.target_platform = TargetPlatform::kSkSL;
45
46 Compiler sksl_compiler =
47 Compiler(std::move(source_file_mapping), options, sksl_reflector_options);
48 if (!sksl_compiler.IsValid()) {
49 std::cerr << "Compilation to SkSL failed." << std::endl;
50 std::cerr << sksl_compiler.GetErrorMessages() << std::endl;
51 return nullptr;
52 }
53 return sksl_compiler.GetReflector()->GetRuntimeStageShaderData();
54 }

References CreateReflectorOptions(), impeller::compiler::Switches::CreateSourceOptions(), impeller::compiler::Compiler::GetErrorMessages(), impeller::compiler::Compiler::GetReflector(), impeller::compiler::Reflector::GetRuntimeStageShaderData(), impeller::compiler::Compiler::IsValid(), kSkSL, and impeller::compiler::Reflector::Options::target_platform.

Referenced by OutputIPLR().

## ◆ 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 69 of file utilities.cc.

69 {
70 if (string.empty()) {
71 return "";
72 }
73 std::stringstream stream;
74 // Append a prefix if the first character is not a letter.
75 if (!std::isalpha(string.data()[0])) {
76 stream << "i_";
77 }
78 for (size_t i = 0, count = string.length(); i < count; i++) {
79 auto ch = string.data()[i];
80 if (std::isalnum(ch) || ch == '_') {
81 stream << ch;
82 }
83 }
84 return stream.str();
85 }

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 211 of file compiler.cc.

212 {
213 CompilerBackend compiler;
214 switch (source_options.target_platform) {
215 case TargetPlatform::kMetalDesktop:
216 case TargetPlatform::kMetalIOS:
217 case TargetPlatform::kRuntimeStageMetal:
218 compiler = CreateMSLCompiler(ir, source_options);
219 break;
220 case TargetPlatform::kVulkan:
221 case TargetPlatform::kRuntimeStageVulkan:
222 compiler = CreateVulkanCompiler(ir, source_options);
223 break;
224 case TargetPlatform::kUnknown:
225 case TargetPlatform::kOpenGLES:
226 case TargetPlatform::kOpenGLDesktop:
227 case TargetPlatform::kRuntimeStageGLES:
228 compiler = CreateGLSLCompiler(ir, source_options);
229 break;
230 case TargetPlatform::kSkSL:
231 compiler = CreateSkSLCompiler(ir, source_options);
232 }
233 if (!compiler) {
234 return {};
235 }
236 auto* backend = compiler.GetCompiler();
237 if (!EntryPointMustBeNamedMain(source_options.target_platform) &&
238 source_options.source_language == SourceLanguage::kGLSL) {
239 backend->rename_entry_point("main", source_options.entry_point_name,
240 ToExecutionModel(source_options.type));
241 }
242 return compiler;
243 }

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 136 of file compiler.cc.

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

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

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 51 of file compiler.cc.

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

Referenced by CreateCompiler(), and CreateVulkanCompiler().

## ◆ CreateReflectorOptions()

static Reflector::Options impeller::compiler::CreateReflectorOptions | ( | const SourceOptions & | options,
|  | const Switches & | switches
| ) |  |
| static

Definition at line 23 of file impellerc_main.cc.

24 {
25 Reflector::Options reflector_options;
26 reflector_options.target_platform = options.target_platform;
27 reflector_options.entry_point_name = options.entry_point_name;
28 reflector_options.shader_name =
29 InferShaderNameFromPath(switches.source_file_name);
30 reflector_options.header_file_name = Utf8FromPath(
31 std::filesystem::path{switches.reflection_header_name}.filename());
32 return reflector_options;
33 }

References impeller::compiler::SourceOptions::entry_point_name, impeller::compiler::Reflector::Options::entry_point_name, impeller::compiler::Reflector::Options::header_file_name, InferShaderNameFromPath(), impeller::compiler::Switches::reflection_header_name, impeller::compiler::Reflector::Options::shader_name, impeller::compiler::Switches::source_file_name, impeller::compiler::SourceOptions::target_platform, impeller::compiler::Reflector::Options::target_platform, and Utf8FromPath().

Referenced by CompileSkSL(), Main(), and OutputIPLR().

## ◆ CreateSkSLCompiler()

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

Definition at line 186 of file compiler.cc.

187 {
188 auto sksl_compiler = std::make_shared<CompilerSkSL>(ir);
189 return CompilerBackend(sksl_compiler);
190 }

Referenced by CreateCompiler().

## ◆ CreateVulkanCompiler()

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

Definition at line 122 of file compiler.cc.

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

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 111 of file types.cc.

115 {
116 if (source_language == SourceLanguage::kHLSL) {
117 return entry_point_name;
118 }
119
120 std::stringstream stream;
121 std::filesystem::path file_path(file_name);
122 stream << ConvertToEntrypointName(Utf8FromPath(file_path.stem())) << "_";
123 switch (type) {
124 case SourceType::kUnknown:
125 stream << "unknown";
126 break;
127 case SourceType::kVertexShader:
128 stream << "vertex";
129 break;
130 case SourceType::kFragmentShader:
131 stream << "fragment";
132 break;
133 case SourceType::kComputeShader:
134 stream << "compute";
135 break;
136 }
137 stream << "_main";
138 return stream.str();
139 }

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

Referenced by impeller::compiler::testing::CompilerTest::CanCompileAndReflect(), impeller::compiler::Switches::CreateSourceOptions(), and GenerateShaderFB().

## ◆ EntryPointMustBeNamedMain()

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

Definition at line 192 of file compiler.cc.

192 {
193 switch (platform) {
194 case TargetPlatform::kUnknown:
195 FML_UNREACHABLE();
196 case TargetPlatform::kMetalDesktop:
197 case TargetPlatform::kMetalIOS:
198 case TargetPlatform::kVulkan:
199 case TargetPlatform::kRuntimeStageMetal:
200 case TargetPlatform::kRuntimeStageVulkan:
201 return false;
202 case TargetPlatform::kSkSL:
203 case TargetPlatform::kOpenGLES:
204 case TargetPlatform::kOpenGLDesktop:
205 case TargetPlatform::kRuntimeStageGLES:
206 return true;
207 }
208 FML_UNREACHABLE();
209 }

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::ExecutionModelGLCompute:
80 return "compute";
81 default:
82 return "unsupported";
83 }
84 }

## ◆ GenerateShaderBundle()

bool impeller::compiler::GenerateShaderBundle | ( | Switches & | switches | ) |

Parses the JSON shader bundle configuration and invokes the compiler multiple times to produce a shader bundle flatbuffer, which is then output to the `sl` file.

1. Parse the shader bundle and generate the flatbuffer result.
2. Serialize the shader bundle and write to disk.

Definition at line 175 of file shader_bundle.cc.

175 {
176 // --------------------------------------------------------------------------
177 /// 1. Parse the shader bundle and generate the flatbuffer result.
178 ///
179
180 auto shader_bundle = GenerateShaderBundleFlatbuffer(
181 switches.shader_bundle, switches.CreateSourceOptions());
182 if (!shader_bundle.has_value()) {
183 // Specific error messages are already handled by
184 // GenerateShaderBundleFlatbuffer.
185 return false;
186 }
187
188 // --------------------------------------------------------------------------
189 /// 2. Serialize the shader bundle and write to disk.
190 ///
191
192 auto builder = std::make_shared<flatbuffers::FlatBufferBuilder>();
193 builder->Finish(
194 fb::ShaderBundle::Pack(*builder.get(), &shader_bundle.value()),
195 fb::ShaderBundleIdentifier());
196 auto mapping = std::make_shared<fml::NonOwnedMapping>(
197 builder->GetBufferPointer(), builder->GetSize(),
198 [builder](auto, auto) {});
199
200 auto sl_file_name = std::filesystem::absolute(
201 std::filesystem::current_path() / switches.sl_file_name);
202
203 if (!fml::WriteAtomically(*switches.working_directory, //
204 Utf8FromPath(sl_file_name).c_str(), //
205 *mapping //
206 )) {
207 std::cerr << "Could not write file to " << switches.sl_file_name
208 << std::endl;
209 return false;
210 }
211 // Tools that consume the runtime stage data expect the access mode to
212 // be 0644.
213 if (!SetPermissiveAccess(sl_file_name)) {
214 return false;
215 }
216
217 return true;
218 }

References impeller::compiler::Switches::CreateSourceOptions(), GenerateShaderBundleFlatbuffer(), SetPermissiveAccess(), impeller::compiler::Switches::shader_bundle, impeller::compiler::Switches::sl_file_name, Utf8FromPath(), and impeller::compiler::Switches::working_directory.

Referenced by Main().

## ◆ GenerateShaderBundleFlatbuffer()

std::optional< fb::ShaderBundleT > impeller::compiler::GenerateShaderBundleFlatbuffer | ( | const std::string & | bundle_config_json,
|  | const SourceOptions & | options
| ) |  |

Parses the JSON shader bundle configuration and invokes the compiler multiple times to produce a shader bundle flatbuffer.

Note
  Exposed only for testing purposes. Use `GenerateShaderBundle` directly.

1. Parse the bundle configuration.
2. Build the deserialized shader bundle.

Definition at line 144 of file shader_bundle.cc.

146 {
147 // --------------------------------------------------------------------------
148 /// 1. Parse the bundle configuration.
149 ///
150
151 std::optional<ShaderBundleConfig> bundle_config =
152 ParseShaderBundleConfig(bundle_config_json, std::cerr);
153 if (!bundle_config) {
154 return std::nullopt;
155 }
156
157 // --------------------------------------------------------------------------
158 /// 2. Build the deserialized shader bundle.
159 ///
160
161 fb::ShaderBundleT shader_bundle;
162
163 for (const auto& [shader_name, shader_config] : bundle_config.value()) {
164 std::unique_ptr<fb::ShaderT> shader =
165 GenerateShaderFB(options, shader_name, shader_config);
166 if (!shader) {
167 return std::nullopt;
168 }
169 shader_bundle.shaders.push_back(std::move(shader));
170 }
171
172 return shader_bundle;
173 }

References GenerateShaderFB(), and ParseShaderBundleConfig().

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

## ◆ GenerateShaderFB()

static std::unique_ptr<fb::ShaderT> impeller::compiler::GenerateShaderFB | ( | SourceOptions | options,
|  | const std::string & | shader_name,
|  | const ShaderConfig & | shader_config
| ) |  |
| static

Override options.

Definition at line 84 of file shader_bundle.cc.

87 {
88 auto result = std::make_unique<fb::ShaderT>();
89 result->name = shader_name;
90
91 std::shared_ptr<fml::FileMapping> source_file_mapping =
92 fml::FileMapping::CreateReadOnly(shader_config.source_file_name);
93 if (!source_file_mapping) {
94 std::cerr << "Could not open file for bundled shader \"" << shader_name
95 << "\"." << std::endl;
96 return nullptr;
97 }
98
99 /// Override options.
100 options.type = shader_config.type;
101 options.source_language = shader_config.language;
102 options.entry_point_name = EntryPointFunctionNameFromSourceName(
103 shader_config.source_file_name, options.type, options.source_language,
104 shader_config.entry_point);
105
106 Reflector::Options reflector_options;
107 reflector_options.target_platform = options.target_platform;
108 reflector_options.entry_point_name = options.entry_point_name;
109 reflector_options.shader_name = shader_name;
110
111 Compiler compiler(source_file_mapping, options, reflector_options);
112 if (!compiler.IsValid()) {
113 std::cerr << "Compilation failed for bundled shader \"" << shader_name
114 << "\"." << std::endl;
115 std::cerr << compiler.GetErrorMessages() << std::endl;
116 return nullptr;
117 }
118
119 auto reflector = compiler.GetReflector();
120 if (reflector == nullptr) {
121 std::cerr << "Could not create reflector for bundled shader \""
122 << shader_name << "\"." << std::endl;
123 return nullptr;
124 }
125
126 auto stage_data = reflector->GetRuntimeStageShaderData();
127 if (!stage_data) {
128 std::cerr << "Runtime stage information was nil for bundled shader \""
129 << shader_name << "\"." << std::endl;
130 return nullptr;
131 }
132 RuntimeStageData stages;
133 stages.AddShader(stage_data);
134 result->shader = stages.CreateFlatbuffer();
135 if (!result->shader) {
136 std::cerr << "Failed to create flatbuffer for bundled shader \""
137 << shader_name << "\"." << std::endl;
138 return nullptr;
139 }
140
141 return result;
142 }

References impeller::compiler::RuntimeStageData::AddShader(), impeller::compiler::RuntimeStageData::CreateFlatbuffer(), impeller::compiler::ShaderConfig::entry_point, impeller::compiler::SourceOptions::entry_point_name, impeller::compiler::Reflector::Options::entry_point_name, EntryPointFunctionNameFromSourceName(), impeller::compiler::Compiler::GetErrorMessages(), impeller::compiler::Compiler::GetReflector(), impeller::compiler::Reflector::GetRuntimeStageShaderData(), impeller::compiler::Compiler::IsValid(), impeller::compiler::ShaderConfig::language, impeller::compiler::Reflector::Options::shader_name, impeller::compiler::ShaderConfig::source_file_name, impeller::compiler::SourceOptions::source_language, impeller::compiler::SourceOptions::target_platform, impeller::compiler::Reflector::Options::target_platform, impeller::compiler::SourceOptions::type, and impeller::compiler::ShaderConfig::type.

Referenced by GenerateShaderBundleFlatbuffer().

## ◆ 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] | members | The members

Returns
  The reflected structure size.

Definition at line 633 of file reflector.cc.

633 {
634 auto struct_size = 0u;
635 for (const auto& member : members) {
636 struct_size += member.byte_length;
637 }
638 return struct_size;
639 }

## ◆ GetRuntimeStageBackend()

static std::optional<RuntimeStageBackend> impeller::compiler::GetRuntimeStageBackend | ( | TargetPlatform | target_platform | ) |
| static

Definition at line 320 of file reflector.cc.

321 {
322 switch (target_platform) {
323 case TargetPlatform::kUnknown:
324 case TargetPlatform::kMetalDesktop:
325 case TargetPlatform::kMetalIOS:
326 case TargetPlatform::kOpenGLES:
327 case TargetPlatform::kOpenGLDesktop:
328 case TargetPlatform::kVulkan:
329 return std::nullopt;
330 case TargetPlatform::kRuntimeStageMetal:
331 return RuntimeStageBackend::kMetal;
332 case TargetPlatform::kRuntimeStageGLES:
333 return RuntimeStageBackend::kOpenGLES;
334 case TargetPlatform::kRuntimeStageVulkan:
335 return RuntimeStageBackend::kVulkan;
336 case TargetPlatform::kSkSL:
337 return RuntimeStageBackend::kSkSL;
338 }
339 FML_UNREACHABLE();
340 }

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

## ◆ InferShaderNameFromPath()

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

Definition at line 34 of file utilities.cc.

34 {
35 auto p = std::filesystem::path{path}.stem();
36 return Utf8FromPath(p);
37 }

References Utf8FromPath().

Referenced by CreateReflectorOptions().

## ◆ JoinStrings()

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

Definition at line 458 of file compiler.cc.

459 {
460 std::stringstream stream;
461 for (size_t i = 0, count = items.size(); i < count; i++) {
462 const auto is_last = (i == count - 1);
463
464 stream << items[i];
465 if (!is_last) {
466 stream << separator;
467 }
468 }
469 return stream.str();
470 }

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

## ◆ Main()

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

Definition at line 233 of file impellerc_main.cc.

233 {
234 fml::InstallCrashHandler();
235 if (command_line.HasOption("help")) {
236 Switches::PrintHelp(std::cout);
237 return true;
238 }
239
240 Switches switches(command_line);
241 if (!switches.AreValid(std::cerr)) {
242 std::cerr << "Invalid flags specified." << std::endl;
243 Switches::PrintHelp(std::cerr);
244 return false;
245 }
246
247 if (!switches.shader_bundle.empty()) {
248 // Invoke the compiler multiple times to build a shader bundle with the
249 // given shader_bundle spec.
250 return GenerateShaderBundle(switches);
251 }
252
253 std::shared_ptr<fml::FileMapping> source_file_mapping =
254 fml::FileMapping::CreateReadOnly(switches.source_file_name);
255 if (!source_file_mapping) {
256 std::cerr << "Could not open input file." << std::endl;
257 return false;
258 }
259
260 if (switches.iplr && !OutputIPLR(switches, source_file_mapping)) {
261 return false;
262 }
263
264 // Create at least one compiler to output the SL file, reflection data, and a
265 // depfile.
266 // TODO(dnfield): This seems off. We should more explicitly handle how we
267 // generate reflection and depfile data for the runtime stage case.
268 // https://github.com/flutter/flutter/issues/140841
269
270 SourceOptions options = switches.CreateSourceOptions();
271
272 // Invoke the compiler and generate reflection data for a single shader.
273
274 Reflector::Options reflector_options =
275 CreateReflectorOptions(options, switches);
276
277 Compiler compiler(source_file_mapping, options, reflector_options);
278 if (!compiler.IsValid()) {
279 std::cerr << "Compilation failed." << std::endl;
280 std::cerr << compiler.GetErrorMessages() << std::endl;
281 return false;
282 }
283
284 auto spriv_file_name = std::filesystem::absolute(
285 std::filesystem::current_path() / switches.spirv_file_name);
286 if (!fml::WriteAtomically(*switches.working_directory,
287 Utf8FromPath(spriv_file_name).c_str(),
288 *compiler.GetSPIRVAssembly())) {
289 std::cerr << "Could not write file to " << switches.spirv_file_name
290 << std::endl;
291 return false;
292 }
293
294 if (!switches.iplr && !OutputSLFile(compiler, switches)) {
295 return false;
296 }
297
298 if (!OutputReflectionData(compiler, switches, options)) {
299 return false;
300 }
301
302 if (!OutputDepfile(compiler, switches)) {
303 return false;
304 }
305
306 return true;
307 }

References impeller::compiler::Switches::AreValid(), CreateReflectorOptions(), impeller::compiler::Switches::CreateSourceOptions(), GenerateShaderBundle(), impeller::compiler::Compiler::GetErrorMessages(), impeller::compiler::Compiler::GetSPIRVAssembly(), impeller::compiler::Switches::iplr, impeller::compiler::Compiler::IsValid(), OutputDepfile(), OutputIPLR(), OutputReflectionData(), OutputSLFile(), impeller::compiler::Switches::PrintHelp(), impeller::compiler::Switches::shader_bundle, impeller::compiler::Switches::source_file_name, impeller::compiler::Switches::spirv_file_name, Utf8FromPath(), and impeller::compiler::Switches::working_directory.

Referenced by main().

## ◆ OutputDepfile()

static bool impeller::compiler::OutputDepfile | ( | const Compiler & | compiler,
|  | const Switches & | switches
| ) |  |
| static

1. Output a depfile.

Definition at line 196 of file impellerc_main.cc.

196 {
197 // --------------------------------------------------------------------------
198 /// 4. Output a depfile.
199 ///
200
201 if (!switches.depfile_path.empty()) {
202 std::string result_file;
203 switch (switches.SelectDefaultTargetPlatform()) {
204 case TargetPlatform::kMetalDesktop:
205 case TargetPlatform::kMetalIOS:
206 case TargetPlatform::kOpenGLES:
207 case TargetPlatform::kOpenGLDesktop:
208 case TargetPlatform::kRuntimeStageMetal:
209 case TargetPlatform::kRuntimeStageGLES:
210 case TargetPlatform::kRuntimeStageVulkan:
211 case TargetPlatform::kSkSL:
212 case TargetPlatform::kVulkan:
213 result_file = switches.sl_file_name;
214 break;
215 case TargetPlatform::kUnknown:
216 result_file = switches.spirv_file_name;
217 break;
218 }
219 auto depfile_path = std::filesystem::absolute(
220 std::filesystem::current_path() / switches.depfile_path.c_str());
221 if (!fml::WriteAtomically(*switches.working_directory,
222 Utf8FromPath(depfile_path).c_str(),
223 *compiler.CreateDepfileContents({result_file}))) {
224 std::cerr << "Could not write depfile to " << switches.depfile_path
225 << std::endl;
226 return false;
227 }
228 }
229
230 return true;
231 }

References impeller::compiler::Compiler::CreateDepfileContents(), impeller::compiler::Switches::depfile_path, kMetalDesktop, kMetalIOS, kOpenGLDesktop, kOpenGLES, kRuntimeStageGLES, kRuntimeStageMetal, kRuntimeStageVulkan, kSkSL, kUnknown, kVulkan, impeller::compiler::Switches::SelectDefaultTargetPlatform(), impeller::compiler::Switches::sl_file_name, impeller::compiler::Switches::spirv_file_name, Utf8FromPath(), and impeller::compiler::Switches::working_directory.

Referenced by Main().

## ◆ OutputIPLR()

static bool impeller::compiler::OutputIPLR | ( | const Switches & | switches,
|  | const std::shared_ptr< fml::Mapping > & | source_file_mapping
| ) |  |
| static

Definition at line 56 of file impellerc_main.cc.

58 {
59 FML_DCHECK(switches.iplr);
60
61 RuntimeStageData stages;
62 std::shared_ptr<RuntimeStageData::Shader> sksl_shader;
63 if (TargetPlatformBundlesSkSL(switches.SelectDefaultTargetPlatform())) {
64 sksl_shader = CompileSkSL(source_file_mapping, switches);
65 if (!sksl_shader) {
66 return false;
67 }
68 stages.AddShader(sksl_shader);
69 }
70
71 for (const auto& platform : switches.PlatformsToCompile()) {
72 if (platform == TargetPlatform::kSkSL) {
73 // Already handled above.
74 continue;
75 }
76 SourceOptions options = switches.CreateSourceOptions(platform);
77
78 // Invoke the compiler and generate reflection data for a single shader.
79
80 Reflector::Options reflector_options =
81 CreateReflectorOptions(options, switches);
82 Compiler compiler(source_file_mapping, options, reflector_options);
83 if (!compiler.IsValid()) {
84 std::cerr << "Compilation failed." << std::endl;
85 std::cerr << compiler.GetErrorMessages() << std::endl;
86 return false;
87 }
88
89 auto reflector = compiler.GetReflector();
90 if (reflector == nullptr) {
91 std::cerr << "Could not create reflector." << std::endl;
92 return false;
93 }
94
95 auto stage_data = reflector->GetRuntimeStageShaderData();
96 if (!stage_data) {
97 std::cerr << "Runtime stage information was nil." << std::endl;
98 return false;
99 }
100
101 stages.AddShader(stage_data);
102 }
103
104 auto stage_data_mapping = switches.json_format ? stages.CreateJsonMapping()
105 : stages.CreateMapping();
106 if (!stage_data_mapping) {
107 std::cerr << "Runtime stage data could not be created." << std::endl;
108 return false;
109 }
110 if (!fml::WriteAtomically(*switches.working_directory, //
111 Utf8FromPath(switches.sl_file_name).c_str(), //
112 *stage_data_mapping //
113 )) {
114 std::cerr << "Could not write file to " << switches.sl_file_name
115 << std::endl;
116 return false;
117 }
118 // Tools that consume the runtime stage data expect the access mode to
119 // be 0644.
120 if (!SetPermissiveAccess(switches.sl_file_name)) {
121 return false;
122 }
123 return true;
124 }

References impeller::compiler::RuntimeStageData::AddShader(), CompileSkSL(), impeller::compiler::RuntimeStageData::CreateJsonMapping(), impeller::compiler::RuntimeStageData::CreateMapping(), CreateReflectorOptions(), impeller::compiler::Switches::CreateSourceOptions(), impeller::compiler::Compiler::GetErrorMessages(), impeller::compiler::Compiler::GetReflector(), impeller::compiler::Reflector::GetRuntimeStageShaderData(), impeller::compiler::Switches::iplr, impeller::compiler::Compiler::IsValid(), impeller::compiler::Switches::json_format, kSkSL, impeller::compiler::Switches::PlatformsToCompile(), impeller::compiler::Switches::SelectDefaultTargetPlatform(), SetPermissiveAccess(), impeller::compiler::Switches::sl_file_name, TargetPlatformBundlesSkSL(), Utf8FromPath(), and impeller::compiler::Switches::working_directory.

Referenced by Main().

## ◆ OutputReflectionData()

static bool impeller::compiler::OutputReflectionData | ( | const Compiler & | compiler,
|  | const Switches & | switches,
|  | const SourceOptions & | options
| ) |  |
| static

1. Output shader reflection data. May include a JSON file, a C++ header, and/or a C++ TU.

Definition at line 144 of file impellerc_main.cc.

146 {
147 // --------------------------------------------------------------------------
148 /// 3. Output shader reflection data.
149 /// May include a JSON file, a C++ header, and/or a C++ TU.
150 ///
151
152 if (TargetPlatformNeedsReflection(options.target_platform)) {
153 if (!switches.reflection_json_name.empty()) {
154 auto reflection_json_name = std::filesystem::absolute(
155 std::filesystem::current_path() / switches.reflection_json_name);
156 if (!fml::WriteAtomically(
157 *switches.working_directory,
158 Utf8FromPath(reflection_json_name).c_str(),
159 *compiler.GetReflector()->GetReflectionJSON())) {
160 std::cerr << "Could not write reflection json to "
161 << switches.reflection_json_name << std::endl;
162 return false;
163 }
164 }
165
166 if (!switches.reflection_header_name.empty()) {
167 auto reflection_header_name =
168 std::filesystem::absolute(std::filesystem::current_path() /
169 switches.reflection_header_name.c_str());
170 if (!fml::WriteAtomically(
171 *switches.working_directory,
172 Utf8FromPath(reflection_header_name).c_str(),
173 *compiler.GetReflector()->GetReflectionHeader())) {
174 std::cerr << "Could not write reflection header to "
175 << switches.reflection_header_name << std::endl;
176 return false;
177 }
178 }
179
180 if (!switches.reflection_cc_name.empty()) {
181 auto reflection_cc_name =
182 std::filesystem::absolute(std::filesystem::current_path() /
183 switches.reflection_cc_name.c_str());
184 if (!fml::WriteAtomically(*switches.working_directory,
185 Utf8FromPath(reflection_cc_name).c_str(),
186 *compiler.GetReflector()->GetReflectionCC())) {
187 std::cerr << "Could not write reflection CC to "
188 << switches.reflection_cc_name << std::endl;
189 return false;
190 }
191 }
192 }
193 return true;
194 }

References impeller::compiler::Reflector::GetReflectionCC(), impeller::compiler::Reflector::GetReflectionHeader(), impeller::compiler::Reflector::GetReflectionJSON(), impeller::compiler::Compiler::GetReflector(), impeller::compiler::Switches::reflection_cc_name, impeller::compiler::Switches::reflection_header_name, impeller::compiler::Switches::reflection_json_name, impeller::compiler::SourceOptions::target_platform, TargetPlatformNeedsReflection(), Utf8FromPath(), and impeller::compiler::Switches::working_directory.

Referenced by Main().

## ◆ OutputSLFile()

static bool impeller::compiler::OutputSLFile | ( | const Compiler & | compiler,
|  | const Switches & | switches
| ) |  |
| static

1. Output the source file. When in IPLR/RuntimeStage mode, output the serialized IPLR flatbuffer.

Definition at line 126 of file impellerc_main.cc.

126 {
127 // --------------------------------------------------------------------------
128 /// 2. Output the source file. When in IPLR/RuntimeStage mode, output the
129 /// serialized IPLR flatbuffer.
130 ///
131
132 auto sl_file_name = std::filesystem::absolute(
133 std::filesystem::current_path() / switches.sl_file_name);
134 if (!fml::WriteAtomically(*switches.working_directory,
135 Utf8FromPath(sl_file_name).c_str(),
136 *compiler.GetSLShaderSource())) {
137 std::cerr << "Could not write file to " << switches.sl_file_name
138 << std::endl;
139 return false;
140 }
141 return true;
142 }

References impeller::compiler::Compiler::GetSLShaderSource(), impeller::compiler::Switches::sl_file_name, Utf8FromPath(), and impeller::compiler::Switches::working_directory.

Referenced by Main().

## ◆ ParseMSLVersion()

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

Definition at line 28 of file compiler.cc.

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

## ◆ ParseShaderBundleConfig()

std::optional< ShaderBundleConfig > impeller::compiler::ParseShaderBundleConfig | ( | const std::string & | bundle_config_json,
|  | std::ostream & | error_stream
| ) |  |

Parse a shader bundle configuration from a given JSON string.

Note
  Exposed only for testing purposes. Use `GenerateShaderBundle` directly.

Definition at line 19 of file shader_bundle.cc.

21 {
22 auto json = nlohmann::json::parse(bundle_config_json, nullptr, false);
23 if (json.is_discarded() || !json.is_object()) {
24 error_stream << "The shader bundle is not a valid JSON object."
25 << std::endl;
26 return std::nullopt;
27 }
28
29 ShaderBundleConfig bundle;
30 for (auto& [shader_name, shader_value] : json.items()) {
31 if (bundle.find(shader_name) != bundle.end()) {
32 error_stream << "Duplicate shader \"" << shader_name << "\"."
33 << std::endl;
34 return std::nullopt;
35 }
36 if (!shader_value.is_object()) {
37 error_stream << "Invalid shader entry \"" << shader_name
38 << "\": Entry is not a JSON object." << std::endl;
39 return std::nullopt;
40 }
41
42 ShaderConfig shader;
43
44 if (!shader_value.contains("file")) {
45 error_stream << "Invalid shader entry \"" << shader_name
46 << "\": Missing required \"file\" field." << std::endl;
47 return std::nullopt;
48 }
49 shader.source_file_name = shader_value["file"];
50
51 if (!shader_value.contains("type")) {
52 error_stream << "Invalid shader entry \"" << shader_name
53 << "\": Missing required \"type\" field." << std::endl;
54 return std::nullopt;
55 }
56 shader.type = SourceTypeFromString(shader_value["type"]);
57 if (shader.type == SourceType::kUnknown) {
58 error_stream << "Invalid shader entry \"" << shader_name
59 << "\": Shader type " << shader_value["type"]
60 << " is unknown." << std::endl;
61 return std::nullopt;
62 }
63
64 shader.language = shader_value.contains("language")
65 ? ToSourceLanguage(shader_value["language"])
66 : SourceLanguage::kGLSL;
67 if (shader.language == SourceLanguage::kUnknown) {
68 error_stream << "Invalid shader entry \"" << shader_name
69 << "\": Unknown language type " << shader_value["language"]
70 << "." << std::endl;
71 return std::nullopt;
72 }
73
74 shader.entry_point = shader_value.contains("entry_point")
75 ? shader_value["entry_point"]
76 : "main";
77
78 bundle[shader_name] = shader;
79 }
80
81 return bundle;
82 }

References impeller::compiler::ShaderConfig::entry_point, kGLSL, kUnknown, impeller::compiler::ShaderConfig::language, impeller::compiler::ShaderConfig::source_file_name, SourceTypeFromString(), ToSourceLanguage(), and impeller::compiler::ShaderConfig::type.

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

## ◆ ReadKnownScalarType()

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

Definition at line 586 of file reflector.cc.

587 {
588 switch (type) {
589 case spirv_cross::SPIRType::BaseType::Boolean:
590 return KnownType{
591 .name = "bool",
592 .byte_size = sizeof(bool),
593 };
594 case spirv_cross::SPIRType::BaseType::Float:
595 return KnownType{
596 .name = "Scalar",
597 .byte_size = sizeof(Scalar),
598 };
599 case spirv_cross::SPIRType::BaseType::Half:
600 return KnownType{
601 .name = "Half",
602 .byte_size = sizeof(Half),
603 };
604 case spirv_cross::SPIRType::BaseType::UInt:
605 return KnownType{
606 .name = "uint32_t",
607 .byte_size = sizeof(uint32_t),
608 };
609 case spirv_cross::SPIRType::BaseType::Int:
610 return KnownType{
611 .name = "int32_t",
612 .byte_size = sizeof(int32_t),
613 };
614 default:
615 break;
616 }
617 return std::nullopt;
618 }

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 }

## ◆ RuntimeStageBackendToString()

static std::string impeller::compiler::RuntimeStageBackendToString | ( | RuntimeStageBackend | backend | ) |
| static

Definition at line 206 of file runtime_stage_data.cc.

206 {
207 switch (backend) {
208 case RuntimeStageBackend::kSkSL:
209 return "sksl";
210 case RuntimeStageBackend::kMetal:
211 return "metal";
212 case RuntimeStageBackend::kOpenGLES:
213 return "opengles";
214 case RuntimeStageBackend::kVulkan:
215 return "vulkan";
216 }
217 }

References impeller::kMetal, impeller::kOpenGLES, impeller::kSkSL, and impeller::kVulkan.

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

## ◆ RuntimeStagesFromCommandLine()

static std::vector<TargetPlatform> impeller::compiler::RuntimeStagesFromCommandLine | ( | const fml::CommandLine & | command_line | ) |
| static

Definition at line 137 of file switches.cc.

138 {
139 std::vector<TargetPlatform> stages;
140 for (const auto& platform : kKnownRuntimeStages) {
141 if (command_line.HasOption(platform.first)) {
142 stages.push_back(platform.second);
143 }
144 }
145 return stages;
146 }

References kKnownRuntimeStages.

## ◆ 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()

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

Sets the file access mode of the file at path 'p' to 0644.

Definition at line 16 of file utilities.cc.

16 {
17 auto permissions =
18 std::filesystem::perms::owner_read | std::filesystem::perms::owner_write |
19 std::filesystem::perms::group_read | std::filesystem::perms::others_read;
20 std::error_code error;
21 std::filesystem::permissions(p, permissions, error);
22 if (error) {
23 std::cerr << "Failed to set access on file '" << p
24 << "': " << error.message() << std::endl;
25 return false;
26 }
27 return true;
28 }

Referenced by GenerateShaderBundle(), and OutputIPLR().

## ◆ ShaderCErrorToString()

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

Definition at line 159 of file types.cc.

159 {
160 using Status = shaderc_compilation_status;
161 switch (status) {
162 case Status::shaderc_compilation_status_success:
163 return "Success";
164 case Status::shaderc_compilation_status_invalid_stage:
165 return "Invalid shader stage specified";
166 case Status::shaderc_compilation_status_compilation_error:
167 return "Compilation error";
168 case Status::shaderc_compilation_status_internal_error:
169 return "Internal error";
170 case Status::shaderc_compilation_status_null_result_object:
171 return "Internal error. Null result object";
172 case Status::shaderc_compilation_status_invalid_assembly:
173 return "Invalid assembly";
174 case Status::shaderc_compilation_status_validation_error:
175 return "Validation error";
176 case Status::shaderc_compilation_status_transformation_error:
177 return "Transform error";
178 case Status::shaderc_compilation_status_configuration_error:
179 return "Configuration error";
180 }
181 return "Unknown internal error";
182 }

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

## ◆ SourceLanguageToString()

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

Definition at line 100 of file types.cc.

100 {
101 switch (source_language) {
102 case SourceLanguage::kUnknown:
103 return "Unknown";
104 case SourceLanguage::kGLSL:
105 return "GLSL";
106 case SourceLanguage::kHLSL:
107 return "HLSL";
108 }
109 }

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 148 of file switches.cc.

149 {
150 auto source_type_option =
151 command_line.GetOptionValueWithDefault("input-type", "");
152 auto source_type_search = kKnownSourceTypes.find(source_type_option);
153 if (source_type_search == kKnownSourceTypes.end()) {
154 return SourceType::kUnknown;
155 }
156 return source_type_search->second;
157 }

References kKnownSourceTypes, and kUnknown.

## ◆ SourceTypeFromFileName()

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

Definition at line 30 of file types.cc.

30 {
31 if (StringEndWith(file_name, ".vert")) {
32 return SourceType::kVertexShader;
33 }
34
35 if (StringEndWith(file_name, ".frag")) {
36 return SourceType::kFragmentShader;
37 }
38
39 if (StringEndWith(file_name, ".comp")) {
40 return SourceType::kComputeShader;
41 }
42
43 return SourceType::kUnknown;
44 }

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

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

## ◆ SourceTypeFromString()

SourceType impeller::compiler::SourceTypeFromString | ( | std::string | name | ) |

Definition at line 46 of file types.cc.

46 {
47 name = ToLowerCase(name);
48
49 if (name == "vertex") {
50 return SourceType::kVertexShader;
51 }
52
53 if (name == "fragment") {
54 return SourceType::kFragmentShader;
55 }
56
57 if (name == "compute") {
58 return SourceType::kComputeShader;
59 }
60
61 return SourceType::kUnknown;
62 }

References kComputeShader, kFragmentShader, kUnknown, kVertexShader, and ToLowerCase().

Referenced by ParseShaderBundleConfig().

## ◆ SourceTypeToString()

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

Definition at line 232 of file types.cc.

232 {
233 switch (type) {
234 case SourceType::kUnknown:
235 return "unknown";
236 case SourceType::kVertexShader:
237 return "vert";
238 case SourceType::kFragmentShader:
239 return "frag";
240 case SourceType::kComputeShader:
241 return "comp";
242 }
243 FML_UNREACHABLE();
244 }

References kComputeShader, kFragmentShader, kUnknown, and kVertexShader.

## ◆ StringEndWith()

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

Definition at line 17 of file types.cc.

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

Referenced by SourceTypeFromFileName().

## ◆ StringStartsWith()

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

Definition at line 87 of file utilities.cc.

87 {
88 if (prefix.length() > target.length()) {
89 return false;
90 }
91 for (size_t i = 0; i < prefix.length(); i++) {
92 if (target[i] != prefix[i]) {
93 return false;
94 }
95 }
96 return true;
97 }

Referenced by CreateGLSLCompiler().

## ◆ StringToShaderStage()

static std::string impeller::compiler::StringToShaderStage | ( | const std::string & | str | ) |
| static

Definition at line 86 of file reflector.cc.

86 {
87 if (str == "vertex") {
88 return "ShaderStage::kVertex";
89 }
90
91 if (str == "fragment") {
92 return "ShaderStage::kFragment";
93 }
94
95 if (str == "compute") {
96 return "ShaderStage::kCompute";
97 }
98
99 return "ShaderStage::kUnknown";
100 }

## ◆ TargetPlatformBundlesSkSL()

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

Definition at line 320 of file types.cc.

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

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

Referenced by OutputIPLR().

## ◆ TargetPlatformFromCommandLine()

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

Definition at line 119 of file switches.cc.

120 {
121 auto target = TargetPlatform::kUnknown;
122 for (const auto& platform : kKnownPlatforms) {
123 if (command_line.HasOption(platform.first)) {
124 // If the platform has already been determined, the caller may have
125 // specified multiple platforms. This is an error and only one must be
126 // selected.
127 if (target != TargetPlatform::kUnknown) {
128 return TargetPlatform::kUnknown;
129 }
130 target = platform.second;
131 // Keep going to detect duplicates.
132 }
133 }
134 return target;
135 }

References kKnownPlatforms, and kUnknown.

## ◆ TargetPlatformIsMetal()

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

Definition at line 284 of file types.cc.

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

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 266 of file types.cc.

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

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

## ◆ TargetPlatformIsVulkan()

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

Definition at line 302 of file types.cc.

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

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 141 of file types.cc.

141 {
142 switch (platform) {
143 case TargetPlatform::kMetalIOS:
144 case TargetPlatform::kMetalDesktop:
145 case TargetPlatform::kOpenGLES:
146 case TargetPlatform::kOpenGLDesktop:
147 case TargetPlatform::kRuntimeStageMetal:
148 case TargetPlatform::kRuntimeStageGLES:
149 case TargetPlatform::kRuntimeStageVulkan:
150 case TargetPlatform::kVulkan:
151 return true;
152 case TargetPlatform::kUnknown:
153 case TargetPlatform::kSkSL:
154 return false;
155 }
156 FML_UNREACHABLE();
157 }

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

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

## ◆ TargetPlatformSLExtension()

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

Definition at line 246 of file types.cc.

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

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 212 of file types.cc.

213 {
214 switch (platform) {
215 case TargetPlatform::kMetalIOS:
216 case TargetPlatform::kRuntimeStageMetal:
217 return spirv_cross::CompilerMSL::Options::Platform::iOS;
218 case TargetPlatform::kMetalDesktop:
219 return spirv_cross::CompilerMSL::Options::Platform::macOS;
220 case TargetPlatform::kSkSL:
221 case TargetPlatform::kOpenGLES:
222 case TargetPlatform::kOpenGLDesktop:
223 case TargetPlatform::kRuntimeStageGLES:
224 case TargetPlatform::kRuntimeStageVulkan:
225 case TargetPlatform::kVulkan:
226 case TargetPlatform::kUnknown:
227 return spirv_cross::CompilerMSL::Options::Platform::macOS;
228 }
229 FML_UNREACHABLE();
230 }

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

## ◆ TargetPlatformToString()

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

Definition at line 74 of file types.cc.

74 {
75 switch (platform) {
76 case TargetPlatform::kUnknown:
77 return "Unknown";
78 case TargetPlatform::kMetalDesktop:
79 return "MetalDesktop";
80 case TargetPlatform::kMetalIOS:
81 return "MetaliOS";
82 case TargetPlatform::kOpenGLES:
83 return "OpenGLES";
84 case TargetPlatform::kOpenGLDesktop:
85 return "OpenGLDesktop";
86 case TargetPlatform::kVulkan:
87 return "Vulkan";
88 case TargetPlatform::kRuntimeStageMetal:
89 return "RuntimeStageMetal";
90 case TargetPlatform::kRuntimeStageGLES:
91 return "RuntimeStageGLES";
92 case TargetPlatform::kRuntimeStageVulkan:
93 return "RuntimeStageVulkan";
94 case TargetPlatform::kSkSL:
95 return "SkSL";
96 }
97 FML_UNREACHABLE();
98 }

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

## ◆ ToCamelCase()

std::string impeller::compiler::ToCamelCase | ( | std::string_view | string | ) |

Definition at line 39 of file utilities.cc.

39 {
40 if (string.empty()) {
41 return "";
42 }
43
44 std::stringstream stream;
45 bool next_upper = true;
46 for (size_t i = 0, count = string.length(); i < count; i++) {
47 auto ch = string.data()[i];
48 if (next_upper) {
49 next_upper = false;
50 stream << static_cast<char>(std::toupper(ch));
51 continue;
52 }
53 if (ch == '_') {
54 next_upper = true;
55 continue;
56 }
57 stream << ch;
58 }
59 return stream.str();
60 }

## ◆ ToExecutionModel()

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

Definition at line 198 of file types.cc.

198 {
199 switch (type) {
200 case SourceType::kVertexShader:
201 return spv::ExecutionModel::ExecutionModelVertex;
202 case SourceType::kFragmentShader:
203 return spv::ExecutionModel::ExecutionModelFragment;
204 case SourceType::kComputeShader:
205 return spv::ExecutionModel::ExecutionModelGLCompute;
206 case SourceType::kUnknown:
207 break;
208 }
209 return spv::ExecutionModel::ExecutionModelMax;
210 }

References kComputeShader, kFragmentShader, kUnknown, and kVertexShader.

Referenced by CreateCompiler().

## ◆ ToInputType()

static std::optional<fb::InputDataType> impeller::compiler::ToInputType | ( | spirv_cross::SPIRType::BaseType | type | ) |
| static

Definition at line 105 of file runtime_stage_data.cc.

106 {
107 switch (type) {
108 case spirv_cross::SPIRType::Boolean:
109 return fb::InputDataType::kBoolean;
110 case spirv_cross::SPIRType::SByte:
111 return fb::InputDataType::kSignedByte;
112 case spirv_cross::SPIRType::UByte:
113 return fb::InputDataType::kUnsignedByte;
114 case spirv_cross::SPIRType::Short:
115 return fb::InputDataType::kSignedShort;
116 case spirv_cross::SPIRType::UShort:
117 return fb::InputDataType::kUnsignedShort;
118 case spirv_cross::SPIRType::Int:
119 return fb::InputDataType::kSignedInt;
120 case spirv_cross::SPIRType::UInt:
121 return fb::InputDataType::kUnsignedInt;
122 case spirv_cross::SPIRType::Int64:
123 return fb::InputDataType::kSignedInt64;
124 case spirv_cross::SPIRType::UInt64:
125 return fb::InputDataType::kUnsignedInt64;
126 case spirv_cross::SPIRType::Float:
127 return fb::InputDataType::kFloat;
128 case spirv_cross::SPIRType::Double:
129 return fb::InputDataType::kDouble;
130 case spirv_cross::SPIRType::Unknown:
131 case spirv_cross::SPIRType::Void:
132 case spirv_cross::SPIRType::Half:
133 case spirv_cross::SPIRType::AtomicCounter:
134 case spirv_cross::SPIRType::Struct:
135 case spirv_cross::SPIRType::Image:
136 case spirv_cross::SPIRType::SampledImage:
137 case spirv_cross::SPIRType::Sampler:
138 case spirv_cross::SPIRType::AccelerationStructure:
139 case spirv_cross::SPIRType::RayQuery:
140 case spirv_cross::SPIRType::ControlPointArray:
141 case spirv_cross::SPIRType::Interpolant:
142 case spirv_cross::SPIRType::Char:
143 return std::nullopt;
144 }
145 FML_UNREACHABLE();
146 }

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

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

## ◆ ToJsonStage()

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

Definition at line 47 of file runtime_stage_data.cc.

47 {
48 switch (stage) {
49 case spv::ExecutionModel::ExecutionModelVertex:
50 return fb::Stage::kVertex;
51 case spv::ExecutionModel::ExecutionModelFragment:
52 return fb::Stage::kFragment;
53 case spv::ExecutionModel::ExecutionModelGLCompute:
54 return fb::Stage::kCompute;
55 default:
56 return std::nullopt;
57 }
58 FML_UNREACHABLE();
59 }

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

## ◆ ToJsonType()

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

Definition at line 148 of file runtime_stage_data.cc.

149 {
150 switch (type) {
151 case spirv_cross::SPIRType::Boolean:
152 return 0; // fb::UniformDataType::kBoolean;
153 case spirv_cross::SPIRType::SByte:
154 return 1; // fb::UniformDataType::kSignedByte;
155 case spirv_cross::SPIRType::UByte:
156 return 2; // fb::UniformDataType::kUnsignedByte;
157 case spirv_cross::SPIRType::Short:
158 return 3; // fb::UniformDataType::kSignedShort;
159 case spirv_cross::SPIRType::UShort:
160 return 4; // fb::UniformDataType::kUnsignedShort;
161 case spirv_cross::SPIRType::Int:
162 return 5; // fb::UniformDataType::kSignedInt;
163 case spirv_cross::SPIRType::UInt:
164 return 6; // fb::UniformDataType::kUnsignedInt;
165 case spirv_cross::SPIRType::Int64:
166 return 7; // fb::UniformDataType::kSignedInt64;
167 case spirv_cross::SPIRType::UInt64:
168 return 8; // fb::UniformDataType::kUnsignedInt64;
169 case spirv_cross::SPIRType::Half:
170 return 9; // b::UniformDataType::kHalfFloat;
171 case spirv_cross::SPIRType::Float:
172 return 10; // fb::UniformDataType::kFloat;
173 case spirv_cross::SPIRType::Double:
174 return 11; // fb::UniformDataType::kDouble;
175 case spirv_cross::SPIRType::SampledImage:
176 return 12; // fb::UniformDataType::kSampledImage;
177 case spirv_cross::SPIRType::AccelerationStructure:
178 case spirv_cross::SPIRType::AtomicCounter:
179 case spirv_cross::SPIRType::Char:
180 case spirv_cross::SPIRType::ControlPointArray:
181 case spirv_cross::SPIRType::Image:
182 case spirv_cross::SPIRType::Interpolant:
183 case spirv_cross::SPIRType::RayQuery:
184 case spirv_cross::SPIRType::Sampler:
185 case spirv_cross::SPIRType::Struct:
186 case spirv_cross::SPIRType::Unknown:
187 case spirv_cross::SPIRType::Void:
188 return std::nullopt;
189 }
190 FML_UNREACHABLE();
191 }

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

## ◆ ToLowerCase()

std::string impeller::compiler::ToLowerCase | ( | std::string_view | string | ) |

Definition at line 62 of file utilities.cc.

62 {
63 std::string result = std::string(string);
64 std::transform(result.begin(), result.end(), result.begin(),
65 [](char x) { return std::tolower(x); });
66 return result;
67 }

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

## ◆ ToShaderCShaderKind()

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

Definition at line 184 of file types.cc.

184 {
185 switch (type) {
186 case SourceType::kVertexShader:
187 return shaderc_shader_kind::shaderc_vertex_shader;
188 case SourceType::kFragmentShader:
189 return shaderc_shader_kind::shaderc_fragment_shader;
190 case SourceType::kComputeShader:
191 return shaderc_shader_kind::shaderc_compute_shader;
192 case SourceType::kUnknown:
193 break;
194 }
195 return shaderc_shader_kind::shaderc_glsl_infer_from_source;
196 }

References kComputeShader, kFragmentShader, kUnknown, and kVertexShader.

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

## ◆ ToSourceLanguage()

SourceLanguage impeller::compiler::ToSourceLanguage | ( | const std::string & | source_language | ) |

Definition at line 64 of file types.cc.

64 {
65 if (source_language == "glsl") {
66 return SourceLanguage::kGLSL;
67 }
68 if (source_language == "hlsl") {
69 return SourceLanguage::kHLSL;
70 }
71 return SourceLanguage::kUnknown;
72 }

References kGLSL, kHLSL, and kUnknown.

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

## ◆ ToStage()

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

Definition at line 33 of file runtime_stage_data.cc.

33 {
34 switch (stage) {
35 case spv::ExecutionModel::ExecutionModelVertex:
36 return fb::Stage::kVertex;
37 case spv::ExecutionModel::ExecutionModelFragment:
38 return fb::Stage::kFragment;
39 case spv::ExecutionModel::ExecutionModelGLCompute:
40 return fb::Stage::kCompute;
41 default:
42 return std::nullopt;
43 }
44 FML_UNREACHABLE();
45 }

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

## ◆ ToString()

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

Definition at line 422 of file reflector.cc.

422 {
423 switch (type) {
424 case CompilerBackend::Type::kMSL:
425 return "Metal Shading Language";
426 case CompilerBackend::Type::kGLSL:
427 return "OpenGL Shading Language";
428 case CompilerBackend::Type::kSkSL:
429 return "SkSL Shading Language";
430 }
431 FML_UNREACHABLE();
432 }

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

## ◆ ToUniformType()

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

Definition at line 61 of file runtime_stage_data.cc.

62 {
63 switch (type) {
64 case spirv_cross::SPIRType::Boolean:
65 return fb::UniformDataType::kBoolean;
66 case spirv_cross::SPIRType::SByte:
67 return fb::UniformDataType::kSignedByte;
68 case spirv_cross::SPIRType::UByte:
69 return fb::UniformDataType::kUnsignedByte;
70 case spirv_cross::SPIRType::Short:
71 return fb::UniformDataType::kSignedShort;
72 case spirv_cross::SPIRType::UShort:
73 return fb::UniformDataType::kUnsignedShort;
74 case spirv_cross::SPIRType::Int:
75 return fb::UniformDataType::kSignedInt;
76 case spirv_cross::SPIRType::UInt:
77 return fb::UniformDataType::kUnsignedInt;
78 case spirv_cross::SPIRType::Int64:
79 return fb::UniformDataType::kSignedInt64;
80 case spirv_cross::SPIRType::UInt64:
81 return fb::UniformDataType::kUnsignedInt64;
82 case spirv_cross::SPIRType::Half:
83 return fb::UniformDataType::kHalfFloat;
84 case spirv_cross::SPIRType::Float:
85 return fb::UniformDataType::kFloat;
86 case spirv_cross::SPIRType::Double:
87 return fb::UniformDataType::kDouble;
88 case spirv_cross::SPIRType::SampledImage:
89 return fb::UniformDataType::kSampledImage;
90 case spirv_cross::SPIRType::AccelerationStructure:
91 case spirv_cross::SPIRType::AtomicCounter:
92 case spirv_cross::SPIRType::Char:
93 case spirv_cross::SPIRType::ControlPointArray:
94 case spirv_cross::SPIRType::Image:
95 case spirv_cross::SPIRType::Interpolant:
96 case spirv_cross::SPIRType::RayQuery:
97 case spirv_cross::SPIRType::Sampler:
98 case spirv_cross::SPIRType::Struct:
99 case spirv_cross::SPIRType::Unknown:
100 case spirv_cross::SPIRType::Void:
101 return std::nullopt;
102 }
103 FML_UNREACHABLE();
104 }

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::CreateFlatbuffer().

## ◆ TypeNameWithPaddingOfSize()

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

Definition at line 575 of file reflector.cc.

575 {
576 std::stringstream stream;
577 stream << "Padding<" << size << ">";
578 return stream.str();
579 }

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 30 of file utilities.cc.

30 {
31 return reinterpret_cast<const char*>(path.u8string().c_str());
32 }

Referenced by impeller::compiler::Switches::AreValid(), CreateReflectorOptions(), EntryPointFunctionNameFromSourceName(), GenerateShaderBundle(), InferShaderNameFromPath(), impeller::scene::importer::Main(), Main(), OutputDepfile(), OutputIPLR(), OutputReflectionData(), OutputSLFile(), 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 1034 of file reflector.cc.

1036 {
1037 VertexType result;
1038 result.variable_name = resource->name;
1039 const auto type = compiler.get_type(resource->type_id);
1040 result.base_type_name = BaseTypeToString(type.basetype);
1041 const auto total_size = type.columns * type.vecsize * type.width / 8u;
1042 result.byte_length = total_size;
1043
1044 if (type.basetype == spirv_cross::SPIRType::BaseType::Float &&
1045 type.columns == 1u && type.vecsize == 2u &&
1046 type.width == sizeof(float) * 8u) {
1047 result.type_name = "Point";
1048 } else if (type.basetype == spirv_cross::SPIRType::BaseType::Float &&
1049 type.columns == 1u && type.vecsize == 4u &&
1050 type.width == sizeof(float) * 8u) {
1051 result.type_name = "Vector4";
1052 } else if (type.basetype == spirv_cross::SPIRType::BaseType::Float &&
1053 type.columns == 1u && type.vecsize == 3u &&
1054 type.width == sizeof(float) * 8u) {
1055 result.type_name = "Vector3";
1056 } else if (type.basetype == spirv_cross::SPIRType::BaseType::Float &&
1057 type.columns == 1u && type.vecsize == 1u &&
1058 type.width == sizeof(float) * 8u) {
1059 result.type_name = "Scalar";
1060 } else if (type.basetype == spirv_cross::SPIRType::BaseType::Int &&
1061 type.columns == 1u && type.vecsize == 1u &&
1062 type.width == sizeof(int32_t) * 8u) {
1063 result.type_name = "int32_t";
1064 } else {
1065 // Catch all unknown padding.
1066 result.type_name = TypeNameWithPaddingOfSize(total_size);
1067 }
1068
1069 return result;
1070 }

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 195 of file runtime_stage_data.cc.

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

## ◆ kExternalTexturePrefix

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

Definition at line 11 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},
}

Definition at line 20 of file switches.cc.

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

## ◆ kKnownRuntimeStages

const std::map<std::string, TargetPlatform> impeller::compiler::kKnownRuntimeStages
| static

Initial value:
= {
{"sksl", TargetPlatform::kSkSL},
{"runtime-stage-metal", TargetPlatform::kRuntimeStageMetal},
{"runtime-stage-gles", TargetPlatform::kRuntimeStageGLES},
{"runtime-stage-vulkan", TargetPlatform::kRuntimeStageVulkan},
}

Definition at line 28 of file switches.cc.

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

## ◆ kKnownSourceTypes

const std::map<std::string, SourceType> impeller::compiler::kKnownSourceTypes
| static

Initial value:
= {
{"vert", SourceType::kVertexShader},
{"frag", SourceType::kFragmentShader},
{"comp", SourceType::kComputeShader},
}

Definition at line 35 of file switches.cc.

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

## ◆ kReflectionCCTemplate

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

Definition at line 204 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 = "shader"
| static

Definition at line 197 of file runtime_stage_data.cc.

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

## ◆ kStageKey

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

Definition at line 193 of file runtime_stage_data.cc.

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

## ◆ kTargetPlatformKey

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

Definition at line 194 of file runtime_stage_data.cc.

## ◆ kUniformArrayElementsKey

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

Definition at line 204 of file runtime_stage_data.cc.

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

## ◆ kUniformBitWidthKey

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

Definition at line 203 of file runtime_stage_data.cc.

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

## ◆ kUniformColumnsKey

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

Definition at line 202 of file runtime_stage_data.cc.

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

## ◆ kUniformLocationKey

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

Definition at line 199 of file runtime_stage_data.cc.

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

## ◆ kUniformNameKey

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

Definition at line 198 of file runtime_stage_data.cc.

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

## ◆ kUniformRowsKey

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

Definition at line 201 of file runtime_stage_data.cc.

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

## ◆ kUniformsKey

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

Definition at line 196 of file runtime_stage_data.cc.

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

## ◆ kUniformTypeKey

const char* impeller::compiler::kUniformTypeKey = "type"
| static

Definition at line 200 of file runtime_stage_data.cc.

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

impeller::kBoolean
@ kBoolean
Definition: runtime_types.h:22
impeller::kFloat
@ kFloat
Definition: runtime_types.h:32
impeller::compiler::CreateVulkanCompiler
static CompilerBackend CreateVulkanCompiler(const spirv_cross::ParsedIR &ir, const SourceOptions &source_options)
Definition: compiler.cc:122
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::kUnsignedShort
@ kUnsignedShort
Definition: runtime_types.h:26
impeller::compiler::CreateSkSLCompiler
static CompilerBackend CreateSkSLCompiler(const spirv_cross::ParsedIR &ir, const SourceOptions &source_options)
Definition: compiler.cc:186
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:69
impeller::compiler::ToLowerCase
std::string ToLowerCase(std::string_view string)
Definition: utilities.cc:62
impeller::compiler::SourceType::kUnknown
@ kUnknown
impeller::compiler::EntryPointMustBeNamedMain
static bool EntryPointMustBeNamedMain(TargetPlatform platform)
Definition: compiler.cc:192
impeller::compiler::ParseMSLVersion
static uint32_t ParseMSLVersion(const std::string &msl_version)
Definition: compiler.cc:28
impeller::compiler::TargetPlatform::kMetalDesktop
@ kMetalDesktop
impeller::kSignedByte
@ kSignedByte
Definition: runtime_types.h:23
impeller::compiler::TargetPlatformToMSLPlatform
spirv_cross::CompilerMSL::Options::Platform TargetPlatformToMSLPlatform(TargetPlatform platform)
Definition: types.cc:212
impeller::compiler::OutputDepfile
static bool OutputDepfile(const Compiler &compiler, const Switches &switches)
Definition: impellerc_main.cc:196
impeller::kSampledImage
@ kSampledImage
Definition: runtime_types.h:34
impeller::compiler::CreateGLSLCompiler
static CompilerBackend CreateGLSLCompiler(const spirv_cross::ParsedIR &ir, const SourceOptions &source_options)
Definition: compiler.cc:136
impeller::compiler::TargetPlatformNeedsReflection
bool TargetPlatformNeedsReflection(TargetPlatform platform)
Definition: types.cc:141
impeller::compiler::InferShaderNameFromPath
std::string InferShaderNameFromPath(std::string_view path)
Definition: utilities.cc:34
impeller::compiler::TargetPlatform::kMetalIOS
@ kMetalIOS
impeller::compiler::ParseShaderBundleConfig
std::optional< ShaderBundleConfig > ParseShaderBundleConfig(const std::string &bundle_config_json, std::ostream &error_stream)
Parse a shader bundle configuration from a given JSON string.
Definition: shader_bundle.cc:19
impeller::compiler::kKnownPlatforms
static const std::map< std::string, TargetPlatform > kKnownPlatforms
Definition: switches.cc:20
impeller::compiler::SourceLanguage::kGLSL
@ kGLSL
impeller::compiler::StringEndWith
static bool StringEndWith(const std::string &string, const std::string &suffix)
Definition: types.cc:17
impeller::kSignedInt
@ kSignedInt
Definition: runtime_types.h:27
impeller::compiler::kExternalTexturePrefix
constexpr char kExternalTexturePrefix[]
Definition: constants.h:11
impeller::compiler::ToSourceLanguage
SourceLanguage ToSourceLanguage(const std::string &source_language)
Definition: types.cc:64
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:11
impeller::compiler::GenerateShaderFB
static std::unique_ptr< fb::ShaderT > GenerateShaderFB(SourceOptions options, const std::string &shader_name, const ShaderConfig &shader_config)
Definition: shader_bundle.cc:84
impeller::compiler::SourceLanguage::kHLSL
@ kHLSL
impeller::compiler::TargetPlatform::kVulkan
@ kVulkan
impeller::compiler::SourceType::kFragmentShader
@ kFragmentShader
impeller::compiler::TargetPlatform::kRuntimeStageVulkan
@ kRuntimeStageVulkan
impeller::compiler::OutputReflectionData
static bool OutputReflectionData(const Compiler &compiler, const Switches &switches, const SourceOptions &options)
Definition: impellerc_main.cc:144
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:111
impeller::compiler::OutputIPLR
static bool OutputIPLR(const Switches &switches, const std::shared_ptr< fml::Mapping > &source_file_mapping)
Definition: impellerc_main.cc:56
impeller::scene::importer::kKnownSourceTypes
static const std::map< std::string, SourceType > kKnownSourceTypes
Definition: switches.cc:20
impeller::kUnsignedByte
@ kUnsignedByte
Definition: runtime_types.h:24
impeller::kUnsignedInt64
@ kUnsignedInt64
Definition: runtime_types.h:30
impeller::compiler::OutputSLFile
static bool OutputSLFile(const Compiler &compiler, const Switches &switches)
Definition: impellerc_main.cc:126
impeller::kHalfFloat
@ kHalfFloat
Definition: runtime_types.h:31
impeller::kUnsignedInt
@ kUnsignedInt
Definition: runtime_types.h:28
impeller::compiler::CompileSkSL
static std::shared_ptr< RuntimeStageData::Shader > CompileSkSL(std::shared_ptr< fml::Mapping > source_file_mapping, const Switches &switches)
Definition: impellerc_main.cc:37
impeller::compiler::ToExecutionModel
spv::ExecutionModel ToExecutionModel(SourceType type)
Definition: types.cc:198
impeller::kSignedShort
@ kSignedShort
Definition: runtime_types.h:25
impeller::compiler::ShaderBundleConfig
std::unordered_map< std::string, ShaderConfig > ShaderBundleConfig
Definition: types.h:55
impeller::compiler::GenerateShaderBundleFlatbuffer
std::optional< fb::ShaderBundleT > GenerateShaderBundleFlatbuffer(const std::string &bundle_config_json, const SourceOptions &options)
Parses the JSON shader bundle configuration and invokes the compiler multiple times to produce a shad...
Definition: shader_bundle.cc:144
impeller::kDouble
@ kDouble
Definition: runtime_types.h:33
impeller::compiler::SourceLanguage
SourceLanguage
Definition: types.h:41
impeller::compiler::TargetPlatform::kOpenGLDesktop
@ kOpenGLDesktop
impeller::compiler::SourceTypeFromString
SourceType SourceTypeFromString(std::string name)
Definition: types.cc:46
impeller::kSignedInt64
@ kSignedInt64
Definition: runtime_types.h:29
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:51
impeller::compiler::SetPermissiveAccess
bool SetPermissiveAccess(const std::filesystem::path &p)
Sets the file access mode of the file at path 'p' to 0644.
Definition: utilities.cc:16
impeller::compiler::Utf8FromPath
std::string Utf8FromPath(const std::filesystem::path &path)
Converts a native format path to a utf8 string.
Definition: utilities.cc:30
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:87
impeller::compiler::TargetPlatformBundlesSkSL
bool TargetPlatformBundlesSkSL(TargetPlatform platform)
Definition: types.cc:320
impeller::compiler::GenerateShaderBundle
bool GenerateShaderBundle(Switches &switches)
Parses the JSON shader bundle configuration and invokes the compiler multiple times to produce a shad...
Definition: shader_bundle.cc:175
impeller::compiler::TypeNameWithPaddingOfSize
static std::string TypeNameWithPaddingOfSize(size_t size)
Definition: reflector.cc:575
impeller::compiler::kKnownRuntimeStages
static const std::map< std::string, TargetPlatform > kKnownRuntimeStages
Definition: switches.cc:28
impeller::compiler::TargetPlatform::kSkSL
@ kSkSL
impeller::compiler::TargetPlatform::kRuntimeStageGLES
@ kRuntimeStageGLES
impeller::compiler::CreateReflectorOptions
static Reflector::Options CreateReflectorOptions(const SourceOptions &options, const Switches &switches)
Definition: impellerc_main.cc:23