Skip to content

Commit 2410441

Browse files
committed
Final tweeks
1 parent bdb0a22 commit 2410441

File tree

3 files changed

+35
-22
lines changed

3 files changed

+35
-22
lines changed

CHANGELOG.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,23 @@ Bottom level categories:
4242

4343
### Major Changes
4444

45-
#### Builtin Support for DirectComposition/DXGI swapchains in DX12
45+
#### Builtin Support for DXGI swapchains on top of of DirectComposition Visuals in DX12
4646

47-
By selecting DirectComposition, the compositor cannot optimize your Swapchain as much, but you can support transparent windows.
47+
By enabling DirectComposition support, the dx12 backend can now support transparent windows.
4848

49-
This creates a single `IDCompositionVisual` over the entire window that is used by the `Surface`. If a user wants to manage the composition tree themselves, they should create their own device and composition, and pass the relevant visual down into `wgpu` via `IDCompositionTarget::CompositionVisual` or `IDCompositionTarget::SurfaceHandle`.
49+
This creates a single `IDCompositionVisual` over the entire window that is used by the mf`Surface`. If a user wants to manage the composition tree themselves, they should create their own device and composition, and pass the relevant visual down into `wgpu` via `SurfaceTargetUnsafe::CompositionVisual`.
5050

51-
```diff
52-
-pub struct Dx12BackendOptions { pub shader_compiler: Dx12Compiler }
53-
+pub struct Dx12BackendOptions { pub shader_compiler: Dx12Compiler, pub presentation_system: Dx12SwapchainKind }
51+
```rust
52+
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
53+
backend_options: wgpu::BackendOptions {
54+
dx12: wgpu::Dx12BackendOptions {
55+
presentation_system: wgpu::Dx12SwapchainKind::DxgiFromVisual,
56+
..
57+
},
58+
..
59+
},
60+
..
61+
});
5462
```
5563

5664
By @n1ght-hunter in [#7550](https://github.com/gfx-rs/wgpu/pull/7550).

wgpu-hal/src/dx12/instance.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,11 @@ impl crate::Instance for super::Instance {
124124
// https://github.com/rust-windowing/raw-window-handle/issues/171
125125
let handle = Foundation::HWND(handle.hwnd.get() as *mut _);
126126
let target = match self.presentation_system {
127-
wgt::Dx12SwapchainKind::Dxgi => SurfaceTarget::WndHandle(handle),
128-
wgt::Dx12SwapchainKind::DirectComposition => {
129-
SurfaceTarget::VisualFromWndHandle {
130-
handle,
131-
dcomp_state: Default::default(),
132-
}
133-
}
127+
wgt::Dx12SwapchainKind::DxgiFromHwnd => SurfaceTarget::WndHandle(handle),
128+
wgt::Dx12SwapchainKind::DxgiFromVisual => SurfaceTarget::VisualFromWndHandle {
129+
handle,
130+
dcomp_state: Default::default(),
131+
},
134132
};
135133

136134
Ok(super::Surface {

wgpu-types/src/instance.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -449,29 +449,36 @@ impl NoopBackendOptions {
449449
pub enum Dx12SwapchainKind {
450450
/// Use a DXGI swapchain made directly from the window's HWND.
451451
///
452-
/// This supports fullscreen optimization, making borderless windows just as efficient as exclusive fullscreen. It does not support transparent windows.
452+
/// This does not support transparency but has better support from developer tooling from RenderDoc.
453453
#[default]
454-
Dxgi,
455-
/// Use a DXGI swapchain made from a DirectComposition visual made from the window.
454+
DxgiFromHwnd,
455+
/// Use a DXGI swapchain made from a DirectComposition visual made automatically from the window's HWND.
456456
///
457-
/// This supports transparent windows, but does not support fullscreen optimization.
458-
DirectComposition,
457+
/// This creates a single [`IDCompositionVisual`] over the entire window that is used by the `Surface`.
458+
/// If a user wants to manage the composition tree themselves, they should create their own device and
459+
/// composition, and pass the relevant visual down via [`SurfaceTargetUnsafe::CompositionVisual`][CV].
460+
///
461+
/// This supports transparent windows, but does not have support from RenderDoc.
462+
///
463+
/// [`IDCompositionVisual`]: https://learn.microsoft.com/en-us/windows/win32/api/dcomp/nn-dcomp-idcompositionvisual
464+
/// [CV]: ../wgpu/struct.SurfaceTargetUnsafe.html#variant.CompositionVisual
465+
DxgiFromVisual,
459466
}
460467

461468
impl Dx12SwapchainKind {
462469
/// Choose which presentation system to use from the environment variable `WGPU_DX12_PRESENTATION_SYSTEM`.
463470
///
464471
/// Valid values, case insensitive:
465-
/// - `Dxgi`
466-
/// - `DirectComposition`
472+
/// - `DxgiFromVisual` or `Visual`
473+
/// - `DxgiFromHwnd` or `Hwnd` for [`Self::DxgiFromHwnd`]
467474
#[must_use]
468475
pub fn from_env() -> Option<Self> {
469476
let value = crate::env::var("WGPU_DX12_PRESENTATION_SYSTEM")
470477
.as_deref()?
471478
.to_lowercase();
472479
match value.as_str() {
473-
"dcomp" | "directcomposition" => Some(Self::DirectComposition),
474-
"dxgi" => Some(Self::Dxgi),
480+
"dxgifromvisual" | "visual" => Some(Self::DxgiFromVisual),
481+
"dxgifromhwnd" | "hwnd" => Some(Self::DxgiFromHwnd),
475482
_ => None,
476483
}
477484
}

0 commit comments

Comments
 (0)