Flutter Impeller
impeller::compiler::testing Namespace Reference

Classes

class  CompilerTestBase
 
class  CompilerTest
 
class  CompilerTestSkSL
 
class  CompilerTestRuntime
 

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, 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, BindingBaseForFragShader)
 
 TEST_P (CompilerTestRuntime, UniformsAppearInJson)
 
 TEST_P (CompilerTestRuntime, PositionedUniformsAppearInJson)
 
 TEST_P (CompilerTest, UniformsHaveBindingAndSet)
 
 TEST_P (CompilerTestSkSL, SkSLTextureLookUpOrderOfOperations)
 
 TEST_P (CompilerTestSkSL, CanCompileStructs)
 
 INSTANTIATE_TARGET_PLATFORM_TEST_SUITE_P (CompilerSuite)
 
 INSTANTIATE_RUNTIME_TARGET_PLATFORM_TEST_SUITE_P (CompilerSuite)
 
 INSTANTIATE_SKSL_TARGET_PLATFORM_TEST_SUITE_P (CompilerSuite)
 
 TEST (ShaderBundleTest, ParseShaderBundleConfigFailsForInvalidJSON)
 
 TEST (ShaderBundleTest, ParseShaderBundleConfigFailsWhenEntryNotObject)
 
 TEST (ShaderBundleTest, ParseShaderBundleConfigFailsWhenMissingFile)
 
 TEST (ShaderBundleTest, ParseShaderBundleConfigFailsWhenMissingType)
 
 TEST (ShaderBundleTest, ParseShaderBundleConfigFailsForInvalidType)
 
 TEST (ShaderBundleTest, ParseShaderBundleConfigFailsForInvalidLanguage)
 
 TEST (ShaderBundleTest, ParseShaderBundleConfigReturnsExpectedConfig)
 
template<typename T >
const T * FindByName (const std::vector< std::unique_ptr< T >> &collection, const std::string &name)
 
 TEST (ShaderBundleTest, GenerateShaderBundleFlatbufferProducesCorrectResult)
 
Switches MakeSwitchesDesktopGL (std::initializer_list< const char * > additional_options={})
 
 TEST (SwitchesTest, DoesntMangleUnicodeIncludes)
 
 TEST (SwitchesTest, SourceLanguageDefaultsToGLSL)
 
 TEST (SwitchesTest, SourceLanguageCanBeSetToHLSL)
 
 TEST (SwitchesTest, DefaultEntryPointIsMain)
 
 TEST (SwitchesTest, EntryPointCanBeSetForHLSL)
 
 TEST (SwitchesTEst, ConvertToEntrypointName)
 
 TEST (SwitchesTest, ShaderBundleModeValid)
 
 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 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 }
int32_t value

References value.

Referenced by TEST().

◆ 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());
22  return fml::paths::JoinPaths(
23  {flutter::testing::GetFixturesPath(), dir_name.str()});
24 }

◆ INSTANTIATE_RUNTIME_TARGET_PLATFORM_TEST_SUITE_P()

impeller::compiler::testing::INSTANTIATE_RUNTIME_TARGET_PLATFORM_TEST_SUITE_P ( CompilerSuite  )

◆ INSTANTIATE_SKSL_TARGET_PLATFORM_TEST_SUITE_P()

impeller::compiler::testing::INSTANTIATE_SKSL_TARGET_PLATFORM_TEST_SUITE_P ( CompilerSuite  )

◆ 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 19 of file switches_unittests.cc.

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

Referenced by TEST().

◆ ReflectionCCName()

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

Definition at line 47 of file compiler_test.cc.

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

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

◆ ReflectionHeaderName()

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

Definition at line 41 of file compiler_test.cc.

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

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

◆ ReflectionJSONName()

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

Definition at line 53 of file compiler_test.cc.

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

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 65 of file compiler_test.cc.

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

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 59 of file compiler_test.cc.

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

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

◆ TEST() [1/19]

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

