Skip to content

Add dcomp on windows #7550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: trunk
Choose a base branch
from

Conversation

n1ght-hunter
Copy link

@n1ght-hunter n1ght-hunter commented Apr 16, 2025

Connections
#3486
#7108
#5150

Description
This adds dcomp support to the dx12 backend.
My main goal for this was to get window transparency to work on windows

Testing
Tested using a basic wgpu app with transparency

Squash or Rebase?
Squash

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

I dont know if its normal or not but when running cargo xtask test i had 201 tests fail with code 0xc0000005: Invalid access to memory location. (os error 998) this is run on windows 10

@n1ght-hunter n1ght-hunter requested review from crowlKats and a team as code owners April 16, 2025 06:17
Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

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

Generally looking good, some comments.

@cwfitzgerald cwfitzgerald self-assigned this Apr 16, 2025
@n1ght-hunter
Copy link
Author

n1ght-hunter commented Apr 17, 2025

will get to this in the next day or two

@n1ght-hunter
Copy link
Author

@cwfitzgerald would you be able to re review when you get time thanks

Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

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

Sorry for the delay, looks good in general with a few small comments. I also think that the hardcoded list of blending modes needs to be adjusted based on if DXGI or DComp is selected

}

impl DCompState {
pub fn get_or_init(
Copy link
Member

Choose a reason for hiding this comment

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

This function should also be unsafe

Comment on lines +66 to +72
let dcomp_device = {
profiling::scope!("DirectComposition::DCompositionCreateDevice");
unsafe {
DirectComposition::DCompositionCreateDevice::<
_,
DirectComposition::IDCompositionDevice,
>(&dxgi_device)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let dcomp_device = {
profiling::scope!("DirectComposition::DCompositionCreateDevice");
unsafe {
DirectComposition::DCompositionCreateDevice::<
_,
DirectComposition::IDCompositionDevice,
>(&dxgi_device)
let dcomp_device: DirectComposition::IDCompositionDevice = {
profiling::scope!("DirectComposition::DCompositionCreateDevice");
unsafe {
DirectComposition::DCompositionCreateDevice(&dxgi_device)

This feels cleaner

@Anutrix
Copy link

Anutrix commented May 30, 2025

Might totally be unfounded and not apply here but DirectComposition on Windows has issues with NVIDIA GPU when used with multiple monitors with different and high(60+) refresh rates. This was seen on Firefox so might be specific to it.
Recent ticket: https://bugzilla.mozilla.org/show_bug.cgi?id=1968876 . Couldn't find original ticket.

@cwfitzgerald
Copy link
Member

I definitely wouldn't worry about it here. That issue seems to be Windows 10 specific too.

@melody-rs
Copy link
Contributor

Oh! Thank you for doing this, transparency support in wgpu has been a pretty big pain point for me in the past

@n1ght-hunter
Copy link
Author

Im just traveling abroad atm should be able to get to this in the next week or so

@cwfitzgerald
Copy link
Member

Boop :)

@MarijnS95
Copy link
Contributor

So if I understand this correctly, normally one would create and manage a composition (device, target) externally, and pass either the IDCompositionVisual (where wgpu will insert the internally-crated IDXGISwapChain1 as content into the visual) or a HANDLE to an opaque "composition surface" (which the caller should insert as the content of a visual themselves - useful for cross-process sharing) into wgpu surface creation. Allowing users to render into arbitrary surfaces with wgpu while possibly combining it with a much more complicated composition/transformation tree and surfaces filled by other sources.

This PR seems to abstract away the most basic form of that, by creating and managing that DirectComposition device and a single Visual spanning the full Target that wraps the window (where hopefully "someone" disables the backing redirection buffer...) so that users no longer have to deal with it?

i.e. maybe this PR should be retitled and have a better description of what it achieves. Technically "dcomp on Windows" is already supported :)

let dcomp_device = {
profiling::scope!("DirectComposition::DCompositionCreateDevice");
unsafe {
DirectComposition::DCompositionCreateDevice::<
Copy link
Contributor

@MarijnS95 MarijnS95 Jul 6, 2025

Choose a reason for hiding this comment

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

As long as Create(Virtual)Surface() or BeginDraw() is not used, I'm quite sure you can just call DCompositionCreateDevice2(NULL) (None in Rust), without having to use the entire Direct3D11on12 emulation/mapping layer.

https://learn.microsoft.com/en-us/windows/win32/api/dcomp/nf-dcomp-dcompositioncreatedevice2#remarks:

If the renderingDevice parameter is NULL then the returned DirectComposition device cannot directly create DirectComposition surface objects. In particular, IDCompositionDevice2::CreateSurface and IDCompositionDevice2::CreateVirtualSurface methods return E_INVALIDARG, regardless of the supplied parameters. However, such a DirectComposition device object can still be used to indirectly create surfaces if the application creates a surface factory object via the IDCompositionDevice2::CreateSurfaceFactory method.

Copy link
Author

Choose a reason for hiding this comment

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

thanks i will have a look

@n1ght-hunter
Copy link
Author

sorry ended up being very busy. still traveling :). i will be home in about 3 weeks. should have time to work on it then. maybe before but unlikely. if someone else wants to fix it up no worries from me otherwise i will when i get time.

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.

5 participants