Reimplement function pointers

This commit is contained in:
twinaphex 2016-03-01 02:21:53 +01:00
parent 937230564d
commit b79edb6095
6 changed files with 51 additions and 156 deletions

View File

@ -27,7 +27,7 @@
#define VK_STRUCTURE_TYPE_DMA_BUF_IMAGE_CREATE_INFO_INTEL 1024 #define VK_STRUCTURE_TYPE_DMA_BUF_IMAGE_CREATE_INFO_INTEL 1024
#endif #endif
#define VKFUNC(sym) (vkcfp->sym) #define VKFUNC(sym) (vkcfp.sym)
#define VK_PROTOTYPES #define VK_PROTOTYPES
@ -255,4 +255,6 @@ typedef struct vulkan_context_fp
#endif #endif
} vulkan_context_fp_t; } vulkan_context_fp_t;
extern vulkan_context_fp_t vkcfp;
#endif #endif

View File

@ -26,31 +26,31 @@
#include "vulkan_common.h" #include "vulkan_common.h"
#ifdef HAVE_VULKAN vulkan_context_fp_t vkcfp;
static dylib_t vulkan_library; static dylib_t vulkan_library;
static VkInstance cached_instance; static VkInstance cached_instance;
static VkDevice cached_device; static VkDevice cached_device;
#endif
#define VKSYM(vk, entrypoint) do { \ #define VKSYM(vk, entrypoint) do { \
vk->context.fp.vk##entrypoint = (PFN_vk##entrypoint) dylib_proc(vulkan_library, "vk"#entrypoint);\ vkcfp.vk##entrypoint = (PFN_vk##entrypoint) dylib_proc(vulkan_library, "vk"#entrypoint);\
if (vk->context.fp.vk##entrypoint == NULL) { \ if (vkcfp.vk##entrypoint == NULL) { \
RARCH_ERR("vkGetInstanceProcAddr failed to find vk%s\n", #entrypoint); \ RARCH_ERR("vkGetInstanceProcAddr failed to find vk%s\n", #entrypoint); \
return false; \ return false; \
} \ } \
} while(0) } while(0)
#define VK_GET_INSTANCE_PROC_ADDR(vk, inst, entrypoint) do { \ #define VK_GET_INSTANCE_PROC_ADDR(vk, inst, entrypoint) do { \
vk->context.fp.vk##entrypoint = (PFN_vk##entrypoint) vk->context.fp.vkGetInstanceProcAddr(inst, "vk"#entrypoint); \ vkcfp.vk##entrypoint = (PFN_vk##entrypoint) vkcfp.vkGetInstanceProcAddr(inst, "vk"#entrypoint); \
if (vk->context.fp.vk##entrypoint == NULL) { \ if (vkcfp.vk##entrypoint == NULL) { \
RARCH_ERR("vkGetInstanceProcAddr failed to find vk%s\n", #entrypoint); \ RARCH_ERR("vkGetInstanceProcAddr failed to find vk%s\n", #entrypoint); \
return false; \ return false; \
} \ } \
} while(0) } while(0)
#define VK_GET_DEVICE_PROC_ADDR(vk, dev, entrypoint) do { \ #define VK_GET_DEVICE_PROC_ADDR(vk, dev, entrypoint) do { \
vk->context.fp.vk##entrypoint = (PFN_vk##entrypoint) vk->context.fp.vkGetDeviceProcAddr(dev, "vk" #entrypoint); \ vkcfp.vk##entrypoint = (PFN_vk##entrypoint) vkcfp.vkGetDeviceProcAddr(dev, "vk" #entrypoint); \
if (vk->context.fp.vk##entrypoint == NULL) { \ if (vkcfp.vk##entrypoint == NULL) { \
RARCH_ERR("vkGetDeviceProcAddr failed to find vk%s\n", #entrypoint); \ RARCH_ERR("vkGetDeviceProcAddr failed to find vk%s\n", #entrypoint); \
return false; \ return false; \
} \ } \
@ -96,7 +96,6 @@ uint32_t vulkan_find_memory_type_fallback(
} }
void vulkan_map_persistent_texture( void vulkan_map_persistent_texture(
struct vulkan_context_fp *vkcfp,
VkDevice device, VkDevice device,
struct vk_texture *texture) struct vk_texture *texture)
{ {
@ -109,8 +108,6 @@ void vulkan_copy_staging_to_dynamic(vk_t *vk, VkCommandBuffer cmd,
struct vk_texture *staging) struct vk_texture *staging)
{ {
VkImageCopy region; VkImageCopy region;
struct vulkan_context_fp *vkcfp =
vk->context ? (struct vulkan_context_fp*)&vk->context->fp : NULL;
retro_assert(dynamic->type == VULKAN_TEXTURE_DYNAMIC); retro_assert(dynamic->type == VULKAN_TEXTURE_DYNAMIC);
retro_assert(staging->type == VULKAN_TEXTURE_STAGING); retro_assert(staging->type == VULKAN_TEXTURE_STAGING);
@ -207,8 +204,6 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
struct vk_texture tex; struct vk_texture tex;
VkMemoryRequirements mem_reqs; VkMemoryRequirements mem_reqs;
VkSubresourceLayout layout; VkSubresourceLayout layout;
struct vulkan_context_fp *vkcfp =
vk->context ? (struct vulkan_context_fp*)&vk->context->fp : NULL;
VkDevice device = vk->context->device; VkDevice device = vk->context->device;
VkImageCreateInfo info = { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO }; VkImageCreateInfo info = { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO };
VkImageViewCreateInfo view = { VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO }; VkImageViewCreateInfo view = { VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO };
@ -488,7 +483,7 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
slock_unlock(vk->context->queue_lock); slock_unlock(vk->context->queue_lock);
VKFUNC(vkFreeCommandBuffers)(vk->context->device, vk->staging_pool, 1, &staging); VKFUNC(vkFreeCommandBuffers)(vk->context->device, vk->staging_pool, 1, &staging);
vulkan_destroy_texture(&vk->context->fp, vulkan_destroy_texture(
vk->context->device, &tmp); vk->context->device, &tmp);
tex.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; tex.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
} }
@ -496,7 +491,6 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
} }
void vulkan_destroy_texture( void vulkan_destroy_texture(
struct vulkan_context_fp *vkcfp,
VkDevice device, VkDevice device,
struct vk_texture *tex) struct vk_texture *tex)
{ {
@ -512,7 +506,6 @@ void vulkan_destroy_texture(
} }
static void vulkan_write_quad_descriptors( static void vulkan_write_quad_descriptors(
struct vulkan_context_fp *vkcfp,
VkDevice device, VkDevice device,
VkDescriptorSet set, VkDescriptorSet set,
VkBuffer buffer, VkBuffer buffer,
@ -566,7 +559,6 @@ void vulkan_transition_texture(vk_t *vk, struct vk_texture *texture)
} }
static void vulkan_check_dynamic_state( static void vulkan_check_dynamic_state(
struct vulkan_context_fp *vkcfp,
vk_t *vk) vk_t *vk)
{ {
@ -585,9 +577,6 @@ static void vulkan_check_dynamic_state(
void vulkan_draw_triangles(vk_t *vk, const struct vk_draw_triangles *call) void vulkan_draw_triangles(vk_t *vk, const struct vk_draw_triangles *call)
{ {
struct vulkan_context_fp *vkcfp =
vk->context ? (struct vulkan_context_fp*)&vk->context->fp : NULL;
vulkan_transition_texture(vk, call->texture); vulkan_transition_texture(vk, call->texture);
if (call->pipeline != vk->tracker.pipeline) if (call->pipeline != vk->tracker.pipeline)
@ -600,7 +589,7 @@ void vulkan_draw_triangles(vk_t *vk, const struct vk_draw_triangles *call)
vk->tracker.dirty |= VULKAN_DIRTY_DYNAMIC_BIT; vk->tracker.dirty |= VULKAN_DIRTY_DYNAMIC_BIT;
} }
vulkan_check_dynamic_state(&vk->context->fp, vk); vulkan_check_dynamic_state(vk);
/* Upload descriptors */ /* Upload descriptors */
{ {
@ -618,10 +607,9 @@ void vulkan_draw_triangles(vk_t *vk, const struct vk_draw_triangles *call)
memcpy(range.data, call->mvp, sizeof(*call->mvp)); memcpy(range.data, call->mvp, sizeof(*call->mvp));
set = vulkan_descriptor_manager_alloc( set = vulkan_descriptor_manager_alloc(
&vk->context->fp,
vk->context->device, vk->context->device,
&vk->chain->descriptor_manager); &vk->chain->descriptor_manager);
vulkan_write_quad_descriptors(&vk->context->fp, vulkan_write_quad_descriptors(
vk->context->device, vk->context->device,
set, set,
range.buffer, range.buffer,
@ -650,9 +638,6 @@ void vulkan_draw_triangles(vk_t *vk, const struct vk_draw_triangles *call)
void vulkan_draw_quad(vk_t *vk, const struct vk_draw_quad *quad) void vulkan_draw_quad(vk_t *vk, const struct vk_draw_quad *quad)
{ {
struct vulkan_context_fp *vkcfp =
vk->context ? (struct vulkan_context_fp*)&vk->context->fp : NULL;
vulkan_transition_texture(vk, quad->texture); vulkan_transition_texture(vk, quad->texture);
if (quad->pipeline != vk->tracker.pipeline) if (quad->pipeline != vk->tracker.pipeline)
@ -665,7 +650,7 @@ void vulkan_draw_quad(vk_t *vk, const struct vk_draw_quad *quad)
vk->tracker.dirty |= VULKAN_DIRTY_DYNAMIC_BIT; vk->tracker.dirty |= VULKAN_DIRTY_DYNAMIC_BIT;
} }
vulkan_check_dynamic_state(&vk->context->fp, vk); vulkan_check_dynamic_state(vk);
/* Upload descriptors */ /* Upload descriptors */
{ {
@ -689,12 +674,11 @@ void vulkan_draw_quad(vk_t *vk, const struct vk_draw_quad *quad)
memcpy(range.data, quad->mvp, sizeof(*quad->mvp)); memcpy(range.data, quad->mvp, sizeof(*quad->mvp));
set = vulkan_descriptor_manager_alloc(&vk->context->fp, set = vulkan_descriptor_manager_alloc(
vk->context->device, vk->context->device,
&vk->chain->descriptor_manager); &vk->chain->descriptor_manager);
vulkan_write_quad_descriptors( vulkan_write_quad_descriptors(
&vk->context->fp,
vk->context->device, vk->context->device,
set, set,
range.buffer, range.buffer,
@ -743,8 +727,6 @@ void vulkan_image_layout_transition(
VkPipelineStageFlags srcStages, VkPipelineStageFlags srcStages,
VkPipelineStageFlags dstStages) VkPipelineStageFlags dstStages)
{ {
struct vulkan_context_fp *vkcfp =
(struct vulkan_context_fp*)&vk->context->fp;
VkImageMemoryBarrier barrier = VkImageMemoryBarrier barrier =
{ VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER }; { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER };
@ -769,7 +751,6 @@ void vulkan_image_layout_transition(
} }
struct vk_buffer vulkan_create_buffer( struct vk_buffer vulkan_create_buffer(
struct vulkan_context_fp *vkcfp,
const struct vulkan_context *context, const struct vulkan_context *context,
size_t size, VkBufferUsageFlags usage) size_t size, VkBufferUsageFlags usage)
{ {
@ -802,7 +783,6 @@ struct vk_buffer vulkan_create_buffer(
} }
void vulkan_destroy_buffer( void vulkan_destroy_buffer(
struct vulkan_context_fp *vkcfp,
VkDevice device, VkDevice device,
struct vk_buffer *buffer) struct vk_buffer *buffer)
{ {
@ -815,7 +795,6 @@ void vulkan_destroy_buffer(
} }
static struct vk_descriptor_pool *vulkan_alloc_descriptor_pool( static struct vk_descriptor_pool *vulkan_alloc_descriptor_pool(
struct vulkan_context_fp *vkcfp,
VkDevice device, VkDevice device,
const struct vk_descriptor_manager *manager) const struct vk_descriptor_manager *manager)
{ {
@ -849,7 +828,6 @@ static struct vk_descriptor_pool *vulkan_alloc_descriptor_pool(
} }
VkDescriptorSet vulkan_descriptor_manager_alloc( VkDescriptorSet vulkan_descriptor_manager_alloc(
struct vulkan_context_fp *vkcfp,
VkDevice device, struct vk_descriptor_manager *manager) VkDevice device, struct vk_descriptor_manager *manager)
{ {
if (manager->count < VULKAN_DESCRIPTOR_MANAGER_BLOCK_SETS) if (manager->count < VULKAN_DESCRIPTOR_MANAGER_BLOCK_SETS)
@ -862,7 +840,7 @@ VkDescriptorSet vulkan_descriptor_manager_alloc(
return manager->current->sets[manager->count++]; return manager->current->sets[manager->count++];
} }
manager->current->next = vulkan_alloc_descriptor_pool(vkcfp, device, manager); manager->current->next = vulkan_alloc_descriptor_pool(device, manager);
retro_assert(manager->current->next); retro_assert(manager->current->next);
manager->current = manager->current->next; manager->current = manager->current->next;
@ -877,7 +855,6 @@ void vulkan_descriptor_manager_restart(struct vk_descriptor_manager *manager)
} }
struct vk_descriptor_manager vulkan_create_descriptor_manager( struct vk_descriptor_manager vulkan_create_descriptor_manager(
struct vulkan_context_fp *vkcfp,
VkDevice device, VkDevice device,
const VkDescriptorPoolSize *sizes, const VkDescriptorPoolSize *sizes,
unsigned num_sizes, unsigned num_sizes,
@ -890,13 +867,12 @@ struct vk_descriptor_manager vulkan_create_descriptor_manager(
manager.num_sizes = num_sizes; manager.num_sizes = num_sizes;
manager.set_layout = set_layout; manager.set_layout = set_layout;
manager.head = vulkan_alloc_descriptor_pool(vkcfp, device, &manager); manager.head = vulkan_alloc_descriptor_pool(device, &manager);
retro_assert(manager.head); retro_assert(manager.head);
return manager; return manager;
} }
void vulkan_destroy_descriptor_manager( void vulkan_destroy_descriptor_manager(
struct vulkan_context_fp *vkcfp,
VkDevice device, VkDevice device,
struct vk_descriptor_manager *manager) struct vk_descriptor_manager *manager)
{ {
@ -951,7 +927,6 @@ static struct vk_buffer_node *vulkan_buffer_chain_alloc_node(
return NULL; return NULL;
node->buffer = vulkan_create_buffer( node->buffer = vulkan_create_buffer(
(struct vulkan_context_fp*)&context->fp,
context, size, usage); context, size, usage);
return node; return node;
} }
@ -1017,7 +992,6 @@ bool vulkan_buffer_chain_alloc(const struct vulkan_context *context,
} }
void vulkan_buffer_chain_free( void vulkan_buffer_chain_free(
struct vulkan_context_fp *vkcfp,
VkDevice device, VkDevice device,
struct vk_buffer_chain *chain) struct vk_buffer_chain *chain)
{ {
@ -1025,7 +999,7 @@ void vulkan_buffer_chain_free(
while (node) while (node)
{ {
struct vk_buffer_node *next = node->next; struct vk_buffer_node *next = node->next;
vulkan_destroy_buffer(vkcfp, device, &node->buffer); vulkan_destroy_buffer(device, &node->buffer);
free(node); free(node);
node = next; node = next;
@ -1048,7 +1022,6 @@ bool vulkan_context_init(gfx_ctx_vulkan_data_t *vk,
bool found_queue = false; bool found_queue = false;
VkPhysicalDevice *gpus = NULL; VkPhysicalDevice *gpus = NULL;
static const float one = 1.0f; static const float one = 1.0f;
struct vulkan_context_fp *vkcfp = (struct vulkan_context_fp*)&vk->context.fp;
static const char *device_extensions[] = { static const char *device_extensions[] = {
"VK_KHR_swapchain", "VK_KHR_swapchain",
}; };
@ -1409,9 +1382,6 @@ bool vulkan_surface_create(gfx_ctx_vulkan_data_t *vk,
unsigned width, unsigned height, unsigned width, unsigned height,
unsigned swap_interval) unsigned swap_interval)
{ {
struct vulkan_context_fp *vkcfp =
(struct vulkan_context_fp*)&vk->context.fp;
switch (type) switch (type)
{ {
case VULKAN_WSI_WAYLAND: case VULKAN_WSI_WAYLAND:
@ -1541,7 +1511,6 @@ void vulkan_present(gfx_ctx_vulkan_data_t *vk, unsigned index)
VkPresentInfoKHR present; VkPresentInfoKHR present;
VkResult result = VK_SUCCESS; VkResult result = VK_SUCCESS;
VkResult err = VK_SUCCESS; VkResult err = VK_SUCCESS;
struct vulkan_context_fp *vkcfp = (struct vulkan_context_fp*)&vk->context.fp;
present.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; present.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
present.swapchainCount = 1; present.swapchainCount = 1;
@ -1568,8 +1537,6 @@ void vulkan_context_destroy(gfx_ctx_vulkan_data_t *vk,
bool destroy_surface) bool destroy_surface)
{ {
unsigned i; unsigned i;
struct vulkan_context_fp *vkcfp = (struct vulkan_context_fp
*)&vk->context.fp;
if (vk->context.queue) if (vk->context.queue)
VKFUNC(vkQueueWaitIdle)(vk->context.queue); VKFUNC(vkQueueWaitIdle)(vk->context.queue);
@ -1617,8 +1584,6 @@ void vulkan_acquire_next_image(gfx_ctx_vulkan_data_t *vk)
VkSemaphoreCreateInfo sem_info; VkSemaphoreCreateInfo sem_info;
VkFenceCreateInfo fence_info; VkFenceCreateInfo fence_info;
VkFence *next_fence = NULL; VkFence *next_fence = NULL;
struct vulkan_context_fp *vkcfp = (struct vulkan_context_fp
*)&vk->context.fp;
sem_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; sem_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
@ -1668,8 +1633,6 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
VkExtent2D swapchain_size; VkExtent2D swapchain_size;
VkSwapchainKHR old_swapchain; VkSwapchainKHR old_swapchain;
VkSurfaceTransformFlagBitsKHR pre_transform; VkSurfaceTransformFlagBitsKHR pre_transform;
struct vulkan_context_fp *vkcfp = (struct vulkan_context_fp
*)&vk->context.fp;
/* TODO: Properly query these. */ /* TODO: Properly query these. */
VkPresentModeKHR swapchain_present_mode = swap_interval VkPresentModeKHR swapchain_present_mode = swap_interval

View File

@ -80,11 +80,8 @@ enum vulkan_wsi_type
VULKAN_WSI_XLIB VULKAN_WSI_XLIB
}; };
typedef struct vulkan_context typedef struct vulkan_context
{ {
vulkan_context_fp_t fp;
VkInstance instance; VkInstance instance;
VkPhysicalDevice gpu; VkPhysicalDevice gpu;
VkDevice device; VkDevice device;
@ -201,7 +198,6 @@ bool vulkan_buffer_chain_alloc(const struct vulkan_context *context,
struct vk_buffer_range *range); struct vk_buffer_range *range);
void vulkan_buffer_chain_free( void vulkan_buffer_chain_free(
struct vulkan_context_fp *vkcfp,
VkDevice device, VkDevice device,
struct vk_buffer_chain *chain); struct vk_buffer_chain *chain);
@ -392,12 +388,10 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
void vulkan_transition_texture(vk_t *vk, struct vk_texture *texture); void vulkan_transition_texture(vk_t *vk, struct vk_texture *texture);
void vulkan_map_persistent_texture( void vulkan_map_persistent_texture(
struct vulkan_context_fp *vkcfp,
VkDevice device, VkDevice device,
struct vk_texture *texture); struct vk_texture *texture);
void vulkan_destroy_texture( void vulkan_destroy_texture(
struct vulkan_context_fp *vkcfp,
VkDevice device, VkDevice device,
struct vk_texture *tex); struct vk_texture *tex);
@ -465,17 +459,14 @@ static INLINE void vulkan_write_quad_vbo(struct vk_vertex *pv,
} }
struct vk_buffer vulkan_create_buffer( struct vk_buffer vulkan_create_buffer(
struct vulkan_context_fp *vkcfp,
const struct vulkan_context *context, const struct vulkan_context *context,
size_t size, VkBufferUsageFlags usage); size_t size, VkBufferUsageFlags usage);
void vulkan_destroy_buffer( void vulkan_destroy_buffer(
struct vulkan_context_fp *vkcfp,
VkDevice device, VkDevice device,
struct vk_buffer *buffer); struct vk_buffer *buffer);
VkDescriptorSet vulkan_descriptor_manager_alloc( VkDescriptorSet vulkan_descriptor_manager_alloc(
struct vulkan_context_fp *vkcfp,
VkDevice device, VkDevice device,
struct vk_descriptor_manager *manager); struct vk_descriptor_manager *manager);
@ -483,13 +474,11 @@ void vulkan_descriptor_manager_restart(
struct vk_descriptor_manager *manager); struct vk_descriptor_manager *manager);
struct vk_descriptor_manager vulkan_create_descriptor_manager( struct vk_descriptor_manager vulkan_create_descriptor_manager(
struct vulkan_context_fp *vkcfp,
VkDevice device, VkDevice device,
const VkDescriptorPoolSize *sizes, unsigned num_sizes, const VkDescriptorPoolSize *sizes, unsigned num_sizes,
VkDescriptorSetLayout set_layout); VkDescriptorSetLayout set_layout);
void vulkan_destroy_descriptor_manager( void vulkan_destroy_descriptor_manager(
struct vulkan_context_fp *vkcfp,
VkDevice device, VkDevice device,
struct vk_descriptor_manager *manager); struct vk_descriptor_manager *manager);

View File

@ -71,7 +71,6 @@ static const gfx_ctx_driver_t *vulkan_get_context(vk_t *vk)
} }
static void vulkan_init_render_pass( static void vulkan_init_render_pass(
struct vulkan_context_fp *vkcfp,
vk_t *vk) vk_t *vk)
{ {
VkRenderPassCreateInfo rp_info; VkRenderPassCreateInfo rp_info;
@ -115,12 +114,11 @@ static void vulkan_init_render_pass(
} }
static void vulkan_init_framebuffers( static void vulkan_init_framebuffers(
struct vulkan_context_fp *vkcfp,
vk_t *vk) vk_t *vk)
{ {
unsigned i; unsigned i;
vulkan_init_render_pass(vkcfp, vk); vulkan_init_render_pass(vk);
for (i = 0; i < vk->num_swapchain_images; i++) for (i = 0; i < vk->num_swapchain_images; i++)
{ {
@ -162,7 +160,6 @@ static void vulkan_init_framebuffers(
} }
static void vulkan_init_pipeline_layout( static void vulkan_init_pipeline_layout(
struct vulkan_context_fp *vkcfp,
vk_t *vk) vk_t *vk)
{ {
VkDescriptorSetLayoutCreateInfo set_layout_info = { VkDescriptorSetLayoutCreateInfo set_layout_info = {
@ -197,7 +194,6 @@ static void vulkan_init_pipeline_layout(
} }
static void vulkan_init_pipelines( static void vulkan_init_pipelines(
struct vulkan_context_fp *vkcfp,
vk_t *vk) vk_t *vk)
{ {
unsigned i; unsigned i;
@ -236,7 +232,7 @@ static void vulkan_init_pipelines(
VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_SCISSOR,
}; };
vulkan_init_pipeline_layout(vkcfp, vk); vulkan_init_pipeline_layout(vk);
/* Input assembly */ /* Input assembly */
input_assembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; input_assembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
@ -365,7 +361,7 @@ static void vulkan_init_pipelines(
VKFUNC(vkDestroyShaderModule)(vk->context->device, shader_stages[1].module, NULL); VKFUNC(vkDestroyShaderModule)(vk->context->device, shader_stages[1].module, NULL);
} }
static void vulkan_init_command_buffers(struct vulkan_context_fp *vkcfp, vk_t *vk) static void vulkan_init_command_buffers(vk_t *vk)
{ {
/* RESET_COMMAND_BUFFER_BIT allows command buffer to be reset. */ /* RESET_COMMAND_BUFFER_BIT allows command buffer to be reset. */
unsigned i; unsigned i;
@ -393,9 +389,7 @@ static void vulkan_init_command_buffers(struct vulkan_context_fp *vkcfp, vk_t *v
} }
} }
static void vulkan_init_samplers( static void vulkan_init_samplers(vk_t *vk)
struct vulkan_context_fp *vkcfp,
vk_t *vk)
{ {
VkSamplerCreateInfo info; VkSamplerCreateInfo info;
@ -422,9 +416,7 @@ static void vulkan_init_samplers(
&info, NULL, &vk->samplers.linear); &info, NULL, &vk->samplers.linear);
} }
static void vulkan_deinit_samplers( static void vulkan_deinit_samplers(vk_t *vk)
struct vulkan_context_fp *vkcfp,
vk_t *vk)
{ {
VKFUNC(vkDestroySampler)(vk->context->device, vk->samplers.nearest, NULL); VKFUNC(vkDestroySampler)(vk->context->device, vk->samplers.nearest, NULL);
VKFUNC(vkDestroySampler)(vk->context->device, vk->samplers.linear, NULL); VKFUNC(vkDestroySampler)(vk->context->device, vk->samplers.linear, NULL);
@ -449,9 +441,9 @@ static void vulkan_deinit_buffers(vk_t *vk)
unsigned i; unsigned i;
for (i = 0; i < vk->num_swapchain_images; i++) for (i = 0; i < vk->num_swapchain_images; i++)
{ {
vulkan_buffer_chain_free(&vk->context->fp, vulkan_buffer_chain_free(
vk->context->device, &vk->swapchain[i].vbo); vk->context->device, &vk->swapchain[i].vbo);
vulkan_buffer_chain_free(&vk->context->fp, vulkan_buffer_chain_free(
vk->context->device, &vk->swapchain[i].ubo); vk->context->device, &vk->swapchain[i].ubo);
} }
} }
@ -470,7 +462,6 @@ static void vulkan_init_descriptor_pool(vk_t *vk)
{ {
vk->swapchain[i].descriptor_manager = vk->swapchain[i].descriptor_manager =
vulkan_create_descriptor_manager( vulkan_create_descriptor_manager(
&vk->context->fp,
vk->context->device, vk->context->device,
pool_sizes, 2, vk->pipelines.set_layout); pool_sizes, 2, vk->pipelines.set_layout);
} }
@ -481,7 +472,6 @@ static void vulkan_deinit_descriptor_pool(vk_t *vk)
unsigned i; unsigned i;
for (i = 0; i < vk->num_swapchain_images; i++) for (i = 0; i < vk->num_swapchain_images; i++)
vulkan_destroy_descriptor_manager( vulkan_destroy_descriptor_manager(
&vk->context->fp,
vk->context->device, vk->context->device,
&vk->swapchain[i].descriptor_manager); &vk->swapchain[i].descriptor_manager);
} }
@ -489,7 +479,7 @@ static void vulkan_deinit_descriptor_pool(vk_t *vk)
static void vulkan_init_textures(vk_t *vk) static void vulkan_init_textures(vk_t *vk)
{ {
unsigned i; unsigned i;
vulkan_init_samplers(&vk->context->fp, vk); vulkan_init_samplers(vk);
if (!vk->hw.enable) if (!vk->hw.enable)
{ {
@ -499,7 +489,7 @@ static void vulkan_init_textures(vk_t *vk)
vk->tex_w, vk->tex_h, vk->tex_fmt, vk->tex_w, vk->tex_h, vk->tex_fmt,
NULL, NULL, VULKAN_TEXTURE_STREAMED); NULL, NULL, VULKAN_TEXTURE_STREAMED);
vulkan_map_persistent_texture(&vk->context->fp, vulkan_map_persistent_texture(
vk->context->device, vk->context->device,
&vk->swapchain[i].texture); &vk->swapchain[i].texture);
@ -515,23 +505,21 @@ static void vulkan_deinit_textures(vk_t *vk)
{ {
unsigned i; unsigned i;
vulkan_deinit_samplers(&vk->context->fp, vk); vulkan_deinit_samplers(vk);
for (i = 0; i < vk->num_swapchain_images; i++) for (i = 0; i < vk->num_swapchain_images; i++)
{ {
if (vk->swapchain[i].texture.memory != VK_NULL_HANDLE) if (vk->swapchain[i].texture.memory != VK_NULL_HANDLE)
vulkan_destroy_texture(&vk->context->fp, vulkan_destroy_texture(
vk->context->device, &vk->swapchain[i].texture); vk->context->device, &vk->swapchain[i].texture);
if (vk->swapchain[i].texture_optimal.memory != VK_NULL_HANDLE) if (vk->swapchain[i].texture_optimal.memory != VK_NULL_HANDLE)
vulkan_destroy_texture(&vk->context->fp, vulkan_destroy_texture(
vk->context->device, &vk->swapchain[i].texture_optimal); vk->context->device, &vk->swapchain[i].texture_optimal);
} }
} }
static void vulkan_deinit_command_buffers( static void vulkan_deinit_command_buffers(vk_t *vk)
struct vulkan_context_fp *vkcfp,
vk_t *vk)
{ {
unsigned i; unsigned i;
for (i = 0; i < vk->num_swapchain_images; i++) for (i = 0; i < vk->num_swapchain_images; i++)
@ -545,9 +533,7 @@ static void vulkan_deinit_command_buffers(
} }
} }
static void vulkan_deinit_pipeline_layout( static void vulkan_deinit_pipeline_layout(vk_t *vk)
struct vulkan_context_fp *vkcfp,
vk_t *vk)
{ {
VKFUNC(vkDestroyPipelineLayout)(vk->context->device, VKFUNC(vkDestroyPipelineLayout)(vk->context->device,
vk->pipelines.layout, NULL); vk->pipelines.layout, NULL);
@ -555,13 +541,11 @@ static void vulkan_deinit_pipeline_layout(
vk->pipelines.set_layout, NULL); vk->pipelines.set_layout, NULL);
} }
static void vulkan_deinit_pipelines( static void vulkan_deinit_pipelines(vk_t *vk)
struct vulkan_context_fp *vkcfp,
vk_t *vk)
{ {
unsigned i; unsigned i;
vulkan_deinit_pipeline_layout(vkcfp, vk); vulkan_deinit_pipeline_layout(vk);
VKFUNC(vkDestroyPipeline)(vk->context->device, VKFUNC(vkDestroyPipeline)(vk->context->device,
vk->pipelines.alpha_blend, NULL); vk->pipelines.alpha_blend, NULL);
VKFUNC(vkDestroyPipeline)(vk->context->device, VKFUNC(vkDestroyPipeline)(vk->context->device,
@ -572,9 +556,7 @@ static void vulkan_deinit_pipelines(
vk->display.pipelines[i], NULL); vk->display.pipelines[i], NULL);
} }
static void vulkan_deinit_framebuffers( static void vulkan_deinit_framebuffers(vk_t *vk)
struct vulkan_context_fp *vkcfp,
vk_t *vk)
{ {
unsigned i; unsigned i;
for (i = 0; i < vk->num_swapchain_images; i++) for (i = 0; i < vk->num_swapchain_images; i++)
@ -594,7 +576,6 @@ static bool vulkan_init_default_filter_chain(vk_t *vk)
memset(&info, 0, sizeof(info)); memset(&info, 0, sizeof(info));
info.fp = (void*)&vk->context->fp;
info.device = vk->context->device; info.device = vk->context->device;
info.memory_properties = &vk->context->memory_properties; info.memory_properties = &vk->context->memory_properties;
info.pipeline_cache = vk->pipelines.cache; info.pipeline_cache = vk->pipelines.cache;
@ -626,7 +607,6 @@ static bool vulkan_init_filter_chain_preset(vk_t *vk, const char *shader_path)
memset(&info, 0, sizeof(info)); memset(&info, 0, sizeof(info));
info.fp = (void*)&vk->context->fp;
info.device = vk->context->device; info.device = vk->context->device;
info.memory_properties = &vk->context->memory_properties; info.memory_properties = &vk->context->memory_properties;
info.pipeline_cache = vk->pipelines.cache; info.pipeline_cache = vk->pipelines.cache;
@ -680,12 +660,12 @@ static bool vulkan_init_filter_chain(vk_t *vk)
static void vulkan_init_resources(vk_t *vk) static void vulkan_init_resources(vk_t *vk)
{ {
vk->num_swapchain_images = vk->context->num_swapchain_images; vk->num_swapchain_images = vk->context->num_swapchain_images;
vulkan_init_framebuffers(&vk->context->fp, vk); vulkan_init_framebuffers(vk);
vulkan_init_pipelines(&vk->context->fp, vk); vulkan_init_pipelines(vk);
vulkan_init_descriptor_pool(vk); vulkan_init_descriptor_pool(vk);
vulkan_init_textures(vk); vulkan_init_textures(vk);
vulkan_init_buffers(vk); vulkan_init_buffers(vk);
vulkan_init_command_buffers(&vk->context->fp, vk); vulkan_init_command_buffers(vk);
} }
static void vulkan_init_static_resources(vk_t *vk) static void vulkan_init_static_resources(vk_t *vk)
@ -697,8 +677,6 @@ static void vulkan_init_static_resources(vk_t *vk)
/* Create the pipeline cache. */ /* Create the pipeline cache. */
VkPipelineCacheCreateInfo cache = { VkPipelineCacheCreateInfo cache = {
VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO }; VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO };
struct vulkan_context_fp *vkcfp =
vk->context ? (struct vulkan_context_fp*)&vk->context->fp : NULL;
VKFUNC(vkCreatePipelineCache)(vk->context->device, VKFUNC(vkCreatePipelineCache)(vk->context->device,
&cache, NULL, &vk->pipelines.cache); &cache, NULL, &vk->pipelines.cache);
@ -716,14 +694,12 @@ static void vulkan_init_static_resources(vk_t *vk)
blank, NULL, VULKAN_TEXTURE_STATIC); blank, NULL, VULKAN_TEXTURE_STATIC);
} }
static void vulkan_deinit_static_resources( static void vulkan_deinit_static_resources(vk_t *vk)
struct vulkan_context_fp *vkcfp,
vk_t *vk)
{ {
unsigned i; unsigned i;
VKFUNC(vkDestroyPipelineCache)(vk->context->device, VKFUNC(vkDestroyPipelineCache)(vk->context->device,
vk->pipelines.cache, NULL); vk->pipelines.cache, NULL);
vulkan_destroy_texture(&vk->context->fp, vulkan_destroy_texture(
vk->context->device, vk->context->device,
&vk->display.blank_texture); &vk->display.blank_texture);
@ -734,19 +710,19 @@ static void vulkan_deinit_static_resources(
for (i = 0; i < VULKAN_MAX_SWAPCHAIN_IMAGES; i++) for (i = 0; i < VULKAN_MAX_SWAPCHAIN_IMAGES; i++)
if (vk->readback.staging[i].memory != VK_NULL_HANDLE) if (vk->readback.staging[i].memory != VK_NULL_HANDLE)
vulkan_destroy_texture(&vk->context->fp, vulkan_destroy_texture(
vk->context->device, vk->context->device,
&vk->readback.staging[i]); &vk->readback.staging[i]);
} }
static void vulkan_deinit_resources(vk_t *vk) static void vulkan_deinit_resources(vk_t *vk)
{ {
vulkan_deinit_pipelines(&vk->context->fp, vk); vulkan_deinit_pipelines(vk);
vulkan_deinit_framebuffers(&vk->context->fp, vk); vulkan_deinit_framebuffers(vk);
vulkan_deinit_descriptor_pool(vk); vulkan_deinit_descriptor_pool(vk);
vulkan_deinit_textures(vk); vulkan_deinit_textures(vk);
vulkan_deinit_buffers(vk); vulkan_deinit_buffers(vk);
vulkan_deinit_command_buffers(&vk->context->fp, vk); vulkan_deinit_command_buffers(vk);
} }
static void vulkan_deinit_menu(vk_t *vk) static void vulkan_deinit_menu(vk_t *vk)
@ -755,10 +731,10 @@ static void vulkan_deinit_menu(vk_t *vk)
for (i = 0; i < VULKAN_MAX_SWAPCHAIN_IMAGES; i++) for (i = 0; i < VULKAN_MAX_SWAPCHAIN_IMAGES; i++)
{ {
if (vk->menu.textures[i].memory) if (vk->menu.textures[i].memory)
vulkan_destroy_texture(&vk->context->fp, vulkan_destroy_texture(
vk->context->device, &vk->menu.textures[i]); vk->context->device, &vk->menu.textures[i]);
if (vk->menu.textures_optimal[i].memory) if (vk->menu.textures_optimal[i].memory)
vulkan_destroy_texture(&vk->context->fp, vulkan_destroy_texture(
vk->context->device, &vk->menu.textures_optimal[i]); vk->context->device, &vk->menu.textures_optimal[i]);
} }
} }
@ -766,8 +742,6 @@ static void vulkan_deinit_menu(vk_t *vk)
static void vulkan_free(void *data) static void vulkan_free(void *data)
{ {
vk_t *vk = (vk_t*)data; vk_t *vk = (vk_t*)data;
struct vulkan_context_fp *vkcfp =
vk->context ? (struct vulkan_context_fp*)&vk->context->fp : NULL;
if (!vk) if (!vk)
return; return;
@ -780,7 +754,7 @@ static void vulkan_free(void *data)
vulkan_deinit_menu(vk); vulkan_deinit_menu(vk);
font_driver_free(NULL); font_driver_free(NULL);
vulkan_deinit_static_resources(&vk->context->fp, vk); vulkan_deinit_static_resources(vk);
vulkan_overlay_free(vk); vulkan_overlay_free(vk);
if (vk->filter_chain) if (vk->filter_chain)
@ -1049,9 +1023,6 @@ static void vulkan_update_filter_chain(vk_t *vk)
static void vulkan_check_swapchain(vk_t *vk) static void vulkan_check_swapchain(vk_t *vk)
{ {
struct vulkan_context_fp *vkcfp =
vk->context ? (struct vulkan_context_fp*)&vk->context->fp : NULL;
if (vk->context->invalid_swapchain) if (vk->context->invalid_swapchain)
{ {
VKFUNC(vkQueueWaitIdle)(vk->context->queue); VKFUNC(vkQueueWaitIdle)(vk->context->queue);
@ -1331,8 +1302,6 @@ static void vulkan_readback(vk_t *vk)
VkImageCopy region; VkImageCopy region;
struct vk_texture *staging; struct vk_texture *staging;
struct video_viewport vp; struct video_viewport vp;
struct vulkan_context_fp *vkcfp =
vk->context ? (struct vulkan_context_fp*)&vk->context->fp : NULL;
vulkan_viewport_info(vk, &vp); vulkan_viewport_info(vk, &vp);
memset(&region, 0, sizeof(region)); memset(&region, 0, sizeof(region));
@ -1401,8 +1370,6 @@ static bool vulkan_frame(void *data, const void *frame,
VK_STRUCTURE_TYPE_SUBMIT_INFO }; VK_STRUCTURE_TYPE_SUBMIT_INFO };
unsigned frame_index = unsigned frame_index =
vk->context->current_swapchain_index; vk->context->current_swapchain_index;
struct vulkan_context_fp *vkcfp =
vk->context ? (struct vulkan_context_fp*)&vk->context->fp : NULL;
rarch_perf_init(&frame_run, "frame_run"); rarch_perf_init(&frame_run, "frame_run");
rarch_perf_init(&copy_frame, "copy_frame"); rarch_perf_init(&copy_frame, "copy_frame");
@ -1445,7 +1412,7 @@ static bool vulkan_frame(void *data, const void *frame,
chain->texture_optimal.memory chain->texture_optimal.memory
? VULKAN_TEXTURE_STAGING : VULKAN_TEXTURE_STREAMED); ? VULKAN_TEXTURE_STAGING : VULKAN_TEXTURE_STREAMED);
vulkan_map_persistent_texture(&vk->context->fp, vulkan_map_persistent_texture(
vk->context->device, &chain->texture); vk->context->device, &chain->texture);
if (chain->texture.type == VULKAN_TEXTURE_STAGING) if (chain->texture.type == VULKAN_TEXTURE_STAGING)
@ -1790,7 +1757,7 @@ static bool vulkan_get_current_sw_framebuffer(void *data,
chain->texture = vulkan_create_texture(vk, &chain->texture, chain->texture = vulkan_create_texture(vk, &chain->texture,
framebuffer->width, framebuffer->height, chain->texture.format, framebuffer->width, framebuffer->height, chain->texture.format,
NULL, NULL, VULKAN_TEXTURE_STREAMED); NULL, NULL, VULKAN_TEXTURE_STREAMED);
vulkan_map_persistent_texture(&vk->context->fp, vulkan_map_persistent_texture(
vk->context->device, &chain->texture); vk->context->device, &chain->texture);
if (chain->texture.type == VULKAN_TEXTURE_STAGING) if (chain->texture.type == VULKAN_TEXTURE_STAGING)
@ -1836,7 +1803,6 @@ static void vulkan_set_texture_frame(void *data,
uint8_t *ptr = NULL; uint8_t *ptr = NULL;
uint8_t *dst = NULL; uint8_t *dst = NULL;
const uint8_t *src = NULL; const uint8_t *src = NULL;
struct vulkan_context_fp *vkcfp = NULL;
vk_t *vk = (vk_t*)data; vk_t *vk = (vk_t*)data;
unsigned index = vk->context->current_swapchain_index; unsigned index = vk->context->current_swapchain_index;
struct vk_texture *texture = &vk->menu.textures[index]; struct vk_texture *texture = &vk->menu.textures[index];
@ -1851,11 +1817,6 @@ static void vulkan_set_texture_frame(void *data,
if (!vk) if (!vk)
return; return;
vkcfp = &vk->context->fp;
if (!vkcfp)
return;
/* B4G4R4A4 must be supported, but R4G4B4A4 is optional, /* B4G4R4A4 must be supported, but R4G4B4A4 is optional,
* just apply the swizzle in the image view instead. */ * just apply the swizzle in the image view instead. */
*texture = vulkan_create_texture(vk, *texture = vulkan_create_texture(vk,
@ -1936,8 +1897,6 @@ static void vulkan_unload_texture(void *data, uintptr_t handle)
{ {
vk_t *vk = (vk_t*)data; vk_t *vk = (vk_t*)data;
struct vk_texture *texture = (struct vk_texture*)handle; struct vk_texture *texture = (struct vk_texture*)handle;
struct vulkan_context_fp *vkcfp =
vk->context ? (struct vulkan_context_fp*)&vk->context->fp : NULL;
if (!texture) if (!texture)
return; return;
@ -1945,7 +1904,6 @@ static void vulkan_unload_texture(void *data, uintptr_t handle)
* but this will do for now. */ * but this will do for now. */
VKFUNC(vkQueueWaitIdle)(vk->context->queue); VKFUNC(vkQueueWaitIdle)(vk->context->queue);
vulkan_destroy_texture( vulkan_destroy_texture(
&vk->context->fp,
vk->context->device, texture); vk->context->device, texture);
free(texture); free(texture);
} }
@ -2003,8 +1961,6 @@ static bool vulkan_read_viewport(void *data, uint8_t *buffer)
{ {
struct vk_texture *staging = NULL; struct vk_texture *staging = NULL;
vk_t *vk = (vk_t*)data; vk_t *vk = (vk_t*)data;
struct vulkan_context_fp *vkcfp =
vk->context ? (struct vulkan_context_fp*)&vk->context->fp : NULL;
if (!vk) if (!vk)
return false; return false;
@ -2048,7 +2004,6 @@ static bool vulkan_read_viewport(void *data, uint8_t *buffer)
if (!staging->mapped) if (!staging->mapped)
vulkan_map_persistent_texture( vulkan_map_persistent_texture(
&vk->context->fp,
vk->context->device, staging); vk->context->device, staging);
{ {
@ -2069,7 +2024,6 @@ static bool vulkan_read_viewport(void *data, uint8_t *buffer)
} }
} }
vulkan_destroy_texture( vulkan_destroy_texture(
&vk->context->fp,
vk->context->device, staging); vk->context->device, staging);
} }
return true; return true;
@ -2106,7 +2060,6 @@ static void vulkan_overlay_free(vk_t *vk)
for (i = 0; i < vk->overlay.count; i++) for (i = 0; i < vk->overlay.count; i++)
if (vk->overlay.images[i].memory != VK_NULL_HANDLE) if (vk->overlay.images[i].memory != VK_NULL_HANDLE)
vulkan_destroy_texture( vulkan_destroy_texture(
&vk->context->fp,
vk->context->device, vk->context->device,
&vk->overlay.images[i]); &vk->overlay.images[i]);
@ -2220,9 +2173,6 @@ static bool vulkan_overlay_load(void *data,
const struct texture_image *images = const struct texture_image *images =
(const struct texture_image*)image_data; (const struct texture_image*)image_data;
vk_t *vk = (vk_t*)data; vk_t *vk = (vk_t*)data;
struct vulkan_context_fp *vkcfp =
vk->context ? (struct vulkan_context_fp*)&vk->context->fp
: NULL;
static const struct vk_color white = { static const struct vk_color white = {
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
}; };

View File

@ -69,9 +69,6 @@ static void *vulkan_raster_font_init_font(void *data,
static void vulkan_raster_font_free_font(void *data) static void vulkan_raster_font_free_font(void *data)
{ {
vulkan_raster_t *font = (vulkan_raster_t*)data; vulkan_raster_t *font = (vulkan_raster_t*)data;
struct vulkan_context_fp *vkcfp =
font->vk->context ? (struct vulkan_context_fp*)&font->vk->context->fp
: NULL;
if (!font) if (!font)
return; return;
@ -79,7 +76,7 @@ static void vulkan_raster_font_free_font(void *data)
font->font_driver->free(font->font_data); font->font_driver->free(font->font_data);
VKFUNC(vkQueueWaitIdle)(font->vk->context->queue); VKFUNC(vkQueueWaitIdle)(font->vk->context->queue);
vulkan_destroy_texture(vkcfp, vulkan_destroy_texture(
font->vk->context->device, &font->texture); font->vk->context->device, &font->texture);
free(font); free(font);

View File

@ -191,16 +191,10 @@ static void menu_display_vk_clear_color(void *data)
VkClearAttachment attachment; VkClearAttachment attachment;
menu_display_ctx_clearcolor_t *clearcolor = menu_display_ctx_clearcolor_t *clearcolor =
(menu_display_ctx_clearcolor_t*)data; (menu_display_ctx_clearcolor_t*)data;
struct vulkan_context_fp *vkcfp = NULL;
vk_t *vk = vk_get_ptr(); vk_t *vk = vk_get_ptr();
if (!vk || !clearcolor) if (!vk || !clearcolor)
return; return;
vkcfp = &vk->context->fp;
if (!vkcfp)
return;
attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
attachment.clearValue.color.float32[0] = clearcolor->r; attachment.clearValue.color.float32[0] = clearcolor->r;
attachment.clearValue.color.float32[1] = clearcolor->g; attachment.clearValue.color.float32[1] = clearcolor->g;