diff options
author | Fernando Sahmkow <fsahmkow27@gmail.com> | 2021-06-12 15:52:27 +0200 |
---|---|---|
committer | Fernando Sahmkow <fsahmkow27@gmail.com> | 2021-07-04 22:32:03 +0200 |
commit | 38165fb7e3e486b5099cfa76f5a09ec9f3201acd (patch) | |
tree | a80e66a254960c9c8c602f256cd37361c780d188 /src/video_core/texture_cache/util.cpp | |
parent | Merge pull request #6553 from FernandoS27/bite-a-bat-change-the-world (diff) | |
download | yuzu-38165fb7e3e486b5099cfa76f5a09ec9f3201acd.tar yuzu-38165fb7e3e486b5099cfa76f5a09ec9f3201acd.tar.gz yuzu-38165fb7e3e486b5099cfa76f5a09ec9f3201acd.tar.bz2 yuzu-38165fb7e3e486b5099cfa76f5a09ec9f3201acd.tar.lz yuzu-38165fb7e3e486b5099cfa76f5a09ec9f3201acd.tar.xz yuzu-38165fb7e3e486b5099cfa76f5a09ec9f3201acd.tar.zst yuzu-38165fb7e3e486b5099cfa76f5a09ec9f3201acd.zip |
Diffstat (limited to 'src/video_core/texture_cache/util.cpp')
-rw-r--r-- | src/video_core/texture_cache/util.cpp | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/src/video_core/texture_cache/util.cpp b/src/video_core/texture_cache/util.cpp index 4efe042b6..96bf8f8d9 100644 --- a/src/video_core/texture_cache/util.cpp +++ b/src/video_core/texture_cache/util.cpp @@ -664,6 +664,16 @@ LevelArray CalculateMipLevelOffsets(const ImageInfo& info) noexcept { return offsets; } +LevelArray CalculateMipLevelSizes(const ImageInfo& info) noexcept { + const u32 num_levels = info.resources.levels; + const LevelInfo level_info = MakeLevelInfo(info); + LevelArray sizes{}; + for (u32 level = 0; level < num_levels; ++level) { + sizes[level] = CalculateLevelSize(level_info, level); + } + return sizes; +} + std::vector<u32> CalculateSliceOffsets(const ImageInfo& info) { ASSERT(info.type == ImageType::e3D); std::vector<u32> offsets; @@ -776,14 +786,37 @@ std::vector<ImageCopy> MakeShrinkImageCopies(const ImageInfo& dst, const ImageIn return copies; } -bool IsValidAddress(const Tegra::MemoryManager& gpu_memory, const TICEntry& config) { - if (config.Address() == 0) { +bool IsValidAddress(const Tegra::MemoryManager& gpu_memory, GPUVAddr gpu_addr) { + if (gpu_addr == 0) { return false; } - if (config.Address() > (u64(1) << 48)) { + if (gpu_addr > (u64(1) << 48)) { return false; } - return gpu_memory.GpuToCpuAddress(config.Address()).has_value(); + const auto cpu_addr = gpu_memory.GpuToCpuAddress(gpu_addr); + return cpu_addr.has_value() && *cpu_addr != 0; +} + +bool IsValidEntry(const Tegra::MemoryManager& gpu_memory, const TICEntry& config) { + const GPUVAddr gpu_addr = config.Address(); + if (IsValidAddress(gpu_memory, gpu_addr)) { + return true; + } + if (!config.IsBlockLinear()) { + return false; + } + const size_t levels = config.max_mip_level + 1; + if (levels <= 1) { + return false; + } + const ImageInfo info{config}; + const LevelArray offsets = CalculateMipLevelOffsets(info); + for (size_t level = 1; level < levels; level++) { + if (IsValidAddress(gpu_memory, static_cast<GPUVAddr>(gpu_addr + offsets[level]))) { + return true; + } + } + return false; } std::vector<BufferImageCopy> UnswizzleImage(Tegra::MemoryManager& gpu_memory, GPUVAddr gpu_addr, |