4 ms·
Shaders would be so much more accessible, if there simply was an easy way to debug them. How many developer hours would have been saved with a simple printf sta
by zubspace 5y ago
Shaders would be so much more accessible, if there simply was an easy way to debug them. How many developer hours would have been saved with a simple printf statement? Or god forbid a step-through-debugger where you can inspect values...
The most common cause for errors in my shader code are values outside of the expected range or matrix transformation errors where I have to go through them step by step on paper...
So, how do you debug shaders? Is there a reliable tool which actually helps? Or am I missing something?
- westoncb 5y agoThis is definitely a problem. I always resort to doing some kind of 'debug rendering,' modulating colors and trying to read back vals from that, in lieu of a printf. Works fine for some things, but I've definitely dead-ended on others, no way I could think of to inspect.
- corysama 5y agoMicrosoft Pix has been able to debug shaders for nearly twenty years.
- pjmlp 5y agoYou just use modern APIs like Metal and DirectX that have GPGPU debuggers, which include shader debugging, just like a normal CPU language. The problem with Khronos standards is that they always let the community fix their lack of tooling, so the best you can hope for is vendor specific debugging tools, or something like RenderDoc, which isn't as feature rich.
- Milol 5y agoI have used RenderDoc (https://renderdoc.org/ https://renderdoc.org/) a couple of times, where i could click on a pixel to debug, and step through the shader step by step like regular debugging. I haven't used it alot, but it was quite excellent out of the box for me. I needed to pass some debug flags to shader compilation - and it was only automatically able to capture output to the screen buffer as far as i remember. But there is an api to integrate it if you want offscreen target debugging i think.
- anentropic 5y agoif only it had macos support...
- mtsr 5y agoXcode has a decent graphics debugger as well, or so I’ve heard.
- HelloNurse 5y agoDo you mean "if only MacOS had Vulkan support"?
- flohofwoe 5y agoXcode has a good Metal frame debugger, which also allows to step through shader code. The Graphics Debugger that's integrated into Visual Studio also has a shader debugger (for D3D/HLSL). RenderDoc allows shader debugging for some backends, although I currently don't remember which one (either D3D, GL or Vulkan). Nvidia has the NSIGHT debugger, which AFAIK exists both as standalone tool and integrated into Visual Studio and also allows to step through shader code. Game consoles usually come with their own graphics debugging tools.
- Liquix 5y agoIt doesn't run directly in your environment, but https://www.shadertoy.com/ https://www.shadertoy.com/ is incredible for rapid prototyping & debugging
- kevingadd 5y agoRenderDoc's debugger is great, and before it was shot in the head Direct3D9 PIX had a world-class shader debugger. For game console development you have access to world-class shader debuggers that let you step through the raw shader assembly on the GPU at the hardware level (so you can see the individual waves/threads and register values). In practice shader debugging only sucks in OpenGL (vulkan is not great, but is closer to ideal). In Direct3D it's totally fine. This is partly due to Direct3D having well-specified semantics and always having a reference rasterizer, so a debugger can use refrast to do accurate shader step-through (unless you hit driver bugs).
- turbohz 5y agoThere's SHADERed (https://github.com/dfranx/SHADERed https://github.com/dfranx/SHADERed). I've only done very basic shader stuff, but it helped me when I got stuck.