render: store underlying DmaBufs in textures
This commit is contained in:
parent
1ac4f3dc52
commit
3635ae0104
10 changed files with 38 additions and 35 deletions
|
|
@ -267,6 +267,7 @@ pub trait GfxTexture: Debug {
|
||||||
format: &'static Format,
|
format: &'static Format,
|
||||||
shm: &[Cell<u8>],
|
shm: &[Cell<u8>],
|
||||||
) -> Result<(), GfxError>;
|
) -> Result<(), GfxError>;
|
||||||
|
fn dmabuf(&self) -> Option<&DmaBuf>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait GfxContext: Debug {
|
pub trait GfxContext: Debug {
|
||||||
|
|
|
||||||
|
|
@ -259,10 +259,8 @@ impl EglDisplay {
|
||||||
Ok(Rc::new(EglImage {
|
Ok(Rc::new(EglImage {
|
||||||
dpy: self.clone(),
|
dpy: self.clone(),
|
||||||
img,
|
img,
|
||||||
width: buf.width,
|
|
||||||
height: buf.height,
|
|
||||||
external_only: format.external_only,
|
external_only: format.external_only,
|
||||||
format: buf.format,
|
dmabuf: buf.clone(),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::{
|
||||||
format::Format,
|
|
||||||
gfx_apis::gl::egl::{
|
gfx_apis::gl::egl::{
|
||||||
display::EglDisplay,
|
display::EglDisplay,
|
||||||
sys::{EGLImageKHR, EGL_FALSE},
|
sys::{EGLImageKHR, EGL_FALSE},
|
||||||
PROCS,
|
PROCS,
|
||||||
},
|
},
|
||||||
|
video::dmabuf::DmaBuf,
|
||||||
},
|
},
|
||||||
std::rc::Rc,
|
std::rc::Rc,
|
||||||
};
|
};
|
||||||
|
|
@ -13,10 +13,8 @@ use {
|
||||||
pub struct EglImage {
|
pub struct EglImage {
|
||||||
pub dpy: Rc<EglDisplay>,
|
pub dpy: Rc<EglDisplay>,
|
||||||
pub img: EGLImageKHR,
|
pub img: EGLImageKHR,
|
||||||
pub width: i32,
|
|
||||||
pub height: i32,
|
|
||||||
pub external_only: bool,
|
pub external_only: bool,
|
||||||
pub format: &'static Format,
|
pub dmabuf: DmaBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for EglImage {
|
impl Drop for EglImage {
|
||||||
|
|
|
||||||
|
|
@ -60,8 +60,8 @@ impl GlRenderBuffer {
|
||||||
_tex: None,
|
_tex: None,
|
||||||
ctx: self.ctx.clone(),
|
ctx: self.ctx.clone(),
|
||||||
fbo,
|
fbo,
|
||||||
width: self.img.width,
|
width: self.img.dmabuf.width,
|
||||||
height: self.img.height,
|
height: self.img.dmabuf.height,
|
||||||
};
|
};
|
||||||
if status != GL_FRAMEBUFFER_COMPLETE {
|
if status != GL_FRAMEBUFFER_COMPLETE {
|
||||||
return Err(RenderError::CreateFramebuffer);
|
return Err(RenderError::CreateFramebuffer);
|
||||||
|
|
|
||||||
|
|
@ -56,10 +56,10 @@ impl GlTexture {
|
||||||
ctx: ctx.clone(),
|
ctx: ctx.clone(),
|
||||||
img: Some(img.clone()),
|
img: Some(img.clone()),
|
||||||
tex,
|
tex,
|
||||||
width: img.width,
|
width: img.dmabuf.width,
|
||||||
height: img.height,
|
height: img.dmabuf.height,
|
||||||
external_only: img.external_only,
|
external_only: img.external_only,
|
||||||
format: img.format,
|
format: img.dmabuf.format,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,6 @@ impl GfxFramebuffer for Framebuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format(&self) -> &'static Format {
|
fn format(&self) -> &'static Format {
|
||||||
self.gl.rb.img.format
|
self.gl.rb.img.dmabuf.format
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,11 @@ pub struct Image {
|
||||||
|
|
||||||
impl Image {
|
impl Image {
|
||||||
pub fn width(&self) -> i32 {
|
pub fn width(&self) -> i32 {
|
||||||
self.gl.width
|
self.gl.dmabuf.width
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn height(&self) -> i32 {
|
pub fn height(&self) -> i32 {
|
||||||
self.gl.height
|
self.gl.dmabuf.height
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_texture(self: &Rc<Self>) -> Result<Rc<Texture>, RenderError> {
|
fn to_texture(self: &Rc<Self>) -> Result<Rc<Texture>, RenderError> {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use {
|
||||||
format::Format,
|
format::Format,
|
||||||
gfx_api::{GfxError, GfxTexture},
|
gfx_api::{GfxError, GfxTexture},
|
||||||
gfx_apis::gl::{gl::texture::GlTexture, renderer::context::GlRenderContext, RenderError},
|
gfx_apis::gl::{gl::texture::GlTexture, renderer::context::GlRenderContext, RenderError},
|
||||||
|
video::dmabuf::DmaBuf,
|
||||||
},
|
},
|
||||||
std::{
|
std::{
|
||||||
any::Any,
|
any::Any,
|
||||||
|
|
@ -58,4 +59,8 @@ impl GfxTexture for Texture {
|
||||||
) -> Result<(), GfxError> {
|
) -> Result<(), GfxError> {
|
||||||
Err(RenderError::UnsupportedOperation.into())
|
Err(RenderError::UnsupportedOperation.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn dmabuf(&self) -> Option<&DmaBuf> {
|
||||||
|
self.gl.img.as_ref().map(|i| &i.dmabuf)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,7 @@ use {
|
||||||
},
|
},
|
||||||
theme::Color,
|
theme::Color,
|
||||||
utils::clonecell::CloneCell,
|
utils::clonecell::CloneCell,
|
||||||
video::{
|
video::dmabuf::{DmaBuf, PlaneVec},
|
||||||
dmabuf::{DmaBuf, DmaBufPlane, PlaneVec},
|
|
||||||
Modifier,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
ash::vk::{
|
ash::vk::{
|
||||||
BindImageMemoryInfo, BindImagePlaneMemoryInfo, ComponentMapping, ComponentSwizzle,
|
BindImageMemoryInfo, BindImagePlaneMemoryInfo, ComponentMapping, ComponentSwizzle,
|
||||||
|
|
@ -36,12 +33,10 @@ use {
|
||||||
|
|
||||||
pub struct VulkanDmaBufImageTemplate {
|
pub struct VulkanDmaBufImageTemplate {
|
||||||
pub(super) renderer: Rc<VulkanRenderer>,
|
pub(super) renderer: Rc<VulkanRenderer>,
|
||||||
pub(super) format: &'static Format,
|
|
||||||
pub(super) width: u32,
|
pub(super) width: u32,
|
||||||
pub(super) height: u32,
|
pub(super) height: u32,
|
||||||
pub(super) modifier: Modifier,
|
|
||||||
pub(super) disjoint: bool,
|
pub(super) disjoint: bool,
|
||||||
pub(super) planes: PlaneVec<DmaBufPlane>,
|
pub(super) dmabuf: DmaBuf,
|
||||||
pub(super) render_max_extents: Option<VulkanMaxExtents>,
|
pub(super) render_max_extents: Option<VulkanMaxExtents>,
|
||||||
pub(super) texture_max_extents: Option<VulkanMaxExtents>,
|
pub(super) texture_max_extents: Option<VulkanMaxExtents>,
|
||||||
}
|
}
|
||||||
|
|
@ -260,12 +255,10 @@ impl VulkanRenderer {
|
||||||
}
|
}
|
||||||
Ok(Rc::new(VulkanDmaBufImageTemplate {
|
Ok(Rc::new(VulkanDmaBufImageTemplate {
|
||||||
renderer: self.clone(),
|
renderer: self.clone(),
|
||||||
format: dmabuf.format,
|
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
modifier: dmabuf.modifier,
|
|
||||||
disjoint,
|
disjoint,
|
||||||
planes: dmabuf.planes.clone(),
|
dmabuf: dmabuf.clone(),
|
||||||
render_max_extents: modifier.render_max_extents,
|
render_max_extents: modifier.render_max_extents,
|
||||||
texture_max_extents: modifier.texture_max_extents,
|
texture_max_extents: modifier.texture_max_extents,
|
||||||
}))
|
}))
|
||||||
|
|
@ -332,6 +325,7 @@ impl VulkanDmaBufImageTemplate {
|
||||||
}
|
}
|
||||||
let image = {
|
let image = {
|
||||||
let plane_layouts: PlaneVec<_> = self
|
let plane_layouts: PlaneVec<_> = self
|
||||||
|
.dmabuf
|
||||||
.planes
|
.planes
|
||||||
.iter()
|
.iter()
|
||||||
.map(|p| SubresourceLayout {
|
.map(|p| SubresourceLayout {
|
||||||
|
|
@ -343,7 +337,7 @@ impl VulkanDmaBufImageTemplate {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let mut mod_info = ImageDrmFormatModifierExplicitCreateInfoEXT::builder()
|
let mut mod_info = ImageDrmFormatModifierExplicitCreateInfoEXT::builder()
|
||||||
.drm_format_modifier(self.modifier)
|
.drm_format_modifier(self.dmabuf.modifier)
|
||||||
.plane_layouts(&plane_layouts)
|
.plane_layouts(&plane_layouts)
|
||||||
.build();
|
.build();
|
||||||
let mut memory_image_create_info = ExternalMemoryImageCreateInfo::builder()
|
let mut memory_image_create_info = ExternalMemoryImageCreateInfo::builder()
|
||||||
|
|
@ -361,7 +355,7 @@ impl VulkanDmaBufImageTemplate {
|
||||||
};
|
};
|
||||||
let create_info = ImageCreateInfo::builder()
|
let create_info = ImageCreateInfo::builder()
|
||||||
.image_type(ImageType::TYPE_2D)
|
.image_type(ImageType::TYPE_2D)
|
||||||
.format(self.format.vk_format)
|
.format(self.dmabuf.format.vk_format)
|
||||||
.mip_levels(1)
|
.mip_levels(1)
|
||||||
.array_layers(1)
|
.array_layers(1)
|
||||||
.tiling(ImageTiling::DRM_FORMAT_MODIFIER_EXT)
|
.tiling(ImageTiling::DRM_FORMAT_MODIFIER_EXT)
|
||||||
|
|
@ -383,14 +377,14 @@ impl VulkanDmaBufImageTemplate {
|
||||||
};
|
};
|
||||||
let destroy_image = OnDrop(|| unsafe { device.device.destroy_image(image, None) });
|
let destroy_image = OnDrop(|| unsafe { device.device.destroy_image(image, None) });
|
||||||
let num_device_memories = match self.disjoint {
|
let num_device_memories = match self.disjoint {
|
||||||
true => self.planes.len(),
|
true => self.dmabuf.planes.len(),
|
||||||
false => 1,
|
false => 1,
|
||||||
};
|
};
|
||||||
let mut device_memories = PlaneVec::new();
|
let mut device_memories = PlaneVec::new();
|
||||||
let mut free_device_memories = PlaneVec::new();
|
let mut free_device_memories = PlaneVec::new();
|
||||||
let mut bind_image_plane_memory_infos = PlaneVec::new();
|
let mut bind_image_plane_memory_infos = PlaneVec::new();
|
||||||
for plane_idx in 0..num_device_memories {
|
for plane_idx in 0..num_device_memories {
|
||||||
let dma_buf_plane = &self.planes[plane_idx];
|
let dma_buf_plane = &self.dmabuf.planes[plane_idx];
|
||||||
let memory_fd_properties = unsafe {
|
let memory_fd_properties = unsafe {
|
||||||
device.external_memory_fd.get_memory_fd_properties(
|
device.external_memory_fd.get_memory_fd_properties(
|
||||||
ExternalMemoryHandleTypeFlags::DMA_BUF_EXT,
|
ExternalMemoryHandleTypeFlags::DMA_BUF_EXT,
|
||||||
|
|
@ -467,8 +461,8 @@ impl VulkanDmaBufImageTemplate {
|
||||||
}
|
}
|
||||||
let res = unsafe { device.device.bind_image_memory2(&bind_image_memory_infos) };
|
let res = unsafe { device.device.bind_image_memory2(&bind_image_memory_infos) };
|
||||||
res.map_err(VulkanError::BindImageMemory)?;
|
res.map_err(VulkanError::BindImageMemory)?;
|
||||||
let texture_view = device.create_image_view(image, self.format, false)?;
|
let texture_view = device.create_image_view(image, self.dmabuf.format, false)?;
|
||||||
let render_view = device.create_image_view(image, self.format, true)?;
|
let render_view = device.create_image_view(image, self.dmabuf.format, true)?;
|
||||||
free_device_memories.drain(..).for_each(mem::forget);
|
free_device_memories.drain(..).for_each(mem::forget);
|
||||||
mem::forget(destroy_image);
|
mem::forget(destroy_image);
|
||||||
Ok(Rc::new(VulkanImage {
|
Ok(Rc::new(VulkanImage {
|
||||||
|
|
@ -484,7 +478,7 @@ impl VulkanDmaBufImageTemplate {
|
||||||
template: self.clone(),
|
template: self.clone(),
|
||||||
mems: device_memories,
|
mems: device_memories,
|
||||||
}),
|
}),
|
||||||
format: self.format,
|
format: self.dmabuf.format,
|
||||||
is_undefined: Cell::new(true),
|
is_undefined: Cell::new(true),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
@ -579,4 +573,11 @@ impl GfxTexture for VulkanImage {
|
||||||
.read_pixels(&self, x, y, width, height, stride, format, shm)
|
.read_pixels(&self, x, y, width, height, stride, format, shm)
|
||||||
.map_err(|e| e.into())
|
.map_err(|e| e.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn dmabuf(&self) -> Option<&DmaBuf> {
|
||||||
|
match &self.ty {
|
||||||
|
VulkanImageMemory::DmaBuf(b) => Some(&b.template.dmabuf),
|
||||||
|
VulkanImageMemory::Internal(_) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -532,7 +532,7 @@ impl VulkanRenderer {
|
||||||
flag: u32|
|
flag: u32|
|
||||||
-> Result<(), VulkanError> {
|
-> Result<(), VulkanError> {
|
||||||
if let VulkanImageMemory::DmaBuf(buf) = &img.ty {
|
if let VulkanImageMemory::DmaBuf(buf) = &img.ty {
|
||||||
for plane in &buf.template.planes {
|
for plane in &buf.template.dmabuf.planes {
|
||||||
let fd = dma_buf_export_sync_file(&plane.fd, flag)
|
let fd = dma_buf_export_sync_file(&plane.fd, flag)
|
||||||
.map_err(VulkanError::IoctlExportSyncFile)?;
|
.map_err(VulkanError::IoctlExportSyncFile)?;
|
||||||
let semaphore = self.allocate_semaphore()?;
|
let semaphore = self.allocate_semaphore()?;
|
||||||
|
|
@ -573,7 +573,7 @@ impl VulkanRenderer {
|
||||||
};
|
};
|
||||||
let import = |img: &VulkanImage, flag: u32| {
|
let import = |img: &VulkanImage, flag: u32| {
|
||||||
if let VulkanImageMemory::DmaBuf(buf) = &img.ty {
|
if let VulkanImageMemory::DmaBuf(buf) = &img.ty {
|
||||||
for plane in &buf.template.planes {
|
for plane in &buf.template.dmabuf.planes {
|
||||||
let res = dma_buf_import_sync_file(&plane.fd, flag, &syncfile)
|
let res = dma_buf_import_sync_file(&plane.fd, flag, &syncfile)
|
||||||
.map_err(VulkanError::IoctlImportSyncFile);
|
.map_err(VulkanError::IoctlImportSyncFile);
|
||||||
if let Err(e) = res {
|
if let Err(e) = res {
|
||||||
|
|
@ -764,7 +764,7 @@ impl VulkanRenderer {
|
||||||
let mut semaphores = vec![];
|
let mut semaphores = vec![];
|
||||||
let mut semaphore_infos = vec![];
|
let mut semaphore_infos = vec![];
|
||||||
if let VulkanImageMemory::DmaBuf(buf) = &tex.ty {
|
if let VulkanImageMemory::DmaBuf(buf) = &tex.ty {
|
||||||
for plane in &buf.template.planes {
|
for plane in &buf.template.dmabuf.planes {
|
||||||
let fd = dma_buf_export_sync_file(&plane.fd, DMA_BUF_SYNC_READ)
|
let fd = dma_buf_export_sync_file(&plane.fd, DMA_BUF_SYNC_READ)
|
||||||
.map_err(VulkanError::IoctlExportSyncFile)?;
|
.map_err(VulkanError::IoctlExportSyncFile)?;
|
||||||
let semaphore = self.allocate_semaphore()?;
|
let semaphore = self.allocate_semaphore()?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue