Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add assert function #32

Open
stefnotch opened this issue May 25, 2024 · 0 comments
Open

Add assert function #32

stefnotch opened this issue May 25, 2024 · 0 comments

Comments

@stefnotch
Copy link
Collaborator

Woah, compute.toys has an assert function in shaders
https://github.com/compute-toys/wgpu-compute-toy/blob/edabd7558a9565f2e096f52a1c6ff6c76456ec23/src/lib.rs#L413-L417
And it's actually pretty easy to implement. We're definitely copying this.
Basically assert(x > 0) would first be turned into assert(UNIQUE ID, x > 0).
Then we adds an atomic counter to the shader. And the assert function writes to the atomic counter every time it fails.
Finally, we asynchronously read back that information on the CPU, and if it's greater than 0, we know that something failed.
And there's even the "obvious" extension, where we then automatically rerun the shader with more tracing info to show the user some top tier debug info.
(Doesn't work with race conditions, but that's an acceptable limitation.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant