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

Memory utilization way too high on integrated GPU. #3518

Closed
codename-irvin opened this issue Feb 21, 2023 · 3 comments
Closed

Memory utilization way too high on integrated GPU. #3518

codename-irvin opened this issue Feb 21, 2023 · 3 comments
Labels
api: dx12 Issues with DX12 or DXGI type: bug Something isn't working

Comments

@codename-irvin
Copy link

Description
Simply requesting a device results in 334MB of memory usage.

Repro steps

use winit::{
    event::{Event, WindowEvent},
    event_loop::{ControlFlow, EventLoop},
    window::WindowBuilder,
};

use pollster::{self, FutureExt};
use wgpu::{
    Backends, DeviceDescriptor, Features, Instance, InstanceDescriptor, Limits, PowerPreference,
    RequestAdapterOptions, Surface,
};
use winit::window::Window;

pub struct Device<'a> {
    window: &'a Window,
    instance: Instance,
    surface: Surface,
}

impl<'a> Device<'a> {
    pub fn new(window: &'a Window) -> Self {
        let size = window.inner_size();

        // Create the wgpu instance.
        let inst_desc = InstanceDescriptor {
            backends: Backends::DX12,
            dx12_shader_compiler: Default::default(),
        };
        let instance = Instance::new(inst_desc);

        // Create the surface.
        let surface =
            unsafe { instance.create_surface(window) }.expect("Unable to create surface.");

        // Request the adapter.
        let adapter_request = RequestAdapterOptions {
            power_preference: PowerPreference::default(), // Should default to integrated GPU.
            compatible_surface: Some(&surface),
            force_fallback_adapter: false,
        };

        let adapter = instance
            .request_adapter(&adapter_request)
            .block_on()
            .expect("Unable to find device matching request.");

        dbg!(adapter.get_info());

        // Request device and queue.
        let device_descriptor = DeviceDescriptor {
            features: Features::empty(),
            limits: Limits::default(),
            label: None,
        };

        let (device, queue) = adapter
            .request_device(
                &device_descriptor,
                None, // Trace path
            )
            .block_on()
            .unwrap();

        Device {
            window,
            instance,
            surface,
        }
    }
}

fn main() {
    let event_loop = EventLoop::new();
    let window = WindowBuilder::new().build(&event_loop).unwrap();

    let _device = Device::new(&window);

    event_loop.run(move |event, _, control_flow| {
        *control_flow = ControlFlow::Wait;

        match event {
            Event::WindowEvent {
                window_id: _,
                event,
            } => match event {
                WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
                _ => {}
            },
            _ => {}
        }
    });
}

Expected vs observed behavior
Expected: <10MB RAM. Actual: nearly 350MB RAM.

Platform
Windows, targeting DX12 backend, using integrated GPU.
AdapterInfo {
name: "Intel(R) UHD Graphics",
vendor: 32902,
device: 39876,
device_type: IntegratedGpu,
driver: "",
driver_info: "",
backend: Dx12,
}

@grovesNL
Copy link
Collaborator

Maybe related to the initial block of memory allocated through gpu-allocator (see #3498 (comment))

@codename-irvin
Copy link
Author

That is definitely it. 256 MB seems like a lot of memory to allocate ahead of time. Is there a way to configure that to be substantially less?

@teoxoy teoxoy added type: bug Something isn't working api: dx12 Issues with DX12 or DXGI labels Feb 22, 2023
@teoxoy
Copy link
Member

teoxoy commented Jul 30, 2024

This has been addressed by #5875. You can now request a device with the MemoryHints::MemoryUsage option.

@teoxoy teoxoy closed this as completed Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: dx12 Issues with DX12 or DXGI type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants