mirror of
https://github.com/libretro/RetroArch
synced 2025-02-28 12:40:23 +00:00
Go through more function pointers
This commit is contained in:
parent
dfde6f833a
commit
0e91bb6852
gfx
@ -96,10 +96,11 @@ uint32_t vulkan_find_memory_type_fallback(
|
||||
}
|
||||
|
||||
void vulkan_map_persistent_texture(
|
||||
struct vulkan_context_fp *vkcfp,
|
||||
VkDevice device,
|
||||
struct vk_texture *texture)
|
||||
{
|
||||
vkMapMemory(device, texture->memory, texture->offset,
|
||||
VKFUNC(vkMapMemory)(device, texture->memory, texture->offset,
|
||||
texture->size, 0, &texture->mapped);
|
||||
}
|
||||
|
||||
@ -355,8 +356,9 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
|
||||
tex.memory_type = old->memory_type;
|
||||
|
||||
if (old->mapped)
|
||||
vkUnmapMemory(device, old->memory);
|
||||
old->memory = VK_NULL_HANDLE;
|
||||
VKFUNC(vkUnmapMemory)(device, old->memory);
|
||||
|
||||
old->memory = VK_NULL_HANDLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -419,7 +421,7 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
|
||||
for (y = 0; y < tex.height; y++, dst += tex.stride, src += stride)
|
||||
memcpy(dst, src, width * bpp);
|
||||
|
||||
vkUnmapMemory(device, tex.memory);
|
||||
VKFUNC(vkUnmapMemory)(device, tex.memory);
|
||||
}
|
||||
else if (initial && type == VULKAN_TEXTURE_STATIC)
|
||||
{
|
||||
@ -485,16 +487,20 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
|
||||
slock_unlock(vk->context->queue_lock);
|
||||
|
||||
vkFreeCommandBuffers(vk->context->device, vk->staging_pool, 1, &staging);
|
||||
vulkan_destroy_texture(vk->context->device, &tmp);
|
||||
vulkan_destroy_texture(&vk->context->fp,
|
||||
vk->context->device, &tmp);
|
||||
tex.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||
}
|
||||
return tex;
|
||||
}
|
||||
|
||||
void vulkan_destroy_texture(VkDevice device, struct vk_texture *tex)
|
||||
void vulkan_destroy_texture(
|
||||
struct vulkan_context_fp *vkcfp,
|
||||
VkDevice device,
|
||||
struct vk_texture *tex)
|
||||
{
|
||||
if (tex->mapped)
|
||||
vkUnmapMemory(device, tex->memory);
|
||||
VKFUNC(vkUnmapMemory)(device, tex->memory);
|
||||
vkFreeMemory(device, tex->memory, NULL);
|
||||
vkDestroyImageView(device, tex->view, NULL);
|
||||
vkDestroyImage(device, tex->image, NULL);
|
||||
@ -788,9 +794,12 @@ struct vk_buffer vulkan_create_buffer(const struct vulkan_context *context,
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void vulkan_destroy_buffer(VkDevice device, struct vk_buffer *buffer)
|
||||
void vulkan_destroy_buffer(
|
||||
struct vulkan_context_fp *vkcfp,
|
||||
VkDevice device,
|
||||
struct vk_buffer *buffer)
|
||||
{
|
||||
vkUnmapMemory(device, buffer->memory);
|
||||
VKFUNC(vkUnmapMemory)(device, buffer->memory);
|
||||
vkFreeMemory(device, buffer->memory, NULL);
|
||||
vkDestroyBuffer(device, buffer->buffer, NULL);
|
||||
memset(buffer, 0, sizeof(*buffer));
|
||||
@ -992,13 +1001,16 @@ bool vulkan_buffer_chain_alloc(const struct vulkan_context *context,
|
||||
return true;
|
||||
}
|
||||
|
||||
void vulkan_buffer_chain_free(VkDevice device, struct vk_buffer_chain *chain)
|
||||
void vulkan_buffer_chain_free(
|
||||
struct vulkan_context_fp *vkcfp,
|
||||
VkDevice device,
|
||||
struct vk_buffer_chain *chain)
|
||||
{
|
||||
struct vk_buffer_node *node = chain->head;
|
||||
while (node)
|
||||
{
|
||||
struct vk_buffer_node *next = node->next;
|
||||
vulkan_destroy_buffer(device, &node->buffer);
|
||||
vulkan_destroy_buffer(vkcfp, device, &node->buffer);
|
||||
|
||||
free(node);
|
||||
node = next;
|
||||
@ -1126,6 +1138,10 @@ bool vulkan_context_init(gfx_ctx_vulkan_data_t *vk,
|
||||
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CmdBindDescriptorSets);
|
||||
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, UpdateDescriptorSets);
|
||||
|
||||
/* Memory allocation */
|
||||
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, MapMemory);
|
||||
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, UnmapMemory);
|
||||
|
||||
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CmdSetScissor);
|
||||
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CmdSetViewport);
|
||||
|
||||
|
@ -165,7 +165,13 @@ typedef struct vulkan_context
|
||||
PFN_vkCmdBindDescriptorSets vkCmdBindDescriptorSets;
|
||||
PFN_vkUpdateDescriptorSets vkUpdateDescriptorSets;
|
||||
|
||||
/* Framebuffers */
|
||||
PFN_vkCreateFramebuffer vkCreateFramebuffer;
|
||||
|
||||
/* Memory allocation */
|
||||
PFN_vkMapMemory vkMapMemory;
|
||||
PFN_vkUnmapMemory vkUnmapMemory;
|
||||
|
||||
PFN_vkCreateCommandPool vkCreateCommandPool;
|
||||
|
||||
PFN_vkCreateInstance vkCreateInstance;
|
||||
@ -331,7 +337,9 @@ bool vulkan_buffer_chain_alloc(const struct vulkan_context *context,
|
||||
struct vk_buffer_chain *chain, size_t size,
|
||||
struct vk_buffer_range *range);
|
||||
|
||||
void vulkan_buffer_chain_free(VkDevice device,
|
||||
void vulkan_buffer_chain_free(
|
||||
struct vulkan_context_fp *vkcfp,
|
||||
VkDevice device,
|
||||
struct vk_buffer_chain *chain);
|
||||
|
||||
|
||||
@ -520,8 +528,15 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
|
||||
|
||||
void vulkan_transition_texture(vk_t *vk, struct vk_texture *texture);
|
||||
|
||||
void vulkan_map_persistent_texture(VkDevice device, struct vk_texture *tex);
|
||||
void vulkan_destroy_texture(VkDevice device, struct vk_texture *tex);
|
||||
void vulkan_map_persistent_texture(
|
||||
struct vulkan_context_fp *vkcfp,
|
||||
VkDevice device,
|
||||
struct vk_texture *texture);
|
||||
|
||||
void vulkan_destroy_texture(
|
||||
struct vulkan_context_fp *vkcfp,
|
||||
VkDevice device,
|
||||
struct vk_texture *tex);
|
||||
|
||||
void vulkan_copy_staging_to_dynamic(vk_t *vk, VkCommandBuffer cmd,
|
||||
struct vk_texture *dynamic,
|
||||
@ -588,7 +603,11 @@ static INLINE void vulkan_write_quad_vbo(struct vk_vertex *pv,
|
||||
|
||||
struct vk_buffer vulkan_create_buffer(const struct vulkan_context *context,
|
||||
size_t size, VkBufferUsageFlags usage);
|
||||
void vulkan_destroy_buffer(VkDevice device, struct vk_buffer *buffer);
|
||||
|
||||
void vulkan_destroy_buffer(
|
||||
struct vulkan_context_fp *vkcfp,
|
||||
VkDevice device,
|
||||
struct vk_buffer *buffer);
|
||||
|
||||
VkDescriptorSet vulkan_descriptor_manager_alloc(
|
||||
struct vulkan_context_fp *vkcfp,
|
||||
|
@ -441,8 +441,10 @@ static void vulkan_deinit_buffers(vk_t *vk)
|
||||
unsigned i;
|
||||
for (i = 0; i < vk->num_swapchain_images; i++)
|
||||
{
|
||||
vulkan_buffer_chain_free(vk->context->device, &vk->swapchain[i].vbo);
|
||||
vulkan_buffer_chain_free(vk->context->device, &vk->swapchain[i].ubo);
|
||||
vulkan_buffer_chain_free(&vk->context->fp,
|
||||
vk->context->device, &vk->swapchain[i].vbo);
|
||||
vulkan_buffer_chain_free(&vk->context->fp,
|
||||
vk->context->device, &vk->swapchain[i].ubo);
|
||||
}
|
||||
}
|
||||
|
||||
@ -486,7 +488,9 @@ static void vulkan_init_textures(vk_t *vk)
|
||||
vk->swapchain[i].texture = vulkan_create_texture(vk, NULL,
|
||||
vk->tex_w, vk->tex_h, vk->tex_fmt,
|
||||
NULL, NULL, VULKAN_TEXTURE_STREAMED);
|
||||
vulkan_map_persistent_texture(vk->context->device,
|
||||
|
||||
vulkan_map_persistent_texture(&vk->context->fp,
|
||||
vk->context->device,
|
||||
&vk->swapchain[i].texture);
|
||||
|
||||
if (vk->swapchain[i].texture.type == VULKAN_TEXTURE_STAGING)
|
||||
@ -507,9 +511,12 @@ static void vulkan_deinit_textures(vk_t *vk)
|
||||
for (i = 0; i < vk->num_swapchain_images; i++)
|
||||
{
|
||||
if (vk->swapchain[i].texture.memory != VK_NULL_HANDLE)
|
||||
vulkan_destroy_texture(vk->context->device, &vk->swapchain[i].texture);
|
||||
vulkan_destroy_texture(&vk->context->fp,
|
||||
vk->context->device, &vk->swapchain[i].texture);
|
||||
|
||||
if (vk->swapchain[i].texture_optimal.memory != VK_NULL_HANDLE)
|
||||
vulkan_destroy_texture(vk->context->device, &vk->swapchain[i].texture_optimal);
|
||||
vulkan_destroy_texture(&vk->context->fp,
|
||||
vk->context->device, &vk->swapchain[i].texture_optimal);
|
||||
}
|
||||
}
|
||||
|
||||
@ -687,15 +694,18 @@ static void vulkan_deinit_static_resources(vk_t *vk)
|
||||
unsigned i;
|
||||
vkDestroyPipelineCache(vk->context->device,
|
||||
vk->pipelines.cache, NULL);
|
||||
vulkan_destroy_texture(vk->context->device,
|
||||
vulkan_destroy_texture(&vk->context->fp,
|
||||
vk->context->device,
|
||||
&vk->display.blank_texture);
|
||||
|
||||
vkDestroyCommandPool(vk->context->device, vk->staging_pool, NULL);
|
||||
free(vk->hw.cmd);
|
||||
free(vk->hw.wait_dst_stages);
|
||||
|
||||
for (i = 0; i < VULKAN_MAX_SWAPCHAIN_IMAGES; i++)
|
||||
if (vk->readback.staging[i].memory != VK_NULL_HANDLE)
|
||||
vulkan_destroy_texture(vk->context->device,
|
||||
vulkan_destroy_texture(&vk->context->fp,
|
||||
vk->context->device,
|
||||
&vk->readback.staging[i]);
|
||||
}
|
||||
|
||||
@ -715,9 +725,11 @@ static void vulkan_deinit_menu(vk_t *vk)
|
||||
for (i = 0; i < VULKAN_MAX_SWAPCHAIN_IMAGES; i++)
|
||||
{
|
||||
if (vk->menu.textures[i].memory)
|
||||
vulkan_destroy_texture(vk->context->device, &vk->menu.textures[i]);
|
||||
vulkan_destroy_texture(&vk->context->fp,
|
||||
vk->context->device, &vk->menu.textures[i]);
|
||||
if (vk->menu.textures_optimal[i].memory)
|
||||
vulkan_destroy_texture(vk->context->device, &vk->menu.textures_optimal[i]);
|
||||
vulkan_destroy_texture(&vk->context->fp,
|
||||
vk->context->device, &vk->menu.textures_optimal[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1398,12 +1410,17 @@ static bool vulkan_frame(void *data, const void *frame,
|
||||
{
|
||||
chain->texture = vulkan_create_texture(vk, &chain->texture,
|
||||
frame_width, frame_height, chain->texture.format, NULL, NULL,
|
||||
chain->texture_optimal.memory ? VULKAN_TEXTURE_STAGING : VULKAN_TEXTURE_STREAMED);
|
||||
vulkan_map_persistent_texture(vk->context->device, &chain->texture);
|
||||
chain->texture_optimal.memory
|
||||
? VULKAN_TEXTURE_STAGING : VULKAN_TEXTURE_STREAMED);
|
||||
|
||||
vulkan_map_persistent_texture(&vk->context->fp,
|
||||
vk->context->device, &chain->texture);
|
||||
|
||||
if (chain->texture.type == VULKAN_TEXTURE_STAGING)
|
||||
{
|
||||
chain->texture_optimal = vulkan_create_texture(vk, &chain->texture_optimal,
|
||||
chain->texture_optimal = vulkan_create_texture(
|
||||
vk,
|
||||
&chain->texture_optimal,
|
||||
frame_width, frame_height, chain->texture_optimal.format,
|
||||
NULL, NULL, VULKAN_TEXTURE_DYNAMIC);
|
||||
}
|
||||
@ -1740,7 +1757,8 @@ static bool vulkan_get_current_sw_framebuffer(void *data,
|
||||
chain->texture = vulkan_create_texture(vk, &chain->texture,
|
||||
framebuffer->width, framebuffer->height, chain->texture.format,
|
||||
NULL, NULL, VULKAN_TEXTURE_STREAMED);
|
||||
vulkan_map_persistent_texture(vk->context->device, &chain->texture);
|
||||
vulkan_map_persistent_texture(&vk->context->fp,
|
||||
vk->context->device, &chain->texture);
|
||||
|
||||
if (chain->texture.type == VULKAN_TEXTURE_STAGING)
|
||||
{
|
||||
@ -1881,7 +1899,9 @@ static void vulkan_unload_texture(void *data, uintptr_t handle)
|
||||
/* TODO: We really want to defer this deletion instead,
|
||||
* but this will do for now. */
|
||||
VKFUNC(vkQueueWaitIdle)(vk->context->queue);
|
||||
vulkan_destroy_texture(vk->context->device, texture);
|
||||
vulkan_destroy_texture(
|
||||
&vk->context->fp,
|
||||
vk->context->device, texture);
|
||||
free(texture);
|
||||
}
|
||||
|
||||
@ -1982,7 +2002,9 @@ static bool vulkan_read_viewport(void *data, uint8_t *buffer)
|
||||
VKFUNC(vkQueueWaitIdle)(vk->context->queue);
|
||||
|
||||
if (!staging->mapped)
|
||||
vulkan_map_persistent_texture(vk->context->device, staging);
|
||||
vulkan_map_persistent_texture(
|
||||
&vk->context->fp,
|
||||
vk->context->device, staging);
|
||||
|
||||
{
|
||||
unsigned x, y;
|
||||
@ -2001,7 +2023,9 @@ static bool vulkan_read_viewport(void *data, uint8_t *buffer)
|
||||
}
|
||||
}
|
||||
}
|
||||
vulkan_destroy_texture(vk->context->device, staging);
|
||||
vulkan_destroy_texture(
|
||||
&vk->context->fp,
|
||||
vk->context->device, staging);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -2036,7 +2060,9 @@ static void vulkan_overlay_free(vk_t *vk)
|
||||
free(vk->overlay.vertex);
|
||||
for (i = 0; i < vk->overlay.count; i++)
|
||||
if (vk->overlay.images[i].memory != VK_NULL_HANDLE)
|
||||
vulkan_destroy_texture(vk->context->device,
|
||||
vulkan_destroy_texture(
|
||||
&vk->context->fp,
|
||||
vk->context->device,
|
||||
&vk->overlay.images[i]);
|
||||
|
||||
memset(&vk->overlay, 0, sizeof(vk->overlay));
|
||||
|
@ -79,7 +79,8 @@ static void vulkan_raster_font_free_font(void *data)
|
||||
font->font_driver->free(font->font_data);
|
||||
|
||||
VKFUNC(vkQueueWaitIdle)(font->vk->context->queue);
|
||||
vulkan_destroy_texture(font->vk->context->device, &font->texture);
|
||||
vulkan_destroy_texture(vkcfp,
|
||||
font->vk->context->device, &font->texture);
|
||||
|
||||
free(font);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user