Flutter Impeller
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, 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 (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 T * FindByName (const std::vector< std::unique_ptr< T >> &collection, const std::string &name)
 
 TEST (ShaderBundleTest, GenerateShaderBundleFlatbufferProducesCorrectResult)
 
Switches MakeSwitchesDesktopGL (std::initializer_list< const char * > additional_options={})
 
 TEST (SwitchesTest, DoesntMangleUnicodeIncludes)
 
 TEST (SwitchesTest, SourceLanguageDefaultsToGLSL)
 
 TEST (SwitchesTest, SourceLanguageCanBeSetToHLSL)
 
 TEST (SwitchesTest, DefaultEntryPointIsMain)
 
 TEST (SwitchesTest, EntryPointCanBeSetForHLSL)
 
 TEST (SwitchesTEst, ConvertToEntrypointName)
 
 TEST (SwitchesTest, ShaderBundleModeValid)
 

Variables

const std::string kUnlitFragmentBundleConfig
 
const std::string kUnlitVertexBundleConfig
 

Function Documentation

◆ 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_TARGET_PLATFORM_TEST_SUITE_P()

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

◆ MakeSwitchesDesktopGL()

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

Definition at line 18 of file switches_unittests.cc.

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

Referenced by TEST().

◆ ReflectionCCName()

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

Definition at line 46 of file compiler_test.cc.

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

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

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

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

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

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

◆ SLFileName()

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

Definition at line 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:250

References impeller::compiler::TargetPlatformSLExtension().

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

◆ SPIRVFileName()

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

Definition at line 58 of file compiler_test.cc.

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

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

◆ TEST() [1/17]

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

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::string &file_name)
Definition: types.cc:30

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

◆ TEST() [3/17]

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

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

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

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

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

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

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

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

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

References impeller::compiler::ConvertToEntrypointName().

◆ TEST() [12/17]

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 }
Switches MakeSwitchesDesktopGL(std::initializer_list< const char * > additional_options={})

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

◆ TEST() [13/17]

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

Definition at line 31 of file switches_unittests.cc.

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

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

◆ TEST() [14/17]

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

Definition at line 66 of file switches_unittests.cc.

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

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

◆ TEST() [15/17]

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

Definition at line 83 of file switches_unittests.cc.

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

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

◆ TEST() [16/17]

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

Definition at line 54 of file switches_unittests.cc.

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

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

◆ TEST() [17/17]

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

Definition at line 48 of file switches_unittests.cc.

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

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

◆ TEST_P() [1/10]

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

Definition at line 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:309

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

◆ TEST_P() [2/10]

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

Definition at line 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/10]

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:290

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

◆ TEST_P() [4/10]

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

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

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

Definition at line 172 of file compiler_unittests.cc.

172  {
173  if (GetParam() != TargetPlatform::kSkSL) {
174  GTEST_SKIP() << "Only supported on SkSL";
175  }
176  ASSERT_TRUE(CanCompileAndReflect("struct_internal.frag",
177  SourceType::kFragmentShader));
178 }

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

◆ TEST_P() [7/10]

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

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

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

Definition at line 155 of file compiler_unittests.cc.

155  {
156  if (GetParam() != TargetPlatform::kSkSL) {
157  GTEST_SKIP() << "Only supported on SkSL";
158  }
159  ASSERT_TRUE(
160  CanCompileAndReflect("texture_lookup.frag", SourceType::kFragmentShader));
161 
162  auto shader = GetShaderFile("texture_lookup.frag", GetParam());
163  std::string_view shader_mapping(
164  reinterpret_cast<const char*>(shader->GetMapping()), shader->GetSize());
165 
166  constexpr std::string_view expected =
167  "textureA.eval(textureA_size * ( vec2(1.0) + flutter_FragCoord.xy));";
168 
169  EXPECT_NE(shader_mapping.find(expected), std::string::npos);
170 }

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

◆ TEST_P() [10/10]

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

Definition at line 126 of file compiler_unittests.cc.

126  {
127  if (GetParam() == TargetPlatform::kSkSL) {
128  GTEST_SKIP() << "Not supported with SkSL";
129  }
130  ASSERT_TRUE(CanCompileAndReflect("sample_with_binding.vert",
131  SourceType::kVertexShader));
132  ASSERT_TRUE(CanCompileAndReflect("sample.frag", SourceType::kFragmentShader));
133 
134  struct binding_and_set {
135  uint32_t binding;
136  uint32_t set;
137  };
138 
139  auto get_binding = [&](const char* fixture) -> binding_and_set {
140  auto json_fd = GetReflectionJson(fixture);
141  nlohmann::json shader_json = nlohmann::json::parse(json_fd->GetMapping());
142  uint32_t binding = shader_json["buffers"][0]["binding"].get<uint32_t>();
143  uint32_t set = shader_json["buffers"][0]["set"].get<uint32_t>();
144  return {binding, set};
145  };
146 
147  auto vert_uniform_binding = get_binding("sample_with_binding.vert");
148  auto frag_uniform_binding = get_binding("sample.frag");
149 
150  ASSERT_EQ(frag_uniform_binding.set, 0u);
151  ASSERT_EQ(vert_uniform_binding.set, 3u);
152  ASSERT_EQ(vert_uniform_binding.binding, 17u);
153 }

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

Variable Documentation

◆ kUnlitFragmentBundleConfig

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

Definition at line 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().