buffer_cache.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. // Copyright 2019 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <list>
  6. #include <memory>
  7. #include <mutex>
  8. #include <unordered_map>
  9. #include <unordered_set>
  10. #include <utility>
  11. #include <vector>
  12. #include <boost/container/small_vector.hpp>
  13. #include <boost/icl/interval_set.hpp>
  14. #include <boost/intrusive/set.hpp>
  15. #include "common/alignment.h"
  16. #include "common/assert.h"
  17. #include "common/common_types.h"
  18. #include "common/logging/log.h"
  19. #include "core/core.h"
  20. #include "core/memory.h"
  21. #include "core/settings.h"
  22. #include "video_core/buffer_cache/buffer_block.h"
  23. #include "video_core/buffer_cache/map_interval.h"
  24. #include "video_core/memory_manager.h"
  25. #include "video_core/rasterizer_interface.h"
  26. namespace VideoCommon {
  27. template <typename Buffer, typename BufferType, typename StreamBuffer>
  28. class BufferCache {
  29. using IntervalSet = boost::icl::interval_set<VAddr>;
  30. using IntervalType = typename IntervalSet::interval_type;
  31. using VectorMapInterval = boost::container::small_vector<MapInterval*, 1>;
  32. static constexpr u64 WRITE_PAGE_BIT = 11;
  33. static constexpr u64 BLOCK_PAGE_BITS = 21;
  34. static constexpr u64 BLOCK_PAGE_SIZE = 1ULL << BLOCK_PAGE_BITS;
  35. public:
  36. using BufferInfo = std::pair<BufferType, u64>;
  37. BufferInfo UploadMemory(GPUVAddr gpu_addr, std::size_t size, std::size_t alignment = 4,
  38. bool is_written = false, bool use_fast_cbuf = false) {
  39. std::lock_guard lock{mutex};
  40. const auto& memory_manager = system.GPU().MemoryManager();
  41. const std::optional<VAddr> cpu_addr_opt = memory_manager.GpuToCpuAddress(gpu_addr);
  42. if (!cpu_addr_opt) {
  43. return {GetEmptyBuffer(size), 0};
  44. }
  45. const VAddr cpu_addr = *cpu_addr_opt;
  46. // Cache management is a big overhead, so only cache entries with a given size.
  47. // TODO: Figure out which size is the best for given games.
  48. constexpr std::size_t max_stream_size = 0x800;
  49. if (use_fast_cbuf || size < max_stream_size) {
  50. if (!is_written && !IsRegionWritten(cpu_addr, cpu_addr + size - 1)) {
  51. auto& memory_manager = system.GPU().MemoryManager();
  52. const bool is_granular = memory_manager.IsGranularRange(gpu_addr, size);
  53. if (use_fast_cbuf) {
  54. u8* dest;
  55. if (is_granular) {
  56. dest = memory_manager.GetPointer(gpu_addr);
  57. } else {
  58. staging_buffer.resize(size);
  59. dest = staging_buffer.data();
  60. memory_manager.ReadBlockUnsafe(gpu_addr, dest, size);
  61. }
  62. return ConstBufferUpload(dest, size);
  63. }
  64. if (is_granular) {
  65. u8* const host_ptr = memory_manager.GetPointer(gpu_addr);
  66. return StreamBufferUpload(size, alignment, [host_ptr, size](u8* dest) {
  67. std::memcpy(dest, host_ptr, size);
  68. });
  69. } else {
  70. return StreamBufferUpload(
  71. size, alignment, [&memory_manager, gpu_addr, size](u8* dest) {
  72. memory_manager.ReadBlockUnsafe(gpu_addr, dest, size);
  73. });
  74. }
  75. }
  76. }
  77. Buffer* const block = GetBlock(cpu_addr, size);
  78. MapInterval* const map = MapAddress(block, gpu_addr, cpu_addr, size);
  79. if (!map) {
  80. return {GetEmptyBuffer(size), 0};
  81. }
  82. if (is_written) {
  83. map->MarkAsModified(true, GetModifiedTicks());
  84. if (Settings::IsGPULevelHigh() && Settings::values.use_asynchronous_gpu_emulation) {
  85. MarkForAsyncFlush(map);
  86. }
  87. if (!map->is_written) {
  88. map->is_written = true;
  89. MarkRegionAsWritten(map->start, map->end - 1);
  90. }
  91. }
  92. return {block->Handle(), static_cast<u64>(block->Offset(cpu_addr))};
  93. }
  94. /// Uploads from a host memory. Returns the OpenGL buffer where it's located and its offset.
  95. BufferInfo UploadHostMemory(const void* raw_pointer, std::size_t size,
  96. std::size_t alignment = 4) {
  97. std::lock_guard lock{mutex};
  98. return StreamBufferUpload(size, alignment, [raw_pointer, size](u8* dest) {
  99. std::memcpy(dest, raw_pointer, size);
  100. });
  101. }
  102. /// Prepares the buffer cache for data uploading
  103. /// @param max_size Maximum number of bytes that will be uploaded
  104. /// @return True when a stream buffer invalidation was required, false otherwise
  105. bool Map(std::size_t max_size) {
  106. std::lock_guard lock{mutex};
  107. bool invalidated;
  108. std::tie(buffer_ptr, buffer_offset_base, invalidated) = stream_buffer->Map(max_size, 4);
  109. buffer_offset = buffer_offset_base;
  110. return invalidated;
  111. }
  112. /// Finishes the upload stream
  113. void Unmap() {
  114. std::lock_guard lock{mutex};
  115. stream_buffer->Unmap(buffer_offset - buffer_offset_base);
  116. }
  117. /// Function called at the end of each frame, inteded for deferred operations
  118. void TickFrame() {
  119. ++epoch;
  120. while (!pending_destruction.empty()) {
  121. // Delay at least 4 frames before destruction.
  122. // This is due to triple buffering happening on some drivers.
  123. static constexpr u64 epochs_to_destroy = 5;
  124. if (pending_destruction.front()->Epoch() + epochs_to_destroy > epoch) {
  125. break;
  126. }
  127. pending_destruction.pop();
  128. }
  129. }
  130. /// Write any cached resources overlapping the specified region back to memory
  131. void FlushRegion(VAddr addr, std::size_t size) {
  132. std::lock_guard lock{mutex};
  133. VectorMapInterval objects = GetMapsInRange(addr, size);
  134. std::sort(objects.begin(), objects.end(),
  135. [](MapInterval* lhs, MapInterval* rhs) { return lhs->ticks < rhs->ticks; });
  136. for (MapInterval* object : objects) {
  137. if (object->is_modified && object->is_registered) {
  138. mutex.unlock();
  139. FlushMap(object);
  140. mutex.lock();
  141. }
  142. }
  143. }
  144. bool MustFlushRegion(VAddr addr, std::size_t size) {
  145. std::lock_guard lock{mutex};
  146. const VectorMapInterval objects = GetMapsInRange(addr, size);
  147. return std::any_of(objects.cbegin(), objects.cend(), [](const MapInterval* map) {
  148. return map->is_modified && map->is_registered;
  149. });
  150. }
  151. /// Mark the specified region as being invalidated
  152. void InvalidateRegion(VAddr addr, u64 size) {
  153. std::lock_guard lock{mutex};
  154. for (auto& object : GetMapsInRange(addr, size)) {
  155. if (object->is_registered) {
  156. Unregister(object);
  157. }
  158. }
  159. }
  160. void OnCPUWrite(VAddr addr, std::size_t size) {
  161. std::lock_guard lock{mutex};
  162. for (MapInterval* object : GetMapsInRange(addr, size)) {
  163. if (object->is_memory_marked && object->is_registered) {
  164. UnmarkMemory(object);
  165. object->is_sync_pending = true;
  166. marked_for_unregister.emplace_back(object);
  167. }
  168. }
  169. }
  170. void SyncGuestHost() {
  171. std::lock_guard lock{mutex};
  172. for (auto& object : marked_for_unregister) {
  173. if (object->is_registered) {
  174. object->is_sync_pending = false;
  175. Unregister(object);
  176. }
  177. }
  178. marked_for_unregister.clear();
  179. }
  180. void CommitAsyncFlushes() {
  181. if (uncommitted_flushes) {
  182. auto commit_list = std::make_shared<std::list<MapInterval*>>();
  183. for (MapInterval* map : *uncommitted_flushes) {
  184. if (map->is_registered && map->is_modified) {
  185. // TODO(Blinkhawk): Implement backend asynchronous flushing
  186. // AsyncFlushMap(map)
  187. commit_list->push_back(map);
  188. }
  189. }
  190. if (!commit_list->empty()) {
  191. committed_flushes.push_back(commit_list);
  192. } else {
  193. committed_flushes.emplace_back();
  194. }
  195. } else {
  196. committed_flushes.emplace_back();
  197. }
  198. uncommitted_flushes.reset();
  199. }
  200. bool ShouldWaitAsyncFlushes() const {
  201. return !committed_flushes.empty() && committed_flushes.front() != nullptr;
  202. }
  203. bool HasUncommittedFlushes() const {
  204. return uncommitted_flushes != nullptr;
  205. }
  206. void PopAsyncFlushes() {
  207. if (committed_flushes.empty()) {
  208. return;
  209. }
  210. auto& flush_list = committed_flushes.front();
  211. if (!flush_list) {
  212. committed_flushes.pop_front();
  213. return;
  214. }
  215. for (MapInterval* map : *flush_list) {
  216. if (map->is_registered) {
  217. // TODO(Blinkhawk): Replace this for reading the asynchronous flush
  218. FlushMap(map);
  219. }
  220. }
  221. committed_flushes.pop_front();
  222. }
  223. virtual BufferType GetEmptyBuffer(std::size_t size) = 0;
  224. protected:
  225. explicit BufferCache(VideoCore::RasterizerInterface& rasterizer, Core::System& system,
  226. std::unique_ptr<StreamBuffer> stream_buffer_)
  227. : rasterizer{rasterizer}, system{system}, stream_buffer{std::move(stream_buffer_)},
  228. stream_buffer_handle{stream_buffer->Handle()} {}
  229. ~BufferCache() = default;
  230. virtual std::shared_ptr<Buffer> CreateBlock(VAddr cpu_addr, std::size_t size) = 0;
  231. virtual void UploadBlockData(const Buffer& buffer, std::size_t offset, std::size_t size,
  232. const u8* data) = 0;
  233. virtual void DownloadBlockData(const Buffer& buffer, std::size_t offset, std::size_t size,
  234. u8* data) = 0;
  235. virtual void CopyBlock(const Buffer& src, const Buffer& dst, std::size_t src_offset,
  236. std::size_t dst_offset, std::size_t size) = 0;
  237. virtual BufferInfo ConstBufferUpload(const void* raw_pointer, std::size_t size) {
  238. return {};
  239. }
  240. /// Register an object into the cache
  241. MapInterval* Register(MapInterval new_map, bool inherit_written = false) {
  242. const VAddr cpu_addr = new_map.start;
  243. if (!cpu_addr) {
  244. LOG_CRITICAL(HW_GPU, "Failed to register buffer with unmapped gpu_address 0x{:016x}",
  245. new_map.gpu_addr);
  246. return nullptr;
  247. }
  248. const std::size_t size = new_map.end - new_map.start;
  249. new_map.is_registered = true;
  250. rasterizer.UpdatePagesCachedCount(cpu_addr, size, 1);
  251. new_map.is_memory_marked = true;
  252. if (inherit_written) {
  253. MarkRegionAsWritten(new_map.start, new_map.end - 1);
  254. new_map.is_written = true;
  255. }
  256. MapInterval* const storage = mapped_addresses_allocator.Allocate();
  257. *storage = new_map;
  258. mapped_addresses.insert(*storage);
  259. return storage;
  260. }
  261. void UnmarkMemory(MapInterval* map) {
  262. if (!map->is_memory_marked) {
  263. return;
  264. }
  265. const std::size_t size = map->end - map->start;
  266. rasterizer.UpdatePagesCachedCount(map->start, size, -1);
  267. map->is_memory_marked = false;
  268. }
  269. /// Unregisters an object from the cache
  270. void Unregister(MapInterval* map) {
  271. UnmarkMemory(map);
  272. map->is_registered = false;
  273. if (map->is_sync_pending) {
  274. map->is_sync_pending = false;
  275. marked_for_unregister.remove(map);
  276. }
  277. if (map->is_written) {
  278. UnmarkRegionAsWritten(map->start, map->end - 1);
  279. }
  280. const auto it = mapped_addresses.find(*map);
  281. ASSERT(it != mapped_addresses.end());
  282. mapped_addresses.erase(it);
  283. mapped_addresses_allocator.Release(map);
  284. }
  285. private:
  286. MapInterval* MapAddress(const Buffer* block, GPUVAddr gpu_addr, VAddr cpu_addr,
  287. std::size_t size) {
  288. const VectorMapInterval overlaps = GetMapsInRange(cpu_addr, size);
  289. if (overlaps.empty()) {
  290. auto& memory_manager = system.GPU().MemoryManager();
  291. const VAddr cpu_addr_end = cpu_addr + size;
  292. if (memory_manager.IsGranularRange(gpu_addr, size)) {
  293. u8* host_ptr = memory_manager.GetPointer(gpu_addr);
  294. UploadBlockData(*block, block->Offset(cpu_addr), size, host_ptr);
  295. } else {
  296. staging_buffer.resize(size);
  297. memory_manager.ReadBlockUnsafe(gpu_addr, staging_buffer.data(), size);
  298. UploadBlockData(*block, block->Offset(cpu_addr), size, staging_buffer.data());
  299. }
  300. return Register(MapInterval(cpu_addr, cpu_addr_end, gpu_addr));
  301. }
  302. const VAddr cpu_addr_end = cpu_addr + size;
  303. if (overlaps.size() == 1) {
  304. MapInterval* const current_map = overlaps[0];
  305. if (current_map->IsInside(cpu_addr, cpu_addr_end)) {
  306. return current_map;
  307. }
  308. }
  309. VAddr new_start = cpu_addr;
  310. VAddr new_end = cpu_addr_end;
  311. bool write_inheritance = false;
  312. bool modified_inheritance = false;
  313. // Calculate new buffer parameters
  314. for (MapInterval* overlap : overlaps) {
  315. new_start = std::min(overlap->start, new_start);
  316. new_end = std::max(overlap->end, new_end);
  317. write_inheritance |= overlap->is_written;
  318. modified_inheritance |= overlap->is_modified;
  319. }
  320. GPUVAddr new_gpu_addr = gpu_addr + new_start - cpu_addr;
  321. for (auto& overlap : overlaps) {
  322. Unregister(overlap);
  323. }
  324. UpdateBlock(block, new_start, new_end, overlaps);
  325. const MapInterval new_map{new_start, new_end, new_gpu_addr};
  326. MapInterval* const map = Register(new_map, write_inheritance);
  327. if (!map) {
  328. return nullptr;
  329. }
  330. if (modified_inheritance) {
  331. map->MarkAsModified(true, GetModifiedTicks());
  332. if (Settings::IsGPULevelHigh() && Settings::values.use_asynchronous_gpu_emulation) {
  333. MarkForAsyncFlush(map);
  334. }
  335. }
  336. return map;
  337. }
  338. void UpdateBlock(const Buffer* block, VAddr start, VAddr end,
  339. const VectorMapInterval& overlaps) {
  340. const IntervalType base_interval{start, end};
  341. IntervalSet interval_set{};
  342. interval_set.add(base_interval);
  343. for (auto& overlap : overlaps) {
  344. const IntervalType subtract{overlap->start, overlap->end};
  345. interval_set.subtract(subtract);
  346. }
  347. for (auto& interval : interval_set) {
  348. const std::size_t size = interval.upper() - interval.lower();
  349. if (size == 0) {
  350. continue;
  351. }
  352. staging_buffer.resize(size);
  353. system.Memory().ReadBlockUnsafe(interval.lower(), staging_buffer.data(), size);
  354. UploadBlockData(*block, block->Offset(interval.lower()), size, staging_buffer.data());
  355. }
  356. }
  357. VectorMapInterval GetMapsInRange(VAddr addr, std::size_t size) {
  358. VectorMapInterval result;
  359. if (size == 0) {
  360. return result;
  361. }
  362. const VAddr addr_end = addr + size;
  363. auto it = mapped_addresses.lower_bound(addr);
  364. if (it != mapped_addresses.begin()) {
  365. --it;
  366. }
  367. while (it != mapped_addresses.end() && it->start < addr_end) {
  368. if (it->Overlaps(addr, addr_end)) {
  369. result.push_back(&*it);
  370. }
  371. ++it;
  372. }
  373. return result;
  374. }
  375. /// Returns a ticks counter used for tracking when cached objects were last modified
  376. u64 GetModifiedTicks() {
  377. return ++modified_ticks;
  378. }
  379. void FlushMap(MapInterval* map) {
  380. const auto it = blocks.find(map->start >> BLOCK_PAGE_BITS);
  381. ASSERT_OR_EXECUTE(it != blocks.end(), return;);
  382. std::shared_ptr<Buffer> block = it->second;
  383. const std::size_t size = map->end - map->start;
  384. staging_buffer.resize(size);
  385. DownloadBlockData(*block, block->Offset(map->start), size, staging_buffer.data());
  386. system.Memory().WriteBlockUnsafe(map->start, staging_buffer.data(), size);
  387. map->MarkAsModified(false, 0);
  388. }
  389. template <typename Callable>
  390. BufferInfo StreamBufferUpload(std::size_t size, std::size_t alignment, Callable&& callable) {
  391. AlignBuffer(alignment);
  392. const std::size_t uploaded_offset = buffer_offset;
  393. callable(buffer_ptr);
  394. buffer_ptr += size;
  395. buffer_offset += size;
  396. return {stream_buffer_handle, uploaded_offset};
  397. }
  398. void AlignBuffer(std::size_t alignment) {
  399. // Align the offset, not the mapped pointer
  400. const std::size_t offset_aligned = Common::AlignUp(buffer_offset, alignment);
  401. buffer_ptr += offset_aligned - buffer_offset;
  402. buffer_offset = offset_aligned;
  403. }
  404. std::shared_ptr<Buffer> EnlargeBlock(std::shared_ptr<Buffer> buffer) {
  405. const std::size_t old_size = buffer->Size();
  406. const std::size_t new_size = old_size + BLOCK_PAGE_SIZE;
  407. const VAddr cpu_addr = buffer->CpuAddr();
  408. std::shared_ptr<Buffer> new_buffer = CreateBlock(cpu_addr, new_size);
  409. CopyBlock(*buffer, *new_buffer, 0, 0, old_size);
  410. QueueDestruction(std::move(buffer));
  411. const VAddr cpu_addr_end = cpu_addr + new_size - 1;
  412. const u64 page_end = cpu_addr_end >> BLOCK_PAGE_BITS;
  413. for (u64 page_start = cpu_addr >> BLOCK_PAGE_BITS; page_start <= page_end; ++page_start) {
  414. blocks.insert_or_assign(page_start, new_buffer);
  415. }
  416. return new_buffer;
  417. }
  418. std::shared_ptr<Buffer> MergeBlocks(std::shared_ptr<Buffer> first,
  419. std::shared_ptr<Buffer> second) {
  420. const std::size_t size_1 = first->Size();
  421. const std::size_t size_2 = second->Size();
  422. const VAddr first_addr = first->CpuAddr();
  423. const VAddr second_addr = second->CpuAddr();
  424. const VAddr new_addr = std::min(first_addr, second_addr);
  425. const std::size_t new_size = size_1 + size_2;
  426. std::shared_ptr<Buffer> new_buffer = CreateBlock(new_addr, new_size);
  427. CopyBlock(*first, *new_buffer, 0, new_buffer->Offset(first_addr), size_1);
  428. CopyBlock(*second, *new_buffer, 0, new_buffer->Offset(second_addr), size_2);
  429. QueueDestruction(std::move(first));
  430. QueueDestruction(std::move(second));
  431. const VAddr cpu_addr_end = new_addr + new_size - 1;
  432. const u64 page_end = cpu_addr_end >> BLOCK_PAGE_BITS;
  433. for (u64 page_start = new_addr >> BLOCK_PAGE_BITS; page_start <= page_end; ++page_start) {
  434. blocks.insert_or_assign(page_start, new_buffer);
  435. }
  436. return new_buffer;
  437. }
  438. Buffer* GetBlock(VAddr cpu_addr, std::size_t size) {
  439. std::shared_ptr<Buffer> found;
  440. const VAddr cpu_addr_end = cpu_addr + size - 1;
  441. const u64 page_end = cpu_addr_end >> BLOCK_PAGE_BITS;
  442. for (u64 page_start = cpu_addr >> BLOCK_PAGE_BITS; page_start <= page_end; ++page_start) {
  443. auto it = blocks.find(page_start);
  444. if (it == blocks.end()) {
  445. if (found) {
  446. found = EnlargeBlock(found);
  447. continue;
  448. }
  449. const VAddr start_addr = page_start << BLOCK_PAGE_BITS;
  450. found = CreateBlock(start_addr, BLOCK_PAGE_SIZE);
  451. blocks.insert_or_assign(page_start, found);
  452. continue;
  453. }
  454. if (!found) {
  455. found = it->second;
  456. continue;
  457. }
  458. if (found != it->second) {
  459. found = MergeBlocks(std::move(found), it->second);
  460. }
  461. }
  462. return found.get();
  463. }
  464. void MarkRegionAsWritten(VAddr start, VAddr end) {
  465. const u64 page_end = end >> WRITE_PAGE_BIT;
  466. for (u64 page_start = start >> WRITE_PAGE_BIT; page_start <= page_end; ++page_start) {
  467. auto it = written_pages.find(page_start);
  468. if (it != written_pages.end()) {
  469. it->second = it->second + 1;
  470. } else {
  471. written_pages.insert_or_assign(page_start, 1);
  472. }
  473. }
  474. }
  475. void UnmarkRegionAsWritten(VAddr start, VAddr end) {
  476. const u64 page_end = end >> WRITE_PAGE_BIT;
  477. for (u64 page_start = start >> WRITE_PAGE_BIT; page_start <= page_end; ++page_start) {
  478. auto it = written_pages.find(page_start);
  479. if (it != written_pages.end()) {
  480. if (it->second > 1) {
  481. it->second = it->second - 1;
  482. } else {
  483. written_pages.erase(it);
  484. }
  485. }
  486. }
  487. }
  488. bool IsRegionWritten(VAddr start, VAddr end) const {
  489. const u64 page_end = end >> WRITE_PAGE_BIT;
  490. for (u64 page_start = start >> WRITE_PAGE_BIT; page_start <= page_end; ++page_start) {
  491. if (written_pages.count(page_start) > 0) {
  492. return true;
  493. }
  494. }
  495. return false;
  496. }
  497. void QueueDestruction(std::shared_ptr<Buffer> buffer) {
  498. buffer->SetEpoch(epoch);
  499. pending_destruction.push(std::move(buffer));
  500. }
  501. void MarkForAsyncFlush(MapInterval* map) {
  502. if (!uncommitted_flushes) {
  503. uncommitted_flushes = std::make_shared<std::unordered_set<MapInterval*>>();
  504. }
  505. uncommitted_flushes->insert(map);
  506. }
  507. VideoCore::RasterizerInterface& rasterizer;
  508. Core::System& system;
  509. std::unique_ptr<StreamBuffer> stream_buffer;
  510. BufferType stream_buffer_handle;
  511. u8* buffer_ptr = nullptr;
  512. u64 buffer_offset = 0;
  513. u64 buffer_offset_base = 0;
  514. MapIntervalAllocator mapped_addresses_allocator;
  515. boost::intrusive::set<MapInterval, boost::intrusive::compare<MapIntervalCompare>>
  516. mapped_addresses;
  517. std::unordered_map<u64, u32> written_pages;
  518. std::unordered_map<u64, std::shared_ptr<Buffer>> blocks;
  519. std::queue<std::shared_ptr<Buffer>> pending_destruction;
  520. u64 epoch = 0;
  521. u64 modified_ticks = 0;
  522. std::vector<u8> staging_buffer;
  523. std::list<MapInterval*> marked_for_unregister;
  524. std::shared_ptr<std::unordered_set<MapInterval*>> uncommitted_flushes;
  525. std::list<std::shared_ptr<std::list<MapInterval*>>> committed_flushes;
  526. std::recursive_mutex mutex;
  527. };
  528. } // namespace VideoCommon