render: use explicit sync for framebuffers
This commit is contained in:
parent
1bc344dcc2
commit
386ee5120f
15 changed files with 235 additions and 64 deletions
|
|
@ -73,6 +73,7 @@ use {
|
|||
ReleaseSync, SyncFile,
|
||||
},
|
||||
gfx_apis::gl::{
|
||||
egl::image::EglImage,
|
||||
gl::texture::image_target,
|
||||
renderer::{
|
||||
context::{GlRenderContext, TexCopyType, TexSourceType},
|
||||
|
|
@ -328,7 +329,7 @@ fn render_texture(ctx: &GlRenderContext, tex: &CopyTexture) {
|
|||
assert!(rc_eq(&ctx.ctx, &texture.ctx.ctx));
|
||||
let gles = ctx.ctx.dpy.gles;
|
||||
unsafe {
|
||||
handle_explicit_sync(ctx, texture, &tex.acquire_sync);
|
||||
handle_explicit_sync(ctx, texture.gl.img.as_ref(), &tex.acquire_sync);
|
||||
|
||||
(gles.glActiveTexture)(GL_TEXTURE0);
|
||||
|
||||
|
|
@ -395,7 +396,7 @@ fn render_texture(ctx: &GlRenderContext, tex: &CopyTexture) {
|
|||
}
|
||||
}
|
||||
|
||||
fn handle_explicit_sync(ctx: &GlRenderContext, texture: &Texture, sync: &AcquireSync) {
|
||||
fn handle_explicit_sync(ctx: &GlRenderContext, img: Option<&Rc<EglImage>>, sync: &AcquireSync) {
|
||||
let sync_file = match sync {
|
||||
AcquireSync::None | AcquireSync::Implicit | AcquireSync::Unnecessary => return,
|
||||
AcquireSync::SyncFile { sync_file } => sync_file,
|
||||
|
|
@ -417,7 +418,7 @@ fn handle_explicit_sync(ctx: &GlRenderContext, texture: &Texture, sync: &Acquire
|
|||
};
|
||||
sync.wait();
|
||||
} else {
|
||||
if let Some(img) = &texture.gl.img {
|
||||
if let Some(img) = img {
|
||||
if let Err(e) = img.dmabuf.import_sync_file(DMA_BUF_SYNC_READ, &sync_file) {
|
||||
log::error!("Could not import sync file into dmabuf: {}", ErrorFmt(e));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
use {
|
||||
crate::{
|
||||
format::Format,
|
||||
gfx_api::{GfxApiOpt, GfxError, GfxFramebuffer, SyncFile},
|
||||
gfx_api::{AcquireSync, GfxApiOpt, GfxError, GfxFramebuffer, ReleaseSync, SyncFile},
|
||||
gfx_apis::gl::{
|
||||
gl::{
|
||||
frame_buffer::GlFrameBuffer,
|
||||
sys::{GL_COLOR_BUFFER_BIT, GL_FRAMEBUFFER},
|
||||
},
|
||||
handle_explicit_sync,
|
||||
renderer::context::GlRenderContext,
|
||||
run_ops,
|
||||
sys::{GL_ONE, GL_ONE_MINUS_SRC_ALPHA},
|
||||
|
|
@ -69,11 +70,13 @@ impl Framebuffer {
|
|||
|
||||
pub fn render(
|
||||
&self,
|
||||
acquire_sync: AcquireSync,
|
||||
ops: &[GfxApiOpt],
|
||||
clear: Option<&Color>,
|
||||
) -> Result<Option<SyncFile>, RenderError> {
|
||||
let gles = self.ctx.ctx.dpy.gles;
|
||||
self.ctx.ctx.with_current(|| {
|
||||
handle_explicit_sync(&self.ctx, self.gl.rb._img.as_ref(), &acquire_sync);
|
||||
unsafe {
|
||||
(gles.glBindFramebuffer)(GL_FRAMEBUFFER, self.gl.fbo);
|
||||
(gles.glViewport)(0, 0, self.gl.width, self.gl.height);
|
||||
|
|
@ -101,10 +104,12 @@ impl GfxFramebuffer for Framebuffer {
|
|||
|
||||
fn render(
|
||||
&self,
|
||||
acquire_sync: AcquireSync,
|
||||
_release_sync: ReleaseSync,
|
||||
ops: &[GfxApiOpt],
|
||||
clear: Option<&Color>,
|
||||
) -> Result<Option<SyncFile>, GfxError> {
|
||||
self.render(ops, clear).map_err(|e| e.into())
|
||||
self.render(acquire_sync, ops, clear).map_err(|e| e.into())
|
||||
}
|
||||
|
||||
fn copy_to_shm(
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ use {
|
|||
clientmem::ClientMemOffset,
|
||||
format::Format,
|
||||
gfx_api::{
|
||||
AsyncShmGfxTexture, AsyncShmGfxTextureCallback, AsyncShmGfxTextureUploadCancellable,
|
||||
GfxApiOpt, GfxError, GfxFramebuffer, GfxImage, GfxTexture, PendingShmUpload,
|
||||
ShmGfxTexture, SyncFile,
|
||||
AcquireSync, AsyncShmGfxTexture, AsyncShmGfxTextureCallback,
|
||||
AsyncShmGfxTextureUploadCancellable, GfxApiOpt, GfxError, GfxFramebuffer, GfxImage,
|
||||
GfxTexture, PendingShmUpload, ReleaseSync, ShmGfxTexture, SyncFile,
|
||||
},
|
||||
gfx_apis::vulkan::{
|
||||
allocator::VulkanAllocation, device::VulkanDevice, format::VulkanModifierLimits,
|
||||
|
|
@ -465,11 +465,13 @@ impl GfxFramebuffer for VulkanImage {
|
|||
|
||||
fn render(
|
||||
&self,
|
||||
acquire_sync: AcquireSync,
|
||||
release_sync: ReleaseSync,
|
||||
ops: &[GfxApiOpt],
|
||||
clear: Option<&Color>,
|
||||
) -> Result<Option<SyncFile>, GfxError> {
|
||||
self.renderer
|
||||
.execute(self, ops, clear)
|
||||
.execute(self, acquire_sync, release_sync, ops, clear)
|
||||
.map_err(|e| e.into())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -643,7 +643,11 @@ impl VulkanRenderer {
|
|||
}
|
||||
}
|
||||
|
||||
fn create_wait_semaphores(&self, fb: &VulkanImage) -> Result<(), VulkanError> {
|
||||
fn create_wait_semaphores(
|
||||
&self,
|
||||
fb: &VulkanImage,
|
||||
fb_acquire_sync: &AcquireSync,
|
||||
) -> Result<(), VulkanError> {
|
||||
zone!("create_wait_semaphores");
|
||||
let mut memory = self.memory.borrow_mut();
|
||||
let memory = &mut *memory;
|
||||
|
|
@ -699,13 +703,13 @@ impl VulkanRenderer {
|
|||
&mut memory.wait_semaphore_infos,
|
||||
&mut memory.wait_semaphores,
|
||||
fb,
|
||||
&AcquireSync::Implicit,
|
||||
fb_acquire_sync,
|
||||
DMA_BUF_SYNC_WRITE,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn import_release_semaphore(&self, fb: &VulkanImage) {
|
||||
fn import_release_semaphore(&self, fb: &VulkanImage, fb_release_sync: ReleaseSync) {
|
||||
zone!("import_release_semaphore");
|
||||
let memory = &mut *self.memory.borrow_mut();
|
||||
let sync_file = match memory.release_sync_file.as_ref() {
|
||||
|
|
@ -736,7 +740,7 @@ impl VulkanRenderer {
|
|||
DMA_BUF_SYNC_READ,
|
||||
);
|
||||
}
|
||||
import(fb, ReleaseSync::Implicit, None, DMA_BUF_SYNC_WRITE);
|
||||
import(fb, fb_release_sync, None, DMA_BUF_SYNC_WRITE);
|
||||
}
|
||||
|
||||
fn submit(&self, buf: CommandBuffer) -> Result<(), VulkanError> {
|
||||
|
|
@ -838,7 +842,10 @@ impl VulkanRenderer {
|
|||
)?;
|
||||
(&*tmp_tex as &dyn GfxFramebuffer)
|
||||
.copy_texture(
|
||||
AcquireSync::None,
|
||||
ReleaseSync::None,
|
||||
&(tex.clone() as _),
|
||||
None,
|
||||
AcquireSync::None,
|
||||
ReleaseSync::None,
|
||||
x,
|
||||
|
|
@ -992,11 +999,13 @@ impl VulkanRenderer {
|
|||
pub fn execute(
|
||||
self: &Rc<Self>,
|
||||
fb: &VulkanImage,
|
||||
fb_acquire_sync: AcquireSync,
|
||||
fb_release_sync: ReleaseSync,
|
||||
opts: &[GfxApiOpt],
|
||||
clear: Option<&Color>,
|
||||
) -> Result<Option<SyncFile>, VulkanError> {
|
||||
zone!("execute");
|
||||
let res = self.try_execute(fb, opts, clear);
|
||||
let res = self.try_execute(fb, fb_acquire_sync, fb_release_sync, opts, clear);
|
||||
let sync_file = {
|
||||
let mut memory = self.memory.borrow_mut();
|
||||
memory.textures.clear();
|
||||
|
|
@ -1032,6 +1041,8 @@ impl VulkanRenderer {
|
|||
fn try_execute(
|
||||
self: &Rc<Self>,
|
||||
fb: &VulkanImage,
|
||||
fb_acquire_sync: AcquireSync,
|
||||
fb_release_sync: ReleaseSync,
|
||||
opts: &[GfxApiOpt],
|
||||
clear: Option<&Color>,
|
||||
) -> Result<(), VulkanError> {
|
||||
|
|
@ -1047,9 +1058,9 @@ impl VulkanRenderer {
|
|||
self.copy_bridge_to_dmabuf(buf.buffer, fb);
|
||||
self.final_barriers(buf.buffer, fb);
|
||||
self.end_command_buffer(buf.buffer)?;
|
||||
self.create_wait_semaphores(fb)?;
|
||||
self.create_wait_semaphores(fb, &fb_acquire_sync)?;
|
||||
self.submit(buf.buffer)?;
|
||||
self.import_release_semaphore(fb);
|
||||
self.import_release_semaphore(fb, fb_release_sync);
|
||||
self.store_layouts(fb);
|
||||
self.create_pending_frame(buf);
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue