buffer_cache.h 22 KB

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