vk: Prefer using native alignment when uploading.

- Allows using fast copy paths and reduces memory and compute footprint
This commit is contained in:
kd-11 2019-09-06 18:38:28 +03:00 committed by kd-11
parent a3a0cb8c17
commit 6aa0b49dbc
3 changed files with 36 additions and 10 deletions

View File

@ -391,16 +391,32 @@ namespace
}
template<typename T>
u32 get_row_pitch_in_block(u16 width_in_block, size_t multiple_constraints_in_byte)
u32 get_row_pitch_in_block(u16 width_in_block, size_t alignment)
{
size_t divided = (width_in_block * sizeof(T) + multiple_constraints_in_byte - 1) / multiple_constraints_in_byte;
return static_cast<u32>(divided * multiple_constraints_in_byte / sizeof(T));
if (const size_t pitch = width_in_block * sizeof(T);
pitch == alignment)
{
return width_in_block;
}
else
{
size_t divided = (pitch + alignment - 1) / alignment;
return static_cast<u32>(divided * alignment / sizeof(T));
}
}
u32 get_row_pitch_in_block(u16 block_size_in_bytes, u16 width_in_block, size_t multiple_constraints_in_byte)
u32 get_row_pitch_in_block(u16 block_size_in_bytes, u16 width_in_block, size_t alignment)
{
size_t divided = (width_in_block * block_size_in_bytes + multiple_constraints_in_byte - 1) / multiple_constraints_in_byte;
return static_cast<u32>(divided * multiple_constraints_in_byte / block_size_in_bytes);
if (const size_t pitch = width_in_block * block_size_in_bytes;
pitch == alignment)
{
return width_in_block;
}
else
{
size_t divided = (pitch + alignment - 1) / alignment;
return static_cast<u32>(divided * alignment / block_size_in_bytes);
}
}
/**

View File

@ -141,7 +141,7 @@ namespace vk
*/
void copy_mipmaped_image_using_buffer(VkCommandBuffer cmd, vk::image* dst_image,
const std::vector<rsx_subresource_layout>& subresource_layout, int format, bool is_swizzled, u16 mipmap_count,
VkImageAspectFlags flags, vk::data_heap &upload_heap, u32 heap_align = 256);
VkImageAspectFlags flags, vk::data_heap &upload_heap, u32 heap_align = 0);
//Other texture management helpers
void change_image_layout(VkCommandBuffer cmd, VkImage image, VkImageLayout current_layout, VkImageLayout new_layout, const VkImageSubresourceRange& range);

View File

@ -519,12 +519,22 @@ namespace vk
texture_uploader_capabilities caps{ true, false, heap_align };
vk::buffer* scratch_buf = nullptr;
u32 scratch_offset = 0;
u32 row_pitch, image_linear_size;
for (const rsx_subresource_layout &layout : subresource_layout)
{
u32 row_pitch = (((layout.width_in_block * block_size_in_bytes) + heap_align - 1) / heap_align) * heap_align;
if (heap_align != 256) verify(HERE), row_pitch == heap_align;
u32 image_linear_size = row_pitch * layout.height_in_block * layout.depth;
if (LIKELY(!heap_align))
{
row_pitch = (layout.pitch_in_block * block_size_in_bytes);
caps.alignment = row_pitch;
}
else
{
row_pitch = (((layout.width_in_block * block_size_in_bytes) + heap_align - 1) / heap_align) * heap_align;
verify(HERE), row_pitch == heap_align;
}
image_linear_size = row_pitch * layout.height_in_block * layout.depth;
// Map with extra padding bytes in case of realignment
size_t offset_in_buffer = upload_heap.alloc<512>(image_linear_size + 8);