From 134c2019b1cdd1e8154c2b5601a2e410a28d047c Mon Sep 17 00:00:00 2001 From: dweiller <4678790+dweiller@users.noreplay.github.com> Date: Thu, 23 Jun 2022 14:10:32 +1000 Subject: [PATCH] gpu: remove Queue.WorkDownCallback lifetime footgun The previous implementation required the specific Queue struct that submit() was called on to be valid when the callback is triggered. By storing a pointer instead, the Queue does not need to be valid, only the callback itself. --- gpu/src/NativeInstance.zig | 2 +- gpu/src/Queue.zig | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/gpu/src/NativeInstance.zig b/gpu/src/NativeInstance.zig index 28b74be8..d8f1ed7d 100644 --- a/gpu/src/NativeInstance.zig +++ b/gpu/src/NativeInstance.zig @@ -902,7 +902,7 @@ const queue_vtable = Queue.VTable{ wgpu_queue, signal_value, cCallback, - &queue.on_submitted_work_done, + queue.on_submitted_work_done, ); } diff --git a/gpu/src/Queue.zig b/gpu/src/Queue.zig index 206be857..2e5b5a9c 100644 --- a/gpu/src/Queue.zig +++ b/gpu/src/Queue.zig @@ -8,7 +8,10 @@ const Texture = @import("Texture.zig"); const Queue = @This(); -on_submitted_work_done: ?WorkDoneCallback = null, +/// Callback to executed when all work has been done +/// This field must be set before calling `submit()` on the commands the callback waits for. +/// Note that the address stored must be valid when the callback is executed. +on_submitted_work_done: ?*WorkDoneCallback = null, /// The type erased pointer to the Queue implementation /// Equal to c.WGPUQueue for NativeInstance.