Flutter Engine
The Flutter Engine
Classes | Functions | Variables
impeller::compiler::testing Namespace Reference

Classes

class  CompilerTest
 

Functions

static std::string GetIntermediatesPath ()
 
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)
 
 TEST_P (CompilerTest, CanCompileStructs)
 
 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 TFindByName (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

◆ 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 119 of file shader_bundle_unittests.cc.

120 {
121 const auto maybe = std::find_if(
122 collection.begin(), collection.end(),
123 [&name](const std::unique_ptr<T>& value) { return value->name == name; });
124 if (maybe == collection.end()) {
125 return nullptr;
126 }
127 return maybe->get();
128}
uint8_t value
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ GetIntermediatesPath()

static std::string impeller::compiler::testing::GetIntermediatesPath ( )
static

Definition at line 16 of file compiler_test.cc.

16 {
17 auto test_name = flutter::testing::GetCurrentTestName();
18 std::replace(test_name.begin(), test_name.end(), '/', '_');
19 std::replace(test_name.begin(), test_name.end(), '.', '_');
20 std::stringstream dir_name;
21 dir_name << test_name << "_" << std::to_string(fml::GetCurrentProcId());
23 {flutter::testing::GetFixturesPath(), dir_name.str()});
24}
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition: testing.cc:15
const char * GetFixturesPath()
Returns the directory containing the test fixture for the target if this target has fixtures configur...
std::string JoinPaths(std::initializer_list< std::string > components)
Definition: paths.cc:14
int GetCurrentProcId()
Definition: process_posix.cc:9
static SkString to_string(int n)
Definition: nanobench.cpp:119

◆ 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}
const char * options
CommandLine CommandLineFromIteratorsWithArgv0(const std::string &argv0, InputIterator first, InputIterator last)
Definition: command_line.h:214

◆ ReflectionCCName()

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

Definition at line 46 of file compiler_test.cc.

46 {
47 std::stringstream stream;
48 stream << fixture_name << ".cc";
49 return stream.str();
50}

◆ ReflectionHeaderName()

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

Definition at line 40 of file compiler_test.cc.

40 {
41 std::stringstream stream;
42 stream << fixture_name << ".h";
43 return stream.str();
44}

◆ ReflectionJSONName()

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

Definition at line 52 of file compiler_test.cc.

52 {
53 std::stringstream stream;
54 stream << fixture_name << ".json";
55 return stream.str();
56}

◆ SLFileName()

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

Definition at line 64 of file compiler_test.cc.

65 {
66 std::stringstream stream;
67 stream << fixture_name << "." << TargetPlatformSLExtension(platform);
68 return stream.str();
69}
std::string TargetPlatformSLExtension(TargetPlatform platform)
Definition: types.cc:246

◆ SPIRVFileName()

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

Definition at line 58 of file compiler_test.cc.

58 {
59 std::stringstream stream;
60 stream << fixture_name << ".spv";
61 return stream.str();
62}

◆ 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}
SourceType SourceTypeFromFileName(const std::string &file_name)
Definition: types.cc:30

◆ TEST() [2/16]

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

Verify vertex shader.

Verify fragment shader.

Definition at line 130 of file shader_bundle_unittests.cc.

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

◆ TEST() [3/16]

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

Definition at line 24 of file shader_bundle_unittests.cc.

24 {
25 std::string bundle = "";
26 std::stringstream error;
27 auto result = ParseShaderBundleConfig(bundle, error);
28 ASSERT_FALSE(result.has_value());
29 ASSERT_STREQ(error.str().c_str(),
30 "The shader bundle is not a valid JSON object.\n");
31}
const uint8_t uint32_t uint32_t GError ** error
GAsyncResult * result
std::optional< ShaderBundleConfig > ParseShaderBundleConfig(const std::string &bundle_config_json, std::ostream &error_stream)
Parse a shader bundle configuration from a given JSON string.

