diff --git a/impeller/compiler/compiler.cc b/impeller/compiler/compiler.cc index c2397c521edc0..daf0a6e878fc3 100644 --- a/impeller/compiler/compiler.cc +++ b/impeller/compiler/compiler.cc @@ -102,7 +102,8 @@ static CompilerBackend CreateCompiler(const spirv_cross::ParsedIR& ir, return {}; } auto* backend = compiler.GetCompiler(); - if (!EntryPointMustBeNamedMain(source_options.target_platform)) { + if (!EntryPointMustBeNamedMain(source_options.target_platform) && + source_options.source_language == SourceLanguage::kGLSL) { backend->rename_entry_point("main", source_options.entry_point_name, ToExecutionModel(source_options.type)); } diff --git a/impeller/compiler/compiler_test.cc b/impeller/compiler/compiler_test.cc index 472951782f46f..f77825790b2fa 100644 --- a/impeller/compiler/compiler_test.cc +++ b/impeller/compiler/compiler_test.cc @@ -67,7 +67,8 @@ std::unique_ptr CompilerTest::GetReflectionJson( bool CompilerTest::CanCompileAndReflect(const char* fixture_name, SourceType source_type, - SourceLanguage source_language) const { + SourceLanguage source_language, + const char* entry_point_name) const { auto fixture = flutter::testing::OpenFixtureAsMapping(fixture_name); if (!fixture || !fixture->GetMapping()) { VALIDATION_LOG << "Could not find shader in fixtures: " << fixture_name; @@ -80,7 +81,8 @@ bool CompilerTest::CanCompileAndReflect(const char* fixture_name, source_options.working_directory = std::make_shared( flutter::testing::OpenFixturesDirectory()); source_options.entry_point_name = EntryPointFunctionNameFromSourceName( - fixture_name, SourceTypeFromFileName(fixture_name), source_language); + fixture_name, SourceTypeFromFileName(fixture_name), source_language, + entry_point_name); Reflector::Options reflector_options; reflector_options.header_file_name = ReflectionHeaderName(fixture_name); diff --git a/impeller/compiler/compiler_test.h b/impeller/compiler/compiler_test.h index 374c06933ac14..37196c1fb30f6 100644 --- a/impeller/compiler/compiler_test.h +++ b/impeller/compiler/compiler_test.h @@ -27,7 +27,8 @@ class CompilerTest : public ::testing::TestWithParam { bool CanCompileAndReflect( const char* fixture_name, SourceType source_type = SourceType::kUnknown, - SourceLanguage source_language = SourceLanguage::kGLSL) const; + SourceLanguage source_language = SourceLanguage::kGLSL, + const char* entry_point_name = "main") const; private: fml::UniqueFD intermediates_directory_; diff --git a/impeller/compiler/compiler_unittests.cc b/impeller/compiler/compiler_unittests.cc index ed96fffac463b..ed59fb8e5d20e 100644 --- a/impeller/compiler/compiler_unittests.cc +++ b/impeller/compiler/compiler_unittests.cc @@ -37,6 +37,15 @@ TEST_P(CompilerTest, CanCompileHLSL) { "simple.vert.hlsl", SourceType::kVertexShader, SourceLanguage::kHLSL)); } +TEST_P(CompilerTest, CanCompileHLSLWithMultipleStages) { + ASSERT_TRUE(CanCompileAndReflect("multiple_stages.hlsl", + SourceType::kVertexShader, + SourceLanguage::kHLSL, "VertexShader")); + ASSERT_TRUE(CanCompileAndReflect("multiple_stages.hlsl", + SourceType::kFragmentShader, + SourceLanguage::kHLSL, "FragmentShader")); +} + TEST_P(CompilerTest, CanCompileTessellationControlShader) { ASSERT_TRUE(CanCompileAndReflect("sample.tesc")); ASSERT_TRUE(CanCompileAndReflect("sample.tesc", diff --git a/impeller/compiler/impellerc_main.cc b/impeller/compiler/impellerc_main.cc index 9d4bf89172e52..569b0006c07c0 100644 --- a/impeller/compiler/impellerc_main.cc +++ b/impeller/compiler/impellerc_main.cc @@ -70,7 +70,8 @@ bool Main(const fml::CommandLine& command_line) { options.include_dirs = switches.include_directories; options.defines = switches.defines; options.entry_point_name = EntryPointFunctionNameFromSourceName( - switches.source_file_name, options.type, options.source_language); + switches.source_file_name, options.type, options.source_language, + switches.entry_point); options.json_format = switches.json_format; Reflector::Options reflector_options; diff --git a/impeller/compiler/switches.cc b/impeller/compiler/switches.cc index 25caa1c968fe5..b816796552675 100644 --- a/impeller/compiler/switches.cc +++ b/impeller/compiler/switches.cc @@ -57,6 +57,9 @@ void Switches::PrintHelp(std::ostream& stream) { stream << "--spirv=" << std::endl; stream << "[optional] --source-language=glsl|hlsl (default: glsl)" << std::endl; + stream << "[optional] --entry-point= (default: main; " + "ignored for glsl)" + << std::endl; stream << "[optional] --iplr (causes --sl file to be emitted in iplr format)" << std::endl; stream << "[optional] --reflection-json=" << std::endl; @@ -120,7 +123,9 @@ Switches::Switches(const fml::CommandLine& command_line) reflection_cc_name( command_line.GetOptionValueWithDefault("reflection-cc", "")), depfile_path(command_line.GetOptionValueWithDefault("depfile", "")), - json_format(command_line.HasOption("json")) { + json_format(command_line.HasOption("json")), + entry_point( + command_line.GetOptionValueWithDefault("entry-point", "main")) { if (!working_directory || !working_directory->is_valid()) { return; } diff --git a/impeller/compiler/switches.h b/impeller/compiler/switches.h index 95d7b4d1701d5..7a62861fcaf71 100644 --- a/impeller/compiler/switches.h +++ b/impeller/compiler/switches.h @@ -33,6 +33,7 @@ struct Switches { std::vector defines; bool json_format; SourceLanguage source_language = SourceLanguage::kUnknown; + std::string entry_point; Switches(); diff --git a/impeller/compiler/switches_unittests.cc b/impeller/compiler/switches_unittests.cc index 3db243ee889dc..b86efe30403fe 100644 --- a/impeller/compiler/switches_unittests.cc +++ b/impeller/compiler/switches_unittests.cc @@ -57,6 +57,18 @@ TEST(SwitchesTest, SourceLanguageCanBeSetToHLSL) { ASSERT_EQ(switches.source_language, SourceLanguage::kHLSL); } +TEST(SwitchesTest, DefaultEntryPointIsMain) { + Switches switches = MakeSwitchesDesktopGL({}); + ASSERT_TRUE(switches.AreValid(std::cout)); + ASSERT_EQ(switches.entry_point, "main"); +} + +TEST(SwitchesTest, EntryPointCanBeSetForHLSL) { + Switches switches = MakeSwitchesDesktopGL({"--entry-point=CustomEntryPoint"}); + ASSERT_TRUE(switches.AreValid(std::cout)); + ASSERT_EQ(switches.entry_point, "CustomEntryPoint"); +} + } // namespace testing } // namespace compiler } // namespace impeller diff --git a/impeller/compiler/types.cc b/impeller/compiler/types.cc index a931b32b50cc8..08b4eb9b14c7a 100644 --- a/impeller/compiler/types.cc +++ b/impeller/compiler/types.cc @@ -88,9 +88,10 @@ std::string SourceLanguageToString(SourceLanguage source_language) { std::string EntryPointFunctionNameFromSourceName( const std::string& file_name, SourceType type, - SourceLanguage source_language) { + SourceLanguage source_language, + const std::string& entry_point_name) { if (source_language == SourceLanguage::kHLSL) { - return "main"; + return entry_point_name; } std::stringstream stream; diff --git a/impeller/compiler/types.h b/impeller/compiler/types.h index 56b8a51f1e7f4..78a630805a6cc 100644 --- a/impeller/compiler/types.h +++ b/impeller/compiler/types.h @@ -60,7 +60,8 @@ std::string TargetPlatformSLExtension(TargetPlatform platform); std::string EntryPointFunctionNameFromSourceName( const std::string& file_name, SourceType type, - SourceLanguage source_language); + SourceLanguage source_language, + const std::string& entry_point_name); bool TargetPlatformNeedsSL(TargetPlatform platform); diff --git a/impeller/fixtures/BUILD.gn b/impeller/fixtures/BUILD.gn index 930d9bbdfe6d5..30d609cd4f138 100644 --- a/impeller/fixtures/BUILD.gn +++ b/impeller/fixtures/BUILD.gn @@ -54,6 +54,7 @@ test_fixtures("file_fixtures") { "boston.jpg", "embarcadero.jpg", "kalimba.jpg", + "multiple_stages.hlsl", "resources_limit.vert", "sample.comp", "sample.frag", diff --git a/impeller/fixtures/multiple_stages.hlsl b/impeller/fixtures/multiple_stages.hlsl new file mode 100644 index 0000000000000..93e7073b24304 --- /dev/null +++ b/impeller/fixtures/multiple_stages.hlsl @@ -0,0 +1,21 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +struct VertexInput { + float3 position : POSITION; +}; + +struct VertexOutput { + float4 position : SV_POSITION; +}; + +VertexOutput VertexShader(VertexInput input) { + VertexOutput output; + output.position = float4(input.position, 1.0); + return output; +} + +float4 FragmentShader(VertexOutput input) { + return input.position; +} diff --git a/impeller/fixtures/simple.vert.hlsl b/impeller/fixtures/simple.vert.hlsl index 421add3ae2922..09c1103967190 100644 --- a/impeller/fixtures/simple.vert.hlsl +++ b/impeller/fixtures/simple.vert.hlsl @@ -10,8 +10,7 @@ struct VertexOutput { float4 position : SV_POSITION; }; -VertexOutput -main(VertexInput input) { +VertexOutput main(VertexInput input) { VertexOutput output; output.position = float4(input.position, 1.0); return output;