Definition at line 18 of file compiler_unittests.cc.

18  {
19  std::shared_ptr<const fml::Mapping> fixture =
20  flutter::testing::OpenFixtureAsMapping("check_gles_definition.frag");
21 
22  SourceOptions options;
23  options.source_language = SourceLanguage::kGLSL;
24  options.target_platform = TargetPlatform::kRuntimeStageGLES;
25  options.entry_point_name = "main";
26  options.type = SourceType::kFragmentShader;
27 
28  Reflector::Options reflector_options;
29  reflector_options.target_platform = TargetPlatform::kRuntimeStageGLES;
30  Compiler compiler = Compiler(fixture, options, reflector_options);
31 
32  // Should fail as the shader has a compilation error in it.
33  EXPECT_EQ(compiler.GetSPIRVAssembly(), nullptr);
34 
35  // Should succeed as the compilation error is ifdef'd out.
36  options.target_platform = TargetPlatform::kRuntimeStageVulkan;
37  reflector_options.target_platform = TargetPlatform::kRuntimeStageVulkan;
38  Compiler compiler_2 = Compiler(fixture, options, reflector_options);
39  EXPECT_NE(compiler_2.GetSPIRVAssembly(), nullptr);
40 }

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

◆ TEST() [2/19]

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

Definition at line 42 of file compiler_unittests.cc.

42  {
43  ASSERT_EQ(SourceTypeFromFileName("hello.vert"), SourceType::kVertexShader);
44  ASSERT_EQ(SourceTypeFromFileName("hello.frag"), SourceType::kFragmentShader);
45  ASSERT_EQ(SourceTypeFromFileName("hello.comp"), SourceType::kComputeShader);
46  ASSERT_EQ(SourceTypeFromFileName("hello.msl"), SourceType::kUnknown);
47  ASSERT_EQ(SourceTypeFromFileName("hello.glsl"), SourceType::kUnknown);
48 }
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/19]

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 
139  SourceOptions options;
140  options.target_platform = TargetPlatform::kRuntimeStageMetal;
141  options.source_language = SourceLanguage::kGLSL;
142 
143  std::optional<fb::shaderbundle::ShaderBundleT> bundle =
144  GenerateShaderBundleFlatbuffer(config, options);
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");
194  EXPECT_EQ(color->type, fb::shaderbundle::UniformDataType::kFloat);
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 }
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...

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

◆ TEST() [4/19]

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 }
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 impeller::compiler::ParseShaderBundleConfig().

◆ TEST() [5/19]

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 }

References impeller::compiler::ParseShaderBundleConfig().

◆ TEST() [6/19]

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 }

References impeller::compiler::ParseShaderBundleConfig().

◆ TEST() [7/19]

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 }

References impeller::compiler::ParseShaderBundleConfig().

◆ TEST() [8/19]

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 }

References impeller::compiler::ParseShaderBundleConfig().

◆ TEST() [9/19]

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 }

References impeller::compiler::ParseShaderBundleConfig().

◆ TEST() [10/19]

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

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

◆ TEST() [11/19]

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

Definition at line 108 of file switches_unittests.cc.

108  {
109  std::u16string filename = u"test\u1234";
110  std::string input_flag = "--input=" + fml::Utf16ToUtf8(filename);
111  Switches switches = MakeSwitchesDesktopGL({input_flag.c_str()});
112  ASSERT_TRUE(switches.AreValid(std::cout));
113  ASSERT_EQ(switches.source_file_name, filename);
114 }
Switches MakeSwitchesDesktopGL(std::initializer_list< const char * > additional_options={})

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

◆ TEST() [12/19]

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

Definition at line 73 of file switches_unittests.cc.

