Skip to content

Commit

Permalink
[Impeller] Add a Stage 2 pass to the Vulkan shader compilation pipeli…
Browse files Browse the repository at this point in the history
…ne. (#40873)

[Impeller] Add a Stage 2 pass to the Vulkan shader compilation pipeline.
  • Loading branch information
chinmaygarde committed Apr 3, 2023
1 parent f0fa8fd commit b789b19
Show file tree
Hide file tree
Showing 9 changed files with 492 additions and 281 deletions.
4 changes: 4 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,8 @@ ORIGIN: ../../../flutter/impeller/compiler/shader_lib/impeller/transform.glsl +
ORIGIN: ../../../flutter/impeller/compiler/shader_lib/impeller/types.glsl + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/compiler/source_options.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/compiler/source_options.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/compiler/spirv_compiler.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/compiler/spirv_compiler.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/compiler/spirv_sksl.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/compiler/spirv_sksl.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/compiler/switches.cc + ../../../flutter/LICENSE
Expand Down Expand Up @@ -3674,6 +3676,8 @@ FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/transform.glsl
FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/types.glsl
FILE: ../../../flutter/impeller/compiler/source_options.cc
FILE: ../../../flutter/impeller/compiler/source_options.h
FILE: ../../../flutter/impeller/compiler/spirv_compiler.cc
FILE: ../../../flutter/impeller/compiler/spirv_compiler.h
FILE: ../../../flutter/impeller/compiler/spirv_sksl.cc
FILE: ../../../flutter/impeller/compiler/spirv_sksl.h
FILE: ../../../flutter/impeller/compiler/switches.cc
Expand Down
2 changes: 2 additions & 0 deletions impeller/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ impeller_component("compiler_lib") {
"runtime_stage_data.h",
"source_options.cc",
"source_options.h",
"spirv_compiler.cc",
"spirv_compiler.h",
"spirv_sksl.cc",
"spirv_sksl.h",
"switches.cc",
Expand Down
357 changes: 90 additions & 267 deletions impeller/compiler/compiler.cc

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions impeller/compiler/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include "impeller/compiler/include_dir.h"
#include "impeller/compiler/reflector.h"
#include "impeller/compiler/source_options.h"
#include "impeller/compiler/spirv_compiler.h"
#include "impeller/compiler/types.h"
#include "shaderc/shaderc.hpp"
#include "spirv_msl.hpp"
#include "spirv_parser.hpp"

Expand All @@ -23,15 +23,15 @@ namespace compiler {

class Compiler {
public:
Compiler(const fml::Mapping& source_mapping,
Compiler(const std::shared_ptr<const fml::Mapping>& source_mapping,
const SourceOptions& options,
Reflector::Options reflector_options);

~Compiler();

bool IsValid() const;

std::unique_ptr<fml::Mapping> GetSPIRVAssembly() const;
std::shared_ptr<fml::Mapping> GetSPIRVAssembly() const;

std::shared_ptr<fml::Mapping> GetSLShaderSource() const;

Expand All @@ -46,7 +46,7 @@ class Compiler {

private:
SourceOptions options_;
std::shared_ptr<shaderc::SpvCompilationResult> spv_result_;
std::shared_ptr<fml::Mapping> spirv_assembly_;
std::shared_ptr<fml::Mapping> sl_mapping_;
std::stringstream error_stream_;
std::unique_ptr<Reflector> reflector_;
Expand All @@ -57,8 +57,6 @@ class Compiler {

std::string GetDependencyNames(const std::string& separator) const;

void SetBindingBase(shaderc::CompileOptions& compiler_opts) const;

FML_DISALLOW_COPY_AND_ASSIGN(Compiler);
};

Expand Down
5 changes: 3 additions & 2 deletions impeller/compiler/compiler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ bool CompilerTest::CanCompileAndReflect(const char* fixture_name,
SourceType source_type,
SourceLanguage source_language,
const char* entry_point_name) const {
auto fixture = flutter::testing::OpenFixtureAsMapping(fixture_name);
std::shared_ptr<fml::Mapping> fixture =
flutter::testing::OpenFixtureAsMapping(fixture_name);
if (!fixture || !fixture->GetMapping()) {
VALIDATION_LOG << "Could not find shader in fixtures: " << fixture_name;
return false;
Expand All @@ -88,7 +89,7 @@ bool CompilerTest::CanCompileAndReflect(const char* fixture_name,
reflector_options.header_file_name = ReflectionHeaderName(fixture_name);
reflector_options.shader_name = "shader_name";

Compiler compiler(*fixture.get(), source_options, reflector_options);
Compiler compiler(fixture, source_options, reflector_options);
if (!compiler.IsValid()) {
VALIDATION_LOG << "Compilation failed: " << compiler.GetErrorMessages();
return false;
Expand Down
6 changes: 3 additions & 3 deletions impeller/compiler/impellerc_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bool Main(const fml::CommandLine& command_line) {
return false;
}

auto source_file_mapping =
std::shared_ptr<fml::FileMapping> source_file_mapping =
fml::FileMapping::CreateReadOnly(switches.source_file_name);
if (!source_file_mapping) {
std::cerr << "Could not open input file." << std::endl;
Expand Down Expand Up @@ -95,7 +95,7 @@ bool Main(const fml::CommandLine& command_line) {
sksl_reflector_options.target_platform = TargetPlatform::kSkSL;

Compiler sksl_compiler =
Compiler(*source_file_mapping, sksl_options, sksl_reflector_options);
Compiler(source_file_mapping, sksl_options, sksl_reflector_options);
if (!sksl_compiler.IsValid()) {
std::cerr << "Compilation to SkSL failed." << std::endl;
std::cerr << sksl_compiler.GetErrorMessages() << std::endl;
Expand All @@ -104,7 +104,7 @@ bool Main(const fml::CommandLine& command_line) {
sksl_mapping = sksl_compiler.GetSLShaderSource();
}

Compiler compiler(*source_file_mapping, options, reflector_options);
Compiler compiler(source_file_mapping, options, reflector_options);
if (!compiler.IsValid()) {
std::cerr << "Compilation failed." << std::endl;
std::cerr << compiler.GetErrorMessages() << std::endl;
Expand Down
7 changes: 4 additions & 3 deletions impeller/compiler/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ class AutoLogger {
FML_DISALLOW_COPY_AND_ASSIGN(AutoLogger);
};

#define COMPILER_ERROR \
::impeller::compiler::AutoLogger(error_stream_) << GetSourcePrefix()
#define COMPILER_ERROR(stream) \
::impeller::compiler::AutoLogger(stream) << GetSourcePrefix()

#define COMPILER_ERROR_NO_PREFIX ::impeller::compiler::AutoLogger(error_stream_)
#define COMPILER_ERROR_NO_PREFIX(stream) \
::impeller::compiler::AutoLogger(stream)

} // namespace compiler
} // namespace impeller
Loading

0 comments on commit b789b19

Please sign in to comment.