From 3a92a60a8e48909ef5f24961529a6ce9f185434f Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 9 Sep 2017 01:30:47 +0200 Subject: [PATCH] Cleanups --- gfx/common/vulkan_common.h | 145 ++++++++++----------- menu/drivers_display/menu_display_vulkan.c | 33 +++-- 2 files changed, 90 insertions(+), 88 deletions(-) diff --git a/gfx/common/vulkan_common.h b/gfx/common/vulkan_common.h index 519570de34..04785517fd 100644 --- a/gfx/common/vulkan_common.h +++ b/gfx/common/vulkan_common.h @@ -86,24 +86,30 @@ enum vulkan_wsi_type typedef struct vulkan_context { + bool invalid_swapchain; + /* Used by screenshot to get blits with correct colorspace. */ + bool swapchain_is_srgb; + bool swap_interval_emulation_lock; + + unsigned swapchain_width; + unsigned swapchain_height; + unsigned swap_interval; + + uint32_t graphics_queue_index; + uint32_t num_swapchain_images; + uint32_t current_swapchain_index; + VkInstance instance; VkPhysicalDevice gpu; VkDevice device; VkQueue queue; - uint32_t graphics_queue_index; VkPhysicalDeviceProperties gpu_properties; VkPhysicalDeviceMemoryProperties memory_properties; - bool invalid_swapchain; VkImage swapchain_images[VULKAN_MAX_SWAPCHAIN_IMAGES]; VkFence swapchain_fences[VULKAN_MAX_SWAPCHAIN_IMAGES]; VkSemaphore swapchain_semaphores[VULKAN_MAX_SWAPCHAIN_IMAGES]; - uint32_t num_swapchain_images; - uint32_t current_swapchain_index; - unsigned swapchain_width; - unsigned swapchain_height; - unsigned swap_interval; VkFormat swapchain_format; slock_t *queue_lock; @@ -112,18 +118,14 @@ typedef struct vulkan_context #ifdef VULKAN_DEBUG VkDebugReportCallbackEXT debug_callback; #endif - - /* Used by screenshot to get blits with correct colorspace. */ - bool swapchain_is_srgb; - bool swap_interval_emulation_lock; } vulkan_context_t; typedef struct gfx_ctx_vulkan_data { + bool need_new_swapchain; vulkan_context_t context; VkSurfaceKHR vk_surface; VkSwapchainKHR swapchain; - bool need_new_swapchain; } gfx_ctx_vulkan_data_t; struct vulkan_display_surface_info @@ -153,25 +155,27 @@ struct vk_image struct vk_texture { - VkImage image; - VkImageView view; - VkDeviceMemory memory; - - unsigned width, height; - VkFormat format; - - void *mapped; - size_t offset; - size_t stride; - size_t size; - VkDeviceSize memory_size; - uint32_t memory_type; - - VkImageLayout layout; enum vk_texture_type type; bool default_smooth; bool need_manual_cache_management; bool mipmap; + uint32_t memory_type; + unsigned width, height; + size_t offset; + size_t stride; + size_t size; + + void *mapped; + + VkImage image; + VkImageView view; + VkDeviceMemory memory; + + VkFormat format; + + VkDeviceSize memory_size; + + VkImageLayout layout; }; struct vk_buffer @@ -263,39 +267,39 @@ struct vk_draw_quad struct vk_draw_triangles { - VkPipeline pipeline; - struct vk_texture *texture; - VkSampler sampler; - - const void *uniform; - size_t uniform_size; - - const struct vk_buffer_range *vbo; unsigned vertices; + size_t uniform_size; + const void *uniform; + const struct vk_buffer_range *vbo; + struct vk_texture *texture; + VkPipeline pipeline; + VkSampler sampler; }; typedef struct vk { - vulkan_context_t *context; - video_info_t video; - - unsigned tex_w, tex_h; - VkFormat tex_fmt; bool vsync; bool keep_aspect; bool fullscreen; bool quitting; bool should_resize; + + unsigned tex_w, tex_h; unsigned vp_out_width, vp_out_height; - unsigned rotation; - math_matrix_4x4 mvp, mvp_no_rot; - struct video_viewport vp; - VkViewport vk_vp; - - VkRenderPass render_pass; - struct vk_per_frame swapchain[VULKAN_MAX_SWAPCHAIN_IMAGES]; unsigned num_swapchain_images; + unsigned last_valid_index; + + vulkan_context_t *context; + video_info_t video; + + VkFormat tex_fmt; + math_matrix_4x4 mvp, mvp_no_rot; + VkViewport vk_vp; + VkRenderPass render_pass; + struct video_viewport vp; + struct vk_per_frame *chain; + struct vk_per_frame swapchain[VULKAN_MAX_SWAPCHAIN_IMAGES]; /* Currently active command buffer. */ VkCommandBuffer cmd; @@ -304,19 +308,19 @@ typedef struct vk struct { - struct vk_texture staging[VULKAN_MAX_SWAPCHAIN_IMAGES]; - struct scaler_ctx scaler; bool pending; bool streamed; + struct scaler_ctx scaler; + struct vk_texture staging[VULKAN_MAX_SWAPCHAIN_IMAGES]; } readback; struct { - struct vk_texture *images; - struct vk_vertex *vertex; - unsigned count; bool enable; bool full_screen; + unsigned count; + struct vk_texture *images; + struct vk_vertex *vertex; } overlay; struct @@ -337,14 +341,13 @@ typedef struct vk struct { + bool enable; + bool full_screen; + unsigned last_index; + float alpha; struct vk_texture textures[VULKAN_MAX_SWAPCHAIN_IMAGES]; struct vk_texture textures_optimal[VULKAN_MAX_SWAPCHAIN_IMAGES]; bool dirty[VULKAN_MAX_SWAPCHAIN_IMAGES]; - - float alpha; - unsigned last_index; - bool enable; - bool full_screen; } menu; struct @@ -355,39 +358,33 @@ typedef struct vk VkSampler mipmap_linear; } samplers; - unsigned last_valid_index; - - struct vk_per_frame *chain; - struct { + bool enable; + bool valid_semaphore; + + unsigned capacity_cmd; + unsigned last_width; + unsigned last_height; + uint32_t num_semaphores; + uint32_t num_cmd; + uint32_t src_queue_family; + struct retro_hw_render_interface_vulkan iface; const struct retro_vulkan_image *image; const VkSemaphore *semaphores; - uint32_t num_semaphores; VkSemaphore signal_semaphore; - VkPipelineStageFlags *wait_dst_stages; - VkCommandBuffer *cmd; - uint32_t num_cmd; - unsigned capacity_cmd; - - unsigned last_width; - unsigned last_height; - uint32_t src_queue_family; - - bool enable; - bool valid_semaphore; } hw; struct { + uint64_t dirty; VkPipeline pipeline; VkImageView view; VkSampler sampler; math_matrix_4x4 mvp; - uint64_t dirty; } tracker; void *filter_chain; diff --git a/menu/drivers_display/menu_display_vulkan.c b/menu/drivers_display/menu_display_vulkan.c index e95353ef33..385ca402a8 100644 --- a/menu/drivers_display/menu_display_vulkan.c +++ b/menu/drivers_display/menu_display_vulkan.c @@ -217,7 +217,8 @@ static void menu_display_vk_draw(void *data) for (i = 0; i < draw->coords->vertices; i++, pv++) { pv->x = *vertex++; - pv->y = 1.0f - (*vertex++); /* Y-flip. Vulkan is top-left clip space */ + /* Y-flip. Vulkan is top-left clip space */ + pv->y = 1.0f - (*vertex++); pv->tex_x = *tex_coord++; pv->tex_y = *tex_coord++; pv->color.r = *color++; @@ -235,16 +236,17 @@ static void menu_display_vk_draw(void *data) case VIDEO_SHADER_MENU_4: case VIDEO_SHADER_MENU_5: { - const struct vk_draw_triangles call = { - vk->display.pipelines[ - to_menu_pipeline(draw->prim_type, draw->pipeline.id)], - NULL, - VK_NULL_HANDLE, - draw->pipeline.backend_data, - draw->pipeline.backend_data_size, - &range, - draw->coords->vertices, - }; + struct vk_draw_triangles call; + + call.pipeline = vk->display.pipelines[ + to_menu_pipeline(draw->prim_type, draw->pipeline.id)]; + call.texture = NULL; + call.sampler = VK_NULL_HANDLE; + call.uniform = draw->pipeline.backend_data; + call.uniform_size = draw->pipeline.backend_data_size; + call.vbo = ⦥ + call.vertices = draw->coords->vertices; + vulkan_draw_triangles(vk, &call); break; } @@ -261,7 +263,8 @@ static void menu_display_vk_draw(void *data) call.texture = texture; call.sampler = texture->mipmap ? vk->samplers.mipmap_linear : - (texture->default_smooth ? vk->samplers.linear : vk->samplers.nearest); + (texture->default_smooth ? vk->samplers.linear + : vk->samplers.nearest); call.uniform = draw->matrix_data ? draw->matrix_data : menu_display_vk_get_default_mvp(); call.uniform_size = sizeof(math_matrix_4x4); @@ -278,7 +281,8 @@ static void menu_display_vk_restore_clear_color(void) { } -static void menu_display_vk_clear_color(menu_display_ctx_clearcolor_t *clearcolor) +static void menu_display_vk_clear_color( + menu_display_ctx_clearcolor_t *clearcolor) { VkClearRect rect; VkClearAttachment attachment; @@ -287,13 +291,14 @@ static void menu_display_vk_clear_color(menu_display_ctx_clearcolor_t *clearcolo return; memset(&attachment, 0, sizeof(attachment)); + memset(&rect, 0, sizeof(rect)); + attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; attachment.clearValue.color.float32[0] = clearcolor->r; attachment.clearValue.color.float32[1] = clearcolor->g; attachment.clearValue.color.float32[2] = clearcolor->b; attachment.clearValue.color.float32[3] = clearcolor->a; - memset(&rect, 0, sizeof(rect)); rect.rect.extent.width = vk->context->swapchain_width; rect.rect.extent.height = vk->context->swapchain_height; rect.layerCount = 1;