feat(vk): Init vma
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Ubuntu Cross to Win64 / Cross Compile with ming64 (1.4.0, ubuntu-latest) (push) Successful in 1m27s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Ubuntu Cross to Win64 / Cross Compile with ming64 (1.4.0, ubuntu-latest) (push) Successful in 1m27s
				
			This commit is contained in:
		
							parent
							
								
									8d303fff9f
								
							
						
					
					
						commit
						faa84d3aa9
					
				@ -8,6 +8,7 @@
 | 
				
			|||||||
#include <runtime/timing.h>
 | 
					#include <runtime/timing.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "device.h"
 | 
					#include "device.h"
 | 
				
			||||||
 | 
					#include "physical_resource_manager.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define TARGET_API_VERSION VK_API_VERSION_1_3
 | 
					#define TARGET_API_VERSION VK_API_VERSION_1_3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -521,58 +522,6 @@ static rt_result CreateDevice(rt_vk_device *dev) {
 | 
				
			|||||||
    return RT_SUCCESS;
 | 
					    return RT_SUCCESS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if 0
 | 
					 | 
				
			||||||
static rt_result CreateAllocator(rt_vk_device *dev) {
 | 
					 | 
				
			||||||
#define SET_FNC(name)     fncs.name = name
 | 
					 | 
				
			||||||
#define SET_KHR_FNC(name) (fncs).name##KHR = name
 | 
					 | 
				
			||||||
    VmaVulkanFunctions fncs                = {NULL};
 | 
					 | 
				
			||||||
    SET_FNC(vkGetInstanceProcAddr);
 | 
					 | 
				
			||||||
    SET_FNC(vkGetDeviceProcAddr);
 | 
					 | 
				
			||||||
    SET_FNC(vkGetPhysicalDeviceProperties);
 | 
					 | 
				
			||||||
    SET_FNC(vkGetPhysicalDeviceMemoryProperties);
 | 
					 | 
				
			||||||
    SET_FNC(vkAllocateMemory);
 | 
					 | 
				
			||||||
    SET_FNC(vkFreeMemory);
 | 
					 | 
				
			||||||
    SET_FNC(vkMapMemory);
 | 
					 | 
				
			||||||
    SET_FNC(vkUnmapMemory);
 | 
					 | 
				
			||||||
    SET_FNC(vkFlushMappedMemoryRanges);
 | 
					 | 
				
			||||||
    SET_FNC(vkInvalidateMappedMemoryRanges);
 | 
					 | 
				
			||||||
    SET_FNC(vkBindBufferMemory);
 | 
					 | 
				
			||||||
    SET_FNC(vkBindImageMemory);
 | 
					 | 
				
			||||||
    SET_FNC(vkGetBufferMemoryRequirements);
 | 
					 | 
				
			||||||
    SET_FNC(vkGetImageMemoryRequirements);
 | 
					 | 
				
			||||||
    SET_FNC(vkCreateBuffer);
 | 
					 | 
				
			||||||
    SET_FNC(vkDestroyBuffer);
 | 
					 | 
				
			||||||
    SET_FNC(vkCreateImage);
 | 
					 | 
				
			||||||
    SET_FNC(vkDestroyImage);
 | 
					 | 
				
			||||||
    SET_FNC(vkCmdCopyBuffer);
 | 
					 | 
				
			||||||
    SET_KHR_FNC(vkGetBufferMemoryRequirements2);
 | 
					 | 
				
			||||||
    SET_KHR_FNC(vkGetImageMemoryRequirements2);
 | 
					 | 
				
			||||||
    SET_KHR_FNC(vkBindBufferMemory2);
 | 
					 | 
				
			||||||
    SET_KHR_FNC(vkBindImageMemory2);
 | 
					 | 
				
			||||||
    SET_KHR_FNC(vkGetPhysicalDeviceMemoryProperties2);
 | 
					 | 
				
			||||||
    SET_FNC(vkGetDeviceBufferMemoryRequirements);
 | 
					 | 
				
			||||||
    SET_FNC(vkGetDeviceImageMemoryRequirements);
 | 
					 | 
				
			||||||
#undef SET_FNC
 | 
					 | 
				
			||||||
#undef SET_KHR_FNC
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    VmaAllocatorCreateInfo allocator_info = {
 | 
					 | 
				
			||||||
        .instance             = dev->instance,
 | 
					 | 
				
			||||||
        .physicalDevice       = dev->phys_device,
 | 
					 | 
				
			||||||
        .device               = dev->device,
 | 
					 | 
				
			||||||
        .pAllocationCallbacks = dev->alloc_cb,
 | 
					 | 
				
			||||||
        .vulkanApiVersion     = TARGET_API_VERSION,
 | 
					 | 
				
			||||||
        .pVulkanFunctions     = &fncs,
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return vmaCreateAllocator(&allocator_info, &dev->allocator) == VK_SUCCESS ? RT_SUCCESS
 | 
					 | 
				
			||||||
                                                                               : RT_UNKNOWN_ERROR;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void DestroyAllocator(void) {
 | 
					 | 
				
			||||||
    vmaDestroyAllocator(dev->allocator);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static rt_result CreatePerFrameObjects(rt_vk_device *dev) {
 | 
					static rt_result CreatePerFrameObjects(rt_vk_device *dev) {
 | 
				
			||||||
    for (unsigned int i = 0; i < dev->max_frames_in_flight; ++i) {
 | 
					    for (unsigned int i = 0; i < dev->max_frames_in_flight; ++i) {
 | 
				
			||||||
        VkSemaphoreCreateInfo semaphore_info = {
 | 
					        VkSemaphoreCreateInfo semaphore_info = {
 | 
				
			||||||
@ -669,6 +618,10 @@ rt_create_vk_device_result rtCreateVkDevice(const rt_renderer_window_info *info)
 | 
				
			|||||||
        goto out;
 | 
					        goto out;
 | 
				
			||||||
    if ((res = CreateSwapchain(&dev)) != RT_SUCCESS)
 | 
					    if ((res = CreateSwapchain(&dev)) != RT_SUCCESS)
 | 
				
			||||||
        goto out;
 | 
					        goto out;
 | 
				
			||||||
 | 
					    rt_create_vk_physical_resource_manager_result phys_res_mgr_res = rtCreateVkPhysicalResourceManager(&dev);
 | 
				
			||||||
 | 
					    if ((res = phys_res_mgr_res.result) != RT_SUCCESS)
 | 
				
			||||||
 | 
					        goto out;
 | 
				
			||||||
 | 
					    dev.phys_res_mgr = phys_res_mgr_res.phys_res_mgr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    rt_time_delta initTime = rtTimeBetween(initBegin, rtTimeNow());
 | 
					    rt_time_delta initTime = rtTimeBetween(initBegin, rtTimeNow());
 | 
				
			||||||
    rtLog("VK", "Init complete. Took %lf seconds.", initTime);
 | 
					    rtLog("VK", "Init complete. Took %lf seconds.", initTime);
 | 
				
			||||||
@ -682,7 +635,7 @@ void rtDestroyVkDevice(rt_vk_device *dev) {
 | 
				
			|||||||
    vkDeviceWaitIdle(dev->device);
 | 
					    vkDeviceWaitIdle(dev->device);
 | 
				
			||||||
    DestroySwapchain(dev);
 | 
					    DestroySwapchain(dev);
 | 
				
			||||||
    DestroyPerFrameObjects(dev);
 | 
					    DestroyPerFrameObjects(dev);
 | 
				
			||||||
    // DestroyAllocator();
 | 
					    rtDestroyVkPhysicalResourceManager(&dev->phys_res_mgr);
 | 
				
			||||||
    vkDestroyDevice(dev->device, dev->alloc_cb);
 | 
					    vkDestroyDevice(dev->device, dev->alloc_cb);
 | 
				
			||||||
    vkDestroySurfaceKHR(dev->instance, dev->surface, dev->alloc_cb);
 | 
					    vkDestroySurfaceKHR(dev->instance, dev->surface, dev->alloc_cb);
 | 
				
			||||||
#ifdef RT_DEBUG
 | 
					#ifdef RT_DEBUG
 | 
				
			||||||
@ -693,6 +646,9 @@ void rtDestroyVkDevice(rt_vk_device *dev) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/* rt_render_device_i functions */
 | 
					/* rt_render_device_i functions */
 | 
				
			||||||
rt_physical_resource_manager_i rtVkDevGetPhysicalResourceManager(void *o) {
 | 
					rt_physical_resource_manager_i rtVkDevGetPhysicalResourceManager(void *o) {
 | 
				
			||||||
    rt_physical_resource_manager_i iface = {};
 | 
					    rt_vk_device *dev = o;
 | 
				
			||||||
 | 
					    rt_physical_resource_manager_i iface = {
 | 
				
			||||||
 | 
					        .o = &dev->phys_res_mgr,
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
    return iface;
 | 
					    return iface;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -6,6 +6,8 @@
 | 
				
			|||||||
#include <renderer/renderer.h>
 | 
					#include <renderer/renderer.h>
 | 
				
			||||||
#include <renderer/backend_api.h>
 | 
					#include <renderer/backend_api.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "physical_resource_manager.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef _WIN32
 | 
					#ifdef _WIN32
 | 
				
			||||||
struct HINSTANCE__;
 | 
					struct HINSTANCE__;
 | 
				
			||||||
struct HWND__;
 | 
					struct HWND__;
 | 
				
			||||||
@ -68,6 +70,8 @@ typedef struct rt_vk_device {
 | 
				
			|||||||
    VkImageView swapchain_image_views[4];
 | 
					    VkImageView swapchain_image_views[4];
 | 
				
			||||||
    uint32_t swapchain_image_count;
 | 
					    uint32_t swapchain_image_count;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    rt_vk_physical_resource_manager phys_res_mgr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* *** Debug utils *** */
 | 
					    /* *** Debug utils *** */
 | 
				
			||||||
#ifdef RT_DEBUG
 | 
					#ifdef RT_DEBUG
 | 
				
			||||||
    VkDebugUtilsMessengerEXT messenger;
 | 
					    VkDebugUtilsMessengerEXT messenger;
 | 
				
			||||||
 | 
				
			|||||||
@ -20,6 +20,7 @@ if get_option('build_vk')
 | 
				
			|||||||
    'init.c',
 | 
					    'init.c',
 | 
				
			||||||
    'physical_resource_manager.c',
 | 
					    'physical_resource_manager.c',
 | 
				
			||||||
    'swapchain.c',
 | 
					    'swapchain.c',
 | 
				
			||||||
 | 
					    'vma_impl.cpp',
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    '../../../contrib/volk/volk.c',
 | 
					    '../../../contrib/volk/volk.c',
 | 
				
			||||||
    '../../../contrib/volk/volk.h',
 | 
					    '../../../contrib/volk/volk.h',
 | 
				
			||||||
 | 
				
			|||||||
@ -1 +1,66 @@
 | 
				
			|||||||
#include "physical_resource_manager.h"
 | 
					#include "physical_resource_manager.h"
 | 
				
			||||||
 | 
					#include "device.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static VmaAllocator CreateAllocator(rt_vk_device *dev) {
 | 
				
			||||||
 | 
					#define SET_FNC(name)     fncs.name = name
 | 
				
			||||||
 | 
					#define SET_KHR_FNC(name) (fncs).name##KHR = name
 | 
				
			||||||
 | 
					    VmaVulkanFunctions fncs                = {NULL};
 | 
				
			||||||
 | 
					    SET_FNC(vkGetInstanceProcAddr);
 | 
				
			||||||
 | 
					    SET_FNC(vkGetDeviceProcAddr);
 | 
				
			||||||
 | 
					    SET_FNC(vkGetPhysicalDeviceProperties);
 | 
				
			||||||
 | 
					    SET_FNC(vkGetPhysicalDeviceMemoryProperties);
 | 
				
			||||||
 | 
					    SET_FNC(vkAllocateMemory);
 | 
				
			||||||
 | 
					    SET_FNC(vkFreeMemory);
 | 
				
			||||||
 | 
					    SET_FNC(vkMapMemory);
 | 
				
			||||||
 | 
					    SET_FNC(vkUnmapMemory);
 | 
				
			||||||
 | 
					    SET_FNC(vkFlushMappedMemoryRanges);
 | 
				
			||||||
 | 
					    SET_FNC(vkInvalidateMappedMemoryRanges);
 | 
				
			||||||
 | 
					    SET_FNC(vkBindBufferMemory);
 | 
				
			||||||
 | 
					    SET_FNC(vkBindImageMemory);
 | 
				
			||||||
 | 
					    SET_FNC(vkGetBufferMemoryRequirements);
 | 
				
			||||||
 | 
					    SET_FNC(vkGetImageMemoryRequirements);
 | 
				
			||||||
 | 
					    SET_FNC(vkCreateBuffer);
 | 
				
			||||||
 | 
					    SET_FNC(vkDestroyBuffer);
 | 
				
			||||||
 | 
					    SET_FNC(vkCreateImage);
 | 
				
			||||||
 | 
					    SET_FNC(vkDestroyImage);
 | 
				
			||||||
 | 
					    SET_FNC(vkCmdCopyBuffer);
 | 
				
			||||||
 | 
					    SET_KHR_FNC(vkGetBufferMemoryRequirements2);
 | 
				
			||||||
 | 
					    SET_KHR_FNC(vkGetImageMemoryRequirements2);
 | 
				
			||||||
 | 
					    SET_KHR_FNC(vkBindBufferMemory2);
 | 
				
			||||||
 | 
					    SET_KHR_FNC(vkBindImageMemory2);
 | 
				
			||||||
 | 
					    SET_KHR_FNC(vkGetPhysicalDeviceMemoryProperties2);
 | 
				
			||||||
 | 
					    SET_FNC(vkGetDeviceBufferMemoryRequirements);
 | 
				
			||||||
 | 
					    SET_FNC(vkGetDeviceImageMemoryRequirements);
 | 
				
			||||||
 | 
					#undef SET_FNC
 | 
				
			||||||
 | 
					#undef SET_KHR_FNC
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    VmaAllocatorCreateInfo allocator_info = {
 | 
				
			||||||
 | 
					        .instance             = dev->instance,
 | 
				
			||||||
 | 
					        .physicalDevice       = dev->phys_device,
 | 
				
			||||||
 | 
					        .device               = dev->device,
 | 
				
			||||||
 | 
					        .pAllocationCallbacks = dev->alloc_cb,
 | 
				
			||||||
 | 
					        .vulkanApiVersion     = VK_API_VERSION_1_3,
 | 
				
			||||||
 | 
					        .pVulkanFunctions     = &fncs,
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    VmaAllocator allocator;
 | 
				
			||||||
 | 
					    if (vmaCreateAllocator(&allocator_info, &allocator) != VK_SUCCESS)
 | 
				
			||||||
 | 
					        return NULL;
 | 
				
			||||||
 | 
					    return allocator;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					rt_create_vk_physical_resource_manager_result rtCreateVkPhysicalResourceManager(struct rt_vk_device *dev) {
 | 
				
			||||||
 | 
					    rt_vk_physical_resource_manager phys_res_mgr;
 | 
				
			||||||
 | 
					    phys_res_mgr.dev = dev;
 | 
				
			||||||
 | 
					    phys_res_mgr.allocator = CreateAllocator(dev);
 | 
				
			||||||
 | 
					    if (!phys_res_mgr.allocator) {
 | 
				
			||||||
 | 
					        return (rt_create_vk_physical_resource_manager_result){.result =  RT_UNKNOWN_ERROR};
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return (rt_create_vk_physical_resource_manager_result){.result =  RT_SUCCESS, .phys_res_mgr = phys_res_mgr};
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void rtDestroyVkPhysicalResourceManager(rt_vk_physical_resource_manager *phys_res_mgr) {
 | 
				
			||||||
 | 
					    vmaDestroyAllocator(phys_res_mgr->allocator);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -1,10 +1,27 @@
 | 
				
			|||||||
#ifndef RT_VK_PHYSICAL_RESOURCE_MANAGER_H
 | 
					#ifndef RT_VK_PHYSICAL_RESOURCE_MANAGER_H
 | 
				
			||||||
#define RT_VK_PHYSICAL_RESOURCE_MANAGER_H
 | 
					#define RT_VK_PHYSICAL_RESOURCE_MANAGER_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <runtime/runtime.h>
 | 
				
			||||||
 | 
					#include <volk/volk.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define VMA_STATIC_VULKAN_FUNCTIONS 0
 | 
				
			||||||
 | 
					#define VMA_DYNAMI_VULKAN_FUNCTIONS 0
 | 
				
			||||||
 | 
					#include <vk_mem_alloc.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct rt_vk_device;
 | 
					struct rt_vk_device;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct {
 | 
					typedef struct {
 | 
				
			||||||
    struct rt_vk_device *dev;
 | 
					    struct rt_vk_device *dev;
 | 
				
			||||||
 | 
					    VmaAllocator allocator;
 | 
				
			||||||
} rt_vk_physical_resource_manager;
 | 
					} rt_vk_physical_resource_manager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct {
 | 
				
			||||||
 | 
					    rt_result result;
 | 
				
			||||||
 | 
					    rt_vk_physical_resource_manager phys_res_mgr;
 | 
				
			||||||
 | 
					} rt_create_vk_physical_resource_manager_result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					rt_create_vk_physical_resource_manager_result rtCreateVkPhysicalResourceManager(struct rt_vk_device *dev);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void rtDestroyVkPhysicalResourceManager(rt_vk_physical_resource_manager *phys_res_mgr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										21
									
								
								src/renderer/vk/vma_impl.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/renderer/vk/vma_impl.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					#ifdef _MSC_VER
 | 
				
			||||||
 | 
					#pragma warning(push, 0)
 | 
				
			||||||
 | 
					#elif defined(__GNUC__) || defined(__clang__)
 | 
				
			||||||
 | 
					#pragma GCC diagnostic push
 | 
				
			||||||
 | 
					#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
 | 
				
			||||||
 | 
					#pragma GCC diagnostic ignored "-Wmissing-braces"
 | 
				
			||||||
 | 
					#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
 | 
				
			||||||
 | 
					#pragma GCC diagnostic ignored "-Wconversion"
 | 
				
			||||||
 | 
					#pragma GCC diagnostic ignored "-Wunused-variable"
 | 
				
			||||||
 | 
					#pragma GCC diagnostic ignored "-Wparentheses"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#include <volk/volk.h>
 | 
				
			||||||
 | 
					#define VMA_STATIC_VULKAN_FUNCTIONS  0
 | 
				
			||||||
 | 
					#define VMA_DYNAMIC_VULKAN_FUNCTIONS 0
 | 
				
			||||||
 | 
					#define VMA_IMPLEMENTATION
 | 
				
			||||||
 | 
					#include <vk_mem_alloc.h>
 | 
				
			||||||
 | 
					#ifdef _MSC_VER
 | 
				
			||||||
 | 
					#pragma warning(pop)
 | 
				
			||||||
 | 
					#elif defined(__GNUC__) || defined(__clang__)
 | 
				
			||||||
 | 
					#pragma GCC diagnostic pop
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user