summaryrefslogtreecommitdiff
path: root/src/cocoa/window.m
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-12 14:31:10 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-12 14:31:10 +0300
commitdfebac1019560e278c605247de3b98cff1d73226 (patch)
tree21df3066f2e60496f259a5981ca5501b4e395b61 /src/cocoa/window.m
parent9ed89c17dee752154c36d71cae93d20cccfc71ef (diff)
perf: cache Cocoa software MTLBuffer and optimize Wayland output/focus loops
Diffstat (limited to 'src/cocoa/window.m')
-rw-r--r--src/cocoa/window.m15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/cocoa/window.m b/src/cocoa/window.m
index 78ab0bd..8856fde 100644
--- a/src/cocoa/window.m
+++ b/src/cocoa/window.m
@@ -53,6 +53,8 @@ struct cocoa_surface {
YaslView *view;
CAMetalLayer *layer;
id<MTLCommandQueue> software_queue;
+ id<MTLBuffer> software_buffer;
+ NSUInteger software_buffer_capacity;
CADisplayLink *link;
struct cocoa_surface *parent;
@@ -1031,15 +1033,20 @@ bool cocoa_surface_present(struct cocoa_surface *w, const struct yasl_framebuffe
return false;
NSUInteger row_bytes = ((NSUInteger)w->size.x * 4 + 255) & ~(NSUInteger)255;
NSUInteger length = row_bytes * (NSUInteger)w->size.y;
- id<MTLBuffer> buffer = [w->layer.device newBufferWithLength:length
- options:MTLResourceStorageModeShared];
+ if (!w->software_buffer || w->software_buffer_capacity < length) {
+ [w->software_buffer release];
+ w->software_buffer = [w->layer.device newBufferWithLength:length
+ options:MTLResourceStorageModeShared];
+ w->software_buffer_capacity = w->software_buffer ? length : 0;
+ }
+ id<MTLBuffer> buffer = w->software_buffer;
if (!buffer) return false;
for (int y = 0; y < w->size.y; y++)
memcpy((char *)buffer.contents + (NSUInteger)y * row_bytes,
w->pixels + (size_t)y * w->size.x, (size_t)w->size.x * 4);
id<MTLCommandBuffer> command = [w->software_queue commandBuffer];
id<MTLBlitCommandEncoder> blit = [command blitCommandEncoder];
- if (!blit) { [buffer release]; return false; }
+ if (!blit) return false;
id<CAMetalDrawable> drawable = w->drawable;
[blit copyFromBuffer:buffer sourceOffset:0 sourceBytesPerRow:row_bytes
sourceBytesPerImage:length sourceSize:MTLSizeMake(w->size.x, w->size.y, 1)
@@ -1048,7 +1055,6 @@ bool cocoa_surface_present(struct cocoa_surface *w, const struct yasl_framebuffe
[blit endEncoding];
[command presentDrawable:drawable];
[command commit];
- [buffer release];
}
yasl_clock_presented(&w->clock, yasl_loop_now_ns(), false);
w->did_present = true;
@@ -1394,6 +1400,7 @@ struct cocoa_surface *cocoa_surface_create_toplevel(struct cocoa_display *d,
static void surface_free(struct cocoa_surface *w)
{
[w->link release];
+ [w->software_buffer release];
[w->software_queue release];
[w->view release];
[w->controller release];