8000 metal: take a drawable only in frames that draw to the screen by benface · Pull Request #693 · not-fl3/miniquad · GitHub
[go: up one dir, main page]

Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/graphics/metal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ pub struct MetalContext {
// / `end_render_pass`.
current_pass_target: Option<Option<RenderPass>>,
pending_end_encoder: bool,
/// Whether this frame drew to the screen, which takes one of the
/// view's drawables, so `commit_frame` presents it.
drew_to_screen: bool,
v 8000 iew: ObjcId,
device: ObjcId,
current_frame_index: usize,
Expand Down Expand Up @@ -388,6 +391,7 @@ impl MetalContext {
current_pass_height: 0,
current_pass_target: None,
pending_end_encoder: false,
drew_to_screen: false,
view,
device,
buffers: vec![],
Expand Down Expand Up @@ -1312,6 +1316,7 @@ impl RenderingBackend for MetalContext {

let (descriptor, width_px, height_px) = match pass {
None => {
self.drew_to_screen = true;
// Read dimensions from the actual pass attachment
// texture, not `screen_size()`. MTKView's
// `drawableSize` and our cached screen size can
Expand Down Expand Up @@ -1454,12 +1459,18 @@ impl RenderingBackend for MetalContext {
}
unsafe {
assert!(!self.command_queue.is_null());
let drawable: ObjcId = msg_send!(self.view, currentDrawable);
//msg_send_![drawable, retain];
msg_send_![self.command_buffer.unwrap(), presentDrawable: drawable];
msg_send_![self.command_buffer.unwrap(), commit];
msg_send_![self.command_buffer.unwrap(), waitUntilCompleted];
if let Some(command_buffer) = self.command_buffer {
// A frame drawn only off-screen leaves the drawables alone:
// `currentDrawable` waits until the display is done with one.
if self.drew_to_screen {
let drawable: ObjcId = msg_send!(self.view, currentDrawable);
msg_send_![command_buffer, presentDrawable: drawable];
}
msg_send_![command_buffer, commit];
msg_send_![command_buffer, waitUntilCompleted];
}
}
self.drew_to_screen = false;
for buffer in &mut self.buffers {
buffer.next_value = 0;
}
Expand Down
Loading
0