Skip to content

Commit

Permalink
fix: compile only shaders with available source (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse authored Apr 9, 2024
1 parent e1af4ab commit f9c504e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/ShaderCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/ShaderCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f9c504e

Please sign in to comment.