Skip to content
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
9 changes: 9 additions & 0 deletions src/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ namespace globals
RE::BSUtilityShader* utilityShader = nullptr;
RE::Sky* sky = nullptr;
RE::UI* ui = nullptr;
RE::Main* main = nullptr;

RE::BSGraphics::PixelShader** currentPixelShader = nullptr;
RE::BSGraphics::VertexShader** currentVertexShader = nullptr;
Expand Down Expand Up @@ -197,6 +198,7 @@ namespace globals
void OnDataLoaded()
{
using namespace game;
main = RE::Main::GetSingleton();
sky = RE::Sky::GetSingleton();
utilityShader = RE::BSUtilityShader::GetSingleton();

Expand All @@ -206,6 +208,13 @@ namespace globals
shadowMaskQuarter = RE::GetINISetting("iShadowMaskQuarter:Display");
}

void OnGameWindowClose()
{
if (shaderCache) {
shaderCache->StopCompilation();
}
}

/**
* @brief Caches the current frame buffer data and clears the mapped pointer.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ namespace globals
extern RE::BSUtilityShader* utilityShader;
extern RE::Sky* sky;
extern RE::UI* ui;
extern RE::Main* main;

extern RE::BSGraphics::PixelShader** currentPixelShader;
extern RE::BSGraphics::VertexShader** currentVertexShader;
Expand Down Expand Up @@ -255,5 +256,6 @@ namespace globals
void OnInit();
void ReInit();
void OnDataLoaded();
void OnGameWindowClose();
void InstallD3DHooks(ID3D11DeviceContext* a_context);
}
3 changes: 3 additions & 0 deletions src/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,9 @@ namespace Hooks
if ((a_msg == WM_KILLFOCUS || a_msg == WM_SETFOCUS) && menu->initialized) {
menu->focusChanged = true;
}
if (a_msg == WM_CLOSE) {
globals::OnGameWindowClose();
}
return func(a_hwnd, a_msg, a_wParam, a_lParam);
}
static inline REL::Relocation<decltype(thunk)> func;
Expand Down
9 changes: 9 additions & 0 deletions src/ShaderCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2206,6 +2206,15 @@ namespace SIE
return compilationSet.totalTasks && compilationSet.completedTasks + compilationSet.failedTasks < compilationSet.totalTasks;
}

void ShaderCache::StopCompilation()
{
if (IsCompiling()) {
logger::info("Stopping {} remaining shader compilation tasks", compilationSet.totalTasks - compilationSet.completedTasks - compilationSet.failedTasks);
}
ssource.request_stop();
compilationSet.Clear();
}

bool ShaderCache::IsEnabled() const
{
return isEnabled;
Expand Down
1 change: 1 addition & 0 deletions src/ShaderCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ namespace SIE
void SetAsync(bool value);
bool IsDump() const;
void SetDump(bool value);
void StopCompilation();

bool IsDiskCache() const;
void SetDiskCache(bool value);
Expand Down
10 changes: 9 additions & 1 deletion src/XSEPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,18 @@ void MessageHandler(SKSE::MessagingInterface::Message* message)

auto shaderCache = globals::shaderCache;
shaderCache->menuLoaded = true;
while (shaderCache->IsCompiling() && !shaderCache->backgroundCompilation) {

auto* main = globals::game::main;

while (shaderCache->IsCompiling() && !shaderCache->backgroundCompilation && !(main && main->quitGame)) {
std::this_thread::sleep_for(100ms);
}

if (main && main->quitGame) {
logger::info("Game was closed, skipping feature DataLoaded methods");
break;
}
Comment thread
brucenguyen marked this conversation as resolved.

if (shaderCache->IsDiskCache()) {
shaderCache->WriteDiskCacheInfo();
}
Expand Down