Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: compile only shaders with available source #267

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading