From b839b9105fc105aa88e36c83381ba3e4e009a743 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Tue, 21 Nov 2023 12:34:55 -0800 Subject: [PATCH 1/4] [Impeller] use spec constant for decal support in morph filter. --- impeller/entity/contents/content_context.cc | 3 ++- impeller/entity/shaders/morphology_filter.frag | 8 +++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/impeller/entity/contents/content_context.cc b/impeller/entity/contents/content_context.cc index 9a2e66039b5f8..3081469c4511e 100644 --- a/impeller/entity/contents/content_context.cc +++ b/impeller/entity/contents/content_context.cc @@ -322,7 +322,8 @@ ContentContext::ContentContext( gaussian_blur_noalpha_nodecal_pipelines_.CreateDefault(*context_, options_trianglestrip); border_mask_blur_pipelines_.CreateDefault(*context_, options_trianglestrip); - morphology_filter_pipelines_.CreateDefault(*context_, options_trianglestrip); + morphology_filter_pipelines_.CreateDefault(*context_, options_trianglestrip, + {supports_decal}); color_matrix_color_filter_pipelines_.CreateDefault(*context_, options_trianglestrip); linear_to_srgb_filter_pipelines_.CreateDefault(*context_, diff --git a/impeller/entity/shaders/morphology_filter.frag b/impeller/entity/shaders/morphology_filter.frag index 29428d0774b7f..17995553ec5db 100644 --- a/impeller/entity/shaders/morphology_filter.frag +++ b/impeller/entity/shaders/morphology_filter.frag @@ -4,6 +4,8 @@ precision mediump float; +layout(constant_id = 0) const int supports_decal = 0; + #include #include #include @@ -34,15 +36,11 @@ void main() { vec2 texture_coords = v_texture_coords + frag_info.uv_offset * i; f16vec4 color; -#ifdef IMPELLER_TARGET_OPENGLES - if (frag_info.supports_decal_sampler_address_mode > 0.0) { + if (supports_decal == 1) { color = texture(texture_sampler, texture_coords); } else { color = IPHalfSampleDecal(texture_sampler, texture_coords); } -#else - color = texture(texture_sampler, texture_coords); -#endif if (frag_info.morph_type == kMorphTypeDilate) { result = max(color, result); From 8dad10c2e5f82907e785771d7fa30364c16d5944 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Tue, 21 Nov 2023 13:06:45 -0800 Subject: [PATCH 2/4] ++ --- .../filters/morphology_filter_contents.cc | 2 -- .../entity/shaders/morphology_filter.frag | 2 +- impeller/tools/malioc.json | 25 ++++++++++--------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/impeller/entity/contents/filters/morphology_filter_contents.cc b/impeller/entity/contents/filters/morphology_filter_contents.cc index d9c871dbbfc11..0fb2760e6aa23 100644 --- a/impeller/entity/contents/filters/morphology_filter_contents.cc +++ b/impeller/entity/contents/filters/morphology_filter_contents.cc @@ -127,8 +127,6 @@ std::optional DirectionalMorphologyFilterContents::RenderFilter( sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal; sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal; } - frag_info.supports_decal_sampler_address_mode = - renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode(); FS::BindTextureSampler( cmd, input_snapshot->texture, diff --git a/impeller/entity/shaders/morphology_filter.frag b/impeller/entity/shaders/morphology_filter.frag index 17995553ec5db..ec9fb0e369e42 100644 --- a/impeller/entity/shaders/morphology_filter.frag +++ b/impeller/entity/shaders/morphology_filter.frag @@ -4,7 +4,7 @@ precision mediump float; -layout(constant_id = 0) const int supports_decal = 0; +layout(constant_id = 0) const int supports_decal = 1; #include #include diff --git a/impeller/tools/malioc.json b/impeller/tools/malioc.json index 12f9d54e6eced..2e2e19f65f923 100644 --- a/impeller/tools/malioc.json +++ b/impeller/tools/malioc.json @@ -4475,16 +4475,17 @@ 0.0 ], "total_bound_pipelines": [ - "texture" + "arith_total", + "arith_cvt" ], "total_cycles": [ - 0.390625, + 0.359375, 0.078125, - 0.390625, + 0.359375, 0.0625, 0.0, 0.25, - 0.5 + 0.25 ] }, "stack_spill_bytes": 0, @@ -4529,14 +4530,14 @@ "arithmetic" ], "total_cycles": [ - 4.666666507720947, + 4.0, 1.0, - 2.0 + 1.0 ] }, "thread_occupancy": 100, "uniform_registers_used": 1, - "work_registers_used": 3 + "work_registers_used": 4 } } } @@ -8063,7 +8064,7 @@ "uses_late_zs_update": false, "variants": { "Main": { - "fp16_arithmetic": 44, + "fp16_arithmetic": 54, "has_stack_spilling": false, "performance": { "longest_path_bound_pipelines": [ @@ -8105,10 +8106,10 @@ "arith_cvt" ], "total_cycles": [ - 0.265625, + 0.359375, 0.046875, - 0.265625, - 0.0, + 0.359375, + 0.1875, 0.0, 0.25, 0.25 @@ -8117,7 +8118,7 @@ "stack_spill_bytes": 0, "thread_occupancy": 100, "uniform_registers_used": 8, - "work_registers_used": 11 + "work_registers_used": 15 } } } From e05c1485e88f0244fc0f029aa8196b4f475f64d4 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Tue, 21 Nov 2023 14:02:56 -0800 Subject: [PATCH 3/4] ++ --- impeller/tools/malioc.json | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/impeller/tools/malioc.json b/impeller/tools/malioc.json index 2e2e19f65f923..90bee3952a2d3 100644 --- a/impeller/tools/malioc.json +++ b/impeller/tools/malioc.json @@ -4437,7 +4437,7 @@ "uses_late_zs_update": false, "variants": { "Main": { - "fp16_arithmetic": 57, + "fp16_arithmetic": 80, "has_stack_spilling": false, "performance": { "longest_path_bound_pipelines": [ @@ -4475,14 +4475,14 @@ 0.0 ], "total_bound_pipelines": [ - "arith_total", - "arith_cvt" + "varying", + "texture" ], "total_cycles": [ - 0.359375, + 0.234375, 0.078125, - 0.359375, - 0.0625, + 0.234375, + 0.0, 0.0, 0.25, 0.25 @@ -4491,7 +4491,7 @@ "stack_spill_bytes": 0, "thread_occupancy": 100, "uniform_registers_used": 8, - "work_registers_used": 20 + "work_registers_used": 21 } } }, @@ -4530,7 +4530,7 @@ "arithmetic" ], "total_cycles": [ - 4.0, + 2.6666667461395264, 1.0, 1.0 ] @@ -8064,7 +8064,7 @@ "uses_late_zs_update": false, "variants": { "Main": { - "fp16_arithmetic": 54, + "fp16_arithmetic": 44, "has_stack_spilling": false, "performance": { "longest_path_bound_pipelines": [ @@ -8106,10 +8106,10 @@ "arith_cvt" ], "total_cycles": [ - 0.359375, + 0.265625, 0.046875, - 0.359375, - 0.1875, + 0.265625, + 0.0, 0.0, 0.25, 0.25 @@ -8118,7 +8118,7 @@ "stack_spill_bytes": 0, "thread_occupancy": 100, "uniform_registers_used": 8, - "work_registers_used": 15 + "work_registers_used": 11 } } } From b54ac978bd8897331fb62725bcd830c5dadd9659 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Sun, 26 Nov 2023 13:12:34 -0800 Subject: [PATCH 4/4] Add unit test. --- impeller/entity/entity_unittests.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/impeller/entity/entity_unittests.cc b/impeller/entity/entity_unittests.cc index 15fa315807954..60aae37ddf693 100644 --- a/impeller/entity/entity_unittests.cc +++ b/impeller/entity/entity_unittests.cc @@ -2514,6 +2514,19 @@ TEST_P(EntityTest, SpecializationConstantsAreAppliedToVariants) { expected_constants); } +TEST_P(EntityTest, DecalSpecializationAppliedToMorphologyFilter) { + auto content_context = + ContentContext(GetContext(), TypographerContextSkia::Make()); + + auto default_color_burn = content_context.GetMorphologyFilterPipeline({}); + + auto decal_supported = static_cast( + GetContext()->GetCapabilities()->SupportsDecalSamplerAddressMode()); + std::vector expected_constants = {decal_supported}; + ASSERT_EQ(default_color_burn->GetDescriptor().GetSpecializationConstants(), + expected_constants); +} + } // namespace testing } // namespace impeller