mirror of
https://github.com/Kbz-8/Pulse.git
synced 2026-01-11 15:33:34 +00:00
adding fences
This commit is contained in:
@@ -104,6 +104,7 @@ typedef enum PulseErrorType
|
|||||||
PULSE_ERROR_INITIALIZATION_FAILED,
|
PULSE_ERROR_INITIALIZATION_FAILED,
|
||||||
PULSE_ERROR_INVALID_HANDLE,
|
PULSE_ERROR_INVALID_HANDLE,
|
||||||
PULSE_ERROR_ALLOCATION_FAILED,
|
PULSE_ERROR_ALLOCATION_FAILED,
|
||||||
|
PULSE_ERROR_DEVICE_LOST,
|
||||||
} PulseErrorType;
|
} PulseErrorType;
|
||||||
|
|
||||||
typedef enum PulseImageType
|
typedef enum PulseImageType
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ bool VulkanLoadBackend(PulseDebugLevel debug_level)
|
|||||||
|
|
||||||
void VulkanUnloadBackend(PulseBackend backend)
|
void VulkanUnloadBackend(PulseBackend backend)
|
||||||
{
|
{
|
||||||
VulkanDestroyInstance(&VULKAN_RETRIEVE_DRIVER_DATA(backend)->instance);
|
VulkanDestroyInstance(&VULKAN_RETRIEVE_DRIVER_DATA_AS(backend, VulkanDriverData*)->instance);
|
||||||
VulkanLoaderShutdown();
|
VulkanLoaderShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#include "../../PulseInternal.h"
|
#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) \
|
#define CHECK_VK_RETVAL(res, error, retval) \
|
||||||
if((res) != VK_SUCCESS) \
|
if((res) != VK_SUCCESS) \
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "Vulkan.h"
|
#include "Vulkan.h"
|
||||||
#include "VulkanComputePipeline.h"
|
#include "VulkanComputePipeline.h"
|
||||||
#include "VulkanDevice.h"
|
#include "VulkanDevice.h"
|
||||||
|
#include "VulkanFence.h"
|
||||||
#include "VulkanInstance.h"
|
#include "VulkanInstance.h"
|
||||||
#include "VulkanLoader.h"
|
#include "VulkanLoader.h"
|
||||||
#include "VulkanQueue.h"
|
#include "VulkanQueue.h"
|
||||||
@@ -117,7 +118,7 @@ PulseDevice VulkanCreateDevice(PulseBackend backend, PulseDevice* forbiden_devic
|
|||||||
VulkanDevice* device = (VulkanDevice*)calloc(1, sizeof(VulkanDevice));
|
VulkanDevice* device = (VulkanDevice*)calloc(1, sizeof(VulkanDevice));
|
||||||
PULSE_CHECK_ALLOCATION_RETVAL(device, PULSE_NULLPTR);
|
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);
|
device->physical = VulkanPickPhysicalDevice(instance, forbiden_devices, forbiden_devices_count);
|
||||||
PULSE_CHECK_HANDLE_RETVAL(device->physical, PULSE_NULLPTR);
|
PULSE_CHECK_HANDLE_RETVAL(device->physical, PULSE_NULLPTR);
|
||||||
@@ -226,12 +227,11 @@ PulseDevice VulkanCreateDevice(PulseBackend backend, PulseDevice* forbiden_devic
|
|||||||
|
|
||||||
void VulkanDestroyDevice(PulseDevice device)
|
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)
|
if(vulkan_device == PULSE_NULLPTR || vulkan_device->device == VK_NULL_HANDLE)
|
||||||
return;
|
return;
|
||||||
vmaDestroyAllocator(vulkan_device->allocator);
|
vmaDestroyAllocator(vulkan_device->allocator);
|
||||||
vulkan_device->vkDestroyDevice(vulkan_device->device, PULSE_NULLPTR);
|
vulkan_device->vkDestroyDevice(vulkan_device->device, PULSE_NULLPTR);
|
||||||
vulkan_device->device = VK_NULL_HANDLE;
|
|
||||||
free(vulkan_device);
|
free(vulkan_device);
|
||||||
free(device);
|
free(device);
|
||||||
}
|
}
|
||||||
|
|||||||
59
Sources/Backends/Vulkan/VulkanFence.c
git.filemode.normal_file
59
Sources/Backends/Vulkan/VulkanFence.c
git.filemode.normal_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
22
Sources/Backends/Vulkan/VulkanFence.h
git.filemode.normal_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
|
||||||
@@ -111,6 +111,7 @@ PULSE_API const char* PulseVerbaliseErrorType(PulseErrorType error)
|
|||||||
case PULSE_ERROR_BACKENDS_CANDIDATES_SHADER_FORMAT_MISMATCH: return "no backend candidates support the required shader formats";
|
case PULSE_ERROR_BACKENDS_CANDIDATES_SHADER_FORMAT_MISMATCH: return "no backend candidates support the required shader formats";
|
||||||
case PULSE_ERROR_INITIALIZATION_FAILED: return "initialization of an object could not be completed for implementation-specific reasons";
|
case PULSE_ERROR_INITIALIZATION_FAILED: return "initialization of an object could not be completed for implementation-specific reasons";
|
||||||
case PULSE_ERROR_ALLOCATION_FAILED: return "an internal allocation failed";
|
case PULSE_ERROR_ALLOCATION_FAILED: return "an internal allocation failed";
|
||||||
|
case PULSE_ERROR_DEVICE_LOST: return "device has been lost";
|
||||||
|
|
||||||
default: return "invalid error type";
|
default: return "invalid error type";
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -45,6 +45,10 @@ typedef void (*PulseDestroyDevicePFN)(PulseDevice);
|
|||||||
typedef PulseComputePipeline (*PulseCreateComputePipelinePFN)(PulseDevice, const PulseComputePipelineCreateInfo*);
|
typedef PulseComputePipeline (*PulseCreateComputePipelinePFN)(PulseDevice, const PulseComputePipelineCreateInfo*);
|
||||||
typedef void (*PulseBindComputePipelinePFN)(PulseComputePass, PulseComputePipeline);
|
typedef void (*PulseBindComputePipelinePFN)(PulseComputePass, PulseComputePipeline);
|
||||||
typedef void (*PulseDestroyComputePipelinePFN)(PulseDevice, PulseComputePipeline);
|
typedef void (*PulseDestroyComputePipelinePFN)(PulseDevice, PulseComputePipeline);
|
||||||
|
typedef PulseFence (*PulseCreateFencePFN)(PulseDevice device);
|
||||||
|
typedef void (*PulseDestroyFencePFN)(PulseDevice device, PulseFence fence);
|
||||||
|
typedef bool (*PulseIsFenceReadyPFN)(PulseDevice device, PulseFence fence);
|
||||||
|
typedef bool (*PulseWaitForFencesPFN)(PulseDevice device, PulseFence* const* fences, uint32_t fences_count, bool wait_for_all);
|
||||||
|
|
||||||
typedef struct PulseBackendHandler
|
typedef struct PulseBackendHandler
|
||||||
{
|
{
|
||||||
@@ -66,20 +70,33 @@ typedef struct PulseDeviceHandler
|
|||||||
PulseCreateComputePipelinePFN PFN_CreateComputePipeline;
|
PulseCreateComputePipelinePFN PFN_CreateComputePipeline;
|
||||||
PulseBindComputePipelinePFN PFN_BindComputePipeline;
|
PulseBindComputePipelinePFN PFN_BindComputePipeline;
|
||||||
PulseDestroyComputePipelinePFN PFN_DestroyComputePipeline;
|
PulseDestroyComputePipelinePFN PFN_DestroyComputePipeline;
|
||||||
|
PulseCreateFencePFN PFN_CreateFence;
|
||||||
|
PulseDestroyFencePFN PFN_DestroyFence;
|
||||||
|
PulseIsFenceReadyPFN PFN_IsFenceReady;
|
||||||
|
PulseWaitForFencesPFN PFN_WaitForFences;
|
||||||
|
|
||||||
// Attributes
|
// Attributes
|
||||||
void* driver_data;
|
void* driver_data;
|
||||||
PulseBackend backend;
|
PulseBackend backend;
|
||||||
} PulseDeviceHandler;
|
} PulseDeviceHandler;
|
||||||
|
|
||||||
|
typedef struct PulseFenceHandler
|
||||||
|
{
|
||||||
|
void* driver_data;
|
||||||
|
} PulseFenceHandler;
|
||||||
|
|
||||||
void PulseSetInternalError(PulseErrorType error);
|
void PulseSetInternalError(PulseErrorType error);
|
||||||
|
|
||||||
#define PULSE_LOAD_DRIVER_DEVICE_FUNCTION(fn, _namespace) pulse_device->PFN_##fn = _namespace##fn;
|
#define PULSE_LOAD_DRIVER_DEVICE_FUNCTION(fn, _namespace) pulse_device->PFN_##fn = _namespace##fn;
|
||||||
#define PULSE_LOAD_DRIVER_DEVICE(_namespace) \
|
#define PULSE_LOAD_DRIVER_DEVICE(_namespace) \
|
||||||
PULSE_LOAD_DRIVER_DEVICE_FUNCTION(DestroyDevice, _namespace) \
|
PULSE_LOAD_DRIVER_DEVICE_FUNCTION(DestroyDevice, _namespace) \
|
||||||
PULSE_LOAD_DRIVER_DEVICE_FUNCTION(CreateComputePipeline, _namespace) \
|
PULSE_LOAD_DRIVER_DEVICE_FUNCTION(CreateComputePipeline, _namespace) \
|
||||||
PULSE_LOAD_DRIVER_DEVICE_FUNCTION(BindComputePipeline, _namespace) \
|
|
||||||
PULSE_LOAD_DRIVER_DEVICE_FUNCTION(DestroyComputePipeline, _namespace) \
|
PULSE_LOAD_DRIVER_DEVICE_FUNCTION(DestroyComputePipeline, _namespace) \
|
||||||
|
PULSE_LOAD_DRIVER_DEVICE_FUNCTION(BindComputePipeline, _namespace) \
|
||||||
|
PULSE_LOAD_DRIVER_DEVICE_FUNCTION(CreateFence, _namespace) \
|
||||||
|
PULSE_LOAD_DRIVER_DEVICE_FUNCTION(DestroyFence, _namespace) \
|
||||||
|
PULSE_LOAD_DRIVER_DEVICE_FUNCTION(IsFenceReady, _namespace) \
|
||||||
|
PULSE_LOAD_DRIVER_DEVICE_FUNCTION(WaitForFences, _namespace) \
|
||||||
|
|
||||||
#ifdef PULSE_ENABLE_VULKAN_BACKEND
|
#ifdef PULSE_ENABLE_VULKAN_BACKEND
|
||||||
extern PulseBackendHandler VulkanDriver;
|
extern PulseBackendHandler VulkanDriver;
|
||||||
|
|||||||
Reference in New Issue
Block a user