SyncobjCtx: add from_dev_t
This commit is contained in:
parent
0a4ce7e458
commit
7192905158
3 changed files with 24 additions and 19 deletions
|
|
@ -8,12 +8,12 @@ use {
|
||||||
rect::{Rect, Region},
|
rect::{Rect, Region},
|
||||||
utils::{
|
utils::{
|
||||||
clonecell::CloneCell, copyhashmap::CopyHashMap, errorfmt::ErrorFmt, numcell::NumCell,
|
clonecell::CloneCell, copyhashmap::CopyHashMap, errorfmt::ErrorFmt, numcell::NumCell,
|
||||||
oserror::OsError, queue::AsyncQueue, stack::Stack,
|
queue::AsyncQueue, stack::Stack,
|
||||||
},
|
},
|
||||||
video::{
|
video::{
|
||||||
LINEAR_MODIFIER, LINEAR_STRIDE_ALIGN, Modifier,
|
LINEAR_MODIFIER, LINEAR_STRIDE_ALIGN, Modifier,
|
||||||
dmabuf::{DmaBuf, DmaBufIds, DmaBufPlane, PlaneVec},
|
dmabuf::{DmaBuf, DmaBufIds, DmaBufPlane, PlaneVec},
|
||||||
drm::{NodeType, get_drm_nodes_from_dev, syncobj::SyncobjCtx},
|
drm::{DrmError, syncobj::SyncobjCtx},
|
||||||
},
|
},
|
||||||
vulkan_core::{
|
vulkan_core::{
|
||||||
self, VULKAN_API_VERSION, VulkanCoreError, VulkanCoreInstance, device::VulkanDeviceInf,
|
self, VULKAN_API_VERSION, VulkanCoreError, VulkanCoreInstance, device::VulkanDeviceInf,
|
||||||
|
|
@ -166,12 +166,8 @@ pub enum CopyDeviceError {
|
||||||
BothOffDevice,
|
BothOffDevice,
|
||||||
#[error("Cannot blit between these formats")]
|
#[error("Cannot blit between these formats")]
|
||||||
BlitNotSupported,
|
BlitNotSupported,
|
||||||
#[error("Could not get DRM nodes")]
|
#[error("Could not create syncobj ctx")]
|
||||||
GetDrmNodes(#[source] OsError),
|
CreateSyncobjCtx(#[source] DrmError),
|
||||||
#[error("Device has no device nodes")]
|
|
||||||
NoDeviceNodes,
|
|
||||||
#[error("Could not open device node")]
|
|
||||||
OpenDeviceNode(#[source] OsError),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Keyed<T> = StaticMap<TransferType, T>;
|
type Keyed<T> = StaticMap<TransferType, T>;
|
||||||
|
|
@ -422,16 +418,9 @@ impl PhysicalCopyDevice {
|
||||||
}
|
}
|
||||||
return Err(CopyDeviceError::NoVulkanDevice);
|
return Err(CopyDeviceError::NoVulkanDevice);
|
||||||
}
|
}
|
||||||
let nodes = get_drm_nodes_from_dev(uapi::major(dev), uapi::minor(dev))
|
let sync_ctx = SyncobjCtx::from_dev_t(dev)
|
||||||
.map_err(CopyDeviceError::GetDrmNodes)?;
|
|
||||||
let path = nodes
|
|
||||||
.get(&NodeType::Render)
|
|
||||||
.or_else(|| nodes.get(&NodeType::Primary))
|
|
||||||
.ok_or(CopyDeviceError::NoDeviceNodes)?;
|
|
||||||
let device_fd = uapi::open(path.as_c_str(), c::O_RDWR, 0)
|
|
||||||
.map(Rc::new)
|
.map(Rc::new)
|
||||||
.map_err(Into::into)
|
.map_err(CopyDeviceError::CreateSyncobjCtx)?;
|
||||||
.map_err(CopyDeviceError::OpenDeviceNode)?;
|
|
||||||
if device_properties.api_version < VULKAN_API_VERSION {
|
if device_properties.api_version < VULKAN_API_VERSION {
|
||||||
return Err(CopyDeviceError::NoVulkan13);
|
return Err(CopyDeviceError::NoVulkan13);
|
||||||
}
|
}
|
||||||
|
|
@ -641,7 +630,7 @@ impl PhysicalCopyDevice {
|
||||||
ring: ring.clone(),
|
ring: ring.clone(),
|
||||||
eng: eng.clone(),
|
eng: eng.clone(),
|
||||||
eventfd_cache: eventfd_cache.clone(),
|
eventfd_cache: eventfd_cache.clone(),
|
||||||
sync_ctx: Rc::new(SyncobjCtx::new(&device_fd)),
|
sync_ctx,
|
||||||
instance: core_instance,
|
instance: core_instance,
|
||||||
physical_device,
|
physical_device,
|
||||||
support,
|
support,
|
||||||
|
|
|
||||||
|
|
@ -151,6 +151,8 @@ pub enum DrmError {
|
||||||
QueueSequence(#[source] OsError),
|
QueueSequence(#[source] OsError),
|
||||||
#[error("Could not stat the DRM fd")]
|
#[error("Could not stat the DRM fd")]
|
||||||
Stat(#[source] OsError),
|
Stat(#[source] OsError),
|
||||||
|
#[error("Device has no device nodes")]
|
||||||
|
NoDeviceNodes,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_node_name(fd: c::c_int) -> Result<Ustring, DrmError> {
|
fn render_node_name(fd: c::c_int) -> Result<Ustring, DrmError> {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ use {
|
||||||
oserror::OsError,
|
oserror::OsError,
|
||||||
},
|
},
|
||||||
video::drm::{
|
video::drm::{
|
||||||
DrmError,
|
DrmError, NodeType, get_drm_nodes_from_dev,
|
||||||
sys::{
|
sys::{
|
||||||
DRM_SYNCOBJ_CREATE_SIGNALED, DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE,
|
DRM_SYNCOBJ_CREATE_SIGNALED, DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE,
|
||||||
DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_TIMELINE,
|
DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_TIMELINE,
|
||||||
|
|
@ -107,6 +107,20 @@ impl SyncobjCtx {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_dev_t(dev: c::dev_t) -> Result<Self, DrmError> {
|
||||||
|
let nodes = get_drm_nodes_from_dev(uapi::major(dev), uapi::minor(dev))
|
||||||
|
.map_err(DrmError::GetNodes)?;
|
||||||
|
let path = nodes
|
||||||
|
.get(&NodeType::Render)
|
||||||
|
.or_else(|| nodes.get(&NodeType::Primary))
|
||||||
|
.ok_or(DrmError::NoDeviceNodes)?;
|
||||||
|
let device_fd = uapi::open(path.as_c_str(), c::O_RDWR | c::O_CLOEXEC, 0)
|
||||||
|
.map(Rc::new)
|
||||||
|
.map_err(Into::into)
|
||||||
|
.map_err(DrmError::ReopenNode)?;
|
||||||
|
Ok(Self::new(&device_fd))
|
||||||
|
}
|
||||||
|
|
||||||
fn get_handle(&self, syncobj: &Syncobj) -> Result<SyncobjHandle, DrmError> {
|
fn get_handle(&self, syncobj: &Syncobj) -> Result<SyncobjHandle, DrmError> {
|
||||||
if let Some(handle) = self.inner.handles.get(&syncobj.id) {
|
if let Some(handle) = self.inner.handles.get(&syncobj.id) {
|
||||||
return Ok(handle);
|
return Ok(handle);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue