Hey,
I’m working on a pretty complex shader with over 800 lines of code in my main Utils.hlsl file, which contains many functions, some with many parameters, and many conditions inside them (if that matters), but no shader variants whatsoever. I’m experiencing extremely long (over 10 minutes) compilation times whenever I edit my shader and go back to the editor. It is impossible to continue working this way.
I’m using Unity 2021.2.5f1, on a Mac M1.
Any idea how resolve this? Is this a bug? Or maybe there’s some known issue with having too many functions or something?
There are some pathologically slow paths in the FXC compiler, like using large arrays, which can increase compilation time a lot.
Which platform(s) do you target?
Right now I’m targeting iOS, in general I’m aiming for both mobile platforms and standalone.
What you’re saying about large arrays is interesting. I’m not using arrays much, but i do have a ton of properties in my shader, as well as some structs to encapsulate those parameters.
Also, I noticed a huge jump in compilation time the moment I added this quadradic bezier SDF implementation to my code:
And it only got worse as I add more logic.
- It is Unlit, not using surface shader.
- Also, I just tried to upgrade to Unity 2023 and 2022 LTS versions, but the problem persisted.
IIRC we didn’t update FXC between 2022 and 2023, so there shouldn’t be any difference there.
You can try adding a #pragma use_dxc if you don’t plan using DX11. It may speed up the compilation.
I’ll try that! Will update if it works.
But regardless of the compiler, it doesn’t sound like I’ve done something fishy in my code right? There’s no some specific bad practice I’ve used I hope
This is amazing it actually works!
Thanks!
I understand why this is not the default compiler, but on which platforms is DX11 used? Just to know how to work around it if I ever end up needing it.
It’s only ever used on Windows by default. You can select DX12 in the project settings.