Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
types.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include <cctype>
8#include <filesystem>
9#include <sstream>
10
11#include "flutter/fml/logging.h"
13
14namespace impeller {
15namespace compiler {
16
17static bool StringEndWith(const std::string& string,
18 const std::string& suffix) {
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}
29
30SourceType SourceTypeFromFileName(const std::string& file_name) {
31 if (StringEndWith(file_name, ".vert")) {
33 }
34
35 if (StringEndWith(file_name, ".frag")) {
37 }
38
39 if (StringEndWith(file_name, ".comp")) {
41 }
42
44}
45
48
49 if (name == "vertex") {
51 }
52
53 if (name == "fragment") {
55 }
56
57 if (name == "compute") {
59 }
60
62}
63
64SourceLanguage ToSourceLanguage(const std::string& source_language) {
65 if (source_language == "glsl") {
67 }
68 if (source_language == "hlsl") {
70 }
72}
73
75 switch (platform) {
77 return "Unknown";
79 return "MetalDesktop";
81 return "MetaliOS";
83 return "OpenGLES";
85 return "OpenGLDesktop";
87 return "Vulkan";
89 return "RuntimeStageMetal";
91 return "RuntimeStageGLES";
93 return "RuntimeStageVulkan";
95 return "SkSL";
96 }
98}
99
100std::string SourceLanguageToString(SourceLanguage source_language) {
101 switch (source_language) {
103 return "Unknown";
105 return "GLSL";
107 return "HLSL";
108 }
109}
110
112 const std::string& file_name,
114 SourceLanguage source_language,
115 const std::string& entry_point_name) {
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) {
125 stream << "unknown";
126 break;
128 stream << "vertex";
129 break;
131 stream << "fragment";
132 break;
134 stream << "compute";
135 break;
136 }
137 stream << "_main";
138 return stream.str();
139}
140
158
159std::string ShaderCErrorToString(shaderc_compilation_status status) {
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}
183
184shaderc_shader_kind ToShaderCShaderKind(SourceType type) {
185 switch (type) {
187 return shaderc_shader_kind::shaderc_vertex_shader;
189 return shaderc_shader_kind::shaderc_fragment_shader;
191 return shaderc_shader_kind::shaderc_compute_shader;
193 break;
194 }
195 return shaderc_shader_kind::shaderc_glsl_infer_from_source;
196}
197
198spv::ExecutionModel ToExecutionModel(SourceType type) {
199 switch (type) {
201 return spv::ExecutionModel::ExecutionModelVertex;
203 return spv::ExecutionModel::ExecutionModelFragment;
205 return spv::ExecutionModel::ExecutionModelGLCompute;
207 break;
208 }
209 return spv::ExecutionModel::ExecutionModelMax;
210}
211
212spirv_cross::CompilerMSL::Options::Platform TargetPlatformToMSLPlatform(
213 TargetPlatform platform) {
214 switch (platform) {
217 return spirv_cross::CompilerMSL::Options::Platform::iOS;
219 return spirv_cross::CompilerMSL::Options::Platform::macOS;
227 return spirv_cross::CompilerMSL::Options::Platform::macOS;
228 }
230}
231
233 switch (type) {
235 return "unknown";
237 return "vert";
239 return "frag";
241 return "comp";
242 }
244}
245
247 switch (platform) {
249 return "unknown";
253 return "metal";
258 return "glsl";
261 return "vk.spirv";
262 }
264}
265
283
301
319
337
338} // namespace compiler
339} // namespace impeller
#define FML_UNREACHABLE()
Definition logging.h:109
const char * name
Definition fuchsia.cc:50
std::string ConvertToEntrypointName(std::string_view string)
Ensure that the entrypoint name is a valid identifier in the target language.
Definition utilities.cc:69
std::string ToLowerCase(std::string_view string)
Definition utilities.cc:62
static bool StringEndWith(const std::string &string, const std::string &suffix)
Definition types.cc:17
std::string SourceLanguageToString(SourceLanguage source_language)
Definition types.cc:100
std::string TargetPlatformToString(TargetPlatform platform)
Definition types.cc:74
std::string TargetPlatformSLExtension(TargetPlatform platform)
Definition types.cc:246
shaderc_shader_kind ToShaderCShaderKind(SourceType type)
Definition types.cc:184
std::string SourceTypeToString(SourceType type)
Definition types.cc:232
SourceType SourceTypeFromString(std::string name)
Definition types.cc:46
SourceType SourceTypeFromFileName(const std::string &file_name)
Definition types.cc:30
std::string EntryPointFunctionNameFromSourceName(const std::string &file_name, SourceType type, SourceLanguage source_language, const std::string &entry_point_name)
Definition types.cc:111
bool TargetPlatformIsMetal(TargetPlatform platform)
Definition types.cc:284
bool TargetPlatformIsOpenGL(TargetPlatform platform)
Definition types.cc:266
std::string ShaderCErrorToString(shaderc_compilation_status status)
Definition types.cc:159
bool TargetPlatformIsVulkan(TargetPlatform platform)
Definition types.cc:302
std::string Utf8FromPath(const std::filesystem::path &path)
Converts a native format path to a utf8 string.
Definition utilities.cc:30
bool TargetPlatformBundlesSkSL(TargetPlatform platform)
Definition types.cc:320
spirv_cross::CompilerMSL::Options::Platform TargetPlatformToMSLPlatform(TargetPlatform platform)
Definition types.cc:212
SourceLanguage ToSourceLanguage(const std::string &source_language)
Definition types.cc:64
bool TargetPlatformNeedsReflection(TargetPlatform platform)
Definition types.cc:141
spv::ExecutionModel ToExecutionModel(SourceType type)
Definition types.cc:198