]> O.S.I.I.S - jp/vkvg.git/commitdiff
vkvg_device_create_info wip
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 21 Sep 2023 05:15:37 +0000 (07:15 +0200)
committerj-p <jp_bruyere@hotmail.com>
Mon, 24 Mar 2025 18:12:00 +0000 (19:12 +0100)
include/vkvg.h
src/vkvg_device.c
tests/bezier.c
tests/common/test.c
tests/inverse_colinear.c
tests/offscreen.c
tests/path_extents.c
tests/vkvg-svg/svg-viewer.c

index ba719c6e25f738d7758dc8723077b4ace543e97d..2ac2c31c50a2e70a2e03edb567aba46f3ef1a6ad 100644 (file)
@@ -550,8 +550,6 @@ void vkvg_matrix_get_scale (const vkvg_matrix_t *matrix, float *sx, float *sy);
  * 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.
@@ -560,14 +558,18 @@ void vkvg_matrix_get_scale (const vkvg_matrix_t *matrix, float *sx, float *sy);
  * @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.
@@ -629,10 +631,7 @@ VkvgDevice vkvg_device_create (vkvg_device_create_info_t* info);
  * @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.
@@ -646,12 +645,10 @@ VkvgDevice vkvg_device_create_from_vk (VkInstance inst, VkPhysicalDevice phy, Vk
  * @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.
  *
index b5e5b459c61c71fd3ed5cd0c3d5ee693605f182f..7783fb5fac76c6c875ac0e16064ac87bb7968eda 100644 (file)
@@ -47,17 +47,17 @@ void vkvg_device_set_context_cache_size (VkvgDevice dev, uint32_t maxCount) {
        }
        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;
 
@@ -78,16 +78,16 @@ void _device_init (VkvgDevice dev, VkInstance inst, VkPhysicalDevice phy, VkDevi
 
        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
@@ -279,114 +279,98 @@ VkvgDevice vkvg_device_create (vkvg_device_create_info_t* info) {
 
        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;
 }
 
index 756a3c7fc53a16a29e24745bfa57af9af9b97416..0ac57d3198e9207d29e98ae0091570d1e2ddca31 100644 (file)
@@ -189,9 +189,17 @@ int main(int argc, char* argv[]) {
        vkengine_set_cursor_pos_callback(e, mouse_move_callback);
        vkengine_set_scroll_callback(e, scroll_callback);
 
-       bool deferredResolve = false;
+    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);
 
-       device = vkvg_device_create_from_vk_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, samples, deferredResolve);
        surf = vkvg_surface_create(device, test_width, test_height);
 
        vkh_presenter_build_blit_cmd (r, vkvg_surface_get_vk_image(surf), test_width, test_height);
index 595f71a2b060f3c11fd536b5da126bd220f2e623..c583f8fbe396855369d08e7367148357b2cc2648 100644 (file)
@@ -161,9 +161,17 @@ void init_test (uint32_t width, uint32_t height){
        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);
@@ -496,8 +504,17 @@ void perform_test_offscreen (void(*testfunc)(void), const char *testName, int ar
 
        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);
@@ -559,9 +576,16 @@ void perform_test_onscreen (void(*testfunc)(void), const char *testName, int arg
        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)
@@ -619,7 +643,7 @@ void perform_test_onscreen (void(*testfunc)(void), const char *testName, int arg
 
                testfunc();
 
-               if (deferredResolve)
+        if (info.deferredResolve)
                        vkvg_surface_resolve(surf);
                if (!vkh_presenter_draw (r)){
                        vkh_presenter_get_size (r, &test_width, &test_height);
index da4069f367bf27efe9db2299d6ec58d28b3bf5c4..38b4adc6b35ac294c27ebc6cb3f0359a6b97c418 100644 (file)
@@ -187,10 +187,17 @@ int main(int argc, char* argv[]) {
        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);
-       surf = vkvg_surface_create(device, test_width, test_height);
+    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, test_width, test_height);
 
        vkh_presenter_build_blit_cmd (r, vkvg_surface_get_vk_image(surf), test_width, test_height);
 
index 095baa0b6f4aa262c34b8aca18cfd5b761bf9d1e..895d1e0d4ab3f4f15c6a600d3d0af5ae1d6276aa 100644 (file)
@@ -1,7 +1,10 @@
 #include "vkvg.h"
 
 int main(int argc, char *argv[]) {
-       VkvgDevice dev = vkvg_device_create(VK_SAMPLE_COUNT_1_BIT, false);
+    vkvg_device_create_info_t info = {
+        VK_SAMPLE_COUNT_1_BIT, false
+    };
+    VkvgDevice dev = vkvg_device_create(&info);
        VkvgSurface surf = vkvg_surface_create(dev, 512,512);
        VkvgContext ctx = vkvg_create(surf);
 
index 3011f1e31e69e759491a2f536112540ea822b982..55c69de4db607ea668b47dde174bf5a28df3f639 100644 (file)
@@ -151,9 +151,16 @@ int main(int argc, char* argv[]) {
        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, test_width, test_height);
 
        vkh_presenter_build_blit_cmd (r, vkvg_surface_get_vk_image(surf), test_width, test_height);
index 6d39baba321e3ef8e02388ed98ef15907c95399c..de18cde3776e5b93484771798e5891698bce05ed 100644 (file)
@@ -270,9 +270,16 @@ int main (int argc, char *argv[]){
        VkEngine e = vkengine_create (VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU,VK_PRESENT_MODE_FIFO_KHR, width, height);
        vkengine_set_key_callback (e, key_callback);
        vkengine_set_scroll_callback(e, scroll_callback);
-
-       dev = vkvg_device_create_from_vk_multisample (vkh_app_get_inst(e->app),
-                        vkengine_get_physical_device(e), vkengine_get_device(e), vkengine_get_queue_fam_idx(e), 0, samples, false);
+    vkvg_device_create_info_t info = {
+        samples,
+        false,
+        vkh_app_get_inst(e->app),
+        vkengine_get_physical_device(e),
+        vkengine_get_device(e),
+        vkengine_get_queue_fam_idx(e),
+        0
+    };
+    dev = vkvg_device_create(&info);
 
        VkvgSurface surf = NULL;