From 67ea4e1d6b723000e39d518cd2e5d2bce9334ea6 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 29 Feb 2016 22:55:31 +0100 Subject: [PATCH] (Vulkan) Pipeline function pointers --- gfx/common/vulkan_common.c | 6 +++++- gfx/common/vulkan_common.h | 9 ++++++++- gfx/drivers/vulkan.c | 27 ++++++++++++++------------- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/gfx/common/vulkan_common.c b/gfx/common/vulkan_common.c index 1c48a340f9..3f99a56871 100644 --- a/gfx/common/vulkan_common.c +++ b/gfx/common/vulkan_common.c @@ -1178,6 +1178,11 @@ bool vulkan_context_init(gfx_ctx_vulkan_data_t *vk, /* Pipelines */ VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, DestroyPipeline); + VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CreateGraphicsPipelines); + + /* Shaders */ + VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CreateShaderModule); + VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, DestroyShaderModule); /* Pipeline Layouts */ VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CreatePipelineLayout); @@ -1187,7 +1192,6 @@ bool vulkan_context_init(gfx_ctx_vulkan_data_t *vk, VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CreatePipelineCache); VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, DestroyPipelineCache); - /* Command buffers */ VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CreateCommandPool); VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, DestroyCommandPool); diff --git a/gfx/common/vulkan_common.h b/gfx/common/vulkan_common.h index d456932d48..93706fb55c 100644 --- a/gfx/common/vulkan_common.h +++ b/gfx/common/vulkan_common.h @@ -173,8 +173,8 @@ typedef struct vulkan_context PFN_vkQueueWaitIdle vkQueueWaitIdle; /* Pipelines */ - PFN_vkCmdBindPipeline vkCmdBindPipeline; PFN_vkDestroyPipeline vkDestroyPipeline; + PFN_vkCreateGraphicsPipelines vkCreateGraphicsPipelines; /* Pipeline Layouts */ PFN_vkCreatePipelineLayout vkCreatePipelineLayout; @@ -226,6 +226,9 @@ typedef struct vulkan_context PFN_vkCreateRenderPass vkCreateRenderPass; PFN_vkDestroyRenderPass vkDestroyRenderPass; + /* Pipeline commands */ + PFN_vkCmdBindPipeline vkCmdBindPipeline; + /* Render Pass commands */ PFN_vkCmdBeginRenderPass vkCmdBeginRenderPass; PFN_vkCmdEndRenderPass vkCmdEndRenderPass; @@ -242,6 +245,10 @@ typedef struct vulkan_context /* Fixed-function vertex postprocessing */ PFN_vkCmdSetViewport vkCmdSetViewport; + /* Shaders */ + PFN_vkCreateShaderModule vkCreateShaderModule; + PFN_vkDestroyShaderModule vkDestroyShaderModule; + PFN_vkGetPhysicalDeviceFormatProperties vkGetPhysicalDeviceFormatProperties; PFN_vkEnumeratePhysicalDevices vkEnumeratePhysicalDevices; PFN_vkGetPhysicalDeviceProperties vkGetPhysicalDeviceProperties; diff --git a/gfx/drivers/vulkan.c b/gfx/drivers/vulkan.c index e7d6df9dcb..0271f78ba3 100644 --- a/gfx/drivers/vulkan.c +++ b/gfx/drivers/vulkan.c @@ -315,7 +315,7 @@ static void vulkan_init_pipelines( module_info.pCode = (const uint32_t*)alpha_blend_vert_spv; shader_stages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; shader_stages[0].pName = "main"; - vkCreateShaderModule(vk->context->device, + VKFUNC(vkCreateShaderModule)(vk->context->device, &module_info, NULL, &shader_stages[0].module); blend_attachment.blendEnable = true; @@ -332,22 +332,22 @@ static void vulkan_init_pipelines( module_info.pCode = (const uint32_t*)font_frag_spv; shader_stages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; shader_stages[1].pName = "main"; - vkCreateShaderModule(vk->context->device, + VKFUNC(vkCreateShaderModule)(vk->context->device, &module_info, NULL, &shader_stages[1].module); - vkCreateGraphicsPipelines(vk->context->device, vk->pipelines.cache, + VKFUNC(vkCreateGraphicsPipelines)(vk->context->device, vk->pipelines.cache, 1, &pipe, NULL, &vk->pipelines.font); - vkDestroyShaderModule(vk->context->device, shader_stages[1].module, NULL); + VKFUNC(vkDestroyShaderModule)(vk->context->device, shader_stages[1].module, NULL); /* Alpha-blended pipeline. */ module_info.codeSize = alpha_blend_frag_spv_len; module_info.pCode = (const uint32_t*)alpha_blend_frag_spv; shader_stages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; shader_stages[1].pName = "main"; - vkCreateShaderModule(vk->context->device, + VKFUNC(vkCreateShaderModule)(vk->context->device, &module_info, NULL, &shader_stages[1].module); - vkCreateGraphicsPipelines(vk->context->device, vk->pipelines.cache, + VKFUNC(vkCreateGraphicsPipelines)(vk->context->device, vk->pipelines.cache, 1, &pipe, NULL, &vk->pipelines.alpha_blend); /* Build display pipelines. */ @@ -357,12 +357,12 @@ static void vulkan_init_pipelines( VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP : VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; blend_attachment.blendEnable = i & 1; - vkCreateGraphicsPipelines(vk->context->device, vk->pipelines.cache, + VKFUNC(vkCreateGraphicsPipelines)(vk->context->device, vk->pipelines.cache, 1, &pipe, NULL, &vk->display.pipelines[i]); } - vkDestroyShaderModule(vk->context->device, shader_stages[0].module, NULL); - vkDestroyShaderModule(vk->context->device, shader_stages[1].module, NULL); + VKFUNC(vkDestroyShaderModule)(vk->context->device, shader_stages[0].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) @@ -1775,10 +1775,11 @@ static struct video_shader *vulkan_get_current_shader(void *data) static bool vulkan_get_current_sw_framebuffer(void *data, struct retro_framebuffer *framebuffer) { - struct vk_per_frame *chain; - vk_t *vk = (vk_t*)data; - vk->chain = &vk->swapchain[vk->context->current_swapchain_index]; - chain = vk->chain; + struct vk_per_frame *chain = NULL; + vk_t *vk = (vk_t*)data; + vk->chain = + &vk->swapchain[vk->context->current_swapchain_index]; + chain = vk->chain; if (chain->texture.width != framebuffer->width || chain->texture.height != framebuffer->height)