summaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2023-09-21 07:15:37 +0200
committerj-p <jp_bruyere@hotmail.com>2025-03-24 19:12:00 +0100
commit3019647f64fc3cc4739422b52345bf80fb89b749 (patch)
treebc855dd4fec698d1c15e548f37b39c901ff6e87c
parent1b05828090997016f24549fc6ee5b505996fc333 (diff)
vkvg_device_create_info wip
-rw-r--r--include/vkvg.h25
-rw-r--r--src/vkvg_device.c186
-rw-r--r--tests/bezier.c12
-rw-r--r--tests/common/test.c38
-rw-r--r--tests/inverse_colinear.c15
-rw-r--r--tests/offscreen.c5
-rw-r--r--tests/path_extents.c13
-rw-r--r--tests/vkvg-svg/svg-viewer.c13
8 files changed, 172 insertions, 135 deletions
diff --git a/include/vkvg.h b/include/vkvg.h
index ba719c6..2ac2c31 100644
--- a/include/vkvg.h
+++ b/include/vkvg.h
@@ -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.
*
diff --git a/src/vkvg_device.c b/src/vkvg_device.c
index b5e5b45..7783fb5 100644
--- a/src/vkvg_device.c
+++ b/src/vkvg_device.c
@@ -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();
+ 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_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();
+ #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);
+ 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
+ #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
+ #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* 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];
+ 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;
- }
+ 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} };
+ 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++;
+ if (vkh_phyinfo_create_queues (pi, pi->gQueue, 1, qPriorities, &pQueueInfos[qCount]))
+ qCount++;
- enabledExtsCount=0;
+ 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;
- }
+ 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);
+ 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};
+ 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);
- VkhDevice vkhd = vkh_device_create(app, pi, &device_info);
+ vkh_app_free_phyinfos (phyCount, phys);
- _device_init (dev,
- vkh_app_get_inst(app),
- vkh_device_get_phy(vkhd),
- vkh_device_get_vkdev(vkhd),
- pi->gQueue, 0,
- info->samples, deferredResolve);
+ 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;
+ }
- dev->vkhDev = vkhd;
+ _device_init (dev, info);
- 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;
}
diff --git a/tests/bezier.c b/tests/bezier.c
index 756a3c7..0ac57d3 100644
--- a/tests/bezier.c
+++ b/tests/bezier.c
@@ -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);
diff --git a/tests/common/test.c b/tests/common/test.c
index 595f71a..c583f8f 100644
--- a/tests/common/test.c
+++ b/tests/common/test.c
@@ -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;
+ 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_from_vk_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, samples, deferredResolve);
+ 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);
+ 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_from_vk_multisample(vkh_app_get_inst(app), dev->phy, dev->dev, pi->gQueue, 0, samples, deferredResolve);
+ 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);
diff --git a/tests/inverse_colinear.c b/tests/inverse_colinear.c
index da4069f..38b4adc 100644
--- a/tests/inverse_colinear.c
+++ b/tests/inverse_colinear.c
@@ -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);
diff --git a/tests/offscreen.c b/tests/offscreen.c
index 095baa0..895d1e0 100644
--- a/tests/offscreen.c
+++ b/tests/offscreen.c
@@ -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);
diff --git a/tests/path_extents.c b/tests/path_extents.c
index 3011f1e..55c69de 100644
--- a/tests/path_extents.c
+++ b/tests/path_extents.c
@@ -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);
diff --git a/tests/vkvg-svg/svg-viewer.c b/tests/vkvg-svg/svg-viewer.c
index 6d39bab..de18cde 100644
--- a/tests/vkvg-svg/svg-viewer.c
+++ b/tests/vkvg-svg/svg-viewer.c
@@ -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;