-
Notifications
You must be signed in to change notification settings - Fork 959
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
Debug printf in shaders #4297
base: trunk
Are you sure you want to change the base?
Debug printf in shaders #4297
Conversation
Looking into how the validation layers implement this, there's no reason we couldn't universally support a feature like this in a similar way with a pass on the naga IR + transparently adding a bind group to shader dispatches. That being said I think this basic validation layer based impl would still be nice to have immediately for users on vulkan platforms. |
92fc6a5
to
dae4b17
Compare
b6841ff
to
b4c2a18
Compare
I believe the minimal functionality in WGSL you'd need in order to support this in user space is just a string type. As soon as you have a string literal to work with, you can have WGSL preprocessor recognizing a construct and writing the format string as well as arguments into some debug buffer. |
The intent behind this PR was to make debugging shaders easier for wgpu users, with this PR if I want to inspect a value all I have to do is enable the validation layers and wgpu feature, and add a single line to my shader source. Even without string support in the language a user can already implement printf-like behavior in their project, as done here for example, but I think it's a much better experience if we can provide built in debugging utilities, so I can debug my shaders without having to make any changes to my project. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good from wgpu side.
Please re-request a review from me once the changes are addressed to make sure I see it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving the wgpu side!
Is there anything left to do here besides rebase? |
Needs a review from the Naga team, will poke them in our next meeting, but holidays are approaching, so it may be a little bit. |
fc5647c
to
a492318
Compare
I took the liberty of rebasing the branch on trunk, replacing the merge commit. I hope that's all right. |
My rebase seems to have broken something. I'm looking into it. |
92bca6b
to
a970533
Compare
@exrook friendly poke :) |
I'll update this tonight :) |
DXC doesn't support printf when targeting dxil, disable the test to allow CI to pass.
9a36c03
to
d7b3be9
Compare
Is this ready for re-review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nits, just waiting on naga review.
/// Enables support for debugPrintf in WGSL shaders. | ||
/// | ||
/// Supported Platforms: | ||
/// - DX11 (fxc only) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// - DX11 (fxc only) |
/// - DX11 (fxc only) | ||
/// - DX12 (fxc only) | ||
/// - Vulkan | ||
/// - OpenGL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't support it on GL, so we should label this as an "unimplemented platform, if it is implementable
@exrook I'm very sorry - this PR fell through the cracks, and we didn't get around to reviewing it. The wgpu maintainers decided to review our outstanding PRs each week, and in our meeting today, everyone agreed we would like to take this PR, as it seems like something that Vulkan users use pretty frequently. Would you be able to rebase this PR against the current trunk? |
Looking forward to this getting merged |
cargo clippy
.cargo clippy --target wasm32-unknown-unknown
if applicable.Connections
Migrated from gfx-rs/naga#2563
Description
Exposes the vulkan validation layers shader printf feature to wgsl shaders through a new
debugPrintf
builtin function.example:
output with validation layers enabled and configured properly:
This feature is also supported on HLSL/DirectX though only when using FXC. DXC does not fully support printf, see microsoft/hlsl-specs#245.
Additionally supports converting SPIR-V shaders containing
NonSemantic.DebugPrintf
to wgsl, glsl, hlsl.Testing
TBD