image_base.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2020 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include <optional>
  7. #include <vector>
  8. #include "common/common_funcs.h"
  9. #include "common/common_types.h"
  10. #include "video_core/texture_cache/image_info.h"
  11. #include "video_core/texture_cache/image_view_info.h"
  12. #include "video_core/texture_cache/types.h"
  13. namespace VideoCommon {
  14. enum class ImageFlagBits : u32 {
  15. AcceleratedUpload = 1 << 0, ///< Upload can be accelerated in the GPU
  16. Converted = 1 << 1, ///< Guest format is not supported natively and it has to be converted
  17. CpuModified = 1 << 2, ///< Contents have been modified from the CPU
  18. GpuModified = 1 << 3, ///< Contents have been modified from the GPU
  19. Tracked = 1 << 4, ///< Writes and reads are being hooked from the CPU JIT
  20. Strong = 1 << 5, ///< Exists in the image table, the dimensions are can be trusted
  21. Registered = 1 << 6, ///< True when the image is registered
  22. Picked = 1 << 7, ///< Temporary flag to mark the image as picked
  23. };
  24. DECLARE_ENUM_FLAG_OPERATORS(ImageFlagBits)
  25. struct ImageViewInfo;
  26. struct AliasedImage {
  27. std::vector<ImageCopy> copies;
  28. ImageId id;
  29. };
  30. struct ImageBase {
  31. explicit ImageBase(const ImageInfo& info, GPUVAddr gpu_addr, VAddr cpu_addr);
  32. [[nodiscard]] std::optional<SubresourceBase> TryFindBase(GPUVAddr other_addr) const noexcept;
  33. [[nodiscard]] ImageViewId FindView(const ImageViewInfo& view_info) const noexcept;
  34. void InsertView(const ImageViewInfo& view_info, ImageViewId image_view_id);
  35. [[nodiscard]] bool IsSafeDownload() const noexcept;
  36. [[nodiscard]] bool Overlaps(VAddr overlap_cpu_addr, size_t overlap_size) const noexcept {
  37. const VAddr overlap_end = overlap_cpu_addr + overlap_size;
  38. return cpu_addr < overlap_end && overlap_cpu_addr < cpu_addr_end;
  39. }
  40. ImageInfo info;
  41. u32 guest_size_bytes = 0;
  42. u32 unswizzled_size_bytes = 0;
  43. u32 converted_size_bytes = 0;
  44. ImageFlagBits flags = ImageFlagBits::CpuModified;
  45. GPUVAddr gpu_addr = 0;
  46. VAddr cpu_addr = 0;
  47. VAddr cpu_addr_end = 0;
  48. u64 modification_tick = 0;
  49. u64 frame_tick = 0;
  50. std::array<u32, MAX_MIP_LEVELS> mip_level_offsets{};
  51. std::vector<ImageViewInfo> image_view_infos;
  52. std::vector<ImageViewId> image_view_ids;
  53. std::vector<u32> slice_offsets;
  54. std::vector<SubresourceBase> slice_subresources;
  55. std::vector<AliasedImage> aliased_images;
  56. };
  57. struct ImageAllocBase {
  58. std::vector<ImageId> images;
  59. };
  60. void AddImageAlias(ImageBase& lhs, ImageBase& rhs, ImageId lhs_id, ImageId rhs_id);
  61. } // namespace VideoCommon