Flutter Impeller
types.h
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 
5 #ifndef FLUTTER_IMPELLER_COMPILER_TYPES_H_
6 #define FLUTTER_IMPELLER_COMPILER_TYPES_H_
7 
8 #include <codecvt>
9 #include <locale>
10 #include <map>
11 #include <optional>
12 #include <string>
13 
14 #include "shaderc/shaderc.hpp"
15 #include "spirv_cross.hpp"
16 #include "spirv_msl.hpp"
17 
18 namespace impeller {
19 namespace compiler {
20 
21 enum class SourceType {
22  kUnknown,
26 };
27 
28 enum class TargetPlatform {
29  kUnknown,
31  kMetalIOS,
32  kOpenGLES,
34  kVulkan,
39  kSkSL,
40 };
41 
42 enum class SourceLanguage {
43  kUnknown,
44  kGLSL,
45  kHLSL,
46 };
47 
49  std::string name;
50  size_t location = 0u;
51  size_t binding = 0u;
52  spirv_cross::SPIRType::BaseType type = spirv_cross::SPIRType::BaseType::Float;
53  size_t rows = 0u;
54  size_t columns = 0u;
55  size_t bit_width = 0u;
56  std::optional<size_t> array_elements = std::nullopt;
57  std::vector<uint8_t> struct_layout = {};
58  size_t struct_float_count = 0u;
59 };
60 
62  std::string name;
63  size_t location;
64  size_t set;
65  size_t binding;
66  spirv_cross::SPIRType::BaseType type =
67  spirv_cross::SPIRType::BaseType::Unknown;
68  size_t bit_width;
69  size_t vec_size;
70  size_t columns;
71  size_t offset;
72 };
73 
74 /// A shader config parsed as part of a ShaderBundleConfig.
75 struct ShaderConfig {
76  std::string source_file_name;
79  std::string entry_point;
80 };
81 
82 using ShaderBundleConfig = std::unordered_map<std::string, ShaderConfig>;
83 
85 
87 
89 
90 SourceType SourceTypeFromFileName(const std::string& file_name);
91 
92 SourceType SourceTypeFromString(std::string name);
93 
95 
96 std::string TargetPlatformToString(TargetPlatform platform);
97 
98 SourceLanguage ToSourceLanguage(const std::string& source_language);
99 
100 std::string SourceLanguageToString(SourceLanguage source_language);
101 
102 std::string TargetPlatformSLExtension(TargetPlatform platform);
103 
105  const std::string& file_name,
107  SourceLanguage source_language,
108  const std::string& entry_point_name);
109 
111 
113 
114 std::string ShaderCErrorToString(shaderc_compilation_status status);
115 
116 shaderc_shader_kind ToShaderCShaderKind(SourceType type);
117 
118 spv::ExecutionModel ToExecutionModel(SourceType type);
119 
120 spirv_cross::CompilerMSL::Options::Platform TargetPlatformToMSLPlatform(
121  TargetPlatform platform);
122 
123 } // namespace compiler
124 } // namespace impeller
125 
126 #endif // FLUTTER_IMPELLER_COMPILER_TYPES_H_
GLenum type
std::string SourceLanguageToString(SourceLanguage source_language)
Definition: types.cc:102
std::string TargetPlatformToString(TargetPlatform platform)
Definition: types.cc:74
std::string TargetPlatformSLExtension(TargetPlatform platform)
Definition: types.cc:250
shaderc_shader_kind ToShaderCShaderKind(SourceType type)
Definition: types.cc:187
std::string SourceTypeToString(SourceType type)
Definition: types.cc:236
std::unordered_map< std::string, ShaderConfig > ShaderBundleConfig
Definition: types.h:82
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:113
bool TargetPlatformIsMetal(TargetPlatform platform)
Definition: types.cc:290
bool TargetPlatformIsOpenGL(TargetPlatform platform)
Definition: types.cc:271
std::string ShaderCErrorToString(shaderc_compilation_status status)
Definition: types.cc:162
bool TargetPlatformIsVulkan(TargetPlatform platform)
Definition: types.cc:309
bool TargetPlatformBundlesSkSL(TargetPlatform platform)
Definition: types.cc:328
spirv_cross::CompilerMSL::Options::Platform TargetPlatformToMSLPlatform(TargetPlatform platform)
Definition: types.cc:215
SourceLanguage ToSourceLanguage(const std::string &source_language)
Definition: types.cc:64
bool TargetPlatformNeedsReflection(TargetPlatform platform)
Definition: types.cc:143
spv::ExecutionModel ToExecutionModel(SourceType type)
Definition: types.cc:201
spirv_cross::SPIRType::BaseType type
Definition: types.h:66
A shader config parsed as part of a ShaderBundleConfig.
Definition: types.h:75
std::string source_file_name
Definition: types.h:76
SourceLanguage language
Definition: types.h:78
spirv_cross::SPIRType::BaseType type
Definition: types.h:52
std::optional< size_t > array_elements
Definition: types.h:56
std::vector< uint8_t > struct_layout
Definition: types.h:57