Very slow pipeline creation/failure

On the newest driver (I don’t know if older drivers also have this), version 531.79, on an RTX 3080 graphics pipeline creation is very slow when using (large) arrays as function arguments (>20 minutes, after which I quit trying to create the pipeline). I have a minimal reproducible solution here: (29.3 KB)

The implementation is in “SlowPipelineCreation.cpp”, and the shaders are in “shaders/slow_pipeline_creation”

You can change the different tests by changing the define: “TRY_TEST” at the top of “shader.frag”, there is also a bit more explanation there.

The amount of SPIRV generated is also not a lot.

As far as I know, using arrays like this as function arguments should not make copies of the whole buffer, but even if it does, then the only slowdown should be during execution, the creation of the pipeline should not hang for more than 20 minutes.

When I used 32 as a base count (here every material is supposed to have 9 textures), it still took really long, but it managed to create in ~5 seconds (which is still incredibly slow). However since I used vk::PipelineCache, every time I tried to create the pipeline again, with the exact same shaders and configuration, it took just a normal amount of time (not exactly timed, but it should be in the millisecond range).

I also tried with a base count of 64 (which, again, means that the total sampler2D count is 64 * 9, and the amount of materials is 64) it took ~35 seconds to create the pipeline.

Note: observed the same behaviour with an RTX 2070, on the same driver version.

After further testing, I found out that when getting very close to a mesh (of llow complexity), which uses this technique (passing the materials and texture via a function) causes the shader to slow down dramatically. From ~0.03ms to ~8.5ms for a simple low-res sphere.

I think this could also be a potential bug because it only happens when you get very close (close to the near plane), I’d feel if it were not a bug, it would always happen.

Also as already mentioned, you should get pretty close to the near plane for it to slow down dramatically, just being close (where the sphere takes more than half the viewport is not enough).

I remember the same behaviour occurring some time ago when getting very close to spotlight shadow maps, this is most likely caused by the perspective divide or something.