vk: Properly calculate cubemap memory size

This commit is contained in:
kd-11 2021-08-13 20:08:52 +03:00 committed by kd-11
parent 53bfc6fa59
commit b5faa8f83c
3 changed files with 7 additions and 4 deletions

View file

@ -75,7 +75,7 @@ namespace vk
}; };
void upload_image(const vk::command_buffer& cmd, vk::image* dst_image, void upload_image(const vk::command_buffer& cmd, vk::image* dst_image,
const std::vector<rsx::subresource_layout>& subresource_layout, int format, bool is_swizzled, u16 mipmap_count, const std::vector<rsx::subresource_layout>& subresource_layout, int format, bool is_swizzled, u16 layer_count,
VkImageAspectFlags flags, vk::data_heap &upload_heap, u32 heap_align, rsx::flags32_t image_setup_flags); VkImageAspectFlags flags, vk::data_heap &upload_heap, u32 heap_align, rsx::flags32_t image_setup_flags);
//Other texture management helpers //Other texture management helpers

View file

@ -884,7 +884,7 @@ namespace vk
} }
void upload_image(const vk::command_buffer& cmd, vk::image* dst_image, void upload_image(const vk::command_buffer& cmd, vk::image* dst_image,
const std::vector<rsx::subresource_layout>& subresource_layout, int format, bool is_swizzled, u16 /*mipmap_count*/, const std::vector<rsx::subresource_layout>& subresource_layout, int format, bool is_swizzled, u16 layer_count,
VkImageAspectFlags flags, vk::data_heap &upload_heap, u32 heap_align, rsx::flags32_t image_setup_flags) VkImageAspectFlags flags, vk::data_heap &upload_heap, u32 heap_align, rsx::flags32_t image_setup_flags)
{ {
const bool requires_depth_processing = (dst_image->aspect() & VK_IMAGE_ASPECT_STENCIL_BIT) || (format == CELL_GCM_TEXTURE_DEPTH16_FLOAT); const bool requires_depth_processing = (dst_image->aspect() & VK_IMAGE_ASPECT_STENCIL_BIT) || (format == CELL_GCM_TEXTURE_DEPTH16_FLOAT);
@ -977,7 +977,8 @@ namespace vk
if (!scratch_buf) if (!scratch_buf)
{ {
// Calculate enough scratch memory. We need 2x the size of layer 0 to fit all the mip levels and an extra 128 bytes per level as alignment overhead. // Calculate enough scratch memory. We need 2x the size of layer 0 to fit all the mip levels and an extra 128 bytes per level as alignment overhead.
auto scratch_buf_size = 128u * ::size32(subresource_layout) + image_linear_size + image_linear_size; const u64 layer_size = (image_linear_size + image_linear_size);
u64 scratch_buf_size = 128u * ::size32(subresource_layout) + (layer_size * layer_count);
if (opt.require_deswizzle) if (opt.require_deswizzle)
{ {
// Double the memory if hw deswizzle is going to be used. // Double the memory if hw deswizzle is going to be used.
@ -988,6 +989,7 @@ namespace vk
if (requires_depth_processing) if (requires_depth_processing)
{ {
// D-S aspect requires a load section that can fit a separated block => D(4) + S(1) // D-S aspect requires a load section that can fit a separated block => D(4) + S(1)
// Due to reverse processing of inputs, only enough space to fit one layer is needed here.
scratch_buf_size += dst_image->width() * dst_image->height() * 5; scratch_buf_size += dst_image->width() * dst_image->height() * 5;
} }

View file

@ -921,7 +921,8 @@ namespace vk
rsx::flags32_t upload_command_flags = initialize_image_layout | rsx::flags32_t upload_command_flags = initialize_image_layout |
(rsx::get_current_renderer()->get_backend_config().supports_asynchronous_compute ? upload_contents_async : upload_contents_inline); (rsx::get_current_renderer()->get_backend_config().supports_asynchronous_compute ? upload_contents_async : upload_contents_inline);
vk::upload_image(cmd, image, subresource_layout, gcm_format, input_swizzled, mipmaps, image->aspect(), const u16 layer_count = (type == rsx::texture_dimension_extended::texture_dimension_cubemap) ? 6 : 1;
vk::upload_image(cmd, image, subresource_layout, gcm_format, input_swizzled, layer_count, image->aspect(),
*m_texture_upload_heap, upload_heap_align_default, upload_command_flags); *m_texture_upload_heap, upload_heap_align_default, upload_command_flags);
vk::leave_uninterruptible(); vk::leave_uninterruptible();