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
148
149std::string ShaderCErrorToString(shaderc_compilation_status status) {
150 using Status = shaderc_compilation_status;
151 switch (status) {
152 case Status::shaderc_compilation_status_success:
153 return "Success";
154 case Status::shaderc_compilation_status_invalid_stage:
155 return "Invalid shader stage specified";
156 case Status::shaderc_compilation_status_compilation_error:
157 return "Compilation error";
158 case Status::shaderc_compilation_status_internal_error:
159 return "Internal error";
160 case Status::shaderc_compilation_status_null_result_object:
161 return "Internal error. Null result object";
162 case Status::shaderc_compilation_status_invalid_assembly:
163 return "Invalid assembly";
164 case Status::shaderc_compilation_status_validation_error:
165 return "Validation error";
166 case Status::shaderc_compilation_status_transformation_error:
167 return "Transform error";
168 case Status::shaderc_compilation_status_configuration_error:
169 return "Configuration error";
170 }
171 return "Unknown internal error";
172}
173
174shaderc_shader_kind ToShaderCShaderKind(SourceType type) {
175 switch (type) {
177 return shaderc_shader_kind::shaderc_vertex_shader;
179 return shaderc_shader_kind::shaderc_fragment_shader;
181 return shaderc_shader_kind::shaderc_compute_shader;
183 break;
184 }
185 return shaderc_shader_kind::shaderc_glsl_infer_from_source;
186}
187
188spv::ExecutionModel ToExecutionModel(SourceType type) {
189 switch (type) {
191 return spv::ExecutionModel::ExecutionModelVertex;
193 return spv::ExecutionModel::ExecutionModelFragment;
195 return spv::ExecutionModel::ExecutionModelGLCompute;
197 break;
198 }
199 return spv::ExecutionModel::ExecutionModelMax;
200}
201
202spirv_cross::CompilerMSL::Options::Platform TargetPlatformToMSLPlatform(
203 TargetPlatform platform) {
204 switch (platform) {
207 return spirv_cross::CompilerMSL::Options::Platform::iOS;
209 return spirv_cross::CompilerMSL::Options::Platform::macOS;
218 return spirv_cross::CompilerMSL::Options::Platform::macOS;
219 }
221}
222
224 switch (type) {
226 return "unknown";
228 return "vert";
230 return "frag";
232 return "comp";
233 }
235}
236
238 switch (platform) {
240 return "unknown";
244 return "metal";
250 return "glsl";
253 return "vk.spirv";
254 }
256}
257
276
295
314
333
334} // namespace compiler
335} // namespace impeller
GLenum type
#define FML_UNREACHABLE()
Definition logging.h:128
const char * name
Definition fuchsia.cc:49
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:237
shaderc_shader_kind ToShaderCShaderKind(SourceType type)
Definition types.cc:174
std::string SourceTypeToString(SourceType type)
Definition types.cc:223
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:277
bool TargetPlatformIsOpenGL(TargetPlatform platform)
Definition types.cc:258
std::string ShaderCErrorToString(shaderc_compilation_status status)
Definition types.cc:149
bool TargetPlatformIsVulkan(TargetPlatform platform)
Definition types.cc:296
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:315
spirv_cross::CompilerMSL::Options::Platform TargetPlatformToMSLPlatform(TargetPlatform platform)
Definition types.cc:202
SourceLanguage ToSourceLanguage(const std::string &source_language)
Definition types.cc:52
bool TargetPlatformNeedsReflection(TargetPlatform platform)
Definition types.cc:130
spv::ExecutionModel ToExecutionModel(SourceType type)
Definition types.cc:188