Skip to content
Closed
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
19 changes: 0 additions & 19 deletions src/Deferred.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,25 +288,6 @@ void Deferred::PrepassPasses()
auto context = globals::d3d::context;
context->OMSetRenderTargets(0, nullptr, nullptr); // Unbind all bound render targets

globals::game::stateUpdateFlags->set(RE::BSGraphics::ShaderFlags::DIRTY_RENDERTARGET); // Run OMSetRenderTargets again

{
Comment thread
soda3000 marked this conversation as resolved.
ID3D11Buffer* buffers[1] = { *globals::game::perFrame.get() };

ID3D11Buffer* vrBuffer = nullptr;

if (REL::Module::IsVR()) {
static REL::Relocation<ID3D11Buffer**> VRValues{ REL::Offset(0x3180688) };
vrBuffer = *VRValues.get();
}
if (vrBuffer) {
context->CSSetConstantBuffers(12, 1, buffers);
context->CSSetConstantBuffers(13, 1, &vrBuffer);
} else {
context->CSSetConstantBuffers(12, 1, buffers);
}
}

globals::truePBR->PrePass();
for (auto* feature : Feature::GetFeatureList()) {
if (feature->loaded) {
Expand Down
37 changes: 33 additions & 4 deletions src/ShaderCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2724,9 +2724,29 @@ namespace SIE
QueryPerformanceCounter(&now);
totalTime.QuadPart += now.QuadPart - lastCalculation.QuadPart;
lastCalculation = now;
std::scoped_lock lock(compilationMutex);
processedTasks.insert(task);
tasksInProgress.erase(task);

// Check if compilation is complete and set completion time if needed (thread-safe)
bool shouldLogCompletion = false;
if (completionTime.QuadPart == 0 && completedTasks + failedTasks >= totalTasks) {
std::scoped_lock lock(compilationMutex);
// Double-check with lock held to prevent race condition
if (completionTime.QuadPart == 0 && completedTasks + failedTasks >= totalTasks) {
QueryPerformanceCounter(&completionTime);
shouldLogCompletion = true;
}
}

// Log completion outside the lock to avoid holding it during logging
if (shouldLogCompletion) {
logger::debug("Compilation completed in {} ms", GetHumanTime(static_cast<double>(completionTime.QuadPart - lastReset.QuadPart) * 1000.0 / frequency.QuadPart));
}

// Handle task completion tracking
{
std::scoped_lock lock(compilationMutex);
processedTasks.insert(task);
tasksInProgress.erase(task);
}
conditionVariable.notify_one();
}

Expand All @@ -2742,6 +2762,7 @@ namespace SIE
cacheHitTasks = 0;
QueryPerformanceCounter(&lastReset);
QueryPerformanceCounter(&lastCalculation);
completionTime = { 0 }; // Reset completion time
totalTime = { 0 };
}

Expand All @@ -2759,6 +2780,8 @@ namespace SIE

double CompilationSet::GetEta()
{
// For ETA calculation, we still use the active compilation time (totalTime)
// because it reflects the actual work time, not wall-clock time
double totalMs = static_cast<double>(totalTime.QuadPart) * 1000.0 / frequency.QuadPart;

if (totalMs == 0.0) {
Expand All @@ -2771,7 +2794,13 @@ namespace SIE

std::string CompilationSet::GetStatsString(bool a_timeOnly, bool a_elapsedOnly)
{
double totalMs = static_cast<double>(totalTime.QuadPart) * 1000.0 / frequency.QuadPart;
// Calculate elapsed time since compilation started
LARGE_INTEGER currentTime;
QueryPerformanceCounter(&currentTime);

// Use completion time if compilation is finished, otherwise current time
LARGE_INTEGER endTime = (completionTime.QuadPart != 0) ? completionTime : currentTime;
double totalMs = static_cast<double>(endTime.QuadPart - lastReset.QuadPart) * 1000.0 / frequency.QuadPart;

if (a_timeOnly) {
if (a_elapsedOnly) {
Expand Down
2 changes: 2 additions & 0 deletions src/ShaderCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ namespace SIE
public:
LARGE_INTEGER lastReset;
LARGE_INTEGER lastCalculation;
LARGE_INTEGER completionTime; // When compilation completed
LARGE_INTEGER frequency;
LARGE_INTEGER totalTime = { 0 };

Expand All @@ -252,6 +253,7 @@ namespace SIE
QueryPerformanceFrequency(&frequency);
QueryPerformanceCounter(&lastReset);
QueryPerformanceCounter(&lastCalculation);
completionTime = { 0 }; // Initialize to zero (not completed)
}

std::optional<ShaderCompilationTask> WaitTake(std::stop_token stoken);
Expand Down