Flutter Impeller
impeller::compiler::testing::CompilerTest Class Reference

#include <compiler_test.h>

Inheritance diagram for impeller::compiler::testing::CompilerTest:

Public Member Functions

 CompilerTest ()
 
 ~CompilerTest ()
 
std::unique_ptr< fml::FileMapping > GetReflectionJson (const char *fixture_name) const
 
bool CanCompileAndReflect (const char *fixture_name, SourceType source_type=SourceType::kUnknown, SourceLanguage source_language=SourceLanguage::kGLSL, const char *entry_point_name="main") const
 

Detailed Description

Definition at line 18 of file compiler_test.h.

Constructor & Destructor Documentation

◆ CompilerTest()

impeller::compiler::testing::CompilerTest::CompilerTest ( )

Definition at line 23 of file compiler_test.cc.

24  : intermediates_directory_(CreateIntermediatesDirectory()) {
25  FML_CHECK(intermediates_directory_.is_valid());
26 }

◆ ~CompilerTest()

impeller::compiler::testing::CompilerTest::~CompilerTest ( )
default

Member Function Documentation

◆ CanCompileAndReflect()

bool impeller::compiler::testing::CompilerTest::CanCompileAndReflect ( const char *  fixture_name,
SourceType  source_type = SourceType::kUnknown,
SourceLanguage  source_language = SourceLanguage::kGLSL,
const char *  entry_point_name = "main" 
) const

Definition at line 68 of file compiler_test.cc.

71  {
72  std::shared_ptr<fml::Mapping> fixture =
73  flutter::testing::OpenFixtureAsMapping(fixture_name);
74  if (!fixture || !fixture->GetMapping()) {
75  VALIDATION_LOG << "Could not find shader in fixtures: " << fixture_name;
76  return false;
77  }
78 
79  SourceOptions source_options(fixture_name, source_type);
80  source_options.target_platform = GetParam();
81  source_options.source_language = source_language;
82  source_options.working_directory = std::make_shared<fml::UniqueFD>(
83  flutter::testing::OpenFixturesDirectory());
84  source_options.entry_point_name = EntryPointFunctionNameFromSourceName(
85  fixture_name, SourceTypeFromFileName(fixture_name), source_language,
86  entry_point_name);
87 
88  Reflector::Options reflector_options;
89  reflector_options.header_file_name = ReflectionHeaderName(fixture_name);
90  reflector_options.shader_name = "shader_name";
91 
92  Compiler compiler(fixture, source_options, reflector_options);
93  if (!compiler.IsValid()) {
94  VALIDATION_LOG << "Compilation failed: " << compiler.GetErrorMessages();
95  return false;
96  }
97 
98  auto spirv_assembly = compiler.GetSPIRVAssembly();
99  if (!spirv_assembly) {
100  VALIDATION_LOG << "No spirv was generated.";
101  return false;
102  }
103 
104  if (!fml::WriteAtomically(intermediates_directory_,
105  SPIRVFileName(fixture_name).c_str(),
106  *spirv_assembly)) {
107  VALIDATION_LOG << "Could not write SPIRV intermediates.";
108  return false;
109  }
110 
111  auto sl_source = compiler.GetSLShaderSource();
112  if (!sl_source) {
113  VALIDATION_LOG << "No SL source was generated.";
114  return false;
115  }
116 
117  if (!fml::WriteAtomically(intermediates_directory_,
118  SLFileName(fixture_name, GetParam()).c_str(),
119  *sl_source)) {
120  VALIDATION_LOG << "Could not write SL intermediates.";
121  return false;
122  }
123 
124  if (TargetPlatformNeedsReflection(GetParam())) {
125  auto reflector = compiler.GetReflector();
126  if (!reflector) {
128  << "No reflector was found for target platform SL compiler.";
129  return false;
130  }
131 
132  auto reflection_json = reflector->GetReflectionJSON();
133  auto reflection_header = reflector->GetReflectionHeader();
134  auto reflection_source = reflector->GetReflectionCC();
135 
136  if (!reflection_json) {
137  VALIDATION_LOG << "Reflection JSON was not found.";
138  return false;
139  }
140 
141  if (!reflection_header) {
142  VALIDATION_LOG << "Reflection header was not found.";
143  return false;
144  }
145 
146  if (!reflection_source) {
147  VALIDATION_LOG << "Reflection source was not found.";
148  return false;
149  }
150 
151  if (!fml::WriteAtomically(intermediates_directory_,
152  ReflectionHeaderName(fixture_name).c_str(),
153  *reflection_header)) {
154  VALIDATION_LOG << "Could not write reflection header intermediates.";
155  return false;
156  }
157 
158  if (!fml::WriteAtomically(intermediates_directory_,
159  ReflectionCCName(fixture_name).c_str(),
160  *reflection_source)) {
161  VALIDATION_LOG << "Could not write reflection CC intermediates.";
162  return false;
163  }
164 
165  if (!fml::WriteAtomically(intermediates_directory_,
166  ReflectionJSONName(fixture_name).c_str(),
167  *reflection_json)) {
168  VALIDATION_LOG << "Could not write reflection json intermediates.";
169  return false;
170  }
171  }
172  return true;
173 }

References impeller::compiler::SourceOptions::entry_point_name, impeller::compiler::EntryPointFunctionNameFromSourceName(), impeller::compiler::Compiler::GetErrorMessages(), impeller::compiler::Compiler::GetReflector(), impeller::compiler::Compiler::GetSLShaderSource(), impeller::compiler::Compiler::GetSPIRVAssembly(), impeller::compiler::Reflector::Options::header_file_name, impeller::compiler::Compiler::IsValid(), impeller::compiler::testing::ReflectionCCName(), impeller::compiler::testing::ReflectionHeaderName(), impeller::compiler::testing::ReflectionJSONName(), impeller::compiler::Reflector::Options::shader_name, impeller::compiler::testing::SLFileName(), impeller::compiler::SourceOptions::source_language, impeller::compiler::SourceTypeFromFileName(), impeller::compiler::testing::SPIRVFileName(), impeller::compiler::SourceOptions::target_platform, impeller::compiler::TargetPlatformNeedsReflection(), VALIDATION_LOG, and impeller::compiler::SourceOptions::working_directory.

◆ GetReflectionJson()

std::unique_ptr< fml::FileMapping > impeller::compiler::testing::CompilerTest::GetReflectionJson ( const char *  fixture_name) const

Definition at line 61 of file compiler_test.cc.

62  {
63  auto filename = ReflectionJSONName(fixture_name);
64  auto fd = fml::OpenFileReadOnly(intermediates_directory_, filename.c_str());
65  return fml::FileMapping::CreateReadOnly(fd);
66 }

References impeller::compiler::testing::ReflectionJSONName().


The documentation for this class was generated from the following files:
impeller::compiler::testing::SLFileName
static std::string SLFileName(const char *fixture_name, TargetPlatform platform)
Definition: compiler_test.cc:54
impeller::compiler::testing::ReflectionCCName
static std::string ReflectionCCName(const char *fixture_name)
Definition: compiler_test.cc:36
impeller::compiler::TargetPlatformNeedsReflection
bool TargetPlatformNeedsReflection(TargetPlatform platform)
Definition: types.cc:126
impeller::compiler::testing::ReflectionHeaderName
static std::string ReflectionHeaderName(const char *fixture_name)
Definition: compiler_test.cc:30
impeller::compiler::testing::SPIRVFileName
static std::string SPIRVFileName(const char *fixture_name)
Definition: compiler_test.cc:48
impeller::compiler::testing::ReflectionJSONName
static std::string ReflectionJSONName(const char *fixture_name)
Definition: compiler_test.cc:42
impeller::compiler::testing::CreateIntermediatesDirectory
static fml::UniqueFD CreateIntermediatesDirectory()
Definition: compiler_test.cc:13
impeller::compiler::EntryPointFunctionNameFromSourceName
std::string EntryPointFunctionNameFromSourceName(const std::string &file_name, SourceType type, SourceLanguage source_language, const std::string &entry_point_name)
Definition: types.cc:90
impeller::compiler::SourceTypeFromFileName
SourceType SourceTypeFromFileName(const std::string &file_name)
Definition: types.cc:29
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:60