◆ TEST() [4/16]

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

Definition at line 76 of file shader_bundle_unittests.cc.

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

◆ TEST() [5/16]

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

Definition at line 64 of file shader_bundle_unittests.cc.

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

◆ TEST() [6/16]

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

Definition at line 33 of file shader_bundle_unittests.cc.

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

◆ TEST() [7/16]

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

Definition at line 43 of file shader_bundle_unittests.cc.

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

◆ TEST() [8/16]

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

Definition at line 53 of file shader_bundle_unittests.cc.

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

◆ TEST() [9/16]

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

Definition at line 88 of file shader_bundle_unittests.cc.

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

◆ 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}
std::string ConvertToEntrypointName(std::string_view string)
Ensure that the entrypoint name is a valid identifier in the target language.
Definition: utilities.cc:69

◆ 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}
bool AreValid(std::ostream &explain) const
Definition: switches.cc:239
Switches MakeSwitchesDesktopGL(std::initializer_list< const char * > additional_options={})

◆ 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_�";
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}
std::vector< IncludeDir > include_directories
Definition: switches.h:24
fml::UniqueFD OpenFixturesDirectory()
Opens the fixtures directory for the unit-test harness.
Definition: testing.cc:23
static fml::UniqueFD CreateDirectory(const fml::UniqueFD &base_directory, const std::vector< std::string > &components, FilePermission permission, size_t index)
Definition: file.cc:12

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

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

◆ 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}
SourceLanguage source_language
Definition: switches.h:40

◆ TEST() [16/16]

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

Definition at line 48 of file switches_unittests.cc.

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

◆ TEST_P() [1/10]

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}
bool TargetPlatformIsVulkan(TargetPlatform platform)
Definition: types.cc:302
def parse(repo_root, recipes_cfg_path)
Definition: recipes.py:56

◆ TEST_P() [2/10]

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}

◆ TEST_P() [3/10]

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}
bool TargetPlatformIsMetal(TargetPlatform platform)
Definition: types.cc:284

◆ TEST_P() [4/10]

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}

◆ TEST_P() [5/10]

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}

◆ TEST_P() [6/10]

impeller::compiler::testing::TEST_P ( CompilerTest  ,
CanCompileStructs   
)

Definition at line 147 of file compiler_unittests.cc.

147 {
148 if (GetParam() != TargetPlatform::kSkSL) {
149 GTEST_SKIP() << "Only supported on SkSL";
150 }
151 ASSERT_TRUE(CanCompileAndReflect("struct_internal.frag",
152 SourceType::kFragmentShader));
153}

◆ TEST_P() [7/10]

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}

◆ TEST_P() [8/10]

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}

◆ TEST_P() [9/10]

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 std::string_view shader_mapping(
139 reinterpret_cast<const char*>(shader->GetMapping()), shader->GetSize());
140
141 constexpr std::string_view expected =
142 "textureA.eval(textureA_size * ( vec2(1.0) + flutter_FragCoord.xy));";
143
144 EXPECT_NE(shader_mapping.find(expected), std::string::npos);
145}

◆ TEST_P() [10/10]

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}
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not set
Definition: switches.h:76

Variable Documentation

◆ kUnlitFragmentBundleConfig

const std::string impeller::compiler::testing::kUnlitFragmentBundleConfig
Initial value:
=
"\"UnlitFragment\": {\"type\": \"fragment\", \"file\": "
"\"shaders/flutter_gpu_unlit.frag\"}"

Definition at line 17 of file shader_bundle_unittests.cc.

◆ kUnlitVertexBundleConfig

const std::string impeller::compiler::testing::kUnlitVertexBundleConfig
Initial value:
=
"\"UnlitVertex\": {\"type\": \"vertex\", \"file\": "
"\"shaders/flutter_gpu_unlit.vert\"}"

Definition at line 20 of file shader_bundle_unittests.cc.