| 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 <filesystem>
10 #include <locale>
11 #include <map>
12 #include <optional>
13 #include <string>
14
15 #include "shaderc/shaderc.hpp"
16 #include "spirv_cross.hpp"
17 #include "spirv_msl.hpp"
18
19 namespace impeller {
20 namespace compiler {
21
22 enum class SourceType {
23 kUnknown,
24 kVertexShader,
25 kFragmentShader,
26 kComputeShader,
27 };
28
29 enum class TargetPlatform {
30 kUnknown,
31 kMetalDesktop,
32 kMetalIOS,
33 kOpenGLES,
34 kOpenGLDesktop,
35 kVulkan,
36 kRuntimeStageMetal,
37 kRuntimeStageGLES,
38 kRuntimeStageGLES3,
39 kRuntimeStageVulkan,
40 kSkSL,
41 };
42
43 enum class SourceLanguage {
44 kUnknown,
45 kGLSL,
46 kHLSL,
47 };
48
49 struct UniformDescription {
50 std::string name;
51 size_t location = 0u;
52 size_t binding = 0u;
53 spirv_cross::SPIRType::BaseType type = spirv_cross::SPIRType::BaseType::Float;
54 size_t rows = 0u;
55 size_t columns = 0u;
56 size_t bit_width = 0u;
57 std::optional<size_t> array_elements = std::nullopt;
58 std::vector<uint8_t> struct_layout = {};
59 size_t struct_float_count = 0u;
60 };
61
62 struct InputDescription {
63 std::string name;
64 size_t location;
65 size_t set;
66 size_t binding;
67 spirv_cross::SPIRType::BaseType type =
68 spirv_cross::SPIRType::BaseType::Unknown;
69 size_t bit_width;
70 size_t vec_size;
71 size_t columns;
72 size_t offset;
73 };
74
75 /// A shader config parsed as part of a ShaderBundleConfig.
76 struct ShaderConfig {
77 std::string source_file_name;
78 SourceType type;
79 SourceLanguage language;
80 std::string entry_point;
81 };
82
83 using ShaderBundleConfig = std::unordered_map<std::string, ShaderConfig>;
84
85 bool TargetPlatformIsMetal(TargetPlatform platform);
86
87 bool TargetPlatformIsOpenGL(TargetPlatform platform);
88
89 bool TargetPlatformIsVulkan(TargetPlatform platform);
90
91 SourceType SourceTypeFromFileName(const std::filesystem::path& file_name);
92
93 SourceType SourceTypeFromString(std::string name);
94
95 std::string SourceTypeToString(SourceType type);
96
97 std::string TargetPlatformToString(TargetPlatform platform);
98
99 SourceLanguage ToSourceLanguage(const std::string& source_language);
100
101 std::string SourceLanguageToString(SourceLanguage source_language);
102
103 std::string TargetPlatformSLExtension(TargetPlatform platform);
104
105 std::string EntryPointFunctionNameFromSourceName(
106 const std::filesystem::path& file_name,
107 SourceType type,
108 SourceLanguage source_language,
109 const std::string& entry_point_name);
110
111 bool TargetPlatformNeedsReflection(TargetPlatform platform);
112
113 bool TargetPlatformBundlesSkSL(TargetPlatform platform);
114
115 std::string ShaderCErrorToString(shaderc_compilation_status status);
116
117 shaderc_shader_kind ToShaderCShaderKind(SourceType type);
118
119 spv::ExecutionModel ToExecutionModel(SourceType type);
120
121 spirv_cross::CompilerMSL::Options::Platform TargetPlatformToMSLPlatform(
122 TargetPlatform platform);
123
124 } // namespace compiler
125 } // namespace impeller
126
127 #endif // FLUTTER_IMPELLER_COMPILER_TYPES_H_
type
GLenum type
Definition: blit_command_gles.cc:153
impeller::compiler::SourceType
SourceType
Definition: types.h:22
impeller::compiler::SourceType::kUnknown
@ kUnknown
impeller::compiler::SourceType::kFragmentShader
@ kFragmentShader
impeller::compiler::SourceType::kVertexShader
@ kVertexShader
impeller::compiler::SourceType::kComputeShader
@ kComputeShader
impeller::compiler::SourceLanguageToString
std::string SourceLanguageToString(SourceLanguage source_language)
Definition: types.cc:90
impeller::compiler::TargetPlatformToString
std::string TargetPlatformToString(TargetPlatform platform)
Definition: types.cc:62
impeller::compiler::TargetPlatformSLExtension
std::string TargetPlatformSLExtension(TargetPlatform platform)
Definition: types.cc:237
impeller::compiler::ToShaderCShaderKind
shaderc_shader_kind ToShaderCShaderKind(SourceType type)
Definition: types.cc:174
impeller::compiler::SourceTypeToString
std::string SourceTypeToString(SourceType type)
Definition: types.cc:223
impeller::compiler::SourceTypeFromFileName
SourceType SourceTypeFromFileName(const std::filesystem::path &file_name)
Definition: types.cc:17
impeller::compiler::SourceLanguage
SourceLanguage
Definition: types.h:43
impeller::compiler::SourceLanguage::kUnknown
@ kUnknown
impeller::compiler::SourceLanguage::kGLSL
@ kGLSL
impeller::compiler::SourceLanguage::kHLSL
@ kHLSL
impeller::compiler::ShaderBundleConfig
std::unordered_map< std::string, ShaderConfig > ShaderBundleConfig
Definition: types.h:83
impeller::compiler::EntryPointFunctionNameFromSourceName
std::string EntryPointFunctionNameFromSourceName(const std::filesystem::path &file_name, SourceType type, SourceLanguage source_language, const std::string &entry_point_name)
Definition: types.cc:101
impeller::compiler::SourceTypeFromString
SourceType SourceTypeFromString(std::string name)
Definition: types.cc:34
impeller::compiler::TargetPlatformIsMetal
bool TargetPlatformIsMetal(TargetPlatform platform)
Definition: types.cc:277
impeller::compiler::TargetPlatformIsOpenGL
bool TargetPlatformIsOpenGL(TargetPlatform platform)
Definition: types.cc:258
impeller::compiler::ShaderCErrorToString
std::string ShaderCErrorToString(shaderc_compilation_status status)
Definition: types.cc:149
impeller::compiler::TargetPlatformIsVulkan
bool TargetPlatformIsVulkan(TargetPlatform platform)
Definition: types.cc:296
impeller::compiler::TargetPlatformBundlesSkSL
bool TargetPlatformBundlesSkSL(TargetPlatform platform)
Definition: types.cc:315
impeller::compiler::TargetPlatformToMSLPlatform
spirv_cross::CompilerMSL::Options::Platform TargetPlatformToMSLPlatform(TargetPlatform platform)
Definition: types.cc:202
impeller::compiler::ToSourceLanguage
SourceLanguage ToSourceLanguage(const std::string &source_language)
Definition: types.cc:52
impeller::compiler::TargetPlatformNeedsReflection
bool TargetPlatformNeedsReflection(TargetPlatform platform)
Definition: types.cc:130
impeller::compiler::TargetPlatform
TargetPlatform
Definition: types.h:29
impeller::compiler::TargetPlatform::kRuntimeStageMetal
@ kRuntimeStageMetal
impeller::compiler::TargetPlatform::kOpenGLES
@ kOpenGLES
impeller::compiler::TargetPlatform::kUnknown
@ kUnknown
impeller::compiler::TargetPlatform::kRuntimeStageVulkan
@ kRuntimeStageVulkan
impeller::compiler::TargetPlatform::kRuntimeStageGLES3
@ kRuntimeStageGLES3
impeller::compiler::TargetPlatform::kVulkan
@ kVulkan
impeller::compiler::TargetPlatform::kMetalDesktop
@ kMetalDesktop
impeller::compiler::TargetPlatform::kMetalIOS
@ kMetalIOS
impeller::compiler::TargetPlatform::kSkSL
@ kSkSL
impeller::compiler::TargetPlatform::kOpenGLDesktop
@ kOpenGLDesktop
impeller::compiler::TargetPlatform::kRuntimeStageGLES
@ kRuntimeStageGLES
impeller::compiler::ToExecutionModel
spv::ExecutionModel ToExecutionModel(SourceType type)
Definition: types.cc:188
impeller
Definition: allocation.cc:12
impeller::compiler::InputDescription
Definition: types.h:62
impeller::compiler::InputDescription::type
spirv_cross::SPIRType::BaseType type
Definition: types.h:67
impeller::compiler::InputDescription::columns
size_t columns
Definition: types.h:71
impeller::compiler::InputDescription::vec_size
size_t vec_size
Definition: types.h:70
impeller::compiler::InputDescription::location
size_t location
Definition: types.h:64
impeller::compiler::InputDescription::set
size_t set
Definition: types.h:65
impeller::compiler::InputDescription::bit_width
size_t bit_width
Definition: types.h:69
impeller::compiler::InputDescription::name
std::string name
Definition: types.h:63
impeller::compiler::InputDescription::binding
size_t binding
Definition: types.h:66
impeller::compiler::InputDescription::offset
size_t offset
Definition: types.h:72
impeller::compiler::ShaderConfig
A shader config parsed as part of a ShaderBundleConfig.
Definition: types.h:76
impeller::compiler::ShaderConfig::source_file_name
std::string source_file_name
Definition: types.h:77
impeller::compiler::ShaderConfig::language
SourceLanguage language
Definition: types.h:79
impeller::compiler::ShaderConfig::type
SourceType type
Definition: types.h:78
impeller::compiler::ShaderConfig::entry_point
std::string entry_point
Definition: types.h:80
impeller::compiler::UniformDescription
Definition: types.h:49
impeller::compiler::UniformDescription::bit_width
size_t bit_width
Definition: types.h:56
impeller::compiler::UniformDescription::type
spirv_cross::SPIRType::BaseType type
Definition: types.h:53
impeller::compiler::UniformDescription::location
size_t location
Definition: types.h:51
impeller::compiler::UniformDescription::name
std::string name
Definition: types.h:50
impeller::compiler::UniformDescription::array_elements
std::optional< size_t > array_elements
Definition: types.h:57
impeller::compiler::UniformDescription::struct_float_count
size_t struct_float_count
Definition: types.h:59
impeller::compiler::UniformDescription::binding
size_t binding
Definition: types.h:52
impeller::compiler::UniformDescription::columns
size_t columns
Definition: types.h:55
impeller::compiler::UniformDescription::rows
size_t rows
Definition: types.h:54
impeller::compiler::UniformDescription::struct_layout
std::vector< uint8_t > struct_layout
Definition: types.h:58