Merge main: one linux-dmabuf, imported on the GPU or mapped without one
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
d478f58d9b
54 files changed
+1110
-376
No files matched your search
@@ -288,6 +288,15 @@ int32_t mp_pwrite_bytes(int32_t fd, moonbit_bytes_t buf, int32_t len, int32_t of
|
||||
return w < 0 ? -1 : (int32_t)w;
|
||||
}
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/dma-buf.h>
|
||||
|
||||
/* Wait for the GPU to finish writing a dma-buf before the CPU reads it; harmless on shm files. */
|
||||
static void dmabuf_sync(int fd, int start) {
|
||||
struct dma_buf_sync sync = { .flags = (start ? DMA_BUF_SYNC_START : DMA_BUF_SYNC_END) | DMA_BUF_SYNC_READ };
|
||||
ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync);
|
||||
}
|
||||
|
||||
MOONBIT_FFI_EXPORT
|
||||
moonbit_bytes_t mp_mmap_read(int32_t fd, int32_t size) {
|
||||
if (fd < 0 || size <= 0) {
|
||||
@@ -302,7 +311,9 @@ moonbit_bytes_t mp_mmap_read(int32_t fd, int32_t size) {
|
||||
return moonbit_make_bytes_raw(0);
|
||||
}
|
||||
moonbit_bytes_t out = moonbit_make_bytes_raw(size);
|
||||
dmabuf_sync(fd, 1);
|
||||
memcpy(out, ptr, (size_t)size);
|
||||
dmabuf_sync(fd, 0);
|
||||
munmap(ptr, (size_t)size);
|
||||
return out;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user