rusticl/device: support query_memory_info to retrieve available memory

Some drivers implement query_memory_info, but not the MAX_GLOBAL_SIZE
compute cap.

Long term we should drop the compute cap anyway.

Signed-off-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28122>
This commit is contained in:
Karol Herbst 2024-03-11 14:03:40 +01:00 committed by Marge Bot
parent 2df640c4f6
commit 7487ac2046
2 changed files with 19 additions and 2 deletions

View file

@ -785,8 +785,17 @@ impl Device {
} }
pub fn global_mem_size(&self) -> cl_ulong { pub fn global_mem_size(&self) -> cl_ulong {
self.screen if let Some(memory_info) = self.screen().query_memory_info() {
.compute_param(pipe_compute_cap::PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE) let memory: cl_ulong = if memory_info.total_device_memory != 0 {
memory_info.total_device_memory.into()
} else {
memory_info.total_staging_memory.into()
};
memory * 1024
} else {
self.screen
.compute_param(pipe_compute_cap::PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE)
}
} }
pub fn image_2d_size(&self) -> usize { pub fn image_2d_size(&self) -> usize {

View file

@ -449,6 +449,14 @@ impl PipeScreen {
); );
} }
} }
pub fn query_memory_info(&self) -> Option<pipe_memory_info> {
let mut info = pipe_memory_info::default();
unsafe {
self.screen().query_memory_info?(self.screen.as_ptr(), &mut info);
}
Some(info)
}
} }
impl Drop for PipeScreen { impl Drop for PipeScreen {