KhronosGroup / SPIRV-Tools

Apache License 2.0
1.03k stars 541 forks source link

spirv-opt takes a long time to optimize a large shader with debugPrintfEXT() #4241

Open FrancoisBeaune opened 3 years ago

FrancoisBeaune commented 3 years ago

This ZIP file contains two large, nearly identical shaders in SPIR-V form that differ only as follow:

They were compiled with glslangValidator from Vulkan SDK 1.2.170.0 [1].

Running spirv-opt on shader-without-debugPrintfEXT.spv (without debugPrintfEXT() statements) takes 21 seconds.

Running spirv-opt on shader-with-debugPrintfEXT.spv (with debugPrintfEXT() statements) takes 172 seconds (2 min 52).

Is there any fundamental reason why a few debugPrintfEXT() statements would cause optimization times to explode, or is this a bug?


[1] Full output of glslangvalidator --version:

Glslang Version: 10:11.1.0
ESSL Version: OpenGL ES GLSL 3.20 glslang Khronos. 11.1.0
GLSL Version: 4.60 glslang Khronos. 11.1.0
SPIR-V Version 0x00010500, Revision 4
GLSL.std.450 Version 100, Revision 1
Khronos Tool ID 8
SPIR-V Generator Version 10
GL_KHR_vulkan_glsl version 100
ARB_GL_gl_spirv version 100
greg-lunarg commented 3 years ago

I will take a look.

greg-lunarg commented 3 years ago

I am going to investigate #4219 first; it may possibly be causing this one.

greg-lunarg commented 3 years ago

The fix for #4219 did not help.

Clue: The DebugPrintf version is blowing up to twice the size of the non-DebugPrintf.

Shouldn't take too long to track down.

greg-lunarg commented 3 years ago

Well, I have found one case in an optimization sequence where there is a 3-4x growth in the size of the DebugPrintf version but it will a little more analysis to figure out what's going on and what to do about it.

In general, this is not seem like some simple bug. Rather it looks like the DebugPrintfs are causing extra code to stick around causing aggregate negative effects downstream.

I need to attend to some other work, so I will not be able to get back to this for at least a week. Regrets.

FrancoisBeaune commented 3 years ago

Thanks for the updates Greg, your work is much appreciated here! We're looking forward to this bug being squashed, even if it takes a little bit of time. Thanks again.

FrancoisBeaune commented 3 years ago

Hi Greg,

Did you have a chance to get back to this?