From ce5d5d2aff50f9ce8159d609824eb2391bed9ef2 Mon Sep 17 00:00:00 2001 From: MrPurple666 Date: Sun, 18 May 2025 17:45:32 +0000 Subject: THIS NEEDS TO BE CHECKED BEFORE MERGE: RAII fix, initial MSAA, some fixes for memory misallocation (#116) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • MSAA Fixes: Fixes upload/download for MSAA textures using temporary non-MSAA images. Ensures compatibility with color formats and adds fallbacks for depth/stencil. • Memory fix misallocation: Adds checks for null/zero-length operations in memory management and improves cleanup to avoid crashes (Related to crash issues due to misallocation, RP5 and 865) • Vulkan Initialization (RAII): this almost rewrites the way vulkan initializes to avoid crashes, using a correct order now (thanks @crueter for the initial fix) •Please check before merging: - Test MSAA workflows (especially color/depth transitions and low memory cases). - Verify memory operations (e.g., unmapping zero-length regions). - Check Vulkan object lifetimes and platform-specific behavior. - Check others plataforms beyond android Why is everything in one PR? Otherwise, this is all a big fix, by checking the points above we can create a branch for each one and check them by themselves. I'm not standing still while I'm away, I'm just out of time for now. Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/116 Co-authored-by: MrPurple666 Co-committed-by: MrPurple666 --- src/video_core/renderer_vulkan/renderer_vulkan.h | 27 ++++++++++++++---------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src/video_core/renderer_vulkan/renderer_vulkan.h') diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.h b/src/video_core/renderer_vulkan/renderer_vulkan.h index c1e6d5db7f..ec4215253f 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.h +++ b/src/video_core/renderer_vulkan/renderer_vulkan.h @@ -76,32 +76,37 @@ private: std::shared_ptr library; vk::InstanceDispatch dld; - // Keep original handles for compatibility with existing code - vk::Instance instance; - // RAII wrapper for instance - ManagedInstance managed_instance; + // Order of member variables determines destruction order (reverse of declaration) + // Critical Vulkan resources should be declared in proper dependency order + // Base Vulkan instance, debugging, and surface + vk::Instance instance; vk::DebugUtilsMessenger debug_messenger; - // RAII wrapper for debug messenger - ManagedDebugUtilsMessenger managed_debug_messenger; - vk::SurfaceKHR surface; - // RAII wrapper for surface - ManagedSurface managed_surface; - + + // Device and core resources Device device; MemoryAllocator memory_allocator; StateTracker state_tracker; Scheduler scheduler; Swapchain swapchain; PresentManager present_manager; + + // Rendering components BlitScreen blit_swapchain; BlitScreen blit_capture; BlitScreen blit_applet; RasterizerVulkan rasterizer; - std::optional turbo_mode; + // Optional components + std::optional turbo_mode; Frame applet_frame; + + // RAII wrappers - must be destroyed before their raw handles + // so they are declared after to be destroyed first + ManagedInstance managed_instance; + ManagedDebugUtilsMessenger managed_debug_messenger; + ManagedSurface managed_surface; }; } // namespace Vulkan -- cgit v1.2.3