diff options
| author | ReinUsesLisp <reinuseslisp@airmail.cc> | 2020-05-21 01:06:40 -0300 |
|---|---|---|
| committer | ReinUsesLisp <reinuseslisp@airmail.cc> | 2020-05-21 16:44:00 -0300 |
| commit | a2dcc642c1737721bafe54605c7826fa08d18f47 (patch) | |
| tree | 655b96d46815d93259b12dccc8acad293437db41 /src/video_core/buffer_cache/map_interval.h | |
| parent | 19d4f28001d3a8e28b41187a7940d14d0a8d708c (diff) | |
map_interval: Add interval allocator and drop hack
Drop the std::list hack to allocate memory indefinitely.
Instead use a custom allocator that keeps references valid until
destruction. This allocates fixed chunks of memory and puts pointers in
a free list. When an allocation is no longer used put it back to the
free list, this doesn't heap allocate because std::vector doesn't change
the capacity. If the free list is empty, allocate a new chunk.
Diffstat (limited to 'src/video_core/buffer_cache/map_interval.h')
| -rw-r--r-- | src/video_core/buffer_cache/map_interval.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/video_core/buffer_cache/map_interval.h b/src/video_core/buffer_cache/map_interval.h index 45705cccf..fe0bcd1d8 100644 --- a/src/video_core/buffer_cache/map_interval.h +++ b/src/video_core/buffer_cache/map_interval.h @@ -4,6 +4,11 @@ #pragma once +#include <array> +#include <cstddef> +#include <memory> +#include <vector> + #include <boost/intrusive/set_hook.hpp> #include "common/common_types.h" @@ -12,6 +17,8 @@ namespace VideoCommon { struct MapInterval : public boost::intrusive::set_base_hook<boost::intrusive::optimize_size<true>> { + MapInterval() = default; + /*implicit*/ MapInterval(VAddr start_) noexcept : start{start_} {} explicit MapInterval(VAddr start_, VAddr end_, GPUVAddr gpu_addr_) noexcept @@ -48,4 +55,38 @@ struct MapIntervalCompare { } }; +class MapIntervalAllocator { +public: + MapIntervalAllocator(); + ~MapIntervalAllocator(); + + MapInterval* Allocate() { + if (free_list.empty()) { + AllocateNewChunk(); + } + MapInterval* const interval = free_list.back(); + free_list.pop_back(); + return interval; + } + + void Release(MapInterval* interval) { + free_list.push_back(interval); + } + +private: + struct Chunk { + std::unique_ptr<Chunk> next; + std::array<MapInterval, 0x8000> data; + }; + + void AllocateNewChunk(); + + void FillFreeList(Chunk& chunk); + + std::vector<MapInterval*> free_list; + std::unique_ptr<Chunk>* new_chunk = &first_chunk.next; + + Chunk first_chunk; +}; + } // namespace VideoCommon |
