mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 09:38:07 +02:00
rusticl/mesa: wrap new VM interfaces SVM edition
Reviewed-by: Adam Jackson <ajax@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32942>
This commit is contained in:
parent
1ff64f6ac1
commit
875fc911b6
1 changed files with 40 additions and 0 deletions
|
|
@ -9,10 +9,12 @@ use mesa_rust_util::has_required_feature;
|
|||
use mesa_rust_util::ptr::ThreadSafeCPtr;
|
||||
|
||||
use std::ffi::CStr;
|
||||
use std::num::NonZeroU64;
|
||||
use std::os::raw::c_schar;
|
||||
use std::os::raw::c_uchar;
|
||||
use std::os::raw::c_void;
|
||||
use std::ptr;
|
||||
use std::ptr::NonNull;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
|
|
@ -43,6 +45,21 @@ impl ResourceType {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct ScreenVMAllocation<'a> {
|
||||
screen: &'a PipeScreen,
|
||||
alloc: NonNull<pipe_vm_allocation>,
|
||||
}
|
||||
|
||||
impl Drop for ScreenVMAllocation<'_> {
|
||||
fn drop(&mut self) {
|
||||
if let Some(free_vm) = self.screen.screen().free_vm {
|
||||
unsafe {
|
||||
free_vm(self.screen.screen.as_ptr(), self.alloc.as_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PipeScreen {
|
||||
pub(super) fn new(ldev: PipeLoaderDevice, screen: *mut pipe_screen) -> Option<Self> {
|
||||
if screen.is_null() || !has_required_cbs(screen) {
|
||||
|
|
@ -79,6 +96,23 @@ impl PipeScreen {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn alloc_vm(&self, start: NonZeroU64, size: NonZeroU64) -> Option<ScreenVMAllocation> {
|
||||
let alloc =
|
||||
unsafe { self.screen().alloc_vm?(self.screen.as_ptr(), start.get(), size.get()) };
|
||||
Some(ScreenVMAllocation {
|
||||
screen: self,
|
||||
alloc: NonNull::new(alloc)?,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn resource_assign_vma(&self, res: &PipeResource, address: u64) -> bool {
|
||||
if let Some(resource_assign_vma) = self.screen().resource_assign_vma {
|
||||
unsafe { resource_assign_vma(self.screen.as_ptr(), res.pipe(), address) }
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn resource_create(&self, tmpl: &pipe_resource) -> Option<PipeResource> {
|
||||
PipeResource::new(
|
||||
unsafe { self.screen().resource_create.unwrap()(self.screen.as_ptr(), tmpl) },
|
||||
|
|
@ -356,6 +390,12 @@ impl PipeScreen {
|
|||
self.screen().resource_get_address.is_some()
|
||||
}
|
||||
|
||||
pub fn is_vm_supported(&self) -> bool {
|
||||
self.screen().resource_assign_vma.is_some()
|
||||
&& self.screen().alloc_vm.is_some()
|
||||
&& self.screen().free_vm.is_some()
|
||||
}
|
||||
|
||||
pub fn nir_shader_compiler_options(
|
||||
&self,
|
||||
shader: pipe_shader_type,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue