Skip to content

implement debugPrintf in msl & spv#9389

Open
39ali wants to merge 36 commits intogfx-rs:trunkfrom
39ali:printf-metal
Open

implement debugPrintf in msl & spv#9389
39ali wants to merge 36 commits intogfx-rs:trunkfrom
39ali:printf-metal

Conversation

@39ali
Copy link
Copy Markdown
Contributor

@39ali 39ali commented Apr 7, 2026

Connections
related to #7662

Description
now you can printf stuff in wgsl using metal backend, should be able add vulkan as well in the future :

        enable wgpu_debug_printf;
        
        @compute @workgroup_size(8, 1, 1)
        fn main(@builtin(local_invocation_index) idx: u32) {
             debugPrintf("WGSL_METAL_LOG: Thread index is %u", idx);
        }

Testing
added an example

Squash or Rebase?

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

@39ali 39ali changed the title implemented debugPrintf in msl implement debugPrintf in msl Apr 8, 2026
@39ali
Copy link
Copy Markdown
Contributor Author

39ali commented Apr 8, 2026

@ErichDonGubler test is failing :
error: error: cannot execute tool 'metal' due to missing Metal Toolchain; use: xcodebuild -downloadComponent MetalToolchain

@39ali 39ali changed the title implement debugPrintf in msl implement debugPrintf in msl & spv Apr 9, 2026
@39ali
Copy link
Copy Markdown
Contributor Author

39ali commented Apr 9, 2026

added vulkan support as well

Copy link
Copy Markdown
Collaborator

@atlv24 atlv24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay, it'll be great to have this! Some feedback, mostly style but also docs and a performance fix.

I'd appreciate safety comments on all the newly added unsafe blocks.

Copy link
Copy Markdown
Collaborator

@atlv24 atlv24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking a lot better

39ali and others added 19 commits April 11, 2026 14:39
Co-authored-by: atlv <email@atlasdostal.com>
Co-authored-by: atlv <email@atlasdostal.com>
Co-authored-by: atlv <email@atlasdostal.com>
Co-authored-by: atlv <email@atlasdostal.com>
Co-authored-by: atlv <email@atlasdostal.com>
Co-authored-by: atlv <email@atlasdostal.com>
Co-authored-by: atlv <email@atlasdostal.com>
Co-authored-by: atlv <email@atlasdostal.com>
Co-authored-by: atlv <email@atlasdostal.com>
Co-authored-by: atlv <email@atlasdostal.com>
Copy link
Copy Markdown
Collaborator

@atlv24 atlv24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs some naga validation fail tests showing that string literals are banned from non debugPrintf locations, and also that debugPrintf is not allowed unless the extension is present.

39ali and others added 12 commits April 12, 2026 16:43
Co-authored-by: atlv <email@atlasdostal.com>
Co-authored-by: atlv <email@atlasdostal.com>
Co-authored-by: atlv <email@atlasdostal.com>
Co-authored-by: atlv <email@atlasdostal.com>
Co-authored-by: atlv <email@atlasdostal.com>
Co-authored-by: atlv <email@atlasdostal.com>
Co-authored-by: atlv <email@atlasdostal.com>
Co-authored-by: atlv <email@atlasdostal.com>
Co-authored-by: atlv <email@atlasdostal.com>
Co-authored-by: atlv <email@atlasdostal.com>
Co-authored-by: atlv <email@atlasdostal.com>
@evilpie
Copy link
Copy Markdown
Contributor

evilpie commented Apr 12, 2026

User defined format strings are famously unsafe and this seems to implicitly assume that all backends going forward will have the same format string formats. Maybe it would be a cool improvement to support (basic) Rust style format strings instead? Then again, maybe too much work for a debug feature.

See also gfx-rs/naga#2563. That seems to support printf in OpenGL via GL_EXT_debug_printf.

@39ali
Copy link
Copy Markdown
Contributor Author

39ali commented Apr 12, 2026

@atlv24 check it out

Copy link
Copy Markdown
Collaborator

@atlv24 atlv24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good to merge now, thanks!

Copy link
Copy Markdown
Collaborator

@atlv24 atlv24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking nits and notes

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants