| Flutter Impeller |

Classes | Functions | Variables
impeller::compiler::testing Namespace Reference

## Classes
class | CompilerTest

## Functions
static fml::UniqueFD | CreateIntermediatesDirectory ()
static std::string | ReflectionHeaderName (const char *fixture_name)
static std::string | ReflectionCCName (const char *fixture_name)
static std::string | ReflectionJSONName (const char *fixture_name)
static std::string | SPIRVFileName (const char *fixture_name)
static std::string | SLFileName (const char *fixture_name, TargetPlatform platform)
| TEST (CompilerTest, ShaderKindMatchingIsSuccessful)
| TEST_P (CompilerTest, CanCompile)
| TEST_P (CompilerTest, CanCompileHLSL)
| TEST_P (CompilerTest, CanCompileHLSLWithMultipleStages)
| TEST_P (CompilerTest, CanCompileComputeShader)
| TEST_P (CompilerTest, MustFailDueToExceedingResourcesLimit)
| TEST_P (CompilerTest, MustFailDueToMultipleLocationPerStructMember)
| TEST_P (CompilerTest, BindingBaseForFragShader)
| TEST_P (CompilerTest, UniformsHaveBindingAndSet)
| TEST_P (CompilerTest, SkSLTextureLookUpOrderOfOperations)
| INSTANTIATE_TARGET_PLATFORM_TEST_SUITE_P (CompilerSuite)
| TEST (ShaderBundleTest, ParseShaderBundleConfigFailsForInvalidJSON)
| TEST (ShaderBundleTest, ParseShaderBundleConfigFailsWhenEntryNotObject)
| TEST (ShaderBundleTest, ParseShaderBundleConfigFailsWhenMissingFile)
| TEST (ShaderBundleTest, ParseShaderBundleConfigFailsWhenMissingType)
| TEST (ShaderBundleTest, ParseShaderBundleConfigFailsForInvalidType)
| TEST (ShaderBundleTest, ParseShaderBundleConfigFailsForInvalidLanguage)
| TEST (ShaderBundleTest, ParseShaderBundleConfigReturnsExpectedConfig)
template<typename T >
const T * | FindByName (const std::vector< std::unique_ptr< T >> &collection, const std::string &name)
| TEST (ShaderBundleTest, GenerateShaderBundleFlatbufferProducesCorrectResult)
Switches | MakeSwitchesDesktopGL (std::initializer_list< const char * > additional_options={})
| TEST (SwitchesTest, DoesntMangleUnicodeIncludes)
| TEST (SwitchesTest, SourceLanguageDefaultsToGLSL)
| TEST (SwitchesTest, SourceLanguageCanBeSetToHLSL)
| TEST (SwitchesTest, DefaultEntryPointIsMain)
| TEST (SwitchesTest, EntryPointCanBeSetForHLSL)
| TEST (SwitchesTEst, ConvertToEntrypointName)
| TEST (SwitchesTest, ShaderBundleModeValid)

## Variables
const std::string | kUnlitFragmentBundleConfig
const std::string | kUnlitVertexBundleConfig

## Function Documentation

## ◆ CreateIntermediatesDirectory()

static fml::UniqueFD impeller::compiler::testing::CreateIntermediatesDirectory | ( |  | ) |
| static

Definition at line 13 of file compiler_test.cc.

13 {
14 auto test_name = flutter::testing::GetCurrentTestName();
15 std::replace(test_name.begin(), test_name.end(), '/', '_');
16 std::replace(test_name.begin(), test_name.end(), '.', '_');
17 return fml::OpenDirectory(flutter::testing::OpenFixturesDirectory(),
18 test_name.c_str(),
19 true, // create if necessary
20 fml::FilePermission::kReadWrite);
21 }

## ◆ FindByName()

template<typename T >

const T* impeller::compiler::testing::FindByName | ( | const std::vector< std::unique_ptr< T >> & | collection,
|  | const std::string & | name
| ) |  |

Definition at line 120 of file shader_bundle_unittests.cc.

121 {
122 const auto maybe = std::find_if(
123 collection.begin(), collection.end(),
124 [&name](const std::unique_ptr<T>& value) { return value->name == name; });
125 if (maybe == collection.end()) {
126 return nullptr;
127 }
128 return maybe->get();
129 }

Referenced by TEST().

## ◆ INSTANTIATE_TARGET_PLATFORM_TEST_SUITE_P()

impeller::compiler::testing::INSTANTIATE_TARGET_PLATFORM_TEST_SUITE_P | ( | CompilerSuite |  | ) |

## ◆ MakeSwitchesDesktopGL()

