Skip to content

Commit

Permalink
Merge branch 'shadps4-emu:main' into Full-BB
Browse files Browse the repository at this point in the history
  • Loading branch information
diegolix29 authored Jan 3, 2025
2 parents 908959d + 8e86713 commit a642e8e
Show file tree
Hide file tree
Showing 18 changed files with 89 additions and 166 deletions.
2 changes: 1 addition & 1 deletion src/video_core/buffer_cache/buffer_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ bool BufferCache::SynchronizeBufferFromImage(Buffer& buffer, VAddr device_addr,
FindFlags::NoCreate | FindFlags::RelaxDim | FindFlags::RelaxFmt | FindFlags::RelaxSize;
TextureCache::BaseDesc desc{};
desc.info.guest_address = device_addr;
desc.info.guest_size_bytes = size;
desc.info.guest_size = size;
const ImageId image_id = texture_cache.FindImage(desc, find_flags);
if (!image_id) {
return false;
Expand Down
16 changes: 8 additions & 8 deletions src/video_core/host_shaders/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# SPDX-License-Identifier: GPL-2.0-or-later

set(SHADER_FILES
detile_m8x1.comp
detile_m8x2.comp
detile_m32x1.comp
detile_m32x2.comp
detile_m32x4.comp
detile_macro8x1.comp
detile_macro32x1.comp
detile_macro32x2.comp
detilers/macro_32bpp.comp
detilers/macro_64bpp.comp
detilers/macro_8bpp.comp
detilers/micro_128bpp.comp
detilers/micro_16bpp.comp
detilers/micro_32bpp.comp
detilers/micro_64bpp.comp
detilers/micro_8bpp.comp
fs_tri.vert
post_process.frag
)
Expand Down
2 changes: 1 addition & 1 deletion src/video_core/renderer_vulkan/vk_presenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ bool Presenter::ShowSplash(Frame* frame /*= nullptr*/) {
VideoCore::Extent3D{splash->GetImageInfo().width, splash->GetImageInfo().height, 1};
info.pitch = splash->GetImageInfo().width;
info.guest_address = VAddr(splash->GetImageData().data());
info.guest_size_bytes = splash->GetImageData().size();
info.guest_size = splash->GetImageData().size();
info.mips_layout.emplace_back(splash->GetImageData().size(),
splash->GetImageInfo().width,
splash->GetImageInfo().height, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/video_core/texture_cache/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ Image::Image(const Vulkan::Instance& instance_, Vulkan::Scheduler& scheduler_,

Vulkan::SetObjectName(instance->GetDevice(), (vk::Image)image, "Image {}x{}x{} {:#x}:{:#x}",
info.size.width, info.size.height, info.size.depth, info.guest_address,
info.guest_size_bytes);
info.guest_size);
}

boost::container::small_vector<vk::ImageMemoryBarrier2, 32> Image::GetBarriers(
Expand Down
2 changes: 1 addition & 1 deletion src/video_core/texture_cache/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct Image {
[[nodiscard]] bool Overlaps(VAddr overlap_cpu_addr, size_t overlap_size) const noexcept {
const VAddr overlap_end = overlap_cpu_addr + overlap_size;
const auto image_addr = info.guest_address;
const auto image_end = info.guest_address + info.guest_size_bytes;
const auto image_end = info.guest_address + info.guest_size;
return image_addr < overlap_end && overlap_cpu_addr < image_end;
}

Expand Down
28 changes: 14 additions & 14 deletions src/video_core/texture_cache/image_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,15 @@ ImageInfo::ImageInfo(const Libraries::VideoOut::BufferAttributeGroup& group,

guest_address = cpu_address;
if (!props.is_tiled) {
guest_size_bytes = pitch * size.height * 4;
guest_size = pitch * size.height * 4;
} else {
if (Config::isNeoMode()) {
guest_size_bytes = pitch * ((size.height + 127) & (~127)) * 4;
guest_size = pitch * ((size.height + 127) & (~127)) * 4;
} else {
guest_size_bytes = pitch * ((size.height + 63) & (~63)) * 4;
guest_size = pitch * ((size.height + 63) & (~63)) * 4;
}
}
mips_layout.emplace_back(guest_size_bytes, pitch, 0);
mips_layout.emplace_back(guest_size, pitch, 0);
}

ImageInfo::ImageInfo(const AmdGpu::Liverpool::ColorBuffer& buffer,
Expand All @@ -279,7 +279,7 @@ ImageInfo::ImageInfo(const AmdGpu::Liverpool::ColorBuffer& buffer,

guest_address = buffer.Address();
const auto color_slice_sz = buffer.GetColorSliceSize();
guest_size_bytes = color_slice_sz * buffer.NumSlices();
guest_size = color_slice_sz * buffer.NumSlices();
mips_layout.emplace_back(color_slice_sz, pitch, 0);
tiling_idx = static_cast<u32>(buffer.attrib.tile_mode_index.Value());
}
Expand All @@ -303,7 +303,7 @@ ImageInfo::ImageInfo(const AmdGpu::Liverpool::DepthBuffer& buffer, u32 num_slice

guest_address = buffer.Address();
const auto depth_slice_sz = buffer.GetDepthSliceSize();
guest_size_bytes = depth_slice_sz * num_slices;
guest_size = depth_slice_sz * num_slices;
mips_layout.emplace_back(depth_slice_sz, pitch, 0);
}

Expand Down Expand Up @@ -339,7 +339,7 @@ ImageInfo::ImageInfo(const AmdGpu::Image& image, const Shader::ImageResource& de
void ImageInfo::UpdateSize() {
mips_layout.clear();
MipInfo mip_info{};
guest_size_bytes = 0;
guest_size = 0;
for (auto mip = 0u; mip < resources.levels; ++mip) {
auto bpp = num_bits;
auto mip_w = pitch >> mip;
Expand Down Expand Up @@ -392,11 +392,11 @@ void ImageInfo::UpdateSize() {
}
}
mip_info.size *= mip_d;
mip_info.offset = guest_size_bytes;
mip_info.offset = guest_size;
mips_layout.emplace_back(mip_info);
guest_size_bytes += mip_info.size;
guest_size += mip_info.size;
}
guest_size_bytes *= resources.layers;
guest_size *= resources.layers;
}

int ImageInfo::IsMipOf(const ImageInfo& info) const {
Expand Down Expand Up @@ -468,18 +468,18 @@ int ImageInfo::IsSliceOf(const ImageInfo& info) const {
}

// Check for size alignment.
const bool slice_size = info.guest_size_bytes / info.resources.layers;
if (guest_size_bytes % slice_size != 0) {
const bool slice_size = info.guest_size / info.resources.layers;
if (guest_size % slice_size != 0) {
return -1;
}

// Ensure that address is aligned too.
const auto addr_diff = guest_address - info.guest_address;
if ((addr_diff % guest_size_bytes) != 0) {
if ((addr_diff % guest_size) != 0) {
return -1;
}

return addr_diff / guest_size_bytes;
return addr_diff / guest_size;
}

} // namespace VideoCore
2 changes: 1 addition & 1 deletion src/video_core/texture_cache/image_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ struct ImageInfo {
};
boost::container::small_vector<MipInfo, 14> mips_layout;
VAddr guest_address{0};
u32 guest_size_bytes{0};
u32 guest_size{0};
u32 tiling_idx{0}; // TODO: merge with existing!

VAddr stencil_addr{0};
Expand Down
34 changes: 19 additions & 15 deletions src/video_core/texture_cache/texture_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

#include <optional>
#include <xxhash.h>

#include "common/assert.h"
#include "common/debug.h"
#include "video_core/buffer_cache/buffer_cache.h"
#include "video_core/page_manager.h"
#include "video_core/renderer_vulkan/vk_instance.h"
Expand Down Expand Up @@ -34,7 +36,7 @@ TextureCache::TextureCache(const Vulkan::Instance& instance_, Vulkan::Scheduler&
Vulkan::SetObjectName(instance.GetDevice(), null_image, "Null Image");
img.flags = ImageFlagBits::Empty;
img.track_addr = img.info.guest_address;
img.track_addr_end = img.info.guest_address + img.info.guest_size_bytes;
img.track_addr_end = img.info.guest_address + img.info.guest_size;

ImageViewInfo view_info;
const auto null_view_id =
Expand All @@ -50,7 +52,7 @@ void TextureCache::MarkAsMaybeDirty(ImageId image_id, Image& image) {
if (image.hash == 0) {
// Initialize hash
const u8* addr = std::bit_cast<u8*>(image.info.guest_address);
image.hash = XXH3_64bits(addr, image.info.guest_size_bytes);
image.hash = XXH3_64bits(addr, image.info.guest_size);
}
image.flags |= ImageFlagBits::MaybeCpuDirty;
UntrackImage(image_id);
Expand All @@ -63,7 +65,7 @@ void TextureCache::InvalidateMemory(VAddr addr, size_t size) {
const auto pages_end = PageManager::GetNextPageAddr(addr + size - 1);
ForEachImageInRegion(pages_start, pages_end - pages_start, [&](ImageId image_id, Image& image) {
const auto image_begin = image.info.guest_address;
const auto image_end = image.info.guest_address + image.info.guest_size_bytes;
const auto image_end = image.info.guest_address + image.info.guest_size;
if (image_begin < end && addr < image_end) {
// Start or end of the modified region is in the image, or the image is entirely within
// the modified region, so the image was definitely accessed by this page fault.
Expand Down Expand Up @@ -201,7 +203,7 @@ std::tuple<ImageId, int, int> TextureCache::ResolveOverlap(const ImageInfo& imag
}

if (image_info.pixel_format != tex_cache_image.info.pixel_format ||
image_info.guest_size_bytes <= tex_cache_image.info.guest_size_bytes) {
image_info.guest_size <= tex_cache_image.info.guest_size) {
auto result_id = merged_image_id ? merged_image_id : cache_image_id;
const auto& result_image = slot_images[result_id];
return {
Expand Down Expand Up @@ -302,7 +304,7 @@ ImageId TextureCache::FindImage(BaseDesc& desc, FindFlags flags) {

std::scoped_lock lock{mutex};
boost::container::small_vector<ImageId, 8> image_ids;
ForEachImageInRegion(info.guest_address, info.guest_size_bytes,
ForEachImageInRegion(info.guest_address, info.guest_size,
[&](ImageId image_id, Image& image) { image_ids.push_back(image_id); });

ImageId image_id{};
Expand All @@ -313,8 +315,7 @@ ImageId TextureCache::FindImage(BaseDesc& desc, FindFlags flags) {
if (cache_image.info.guest_address != info.guest_address) {
continue;
}
if (False(flags & FindFlags::RelaxSize) &&
cache_image.info.guest_size_bytes != info.guest_size_bytes) {
if (False(flags & FindFlags::RelaxSize) && cache_image.info.guest_size != info.guest_size) {
continue;
}
if (False(flags & FindFlags::RelaxDim) && cache_image.info.size != info.size) {
Expand Down Expand Up @@ -455,7 +456,7 @@ ImageView& TextureCache::FindDepthTarget(BaseDesc& desc) {
if (!stencil_id) {
ImageInfo info{};
info.guest_address = desc.info.stencil_addr;
info.guest_size_bytes = desc.info.stencil_size;
info.guest_size = desc.info.stencil_size;
info.size = desc.info.size;
stencil_id = slot_images.insert(instance, scheduler, info);
RegisterImage(stencil_id);
Expand All @@ -468,6 +469,9 @@ ImageView& TextureCache::FindDepthTarget(BaseDesc& desc) {
}

void TextureCache::RefreshImage(Image& image, Vulkan::Scheduler* custom_scheduler /*= nullptr*/) {
RENDERER_TRACE;
TRACE_HINT(fmt::format("{:x}:{:x}", image.info.guest_address, image.info.guest_size));

if (False(image.flags & ImageFlagBits::Dirty)) {
return;
}
Expand Down Expand Up @@ -543,7 +547,7 @@ void TextureCache::RefreshImage(Image& image, Vulkan::Scheduler* custom_schedule

const auto cmdbuf = sched_ptr->CommandBuffer();
const VAddr image_addr = image.info.guest_address;
const size_t image_size = image.info.guest_size_bytes;
const size_t image_size = image.info.guest_size;
const auto [vk_buffer, buf_offset] =
buffer_cache.ObtainViewBuffer(image_addr, image_size, is_gpu_dirty);

Expand Down Expand Up @@ -612,7 +616,7 @@ void TextureCache::RegisterImage(ImageId image_id) {
ASSERT_MSG(False(image.flags & ImageFlagBits::Registered),
"Trying to register an already registered image");
image.flags |= ImageFlagBits::Registered;
ForEachPage(image.info.guest_address, image.info.guest_size_bytes,
ForEachPage(image.info.guest_address, image.info.guest_size,
[this, image_id](u64 page) { page_table[page].push_back(image_id); });
}

Expand All @@ -621,7 +625,7 @@ void TextureCache::UnregisterImage(ImageId image_id) {
ASSERT_MSG(True(image.flags & ImageFlagBits::Registered),
"Trying to unregister an already unregistered image");
image.flags &= ~ImageFlagBits::Registered;
ForEachPage(image.info.guest_address, image.info.guest_size_bytes, [this, image_id](u64 page) {
ForEachPage(image.info.guest_address, image.info.guest_size, [this, image_id](u64 page) {
const auto page_it = page_table.find(page);
if (page_it == nullptr) {
UNREACHABLE_MSG("Unregistering unregistered page=0x{:x}", page << PageShift);
Expand All @@ -640,7 +644,7 @@ void TextureCache::UnregisterImage(ImageId image_id) {
void TextureCache::TrackImage(ImageId image_id) {
auto& image = slot_images[image_id];
const auto image_begin = image.info.guest_address;
const auto image_end = image.info.guest_address + image.info.guest_size_bytes;
const auto image_end = image.info.guest_address + image.info.guest_size;
if (image_begin == image.track_addr && image_end == image.track_addr_end) {
return;
}
Expand All @@ -649,7 +653,7 @@ void TextureCache::TrackImage(ImageId image_id) {
// Re-track the whole image
image.track_addr = image_begin;
image.track_addr_end = image_end;
tracker.UpdatePagesCachedCount(image_begin, image.info.guest_size_bytes, 1);
tracker.UpdatePagesCachedCount(image_begin, image.info.guest_size, 1);
} else {
if (image_begin < image.track_addr) {
TrackImageHead(image_id);
Expand All @@ -674,7 +678,7 @@ void TextureCache::TrackImageHead(ImageId image_id) {

void TextureCache::TrackImageTail(ImageId image_id) {
auto& image = slot_images[image_id];
const auto image_end = image.info.guest_address + image.info.guest_size_bytes;
const auto image_end = image.info.guest_address + image.info.guest_size;
if (image_end == image.track_addr_end) {
return;
}
Expand Down Expand Up @@ -719,7 +723,7 @@ void TextureCache::UntrackImageHead(ImageId image_id) {

void TextureCache::UntrackImageTail(ImageId image_id) {
auto& image = slot_images[image_id];
const auto image_end = image.info.guest_address + image.info.guest_size_bytes;
const auto image_end = image.info.guest_address + image.info.guest_size;
if (!image.IsTracked() || image.track_addr_end < image_end) {
return;
}
Expand Down
Loading

0 comments on commit a642e8e

Please sign in to comment.