Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
8 changes: 6 additions & 2 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2947,8 +2947,10 @@ TEST_P(AiksTest, CanRenderClippedRuntimeEffects) {
GTEST_SKIP_("This backend doesn't support runtime effects.");
}

auto runtime_stage =
auto runtime_stages =
OpenAssetAsRuntimeStage("runtime_stage_example.frag.iplr");
auto runtime_stage = runtime_stages[RuntimeStageBackend::kMetal];
ASSERT_TRUE(runtime_stage);
ASSERT_TRUE(runtime_stage->IsDirty());

struct FragUniforms {
Expand Down Expand Up @@ -2980,7 +2982,9 @@ TEST_P(AiksTest, DrawPaintTransformsBounds) {
GTEST_SKIP_("This backend doesn't support runtime effects.");
}

auto runtime_stage = OpenAssetAsRuntimeStage("gradient.frag.iplr");
auto runtime_stages = OpenAssetAsRuntimeStage("gradient.frag.iplr");
auto runtime_stage = runtime_stages[RuntimeStageBackend::kMetal];
ASSERT_TRUE(runtime_stage);
ASSERT_TRUE(runtime_stage->IsDirty());

struct FragUniforms {
Expand Down
50 changes: 38 additions & 12 deletions impeller/compiler/impellerc_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "flutter/fml/file.h"
#include "flutter/fml/mapping.h"
#include "impeller/compiler/compiler.h"
#include "impeller/compiler/runtime_stage_data.h"
#include "impeller/compiler/shader_bundle.h"
#include "impeller/compiler/source_options.h"
#include "impeller/compiler/switches.h"
Expand All @@ -19,9 +20,9 @@
namespace impeller {
namespace compiler {

/// Run the shader compiler to geneate SkSL.
/// Run the shader compiler to geneate SkSL reflection data.
/// If there is an error, prints error text and returns `nullptr`.
static std::shared_ptr<fml::Mapping> CompileSkSL(
static std::shared_ptr<RuntimeStageData::Shader> CompileSkSL(
std::shared_ptr<fml::Mapping> source_file_mapping,
SourceOptions& options,
Reflector::Options& reflector_options) {
Expand All @@ -38,7 +39,7 @@ static std::shared_ptr<fml::Mapping> CompileSkSL(
std::cerr << sksl_compiler.GetErrorMessages() << std::endl;
return nullptr;
}
return sksl_compiler.GetSLShaderSource();
return sksl_compiler.GetReflector()->GetRuntimeStageShaderData();
}

/// Outputs artifacts for a single compiler invocation and option configuration.
Expand All @@ -52,11 +53,11 @@ static bool OutputArtifacts(Compiler& compiler,
/// 1. Invoke the compiler to generate SkSL if needed.
///

std::shared_ptr<fml::Mapping> sksl_mapping;
std::shared_ptr<RuntimeStageData::Shader> sksl_shader;
if (switches.iplr && TargetPlatformBundlesSkSL(switches.target_platform)) {
sksl_mapping =
sksl_shader =
CompileSkSL(std::move(source_file_mapping), options, reflector_options);
if (!sksl_mapping) {
if (!sksl_shader) {
return false;
}
}
Expand All @@ -74,17 +75,42 @@ static bool OutputArtifacts(Compiler& compiler,
std::cerr << "Could not create reflector." << std::endl;
return false;
}
auto stage_data = reflector->GetRuntimeStageData();
auto stage_data = reflector->GetRuntimeStageShaderData();
if (!stage_data) {
std::cerr << "Runtime stage information was nil." << std::endl;
return false;
}
if (sksl_mapping) {
stage_data->SetSkSLData(std::move(sksl_mapping));
RuntimeStageData stages;
if (sksl_shader) {
stages.AddShader(RuntimeStageBackend::kSkSL, sksl_shader);
}
auto stage_data_mapping = options.json_format
? stage_data->CreateJsonMapping()
: stage_data->CreateMapping();
switch (switches.target_platform) {
case TargetPlatform::kUnknown:
case TargetPlatform::kMetalDesktop:
case TargetPlatform::kMetalIOS:
case TargetPlatform::kOpenGLES:
case TargetPlatform::kOpenGLDesktop:
case TargetPlatform::kVulkan:
std::cerr << "TargetPlatform "
<< TargetPlatformToString(switches.target_platform)
<< " not supported for IPLR.";
return false;
case TargetPlatform::kRuntimeStageMetal:
stages.AddShader(RuntimeStageBackend::kMetal, stage_data);
break;
case TargetPlatform::kRuntimeStageGLES:
stages.AddShader(RuntimeStageBackend::kOpenGLES, stage_data);
break;
case TargetPlatform::kRuntimeStageVulkan:
stages.AddShader(RuntimeStageBackend::kVulkan, stage_data);
break;
Copy link
Member

@bdero bdero Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an FYI: once you get to the point of invoking the shader compiler multiple times for --iplr and packing multiple backends into one flatbuffer, you'll probably need to branch off and employ a similar approach to what happens for --shader-bundle and:

  • Avoid generating intermediates for, reflection headers, etc.
  • Remove all the unnecessary flags when iplr is enabled in the impellerc GN template.
  • Relax the restrictions in switches.cc for iplr mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I need to fix at least some of that as part of this PR. Looking into the failure on flutter_tester when we --enable-impeller

case TargetPlatform::kSkSL:
// Already handled above.
break;
}

auto stage_data_mapping = options.json_format ? stages.CreateJsonMapping()
: stages.CreateMapping();
if (!stage_data_mapping) {
std::cerr << "Runtime stage data could not be created." << std::endl;
return false;
Expand Down
26 changes: 13 additions & 13 deletions impeller/compiler/reflector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ Reflector::Reflector(Options options,
return;
}

runtime_stage_data_ = GenerateRuntimeStageData();
if (!runtime_stage_data_) {
runtime_stage_shader_ = GenerateRuntimeStageData();
if (!runtime_stage_shader_) {
return;
}

Expand Down Expand Up @@ -162,8 +162,9 @@ std::shared_ptr<fml::Mapping> Reflector::GetReflectionCC() const {
return reflection_cc_;
}

std::shared_ptr<RuntimeStageData> Reflector::GetRuntimeStageData() const {
return runtime_stage_data_;
std::shared_ptr<RuntimeStageData::Shader> Reflector::GetRuntimeStageShaderData()
const {
return runtime_stage_shader_;
}

std::optional<nlohmann::json> Reflector::GenerateTemplateArguments() const {
Expand Down Expand Up @@ -317,18 +318,17 @@ std::shared_ptr<fml::Mapping> Reflector::GenerateReflectionCC() const {
return InflateTemplate(kReflectionCCTemplate);
}

std::shared_ptr<RuntimeStageData> Reflector::GenerateRuntimeStageData() const {
std::shared_ptr<RuntimeStageData::Shader> Reflector::GenerateRuntimeStageData()
const {
const auto& entrypoints = compiler_->get_entry_points_and_stages();
if (entrypoints.size() != 1u) {
VALIDATION_LOG << "Single entrypoint not found.";
return nullptr;
}
auto data = std::make_shared<RuntimeStageData>(
options_.entry_point_name, //
entrypoints.front().execution_model, //
options_.target_platform //
);
data->SetShaderData(shader_data_);
auto data = std::make_unique<RuntimeStageData::Shader>();
data->entrypoint = options_.entry_point_name;
data->stage = entrypoints.front().execution_model;
data->shader = shader_data_;

// Sort the IR so that the uniforms are in declaration order.
std::vector<spirv_cross::ID> uniforms =
Expand All @@ -346,7 +346,7 @@ std::shared_ptr<RuntimeStageData> Reflector::GenerateRuntimeStageData() const {
uniform_description.columns = spir_type.columns;
uniform_description.bit_width = spir_type.width;
uniform_description.array_elements = GetArrayElements(spir_type);
data->AddUniformDescription(std::move(uniform_description));
data->uniforms.emplace_back(std::move(uniform_description));
}

// We only need to worry about storing vertex attributes.
Expand All @@ -373,7 +373,7 @@ std::shared_ptr<RuntimeStageData> Reflector::GenerateRuntimeStageData() const {
input_description.vec_size = type.vecsize;
input_description.columns = type.columns;
input_description.offset = offset.value_or(0u);
data->AddInputDescription(std::move(input_description));
data->inputs.emplace_back(std::move(input_description));
}
}

Expand Down
6 changes: 3 additions & 3 deletions impeller/compiler/reflector.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Reflector {

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

std::shared_ptr<RuntimeStageData> GetRuntimeStageData() const;
std::shared_ptr<RuntimeStageData::Shader> GetRuntimeStageShaderData() const;

private:
struct StructDefinition {
Expand Down Expand Up @@ -100,7 +100,7 @@ class Reflector {
std::unique_ptr<const nlohmann::json> template_arguments_;
std::shared_ptr<fml::Mapping> reflection_header_;
std::shared_ptr<fml::Mapping> reflection_cc_;
std::shared_ptr<RuntimeStageData> runtime_stage_data_;
std::shared_ptr<RuntimeStageData::Shader> runtime_stage_shader_;
bool is_valid_ = false;

std::optional<nlohmann::json> GenerateTemplateArguments() const;
Expand All @@ -109,7 +109,7 @@ class Reflector {

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

std::shared_ptr<RuntimeStageData> GenerateRuntimeStageData() const;
std::shared_ptr<RuntimeStageData::Shader> GenerateRuntimeStageData() const;

std::shared_ptr<fml::Mapping> InflateTemplate(std::string_view tmpl) const;

Expand Down
Loading