summaryrefslogtreecommitdiff
path: root/src/video_core/query_cache.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core/query_cache.h')
-rw-r--r--src/video_core/query_cache.h39
1 files changed, 26 insertions, 13 deletions
diff --git a/src/video_core/query_cache.h b/src/video_core/query_cache.h
index 2a14cc36a..9c6f57817 100644
--- a/src/video_core/query_cache.h
+++ b/src/video_core/query_cache.h
@@ -6,6 +6,7 @@
6#include <algorithm> 6#include <algorithm>
7#include <array> 7#include <array>
8#include <cstring> 8#include <cstring>
9#include <functional>
9#include <iterator> 10#include <iterator>
10#include <list> 11#include <list>
11#include <memory> 12#include <memory>
@@ -101,10 +102,10 @@ class QueryCacheBase : public VideoCommon::ChannelSetupCaches<VideoCommon::Chann
101public: 102public:
102 explicit QueryCacheBase(VideoCore::RasterizerInterface& rasterizer_, 103 explicit QueryCacheBase(VideoCore::RasterizerInterface& rasterizer_,
103 Core::Memory::Memory& cpu_memory_) 104 Core::Memory::Memory& cpu_memory_)
104 : rasterizer{rasterizer_}, cpu_memory{cpu_memory_}, streams{ 105 : rasterizer{rasterizer_},
105 {CounterStream{static_cast<QueryCache&>(*this), 106 cpu_memory{cpu_memory_}, streams{{CounterStream{static_cast<QueryCache&>(*this),
106 VideoCore::QueryType::SamplesPassed}}} { 107 VideoCore::QueryType::SamplesPassed}}} {
107 (void) slot_async_jobs.insert(); // Null value 108 (void)slot_async_jobs.insert(); // Null value
108 } 109 }
109 110
110 void InvalidateRegion(VAddr addr, std::size_t size) { 111 void InvalidateRegion(VAddr addr, std::size_t size) {
@@ -136,7 +137,7 @@ public:
136 query = Register(type, *cpu_addr, host_ptr, timestamp.has_value()); 137 query = Register(type, *cpu_addr, host_ptr, timestamp.has_value());
137 } 138 }
138 139
139 auto result = query->BindCounter(Stream(type).Current()); 140 auto result = query->BindCounter(Stream(type).Current(), timestamp);
140 if (result) { 141 if (result) {
141 auto async_job_id = query->GetAsyncJob(); 142 auto async_job_id = query->GetAsyncJob();
142 auto& async_job = slot_async_jobs[async_job_id]; 143 auto& async_job = slot_async_jobs[async_job_id];
@@ -294,15 +295,17 @@ private:
294 void AsyncFlushQuery(CachedQuery* query, std::optional<u64> timestamp, 295 void AsyncFlushQuery(CachedQuery* query, std::optional<u64> timestamp,
295 std::unique_lock<std::recursive_mutex>& lock) { 296 std::unique_lock<std::recursive_mutex>& lock) {
296 const AsyncJobId new_async_job_id = slot_async_jobs.insert(); 297 const AsyncJobId new_async_job_id = slot_async_jobs.insert();
297 AsyncJob& async_job = slot_async_jobs[new_async_job_id]; 298 {
298 query->SetAsyncJob(new_async_job_id); 299 AsyncJob& async_job = slot_async_jobs[new_async_job_id];
299 async_job.query_location = query->GetCpuAddr(); 300 query->SetAsyncJob(new_async_job_id);
300 async_job.collected = false; 301 async_job.query_location = query->GetCpuAddr();
302 async_job.collected = false;
301 303
302 if (!uncommitted_flushes) { 304 if (!uncommitted_flushes) {
303 uncommitted_flushes = std::make_shared<std::vector<AsyncJobId>>(); 305 uncommitted_flushes = std::make_shared<std::vector<AsyncJobId>>();
306 }
307 uncommitted_flushes->push_back(new_async_job_id);
304 } 308 }
305 uncommitted_flushes->push_back(new_async_job_id);
306 lock.unlock(); 309 lock.unlock();
307 std::function<void()> operation([this, new_async_job_id, timestamp] { 310 std::function<void()> operation([this, new_async_job_id, timestamp] {
308 std::unique_lock local_lock{mutex}; 311 std::unique_lock local_lock{mutex};
@@ -408,11 +411,20 @@ public:
408 // When counter is nullptr it means that it's just been reset. We are supposed to write a 411 // When counter is nullptr it means that it's just been reset. We are supposed to write a
409 // zero in these cases. 412 // zero in these cases.
410 const u64 value = counter ? counter->Query(async) : 0; 413 const u64 value = counter ? counter->Query(async) : 0;
414 if (async) {
415 return value;
416 }
417 std::memcpy(host_ptr, &value, sizeof(u64));
418
419 if (timestamp) {
420 std::memcpy(host_ptr + TIMESTAMP_OFFSET, &*timestamp, sizeof(u64));
421 }
411 return value; 422 return value;
412 } 423 }
413 424
414 /// Binds a counter to this query. 425 /// Binds a counter to this query.
415 std::optional<u64> BindCounter(std::shared_ptr<HostCounter> counter_) { 426 std::optional<u64> BindCounter(std::shared_ptr<HostCounter> counter_,
427 std::optional<u64> timestamp_) {
416 std::optional<u64> result{}; 428 std::optional<u64> result{};
417 if (counter) { 429 if (counter) {
418 // If there's an old counter set it means the query is being rewritten by the game. 430 // If there's an old counter set it means the query is being rewritten by the game.
@@ -420,6 +432,7 @@ public:
420 result = std::make_optional(Flush()); 432 result = std::make_optional(Flush());
421 } 433 }
422 counter = std::move(counter_); 434 counter = std::move(counter_);
435 timestamp = timestamp_;
423 return result; 436 return result;
424 } 437 }
425 438