* @brief Asynchronously submits a kernel to the GPU queue for execution. * It also sets up a callback to notify when the kernel has finished executing * by setting the value of the promise in the kernel instance argument. * * dispatchKernel does *not* wait for the kernel to finish executing and * returns immediately. The caller can wait for the kernel to finish executing * by calling wait()
| 1427 | * @endcode |
| 1428 | */ |
| 1429 | inline void dispatchKernel(Context &ctx, Kernel &kernel, |
| 1430 | std::promise<void> &promise) { |
| 1431 | // Submit the command buffer |
| 1432 | wgpuQueueSubmit(ctx.queue, 1, &kernel.commandBuffer); |
| 1433 | wgpuQueueOnSubmittedWorkDone( |
| 1434 | ctx.queue, |
| 1435 | [](WGPUQueueWorkDoneStatus status, void *data) { |
| 1436 | check(status == WGPUQueueWorkDoneStatus_Success, "Queue work done", |
| 1437 | __FILE__, __LINE__); |
| 1438 | auto *promise = static_cast<std::promise<void> *>(data); |
| 1439 | promise->set_value(); |
| 1440 | }, |
| 1441 | &promise); |
| 1442 | } |
| 1443 | |
| 1444 | } // namespace gpu |
| 1445 |