Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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
17SourceType SourceTypeFromFileName(const std::filesystem::path& file_name) {
18 std::string extension = file_name.extension().string();
19 if (extension == ".vert") {
21 }
22
23 if (extension == ".frag") {
25 }
26
27 if (extension == ".comp") {
29 }
30
32}
33
36
37 if (name == "vertex") {
39 }
40
41 if (name == "fragment") {
43 }
44
45 if (name == "compute") {
47 }
48
50}
51
52SourceLanguage ToSourceLanguage(const std::string& source_language) {
53 if (source_language == "glsl") {
55 }
56 if (source_language == "hlsl") {
58 }
60}
61
63 switch (platform) {
65 return "Unknown";
67 return "MetalDesktop";
69 return "MetaliOS";
71 return "OpenGLES";
73 return "OpenGLDesktop";
75 return "Vulkan";
77 return "RuntimeStageMetal";
79 return "RuntimeStageGLES";
81 return "RuntimeStageGLES3";
83 return "RuntimeStageVulkan";
85 return "SkSL";
86 }
88}
89
90std::string SourceLanguageToString(SourceLanguage source_language) {
91 switch (source_language) {
93 return "Unknown";
95 return "GLSL";
97 return "HLSL";
98 }
99}
100
102 const std::filesystem::path& file_name,
104 SourceLanguage source_language,
105 const std::string& entry_point_name) {
106 if (source_language == SourceLanguage::kHLSL) {
107 return entry_point_name;
108 }
109
110 std::stringstream stream;
111 stream << ConvertToEntrypointName(Utf8FromPath(file_name.stem())) << "_";
112 switch (type) {
114 stream << "unknown";
115 break;
117 stream << "vertex";
118 break;
120 stream << "fragment";
121 break;
123 stream << "compute";
124 break;
125 }
126 stream << "_main";
127 return stream.str();
128}
129
130std::string ShaderCErrorToString(shaderc_compilation_status status) {
131 using Status = shaderc_compilation_status;
132 switch (status) {
133 case Status::shaderc_compilation_status_success:
134 return "Success";
135 case Status::shaderc_compilation_status_invalid_stage:
136 return "Invalid shader stage specified";
137 case Status::shaderc_compilation_status_compilation_error:
138 return "Compilation error";
139 case Status::shaderc_compilation_status_internal_error:
140 return "Internal error";
141 case Status::shaderc_compilation_status_null_result_object:
142 return "Internal error. Null result object";
143 case Status::shaderc_compilation_status_invalid_assembly:
144 return "Invalid assembly";
145 case Status::shaderc_compilation_status_validation_error:
146 return "Validation error";
147 case Status::shaderc_compilation_status_transformation_error:
148 return "Transform error";
149 case Status::shaderc_compilation_status_configuration_error:
150 return "Configuration error";
151 }
152 return "Unknown internal error";
153}
154
155shaderc_shader_kind ToShaderCShaderKind(SourceType type) {
156 switch (type) {
158 return shaderc_shader_kind::shaderc_vertex_shader;
160 return shaderc_shader_kind::shaderc_fragment_shader;
162 return shaderc_shader_kind::shaderc_compute_shader;
164 break;
165 }
166 return shaderc_shader_kind::shaderc_glsl_infer_from_source;
167}
168
169spv::ExecutionModel ToExecutionModel(SourceType type) {
170 switch (type) {
172 return spv::ExecutionModel::ExecutionModelVertex;
174 return spv::ExecutionModel::ExecutionModelFragment;
176 return spv::ExecutionModel::ExecutionModelGLCompute;
178 break;
179 }
180 return spv::ExecutionModel::ExecutionModelMax;
181}
182
183spirv_cross::CompilerMSL::Options::Platform TargetPlatformToMSLPlatform(
184 TargetPlatform platform) {
185 switch (platform) {
188 return spirv_cross::CompilerMSL::Options::Platform::iOS;
190 return spirv_cross::CompilerMSL::Options::Platform::macOS;
199 return spirv_cross::CompilerMSL::Options::Platform::macOS;
200 }
202}
203
205 switch (type) {
207 return "unknown";
209 return "vert";
211 return "frag";
213 return "comp";
214 }
216}
217
219 switch (platform) {
221 return "unknown";
225 return "metal";
231 return "glsl";
234 return "vk.spirv";
235 }
237}
238
257
276
295
296} // namespace compiler
297} // namespace impeller
#define FML_UNREACHABLE()
Definition logging.h:128
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:68
std::string ToLowerCase(std::string_view string)
Definition utilities.cc:61
std::string SourceLanguageToString(SourceLanguage source_language)
Definition types.cc:90
std::string TargetPlatformToString(TargetPlatform platform)
Definition types.cc:62
std::string TargetPlatformSLExtension(TargetPlatform platform)
Definition types.cc:218
shaderc_shader_kind ToShaderCShaderKind(SourceType type)
Definition types.cc:155
std::string SourceTypeToString(SourceType type)
Definition types.cc:204
SourceType SourceTypeFromFileName(const std::filesystem::path &file_name)
Definition types.cc:17
std::string EntryPointFunctionNameFromSourceName(const std::filesystem::path &file_name, SourceType type, SourceLanguage source_language, const std::string &entry_point_name)
Definition types.cc:101
SourceType SourceTypeFromString(std::string name)
Definition types.cc:34
bool TargetPlatformIsMetal(TargetPlatform platform)
Definition types.cc:258
bool TargetPlatformIsOpenGL(TargetPlatform platform)
Definition types.cc:239
std::string ShaderCErrorToString(shaderc_compilation_status status)
Definition types.cc:130
bool TargetPlatformIsVulkan(TargetPlatform platform)
Definition types.cc:277
std::string Utf8FromPath(const std::filesystem::path &path)
Converts a native format path to a utf8 string.
Definition utilities.cc:30
spirv_cross::CompilerMSL::Options::Platform TargetPlatformToMSLPlatform(TargetPlatform platform)
Definition types.cc:183
SourceLanguage ToSourceLanguage(const std::string &source_language)
Definition types.cc:52
spv::ExecutionModel ToExecutionModel(SourceType type)
Definition types.cc:169
impeller::ShaderType type