Switches impeller::compiler::testing::MakeSwitchesDesktopGL | ( | std::initializer_list< const char * > | additional_options = `{}` | ) |

Definition at line 18 of file switches_unittests.cc.

19 {}) {
20 std::vector<const char*> options = {"--opengl-desktop", "--input=input.vert",
21 "--sl=output.vert",
22 "--spirv=output.spirv"};
23 options.insert(options.end(), additional_options.begin(),
24 additional_options.end());
25
26 auto cl = fml::CommandLineFromIteratorsWithArgv0("impellerc", options.begin(),
27 options.end());
28 return Switches(cl);
29 }

Referenced by TEST().

## ◆ ReflectionCCName()

static std::string impeller::compiler::testing::ReflectionCCName | ( | const char * | fixture_name | ) |
| static

Definition at line 36 of file compiler_test.cc.

36 {
37 std::stringstream stream;
38 stream << fixture_name << ".cc";
39 return stream.str();
40 }

Referenced by impeller::compiler::testing::CompilerTest::CanCompileAndReflect().

## ◆ ReflectionHeaderName()

static std::string impeller::compiler::testing::ReflectionHeaderName | ( | const char * | fixture_name | ) |
| static

Definition at line 30 of file compiler_test.cc.

30 {
31 std::stringstream stream;
32 stream << fixture_name << ".h";
33 return stream.str();
34 }

Referenced by impeller::compiler::testing::CompilerTest::CanCompileAndReflect().

## ◆ ReflectionJSONName()

static std::string impeller::compiler::testing::ReflectionJSONName | ( | const char * | fixture_name | ) |
| static

Definition at line 42 of file compiler_test.cc.

42 {
43 std::stringstream stream;
44 stream << fixture_name << ".json";
45 return stream.str();
46 }

Referenced by impeller::compiler::testing::CompilerTest::CanCompileAndReflect(), and impeller::compiler::testing::CompilerTest::GetReflectionJson().

## ◆ SLFileName()

static std::string impeller::compiler::testing::SLFileName | ( | const char * | fixture_name,
|  | TargetPlatform | platform
| ) |  |
| static

Definition at line 54 of file compiler_test.cc.

55 {
56 std::stringstream stream;
57 stream << fixture_name << "." << TargetPlatformSLExtension(platform);
58 return stream.str();
59 }

References impeller::compiler::TargetPlatformSLExtension().

Referenced by impeller::compiler::testing::CompilerTest::CanCompileAndReflect(), and impeller::compiler::testing::CompilerTest::GetShaderFile().

## ◆ SPIRVFileName()

static std::string impeller::compiler::testing::SPIRVFileName | ( | const char * | fixture_name | ) |
| static

Definition at line 48 of file compiler_test.cc.

48 {
49 std::stringstream stream;
50 stream << fixture_name << ".spv";
51 return stream.str();
52 }

Referenced by impeller::compiler::testing::CompilerTest::CanCompileAndReflect().

## ◆ TEST() [1/16]

impeller::compiler::testing::TEST | ( | CompilerTest | ,
|  | ShaderKindMatchingIsSuccessful |
| ) |  |

Definition at line 18 of file compiler_unittests.cc.

18 {
19 ASSERT_EQ(SourceTypeFromFileName("hello.vert"), SourceType::kVertexShader);
20 ASSERT_EQ(SourceTypeFromFileName("hello.frag"), SourceType::kFragmentShader);
21 ASSERT_EQ(SourceTypeFromFileName("hello.comp"), SourceType::kComputeShader);
22 ASSERT_EQ(SourceTypeFromFileName("hello.msl"), SourceType::kUnknown);
23 ASSERT_EQ(SourceTypeFromFileName("hello.glsl"), SourceType::kUnknown);
24 }

References impeller::compiler::kComputeShader, impeller::compiler::kFragmentShader, impeller::compiler::kUnknown, impeller::compiler::kVertexShader, and impeller::compiler::SourceTypeFromFileName().

## ◆ TEST() [2/16]

impeller::compiler::testing::TEST | ( | ShaderBundleTest | ,
|  | GenerateShaderBundleFlatbufferProducesCorrectResult |
| ) |  |

Verify vertex shader.

Verify fragment shader.

Definition at line 131 of file shader_bundle_unittests.cc.

