Skip to content

Commit e4f2e98

Browse files
committed
[Metal] Implement waits
1 parent 239d93f commit e4f2e98

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

backends/gpu/metal/sources/device.m

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,29 @@ kore_gpu_texture_format kore_metal_device_framebuffer_format(kore_gpu_device *de
110110
return KORE_GPU_TEXTURE_FORMAT_BGRA8_UNORM;
111111
}
112112

113+
static void *last_running_command_buffer = NULL;
114+
113115
void kore_metal_device_execute_command_list(kore_gpu_device *device, kore_gpu_command_list *list) {
114116
kore_metal_command_list_end_compute_pass(list);
115117
kore_metal_command_list_end_blit_pass(list);
116118

117119
id<MTLCommandBuffer> command_buffer = (__bridge id<MTLCommandBuffer>)list->metal.command_buffer;
118120
[command_buffer commit];
119121

122+
last_running_command_buffer = (__bridge_retained void *)command_buffer;
123+
120124
id<MTLCommandQueue> command_queue = (__bridge id<MTLCommandQueue>)list->metal.command_queue;
121125
command_buffer = [command_queue commandBuffer];
122126
list->metal.command_buffer = (__bridge_retained void *)[command_queue commandBuffer];
123127
}
124128

125-
void kore_metal_device_wait_until_idle(kore_gpu_device *device) {}
129+
void kore_metal_device_wait_until_idle(kore_gpu_device *device) {
130+
if (last_running_command_buffer != NULL) {
131+
id<MTLCommandBuffer> command_buffer = (__bridge id<MTLCommandBuffer>)last_running_command_buffer;
132+
[command_buffer waitUntilCompleted];
133+
last_running_command_buffer = NULL;
134+
}
135+
}
126136

127137
void kore_metal_device_create_descriptor_set_buffer(kore_gpu_device *device, uint64_t encoded_length, kore_gpu_buffer *buffer) {
128138
id<MTLDevice> metal_device = (__bridge id<MTLDevice>)device->metal.device;

0 commit comments

Comments
 (0)