diff options
Diffstat (limited to '')
-rw-r--r-- | src/video_core/renderer_opengl/gl_buffer_cache.h | 115 |
1 files changed, 14 insertions, 101 deletions
diff --git a/src/video_core/renderer_opengl/gl_buffer_cache.h b/src/video_core/renderer_opengl/gl_buffer_cache.h index 19d643e41..3befdc6ab 100644 --- a/src/video_core/renderer_opengl/gl_buffer_cache.h +++ b/src/video_core/renderer_opengl/gl_buffer_cache.h @@ -4,15 +4,10 @@ #pragma once -#include <cstddef> -#include <map> #include <memory> -#include <tuple> -#include <unordered_set> -#include <utility> -#include <vector> #include "common/common_types.h" +#include "video_core/buffer_cache.h" #include "video_core/rasterizer_cache.h" #include "video_core/renderer_opengl/gl_resource_manager.h" #include "video_core/renderer_opengl/gl_stream_buffer.h" @@ -23,112 +18,30 @@ class System; namespace OpenGL { +class OGLStreamBuffer; class RasterizerOpenGL; -class CachedBufferEntry final : public RasterizerCacheObject { +class OGLBufferCache final : public VideoCommon::BufferCache<OGLBuffer, GLuint, OGLStreamBuffer> { public: - explicit CachedBufferEntry(VAddr cpu_addr, u8* host_ptr); - - VAddr GetCpuAddr() const override { - return cpu_addr; - } - - std::size_t GetSizeInBytes() const override { - return size; - } - - u8* GetWritableHostPtr() const { - return host_ptr; - } - - std::size_t GetSize() const { - return size; - } - - std::size_t GetCapacity() const { - return capacity; - } - - bool IsInternalized() const { - return is_internal; - } - - GLuint GetBuffer() const { - return buffer.handle; - } - - void SetSize(std::size_t new_size) { - size = new_size; - } - - void SetInternalState(bool is_internal_) { - is_internal = is_internal_; - } - - void SetCapacity(OGLBuffer&& new_buffer, std::size_t new_capacity) { - capacity = new_capacity; - buffer = std::move(new_buffer); - } - -private: - u8* host_ptr{}; - VAddr cpu_addr{}; - std::size_t size{}; - std::size_t capacity{}; - bool is_internal{}; - OGLBuffer buffer; -}; - -class OGLBufferCache final : public RasterizerCache<std::shared_ptr<CachedBufferEntry>> { - using BufferInfo = std::pair<GLuint, GLintptr>; - -public: - explicit OGLBufferCache(RasterizerOpenGL& rasterizer, Core::System& system, std::size_t size); + explicit OGLBufferCache(RasterizerOpenGL& rasterizer, Core::System& system, + std::size_t stream_size); ~OGLBufferCache(); - void Unregister(const std::shared_ptr<CachedBufferEntry>& entry) override; - - /// Uploads data from a guest GPU address. Returns the OpenGL buffer where it's located and its - /// offset. - BufferInfo UploadMemory(GPUVAddr gpu_addr, std::size_t size, std::size_t alignment = 4, - bool internalize = false, bool is_written = false); - - /// Uploads from a host memory. Returns the OpenGL buffer where it's located and its offset. - BufferInfo UploadHostMemory(const void* raw_pointer, std::size_t size, - std::size_t alignment = 4); - - bool Map(std::size_t max_size); - void Unmap(); - protected: - // We do not have to flush this cache as things in it are never modified by us. - void FlushObjectInner(const std::shared_ptr<CachedBufferEntry>& entry) override; - -private: - BufferInfo StreamBufferUpload(const void* raw_pointer, std::size_t size, std::size_t alignment); - - BufferInfo FixedBufferUpload(GPUVAddr gpu_addr, u8* host_ptr, std::size_t size, - bool internalize, bool is_written); - - void GrowBuffer(std::shared_ptr<CachedBufferEntry>& entry, std::size_t new_size); - - std::shared_ptr<CachedBufferEntry> GetUncachedBuffer(VAddr cpu_addr, u8* host_ptr); - - std::shared_ptr<CachedBufferEntry> TryGetReservedBuffer(u8* host_ptr); + OGLBuffer CreateBuffer(std::size_t size) override; - void ReserveBuffer(std::shared_ptr<CachedBufferEntry> entry); + const GLuint* ToHandle(const OGLBuffer& buffer) override; - void AlignBuffer(std::size_t alignment); + const GLuint* GetEmptyBuffer(std::size_t) override; - Core::System& system; + void UploadBufferData(const OGLBuffer& buffer, std::size_t offset, std::size_t size, + const u8* data) override; - u8* buffer_ptr = nullptr; - GLintptr buffer_offset = 0; - GLintptr buffer_offset_base = 0; + void DownloadBufferData(const OGLBuffer& buffer, std::size_t offset, std::size_t size, + u8* data) override; - OGLStreamBuffer stream_buffer; - std::unordered_set<CacheAddr> internalized_entries; - std::unordered_map<CacheAddr, std::vector<std::shared_ptr<CachedBufferEntry>>> buffer_reserve; + void CopyBufferData(const OGLBuffer& src, const OGLBuffer& dst, std::size_t src_offset, + std::size_t dst_offset, std::size_t size) override; }; } // namespace OpenGL |