gfx-rs / wgpu

A cross-platform, safe, pure-Rust graphics API.
https://wgpu.rs
Apache License 2.0
12.8k stars 938 forks source link

Hardware Memory Usage Query #2447

Open cwfitzgerald opened 2 years ago

cwfitzgerald commented 2 years ago

Is your feature request related to a problem? Please describe.

Users often need to know how much memory they can actually use to make good use of the data they have, without needing to do it on a reactionary basis.

Describe the solution you'd like

Add an api that dispatches to the following apis:

We can also, barring information about real memory usage, expose the "expected heap sizes" which are:

I think we should just expose both if we can with a simple

pub struct MemInfo {
     pub used: u64;
     pub max: u64;
}    

pub struct MemoryUsage {
    pub actual: Option<MemInfo>
    pub expected: Option<MemInfo>
}

Describe alternatives you've considered

Not providing this information. It works in a pinch, but in practice, this isn't great as applications that need to store datasets well above what memory supports needs some way to understand the current memory pressure.

Additional context

https://github.com/BVE-Reborn/rend3/issues/348

pixelcluster commented 2 years ago

FWIW, GL has GL_NVX_gpu_memory_info which seems to be supported okay-ish (~50% of reports on gpuinfo).

GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX would then be maximum/"expected" memory size, and GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX would be the actual available value.

cwfitzgerald commented 2 years ago

I'm not positive if that will show up as we use GLES, but if it does we totally should. Thanks for the pointer!