buffer_cache.h 22 KB

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