gpu: make Buffer.bufferMapAsync friendlier

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-07-31 10:27:43 -07:00 committed by Stephen Gutekanst
parent 13058274b0
commit 2b4ba59cc8
2 changed files with 18 additions and 5 deletions

View file

@ -82,8 +82,8 @@ pub const Adapter = opaque {
) callconv(.Inline) void,
context: Context,
) void {
const c_callback = struct {
pub fn callback(status: RequestDeviceStatus, device: *Device, message: ?[*:0]const u8, userdata: ?*anyopaque) void {
const Helper = struct {
pub fn callback(status: RequestDeviceStatus, device: *Device, message: ?[*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
callback(
status,
device,
@ -92,7 +92,7 @@ pub const Adapter = opaque {
);
}
};
Impl.adapterRequestDevice(adapter, descriptor, c_callback, if (Context == void) null orelse context);
Impl.adapterRequestDevice(adapter, descriptor, Helper.callback, if (Context == void) null orelse context);
}
pub inline fn reference(adapter: *Adapter) void {

View file

@ -89,8 +89,21 @@ pub const Buffer = opaque {
return Impl.bufferGetUsage(buffer);
}
pub inline fn bufferMapAsync(buffer: *Buffer, mode: MapModeFlags, offset: usize, size: usize, callback: MapCallback, userdata: ?*anyopaque) void {
Impl.bufferMapAsync(buffer, mode, offset, size, callback, userdata);
pub inline fn bufferMapAsync(
buffer: *Buffer,
mode: MapModeFlags,
offset: usize,
size: usize,
comptime Context: type,
comptime callback: fn (status: MapAsyncStatus, ctx: Context) callconv(.Inline) void,
context: Context,
) void {
const Helper = struct {
pub fn callback(status: MapAsyncStatus, userdata: ?*anyopaque) callconv(.C) void {
callback(status, if (Context == void) {} orelse @ptrCast(Context, userdata));
}
};
Impl.bufferMapAsync(buffer, mode, offset, size, Helper.callback, if (Context == void) null orelse context);
}
pub inline fn bufferSetLabel(buffer: *Buffer, label: [*:0]const u8) void {