Skip to content

Commit

Permalink
Fixed userfaultfd path, removed dead code, simplified calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
roamic committed Nov 21, 2024
1 parent d902900 commit bd5c672
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/video_core/page_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ struct PageManager::Impl {
// Notify rasterizer about the fault.
const VAddr addr = msg.arg.pagefault.address;
const VAddr addr_page = Common::AlignDown(addr, PAGESIZE);
rasterizer->InvalidateMemory(addr_page, PAGESIZE);
rasterizer->InvalidateMemory(addr, addr_page, PAGESIZE);
}
}

Expand Down
26 changes: 5 additions & 21 deletions src/video_core/texture_cache/texture_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,8 @@ TextureCache::~TextureCache() = default;
void TextureCache::InvalidateMemory(VAddr addr, VAddr addr_aligned, size_t size) {
std::scoped_lock lock{mutex};
ForEachImageInRegion(addr_aligned, size, [&](ImageId image_id, Image& image) {
const auto addr_begin = addr;
const auto addr_end = addr + size;
const auto image_begin = image.info.guest_address;
const auto image_end = image.info.guest_address + image.info.guest_size_bytes;
if (addr_begin < image_end && image_begin < addr_end) {
if (addr < image_end) {
// Ensure image is reuploaded when accessed again.
image.flags |= ImageFlagBits::CpuDirty;
}
Expand Down Expand Up @@ -392,24 +389,11 @@ void TextureCache::RefreshImage(Image& image, Vulkan::Scheduler* custom_schedule
const u32 height = std::max(image.info.size.height >> m, 1u);
const u32 depth =
image.info.props.is_volume ? std::max(image.info.size.depth >> m, 1u) : 1u;
const auto& [mip_size, mip_pitch, mip_height, mip_ofs] = image.info.mips_layout[m];

// Protect GPU modified resources from accidental CPU reuploads.
const bool is_gpu_modified = True(image.flags & ImageFlagBits::GpuModified);
const bool is_gpu_dirty = True(image.flags & ImageFlagBits::GpuDirty);
if (is_gpu_modified && !is_gpu_dirty) {
const u8* addr = std::bit_cast<u8*>(image.info.guest_address);
const u64 hash = XXH3_64bits(addr + mip_ofs, mip_size);
if (image.mip_hashes[m] == hash) {
continue;
}
image.mip_hashes[m] = hash;
}

const auto& mip = image.info.mips_layout[m];
image_copy.push_back({
.bufferOffset = mip_ofs * num_layers,
.bufferRowLength = static_cast<u32>(mip_pitch),
.bufferImageHeight = static_cast<u32>(mip_height),
.bufferOffset = mip.offset * num_layers,
.bufferRowLength = static_cast<u32>(mip.pitch),
.bufferImageHeight = static_cast<u32>(mip.height),
.imageSubresource{
.aspectMask = image.aspect_mask & ~vk::ImageAspectFlagBits::eStencil,
.mipLevel = m,
Expand Down

0 comments on commit bd5c672

Please sign in to comment.