131 {
132 std::string fixtures_path = flutter::testing::GetFixturesPath();
133 std::string config =
134 "{\"UnlitFragment\": {\"type\": \"fragment\", \"file\": \"" +
135 fixtures_path +
136 "/flutter_gpu_unlit.frag\"}, \"UnlitVertex\": {\"type\": "
137 "\"vertex\", \"file\": \"" +
138 fixtures_path + "/flutter_gpu_unlit.vert\"}}";
139
140 SourceOptions options;
141 options.target_platform = TargetPlatform::kRuntimeStageMetal;
142 options.source_language = SourceLanguage::kGLSL;
143
144 std::optional<fb::ShaderBundleT> bundle =
145 GenerateShaderBundleFlatbuffer(config, options);
146 ASSERT_TRUE(bundle.has_value());
147
148 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
149 const auto& shaders = bundle->shaders;
150 const auto* vertex = FindByName(shaders, "UnlitVertex");
151 const auto* fragment = FindByName(shaders, "UnlitFragment");
152 ASSERT_NE(vertex, nullptr);
153 ASSERT_NE(fragment, nullptr);
154
155 // --------------------------------------------------------------------------
156 /// Verify vertex shader.
157 ///
158
159 EXPECT_TRUE(vertex->shader->metal);
160 EXPECT_STREQ(vertex->shader->metal->entrypoint.c_str(),
161 "flutter_gpu_unlit_vertex_main");
162 EXPECT_EQ(vertex->shader->metal->stage, fb::Stage::kVertex);
163
164 // Inputs.
165 ASSERT_EQ(vertex->shader->metal->inputs.size(), 1u);
166 const auto& v_in_position = vertex->shader->metal->inputs[0];
167 EXPECT_STREQ(v_in_position->name.c_str(), "position");
168 EXPECT_EQ(v_in_position->location, 0u);
169 EXPECT_EQ(v_in_position->set, 0u);
170 EXPECT_EQ(v_in_position->binding, 0u);
171 EXPECT_EQ(v_in_position->type, fb::InputDataType::kFloat);
172 EXPECT_EQ(v_in_position->bit_width, 32u);
173 EXPECT_EQ(v_in_position->vec_size, 2u);
174 EXPECT_EQ(v_in_position->columns, 1u);
175 EXPECT_EQ(v_in_position->offset, 0u);
176
177 // Uniforms.
178 ASSERT_EQ(vertex->shader->metal->uniforms.size(), 2u);
179 const auto* v_mvp = FindByName(vertex->shader->metal->uniforms, "mvp");
180 ASSERT_NE(v_mvp, nullptr);
181 EXPECT_EQ(v_mvp->location, 0u);
182 EXPECT_EQ(v_mvp->type, fb::UniformDataType::kFloat);
183 EXPECT_EQ(v_mvp->bit_width, 32u);
184 EXPECT_EQ(v_mvp->rows, 4u);
185 EXPECT_EQ(v_mvp->columns, 4u);
186 EXPECT_EQ(v_mvp->array_elements, 0u);
187 const auto* v_color = FindByName(vertex->shader->metal->uniforms, "color");
188 ASSERT_NE(v_color, nullptr);
189 EXPECT_EQ(v_color->location, 1u);
190 EXPECT_EQ(v_color->type, fb::UniformDataType::kFloat);
191 EXPECT_EQ(v_color->bit_width, 32u);
192 EXPECT_EQ(v_color->rows, 4u);
193 EXPECT_EQ(v_color->columns, 1u);
194 EXPECT_EQ(v_color->array_elements, 0u);
195
196 // --------------------------------------------------------------------------
197 /// Verify fragment shader.
198 ///
199
200 EXPECT_TRUE(fragment->shader->metal);
201 EXPECT_STREQ(fragment->shader->metal->entrypoint.c_str(),
202 "flutter_gpu_unlit_fragment_main");
203 EXPECT_EQ(fragment->shader->metal->stage, fb::Stage::kFragment);
204
205 // Inputs (not recorded for fragment shaders).
206 ASSERT_EQ(fragment->shader->metal->inputs.size(), 0u);
207
208 // Uniforms.
209 ASSERT_EQ(fragment->shader->metal->inputs.size(), 0u);
210 }

References FindByName(), impeller::compiler::GenerateShaderBundleFlatbuffer(), impeller::kFloat, impeller::compiler::kGLSL, impeller::compiler::kRuntimeStageMetal, impeller::compiler::SourceOptions::source_language, and impeller::compiler::SourceOptions::target_platform.

## ◆ TEST() [3/16]

impeller::compiler::testing::TEST | ( | ShaderBundleTest | ,
|  | ParseShaderBundleConfigFailsForInvalidJSON |
| ) |  |

Definition at line 25 of file shader_bundle_unittests.cc.

25 {
26 std::string bundle = "";
27 std::stringstream error;
28 auto result = ParseShaderBundleConfig(bundle, error);
29 ASSERT_FALSE(result.has_value());
30 ASSERT_STREQ(error.str().c_str(),
31 "The shader bundle is not a valid JSON object.\n");
32 }

References impeller::compiler::ParseShaderBundleConfig().

## ◆ TEST() [4/16]

impeller::compiler::testing::TEST | ( | ShaderBundleTest | ,
|  | ParseShaderBundleConfigFailsForInvalidLanguage |
| ) |  |

Definition at line 77 of file shader_bundle_unittests.cc.

77 {
78 std::string bundle =
79 "{\"UnlitVertex\": {\"type\": \"vertex\", \"language\": \"invalid\", "
80 "\"file\": \"shaders/flutter_gpu_unlit.vert\"}}";
81 std::stringstream error;
82 auto result = ParseShaderBundleConfig(bundle, error);
83 ASSERT_FALSE(result.has_value());
84 ASSERT_STREQ(error.str().c_str(),
85 "Invalid shader entry \"UnlitVertex\": Unknown language type "
86 "\"invalid\".\n");
87 }

References impeller::compiler::ParseShaderBundleConfig().

## ◆ TEST() [5/16]

impeller::compiler::testing::TEST | ( | ShaderBundleTest | ,
|  | ParseShaderBundleConfigFailsForInvalidType |
| ) |  |

Definition at line 65 of file shader_bundle_unittests.cc.

65 {
66 std::string bundle =
67 "{\"UnlitVertex\": {\"type\": \"invalid\", \"file\": "
68 "\"shaders/flutter_gpu_unlit.vert\"}}";
69 std::stringstream error;
70 auto result = ParseShaderBundleConfig(bundle, error);
71 ASSERT_FALSE(result.has_value());
72 ASSERT_STREQ(error.str().c_str(),
73 "Invalid shader entry \"UnlitVertex\": Shader type "
74 "\"invalid\" is unknown.\n");
75 }

References impeller::compiler::ParseShaderBundleConfig().

## ◆ TEST() [6/16]

impeller::compiler::testing::TEST | ( | ShaderBundleTest | ,
|  | ParseShaderBundleConfigFailsWhenEntryNotObject |
| ) |  |

Definition at line 34 of file shader_bundle_unittests.cc.

34 {
35 std::string bundle = "{\"UnlitVertex\": []}";
36 std::stringstream error;
37 auto result = ParseShaderBundleConfig(bundle, error);
38 ASSERT_FALSE(result.has_value());
39 ASSERT_STREQ(
40 error.str().c_str(),
41 "Invalid shader entry \"UnlitVertex\": Entry is not a JSON object.\n");
42 }

References impeller::compiler::ParseShaderBundleConfig().

## ◆ TEST() [7/16]

impeller::compiler::testing::TEST | ( | ShaderBundleTest | ,
|  | ParseShaderBundleConfigFailsWhenMissingFile |
| ) |  |

Definition at line 44 of file shader_bundle_unittests.cc.

44 {
45 std::string bundle = "{\"UnlitVertex\": {\"type\": \"vertex\"}}";
46 std::stringstream error;
47 auto result = ParseShaderBundleConfig(bundle, error);
48 ASSERT_FALSE(result.has_value());
49 ASSERT_STREQ(error.str().c_str(),
50 "Invalid shader entry \"UnlitVertex\": Missing required "
51 "\"file\" field.\n");
52 }

References impeller::compiler::ParseShaderBundleConfig().

## ◆ TEST() [8/16]

impeller::compiler::testing::TEST | ( | ShaderBundleTest | ,
|  | ParseShaderBundleConfigFailsWhenMissingType |
| ) |  |

Definition at line 54 of file shader_bundle_unittests.cc.

54 {
55 std::string bundle =
56 "{\"UnlitVertex\": {\"file\": \"shaders/flutter_gpu_unlit.vert\"}}";
57 std::stringstream error;
58 auto result = ParseShaderBundleConfig(bundle, error);
59 ASSERT_FALSE(result.has_value());
60 ASSERT_STREQ(error.str().c_str(),
61 "Invalid shader entry \"UnlitVertex\": Missing required "
62 "\"type\" field.\n");
63 }

References impeller::compiler::ParseShaderBundleConfig().

## ◆ TEST() [9/16]

impeller::compiler::testing::TEST | ( | ShaderBundleTest | ,
|  | ParseShaderBundleConfigReturnsExpectedConfig |
| ) |  |

Definition at line 89 of file shader_bundle_unittests.cc.

