From a4d3c3d64386e216ff836b96231426f4448dde08 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Mon, 16 Apr 2018 16:10:53 +0200 Subject: [PATCH] VkhApp, VkhQueue; add readme and licence --- LICENSE.md | 21 +++++++++++++++++++++ README.md | 44 +++++++++++++++++++++++++++++++++++++++++++- include/vkh.h | 10 +++++++--- src/vkh_app.c | 18 ++++++++---------- src/vkh_app.h | 1 + src/vkh_device.h | 5 +---- src/vkh_queue.c | 39 +++++++++++++++++++++++++++++++++++++++ src/vkh_queue.h | 13 +++++++++++++ src/vkhelpers.c | 24 ------------------------ 9 files changed, 133 insertions(+), 42 deletions(-) create mode 100644 LICENSE.md create mode 100644 src/vkh_queue.c create mode 100644 src/vkh_queue.h diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..d65cd06 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) [2018] [Jean-Philippe Bruyère] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 78db504..1db601a 100644 --- a/README.md +++ b/README.md @@ -1 +1,43 @@ -# vkhelpers +

+
+
+ Vulkan Helpers +
+

+ + + +

+

+ +### What is vkh? + +**vkh** is a multiplatform helper library for [Vulkan](https://www.khronos.org/vulkan/) written in **c**. + +vkh main goal is to offer an api which will ease the development of wrappers for higher level languages. +No additional library except vulkan is required. + +### Current status: + +Early development stage, api may changed frequently. + +### Building + +```bash +git clone https://github.com/jpbruyere/vkhelpers.git +cd vkhelpers +mkdir build +cd build +cmake .. +make && make install +``` + +### Adding vkh to your CMake project + +- clone vkh as a subdirectory of your root dir. +- in your main CMakeFile, add `add_subdirectory (vkhelpers)` +- add to your **TARGET_INCLUDE_DIRECTORIES** `${CMAKE_CURRENT_SOURCE_DIR}/vkhelpers/include` and if you want to bypass opaque pointers and be able to address +fiels of internal structures of vkh, add also `${CMAKE_CURRENT_SOURCE_DIR}/vkhelpers/src`. +- to link vkh staticaly, add to **TARGET_LINK_LIBRARIES** `vkh_static` or `vkh_shared` to link it as a shared library. + + diff --git a/include/vkh.h b/include/vkh.h index 77eaa58..08c0190 100644 --- a/include/vkh.h +++ b/include/vkh.h @@ -26,10 +26,11 @@ typedef struct _vkh_app_t* VkhApp; typedef struct _vkh_device_t* VkhDevice; typedef struct _vkh_image_t* VkhImage; typedef struct _vkh_buffer_t* VkhBuffer; +typedef struct _vkh_queue_t* VkhQueue; //typedef struct _vkh_presenter_t* VkhPresenter; /////////////////// -VkhApp vkh_app_create (const char* app_name, const char* extentions[], int ext_count); +VkhApp vkh_app_create (const char* app_name, int ext_count, const char* extentions[]); void vkh_app_destroy (VkhApp app); VkInstance vkh_app_get_inst (VkhApp app); VkPhysicalDevice vkh_app_select_phy (VkhApp app, VkPhysicalDeviceType preferedPhyType); @@ -83,8 +84,6 @@ void vkh_cmd_submit (VkQueue queue, VkCommandBuffer *pCmdBuff, VkFence fence); void vkh_cmd_submit_with_semaphores(VkQueue queue, VkCommandBuffer *pCmdBuff, VkSemaphore waitSemaphore, VkSemaphore signalSemaphore, VkFence fence); -VkPhysicalDevice vkh_find_phy (VkInstance inst, VkPhysicalDeviceType phyType); - VkShaderModule vkh_load_module(VkDevice dev, const char* path); bool memory_type_from_properties(VkPhysicalDeviceMemoryProperties* memory_properties, uint32_t typeBits, @@ -98,4 +97,9 @@ void set_image_layout(VkCommandBuffer cmdBuff, VkImage image, VkImageAspe VkImageLayout new_image_layout, VkPipelineStageFlags src_stages, VkPipelineStageFlags dest_stages); void set_image_layout_subres(VkCommandBuffer cmdBuff, VkImage image, VkImageSubresourceRange subresourceRange, VkImageLayout old_image_layout, VkImageLayout new_image_layout, VkPipelineStageFlags src_stages, VkPipelineStageFlags dest_stages); +///////////////////// +VkhQueue vkh_queue_create (VkhDevice dev, uint32_t familyIndex, uint32_t qIndex, VkQueueFlags flags); +void vkh_queue_destroy (VkhQueue queue); +VkhQueue vkh_queue_find (VkhDevice dev, VkQueueFlags flags); +///////////////////// #endif diff --git a/src/vkh_app.c b/src/vkh_app.c index 3e66c31..9836d9c 100644 --- a/src/vkh_app.c +++ b/src/vkh_app.c @@ -3,7 +3,7 @@ #define ENGINE_NAME "vkheplers" #define ENGINE_VERSION 1 -VkhApp vkh_app_create (const char* app_name, const char* extentions[], int ext_count) { +VkhApp vkh_app_create (const char* app_name, int ext_count, const char* extentions[]) { VkhApp app = (VkhApp)malloc(sizeof(vkh_app_t)); VkApplicationInfo infos = { .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, @@ -29,6 +29,9 @@ VkhApp vkh_app_create (const char* app_name, const char* extentions[], int ext_c .ppEnabledLayerNames = enabledLayers }; VK_CHECK_RESULT(vkCreateInstance (&inst_info, NULL, &app->inst)); + + VK_CHECK_RESULT(vkEnumeratePhysicalDevices (app->inst, &app->phyCount, NULL)); + return app; } @@ -42,18 +45,13 @@ VkInstance vkh_app_get_inst (VkhApp app) { } VkPhysicalDevice vkh_app_select_phy (VkhApp app, VkPhysicalDeviceType preferedPhyType) { - uint32_t gpu_count = 0; - - VK_CHECK_RESULT(vkEnumeratePhysicalDevices (app->inst, &gpu_count, NULL)); - - VkPhysicalDevice phys[gpu_count]; - - VK_CHECK_RESULT(vkEnumeratePhysicalDevices (app->inst, &gpu_count, &phys)); + VkPhysicalDevice phys[app->phyCount]; + VK_CHECK_RESULT(vkEnumeratePhysicalDevices (app->inst, &app->phyCount, &phys)); - if (gpu_count == 1) + if (app->phyCount == 1) return phys[0]; - for (int i=0; iphyCount; i++){ VkPhysicalDeviceProperties phy; vkGetPhysicalDeviceProperties (phys[i], &phy); if (phy.deviceType & preferedPhyType){ diff --git a/src/vkh_app.h b/src/vkh_app.h index c937a4b..e39b851 100644 --- a/src/vkh_app.h +++ b/src/vkh_app.h @@ -6,5 +6,6 @@ typedef struct _vkh_app_t{ VkApplicationInfo infos; VkInstance inst; + uint32_t phyCount; }vkh_app_t; #endif diff --git a/src/vkh_device.h b/src/vkh_device.h index 6ddeaed..279957b 100644 --- a/src/vkh_device.h +++ b/src/vkh_device.h @@ -7,10 +7,7 @@ typedef struct _vkh_device_t{ VkDevice dev; VkPhysicalDeviceMemoryProperties phyMemProps; VkRenderPass renderPass; -// VkPhysicalDevice phy; -// VkDevice dev; - -// VkPhysicalDeviceMemoryProperties phyMemProps; + VkPhysicalDevice phy; }vkh_device_t; #endif diff --git a/src/vkh_queue.c b/src/vkh_queue.c new file mode 100644 index 0000000..6558910 --- /dev/null +++ b/src/vkh_queue.c @@ -0,0 +1,39 @@ +#include "vkh_queue.h" +#include "vkh_device.h" + +VkhQueue _init_queue (VkhDevice dev) { + VkhQueue q = (vkh_queue_t*)calloc(1, sizeof(vkh_queue_t)); + q->dev = dev; + return q; +} + + +VkhQueue vkh_queue_create (VkhDevice dev, uint32_t familyIndex, uint32_t qIndex, VkQueueFlags flags) { + VkhQueue q = _init_queue (dev); + q->familyIndex = familyIndex; + vkGetDeviceQueue (dev->dev, familyIndex, qIndex, &q->queue); + return q; +} + +VkhQueue vkh_queue_find (VkhDevice dev, VkQueueFlags flags) { + uint32_t qFamCount = 0; + vkGetPhysicalDeviceQueueFamilyProperties (dev->phy, &qFamCount, NULL); + VkQueueFamilyProperties qFams[qFamCount]; + vkGetPhysicalDeviceQueueFamilyProperties (dev->phy, &qFamCount, qFams); + + //first try to find dedicated queue + for (int i=0; i>22, phy.apiVersion>>12&2048, phy.apiVersion&8191, - phy.driverVersion); - return phys[i]; - } - } - fprintf (stderr, "No suitable GPU found\n"); - exit (-1); -} - VkFence vkh_fence_create (VkDevice dev) { VkFence fence; VkFenceCreateInfo fenceInfo = { .sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, -- 2.47.3