VkvgDevice vkvg_device_create(VkSampleCountFlags samples, bool deferredResolve) {
const char* enabledExts [10];
- uint32_t enabledExtsCount = 0, phyCount = 0;
+ const char* enabledLayers[10];
+ uint32_t enabledExtsCount = 0, enabledLayersCount = 0, phyCount = 0;
-#ifdef VKVG_USE_RENDERDOC
- const uint32_t enabledLayersCount = 2;
- const char* enabledLayers[] = {"VK_LAYER_KHRONOS_validation", "VK_LAYER_RENDERDOC_Capture"};
-#elif defined (VKVG_USE_VALIDATION)
- const uint32_t enabledLayersCount = 1;
- const char* enabledLayers[] = {"VK_LAYER_KHRONOS_validation"};
-#else
- const uint32_t enabledLayersCount = 0;
- const char** enabledLayers = NULL;
+ vkh_layers_check_init();
+
+#ifdef VKVG_USE_VALIDATION
+ if (vkh_layer_is_present("VK_LAYER_KHRONOS_validation"))
+ enabledLayers[enabledLayersCount++] = "VK_LAYER_KHRONOS_validation";
#endif
-#if defined(DEBUG) && defined (VKVG_DBG_UTILS)
- enabledExts[enabledExtsCount++] = "VK_EXT_debug_utils";
+
+#ifdef VKVG_USE_RENDERDOC
+ if (vkh_layer_is_present("VK_LAYER_RENDERDOC_Capture"))
+ enabledLayers[enabledLayersCount++] = "VK_LAYER_RENDERDOC_Capture";
#endif
+ vkh_layers_check_release();
- _instance_extensions_check_init ();
+ vkh_instance_extensions_check_init ();
#if defined(DEBUG) && defined (VKVG_DBG_UTILS)
- bool dbgUtilsSupported = _instance_extension_supported("VK_EXT_debug_utils");
+ bool dbgUtilsSupported = vkh_instance_extension_supported("VK_EXT_debug_utils");
if (dbgUtilsSupported)
enabledExts[enabledExtsCount++] = "VK_EXT_debug_utils";
#endif
- if (_instance_extension_supported("VK_KHR_get_physical_device_properties2"))
+ if (vkh_instance_extension_supported("VK_KHR_get_physical_device_properties2"))
enabledExts[enabledExtsCount++] = "VK_KHR_get_physical_device_properties2";
- _instance_extensions_check_release();
+ vkh_instance_extensions_check_release();
VkhApp app = vkh_app_create(1, 2, "vkvg", enabledLayersCount, enabledLayers, enabledExtsCount, enabledExts);
LOG(VKVG_LOG_ERR, "vkvg create device failed: image format not supported: %d\n", format);
}
-static VkExtensionProperties* instExtProps;
-static uint32_t instExtCount;
-bool _instance_extension_supported (const char* instanceName) {
- for (uint32_t i=0; i<instExtCount; i++) {
- if (!strcmp(instExtProps[i].extensionName, instanceName))
- return true;
- }
- return false;
-}
-void _instance_extensions_check_init () {
- VK_CHECK_RESULT(vkEnumerateInstanceExtensionProperties(NULL, &instExtCount, NULL));
- instExtProps =(VkExtensionProperties*)malloc(instExtCount * sizeof(VkExtensionProperties));
- VK_CHECK_RESULT(vkEnumerateInstanceExtensionProperties(NULL, &instExtCount, instExtProps));
-}
-void _instance_extensions_check_release () {
- free (instExtProps);
-}
-
-static VkLayerProperties* instLayerProps;
-static uint32_t instance_layer_count;
-bool _layer_is_present (const char* layerName) {
- for (uint32_t i=0; i<instance_layer_count; i++) {
- if (!strcmp(instLayerProps[i].layerName, layerName))
- return true;
- }
- return false;
-}
-void _layers_check_init () {
- VK_CHECK_RESULT(vkEnumerateInstanceLayerProperties(&instance_layer_count, NULL));
- instLayerProps =(VkLayerProperties*)malloc(instance_layer_count * sizeof(VkLayerProperties));
- VK_CHECK_RESULT(vkEnumerateInstanceLayerProperties(&instance_layer_count, instLayerProps));
-}
-void _layers_check_release () {
- free (instLayerProps);
-}
void _dump_image_format_properties (VkvgDevice dev, VkFormat format) {
/*VkImageFormatProperties imgProps;
VK_CHECK_RESULT(vkGetPhysicalDeviceImageFormatProperties(dev->phy,
void _wait_idle (VkvgDevice dev);
void _wait_and_reset_device_fence (VkvgDevice dev);
void _submit_cmd (VkvgDevice dev, VkCommandBuffer* cmd, VkFence fence);
-
-bool _instance_extension_supported (const char* instanceName);
-void _instance_extensions_check_init ();
-void _instance_extensions_check_release ();
-
-bool _layer_is_present (const char* layerName);
-void _layers_check_init ();
-void _layers_check_release ();
#endif
#define _USE_MATH_DEFINES
#include <math.h>
-#define M_PIF 3.14159265358979323846f /* float pi */
-#define M_PIF_2 1.57079632679489661923f
-#define M_2_PIF 0.63661977236758134308f // 2/pi
+#ifndef M_PIF
+ #define M_PIF 3.14159265358979323846f /* float pi */
+ #define M_PIF_2 1.57079632679489661923f
+ #define M_2_PIF 0.63661977236758134308f // 2/pi
+#endif
+
/*#ifndef M_2_PI
#define M_2_PI 0.63661977236758134308 // 2/pi
#endif*/
#ifdef DEBUG
#define LOG(level,...) { \
- if ((vkvg_log_level) & (level)) \
+ if ((vkvg_log_level) & (level)) \
fprintf (stdout, __VA_ARGS__); \
}
#else
exit(-1);
}
- uint32_t enabledExtsCount = 0, phyCount = 0;
- const char** gflwExts = glfwGetRequiredInstanceExtensions (&enabledExtsCount);
-
+ const char* enabledLayers[10];
const char* enabledExts [10];
+ uint32_t enabledExtsCount = 0, enabledLayersCount = 0, phyCount = 0;
+
+ vkh_layers_check_init();
+#ifdef VKVG_USE_VALIDATION
+ if (vkh_layer_is_present("VK_LAYER_KHRONOS_validation"))
+ enabledLayers[enabledLayersCount++] = "VK_LAYER_KHRONOS_validation";
+#endif
- for (uint32_t i=0;i<enabledExtsCount;i++)
- enabledExts[i] = gflwExts[i];
#ifdef VKVG_USE_RENDERDOC
- const uint32_t enabledLayersCount = 2;
- const char* enabledLayers[] = {"VK_LAYER_KHRONOS_validation", "VK_LAYER_RENDERDOC_Capture"};
-#elif defined (VKVG_USE_VALIDATION)
- const uint32_t enabledLayersCount = 1;
- const char* enabledLayers[] = {"VK_LAYER_KHRONOS_validation"};
-#else
- const uint32_t enabledLayersCount = 0;
- const char** enabledLayers = NULL;
+ if (vkh_layer_is_present("VK_LAYER_RENDERDOC_Capture"))
+ enabledLayers[enabledLayersCount++] = "VK_LAYER_RENDERDOC_Capture";
#endif
+ vkh_layers_check_release();
+
+ const char** gflwExts = glfwGetRequiredInstanceExtensions (&enabledExtsCount);
+
+ for (uint32_t i=0;i<enabledExtsCount;i++)
+ enabledExts[i] = gflwExts[i];
+
+ vkh_instance_extensions_check_init ();
#if defined(DEBUG) && defined (VKVG_DBG_UTILS)
- enabledExts[enabledExtsCount++] = "VK_EXT_debug_utils";
+ bool dbgUtilsSupported = vkh_instance_extension_supported("VK_EXT_debug_utils");
+ if (dbgUtilsSupported)
+ enabledExts[enabledExtsCount++] = "VK_EXT_debug_utils";
#endif
- uint32_t instanceExtCount;
- VK_CHECK_RESULT(vkEnumerateInstanceExtensionProperties(NULL, &instanceExtCount, NULL));
- VkExtensionProperties* instanceExtProps =(VkExtensionProperties*)malloc(instanceExtCount * sizeof(VkExtensionProperties));
- VK_CHECK_RESULT(vkEnumerateInstanceExtensionProperties(NULL, &instanceExtCount, instanceExtProps));
-
- if (instance_extension_supported(instanceExtProps, instanceExtCount, "VK_KHR_get_physical_device_properties2"))
+ if (vkh_instance_extension_supported("VK_KHR_get_physical_device_properties2"))
enabledExts[enabledExtsCount++] = "VK_KHR_get_physical_device_properties2";
- free(instanceExtProps);
+ vkh_instance_extensions_check_release();
vk_engine_t* e = (vk_engine_t*)calloc(1,sizeof(vk_engine_t));
e->app = vkh_app_create(1 ,2 , "vkvgTest", enabledLayersCount, enabledLayers, enabledExtsCount, enabledExts);
#if defined(DEBUG) && defined (VKVG_DBG_UTILS)
- vkh_app_enable_debug_messenger(e->app
+ if (dbgUtilsSupported)
+ vkh_app_enable_debug_messenger(e->app
, VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT
//| VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT
//| VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT
-Subproject commit 41daf55f834aede1698aaa1afae02e2faf22530a
+Subproject commit d4c367287ea50e854205e27cf814abbb23615b8a