73  {
74  ASSERT_EQ(ConvertToEntrypointName("mandelbrot_unrolled"),
75  "mandelbrot_unrolled");
76  ASSERT_EQ(ConvertToEntrypointName("mandelbrot-unrolled"),
77  "mandelbrotunrolled");
78  ASSERT_EQ(ConvertToEntrypointName("7_"), "i_7_");
79  ASSERT_EQ(ConvertToEntrypointName("415"), "i_415");
80  ASSERT_EQ(ConvertToEntrypointName("#$%"), "i_");
81  ASSERT_EQ(ConvertToEntrypointName(""), "");
82 }
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() [13/19]

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

Definition at line 61 of file switches_unittests.cc.

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

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

◆ TEST() [14/19]

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

Definition at line 32 of file switches_unittests.cc.

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

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

◆ TEST() [15/19]

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

Definition at line 67 of file switches_unittests.cc.

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

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

◆ TEST() [16/19]

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

Definition at line 97 of file switches_unittests.cc.

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

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

◆ TEST() [17/19]

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

Definition at line 84 of file switches_unittests.cc.

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

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

◆ TEST() [18/19]

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

Definition at line 55 of file switches_unittests.cc.

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

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

◆ TEST() [19/19]

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

Definition at line 49 of file switches_unittests.cc.

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

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

◆ TEST_P() [1/12]

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

Definition at line 106 of file compiler_unittests.cc.

106  {
107  if (!TargetPlatformIsVulkan(GetParam())) {
108  GTEST_SKIP();
109  }
110 
111  ASSERT_TRUE(CanCompileAndReflect("sample.vert", SourceType::kVertexShader));
112  ASSERT_TRUE(CanCompileAndReflect("sample.frag", SourceType::kFragmentShader));
113 
114  auto get_binding = [&](const char* fixture) -> uint32_t {
115  auto json_fd = GetReflectionJson(fixture);
116  nlohmann::json shader_json = nlohmann::json::parse(json_fd->GetMapping());
117  return shader_json["buffers"][0]["binding"].get<uint32_t>();
118  };
119 
120  auto vert_uniform_binding = get_binding("sample.vert");
121  auto frag_uniform_binding = get_binding("sample.frag");
122 
123  ASSERT_GT(frag_uniform_binding, vert_uniform_binding);
124 }
bool TargetPlatformIsVulkan(TargetPlatform platform)
Definition: types.cc:296

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

◆ TEST_P() [2/12]

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

Definition at line 50 of file compiler_unittests.cc.

50  {
51  if (GetParam() == TargetPlatform::kSkSL) {
52  GTEST_SKIP() << "Not supported with SkSL";
53  }
54  ASSERT_TRUE(CanCompileAndReflect("sample.vert"));
55  ASSERT_TRUE(CanCompileAndReflect("sample.vert", SourceType::kVertexShader));
56  ASSERT_TRUE(CanCompileAndReflect("sample.vert", SourceType::kVertexShader,
57  SourceLanguage::kGLSL));
58 }

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

◆ TEST_P() [3/12]

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

Definition at line 80 of file compiler_unittests.cc.

80  {
81  if (!TargetPlatformIsMetal(GetParam())) {
82  GTEST_SKIP()
83  << "Only enabled on Metal backends till ES 3.2 support is added.";
84  }
85  ASSERT_TRUE(CanCompileAndReflect("sample.comp"));
86  ASSERT_TRUE(CanCompileAndReflect("sample.comp", SourceType::kComputeShader));
87 }
bool TargetPlatformIsMetal(TargetPlatform platform)
Definition: types.cc:277

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

◆ TEST_P() [4/12]

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

Definition at line 60 of file compiler_unittests.cc.

60  {
61  if (GetParam() == TargetPlatform::kSkSL) {
62  GTEST_SKIP() << "Not supported with SkSL";
63  }
64  ASSERT_TRUE(CanCompileAndReflect(
65  "simple.vert.hlsl", SourceType::kVertexShader, SourceLanguage::kHLSL));
66 }

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

◆ TEST_P() [5/12]

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

Definition at line 68 of file compiler_unittests.cc.

68  {
69  if (GetParam() == TargetPlatform::kSkSL) {
70  GTEST_SKIP() << "Not supported with SkSL";
71  }
72  ASSERT_TRUE(CanCompileAndReflect("multiple_stages.hlsl",
73  SourceType::kVertexShader,
74  SourceLanguage::kHLSL, "VertexShader"));
75  ASSERT_TRUE(CanCompileAndReflect("multiple_stages.hlsl",
76  SourceType::kFragmentShader,
77  SourceLanguage::kHLSL, "FragmentShader"));
78 }

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

◆ TEST_P() [6/12]

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

Definition at line 89 of file compiler_unittests.cc.

89  {
90  if (GetParam() == TargetPlatform::kSkSL) {
91  GTEST_SKIP() << "Not supported with SkSL";
92  }
93  ScopedValidationDisable disable_validation;
94  ASSERT_FALSE(
95  CanCompileAndReflect("resources_limit.vert", SourceType::kVertexShader));
96 }

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

◆ TEST_P() [7/12]

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

Definition at line 98 of file compiler_unittests.cc.

98  {
99  if (GetParam() == TargetPlatform::kSkSL) {
100  GTEST_SKIP() << "Not supported with SkSL";
101  }
102  ScopedValidationDisable disable_validation;
103  ASSERT_FALSE(CanCompileAndReflect("struct_def_bug.vert"));
104 }

References impeller::compiler::kSkSL.

◆ TEST_P() [8/12]

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

Definition at line 298 of file compiler_unittests.cc.

298  {
299  if (GetParam() == TargetPlatform::kSkSL) {
300  GTEST_SKIP() << "Not supported with SkSL";
301  }
302  ASSERT_TRUE(CanCompileAndReflect("sample_with_binding.vert",
303  SourceType::kVertexShader));
304  ASSERT_TRUE(CanCompileAndReflect("sample.frag", SourceType::kFragmentShader));
305 
306  struct binding_and_set {
307  uint32_t binding;
308  uint32_t set;
309  };
310 
311  auto get_binding = [&](const char* fixture) -> binding_and_set {
312  auto json_fd = GetReflectionJson(fixture);
313  nlohmann::json shader_json = nlohmann::json::parse(json_fd->GetMapping());
314  uint32_t binding = shader_json["buffers"][0]["binding"].get<uint32_t>();
315  uint32_t set = shader_json["buffers"][0]["set"].get<uint32_t>();
316  return {binding, set};
317  };
318 
319  auto vert_uniform_binding = get_binding("sample_with_binding.vert");
320  auto frag_uniform_binding = get_binding("sample.frag");
321 
322  ASSERT_EQ(frag_uniform_binding.set, 0u);
323  ASSERT_EQ(vert_uniform_binding.set, 3u);
324  ASSERT_EQ(vert_uniform_binding.binding, 17u);
325 }

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

◆ TEST_P() [9/12]

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

Definition at line 250 of file compiler_unittests.cc.

