]> O.S.I.I.S - jp/vkhelpers.git/commitdiff
create and import device ctor
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sun, 8 Sep 2019 14:02:37 +0000 (16:02 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sun, 8 Sep 2019 14:02:37 +0000 (16:02 +0200)
include/vkh.h
src/vkh_device.c
src/vkh_phyinfo.c
src/vkh_presenter.c

index a171c01d6ddcd3e1f1f6f0ae60a96932a2c1a8b0..73f811fd6f4edd985306164d924d0f3c4fd9c217 100644 (file)
@@ -28,10 +28,9 @@ extern "C" {
 
 #include <vulkan/vulkan.h>
 
+enum VmaMemoryUsage;
 typedef enum VmaMemoryUsage VmaMemoryUsage;
 
-//#include "vk_mem_alloc.h"
-
 #include <stdlib.h>
 #include <stdio.h>
 #include <assert.h>
@@ -71,16 +70,24 @@ VkPhysicalDevice    vkh_app_select_phy  (VkhApp app, VkPhysicalDeviceType prefer
 VkhPhyInfo*         vkh_app_get_phyinfos    (VkhApp app, uint32_t* count, VkSurfaceKHR surface);
 void                vkh_app_free_phyinfos   (uint32_t count, VkhPhyInfo* infos);
 
-VkPhysicalDeviceProperties vkh_app_get_phy_properties (VkhApp app, uint32_t phyIndex);
-// VkhPhy
-VkhPhyInfo  vkh_phyinfo_create  (VkPhysicalDevice phy, VkSurfaceKHR surface);
-void        vkh_phyinfo_destroy (VkhPhyInfo phy);
+VkPhysicalDeviceProperties          vkh_app_get_phy_properties          (VkhApp app, uint32_t phyIndex);
+
+/*************
+ * VkhPhy    *
+ *************/
+VkhPhyInfo          vkh_phyinfo_create  (VkPhysicalDevice phy, VkSurfaceKHR surface);
+void                vkh_phyinfo_destroy (VkhPhyInfo phy);
+
+VkPhysicalDeviceProperties          vkh_phyinfo_get_properties          (VkhPhyInfo phy);
+VkPhysicalDeviceMemoryProperties    vkh_phyinfo_get_memory_properties   (VkhPhyInfo phy);
+uint32_t                            vkh_phy_info_get_graphic_queue_index(VkhPhyInfo phy);
 
 /*************
  * VkhDevice *
  *************/
-VkhDevice   vkh_device_create   (VkInstance inst, VkPhysicalDevice phy, VkDevice vkDev);
-void        vkh_device_destroy  (VkhDevice dev);
+VkhDevice           vkh_device_create   (VkhApp app, VkhPhyInfo phyInfo, VkDeviceCreateInfo* pDevice_info);
+VkhDevice           vkh_device_import   (VkInstance inst, VkPhysicalDevice phy, VkDevice vkDev);
+void                vkh_device_destroy  (VkhDevice dev);
 
 VkDebugReportCallbackEXT vkh_device_create_debug_report (VkhDevice dev, VkDebugReportFlagsEXT flags);
 void vkh_device_destroy_debug_report (VkhDevice dev, VkDebugReportCallbackEXT dbgReport);
index 453532fc819955a4aaa2b125e45410ea5bffd8dc..88c471e91e622e18a48f84ae2a0f8f86875e9a8f 100644 (file)
@@ -20,6 +20,8 @@
  * THE SOFTWARE.
  */
 #include "vkh_device.h"
+#include "vkh_phyinfo.h"
+#include "vkh_app.h"
 #include "string.h"
 
 #define KNRM  "\x1B[0m\x1B[40m"
@@ -71,8 +73,12 @@ VKAPI_ATTR VkBool32 VKAPI_CALL messageCallback(
     fflush(stdout);
     return VK_FALSE;
 }
-
-VkhDevice vkh_device_create (VkInstance inst, VkPhysicalDevice phy, VkDevice vkDev) {
+VkhDevice vkh_device_create (VkhApp app, VkhPhyInfo phyInfo, VkDeviceCreateInfo* pDevice_info){
+    VkDevice dev;
+    VK_CHECK_RESULT(vkCreateDevice (phyInfo->phy, pDevice_info, NULL, &dev));
+    return vkh_device_import(app->inst, phyInfo->phy, dev);
+}
+VkhDevice vkh_device_import (VkInstance inst, VkPhysicalDevice phy, VkDevice vkDev) {
     VkhDevice dev = (vkh_device_t*)malloc(sizeof(vkh_device_t));
     dev->dev = vkDev;
     dev->phy = phy;
index 299364a79ed1351dfe1243dc8437562185eb4d4d..d97a126fca45cd71d217ff016191f2b701339c5f 100644 (file)
@@ -97,3 +97,12 @@ void vkh_phyinfo_destroy (VkhPhyInfo phy) {
 void vkh_phyinfo_select_queue (VkhPhyInfo phy, uint32_t qIndex, float* priorities) {
 
 }
+VkPhysicalDeviceProperties vkh_phyinfo_get_properties (VkhPhyInfo phy) {
+    return phy->properties;
+}
+VkPhysicalDeviceMemoryProperties vkh_phyinfo_get_memory_properties (VkhPhyInfo phy) {
+    return phy->memProps;
+}
+uint32_t vkh_phy_info_get_graphic_queue_index (VkhPhyInfo phy) {
+    return (uint32_t)phy->gQueue;
+}
index b305c423bd0201afd74b4d696386262aaaf7cada..83cdc74380eed32c3b57c86ca378fe3fdbcd0c5d 100644 (file)
@@ -111,7 +111,7 @@ void vkh_presenter_build_blit_cmd (VkhPresenter r, VkImage blitSource, uint32_t
 
     uint32_t w = MIN(width, r->width), h = MIN(height, r->height);
 
-    for (int32_t i = 0; i < r->imgCount; ++i)
+    for (uint32_t i = 0; i < r->imgCount; ++i)
     {
         VkImage bltDstImage = r->ScBuffers[i]->image;
         VkCommandBuffer cb = r->cmdBuffs[i];
@@ -153,7 +153,7 @@ void _init_phy_surface(VkhPresenter r, VkFormat preferedFormat, VkPresentModeKHR
     VkSurfaceFormatKHR formats[count];
     VK_CHECK_RESULT(vkGetPhysicalDeviceSurfaceFormatsKHR (r->dev->phy, r->surface, &count, formats));
 
-    for (int i=0; i<count; i++){
+    for (uint i=0; i<count; i++){
         if (formats[i].format == preferedFormat) {
             r->format = formats[i].format;
             r->colorSpace = formats[i].colorSpace;
@@ -167,7 +167,7 @@ void _init_phy_surface(VkhPresenter r, VkFormat preferedFormat, VkPresentModeKHR
     VkPresentModeKHR presentModes[count];
     VK_CHECK_RESULT(vkGetPhysicalDeviceSurfacePresentModesKHR(r->dev->phy, r->surface, &count, presentModes));
     r->presentMode = -1;
-    for (int i=0; i<count; i++){
+    for (uint i=0; i<count; i++){
         if (presentModes[i] == presentMode) {
             r->presentMode = presentModes[i];
             break;