From 9c32d03c1eb01ed71d9e268ef7745aa56ef0f3f7 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 12 Aug 2017 17:56:30 +0200 Subject: [PATCH] (Vulkan/Win32) C89_BUILD fixes --- gfx/common/vulkan_common.c | 29 +++++++++++++----- gfx/drivers/vulkan.c | 15 +++++----- gfx/include/vulkan/vk_platform.h | 33 +++++++++++---------- gfx/include/vulkan/vk_sdk_platform.h | 25 ++++++++-------- gfx/include/vulkan/vulkan.h | 10 ++++--- gfx/include/vulkan/vulkan_intel.h | 14 ++++----- ui/drivers/ui_win32.c | 44 ++++++++++++++-------------- 7 files changed, 94 insertions(+), 76 deletions(-) diff --git a/gfx/common/vulkan_common.c b/gfx/common/vulkan_common.c index b8f6c32fac..e2c64f2ffc 100644 --- a/gfx/common/vulkan_common.c +++ b/gfx/common/vulkan_common.c @@ -772,9 +772,12 @@ static void vulkan_check_dynamic_state( if (vk->tracker.dirty & VULKAN_DIRTY_DYNAMIC_BIT) { - const VkRect2D sci = { - { vk->vp.x, vk->vp.y }, - { vk->vp.width, vk->vp.height }}; + VkRect2D sci; + + sci.offset.x = vk->vp.x; + sci.offset.y = vk->vp.y; + sci.extent.width = vk->vp.width; + sci.extent.height = vk->vp.height; vkCmdSetViewport(vk->cmd, 0, 1, &vk->vk_vp); vkCmdSetScissor (vk->cmd, 0, 1, &sci); @@ -1144,8 +1147,15 @@ struct vk_buffer_chain vulkan_buffer_chain_init( VkDeviceSize alignment, VkBufferUsageFlags usage) { - struct vk_buffer_chain chain = { - block_size, alignment, 0, usage, NULL, NULL }; + struct vk_buffer_chain chain; + + chain.block_size = block_size; + chain.alignment = alignment; + chain.offset = 0; + chain.usage = usage; + chain.head = NULL; + chain.current = NULL; + return chain; } @@ -1487,12 +1497,13 @@ static bool vulkan_context_init_device(gfx_ctx_vulkan_data_t *vk) for (i = 0; i < queue_count; i++) { + VkQueueFlags required; VkBool32 supported = VK_FALSE; vkGetPhysicalDeviceSurfaceSupportKHR( vk->context.gpu, i, vk->vk_surface, &supported); - VkQueueFlags required = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT; + required = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT; if (supported && ((queue_properties[i].queueFlags & required) == required)) { vk->context.graphics_queue_index = i; @@ -1573,6 +1584,7 @@ bool vulkan_context_init(gfx_ctx_vulkan_data_t *vk, { unsigned i; VkResult res; + PFN_vkGetInstanceProcAddr GetInstanceProcAddr; VkInstanceCreateInfo info = { VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO }; VkApplicationInfo app = { VK_STRUCTURE_TYPE_APPLICATION_INFO }; @@ -1647,7 +1659,7 @@ bool vulkan_context_init(gfx_ctx_vulkan_data_t *vk, RARCH_LOG("Vulkan dynamic library loaded.\n"); - PFN_vkGetInstanceProcAddr GetInstanceProcAddr = + GetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)dylib_proc(vulkan_library, "vkGetInstanceProcAddr"); if (!GetInstanceProcAddr) @@ -2018,10 +2030,11 @@ bool vulkan_surface_create(gfx_ctx_vulkan_data_t *vk, case VULKAN_WSI_WIN32: #ifdef _WIN32 { + VkWin32SurfaceCreateInfoKHR surf_info; PFN_vkCreateWin32SurfaceKHR create; + if (!VULKAN_SYMBOL_WRAPPER_LOAD_INSTANCE_SYMBOL(vk->context.instance, "vkCreateWin32SurfaceKHR", create)) return false; - VkWin32SurfaceCreateInfoKHR surf_info; memset(&surf_info, 0, sizeof(surf_info)); diff --git a/gfx/drivers/vulkan.c b/gfx/drivers/vulkan.c index 65732b7a95..01e4196e86 100644 --- a/gfx/drivers/vulkan.c +++ b/gfx/drivers/vulkan.c @@ -1194,12 +1194,12 @@ error: static void vulkan_update_filter_chain(vk_t *vk) { - const struct vulkan_filter_chain_swapchain_info info = { - vk->vk_vp, - vk->context->swapchain_format, - vk->render_pass, - vk->context->num_swapchain_images, - }; + struct vulkan_filter_chain_swapchain_info info; + + info.viewport = vk->vk_vp; + info.format = vk->context->swapchain_format; + info.render_pass = vk->render_pass; + info.num_indices = vk->context->num_swapchain_images; if (!vulkan_filter_chain_update_swapchain_info((vulkan_filter_chain_t*)vk->filter_chain, &info)) RARCH_ERR("Failed to update filter chain info. This will probably lead to a crash ...\n"); @@ -1346,9 +1346,10 @@ static void vulkan_set_video_mode(void *data, unsigned width, unsigned height, bool fullscreen) { - (void)data; gfx_ctx_mode_t mode; + (void)data; + mode.width = width; mode.height = height; mode.fullscreen = fullscreen; diff --git a/gfx/include/vulkan/vk_platform.h b/gfx/include/vulkan/vk_platform.h index 5d0fc766ec..3771c169e1 100644 --- a/gfx/include/vulkan/vk_platform.h +++ b/gfx/include/vulkan/vk_platform.h @@ -1,6 +1,7 @@ -// -// File: vk_platform.h -// +/* + * File: vk_platform.h + */ + /* ** Copyright (c) 2014-2015 The Khronos Group Inc. ** @@ -24,7 +25,7 @@ #ifdef __cplusplus extern "C" { -#endif // __cplusplus +#endif /* __cplusplus */ /* *************************************************************************************************** @@ -47,22 +48,22 @@ extern "C" * Function pointer type: typedef void (VKAPI_PTR *PFN_vkCommand)(void); */ #if defined(_WIN32) - // On Windows, Vulkan commands use the stdcall convention + /* On Windows, Vulkan commands use the stdcall convention */ #define VKAPI_ATTR #define VKAPI_CALL __stdcall #define VKAPI_PTR VKAPI_CALL #elif defined(__ANDROID__) && defined(__ARM_EABI__) && !defined(__ARM_ARCH_7A__) - // Android does not support Vulkan in native code using the "armeabi" ABI. + /* Android does not support Vulkan in native code using the "armeabi" ABI. */ #error "Vulkan requires the 'armeabi-v7a' or 'armeabi-v7a-hard' ABI on 32-bit ARM CPUs" #elif defined(__ANDROID__) && defined(__ARM_ARCH_7A__) - // On Android/ARMv7a, Vulkan functions use the armeabi-v7a-hard calling - // convention, even if the application's native code is compiled with the - // armeabi-v7a calling convention. + /* On Android/ARMv7a, Vulkan functions use the armeabi-v7a-hard calling + * convention, even if the application's native code is compiled with the + * armeabi-v7a calling convention. */ #define VKAPI_ATTR __attribute__((pcs("aapcs-vfp"))) #define VKAPI_CALL #define VKAPI_PTR VKAPI_ATTR #else - // On other platforms, use the default calling convention + /* On other platforms, use the default calling convention */ #define VKAPI_ATTR #define VKAPI_CALL #define VKAPI_PTR @@ -83,15 +84,15 @@ extern "C" #else #include #endif -#endif // !defined(VK_NO_STDINT_H) +#endif /* !defined(VK_NO_STDINT_H) */ #ifdef __cplusplus -} // extern "C" -#endif // __cplusplus +} /* extern "C" */ +#endif /* __cplusplus */ -// Platform-specific headers required by platform window system extensions. -// These are enabled prior to #including "vulkan.h". The same enable then -// controls inclusion of the extension interfaces in vulkan.h. +/* Platform-specific headers required by platform window system extensions. + * These are enabled prior to #including "vulkan.h". The same enable then + * controls inclusion of the extension interfaces in vulkan.h. */ #ifdef VK_USE_PLATFORM_ANDROID_KHR #include diff --git a/gfx/include/vulkan/vk_sdk_platform.h b/gfx/include/vulkan/vk_sdk_platform.h index ef9a000fb2..29653774ff 100644 --- a/gfx/include/vulkan/vk_sdk_platform.h +++ b/gfx/include/vulkan/vk_sdk_platform.h @@ -1,6 +1,7 @@ -// -// File: vk_sdk_platform.h -// +/* + * File: vk_sdk_platform.h + */ + /* * Copyright (c) 2015-2016 The Khronos Group Inc. * Copyright (c) 2015-2016 Valve Corporation @@ -27,20 +28,20 @@ #ifndef __cplusplus #undef inline #define inline __inline -#endif // __cplusplus +#endif /* __cplusplus */ #if (defined(_MSC_VER) && _MSC_VER < 1900 /*vs2015*/) -// C99: -// Microsoft didn't implement C99 in Visual Studio; but started adding it with -// VS2013. However, VS2013 still didn't have snprintf(). The following is a -// work-around (Note: The _CRT_SECURE_NO_WARNINGS macro must be set in the -// "CMakeLists.txt" file). -// NOTE: This is fixed in Visual Studio 2015. +/* C99: + * Microsoft didn't implement C99 in Visual Studio; but started adding it with + * VS2013. However, VS2013 still didn't have snprintf(). The following is a + * work-around (Note: The _CRT_SECURE_NO_WARNINGS macro must be set in the + * "CMakeLists.txt" file). + * NOTE: This is fixed in Visual Studio 2015. */ #define snprintf _snprintf #endif #define strdup _strdup -#endif // _WIN32 +#endif /* _WIN32 */ -#endif // VK_SDK_PLATFORM_H +#endif /* VK_SDK_PLATFORM_H */ diff --git a/gfx/include/vulkan/vulkan.h b/gfx/include/vulkan/vulkan.h index 9b91e62973..121738c08f 100644 --- a/gfx/include/vulkan/vulkan.h +++ b/gfx/include/vulkan/vulkan.h @@ -33,16 +33,18 @@ extern "C" { #define VK_MAKE_VERSION(major, minor, patch) \ (((major) << 22) | ((minor) << 12) | (patch)) -// DEPRECATED: This define has been removed. Specific version defines (e.g. VK_API_VERSION_1_0), or the VK_MAKE_VERSION macro, should be used instead. -//#define VK_API_VERSION VK_MAKE_VERSION(1, 0, 0) +/* DEPRECATED: This define has been removed. Specific version defines (e.g. VK_API_VERSION_1_0), or the VK_MAKE_VERSION macro, should be used instead. */ +#if 0 +#define VK_API_VERSION VK_MAKE_VERSION(1, 0, 0) +#endif -// Vulkan 1.0 version number +/* Vulkan 1.0 version number */ #define VK_API_VERSION_1_0 VK_MAKE_VERSION(1, 0, 0) #define VK_VERSION_MAJOR(version) ((uint32_t)(version) >> 22) #define VK_VERSION_MINOR(version) (((uint32_t)(version) >> 12) & 0x3ff) #define VK_VERSION_PATCH(version) ((uint32_t)(version) & 0xfff) -// Version of this file +/* Version of this file */ #define VK_HEADER_VERSION 17 diff --git a/gfx/include/vulkan/vulkan_intel.h b/gfx/include/vulkan/vulkan_intel.h index 1f77128961..15b5a02ad0 100644 --- a/gfx/include/vulkan/vulkan_intel.h +++ b/gfx/include/vulkan/vulkan_intel.h @@ -29,16 +29,16 @@ #ifdef __cplusplus extern "C" { -#endif // __cplusplus +#endif /* __cplusplus */ #define VK_STRUCTURE_TYPE_DMA_BUF_IMAGE_CREATE_INFO_INTEL 1024 typedef struct VkDmaBufImageCreateInfo_ { - VkStructureType sType; // Must be VK_STRUCTURE_TYPE_DMA_BUF_IMAGE_CREATE_INFO_INTEL - const void* pNext; // Pointer to next structure. + VkStructureType sType; /* Must be VK_STRUCTURE_TYPE_DMA_BUF_IMAGE_CREATE_INFO_INTEL */ + const void* pNext; /* Pointer to next structure. */ int fd; VkFormat format; - VkExtent3D extent; // Depth must be 1 + VkExtent3D extent; /* Depth must be 1 */ uint32_t strideInBytes; } VkDmaBufImageCreateInfo; @@ -56,7 +56,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateDmaBufImageINTEL( #endif #ifdef __cplusplus -} // extern "C" -#endif // __cplusplus +} /* extern "C" */ +#endif /* __cplusplus */ -#endif // __VULKAN_INTEL_H__ +#endif /* __VULKAN_INTEL_H__ */ diff --git a/ui/drivers/ui_win32.c b/ui/drivers/ui_win32.c index 116c7844e6..5b2a411390 100644 --- a/ui/drivers/ui_win32.c +++ b/ui/drivers/ui_win32.c @@ -101,7 +101,7 @@ typedef struct HWND label_title; HWND label_val; } trackbar; - }; + } elems; } shader_param_ctrl_t; typedef struct @@ -128,7 +128,7 @@ static bool shader_dlg_refresh_trackbar_label(int index, snprintf(val_buffer, sizeof(val_buffer), "%.2f", shader_info->data->parameters[index].current); - SendMessage(g_shader_dlg.controls[index].trackbar.label_val, + SendMessage(g_shader_dlg.controls[index].elems.trackbar.label_val, WM_SETTEXT, 0, (LPARAM)val_buffer); return true; @@ -155,7 +155,7 @@ static void shader_dlg_params_refresh(void) bool checked = shader_info.data ? (shader_info.data->parameters[i].current == shader_info.data->parameters[i].maximum) : false; - SendMessage(control->checkbox.hwnd, BM_SETCHECK, checked, 0); + SendMessage(control->elems.checkbox.hwnd, BM_SETCHECK, checked, 0); } break; case SHADER_PARAM_CTRL_TRACKBAR: @@ -167,14 +167,14 @@ static void shader_dlg_params_refresh(void) if (shader_info.data) { - SendMessage(control->trackbar.hwnd, + SendMessage(control->elems.trackbar.hwnd, TBM_SETRANGEMIN, (WPARAM)TRUE, (LPARAM)0); - SendMessage(control->trackbar.hwnd, + SendMessage(control->elems.trackbar.hwnd, TBM_SETRANGEMAX, (WPARAM)TRUE, (LPARAM)((shader_info.data->parameters[i].maximum - shader_info.data->parameters[i].minimum) / shader_info.data->parameters[i].step)); - SendMessage(control->trackbar.hwnd, TBM_SETPOS, (WPARAM)TRUE, + SendMessage(control->elems.trackbar.hwnd, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)((shader_info.data->parameters[i].current - shader_info.data->parameters[i].minimum) / shader_info.data->parameters[i].step)); @@ -207,13 +207,13 @@ static void shader_dlg_params_clear(void) { const ui_window_t *window = ui_companion_driver_get_window_ptr(); if (window) - window->destroy(&control->checkbox); + window->destroy(&control->elems.checkbox); } break; case SHADER_PARAM_CTRL_TRACKBAR: - DestroyWindow(control->trackbar.label_title); - DestroyWindow(control->trackbar.label_val); - DestroyWindow(control->trackbar.hwnd); + DestroyWindow(control->elems.trackbar.label_title); + DestroyWindow(control->elems.trackbar.label_val); + DestroyWindow(control->elems.trackbar.hwnd); break; } @@ -260,12 +260,12 @@ void shader_dlg_params_reload(void) } control->type = SHADER_PARAM_CTRL_CHECKBOX; - control->checkbox.hwnd = CreateWindowEx(0, "BUTTON", + control->elems.checkbox.hwnd = CreateWindowEx(0, "BUTTON", shader_info.data->parameters[i].desc, WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX, pos_x, pos_y, SHADER_DLG_CTRL_WIDTH, SHADER_DLG_CHECKBOX_HEIGHT, g_shader_dlg.window.hwnd, (HMENU)(size_t)i, NULL, NULL); - SendMessage(control->checkbox.hwnd, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0)); + SendMessage(control->elems.checkbox.hwnd, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0)); pos_y += SHADER_DLG_CHECKBOX_HEIGHT + SHADER_DLG_CTRL_MARGIN; } else @@ -277,29 +277,29 @@ void shader_dlg_params_reload(void) pos_x += SHADER_DLG_WIDTH; } - control->type = SHADER_PARAM_CTRL_TRACKBAR; - control->trackbar.label_title = CreateWindowEx(0, "STATIC", + control->type = SHADER_PARAM_CTRL_TRACKBAR; + control->elems.trackbar.label_title = CreateWindowEx(0, "STATIC", shader_info.data->parameters[i].desc, WS_CHILD | WS_VISIBLE | SS_LEFT, pos_x, pos_y, SHADER_DLG_CTRL_WIDTH, SHADER_DLG_LABEL_HEIGHT, g_shader_dlg.window.hwnd, (HMENU)(size_t)i, NULL, NULL); - SendMessage(control->trackbar.label_title, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0)); + SendMessage(control->elems.trackbar.label_title, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0)); pos_y += SHADER_DLG_LABEL_HEIGHT; - control->trackbar.hwnd = CreateWindowEx(0, (LPCSTR)TRACKBAR_CLASS, "", + control->elems.trackbar.hwnd = CreateWindowEx(0, (LPCSTR)TRACKBAR_CLASS, "", WS_CHILD | WS_VISIBLE | TBS_HORZ | TBS_NOTICKS, pos_x + SHADER_DLG_TRACKBAR_LABEL_WIDTH, pos_y, SHADER_DLG_TRACKBAR_WIDTH, SHADER_DLG_TRACKBAR_HEIGHT, g_shader_dlg.window.hwnd, (HMENU)(size_t)i, NULL, NULL); - control->trackbar.label_val = CreateWindowEx(0, "STATIC", "", + control->elems.trackbar.label_val = CreateWindowEx(0, "STATIC", "", WS_CHILD | WS_VISIBLE | SS_LEFT, pos_x, pos_y, SHADER_DLG_TRACKBAR_LABEL_WIDTH, SHADER_DLG_LABEL_HEIGHT, g_shader_dlg.window.hwnd, (HMENU)(size_t)i, NULL, NULL); - SendMessage(control->trackbar.label_val, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0)); + SendMessage(control->elems.trackbar.label_val, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0)); - SendMessage(control->trackbar.hwnd, TBM_SETBUDDY, (WPARAM)TRUE, - (LPARAM)control->trackbar.label_val); + SendMessage(control->elems.trackbar.hwnd, TBM_SETBUDDY, (WPARAM)TRUE, + (LPARAM)control->elems.trackbar.label_val); pos_y += SHADER_DLG_TRACKBAR_HEIGHT + SHADER_DLG_CTRL_MARGIN; @@ -402,7 +402,7 @@ static LRESULT CALLBACK ShaderDlgWndProc(HWND hwnd, UINT message, video_shader_ctx_t shader_info; video_shader_driver_get_current_shader(&shader_info); - if (SendMessage(g_shader_dlg.controls[i].checkbox.hwnd, + if (SendMessage(g_shader_dlg.controls[i].elems.checkbox.hwnd, BM_GETCHECK, 0, 0) == BST_CHECKED) shader_info.data->parameters[i].current = shader_info.data->parameters[i].maximum; @@ -424,7 +424,7 @@ static LRESULT CALLBACK ShaderDlgWndProc(HWND hwnd, UINT message, if (g_shader_dlg.controls[i].type != SHADER_PARAM_CTRL_TRACKBAR) break; - pos = (int)SendMessage(g_shader_dlg.controls[i].trackbar.hwnd, TBM_GETPOS, 0, 0); + pos = (int)SendMessage(g_shader_dlg.controls[i].elems.trackbar.hwnd, TBM_GETPOS, 0, 0); {