Simplify vulkan_create_texture

This commit is contained in:
twinaphex 2020-12-15 08:00:22 +01:00
parent d55ca599e0
commit 2d588ca4ef

View File

@ -635,7 +635,12 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
tex.format = format;
tex.type = type;
if (initial && (type == VULKAN_TEXTURE_STREAMED || type == VULKAN_TEXTURE_STAGING))
if (initial)
{
switch (type)
{
case VULKAN_TEXTURE_STREAMED:
case VULKAN_TEXTURE_STAGING:
{
unsigned y;
uint8_t *dst = NULL;
@ -656,7 +661,8 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
VULKAN_SYNC_TEXTURE_TO_GPU(vk->context->device, tex.memory);
vkUnmapMemory(device, tex.memory);
}
else if (initial && type == VULKAN_TEXTURE_STATIC)
break;
case VULKAN_TEXTURE_STATIC:
{
VkBufferImageCopy region;
VkCommandBuffer staging;
@ -667,21 +673,26 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
cmd_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
cmd_info.commandBufferCount = 1;
vkAllocateCommandBuffers(vk->context->device, &cmd_info, &staging);
vkAllocateCommandBuffers(vk->context->device,
&cmd_info, &staging);
begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
vkBeginCommandBuffer(staging, &begin_info);
/* If doing mipmapping on upload, keep in general so we can easily do transfers to
/* If doing mipmapping on upload, keep in general
* so we can easily do transfers to
* and transfers from the images without having to
* mess around with lots of extra transitions at per-level granularity.
* mess around with lots of extra transitions at
* per-level granularity.
*/
VULKAN_IMAGE_LAYOUT_TRANSITION(
staging,
tex.image,
VK_IMAGE_LAYOUT_UNDEFINED,
tex.mipmap ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
tex.mipmap
? VK_IMAGE_LAYOUT_GENERAL
: VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
0, VK_ACCESS_TRANSFER_WRITE_BIT,
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT);
@ -696,7 +707,9 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
vkCmdCopyBufferToImage(staging,
tmp.buffer,
tex.image,
tex.mipmap ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
tex.mipmap
? VK_IMAGE_LAYOUT_GENERAL
: VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1, &region);
if (tex.mipmap)
@ -726,7 +739,8 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
/* Only injects execution and memory barriers,
* not actual transition. */
VULKAN_IMAGE_LAYOUT_TRANSITION(
staging, tex.image,
staging,
tex.image,
VK_IMAGE_LAYOUT_GENERAL,
VK_IMAGE_LAYOUT_GENERAL,
VK_ACCESS_TRANSFER_WRITE_BIT,
@ -734,15 +748,21 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT);
vkCmdBlitImage(staging,
tex.image, VK_IMAGE_LAYOUT_GENERAL,
tex.image, VK_IMAGE_LAYOUT_GENERAL,
1, &blit_region, VK_FILTER_LINEAR);
vkCmdBlitImage(
staging,
tex.image,
VK_IMAGE_LAYOUT_GENERAL,
tex.image,
VK_IMAGE_LAYOUT_GENERAL,
1,
&blit_region,
VK_FILTER_LINEAR);
}
/* Complete our texture. */
VULKAN_IMAGE_LAYOUT_TRANSITION(
staging, tex.image,
staging,
tex.image,
VK_IMAGE_LAYOUT_GENERAL,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
VK_ACCESS_TRANSFER_WRITE_BIT,
@ -753,7 +773,8 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
else
{
VULKAN_IMAGE_LAYOUT_TRANSITION(
staging, tex.image,
staging,
tex.image,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
VK_ACCESS_TRANSFER_WRITE_BIT,
@ -786,6 +807,14 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
vk->context->device, &tmp);
tex.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
}
break;
case VULKAN_TEXTURE_DYNAMIC:
case VULKAN_TEXTURE_READBACK:
/* TODO/FIXME - stubs */
break;
}
}
return tex;
}