wpf icon indicating copy to clipboard operation
wpf copied to clipboard

WPF app with D3D texture is using too much CPU when in background

Open vsfeedback opened this issue 1 year ago • 0 comments

This issue has been moved from a ticket on Developer Community.


I have a native app that renders some image into a shared texture 60 frames per second. I also have a WPF app that gets a handle to this texture on launch and assigns it to a D3DImage control as explained here. This allows me to see the image in my WPF app and it seems to work OK.

When not the active window, my WPF app consumes ~2% CPU. When it becomes the foreground window, the CPU usage goes up to ~14%.

My app does not execute any code that is specific to it being in the foreground. CPU samples from the trace also don't contain any frames from my code.

I have acquired some traces. For some reason, releasing a texture seems to be taking the most time. In the attached etl file,

  • The first 9 seconds was recorded when the app was in the background.
  • Then the app is brought to foreground until the 17th second.
  • App loses its focus again after 17th second.

CPU usage a

Call tree of heaviest frames b

Pretty much the same code that you can find in the documentation is running to set the pixels dirty (OnRender callback isn't doing anything as you can see from the traces): c

When the D3DImage visibility is set to "Collapsed", the issue disappears. When I update the above code to render less frequently, the issue becomes less severe. What can I do to mitigate this performance issue? I want the app to perform just as fast in the foreground as it is in the background.


Original Comments

Feedback Bot on 11/7/2022, 08:24 AM:

(private comment, text removed)

Dolly Wang [MSFT] on 11/8/2022, 01:46 PM:

(private comment, text removed)

Bekir Ozturk on 11/20/2022, 08:24 PM:

(private comment, text removed)

Bekir Ozturk on 11/23/2022, 01:46 AM:

(private comment, text removed)

Feedback Bot on 11/16/2022, 02:31 PM:

(private comment, text removed)

Feedback Bot on 11/23/2022, 07:40 AM:

(private comment, text removed)

Feedback Bot on 1/11/2023, 09:22 PM:

(private comment, text removed)

Feedback Bot on 3/2/2023, 01:55 PM:

(private comment, text removed)


Original Solutions

(no solutions)


Repro

D3DImagePerfSample.zip

vsfeedback avatar Jul 12 '24 08:07 vsfeedback