-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
n1ght-hunter
wants to merge
13
commits into
gfx-rs:trunk
Choose a base branch
from
n1ght-hunter:dev/windows-os-transparent
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add dcomp on windows #7550
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e6d7e5f
add dx12 dcomp option to backend options
n1ght-hunter c328699
impl dcomp for the dx12 backend
n1ght-hunter 3f91a00
Merge branch 'gfx-rs:trunk' into dev/windows-os-transparent
n1ght-hunter b8131bf
Merge branch 'gfx-rs:trunk' into dev/windows-os-transparent
n1ght-hunter 1f70a9a
Add Dcomp support to DX12 backend in changelog
n1ght-hunter 60a747c
move decomp to another module
n1ght-hunter 8b012f3
refactor: replace use_dcomp with presentation_system in Dx12BackendOp…
n1ght-hunter 91d98af
refactor: enhance Dx12PresentationSystem with Copy, PartialEq, and Eq…
n1ght-hunter bae60c3
refactor: replace use_dcomp with presentation_system in Dx12 backend …
n1ght-hunter 194a685
Merge branch 'trunk' into dev/windows-os-transparent
n1ght-hunter 32ce523
refactor: update Dx12BackendOptions to use presentation_system instea…
n1ght-hunter 157c1c6
Merge branch 'dev/windows-os-transparent' of https://github.com/n1ght…
n1ght-hunter cd41a6e
Merge branch 'trunk' into dev/windows-os-transparent
n1ght-hunter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
use windows::Win32::{ | ||
Foundation::HWND, | ||
Graphics::{Direct3D11, Direct3D11on12, DirectComposition, Dxgi}, | ||
}; | ||
use windows_core::Interface as _; | ||
|
||
#[derive(Default)] | ||
pub struct DCompState { | ||
inner: Option<InnerState>, | ||
} | ||
|
||
impl DCompState { | ||
pub fn get_or_init( | ||
&mut self, | ||
hwnd: &HWND, | ||
device: &super::Device, | ||
) -> Result<&mut InnerState, crate::SurfaceError> { | ||
if self.inner.is_none() { | ||
self.inner = Some(unsafe { InnerState::init(hwnd, device) }?); | ||
} | ||
Ok(self.inner.as_mut().unwrap()) | ||
} | ||
} | ||
|
||
pub struct InnerState { | ||
pub visual: DirectComposition::IDCompositionVisual, | ||
pub device: DirectComposition::IDCompositionDevice, | ||
// Must be kept alive but is otherwise unused after initialization. | ||
pub _target: DirectComposition::IDCompositionTarget, | ||
} | ||
|
||
impl InnerState { | ||
/// Creates a DirectComposition device and a target for the given window handle. | ||
/// From a Direct3D 12 device, it creates a Direct3D 11 device and then a DirectComposition device. | ||
pub unsafe fn init(hwnd: &HWND, device: &super::Device) -> Result<Self, crate::SurfaceError> { | ||
let mut d3d11_device = None; | ||
{ | ||
profiling::scope!("Direct3D11on12::D3D11On12CreateDevice"); | ||
unsafe { | ||
Direct3D11on12::D3D11On12CreateDevice( | ||
&device.raw, | ||
Direct3D11::D3D11_CREATE_DEVICE_BGRA_SUPPORT.0, | ||
None, | ||
None, | ||
0, | ||
Some(&mut d3d11_device), | ||
None, | ||
None, | ||
) | ||
} | ||
.map_err(|err| { | ||
log::error!("Direct3D11on12::D3D11On12CreateDevice failed: {err}"); | ||
crate::SurfaceError::Other("Direct3D11on12::D3D11On12CreateDevice") | ||
})?; | ||
} | ||
let d3d11_device = d3d11_device.unwrap(); | ||
|
||
let dxgi_device = { | ||
profiling::scope!("IDXGIDevice::QueryInterface"); | ||
d3d11_device.cast::<Dxgi::IDXGIDevice>().map_err(|err| { | ||
log::error!("IDXGIDevice::QueryInterface failed: {err}"); | ||
crate::SurfaceError::Other("IDXGIDevice::QueryInterface") | ||
})? | ||
}; | ||
|
||
let dcomp_device = { | ||
profiling::scope!("DirectComposition::DCompositionCreateDevice"); | ||
unsafe { | ||
DirectComposition::DCompositionCreateDevice::< | ||
_, | ||
DirectComposition::IDCompositionDevice, | ||
>(&dxgi_device) | ||
} | ||
.map_err(|err| { | ||
log::error!("DirectComposition::DCompositionCreateDevice failed: {err}"); | ||
crate::SurfaceError::Other("DirectComposition::DCompositionCreateDevice") | ||
})? | ||
}; | ||
|
||
let target = { | ||
profiling::scope!("IDCompositionDevice::CreateTargetForHwnd"); | ||
unsafe { dcomp_device.CreateTargetForHwnd(*hwnd, false) }.map_err(|err| { | ||
log::error!("IDCompositionDevice::CreateTargetForHwnd failed: {err}"); | ||
crate::SurfaceError::Other("IDCompositionDevice::CreateTargetForHwnd") | ||
})? | ||
}; | ||
|
||
let visual = { | ||
profiling::scope!("IDCompositionDevice::CreateVisual"); | ||
unsafe { dcomp_device.CreateVisual() }.map_err(|err| { | ||
log::error!("IDCompositionDevice::CreateVisual failed: {err}"); | ||
crate::SurfaceError::Other("IDCompositionDevice::CreateVisual") | ||
})? | ||
}; | ||
|
||
{ | ||
profiling::scope!("IDCompositionTarget::SetRoot"); | ||
unsafe { target.SetRoot(&visual) }.map_err(|err| { | ||
log::error!("IDCompositionTarget::SetRoot failed: {err}"); | ||
crate::SurfaceError::Other("IDCompositionTarget::SetRoot") | ||
})?; | ||
} | ||
|
||
Ok(InnerState { | ||
visual, | ||
device: dcomp_device, | ||
_target: target, | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be combining these enums?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
honestly i dont know enough about it to say. i think what maybe would make sense is to have a Visual Enum one variant that just has Dcomp Visual and one that has the handle and other state needed