| Flutter Impeller |

Classes | Functions
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, CanCompileTessellationControlShader)
| TEST_P (CompilerTest, CanCompileTessellationEvaluationShader)
| TEST_P (CompilerTest, CanCompileComputeShader)
| TEST_P (CompilerTest, MustFailDueToExceedingResourcesLimit)
| TEST_P (CompilerTest, MustFailDueToMultipleLocationPerStructMember)
| TEST_P (CompilerTest, BindingBaseForFragShader)
| TEST_P (CompilerTest, UniformsHaveBindingAndSet)
| INSTANTIATE_TARGET_PLATFORM_TEST_SUITE_P (CompilerSuite)
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)

## 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 }

## ◆ 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().

## ◆ 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/7]

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

Definition at line 16 of file compiler_unittests.cc.

16 {
17 ASSERT_EQ(SourceTypeFromFileName("hello.vert"), SourceType::kVertexShader);
18 ASSERT_EQ(SourceTypeFromFileName("hello.frag"), SourceType::kFragmentShader);
19 ASSERT_EQ(SourceTypeFromFileName("hello.tesc"),
20 SourceType::kTessellationControlShader);
21 ASSERT_EQ(SourceTypeFromFileName("hello.tese"),
22 SourceType::kTessellationEvaluationShader);
23 ASSERT_EQ(SourceTypeFromFileName("hello.comp"), SourceType::kComputeShader);
24 ASSERT_EQ(SourceTypeFromFileName("hello.msl"), SourceType::kUnknown);
25 ASSERT_EQ(SourceTypeFromFileName("hello.glsl"), SourceType::kUnknown);
26 }

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

## ◆ TEST() [2/7]

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() [3/7]

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() [4/7]

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() [5/7]

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() [6/7]

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() [7/7]

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/10]

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

Definition at line 80 of file compiler_unittests.cc.

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

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

## ◆ TEST_P() [2/10]

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

Definition at line 28 of file compiler_unittests.cc.

28 {
29 ASSERT_TRUE(CanCompileAndReflect("sample.vert"));
30 ASSERT_TRUE(CanCompileAndReflect("sample.vert", SourceType::kVertexShader));
31 ASSERT_TRUE(CanCompileAndReflect("sample.vert", SourceType::kVertexShader,
32 SourceLanguage::kGLSL));
33 }

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

## ◆ TEST_P() [3/10]

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

Definition at line 61 of file compiler_unittests.cc.

61 {
62 if (!TargetPlatformIsMetal(GetParam())) {
63 GTEST_SKIP_("Only enabled on Metal backends till ES 3.2 support is added.");
64 }
65 ASSERT_TRUE(CanCompileAndReflect("sample.comp"));
66 ASSERT_TRUE(CanCompileAndReflect("sample.comp", SourceType::kComputeShader));
67 }

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

## ◆ TEST_P() [4/10]

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

Definition at line 35 of file compiler_unittests.cc.

35 {
36 ASSERT_TRUE(CanCompileAndReflect(
37 "simple.vert.hlsl", SourceType::kVertexShader, SourceLanguage::kHLSL));
38 }

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

## ◆ TEST_P() [5/10]

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

Definition at line 40 of file compiler_unittests.cc.

40 {
41 ASSERT_TRUE(CanCompileAndReflect("multiple_stages.hlsl",
42 SourceType::kVertexShader,
43 SourceLanguage::kHLSL, "VertexShader"));
44 ASSERT_TRUE(CanCompileAndReflect("multiple_stages.hlsl",
45 SourceType::kFragmentShader,
46 SourceLanguage::kHLSL, "FragmentShader"));
47 }

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

## ◆ TEST_P() [6/10]

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

Definition at line 49 of file compiler_unittests.cc.

49 {
50 ASSERT_TRUE(CanCompileAndReflect("sample.tesc"));
51 ASSERT_TRUE(CanCompileAndReflect("sample.tesc",
52 SourceType::kTessellationControlShader));
53 }

References impeller::compiler::kTessellationControlShader.

## ◆ TEST_P() [7/10]

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

Definition at line 55 of file compiler_unittests.cc.

55 {
56 ASSERT_TRUE(CanCompileAndReflect("sample.tese"));
57 ASSERT_TRUE(CanCompileAndReflect("sample.tese",
58 SourceType::kTessellationEvaluationShader));
59 }

References impeller::compiler::kTessellationEvaluationShader.

## ◆ TEST_P() [8/10]

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

Definition at line 69 of file compiler_unittests.cc.

69 {
70 ScopedValidationDisable disable_validation;
71 ASSERT_FALSE(
72 CanCompileAndReflect("resources_limit.vert", SourceType::kVertexShader));
73 }

References impeller::compiler::kVertexShader.

## ◆ TEST_P() [9/10]

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

Definition at line 75 of file compiler_unittests.cc.

75 {
76 ScopedValidationDisable disable_validation;
77 ASSERT_FALSE(CanCompileAndReflect("struct_def_bug.vert"));
78 }

## ◆ TEST_P() [10/10]

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

Definition at line 100 of file compiler_unittests.cc.

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

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

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:46
impeller::compiler::TargetPlatformSLExtension
std::string TargetPlatformSLExtension(TargetPlatform platform)
Definition: types.cc:243
impeller::compiler::TargetPlatformIsMetal
bool TargetPlatformIsMetal(TargetPlatform platform)
Definition: types.cc:281
impeller::compiler::TargetPlatformIsVulkan
bool TargetPlatformIsVulkan(TargetPlatform platform)
Definition: types.cc:299
impeller::compiler::SourceTypeFromFileName
SourceType SourceTypeFromFileName(const std::string &file_name)
Definition: types.cc:29
impeller::compiler::testing::MakeSwitchesDesktopGL
Switches MakeSwitchesDesktopGL(std::initializer_list< const char * > additional_options={})
Definition: switches_unittests.cc:18