Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
impeller::compiler::testing Namespace Reference

Classes

class  CompilerTest
 
class  CompilerTestBase
 
class  CompilerTestRuntime
 
class  CompilerTestSkSL
 
class  CompilerTestUnknownPlatform
 

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)
 
 INSTANTIATE_TEST_SUITE_P (CompilerSuite, CompilerTest, ::testing::Values(TargetPlatform::kOpenGLES, TargetPlatform::kOpenGLDesktop, TargetPlatform::kMetalDesktop, TargetPlatform::kMetalIOS, TargetPlatform::kVulkan), [](const ::testing::TestParamInfo< CompilerTest::ParamType > &info) { return TargetPlatformToString(info.param);})
 
 INSTANTIATE_TEST_SUITE_P (CompilerSuite, CompilerTestRuntime, ::testing::Values(TargetPlatform::kRuntimeStageMetal, TargetPlatform::kRuntimeStageGLES, TargetPlatform::kRuntimeStageGLES3, TargetPlatform::kRuntimeStageVulkan, TargetPlatform::kSkSL), [](const ::testing::TestParamInfo< CompilerTest::ParamType > &info) { return TargetPlatformToString(info.param);})
 
 INSTANTIATE_TEST_SUITE_P (CompilerSuite, CompilerTestSkSL, ::testing::Values(TargetPlatform::kSkSL), [](const ::testing::TestParamInfo< CompilerTest::ParamType > &info) { return TargetPlatformToString(info.param);})
 
 INSTANTIATE_TEST_SUITE_P (CompilerSuite, CompilerTestUnknownPlatform, ::testing::Values(TargetPlatform::kUnknown), [](const ::testing::TestParamInfo< CompilerTest::ParamType > &info) { return TargetPlatformToString(info.param);})
 
 TEST (CompilerTest, Defines)
 
 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, UniformBlockInstanceNameCanonicalizedForGL)
 
 TEST_P (CompilerTest, BindingBaseForFragShader)
 
 TEST_P (CompilerTestRuntime, UniformsAppearInJson)
 
 TEST_P (CompilerTestRuntime, PositionedUniformsAppearInJson)
 
 TEST_P (CompilerTest, UniformsHaveBindingAndSet)
 
 TEST_P (CompilerTestSkSL, SkSLTextureLookUpOrderOfOperations)
 
 TEST_P (CompilerTestSkSL, CanCompileStructs)
 
 TEST_P (CompilerTestSkSL, FailsToCompileDueToArrayInitializerWithConstants)
 
 TEST_P (CompilerTestSkSL, FailsToCompileDueToArrayInitializerWithVariables)
 
 TEST_P (CompilerTestSkSL, FailsToCompileDueToArrayAssignment)
 
 TEST_P (CompilerTestSkSL, CompilesWithValidArrayInitialization)
 
 TEST_P (CompilerTestRuntime, Mat2Reflection)
 
 TEST_P (CompilerTestUnknownPlatform, MustFailDueToUnknownPlatform)
 
 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)
 
 TEST (ShaderBundleTest, GenerateShaderBundleFlatbufferReportsSourceFilesAsDependencies)
 
 TEST (ShaderBundleTest, GenerateShaderBundleFlatbufferIgnoresNullDependencyCollector)
 
 TEST (ShaderBundleTest, DeriveShaderFloatTypeFromDimensions)
 
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)
 
 TEST (SwitchesTest, EntryPointPrefixIsApplied)
 
 TEST (SwitchesTest, CommandLinePathUtf8)
 

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 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}
const char * name
Definition fuchsia.cc:50

References name, and value.

Referenced by TEST().

◆ GetIntermediatesPath()

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

Definition at line 17 of file compiler_test.cc.

17 {
18 auto test_name = flutter::testing::GetCurrentTestName();
19 std::replace(test_name.begin(), test_name.end(), '/', '_');
20 std::replace(test_name.begin(), test_name.end(), '.', '_');
21 std::stringstream dir_name;
22 dir_name << test_name << "_" << std::to_string(fml::GetCurrentProcId());
24 {flutter::testing::GetFixturesPath(), dir_name.str()});
25}
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:14
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()

References fml::GetCurrentProcId(), flutter::testing::GetCurrentTestName(), flutter::testing::GetFixturesPath(), and fml::paths::JoinPaths().

◆ INSTANTIATE_TEST_SUITE_P() [1/4]

