[Flutter GPU] Generate DescriptorSetLayouts for pipelines & export symbols on Android. (flutter/engine#53184)
Part of https://github.com/flutter/flutter/issues/145011. This gets Flutter GPU working on Android.
This commit is contained in:
@@ -21,7 +21,14 @@ RenderPipeline::RenderPipeline(
|
||||
void RenderPipeline::BindToPipelineDescriptor(
|
||||
impeller::ShaderLibrary& library,
|
||||
impeller::PipelineDescriptor& desc) {
|
||||
desc.SetVertexDescriptor(vertex_shader_->GetVertexDescriptor());
|
||||
auto vertex_descriptor = vertex_shader_->CreateVertexDescriptor();
|
||||
vertex_descriptor->RegisterDescriptorSetLayouts(
|
||||
vertex_shader_->GetDescriptorSetLayouts().data(),
|
||||
vertex_shader_->GetDescriptorSetLayouts().size());
|
||||
vertex_descriptor->RegisterDescriptorSetLayouts(
|
||||
fragment_shader_->GetDescriptorSetLayouts().data(),
|
||||
fragment_shader_->GetDescriptorSetLayouts().size());
|
||||
desc.SetVertexDescriptor(vertex_descriptor);
|
||||
|
||||
desc.AddStageEntrypoint(vertex_shader_->GetFunctionFromLibrary(library));
|
||||
desc.AddStageEntrypoint(fragment_shader_->GetFunctionFromLibrary(library));
|
||||
|
||||
@@ -39,17 +39,21 @@ fml::RefPtr<Shader> Shader::Make(
|
||||
std::string entrypoint,
|
||||
impeller::ShaderStage stage,
|
||||
std::shared_ptr<fml::Mapping> code_mapping,
|
||||
std::shared_ptr<impeller::VertexDescriptor> vertex_desc,
|
||||
std::vector<impeller::ShaderStageIOSlot> inputs,
|
||||
std::vector<impeller::ShaderStageBufferLayout> layouts,
|
||||
std::unordered_map<std::string, UniformBinding> uniform_structs,
|
||||
std::unordered_map<std::string, impeller::SampledImageSlot>
|
||||
uniform_textures) {
|
||||
uniform_textures,
|
||||
std::vector<impeller::DescriptorSetLayout> descriptor_set_layouts) {
|
||||
auto shader = fml::MakeRefCounted<Shader>();
|
||||
shader->entrypoint_ = std::move(entrypoint);
|
||||
shader->stage_ = stage;
|
||||
shader->code_mapping_ = std::move(code_mapping);
|
||||
shader->vertex_desc_ = std::move(vertex_desc);
|
||||
shader->inputs_ = std::move(inputs);
|
||||
shader->layouts_ = std::move(layouts);
|
||||
shader->uniform_structs_ = std::move(uniform_structs);
|
||||
shader->uniform_textures_ = std::move(uniform_textures);
|
||||
shader->descriptor_set_layouts_ = std::move(descriptor_set_layouts);
|
||||
return shader;
|
||||
}
|
||||
|
||||
@@ -83,15 +87,22 @@ bool Shader::RegisterSync(Context& context) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<impeller::VertexDescriptor> Shader::GetVertexDescriptor()
|
||||
std::shared_ptr<impeller::VertexDescriptor> Shader::CreateVertexDescriptor()
|
||||
const {
|
||||
return vertex_desc_;
|
||||
auto vertex_descriptor = std::make_shared<impeller::VertexDescriptor>();
|
||||
vertex_descriptor->SetStageInputs(inputs_, layouts_);
|
||||
return vertex_descriptor;
|
||||
}
|
||||
|
||||
impeller::ShaderStage Shader::GetShaderStage() const {
|
||||
return stage_;
|
||||
}
|
||||
|
||||
const std::vector<impeller::DescriptorSetLayout>&
|
||||
Shader::GetDescriptorSetLayouts() const {
|
||||
return descriptor_set_layouts_;
|
||||
}
|
||||
|
||||
const Shader::UniformBinding* Shader::GetUniformStruct(
|
||||
const std::string& name) const {
|
||||
auto uniform = uniform_structs_.find(name);
|
||||
|
||||
@@ -40,10 +40,12 @@ class Shader : public RefCountedDartWrappable<Shader> {
|
||||
std::string entrypoint,
|
||||
impeller::ShaderStage stage,
|
||||
std::shared_ptr<fml::Mapping> code_mapping,
|
||||
std::shared_ptr<impeller::VertexDescriptor> vertex_desc,
|
||||
std::vector<impeller::ShaderStageIOSlot> inputs,
|
||||
std::vector<impeller::ShaderStageBufferLayout> layouts,
|
||||
std::unordered_map<std::string, UniformBinding> uniform_structs,
|
||||
std::unordered_map<std::string, impeller::SampledImageSlot>
|
||||
uniform_textures);
|
||||
uniform_textures,
|
||||
std::vector<impeller::DescriptorSetLayout> descriptor_set_layouts);
|
||||
|
||||
std::shared_ptr<const impeller::ShaderFunction> GetFunctionFromLibrary(
|
||||
impeller::ShaderLibrary& library);
|
||||
@@ -52,7 +54,10 @@ class Shader : public RefCountedDartWrappable<Shader> {
|
||||
|
||||
bool RegisterSync(Context& context);
|
||||
|
||||
std::shared_ptr<impeller::VertexDescriptor> GetVertexDescriptor() const;
|
||||
std::shared_ptr<impeller::VertexDescriptor> CreateVertexDescriptor() const;
|
||||
|
||||
const std::vector<impeller::DescriptorSetLayout>& GetDescriptorSetLayouts()
|
||||
const;
|
||||
|
||||
impeller::ShaderStage GetShaderStage() const;
|
||||
|
||||
@@ -67,9 +72,11 @@ class Shader : public RefCountedDartWrappable<Shader> {
|
||||
std::string entrypoint_;
|
||||
impeller::ShaderStage stage_;
|
||||
std::shared_ptr<fml::Mapping> code_mapping_;
|
||||
std::shared_ptr<impeller::VertexDescriptor> vertex_desc_;
|
||||
std::vector<impeller::ShaderStageIOSlot> inputs_;
|
||||
std::vector<impeller::ShaderStageBufferLayout> layouts_;
|
||||
std::unordered_map<std::string, UniformBinding> uniform_structs_;
|
||||
std::unordered_map<std::string, impeller::SampledImageSlot> uniform_textures_;
|
||||
std::vector<impeller::DescriptorSetLayout> descriptor_set_layouts_;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(Shader);
|
||||
};
|
||||
|
||||
@@ -208,6 +208,8 @@ fml::RefPtr<ShaderLibrary> ShaderLibrary::MakeFromFlatbuffer(
|
||||
[payload = payload](auto, auto) {} //
|
||||
);
|
||||
|
||||
std::vector<impeller::DescriptorSetLayout> descriptor_set_layouts;
|
||||
|
||||
std::unordered_map<std::string, Shader::UniformBinding> uniform_structs;
|
||||
if (backend_shader->uniform_structs() != nullptr) {
|
||||
for (const auto& uniform : *backend_shader->uniform_structs()) {
|
||||
@@ -245,6 +247,12 @@ fml::RefPtr<ShaderLibrary> ShaderLibrary::MakeFromFlatbuffer(
|
||||
},
|
||||
.size_in_bytes = static_cast<size_t>(uniform->size_in_bytes()),
|
||||
};
|
||||
|
||||
descriptor_set_layouts.push_back(impeller::DescriptorSetLayout{
|
||||
static_cast<uint32_t>(uniform->binding()),
|
||||
impeller::DescriptorType::kUniformBuffer,
|
||||
ToShaderStage(backend_shader->stage()),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,16 +266,21 @@ fml::RefPtr<ShaderLibrary> ShaderLibrary::MakeFromFlatbuffer(
|
||||
.set = static_cast<size_t>(uniform->set()),
|
||||
.binding = static_cast<size_t>(uniform->binding()),
|
||||
};
|
||||
|
||||
descriptor_set_layouts.push_back(impeller::DescriptorSetLayout{
|
||||
static_cast<uint32_t>(uniform->binding()),
|
||||
impeller::DescriptorType::kSampledImage,
|
||||
ToShaderStage(backend_shader->stage()),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<impeller::VertexDescriptor> vertex_descriptor = nullptr;
|
||||
std::vector<impeller::ShaderStageIOSlot> inputs;
|
||||
std::vector<impeller::ShaderStageBufferLayout> layouts;
|
||||
if (backend_shader->stage() ==
|
||||
impeller::fb::shaderbundle::ShaderStage::kVertex) {
|
||||
vertex_descriptor = std::make_shared<impeller::VertexDescriptor>();
|
||||
auto inputs_fb = backend_shader->inputs();
|
||||
|
||||
std::vector<impeller::ShaderStageIOSlot> inputs;
|
||||
inputs.reserve(inputs_fb->size());
|
||||
size_t default_stride = 0;
|
||||
for (const auto& input : *inputs_fb) {
|
||||
@@ -286,20 +299,17 @@ fml::RefPtr<ShaderLibrary> ShaderLibrary::MakeFromFlatbuffer(
|
||||
default_stride +=
|
||||
SizeOfInputType(input->type()) * slot.vec_size * slot.columns;
|
||||
}
|
||||
std::vector<impeller::ShaderStageBufferLayout> layouts = {
|
||||
impeller::ShaderStageBufferLayout{
|
||||
.stride = default_stride,
|
||||
.binding = 0u,
|
||||
}};
|
||||
|
||||
vertex_descriptor->SetStageInputs(inputs, layouts);
|
||||
layouts = {impeller::ShaderStageBufferLayout{
|
||||
.stride = default_stride,
|
||||
.binding = 0u,
|
||||
}};
|
||||
}
|
||||
|
||||
auto shader = flutter::gpu::Shader::Make(
|
||||
backend_shader->entrypoint()->str(),
|
||||
ToShaderStage(backend_shader->stage()), std::move(code_mapping),
|
||||
std::move(vertex_descriptor), std::move(uniform_structs),
|
||||
std::move(uniform_textures));
|
||||
std::move(inputs), std::move(layouts), std::move(uniform_structs),
|
||||
std::move(uniform_textures), std::move(descriptor_set_layouts));
|
||||
shader_map[bundled_shader->name()->str()] = std::move(shader);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
JNI_OnLoad;
|
||||
_binary_icudtl_dat_start;
|
||||
_binary_icudtl_dat_size;
|
||||
InternalFlutterGpu*;
|
||||
kInternalFlutterGpu*;
|
||||
local:
|
||||
*;
|
||||
};
|
||||
|
||||
@@ -140,7 +140,9 @@ int _checkAndroid(String outPath, String nmPath, Iterable<String> builds) {
|
||||
};
|
||||
final Map<String, String> badSymbols = <String, String>{};
|
||||
for (final String key in entryMap.keys) {
|
||||
if (entryMap[key] != expectedSymbols[key]) {
|
||||
final bool isValidFlutterGpuSymbol =
|
||||
key.startsWith('InternalFlutterGpu') && entryMap[key] == 'T';
|
||||
if (!isValidFlutterGpuSymbol && entryMap[key] != expectedSymbols[key]) {
|
||||
badSymbols[key] = entryMap[key]!;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user