From 3ab2d623bb48376e3b29ab379b90c32ebf21b0d1 Mon Sep 17 00:00:00 2001 From: Alan Tse Date: Mon, 8 Apr 2024 23:22:15 -0700 Subject: [PATCH] fix: compile only shaders with available source --- src/ShaderCache.cpp | 20 +++++++++++++++++--- src/ShaderCache.h | 2 ++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/ShaderCache.cpp b/src/ShaderCache.cpp index f9b2bebf0..168c161ab 100644 --- a/src/ShaderCache.cpp +++ b/src/ShaderCache.cpp @@ -1035,6 +1035,10 @@ namespace SIE std::transform(path.begin(), path.end(), std::back_inserter(strPath), [](wchar_t c) { return (char)c; }); + if (!std::filesystem::exists(path)) { + logger::error("Failed to compile {} shader {}::{}: {} does not exist", magic_enum::enum_name(shaderClass), magic_enum::enum_name(type), descriptor, strPath); + return nullptr; + } logger::debug("Compiling {} {}:{}:{:X} to {}", strPath, magic_enum::enum_name(type), magic_enum::enum_name(shaderClass), descriptor, MergeDefinesString(defines)); // compile shaders @@ -1237,7 +1241,7 @@ namespace SIE } auto state = State::GetSingleton(); - if (!((ShaderCache::IsSupportedShader(shader) || state->IsDeveloperMode() && state->IsShaderEnabled(shader)))) { + if (!((ShaderCache::IsSupportedShader(shader) || state->IsDeveloperMode() && state->IsShaderEnabled(shader) && ShaderCache::IsShaderSourceAvailable(shader)))) { return nullptr; } @@ -1278,8 +1282,7 @@ namespace SIE } auto state = State::GetSingleton(); - if (!(ShaderCache::IsSupportedShader(shader) || state->IsDeveloperMode() && - state->IsShaderEnabled(shader))) { + if (!((ShaderCache::IsSupportedShader(shader) || state->IsDeveloperMode() && state->IsShaderEnabled(shader) && ShaderCache::IsShaderSourceAvailable(shader)))) { return nullptr; } @@ -1414,6 +1417,17 @@ namespace SIE return compilationSet.GetStatsString(a_timeOnly); } + inline bool ShaderCache::IsShaderSourceAvailable(const RE::BSShader& shader) + { + const std::wstring path = SIE::SShaderCache::GetShaderPath(shader.fxpFilename); + + std::string strPath; + std::transform(path.begin(), path.end(), std::back_inserter(strPath), [](wchar_t c) { + return (char)c; + }); + return std::filesystem::exists(path); + } + bool ShaderCache::IsCompiling() { return compilationSet.totalTasks && compilationSet.completedTasks + compilationSet.failedTasks < compilationSet.totalTasks; diff --git a/src/ShaderCache.h b/src/ShaderCache.h index f7f78bf89..a58a9c126 100644 --- a/src/ShaderCache.h +++ b/src/ShaderCache.h @@ -125,6 +125,8 @@ namespace SIE return IsSupportedShader(shader.shaderType.get()); } + inline static bool IsShaderSourceAvailable(const RE::BSShader& shader); + bool IsCompiling(); bool IsEnabled() const; void SetEnabled(bool value);