mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-02 22:28:45 +00:00
video_core: buffer_cache: don't copy over the image size
This commit is contained in:
parent
6cce6599b6
commit
673ff8d74a
1 changed files with 14 additions and 7 deletions
|
@ -581,15 +581,22 @@ bool BufferCache::SynchronizeBufferFromImage(Buffer& buffer, VAddr device_addr,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Image& image = texture_cache.GetImage(image_id);
|
Image& image = texture_cache.GetImage(image_id);
|
||||||
|
ASSERT_MSG(buffer.CpuAddr() == image.info.guest_address,
|
||||||
|
"Texel buffer aliases image subresources {} : {}", buffer.CpuAddr(),
|
||||||
|
image.info.guest_address);
|
||||||
boost::container::small_vector<vk::BufferImageCopy, 8> copies;
|
boost::container::small_vector<vk::BufferImageCopy, 8> copies;
|
||||||
u32 offset = buffer.Offset(image.cpu_addr);
|
u32 offset = buffer.Offset(image.cpu_addr);
|
||||||
const u32 num_layers = image.info.resources.layers;
|
const u32 num_layers = image.info.resources.layers;
|
||||||
|
u32 total_size = 0;
|
||||||
for (u32 m = 0; m < image.info.resources.levels; m++) {
|
for (u32 m = 0; m < image.info.resources.levels; m++) {
|
||||||
const u32 width = std::max(image.info.size.width >> m, 1u);
|
const u32 width = std::max(image.info.size.width >> m, 1u);
|
||||||
const u32 height = std::max(image.info.size.height >> m, 1u);
|
const u32 height = std::max(image.info.size.height >> m, 1u);
|
||||||
const u32 depth =
|
const u32 depth =
|
||||||
image.info.props.is_volume ? std::max(image.info.size.depth >> m, 1u) : 1u;
|
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];
|
const auto& [mip_size, mip_pitch, mip_height, mip_ofs] = image.info.mips_layout[m];
|
||||||
|
if (total_size + mip_size > buffer.SizeBytes()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
copies.push_back({
|
copies.push_back({
|
||||||
.bufferOffset = offset,
|
.bufferOffset = offset,
|
||||||
.bufferRowLength = static_cast<u32>(mip_pitch),
|
.bufferRowLength = static_cast<u32>(mip_pitch),
|
||||||
|
@ -604,14 +611,14 @@ bool BufferCache::SynchronizeBufferFromImage(Buffer& buffer, VAddr device_addr,
|
||||||
.imageExtent = {width, height, depth},
|
.imageExtent = {width, height, depth},
|
||||||
});
|
});
|
||||||
offset += mip_ofs * num_layers;
|
offset += mip_ofs * num_layers;
|
||||||
|
total_size += mip_size;
|
||||||
}
|
}
|
||||||
if (!copies.empty()) {
|
ASSERT(!copies.empty()); // If triggered, need to find which layers fit
|
||||||
scheduler.EndRendering();
|
scheduler.EndRendering();
|
||||||
image.Transit(vk::ImageLayout::eTransferSrcOptimal, vk::AccessFlagBits2::eTransferRead, {});
|
image.Transit(vk::ImageLayout::eTransferSrcOptimal, vk::AccessFlagBits2::eTransferRead, {});
|
||||||
const auto cmdbuf = scheduler.CommandBuffer();
|
const auto cmdbuf = scheduler.CommandBuffer();
|
||||||
cmdbuf.copyImageToBuffer(image.image, vk::ImageLayout::eTransferSrcOptimal, buffer.buffer,
|
cmdbuf.copyImageToBuffer(image.image, vk::ImageLayout::eTransferSrcOptimal, buffer.buffer,
|
||||||
copies);
|
copies);
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue