Search code examples
compilationshaderwebgpu

WebGPU: Is it possible to access the compiled shader code in browser?


As I understand, the Tint compiler within Google's Dawn (their WebGPU implementation) is used to compile WGSL down to GPU-executable code. (WGSL -> SPIR-V -> GPU-executable binary.)

Given my WGSL shader, without downloading / building Dawn / Tint myself, how can I see what compiled instructions are being generated by Chrome and sent to the GPU?

Alternatively, is it possible using Firefox, Edge etc. to see same?

I'd like to find inefficiencies resulting from my novice WGSL, where loops are being unrolled, inlining of functions, superfluous casts between numeric types, etc.


Solution

  • In chrome try passing in --enable-dawn-features=dump_shaders

    Other flags for the curious

    https://source.chromium.org/chromium/chromium/src/+/main:third_party/dawn/src/dawn/native/Toggles.cpp;l=1?q=Toggles.cpp&ss=chromium

    You can see which flags are currently in use by going to about:gpu and scrolling down to the Dawn Info section.

    You can pass in more than one flag by separating with commas

    You can also disable flags with --disable-dawn-features=<flag>