Debugging setup for Rust / wasm32 / wgpu

I have a Rust / wasm32 app that runs on Chrome / webgpu (webgl2 backend).

The following would be my ideal debug setup. How close can we get to this ?

  1. We add a bunch of printfs to the fragment shader.

  2. We render the scene to canvas.

  3. I find a pixel I don't like. I click on that pixel.

  4. It reruns the scene (with identical data), dumping out all the printfs FOR THAT ONE PIXEL to console.log

How close can we get to this ? Right now, I don't even have printf in fragment shaders.

As far as I know, you can't print inside a shader. See opengl - How to debug a GLSL shader? - Stack Overflow for more tips.

Single it's only a single pixel, is there some type of emulator / simulator to run the fragment on the CPU ? I just need it for a single %T*$(# pixel :slight_smile:

I don't know about wgpu, but for vulkan, you can enable the "VK_KHR_shader_non_semantic_info" extension and you can then configure the validation layer to enable DebugPrintf. you'll also need to compile glsl shader with "GL_EXT_debug_printf" extension. then you can check the messages either from the validation layer output, or you can view them in RenderDoc!

but I suggest not to use this in fragment shaders, or render to a small image.

also, RenderDoc can debug shaders. you can debug a vertex shader for a single vertex, or a fragment shader for a single pixel.

I have never used browser for graphics, but I know the wgpu crate can run webgpu on native platform, and it supports spirv shaders, maybe you can try to debug your code on native target first?

1 Like

I've never used Renderdoc, but heard it mentioned many times.

I know that with Renderdoc, you can view the gl state / uniforms / vbos.

However, none of that is my problem.

My problem is WITHIN the fragment shader. I need something that lets me "look inside" the fragment shader, to see what values the vars hold.

Besides the Vulkan extension you mentioned above, does RenderDoc provide anything of use for this ?

Thanks!

yes, RenderDoc can records the shader invocation and let you "playback" the shader execution. you can set break points, single step, or even run backward or single step backward. at least that's the experience I get for vulkan and spirv. I assume wgpu has a vulkan backend so renderdoc should capture the draw calls too, but I never tried it.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.