diff options
Diffstat (limited to 'src/frygon/vulkan/fgvk_device.c')
| -rw-r--r-- | src/frygon/vulkan/fgvk_device.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/frygon/vulkan/fgvk_device.c b/src/frygon/vulkan/fgvk_device.c new file mode 100644 index 00000000000..6f36e725070 --- /dev/null +++ b/src/frygon/vulkan/fgvk_device.c @@ -0,0 +1,76 @@ +/* + * Copyright © 2025 Lucas Francisco Fryzek + * SPDX-License-Identifier: MIT + */ +#include "fgvk_device.h" + +#include "fgvk_physical_device.h" +#include "fgvk_cmd_buffer.h" +#include "fgvk_shader.h" +#include "fgvk_queue.h" + +VKAPI_ATTR VkResult VKAPI_CALL +fgvk_CreateDevice(VkPhysicalDevice physicalDevice, + const VkDeviceCreateInfo *pCreateInfo, + const VkAllocationCallbacks *pAllocator, + VkDevice *pDevice) +{ + VK_FROM_HANDLE(fgvk_physical_device, pdev, physicalDevice); + VkResult result = VK_ERROR_OUT_OF_HOST_MEMORY; + struct fgvk_device *dev; + + dev = vk_zalloc2(&pdev->vk.instance->alloc, pAllocator, + sizeof(*dev), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); + + if (!dev) + return vk_error(pdev, VK_ERROR_OUT_OF_HOST_MEMORY); + + struct vk_device_dispatch_table dispatch_table; + vk_device_dispatch_table_from_entrypoints(&dispatch_table, + &fgvk_device_entrypoints, true); + //vk_device_dispatch_table_from_entrypoints(&dispatch_table, + // &wsi_device_entrypoints, false); + + result = vk_device_init(&dev->vk, &pdev->vk, &dispatch_table, + pCreateInfo, pAllocator); + + if (result != VK_SUCCESS) + goto fail_alloc; + + dev->vk.shader_ops = &fgvk_device_shader_ops; + dev->vk.command_buffer_ops = &fgvk_cmd_buffer_ops; + + for (unsigned i = 0; i < pCreateInfo->queueCreateInfoCount; i++) { + for (unsigned q = 0; q < pCreateInfo->pQueueCreateInfos[i].queueCount; q++) { + result = fgvk_queue_create(dev, &pCreateInfo->pQueueCreateInfos[i], q); + if (result != VK_SUCCESS) + goto fail_queues; + } + } + + *pDevice = fgvk_device_to_handle(dev); + + return result; + +fail_queues: + vk_foreach_queue_safe(iter, &dev->vk) { + struct fgvk_queue *queue = container_of(iter, struct fgvk_queue, vk); + fgvk_queue_destroy(dev, queue); + } +fail_alloc: + vk_free(&dev->vk.alloc, dev); + return result; +} + +VKAPI_ATTR void VKAPI_CALL +fgvk_DestroyDevice(VkDevice _device, const VkAllocationCallbacks *pAllocator) +{ + VK_FROM_HANDLE(fgvk_device, dev, _device); + + if (!dev) + return; + + // TODO we can't finish cause sync doesn't work + //vk_device_finish(&dev->vk); + vk_free(&dev->vk.alloc, dev); +} |