KEMBAR78
[Windows] Fix performance issue using Shadows by jsuarezruiz · Pull Request #18337 · dotnet/maui · GitHub
Skip to content

Conversation

@jsuarezruiz
Copy link
Contributor

@jsuarezruiz jsuarezruiz commented Oct 25, 2023

Description of Change

Fix performance issue using Shadows on Windows.

Issue Before After
Issue 18205 shadow-perf-before shadow-perf-after

Issues Fixed

Fixes #18205

@jsuarezruiz jsuarezruiz added t/bug Something isn't working platform/windows area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing labels Oct 25, 2023
@jsuarezruiz jsuarezruiz requested a review from emaf October 25, 2023 11:52
@jsuarezruiz jsuarezruiz marked this pull request as ready for review October 27, 2023 11:51
@jsuarezruiz jsuarezruiz requested a review from a team as a code owner October 27, 2023 11:51
@mattleibow
Copy link
Member

I see a lot of code here that we are writing and maintaining. How close is this to https://learn.microsoft.com/en-us/windows/communitytoolkit/helpers/attachedshadows?

Can we borrow some of that code and rather sync it instead of us creating the same code and having to fix all the same bugs that they probably already fixed? We could copy the required files and change to internal.

@samhouts samhouts added the stale Indicates a stale issue/pr and will be closed soon label Dec 7, 2023
@jsuarezruiz jsuarezruiz removed the stale Indicates a stale issue/pr and will be closed soon label Dec 12, 2023
@jsuarezruiz
Copy link
Contributor Author

I see a lot of code here that we are writing and maintaining. How close is this to https://learn.microsoft.com/en-us/windows/communitytoolkit/helpers/attachedshadows?

Can we borrow some of that code and rather sync it instead of us creating the same code and having to fix all the same bugs that they probably already fixed? We could copy the required files and change to internal.

Initially the Toolkit had DropShadowPanel but it is deprecated and also modified the VisualTree. Currently the similar option would be AttachedCardShadow which is similar in implementation (Win2D). We can create a new task to make the change although we would have to do some tests beforehand to know if it adapts to all the conditions (for example, making a clip on a View, and applying a shadow, the shadow must follow the figure of the clipped geometry).

@samhouts samhouts added the stale Indicates a stale issue/pr and will be closed soon label Feb 6, 2024
@PureWeen
Copy link
Member

PureWeen commented Feb 7, 2024

/rebase

@MartyIX
Copy link
Contributor

MartyIX commented Jun 13, 2025

Need to see what the CI says after all this time. But, something is iffy with the shadows:

Notice the big black shadpw is offset and clipped a bit.
image

#29681 was merged. Perhaps if main is merged to this PR, it might affect the result?

@PureWeen PureWeen modified the milestones: .NET 9 SR9, .NET 9 SR10 Jul 3, 2025
@PureWeen PureWeen modified the milestones: .NET 9 SR10, .NET 9 SR12 Aug 4, 2025
@bronteq
Copy link

bronteq commented Aug 28, 2025

@jfversluis this pr needs a rebase and probably then to adjust the artifacts

@Copilot Copilot AI review requested due to automatic review settings August 28, 2025 11:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a performance issue with shadows on Windows by optimizing the shadow rendering logic. The fix prevents unnecessary expensive operations when elements have clipping applied, which was causing severe performance degradation.

  • Adds a clipping check to avoid expensive alpha mask operations on clipped elements
  • Introduces special handling for ContentPanel elements
  • Includes comprehensive test coverage and benchmarking tools for shadow performance

Reviewed Changes

Copilot reviewed 7 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
ShadowExtensions.cs Core fix - adds clipping detection and optimizes alpha mask generation logic
Issue18172.cs (test) UI test implementation for validating shadow rendering behavior
Issue18172.cs (hostapp) Test page demonstrating the shadow performance issue scenario
ShadowPage.cs Adds navigation to new shadow testing pages
ShadowMaskPage.xaml/.cs Sample page for testing shadow mask functionality
ShadowBenchmark.cs Performance benchmarking tool for shadow rendering

else if (element is FrameworkElement frameworkElement)
if (!isClipped && element is ContentPanel contentPanel)
{
return contentPanel.BorderPath?.GetAlphaMask();
Copy link

Copilot AI Aug 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method returns a CompositionBrush but the call to GetAlphaMask() could return null due to the null-conditional operator. This will cause a type mismatch since the method signature expects a non-null CompositionBrush return value.

Suggested change
return contentPanel.BorderPath?.GetAlphaMask();
mask = contentPanel.BorderPath?.GetAlphaMask();
break;

Copilot uses AI. Check for mistakes.

…172.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@MartyIX
Copy link
Contributor

MartyIX commented Aug 29, 2025

There are two tests failing

image

and it looks like they might be genuine test failures

image

@MartyIX
Copy link
Contributor

MartyIX commented Aug 30, 2025

@jfversluis Could you please add the images:

snapshots-diff.zip (I downloaded the drop.zip file and extracted relevant files)

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsuarezruiz I know this was wrong even before, but there should be no shadows here given that the code does

case 5:
    border.Shadow = null;
    break;

@albyrock87
Copy link
Contributor

Looking at 24414 screenshots, I can definitely say that there are regressions in shadow drawing.
This is one is super-evident:
image

@MartyIX
Copy link
Contributor

MartyIX commented Sep 1, 2025

Looking at 24414 screenshots, I can definitely say that there are regressions in shadow drawing. This is one is super-evident: image

That test's snapshot is not yet updated: #18337 (comment) (if you look only at github). I can't paste here atm from phone.

@jfversluis jfversluis added the do-not-merge Don't merge this PR label Sep 4, 2025
@jfversluis
Copy link
Member

Adding do-not-merge, setting it to draft, while everything builds, the snapshots seem to indicate a change in how shadows are rendered after this change.

@jfversluis jfversluis marked this pull request as draft September 4, 2025 11:28
@MartyIX
Copy link
Contributor

MartyIX commented Sep 4, 2025

The PR shoud be rebased to the inflight branch and not main.

@bronteq
Copy link

bronteq commented Sep 19, 2025

Now that #31488 and #31452 are merged in main, is it possible to re-run the pipeline please? @jfversluis

@jfversluis
Copy link
Member

Looks like there are conflicts to resolve now first @jsuarezruiz

@MartyIX
Copy link
Contributor

MartyIX commented Sep 22, 2025

Looks like there are conflicts to resolve now first @jsuarezruiz

I did it here: #31713

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing do-not-merge Don't merge this PR platform/windows t/bug Something isn't working

Projects

Status: Changes Requested