From ed70f697a32d4c92504e0d5af6480d21eb89f474 Mon Sep 17 00:00:00 2001 From: ParantezTech <12572227+par274@users.noreply.github.com> Date: Sat, 3 Oct 2026 02:33:41 +0300 Subject: [PATCH] [Vulkan] Keep the pipeline cache in memory on Windows The GPU driver keeps its own shader cache on disk, and the shader prewarm list rebuilds it after an update, so Windows no longer writes the driver cache file by default. SHARPEMU_VK_PIPELINE_CACHE=file keeps one; Linux keeps the file and macOS keeps its shards. --- .../VulkanVideoPresenter.Device.Setup.cs | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/SharpEmu.Libs/VideoOut/VulkanVideoPresenter.Device.Setup.cs b/src/SharpEmu.Libs/VideoOut/VulkanVideoPresenter.Device.Setup.cs index a9a2d19..a573712 100644 --- a/src/SharpEmu.Libs/VideoOut/VulkanVideoPresenter.Device.Setup.cs +++ b/src/SharpEmu.Libs/VideoOut/VulkanVideoPresenter.Device.Setup.cs @@ -1197,6 +1197,11 @@ internal static unsafe partial class VulkanVideoPresenter private void CreatePipelineCache() { var cacheMode = Environment.GetEnvironmentVariable("SHARPEMU_VK_PIPELINE_CACHE"); + // MoltenVK imports compile every cached MSL library. Load shader + // groups on demand on macOS so a mature cache cannot hold startup + // behind unrelated scenes. Keep explicit overrides for comparison. + var shardMode = Environment.GetEnvironmentVariable("SHARPEMU_VK_PIPELINE_CACHE_SHARDS"); + var useShards = shardMode == "1" || (shardMode is null && OperatingSystem.IsMacOS()); // Vulkan cache blobs carry the implementation's compatibility // header and are rejected/rebuilt below when the device or driver // changes. MoltenVK compilation of a large translated shader can @@ -1204,13 +1209,9 @@ internal static unsafe partial class VulkanVideoPresenter // much more harmful than using Vulkan's normal persistence path. // Keep an explicit opt-out for diagnostics and read-only systems. var persistentCacheEnabled = - !string.Equals(cacheMode, "0", StringComparison.Ordinal); + !string.Equals(cacheMode, "0", StringComparison.Ordinal) && + (useShards || !OperatingSystem.IsWindows() || cacheMode is "1" or "file"); _pipelineCachePath = persistentCacheEnabled ? GetPipelineCachePath() : null; - // MoltenVK imports compile every cached MSL library. Load shader - // groups on demand on macOS so a mature cache cannot hold startup - // behind unrelated scenes. Keep explicit overrides for comparison. - var shardMode = Environment.GetEnvironmentVariable("SHARPEMU_VK_PIPELINE_CACHE_SHARDS"); - var useShards = shardMode == "1" || (shardMode is null && OperatingSystem.IsMacOS()); if (_pipelineCachePath is not null && useShards) { @@ -1273,8 +1274,12 @@ internal static unsafe partial class VulkanVideoPresenter if (_pipelineCachePath is null) { Console.Error.WriteLine( - "[LOADER][INFO] Vulkan pipeline cache ready: memory-only " + - "(persistence disabled with SHARPEMU_VK_PIPELINE_CACHE=0)."); + string.Equals(cacheMode, "0", StringComparison.Ordinal) + ? "[LOADER][INFO] Vulkan pipeline cache ready: memory-only " + + "(persistence disabled with SHARPEMU_VK_PIPELINE_CACHE=0)." + : "[LOADER][INFO] Vulkan pipeline cache ready: memory-only " + + "(the driver shader cache and the shader prewarm list replace the cache file; " + + "SHARPEMU_VK_PIPELINE_CACHE=file keeps one)."); } else {