summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_opengl/gl_query_cache.h
diff options
context:
space:
mode:
authorReinUsesLisp <reinuseslisp@airmail.cc>2019-11-28 06:15:34 +0100
committerReinUsesLisp <reinuseslisp@airmail.cc>2020-02-14 21:38:27 +0100
commit73d2d3342dc8867d32f08f89b2ca36ff071598dc (patch)
tree3a032d4a36d0f07981eeb8b396472670bfd11e5a /src/video_core/renderer_opengl/gl_query_cache.h
parentgl_query_cache: Implement host queries using a deferred cache (diff)
downloadyuzu-73d2d3342dc8867d32f08f89b2ca36ff071598dc.tar
yuzu-73d2d3342dc8867d32f08f89b2ca36ff071598dc.tar.gz
yuzu-73d2d3342dc8867d32f08f89b2ca36ff071598dc.tar.bz2
yuzu-73d2d3342dc8867d32f08f89b2ca36ff071598dc.tar.lz
yuzu-73d2d3342dc8867d32f08f89b2ca36ff071598dc.tar.xz
yuzu-73d2d3342dc8867d32f08f89b2ca36ff071598dc.tar.zst
yuzu-73d2d3342dc8867d32f08f89b2ca36ff071598dc.zip
Diffstat (limited to 'src/video_core/renderer_opengl/gl_query_cache.h')
-rw-r--r--src/video_core/renderer_opengl/gl_query_cache.h61
1 files changed, 42 insertions, 19 deletions
diff --git a/src/video_core/renderer_opengl/gl_query_cache.h b/src/video_core/renderer_opengl/gl_query_cache.h
index 91594b120..d9f22b44d 100644
--- a/src/video_core/renderer_opengl/gl_query_cache.h
+++ b/src/video_core/renderer_opengl/gl_query_cache.h
@@ -7,12 +7,12 @@
#include <array>
#include <memory>
#include <optional>
+#include <unordered_map>
#include <vector>
#include <glad/glad.h>
#include "common/common_types.h"
-#include "video_core/rasterizer_cache.h"
#include "video_core/rasterizer_interface.h"
#include "video_core/renderer_opengl/gl_resource_manager.h"
@@ -43,6 +43,10 @@ public:
}
private:
+ void Enable();
+
+ void Disable(bool any_command_queued);
+
void EndQuery(bool any_command_queued);
QueryCache& cache;
@@ -53,12 +57,16 @@ private:
GLenum target;
};
-class QueryCache final : public RasterizerCache<std::shared_ptr<CachedQuery>> {
+class QueryCache final {
public:
explicit QueryCache(Core::System& system, RasterizerOpenGL& rasterizer);
~QueryCache();
- void Query(GPUVAddr gpu_addr, VideoCore::QueryType type);
+ void InvalidateRegion(CacheAddr addr, std::size_t size);
+
+ void FlushRegion(CacheAddr addr, std::size_t size);
+
+ void Query(GPUVAddr gpu_addr, VideoCore::QueryType type, std::optional<u64> timestamp);
void UpdateCounters();
@@ -69,15 +77,20 @@ public:
std::shared_ptr<HostCounter> GetHostCounter(std::shared_ptr<HostCounter> dependency,
VideoCore::QueryType type);
-protected:
- void FlushObjectInner(const std::shared_ptr<CachedQuery>& counter) override;
-
private:
+ CachedQuery& Register(CachedQuery&& cached_query);
+
+ CachedQuery* TryGet(CacheAddr addr);
+
+ void Flush(CachedQuery& cached_query);
+
CounterStream& GetStream(VideoCore::QueryType type);
Core::System& system;
RasterizerOpenGL& rasterizer;
+ std::unordered_map<u64, std::vector<CachedQuery>> cached_queries;
+
std::array<CounterStream, VideoCore::NumQueryTypes> streams;
std::array<std::vector<OGLQuery>, VideoCore::NumQueryTypes> reserved_queries;
};
@@ -85,50 +98,60 @@ private:
class HostCounter final {
public:
explicit HostCounter(QueryCache& cache, std::shared_ptr<HostCounter> dependency,
- VideoCore::QueryType type);
- explicit HostCounter(QueryCache& cache, std::shared_ptr<HostCounter> dependency,
VideoCore::QueryType type, OGLQuery&& query);
~HostCounter();
/// Returns the current value of the query.
u64 Query();
+ /// Returns true when querying this counter will potentially wait for OpenGL.
+ bool WaitPending() const noexcept;
+
private:
QueryCache& cache;
VideoCore::QueryType type;
std::shared_ptr<HostCounter> dependency; ///< Counter queued before this one.
OGLQuery query; ///< OpenGL query.
- u64 result; ///< Added values of the counter.
+ std::optional<u64> result; ///< Added values of the counter.
};
-class CachedQuery final : public RasterizerCacheObject {
+class CachedQuery final {
public:
explicit CachedQuery(VideoCore::QueryType type, VAddr cpu_addr, u8* host_ptr);
+ CachedQuery(CachedQuery&&) noexcept;
+ CachedQuery(const CachedQuery&) = delete;
~CachedQuery();
+ CachedQuery& operator=(CachedQuery&&) noexcept;
+
/// Writes the counter value to host memory.
void Flush();
/// Updates the counter this cached query registered in guest memory will write when requested.
- void SetCounter(std::shared_ptr<HostCounter> counter);
+ void SetCounter(std::shared_ptr<HostCounter> counter, std::optional<u64> timestamp);
+
+ /// Returns true when a flushing this query will potentially wait for OpenGL.
+ bool WaitPending() const noexcept;
/// Returns the query type.
- VideoCore::QueryType GetType() const;
+ VideoCore::QueryType GetType() const noexcept;
- VAddr GetCpuAddr() const override {
- return cpu_addr;
- }
+ /// Returns the guest CPU address for this query.
+ VAddr GetCpuAddr() const noexcept;
- std::size_t GetSizeInBytes() const override {
- return sizeof(u64);
- }
+ /// Returns the cache address for this query.
+ CacheAddr GetCacheAddr() const noexcept;
+
+ /// Returns the number of cached bytes.
+ u64 GetSizeInBytes() const noexcept;
private:
- VideoCore::QueryType type;
+ VideoCore::QueryType type; ///< Abstracted query type (e.g. samples passed).
VAddr cpu_addr; ///< Guest CPU address.
u8* host_ptr; ///< Writable host pointer.
std::shared_ptr<HostCounter> counter; ///< Host counter to query, owns the dependency tree.
+ std::optional<u64> timestamp; ///< Timestamp to flush to guest memory.
};
} // namespace OpenGL