89 {
90 std::string bundle =
91 "{" + kUnlitVertexBundleConfig + ", " + kUnlitFragmentBundleConfig + "}";
92 std::stringstream error;
93 auto result = ParseShaderBundleConfig(bundle, error);
94 ASSERT_TRUE(result.has_value());
95 ASSERT_STREQ(error.str().c_str(), "");
96
97 // NOLINTBEGIN(bugprone-unchecked-optional-access)
98 auto maybe_vertex = result->find("UnlitVertex");
99 auto maybe_fragment = result->find("UnlitFragment");
100 ASSERT_TRUE(maybe_vertex != result->end());
101 ASSERT_TRUE(maybe_fragment != result->end());
102 auto vertex = maybe_vertex->second;
103 auto fragment = maybe_fragment->second;
104 // NOLINTEND(bugprone-unchecked-optional-access)
105
106 EXPECT_EQ(vertex.type, SourceType::kVertexShader);
107 EXPECT_EQ(vertex.language, SourceLanguage::kGLSL);
108 EXPECT_STREQ(vertex.entry_point.c_str(), "main");
109 EXPECT_STREQ(vertex.source_file_name.c_str(),
110 "shaders/flutter_gpu_unlit.vert");
111
112 EXPECT_EQ(fragment.type, SourceType::kFragmentShader);
113 EXPECT_EQ(fragment.language, SourceLanguage::kGLSL);
114 EXPECT_STREQ(fragment.entry_point.c_str(), "main");
115 EXPECT_STREQ(fragment.source_file_name.c_str(),
116 "shaders/flutter_gpu_unlit.frag");
117 }

References impeller::compiler::kFragmentShader, impeller::compiler::kGLSL, kUnlitFragmentBundleConfig, kUnlitVertexBundleConfig, impeller::compiler::kVertexShader, and impeller::compiler::ParseShaderBundleConfig().

## ◆ TEST() [10/16]

impeller::compiler::testing::TEST | ( | SwitchesTEst | ,
|  | ConvertToEntrypointName |
| ) |  |

Definition at line 72 of file switches_unittests.cc.

72 {
73 ASSERT_EQ(ConvertToEntrypointName("mandelbrot_unrolled"),
74 "mandelbrot_unrolled");
75 ASSERT_EQ(ConvertToEntrypointName("mandelbrot-unrolled"),
76 "mandelbrotunrolled");
77 ASSERT_EQ(ConvertToEntrypointName("7_"), "i_7_");
78 ASSERT_EQ(ConvertToEntrypointName("415"), "i_415");
79 ASSERT_EQ(ConvertToEntrypointName("#$%"), "i_");
80 ASSERT_EQ(ConvertToEntrypointName(""), "");
81 }

References impeller::compiler::ConvertToEntrypointName().

## ◆ TEST() [11/16]

impeller::compiler::testing::TEST | ( | SwitchesTest | ,
|  | DefaultEntryPointIsMain |
| ) |  |

Definition at line 60 of file switches_unittests.cc.

60 {
61 Switches switches = MakeSwitchesDesktopGL({});
62 ASSERT_TRUE(switches.AreValid(std::cout));
63 ASSERT_EQ(switches.entry_point, "main");
64 }

References impeller::compiler::Switches::AreValid(), impeller::compiler::Switches::entry_point, and MakeSwitchesDesktopGL().

## ◆ TEST() [12/16]

impeller::compiler::testing::TEST | ( | SwitchesTest | ,
|  | DoesntMangleUnicodeIncludes |
| ) |  |

Definition at line 31 of file switches_unittests.cc.

31 {
32 const char* directory_name = "test_shader_include_Ã�";
33 fml::CreateDirectory(flutter::testing::OpenFixturesDirectory(),
34 {directory_name}, fml::FilePermission::kRead);
35
36 auto include_path =
37 std::string(flutter::testing::GetFixturesPath()) + "/" + directory_name;
38 auto include_option = "--include=" + include_path;
39
40 Switches switches = MakeSwitchesDesktopGL({include_option.c_str()});
41
42 ASSERT_TRUE(switches.AreValid(std::cout));
43 ASSERT_EQ(switches.include_directories.size(), 1u);
44 ASSERT_NE(switches.include_directories[0].dir, nullptr);
45 ASSERT_EQ(switches.include_directories[0].name, include_path);
46 }

References impeller::compiler::Switches::AreValid(), impeller::compiler::Switches::include_directories, and MakeSwitchesDesktopGL().

## ◆ TEST() [13/16]

impeller::compiler::testing::TEST | ( | SwitchesTest | ,
|  | EntryPointCanBeSetForHLSL |
| ) |  |

Definition at line 66 of file switches_unittests.cc.

