mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-07 07:21:25 +12:00
vk: Prefer using native alignment when uploading.
- Allows using fast copy paths and reduces memory and compute footprint
This commit is contained in:
parent
a3a0cb8c17
commit
6aa0b49dbc
3 changed files with 36 additions and 10 deletions
|
@ -391,16 +391,32 @@ namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
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;
|
if (const size_t pitch = width_in_block * sizeof(T);
|
||||||
return static_cast<u32>(divided * multiple_constraints_in_byte / 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;
|
if (const size_t pitch = width_in_block * block_size_in_bytes;
|
||||||
return static_cast<u32>(divided * multiple_constraints_in_byte / 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -141,7 +141,7 @@ namespace vk
|
||||||
*/
|
*/
|
||||||
void copy_mipmaped_image_using_buffer(VkCommandBuffer cmd, vk::image* dst_image,
|
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,
|
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
|
//Other texture management helpers
|
||||||
void change_image_layout(VkCommandBuffer cmd, VkImage image, VkImageLayout current_layout, VkImageLayout new_layout, const VkImageSubresourceRange& range);
|
void change_image_layout(VkCommandBuffer cmd, VkImage image, VkImageLayout current_layout, VkImageLayout new_layout, const VkImageSubresourceRange& range);
|
||||||
|
|
|
@ -519,12 +519,22 @@ namespace vk
|
||||||
texture_uploader_capabilities caps{ true, false, heap_align };
|
texture_uploader_capabilities caps{ true, false, heap_align };
|
||||||
vk::buffer* scratch_buf = nullptr;
|
vk::buffer* scratch_buf = nullptr;
|
||||||
u32 scratch_offset = 0;
|
u32 scratch_offset = 0;
|
||||||
|
u32 row_pitch, image_linear_size;
|
||||||
|
|
||||||
for (const rsx_subresource_layout &layout : subresource_layout)
|
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 (LIKELY(!heap_align))
|
||||||
if (heap_align != 256) verify(HERE), row_pitch == heap_align;
|
{
|
||||||
u32 image_linear_size = row_pitch * layout.height_in_block * layout.depth;
|
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
|
// Map with extra padding bytes in case of realignment
|
||||||
size_t offset_in_buffer = upload_heap.alloc<512>(image_linear_size + 8);
|
size_t offset_in_buffer = upload_heap.alloc<512>(image_linear_size + 8);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue