From d8c0b1fe9a0a2761614e17102482105b3c7da362 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Mon, 3 Jun 2024 16:14:15 -0700 Subject: [PATCH 1/4] [Flutter GPU] Generate DescriptorSetLayouts for pipelines. --- lib/gpu/render_pipeline.cc | 9 ++++++++- lib/gpu/shader.cc | 21 ++++++++++++++++----- lib/gpu/shader.h | 15 +++++++++++---- lib/gpu/shader_library.cc | 34 ++++++++++++++++++++++------------ 4 files changed, 57 insertions(+), 22 deletions(-) diff --git a/lib/gpu/render_pipeline.cc b/lib/gpu/render_pipeline.cc index df93e8770ef83..fc60ba813a34f 100644 --- a/lib/gpu/render_pipeline.cc +++ b/lib/gpu/render_pipeline.cc @@ -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)); diff --git a/lib/gpu/shader.cc b/lib/gpu/shader.cc index 337baadd0f59c..a93f02a1638e3 100644 --- a/lib/gpu/shader.cc +++ b/lib/gpu/shader.cc @@ -39,17 +39,21 @@ fml::RefPtr Shader::Make( std::string entrypoint, impeller::ShaderStage stage, std::shared_ptr code_mapping, - std::shared_ptr vertex_desc, + std::vector inputs, + std::vector layouts, std::unordered_map uniform_structs, std::unordered_map - uniform_textures) { + uniform_textures, + std::vector descriptor_set_layouts) { auto shader = fml::MakeRefCounted(); 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 Shader::GetVertexDescriptor() +std::shared_ptr Shader::CreateVertexDescriptor() const { - return vertex_desc_; + auto vertex_descriptor = std::make_shared(); + vertex_descriptor->SetStageInputs(inputs_, layouts_); + return vertex_descriptor; } impeller::ShaderStage Shader::GetShaderStage() const { return stage_; } +const std::vector& +Shader::GetDescriptorSetLayouts() const { + return descriptor_set_layouts_; +} + const Shader::UniformBinding* Shader::GetUniformStruct( const std::string& name) const { auto uniform = uniform_structs_.find(name); diff --git a/lib/gpu/shader.h b/lib/gpu/shader.h index b2d88b9bb82cb..90c1a854952c4 100644 --- a/lib/gpu/shader.h +++ b/lib/gpu/shader.h @@ -40,10 +40,12 @@ class Shader : public RefCountedDartWrappable { std::string entrypoint, impeller::ShaderStage stage, std::shared_ptr code_mapping, - std::shared_ptr vertex_desc, + std::vector inputs, + std::vector layouts, std::unordered_map uniform_structs, std::unordered_map - uniform_textures); + uniform_textures, + std::vector descriptor_set_layouts); std::shared_ptr GetFunctionFromLibrary( impeller::ShaderLibrary& library); @@ -52,7 +54,10 @@ class Shader : public RefCountedDartWrappable { bool RegisterSync(Context& context); - std::shared_ptr GetVertexDescriptor() const; + std::shared_ptr CreateVertexDescriptor() const; + + const std::vector& GetDescriptorSetLayouts() + const; impeller::ShaderStage GetShaderStage() const; @@ -67,9 +72,11 @@ class Shader : public RefCountedDartWrappable { std::string entrypoint_; impeller::ShaderStage stage_; std::shared_ptr code_mapping_; - std::shared_ptr vertex_desc_; + std::vector inputs_; + std::vector layouts_; std::unordered_map uniform_structs_; std::unordered_map uniform_textures_; + std::vector descriptor_set_layouts_; FML_DISALLOW_COPY_AND_ASSIGN(Shader); }; diff --git a/lib/gpu/shader_library.cc b/lib/gpu/shader_library.cc index 565c2f938fff9..78d130ca079cf 100644 --- a/lib/gpu/shader_library.cc +++ b/lib/gpu/shader_library.cc @@ -208,6 +208,8 @@ fml::RefPtr ShaderLibrary::MakeFromFlatbuffer( [payload = payload](auto, auto) {} // ); + std::vector descriptor_set_layouts; + std::unordered_map uniform_structs; if (backend_shader->uniform_structs() != nullptr) { for (const auto& uniform : *backend_shader->uniform_structs()) { @@ -245,6 +247,12 @@ fml::RefPtr ShaderLibrary::MakeFromFlatbuffer( }, .size_in_bytes = static_cast(uniform->size_in_bytes()), }; + + descriptor_set_layouts.push_back(impeller::DescriptorSetLayout{ + static_cast(uniform->binding()), + impeller::DescriptorType::kUniformBuffer, + ToShaderStage(backend_shader->stage()), + }); } } @@ -258,16 +266,21 @@ fml::RefPtr ShaderLibrary::MakeFromFlatbuffer( .set = static_cast(uniform->set()), .binding = static_cast(uniform->binding()), }; + + descriptor_set_layouts.push_back(impeller::DescriptorSetLayout{ + static_cast(uniform->binding()), + impeller::DescriptorType::kSampledImage, + ToShaderStage(backend_shader->stage()), + }); } } - std::shared_ptr vertex_descriptor = nullptr; + std::vector inputs; + std::vector layouts; if (backend_shader->stage() == impeller::fb::shaderbundle::ShaderStage::kVertex) { - vertex_descriptor = std::make_shared(); auto inputs_fb = backend_shader->inputs(); - std::vector inputs; inputs.reserve(inputs_fb->size()); size_t default_stride = 0; for (const auto& input : *inputs_fb) { @@ -286,20 +299,17 @@ fml::RefPtr ShaderLibrary::MakeFromFlatbuffer( default_stride += SizeOfInputType(input->type()) * slot.vec_size * slot.columns; } - std::vector 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); } From ddc11f9badfeaea225e46a1469281d43b47124d3 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Sat, 8 Jun 2024 16:37:05 -0700 Subject: [PATCH 2/4] Export symbols --- shell/platform/android/android_exports.lst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shell/platform/android/android_exports.lst b/shell/platform/android/android_exports.lst index 3bea8e22e3814..198bff773dd74 100644 --- a/shell/platform/android/android_exports.lst +++ b/shell/platform/android/android_exports.lst @@ -9,6 +9,8 @@ JNI_OnLoad; _binary_icudtl_dat_start; _binary_icudtl_dat_size; + InternalFlutterGpu*; + kInternalFlutterGpu*; local: *; }; From d7aa6acec86c83805691aaaeb00dfd55ef8e2065 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Sat, 8 Jun 2024 17:04:32 -0700 Subject: [PATCH 3/4] Update symbol export test --- testing/symbols/verify_exported.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testing/symbols/verify_exported.dart b/testing/symbols/verify_exported.dart index 942f5cd9d1be0..87cab83c38c4a 100644 --- a/testing/symbols/verify_exported.dart +++ b/testing/symbols/verify_exported.dart @@ -140,7 +140,8 @@ int _checkAndroid(String outPath, String nmPath, Iterable builds) { }; final Map badSymbols = {}; for (final String key in entryMap.keys) { - if (entryMap[key] != expectedSymbols[key]) { + final bool isFlutterGpuSymbol = key.startsWith('InternalFlutterGpu'); + if (entryMap[key] != expectedSymbols[key] && !isFlutterGpuSymbol) { badSymbols[key] = entryMap[key]!; } } From 4d5f4d7cbc4f662102e5c139674e5ae21684803b Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Sat, 8 Jun 2024 17:26:18 -0700 Subject: [PATCH 4/4] stricter symbols check --- testing/symbols/verify_exported.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/testing/symbols/verify_exported.dart b/testing/symbols/verify_exported.dart index 87cab83c38c4a..7f4e5e844d179 100644 --- a/testing/symbols/verify_exported.dart +++ b/testing/symbols/verify_exported.dart @@ -140,8 +140,9 @@ int _checkAndroid(String outPath, String nmPath, Iterable builds) { }; final Map badSymbols = {}; for (final String key in entryMap.keys) { - final bool isFlutterGpuSymbol = key.startsWith('InternalFlutterGpu'); - if (entryMap[key] != expectedSymbols[key] && !isFlutterGpuSymbol) { + final bool isValidFlutterGpuSymbol = + key.startsWith('InternalFlutterGpu') && entryMap[key] == 'T'; + if (!isValidFlutterGpuSymbol && entryMap[key] != expectedSymbols[key]) { badSymbols[key] = entryMap[key]!; } }