Skip to content

Implement LowLatencyDxgiSwapChain window transparency#20879

Draft
lindexi wants to merge 18 commits intoAvaloniaUI:masterfrom
dotnet-campus:t/lindexi/RenderLowLatencyDxgiSwapChain
Draft

Implement LowLatencyDxgiSwapChain window transparency#20879
lindexi wants to merge 18 commits intoAvaloniaUI:masterfrom
dotnet-campus:t/lindexi/RenderLowLatencyDxgiSwapChain

Conversation

@lindexi
Copy link
Contributor

@lindexi lindexi commented Mar 12, 2026

What does the pull request do?

See #20615

Base on: #20757

  • Implement LowLatencyDxgiSwapChain window transparency
  • Using the expectedPixelSize in DxgiRenderTarget.BeginDrawCore

What's the difference between this change and DirectComposition in Transparency mode?

When using LowLatencyDxgiSwapChain with Transparency mode, the IDXGISwapChain1 object is created via the CreateSwapChainForComposition method. Rendering operations are then executed using this SwapChain; once rendering is complete, the IDXGISwapChain1.Present method is invoked to submit the rendered content.

In contrast, DirectComposition directly acquires a texture for rendering by calling IDCompositionVirtualSurface.BeginDraw. After finishing rendering, the IDCompositionDevice2.Commit and IDCompositionDevice2.WaitForCommitCompletion methods are called to wait for the rendering process to finalize.

Based on my practical tests, I observed that using LowLatencyDxgiSwapChain in Transparency mode yields higher frame rates and lower rendering latency compared to DirectComposition.

Testing the RenderDemo in my device:

  • Screen: 3840x2160 (4K) + 100% DPI
  • CPU: i5-12450H
  • GPU: - (Integrated graphics card)
// In RenderDemo App.xaml.cs:
        static AppBuilder BuildAvaloniaApp()
           => AppBuilder.Configure<App>()
+              .With(new Win32PlatformOptions
+              {
+                  OverlayPopups = true,
+                   CompositionMode = [Win32CompositionMode.LowLatencyDxgiSwapChain]
+               })
                .UsePlatformDetect()
                .WithDeveloperTools()
                .LogToTrace();
Win32CompositionMode Frame rate GPU for RenderDemo GPU for DWM
WinUIComposition + Transparency 25-30 27% 45%
WinUIComposition + not Transparency 30 31% 12%
LowLatencyDxgiSwapChain + Transparency 60 45% 30%
LowLatencyDxgiSwapChain + not Transparency 60 70% 0%

What is the current behavior?

What is the updated/expected behavior with this PR?

How was the solution implemented (if it's not obvious)?

Checklist

Breaking changes

Obsoletions / Deprecations

Fixed issues

Fixes #20615

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0063311-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0063319-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement LowLatencyDxgiSwapChain window transparency

2 participants