adding fences

This commit is contained in:
2024-10-10 21:12:48 +02:00
parent 405c8b186a
commit 370f0b0f11
8 changed files with 106 additions and 6 deletions

View File

@@ -51,7 +51,7 @@ bool VulkanLoadBackend(PulseDebugLevel debug_level)
void VulkanUnloadBackend(PulseBackend backend)
{
VulkanDestroyInstance(&VULKAN_RETRIEVE_DRIVER_DATA(backend)->instance);
VulkanDestroyInstance(&VULKAN_RETRIEVE_DRIVER_DATA_AS(backend, VulkanDriverData*)->instance);
VulkanLoaderShutdown();
}

View File

@@ -14,7 +14,7 @@
#include "../../PulseInternal.h"
#define VULKAN_RETRIEVE_DRIVER_DATA(handle) ((VulkanDriverData*)handle->driver_data)
#define VULKAN_RETRIEVE_DRIVER_DATA_AS(handle, cast) ((cast)handle->driver_data)
#define CHECK_VK_RETVAL(res, error, retval) \
if((res) != VK_SUCCESS) \

View File

@@ -6,6 +6,7 @@
#include "Vulkan.h"
#include "VulkanComputePipeline.h"
#include "VulkanDevice.h"
#include "VulkanFence.h"
#include "VulkanInstance.h"
#include "VulkanLoader.h"
#include "VulkanQueue.h"
@@ -117,7 +118,7 @@ PulseDevice VulkanCreateDevice(PulseBackend backend, PulseDevice* forbiden_devic
VulkanDevice* device = (VulkanDevice*)calloc(1, sizeof(VulkanDevice));
PULSE_CHECK_ALLOCATION_RETVAL(device, PULSE_NULLPTR);
VulkanInstance* instance = &VULKAN_RETRIEVE_DRIVER_DATA(backend)->instance;
VulkanInstance* instance = &VULKAN_RETRIEVE_DRIVER_DATA_AS(backend, VulkanDriverData*)->instance;
device->physical = VulkanPickPhysicalDevice(instance, forbiden_devices, forbiden_devices_count);
PULSE_CHECK_HANDLE_RETVAL(device->physical, PULSE_NULLPTR);
@@ -226,12 +227,11 @@ PulseDevice VulkanCreateDevice(PulseBackend backend, PulseDevice* forbiden_devic
void VulkanDestroyDevice(PulseDevice device)
{
VulkanDevice* vulkan_device = (VulkanDevice*)device->driver_data;
VulkanDevice* vulkan_device = VULKAN_RETRIEVE_DRIVER_DATA_AS(device, VulkanDevice*);
if(vulkan_device == PULSE_NULLPTR || vulkan_device->device == VK_NULL_HANDLE)
return;
vmaDestroyAllocator(vulkan_device->allocator);
vulkan_device->vkDestroyDevice(vulkan_device->device, PULSE_NULLPTR);
vulkan_device->device = VK_NULL_HANDLE;
free(vulkan_device);
free(device);
}

59
Sources/Backends/Vulkan/VulkanFence.c git.filemode.normal_file
View File

@@ -0,0 +1,59 @@
// Copyright (C) 2024 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#include "Pulse.h"
#include "Vulkan.h"
#include "VulkanDevice.h"
#include "VulkanFence.h"
PulseFence VulkanCreateFence(PulseDevice device)
{
VkFenceCreateInfo fence_info = {};
fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
fence_info.flags = VK_FENCE_CREATE_SIGNALED_BIT;
VkFence vulkan_fence;
VulkanDevice* vulkan_device = VULKAN_RETRIEVE_DRIVER_DATA_AS(device, VulkanDevice*);
CHECK_VK_RETVAL(vulkan_device->vkCreateFence(vulkan_device->device, &fence_info, PULSE_NULLPTR, &vulkan_fence), PULSE_ERROR_INITIALIZATION_FAILED, PULSE_NULL_HANDLE);
PulseFenceHandler* fence = (PulseFenceHandler*)malloc(sizeof(PulseFenceHandler));
PULSE_CHECK_ALLOCATION_RETVAL(fence, PULSE_NULL_HANDLE);
fence->driver_data = vulkan_fence;
return fence;
}
void VulkanDestroyFence(PulseDevice device, PulseFence fence)
{
VulkanDevice* vulkan_device = VULKAN_RETRIEVE_DRIVER_DATA_AS(device, VulkanDevice*);
if(vulkan_device == PULSE_NULLPTR || vulkan_device->device == VK_NULL_HANDLE)
return;
VkFence vulkan_fence = VULKAN_RETRIEVE_DRIVER_DATA_AS(fence, VkFence);
if(vulkan_fence == VK_NULL_HANDLE)
return;
vulkan_device->vkDestroyFence(vulkan_device->device, vulkan_fence, PULSE_NULLPTR);
free(fence);
}
bool VulkanIsFenceReady(PulseDevice device, PulseFence fence)
{
VulkanDevice* vulkan_device = VULKAN_RETRIEVE_DRIVER_DATA_AS(device, VulkanDevice*);
if(vulkan_device == PULSE_NULLPTR || vulkan_device->device == VK_NULL_HANDLE)
return false;
VkFence vulkan_fence = VULKAN_RETRIEVE_DRIVER_DATA_AS(fence, VkFence);
if(vulkan_fence == VK_NULL_HANDLE)
return false;
VkResult res = vulkan_device->vkGetFenceStatus(vulkan_device->device, vulkan_fence);
switch(res)
{
case VK_ERROR_DEVICE_LOST: PulseSetInternalError(PULSE_ERROR_DEVICE_LOST); return false;
case VK_NOT_READY: return false;
case VK_SUCCESS: return true;
default: return false;
}
return false;
}
bool VulkanWaitForFences(PulseDevice device, PulseFence *const *fences, uint32_t fences_count, bool wait_for_all)
{
}

22
Sources/Backends/Vulkan/VulkanFence.h git.filemode.normal_file
View File

@@ -0,0 +1,22 @@
// Copyright (C) 2024 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#ifdef PULSE_ENABLE_VULKAN_BACKEND
#ifndef PULSE_VULKAN_FENCE_H_
#define PULSE_VULKAN_FENCE_H_
#include <vulkan/vulkan_core.h>
#include <Pulse.h>
#include "VulkanDevice.h"
PulseFence VulkanCreateFence(PulseDevice device);
void VulkanDestroyFence(PulseDevice device, PulseFence fence);
bool VulkanIsFenceReady(PulseDevice device, PulseFence fence);
bool VulkanWaitForFences(PulseDevice device, PulseFence *const *fences, uint32_t fences_count, bool wait_for_all);
#endif // PULSE_VULKAN_FENCE_H_
#endif // PULSE_ENABLE_VULKAN_BACKEND