mirror of https://github.com/RPCS3/rpcs3.git
vk: Tighten some memory bounds checks
This commit is contained in:
parent
e5c831a800
commit
041daab068
|
@ -601,20 +601,20 @@ namespace vk
|
||||||
this->in_offset = config.src_offset;
|
this->in_offset = config.src_offset;
|
||||||
this->out_offset = config.dst_offset;
|
this->out_offset = config.dst_offset;
|
||||||
|
|
||||||
const auto tiled_height = std::min(
|
const auto tile_aligned_height = std::min(
|
||||||
utils::align<u32>(config.image_height, 64),
|
utils::align<u32>(config.image_height, 64),
|
||||||
utils::aligned_div(config.tile_size - config.tile_base_offset, config.tile_pitch)
|
utils::aligned_div(config.tile_size - config.tile_base_offset, config.tile_pitch)
|
||||||
);
|
);
|
||||||
|
|
||||||
if constexpr (Op == RSX_detiler_op::decode)
|
if constexpr (Op == RSX_detiler_op::decode)
|
||||||
{
|
{
|
||||||
this->in_block_length = tiled_height * config.tile_pitch;
|
this->in_block_length = tile_aligned_height * config.tile_pitch;
|
||||||
this->out_block_length = config.image_height * config.image_pitch;
|
this->out_block_length = config.image_height * config.image_pitch;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->in_block_length = config.image_height * config.image_pitch;
|
this->in_block_length = config.image_height * config.image_pitch;
|
||||||
this->out_block_length = tiled_height* config.tile_pitch;
|
this->out_block_length = tile_aligned_height * config.tile_pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto get_prime_factor = [](u32 pitch) -> std::pair<u32, u32>
|
auto get_prime_factor = [](u32 pitch) -> std::pair<u32, u32>
|
||||||
|
@ -650,7 +650,7 @@ namespace vk
|
||||||
params.tile_pitch = config.tile_pitch;
|
params.tile_pitch = config.tile_pitch;
|
||||||
params.tile_bank = config.bank;
|
params.tile_bank = config.bank;
|
||||||
params.image_width = config.image_width;
|
params.image_width = config.image_width;
|
||||||
params.image_height = tiled_height;
|
params.image_height = (Op == RSX_detiler_op::decode) ? tile_aligned_height : config.image_height;
|
||||||
params.image_pitch = config.image_pitch;
|
params.image_pitch = config.image_pitch;
|
||||||
params.image_bpp = config.image_bpp;
|
params.image_bpp = config.image_bpp;
|
||||||
set_parameters(cmd);
|
set_parameters(cmd);
|
||||||
|
|
|
@ -115,7 +115,6 @@ namespace vk
|
||||||
|
|
||||||
if (require_gpu_transform)
|
if (require_gpu_transform)
|
||||||
{
|
{
|
||||||
auto section_length = valid_range.length();
|
|
||||||
const auto transfer_pitch = real_pitch;
|
const auto transfer_pitch = real_pitch;
|
||||||
const auto task_length = transfer_pitch * src_area.height();
|
const auto task_length = transfer_pitch * src_area.height();
|
||||||
auto working_buffer_length = calculate_working_buffer_size(task_length, src->aspect());
|
auto working_buffer_length = calculate_working_buffer_size(task_length, src->aspect());
|
||||||
|
@ -251,25 +250,28 @@ namespace vk
|
||||||
real_pitch = tiled_region.tile->pitch; // We're always copying the full image. In case of partials we're "filling in" blocks, not doing partial 2D copies.
|
real_pitch = tiled_region.tile->pitch; // We're always copying the full image. In case of partials we're "filling in" blocks, not doing partial 2D copies.
|
||||||
require_rw_barrier = true;
|
require_rw_barrier = true;
|
||||||
|
|
||||||
#if 0
|
#if VISUALIZE_GPU_TILING
|
||||||
vk::insert_buffer_memory_barrier(cmd, working_buffer->value, result_offset, working_buffer_length,
|
if (g_cfg.video.renderdoc_compatiblity)
|
||||||
VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
{
|
||||||
VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT);
|
vk::insert_buffer_memory_barrier(cmd, working_buffer->value, result_offset, working_buffer_length,
|
||||||
|
VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||||
|
VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT);
|
||||||
|
|
||||||
// Debug write
|
// Debug write
|
||||||
auto scratch_img = vk::get_typeless_helper(VK_FORMAT_B8G8R8A8_UNORM, RSX_FORMAT_CLASS_COLOR, tiled_region.tile->pitch / 4, 768);
|
auto scratch_img = vk::get_typeless_helper(VK_FORMAT_B8G8R8A8_UNORM, RSX_FORMAT_CLASS_COLOR, tiled_region.tile->pitch / 4, 768);
|
||||||
scratch_img->change_layout(cmd, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
scratch_img->change_layout(cmd, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||||
|
|
||||||
VkBufferImageCopy dbg_copy{};
|
VkBufferImageCopy dbg_copy{};
|
||||||
dbg_copy.bufferOffset = config.dst_offset;
|
dbg_copy.bufferOffset = config.dst_offset;
|
||||||
dbg_copy.imageExtent.width = width;
|
dbg_copy.imageExtent.width = width;
|
||||||
dbg_copy.imageExtent.height = height;
|
dbg_copy.imageExtent.height = height;
|
||||||
dbg_copy.imageExtent.depth = 1;
|
dbg_copy.imageExtent.depth = 1;
|
||||||
dbg_copy.bufferRowLength = tiled_region.tile->pitch / 4;
|
dbg_copy.bufferRowLength = tiled_region.tile->pitch / 4;
|
||||||
dbg_copy.imageSubresource = { .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, .mipLevel = 0, .baseArrayLayer = 0, .layerCount = 1 };
|
dbg_copy.imageSubresource = { .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, .mipLevel = 0, .baseArrayLayer = 0, .layerCount = 1 };
|
||||||
vk::copy_buffer_to_image(cmd, working_buffer, scratch_img, dbg_copy);
|
vk::copy_buffer_to_image(cmd, working_buffer, scratch_img, dbg_copy);
|
||||||
|
|
||||||
scratch_img->change_layout(cmd, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
scratch_img->change_layout(cmd, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -277,7 +279,7 @@ namespace vk
|
||||||
|
|
||||||
if (require_rw_barrier)
|
if (require_rw_barrier)
|
||||||
{
|
{
|
||||||
vk::insert_buffer_memory_barrier(cmd, working_buffer->value, result_offset, working_buffer_length,
|
vk::insert_buffer_memory_barrier(cmd, working_buffer->value, result_offset, dma_sync_region.length(),
|
||||||
VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||||
VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT);
|
VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT);
|
||||||
}
|
}
|
||||||
|
@ -289,7 +291,7 @@ namespace vk
|
||||||
VkBufferCopy copy = {};
|
VkBufferCopy copy = {};
|
||||||
copy.srcOffset = result_offset;
|
copy.srcOffset = result_offset;
|
||||||
copy.dstOffset = dma_mapping.first;
|
copy.dstOffset = dma_mapping.first;
|
||||||
copy.size = section_length;
|
copy.size = dma_sync_region.length();
|
||||||
vkCmdCopyBuffer(cmd, working_buffer->value, dma_mapping.second->value, 1, ©);
|
vkCmdCopyBuffer(cmd, working_buffer->value, dma_mapping.second->value, 1, ©);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue