| 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 "runtime_stage_types_flatbuffers.h"
16 #include "shaderc/shaderc.hpp"
17 #include "spirv_cross.hpp"
18 #include "spirv_msl.hpp"
19
20 namespace impeller {
21 namespace compiler {
22
23 enum class SourceType {
24 kUnknown,
25 kVertexShader,
26 kFragmentShader,
27 kComputeShader,
28 };
29
30 enum class TargetPlatform {
31 kUnknown,
32 kMetalDesktop,
33 kMetalIOS,
34 kOpenGLES,
35 kOpenGLDesktop,
36 kVulkan,
37 kRuntimeStageMetal,
38 kRuntimeStageGLES,
39 kRuntimeStageGLES3,
40 kRuntimeStageVulkan,
41 kSkSL,
42 };
43
44 enum class SourceLanguage {
45 kUnknown,
46 kGLSL,
47 kHLSL,
48 };
49
50 struct StructField {
51 std::string name;
52 // The size in bytes of this field, not including padding.
53 size_t byte_size;
54 };
55
56 struct UniformDescription {
57 std::string name;
58 size_t location = 0u;
59 size_t binding = 0u;
60 spirv_cross::SPIRType::BaseType type = spirv_cross::SPIRType::BaseType::Float;
61 size_t rows = 0u;
62 size_t columns = 0u;
63 size_t bit_width = 0u;
64 std::optional<size_t> array_elements = std::nullopt;
65 /// The layout of padding bytes in the uniform buffer.
66 /// The format matches the values in the flatbuffer
67 /// UniformDescription::padding_layout.
68 /// \see RuntimeEffectContents::EmplaceUniform
69 std::vector<fb::PaddingType> padding_layout = {};
70 // The fields of the struct. Necessary on Vulkan, where everything is
71 // packed into a struct.
72 std::vector<StructField> struct_fields = {};
73 size_t struct_float_count = 0u;
74 };
75
76 struct InputDescription {
77 std::string name;
78 size_t location;
79 size_t set;
80 size_t binding;
81 spirv_cross::SPIRType::BaseType type =
82 spirv_cross::SPIRType::BaseType::Unknown;
83 size_t bit_width;
84 size_t vec_size;
85 size_t columns;
86 size_t offset;
87 };
88
89 /// A shader config parsed as part of a ShaderBundleConfig.
90 struct ShaderConfig {
91 std::string source_file_name;
92 SourceType type;
93 SourceLanguage language;
94 std::string entry_point;
95 };
96
97 using ShaderBundleConfig = std::unordered_map<std::string, ShaderConfig>;
98
99 bool TargetPlatformIsMetal(TargetPlatform platform);
100
101 bool TargetPlatformIsOpenGL(TargetPlatform platform);
102
103 bool TargetPlatformIsVulkan(TargetPlatform platform);
104
105 SourceType SourceTypeFromFileName(const std::filesystem::path& file_name);
106
107 SourceType SourceTypeFromString(std::string name);
108
109 std::string SourceTypeToString(SourceType type);
110
111 std::string TargetPlatformToString(TargetPlatform platform);
112
113 SourceLanguage ToSourceLanguage(const std::string& source_language);
114
115 std::string SourceLanguageToString(SourceLanguage source_language);
116
117 std::string TargetPlatformSLExtension(TargetPlatform platform);
118
119 std::string EntryPointFunctionNameFromSourceName(
120 const std::filesystem::path& file_name,
121 SourceType type,
122 SourceLanguage source_language,
123 const std::string& entry_point_name);
124
125 bool TargetPlatformNeedsReflection(TargetPlatform platform);
126
127 bool TargetPlatformBundlesSkSL(TargetPlatform platform);
128
129 std::string ShaderCErrorToString(shaderc_compilation_status status);
130
131 shaderc_shader_kind ToShaderCShaderKind(SourceType type);
132
133 spv::ExecutionModel ToExecutionModel(SourceType type);
134
135 spirv_cross::CompilerMSL::Options::Platform TargetPlatformToMSLPlatform(
136 TargetPlatform platform);
137
138 } // namespace compiler
139 } // namespace impeller
140
141 #endif // FLUTTER_IMPELLER_COMPILER_TYPES_H_
type
GLenum type
Definition: blit_command_gles.cc:153
impeller::compiler::SourceType
SourceType
Definition: types.h:23
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:44
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:97
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:30
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:76
impeller::compiler::InputDescription::type
spirv_cross::SPIRType::BaseType type
Definition: types.h:81
impeller::compiler::InputDescription::columns
size_t columns
Definition: types.h:85
impeller::compiler::InputDescription::vec_size
size_t vec_size
Definition: types.h:84
impeller::compiler::InputDescription::location
size_t location
Definition: types.h:78
impeller::compiler::InputDescription::set
size_t set
Definition: types.h:79
impeller::compiler::InputDescription::bit_width
size_t bit_width
Definition: types.h:83
impeller::compiler::InputDescription::name
std::string name
Definition: types.h:77
impeller::compiler::InputDescription::binding
size_t binding
Definition: types.h:80
impeller::compiler::InputDescription::offset
size_t offset
Definition: types.h:86
impeller::compiler::ShaderConfig
A shader config parsed as part of a ShaderBundleConfig.
Definition: types.h:90
impeller::compiler::ShaderConfig::source_file_name
std::string source_file_name
Definition: types.h:91
impeller::compiler::ShaderConfig::language
SourceLanguage language
Definition: types.h:93
impeller::compiler::ShaderConfig::type
SourceType type
Definition: types.h:92
impeller::compiler::ShaderConfig::entry_point
std::string entry_point
Definition: types.h:94
impeller::compiler::StructField
Definition: types.h:50
impeller::compiler::StructField::name
std::string name
Definition: types.h:51
impeller::compiler::StructField::byte_size
size_t byte_size
Definition: types.h:53
impeller::compiler::UniformDescription
Definition: types.h:56
impeller::compiler::UniformDescription::bit_width
size_t bit_width
Definition: types.h:63
impeller::compiler::UniformDescription::type
spirv_cross::SPIRType::BaseType type
Definition: types.h:60
impeller::compiler::UniformDescription::location
size_t location
Definition: types.h:58
impeller::compiler::UniformDescription::name
std::string name
Definition: types.h:57
impeller::compiler::UniformDescription::array_elements
std::optional< size_t > array_elements
Definition: types.h:64
impeller::compiler::UniformDescription::padding_layout
std::vector< fb::PaddingType > padding_layout
Definition: types.h:69
impeller::compiler::UniformDescription::struct_float_count
size_t struct_float_count
Definition: types.h:73
impeller::compiler::UniformDescription::binding
size_t binding
Definition: types.h:59
impeller::compiler::UniformDescription::columns
size_t columns
Definition: types.h:62
impeller::compiler::UniformDescription::rows
size_t rows
Definition: types.h:61
impeller::compiler::UniformDescription::struct_fields
std::vector< StructField > struct_fields
Definition: types.h:72