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,
28 };
29 
30 enum class TargetPlatform {
31  kUnknown,
33  kMetalIOS,
34  kOpenGLES,
36  kVulkan,
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 
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 
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;
94  std::string entry_point;
95 };
96 
97 using ShaderBundleConfig = std::unordered_map<std::string, ShaderConfig>;
98 
100 
102 
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 
120  const std::filesystem::path& file_name,
122  SourceLanguage source_language,
123  const std::string& entry_point_name);
124 
126 
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_
GLenum type
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::unordered_map< std::string, ShaderConfig > ShaderBundleConfig
Definition: types.h:97
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
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
spirv_cross::SPIRType::BaseType type
Definition: types.h:81
A shader config parsed as part of a ShaderBundleConfig.
Definition: types.h:90
std::string source_file_name
Definition: types.h:91
SourceLanguage language
Definition: types.h:93
spirv_cross::SPIRType::BaseType type
Definition: types.h:60
std::optional< size_t > array_elements
Definition: types.h:64
std::vector< fb::PaddingType > padding_layout
Definition: types.h:69
std::vector< StructField > struct_fields
Definition: types.h:72