66 {
67 Switches switches = MakeSwitchesDesktopGL({"--entry-point=CustomEntryPoint"});
68 ASSERT_TRUE(switches.AreValid(std::cout));
69 ASSERT_EQ(switches.entry_point, "CustomEntryPoint");
70 }

References impeller::compiler::Switches::AreValid(), impeller::compiler::Switches::entry_point, and MakeSwitchesDesktopGL().

## ◆ TEST() [14/16]

impeller::compiler::testing::TEST | ( | SwitchesTest | ,
|  | ShaderBundleModeValid |
| ) |  |

Definition at line 83 of file switches_unittests.cc.

83 {
84 // Shader bundles process multiple shaders, and so the single-file input/spirv
85 // flags are not required.
86 std::vector<const char*> options = {
87 "--shader-bundle={}", "--sl=test.shaderbundle", "--runtime-stage-metal"};
88
89 auto cl = fml::CommandLineFromIteratorsWithArgv0("impellerc", options.begin(),
90 options.end());
91 Switches switches(cl);
92 ASSERT_TRUE(switches.AreValid(std::cout));
93 ASSERT_EQ(switches.shader_bundle, "{}");
94 }

References impeller::compiler::Switches::AreValid(), and impeller::compiler::Switches::shader_bundle.

## ◆ TEST() [15/16]

impeller::compiler::testing::TEST | ( | SwitchesTest | ,
|  | SourceLanguageCanBeSetToHLSL |
| ) |  |

Definition at line 54 of file switches_unittests.cc.

54 {
55 Switches switches = MakeSwitchesDesktopGL({"--source-language=hLsL"});
56 ASSERT_TRUE(switches.AreValid(std::cout));
57 ASSERT_EQ(switches.source_language, SourceLanguage::kHLSL);
58 }

References impeller::compiler::Switches::AreValid(), impeller::compiler::kHLSL, MakeSwitchesDesktopGL(), and impeller::compiler::Switches::source_language.

## ◆ TEST() [16/16]

impeller::compiler::testing::TEST | ( | SwitchesTest | ,
|  | SourceLanguageDefaultsToGLSL |
| ) |  |

Definition at line 48 of file switches_unittests.cc.

48 {
49 Switches switches = MakeSwitchesDesktopGL();
50 ASSERT_TRUE(switches.AreValid(std::cout));
51 ASSERT_EQ(switches.source_language, SourceLanguage::kGLSL);
52 }

References impeller::compiler::Switches::AreValid(), impeller::compiler::kGLSL, MakeSwitchesDesktopGL(), and impeller::compiler::Switches::source_language.

## ◆ TEST_P() [1/9]

impeller::compiler::testing::TEST_P | ( | CompilerTest | ,
|  | BindingBaseForFragShader |
| ) |  |

Definition at line 81 of file compiler_unittests.cc.

81 {
82 if (!TargetPlatformIsVulkan(GetParam())) {
83 GTEST_SKIP();
84 }
85
86 ASSERT_TRUE(CanCompileAndReflect("sample.vert", SourceType::kVertexShader));
87 ASSERT_TRUE(CanCompileAndReflect("sample.frag", SourceType::kFragmentShader));
88
89 auto get_binding = [&](const char* fixture) -> uint32_t {
90 auto json_fd = GetReflectionJson(fixture);
91 nlohmann::json shader_json = nlohmann::json::parse(json_fd->GetMapping());
92 return shader_json["buffers"][0]["binding"].get<uint32_t>();
93 };
94
95 auto vert_uniform_binding = get_binding("sample.vert");
96 auto frag_uniform_binding = get_binding("sample.frag");
97
98 ASSERT_GT(frag_uniform_binding, vert_uniform_binding);
99 }

References impeller::compiler::kFragmentShader, impeller::compiler::kVertexShader, and impeller::compiler::TargetPlatformIsVulkan().

## ◆ TEST_P() [2/9]

impeller::compiler::testing::TEST_P | ( | CompilerTest | ,
|  | CanCompile |
| ) |  |

Definition at line 26 of file compiler_unittests.cc.

26 {
27 if (GetParam() == TargetPlatform::kSkSL) {
28 GTEST_SKIP() << "Not supported with SkSL";
29 }
30 ASSERT_TRUE(CanCompileAndReflect("sample.vert"));
31 ASSERT_TRUE(CanCompileAndReflect("sample.vert", SourceType::kVertexShader));
32 ASSERT_TRUE(CanCompileAndReflect("sample.vert", SourceType::kVertexShader,
33 SourceLanguage::kGLSL));
34 }

References impeller::compiler::kGLSL, impeller::compiler::kSkSL, and impeller::compiler::kVertexShader.

