From 1c9e17496b6f9f4b083c62aa25548617dd179a8b Mon Sep 17 00:00:00 2001 From: Zephyron Date: Sun, 16 Feb 2025 18:30:50 +1000 Subject: [PATCH] texture_cache: Add equality operators for ImageInfo and ImageViewInfo - Add operator== to ImageInfo and ImageViewInfo classes to enable direct equality comparisons. The implementations use std::tie to perform member-wise comparisons of all relevant fields in a safe and efficient manner. This allows for easier comparison of texture cache entries and view information, which can be useful for cache management and debugging. --- src/video_core/texture_cache/image_info.cpp | 12 ++++++++++++ src/video_core/texture_cache/image_info.h | 3 +++ src/video_core/texture_cache/image_view_info.cpp | 8 ++++++++ src/video_core/texture_cache/image_view_info.h | 3 +++ 4 files changed, 26 insertions(+) diff --git a/src/video_core/texture_cache/image_info.cpp b/src/video_core/texture_cache/image_info.cpp index 135dd64de..08df876b1 100644 --- a/src/video_core/texture_cache/image_info.cpp +++ b/src/video_core/texture_cache/image_info.cpp @@ -1,4 +1,5 @@ // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project +// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #include @@ -284,4 +285,15 @@ ImageInfo::ImageInfo(const Tegra::DMA::ImageOperand& config) noexcept { downscaleable = size.height > DownscaleHeightThreshold; } +bool ImageInfo::operator==(const ImageInfo& rhs) const noexcept { + return std::tie(this->format, this->num_samples, this->resources, this->type, + this->pitch, this->block, this->size, this->tile_width_spacing, + this->is_sparse, this->rescaleable, this->downscaleable, + this->forced_flushed, this->dma_downloaded) == + std::tie(rhs.format, rhs.num_samples, rhs.resources, rhs.type, + rhs.pitch, rhs.block, rhs.size, rhs.tile_width_spacing, + rhs.is_sparse, rhs.rescaleable, rhs.downscaleable, + rhs.forced_flushed, rhs.dma_downloaded); +} + } // namespace VideoCommon diff --git a/src/video_core/texture_cache/image_info.h b/src/video_core/texture_cache/image_info.h index eb490a642..63bc9bf78 100644 --- a/src/video_core/texture_cache/image_info.h +++ b/src/video_core/texture_cache/image_info.h @@ -1,4 +1,5 @@ // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project +// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #pragma once @@ -42,6 +43,8 @@ struct ImageInfo { bool forced_flushed = false; bool dma_downloaded = false; bool is_sparse = false; + + bool operator==(const ImageInfo& rhs) const noexcept; }; } // namespace VideoCommon diff --git a/src/video_core/texture_cache/image_view_info.cpp b/src/video_core/texture_cache/image_view_info.cpp index f47885147..5930204db 100644 --- a/src/video_core/texture_cache/image_view_info.cpp +++ b/src/video_core/texture_cache/image_view_info.cpp @@ -1,4 +1,5 @@ // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project +// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #include @@ -87,4 +88,11 @@ bool ImageViewInfo::IsRenderTarget() const noexcept { z_source == RENDER_TARGET_SWIZZLE && w_source == RENDER_TARGET_SWIZZLE; } +bool ImageViewInfo::operator==(const ImageViewInfo& rhs) const noexcept { + return std::tie(this->type, this->format, this->range, + this->x_source, this->y_source, this->z_source, this->w_source) == + std::tie(rhs.type, rhs.format, rhs.range, + rhs.x_source, rhs.y_source, rhs.z_source, rhs.w_source); +} + } // namespace VideoCommon diff --git a/src/video_core/texture_cache/image_view_info.h b/src/video_core/texture_cache/image_view_info.h index 921f88988..a28248795 100644 --- a/src/video_core/texture_cache/image_view_info.h +++ b/src/video_core/texture_cache/image_view_info.h @@ -1,4 +1,5 @@ // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project +// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #pragma once @@ -43,6 +44,8 @@ struct ImageViewInfo { u8 y_source = static_cast(SwizzleSource::G); u8 z_source = static_cast(SwizzleSource::B); u8 w_source = static_cast(SwizzleSource::A); + + bool operator==(const ImageViewInfo& rhs) const noexcept; }; static_assert(std::has_unique_object_representations_v);