(Vulkan) Simplify vulkan_create_texture

This commit is contained in:
libretroadmin 2022-05-18 23:19:58 +02:00
parent 8881020b75
commit 241d6eb901
1 changed files with 22 additions and 37 deletions

View File

@ -677,6 +677,10 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
{ {
VkBufferImageCopy region; VkBufferImageCopy region;
VkCommandBuffer staging; VkCommandBuffer staging;
enum VkImageLayout layout_fmt =
tex.mipmap
? VK_IMAGE_LAYOUT_GENERAL
: VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
struct vk_texture tmp = vulkan_create_texture(vk, NULL, struct vk_texture tmp = vulkan_create_texture(vk, NULL,
width, height, format, initial, NULL, VULKAN_TEXTURE_STAGING); width, height, format, initial, NULL, VULKAN_TEXTURE_STAGING);
@ -701,9 +705,7 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
staging, staging,
tex.image, tex.image,
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_UNDEFINED,
tex.mipmap layout_fmt,
? VK_IMAGE_LAYOUT_GENERAL
: VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
0, VK_ACCESS_TRANSFER_WRITE_BIT, 0, VK_ACCESS_TRANSFER_WRITE_BIT,
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT); VK_PIPELINE_STAGE_TRANSFER_BIT);
@ -715,13 +717,8 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
region.imageExtent.height = height; region.imageExtent.height = height;
region.imageExtent.depth = 1; region.imageExtent.depth = 1;
vkCmdCopyBufferToImage(staging, vkCmdCopyBufferToImage(staging, tmp.buffer,
tmp.buffer, tex.image, layout_fmt, 1, &region);
tex.image,
tex.mipmap
? VK_IMAGE_LAYOUT_GENERAL
: VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1, &region);
if (tex.mipmap) if (tex.mipmap)
{ {
@ -769,30 +766,18 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
&blit_region, &blit_region,
VK_FILTER_LINEAR); VK_FILTER_LINEAR);
} }
}
/* Complete our texture. */ /* Complete our texture. */
VULKAN_IMAGE_LAYOUT_TRANSITION( VULKAN_IMAGE_LAYOUT_TRANSITION(
staging, staging,
tex.image, tex.image,
VK_IMAGE_LAYOUT_GENERAL, layout_fmt,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_TRANSFER_WRITE_BIT,
VK_ACCESS_SHADER_READ_BIT, VK_ACCESS_SHADER_READ_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
}
else
{
VULKAN_IMAGE_LAYOUT_TRANSITION(
staging,
tex.image,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
VK_ACCESS_TRANSFER_WRITE_BIT,
VK_ACCESS_SHADER_READ_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
}
vkEndCommandBuffer(staging); vkEndCommandBuffer(staging);
submit_info.commandBufferCount = 1; submit_info.commandBufferCount = 1;