vulkan_copy_staging_to_dynamic - put sync texture to GPU

outside of the function
This commit is contained in:
twinaphex 2020-12-15 07:01:00 +01:00
parent 6b38a7916a
commit d70420a12d
4 changed files with 43 additions and 21 deletions

View File

@ -318,19 +318,15 @@ uint32_t vulkan_find_memory_type_fallback(
device_reqs, host_reqs_second, 0);
}
/* Dynamic texture type should be set to : VULKAN_TEXTURE_DYNAMIC
* Staging texture type should be set to : VULKAN_TEXTURE_STAGING
*/
void vulkan_copy_staging_to_dynamic(vk_t *vk, VkCommandBuffer cmd,
struct vk_texture *dynamic,
struct vk_texture *staging)
{
VkBufferImageCopy region;
retro_assert(dynamic->type == VULKAN_TEXTURE_DYNAMIC);
retro_assert(staging->type == VULKAN_TEXTURE_STAGING);
if ( staging->need_manual_cache_management &&
staging->memory != VK_NULL_HANDLE)
VULKAN_SYNC_TEXTURE_TO_GPU(vk->context->device, staging->memory);
/* We don't have to sync against previous TRANSFER,
* since we observed the completion by fences.
*
@ -340,9 +336,13 @@ void vulkan_copy_staging_to_dynamic(vk_t *vk, VkCommandBuffer cmd,
* We would also need to optionally maintain extra textures due to
* changes in resolution, so this seems like the sanest and
* simplest solution. */
VULKAN_IMAGE_LAYOUT_TRANSITION(cmd, dynamic->image,
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
0, VK_ACCESS_TRANSFER_WRITE_BIT,
VULKAN_IMAGE_LAYOUT_TRANSITION(
cmd,
dynamic->image,
VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
0,
VK_ACCESS_TRANSFER_WRITE_BIT,
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT);
@ -360,12 +360,16 @@ void vulkan_copy_staging_to_dynamic(vk_t *vk, VkCommandBuffer cmd,
region.imageExtent.height = dynamic->height;
region.imageExtent.depth = 1;
vkCmdCopyBufferToImage(cmd,
vkCmdCopyBufferToImage(
cmd,
staging->buffer,
dynamic->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1, &region);
dynamic->image,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1,
&region);
VULKAN_IMAGE_LAYOUT_TRANSITION(cmd,
VULKAN_IMAGE_LAYOUT_TRANSITION(
cmd,
dynamic->image,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,

View File

@ -609,6 +609,22 @@ void vulkan_copy_staging_to_dynamic(vk_t *vk, VkCommandBuffer cmd,
struct vk_texture *dynamic,
struct vk_texture *staging);
#define VULKAN_SYNC_TEXTURE_TO_GPU_COND_PTR(vk, tex) \
if ((tex)->need_manual_cache_management && (tex)->memory != VK_NULL_HANDLE) \
VULKAN_SYNC_TEXTURE_TO_GPU(vk->context->device, (tex)->memory) \
#define VULKAN_SYNC_TEXTURE_TO_GPU_COND_OBJ(vk, tex) \
if ((tex).need_manual_cache_management && (tex).memory != VK_NULL_HANDLE) \
VULKAN_SYNC_TEXTURE_TO_GPU(vk->context->device, (tex).memory) \
#define VULKAN_COPY_STAGING_TO_DYNAMIC_PTR(vk, cmd, dynamic, staging) \
VULKAN_SYNC_TEXTURE_TO_GPU_COND_PTR(vk, staging); \
vulkan_copy_staging_to_dynamic(vk, cmd, dynamic, staging)
#define VULKAN_COPY_STAGING_TO_DYNAMIC_OBJ(vk, cmd, dynamic, staging) \
VULKAN_SYNC_TEXTURE_TO_GPU_COND_PTR(vk, staging); \
vulkan_copy_staging_to_dynamic(vk, cmd, &dynamic, &staging);
/* VBO will be written to here. */
void vulkan_draw_quad(vk_t *vk, const struct vk_draw_quad *quad);

View File

@ -1845,16 +1845,14 @@ static bool vulkan_frame(void *data, const void *frame,
memcpy(dst, src, frame_width * bpp);
}
VULKAN_SYNC_TEXTURE_TO_GPU_COND_OBJ(vk, chain->texture);
/* If we have an optimal texture, copy to that now. */
if (chain->texture_optimal.memory != VK_NULL_HANDLE)
{
vulkan_copy_staging_to_dynamic(vk, vk->cmd,
&chain->texture_optimal, &chain->texture);
}
else if (chain->texture.need_manual_cache_management
&& chain->texture.memory != VK_NULL_HANDLE)
VULKAN_SYNC_TEXTURE_TO_GPU(vk->context->device,
chain->texture.memory);
vk->last_valid_index = frame_index;
}
@ -1966,9 +1964,11 @@ static bool vulkan_frame(void *data, const void *frame,
{
if (vk->menu.dirty[vk->menu.last_index])
{
vulkan_copy_staging_to_dynamic(vk, vk->cmd,
optimal, texture);
vk->menu.dirty[vk->menu.last_index] = false;
VULKAN_SYNC_TEXTURE_TO_GPU_COND_PTR(vk, texture);
vulkan_copy_staging_to_dynamic(vk, vk->cmd,
optimal, texture);
vk->menu.dirty[vk->menu.last_index] = false;
}
}
}

View File

@ -308,6 +308,8 @@ static void vulkan_raster_font_flush(vulkan_raster_t *font)
begin_info.pInheritanceInfo = NULL;
vkBeginCommandBuffer(staging, &begin_info);
VULKAN_SYNC_TEXTURE_TO_GPU_COND_OBJ(font->vk, font->texture);
vulkan_copy_staging_to_dynamic(font->vk, staging,
&font->texture_optimal, &font->texture);