Rosalie241 / RMG

Rosalie's Mupen GUI
GNU General Public License v3.0
572 stars 50 forks source link

Segfault with mupen64plus-video-parallel #219

Closed orbea closed 3 months ago

orbea commented 5 months ago

OS: Gentoo RMG: https://github.com/Rosalie241/RMG/commit/48baa1bed0f5cc1208bb2c9849eccdef1723963f

On one of my Gentoo systems the mupen64plus-video-parallel plugin will segfault when starting any content, the other video and rsp plugins work however.

libc: musl-1.2.4 cpu: AMD FX(tm)-6350 gpu: [AMD/ATI] Vega 10 XL/XT [Radeon RX Vega 56/64] (rev c3)

While on my other Gentoo system the mupen64plus-video-parallel plugin works correctly.

libc: glibc-2.38 cpu: Intel(R) Core(TM) i5-7600K CPU gpu: [AMD/ATI] Navi 10 [Radeon RX 5600 OEM/5600 XT / 5700/5700 XT] (rev c1)

I am not sure what the crucial difference is, but I suspect its the libc or gpu. Additionally I suspect this is a Parallel-RDP-Standalone, mesa and / or vulkan-loader issue, but I am making it here first so I can share the issue elsewhere. Of course any insight or help you can offer would be greatly appreciated.

Thread 14 "Thread::Emulati" received signal SIGSEGV, Segmentation fault.
[Switching to LWP 2599]
0x00007fff90fa9c0d in aco::(anonymous namespace)::get_reg_impl (ctx=..., 
    reg_file=..., parallelcopies=..., info=..., instr=...)
    at ../mesa-9999/src/amd/compiler/aco_register_allocation.cpp:1260
1260    {
(gdb) bt
#0  0x00007fff90fa9c0d in aco::(anonymous namespace)::get_reg_impl (ctx=..., 
    reg_file=..., parallelcopies=..., info=..., instr=...)
    at ../mesa-9999/src/amd/compiler/aco_register_allocation.cpp:1260
#1  0x00007fff90fac0ae in aco::(anonymous namespace)::get_reg (ctx=..., 
    reg_file=..., temp=..., parallelcopies=..., instr=..., operand_index=-1)
    at ../mesa-9999/src/amd/compiler/aco_register_allocation.cpp:1681
#2  0x00007fff90fad2df in aco::(anonymous namespace)::get_reg_create_vector (
    ctx=..., reg_file=..., temp=..., parallelcopies=..., instr=...)
    at ../mesa-9999/src/amd/compiler/aco_register_allocation.cpp:1840
#3  0x00007fff90fb4ed7 in aco::register_allocation (program=0x7fff8b8b9ab0, 
    live_out_per_block=..., policy=...)
    at ../mesa-9999/src/amd/compiler/aco_register_allocation.cpp:2962
#4  0x00007fff90f52296 in aco_postprocess_shader (options=0x7fffd1e79b80, 
    info=0x7fffd1e79bb0, program=...)
    at ../mesa-9999/src/amd/compiler/aco_interface.cpp:178
#5  0x00007fff90f52aa6 in aco_compile_shader (options=0x7fffd1e79b80, 
    info=0x7fffd1e79bb0, shader_count=1, shaders=0x7fffd1e79d80, 
    args=0x7fffd1e81480, 
    build_binary=0x7fff90bc3dd1 <radv_aco_build_shader_binary>, 
    binary=0x7fffd1e79b68) at ../mesa-9999/src/amd/compiler/aco_interface.cpp:242
#6  0x00007fff90bc4524 in shader_compile (device=0x7fff90956150, 
    shaders=0x7fffd1e79d80, shader_count=1, stage=MESA_SHADER_FRAGMENT, 
    info=0x7fffd1e810f8, args=0x7fffd1e81480, stage_key=0x7fffd1e82a78, 
    options=0x7fffd1e79ca0) at ../mesa-9999/src/amd/vulkan/radv_shader.c:2455
#7  0x00007fff90bc46f3 in radv_shader_nir_to_asm (device=0x7fff90956150, 
    pl_stage=0x7fffd1e810a0, shaders=0x7fffd1e79d80, shader_count=1, 
    gfx_state=0x7fffd1e92c60, keep_shader_info=false, keep_statistic_info=false)
    at ../mesa-9999/src/amd/vulkan/radv_shader.c:2483
#8  0x00007fff90b99ec1 in radv_graphics_shaders_nir_to_asm (
    device=0x7fff90956150, cache=0x7fffd2277c70, stages=0x7fffd1e7a0a0, 
    gfx_state=0x7fffd1e92c60, keep_executable_info=false, 
    keep_statistic_info=false, active_nir_stages=17, shaders=0x7fff8b6665f8, 
    binaries=0x7fffd1e7a030, gs_copy_shader=0x7fff8b666668, 
    gs_copy_binary=0x7fffd1e79fd0)
    at ../mesa-9999/src/amd/vulkan/radv_pipeline_graphics.c:2271
#9  0x00007fff90b9b634 in radv_graphics_shaders_compile (device=0x7fff90956150, 
    cache=0x7fffd2277c70, stages=0x7fffd1e7a0a0, gfx_state=0x7fffd1e92c60, 
    keep_executable_info=false, keep_statistic_info=false, is_internal=true, 
    retained_shaders=0x0, noop_fs=false, shaders=0x7fff8b6665f8, 
    binaries=0x7fffd1e7a030, gs_copy_shader=0x7fff8b666668, 
    gs_copy_binary=0x7fffd1e79fd0)
    at ../mesa-9999/src/amd/vulkan/radv_pipeline_graphics.c:2578
#10 0x00007fff90b9be83 in radv_graphics_pipeline_compile (
    pipeline=0x7fff8b666590, pCreateInfo=0x7fffd1e930d0, 
    pipeline_layout=0x7fffd1e929f0, device=0x7fff90956150, cache=0x7fffd2277c70, 
    pipeline_key=0x7fffd1e92c60, lib_flags=15, fast_linking_enabled=false)
    at ../mesa-9999/src/amd/vulkan/radv_pipeline_graphics.c:2717
#11 0x00007fff90b9fbd1 in radv_graphics_pipeline_init (pipeline=0x7fff8b666590, 
    device=0x7fff90956150, cache=0x7fffd2277c70, pCreateInfo=0x7fffd1e930d0, 
    extra=0x7fffd1e92fb4)
    at ../mesa-9999/src/amd/vulkan/radv_pipeline_graphics.c:3937
#12 0x00007fff90ba01d4 in radv_graphics_pipeline_create (_device=0x7fff90956150, 
    _cache=0x7fffd2277c70, pCreateInfo=0x7fffd1e930d0, extra=0x7fffd1e92fb4, 
    pAllocator=0x7fff9095b300, pPipeline=0x7fff9095d098)
    at ../mesa-9999/src/amd/vulkan/radv_pipeline_graphics.c:4036
#13 0x00007fff90ada399 in create_resolve_pipeline (device=0x7fff90956150, 
    samples_log2=3, format=VK_FORMAT_R32G32_SFLOAT)
    at ../mesa-9999/src/amd/vulkan/meta/radv_meta_resolve_fs.c:217
#14 0x00007fff90adaffa in radv_device_init_meta_resolve_fragment_state (
    device=0x7fff90956150, on_demand=false)
    at ../mesa-9999/src/amd/vulkan/meta/radv_meta_resolve_fs.c:494
#15 0x00007fff90a9e320 in radv_device_init_meta (device=0x7fff90956150)
    at ../mesa-9999/src/amd/vulkan/meta/radv_meta.c:491
#16 0x00007fff90b4f5cc in radv_CreateDevice (physicalDevice=0x7fff909db310, 
    pCreateInfo=0x7fffd1e938b0, pAllocator=0x0, pDevice=0x7fffd212d930)
    at ../mesa-9999/src/amd/vulkan/radv_device.c:1121
#17 0x00007fff90c18658 in vk_tramp_CreateDevice (physicalDevice=0x7fff909db310, 
    pCreateInfo=0x7fffd1e938b0, pAllocator=0x0, pDevice=0x7fffd212d930)
    at src/vulkan/runtime/vk_dispatch_trampolines.c:78
#18 0x00007fffd1febcb0 in terminator_CreateDevice (
    physicalDevice=0x7ffff4d3a280, pCreateInfo=0x7fffd1e93df0, pAllocator=0x0, 
    pDevice=0x7fffd1e93d08)
    at /usr/src/debug/media-libs/vulkan-loader-1.3.275/Vulkan-Loader-vulkan-sdk-1.3.275/loader/loader.c:5833
#19 0x00007fffd1fe9612 in loader_create_device_chain (pd=0x7ffff4d3a280, 
    pCreateInfo=0x7fffd1e94090, pAllocator=0x0, inst=0x7fff9179c070, 
    dev=0x7fffd212bfe0, callingLayer=0x0, layerNextGDPA=0x0)
    at /usr/src/debug/media-libs/vulkan-loader-1.3.275/Vulkan-Loader-vulkan-sdk-1.3.275/loader/loader.c:4937
#20 0x00007fffd1fe7483 in loader_layer_create_device (instance=0x0, 
    physicalDevice=0x7ffff4d3a130, pCreateInfo=0x7fffd1e94090, pAllocator=0x0, 
    pDevice=0x7fffd2129fd8, layerGIPA=0x0, nextGDPA=0x0)
    at /usr/src/debug/media-libs/vulkan-loader-1.3.275/Vulkan-Loader-vulkan-sdk-1.3.275/loader/loader.c:4317
