Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,8 @@ set(VIDEO_CORE src/video_core/amdgpu/cb_db_extent.h
src/video_core/renderer_vulkan/host_passes/fsr_pass.h
src/video_core/renderer_vulkan/host_passes/pp_pass.cpp
src/video_core/renderer_vulkan/host_passes/pp_pass.h
src/video_core/texture_cache/aliasing.cpp
src/video_core/texture_cache/aliasing.h
src/video_core/texture_cache/blit_helper.cpp
src/video_core/texture_cache/blit_helper.h
src/video_core/texture_cache/host_compatibility.cpp
Expand Down
7 changes: 7 additions & 0 deletions src/video_core/buffer_cache/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ void Buffer::Fill(u64 offset, u32 num_bytes, u32 value) {
});
}

void Buffer::Invalidate(u64 offset, u64 size) {
ASSERT(offset + size <= size_bytes);
if (!is_coherent && usage == MemoryUsage::Download) {
vmaInvalidateAllocation(instance->GetAllocator(), buffer.allocation, offset, size);
}
}

constexpr u64 WATCHES_INITIAL_RESERVE = 0x4000;
constexpr u64 WATCHES_RESERVE_CHUNK = 0x1000;

Expand Down
3 changes: 3 additions & 0 deletions src/video_core/buffer_cache/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ class Buffer {

void Fill(u64 offset, u32 num_bytes, u32 value);

/// Makes a completed download range visible to the CPU.
void Invalidate(u64 offset, u64 size);

public:
VAddr cpu_addr = 0;
bool is_picked{};
Expand Down
49 changes: 49 additions & 0 deletions src/video_core/texture_cache/aliasing.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// SPDX-FileCopyrightText: Copyright 2026 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include <algorithm>
#include <optional>

#include "video_core/texture_cache/aliasing.h"
#include "video_core/texture_cache/host_compatibility.h"
#include "video_core/texture_cache/image_info.h"
#include "video_core/texture_cache/types.h"

namespace VideoCore {

std::optional<Extent3D> GetAliasCopyExtent(const ImageInfo& src, const ImageInfo& dst) {
const bool same_layout =
src.guest_address == dst.guest_address && src.num_bits == dst.num_bits &&
src.num_samples == dst.num_samples && !src.props.is_depth && !dst.props.is_depth &&
src.props.is_block == dst.props.is_block && src.props.is_pow2 == dst.props.is_pow2 &&
src.type == dst.type && src.pitch == dst.pitch && src.tile_mode == dst.tile_mode &&
src.array_mode == dst.array_mode && src.bank_swizzle == dst.bank_swizzle &&
src.alt_tile == dst.alt_tile;
if (!same_layout) {
return std::nullopt;
}

if (src.pixel_format == dst.pixel_format && src.resources.levels == 1 &&
dst.resources.levels == 1 && src.resources.layers >= dst.resources.layers &&
src.size.width >= dst.size.width && src.size.height >= dst.size.height &&
src.size.depth >= dst.size.depth) {
return dst.size;
}

const bool can_copy_intersection = !src.props.is_block && src.resources.levels == 1 &&
dst.resources.levels == 1 && src.resources.layers == 1 &&
dst.resources.layers == 1 && src.size.depth == 1 &&
dst.size.depth == 1 && src.size.width == dst.size.width &&
IsVulkanFormatCompatible(src.pixel_format, dst.pixel_format);
if (!can_copy_intersection) {
return std::nullopt;
}

return Extent3D{
.width = src.size.width,
.height = std::min(src.size.height, dst.size.height),
.depth = 1,
};
}

} // namespace VideoCore
17 changes: 17 additions & 0 deletions src/video_core/texture_cache/aliasing.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: Copyright 2026 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <optional>

#include "video_core/texture_cache/types.h"

namespace VideoCore {

struct ImageInfo;

[[nodiscard]] std::optional<Extent3D> GetAliasCopyExtent(const ImageInfo& src,
const ImageInfo& dst);

} // namespace VideoCore
2 changes: 2 additions & 0 deletions src/video_core/texture_cache/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum ImageFlagBits : u32 {
GpuDirty = 1 << 2, ///< Contents have been modified from the GPU (valid data in buffer cache)
Dirty = MaybeCpuDirty | CpuDirty | GpuDirty,
GpuModified = 1 << 3, ///< Contents have been modified from the GPU
Aliased = 1 << 4, ///< Image shares its guest storage with another compatible image
Registered = 1 << 6, ///< True when the image is registered
Picked = 1 << 7, ///< Temporary flag to mark the image as picked
};
Expand Down Expand Up @@ -176,6 +177,7 @@ struct Image {
BackingImage* backing{};
boost::container::static_vector<u64, 16> mip_hashes{};
u64 image_uid{};
u64 alias_generation{};
u64 lru_id{};
u64 tick_accessed_last{};
u64 hash{};
Expand Down
Loading
Loading