Skip to content

Add assert function #32

@stefnotch

Description

@stefnotch

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions