* Structure used to pass parameter to the device creation method.
*
* @code
- * x_new = xx * x + xy * y + x0;
- * y_new = yx * x + yy * y + y0;
* @endcode
*
* @samples: sample count.
* @vkdev: vulkan logical device, may be null to create a new one.
* @qFamIdx: graphic queue family index, ignored if vkdev is NULL.
* @qIndex: queue index, ignored if vkdev is NULL.
+ * @deferredResolve: If true, the final simple sampled image of the surface will only be resolved on demand
+ * when calling @ref vkvg_surface_get_vk_image or by explicitly calling @ref vkvg_multisample_surface_resolve.
+ * If false, multisampled image is resolved on each draw operation.
*/
typedef struct {
- VkSampleCountFlags samples;
- VkInstance inst;
+ VkSampleCountFlags samples;
+ bool deferredResolve;
+ VkInstance inst;
VkPhysicalDevice phy;
VkDevice vkdev;
uint32_t qFamIdx;
- uint32_t qIndex;
+ uint32_t qIndex;
}vkvg_device_create_info_t;
/**
* @brief Set device ready for multithreading.
* @param qFamIdx Queue family Index of the graphic queue used for drawing operations.
* @param qIndex Index of the queue into the choosen familly, 0 in general.
* @return The handle of the created vkvg device, or null if an error occured.
- */
-vkvg_public
-VkvgDevice vkvg_device_create_from_vk (VkInstance inst, VkPhysicalDevice phy, VkDevice vkdev, uint32_t qFamIdx, uint32_t qIndex);
-/**
+
* @brief Create a new multisampled vkvg device.
*
* This function allows to create vkvg device for working with multisampled surfaces.
* @param qFamIdx Queue family Index of the graphic queue used for drawing operations.
* @param qIndex Index of the queue into the choosen familly, 0 in general.
* @param samples The sample count that will be setup for the surfaces created by this device.
- * @param deferredResolve If true, the final simple sampled image of the surface will only be resolved on demand
- * when calling @ref vkvg_surface_get_vk_image or by explicitly calling @ref vkvg_multisample_surface_resolve. If false, multisampled image is resolved on each draw operation.
+
* @return The handle of the created vkvg device, or null if an error occured.
- */
-vkvg_public
-VkvgDevice vkvg_device_create_from_vk_multisample (VkInstance inst, VkPhysicalDevice phy, VkDevice vkdev, uint32_t qFamIdx, uint32_t qIndex, VkSampleCountFlags samples, bool deferredResolve);
+
+
/**
* @brief Decrement the reference count of the device by 1. Release all its resources if count reaches 0.
*
}
dev->cachedContextLast = cur;
}
-void _device_init (VkvgDevice dev, VkInstance inst, VkPhysicalDevice phy, VkDevice vkdev, uint32_t qFamIdx, uint32_t qIndex, VkSampleCountFlags samples, bool deferredResolve) {
- dev->vkDev = vkdev;
- dev->phy = phy;
- dev->instance = inst;
+void _device_init (VkvgDevice dev, const vkvg_device_create_info_t* info) {
+ dev->vkDev = info->vkdev;
+ dev->phy = info->phy;
+ dev->instance = info->inst;
dev->hdpi = 72;
- dev->vdpi = 72;
- dev->samples= samples;
+ dev->vdpi = 72;
+ dev->samples= info->samples;
if (dev->samples == VK_SAMPLE_COUNT_1_BIT)
dev->deferredResolve = false;
- else
- dev->deferredResolve = deferredResolve;
+ else
+ dev->deferredResolve = info->deferredResolve;
dev->cachedContextMaxCount = VKVG_MAX_CACHED_CONTEXT_COUNT;
VkhPhyInfo phyInfos = vkh_phyinfo_create (dev->phy, NULL);
- dev->phyMemProps = phyInfos->memProps;
- dev->gQueue = vkh_queue_create ((VkhDevice)dev, qFamIdx, qIndex);
+ dev->phyMemProps = phyInfos->memProps;
+ dev->gQueue = vkh_queue_create ((VkhDevice)dev, info->qFamIdx, info->qIndex);
//mtx_init (&dev->gQMutex, mtx_plain);
vkh_phyinfo_destroy (phyInfos);
#ifdef VKH_USE_VMA
VmaAllocatorCreateInfo allocatorInfo = {
- .physicalDevice = phy,
- .device = vkdev
+ .physicalDevice = info->phy,
+ .device = info->vkdev
};
vmaCreateAllocator(&allocatorInfo, (VmaAllocator*)&dev->allocator);
#endif
dev->references = 1;
- const char* enabledExts [10];
- const char* enabledLayers[10];
- uint32_t enabledExtsCount = 0, enabledLayersCount = 0, phyCount = 0;
+ if (!info->vkdev) {
+ const char* enabledExts [10];
+ const char* enabledLayers[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
+
+ #ifdef VKVG_USE_RENDERDOC
+ if (vkh_layer_is_present("VK_LAYER_RENDERDOC_Capture"))
+ enabledLayers[enabledLayersCount++] = "VK_LAYER_RENDERDOC_Capture";
+ #endif
+ vkh_layers_check_release();
+
+ vkvg_get_required_instance_extensions (enabledExts, &enabledExtsCount);
+
+ #ifdef VK_VERSION_1_2
+ VkhApp app = vkh_app_create(1, 2, "vkvg", enabledLayersCount, enabledLayers, enabledExtsCount, enabledExts);
+ #else
+ VkhApp app = vkh_app_create(1, 1, "vkvg", enabledLayersCount, enabledLayers, enabledExtsCount, enabledExts);
+ #endif
+
+ #if defined(DEBUG) && defined (VKVG_DBG_UTILS)
+ vkh_app_enable_debug_messenger(app
+ , VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT
+ , VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT
+ , NULL);
+ #endif
+
+ VkhPhyInfo* phys = vkh_app_get_phyinfos (app, &phyCount, VK_NULL_HANDLE);
+ if (phyCount == 0) {
+ dev->status = VKVG_STATUS_DEVICE_ERROR;
+ vkh_app_destroy (app);
+ return dev;
+ }
+
+ VkhPhyInfo pi = 0;
+ if (!_device_try_get_phyinfo(phys, phyCount, VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU, &pi))
+ if (!_device_try_get_phyinfo(phys, phyCount, VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU, &pi))
+ pi = phys[0];
+
+ if (!(pi->properties.limits.framebufferColorSampleCounts & info->samples)) {
+ LOG(VKVG_LOG_ERR, "CREATE Device failed: sample count not supported: %d\n", info->samples);
+ dev->status = VKVG_STATUS_DEVICE_ERROR;
+ vkh_app_free_phyinfos (phyCount, phys);
+ vkh_app_destroy (app);
+ return dev;
+ }
+
+ uint32_t qCount = 0;
+ float qPriorities[] = {0.0};
+ VkDeviceQueueCreateInfo pQueueInfos[] = { {0},{0},{0} };
+
+ if (vkh_phyinfo_create_queues (pi, pi->gQueue, 1, qPriorities, &pQueueInfos[qCount]))
+ qCount++;
+
+ enabledExtsCount=0;
+
+ if (vkvg_get_required_device_extensions (pi->phy, enabledExts, &enabledExtsCount) != VKVG_STATUS_SUCCESS){
+ dev->status = VKVG_STATUS_DEVICE_ERROR;
+ vkh_app_free_phyinfos (phyCount, phys);
+ vkh_app_destroy (app);
+ return dev;
+ }
+
+ VkPhysicalDeviceFeatures enabledFeatures = {0};
+ const void* pNext = vkvg_get_device_requirements (&enabledFeatures);
+
+ VkDeviceCreateInfo device_info = { .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
+ .queueCreateInfoCount = qCount,
+ .pQueueCreateInfos = (VkDeviceQueueCreateInfo*)&pQueueInfos,
+ .enabledExtensionCount = enabledExtsCount,
+ .ppEnabledExtensionNames = enabledExts,
+ .pEnabledFeatures = &enabledFeatures,
+ .pNext = pNext};
+ dev->vkhDev = vkh_device_create(app, pi, &device_info);
+
+ vkh_app_free_phyinfos (phyCount, phys);
+
+ info->inst = vkh_app_get_inst(app);
+ info->phy = vkh_device_get_phy(dev->vkhDev);
+ info->vkdev = vkh_device_get_vkdev(dev->vkhDev);
+ info->qFamIdx = pi->gQueue;
+ info->qIndex = 0;
+ }
+
+ _device_init (dev, info);
- vkh_layers_check_init();
-
-#ifdef VKVG_USE_VALIDATION
- if (vkh_layer_is_present("VK_LAYER_KHRONOS_validation"))
- enabledLayers[enabledLayersCount++] = "VK_LAYER_KHRONOS_validation";
-#endif
-
-#ifdef VKVG_USE_RENDERDOC
- if (vkh_layer_is_present("VK_LAYER_RENDERDOC_Capture"))
- enabledLayers[enabledLayersCount++] = "VK_LAYER_RENDERDOC_Capture";
-#endif
- vkh_layers_check_release();
-
- vkvg_get_required_instance_extensions (enabledExts, &enabledExtsCount);
-
-#ifdef VK_VERSION_1_2
- VkhApp app = vkh_app_create(1, 2, "vkvg", enabledLayersCount, enabledLayers, enabledExtsCount, enabledExts);
-#else
- VkhApp app = vkh_app_create(1, 1, "vkvg", enabledLayersCount, enabledLayers, enabledExtsCount, enabledExts);
-#endif
-
-#if defined(DEBUG) && defined (VKVG_DBG_UTILS)
- vkh_app_enable_debug_messenger(app
- , VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT
- , VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT
- , NULL);
-#endif
-
- VkhPhyInfo* phys = vkh_app_get_phyinfos (app, &phyCount, VK_NULL_HANDLE);
- if (phyCount == 0) {
- dev->status = VKVG_STATUS_DEVICE_ERROR;
- vkh_app_destroy (app);
- return dev;
- }
-
- VkhPhyInfo pi = 0;
- if (!_device_try_get_phyinfo(phys, phyCount, VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU, &pi))
- if (!_device_try_get_phyinfo(phys, phyCount, VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU, &pi))
- pi = phys[0];
-
- if (!(pi->properties.limits.framebufferColorSampleCounts & info->samples)) {
- LOG(VKVG_LOG_ERR, "CREATE Device failed: sample count not supported: %d\n", info->samples);
- dev->status = VKVG_STATUS_DEVICE_ERROR;
- vkh_app_free_phyinfos (phyCount, phys);
- vkh_app_destroy (app);
- return dev;
- }
-
- uint32_t qCount = 0;
- float qPriorities[] = {0.0};
- VkDeviceQueueCreateInfo pQueueInfos[] = { {0},{0},{0} };
-
- if (vkh_phyinfo_create_queues (pi, pi->gQueue, 1, qPriorities, &pQueueInfos[qCount]))
- qCount++;
-
- enabledExtsCount=0;
-
- if (vkvg_get_required_device_extensions (pi->phy, enabledExts, &enabledExtsCount) != VKVG_STATUS_SUCCESS){
- dev->status = VKVG_STATUS_DEVICE_ERROR;
- vkh_app_free_phyinfos (phyCount, phys);
- vkh_app_destroy (app);
- return dev;
- }
-
- VkPhysicalDeviceFeatures enabledFeatures = {0};
- const void* pNext = vkvg_get_device_requirements (&enabledFeatures);
-
- VkDeviceCreateInfo device_info = { .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
- .queueCreateInfoCount = qCount,
- .pQueueCreateInfos = (VkDeviceQueueCreateInfo*)&pQueueInfos,
- .enabledExtensionCount = enabledExtsCount,
- .ppEnabledExtensionNames = enabledExts,
- .pEnabledFeatures = &enabledFeatures,
- .pNext = pNext};
-
- VkhDevice vkhd = vkh_device_create(app, pi, &device_info);
-
- _device_init (dev,
- vkh_app_get_inst(app),
- vkh_device_get_phy(vkhd),
- vkh_device_get_vkdev(vkhd),
- pi->gQueue, 0,
- info->samples, deferredResolve);
-
- dev->vkhDev = vkhd;
-
- vkh_app_free_phyinfos (phyCount, phys);
-
- return dev;
-}
-VkvgDevice vkvg_device_create_from_vk(VkInstance inst, VkPhysicalDevice phy, VkDevice vkdev, uint32_t qFamIdx, uint32_t qIndex)
-{
- return vkvg_device_create_from_vk_multisample (inst,phy,vkdev,qFamIdx,qIndex, VK_SAMPLE_COUNT_1_BIT, false);
-}
-VkvgDevice vkvg_device_create_from_vk_multisample(VkInstance inst, VkPhysicalDevice phy, VkDevice vkdev, uint32_t qFamIdx, uint32_t qIndex, VkSampleCountFlags samples, bool deferredResolve)
-{
- LOG(VKVG_LOG_INFO, "CREATE Device from vk: qFam = %d; qIdx = %d\n", qFamIdx, qIndex);
- VkvgDevice dev = (vkvg_device*)calloc(1,sizeof(vkvg_device));
- if (!dev) {
- LOG(VKVG_LOG_ERR, "CREATE Device failed, no memory\n");
- exit(-1);
- }
- dev->references = 1;
- _device_init(dev, inst, phy, vkdev, qFamIdx, qIndex, samples, deferredResolve);
return dev;
}
vkengine_set_cursor_pos_callback(e, mouse_move_callback);
vkengine_set_scroll_callback(e, scroll_callback);
- bool deferredResolve = false;
-
- device = vkvg_device_create_from_vk_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, samples, deferredResolve);
+ vkvg_device_create_info_t info = {
+ samples,
+ false,
+ vkh_app_get_inst(e->app),
+ r->dev->phy,
+ r->dev->dev,
+ r->qFam,
+ 0
+ };
+
+ device = vkvg_device_create(&info);
surf = vkvg_surface_create(device, width, height);
vkh_presenter_build_blit_cmd (r, vkvg_surface_get_vk_image(surf), width, height);
VkhDevice dev = vkh_device_create(app, pi, &device_info);
-
- device = vkvg_device_create_from_vk_multisample(vkh_app_get_inst(app), dev->phy, dev->dev, pi->gQueue, 0, samples, deferredResolve);
+ vkvg_device_create_info_t info = {
+ samples,
+ deferredResolve,
+ vkh_app_get_inst(e->app),
+ dev->phy,
+ dev->dev,
+ pi->gQueue,
+ 0
+ };
+
+ device = vkvg_device_create(&info);
//vkvg_device_set_dpy(device, 96, 96);
vkh_app_free_phyinfos (phyCount, phys);
vkengine_set_cursor_pos_callback (e, mouse_move_callback);
vkengine_set_scroll_callback (e, scroll_callback);
- bool deferredResolve = false;
-
- device = vkvg_device_create_from_vk_multisample (vkh_app_get_inst (e->app), r->dev->phy, r->dev->dev, r->qFam, 0, samples, deferredResolve);
+ vkvg_device_create_info_t info = {
+ samples,
+ false,
+ vkh_app_get_inst(e->app),
+ r->dev->phy,
+ r->dev->dev,
+ r->qFam,
+ 0
+ };
+ device = vkvg_device_create(&info);
vkvg_device_set_dpy (device, 96, 96);
if (threadAware)
testfunc();
- if (deferredResolve)
+ if (info.deferredResolve)
vkvg_surface_resolve(surf);
if (!vkh_presenter_draw (r)){
vkh_presenter_get_size (r, &test_width, &test_height);