dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.07k stars 1.17k forks source link

High GPU usage when using WindowChrome, MediaElement and InkCanvas on Intel Iris Xe #8686

Open Lililili-m opened 9 months ago

Lililili-m commented 9 months ago

Description

When I create a WPF full screen demo using WindowChrome 、MediaElement and InkCanvas,the GPU usage will surge to 60%. 1 2

I tested different computers. This problem occurs when the computer graphics card driver is Intel Iris Xe , but is normal on UHD.

And I listed the GPU usage under different configurations: 3

I can't reproduce the same issue from the system native app, so I'm not sure if this is an Intel issue or a WPF issue.

And I tried to get window's touch events to draw Geometry, and the GPU usage was not as exaggerated as InkCanvas, about 30%~40%.

My demo is as follows:

<Window x:Class="MediaElement.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        WindowState="Maximized" 
        ShowInTaskbar="False">
    <WindowChrome.WindowChrome>
        <WindowChrome GlassFrameThickness="-1"/>
    </WindowChrome.WindowChrome>
    <Grid x:Name="TestSp">
        <InkCanvas Background="Aquamarine"></InkCanvas>
        <MediaElement x:Name="LoadingElement" MediaEnded="LoadingElement_OnMediaEnded" LoadedBehavior="Play" Source="MLLoading.gif" 
                      HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0 0 0 68" Width="100" Height="100" />
    </Grid>
</Window>
        private void LoadingElement_OnMediaEnded(object sender, RoutedEventArgs e)
        {
            ((MediaElement)sender).Position = ((MediaElement)sender).Position.Add(TimeSpan.FromMilliseconds(1));
        }

Reproduction Steps

  1. Prepare a computer with Intel Iris Xe graphics (I tried it on two computers and it can be reproduced on both computers.),version of the graphics card driver is 31.0.101.5084.
  2. Create an empty WPF application, .net 6.0 or .net framework 4.7.2. I am using .net framework 472, and it is the same when using .net 6.0.
  3. Add MediaElement and Inkcanvas in xaml, and set WindowChrome.
  4. Run the application, write on Inkcanvs.
  5. Observe GPU usage in task manager.

Expected behavior

The GPU usage is normal.

Actual behavior

The GPU usage is very high.

Regression?

No response

Known Workarounds

Set the WPF app to use software rendering.

RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;

Impact

No response

Configuration

No response

Other information

No response

lindexi commented 9 months ago

It looks like an Intel issues.

Lililili-m commented 9 months ago

It looks like an Intel issues.

Yeah, I also posted a question in the Intel community. https://community.intel.com/t5/Graphics/WPF-Application-high-GPU-usage-on-Iris-Xe-GPU/m-p/1563448#M127328

lindexi commented 9 months ago

Underneath the MediaElement element in WPF, Windows Media Player is used to carry out the actual playback logic. In WPF's InkCanvas, a large number of Geometry objects are created for drawing strokes. I suspect that there is a bug in Intel's Windows Media Player that causes more GPU resources to be consumed when touching or drawing Geometry. However, as more code enters the driver layer, I am unable to obtain more logic through VisualStudio's GPU performance detector. At the same time, according to feedback from the Intel community, the same code works normally on UHD devices, so I have sufficient reason to suspect that this is a problem existing in the Intel driver layer. Can anyone help push Intel to assist in investigating this issue?

lindexi commented 8 months ago

According to Intel engineers, the issue originates from the driver layer. The likely cause is that in the current version of Intel, when DX9 processes resources, it will invoke the Media engine to decompress resources, even if there is no Media currently playing. This will result in the consumption of more GPU resources. This issue will be addressed in subsequent Intel driver updates. Once again, thank you for Intel's support.

Lililili-m commented 8 months ago

According to Intel engineers, the issue originates from the driver layer. The likely cause is that in the current version of Intel, when DX9 processes resources, it will invoke the Media engine to decompress resources, even if there is no Media currently playing. This will result in the consumption of more GPU resources. This issue will be addressed in subsequent Intel driver updates. Once again, thank you for Intel's support.

When the fix driver is released and verified, I will close the issue.

pwhistlef commented 2 months ago

According to Intel engineers, the issue originates from the driver layer. The likely cause is that in the current version of Intel, when DX9 processes resources, it will invoke the Media engine to decompress resources, even if there is no Media currently playing. This will result in the consumption of more GPU resources. This issue will be addressed in subsequent Intel driver updates. Once again, thank you for Intel's support.

When the fix driver is released and verified, I will close the issue.

Thanks for your investigation. We are facing the same issues with you. When I create the MediaElement control to play videos, and then system for storyboard effective is lagging. This problem occurs also when the computer graphics card driver is Intel Iris Xe , but is normal on UHD.

Could it be using the new driver to fix?

lindexi commented 2 months ago

@pwhistlef I not sure the fixs be publish in the newest driver version, but feel free to update it to the lastest version.

Lililili-m commented 2 months ago

According to Intel engineers, the issue originates from the driver layer. The likely cause is that in the current version of Intel, when DX9 processes resources, it will invoke the Media engine to decompress resources, even if there is no Media currently playing. This will result in the consumption of more GPU resources. This issue will be addressed in subsequent Intel driver updates. Once again, thank you for Intel's support.

When the fix driver is released and verified, I will close the issue.

Thanks for your investigation. We are facing the same issues with you. When I create the MediaElement control to play videos, and then system for storyboard effective is lagging. This problem occurs also when the computer graphics card driver is Intel Iris Xe , but is normal on UHD.

Could it be using the new driver to fix?

Intel has processed it, but because they want to control the scope of the impact, this processing only targets specific processes. Currently only processes named MediaElement are handled.

pwhistlef commented 2 months ago

Thanks for information! Could be given the drive version for those inter updated? We also want to make some further tests.

Lililili-m commented 2 months ago

Thanks for information! Could be given the drive version for those inter updated? We also want to make some further tests.

The latest released version has incorporated the above modifications, and I have previously verified that version 5592 has been incorporated.

Lililili-m commented 2 months ago

Thanks for information! Could be given the drive version for those inter updated? We also want to make some further tests.

You need to change the process name of the project you develop to MediaElement.