From 2e611565b46c702dafa3ec16e769e5ba08679c8e Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sun, 31 Jul 2022 13:40:36 -0700 Subject: [PATCH] gpu: make Device.createRenderPipelineAsync friendlier Signed-off-by: Stephen Gutekanst --- gpu/src/device.zig | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/gpu/src/device.zig b/gpu/src/device.zig index 3e0bfe85..b73add5d 100644 --- a/gpu/src/device.zig +++ b/gpu/src/device.zig @@ -75,7 +75,7 @@ pub const Device = opaque { comptime Context: type, comptime callback: fn ( status: CreatePipelineAsyncStatus, - compute_pipeline: *ComputePipeline,' + compute_pipeline: *ComputePipeline, message: [*:0]const u8, ctx: Context, ) callconv(.Inline) void, @@ -130,10 +130,31 @@ pub const Device = opaque { pub inline fn createRenderPipelineAsync( device: *Device, descriptor: *const RenderPipeline.Descriptor, - callback: CreateRenderPipelineAsyncCallback, - userdata: ?*anyopaque, + comptime Context: type, + comptime callback: fn ( + status: CreatePipelineAsyncStatus, + pipeline: *RenderPipeline, + message: [*:0]const u8, + ctx: Context, + ) callconv(.Inline) void, + context: Context, ) void { - Impl.deviceCreateRenderPipelineAsync(device, descriptor, callback, userdata); + const Helper = struct { + pub fn callback( + status: CreatePipelineAsyncStatus, + pipeline: *RenderPipeline, + message: [*:0]const u8, + userdata: ?*anyopaque, + ) callconv(.C) void { + callback( + status, + pipeline, + message, + if (Context == void) {} else @ptrCast(Context, userdata), + ); + } + }; + Impl.deviceCreateRenderPipelineAsync(device, descriptor, Helper.callback, if (Context == void) null else context); } pub inline fn createSampler(device: *Device, descriptor: ?*const Sampler.Descriptor) *Sampler {