summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/audio_core/renderer/adsp/audio_renderer.cpp2
-rw-r--r--src/common/steady_clock.cpp25
-rw-r--r--src/common/steady_clock.h11
-rw-r--r--src/common/x64/native_clock.cpp38
-rw-r--r--src/common/x64/native_clock.h5
-rw-r--r--src/core/core_timing.cpp2
-rw-r--r--src/core/cpu_manager.cpp2
-rw-r--r--src/core/hle/kernel/k_thread.cpp24
-rw-r--r--src/core/hle/kernel/k_thread.h2
-rw-r--r--src/core/hle/kernel/svc/svc_thread.cpp3
-rw-r--r--src/core/hle/service/hid/controllers/stubbed.cpp2
-rw-r--r--src/core/hle/service/hid/controllers/touchscreen.cpp8
-rw-r--r--src/core/perf_stats.cpp4
-rw-r--r--src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp8
-rw-r--r--src/video_core/buffer_cache/buffer_cache.h24
-rw-r--r--src/video_core/gpu_thread.cpp2
-rw-r--r--src/video_core/renderer_opengl/gl_fence_manager.cpp4
-rw-r--r--src/video_core/renderer_opengl/gl_graphics_pipeline.cpp5
-rw-r--r--src/video_core/renderer_opengl/gl_resource_manager.cpp10
-rw-r--r--src/video_core/renderer_opengl/gl_resource_manager.h3
-rw-r--r--src/video_core/renderer_opengl/gl_texture_cache.cpp4
21 files changed, 154 insertions, 34 deletions
diff --git a/src/audio_core/renderer/adsp/audio_renderer.cpp b/src/audio_core/renderer/adsp/audio_renderer.cpp
index 78c15629b..0e437e779 100644
--- a/src/audio_core/renderer/adsp/audio_renderer.cpp
+++ b/src/audio_core/renderer/adsp/audio_renderer.cpp
@@ -135,7 +135,7 @@ void AudioRenderer::ThreadFunc() {
static constexpr char name[]{"AudioRenderer"};
MicroProfileOnThreadCreate(name);
Common::SetCurrentThreadName(name);
- Common::SetCurrentThreadPriority(Common::ThreadPriority::Critical);
+ Common::SetCurrentThreadPriority(Common::ThreadPriority::High);
if (mailbox->ADSPWaitMessage() != RenderMessage::AudioRenderer_InitializeOK) {
LOG_ERROR(Service_Audio,
"ADSP Audio Renderer -- Failed to receive initialize message from host!");
diff --git a/src/common/steady_clock.cpp b/src/common/steady_clock.cpp
index 0d5908aa7..782859196 100644
--- a/src/common/steady_clock.cpp
+++ b/src/common/steady_clock.cpp
@@ -23,6 +23,19 @@ static s64 WindowsQueryPerformanceCounter() {
QueryPerformanceCounter(&counter);
return counter.QuadPart;
}
+
+static s64 GetSystemTimeNS() {
+ // GetSystemTimePreciseAsFileTime returns the file time in 100ns units.
+ static constexpr s64 Multiplier = 100;
+ // Convert Windows epoch to Unix epoch.
+ static constexpr s64 WindowsEpochToUnixEpochNS = 0x19DB1DED53E8000LL;
+
+ FILETIME filetime;
+ GetSystemTimePreciseAsFileTime(&filetime);
+ return Multiplier * ((static_cast<s64>(filetime.dwHighDateTime) << 32) +
+ static_cast<s64>(filetime.dwLowDateTime)) -
+ WindowsEpochToUnixEpochNS;
+}
#endif
SteadyClock::time_point SteadyClock::Now() noexcept {
@@ -53,4 +66,16 @@ SteadyClock::time_point SteadyClock::Now() noexcept {
#endif
}
+RealTimeClock::time_point RealTimeClock::Now() noexcept {
+#if defined(_WIN32)
+ return time_point{duration{GetSystemTimeNS()}};
+#elif defined(__APPLE__)
+ return time_point{duration{clock_gettime_nsec_np(CLOCK_REALTIME)}};
+#else
+ timespec ts;
+ clock_gettime(CLOCK_REALTIME, &ts);
+ return time_point{std::chrono::seconds{ts.tv_sec} + std::chrono::nanoseconds{ts.tv_nsec}};
+#endif
+}
+
}; // namespace Common
diff --git a/src/common/steady_clock.h b/src/common/steady_clock.h
index 9497cf865..dbd0e2513 100644
--- a/src/common/steady_clock.h
+++ b/src/common/steady_clock.h
@@ -20,4 +20,15 @@ struct SteadyClock {
[[nodiscard]] static time_point Now() noexcept;
};
+struct RealTimeClock {
+ using rep = s64;
+ using period = std::nano;
+ using duration = std::chrono::nanoseconds;
+ using time_point = std::chrono::time_point<RealTimeClock>;
+
+ static constexpr bool is_steady = false;
+
+ [[nodiscard]] static time_point Now() noexcept;
+};
+
} // namespace Common
diff --git a/src/common/x64/native_clock.cpp b/src/common/x64/native_clock.cpp
index bc1a973b0..76c66e7ee 100644
--- a/src/common/x64/native_clock.cpp
+++ b/src/common/x64/native_clock.cpp
@@ -53,11 +53,11 @@ u64 EstimateRDTSCFrequency() {
FencedRDTSC();
// Get the current time.
- const auto start_time = Common::SteadyClock::Now();
+ const auto start_time = Common::RealTimeClock::Now();
const u64 tsc_start = FencedRDTSC();
// Wait for 250 milliseconds.
std::this_thread::sleep_for(std::chrono::milliseconds{250});
- const auto end_time = Common::SteadyClock::Now();
+ const auto end_time = Common::RealTimeClock::Now();
const u64 tsc_end = FencedRDTSC();
// Calculate differences.
const u64 timer_diff = static_cast<u64>(
@@ -72,13 +72,29 @@ NativeClock::NativeClock(u64 emulated_cpu_frequency_, u64 emulated_clock_frequen
u64 rtsc_frequency_)
: WallClock(emulated_cpu_frequency_, emulated_clock_frequency_, true), rtsc_frequency{
rtsc_frequency_} {
+ // Thread to re-adjust the RDTSC frequency after 10 seconds has elapsed.
+ time_sync_thread = std::jthread{[this](std::stop_token token) {
+ // Get the current time.
+ const auto start_time = Common::RealTimeClock::Now();
+ const u64 tsc_start = FencedRDTSC();
+ // Wait for 10 seconds.
+ if (!Common::StoppableTimedWait(token, std::chrono::seconds{10})) {
+ return;
+ }
+ const auto end_time = Common::RealTimeClock::Now();
+ const u64 tsc_end = FencedRDTSC();
+ // Calculate differences.
+ const u64 timer_diff = static_cast<u64>(
+ std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time).count());
+ const u64 tsc_diff = tsc_end - tsc_start;
+ const u64 tsc_freq = MultiplyAndDivide64(tsc_diff, 1000000000ULL, timer_diff);
+ rtsc_frequency = tsc_freq;
+ CalculateAndSetFactors();
+ }};
+
time_point.inner.last_measure = FencedRDTSC();
time_point.inner.accumulated_ticks = 0U;
- ns_rtsc_factor = GetFixedPoint64Factor(NS_RATIO, rtsc_frequency);
- us_rtsc_factor = GetFixedPoint64Factor(US_RATIO, rtsc_frequency);
- ms_rtsc_factor = GetFixedPoint64Factor(MS_RATIO, rtsc_frequency);
- clock_rtsc_factor = GetFixedPoint64Factor(emulated_clock_frequency, rtsc_frequency);
- cpu_rtsc_factor = GetFixedPoint64Factor(emulated_cpu_frequency, rtsc_frequency);
+ CalculateAndSetFactors();
}
u64 NativeClock::GetRTSC() {
@@ -138,6 +154,14 @@ u64 NativeClock::GetCPUCycles() {
return MultiplyHigh(rtsc_value, cpu_rtsc_factor);
}
+void NativeClock::CalculateAndSetFactors() {
+ ns_rtsc_factor = GetFixedPoint64Factor(NS_RATIO, rtsc_frequency);
+ us_rtsc_factor = GetFixedPoint64Factor(US_RATIO, rtsc_frequency);
+ ms_rtsc_factor = GetFixedPoint64Factor(MS_RATIO, rtsc_frequency);
+ clock_rtsc_factor = GetFixedPoint64Factor(emulated_clock_frequency, rtsc_frequency);
+ cpu_rtsc_factor = GetFixedPoint64Factor(emulated_cpu_frequency, rtsc_frequency);
+}
+
} // namespace X64
} // namespace Common
diff --git a/src/common/x64/native_clock.h b/src/common/x64/native_clock.h
index 38ae7a462..03ca291d8 100644
--- a/src/common/x64/native_clock.h
+++ b/src/common/x64/native_clock.h
@@ -3,6 +3,7 @@
#pragma once
+#include "common/polyfill_thread.h"
#include "common/wall_clock.h"
namespace Common {
@@ -28,6 +29,8 @@ public:
private:
u64 GetRTSC();
+ void CalculateAndSetFactors();
+
union alignas(16) TimePoint {
TimePoint() : pack{} {}
u128 pack{};
@@ -47,6 +50,8 @@ private:
u64 ms_rtsc_factor{};
u64 rtsc_frequency;
+
+ std::jthread time_sync_thread;
};
} // namespace X64
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp
index 742cfb996..cd4df4522 100644
--- a/src/core/core_timing.cpp
+++ b/src/core/core_timing.cpp
@@ -53,7 +53,7 @@ void CoreTiming::ThreadEntry(CoreTiming& instance) {
static constexpr char name[] = "HostTiming";
MicroProfileOnThreadCreate(name);
Common::SetCurrentThreadName(name);
- Common::SetCurrentThreadPriority(Common::ThreadPriority::Critical);
+ Common::SetCurrentThreadPriority(Common::ThreadPriority::High);
instance.on_thread_init();
instance.ThreadLoop();
MicroProfileOnThreadExit();
diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp
index 04a11f444..980bb97f9 100644
--- a/src/core/cpu_manager.cpp
+++ b/src/core/cpu_manager.cpp
@@ -192,7 +192,7 @@ void CpuManager::RunThread(std::stop_token token, std::size_t core) {
}
MicroProfileOnThreadCreate(name.c_str());
Common::SetCurrentThreadName(name.c_str());
- Common::SetCurrentThreadPriority(Common::ThreadPriority::High);
+ Common::SetCurrentThreadPriority(Common::ThreadPriority::Critical);
auto& data = core_data[core];
data.host_context = Common::Fiber::ThreadToFiber();
diff --git a/src/core/hle/kernel/k_thread.cpp b/src/core/hle/kernel/k_thread.cpp
index 8c403f5fd..15ae652f9 100644
--- a/src/core/hle/kernel/k_thread.cpp
+++ b/src/core/hle/kernel/k_thread.cpp
@@ -49,6 +49,7 @@ static void ResetThreadContext32(Core::ARM_Interface::ThreadContext32& context,
context.cpu_registers[0] = arg;
context.cpu_registers[15] = entry_point;
context.cpu_registers[13] = stack_top;
+ context.fpscr = 0;
}
static void ResetThreadContext64(Core::ARM_Interface::ThreadContext64& context, VAddr stack_top,
@@ -58,8 +59,8 @@ static void ResetThreadContext64(Core::ARM_Interface::ThreadContext64& context,
context.cpu_registers[18] = Kernel::KSystemControl::GenerateRandomU64() | 1;
context.pc = entry_point;
context.sp = stack_top;
- // TODO(merry): Perform a hardware test to determine the below value.
context.fpcr = 0;
+ context.fpsr = 0;
}
} // namespace
@@ -815,6 +816,27 @@ void KThread::Continue() {
KScheduler::OnThreadStateChanged(kernel, this, old_state);
}
+void KThread::CloneFpuStatus() {
+ // We shouldn't reach here when starting kernel threads.
+ ASSERT(this->GetOwnerProcess() != nullptr);
+ ASSERT(this->GetOwnerProcess() == GetCurrentProcessPointer(kernel));
+
+ if (this->GetOwnerProcess()->Is64BitProcess()) {
+ // Clone FPSR and FPCR.
+ ThreadContext64 cur_ctx{};
+ kernel.System().CurrentArmInterface().SaveContext(cur_ctx);
+
+ this->GetContext64().fpcr = cur_ctx.fpcr;
+ this->GetContext64().fpsr = cur_ctx.fpsr;
+ } else {
+ // Clone FPSCR.
+ ThreadContext32 cur_ctx{};
+ kernel.System().CurrentArmInterface().SaveContext(cur_ctx);
+
+ this->GetContext32().fpscr = cur_ctx.fpscr;
+ }
+}
+
Result KThread::SetActivity(Svc::ThreadActivity activity) {
// Lock ourselves.
KScopedLightLock lk(activity_pause_lock);
diff --git a/src/core/hle/kernel/k_thread.h b/src/core/hle/kernel/k_thread.h
index bd125f5f1..9423f08ca 100644
--- a/src/core/hle/kernel/k_thread.h
+++ b/src/core/hle/kernel/k_thread.h
@@ -254,6 +254,8 @@ public:
thread_context_32.tpidr = static_cast<u32>(value);
}
+ void CloneFpuStatus();
+
[[nodiscard]] ThreadContext32& GetContext32() {
return thread_context_32;
}
diff --git a/src/core/hle/kernel/svc/svc_thread.cpp b/src/core/hle/kernel/svc/svc_thread.cpp
index b39807841..9bc1ebe74 100644
--- a/src/core/hle/kernel/svc/svc_thread.cpp
+++ b/src/core/hle/kernel/svc/svc_thread.cpp
@@ -82,6 +82,9 @@ Result CreateThread(Core::System& system, Handle* out_handle, VAddr entry_point,
// Commit the thread reservation.
thread_reservation.Commit();
+ // Clone the current fpu status to the new thread.
+ thread->CloneFpuStatus();
+
// Register the new thread.
KThread::Register(kernel, thread);
diff --git a/src/core/hle/service/hid/controllers/stubbed.cpp b/src/core/hle/service/hid/controllers/stubbed.cpp
index df9ee0c3f..9e2f3ab21 100644
--- a/src/core/hle/service/hid/controllers/stubbed.cpp
+++ b/src/core/hle/service/hid/controllers/stubbed.cpp
@@ -26,7 +26,7 @@ void Controller_Stubbed::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
}
CommonHeader header{};
- header.timestamp = core_timing.GetCPUTicks();
+ header.timestamp = core_timing.GetGlobalTimeNs().count();
header.total_entry_count = 17;
header.entry_count = 0;
header.last_entry_index = 0;
diff --git a/src/core/hle/service/hid/controllers/touchscreen.cpp b/src/core/hle/service/hid/controllers/touchscreen.cpp
index d90a4e732..3ef91df4b 100644
--- a/src/core/hle/service/hid/controllers/touchscreen.cpp
+++ b/src/core/hle/service/hid/controllers/touchscreen.cpp
@@ -32,7 +32,7 @@ void Controller_Touchscreen::OnInit() {}
void Controller_Touchscreen::OnRelease() {}
void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
- shared_memory->touch_screen_lifo.timestamp = core_timing.GetCPUTicks();
+ shared_memory->touch_screen_lifo.timestamp = core_timing.GetGlobalTimeNs().count();
if (!IsControllerActivated()) {
shared_memory->touch_screen_lifo.buffer_count = 0;
@@ -85,7 +85,7 @@ void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timin
const auto active_fingers_count =
static_cast<std::size_t>(std::distance(active_fingers.begin(), end_iter));
- const u64 tick = core_timing.GetCPUTicks();
+ const u64 timestamp = static_cast<u64>(core_timing.GetGlobalTimeNs().count());
const auto& last_entry = shared_memory->touch_screen_lifo.ReadCurrentEntry().state;
next_state.sampling_number = last_entry.sampling_number + 1;
@@ -102,8 +102,8 @@ void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timin
touch_entry.diameter_x = Settings::values.touchscreen.diameter_x;
touch_entry.diameter_y = Settings::values.touchscreen.diameter_y;
touch_entry.rotation_angle = Settings::values.touchscreen.rotation_angle;
- touch_entry.delta_time = tick - active_fingers[id].last_touch;
- fingers[active_fingers[id].id].last_touch = tick;
+ touch_entry.delta_time = timestamp - active_fingers[id].last_touch;
+ fingers[active_fingers[id].id].last_touch = timestamp;
touch_entry.finger = active_fingers[id].id;
touch_entry.attribute.raw = active_fingers[id].attribute.raw;
} else {
diff --git a/src/core/perf_stats.cpp b/src/core/perf_stats.cpp
index f09c176f8..1231c0dc8 100644
--- a/src/core/perf_stats.cpp
+++ b/src/core/perf_stats.cpp
@@ -126,8 +126,8 @@ double PerfStats::GetLastFrameTimeScale() const {
}
void SpeedLimiter::DoSpeedLimiting(microseconds current_system_time_us) {
- if (!Settings::values.use_speed_limit.GetValue() ||
- Settings::values.use_multi_core.GetValue()) {
+ if (Settings::values.use_multi_core.GetValue() ||
+ !Settings::values.use_speed_limit.GetValue()) {
return;
}
diff --git a/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp b/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp
index 336338e62..d1e59f22e 100644
--- a/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp
+++ b/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp
@@ -35,6 +35,7 @@ struct Bias {
u32 index;
u32 offset_begin;
u32 offset_end;
+ u32 alignment;
};
using boost::container::flat_set;
@@ -349,7 +350,8 @@ std::optional<StorageBufferAddr> Track(const IR::Value& value, const Bias* bias)
.index = index.U32(),
.offset = offset.U32(),
};
- if (!Common::IsAligned(storage_buffer.offset, 16)) {
+ const u32 alignment{bias ? bias->alignment : 8U};
+ if (!Common::IsAligned(storage_buffer.offset, alignment)) {
// The SSBO pointer has to be aligned
return std::nullopt;
}
@@ -371,6 +373,7 @@ void CollectStorageBuffers(IR::Block& block, IR::Inst& inst, StorageInfo& info)
.index = 0,
.offset_begin = 0x110,
.offset_end = 0x610,
+ .alignment = 16,
};
// Track the low address of the instruction
const std::optional<LowAddrInfo> low_addr_info{TrackLowAddress(&inst)};
@@ -386,8 +389,11 @@ void CollectStorageBuffers(IR::Block& block, IR::Inst& inst, StorageInfo& info)
storage_buffer = Track(low_addr, nullptr);
if (!storage_buffer) {
// If that also fails, use NVN fallbacks
+ LOG_WARNING(Shader, "Storage buffer failed to track, using global memory fallbacks");
return;
}
+ LOG_WARNING(Shader, "Storage buffer tracked without bias, index {} offset {}",
+ storage_buffer->index, storage_buffer->offset);
}
// Collect storage buffer and the instruction
if (IsGlobalMemoryWrite(inst)) {
diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h
index 2a150ccdc..1f656ffa8 100644
--- a/src/video_core/buffer_cache/buffer_cache.h
+++ b/src/video_core/buffer_cache/buffer_cache.h
@@ -383,7 +383,8 @@ private:
void NotifyBufferDeletion();
- [[nodiscard]] Binding StorageBufferBinding(GPUVAddr ssbo_addr, bool is_written = false) const;
+ [[nodiscard]] Binding StorageBufferBinding(GPUVAddr ssbo_addr, u32 cbuf_index,
+ bool is_written = false) const;
[[nodiscard]] TextureBufferBinding GetTextureBufferBinding(GPUVAddr gpu_addr, u32 size,
PixelFormat format);
@@ -802,7 +803,7 @@ void BufferCache<P>::BindGraphicsStorageBuffer(size_t stage, size_t ssbo_index,
const auto& cbufs = maxwell3d->state.shader_stages[stage];
const GPUVAddr ssbo_addr = cbufs.const_buffers[cbuf_index].address + cbuf_offset;
- storage_buffers[stage][ssbo_index] = StorageBufferBinding(ssbo_addr, is_written);
+ storage_buffers[stage][ssbo_index] = StorageBufferBinding(ssbo_addr, cbuf_index, is_written);
}
template <class P>
@@ -842,7 +843,7 @@ void BufferCache<P>::BindComputeStorageBuffer(size_t ssbo_index, u32 cbuf_index,
const auto& cbufs = launch_desc.const_buffer_config;
const GPUVAddr ssbo_addr = cbufs[cbuf_index].Address() + cbuf_offset;
- compute_storage_buffers[ssbo_index] = StorageBufferBinding(ssbo_addr, is_written);
+ compute_storage_buffers[ssbo_index] = StorageBufferBinding(ssbo_addr, cbuf_index, is_written);
}
template <class P>
@@ -1988,11 +1989,26 @@ void BufferCache<P>::NotifyBufferDeletion() {
template <class P>
typename BufferCache<P>::Binding BufferCache<P>::StorageBufferBinding(GPUVAddr ssbo_addr,
+ u32 cbuf_index,
bool is_written) const {
const GPUVAddr gpu_addr = gpu_memory->Read<u64>(ssbo_addr);
- const u32 size = gpu_memory->Read<u32>(ssbo_addr + 8);
+ const auto size = [&]() {
+ const bool is_nvn_cbuf = cbuf_index == 0;
+ // The NVN driver buffer (index 0) is known to pack the SSBO address followed by its size.
+ if (is_nvn_cbuf) {
+ return gpu_memory->Read<u32>(ssbo_addr + 8);
+ }
+ // Other titles (notably Doom Eternal) may use STG/LDG on buffer addresses in custom defined
+ // cbufs, which do not store the sizes adjacent to the addresses, so use the fully
+ // mapped buffer size for now.
+ const u32 memory_layout_size = static_cast<u32>(gpu_memory->GetMemoryLayoutSize(gpu_addr));
+ LOG_INFO(HW_GPU, "Binding storage buffer for cbuf index {}, MemoryLayoutSize 0x{:X}",
+ cbuf_index, memory_layout_size);
+ return memory_layout_size;
+ }();
const std::optional<VAddr> cpu_addr = gpu_memory->GpuToCpuAddress(gpu_addr);
if (!cpu_addr || size == 0) {
+ LOG_WARNING(HW_GPU, "Failed to find storage buffer for cbuf index {}", cbuf_index);
return NULL_BINDING;
}
const VAddr cpu_end = Common::AlignUp(*cpu_addr + size, Core::Memory::YUZU_PAGESIZE);
diff --git a/src/video_core/gpu_thread.cpp b/src/video_core/gpu_thread.cpp
index 9c103c0d4..050b11874 100644
--- a/src/video_core/gpu_thread.cpp
+++ b/src/video_core/gpu_thread.cpp
@@ -25,7 +25,7 @@ static void RunThread(std::stop_token stop_token, Core::System& system,
SCOPE_EXIT({ MicroProfileOnThreadExit(); });
Common::SetCurrentThreadName(name.c_str());
- Common::SetCurrentThreadPriority(Common::ThreadPriority::High);
+ Common::SetCurrentThreadPriority(Common::ThreadPriority::Critical);
system.RegisterHostThread();
auto current_context = context.Acquire();
diff --git a/src/video_core/renderer_opengl/gl_fence_manager.cpp b/src/video_core/renderer_opengl/gl_fence_manager.cpp
index 91463f854..5326172af 100644
--- a/src/video_core/renderer_opengl/gl_fence_manager.cpp
+++ b/src/video_core/renderer_opengl/gl_fence_manager.cpp
@@ -27,9 +27,7 @@ bool GLInnerFence::IsSignaled() const {
return true;
}
ASSERT(sync_object.handle != 0);
- GLint sync_status;
- glGetSynciv(sync_object.handle, GL_SYNC_STATUS, 1, nullptr, &sync_status);
- return sync_status == GL_SIGNALED;
+ return sync_object.IsSignaled();
}
void GLInnerFence::Wait() {
diff --git a/src/video_core/renderer_opengl/gl_graphics_pipeline.cpp b/src/video_core/renderer_opengl/gl_graphics_pipeline.cpp
index 29491e762..89000d6e0 100644
--- a/src/video_core/renderer_opengl/gl_graphics_pipeline.cpp
+++ b/src/video_core/renderer_opengl/gl_graphics_pipeline.cpp
@@ -621,10 +621,7 @@ bool GraphicsPipeline::IsBuilt() noexcept {
if (built_fence.handle == 0) {
return false;
}
- // Timeout of zero means this is non-blocking
- const auto sync_status = glClientWaitSync(built_fence.handle, 0, 0);
- ASSERT(sync_status != GL_WAIT_FAILED);
- is_built = sync_status != GL_TIMEOUT_EXPIRED;
+ is_built = built_fence.IsSignaled();
return is_built;
}
diff --git a/src/video_core/renderer_opengl/gl_resource_manager.cpp b/src/video_core/renderer_opengl/gl_resource_manager.cpp
index 3a664fdec..eae8fd110 100644
--- a/src/video_core/renderer_opengl/gl_resource_manager.cpp
+++ b/src/video_core/renderer_opengl/gl_resource_manager.cpp
@@ -3,6 +3,7 @@
#include <string_view>
#include <glad/glad.h>
+#include "common/assert.h"
#include "common/microprofile.h"
#include "video_core/renderer_opengl/gl_resource_manager.h"
#include "video_core/renderer_opengl/gl_shader_util.h"
@@ -158,6 +159,15 @@ void OGLSync::Release() {
handle = 0;
}
+bool OGLSync::IsSignaled() const noexcept {
+ // At least on Nvidia, glClientWaitSync with a timeout of 0
+ // is faster than glGetSynciv of GL_SYNC_STATUS.
+ // Timeout of 0 means this check is non-blocking.
+ const auto sync_status = glClientWaitSync(handle, 0, 0);
+ ASSERT(sync_status != GL_WAIT_FAILED);
+ return sync_status != GL_TIMEOUT_EXPIRED;
+}
+
void OGLFramebuffer::Create() {
if (handle != 0)
return;
diff --git a/src/video_core/renderer_opengl/gl_resource_manager.h b/src/video_core/renderer_opengl/gl_resource_manager.h
index bc05ba4bd..77362acd2 100644
--- a/src/video_core/renderer_opengl/gl_resource_manager.h
+++ b/src/video_core/renderer_opengl/gl_resource_manager.h
@@ -263,6 +263,9 @@ public:
/// Deletes the internal OpenGL resource
void Release();
+ /// Checks if the sync has been signaled
+ bool IsSignaled() const noexcept;
+
GLsync handle = 0;
};
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp
index d3eabd686..9b99125e5 100644
--- a/src/video_core/renderer_opengl/gl_texture_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp
@@ -717,9 +717,7 @@ std::optional<size_t> TextureCacheRuntime::StagingBuffers::FindBuffer(size_t req
continue;
}
if (syncs[index].handle != 0) {
- GLint status;
- glGetSynciv(syncs[index].handle, GL_SYNC_STATUS, 1, nullptr, &status);
- if (status != GL_SIGNALED) {
+ if (!syncs[index].IsSignaled()) {
continue;
}
syncs[index].Release();