[Impeller] Make IPLR files multi-platform (flutter/engine#49253)

This is part of the work towards supporting OpenGLES and Vulkan for runtime stage shaders.

Removes some redundant work we had around SkSL. Now only bundles the shaders we actually ask for from the command line.

@bdero, we should figure out if this is the right approach for flutter_gpu.

With this change, the IPLR format goes from having a root table of shader related information to a root table of shader information per `sksl`, `metal`, `opengles`, and `vulkan` platforms. 

This may end up allowing us to revert https://github.com/flutter/engine/pull/47278, but I'm not sure I understand all the implications of that at this point.

I have run some but not all tests locally.
This commit is contained in:
Dan Field
2023-12-20 22:17:26 -08:00
committed by GitHub
parent b3b7451d1e
commit ae9289f5c1
36 changed files with 649 additions and 424 deletions

View File

@@ -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 {
@@ -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 {

View File

@@ -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"
@@ -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) {
@@ -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.
@@ -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;
}
}
@@ -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;
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;

View File

@@ -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;
}
@@ -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 {
@@ -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 =
@@ -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.
@@ -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));
}
}

View File

@@ -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 {
@@ -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;
@@ -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;

View File

@@ -6,39 +6,27 @@
#include <array>
#include <cstdint>
#include <memory>
#include <optional>
#include "impeller/core/runtime_types.h"
#include "inja/inja.hpp"
#include "impeller/base/validation.h"
#include "impeller/runtime_stage/runtime_stage_flatbuffers.h"
#include "runtime_stage_types_flatbuffers.h"
namespace impeller {
namespace compiler {
RuntimeStageData::RuntimeStageData(std::string entrypoint,
spv::ExecutionModel stage,
TargetPlatform target_platform)
: entrypoint_(std::move(entrypoint)),
stage_(stage),
target_platform_(target_platform) {}
RuntimeStageData::RuntimeStageData() = default;
RuntimeStageData::~RuntimeStageData() = default;
void RuntimeStageData::AddUniformDescription(UniformDescription uniform) {
uniforms_.emplace_back(std::move(uniform));
}
void RuntimeStageData::AddInputDescription(InputDescription input) {
inputs_.emplace_back(std::move(input));
}
void RuntimeStageData::SetShaderData(std::shared_ptr<fml::Mapping> shader) {
shader_ = std::move(shader);
}
void RuntimeStageData::SetSkSLData(std::shared_ptr<fml::Mapping> sksl) {
sksl_ = std::move(sksl);
void RuntimeStageData::AddShader(RuntimeStageBackend backend,
const std::shared_ptr<Shader>& data) {
FML_DCHECK(data_.find(backend) == data_.end());
data_[backend] = data;
}
static std::optional<fb::Stage> ToStage(spv::ExecutionModel stage) {
@@ -69,49 +57,6 @@ static std::optional<fb::Stage> ToJsonStage(spv::ExecutionModel stage) {
FML_UNREACHABLE();
}
static std::optional<fb::TargetPlatform> ToTargetPlatform(
TargetPlatform platform) {
switch (platform) {
case TargetPlatform::kUnknown:
case TargetPlatform::kMetalDesktop:
case TargetPlatform::kMetalIOS:
case TargetPlatform::kOpenGLES:
case TargetPlatform::kOpenGLDesktop:
case TargetPlatform::kVulkan:
return std::nullopt;
case TargetPlatform::kSkSL:
return fb::TargetPlatform::kSkSL;
case TargetPlatform::kRuntimeStageMetal:
return fb::TargetPlatform::kMetal;
case TargetPlatform::kRuntimeStageGLES:
return fb::TargetPlatform::kOpenGLES;
case TargetPlatform::kRuntimeStageVulkan:
return fb::TargetPlatform::kVulkan;
}
FML_UNREACHABLE();
}
static std::optional<uint32_t> ToJsonTargetPlatform(TargetPlatform platform) {
switch (platform) {
case TargetPlatform::kUnknown:
case TargetPlatform::kMetalDesktop:
case TargetPlatform::kMetalIOS:
case TargetPlatform::kOpenGLES:
case TargetPlatform::kOpenGLDesktop:
case TargetPlatform::kVulkan:
return std::nullopt;
case TargetPlatform::kSkSL:
return static_cast<uint32_t>(fb::TargetPlatform::kSkSL);
case TargetPlatform::kRuntimeStageMetal:
return static_cast<uint32_t>(fb::TargetPlatform::kMetal);
case TargetPlatform::kRuntimeStageGLES:
return static_cast<uint32_t>(fb::TargetPlatform::kOpenGLES);
case TargetPlatform::kRuntimeStageVulkan:
return static_cast<uint32_t>(fb::TargetPlatform::kVulkan);
}
FML_UNREACHABLE();
}
static std::optional<fb::UniformDataType> ToUniformType(
spirv_cross::SPIRType::BaseType type) {
switch (type) {
@@ -248,7 +193,7 @@ static const char* kStageKey = "stage";
static const char* kTargetPlatformKey = "target_platform";
static const char* kEntrypointKey = "entrypoint";
static const char* kUniformsKey = "uniforms";
static const char* kShaderKey = "sksl";
static const char* kShaderKey = "shader";
static const char* kUniformNameKey = "name";
static const char* kUniformLocationKey = "location";
static const char* kUniformTypeKey = "type";
@@ -257,71 +202,87 @@ static const char* kUniformColumnsKey = "columns";
static const char* kUniformBitWidthKey = "bit_width";
static const char* kUniformArrayElementsKey = "array_elements";
static std::string RuntimeStageBackendToString(RuntimeStageBackend backend) {
switch (backend) {
case RuntimeStageBackend::kSkSL:
return "sksl";
case RuntimeStageBackend::kMetal:
return "metal";
case RuntimeStageBackend::kOpenGLES:
return "opengles";
case RuntimeStageBackend::kVulkan:
return "vulkan";
}
}
std::shared_ptr<fml::Mapping> RuntimeStageData::CreateJsonMapping() const {
// Runtime Stage Data JSON format
// {
// "stage": 0,
// "target_platform": "",
// "entrypoint": "",
// "shader": "",
// "sksl": "",
// "uniforms": [
// {
// "name": "..",
// "location": 0,
// "type": 0,
// "rows": 0,
// "columns": 0,
// "bit_width": 0,
// "array_elements": 0,
// }
// ]
// "sksl": {
// "stage": 0,
// "entrypoint": "",
// "shader": "",
// "uniforms": [
// {
// "name": "..",
// "location": 0,
// "type": 0,
// "rows": 0,
// "columns": 0,
// "bit_width": 0,
// "array_elements": 0,
// }
// ]
// },
// "metal": ...
// },
nlohmann::json root;
const auto stage = ToJsonStage(stage_);
if (!stage.has_value()) {
VALIDATION_LOG << "Invalid runtime stage.";
return nullptr;
}
root[kStageKey] = static_cast<uint32_t>(stage.value());
for (const auto& kvp : data_) {
nlohmann::json platform_object;
const auto target_platform = ToJsonTargetPlatform(target_platform_);
if (!target_platform.has_value()) {
VALIDATION_LOG << "Invalid target platform for runtime stage.";
return nullptr;
}
root[kTargetPlatformKey] = target_platform.value();
if (shader_->GetSize() > 0u) {
std::string shader(reinterpret_cast<const char*>(shader_->GetMapping()),
shader_->GetSize());
root[kShaderKey] = shader.c_str();
}
auto& uniforms = root[kUniformsKey] = nlohmann::json::array_t{};
for (const auto& uniform : uniforms_) {
nlohmann::json uniform_object;
uniform_object[kUniformNameKey] = uniform.name.c_str();
uniform_object[kUniformLocationKey] = uniform.location;
uniform_object[kUniformRowsKey] = uniform.rows;
uniform_object[kUniformColumnsKey] = uniform.columns;
auto uniform_type = ToJsonType(uniform.type);
if (!uniform_type.has_value()) {
VALIDATION_LOG << "Invalid uniform type for runtime stage.";
const auto stage = ToJsonStage(kvp.second->stage);
if (!stage.has_value()) {
VALIDATION_LOG << "Invalid runtime stage.";
return nullptr;
}
platform_object[kStageKey] = static_cast<uint32_t>(stage.value());
platform_object[kEntrypointKey] = kvp.second->entrypoint;
uniform_object[kUniformTypeKey] = uniform_type.value();
uniform_object[kUniformBitWidthKey] = uniform.bit_width;
if (uniform.array_elements.has_value()) {
uniform_object[kUniformArrayElementsKey] = uniform.array_elements.value();
} else {
uniform_object[kUniformArrayElementsKey] = 0;
if (kvp.second->shader->GetSize() > 0u) {
std::string shader(
reinterpret_cast<const char*>(kvp.second->shader->GetMapping()),
kvp.second->shader->GetSize());
platform_object[kShaderKey] = shader.c_str();
}
uniforms.push_back(uniform_object);
auto& uniforms = platform_object[kUniformsKey] = nlohmann::json::array_t{};
for (const auto& uniform : kvp.second->uniforms) {
nlohmann::json uniform_object;
uniform_object[kUniformNameKey] = uniform.name.c_str();
uniform_object[kUniformLocationKey] = uniform.location;
uniform_object[kUniformRowsKey] = uniform.rows;
uniform_object[kUniformColumnsKey] = uniform.columns;
auto uniform_type = ToJsonType(uniform.type);
if (!uniform_type.has_value()) {
VALIDATION_LOG << "Invalid uniform type for runtime stage.";
return nullptr;
}
uniform_object[kUniformTypeKey] = uniform_type.value();
uniform_object[kUniformBitWidthKey] = uniform.bit_width;
if (uniform.array_elements.has_value()) {
uniform_object[kUniformArrayElementsKey] =
uniform.array_elements.value();
} else {
uniform_object[kUniformArrayElementsKey] = 0;
}
uniforms.push_back(uniform_object);
}
root[RuntimeStageBackendToString(kvp.first)] = platform_object;
}
auto json_string = std::make_shared<std::string>(root.dump(2u));
@@ -331,100 +292,106 @@ std::shared_ptr<fml::Mapping> RuntimeStageData::CreateJsonMapping() const {
json_string->size(), [json_string](auto, auto) {});
}
std::unique_ptr<fb::RuntimeStageT> RuntimeStageData::CreateFlatbuffer() const {
auto runtime_stage = std::make_unique<fb::RuntimeStageT>();
std::unique_ptr<fb::RuntimeStagesT> RuntimeStageData::CreateFlatbuffer() const {
// The high level object API is used here for writing to the buffer. This is
// just a convenience.
runtime_stage->entrypoint = entrypoint_;
const auto stage = ToStage(stage_);
if (!stage.has_value()) {
VALIDATION_LOG << "Invalid runtime stage.";
return nullptr;
}
runtime_stage->stage = stage.value();
const auto target_platform = ToTargetPlatform(target_platform_);
if (!target_platform.has_value()) {
VALIDATION_LOG << "Invalid target platform for runtime stage.";
return nullptr;
}
runtime_stage->target_platform = target_platform.value();
if (!shader_) {
VALIDATION_LOG << "No shader specified for runtime stage.";
return nullptr;
}
if (shader_->GetSize() > 0u) {
runtime_stage->shader = {shader_->GetMapping(),
shader_->GetMapping() + shader_->GetSize()};
}
// It is not an error for the SkSL to be ommitted.
if (sksl_ && sksl_->GetSize() > 0u) {
runtime_stage->sksl = {sksl_->GetMapping(),
sksl_->GetMapping() + sksl_->GetSize()};
}
for (const auto& uniform : uniforms_) {
auto desc = std::make_unique<fb::UniformDescriptionT>();
auto runtime_stages = std::make_unique<fb::RuntimeStagesT>();
desc->name = uniform.name;
if (desc->name.empty()) {
VALIDATION_LOG << "Uniform name cannot be empty.";
for (const auto& kvp : data_) {
auto runtime_stage = std::make_unique<fb::RuntimeStageT>();
runtime_stage->entrypoint = kvp.second->entrypoint;
const auto stage = ToStage(kvp.second->stage);
if (!stage.has_value()) {
VALIDATION_LOG << "Invalid runtime stage.";
return nullptr;
}
desc->location = uniform.location;
desc->rows = uniform.rows;
desc->columns = uniform.columns;
auto uniform_type = ToUniformType(uniform.type);
if (!uniform_type.has_value()) {
VALIDATION_LOG << "Invalid uniform type for runtime stage.";
runtime_stage->stage = stage.value();
if (!kvp.second->shader) {
VALIDATION_LOG << "No shader specified for runtime stage.";
return nullptr;
}
desc->type = uniform_type.value();
desc->bit_width = uniform.bit_width;
if (uniform.array_elements.has_value()) {
desc->array_elements = uniform.array_elements.value();
if (kvp.second->shader->GetSize() > 0u) {
runtime_stage->shader = {
kvp.second->shader->GetMapping(),
kvp.second->shader->GetMapping() + kvp.second->shader->GetSize()};
}
for (const auto& uniform : kvp.second->uniforms) {
auto desc = std::make_unique<fb::UniformDescriptionT>();
desc->name = uniform.name;
if (desc->name.empty()) {
VALIDATION_LOG << "Uniform name cannot be empty.";
return nullptr;
}
desc->location = uniform.location;
desc->rows = uniform.rows;
desc->columns = uniform.columns;
auto uniform_type = ToUniformType(uniform.type);
if (!uniform_type.has_value()) {
VALIDATION_LOG << "Invalid uniform type for runtime stage.";
return nullptr;
}
desc->type = uniform_type.value();
desc->bit_width = uniform.bit_width;
if (uniform.array_elements.has_value()) {
desc->array_elements = uniform.array_elements.value();
}
runtime_stage->uniforms.emplace_back(std::move(desc));
}
runtime_stage->uniforms.emplace_back(std::move(desc));
for (const auto& input : kvp.second->inputs) {
auto desc = std::make_unique<fb::StageInputT>();
desc->name = input.name;
if (desc->name.empty()) {
VALIDATION_LOG << "Stage input name cannot be empty.";
return nullptr;
}
desc->location = input.location;
desc->set = input.set;
desc->binding = input.binding;
auto input_type = ToInputType(input.type);
if (!input_type.has_value()) {
VALIDATION_LOG << "Invalid uniform type for runtime stage.";
return nullptr;
}
desc->type = input_type.value();
desc->bit_width = input.bit_width;
desc->vec_size = input.vec_size;
desc->columns = input.columns;
desc->offset = input.offset;
runtime_stage->inputs.emplace_back(std::move(desc));
}
switch (kvp.first) {
case RuntimeStageBackend::kSkSL:
runtime_stages->sksl = std::move(runtime_stage);
break;
case RuntimeStageBackend::kMetal:
runtime_stages->metal = std::move(runtime_stage);
break;
case RuntimeStageBackend::kOpenGLES:
runtime_stages->opengles = std::move(runtime_stage);
break;
case RuntimeStageBackend::kVulkan:
runtime_stages->vulkan = std::move(runtime_stage);
break;
}
}
for (const auto& input : inputs_) {
auto desc = std::make_unique<fb::StageInputT>();
desc->name = input.name;
if (desc->name.empty()) {
VALIDATION_LOG << "Stage input name cannot be empty.";
return nullptr;
}
desc->location = input.location;
desc->set = input.set;
desc->binding = input.binding;
auto input_type = ToInputType(input.type);
if (!input_type.has_value()) {
VALIDATION_LOG << "Invalid uniform type for runtime stage.";
return nullptr;
}
desc->type = input_type.value();
desc->bit_width = input.bit_width;
desc->vec_size = input.vec_size;
desc->columns = input.columns;
desc->offset = input.offset;
runtime_stage->inputs.emplace_back(std::move(desc));
}
return runtime_stage;
return runtime_stages;
}
std::shared_ptr<fml::Mapping> RuntimeStageData::CreateMapping() const {
auto runtime_stage = CreateFlatbuffer();
if (!runtime_stage) {
auto runtime_stages = CreateFlatbuffer();
if (!runtime_stages) {
return nullptr;
}
auto builder = std::make_shared<flatbuffers::FlatBufferBuilder>();
builder->Finish(fb::RuntimeStage::Pack(*builder.get(), runtime_stage.get()),
fb::RuntimeStageIdentifier());
builder->Finish(fb::RuntimeStages::Pack(*builder.get(), runtime_stages.get()),
fb::RuntimeStagesIdentifier());
return std::make_shared<fml::NonOwnedMapping>(builder->GetBufferPointer(),
builder->GetSize(),
[builder](auto, auto) {});

View File

@@ -11,6 +11,7 @@
#include "flutter/fml/macros.h"
#include "flutter/fml/mapping.h"
#include "impeller/compiler/types.h"
#include "impeller/core/runtime_types.h"
#include "runtime_stage_types_flatbuffers.h"
#include "spirv_parser.hpp"
@@ -42,34 +43,34 @@ struct InputDescription {
class RuntimeStageData {
public:
RuntimeStageData(std::string entrypoint,
spv::ExecutionModel stage,
TargetPlatform target_platform);
struct Shader {
Shader() = default;
std::string entrypoint;
spv::ExecutionModel stage;
std::vector<UniformDescription> uniforms;
std::vector<InputDescription> inputs;
std::shared_ptr<fml::Mapping> shader;
Shader(const Shader&) = delete;
Shader& operator=(const Shader&) = delete;
};
RuntimeStageData();
~RuntimeStageData();
void AddUniformDescription(UniformDescription uniform);
void AddShader(RuntimeStageBackend backend,
const std::shared_ptr<Shader>& data);
void AddInputDescription(InputDescription input);
void SetShaderData(std::shared_ptr<fml::Mapping> shader);
void SetSkSLData(std::shared_ptr<fml::Mapping> sksl);
std::unique_ptr<fb::RuntimeStageT> CreateFlatbuffer() const;
std::shared_ptr<fml::Mapping> CreateMapping() const;
std::unique_ptr<fb::RuntimeStagesT> CreateFlatbuffer() const;
std::shared_ptr<fml::Mapping> CreateJsonMapping() const;
std::shared_ptr<fml::Mapping> CreateMapping() const;
private:
const std::string entrypoint_;
const spv::ExecutionModel stage_;
const TargetPlatform target_platform_;
std::vector<UniformDescription> uniforms_;
std::vector<InputDescription> inputs_;
std::shared_ptr<fml::Mapping> shader_;
std::shared_ptr<fml::Mapping> sksl_;
std::map<RuntimeStageBackend, std::shared_ptr<Shader>> data_;
RuntimeStageData(const RuntimeStageData&) = delete;

View File

@@ -9,6 +9,7 @@
#include "impeller/compiler/types.h"
#include "impeller/compiler/utilities.h"
#include "impeller/runtime_stage/runtime_stage.h"
#include "impeller/shader_bundle/shader_bundle_flatbuffers.h"
#include "third_party/json/include/nlohmann/json.hpp"
@@ -122,14 +123,35 @@ static std::unique_ptr<fb::ShaderT> GenerateShaderFB(
return nullptr;
}
auto stage_data = reflector->GetRuntimeStageData();
auto stage_data = reflector->GetRuntimeStageShaderData();
if (!stage_data) {
std::cerr << "Runtime stage information was nil for bundled shader \""
<< shader_name << "\"." << std::endl;
return nullptr;
}
result->shader = stage_data->CreateFlatbuffer();
RuntimeStageData stages;
switch (options.target_platform) {
case TargetPlatform::kUnknown:
case TargetPlatform::kMetalDesktop:
case TargetPlatform::kMetalIOS:
case TargetPlatform::kOpenGLES:
case TargetPlatform::kOpenGLDesktop:
case TargetPlatform::kVulkan:
case TargetPlatform::kSkSL:
std::cerr << "Invalid target platform "
<< TargetPlatformToString(options.target_platform);
return nullptr;
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;
}
result->shader = stages.CreateFlatbuffer();
if (!result->shader) {
std::cerr << "Failed to create flatbuffer for bundled shader \""
<< shader_name << "\"." << std::endl;

View File

@@ -156,14 +156,14 @@ TEST(ShaderBundleTest, GenerateShaderBundleFlatbufferProducesCorrectResult) {
/// Verify vertex shader.
///
EXPECT_STREQ(vertex->shader->entrypoint.c_str(),
EXPECT_TRUE(vertex->shader->metal);
EXPECT_STREQ(vertex->shader->metal->entrypoint.c_str(),
"flutter_gpu_unlit_vertex_main");
EXPECT_EQ(vertex->shader->stage, fb::Stage::kVertex);
EXPECT_EQ(vertex->shader->target_platform, fb::TargetPlatform::kMetal);
EXPECT_EQ(vertex->shader->metal->stage, fb::Stage::kVertex);
// Inputs.
ASSERT_EQ(vertex->shader->inputs.size(), 1u);
const auto& v_in_position = vertex->shader->inputs[0];
ASSERT_EQ(vertex->shader->metal->inputs.size(), 1u);
const auto& v_in_position = vertex->shader->metal->inputs[0];
EXPECT_STREQ(v_in_position->name.c_str(), "position");
EXPECT_EQ(v_in_position->location, 0u);
EXPECT_EQ(v_in_position->set, 0u);
@@ -175,8 +175,8 @@ TEST(ShaderBundleTest, GenerateShaderBundleFlatbufferProducesCorrectResult) {
EXPECT_EQ(v_in_position->offset, 0u);
// Uniforms.
ASSERT_EQ(vertex->shader->uniforms.size(), 2u);
const auto* v_mvp = FindByName(vertex->shader->uniforms, "mvp");
ASSERT_EQ(vertex->shader->metal->uniforms.size(), 2u);
const auto* v_mvp = FindByName(vertex->shader->metal->uniforms, "mvp");
ASSERT_NE(v_mvp, nullptr);
EXPECT_EQ(v_mvp->location, 0u);
EXPECT_EQ(v_mvp->type, fb::UniformDataType::kFloat);
@@ -184,7 +184,7 @@ TEST(ShaderBundleTest, GenerateShaderBundleFlatbufferProducesCorrectResult) {
EXPECT_EQ(v_mvp->rows, 4u);
EXPECT_EQ(v_mvp->columns, 4u);
EXPECT_EQ(v_mvp->array_elements, 0u);
const auto* v_color = FindByName(vertex->shader->uniforms, "color");
const auto* v_color = FindByName(vertex->shader->metal->uniforms, "color");
ASSERT_NE(v_color, nullptr);
EXPECT_EQ(v_color->location, 1u);
EXPECT_EQ(v_color->type, fb::UniformDataType::kFloat);
@@ -197,16 +197,16 @@ TEST(ShaderBundleTest, GenerateShaderBundleFlatbufferProducesCorrectResult) {
/// Verify fragment shader.
///
EXPECT_STREQ(fragment->shader->entrypoint.c_str(),
EXPECT_TRUE(fragment->shader->metal);
EXPECT_STREQ(fragment->shader->metal->entrypoint.c_str(),
"flutter_gpu_unlit_fragment_main");
EXPECT_EQ(fragment->shader->stage, fb::Stage::kFragment);
EXPECT_EQ(fragment->shader->target_platform, fb::TargetPlatform::kMetal);
EXPECT_EQ(fragment->shader->metal->stage, fb::Stage::kFragment);
// Inputs (not recorded for fragment shaders).
ASSERT_EQ(fragment->shader->inputs.size(), 0u);
ASSERT_EQ(fragment->shader->metal->inputs.size(), 0u);
// Uniforms.
ASSERT_EQ(fragment->shader->inputs.size(), 0u);
ASSERT_EQ(fragment->shader->metal->inputs.size(), 0u);
}
} // namespace testing

View File

@@ -11,6 +11,13 @@
namespace impeller {
enum class RuntimeStageBackend {
kSkSL,
kMetal,
kOpenGLES,
kVulkan,
};
enum RuntimeUniformType {
kBoolean,
kSignedByte,

View File

@@ -2136,8 +2136,10 @@ TEST_P(EntityTest, RuntimeEffect) {
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());
bool first_frame = true;

View File

@@ -47,8 +47,7 @@ class GoldenPlaygroundTest
const char* fixture_name,
bool enable_mipmapping = false) const;
std::shared_ptr<RuntimeStage> OpenAssetAsRuntimeStage(
const char* asset_name) const;
RuntimeStage::Map OpenAssetAsRuntimeStage(const char* asset_name) const;
std::shared_ptr<Context> GetContext() const;

View File

@@ -167,17 +167,14 @@ std::shared_ptr<Texture> GoldenPlaygroundTest::CreateTextureForFixture(
return result;
}
std::shared_ptr<RuntimeStage> GoldenPlaygroundTest::OpenAssetAsRuntimeStage(
RuntimeStage::Map GoldenPlaygroundTest::OpenAssetAsRuntimeStage(
const char* asset_name) const {
auto fixture = flutter::testing::OpenFixtureAsMapping(asset_name);
const std::shared_ptr<fml::Mapping> fixture =
flutter::testing::OpenFixtureAsMapping(asset_name);
if (!fixture || fixture->GetSize() == 0) {
return nullptr;
return {};
}
auto stage = std::make_unique<RuntimeStage>(std::move(fixture));
if (!stage->IsValid()) {
return nullptr;
}
return stage;
return RuntimeStage::DecodeRuntimeStages(fixture);
}
std::shared_ptr<Context> GoldenPlaygroundTest::GetContext() const {

View File

@@ -42,10 +42,9 @@ std::shared_ptr<Texture> GoldenPlaygroundTest::CreateTextureForFixture(
bool enable_mipmapping) const {
return nullptr;
}
std::shared_ptr<RuntimeStage> GoldenPlaygroundTest::OpenAssetAsRuntimeStage(
RuntimeStage::Map GoldenPlaygroundTest::OpenAssetAsRuntimeStage(
const char* asset_name) const {
return nullptr;
return {};
}
std::shared_ptr<Context> GoldenPlaygroundTest::GetContext() const {

View File

@@ -41,19 +41,6 @@ std::unique_ptr<fml::Mapping> ComputePlaygroundTest::OpenAssetAsMapping(
return flutter::testing::OpenFixtureAsMapping(asset_name);
}
std::shared_ptr<RuntimeStage> ComputePlaygroundTest::OpenAssetAsRuntimeStage(
const char* asset_name) const {
auto fixture = flutter::testing::OpenFixtureAsMapping(asset_name);
if (!fixture || fixture->GetSize() == 0) {
return nullptr;
}
auto stage = std::make_unique<RuntimeStage>(std::move(fixture));
if (!stage->IsValid()) {
return nullptr;
}
return stage;
}
static std::string FormatWindowTitle(const std::string& test_name) {
std::stringstream stream;
stream << "Impeller Playground for '" << test_name << "' (Press ESC to quit)";

View File

@@ -32,9 +32,6 @@ class ComputePlaygroundTest
std::unique_ptr<fml::Mapping> OpenAssetAsMapping(
std::string asset_name) const override;
std::shared_ptr<RuntimeStage> OpenAssetAsRuntimeStage(
const char* asset_name) const;
// |Playground|
std::string GetWindowTitle() const override;

View File

@@ -46,17 +46,14 @@ std::unique_ptr<fml::Mapping> PlaygroundTest::OpenAssetAsMapping(
return flutter::testing::OpenFixtureAsMapping(asset_name);
}
std::shared_ptr<RuntimeStage> PlaygroundTest::OpenAssetAsRuntimeStage(
RuntimeStage::Map PlaygroundTest::OpenAssetAsRuntimeStage(
const char* asset_name) const {
auto fixture = flutter::testing::OpenFixtureAsMapping(asset_name);
const std::shared_ptr<fml::Mapping> fixture =
flutter::testing::OpenFixtureAsMapping(asset_name);
if (!fixture || fixture->GetSize() == 0) {
return nullptr;
return {};
}
auto stage = std::make_unique<RuntimeStage>(std::move(fixture));
if (!stage->IsValid()) {
return nullptr;
}
return stage;
return RuntimeStage::DecodeRuntimeStages(fixture);
}
static std::string FormatWindowTitle(const std::string& test_name) {

View File

@@ -37,8 +37,7 @@ class PlaygroundTest : public Playground,
std::unique_ptr<fml::Mapping> OpenAssetAsMapping(
std::string asset_name) const override;
std::shared_ptr<RuntimeStage> OpenAssetAsRuntimeStage(
const char* asset_name) const;
RuntimeStage::Map OpenAssetAsRuntimeStage(const char* asset_name) const;
// |Playground|
std::string GetWindowTitle() const override;

View File

@@ -5,9 +5,12 @@
#include "impeller/runtime_stage/runtime_stage.h"
#include <array>
#include <memory>
#include "fml/mapping.h"
#include "impeller/base/validation.h"
#include "impeller/runtime_stage/runtime_stage_flatbuffers.h"
#include "runtime_stage_types_flatbuffers.h"
namespace impeller {
@@ -55,26 +58,44 @@ static RuntimeShaderStage ToShaderStage(fb::Stage stage) {
FML_UNREACHABLE();
}
RuntimeStage::RuntimeStage(std::shared_ptr<fml::Mapping> payload)
: payload_(std::move(payload)) {
if (payload_ == nullptr || !payload_->GetMapping()) {
return;
}
if (!fb::RuntimeStageBufferHasIdentifier(payload_->GetMapping())) {
return;
}
Setup(fb::GetRuntimeStage(payload_->GetMapping()));
}
RuntimeStage::RuntimeStage(const fb::RuntimeStage* runtime_stage) {
Setup(runtime_stage);
}
void RuntimeStage::Setup(const fb::RuntimeStage* runtime_stage) {
std::unique_ptr<RuntimeStage> RuntimeStage::RuntimeStageIfPresent(
const fb::RuntimeStage* runtime_stage,
const std::shared_ptr<fml::Mapping>& payload) {
if (!runtime_stage) {
return;
return nullptr;
}
return std::unique_ptr<RuntimeStage>(
new RuntimeStage(runtime_stage, payload));
}
RuntimeStage::Map RuntimeStage::DecodeRuntimeStages(
const std::shared_ptr<fml::Mapping>& payload) {
if (payload == nullptr || !payload->GetMapping()) {
return {};
}
if (!fb::RuntimeStagesBufferHasIdentifier(payload->GetMapping())) {
return {};
}
auto raw_stages = fb::GetRuntimeStages(payload->GetMapping());
return {
{RuntimeStageBackend::kSkSL,
RuntimeStageIfPresent(raw_stages->sksl(), payload)},
{RuntimeStageBackend::kMetal,
RuntimeStageIfPresent(raw_stages->metal(), payload)},
{RuntimeStageBackend::kOpenGLES,
RuntimeStageIfPresent(raw_stages->opengles(), payload)},
{RuntimeStageBackend::kVulkan,
RuntimeStageIfPresent(raw_stages->vulkan(), payload)},
};
}
RuntimeStage::RuntimeStage(const fb::RuntimeStage* runtime_stage,
const std::shared_ptr<fml::Mapping>& payload)
: payload_(payload) {
FML_DCHECK(runtime_stage);
stage_ = ToShaderStage(runtime_stage->stage());
entrypoint_ = runtime_stage->entrypoint()->str();
@@ -99,14 +120,6 @@ void RuntimeStage::Setup(const fb::RuntimeStage* runtime_stage) {
[payload = payload_](auto, auto) {} //
);
if (runtime_stage->sksl()) {
sksl_mapping_ = std::make_shared<fml::NonOwnedMapping>(
runtime_stage->sksl()->data(), //
runtime_stage->sksl()->size(), //
[payload = payload_](auto, auto) {} //
);
}
is_valid_ = true;
}
@@ -122,10 +135,6 @@ const std::shared_ptr<fml::Mapping>& RuntimeStage::GetCodeMapping() const {
return code_mapping_;
}
const std::shared_ptr<fml::Mapping>& RuntimeStage::GetSkSLMapping() const {
return sksl_mapping_;
}
const std::vector<RuntimeUniformDescription>& RuntimeStage::GetUniforms()
const {
return uniforms_;

View File

@@ -6,5 +6,5 @@ include "runtime_stage_types.fbs";
namespace impeller.fb;
root_type RuntimeStage;
root_type RuntimeStages;
file_identifier "IPLR";

View File

@@ -5,6 +5,7 @@
#ifndef FLUTTER_IMPELLER_RUNTIME_STAGE_RUNTIME_STAGE_H_
#define FLUTTER_IMPELLER_RUNTIME_STAGE_RUNTIME_STAGE_H_
#include <map>
#include <memory>
#include <string>
@@ -18,10 +19,11 @@ namespace impeller {
class RuntimeStage {
public:
explicit RuntimeStage(std::shared_ptr<fml::Mapping> payload);
explicit RuntimeStage(const fb::RuntimeStage* runtime_stage);
using Map = std::map<RuntimeStageBackend, std::shared_ptr<RuntimeStage>>;
static Map DecodeRuntimeStages(const std::shared_ptr<fml::Mapping>& payload);
RuntimeStage(const fb::RuntimeStage* runtime_stage,
const std::shared_ptr<fml::Mapping>& payload);
~RuntimeStage();
RuntimeStage(RuntimeStage&&);
RuntimeStage& operator=(RuntimeStage&&);
@@ -38,26 +40,25 @@ class RuntimeStage {
const std::shared_ptr<fml::Mapping>& GetCodeMapping() const;
const std::shared_ptr<fml::Mapping>& GetSkSLMapping() const;
bool IsDirty() const;
void SetClean();
private:
RuntimeShaderStage stage_ = RuntimeShaderStage::kVertex;
std::shared_ptr<fml::Mapping> payload_;
RuntimeShaderStage stage_ = RuntimeShaderStage::kVertex;
std::string entrypoint_;
std::shared_ptr<fml::Mapping> code_mapping_;
std::shared_ptr<fml::Mapping> sksl_mapping_;
std::vector<RuntimeUniformDescription> uniforms_;
bool is_valid_ = false;
bool is_dirty_ = true;
void Setup(const fb::RuntimeStage* runtime_stage);
RuntimeStage(const RuntimeStage&) = delete;
static std::unique_ptr<RuntimeStage> RuntimeStageIfPresent(
const fb::RuntimeStage* runtime_stage,
const std::shared_ptr<fml::Mapping>& payload);
RuntimeStage& operator=(const RuntimeStage&) = delete;
};

View File

@@ -10,13 +10,6 @@ enum Stage:byte {
kCompute,
}
enum TargetPlatform:byte {
kMetal,
kOpenGLES,
kSkSL,
kVulkan,
}
// The subset of impeller::ShaderType that may be used for uniform bindings.
enum UniformDataType:uint32 {
kBoolean,
@@ -75,10 +68,15 @@ table StageInput {
table RuntimeStage {
stage: Stage;
target_platform: TargetPlatform;
entrypoint: string;
inputs: [StageInput];
uniforms: [UniformDescription];
shader: [ubyte];
sksl: [ubyte];
}
table RuntimeStages {
sksl: RuntimeStage;
metal: RuntimeStage;
opengles: RuntimeStage;
vulkan: RuntimeStage;
}

View File

@@ -24,18 +24,19 @@ using RuntimeStageTest = RuntimeStagePlayground;
INSTANTIATE_PLAYGROUND_SUITE(RuntimeStageTest);
TEST(RuntimeStageTest, CanReadValidBlob) {
auto fixture =
const std::shared_ptr<fml::Mapping> fixture =
flutter::testing::OpenFixtureAsMapping("ink_sparkle.frag.iplr");
ASSERT_TRUE(fixture);
ASSERT_GT(fixture->GetSize(), 0u);
RuntimeStage stage(std::move(fixture));
ASSERT_TRUE(stage.IsValid());
ASSERT_EQ(stage.GetShaderStage(), RuntimeShaderStage::kFragment);
auto stages = RuntimeStage::DecodeRuntimeStages(fixture);
auto stage = stages[RuntimeStageBackend::kMetal];
ASSERT_TRUE(stage->IsValid());
ASSERT_EQ(stage->GetShaderStage(), RuntimeShaderStage::kFragment);
}
TEST(RuntimeStageTest, CanRejectInvalidBlob) {
ScopedValidationDisable disable_validation;
auto fixture =
const std::shared_ptr<fml::Mapping> fixture =
flutter::testing::OpenFixtureAsMapping("ink_sparkle.frag.iplr");
ASSERT_TRUE(fixture);
auto junk_allocation = std::make_shared<Allocation>();
@@ -43,20 +44,23 @@ TEST(RuntimeStageTest, CanRejectInvalidBlob) {
// Not meant to be secure. Just reject obviously bad blobs using magic
// numbers.
::memset(junk_allocation->GetBuffer(), 127, junk_allocation->GetLength());
RuntimeStage stage(CreateMappingFromAllocation(junk_allocation));
ASSERT_FALSE(stage.IsValid());
auto stages = RuntimeStage::DecodeRuntimeStages(
CreateMappingFromAllocation(junk_allocation));
ASSERT_FALSE(stages[RuntimeStageBackend::kMetal]);
}
TEST(RuntimeStageTest, CanReadUniforms) {
auto fixture =
const std::shared_ptr<fml::Mapping> fixture =
flutter::testing::OpenFixtureAsMapping("ink_sparkle.frag.iplr");
ASSERT_TRUE(fixture);
ASSERT_GT(fixture->GetSize(), 0u);
RuntimeStage stage(std::move(fixture));
ASSERT_TRUE(stage.IsValid());
ASSERT_EQ(stage.GetUniforms().size(), 17u);
auto stages = RuntimeStage::DecodeRuntimeStages(fixture);
auto stage = stages[RuntimeStageBackend::kMetal];
ASSERT_TRUE(stage->IsValid());
ASSERT_EQ(stage->GetUniforms().size(), 17u);
{
auto uni = stage.GetUniform("u_color");
auto uni = stage->GetUniform("u_color");
ASSERT_NE(uni, nullptr);
ASSERT_EQ(uni->dimensions.rows, 4u);
ASSERT_EQ(uni->dimensions.cols, 1u);
@@ -64,7 +68,7 @@ TEST(RuntimeStageTest, CanReadUniforms) {
ASSERT_EQ(uni->type, RuntimeUniformType::kFloat);
}
{
auto uni = stage.GetUniform("u_alpha");
auto uni = stage->GetUniform("u_alpha");
ASSERT_NE(uni, nullptr);
ASSERT_EQ(uni->dimensions.rows, 1u);
ASSERT_EQ(uni->dimensions.cols, 1u);
@@ -72,7 +76,7 @@ TEST(RuntimeStageTest, CanReadUniforms) {
ASSERT_EQ(uni->type, RuntimeUniformType::kFloat);
}
{
auto uni = stage.GetUniform("u_sparkle_color");
auto uni = stage->GetUniform("u_sparkle_color");
ASSERT_NE(uni, nullptr);
ASSERT_EQ(uni->dimensions.rows, 4u);
ASSERT_EQ(uni->dimensions.cols, 1u);
@@ -80,7 +84,7 @@ TEST(RuntimeStageTest, CanReadUniforms) {
ASSERT_EQ(uni->type, RuntimeUniformType::kFloat);
}
{
auto uni = stage.GetUniform("u_sparkle_alpha");
auto uni = stage->GetUniform("u_sparkle_alpha");
ASSERT_NE(uni, nullptr);
ASSERT_EQ(uni->dimensions.rows, 1u);
ASSERT_EQ(uni->dimensions.cols, 1u);
@@ -88,7 +92,7 @@ TEST(RuntimeStageTest, CanReadUniforms) {
ASSERT_EQ(uni->type, RuntimeUniformType::kFloat);
}
{
auto uni = stage.GetUniform("u_blur");
auto uni = stage->GetUniform("u_blur");
ASSERT_NE(uni, nullptr);
ASSERT_EQ(uni->dimensions.rows, 1u);
ASSERT_EQ(uni->dimensions.cols, 1u);
@@ -96,7 +100,7 @@ TEST(RuntimeStageTest, CanReadUniforms) {
ASSERT_EQ(uni->type, RuntimeUniformType::kFloat);
}
{
auto uni = stage.GetUniform("u_radius_scale");
auto uni = stage->GetUniform("u_radius_scale");
ASSERT_NE(uni, nullptr);
ASSERT_EQ(uni->dimensions.rows, 1u);
ASSERT_EQ(uni->dimensions.cols, 1u);
@@ -104,7 +108,7 @@ TEST(RuntimeStageTest, CanReadUniforms) {
ASSERT_EQ(uni->type, RuntimeUniformType::kFloat);
}
{
auto uni = stage.GetUniform("u_max_radius");
auto uni = stage->GetUniform("u_max_radius");
ASSERT_NE(uni, nullptr);
ASSERT_EQ(uni->dimensions.rows, 1u);
ASSERT_EQ(uni->dimensions.cols, 1u);
@@ -112,7 +116,7 @@ TEST(RuntimeStageTest, CanReadUniforms) {
ASSERT_EQ(uni->type, RuntimeUniformType::kFloat);
}
{
auto uni = stage.GetUniform("u_resolution_scale");
auto uni = stage->GetUniform("u_resolution_scale");
ASSERT_NE(uni, nullptr);
ASSERT_EQ(uni->dimensions.rows, 2u);
ASSERT_EQ(uni->dimensions.cols, 1u);
@@ -120,7 +124,7 @@ TEST(RuntimeStageTest, CanReadUniforms) {
ASSERT_EQ(uni->type, RuntimeUniformType::kFloat);
}
{
auto uni = stage.GetUniform("u_noise_scale");
auto uni = stage->GetUniform("u_noise_scale");
ASSERT_NE(uni, nullptr);
ASSERT_EQ(uni->dimensions.rows, 2u);
ASSERT_EQ(uni->dimensions.cols, 1u);
@@ -128,7 +132,7 @@ TEST(RuntimeStageTest, CanReadUniforms) {
ASSERT_EQ(uni->type, RuntimeUniformType::kFloat);
}
{
auto uni = stage.GetUniform("u_noise_phase");
auto uni = stage->GetUniform("u_noise_phase");
ASSERT_NE(uni, nullptr);
ASSERT_EQ(uni->dimensions.rows, 1u);
ASSERT_EQ(uni->dimensions.cols, 1u);
@@ -137,7 +141,7 @@ TEST(RuntimeStageTest, CanReadUniforms) {
}
{
auto uni = stage.GetUniform("u_circle1");
auto uni = stage->GetUniform("u_circle1");
ASSERT_NE(uni, nullptr);
ASSERT_EQ(uni->dimensions.rows, 2u);
ASSERT_EQ(uni->dimensions.cols, 1u);
@@ -145,7 +149,7 @@ TEST(RuntimeStageTest, CanReadUniforms) {
ASSERT_EQ(uni->type, RuntimeUniformType::kFloat);
}
{
auto uni = stage.GetUniform("u_circle2");
auto uni = stage->GetUniform("u_circle2");
ASSERT_NE(uni, nullptr);
ASSERT_EQ(uni->dimensions.rows, 2u);
ASSERT_EQ(uni->dimensions.cols, 1u);
@@ -153,7 +157,7 @@ TEST(RuntimeStageTest, CanReadUniforms) {
ASSERT_EQ(uni->type, RuntimeUniformType::kFloat);
}
{
auto uni = stage.GetUniform("u_circle3");
auto uni = stage->GetUniform("u_circle3");
ASSERT_NE(uni, nullptr);
ASSERT_EQ(uni->dimensions.rows, 2u);
ASSERT_EQ(uni->dimensions.cols, 1u);
@@ -161,7 +165,7 @@ TEST(RuntimeStageTest, CanReadUniforms) {
ASSERT_EQ(uni->type, RuntimeUniformType::kFloat);
}
{
auto uni = stage.GetUniform("u_rotation1");
auto uni = stage->GetUniform("u_rotation1");
ASSERT_NE(uni, nullptr);
ASSERT_EQ(uni->dimensions.rows, 2u);
ASSERT_EQ(uni->dimensions.cols, 1u);
@@ -169,7 +173,7 @@ TEST(RuntimeStageTest, CanReadUniforms) {
ASSERT_EQ(uni->type, RuntimeUniformType::kFloat);
}
{
auto uni = stage.GetUniform("u_rotation2");
auto uni = stage->GetUniform("u_rotation2");
ASSERT_NE(uni, nullptr);
ASSERT_EQ(uni->dimensions.rows, 2u);
ASSERT_EQ(uni->dimensions.cols, 1u);
@@ -177,7 +181,7 @@ TEST(RuntimeStageTest, CanReadUniforms) {
ASSERT_EQ(uni->type, RuntimeUniformType::kFloat);
}
{
auto uni = stage.GetUniform("u_rotation3");
auto uni = stage->GetUniform("u_rotation3");
ASSERT_NE(uni, nullptr);
ASSERT_EQ(uni->dimensions.rows, 2u);
ASSERT_EQ(uni->dimensions.cols, 1u);
@@ -190,35 +194,36 @@ TEST_P(RuntimeStageTest, CanRegisterStage) {
if (GetParam() != PlaygroundBackend::kMetal) {
GTEST_SKIP_("Skipped: https://github.com/flutter/flutter/issues/105538");
}
auto fixture =
const std::shared_ptr<fml::Mapping> fixture =
flutter::testing::OpenFixtureAsMapping("ink_sparkle.frag.iplr");
ASSERT_TRUE(fixture);
ASSERT_GT(fixture->GetSize(), 0u);
RuntimeStage stage(std::move(fixture));
ASSERT_TRUE(stage.IsValid());
auto stages = RuntimeStage::DecodeRuntimeStages(fixture);
auto stage = stages[RuntimeStageBackend::kMetal];
ASSERT_TRUE(stage->IsValid());
std::promise<bool> registration;
auto future = registration.get_future();
auto library = GetContext()->GetShaderLibrary();
library->RegisterFunction(
stage.GetEntrypoint(), //
ToShaderStage(stage.GetShaderStage()), //
stage.GetCodeMapping(), //
stage->GetEntrypoint(), //
ToShaderStage(stage->GetShaderStage()), //
stage->GetCodeMapping(), //
fml::MakeCopyable([reg = std::move(registration)](bool result) mutable {
reg.set_value(result);
}));
ASSERT_TRUE(future.get());
{
auto function =
library->GetFunction(stage.GetEntrypoint(), ShaderStage::kFragment);
library->GetFunction(stage->GetEntrypoint(), ShaderStage::kFragment);
ASSERT_NE(function, nullptr);
}
// Check if unregistering works.
library->UnregisterFunction(stage.GetEntrypoint(), ShaderStage::kFragment);
library->UnregisterFunction(stage->GetEntrypoint(), ShaderStage::kFragment);
{
auto function =
library->GetFunction(stage.GetEntrypoint(), ShaderStage::kFragment);
library->GetFunction(stage->GetEntrypoint(), ShaderStage::kFragment);
ASSERT_EQ(function, nullptr);
}
}
@@ -227,7 +232,10 @@ TEST_P(RuntimeStageTest, CanCreatePipelineFromRuntimeStage) {
if (GetParam() != PlaygroundBackend::kMetal) {
GTEST_SKIP_("Skipped: https://github.com/flutter/flutter/issues/105538");
}
auto stage = OpenAssetAsRuntimeStage("ink_sparkle.frag.iplr");
auto stages = OpenAssetAsRuntimeStage("ink_sparkle.frag.iplr");
auto stage = stages[RuntimeStageBackend::kMetal];
ASSERT_TRUE(stage);
ASSERT_NE(stage, nullptr);
ASSERT_TRUE(RegisterStage(*stage));
auto library = GetContext()->GetShaderLibrary();

View File

@@ -8,7 +8,7 @@ namespace impeller.fb;
table Shader {
name: string;
shader: RuntimeStage;
shader: RuntimeStages;
}
table ShaderBundle {

View File

@@ -123,8 +123,26 @@ fml::RefPtr<ShaderLibrary> ShaderLibrary::MakeFromFlatbuffer(
ShaderLibrary::ShaderMap shader_map;
for (const auto* bundled_shader : *bundle->shaders()) {
const impeller::fb::RuntimeStage* runtime_stage = bundled_shader->shader();
impeller::RuntimeStage stage(runtime_stage);
auto* runtime_stages = bundled_shader->shader();
const impeller::fb::RuntimeStage* runtime_stage = nullptr;
auto backend = UIDartState::Current()->GetRuntimeStageBackend();
switch (backend) {
case impeller::RuntimeStageBackend::kSkSL:
FML_LOG(ERROR) << "Cannot target SkSL";
return nullptr;
case impeller::RuntimeStageBackend::kMetal:
runtime_stage = runtime_stages->metal();
break;
case impeller::RuntimeStageBackend::kOpenGLES:
runtime_stage = runtime_stages->opengles();
break;
case impeller::RuntimeStageBackend::kVulkan:
runtime_stage = runtime_stages->vulkan();
break;
}
impeller::RuntimeStage stage(runtime_stage, payload);
std::shared_ptr<impeller::VertexDescriptor> vertex_descriptor = nullptr;
if (stage.GetShaderStage() == impeller::RuntimeShaderStage::kVertex) {

View File

@@ -15,6 +15,7 @@
#include "flutter/lib/ui/ui_dart_state.h"
#include "flutter/lib/ui/window/platform_configuration.h"
#include "impeller/core/runtime_types.h"
#include "third_party/skia/include/core/SkString.h"
#include "third_party/tonic/converter/dart_converter.h"
#include "third_party/tonic/dart_args.h"
@@ -26,6 +27,20 @@ namespace flutter {
IMPLEMENT_WRAPPERTYPEINFO(ui, FragmentProgram);
static std::string RuntimeStageBackendToString(
impeller::RuntimeStageBackend backend) {
switch (backend) {
case impeller::RuntimeStageBackend::kSkSL:
return "SkSL";
case impeller::RuntimeStageBackend::kMetal:
return "Metal";
case impeller::RuntimeStageBackend::kOpenGLES:
return "OpenGLES";
case impeller::RuntimeStageBackend::kVulkan:
return "Vulkan";
}
}
std::string FragmentProgram::initFromAsset(const std::string& asset_name) {
FML_TRACE_EVENT("flutter", "FragmentProgram::initFromAsset", "asset",
asset_name);
@@ -38,15 +53,34 @@ std::string FragmentProgram::initFromAsset(const std::string& asset_name) {
return std::string("Asset '") + asset_name + std::string("' not found");
}
auto runtime_stage = impeller::RuntimeStage(std::move(data));
if (!runtime_stage.IsValid()) {
auto runtime_stages =
impeller::RuntimeStage::DecodeRuntimeStages(std::move(data));
if (runtime_stages.empty()) {
return std::string("Asset '") + asset_name +
std::string("' does not contain valid shader data.");
std::string("' does not contain any shader data.");
}
auto backend = UIDartState::Current()->GetRuntimeStageBackend();
auto runtime_stage = runtime_stages[backend];
if (!runtime_stage) {
std::ostringstream stream;
stream << "Asset '" << asset_name
<< "' does not contain appropriate runtime stage data for current "
"backend ("
<< RuntimeStageBackendToString(backend) << ")." << std::endl
<< "Found stages: ";
for (const auto& kvp : runtime_stages) {
if (kvp.second) {
stream << RuntimeStageBackendToString(kvp.first) << " ";
}
}
return stream.str();
}
int sampled_image_count = 0;
size_t other_uniforms_bytes = 0;
for (const auto& uniform_description : runtime_stage.GetUniforms()) {
for (const auto& uniform_description : runtime_stage->GetUniforms()) {
if (uniform_description.type ==
impeller::RuntimeUniformType::kSampledImage) {
sampled_image_count++;
@@ -56,10 +90,9 @@ std::string FragmentProgram::initFromAsset(const std::string& asset_name) {
}
if (UIDartState::Current()->IsImpellerEnabled()) {
runtime_effect_ = DlRuntimeEffect::MakeImpeller(
std::make_unique<impeller::RuntimeStage>(std::move(runtime_stage)));
runtime_effect_ = DlRuntimeEffect::MakeImpeller(std::move(runtime_stage));
} else {
const auto& code_mapping = runtime_stage.GetSkSLMapping();
const auto& code_mapping = runtime_stage->GetCodeMapping();
auto code_size = code_mapping->GetSize();
const char* sksl =
reinterpret_cast<const char*>(code_mapping->GetMapping());

View File

@@ -40,7 +40,8 @@ UIDartState::Context::Context(
std::string advisory_script_entrypoint,
std::shared_ptr<VolatilePathTracker> volatile_path_tracker,
std::shared_ptr<fml::ConcurrentTaskRunner> concurrent_task_runner,
bool enable_impeller)
bool enable_impeller,
impeller::RuntimeStageBackend runtime_stage_backend)
: task_runners(task_runners),
snapshot_delegate(std::move(snapshot_delegate)),
io_manager(std::move(io_manager)),
@@ -51,7 +52,8 @@ UIDartState::Context::Context(
advisory_script_entrypoint(std::move(advisory_script_entrypoint)),
volatile_path_tracker(std::move(volatile_path_tracker)),
concurrent_task_runner(std::move(concurrent_task_runner)),
enable_impeller(enable_impeller) {}
enable_impeller(enable_impeller),
runtime_stage_backend(runtime_stage_backend) {}
UIDartState::UIDartState(
TaskObserverAdd add_callback,
@@ -85,6 +87,10 @@ bool UIDartState::IsImpellerEnabled() const {
return context_.enable_impeller;
}
impeller::RuntimeStageBackend UIDartState::GetRuntimeStageBackend() const {
return context_.runtime_stage_backend;
}
void UIDartState::DidSetIsolate() {
main_port_ = Dart_GetMainPortId();
std::ostringstream debug_name;

View File

@@ -20,6 +20,7 @@
#include "flutter/lib/ui/snapshot_delegate.h"
#include "flutter/lib/ui/volatile_path_tracker.h"
#include "flutter/shell/common/platform_message_handler.h"
#include "impeller/runtime_stage/runtime_stage.h"
#include "third_party/dart/runtime/include/dart_api.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "third_party/tonic/dart_microtask_queue.h"
@@ -54,7 +55,8 @@ class UIDartState : public tonic::DartState {
std::string advisory_script_entrypoint,
std::shared_ptr<VolatilePathTracker> volatile_path_tracker,
std::shared_ptr<fml::ConcurrentTaskRunner> concurrent_task_runner,
bool enable_impeller);
bool enable_impeller,
impeller::RuntimeStageBackend runtime_stage_backend);
/// The task runners used by the shell hosting this runtime controller. This
/// may be used by the isolate to scheduled asynchronous texture uploads or
@@ -99,6 +101,9 @@ class UIDartState : public tonic::DartState {
/// Whether Impeller is enabled or not.
bool enable_impeller = false;
/// The expected backend for runtime stage shaders.
impeller::RuntimeStageBackend runtime_stage_backend;
};
Dart_Port main_port() const { return main_port_; }
@@ -163,6 +168,9 @@ class UIDartState : public tonic::DartState {
/// Whether Impeller is enabled for this application.
bool IsImpellerEnabled() const;
/// The expected type for runtime stage shaders.
impeller::RuntimeStageBackend GetRuntimeStageBackend() const;
protected:
UIDartState(TaskObserverAdd add_callback,
TaskObserverRemove remove_callback,

View File

@@ -63,7 +63,7 @@ std::unique_ptr<RuntimeController> RuntimeController::Spawn(
std::move(image_decoder), std::move(image_generator_registry),
std::move(advisory_script_uri), std::move(advisory_script_entrypoint),
context_.volatile_path_tracker, context_.concurrent_task_runner,
context_.enable_impeller};
context_.enable_impeller, context_.runtime_stage_backend};
auto result =
std::make_unique<RuntimeController>(p_client, //
vm_, //

View File

@@ -18,6 +18,7 @@
#include "flutter/shell/common/animator.h"
#include "flutter/shell/common/platform_view.h"
#include "flutter/shell/common/shell.h"
#include "impeller/runtime_stage/runtime_stage.h"
#include "rapidjson/document.h"
#include "third_party/dart/runtime/include/dart_tools_api.h"
@@ -74,7 +75,8 @@ Engine::Engine(Delegate& delegate,
fml::RefPtr<SkiaUnrefQueue> unref_queue,
fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate,
std::shared_ptr<VolatilePathTracker> volatile_path_tracker,
const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch)
const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch,
impeller::RuntimeStageBackend runtime_stage_type)
: Engine(delegate,
dispatcher_maker,
vm.GetConcurrentWorkerTaskRunner(),
@@ -106,6 +108,7 @@ Engine::Engine(Delegate& delegate,
std::move(volatile_path_tracker), // volatile path tracker
vm.GetConcurrentWorkerTaskRunner(), // concurrent task runner
settings_.enable_impeller, // enable impeller
runtime_stage_type, // runtime stage type
});
}

View File

@@ -399,7 +399,9 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate {
fml::RefPtr<SkiaUnrefQueue> unref_queue,
fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate,
std::shared_ptr<VolatilePathTracker> volatile_path_tracker,
const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch);
const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch,
impeller::RuntimeStageBackend runtime_stage_type =
impeller::RuntimeStageBackend::kSkSL);
//----------------------------------------------------------------------------
/// @brief Create a Engine that shares as many resources as

View File

@@ -9,6 +9,11 @@ import 'dart:ui';
void main() {}
@pragma('vm:entry-point')
void mainNotifyNative() {
notifyNative();
}
@pragma('vm:external-name', 'NativeReportTimingsCallback')
external void nativeReportTimingsCallback(List<int> timings);
@pragma('vm:external-name', 'NativeOnBeginFrame')

View File

@@ -28,6 +28,7 @@
#include "flutter/shell/common/skia_event_tracer_impl.h"
#include "flutter/shell/common/switches.h"
#include "flutter/shell/common/vsync_waiter.h"
#include "impeller/runtime_stage/runtime_stage.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/writer.h"
#include "third_party/dart/runtime/include/dart_tools_api.h"
@@ -64,7 +65,8 @@ std::unique_ptr<Engine> CreateEngine(
const fml::RefPtr<SkiaUnrefQueue>& unref_queue,
const fml::TaskRunnerAffineWeakPtr<SnapshotDelegate>& snapshot_delegate,
const std::shared_ptr<VolatilePathTracker>& volatile_path_tracker,
const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch) {
const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch,
impeller::RuntimeStageBackend runtime_stage_backend) {
return std::make_unique<Engine>(delegate, //
dispatcher_maker, //
vm, //
@@ -77,7 +79,8 @@ std::unique_ptr<Engine> CreateEngine(
unref_queue, //
snapshot_delegate, //
volatile_path_tracker, //
gpu_disabled_switch);
gpu_disabled_switch, //
runtime_stage_backend);
}
void RegisterCodecsWithSkia() {
@@ -191,6 +194,21 @@ std::unique_ptr<Shell> Shell::Create(
CreateEngine, is_gpu_disabled);
}
static impeller::RuntimeStageBackend DetermineRuntimeStageBackend(
const std::shared_ptr<impeller::Context>& impeller_context) {
if (!impeller_context) {
return impeller::RuntimeStageBackend::kSkSL;
}
switch (impeller_context->GetBackendType()) {
case impeller::Context::BackendType::kMetal:
return impeller::RuntimeStageBackend::kMetal;
case impeller::Context::BackendType::kOpenGLES:
return impeller::RuntimeStageBackend::kOpenGLES;
case impeller::Context::BackendType::kVulkan:
return impeller::RuntimeStageBackend::kVulkan;
}
}
std::unique_ptr<Shell> Shell::CreateShellOnPlatformThread(
DartVMRef vm,
fml::RefPtr<fml::RasterThreadMerger> parent_merger,
@@ -312,7 +330,9 @@ std::unique_ptr<Shell> Shell::CreateShellOnPlatformThread(
&weak_io_manager_future, //
&snapshot_delegate_future, //
&unref_queue_future, //
&on_create_engine]() mutable {
&on_create_engine,
runtime_stage_backend = DetermineRuntimeStageBackend(
platform_view->GetImpellerContext())]() mutable {
TRACE_EVENT0("flutter", "ShellSetupUISubsystem");
const auto& task_runners = shell->GetTaskRunners();
@@ -321,20 +341,22 @@ std::unique_ptr<Shell> Shell::CreateShellOnPlatformThread(
auto animator = std::make_unique<Animator>(*shell, task_runners,
std::move(vsync_waiter));
engine_promise.set_value(
on_create_engine(*shell, //
dispatcher_maker, //
*shell->GetDartVM(), //
std::move(isolate_snapshot), //
task_runners, //
platform_data, //
shell->GetSettings(), //
std::move(animator), //
weak_io_manager_future.get(), //
unref_queue_future.get(), //
snapshot_delegate_future.get(), //
shell->volatile_path_tracker_,
shell->is_gpu_disabled_sync_switch_));
engine_promise.set_value(on_create_engine(
*shell, //
dispatcher_maker, //
*shell->GetDartVM(), //
std::move(isolate_snapshot), //
task_runners, //
platform_data, //
shell->GetSettings(), //
std::move(animator), //
weak_io_manager_future.get(), //
unref_queue_future.get(), //
snapshot_delegate_future.get(), //
shell->volatile_path_tracker_, //
shell->is_gpu_disabled_sync_switch_, //
runtime_stage_backend //
));
}));
if (!shell->Setup(std::move(platform_view), //
@@ -574,7 +596,8 @@ std::unique_ptr<Shell> Shell::Spawn(
const fml::RefPtr<SkiaUnrefQueue>& unref_queue,
fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate,
const std::shared_ptr<VolatilePathTracker>& volatile_path_tracker,
const std::shared_ptr<fml::SyncSwitch>& is_gpu_disabled_sync_switch) {
const std::shared_ptr<fml::SyncSwitch>& is_gpu_disabled_sync_switch,
impeller::RuntimeStageBackend runtime_stage_backend) {
return engine->Spawn(
/*delegate=*/delegate,
/*dispatcher_maker=*/dispatcher_maker,

View File

@@ -40,6 +40,7 @@
#include "flutter/shell/common/rasterizer.h"
#include "flutter/shell/common/resource_cache_limit_calculator.h"
#include "flutter/shell/common/shell_io_manager.h"
#include "impeller/runtime_stage/runtime_stage.h"
namespace flutter {
@@ -129,7 +130,8 @@ class Shell final : public PlatformView::Delegate,
fml::RefPtr<SkiaUnrefQueue> unref_queue,
fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate,
std::shared_ptr<VolatilePathTracker> volatile_path_tracker,
const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch)>
const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch,
impeller::RuntimeStageBackend runtime_stage_type)>
EngineCreateCallback;
//----------------------------------------------------------------------------

View File

@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include <strstream>
#include "impeller/core/runtime_types.h"
#define FML_USED_ON_EMBEDDER
#include <algorithm>
@@ -4564,6 +4565,96 @@ TEST_F(ShellTest, ShellFlushesPlatformStatesByMain) {
DestroyShell(std::move(shell), task_runners);
}
TEST_F(ShellTest, RuntimeStageBackendDefaultsToSkSLWithoutImpeller) {
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
Settings settings = CreateSettingsForFixture();
settings.enable_impeller = false;
ThreadHost thread_host(ThreadHost::ThreadHostConfig(
"io.flutter.test." + GetCurrentTestName() + ".",
ThreadHost::Type::kPlatform | ThreadHost::Type::kRaster |
ThreadHost::Type::kIo | ThreadHost::Type::kUi));
TaskRunners task_runners("test", thread_host.platform_thread->GetTaskRunner(),
thread_host.raster_thread->GetTaskRunner(),
thread_host.ui_thread->GetTaskRunner(),
thread_host.io_thread->GetTaskRunner());
std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
ASSERT_TRUE(shell);
fml::AutoResetWaitableEvent latch;
AddNativeCallback("NotifyNative", CREATE_NATIVE_ENTRY([&latch](auto args) {
auto backend =
UIDartState::Current()->GetRuntimeStageBackend();
EXPECT_EQ(backend, impeller::RuntimeStageBackend::kSkSL);
latch.Signal();
}));
auto configuration = RunConfiguration::InferFromSettings(settings);
configuration.SetEntrypoint("mainNotifyNative");
RunEngine(shell.get(), std::move(configuration));
latch.Wait();
DestroyShell(std::move(shell), task_runners);
}
// TODO(dnfield): Enable GL and Vulkan after
// https://github.com/flutter/flutter/issues/140419
#if SHELL_ENABLE_METAL
TEST_F(ShellTest, RuntimeStageBackendWithImpeller) {
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
Settings settings = CreateSettingsForFixture();
settings.enable_impeller = true;
ThreadHost thread_host(ThreadHost::ThreadHostConfig(
"io.flutter.test." + GetCurrentTestName() + ".",
ThreadHost::Type::kPlatform | ThreadHost::Type::kRaster |
ThreadHost::Type::kIo | ThreadHost::Type::kUi));
TaskRunners task_runners("test", thread_host.platform_thread->GetTaskRunner(),
thread_host.raster_thread->GetTaskRunner(),
thread_host.ui_thread->GetTaskRunner(),
thread_host.io_thread->GetTaskRunner());
std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
ASSERT_TRUE(shell);
fml::AutoResetWaitableEvent latch;
impeller::Context::BackendType impeller_backend;
fml::TaskRunner::RunNowOrPostTask(
shell->GetTaskRunners().GetPlatformTaskRunner(),
[platform_view = shell->GetPlatformView(), &latch, &impeller_backend]() {
auto impeller_context = platform_view->GetImpellerContext();
EXPECT_TRUE(impeller_context);
impeller_backend = impeller_context->GetBackendType();
latch.Signal();
});
latch.Wait();
AddNativeCallback(
"NotifyNative", CREATE_NATIVE_ENTRY([&](auto args) {
auto backend = UIDartState::Current()->GetRuntimeStageBackend();
switch (impeller_backend) {
case impeller::Context::BackendType::kMetal:
EXPECT_EQ(backend, impeller::RuntimeStageBackend::kMetal);
break;
case impeller::Context::BackendType::kOpenGLES:
EXPECT_EQ(backend, impeller::RuntimeStageBackend::kOpenGLES);
break;
case impeller::Context::BackendType::kVulkan:
EXPECT_EQ(backend, impeller::RuntimeStageBackend::kVulkan);
break;
}
latch.Signal();
}));
auto configuration = RunConfiguration::InferFromSettings(settings);
configuration.SetEntrypoint("mainNotifyNative");
RunEngine(shell.get(), std::move(configuration));
latch.Wait();
DestroyShell(std::move(shell), task_runners);
}
#endif // SHELL_ENABLE_METAL
} // namespace testing
} // namespace flutter

View File

@@ -30,10 +30,13 @@ void main() async {
expect(rawData is Map<String, Object?>, true);
final Map<String, Object?> data = rawData! as Map<String, Object?>;
expect(data['sksl'] is String, true);
expect(data['uniforms'] is List<Object?>, true);
expect(data.keys.toList(), <String>['sksl']);
expect(data['sksl'] is Map<String, Object?>, true);
final Object? rawUniformData = (data['uniforms']! as List<Object?>)[0];
final Map<String, Object?> skslData = data['sksl']! as Map<String, Object?>;
expect(skslData['uniforms'] is List<Object?>, true);
final Object? rawUniformData = (skslData['uniforms']! as List<Object?>)[0];
expect(rawUniformData is Map<String, Object?>, true);
@@ -42,6 +45,11 @@ void main() async {
expect(uniformData['location'] is int, true);
});
if (impellerEnabled) {
// https://github.com/flutter/flutter/issues/122823
return;
}
test('FragmentShader setSampler throws with out-of-bounds index', () async {
final FragmentProgram program = await FragmentProgram.fromAsset(
'blue_green_sampler.frag.iplr',

View File

@@ -9,8 +9,14 @@ import 'package:litetest/litetest.dart';
import 'package:vm_service/vm_service.dart' as vms;
import 'package:vm_service/vm_service_io.dart';
import '../impeller_enabled.dart';
void main() {
test('simple iplr shader can be re-initialized', () async {
if (impellerEnabled) {
// Needs https://github.com/flutter/flutter/issues/129659
return;
}
vms.VmService? vmService;
FragmentShader? shader;
try {