#21 0x00007fffd1ff6b3c in vkCreateDevice (physicalDevice=0x7ffff4d3a130, 
    pCreateInfo=0x7fffd1e94090, pAllocator=0x0, pDevice=0x7fffd2129fd8)
    at /usr/src/debug/media-libs/vulkan-loader-1.3.275/Vulkan-Loader-vulkan-sdk-1.3.275/loader/trampoline.c:1004
#22 0x00007fffd266185e in Vulkan::Context::create_device (
    this=this@entry=0x7fffd2129fc0, gpu_=gpu_@entry=0x0, 
    surface=<optimized out>, surface@entry=0x7fff917cb450, 
    required_device_extensions=<optimized out>, 
    num_required_device_extensions=<optimized out>, 
    required_features=required_features@entry=0x7fffd1e94e00, flags=1)
    at /usr/src/debug/games-emulation/rmg-9999/rmg-9999/Source/3rdParty/mupen64plus-video-parallel/vulkan/context.cpp:1702
#23 0x00007fffd26624b0 in Vulkan::Context::init_device (
    this=this@entry=0x7fffd2129fc0, gpu_=gpu_@entry=0x0, 
    surface_compat=surface_compat@entry=0x7fff917cb450, 
    device_ext=<optimized out>, device_ext_count=<optimized out>, 
    flags=flags@entry=1)
    at /usr/src/debug/games-emulation/rmg-9999/rmg-9999/Source/3rdParty/mupen64plus-video-parallel/vulkan/context.cpp:175
#24 0x00007fffd26a30df in Vulkan::WSI::init_context_from_platform (
    this=this@entry=0x7fffd2276270, 
    num_thread_indices=num_thread_indices@entry=1, system_handles=...)
    at /usr/src/debug/games-emulation/rmg-9999/rmg-9999/Source/3rdParty/mupen64plus-video-parallel/vulkan/wsi.cpp:274
#25 0x00007fffd26a51a9 in Vulkan::WSI::init_simple (this=0x7fffd2276270, 
    num_thread_indices=num_thread_indices@entry=1, system_handles=...)
    at /usr/src/debug/games-emulation/rmg-9999/rmg-9999/Source/3rdParty/mupen64plus-video-parallel/vulkan/wsi.cpp:232
#26 0x00007fffd26b006f in vk_init ()
    at /usr/lib/gcc/x86_64-gentoo-linux-musl/13/include/g++-v13/bits/unique_ptr.h:199
#27 0x00007fffd26af87c in RomOpen ()
    at /usr/src/debug/games-emulation/rmg-9999/rmg-9999/Source/3rdParty/mupen64plus-video-parallel/gfx_m64p.cpp:316
#28 0x00007ffff2c592bd in main_run ()
    at /usr/src/debug/games-emulation/rmg-9999/rmg-9999/Source/3rdParty/mupen64plus-core/src/main/main.c:1925
#29 0x00007ffff2c0d898 in CoreDoCommand (Command=M64CMD_EXECUTE, ParamInt=0, 
    ParamPtr=0x0)
    at /usr/src/debug/games-emulation/rmg-9999/rmg-9999/Source/3rdParty/mupen64plus-core/src/api/frontend.c:266
#30 0x00007ffff7ed9c66 in CoreStartEmulation (n64rom=..., n64ddrom=...)
    at /usr/src/debug/games-emulation/rmg-9999/rmg-9999/Source/RMG-Core/Emulation.cpp:156
#31 0x0000555555617b84 in Thread::EmulationThread::run (this=0x7fffd22a50e0)
    at /usr/src/debug/games-emulation/rmg-9999/rmg-9999/Source/RMG/Thread/EmulationThread.cpp:37
#32 0x00007ffff5e157ce in operator() (__closure=0x7fffd1e97858)
    at /usr/src/debug/dev-qt/qtbase-6.6.1-r3/qtbase-everywhere-src-6.6.1/src/corelib/thread/qthread_unix.cpp:324
#33 0x00007ffff5e169eb in (anonymous namespace)::terminate_on_exception<QThreadPrivate::start(void*)::<lambda()> >(struct {...} &&) (t=...)
    at /usr/src/debug/dev-qt/qtbase-6.6.1-r3/qtbase-everywhere-src-6.6.1/src/corelib/thread/qthread_unix.cpp:260
#34 0x00007ffff5e158c0 in QThreadPrivate::start (arg=0x7fffd22a50e0)
    at /usr/src/debug/dev-qt/qtbase-6.6.1-r3/qtbase-everywhere-src-6.6.1/src/corelib/thread/qthread_unix.cpp:283
#35 0x00007ffff7fb59de in start (p=0x7fffd1e978b0)
    at src/thread/pthread_create.c:207
#36 0x00007ffff7fc3295 in __clone () at src/thread/x86_64/clone.s:22
Backtrace stopped: frame did not save the PC

RMG-gdb.log

orbea commented 5 months ago

Additionally this PR was used to fix the build with musl. https://github.com/Themaister/Granite/pull/129

Rosalie241 commented 5 months ago

Does this happen after starting a ROM after starting RMG? Or does this happen after ending emulation and then starting a ROM again?

Rosalie241 commented 5 months ago

Er, actually, nevermind, it does look like a mesa issue on first glance so I'd recommend taking the issue there maybe

orbea commented 5 months ago

llvm: 17.0.6

It also fails with RADV_DEBUG=llvm.

Thread 15 "Thread::Emulati" received signal SIGSEGV, Segmentation fault.
[Switching to LWP 19732]
0x00007fff8c576c5b in llvm::TargetLowering::SimplifyDemandedVectorElts (
    this=0x0, Op=..., OriginalDemandedElts=..., KnownUndef=..., KnownZero=..., 
    TLO=..., Depth=4, AssumeSingleUse=false)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:2864
2864    /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp: No such file or directory.
(gdb) bt
#0  0x00007fff8c576c5b in llvm::TargetLowering::SimplifyDemandedVectorElts (
    this=0x0, Op=..., OriginalDemandedElts=..., KnownUndef=..., KnownZero=..., 
    TLO=..., Depth=4, AssumeSingleUse=false)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:2864
#1  0x00007fff8c570c58 in llvm::TargetLowering::SimplifyDemandedBits (
    this=0x7fff87047600, Op=..., OriginalDemandedBits=..., 
    OriginalDemandedElts=..., Known=..., TLO=..., Depth=3, AssumeSingleUse=false)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:2555
#2  0x00007fff8c56fe7c in llvm::TargetLowering::SimplifyDemandedBits (
    this=0x7fff87047600, Op=..., OriginalDemandedBits=..., 
    OriginalDemandedElts=..., Known=..., TLO=..., Depth=2, AssumeSingleUse=false)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:2485
#3  0x00007fff8c563eea in llvm::TargetLowering::SimplifyDemandedBits (
    this=0x7fff87047600, Op=..., OriginalDemandedBits=..., 
    OriginalDemandedElts=..., Known=..., TLO=..., Depth=1, AssumeSingleUse=false)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:1407
#4  0x00007fff8c564a6f in llvm::TargetLowering::SimplifyDemandedBits (
    this=0x7fff87047600, Op=..., OriginalDemandedBits=..., 
    OriginalDemandedElts=..., Known=..., TLO=..., Depth=0, AssumeSingleUse=false)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:1454
#5  0x00007fff8c5602c0 in llvm::TargetLowering::SimplifyDemandedBits (
    this=0x7fff87047600, Op=..., DemandedBits=..., Known=..., TLO=..., Depth=0, 
    AssumeSingleUse=false)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:646
#6  0x00007fff8c1a6490 in (anonymous namespace)::DAGCombiner::SimplifyDemandedBits (this=0x7fffd1e68c78, Op=..., DemandedBits=...)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:335
#7  0x00007fff8c19f443 in (anonymous namespace)::DAGCombiner::SimplifyDemandedBits (this=0x7fffd1e68c78, Op=...)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:329
#8  0x00007fff8c145f7c in (anonymous namespace)::DAGCombiner::visitOR (
    this=0x7fffd1e68c78, N=0x7fff86ffb7f0)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:7819
#9  0x00007fff8c1265e6 in (anonymous namespace)::DAGCombiner::visit (
    this=0x7fffd1e68c78, N=0x7fff86ffb7f0)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1924
#10 0x00007fff8c125191 in (anonymous namespace)::DAGCombiner::combine (
    this=0x7fffd1e68c78, N=0x7fff86ffb7f0)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:2035
#11 0x00007fff8c11f2c2 in (anonymous namespace)::DAGCombiner::Run (
    this=0x7fffd1e68c78, AtLevel=llvm::BeforeLegalizeTypes)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1827
#12 0x00007fff8c11e6eb in llvm::SelectionDAG::Combine (this=0x7ffff4cc4380, 
    Level=llvm::BeforeLegalizeTypes, AA=0x7fff908a88b0, 
    OptLevel=llvm::CodeGenOpt::Default)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:27592
#13 0x00007fff8c52b66d in llvm::SelectionDAGISel::CodeGenAndEmitDAG (
    this=0x7fff9179a940)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:785
