buffer_block.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 <unordered_set>
  6. #include <utility>
  7. #include "common/alignment.h"
  8. #include "common/common_types.h"
  9. #include "video_core/gpu.h"
  10. namespace VideoCommon {
  11. class BufferBlock {
  12. public:
  13. bool Overlaps(const CacheAddr start, const CacheAddr end) const {
  14. return (cache_addr < end) && (cache_addr_end > start);
  15. }
  16. bool IsInside(const CacheAddr other_start, const CacheAddr other_end) const {
  17. return cache_addr <= other_start && other_end <= cache_addr_end;
  18. }
  19. u8* GetWritableHostPtr() const {
  20. return FromCacheAddr(cache_addr);
  21. }
  22. u8* GetWritableHostPtr(std::size_t offset) const {
  23. return FromCacheAddr(cache_addr + offset);
  24. }
  25. std::size_t GetOffset(const CacheAddr in_addr) {
  26. return static_cast<std::size_t>(in_addr - cache_addr);
  27. }
  28. CacheAddr GetCacheAddr() const {
  29. return cache_addr;
  30. }
  31. CacheAddr GetCacheAddrEnd() const {
  32. return cache_addr_end;
  33. }
  34. void SetCacheAddr(const CacheAddr new_addr) {
  35. cache_addr = new_addr;
  36. cache_addr_end = new_addr + size;
  37. }
  38. std::size_t GetSize() const {
  39. return size;
  40. }
  41. void SetEpoch(u64 new_epoch) {
  42. epoch = new_epoch;
  43. }
  44. u64 GetEpoch() {
  45. return epoch;
  46. }
  47. protected:
  48. explicit BufferBlock(CacheAddr cache_addr, const std::size_t size) : size{size} {
  49. SetCacheAddr(cache_addr);
  50. }
  51. ~BufferBlock() = default;
  52. private:
  53. CacheAddr cache_addr{};
  54. CacheAddr cache_addr_end{};
  55. u64 pages{};
  56. std::size_t size{};
  57. u64 epoch{};
  58. };
  59. } // namespace VideoCommon