hexops / mach

zig game engine & graphics toolkit
https://machengine.org
Other
3.41k stars 162 forks source link

sysgpu: vram & ram memory leak using vulkan/wayland #1271

Closed joshua-holmes closed 1 month ago

joshua-holmes commented 2 months ago

A Discord user reported this bug in the Discord chat.

When running the core-triangle example with ManogHUD enabled so I can monitor resource usage, the VRAM and RAM usage steadily climbs while the core-triangle example is running. My total system VRAM usage starts at 1.9 GiB used and every 10-15 sec another 0.1 GiB is added indefinitely. RAM creeps up at a slower rate for me.

For the mentioned Discord user, the program crashes after 15 sec with the following error message, although, that did not happen for me:

 ./core-triangle
info(gamemode): gamemode: activated
info(mach): found Vulkan backend on Discrete GPU adapter: AMD Radeon RX 7900 XTX (RADV NAVI31), Vulkan driver version 24.2.2
General protection exception (no address available)
???:?:?: 0x70a8362a20d0 in ??? (libvulkan_radeon.so)
Unwind information for `libvulkan_radeon.so:0x70a8362a20d0` was not available, trace may be incomplete

???:?:?: 0x70a82a76daf2 in ??? (libVkLayer_khronos_validation.so)
/home/meiko/.cache/zig/p/1220d2b6789b71a94e692cb2f060bff4ffa4edfe196216cd573da68e74ab884eb34e/vk.zig:29755:62: 0x10d6232 in beginCommandBuffer (core-triangle)
            const result = self.dispatch.vkBeginCommandBuffer(
                                                             ^
/home/meiko/dev/Motoko/mach/src/sysgpu/vulkan.zig:2316:35: 0x10d5e4b in init (core-triangle)
        try vkd.beginCommandBuffer(vk_command_buffer, &.{ .flags = .{ .one_time_submit_bit = true } });
                                  ^
/home/meiko/dev/Motoko/mach/src/sysgpu/vulkan.zig:2487:54: 0x10d6bd1 in init (core-triangle)
        const command_buffer = try CommandBuffer.init(device);
                                                     ^
/home/meiko/dev/Motoko/mach/src/sysgpu/vulkan.zig:632:35: 0x1134451 in createCommandEncoder (core-triangle)
        return CommandEncoder.init(device, desc);
                                  ^
/home/meiko/dev/Motoko/mach/src/sysgpu/main.zig:449:60: 0x1139298 in tick (core-triangle)
        const command_encoder = device.createCommandEncoder(descriptor orelse &.{}) catch @panic("api error");
                                                           ^
/home/meiko/dev/Motoko/mach/src/module/module.zig:444:32: 0x113bf0c in dispatchInternal__anon_13098 (core-triangle)
                .ErrorUnion => try @call(.auto, handler, args),
                               ^
/home/meiko/dev/Motoko/mach/src/module/module.zig:360:38: 0x113c74f in dispatch (core-triangle)
            return m.dispatchInternal(stack_space, options, injectable);
                                     ^
/home/meiko/dev/Motoko/mach/src/module/module.zig:325:27: 0x122a184 in dispatchUntil__anon_28952 (core-triangle)
            try m.dispatch(stack_space, .{
                          ^
/home/meiko/dev/Motoko/mach/src/Core.zig:332:28: 0x112e9bc in dispatch (core-triangle)
    mach.mods.dispatchUntil(stack_space, .mach_core, .frame_finished) catch {
                           ^
/home/meiko/dev/Motoko/mach/src/Core.zig:315:21: 0x112e894 in start (core-triangle)
            dispatch(stack_space);
                    ^
/home/meiko/dev/Motoko/mach/src/module/module.zig:444:32: 0x113b19f in dispatchInternal__anon_13098 (core-triangle)
                .ErrorUnion => try @call(.auto, handler, args),
                               ^
/home/meiko/dev/Motoko/mach/src/module/module.zig:360:38: 0x113c74f in dispatch (core-triangle)
            return m.dispatchInternal(stack_space, options, injectable);
                                     ^
/home/meiko/dev/Motoko/mach/examples/core/triangle/main.zig:23:27: 0x113c89e in main (core-triangle)
    try mach.mods.dispatch(stack_space, .{});
                          ^
/home/meiko/.local/share/zigup/zig-0.13.0-dev.351+64ef45eb0/files/lib/std/start.zig:524:37: 0x113ccde in main (core-triangle)
            const result = root.main() catch |err| {
                                    ^
???:?:?: 0x70a8383f3e07 in ??? (libc.so.6)
???:?:?: 0x70a8383f3ecb in ??? (libc.so.6)
???:?:?: 0x10b7524 in ??? (???)
RonaldZielaznicki commented 1 month ago

I think this should be fixed in https://github.com/hexops/mach/pull/1289

joshua-holmes commented 1 month ago

Yes! That fixed the issue!