#14 0x00007fff8c52b529 in llvm::SelectionDAGISel::SelectBasicBlock (
    this=0x7fff9179a940, Begin=..., End=..., HadTailCall=@0x7fffd1e69c87: false)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:701
#15 0x00007fff8c52ac92 in llvm::SelectionDAGISel::SelectAllBasicBlocks (
    this=0x7fff9179a940, Fn=...)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1700
#16 0x00007fff8c526c6f in llvm::SelectionDAGISel::runOnMachineFunction (
    this=0x7fff9179a940, mf=...)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:482
#17 0x00007fff8f49af30 in AMDGPUDAGToDAGISel::runOnMachineFunction (
    this=0x7fff9179a940, MF=...)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp:136
#18 0x00007fff8bb85592 in llvm::MachineFunctionPass::runOnFunction (
    this=0x7fff9179a940, F=...)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/CodeGen/MachineFunctionPass.cpp:91
#19 0x00007fff8b51dc2f in llvm::FPPassManager::runOnFunction (
    this=0x7fff9179cc30, F=...)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/IR/LegacyPassManager.cpp:1435
#20 0x00007fff8de0d50e in (anonymous namespace)::CGPassManager::RunPassOnSCC (
    this=0x7fff9179c670, P=0x7fff9179cc30, CurSCC=..., CG=..., 
    CallGraphUpToDate=@0x7fffd1e6b9e7: true, 
    DevirtualizedCall=@0x7fffd1e6ba9f: false)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/Analysis/CallGraphSCCPass.cpp:180
#21 0x00007fff8de0c53a in (anonymous namespace)::CGPassManager::RunAllPassesOnSCC
    (this=0x7fff9179c670, CurSCC=..., CG=..., 
    DevirtualizedCall=@0x7fffd1e6ba9f: false)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/Analysis/CallGraphSCCPass.cpp:470
#22 0x00007fff8de0bead in (anonymous namespace)::CGPassManager::runOnModule (
    this=0x7fff9179c670, M=...)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/Analysis/CallGraphSCCPass.cpp:535
#23 0x00007fff8b51e712 in (anonymous namespace)::MPPassManager::runOnModule (
    this=0x7fff9179bca0, M=...)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/IR/LegacyPassManager.cpp:1550
#24 0x00007fff8b51e17a in llvm::legacy::PassManagerImpl::run (
    this=0x7fff908cf6c0, M=...)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/IR/LegacyPassManager.cpp:535
#25 0x00007fff8b526b61 in llvm::legacy::PassManager::run (this=0x7fff909ebac8, 
    M=...)
    at /var/tmp/portage/sys-devel/llvm-17.0.6/work/llvm/lib/IR/LegacyPassManager.cpp:1677
#26 0x00007fff90efdaa5 in ac_compile_module_to_elf (p=0x7fff909eba70, 
    module=0x7fffd2280850, pelf_buffer=0x7fffd1e6bf98, pelf_size=0x7fffd1e6bfa0)
    at ../mesa-9999/src/amd/llvm/ac_llvm_helper.cpp:274
#27 0x00007fff90bf52d4 in radv_llvm_per_thread_info::compile_to_memory_buffer (
    this=0x7fff909f5820, module=0x7fffd2280850, pelf_buffer=0x7fffd1e6bf98, 
    pelf_size=0x7fffd1e6bfa0)
    at ../mesa-9999/src/amd/vulkan/radv_llvm_helper.cpp:54
#28 0x00007fff90bf5481 in radv_compile_to_elf (info=0x7fffd1e6c090, 
    module=0x7fffd2280850, pelf_buffer=0x7fffd1e6bf98, pelf_size=0x7fffd1e6bfa0)
    at ../mesa-9999/src/amd/vulkan/radv_llvm_helper.cpp:94
#29 0x00007fff90bf7909 in radv_llvm_compile (M=0x7fffd2280850, 
    pelf_buffer=0x7fffd1e6bf98, pelf_size=0x7fffd1e6bfa0, ac_llvm=0x7fffd1e6c090)
    at ../mesa-9999/src/amd/vulkan/radv_nir_to_llvm.c:511
#30 0x00007fff90bf7a17 in ac_compile_llvm_module (ac_llvm=0x7fffd1e6c090, 
    llvm_module=0x7fffd2280850, rbinary=0x7fffd1e6c128, 
    name=0x7fff9119c662 "Compute Shader", options=0x7fffd1e6c260)
    at ../mesa-9999/src/amd/vulkan/radv_nir_to_llvm.c:536
#31 0x00007fff90bf7c0b in radv_compile_nir_shader (ac_llvm=0x7fffd1e6c090, 
    options=0x7fffd1e6c260, info=0x7fffd1e6c408, rbinary=0x7fffd1e6c128, 
    args=0x7fffd1e6c790, nir=0x7fffd1e6c3f8, nir_count=1)
    at ../mesa-9999/src/amd/vulkan/radv_nir_to_llvm.c:572
#32 0x00007fff90bf7ca7 in llvm_compile_shader (options=0x7fffd1e6c260, 
    info=0x7fffd1e6c408, shader_count=1, shaders=0x7fffd1e6c3f8, 
    binary=0x7fffd1e6c128, args=0x7fffd1e6c790)
    at ../mesa-9999/src/amd/vulkan/radv_nir_to_llvm.c:590
#33 0x00007fff90bc4485 in shader_compile (device=0x7fff9094d220, 
    shaders=0x7fffd1e6c3f8, shader_count=1, stage=MESA_SHADER_COMPUTE, 
    info=0x7fffd1e6c408, args=0x7fffd1e6c790, stage_key=0x7fffd1e6dd88, 
    options=0x7fffd1e6c260) at ../mesa-9999/src/amd/vulkan/radv_shader.c:2446
#34 0x00007fff90bc46f3 in radv_shader_nir_to_asm (device=0x7fff9094d220, 
    pl_stage=0x7fffd1e6c3b0, shaders=0x7fffd1e6c3f8, shader_count=1, 
    gfx_state=0x0, keep_shader_info=false, keep_statistic_info=false)
    at ../mesa-9999/src/amd/vulkan/radv_shader.c:2483
#35 0x00007fff90b91285 in radv_compile_cs (device=0x7fff9094d220, 
    cache=0x7fffd1e84b50, cs_stage=0x7fffd1e6c3b0, keep_executable_info=false, 
    keep_statistic_info=false, is_internal=true, cs_binary=0x7fffd1e6c388)
    at ../mesa-9999/src/amd/vulkan/radv_pipeline_compute.c:157
#36 0x00007fff90b915a8 in radv_compute_pipeline_compile (
    pipeline=0x7fffd1ef7fc0, pipeline_layout=0x7fff9096f550, 
    device=0x7fff9094d220, cache=0x7fffd1e84b50, stage_key=0x7fffd1e6e02a, 
    pStage=0x7fffd1e6e148, creation_feedback=0x0)
    at ../mesa-9999/src/amd/vulkan/radv_pipeline_compute.c:212
#37 0x00007fff90b91873 in radv_compute_pipeline_create (_device=0x7fff9094d220, 
    _cache=0x7fffd1e84b50, pCreateInfo=0x7fffd1e6e130, pAllocator=0x0, 
    pPipeline=0x7fff909531d0)
    at ../mesa-9999/src/amd/vulkan/radv_pipeline_compute.c:268
#38 0x00007fff90ab8c82 in init_meta_clear_htile_mask_state (
    device=0x7fff9094d220)
    at ../mesa-9999/src/amd/vulkan/meta/radv_meta_clear.c:888
#39 0x00007fff90ab9759 in radv_device_init_meta_clear_state (
    device=0x7fff9094d220, on_demand=true)
    at ../mesa-9999/src/amd/vulkan/meta/radv_meta_clear.c:1059
#40 0x00007fff90a9e1f6 in radv_device_init_meta (device=0x7fff9094d220)
    at ../mesa-9999/src/amd/vulkan/meta/radv_meta.c:451
#41 0x00007fff90b4f5cc in radv_CreateDevice (physicalDevice=0x7fff91794090, 
    pCreateInfo=0x7fffd1e6e8b0, pAllocator=0x0, pDevice=0x7fffd212dac0)
    at ../mesa-9999/src/amd/vulkan/radv_device.c:1121
#42 0x00007fff90c18658 in vk_tramp_CreateDevice (physicalDevice=0x7fff91794090, 
    pCreateInfo=0x7fffd1e6e8b0, pAllocator=0x0, pDevice=0x7fffd212dac0)
    at src/vulkan/runtime/vk_dispatch_trampolines.c:78
#43 0x00007fffd1fd8cb0 in terminator_CreateDevice (
    physicalDevice=0x7ffff4cda910, pCreateInfo=0x7fffd1e6edf0, pAllocator=0x0, 
    pDevice=0x7fffd1e6ed08)
    at /usr/src/debug/media-libs/vulkan-loader-1.3.275/Vulkan-Loader-vulkan-sdk-1.3.275/loader/loader.c:5833
#44 0x00007fffd1fd6612 in loader_create_device_chain (pd=0x7ffff4cda910, 
    pCreateInfo=0x7fffd1e6f090, pAllocator=0x0, inst=0x7fffd1f91060, 
    dev=0x7fffd212c170, callingLayer=0x0, layerNextGDPA=0x0)
    at /usr/src/debug/media-libs/vulkan-loader-1.3.275/Vulkan-Loader-vulkan-sdk-1.3.275/loader/loader.c:4937
#45 0x00007fffd1fd4483 in loader_layer_create_device (instance=0x0, 
    physicalDevice=0x7ffff4cda070, pCreateInfo=0x7fffd1e6f090, pAllocator=0x0, 
    pDevice=0x7fffd2129fd8, layerGIPA=0x0, nextGDPA=0x0)
    at /usr/src/debug/media-libs/vulkan-loader-1.3.275/Vulkan-Loader-vulkan-sdk-1.3.275/loader/loader.c:4317
#46 0x00007fffd1fe3b3c in vkCreateDevice (physicalDevice=0x7ffff4cda070, 
    pCreateInfo=0x7fffd1e6f090, pAllocator=0x0, pDevice=0x7fffd2129fd8)
    at /usr/src/debug/media-libs/vulkan-loader-1.3.275/Vulkan-Loader-vulkan-sdk-1.3.275/loader/trampoline.c:1004
#47 0x00007fffd266185e in Vulkan::Context::create_device (
    this=this@entry=0x7fffd2129fc0, gpu_=gpu_@entry=0x0, 
    surface=<optimized out>, surface@entry=0x7fff917cd570, 
    required_device_extensions=<optimized out>, 
    num_required_device_extensions=<optimized out>, 
    required_features=required_features@entry=0x7fffd1e6fe00, flags=1)
    at /usr/src/debug/games-emulation/rmg-9999/rmg-9999/Source/3rdParty/mupen64plus-video-parallel/vulkan/context.cpp:1702
#48 0x00007fffd26624b0 in Vulkan::Context::init_device (
    this=this@entry=0x7fffd2129fc0, gpu_=gpu_@entry=0x0, 
    surface_compat=surface_compat@entry=0x7fff917cd570, 
    device_ext=<optimized out>, device_ext_count=<optimized out>, 
    flags=flags@entry=1)
    at /usr/src/debug/games-emulation/rmg-9999/rmg-9999/Source/3rdParty/mupen64plus-video-parallel/vulkan/context.cpp:175
#49 0x00007fffd26a30df in Vulkan::WSI::init_context_from_platform (
    this=this@entry=0x7fffd22764c0, 
    num_thread_indices=num_thread_indices@entry=1, system_handles=...)
    at /usr/src/debug/games-emulation/rmg-9999/rmg-9999/Source/3rdParty/mupen64plus-video-parallel/vulkan/wsi.cpp:274
#50 0x00007fffd26a51a9 in Vulkan::WSI::init_simple (this=0x7fffd22764c0, 
    num_thread_indices=num_thread_indices@entry=1, system_handles=...)
    at /usr/src/debug/games-emulation/rmg-9999/rmg-9999/Source/3rdParty/mupen64plus-video-parallel/vulkan/wsi.cpp:232
#51 0x00007fffd26b006f in vk_init ()
    at /usr/lib/gcc/x86_64-gentoo-linux-musl/13/include/g++-v13/bits/unique_ptr.h:199
#52 0x00007fffd26af87c in RomOpen ()
    at /usr/src/debug/games-emulation/rmg-9999/rmg-9999/Source/3rdParty/mupen64plus-video-parallel/gfx_m64p.cpp:316
#53 0x00007ffff2c592bd in main_run ()
    at /usr/src/debug/games-emulation/rmg-9999/rmg-9999/Source/3rdParty/mupen64plus-core/src/main/main.c:1925
#54 0x00007ffff2c0d898 in CoreDoCommand (Command=M64CMD_EXECUTE, ParamInt=0, 
    ParamPtr=0x0)
    at /usr/src/debug/games-emulation/rmg-9999/rmg-9999/Source/3rdParty/mupen64plus-core/src/api/frontend.c:266
#55 0x00007ffff7ed9c66 in CoreStartEmulation (n64rom=..., n64ddrom=...)
    at /usr/src/debug/games-emulation/rmg-9999/rmg-9999/Source/RMG-Core/Emulation.cpp:156
#56 0x0000555555617b84 in Thread::EmulationThread::run (this=0x7fffd22a6080)
    at /usr/src/debug/games-emulation/rmg-9999/rmg-9999/Source/RMG/Thread/EmulationThread.cpp:37
#57 0x00007ffff5e157ce in operator() (__closure=0x7fffd1e72858)
    at /usr/src/debug/dev-qt/qtbase-6.6.1-r3/qtbase-everywhere-src-6.6.1/src/corelib/thread/qthread_unix.cpp:324
#58 0x00007ffff5e169eb in (anonymous namespace)::terminate_on_exception<QThreadPrivate::start(void*)::<lambda()> >(struct {...} &&) (t=...)
    at /usr/src/debug/dev-qt/qtbase-6.6.1-r3/qtbase-everywhere-src-6.6.1/src/corelib/thread/qthread_unix.cpp:260
