Possible to set directx compiler flags in shaders?

Can we tell unity to compile HLSL with specified flags like these?

I want to debug a compute shader with visual studio but the whole experience is a disaster. When I step over code it jumps to some other line. This behaviour is unpredictable thanks to the shader code optimization. I want to disable shader optimizations to be able to debug the thing.

Did you ever figure this out? Although I’ve gotten the Visual Studio Graphics analyzer to produce somewhat workable results, the code optimization does appear to throw a wrench in a lot of times.

I’ve also tried Nvidia NSight and I simply cannot get it to find the original source at all, only assembly.

1 Like

Any update on this issue? The shader debugging with VS graphics analyzer is useless in this state…

Or, will this problem be solved if I use another debugging tool?

1 Like

I tried to use RenderDoc, it has the same exact problem… really no solution for such an obvious problem?

If you really, really, really want to use HLSL shaders with specified flags, develop them outside of Unity engine and get via native plugin interface.

https://bitbucket.org/Unity-Technologies/graphicsdemos/src/364ac57cea5c197ca9b7015ba29dcc1ff94c9f61/NativeRenderingPlugin/

Well, I need a simple, straightforward way of debugging shaders while Unity is running. Compiling the shaders elsewhere then loading them through other plugins is anything but. #pragma enable_d3d11_debug_symbols should make the compiler automatically disable optimizations. Or have some other flag that does that…