1
0
Fork 0
forked from wry/wry

render: use explicit sync for framebuffers

This commit is contained in:
Julian Orth 2024-09-16 15:28:44 +02:00
parent 1bc344dcc2
commit 386ee5120f
15 changed files with 235 additions and 64 deletions

View file

@ -9,7 +9,7 @@ use {
},
gfx_api::{
create_render_pass, AcquireSync, BufferResv, GfxApiOpt, GfxRenderPass, GfxTexture,
SyncFile,
ReleaseSync, SyncFile,
},
theme::Color,
time::Time,
@ -43,7 +43,8 @@ pub struct DirectScanoutCache {
pub struct DirectScanoutData {
tex: Rc<dyn GfxTexture>,
acquire_sync: AcquireSync,
_resv: Option<Rc<dyn BufferResv>>,
release_sync: ReleaseSync,
resv: Option<Rc<dyn BufferResv>>,
fb: Rc<DrmFramebuffer>,
dma_buf_id: DmaBufId,
position: DirectScanoutPosition,
@ -618,7 +619,8 @@ impl MetalConnector {
return buffer.fb.as_ref().map(|fb| DirectScanoutData {
tex: buffer.tex.upgrade().unwrap(),
acquire_sync: ct.acquire_sync.clone(),
_resv: ct.buffer_resv.clone(),
release_sync: ct.release_sync,
resv: ct.buffer_resv.clone(),
fb: fb.clone(),
dma_buf_id: dmabuf.id,
position,
@ -643,7 +645,8 @@ impl MetalConnector {
Ok(fb) => Some(DirectScanoutData {
tex: ct.tex.clone(),
acquire_sync: ct.acquire_sync.clone(),
_resv: ct.buffer_resv.clone(),
release_sync: ct.release_sync,
resv: ct.buffer_resv.clone(),
fb: Rc::new(fb),
dma_buf_id: dmabuf.id,
position,
@ -708,7 +711,7 @@ impl MetalConnector {
None => {
let sf = buffer
.render_fb()
.perform_render_pass(pass)
.perform_render_pass(AcquireSync::Unnecessary, ReleaseSync::Explicit, pass)
.map_err(MetalError::RenderFrame)?;
sync_file = buffer.copy_to_dev(sf)?;
fb = buffer.drm.clone();
@ -748,11 +751,23 @@ impl MetalConnector {
let render_hardware_cursor = self.cursor_enabled.get();
match &fb.direct_scanout_data {
None => {
output.perform_screencopies(&fb.tex, render_hardware_cursor, 0, 0, None);
output.perform_screencopies(
&fb.tex,
None,
&AcquireSync::Unnecessary,
ReleaseSync::None,
render_hardware_cursor,
0,
0,
None,
);
}
Some(dsd) => {
output.perform_screencopies(
&dsd.tex,
dsd.resv.as_ref(),
&dsd.acquire_sync,
dsd.release_sync,
render_hardware_cursor,
dsd.position.crtc_x,
dsd.position.crtc_y,

View file

@ -2474,7 +2474,9 @@ impl MetalBackend {
Ok(fb) => fb,
Err(e) => return Err(MetalError::ImportFb(e)),
};
dev_fb.clear().map_err(MetalError::Clear)?;
dev_fb
.clear(AcquireSync::Unnecessary, ReleaseSync::None)
.map_err(MetalError::Clear)?;
let (dev_tex, render_tex, render_fb, render_bo) = if dev.id == render_ctx.dev_id {
let render_tex = match dev_img.to_texture() {
Ok(fb) => fb,
@ -2526,7 +2528,9 @@ impl MetalBackend {
Ok(fb) => fb,
Err(e) => return Err(MetalError::ImportFb(e)),
};
render_fb.clear().map_err(MetalError::Clear)?;
render_fb
.clear(AcquireSync::Unnecessary, ReleaseSync::None)
.map_err(MetalError::Clear)?;
let render_tex = match render_img.to_texture() {
Ok(fb) => fb,
Err(e) => return Err(MetalError::ImportTexture(e)),
@ -2797,9 +2801,17 @@ impl RenderBuffer {
let Some(tex) = &self.dev_tex else {
return Ok(sync_file);
};
let acquire_point = AcquireSync::from_sync_file(sync_file);
self.dev_fb
.copy_texture(tex, acquire_point, ReleaseSync::Implicit, 0, 0)
.copy_texture(
AcquireSync::Unnecessary,
ReleaseSync::Explicit,
tex,
None,
AcquireSync::from_sync_file(sync_file),
ReleaseSync::None,
0,
0,
)
.map_err(MetalError::CopyToOutput)
}
}

View file

@ -10,7 +10,7 @@ use {
},
fixed::Fixed,
format::XRGB8888,
gfx_api::{GfxContext, GfxError, GfxFramebuffer, GfxTexture},
gfx_api::{AcquireSync, GfxContext, GfxError, GfxFramebuffer, GfxTexture, ReleaseSync},
ifs::wl_output::OutputId,
state::State,
utils::{
@ -750,9 +750,14 @@ impl XBackend {
image.last_serial.set(serial);
if let Some(node) = self.state.root.outputs.get(&output.id) {
let res = self
.state
.present_output(&node, &image.fb.get(), &image.tex.get(), true);
let res = self.state.present_output(
&node,
&image.fb.get(),
AcquireSync::Implicit,
ReleaseSync::Implicit,
&image.tex.get(),
true,
);
if let Err(e) = res {
log::error!("Could not render screen: {}", ErrorFmt(e));
return;