diff --git a/engine/src/flutter/impeller/compiler/compiler_test.cc b/engine/src/flutter/impeller/compiler/compiler_test.cc index 62d63a2b61..85b3abaa5f 100644 --- a/engine/src/flutter/impeller/compiler/compiler_test.cc +++ b/engine/src/flutter/impeller/compiler/compiler_test.cc @@ -58,14 +58,15 @@ static std::string SLFileName(const char* fixture_name, return stream.str(); } -bool CompilerTest::CanCompileAndReflect(const char* fixture_name) const { +bool CompilerTest::CanCompileAndReflect(const char* fixture_name, + SourceType source_type) const { auto fixture = flutter::testing::OpenFixtureAsMapping(fixture_name); if (!fixture->GetMapping()) { VALIDATION_LOG << "Could not find shader in fixtures: " << fixture_name; return false; } - SourceOptions source_options(fixture_name); + SourceOptions source_options(fixture_name, source_type); source_options.target_platform = GetParam(); source_options.working_directory = std::make_shared( flutter::testing::OpenFixturesDirectory()); diff --git a/engine/src/flutter/impeller/compiler/compiler_test.h b/engine/src/flutter/impeller/compiler/compiler_test.h index f3141c2135..a7be1c688b 100644 --- a/engine/src/flutter/impeller/compiler/compiler_test.h +++ b/engine/src/flutter/impeller/compiler/compiler_test.h @@ -21,7 +21,9 @@ class CompilerTest : public ::testing::TestWithParam { ~CompilerTest(); - bool CanCompileAndReflect(const char* fixture_name) const; + bool CanCompileAndReflect( + const char* fixture_name, + SourceType source_type = SourceType::kUnknown) const; private: fml::UniqueFD intermediates_directory_; diff --git a/engine/src/flutter/impeller/compiler/compiler_unittests.cc b/engine/src/flutter/impeller/compiler/compiler_unittests.cc index 3aa20e6fef..d19d9f00c9 100644 --- a/engine/src/flutter/impeller/compiler/compiler_unittests.cc +++ b/engine/src/flutter/impeller/compiler/compiler_unittests.cc @@ -27,14 +27,19 @@ TEST(CompilerTest, ShaderKindMatchingIsSuccessful) { TEST_P(CompilerTest, CanCompile) { ASSERT_TRUE(CanCompileAndReflect("sample.vert")); + ASSERT_TRUE(CanCompileAndReflect("sample.vert", SourceType::kVertexShader)); } TEST_P(CompilerTest, CanCompileTessellationControlShader) { ASSERT_TRUE(CanCompileAndReflect("sample.tesc")); + ASSERT_TRUE(CanCompileAndReflect("sample.tesc", + SourceType::kTessellationControlShader)); } TEST_P(CompilerTest, CanCompileTessellationEvaluationShader) { ASSERT_TRUE(CanCompileAndReflect("sample.tese")); + ASSERT_TRUE(CanCompileAndReflect("sample.tese", + SourceType::kTessellationEvaluationShader)); } TEST_P(CompilerTest, CanCompileComputeShader) { @@ -42,6 +47,7 @@ TEST_P(CompilerTest, CanCompileComputeShader) { GTEST_SKIP_("Only enabled on Metal backends till ES 3.2 support is added."); } ASSERT_TRUE(CanCompileAndReflect("sample.comp")); + ASSERT_TRUE(CanCompileAndReflect("sample.comp", SourceType::kComputeShader)); } TEST_P(CompilerTest, MustFailDueToMultipleLocationPerStructMember) { diff --git a/engine/src/flutter/impeller/compiler/impellerc_main.cc b/engine/src/flutter/impeller/compiler/impellerc_main.cc index 0f8458de01..79ff437355 100644 --- a/engine/src/flutter/impeller/compiler/impellerc_main.cc +++ b/engine/src/flutter/impeller/compiler/impellerc_main.cc @@ -13,6 +13,7 @@ #include "impeller/compiler/compiler.h" #include "impeller/compiler/source_options.h" #include "impeller/compiler/switches.h" +#include "impeller/compiler/types.h" #include "impeller/compiler/utilities.h" #include "third_party/shaderc/libshaderc/include/shaderc/shaderc.hpp" @@ -42,14 +43,17 @@ bool Main(const fml::CommandLine& command_line) { SourceOptions options; options.target_platform = switches.target_platform; - options.type = SourceTypeFromFileName(switches.source_file_name); + if (switches.input_type == SourceType::kUnknown) { + options.type = SourceTypeFromFileName(switches.source_file_name); + } else { + options.type = switches.input_type; + } options.working_directory = switches.working_directory; options.file_name = switches.source_file_name; options.include_dirs = switches.include_directories; options.defines = switches.defines; options.entry_point_name = EntryPointFunctionNameFromSourceName( - switches.source_file_name, - SourceTypeFromFileName(switches.source_file_name)); + switches.source_file_name, options.type); Reflector::Options reflector_options; reflector_options.target_platform = switches.target_platform; diff --git a/engine/src/flutter/impeller/compiler/source_options.cc b/engine/src/flutter/impeller/compiler/source_options.cc index eeb1bcf8b7..ace19b5f1f 100644 --- a/engine/src/flutter/impeller/compiler/source_options.cc +++ b/engine/src/flutter/impeller/compiler/source_options.cc @@ -9,8 +9,12 @@ namespace compiler { SourceOptions::SourceOptions() = default; -SourceOptions::SourceOptions(const std::string& file_name) - : type(SourceTypeFromFileName(file_name)), file_name(file_name) {} +SourceOptions::SourceOptions(const std::string& file_name, + SourceType source_type) + : type(source_type == SourceType::kUnknown + ? SourceTypeFromFileName(file_name) + : source_type), + file_name(file_name) {} SourceOptions::~SourceOptions() = default; diff --git a/engine/src/flutter/impeller/compiler/source_options.h b/engine/src/flutter/impeller/compiler/source_options.h index 636c0a5bf9..7a23ae2e9b 100644 --- a/engine/src/flutter/impeller/compiler/source_options.h +++ b/engine/src/flutter/impeller/compiler/source_options.h @@ -29,7 +29,8 @@ struct SourceOptions { ~SourceOptions(); - SourceOptions(const std::string& file_name); + explicit SourceOptions(const std::string& file_name, + SourceType source_type = SourceType::kUnknown); }; } // namespace compiler diff --git a/engine/src/flutter/impeller/compiler/switches.cc b/engine/src/flutter/impeller/compiler/switches.cc index 02b495fe57..ad974f4686 100644 --- a/engine/src/flutter/impeller/compiler/switches.cc +++ b/engine/src/flutter/impeller/compiler/switches.cc @@ -22,6 +22,14 @@ static const std::map kKnownPlatforms = { {"runtime-stage-gles", TargetPlatform::kRuntimeStageGLES}, }; +static const std::map kKnownSourceTypes = { + {"vert", SourceType::kVertexShader}, + {"frag", SourceType::kFragmentShader}, + {"tesc", SourceType::kTessellationControlShader}, + {"tese", SourceType::kTessellationEvaluationShader}, + {"comp", SourceType::kComputeShader}, +}; + void Switches::PrintHelp(std::ostream& stream) { stream << std::endl; stream << "ImpellerC is an offline shader processor and reflection engine." @@ -35,6 +43,11 @@ void Switches::PrintHelp(std::ostream& stream) { } stream << " ]" << std::endl; stream << "--input=" << std::endl; + stream << "[optional] --input-kind={"; + for (const auto& source_type : kKnownSourceTypes) { + stream << source_type.first << ", "; + } + stream << "}" << std::endl; stream << "--sl=" << std::endl; stream << "--spirv=" << std::endl; stream << "[optional] --reflection-json=" << std::endl; @@ -68,6 +81,18 @@ static TargetPlatform TargetPlatformFromCommandLine( return target; } +static SourceType SourceTypeFromCommandLine( + const fml::CommandLine& command_line) { + auto source_type = SourceType::kUnknown; + auto source_type_option = + command_line.GetOptionValueWithDefault("input-type", ""); + auto source_type_search = kKnownSourceTypes.find(source_type_option); + if (source_type_search == kKnownSourceTypes.end()) { + return SourceType::kUnknown; + } + return source_type_search->second; +} + Switches::Switches(const fml::CommandLine& command_line) : target_platform(TargetPlatformFromCommandLine(command_line)), working_directory(std::make_shared(fml::OpenDirectory( @@ -75,6 +100,7 @@ Switches::Switches(const fml::CommandLine& command_line) false, // create if necessary, fml::FilePermission::kRead))), source_file_name(command_line.GetOptionValueWithDefault("input", "")), + input_type(SourceTypeFromCommandLine(command_line)), sl_file_name(command_line.GetOptionValueWithDefault("sl", "")), spirv_file_name(command_line.GetOptionValueWithDefault("spirv", "")), reflection_json_name( diff --git a/engine/src/flutter/impeller/compiler/switches.h b/engine/src/flutter/impeller/compiler/switches.h index 38a0aab318..8d73ceb36c 100644 --- a/engine/src/flutter/impeller/compiler/switches.h +++ b/engine/src/flutter/impeller/compiler/switches.h @@ -22,6 +22,7 @@ struct Switches { std::shared_ptr working_directory; std::vector include_directories; std::string source_file_name; + SourceType input_type; std::string sl_file_name; std::string spirv_file_name; std::string reflection_json_name;