250  {
251  ASSERT_TRUE(CanCompileAndReflect("sample_with_positioned_uniforms.frag",
252  SourceType::kFragmentShader,
253  SourceLanguage::kGLSL));
254 
255  auto json_fd = GetReflectionJson("sample_with_positioned_uniforms.frag");
256  ASSERT_TRUE(json_fd);
257  nlohmann::json shader_json = nlohmann::json::parse(json_fd->GetMapping());
258  auto sampler_list = shader_json["sampled_images"];
259  auto float_list = shader_json["uniforms"];
260  ASSERT_EQ(sampler_list.size(), 3u);
261  ASSERT_EQ(float_list.size(), 7u);
262 
263  {
264  // clang-format off
265  std::array expected_infos = {
266  UniformInfo::Sampler("uSamplerNotPositioned1", 1u),
267  UniformInfo::Sampler("uSampler", 0u),
268  UniformInfo::Sampler("uSamplerNotPositioned2", 3u),
269  };
270  // clang-format on
271  ASSERT_EQ(sampler_list.size(), expected_infos.size());
272  for (size_t i = 0; i < expected_infos.size(); i++) {
273  EXPECT_EQ(UniformInfo::fromJson(sampler_list[i]), expected_infos[i])
274  << "index: " << i;
275  }
276  }
277 
278  {
279  // clang-format off
280  std::array expected_infos = {
281  UniformInfo::Float("uFloatNotPositioned1", 0u),
282  UniformInfo::Float("uFloat", 6u),
283  UniformInfo::Vec2("uVec2", 5u),
284  UniformInfo::Vec3("uVec3", 3u),
285  UniformInfo::Vec4("uVec4", 2u),
286  UniformInfo::Mat4("uMat4", 1u),
287  UniformInfo::Float("uFloatNotPositioned2", 2u),
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 impeller::compiler::kFragmentShader, and impeller::compiler::kGLSL.

◆ TEST_P() [10/12]

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

Definition at line 204 of file compiler_unittests.cc.

204  {
205  ASSERT_TRUE(CanCompileAndReflect("sample_with_uniforms.frag",
206  SourceType::kFragmentShader,
207  SourceLanguage::kGLSL));
208 
209  auto json_fd = GetReflectionJson("sample_with_uniforms.frag");
210  ASSERT_TRUE(json_fd);
211  nlohmann::json shader_json = nlohmann::json::parse(json_fd->GetMapping());
212  auto sampler_list = shader_json["sampled_images"];
213  auto float_list = shader_json["uniforms"];
214  ASSERT_EQ(sampler_list.size(), 2u);
215  ASSERT_EQ(float_list.size(), 6u);
216 
217  {
218  // clang-format off
219  std::array expected_infos = {
220  UniformInfo::Sampler("uFirstSampler", 1u),
221  UniformInfo::Sampler("uSampler", 7u),
222  };
223  // clang-format on
224  ASSERT_EQ(sampler_list.size(), expected_infos.size());
225  for (size_t i = 0; i < expected_infos.size(); i++) {
226  EXPECT_EQ(UniformInfo::fromJson(sampler_list[i]), expected_infos[i])
227  << "index: " << i;
228  }
229  }
230 
231  {
232  // clang-format off
233  std::array expected_infos = {
234  UniformInfo::Float("uFirstFloat", 0u),
235  UniformInfo::Float("uFloat", 2u),
236  UniformInfo::Vec2("uVec2", 3u),
237  UniformInfo::Vec3("uVec3", 4u),
238  UniformInfo::Vec4("uVec4", 5u),
239  UniformInfo::Mat4("uMat4", 6u),
240  };
241  // clang-format on
242  ASSERT_EQ(float_list.size(), expected_infos.size());
243  for (size_t i = 0; i < expected_infos.size(); i++) {
244  EXPECT_EQ(UniformInfo::fromJson(float_list[i]), expected_infos[i])
245  << "index: " << i;
246  }
247  }
248 }

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

◆ TEST_P() [11/12]

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

Definition at line 341 of file compiler_unittests.cc.

341  {
342  ASSERT_TRUE(CanCompileAndReflect("struct_internal.frag",
343  SourceType::kFragmentShader));
344 }

References impeller::compiler::kFragmentShader.

◆ TEST_P() [12/12]

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

Definition at line 327 of file compiler_unittests.cc.

327  {
328  ASSERT_TRUE(
329  CanCompileAndReflect("texture_lookup.frag", SourceType::kFragmentShader));
330 
331  auto shader = GetShaderFile("texture_lookup.frag", GetParam());
332  std::string_view shader_mapping(
333  reinterpret_cast<const char*>(shader->GetMapping()), shader->GetSize());
334 
335  constexpr std::string_view expected =
336  "textureA.eval(textureA_size * ( vec2(1.0) + flutter_FragCoord.xy));";
337 
338  EXPECT_NE(shader_mapping.find(expected), std::string::npos);
339 }

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 17 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 20 of file shader_bundle_unittests.cc.

Referenced by TEST().