Open
Conversation
Owner
Author
|
Only breaking change with latest commit is dispatchKernel and toCPU no longer take a promise, toCPUAsync and dispatchKernelAsync should be used instead to get futures. Manually waiting should no longer be necessary with the sync call though, even in a emscripten context. |
Owner
Author
|
Added an optional param with this refactor to set a offset for the toCPU buffer read. This is tested in the new test/test_gpu.cpp. I think the toCPU with copydata is now redundant. Will leave it alone if you prefer to keep it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
• Refactored key GPU operations (createContext, toCPU, dispatchKernel, and createKernel) to return std::future instead of blocking with busy-wait loops.
• Replaced inline lambda callbacks with free‑standing functions that use promise/future for asynchronous completion.
• Updated createKernel (and its templated overload) to report shader module compilation asynchronously (instead of synchronously busy‑waiting), and dispatchKernel now returns a future that is fulfilled when the kernel dispatch is complete.
• Replaced wait with WaitForFuture(ctx.instance, future) as a template to return future objects after webgpu processing is complete.
Example usage:
Why This Is Better:
• No blocking loops or synchronous waits – all async work is chained via futures, letting the event loop run naturally.
• Reduced risk of reentrancy issues and resource errors due to improper lifetime management.
• Cleaner separation between asynchronous callbacks and higher‐level logic, making the code easier to maintain and integrate (especially in WebAssembly/Emscripten contexts).