What's wrong with shader compilation?

Hello.

It feels like shader compilation takes longer and longer with each Blender release. I always thought that it was because my GTX 1060 was a bit older, but I’ve just acquired a RTX 3060 (12GB RAM) and it’s still the same. I usually have to wait around 45 seconds for the smaller scenes to load all the textures, but it can go up to 90 seconds for the bigger scenes. And those are not really that big compared to what other users might have to deal with in movie or game projects. I don’t remember having to wait that long back in 2.93.

The weird thing is, that once I have loaded the scene and then close Blender and open it again and load the scene again, the textures are there instantly. Another weird thing is, that when I load the scene and immediately hit F12 to start the rendering, the rendering starts after about 10 seconds for the bigger scenes (with all the textures loaded obviously).

Is there anything that can be done about this? It’s really annoying to always have to wait for almost a minute when I load the scene. I tried both Blender 3.2 and 3.3 - it’s the same.

10 seconds are normal for big scenes. It is based your texture count, texture size and procedural texture and shader complexity.

1 Like

I actually happen to use your VShade addon. Might that be an issue? Sometimes there are few textures and sometimes there are more of them. But it always takes very long. But why would it load much faster, when I render the scene immediately. The textures and shaders have to be processed as well, right?

I don’t know your scene. If you share, I can test it.

1 Like

Actually when Cycles X was integrated into master (3.1?) compiling shaders should have become a lot faster IIRC.

1 Like

It’s all the scenes. And I can’t give them to you because of copyright issues. But I might create one from scratch if I find the time.

But aside all that. Why are the shaders and textures processed much faster when I render compared to when I just load them into the viewport. And how comes they are loaded instantly once I have closed and opened Blender again?

What kind of drive do you load the data from ?

1 Like

Local hard drive - SATA. But the loading time can’t be the issue, as the renderings start within 10 seconds.

Did you update your drivers? I remember an issue that I had a while ago after updating my drivers. This had something to do with the optix cache.
I had to delete an optix cache file and which can found god knows where.

1 Like

Installing the drivers was the first thing I did. They are version 516.59. From a few days ago. I didn’t delete any cache file. Wouldn’t even know where to find it.

Overall I’m not too impressed with the performance of the RTX 3060 compared to my old GTX 1060. Viewport isn’t much faster and rendering times are only twice as fast - the benchmark numbers are about five times as high. Maybe something to do with that Optix cache file?

I think I remember that suddently shader compilation had to be done all the time.
I didn’t delete any cache file either. Something broke the cache file when installing the new drivers. Perhaps because Blender was rendering at the time i installed the drivers or because my C: Drive was full or something like that.

Anyway, I believe it was the following file:
C:\Users\YOURUSERNAME\AppData\Local\NVIDIA\OptixCache\optix7cache.db

I am not 100% sure so better back the file up. You have to delete the file and then start Blender and maybe start rendering something. A new file will then be created and the recompiling of shaders should be gone.

Regarding the slow speed: Did you set Blender to use optix in the preferences or are you still using CUDA?

1 Like

Yes, I understand. The first time you load up a scene it’s 45s and then it’s around 10s… I think this may hint at data being persistent in GPU memory? initial loading from disk is slow, maybe because this is a magnetic drive. Can you try changing paths to an SSD, see if it improves?

Maybe it’s unrelated but that was my hunch.

1 Like

Well. When I render the scene immediately (without having loaded the scene previously) it starts in about 10s. If I do the same thing just waiting for the viewport to finish compiling the shaders and loading the textures, it takes up to 90s.

So why is rendering faster than getting the viewport ready? They both have to compile the shaders and load the textures, right?

Thanks for the advice. I deleted the cache. But this didn’t really help. Rendering is still only twice as fast as my GTX 1060. Also shader compilation is still slow.

I had switched to Optix already - so that’s not the issue either.

A reason about slow viewport render can be: F12 render clip the camera view area, but Viewport render does not do this. For this reason, Blender must calculate all shader and textures even outside the camera view area.

1 Like

I’m not talking about Preview Render. This is just Material Preview mode.

Material Preview is buggy in the Blender. I recommend you, don’t use this.

1 Like

It works for me. My only issue is the shader compilation time.

Sounds similar to this:

Found it in this thread:

2 Likes

The shaders it has to compile for the viewport are entirely different from the shaders it uses for rendering.

Eevee needs to recompile its shaders to run in “real-time” and it certainly is buggy AF. So many things trigger recompiling the shaders, if you add any node it will do a full recompile, even like a reroute or something basic,