#59 0x00007ffff5e158c0 in QThreadPrivate::start (arg=0x7fffd22a6080)
    at /usr/src/debug/dev-qt/qtbase-6.6.1-r3/qtbase-everywhere-src-6.6.1/src/corelib/thread/qthread_unix.cpp:283
#60 0x00007ffff7fb59de in start (p=0x7fffd1e728b0)
    at src/thread/pthread_create.c:207
#61 0x00007ffff7fc3295 in __clone () at src/thread/x86_64/clone.s:22
Backtrace stopped: frame did not save the PC

RMG-gdb-radv-llvm.log

orbea commented 5 months ago

Does this happen after starting a ROM after starting RMG? Or does this happen after ending emulation and then starting a ROM again?

It happens when starting any rom, it doesn't get as far as even creating a window.

Er, actually, nevermind, it does look like a mesa issue on first glance so I'd recommend taking the issue there maybe

dri-devel @ OFTC also suggested this, I will create an issue at their Gitlab today.

orbea commented 5 months ago

I made the mesa issue. https://gitlab.freedesktop.org/mesa/mesa/-/issues/10488

Jj0YzL5nvJ commented 5 months ago

Try adding -DCMAKE_CXX_FLAGS="-pthread" to your build.

orbea commented 3 months ago

@Rosalie241 With help from users in #dri-devel @ OFTC it was discovered that the parallel plugin works with musl when building RMG with LDFLAGS=-Wl,-z,stack-size=0x200000.

On glibc systems the default thread stack size is on rlimit_stack which is large enough for RMG, but with musl its 128k which causes the segfault.

So I think the correct fix is to explicitly set the stack size, but I am not sure what code base this needs to be done in?

nekopsykose commented 3 months ago

So I think the correct fix is to explicitly set the stack size, but I am not sure what code base this needs to be done in?

the application is what the linker attribute gets read from (or where you use pthread attrs in code), and RMG is the application that spawns threads here, so it would be here for RMG specifically

Rosalie241 commented 3 months ago

That's an interesting find! I wonder if either parallel or RMG is to blame for needing such a big stack then, but considering it segfaults in parallel I presume it's not RMG's fault.

From a quick search online the best option could be to specify the linker flags for RMG specifically to change the stack size, though I'll need to test that to see if that works properly, sadly I don't have a musl system to test with currently.

nekopsykose commented 3 months ago

That's an interesting find! I wonder if either parallel or RMG is to blame for needing such a big stack then, but considering it segfaults in parallel I presume it's not RMG's fault.

both use the stack (and it's not clear where all the use comes from since nobody checked that), but the thread is created by RMG (in this->emulationThread = new Thread::EmulationThread(this), which then ends up initialising the plugin, etc). the default thread stack size comes from the application (also RMG). the plugin cannot control these parameters itself.

in this case we know it's the emulationthread that overflows, so we can raise the size only for it rather than all threads via the linker flag. i think that would be something like (untested and uncompiled, in MainWindow.cpp):

void MainWindow::initializeEmulationThread(void)
{
    // 2MiB stack
    this->emulationThread = new Thread::EmulationThread(this).setStackSize(0x200000);
}

if @orbea can verify it works that's probably the best way to go, though afaik on glibc the default is currently based on rlimit_stack which defaults to 8MiB, in which case maybe picking 0x800000 might be a bit safer. if this works for everyone though then maybe it's ok :)

nekopsykose commented 3 months ago

or well, setstacksize returns void, so

void MainWindow::initializeEmulationThread(void)
{
    auto thread = new Thread::EmulationThread(this);
    // 2MiB stack
    thread->setStackSize(0x200000);
    this->emulationThread = thread;
}

this works for me on musl (just tested it)

Rosalie241 commented 3 months ago

I've pushed https://github.com/Rosalie241/RMG/commit/b86f520ee72010a5023d3ab6f2b6d33ee8c08e27 to master, I've confirmed that making the stack size as small as musl makes it crash on glibc aswell, I think 2 MiB should be plenty enough for now but can be increased in the future if needed.

I've made you the commit author @nekopsykose because you wrote the code, I just moved it to the constructor of the EmulationThread class :heart:

Thank you both for figuring this issue out and I'm glad the fix wasn't complex, I'll close this issue for now but feel free to re-open it if it still occurs!

nekopsykose commented 3 months ago

I've made you the commit author @nekopsykose because you wrote the code, I just moved it to the constructor of the EmulationThread class ❤️

aww, thank you! <3 glad to have been able to help

orbea commented 3 months ago

Thank you very much, I can confirm it works on my end too now. :)