NIR validation failed after nir_copy_prop
Description
We have a couple of shaders in X-Plane 12 that crash when run with RADV once the NIR optimizer gets its hands on it. The same shaders work fine on the Windows AMD driver, as well as on the Nvidia driver (both Windows and Linux). Unfortunately the shader is somewhat complex and I don't understand enough about NIR to do a good bisect here about which part of our shader exactly is causing this. I can reproduce this issue reliably on my RX 5700 and on Valve's Steam Deck, but I'm unsure if this also happens on GCN cards. My gut tells me this also applies to GCN since it happens while optimizing the IR.
Disabling optimizations via VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT
doesn't solve the problem and instead just moves the crash site to radv_nir_lower_ycbr_textures()
. Smells a bit like the generated IR from the SPIR-V is broken?
Log files (for system lockups / game freezes / crashes)
Console shows this:
NIR validation failed after nir_copy_prop
2 errors:
shader: MESA_SHADER_COMPUTE
workgroup-size: 64, 1, 1
shared-size: 0
inputs: 0
outputs: 0
uniforms: 0
ubos: 4
shared: 0
decl_var ubo INTERP_MODE_NONE u_droplet_compute_meta (~0, 0, 1)
decl_var uniform INTERP_MODE_NONE restrict sampler2D tex_glass_forces (~0, 0, 0)
decl_var uniform INTERP_MODE_NONE restrict sampler2D tex_glass_surface (~0, 0, 1)
decl_var ubo INTERP_MODE_NONE u_rain_info @0 (~0, 0, 2)
decl_var uniform INTERP_MODE_NONE restrict sampler2D tex_glass_wiper (~0, 0, 2)
decl_var ubo INTERP_MODE_NONE u_rain_temperature_data @1 (~0, 0, 3)
decl_var ssbo INTERP_MODE_NONE restrict droplet_data droplets (~0, 0, 4)
decl_var ubo INTERP_MODE_NONE u_environment_data @2 (~0, 0, 0)
decl_function main (0 params)
Followed by what I'm guessing is the main body of the generated IR, snipped for brevity.
Here's some backtraces from a Mesa build against the 21.3.0 tag:
frame #0: 0x00007f71be0f6808 libc.so.6`__GI___pthread_kill [inlined] __pthread_kill_internal(signo=6, threadid=140122326541888) at pthread_kill.c:44:76
frame #1: 0x00007f71be0f67f8 libc.so.6`__GI___pthread_kill(threadid=140122326541888, signo=6) at pthread_kill.c:91:10
frame #2: 0x00007f71be0a2476 libc.so.6`__GI_raise(sig=6) at raise.c:26:13
frame #3: 0x00007f71be0887b7 libc.so.6`__GI_abort at abort.c:79:7
frame #4: 0x00007f71397ea76a libvulkan_radeon.so`dump_errors(state=0x00007f70c57f5ed0, when="after nir_copy_prop") at nir_validate.c:1719:4
frame #5: 0x00007f71397eaa7d libvulkan_radeon.so`nir_validate_shader(shader=0x00007f70a8183590, when="after nir_copy_prop") at nir_validate.c:1770:7
frame #6: 0x00007f713962caf0 libvulkan_radeon.so`radv_optimize_nir(device=0x0000000009459cc0, shader=0x00007f70a8183590, optimize_conservatively=false, allow_copies=true) at radv_shader.c:155:7
frame #7: 0x00007f7139631b13 libvulkan_radeon.so`radv_shader_compile_to_nir(device=0x0000000009459cc0, module=0x00007f70a8308a10, entrypoint_name="main", stage=MESA_SHADER_COMPUTE, spec_info=0x00007f70a8399d30, layout=0x000000000c1fd150, key=0x00007f70c57f8950) at radv_shader.c:684:7
frame #8: 0x00007f713960c31f libvulkan_radeon.so`radv_create_shaders(pipeline=0x00007f70a8382280, pipeline_layout=0x000000000c1fd150, device=0x0000000009459cc0, cache=0x000000000ced53b0, pipeline_key=0x00007f70c57f8950, pStages=0x00007f70c57f88f0, flags=0, custom_hash=0x0000000000000000, pipeline_feedback=0x0000000000000000, stage_feedbacks=0x00007f70c57f8920) at radv_pipeline.c:3409:16
frame #9: 0x00007f7139613183 libvulkan_radeon.so`radv_compute_pipeline_create(_device=0x0000000009459cc0, _cache=0x000000000ced53b0, pCreateInfo=0x00007f70a8399c48, pAllocator=0x0000000000000000, custom_hash=0x0000000000000000, rt_stack_sizes=0x0000000000000000, rt_group_count=0, pPipeline=0x00007f70a832c698) at radv_pipeline.c:5785:13
frame #10: 0x00007f713961334e libvulkan_radeon.so`radv_CreateComputePipelines(_device=0x0000000009459cc0, pipelineCache=0x000000000ced53b0, count=1, pCreateInfos=0x00007f70a8399c48, pAllocator=0x0000000000000000, pPipelines=0x00007f70a832c698) at radv_pipeline.c:5818:11
Backtrace when disabling optimizations:
frame #0: 0x00007fb467603d9a libvulkan_radeon.so`try_lower_tex_ycbcr(layout=0x000000000e619e00, builder=0x00007fb3f3ffb040, tex=0x00007fb3ec6bfcb0) at radv_nir_lower_ycbcr_textures.c:230:28
frame #1: 0x00007fb46760437b libvulkan_radeon.so`radv_nir_lower_ycbcr_textures(shader=0x00007fb3ec62fd20, layout=0x000000000e619e00) at radv_nir_lower_ycbcr_textures.c:320:34
frame #2: 0x00007fb467635b84 libvulkan_radeon.so`radv_shader_compile_to_nir(device=0x00000000080705d0, module=0x00007fb3ec5a8e20, entrypoint_name="main", stage=MESA_SHADER_COMPUTE, spec_info=0x00007fb3ec142e40, layout=0x000000000e619e00, key=0x00007fb3f3ffd950) at radv_shader.c:688:4
frame #3: 0x00007fb46761031f libvulkan_radeon.so`radv_create_shaders(pipeline=0x00007fb3ec533d40, pipeline_layout=0x000000000e619e00, device=0x00000000080705d0, cache=0x000000000e6197b0, pipeline_key=0x00007fb3f3ffd950, pStages=0x00007fb3f3ffd8f0, flags=1, custom_hash=0x0000000000000000, pipeline_feedback=0x0000000000000000, stage_feedbacks=0x00007fb3f3ffd920) at radv_pipeline.c:3409:16
frame #4: 0x00007fb467617183 libvulkan_radeon.so`radv_compute_pipeline_create(_device=0x00000000080705d0, _cache=0x000000000e6197b0, pCreateInfo=0x00007fb3ec310c48, pAllocator=0x0000000000000000, custom_hash=0x0000000000000000, rt_stack_sizes=0x0000000000000000, rt_group_count=0, pPipeline=0x00007fb3ec6d57c8) at radv_pipeline.c:5785:13
frame #5: 0x00007fb46761734e libvulkan_radeon.so`radv_CreateComputePipelines(_device=0x00000000080705d0, pipelineCache=0x000000000e6197b0, count=1, pCreateInfos=0x00007fb3ec310c48, pAllocator=0x0000000000000000, pPipelines=0x00007fb3ec6d57c8) at radv_pipeline.c:5818:11
Steps to reproduce
I have attached a small repro sample that just loads the shader into a super bare bones Vulkan application. Since this is a pre-release title, I unfortunately can't easily share the source shader (I realize SPIR-V isn't some magic encryption, but it's obfuscated in enough SSA that I can post it). Let me know if the source shader is necessary and I'll see if I can get permission to provide it.
System information
- OS:
Ubuntu 21.10
- GPU:
RX 5700 and AMD Van Gogh APU in the Steam Deck
- Kernel version:
Linux ubuntu-amd 5.13.0-20-generic #20-Ubuntu SMP Fri Oct 15 14:21:35 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
- Mesa version:
21.3.0
- Desktop environment:
ubuntu:GNOME
Repro
Should work out of the box. It uses CMake, but it's just a simple source file that needs to find Vulkan, so it should be easy to build it without CMake. There is also a pre-build binary in the cmake-build-debug
folder. Just make sure to put the repro.spv
file in the working directory so application can find it.