Skip to content
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

Disable suballocation on Iris(R) Xe gpu #3668

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ Bottom level categories:
#### Vulkan
- Fix incorrect aspect in barriers when using emulated Stencil8 textures. By @cwfitzgerald in [#3833](https://github.com/gfx-rs/wgpu/pull/3833).

#### DX12

- Disable suballocation on Intel Iris(R) Xe. By @xiaopengli89 in [#3668](https://github.com/gfx-rs/wgpu/pull/3668)

### Examples

#### General
Expand Down
2 changes: 2 additions & 0 deletions wgpu-hal/src/dx12/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ impl super::Adapter {
},
heap_create_not_zeroed: false, //TODO: winapi support for Options7
casting_fully_typed_format_supported,
// See https://github.com/gfx-rs/wgpu/issues/3552
suballocation_supported: !info.name.contains("Iris(R) Xe"),
};

// Theoretically vram limited, but in practice 2^20 is the limit
Expand Down
6 changes: 5 additions & 1 deletion wgpu-hal/src/dx12/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ impl super::Device {
library: &Arc<d3d12::D3D12Lib>,
dx12_shader_compiler: wgt::Dx12Compiler,
) -> Result<Self, crate::DeviceError> {
let mem_allocator = super::suballocation::create_allocator_wrapper(&raw)?;
let mem_allocator = if private_caps.suballocation_supported {
super::suballocation::create_allocator_wrapper(&raw)?
} else {
None
};

let dxc_container = match dx12_shader_compiler {
wgt::Dx12Compiler::Dxc {
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/dx12/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ struct PrivateCapabilities {
#[allow(unused)] // TODO: Exists until windows-rs is standard, then it can probably be removed?
heap_create_not_zeroed: bool,
casting_fully_typed_format_supported: bool,
suballocation_supported: bool,
}

#[derive(Default)]
Expand Down
30 changes: 25 additions & 5 deletions wgpu-hal/src/dx12/suballocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ pub(crate) use allocation::{
free_buffer_allocation, free_texture_allocation, AllocationWrapper, GpuAllocatorWrapper,
};

#[cfg(not(feature = "windows_rs"))]
use committed as allocation;
#[cfg(feature = "windows_rs")]
use placed as allocation;

// This exists to work around https://github.com/gfx-rs/wgpu/issues/3207
// Currently this will work the older, slower way if the windows_rs feature is disabled,
// and will use the fast path of suballocating buffers and textures using gpu_allocator if
// the windows_rs feature is enabled.

// This is the fast path using gpu_allocator to suballocate buffers and textures.
#[cfg(feature = "windows_rs")]
mod allocation {
mod placed {
use d3d12::WeakPtr;
use parking_lot::Mutex;
use std::ptr;
Expand Down Expand Up @@ -63,6 +68,13 @@ mod allocation {
) -> Result<(HRESULT, Option<AllocationWrapper>), crate::DeviceError> {
let is_cpu_read = desc.usage.contains(crate::BufferUses::MAP_READ);
let is_cpu_write = desc.usage.contains(crate::BufferUses::MAP_WRITE);

// It's a workaround for Intel Xe drivers.
if !device.private_caps.suballocation_supported {
return super::committed::create_buffer_resource(device, desc, raw_desc, resource)
.map(|(hr, _)| (hr, None));
xiaopengli89 marked this conversation as resolved.
Show resolved Hide resolved
}

let location = match (is_cpu_read, is_cpu_write) {
(true, true) => MemoryLocation::CpuToGpu,
(true, false) => MemoryLocation::GpuToCpu,
Expand Down Expand Up @@ -111,6 +123,12 @@ mod allocation {
raw_desc: d3d12_ty::D3D12_RESOURCE_DESC,
resource: &mut WeakPtr<ID3D12Resource>,
) -> Result<(HRESULT, Option<AllocationWrapper>), crate::DeviceError> {
// It's a workaround for Intel Xe drivers.
if !device.private_caps.suballocation_supported {
xiaopengli89 marked this conversation as resolved.
Show resolved Hide resolved
return super::committed::create_texture_resource(device, desc, raw_desc, resource)
.map(|(hr, _)| (hr, None));
xiaopengli89 marked this conversation as resolved.
Show resolved Hide resolved
}

let location = MemoryLocation::GpuOnly;

let name = desc.label.unwrap_or("Unlabeled texture");
Expand Down Expand Up @@ -168,7 +186,6 @@ mod allocation {
};
}

#[cfg(feature = "windows_rs")]
impl From<gpu_allocator::AllocationError> for crate::DeviceError {
fn from(result: gpu_allocator::AllocationError) -> Self {
match result {
Expand Down Expand Up @@ -203,8 +220,7 @@ mod allocation {

// This is the older, slower path where it doesn't suballocate buffers.
// Tracking issue for when it can be removed: https://github.com/gfx-rs/wgpu/issues/3207
#[cfg(not(feature = "windows_rs"))]
mod allocation {
mod committed {
use d3d12::WeakPtr;
use parking_lot::Mutex;
use std::ptr;
Expand All @@ -216,7 +232,8 @@ mod allocation {
Interface,
};

const D3D12_HEAP_FLAG_CREATE_NOT_ZEROED: u32 = d3d12_ty::D3D12_HEAP_FLAG_NONE; // TODO: find the exact value
// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_heap_flags
const D3D12_HEAP_FLAG_CREATE_NOT_ZEROED: d3d12_ty::D3D12_HEAP_FLAGS = 0x1000;

// Allocator isn't needed when not suballocating with gpu_allocator
#[derive(Debug)]
Expand All @@ -226,6 +243,7 @@ mod allocation {
#[derive(Debug)]
pub(crate) struct AllocationWrapper {}

#[allow(unused)]
pub(crate) fn create_allocator_wrapper(
_raw: &d3d12::Device,
) -> Result<Option<Mutex<GpuAllocatorWrapper>>, crate::DeviceError> {
Expand Down Expand Up @@ -315,13 +333,15 @@ mod allocation {
Ok((hr, None))
}

#[allow(unused)]
pub(crate) fn free_buffer_allocation(
_allocation: AllocationWrapper,
_allocator: &Mutex<GpuAllocatorWrapper>,
) {
// No-op when not using gpu-allocator
}

#[allow(unused)]
pub(crate) fn free_texture_allocation(
_allocation: AllocationWrapper,
_allocator: &Mutex<GpuAllocatorWrapper>,
Expand Down