gallium: crash when using images obtained from a texture with a bindless handle
This is a bug we get when testing the development version Dæmon game engine for the Unvanquished game on radeonsi. We're in the process of modernizing the renderer and take advantage of bindless textures, compute shaders and other shiny things.
After the various bugs affecting NIR reported in #11535 (closed) (regression with bindless textures) have been fixed, we implemented more features and now we face bugs that look specific to radeonsi.
Here is a crash we get with some code implementing culling on GPU:
tc_create_image_handle (_pipe=0x59af4e19a960, image=0x7ffe32e1fdf0) at ../src/gallium/auxiliary/util/u_threaded_context.c:2404
2404 if (image->resource->target == PIPE_BUFFER)
Thread 1 (Thread 0x77b3ab8c4a80 (LWP 2554073) "daemon"):
#0 tc_create_image_handle (_pipe=0x59af4e19a960, image=0x7ffe32e1fdf0) at ../src/gallium/auxiliary/util/u_threaded_context.c:2404
#1 0x000077b388742c45 in st_create_image_handle_from_unit (prog=<optimized out>, imgUnit=<optimized out>, st=0x59af4e22cae0) at ../src/mesa/state_tracker/st_texture.c:573
#2 st_make_bound_images_resident (st=st@entry=0x59af4e22cae0, prog=prog@entry=0x59af55e236e0) at ../src/mesa/state_tracker/st_texture.c:650
#3 0x000077b3886fde09 in st_upload_constants (st=0x59af4e22cae0, prog=0x59af55e236e0, stage=MESA_SHADER_COMPUTE) at ../src/mesa/state_tracker/st_atom_constbuf.c:108
#4 0x000077b388561f9d in st_validate_state (pipeline_state_mask=18374686479705178112, st=0x59af4e22cae0) at ../src/util/bitscan.h:117
#5 prepare_compute (ctx=ctx@entry=0x59af4e2fab10) at ../src/mesa/main/compute.c:298
#6 0x000077b38856224d in dispatch_compute (no_error=<optimized out>, num_groups_z=<optimized out>, num_groups_y=<optimized out>, num_groups_x=<optimized out>) at ../src/mesa/main/compute.c:330
#7 _mesa_DispatchCompute (num_groups_x=80, num_groups_y=60, num_groups_z=1) at ../src/mesa/main/compute.c:349
#8 0x000077b3885111f7 in _mesa_unmarshal_DispatchCompute (ctx=<optimized out>, cmd=<optimized out>) at src/mapi/glapi/gen/marshal_generated4.c:1235
#9 0x000077b388644bf2 in glthread_unmarshal_batch (job=job@entry=0x59af4e2fecb8, gdata=gdata@entry=0x0, thread_index=thread_index@entry=0) at ../src/mesa/main/glthread.c:141
#10 0x000077b38864523a in _mesa_glthread_finish (ctx=ctx@entry=0x59af4e2fab10) at ../src/mesa/main/glthread.c:422
#11 0x000077b388645499 in _mesa_glthread_finish_before (ctx=ctx@entry=0x59af4e2fab10, func=func@entry=0x77b38839f51f "GetTextureHandleARB") at ../src/mesa/main/glthread.c:438
#12 0x000077b388508416 in _mesa_marshal_GetTextureHandleARB (texture=163) at src/mapi/glapi/gen/marshal_generated4.c:2744
#13 0x000059af4af64120 in Texture::GenBindlessHandle (this=0x59af4f011e90) at daemon/src/engine/renderer/TextureManager.cpp:62
#14 TextureManager::BindTexture (this=0x59af4bb2a9d0 <tr+112>, location=location@entry=0, texture=<optimized out>) at daemon/src/engine/renderer/TextureManager.cpp:89
#15 0x000059af4af3406d in GL_BindToTMU (unit=<optimized out>, unit@entry=0, image=0x77b3a9b19b40) at daemon/src/engine/renderer/tr_backend.cpp:191
#16 0x000059af4af358f9 in RB_CameraPostFX () at daemon/src/engine/renderer/tr_backend.cpp:3363
#17 0x000059af4af35e35 in RB_CameraPostFX () at daemon/src/engine/renderer/tr_backend.cpp:5591
#18 RB_RenderPostProcess () at daemon/src/engine/renderer/tr_backend.cpp:4778
#19 RenderPostProcessCommand::ExecuteSelf (this=0x77b38e13e0fc) at daemon/src/engine/renderer/tr_backend.cpp:5588
#20 0x000059af4af32009 in RB_ExecuteRenderCommands (data=<optimized out>) at daemon/src/engine/renderer/tr_backend.cpp:5812
#21 0x000059af4af4ebd2 in RE_EndFrame (frontEndMsec=0x0, backEndMsec=0x0) at daemon/src/engine/renderer/tr_cmds.cpp:894
#22 0x000059af4aeba244 in SCR_UpdateScreen () at daemon/src/engine/client/cl_scrn.cpp:327
#23 0x000059af4aeaebdd in CL_Frame (msec=msec@entry=200) at daemon/src/engine/client/cl_main.cpp:2074
#24 0x000059af4ae4181c in Com_Frame () at daemon/src/engine/qcommon/common.cpp:958
#25 0x000059af4ae3aded in Application::ClientApplication::Frame (this=0x59af4b150ea0 <Application::GetApp()::app>) at daemon/src/engine/client/ClientApplication.cpp:96
#26 0x000059af4ae3a425 in main (argc=<optimized out>, argv=<optimized out>) at daemon/src/engine/framework/System.cpp:759
When replaying the apitrace, I get those errors:
7601: message: major api error 2: GL_INVALID_OPERATION in glGetNamedBufferPointerv(non-existent buffer object 6)
7601 @0 glDeleteBuffers(n = 1, buffers = &6)
7601: warning: glGetError(glDeleteBuffers) = GL_INVALID_OPERATION
7602: message: major api error 2: GL_INVALID_OPERATION in glGetNamedBufferPointerv(non-existent buffer object 7)
7602 @0 glDeleteBuffers(n = 1, buffers = &7)
7602: warning: glGetError(glDeleteBuffers) = GL_INVALID_OPERATION
7603: message: major api error 2: GL_INVALID_OPERATION in glGetNamedBufferPointerv(non-existent buffer object 8)
7603 @0 glDeleteBuffers(n = 1, buffers = &8)
7603: warning: glGetError(glDeleteBuffers) = GL_INVALID_OPERATION
7604: message: major api error 2: GL_INVALID_OPERATION in glGetNamedBufferPointerv(non-existent buffer object 9)
7604 @0 glDeleteBuffers(n = 1, buffers = &9)
7604: warning: glGetError(glDeleteBuffers) = GL_INVALID_OPERATION
7605: message: major api error 2: GL_INVALID_OPERATION in glGetNamedBufferPointerv(non-existent buffer object 10)
7605 @0 glDeleteBuffers(n = 1, buffers = &10)
7605: warning: glGetError(glDeleteBuffers) = GL_INVALID_OPERATION
7606: message: major api error 2: GL_INVALID_OPERATION in glGetNamedBufferPointerv(non-existent buffer object 11)
7606 @0 glDeleteBuffers(n = 1, buffers = &11)
7606: warning: glGetError(glDeleteBuffers) = GL_INVALID_OPERATION
7607: message: major api error 2: GL_INVALID_OPERATION in glGetNamedBufferPointerv(non-existent buffer object 12)
7607 @0 glDeleteBuffers(n = 1, buffers = &12)
7607: warning: glGetError(glDeleteBuffers) = GL_INVALID_OPERATION
apitrace: warning: caught signal 11
82021: error: caught an unhandled exception
/usr/bin/glretrace+0x2c77f0
/lib/x86_64-linux-gnu/libc.so.6+0x4531f: ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
install/lib/libgallium-24.3.0-devel.so: tc_create_image_handle+0x154d0ae: ../src/gallium/auxiliary/util/u_threaded_context.c:2404
install/lib/libgallium-24.3.0-devel.so: st_create_image_handle_from_unit+0x1142c44: ../src/mesa/state_tracker/st_texture.c:573
install/lib/libgallium-24.3.0-devel.so: st_make_bound_images_resident+0x1142c44: ../src/mesa/state_tracker/st_texture.c:650
install/lib/libgallium-24.3.0-devel.so: st_upload_constants+0x10fde08: ../src/mesa/state_tracker/st_atom_constbuf.c:108
install/lib/libgallium-24.3.0-devel.so: st_validate_state+0xf61f9c: ../src/mesa/state_tracker/st_util.h:131
install/lib/libgallium-24.3.0-devel.so: prepare_compute+0xf61f9c: ../src/mesa/main/compute.c:298
install/lib/libgallium-24.3.0-devel.so: dispatch_compute+0xf6224c: ../src/mesa/main/compute.c:330
install/lib/libgallium-24.3.0-devel.so: _mesa_DispatchCompute+0xf6224c: ../src/mesa/main/compute.c:349
install/lib/libgallium-24.3.0-devel.so: _mesa_unmarshal_DispatchCompute+0xf111f6: src/mapi/glapi/gen/marshal_generated4.c:1235
install/lib/libgallium-24.3.0-devel.so: glthread_unmarshal_batch+0x1044bf1: ../src/mesa/main/glthread.c:141
install/lib/libgallium-24.3.0-devel.so: _mesa_glthread_finish+0x1045239: ../src/mesa/main/glthread.c:422
install/lib/libgallium-24.3.0-devel.so: _mesa_marshal_GetError+0xee141e: src/mapi/glapi/gen/marshal_generated1.c:1515
Here is the apitrace file: apitrace-20241013-172042.trace.xz
I reproduce crashes with stock Mesa 24.0.9 from Ubuntu 24.04 Noble and self-built Mesa 24.3.0-devel on commit f77ffd6b from some days ago.