mirror of
https://github.com/Kbz-8/Pulse.git
synced 2026-01-11 15:33:34 +00:00
working on command lists
This commit is contained in:
32
Sources/Backends/Vulkan/VulkanCommandList.h
git.filemode.normal_file
32
Sources/Backends/Vulkan/VulkanCommandList.h
git.filemode.normal_file
@@ -0,0 +1,32 @@
|
||||
// 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_COMMAND_LIST_H_
|
||||
#define PULSE_VULKAN_COMMAND_LIST_H_
|
||||
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
#include <Pulse.h>
|
||||
#include "../../PulseInternal.h"
|
||||
#include "VulkanCommandPool.h"
|
||||
|
||||
typedef struct VulkanCommandList
|
||||
{
|
||||
PulseDevice device;
|
||||
VulkanCommandPool* pool;
|
||||
PulseThreadID thread_id;
|
||||
VkCommandBuffer cmd;
|
||||
|
||||
PulseComputePipeline* compute_pipelines_bound;
|
||||
uint32_t compute_pipelines_bound_capacity;
|
||||
uint32_t compute_pipelines_bound_size;
|
||||
} VulkanCommandList;
|
||||
|
||||
void VulkanInitCommandList(VulkanCommandPool* pool);
|
||||
|
||||
#endif // PULSE_VULKAN_COMMAND_LIST_H_
|
||||
|
||||
#endif // PULSE_ENABLE_VULKAN_BACKEND
|
||||
47
Sources/Backends/Vulkan/VulkanCommandPool.c
git.filemode.normal_file
47
Sources/Backends/Vulkan/VulkanCommandPool.c
git.filemode.normal_file
@@ -0,0 +1,47 @@
|
||||
// Copyright (C) 2024 kanel
|
||||
// This file is part of "Pulse"
|
||||
// For conditions of distribution and use, see copyright notice in LICENSE
|
||||
|
||||
#include "Vulkan.h"
|
||||
#include "VulkanCommandPool.h"
|
||||
#include "VulkanDevice.h"
|
||||
#include "VulkanQueue.h"
|
||||
|
||||
bool VulkanInitCommandPool(PulseDevice device, VulkanCommandPool* pool, VulkanQueueType queue_type)
|
||||
{
|
||||
PULSE_CHECK_HANDLE_RETVAL(device, false);
|
||||
PULSE_CHECK_PTR_RETVAL(pool, false);
|
||||
|
||||
VulkanDevice* vulkan_device = VULKAN_RETRIEVE_DRIVER_DATA_AS(device, VulkanDevice*);
|
||||
|
||||
VkCommandPoolCreateInfo create_info = {};
|
||||
create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
||||
create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
|
||||
create_info.queueFamilyIndex = vulkan_device->queues[queue_type]->queue_family_index;
|
||||
create_info.pNext = PULSE_NULLPTR;
|
||||
CHECK_VK_RETVAL(vulkan_device->vkCreateCommandPool(vulkan_device->device, &create_info, PULSE_NULLPTR, &pool->pool), PULSE_ERROR_INITIALIZATION_FAILED, false);
|
||||
|
||||
pool->thread_id = PulseGetThreadID();
|
||||
|
||||
pool->available_command_lists = PULSE_NULLPTR;
|
||||
pool->available_command_lists_capacity = 0;
|
||||
pool->available_command_lists_size = 0;
|
||||
|
||||
pool->device = device;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void VulkanUninitCommandPool(VulkanCommandPool* pool)
|
||||
{
|
||||
PULSE_CHECK_PTR(pool);
|
||||
|
||||
VulkanDevice* vulkan_device = VULKAN_RETRIEVE_DRIVER_DATA_AS(pool->device, VulkanDevice*);
|
||||
vulkan_device->vkDestroyCommandPool(vulkan_device->device, pool->pool, PULSE_NULLPTR);
|
||||
if(pool->available_command_lists != PULSE_NULLPTR)
|
||||
free(pool->available_command_lists);
|
||||
pool->thread_id = 0;
|
||||
pool->available_command_lists = PULSE_NULLPTR;
|
||||
pool->available_command_lists_capacity = 0;
|
||||
pool->available_command_lists_size = 0;
|
||||
}
|
||||
35
Sources/Backends/Vulkan/VulkanCommandPool.h
git.filemode.normal_file
35
Sources/Backends/Vulkan/VulkanCommandPool.h
git.filemode.normal_file
@@ -0,0 +1,35 @@
|
||||
// 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_COMMAND_POOL_H_
|
||||
#define PULSE_VULKAN_COMMAND_POOL_H_
|
||||
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
#include <Pulse.h>
|
||||
#include "../../PulseInternal.h"
|
||||
#include "VulkanEnums.h"
|
||||
|
||||
typedef struct VulkanCommandPool
|
||||
{
|
||||
PulseDevice device;
|
||||
|
||||
VkCommandPool pool;
|
||||
VulkanQueueType queue_type;
|
||||
|
||||
PulseThreadID thread_id;
|
||||
|
||||
PulseCommandList* available_command_lists;
|
||||
uint32_t available_command_lists_capacity;
|
||||
uint32_t available_command_lists_size;
|
||||
} VulkanCommandPool;
|
||||
|
||||
bool VulkanInitCommandPool(PulseDevice device, VulkanCommandPool* pool, VulkanQueueType queue_type);
|
||||
void VulkanUninitCommandPool(VulkanCommandPool* pool);
|
||||
|
||||
#endif // PULSE_VULKAN_COMMAND_POOL_H_
|
||||
|
||||
#endif // PULSE_ENABLE_VULKAN_BACKEND
|
||||
@@ -17,11 +17,14 @@
|
||||
#include <Pulse.h>
|
||||
|
||||
#include "VulkanEnums.h"
|
||||
#include "VulkanCommandPool.h"
|
||||
|
||||
struct VulkanQueue;
|
||||
|
||||
typedef struct VulkanDevice
|
||||
{
|
||||
VulkanCommandPool* cmd_pools;
|
||||
|
||||
struct VulkanQueue* queues[VULKAN_QUEUE_END_ENUM];
|
||||
|
||||
VkPhysicalDeviceFeatures features;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// Copyright (C) 2024 kanel
|
||||
//
|
||||
// This file is part of "Pulse"
|
||||
// For conditions of distribution and use, see copyright notice in LICENSE
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
// This file is part of "Pulse"
|
||||
// For conditions of distribution and use, see copyright notice in LICENSE
|
||||
|
||||
#include "Pulse.h"
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
#include "Vulkan.h"
|
||||
#include "VulkanDevice.h"
|
||||
#include "VulkanFence.h"
|
||||
@@ -45,15 +46,39 @@ bool VulkanIsFenceReady(PulseDevice device, PulseFence fence)
|
||||
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;
|
||||
|
||||
case VK_NOT_READY: return false;
|
||||
case VK_ERROR_DEVICE_LOST: PulseSetInternalError(PULSE_ERROR_DEVICE_LOST); return false;
|
||||
|
||||
default: return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VulkanWaitForFences(PulseDevice device, PulseFence *const *fences, uint32_t fences_count, bool wait_for_all)
|
||||
bool VulkanWaitForFences(PulseDevice device, const PulseFence* fences, uint32_t fences_count, bool wait_for_all)
|
||||
{
|
||||
if(fences_count == 0)
|
||||
return true;
|
||||
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_fences = (VkFence*)calloc(fences_count, sizeof(VkFence));
|
||||
PULSE_CHECK_ALLOCATION_RETVAL(vulkan_fences, false);
|
||||
for(uint32_t i = 0; i < fences_count; i++)
|
||||
vulkan_fences[i] = VULKAN_RETRIEVE_DRIVER_DATA_AS(((PulseFence)fences + i), VkFence);
|
||||
VkResult result = vulkan_device->vkWaitForFences(vulkan_device->device, fences_count, vulkan_fences, wait_for_all, UINT64_MAX);
|
||||
free(vulkan_fences);
|
||||
switch(result)
|
||||
{
|
||||
case VK_SUCCESS: break;
|
||||
case VK_TIMEOUT: break;
|
||||
|
||||
case VK_ERROR_DEVICE_LOST: PulseSetInternalError(PULSE_ERROR_DEVICE_LOST); return false;
|
||||
case VK_ERROR_OUT_OF_HOST_MEMORY: PulseSetInternalError(PULSE_ERROR_CPU_ALLOCATION_FAILED); return false;
|
||||
case VK_ERROR_OUT_OF_DEVICE_MEMORY: PulseSetInternalError(PULSE_ERROR_DEVICE_ALLOCATION_FAILED); return false;
|
||||
|
||||
default: break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -7,15 +7,13 @@
|
||||
#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);
|
||||
bool VulkanWaitForFences(PulseDevice device, const PulseFence* fences, uint32_t fences_count, bool wait_for_all);
|
||||
|
||||
#endif // PULSE_VULKAN_FENCE_H_
|
||||
|
||||
|
||||
Reference in New Issue
Block a user