diff options
| author | Zephyron <zephyron@citron-emu.org> | 2025-03-31 20:59:39 +1000 |
|---|---|---|
| committer | MrPurple666 <antoniosacramento666usa@gmail.com> | 2025-04-12 23:39:24 -0300 |
| commit | 0c5659a198816ef09b554308c12cea0b5d6220e9 (patch) | |
| tree | baed9b7dec055c2aa6ab92b0b93b9c7552494035 /src/video_core/renderer_vulkan/renderer_vulkan.cpp | |
| parent | b550c6e3cc67e2c92aeefa208fbc466c050977b9 (diff) | |
video_core: Enhance Vulkan shader compilation with async threading system
Implement a robust asynchronous shader compilation system inspired by commit
1fd5fefcb17fe7fe65faed1c991fb41db782ab0f. This enhancement provides:
- True multi-threaded shader compilation with atomic status tracking
- Persistent disk caching for faster shader loading
- Command queue system for background processing
- Integration with Citron's scheduler for better resource management
- Parallel shader loading to reduce startup times
- Improved error handling and recovery mechanisms
These changes significantly reduce shader compilation stuttering and improve
overall performance when using asynchronous shaders. The implementation
maintains compatibility with Citron's existing architecture while adding
more robust threading capabilities.
Co-authored-by: boss.sfc <boss.sfc@citron-emu.org>
Co-committed-by: boss.sfc <boss.sfc@citron-emu.org>
Signed-off-by: Zephyron <zephyron@citron-emu.org>
Diffstat (limited to 'src/video_core/renderer_vulkan/renderer_vulkan.cpp')
| -rw-r--r-- | src/video_core/renderer_vulkan/renderer_vulkan.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.cpp b/src/video_core/renderer_vulkan/renderer_vulkan.cpp index 7ef1998263..e301dd7aef 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.cpp +++ b/src/video_core/renderer_vulkan/renderer_vulkan.cpp @@ -130,6 +130,39 @@ RendererVulkan::RendererVulkan(Core::Frontend::EmuWindow& emu_window, turbo_mode.emplace(instance, dld); scheduler.RegisterOnSubmit([this] { turbo_mode->QueueSubmitted(); }); } + + // Initialize enhanced shader compilation system + shader_manager.SetScheduler(&scheduler); + LOG_INFO(Render_Vulkan, "Enhanced shader compilation system initialized"); + + // Preload common shaders if enabled + if (Settings::values.use_asynchronous_shaders.GetValue()) { + // Use a simple shader directory path - can be updated to match Citron's actual path structure + const std::string shader_dir = "./shaders"; + std::vector<std::string> common_shaders; + + // Add paths to common shaders that should be preloaded + // These will be compiled in parallel for faster startup + if (std::filesystem::exists(shader_dir)) { + try { + for (const auto& entry : std::filesystem::directory_iterator(shader_dir)) { + if (entry.path().extension() == ".spv") { + common_shaders.push_back(entry.path().string()); + } + } + + if (!common_shaders.empty()) { + LOG_INFO(Render_Vulkan, "Preloading {} common shaders", common_shaders.size()); + shader_manager.PreloadShaders(common_shaders); + } + } catch (const std::exception& e) { + LOG_ERROR(Render_Vulkan, "Error during shader preloading: {}", e.what()); + } + } else { + LOG_INFO(Render_Vulkan, "Shader directory not found at {}", shader_dir); + } + } + Report(); InitializePlatformSpecific(); } catch (const vk::Exception& exception) { @@ -435,6 +468,12 @@ void RendererVulkan::RecoverFromError() { // Wait for device to finish operations void(device.GetLogical().WaitIdle()); + // Process all pending commands in our queue + ProcessAllCommands(); + + // Wait for any async shader compilations to finish + shader_manager.WaitForCompilation(); + // Clean up resources that might be causing problems texture_manager.CleanupTextureCache(); |
