From 51c8b05cffa3b0bdb483790d35cebcb544d156f2 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Tue, 11 Jun 2024 10:36:22 -0700 Subject: [PATCH] [Impeller] remove varying interpolation for solid colors. (flutter/engine#53281) This was an early attempt to support batching that ended up not being important, as well as an attempted work around for high memory reads that ended being unrelated (it was blending) Since its not a performance improvement and just makes things more complicated, remove the feature. --- .../compiler/shader_lib/impeller/types.glsl | 6 - .../entity/contents/solid_color_contents.cc | 8 +- .../impeller/entity/entity_unittests.cc | 7 +- .../impeller/entity/shaders/solid_fill.frag | 9 +- .../impeller/entity/shaders/solid_fill.vert | 4 - .../shader_stage_compatibility_checker.h | 10 + engine/src/flutter/impeller/tools/malioc.json | 196 +++++------------- .../src/flutter/impeller/tools/malioc_diff.py | 29 +-- 8 files changed, 91 insertions(+), 178 deletions(-) diff --git a/engine/src/flutter/impeller/compiler/shader_lib/impeller/types.glsl b/engine/src/flutter/impeller/compiler/shader_lib/impeller/types.glsl index b0ce4188d0..ad1a0e86cf 100644 --- a/engine/src/flutter/impeller/compiler/shader_lib/impeller/types.glsl +++ b/engine/src/flutter/impeller/compiler/shader_lib/impeller/types.glsl @@ -9,12 +9,6 @@ #extension GL_AMD_gpu_shader_half_float_fetch : enable #extension GL_EXT_shader_explicit_arithmetic_types_float16 : enable -#ifdef IMPELLER_TARGET_OPENGLES -#define IMPELLER_MAYBE_FLAT -#else -#define IMPELLER_MAYBE_FLAT flat -#endif - #ifndef IMPELLER_TARGET_METAL_IOS precision mediump sampler2D; diff --git a/engine/src/flutter/impeller/entity/contents/solid_color_contents.cc b/engine/src/flutter/impeller/entity/contents/solid_color_contents.cc index a823b60317..cb41781729 100644 --- a/engine/src/flutter/impeller/entity/contents/solid_color_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/solid_color_contents.cc @@ -49,9 +49,12 @@ bool SolidColorContents::Render(const ContentContext& renderer, const Entity& entity, RenderPass& pass) const { using VS = SolidFillPipeline::VertexShader; + using FS = SolidFillPipeline::FragmentShader; + auto& host_buffer = renderer.GetTransientsBuffer(); VS::FrameInfo frame_info; - frame_info.color = + FS::FragInfo frag_info; + frag_info.color = GetColor().Premultiply() * GetGeometry()->ComputeAlphaCoverage(entity); PipelineBuilderCallback pipeline_callback = @@ -60,7 +63,8 @@ bool SolidColorContents::Render(const ContentContext& renderer, }; return ColorSourceContents::DrawGeometry( renderer, entity, pass, pipeline_callback, frame_info, - [](RenderPass& pass) { + [&frag_info, &host_buffer](RenderPass& pass) { + FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info)); pass.SetCommandLabel("Solid Fill"); return true; }); diff --git a/engine/src/flutter/impeller/entity/entity_unittests.cc b/engine/src/flutter/impeller/entity/entity_unittests.cc index 3025eec1d9..6605ea81da 100644 --- a/engine/src/flutter/impeller/entity/entity_unittests.cc +++ b/engine/src/flutter/impeller/entity/entity_unittests.cc @@ -923,6 +923,7 @@ TEST_P(EntityTest, BlendingModeOptions) { auto draw_rect = [&context, &pass, &world_matrix]( Rect rect, Color color, BlendMode blend_mode) -> bool { using VS = SolidFillPipeline::VertexShader; + using FS = SolidFillPipeline::FragmentShader; VertexBufferBuilder vtx_builder; { @@ -947,10 +948,12 @@ TEST_P(EntityTest, BlendingModeOptions) { VS::FrameInfo frame_info; frame_info.mvp = pass.GetOrthographicTransform() * world_matrix; - frame_info.color = color.Premultiply(); VS::BindFrameInfo( pass, context.GetTransientsBuffer().EmplaceUniform(frame_info)); - + FS::FragInfo frag_info; + frag_info.color = color.Premultiply(); + FS::BindFragInfo( + pass, context.GetTransientsBuffer().EmplaceUniform(frame_info)); return pass.Draw().ok(); }; diff --git a/engine/src/flutter/impeller/entity/shaders/solid_fill.frag b/engine/src/flutter/impeller/entity/shaders/solid_fill.frag index ed376a71d8..b00d69b2db 100644 --- a/engine/src/flutter/impeller/entity/shaders/solid_fill.frag +++ b/engine/src/flutter/impeller/entity/shaders/solid_fill.frag @@ -6,10 +6,13 @@ precision mediump float; #include -IMPELLER_MAYBE_FLAT in f16vec4 v_color; +uniform FragInfo { + vec4 color; +} +frag_info; -out f16vec4 frag_color; +out vec4 frag_color; void main() { - frag_color = v_color; + frag_color = frag_info.color; } diff --git a/engine/src/flutter/impeller/entity/shaders/solid_fill.vert b/engine/src/flutter/impeller/entity/shaders/solid_fill.vert index edbdb8c143..4d8e67e74a 100644 --- a/engine/src/flutter/impeller/entity/shaders/solid_fill.vert +++ b/engine/src/flutter/impeller/entity/shaders/solid_fill.vert @@ -6,15 +6,11 @@ uniform FrameInfo { mat4 mvp; - f16vec4 color; } frame_info; in vec2 position; -IMPELLER_MAYBE_FLAT out mediump f16vec4 v_color; - void main() { - v_color = frame_info.color; gl_Position = frame_info.mvp * vec4(position, 0.0, 1.0); } diff --git a/engine/src/flutter/impeller/renderer/shader_stage_compatibility_checker.h b/engine/src/flutter/impeller/renderer/shader_stage_compatibility_checker.h index 5d59422ecd..666b58c612 100644 --- a/engine/src/flutter/impeller/renderer/shader_stage_compatibility_checker.h +++ b/engine/src/flutter/impeller/renderer/shader_stage_compatibility_checker.h @@ -5,6 +5,10 @@ #ifndef FLUTTER_IMPELLER_RENDERER_SHADER_STAGE_COMPATIBILITY_CHECKER_H_ #define FLUTTER_IMPELLER_RENDERER_SHADER_STAGE_COMPATIBILITY_CHECKER_H_ +#include + +#include "impeller/core/shader_types.h" + namespace impeller { /// This is a classed use to check that the input slots of fragment shaders /// match the output slots of the vertex shaders. @@ -58,11 +62,17 @@ class ShaderStageCompatibilityChecker { // TODO(https://github.com/flutter/flutter/issues/146852): Make impellerc emit // an empty array for output slots. struct ClipVertexShader; +struct SolidFillVertexShader; template class ShaderStageCompatibilityChecker { public: static constexpr bool Check() { return true; } }; +template +class ShaderStageCompatibilityChecker { + public: + static constexpr bool Check() { return true; } +}; } // namespace impeller #endif // FLUTTER_IMPELLER_RENDERER_SHADER_STAGE_COMPATIBILITY_CHECKER_H_ diff --git a/engine/src/flutter/impeller/tools/malioc.json b/engine/src/flutter/impeller/tools/malioc.json index 7d0be585bf..b0ac489c58 100644 --- a/engine/src/flutter/impeller/tools/malioc.json +++ b/engine/src/flutter/impeller/tools/malioc.json @@ -4285,15 +4285,16 @@ "has_stack_spilling": false, "performance": { "longest_path_bound_pipelines": [ - "varying" + "arith_total", + "arith_cvt" ], "longest_path_cycles": [ - 0.03125, + 0.0625, + 0.0, + 0.0625, 0.0, - 0.03125, 0.0, 0.0, - 0.25, 0.0 ], "pipelines": [ @@ -4306,34 +4307,36 @@ "texture" ], "shortest_path_bound_pipelines": [ - "varying" + "arith_total", + "arith_cvt" ], "shortest_path_cycles": [ + 0.03125, + 0.0, + 0.03125, 0.0, 0.0, 0.0, - 0.0, - 0.0, - 0.25, 0.0 ], "total_bound_pipelines": [ - "varying" + "arith_total", + "arith_cvt" ], "total_cycles": [ - 0.03125, + 0.0625, + 0.0, + 0.0625, 0.0, - 0.03125, 0.0, 0.0, - 0.25, 0.0 ] }, "stack_spill_bytes": 0, "thread_occupancy": 100, - "uniform_registers_used": 0, - "work_registers_used": 19 + "uniform_registers_used": 2, + "work_registers_used": 18 } } }, @@ -4347,12 +4350,11 @@ "has_stack_spilling": false, "performance": { "longest_path_bound_pipelines": [ - "arithmetic", - "load_store" + "arithmetic" ], "longest_path_cycles": [ 1.0, - 1.0, + 0.0, 0.0 ], "pipelines": [ @@ -4361,25 +4363,24 @@ "texture" ], "shortest_path_bound_pipelines": [ - "arithmetic", - "load_store" + "arithmetic" ], "shortest_path_cycles": [ 1.0, - 1.0, + 0.0, 0.0 ], "total_bound_pipelines": [ - "load_store" + "arithmetic" ], "total_cycles": [ 0.6666666865348816, - 1.0, + 0.0, 0.0 ] }, "thread_occupancy": 100, - "uniform_registers_used": 0, + "uniform_registers_used": 1, "work_registers_used": 2 } } @@ -4389,7 +4390,7 @@ "Mali-G78": { "core": "Mali-G78", "filename": "flutter/impeller/entity/gles/solid_fill.vert.gles", - "has_uniform_computation": true, + "has_uniform_computation": false, "type": "Vertex", "variants": { "Position": { @@ -4440,59 +4441,8 @@ }, "stack_spill_bytes": 0, "thread_occupancy": 100, - "uniform_registers_used": 22, + "uniform_registers_used": 20, "work_registers_used": 32 - }, - "Varying": { - "fp16_arithmetic": null, - "has_stack_spilling": false, - "performance": { - "longest_path_bound_pipelines": [ - "load_store" - ], - "longest_path_cycles": [ - 0.03125, - 0.0, - 0.03125, - 0.0, - 2.0, - 0.0 - ], - "pipelines": [ - "arith_total", - "arith_fma", - "arith_cvt", - "arith_sfu", - "load_store", - "texture" - ], - "shortest_path_bound_pipelines": [ - "load_store" - ], - "shortest_path_cycles": [ - 0.03125, - 0.0, - 0.03125, - 0.0, - 2.0, - 0.0 - ], - "total_bound_pipelines": [ - "load_store" - ], - "total_cycles": [ - 0.03125, - 0.0, - 0.03125, - 0.0, - 2.0, - 0.0 - ] - }, - "stack_spill_bytes": 0, - "thread_occupancy": 100, - "uniform_registers_used": 10, - "work_registers_used": 5 } } }, @@ -4510,7 +4460,7 @@ ], "longest_path_cycles": [ 2.640000104904175, - 4.0, + 3.0, 0.0 ], "pipelines": [ @@ -4523,7 +4473,7 @@ ], "shortest_path_cycles": [ 2.640000104904175, - 4.0, + 3.0, 0.0 ], "total_bound_pipelines": [ @@ -4531,12 +4481,12 @@ ], "total_cycles": [ 2.6666667461395264, - 4.0, + 3.0, 0.0 ] }, "thread_occupancy": 100, - "uniform_registers_used": 6, + "uniform_registers_used": 5, "work_registers_used": 2 } } @@ -7026,7 +6976,7 @@ "core": "Mali-G78", "filename": "flutter/impeller/entity/solid_fill.frag.vkspv", "has_side_effects": false, - "has_uniform_computation": false, + "has_uniform_computation": true, "modifies_coverage": false, "reads_color_buffer": false, "type": "Fragment", @@ -7038,15 +6988,16 @@ "has_stack_spilling": false, "performance": { "longest_path_bound_pipelines": [ - "varying" + "arith_total", + "arith_cvt" ], "longest_path_cycles": [ + 0.0625, + 0.0, + 0.0625, 0.0, 0.0, 0.0, - 0.0, - 0.0, - 0.25, 0.0 ], "pipelines": [ @@ -7059,34 +7010,36 @@ "texture" ], "shortest_path_bound_pipelines": [ - "varying" + "arith_total", + "arith_cvt" ], "shortest_path_cycles": [ + 0.0625, + 0.0, + 0.0625, 0.0, 0.0, 0.0, - 0.0, - 0.0, - 0.25, 0.0 ], "total_bound_pipelines": [ - "varying" + "arith_total", + "arith_cvt" ], "total_cycles": [ + 0.0625, + 0.0, + 0.0625, 0.0, 0.0, 0.0, - 0.0, - 0.0, - 0.25, 0.0 ] }, "stack_spill_bytes": 0, "thread_occupancy": 100, - "uniform_registers_used": 0, - "work_registers_used": 3 + "uniform_registers_used": 4, + "work_registers_used": 5 } } } @@ -7146,59 +7099,8 @@ }, "stack_spill_bytes": 0, "thread_occupancy": 100, - "uniform_registers_used": 30, + "uniform_registers_used": 28, "work_registers_used": 32 - }, - "Varying": { - "fp16_arithmetic": null, - "has_stack_spilling": false, - "performance": { - "longest_path_bound_pipelines": [ - "load_store" - ], - "longest_path_cycles": [ - 0.03125, - 0.0, - 0.03125, - 0.0, - 2.0, - 0.0 - ], - "pipelines": [ - "arith_total", - "arith_fma", - "arith_cvt", - "arith_sfu", - "load_store", - "texture" - ], - "shortest_path_bound_pipelines": [ - "load_store" - ], - "shortest_path_cycles": [ - 0.03125, - 0.0, - 0.03125, - 0.0, - 2.0, - 0.0 - ], - "total_bound_pipelines": [ - "load_store" - ], - "total_cycles": [ - 0.03125, - 0.0, - 0.03125, - 0.0, - 2.0, - 0.0 - ] - }, - "stack_spill_bytes": 0, - "thread_occupancy": 100, - "uniform_registers_used": 22, - "work_registers_used": 5 } } } diff --git a/engine/src/flutter/impeller/tools/malioc_diff.py b/engine/src/flutter/impeller/tools/malioc_diff.py index 7df66e5190..c48c515084 100755 --- a/engine/src/flutter/impeller/tools/malioc_diff.py +++ b/engine/src/flutter/impeller/tools/malioc_diff.py @@ -246,20 +246,21 @@ def compare_performance(variant, before, after): def compare_variants(befores, afters): differences = [] for variant_name, before_variant in befores.items(): - after_variant = afters[variant_name] - for variant_key, before_variant_val in before_variant.items(): - after_variant_val = after_variant[variant_key] - if variant_key == 'performance': - differences += compare_performance(variant_name, before_variant_val, after_variant_val) - elif before_variant_val != after_variant_val: - differences += [ - 'In variant {}:\n {vkey}: {} <- before\n {vkey}: {} <- after'.format( - variant_name, - before_variant_val, - after_variant_val, - vkey=variant_key, - ) - ] + if variant_name in afters: + after_variant = afters[variant_name] + for variant_key, before_variant_val in before_variant.items(): + after_variant_val = after_variant[variant_key] + if variant_key == 'performance': + differences += compare_performance(variant_name, before_variant_val, after_variant_val) + elif before_variant_val != after_variant_val: + differences += [ + 'In variant {}:\n {vkey}: {} <- before\n {vkey}: {} <- after'.format( + variant_name, + before_variant_val, + after_variant_val, + vkey=variant_key, + ) + ] return differences