From 862bec001b7ada13ba0e97f95d6ad108ae8a8d0c Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Fri, 19 Jul 2019 10:50:40 -0400 Subject: Video_Core: Implement a new Buffer Cache --- src/video_core/buffer_cache/buffer_block.h | 78 ++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/video_core/buffer_cache/buffer_block.h (limited to 'src/video_core/buffer_cache/buffer_block.h') diff --git a/src/video_core/buffer_cache/buffer_block.h b/src/video_core/buffer_cache/buffer_block.h new file mode 100644 index 000000000..2c739a586 --- /dev/null +++ b/src/video_core/buffer_cache/buffer_block.h @@ -0,0 +1,78 @@ +// Copyright 2019 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include + +#include "common/alignment.h" +#include "common/common_types.h" +#include "video_core/gpu.h" + +namespace VideoCommon { + +class BufferBlock { +public: + bool Overlaps(const CacheAddr start, const CacheAddr end) const { + return (cache_addr < end) && (cache_addr_end > start); + } + + bool IsInside(const CacheAddr other_start, const CacheAddr other_end) { + return (cache_addr <= other_start && other_end <= cache_addr_end); + } + + u8* GetWritableHostPtr() const { + return FromCacheAddr(cache_addr); + } + + u8* GetWritableHostPtr(std::size_t offset) const { + return FromCacheAddr(cache_addr + offset); + } + + std::size_t GetOffset(const CacheAddr in_addr) { + return static_cast(in_addr - cache_addr); + } + + CacheAddr GetCacheAddr() const { + return cache_addr; + } + + CacheAddr GetCacheAddrEnd() const { + return cache_addr_end; + } + + void SetCacheAddr(const CacheAddr new_addr) { + cache_addr = new_addr; + cache_addr_end = new_addr + size; + } + + std::size_t GetSize() const { + return size; + } + + void SetEpoch(u64 new_epoch) { + epoch = new_epoch; + } + + u64 GetEpoch() { + return epoch; + } + +protected: + explicit BufferBlock(CacheAddr cache_addr,const std::size_t size) + : size{size} { + SetCacheAddr(cache_addr); + } + ~BufferBlock() = default; + +private: + CacheAddr cache_addr{}; + CacheAddr cache_addr_end{}; + u64 pages{}; + std::size_t size{}; + u64 epoch{}; +}; + +} // namespace VideoCommon -- cgit v1.2.3