impeller::compiler::testing::INSTANTIATE_TEST_SUITE_P ( CompilerSuite  ,
CompilerTest  ,
::testing::Values(TargetPlatform::kOpenGLES, TargetPlatform::kOpenGLDesktop, TargetPlatform::kMetalDesktop, TargetPlatform::kMetalIOS, TargetPlatform::kVulkan ,
[] (const ::testing::TestParamInfo< CompilerTest::ParamType > &info) { return TargetPlatformToString(info.param);}   
)

◆ INSTANTIATE_TEST_SUITE_P() [2/4]

impeller::compiler::testing::INSTANTIATE_TEST_SUITE_P ( CompilerSuite  ,
CompilerTestRuntime  ,
::testing::Values(TargetPlatform::kRuntimeStageMetal, TargetPlatform::kRuntimeStageGLES, TargetPlatform::kRuntimeStageGLES3, TargetPlatform::kRuntimeStageVulkan, TargetPlatform::kSkSL ,
[] (const ::testing::TestParamInfo< CompilerTest::ParamType > &info) { return TargetPlatformToString(info.param);}   
)

◆ INSTANTIATE_TEST_SUITE_P() [3/4]

impeller::compiler::testing::INSTANTIATE_TEST_SUITE_P ( CompilerSuite  ,
CompilerTestSkSL  ,
::testing::Values(TargetPlatform::kSkSL ,
[] (const ::testing::TestParamInfo< CompilerTest::ParamType > &info) { return TargetPlatformToString(info.param);}   
)

◆ INSTANTIATE_TEST_SUITE_P() [4/4]

impeller::compiler::testing::INSTANTIATE_TEST_SUITE_P ( CompilerSuite  ,
CompilerTestUnknownPlatform  ,
::testing::Values(TargetPlatform::kUnknown ,
[] (const ::testing::TestParamInfo< CompilerTest::ParamType > &info) { return TargetPlatformToString(info.param);}   
)

◆ MakeSwitchesDesktopGL()

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

Definition at line 20 of file switches_unittests.cc.

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

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ ReflectionCCName()

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

Definition at line 48 of file compiler_test.cc.

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

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

◆ ReflectionHeaderName()

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

Definition at line 42 of file compiler_test.cc.

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

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

◆ ReflectionJSONName()

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

Definition at line 54 of file compiler_test.cc.

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

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

◆ SLFileName()

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

Definition at line 66 of file compiler_test.cc.

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

References impeller::compiler::TargetPlatformSLExtension().

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

◆ SPIRVFileName()

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

Definition at line 60 of file compiler_test.cc.

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

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

◆ TEST() [1/22]

impeller::compiler::testing::TEST ( CompilerTest  ,
Defines   
)

Definition at line 58 of file compiler_unittests.cc.

58 {
59 std::shared_ptr<const fml::Mapping> fixture =
60 flutter::testing::OpenFixtureAsMapping("check_gles_definition.frag");
61
62 SourceOptions options;
63 options.source_language = SourceLanguage::kGLSL;
64 options.target_platform = TargetPlatform::kRuntimeStageGLES;
65 options.entry_point_name = "main";
66 options.type = SourceType::kFragmentShader;
67
68 Reflector::Options reflector_options;
69 reflector_options.target_platform = TargetPlatform::kRuntimeStageGLES;
70 Compiler compiler = Compiler(fixture, options, reflector_options);
71
72 // Should fail as the shader has a compilation error in it.
73 EXPECT_EQ(compiler.GetSPIRVAssembly(), nullptr);
74
75 // Should succeed as the compilation error is ifdef'd out.
76 options.target_platform = TargetPlatform::kRuntimeStageVulkan;
77 reflector_options.target_platform = TargetPlatform::kRuntimeStageVulkan;
78 Compiler compiler_2 = Compiler(fixture, options, reflector_options);
79 EXPECT_NE(compiler_2.GetSPIRVAssembly(), nullptr);
80}
std::shared_ptr< fml::Mapping > GetSPIRVAssembly() const
Definition compiler.cc:598
std::unique_ptr< fml::Mapping > OpenFixtureAsMapping(const std::string &fixture_name)
Opens a fixture of the given file name and returns a mapping to its contents.
Definition testing.cc:58

References impeller::compiler::SourceOptions::entry_point_name, impeller::compiler::Compiler::GetSPIRVAssembly(), impeller::compiler::kFragmentShader, impeller::compiler::kGLSL, impeller::compiler::kRuntimeStageGLES, impeller::compiler::kRuntimeStageVulkan, flutter::testing::OpenFixtureAsMapping(), impeller::compiler::SourceOptions::source_language, impeller::compiler::Reflector::Options::target_platform, impeller::compiler::SourceOptions::target_platform, and impeller::compiler::SourceOptions::type.

◆ TEST() [2/22]

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

Definition at line 82 of file compiler_unittests.cc.

82 {
83 ASSERT_EQ(SourceTypeFromFileName("hello.vert"), SourceType::kVertexShader);
84 ASSERT_EQ(SourceTypeFromFileName("hello.frag"), SourceType::kFragmentShader);
85 ASSERT_EQ(SourceTypeFromFileName("hello.comp"), SourceType::kComputeShader);
86 ASSERT_EQ(SourceTypeFromFileName("hello.msl"), SourceType::kUnknown);
87 ASSERT_EQ(SourceTypeFromFileName("hello.glsl"), SourceType::kUnknown);
88}
SourceType SourceTypeFromFileName(const std::filesystem::path &file_name)
Definition types.cc:17

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

◆ TEST() [3/22]

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

Definition at line 273 of file shader_bundle_unittests.cc.

273 {
274 // Non-float types always map to nullopt.
275 EXPECT_EQ(DeriveShaderFloatType(ShaderType::kSignedInt, 1, 1), std::nullopt);
276 EXPECT_EQ(DeriveShaderFloatType(ShaderType::kUnsignedInt, 4, 1),
277 std::nullopt);
278 EXPECT_EQ(DeriveShaderFloatType(ShaderType::kBoolean, 1, 1), std::nullopt);
279
280 // Scalar and vector floats (columns == 1).
281 EXPECT_EQ(DeriveShaderFloatType(ShaderType::kFloat, 1, 1),
282 ShaderFloatType::kFloat);
283 EXPECT_EQ(DeriveShaderFloatType(ShaderType::kFloat, 2, 1),
284 ShaderFloatType::kVec2);
285 EXPECT_EQ(DeriveShaderFloatType(ShaderType::kFloat, 3, 1),
286 ShaderFloatType::kVec3);
287 EXPECT_EQ(DeriveShaderFloatType(ShaderType::kFloat, 4, 1),
288 ShaderFloatType::kVec4);
289
290 // Square matrices (vec_size == columns).
291 EXPECT_EQ(DeriveShaderFloatType(ShaderType::kFloat, 2, 2),
292 ShaderFloatType::kMat2);
293 EXPECT_EQ(DeriveShaderFloatType(ShaderType::kFloat, 3, 3),
294 ShaderFloatType::kMat3);
295 EXPECT_EQ(DeriveShaderFloatType(ShaderType::kFloat, 4, 4),
296 ShaderFloatType::kMat4);
297
298 // Non-square matrices and unsupported shapes return nullopt.
299 EXPECT_EQ(DeriveShaderFloatType(ShaderType::kFloat, 3, 2), std::nullopt);
300 EXPECT_EQ(DeriveShaderFloatType(ShaderType::kFloat, 2, 3), std::nullopt);
301 EXPECT_EQ(DeriveShaderFloatType(ShaderType::kFloat, 5, 1), std::nullopt);
302
303 // Zero values (legacy bundle defaults) map to nullopt.
304 EXPECT_EQ(DeriveShaderFloatType(ShaderType::kFloat, 0, 0), std::nullopt);
305 EXPECT_EQ(DeriveShaderFloatType(ShaderType::kFloat, 0, 1), std::nullopt);
306 EXPECT_EQ(DeriveShaderFloatType(ShaderType::kFloat, 1, 0), std::nullopt);
307}
constexpr std::optional< ShaderFloatType > DeriveShaderFloatType(ShaderType type, size_t vec_size, size_t columns)
Derive the ShaderFloatType from the base ShaderType and the (vec_size, columns) dimensions reported b...

References impeller::DeriveShaderFloatType(), impeller::kBoolean, impeller::kFloat, impeller::kMat2, impeller::kMat3, impeller::kMat4, impeller::kSignedInt, impeller::kUnsignedInt, impeller::kVec2, impeller::kVec3, and impeller::kVec4.

◆ TEST() [4/22]

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

Definition at line 251 of file shader_bundle_unittests.cc.

252 {
253 // Passing nullptr as the dependency collector is supported and is
254 // the default behaviour for callers that don't need a depfile.
255 std::string fixtures_path = flutter::testing::GetFixturesPath();
256 std::string config =
257 "{\"UnlitFragment\": {\"type\": \"fragment\", \"file\": \"" +
258 fixtures_path +
259 "/flutter_gpu_unlit.frag\"}, \"UnlitVertex\": {\"type\": \"vertex\", "
260 "\"file\": \"" +
261 fixtures_path + "/flutter_gpu_unlit.vert\"}}";
262
263 SourceOptions options;
264 options.target_platform = TargetPlatform::kRuntimeStageMetal;
265 options.source_language = SourceLanguage::kGLSL;
266
267 std::optional<fb::shaderbundle::ShaderBundleT> bundle =
268 GenerateShaderBundleFlatbuffer(config, options, /*out_dependencies=*/
269 nullptr);
270 ASSERT_TRUE(bundle.has_value());
271}
std::optional< fb::shaderbundle::ShaderBundleT > GenerateShaderBundleFlatbuffer(const std::string &bundle_config_json, const SourceOptions &options, std::set< std::string > *out_dependencies)
Parses the JSON shader bundle configuration and invokes the compiler multiple times to produce a shad...

References impeller::compiler::GenerateShaderBundleFlatbuffer(), flutter::testing::GetFixturesPath(), impeller::compiler::kGLSL, impeller::compiler::kRuntimeStageMetal, impeller::compiler::SourceOptions::source_language, and impeller::compiler::SourceOptions::target_platform.

◆ TEST() [5/22]

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::shaderbundle::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
151 const auto* vertex = FindByName(shaders, "UnlitVertex");
152 const auto* fragment = FindByName(shaders, "UnlitFragment");
153 ASSERT_NE(vertex, nullptr);
154 ASSERT_NE(fragment, nullptr);
155
156 // --------------------------------------------------------------------------
157 /// Verify vertex shader.
158 ///
159
160 EXPECT_STREQ(vertex->metal_desktop->entrypoint.c_str(),
161 "flutter_gpu_unlit_vertex_main");
162 EXPECT_EQ(vertex->metal_desktop->stage,
163 fb::shaderbundle::ShaderStage::kVertex);
164
165 // Inputs.
166 ASSERT_EQ(vertex->metal_desktop->inputs.size(), 1u);
167 const auto& v_in_position = vertex->metal_desktop->inputs[0];
168 EXPECT_STREQ(v_in_position->name.c_str(), "position");
169 EXPECT_EQ(v_in_position->location, 0u);
170 EXPECT_EQ(v_in_position->set, 0u);
171 EXPECT_EQ(v_in_position->binding, 0u);
172 EXPECT_EQ(v_in_position->type, fb::shaderbundle::InputDataType::kFloat);
173 EXPECT_EQ(v_in_position->bit_width, 32u);
174 EXPECT_EQ(v_in_position->vec_size, 2u);
175 EXPECT_EQ(v_in_position->columns, 1u);
176 EXPECT_EQ(v_in_position->offset, 0u);
177
178 // Uniforms.
179 ASSERT_EQ(vertex->metal_desktop->uniform_structs.size(), 1u);
180 const auto* vert_info =
181 FindByName(vertex->metal_desktop->uniform_structs, "VertInfo");
182 ASSERT_NE(vert_info, nullptr);
183 EXPECT_EQ(vert_info->ext_res_0, 0u);
184 EXPECT_EQ(vert_info->set, 0u);
185 EXPECT_EQ(vert_info->binding, 0u);
186 ASSERT_EQ(vert_info->fields.size(), 2u);
187 const auto& mvp = vert_info->fields[0];
188 EXPECT_STREQ(mvp->name.c_str(), "mvp");
189 EXPECT_EQ(mvp->type, fb::shaderbundle::UniformDataType::kFloat);
190 EXPECT_EQ(mvp->offset_in_bytes, 0u);
191 EXPECT_EQ(mvp->element_size_in_bytes, 64u);
192 EXPECT_EQ(mvp->total_size_in_bytes, 64u);
193 EXPECT_EQ(mvp->array_elements, 0u);
194 EXPECT_EQ(mvp->vec_size, 4u);
195 EXPECT_EQ(mvp->columns, 4u);
196 const auto& color = vert_info->fields[1];
197 EXPECT_STREQ(color->name.c_str(), "color");
198 EXPECT_EQ(color->type, fb::shaderbundle::UniformDataType::kFloat);
199 EXPECT_EQ(color->offset_in_bytes, 64u);
200 EXPECT_EQ(color->element_size_in_bytes, 16u);
201 EXPECT_EQ(color->total_size_in_bytes, 16u);
202 EXPECT_EQ(color->array_elements, 0u);
203 EXPECT_EQ(color->vec_size, 4u);
204 EXPECT_EQ(color->columns, 1u);
205
206 // --------------------------------------------------------------------------
207 /// Verify fragment shader.
208 ///
209
210 EXPECT_STREQ(fragment->metal_desktop->entrypoint.c_str(),
211 "flutter_gpu_unlit_fragment_main");
212 EXPECT_EQ(fragment->metal_desktop->stage,
213 fb::shaderbundle::ShaderStage::kFragment);
214
215 // Inputs (not recorded for fragment shaders).
216 ASSERT_EQ(fragment->metal_desktop->inputs.size(), 0u);
217
218 // Uniforms.
219 ASSERT_EQ(fragment->metal_desktop->inputs.size(), 0u);
220}
const T * FindByName(const std::vector< std::unique_ptr< T > > &collection, const std::string &name)

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

◆ TEST() [6/22]

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

Definition at line 222 of file shader_bundle_unittests.cc.

223 {
224 std::string fixtures_path = flutter::testing::GetFixturesPath();
225 const std::string fragment_path = fixtures_path + "/flutter_gpu_unlit.frag";
226 const std::string vertex_path = fixtures_path + "/flutter_gpu_unlit.vert";
227 std::string config =
228 "{\"UnlitFragment\": {\"type\": \"fragment\", \"file\":\"" +
229 fragment_path +
230 "\"}, \"UnlitVertex\": {\"type\": \"vertex\", \"file\": \"" +
231 vertex_path + "\"}}";
232
233 SourceOptions options;
234 options.target_platform = TargetPlatform::kRuntimeStageMetal;
235 options.source_language = SourceLanguage::kGLSL;
236
237 std::set<std::string> dependencies;
238 std::optional<fb::shaderbundle::ShaderBundleT> bundle =
239 GenerateShaderBundleFlatbuffer(config, options, &dependencies);
240 ASSERT_TRUE(bundle.has_value());
241
242 // Every primary source file referenced by the bundle config should
243 // appear in the dependency set, deduplicated across the multiple
244 // target-platform compiles of each shader. The fixtures used here
245 // don't contain `#include` directives, so the dependency set
246 // contains exactly the two source files.
247 EXPECT_NE(dependencies.find(fragment_path), dependencies.end());
248 EXPECT_NE(dependencies.find(vertex_path), dependencies.end());
249}

References impeller::compiler::GenerateShaderBundleFlatbuffer(), flutter::testing::GetFixturesPath(), impeller::compiler::kGLSL, impeller::compiler::kRuntimeStageMetal, impeller::compiler::SourceOptions::source_language, and impeller::compiler::SourceOptions::target_platform.

◆ TEST() [7/22]

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}
const uint8_t uint32_t uint32_t GError ** error
std::optional< ShaderBundleConfig > ParseShaderBundleConfig(const std::string &bundle_config_json, std::ostream &error_stream)
Parse a shader bundle configuration from a given JSON string.

References error, and impeller::compiler::ParseShaderBundleConfig().

◆ TEST() [8/22]

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 error, and impeller::compiler::ParseShaderBundleConfig().

◆ TEST() [9/22]

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 error, and impeller::compiler::ParseShaderBundleConfig().

◆ TEST() [10/22]

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 error, and impeller::compiler::ParseShaderBundleConfig().

◆ TEST() [11/22]

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 error, and impeller::compiler::ParseShaderBundleConfig().

◆ TEST() [12/22]

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 error, and impeller::compiler::ParseShaderBundleConfig().

◆ TEST() [13/22]

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

Definition at line 89 of file shader_bundle_unittests.cc.

89 {
90 std::string bundle =
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 error, impeller::compiler::kFragmentShader, impeller::compiler::kGLSL, kUnlitFragmentBundleConfig, kUnlitVertexBundleConfig, impeller::compiler::kVertexShader, and impeller::compiler::ParseShaderBundleConfig().

◆ TEST() [14/22]

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

Definition at line 109 of file switches_unittests.cc.

109 {
110 std::u16string filename = u"test\u1234";
111 std::string input_flag = "--input=" + fml::Utf16ToUtf8(filename);
112 Switches switches = MakeSwitchesDesktopGL({input_flag.c_str()});
113 ASSERT_TRUE(switches.AreValid(std::cout));
114 ASSERT_EQ(switches.source_file_name, filename);
115}
bool AreValid(std::ostream &explain) const
Definition switches.cc:259
std::filesystem::path source_file_name
Definition switches.h:26
std::string Utf16ToUtf8(const std::u16string_view string)
Switches MakeSwitchesDesktopGL(std::initializer_list< const char * > additional_options={})

References impeller::compiler::Switches::AreValid(), MakeSwitchesDesktopGL(), impeller::compiler::Switches::source_file_name, and fml::Utf16ToUtf8().

◆ TEST() [15/22]

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

Definition at line 74 of file switches_unittests.cc.

74 {
75 ASSERT_EQ(ConvertToEntrypointName("mandelbrot_unrolled"),
76 "mandelbrot_unrolled");
77 ASSERT_EQ(ConvertToEntrypointName("mandelbrot-unrolled"),
78 "mandelbrotunrolled");
79 ASSERT_EQ(ConvertToEntrypointName("7_"), "i_7_");
80 ASSERT_EQ(ConvertToEntrypointName("415"), "i_415");
81 ASSERT_EQ(ConvertToEntrypointName("#$%"), "i_");
82 ASSERT_EQ(ConvertToEntrypointName(""), "");
83}
std::string ConvertToEntrypointName(std::string_view string)
Ensure that the entrypoint name is a valid identifier in the target language.
Definition utilities.cc:68

References impeller::compiler::ConvertToEntrypointName().

◆ TEST() [16/22]

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

Definition at line 62 of file switches_unittests.cc.

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

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

◆ TEST() [17/22]

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

Definition at line 33 of file switches_unittests.cc.

33 {
34 const char* directory_name = "test_shader_include_�";
36 {directory_name}, fml::FilePermission::kRead);
37
38 auto include_path =
39 std::string(flutter::testing::GetFixturesPath()) + "/" + directory_name;
40 auto include_option = "--include=" + include_path;
41
42 Switches switches = MakeSwitchesDesktopGL({include_option.c_str()});
43
44 ASSERT_TRUE(switches.AreValid(std::cout));
45 ASSERT_EQ(switches.include_directories.size(), 1u);
46 ASSERT_NE(switches.include_directories[0].dir, nullptr);
47 ASSERT_EQ(switches.include_directories[0].name, include_path);
48}
std::vector< IncludeDir > include_directories
Definition switches.h:25
fml::UniqueFD OpenFixturesDirectory()
Opens the fixtures directory for the unit-test harness.
Definition testing.cc:22
static fml::UniqueFD CreateDirectory(const fml::UniqueFD &base_directory, const std::vector< std::string > &components, FilePermission permission, size_t index)
Definition file.cc:12

References impeller::compiler::Switches::AreValid(), fml::CreateDirectory(), flutter::testing::GetFixturesPath(), impeller::compiler::Switches::include_directories, fml::kRead, MakeSwitchesDesktopGL(), and flutter::testing::OpenFixturesDirectory().

◆ TEST() [18/22]

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

Definition at line 68 of file switches_unittests.cc.

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

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

◆ TEST() [19/22]

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

Definition at line 98 of file switches_unittests.cc.

98 {
99 Switches switches =
100 MakeSwitchesDesktopGL({"--entry-point-prefix=my_prefix_"});
101 ASSERT_TRUE(switches.AreValid(std::cout));
102 EXPECT_EQ(switches.entry_point_prefix, "my_prefix_");
103
104 switches.source_file_name = "test.frag";
105 auto options = switches.CreateSourceOptions();
106 EXPECT_EQ(options.entry_point_name, "my_prefix_test_fragment_main");
107}
std::string entry_point_prefix
Definition switches.h:45
SourceOptions CreateSourceOptions() const
Definition switches.cc:319

References impeller::compiler::Switches::AreValid(), impeller::compiler::Switches::CreateSourceOptions(), impeller::compiler::Switches::entry_point_prefix, MakeSwitchesDesktopGL(), and impeller::compiler::Switches::source_file_name.

◆ TEST() [20/22]

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

Definition at line 85 of file switches_unittests.cc.

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

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

◆ TEST() [21/22]

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

Definition at line 56 of file switches_unittests.cc.

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

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

◆ TEST() [22/22]

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

Definition at line 50 of file switches_unittests.cc.

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

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

◆ TEST_P() [1/19]

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

Definition at line 148 of file compiler_unittests.cc.

148 {
149 if (!TargetPlatformIsVulkan(GetParam())) {
150 GTEST_SKIP();
151 }
152
153 ASSERT_TRUE(CanCompileAndReflect("sample.vert", SourceType::kVertexShader));
154 ASSERT_TRUE(CanCompileAndReflect("sample.frag", SourceType::kFragmentShader));
155
156 auto get_binding = [&](const char* fixture) -> uint32_t {
157 auto json_fd = GetReflectionJson(fixture);
158 nlohmann::json shader_json = nlohmann::json::parse(json_fd->GetMapping());
159 return shader_json["buffers"][0]["binding"].get<uint32_t>();
160 };
161
162 auto vert_uniform_binding = get_binding("sample.vert");
163 auto frag_uniform_binding = get_binding("sample.frag");
164
165 ASSERT_GT(frag_uniform_binding, vert_uniform_binding);
166}
bool TargetPlatformIsVulkan(TargetPlatform platform)
Definition types.cc:277

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

◆ TEST_P() [2/19]

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

Definition at line 90 of file compiler_unittests.cc.

90 {
91 ASSERT_TRUE(CanCompileAndReflect("sample.vert"));
92 ASSERT_TRUE(CanCompileAndReflect("sample.vert", SourceType::kVertexShader));
93 ASSERT_TRUE(CanCompileAndReflect("sample.vert", SourceType::kVertexShader,
94 SourceLanguage::kGLSL));
95}

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

◆ TEST_P() [3/19]

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

Definition at line 111 of file compiler_unittests.cc.

111 {
112 if (!TargetPlatformIsMetal(GetParam())) {
113 GTEST_SKIP()
114 << "Only enabled on Metal backends till ES 3.2 support is added.";
115 }
116 ASSERT_TRUE(CanCompileAndReflect("sample.comp"));
117 ASSERT_TRUE(CanCompileAndReflect("sample.comp", SourceType::kComputeShader));
118}
bool TargetPlatformIsMetal(TargetPlatform platform)
Definition types.cc:258

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

◆ TEST_P() [4/19]

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

Definition at line 97 of file compiler_unittests.cc.

97 {
98 ASSERT_TRUE(CanCompileAndReflect(
99 "simple.vert.hlsl", SourceType::kVertexShader, SourceLanguage::kHLSL));
100}

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

◆ TEST_P() [5/19]

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

Definition at line 102 of file compiler_unittests.cc.

102 {
103 ASSERT_TRUE(CanCompileAndReflect("multiple_stages.hlsl",
104 SourceType::kVertexShader,
105 SourceLanguage::kHLSL, "VertexShader"));
106 ASSERT_TRUE(CanCompileAndReflect("multiple_stages.hlsl",
107 SourceType::kFragmentShader,
108 SourceLanguage::kHLSL, "FragmentShader"));
109}

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

◆ TEST_P() [6/19]

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

Definition at line 120 of file compiler_unittests.cc.

120 {
121 ScopedValidationDisable disable_validation;
122 ASSERT_FALSE(
123 CanCompileAndReflect("resources_limit.vert", SourceType::kVertexShader));
124}

References impeller::compiler::kVertexShader.

◆ TEST_P() [7/19]

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

Definition at line 126 of file compiler_unittests.cc.

126 {
127 ScopedValidationDisable disable_validation;
128 ASSERT_FALSE(CanCompileAndReflect("struct_def_bug.vert"));
129}

◆ TEST_P() [8/19]

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

Definition at line 131 of file compiler_unittests.cc.

131 {
132 if (!TargetPlatformIsOpenGL(GetParam())) {
133 GTEST_SKIP() << "Only GL targets lower uniform blocks to flat structs.";
134 }
135 // `mat2_test.frag` has `uniform Params { ... } uParams;`. Without
136 // canonicalization, BufferBindingsGLES cannot resolve `uParams.uMat2`.
137 ASSERT_TRUE(
138 CanCompileAndReflect("mat2_test.frag", SourceType::kFragmentShader));
139 auto sl_source = GetCompiler()->GetSLShaderSource();
140 ASSERT_NE(sl_source, nullptr);
141 const std::string source(
142 reinterpret_cast<const char*>(sl_source->GetMapping()),
143 sl_source->GetSize());
144 EXPECT_EQ(source.find("uParams."), std::string::npos) << source;
145 EXPECT_NE(source.find("_Params."), std::string::npos) << source;
146}
bool TargetPlatformIsOpenGL(TargetPlatform platform)
Definition types.cc:239

References impeller::compiler::kFragmentShader, and impeller::compiler::TargetPlatformIsOpenGL().

◆ TEST_P() [9/19]

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

Definition at line 352 of file compiler_unittests.cc.

352 {
353 if (GetParam() == TargetPlatform::kSkSL) {
354 GTEST_SKIP() << "Not supported with SkSL";
355 }
356 ASSERT_TRUE(CanCompileAndReflect("sample_with_binding.vert",
357 SourceType::kVertexShader));
358 ASSERT_TRUE(CanCompileAndReflect("sample.frag", SourceType::kFragmentShader));
359
360 struct binding_and_set {
361 uint32_t binding;
362 uint32_t set;
363 };
364
365 auto get_binding = [&](const char* fixture) -> binding_and_set {
366 auto json_fd = GetReflectionJson(fixture);
367 nlohmann::json shader_json = nlohmann::json::parse(json_fd->GetMapping());
368 uint32_t binding = shader_json["buffers"][0]["binding"].get<uint32_t>();
369 uint32_t set = shader_json["buffers"][0]["set"].get<uint32_t>();
370 return {binding, set};
371 };
372
373 auto vert_uniform_binding = get_binding("sample_with_binding.vert");
374 auto frag_uniform_binding = get_binding("sample.frag");
375
376 ASSERT_EQ(frag_uniform_binding.set, 0u);
377 ASSERT_EQ(vert_uniform_binding.set, 3u);
378 ASSERT_EQ(vert_uniform_binding.binding, 17u);
379}

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

◆ TEST_P() [10/19]

impeller::compiler::testing::TEST_P ( CompilerTestRuntime  ,
Mat2Reflection   
)

Definition at line 488 of file compiler_unittests.cc.

488 {
489 if (GetParam() == TargetPlatform::kSkSL) {
490 GTEST_SKIP() << "Not supported with SkSL";
491 }
492
493 ASSERT_TRUE(CanCompileAndReflect(
494 "mat2_test.frag", SourceType::kFragmentShader, SourceLanguage::kGLSL));
495
496 std::unique_ptr<fml::FileMapping> json_fd =
497 GetReflectionJson("mat2_test.frag");
498 ASSERT_TRUE(json_fd);
499 nlohmann::json shader_json = nlohmann::json::parse(json_fd->GetMapping());
500 nlohmann::json::value_type buffers = shader_json["buffers"];
501
502 // uParams should be in buffers.
503 ASSERT_GE(buffers.size(), 1u);
504 nlohmann::json::value_type uParams = buffers[0];
505 EXPECT_EQ(uParams["name"], "Params");
506
507 nlohmann::json::value_type members = uParams["type"]["members"];
508 // We expect 1 member (for the mat2) which is a Point (vec2) with array
509 // size 2.
510 ASSERT_EQ(members.size(), 1u);
511
512 nlohmann::json::value_type mat2Member = members[0];
513
514 // Should be Mat2 (vec2)
515 EXPECT_EQ(mat2Member["type"], "Mat2");
516
517 // Size 8 bytes (vec2)
518 EXPECT_EQ(mat2Member["size"], 8u);
519
520 // Byte length should be total array size (stride * count)
521 // Stride 16 * 2 = 32.
522 EXPECT_EQ(mat2Member["byte_length"], 32u);
523
524 // Array elements should be 2 (columns).
525 EXPECT_EQ(mat2Member["array_elements"], 2u);
526
527 // Offset 0
528 EXPECT_EQ(mat2Member["offset"], 0u);
529}

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

◆ TEST_P() [11/19]

impeller::compiler::testing::TEST_P ( CompilerTestRuntime  ,
PositionedUniformsAppearInJson   
)

Definition at line 298 of file compiler_unittests.cc.

298 {
299 if (GetParam() == TargetPlatform::kRuntimeStageVulkan) {
300 // TODO(https://github.com/flutter/flutter/issues/182578): Investigate why
301 // this does not pass.
302 GTEST_SKIP() << "Not supported with Vulkan";
303 }
304
305 ASSERT_TRUE(CanCompileAndReflect("sample_with_positioned_uniforms.frag",
306 SourceType::kFragmentShader,
307 SourceLanguage::kGLSL));
308
309 auto json_fd = GetReflectionJson("sample_with_positioned_uniforms.frag");
310 ASSERT_TRUE(json_fd);
311 nlohmann::json shader_json = nlohmann::json::parse(json_fd->GetMapping());
312 auto sampler_list = shader_json["sampled_images"];
313 auto float_list = shader_json["uniforms"];
314 ASSERT_EQ(sampler_list.size(), 3u);
315 ASSERT_EQ(float_list.size(), 7u);
316
317 {
318 // clang-format off
319 std::array expected_infos = {
320 UniformInfo::Sampler("uSamplerNotPositioned1", 1u),
321 UniformInfo::Sampler("uSampler", 0u),
322 UniformInfo::Sampler("uSamplerNotPositioned2", 3u),
323 };
324 // clang-format on
325 ASSERT_EQ(sampler_list.size(), expected_infos.size());
326 for (size_t i = 0; i < expected_infos.size(); i++) {
327 EXPECT_EQ(UniformInfo::fromJson(sampler_list[i]), expected_infos[i])
328 << "index: " << i;
329 }
330 }
331
332 {
333 // clang-format off
334 std::array expected_infos = {
335 UniformInfo::Float("uFloatNotPositioned1", 0u),
336 UniformInfo::Float("uFloat", 6u),
337 UniformInfo::Vec2("uVec2", 5u),
338 UniformInfo::Vec3("uVec3", 3u),
339 UniformInfo::Vec4("uVec4", 2u),
340 UniformInfo::Mat4("uMat4", 1u),
341 UniformInfo::Float("uFloatNotPositioned2", 2u),
342 };
343 // clang-format on
344 ASSERT_EQ(float_list.size(), expected_infos.size());
345 for (size_t i = 0; i < expected_infos.size(); i++) {
346 EXPECT_EQ(UniformInfo::fromJson(float_list[i]), expected_infos[i])
347 << "index: " << i;
348 }
349 }
350}

References i, impeller::compiler::kFragmentShader, impeller::compiler::kGLSL, and impeller::compiler::kRuntimeStageVulkan.

◆ TEST_P() [12/19]

impeller::compiler::testing::TEST_P ( CompilerTestRuntime  ,
UniformsAppearInJson   
)

Definition at line 246 of file compiler_unittests.cc.

246 {
247 if (GetParam() == TargetPlatform::kRuntimeStageVulkan) {
248 // TODO(https://github.com/flutter/flutter/issues/182578): Investigate why
249 // this does not pass.
250 GTEST_SKIP() << "Not supported with Vulkan";
251 }
252
253 ASSERT_TRUE(CanCompileAndReflect("sample_with_uniforms.frag",
254 SourceType::kFragmentShader,
255 SourceLanguage::kGLSL));
256
257 auto json_fd = GetReflectionJson("sample_with_uniforms.frag");
258 ASSERT_TRUE(json_fd);
259 nlohmann::json shader_json = nlohmann::json::parse(json_fd->GetMapping());
260 auto sampler_list = shader_json["sampled_images"];
261 auto float_list = shader_json["uniforms"];
262 ASSERT_EQ(sampler_list.size(), 2u);
263 ASSERT_EQ(float_list.size(), 6u);
264
265 {
266 // clang-format off
267 std::array expected_infos = {
268 UniformInfo::Sampler("uFirstSampler", 1u),
269 UniformInfo::Sampler("uSampler", 7u),
270 };
271 // clang-format on
272 ASSERT_EQ(sampler_list.size(), expected_infos.size());
273 for (size_t i = 0; i < expected_infos.size(); i++) {
274 EXPECT_EQ(UniformInfo::fromJson(sampler_list[i]), expected_infos[i])
275 << "index: " << i;
276 }
277 }
278
279 {
280 // clang-format off
281 std::array expected_infos = {
282 UniformInfo::Float("uFirstFloat", 0u),
283 UniformInfo::Float("uFloat", 2u),
284 UniformInfo::Vec2("uVec2", 3u),
285 UniformInfo::Vec3("uVec3", 4u),
286 UniformInfo::Vec4("uVec4", 5u),
287 UniformInfo::Mat4("uMat4", 6u),
288 };
289 // clang-format on
290 ASSERT_EQ(float_list.size(), expected_infos.size());
291 for (size_t i = 0; i < expected_infos.size(); i++) {
292 EXPECT_EQ(UniformInfo::fromJson(float_list[i]), expected_infos[i])
293 << "index: " << i;
294 }
295 }
296}

References i, impeller::compiler::kFragmentShader, impeller::compiler::kGLSL, and impeller::compiler::kRuntimeStageVulkan.

◆ TEST_P() [13/19]

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

Definition at line 395 of file compiler_unittests.cc.

395 {
396 ASSERT_TRUE(CanCompileAndReflect("struct_internal.frag",
397 SourceType::kFragmentShader));
398}

References impeller::compiler::kFragmentShader.

◆ TEST_P() [14/19]

impeller::compiler::testing::TEST_P ( CompilerTestSkSL  ,
CompilesWithValidArrayInitialization   
)

Definition at line 482 of file compiler_unittests.cc.

482 {
483 ASSERT_TRUE(
484 CanCompileAndReflect("array_initialization_without_initializer.frag",
485 SourceType::kFragmentShader));
486}

References impeller::compiler::kFragmentShader.

◆ TEST_P() [15/19]

impeller::compiler::testing::TEST_P ( CompilerTestSkSL  ,
FailsToCompileDueToArrayAssignment   
)

Definition at line 420 of file compiler_unittests.cc.

420 {
421 // Does not EXIT because the backend SkSL compiler doesn't detect the invalid
422 // SkSL. Returns false because the Impeller Compiler's post-compile validation
423 // fails.
424 ASSERT_FALSE(CanCompileAndReflect("array_assignment.frag",
425 SourceType::kFragmentShader));
426
427 const Compiler* compiler = GetCompiler();
428 ASSERT_TRUE(compiler);
429 // Truncated error message.
430 ASSERT_STREQ(
431 compiler->GetErrorMessages().c_str(),
432 "\"array_assignment.frag\": \n"
433 "Compiled to invalid SkSL:\n"
434 " // This SkSL shader is autogenerated by spirv-cross.\n"
435 " \n"
436 " float4 flutter_FragCoord;\n"
437 " \n"
438 " vec4 frag_color;\n"
439 " \n"
440 "... (truncated 16 lines)\n"
441 "SkSL Error:\n"
442 " error: 12: initializers are not permitted on arrays (or structs "
443 "containing arrays)\n"
444 " float more_nums[2] = nums;\n"
445 " ^^^^\n"
446 " 1 error\n");
447 // Full error message.
448 ASSERT_STREQ(compiler->GetVerboseErrorMessages().c_str(),
449 "\"array_assignment.frag\": \n"
450 "Compiled to invalid SkSL:\n"
451 "// This SkSL shader is autogenerated by spirv-cross.\n"
452 "\n"
453 "float4 flutter_FragCoord;\n"
454 "\n"
455 "vec4 frag_color;\n"
456 "\n"
457 "void FLT_main()\n"
458 "{\n"
459 " float nums[2];\n"
460 " nums[0] = 1.0;\n"
461 " nums[1] = 0.5;\n"
462 " float more_nums[2] = nums;\n"
463 " frag_color = vec4(nums[0], nums[1], 1.0, 1.0);\n"
464 "}\n"
465 "\n"
466 "half4 main(float2 iFragCoord)\n"
467 "{\n"
468 " flutter_FragCoord = float4(iFragCoord, 0, 0);\n"
469 " FLT_main();\n"
470 " return frag_color;\n"
471 "}\n"
472 "\n"
473 "SkSL Error:\n"
474 "error: 12: initializers are not permitted on arrays (or "
475 "structs containing arrays)\n"
476 " float more_nums[2] = nums;\n"
477 " ^^^^\n"
478 "1 error\n"
479 "\n");
480}
std::string GetVerboseErrorMessages() const
Definition compiler.cc:620
std::string GetErrorMessages() const
Definition compiler.cc:616

References impeller::compiler::Compiler::GetErrorMessages(), impeller::compiler::Compiler::GetVerboseErrorMessages(), and impeller::compiler::kFragmentShader.

◆ TEST_P() [16/19]

impeller::compiler::testing::TEST_P ( CompilerTestSkSL  ,
FailsToCompileDueToArrayInitializerWithConstants   
)

Definition at line 400 of file compiler_unittests.cc.

400 {
401 auto expected_err =
402 "There was a compiler error: SkSL does not support array initializers: "
403 "array_initializer_with_constants.frag:6";
404
405 EXPECT_EXIT(CanCompileAndReflect("array_initializer_with_constants.frag",
406 SourceType::kFragmentShader),
407 ::testing::ExitedWithCode(1), expected_err);
408}

References impeller::compiler::kFragmentShader.

◆ TEST_P() [17/19]

impeller::compiler::testing::TEST_P ( CompilerTestSkSL  ,
FailsToCompileDueToArrayInitializerWithVariables   
)

Definition at line 410 of file compiler_unittests.cc.

410 {
411 auto expected_err =
412 "There was a compiler error: SkSL does not support array initializers: "
413 "array_initializer_with_variables.frag:12";
414
415 EXPECT_EXIT(CanCompileAndReflect("array_initializer_with_variables.frag",
416 SourceType::kFragmentShader),
417 ::testing::ExitedWithCode(1), expected_err);
418}

References impeller::compiler::kFragmentShader.

◆ TEST_P() [18/19]

impeller::compiler::testing::TEST_P ( CompilerTestSkSL  ,
SkSLTextureLookUpOrderOfOperations   
)

Definition at line 381 of file compiler_unittests.cc.

381 {
382 ASSERT_TRUE(
383 CanCompileAndReflect("texture_lookup.frag", SourceType::kFragmentShader));
384
385 auto shader = GetShaderFile("texture_lookup.frag", GetParam());
386 std::string_view shader_mapping(
387 reinterpret_cast<const char*>(shader->GetMapping()), shader->GetSize());
388
389 constexpr std::string_view expected =
390 "textureA.eval(textureA_size * ( vec2(1.0) + flutter_FragCoord.xy));";
391
392 EXPECT_NE(shader_mapping.find(expected), std::string::npos);
393}

References impeller::compiler::kFragmentShader.

◆ TEST_P() [19/19]

impeller::compiler::testing::TEST_P ( CompilerTestUnknownPlatform  ,
MustFailDueToUnknownPlatform   
)

Definition at line 531 of file compiler_unittests.cc.

531 {
532 ASSERT_FALSE(
533 CanCompileAndReflect("sample.frag", SourceType::kFragmentShader));
534}

References impeller::compiler::kFragmentShader.

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