buffer_block.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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(VAddr start, VAddr end) const {
  14. return (cpu_addr < end) && (cpu_addr_end > start);
  15. }
  16. bool IsInside(VAddr other_start, VAddr other_end) const {
  17. return cpu_addr <= other_start && other_end <= cpu_addr_end;
  18. }
  19. std::size_t Offset(VAddr in_addr) const {
  20. return static_cast<std::size_t>(in_addr - cpu_addr);
  21. }
  22. VAddr CpuAddr() const {
  23. return cpu_addr;
  24. }
  25. VAddr CpuAddrEnd() const {
  26. return cpu_addr_end;
  27. }
  28. void SetCpuAddr(VAddr new_addr) {
  29. cpu_addr = new_addr;
  30. cpu_addr_end = new_addr + size;
  31. }
  32. std::size_t Size() const {
  33. return size;
  34. }
  35. u64 Epoch() const {
  36. return epoch;
  37. }
  38. void SetEpoch(u64 new_epoch) {
  39. epoch = new_epoch;
  40. }
  41. protected:
  42. explicit BufferBlock(VAddr cpu_addr_, std::size_t size_) : size{size_} {
  43. SetCpuAddr(cpu_addr_);
  44. }
  45. private:
  46. VAddr cpu_addr{};
  47. VAddr cpu_addr_end{};
  48. std::size_t size{};
  49. u64 epoch{};
  50. };
  51. } // namespace VideoCommon