render_targets.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 <algorithm>
  6. #include <span>
  7. #include <utility>
  8. #include "common/bit_cast.h"
  9. #include "video_core/texture_cache/types.h"
  10. namespace VideoCommon {
  11. /// Framebuffer properties used to lookup a framebuffer
  12. struct RenderTargets {
  13. constexpr auto operator<=>(const RenderTargets&) const noexcept = default;
  14. constexpr bool Contains(std::span<const ImageViewId> elements) const noexcept {
  15. const auto contains = [elements](ImageViewId item) {
  16. return std::ranges::find(elements, item) != elements.end();
  17. };
  18. return std::ranges::any_of(color_buffer_ids, contains) || contains(depth_buffer_id);
  19. }
  20. std::array<ImageViewId, NUM_RT> color_buffer_ids{};
  21. ImageViewId depth_buffer_id{};
  22. std::array<u8, NUM_RT> draw_buffers{};
  23. Extent2D size{};
  24. };
  25. } // namespace VideoCommon
  26. namespace std {
  27. template <>
  28. struct hash<VideoCommon::RenderTargets> {
  29. size_t operator()(const VideoCommon::RenderTargets& rt) const noexcept {
  30. using VideoCommon::ImageViewId;
  31. size_t value = std::hash<ImageViewId>{}(rt.depth_buffer_id);
  32. for (const ImageViewId color_buffer_id : rt.color_buffer_ids) {
  33. value ^= std::hash<ImageViewId>{}(color_buffer_id);
  34. }
  35. value ^= Common::BitCast<u64>(rt.draw_buffers);
  36. value ^= Common::BitCast<u64>(rt.size);
  37. return value;
  38. }
  39. };
  40. } // namespace std