## ◆ TEST_P() [3/9]

impeller::compiler::testing::TEST_P | ( | CompilerTest | ,
|  | CanCompileComputeShader |
| ) |  |

Definition at line 56 of file compiler_unittests.cc.

56 {
57 if (!TargetPlatformIsMetal(GetParam())) {
58 GTEST_SKIP_("Only enabled on Metal backends till ES 3.2 support is added.");
59 }
60 ASSERT_TRUE(CanCompileAndReflect("sample.comp"));
61 ASSERT_TRUE(CanCompileAndReflect("sample.comp", SourceType::kComputeShader));
62 }

References impeller::compiler::kComputeShader, and impeller::compiler::TargetPlatformIsMetal().

## ◆ TEST_P() [4/9]

impeller::compiler::testing::TEST_P | ( | CompilerTest | ,
|  | CanCompileHLSL |
| ) |  |

Definition at line 36 of file compiler_unittests.cc.

36 {
37 if (GetParam() == TargetPlatform::kSkSL) {
38 GTEST_SKIP() << "Not supported with SkSL";
39 }
40 ASSERT_TRUE(CanCompileAndReflect(
41 "simple.vert.hlsl", SourceType::kVertexShader, SourceLanguage::kHLSL));
42 }

References impeller::compiler::kHLSL, impeller::compiler::kSkSL, and impeller::compiler::kVertexShader.

## ◆ TEST_P() [5/9]

impeller::compiler::testing::TEST_P | ( | CompilerTest | ,
|  | CanCompileHLSLWithMultipleStages |
| ) |  |

Definition at line 44 of file compiler_unittests.cc.

44 {
45 if (GetParam() == TargetPlatform::kSkSL) {
46 GTEST_SKIP() << "Not supported with SkSL";
47 }
48 ASSERT_TRUE(CanCompileAndReflect("multiple_stages.hlsl",
49 SourceType::kVertexShader,
50 SourceLanguage::kHLSL, "VertexShader"));
51 ASSERT_TRUE(CanCompileAndReflect("multiple_stages.hlsl",
52 SourceType::kFragmentShader,
53 SourceLanguage::kHLSL, "FragmentShader"));
54 }

References impeller::compiler::kFragmentShader, impeller::compiler::kHLSL, impeller::compiler::kSkSL, and impeller::compiler::kVertexShader.

## ◆ TEST_P() [6/9]

impeller::compiler::testing::TEST_P | ( | CompilerTest | ,
|  | MustFailDueToExceedingResourcesLimit |
| ) |  |

Definition at line 64 of file compiler_unittests.cc.

64 {
65 if (GetParam() == TargetPlatform::kSkSL) {
66 GTEST_SKIP() << "Not supported with SkSL";
67 }
68 ScopedValidationDisable disable_validation;
69 ASSERT_FALSE(
70 CanCompileAndReflect("resources_limit.vert", SourceType::kVertexShader));
71 }

References impeller::compiler::kSkSL, and impeller::compiler::kVertexShader.

## ◆ TEST_P() [7/9]

impeller::compiler::testing::TEST_P | ( | CompilerTest | ,
|  | MustFailDueToMultipleLocationPerStructMember |
| ) |  |

Definition at line 73 of file compiler_unittests.cc.

73 {
74 if (GetParam() == TargetPlatform::kSkSL) {
75 GTEST_SKIP() << "Not supported with SkSL";
76 }
77 ScopedValidationDisable disable_validation;
78 ASSERT_FALSE(CanCompileAndReflect("struct_def_bug.vert"));
79 }

References impeller::compiler::kSkSL.

## ◆ TEST_P() [8/9]

impeller::compiler::testing::TEST_P | ( | CompilerTest | ,
|  | SkSLTextureLookUpOrderOfOperations |
| ) |  |

Definition at line 130 of file compiler_unittests.cc.

130 {
131 if (GetParam() != TargetPlatform::kSkSL) {
132 GTEST_SKIP() << "Only supported on SkSL";
133 }
134 ASSERT_TRUE(
135 CanCompileAndReflect("texture_lookup.frag", SourceType::kFragmentShader));
136
137 auto shader = GetShaderFile("texture_lookup.frag", GetParam());
138 auto string_mapping = reinterpret_cast<const char*>(shader->GetMapping());
139
140 EXPECT_TRUE(strcmp(string_mapping,
141 "textureA.eval(textureA_size * ( vec2(1.0) + "
142 "flutter_FragCoord.xy));") != -1);
143 }

References impeller::compiler::kFragmentShader, and impeller::compiler::kSkSL.

## ◆ TEST_P() [9/9]

impeller::compiler::testing::TEST_P | ( | CompilerTest | ,
|  | UniformsHaveBindingAndSet |
| ) |  |

Definition at line 101 of file compiler_unittests.cc.

101 {
102 if (GetParam() == TargetPlatform::kSkSL) {
103 GTEST_SKIP() << "Not supported with SkSL";
104 }
105 ASSERT_TRUE(CanCompileAndReflect("sample_with_binding.vert",
106 SourceType::kVertexShader));
107 ASSERT_TRUE(CanCompileAndReflect("sample.frag", SourceType::kFragmentShader));
108
109 struct binding_and_set {
110 uint32_t binding;
111 uint32_t set;
112 };
113
114 auto get_binding = [&](const char* fixture) -> binding_and_set {
115 auto json_fd = GetReflectionJson(fixture);
116 nlohmann::json shader_json = nlohmann::json::parse(json_fd->GetMapping());
117 uint32_t binding = shader_json["buffers"][0]["binding"].get<uint32_t>();
118 uint32_t set = shader_json["buffers"][0]["set"].get<uint32_t>();
119 return {binding, set};
120 };
121
122 auto vert_uniform_binding = get_binding("sample_with_binding.vert");
123 auto frag_uniform_binding = get_binding("sample.frag");
124
125 ASSERT_EQ(frag_uniform_binding.set, 0u);
126 ASSERT_EQ(vert_uniform_binding.set, 3u);
127 ASSERT_EQ(vert_uniform_binding.binding, 17u);
128 }

References impeller::compiler::kFragmentShader, impeller::compiler::kSkSL, and impeller::compiler::kVertexShader.

## Variable Documentation

## ◆ kUnlitFragmentBundleConfig

const std::string impeller::compiler::testing::kUnlitFragmentBundleConfig

Initial value:
=
"\"UnlitFragment\": {\"type\": \"fragment\", \"file\": "
"\"shaders/flutter_gpu_unlit.frag\"}"

Definition at line 18 of file shader_bundle_unittests.cc.

Referenced by TEST().

## ◆ kUnlitVertexBundleConfig

const std::string impeller::compiler::testing::kUnlitVertexBundleConfig

Initial value:
=
"\"UnlitVertex\": {\"type\": \"vertex\", \"file\": "
"\"shaders/flutter_gpu_unlit.vert\"}"

Definition at line 21 of file shader_bundle_unittests.cc.

Referenced by TEST().

impeller::kFloat
@ kFloat
Definition: runtime_types.h:32
impeller::compiler::ConvertToEntrypointName
std::string ConvertToEntrypointName(std::string_view string)
Ensure that the entrypoint name is a valid identifier in the target language.
Definition: utilities.cc:69
impeller::compiler::TargetPlatformSLExtension
std::string TargetPlatformSLExtension(TargetPlatform platform)
Definition: types.cc:246
impeller::compiler::testing::kUnlitVertexBundleConfig
const std::string kUnlitVertexBundleConfig
Definition: shader_bundle_unittests.cc:21
impeller::compiler::ParseShaderBundleConfig
std::optional< ShaderBundleConfig > ParseShaderBundleConfig(const std::string &bundle_config_json, std::ostream &error_stream)
Parse a shader bundle configuration from a given JSON string.
Definition: shader_bundle.cc:19
impeller::compiler::testing::FindByName
const T * FindByName(const std::vector< std::unique_ptr< T >> &collection, const std::string &name)
Definition: shader_bundle_unittests.cc:120
impeller::compiler::testing::kUnlitFragmentBundleConfig
const std::string kUnlitFragmentBundleConfig
Definition: shader_bundle_unittests.cc:18
impeller::compiler::TargetPlatformIsMetal
bool TargetPlatformIsMetal(TargetPlatform platform)
Definition: types.cc:284
impeller::compiler::TargetPlatformIsVulkan
bool TargetPlatformIsVulkan(TargetPlatform platform)
Definition: types.cc:302
impeller::compiler::SourceTypeFromFileName
SourceType SourceTypeFromFileName(const std::string &file_name)
Definition: types.cc:30
impeller::compiler::testing::MakeSwitchesDesktopGL
Switches MakeSwitchesDesktopGL(std::initializer_list< const char * > additional_options={})
Definition: switches_unittests.cc:18
impeller::compiler::GenerateShaderBundleFlatbuffer
std::optional< fb::ShaderBundleT > GenerateShaderBundleFlatbuffer(const std::string &bundle_config_json, const SourceOptions &options)
Parses the JSON shader bundle configuration and invokes the compiler multiple times to produce a shad...
Definition: shader_bundle.cc:144