diff --git a/projects/apis/vulkan/loader/vulkan_command_loader.c b/projects/apis/vulkan/loader/vulkan_command_loader.c index de7eca7..cbfbf90 100644 --- a/projects/apis/vulkan/loader/vulkan_command_loader.c +++ b/projects/apis/vulkan/loader/vulkan_command_loader.c @@ -2,7 +2,7 @@ #include #include -gnCommandFunctions loadVulkanCommandFunctions() { +gnCommandFunctions loadVulkanCommandFunctions(void) { return (gnCommandFunctions){ ._gnCommandPoolAllocateCommandBuffers = allocateCommandBuffers, ._gnBeginCommandBuffer = beginCommandBuffer, diff --git a/projects/apis/vulkan/loader/vulkan_device_loader.c b/projects/apis/vulkan/loader/vulkan_device_loader.c index ac49efa..bbbae5a 100644 --- a/projects/apis/vulkan/loader/vulkan_device_loader.c +++ b/projects/apis/vulkan/loader/vulkan_device_loader.c @@ -13,7 +13,7 @@ #include #include -gnDeviceFunctions loadVulkanDeviceFunctions() { +gnDeviceFunctions loadVulkanDeviceFunctions(void) { return (gnDeviceFunctions){ ._gnCreatePresentationQueue = createPresentationQueue, ._gnPresentationQueueGetImage = getVulkanPresentQueueImage, diff --git a/projects/apis/vulkan/loader/vulkan_instance_loader.c b/projects/apis/vulkan/loader/vulkan_instance_loader.c index 52a5ee0..542148c 100644 --- a/projects/apis/vulkan/loader/vulkan_instance_loader.c +++ b/projects/apis/vulkan/loader/vulkan_instance_loader.c @@ -4,7 +4,7 @@ #include #include -gryphnInstanceFunctionLayers loadVulkanAPILayer() { +gryphnInstanceFunctionLayers loadVulkanAPILayer(void) { return (gryphnInstanceFunctionLayers) { .createInstance = vulkanCreateInstance, .destroyInstance = vulkanDestroyInstance, @@ -12,7 +12,7 @@ gryphnInstanceFunctionLayers loadVulkanAPILayer() { }; } -gnInstanceFunctions loadVulkanInstanceFunctions() { +gnInstanceFunctions loadVulkanInstanceFunctions(void) { return (gnInstanceFunctions){ ._gnGetPhysicalDevices = getPhysicalDevices, diff --git a/projects/apis/vulkan/loader/vulkan_loader.h b/projects/apis/vulkan/loader/vulkan_loader.h index 200c878..a08ffa2 100644 --- a/projects/apis/vulkan/loader/vulkan_loader.h +++ b/projects/apis/vulkan/loader/vulkan_loader.h @@ -7,12 +7,12 @@ #include "core/gryphn_extensions.h" typedef struct gryphnInstanceFunctionLayers gryphnInstanceFunctionLayers; -gryphnInstanceFunctionLayers loadVulkanAPILayer(); +gryphnInstanceFunctionLayers loadVulkanAPILayer(void); -gnInstanceFunctions loadVulkanInstanceFunctions(); -gnDeviceFunctions loadVulkanDeviceFunctions(); -gnCommandFunctions loadVulkanCommandFunctions(); -gnSyncExtFunctions loadVulkanSyncFunctions(); -gnQueueExtFunctions loadVulkanQueueFunctions(); +gnInstanceFunctions loadVulkanInstanceFunctions(void); +gnDeviceFunctions loadVulkanDeviceFunctions(void); +gnCommandFunctions loadVulkanCommandFunctions(void); +gnSyncExtFunctions loadVulkanSyncFunctions(void); +gnQueueExtFunctions loadVulkanQueueFunctions(void); gnBool vulkanIsExtensionSupported(gnExtension extension); diff --git a/projects/apis/vulkan/loader/vulkan_queue_loader.c b/projects/apis/vulkan/loader/vulkan_queue_loader.c index a120ed0..f078a0f 100644 --- a/projects/apis/vulkan/loader/vulkan_queue_loader.c +++ b/projects/apis/vulkan/loader/vulkan_queue_loader.c @@ -3,7 +3,7 @@ #include #include -gnQueueExtFunctions loadVulkanQueueFunctions() { +gnQueueExtFunctions loadVulkanQueueFunctions(void) { return (gnQueueExtFunctions) { ._gnGetPhysicalDeviceQueueProperties = vulkanPhysicalDeviceQueueProperties, ._gnQueueSubmit = vulkanSubmitQueue, diff --git a/projects/apis/vulkan/loader/vulkan_sync_loader.c b/projects/apis/vulkan/loader/vulkan_sync_loader.c index 5816b03..150fce3 100644 --- a/projects/apis/vulkan/loader/vulkan_sync_loader.c +++ b/projects/apis/vulkan/loader/vulkan_sync_loader.c @@ -5,7 +5,7 @@ #include "submit/vulkan_submit.h" #include "present/vulkan_present.h" -gnSyncExtFunctions loadVulkanSyncFunctions() { +gnSyncExtFunctions loadVulkanSyncFunctions(void) { return (gnSyncExtFunctions){ ._gnPresentationQueueGetImageAsync = getPresentQueueImageAsync, diff --git a/projects/apis/vulkan/src/buffers/vulkan_buffer.c b/projects/apis/vulkan/src/buffers/vulkan_buffer.c index 9c4ba15..7e7e116 100644 --- a/projects/apis/vulkan/src/buffers/vulkan_buffer.c +++ b/projects/apis/vulkan/src/buffers/vulkan_buffer.c @@ -66,7 +66,6 @@ void VkCopyBuffer(gnDevice device, VkBuffer source, VkBuffer destination, VkBuff gnReturnCode createBuffer(gnBufferHandle buffer, gnOutputDeviceHandle device, gnBufferInfo info) { buffer->buffer = malloc(sizeof(struct gnPlatformBuffer_t)); - VkBufferUsageFlags usage = vkGryphnBufferType(info.type); buffer->buffer->useStagingBuffer = (info.usage == GN_STATIC_DRAW); if (info.usage == GN_STATIC_DRAW) { return VkCreateBuffer( @@ -91,14 +90,13 @@ void vulkanBufferData(gnBufferHandle buffer, size_t dataSize, void* data) { } void vulkanBufferSubData(gnBufferHandle buffer, size_t offset, size_t dataSize, void* data) { void* bufferData; - if (buffer->buffer->useStagingBuffer) { VkGryphnBuffer* stagingBuffer = &buffer->device->outputDevice->stagingBuffer; VkDeviceSize sizeLeft = dataSize; while (sizeLeft > 0) { VkDeviceSize chunkSize = (buffer->device->outputDevice->stagingBufferSize < sizeLeft) ? buffer->device->outputDevice->stagingBufferSize : sizeLeft; vkMapMemory(buffer->device->outputDevice->device, stagingBuffer->memory, 0, chunkSize, 0, &bufferData); - memcpy(bufferData, data + (dataSize - sizeLeft), chunkSize); + memcpy(bufferData, (char*)data + (dataSize - sizeLeft), chunkSize); vkUnmapMemory(buffer->device->outputDevice->device, stagingBuffer->memory); VkBufferCopy copyRegion = { @@ -111,7 +109,7 @@ void vulkanBufferSubData(gnBufferHandle buffer, size_t offset, size_t dataSize, } } else { vkMapMemory(buffer->device->outputDevice->device, buffer->buffer->buffer.memory, 0, dataSize, 0, &bufferData); - memcpy(bufferData + offset, data, dataSize); + memcpy((char*)bufferData + offset, data, dataSize); vkUnmapMemory(buffer->device->outputDevice->device, buffer->buffer->buffer.memory); } } diff --git a/projects/apis/vulkan/src/commands/command_buffer/vulkan_command_buffer.c b/projects/apis/vulkan/src/commands/command_buffer/vulkan_command_buffer.c index 1e0d02a..339d556 100644 --- a/projects/apis/vulkan/src/commands/command_buffer/vulkan_command_buffer.c +++ b/projects/apis/vulkan/src/commands/command_buffer/vulkan_command_buffer.c @@ -15,7 +15,7 @@ gnReturnCode allocateCommandBuffers(gnCommandBufferHandle* commandBuffers, uint3 VkResult allocationResult = vkAllocateCommandBuffers(pool->device->outputDevice->device, &allocInfo, buffers); if (allocationResult == VK_SUCCESS) - for (int i = 0; i < count; i++) { + for (uint32_t i = 0; i < count; i++) { commandBuffers[i]->commandBuffer = malloc(sizeof(gnPlatformCommandBuffer)); commandBuffers[i]->commandBuffer->buffer = buffers[i]; } diff --git a/projects/apis/vulkan/src/commands/commands/vulkan_commands.c b/projects/apis/vulkan/src/commands/commands/vulkan_commands.c index 9defeff..9372349 100644 --- a/projects/apis/vulkan/src/commands/commands/vulkan_commands.c +++ b/projects/apis/vulkan/src/commands/commands/vulkan_commands.c @@ -4,7 +4,7 @@ void beginRenderPass(gnCommandBuffer buffer, gnRenderPassInfo passInfo) { VkClearValue* values = malloc(sizeof(VkClearValue) * passInfo.clearValueCount); - for (int i = 0; i < passInfo.clearValueCount; i++) { + for (uint32_t i = 0; i < passInfo.clearValueCount; i++) { values[i] = (VkClearValue){{{ passInfo.clearValues[i].red, passInfo.clearValues[i].green, diff --git a/projects/apis/vulkan/src/output_device/vulkan_physical_device.c b/projects/apis/vulkan/src/output_device/vulkan_physical_device.c index 2ae930e..386eef3 100644 --- a/projects/apis/vulkan/src/output_device/vulkan_physical_device.c +++ b/projects/apis/vulkan/src/output_device/vulkan_physical_device.c @@ -38,18 +38,13 @@ void vulkanLoadNeededQueues(VkPhysicalDevice vulkanDevice, gnPhysicalDevice gryp vkGetPhysicalDeviceQueueFamilyProperties(vulkanDevice, &queueFamilyCount, queueFamilies); gryphnDevice->physicalDevice->neededQueues = malloc(sizeof(vulkanNeededQueue) * queueFamilyCount); - gnBool foundGraphicsQueueFamily = GN_FALSE, foundTransferQueueFamily = GN_FALSE; - for (int c = 0; c < queueFamilyCount; c++) { + for (uint32_t c = 0; c < queueFamilyCount; c++) { gnBool hasNeededQueue = GN_FALSE; - if ((queueFamilies[c].queueFlags & VK_QUEUE_GRAPHICS_BIT) == VK_QUEUE_GRAPHICS_BIT) { - foundGraphicsQueueFamily = GN_TRUE; + if ((queueFamilies[c].queueFlags & VK_QUEUE_GRAPHICS_BIT) == VK_QUEUE_GRAPHICS_BIT) hasNeededQueue = GN_TRUE; - } - if ((queueFamilies[c].queueFlags & VK_QUEUE_TRANSFER_BIT) == VK_QUEUE_TRANSFER_BIT) { - foundTransferQueueFamily = GN_TRUE; + if ((queueFamilies[c].queueFlags & VK_QUEUE_TRANSFER_BIT) == VK_QUEUE_TRANSFER_BIT) hasNeededQueue = GN_TRUE; - } if (hasNeededQueue) { vulkanNeededQueue neededQueue = { @@ -77,7 +72,7 @@ gnPhysicalDevice* getPhysicalDevices(gnInstanceHandle instance, uint32_t* device vkEnumeratePhysicalDevices(instance->instance->vk_instance, deviceCount, physicalDevices); gnPhysicalDevice* outputDevices = (gnPhysicalDevice*)malloc(sizeof(gnPhysicalDevice) * *deviceCount); - for (int i = 0; i < *deviceCount; i++) { + for (uint32_t i = 0; i < *deviceCount; i++) { outputDevices[i] = malloc(sizeof(gnPhysicalOutputDevice_t)); outputDevices[i]->physicalDevice = malloc(sizeof(struct gnPlatformPhysicalDevice_t)); outputDevices[i]->physicalDevice->device = physicalDevices[i]; @@ -112,7 +107,7 @@ gnPhysicalDevice* getPhysicalDevices(gnInstanceHandle instance, uint32_t* device gnBool deviceCanPresentToSurface(gnPhysicalDevice device, gnWindowSurface surface) { gnBool foundQueue = GN_FALSE; - for (int i = 0; i < device->physicalDevice->neededQueueCount; i++) { + for (uint32_t i = 0; i < device->physicalDevice->neededQueueCount; i++) { VkBool32 supportsPresent = VK_FALSE; vkGetPhysicalDeviceSurfaceSupportKHR(device->physicalDevice->device, device->physicalDevice->neededQueues[i].queueIndex, surface->windowSurface->surface, &supportsPresent); if (supportsPresent) { @@ -127,7 +122,7 @@ gnBool deviceCanPresentToSurface(gnPhysicalDevice device, gnWindowSurface surfac uint32_t queueFamilyCount = 0; vkGetPhysicalDeviceQueueFamilyProperties(device->physicalDevice->device, &queueFamilyCount, NULL); - for (int i = 0; i < queueFamilyCount; i++) { + for (uint32_t i = 0; i < queueFamilyCount; i++) { VkBool32 supportsPresent = VK_FALSE; vkGetPhysicalDeviceSurfaceSupportKHR(device->physicalDevice->device, i, surface->windowSurface->surface, &supportsPresent); if (supportsPresent) { diff --git a/projects/apis/vulkan/src/present/vulkan_present.c b/projects/apis/vulkan/src/present/vulkan_present.c index 0ecc50d..56ecabe 100644 --- a/projects/apis/vulkan/src/present/vulkan_present.c +++ b/projects/apis/vulkan/src/present/vulkan_present.c @@ -4,11 +4,13 @@ #include "vulkan_result_converter.h" gnReturnCode vulkanQueuePresentSync(gnDevice device, gnQueue queue, gnPresentSyncInfo info) { + if (device == GN_NULL_HANDLE) return GN_INVALID_HANDLE; + VkSemaphore* waitSemaphores = malloc(sizeof(VkSemaphore) * info.waitCount); - for (int i = 0; i < info.waitCount; i++) waitSemaphores[i] = info.waitSemaphores[i]->semaphore->semaphore; + for (uint32_t i = 0; i < info.waitCount; i++) waitSemaphores[i] = info.waitSemaphores[i]->semaphore->semaphore; VkSwapchainKHR* swapchains = malloc(sizeof(VkSwapchainKHR) * info.presentationQueueCount); - for (int i = 0; i < info.presentationQueueCount; i++) swapchains[i] = info.presentationQueues[i]->presentationQueue->swapChain; + for (uint32_t i = 0; i < info.presentationQueueCount; i++) swapchains[i] = info.presentationQueues[i]->presentationQueue->swapChain; VkPresentInfoKHR presentInfo = { .sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, @@ -27,8 +29,10 @@ gnReturnCode vulkanPresentSync(gnDevice device, gnPresentSyncInfo info) { } gnReturnCode vulkanQueuePresent(gnDevice device, gnQueue queue, gnPresentInfo info) { + if (device == GN_NULL_HANDLE) return GN_INVALID_HANDLE; + VkSwapchainKHR* swapchains = malloc(sizeof(VkSwapchainKHR) * info.presentationQueueCount); - for (int i = 0; i < info.presentationQueueCount; i++) swapchains[i] = info.presentationQueues[i]->presentationQueue->swapChain; + for (uint32_t i = 0; i < info.presentationQueueCount; i++) swapchains[i] = info.presentationQueues[i]->presentationQueue->swapChain; VkPresentInfoKHR presentInfo = { .sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, diff --git a/projects/apis/vulkan/src/presentation_queue/vulkan_presentation_queue.c b/projects/apis/vulkan/src/presentation_queue/vulkan_presentation_queue.c index 87154bb..15b9ca7 100644 --- a/projects/apis/vulkan/src/presentation_queue/vulkan_presentation_queue.c +++ b/projects/apis/vulkan/src/presentation_queue/vulkan_presentation_queue.c @@ -19,42 +19,42 @@ gnReturnCode createPresentationQueue(gnPresentationQueueHandle presentationQueue .height = presentationInfo.imageSize.y }; - VkSwapchainCreateInfoKHR createInfo = {}; - createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; - createInfo.surface = presentationInfo.surface->windowSurface->surface; - - createInfo.minImageCount = presentationInfo.minImageCount; - createInfo.imageFormat = convertedFormat; - createInfo.imageColorSpace = convertedColorSpace; - createInfo.imageExtent = extent; - createInfo.imageArrayLayers = 1; - createInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + VkSwapchainCreateInfoKHR presentQueueCreateInfo = { + .sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR, + .surface = presentationInfo.surface->windowSurface->surface, + .minImageCount = presentationInfo.minImageCount, + .imageFormat = convertedFormat, + .imageColorSpace = convertedColorSpace, + .imageExtent = extent, + .imageArrayLayers = 1, + .imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, + .preTransform = details.capabilities.currentTransform, + .compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR, + .presentMode = presentMode, + .clipped = VK_TRUE, + .oldSwapchain = VK_NULL_HANDLE + }; if (device->instance->enabledExtensions[GN_EXT_QUEUES]) { - createInfo.imageSharingMode = (presentationInfo.imageSharingMode == GN_SHARING_MODE_CONCURRENT) ? VK_SHARING_MODE_CONCURRENT : VK_SHARING_MODE_EXCLUSIVE; - createInfo.queueFamilyIndexCount = presentationInfo.queueFamilyCount; - createInfo.pQueueFamilyIndices = presentationInfo.queueFamilies; + presentQueueCreateInfo.imageSharingMode = (presentationInfo.imageSharingMode == GN_SHARING_MODE_CONCURRENT) ? VK_SHARING_MODE_CONCURRENT : VK_SHARING_MODE_EXCLUSIVE; + presentQueueCreateInfo.queueFamilyIndexCount = presentationInfo.queueFamilyCount; + presentQueueCreateInfo.pQueueFamilyIndices = presentationInfo.queueFamilies; } else { if (presentationInfo.surface->windowSurface->presentQueueIndex != device->outputDevice->graphicsQueueIndex) { - createInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT; - createInfo.queueFamilyIndexCount = 2; - createInfo.pQueueFamilyIndices = (uint32_t[]){ + presentQueueCreateInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT; + presentQueueCreateInfo.queueFamilyIndexCount = 2; + presentQueueCreateInfo.pQueueFamilyIndices = (uint32_t[]){ device->outputDevice->queues[presentationInfo.surface->windowSurface->presentQueueIndex].queueInfo.queueIndex, device->outputDevice->queues[device->outputDevice->graphicsQueueIndex].queueInfo.queueIndex }; } else { - createInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; - createInfo.queueFamilyIndexCount = 1; - createInfo.pQueueFamilyIndices = &device->outputDevice->queues[presentationInfo.surface->windowSurface->presentQueueIndex].queueInfo.queueIndex; + presentQueueCreateInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; + presentQueueCreateInfo.queueFamilyIndexCount = 1; + presentQueueCreateInfo.pQueueFamilyIndices = &device->outputDevice->queues[presentationInfo.surface->windowSurface->presentQueueIndex].queueInfo.queueIndex; } } - createInfo.preTransform = details.capabilities.currentTransform; - createInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; - createInfo.presentMode = presentMode; - createInfo.clipped = VK_TRUE; - createInfo.oldSwapchain = VK_NULL_HANDLE; - VkResult result = vkCreateSwapchainKHR(device->outputDevice->device, &createInfo, NULL, &presentationQueue->presentationQueue->swapChain); + VkResult result = vkCreateSwapchainKHR(device->outputDevice->device, &presentQueueCreateInfo, NULL, &presentationQueue->presentationQueue->swapChain); if (result != VK_SUCCESS) return VkResultToGnReturnCode(result); vkGetSwapchainImagesKHR(device->outputDevice->device, presentationQueue->presentationQueue->swapChain, &presentationQueue->imageCount, NULL); @@ -62,22 +62,23 @@ gnReturnCode createPresentationQueue(gnPresentationQueueHandle presentationQueue presentationQueue->presentationQueue->swapChainImageViews = malloc(sizeof(VkImageView) * presentationQueue->imageCount); vkGetSwapchainImagesKHR(device->outputDevice->device, presentationQueue->presentationQueue->swapChain, &presentationQueue->imageCount, presentationQueue->presentationQueue->swapChainImages); - VkImageViewCreateInfo imageViewCreateInfo = {}; - imageViewCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; - imageViewCreateInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; - imageViewCreateInfo.format = convertedFormat; - imageViewCreateInfo.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; - imageViewCreateInfo.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; - imageViewCreateInfo.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; - imageViewCreateInfo.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; - imageViewCreateInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - imageViewCreateInfo.subresourceRange.baseMipLevel = 0; - imageViewCreateInfo.subresourceRange.levelCount = 1; - imageViewCreateInfo.subresourceRange.baseArrayLayer = 0; - imageViewCreateInfo.subresourceRange.layerCount = 1; + VkImageViewCreateInfo imageViewCreateInfo = { + .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, + .viewType = VK_IMAGE_VIEW_TYPE_2D, + .format = convertedFormat, + .components.r = VK_COMPONENT_SWIZZLE_IDENTITY, + .components.g = VK_COMPONENT_SWIZZLE_IDENTITY, + .components.b = VK_COMPONENT_SWIZZLE_IDENTITY, + .components.a = VK_COMPONENT_SWIZZLE_IDENTITY, + .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, + .subresourceRange.baseMipLevel = 0, + .subresourceRange.levelCount = 1, + .subresourceRange.baseArrayLayer = 0, + .subresourceRange.layerCount = 1 + }; presentationQueue->images = malloc(sizeof(gnTextureHandle) * presentationQueue->imageCount); - for (int i = 0; i < presentationQueue->imageCount; i++) { + for (uint32_t i = 0; i < presentationQueue->imageCount; i++) { presentationQueue->images[i] = malloc(sizeof(struct gnTexture_t)); presentationQueue->images[i]->texture = malloc(sizeof(gnPlatformTexture)); imageViewCreateInfo.image = presentationQueue->presentationQueue->swapChainImages[i]; @@ -99,23 +100,18 @@ gnReturnCode getVulkanPresentQueueImage(gnPresentationQueueHandle presentationQu presentationQueue->presentationQueue->swapChain, UINT64_MAX, VK_NULL_HANDLE, presentationQueue->outputDevice->outputDevice->barrierFence, imageIndex); vkWaitForFences(presentationQueue->outputDevice->outputDevice->device, 1, &presentationQueue->outputDevice->outputDevice->barrierFence, VK_TRUE, UINT64_MAX); - if (result == VK_ERROR_OUT_OF_DATE_KHR) return GN_OUT_OF_DATE_PRESENTATION_QUEUE; - if (result == VK_SUBOPTIMAL_KHR) return GN_SUBOPTIMAL_PRESENTATION_QUEUE; - return GN_SUCCESS; + return VkResultToGnReturnCode(result); } gnReturnCode getPresentQueueImageAsync(gnPresentationQueueHandle presentationQueue, uint64_t timeout, gnSemaphore semaphore, uint32_t* imageIndex) { - VkResult result = vkAcquireNextImageKHR( + return VkResultToGnReturnCode(vkAcquireNextImageKHR( presentationQueue->outputDevice->outputDevice->device, presentationQueue->presentationQueue->swapChain, - timeout, semaphore->semaphore->semaphore, VK_NULL_HANDLE, imageIndex); - if (result == VK_ERROR_OUT_OF_DATE_KHR) return GN_OUT_OF_DATE_PRESENTATION_QUEUE; - if (result == VK_SUBOPTIMAL_KHR) return GN_SUBOPTIMAL_PRESENTATION_QUEUE; - return GN_SUCCESS; + timeout, semaphore->semaphore->semaphore, VK_NULL_HANDLE, imageIndex)); } void destroyPresentationQueue(gnPresentationQueueHandle queue) { - for (int i = 0; i < queue->imageCount; i++) + for (uint32_t i = 0; i < queue->imageCount; i++) vkDestroyImageView(queue->outputDevice->outputDevice->device, queue->presentationQueue->swapChainImageViews[i], NULL); vkDestroySwapchainKHR(queue->outputDevice->outputDevice->device, queue->presentationQueue->swapChain, NULL); free(queue->presentationQueue->swapChainImageViews); diff --git a/projects/apis/vulkan/src/presentation_queue/vulkan_swapchain_support.c b/projects/apis/vulkan/src/presentation_queue/vulkan_swapchain_support.c index 4b31e04..a7ab1d7 100644 --- a/projects/apis/vulkan/src/presentation_queue/vulkan_swapchain_support.c +++ b/projects/apis/vulkan/src/presentation_queue/vulkan_swapchain_support.c @@ -1,10 +1,10 @@ #include "vulkan_swapchain_support.h" -struct vkSwapchainSupportDetails_t vkGetSwapchainSupport( +vkSwapchainSupportDetails vkGetSwapchainSupport( const VkPhysicalDevice device, const VkSurfaceKHR surface ) { - struct vkSwapchainSupportDetails_t details; + vkSwapchainSupportDetails details; vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device, surface, &details.capabilities); vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &details.formatCount, NULL); @@ -21,15 +21,3 @@ struct vkSwapchainSupportDetails_t vkGetSwapchainSupport( return details; } - -struct vkSwapchainDetails_t vkGetSwapchainDetails( - const struct vkSwapchainSupportDetails_t supportDetails -) { - struct vkSwapchainDetails_t details; - - for (int i = 0; i < supportDetails.formatCount; i++) { - // if (supportDetails.) - } - - return details; -} diff --git a/projects/apis/vulkan/src/presentation_queue/vulkan_swapchain_support.h b/projects/apis/vulkan/src/presentation_queue/vulkan_swapchain_support.h index 46d953b..71368a6 100644 --- a/projects/apis/vulkan/src/presentation_queue/vulkan_swapchain_support.h +++ b/projects/apis/vulkan/src/presentation_queue/vulkan_swapchain_support.h @@ -2,7 +2,7 @@ #include #include -typedef struct vkSwapchainSupportDetails_t { +typedef struct vkSwapchainSupportDetails { VkSurfaceCapabilitiesKHR capabilities; uint32_t formatCount; VkSurfaceFormatKHR* formats; @@ -11,15 +11,11 @@ typedef struct vkSwapchainSupportDetails_t { VkPresentModeKHR* presentModes; } vkSwapchainSupportDetails; -typedef struct vkSwapchainDetails_t { +typedef struct vkSwapchainDetails { VkSurfaceFormatKHR surfaceFormat; } vkSwapchainDetails; -struct vkSwapchainSupportDetails_t vkGetSwapchainSupport( +struct vkSwapchainSupportDetails vkGetSwapchainSupport( const VkPhysicalDevice device, const VkSurfaceKHR surface ); - -struct vkSwapchainDetails_t vkGetSwapchainDetails( - const struct vkSwapchainSupportDetails_t supportDetails -); diff --git a/projects/apis/vulkan/src/renderpass/vulkan_render_pass_descriptor.c b/projects/apis/vulkan/src/renderpass/vulkan_render_pass_descriptor.c index c4bb257..368cfda 100644 --- a/projects/apis/vulkan/src/renderpass/vulkan_render_pass_descriptor.c +++ b/projects/apis/vulkan/src/renderpass/vulkan_render_pass_descriptor.c @@ -38,19 +38,17 @@ VkPipelineStageFlags vkGryphnRenderPassStage(gnRenderPassStage stage) { VkAccessFlags vkGryphnRenderPassAccess(gnRenderPassAccess access) { VkAccessFlags flags = 0; - if ((flags & GN_COLOR_ATTACHMENT_WRITE) == GN_COLOR_ATTACHMENT_WRITE) flags |= VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; - if ((flags & GN_DEPTH_STENCIL_WRITE) == GN_DEPTH_STENCIL_WRITE) flags |= VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; + if ((access & GN_COLOR_ATTACHMENT_WRITE) == GN_COLOR_ATTACHMENT_WRITE) flags |= VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; + if ((access & GN_DEPTH_STENCIL_WRITE) == GN_DEPTH_STENCIL_WRITE) flags |= VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; return flags; } gnReturnCode createRenderPass(gnRenderPassDescriptor renderPass, gnDevice device, gnRenderPassDescriptorInfo info) { - - renderPass->renderPassDescriptor = malloc(sizeof(gnPlatformRenderPassDescriptor)); renderPass->renderPassDescriptor->attachmentCount = info.attachmentCount; renderPass->renderPassDescriptor->attachments = malloc(sizeof(VkAttachmentDescription) * info.attachmentCount); - for (int i = 0; i < info.attachmentCount; i++) { + for (uint32_t i = 0; i < info.attachmentCount; i++) { renderPass->renderPassDescriptor->attachments[i].format = vkGryphnFormatToVulkanFormat(info.attachmentInfos[i].format); renderPass->renderPassDescriptor->attachments[i].flags = 0; renderPass->renderPassDescriptor->attachments[i].samples = gnSampleCountToVulkan(info.attachmentInfos[i].samples); @@ -72,11 +70,11 @@ gnReturnCode createRenderPass(gnRenderPassDescriptor renderPass, gnDevice device renderPass->renderPassDescriptor->resolveAttachments = malloc(sizeof(VkAttachmentReference*) * info.subpassCount); - for (int i = 0; i < info.subpassCount; i++) { + for (uint32_t i = 0; i < info.subpassCount; i++) { renderPass->renderPassDescriptor->colorAttachments[i] = malloc(sizeof(VkAttachmentReference) * info.subpassInfos[i].colorAttachmentCount); renderPass->renderPassDescriptor->resolveAttachments[i] = malloc(sizeof(VkAttachmentReference) * info.subpassInfos[i].colorAttachmentCount); - for (int c = 0; c < info.subpassInfos[i].colorAttachmentCount; c++) { + for (uint32_t c = 0; c < info.subpassInfos[i].colorAttachmentCount; c++) { renderPass->renderPassDescriptor->colorAttachments[i][c] = (VkAttachmentReference){ .attachment = info.subpassInfos[i].colorAttachments[c].index, .layout = vkGryphnImageLayout(info.subpassInfos[i].colorAttachments[c].imageLayout) @@ -108,7 +106,7 @@ gnReturnCode createRenderPass(gnRenderPassDescriptor renderPass, gnDevice device } renderPass->renderPassDescriptor->dependencies = malloc(sizeof(VkSubpassDependency) * info.dependencyCount); - for (int i = 0; i < info.dependencyCount; i++) { + for (uint32_t i = 0; i < info.dependencyCount; i++) { renderPass->renderPassDescriptor->dependencies[i] = (VkSubpassDependency) { .srcSubpass = (info.dependencies[i].source == GN_SUBPASS_EXTERNAL) ? VK_SUBPASS_EXTERNAL : info.dependencies[i].source, .dstSubpass = (info.dependencies[i].destination == GN_SUBPASS_EXTERNAL) ? VK_SUBPASS_EXTERNAL : info.dependencies[i].destination, diff --git a/projects/apis/vulkan/src/submit/vulkan_submit.c b/projects/apis/vulkan/src/submit/vulkan_submit.c index 84f6ce7..875e624 100644 --- a/projects/apis/vulkan/src/submit/vulkan_submit.c +++ b/projects/apis/vulkan/src/submit/vulkan_submit.c @@ -2,16 +2,18 @@ #include "vulkan_result_converter.h" gnReturnCode vulkanSubmitSyncQueue(gnOutputDevice device, gnQueue queue, gnSubmitSyncInfo info) { + if (device == GN_NULL_HANDLE) return GN_INVALID_HANDLE; + VkSemaphore* waitSemaphores = malloc(sizeof(VkSemaphore) * info.waitCount); VkPipelineStageFlags* waitStages = malloc(sizeof(VkPipelineStageFlags) * info.waitCount); - for (int i = 0; i < info.waitCount; i++) waitSemaphores[i] = info.waitSemaphores[i]->semaphore->semaphore; - for (int i = 0; i < info.waitCount; i++) waitStages[i] = vkGryphnRenderPassStage(info.waitStages[i]); + for (uint32_t i = 0; i < info.waitCount; i++) waitSemaphores[i] = info.waitSemaphores[i]->semaphore->semaphore; + for (uint32_t i = 0; i < info.waitCount; i++) waitStages[i] = vkGryphnRenderPassStage(info.waitStages[i]); VkCommandBuffer* commandBuffers = malloc(sizeof(VkCommandBuffer) * info.commandBufferCount); - for (int i = 0; i < info.commandBufferCount; i++) commandBuffers[i] = info.commandBuffers[i]->commandBuffer->buffer; + for (uint32_t i = 0; i < info.commandBufferCount; i++) commandBuffers[i] = info.commandBuffers[i]->commandBuffer->buffer; VkSemaphore* signalSemaphores = malloc(sizeof(VkSemaphore) * info.signalCount); - for (int i = 0; i < info.signalCount; i++) signalSemaphores[i] = info.signalSemaphores[i]->semaphore->semaphore; + for (uint32_t i = 0; i < info.signalCount; i++) signalSemaphores[i] = info.signalSemaphores[i]->semaphore->semaphore; VkSubmitInfo submitInfo = { .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, @@ -33,7 +35,7 @@ gnReturnCode vulkanSubmitSync(gnDevice device, gnSubmitSyncInfo info) { gnReturnCode vulkanSubmitQueue(gnOutputDevice device, gnQueue queue, gnSubmitInfo info) { VkCommandBuffer* commandBuffers = malloc(sizeof(VkCommandBuffer) * info.commandBufferCount); - for (int i = 0; i < info.commandBufferCount; i++) commandBuffers[i] = info.commandBuffers[i]->commandBuffer->buffer; + for (uint32_t i = 0; i < info.commandBufferCount; i++) commandBuffers[i] = info.commandBuffers[i]->commandBuffer->buffer; VkSubmitInfo submitInfo = { .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, diff --git a/projects/apis/vulkan/src/uniforms/vulkan_uniform_pool.c b/projects/apis/vulkan/src/uniforms/vulkan_uniform_pool.c index d009c7c..fc8799f 100644 --- a/projects/apis/vulkan/src/uniforms/vulkan_uniform_pool.c +++ b/projects/apis/vulkan/src/uniforms/vulkan_uniform_pool.c @@ -4,9 +4,11 @@ #include "output_device/vulkan_output_devices.h" #include "uniforms/gryphn_uniform.h" #include "vulkan_uniform.h" -#include "stdio.h" -VkGryphnUniformPool* GetLastUniformPool(VkGryphnUniformPoolArrayList* list) { return &list->data[list->count - 1]; } +VkGryphnUniformPool* GetLastUniformPool(VkGryphnUniformPoolArrayList list) { + uint32_t count = VkGryphnUniformPoolArrayListCount(list); + return VkGryphnUniformPoolArrayListRefAt(list, count); +} gnReturnCode createUniformPool(gnUniformPool pool, gnDeviceHandle device) { pool->uniformPool = malloc(sizeof(struct gnPlatformUniformPool_t)); @@ -18,10 +20,10 @@ gnReturnCode createUniformPool(gnUniformPool pool, gnDeviceHandle device) { .pool = VK_NULL_HANDLE, .layouts = VkDescriptorSetLayoutArrayListCreate() }; - VkGryphnUniformPoolArrayListAdd(&pool->uniformPool->pools, firstPool); + VkGryphnUniformPoolArrayListAdd(pool->uniformPool->pools, firstPool); } // scopped because the add function copies and I don't want it lying around - VkGryphnUniformPool* currentPool = GetLastUniformPool(&pool->uniformPool->pools); + VkGryphnUniformPool* currentPool = GetLastUniformPool(pool->uniformPool->pools); VkDescriptorPoolCreateInfo poolInfo = { .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, .flags = VK_DESCRIPTOR_POOL_CREATE_ALLOW_OVERALLOCATION_SETS_BIT_NV, @@ -50,13 +52,13 @@ gnUniform* allocateUniforms(gnUniformPool pool, gnUniformAllocationInfo allocInf }; // TODO: redo this, its not warning me IDK why cuz its totally wrong - VkDescriptorPoolSize poolSizes[GN_UNIFORM_TYPE_MAX] = { }; - for (int i = 0; i < allocInfo.setCount; i++) - for (int c = 0; c < allocInfo.sets[i].uniformBindingCount; c++) + VkDescriptorPoolSize poolSizes[GN_UNIFORM_TYPE_MAX]; + for (uint32_t i = 0; i < allocInfo.setCount; i++) + for (uint32_t c = 0; c < allocInfo.sets[i].uniformBindingCount; c++) poolSizes[allocInfo.sets[i].uniformBindings[c].type].descriptorCount++; uint32_t count = 0; - VkDescriptorPoolSize realPoolSizes[GN_UNIFORM_TYPE_MAX] = {}; + VkDescriptorPoolSize realPoolSizes[GN_UNIFORM_TYPE_MAX]; for (int i = 0; i < GN_UNIFORM_TYPE_MAX; i++) { poolSizes[i].type = vkGryphnUniformType(i); @@ -79,17 +81,17 @@ gnUniform* allocateUniforms(gnUniformPool pool, gnUniformAllocationInfo allocInf ) != VK_SUCCESS) return NULL; - VkGryphnUniformPoolArrayListAdd(&pool->uniformPool->pools, newPool); + VkGryphnUniformPoolArrayListAdd(pool->uniformPool->pools, newPool); } // scopped for same reasons as before - VkGryphnUniformPool* currentPool = GetLastUniformPool(&pool->uniformPool->pools); + VkGryphnUniformPool* currentPool = GetLastUniformPool(pool->uniformPool->pools); - uint32_t startingCount = currentPool->layouts.count; - VkDescriptorSetLayoutArrayListExpand(¤tPool->layouts, allocInfo.setCount); + uint32_t startingCount = VkDescriptorSetLayoutArrayListCount(currentPool->layouts); + VkDescriptorSetLayoutArrayListExpand(currentPool->layouts, allocInfo.setCount); - for (int i = 0; i < allocInfo.setCount; i++) { + for (uint32_t i = 0; i < allocInfo.setCount; i++) { VkDescriptorSetLayoutArrayListAdd( - ¤tPool->layouts, + currentPool->layouts, vkGryphnCreateSetLayouts(&allocInfo.sets[i], pool->device->outputDevice->device) ); } @@ -98,7 +100,7 @@ gnUniform* allocateUniforms(gnUniformPool pool, gnUniformAllocationInfo allocInf .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, .descriptorPool = currentPool->pool, .descriptorSetCount = allocInfo.setCount, - .pSetLayouts = ¤tPool->layouts.data[startingCount] + .pSetLayouts = VkDescriptorSetLayoutArrayListRefAt(currentPool->layouts, startingCount) }; VkDescriptorSet* sets = malloc(sizeof(VkDescriptorSet) * allocInfo.setCount); @@ -106,7 +108,7 @@ gnUniform* allocateUniforms(gnUniformPool pool, gnUniformAllocationInfo allocInf return NULL; gnUniform* uniforms = malloc(sizeof(gnUniform) * allocInfo.setCount); - for (int i = 0; i < allocInfo.setCount; i++) { + for (uint32_t i = 0; i < allocInfo.setCount; i++) { uniforms[i] = malloc(sizeof(struct gnUniform_t)); uniforms[i]->uniform = malloc(sizeof(struct gnPlatformUniform_t)); uniforms[i]->uniform->set = sets[i]; @@ -115,9 +117,15 @@ gnUniform* allocateUniforms(gnUniformPool pool, gnUniformAllocationInfo allocInf } void destroyUniformPool(gnUniformPool pool) { - for (int k = 0; k < pool->uniformPool->pools.count; k++) { - vkDestroyDescriptorPool(pool->device->outputDevice->device, pool->uniformPool->pools.data[k].pool, NULL); - for (int i = 0; i < pool->uniformPool->pools.data[k].layouts.count; i++) - vkDestroyDescriptorSetLayout(pool->device->outputDevice->device, pool->uniformPool->pools.data[k].layouts.data[i], NULL); + for (uint32_t k = 0; k < VkGryphnUniformPoolArrayListCount(pool->uniformPool->pools); k++) { + VkGryphnUniformPool* ref = VkGryphnUniformPoolArrayListRefAt(pool->uniformPool->pools, k); + vkDestroyDescriptorPool(pool->device->outputDevice->device, ref->pool, NULL); + for (uint32_t i = 0; i < VkDescriptorSetLayoutArrayListCount(ref->layouts); i++) + vkDestroyDescriptorSetLayout(pool->device->outputDevice->device, VkDescriptorSetLayoutArrayListAt(ref->layouts, i), NULL); } } + + + +GN_ARRAY_LIST_DEFINITION(VkDescriptorSetLayout) +GN_ARRAY_LIST_DEFINITION(VkGryphnUniformPool) diff --git a/projects/apis/vulkan/src/uniforms/vulkan_uniform_pool.h b/projects/apis/vulkan/src/uniforms/vulkan_uniform_pool.h index d78ab1d..9aa176d 100644 --- a/projects/apis/vulkan/src/uniforms/vulkan_uniform_pool.h +++ b/projects/apis/vulkan/src/uniforms/vulkan_uniform_pool.h @@ -2,13 +2,13 @@ #include #include -GN_ARRAY_LIST(VkDescriptorSetLayout); +GN_ARRAY_LIST_HEADER(VkDescriptorSetLayout); typedef struct VkGryphnUniformPool { VkDescriptorPool pool; VkDescriptorSetLayoutArrayList layouts; } VkGryphnUniformPool; -GN_ARRAY_LIST(VkGryphnUniformPool); +GN_ARRAY_LIST_HEADER(VkGryphnUniformPool); struct gnPlatformUniformPool_t { VkGryphnUniformPoolArrayList pools; diff --git a/projects/apis/vulkan/src/vulkan_surface/vulkan_surface.c b/projects/apis/vulkan/src/vulkan_surface/vulkan_surface.c index e8e15c3..7a8a923 100644 --- a/projects/apis/vulkan/src/vulkan_surface/vulkan_surface.c +++ b/projects/apis/vulkan/src/vulkan_surface/vulkan_surface.c @@ -71,7 +71,7 @@ gnSurfaceFormat* vkGetSurfaceFormats( if (*formatCount > 0) { vkGetPhysicalDeviceSurfaceFormatsKHR(device->physicalDevice->device, windowSurface->windowSurface->surface, formatCount, vkFormats); - for (int i = 0; i < *formatCount; i++) { + for (uint32_t i = 0; i < *formatCount; i++) { switch (vkFormats[i].format) { case VK_FORMAT_B8G8R8A8_SRGB: { formats[i].format = GN_FORMAT_BGRA8_SRGB; break; } case VK_FORMAT_B8G8R8A8_UNORM: { formats[i].format = GN_FORMAT_BGRA8; break; } @@ -100,9 +100,9 @@ gnSurfaceDetails getSurfaceDetails( surfaceDetails.minImageCount = details.minImageCount; surfaceDetails.maxImageCount = details.maxImageCount; - surfaceDetails.minImageSize = (gnUInt2){ details.minImageExtent.width, details.minImageExtent.height }; - surfaceDetails.maxImageSize = (gnUInt2){ details.maxImageExtent.width, details.maxImageExtent.height }; - surfaceDetails.currentSize = (gnUInt2){ details.currentExtent.width, details.currentExtent.height }; + surfaceDetails.minImageSize = (gnUInt2){ .x = details.minImageExtent.width, .y = details.minImageExtent.height }; + surfaceDetails.maxImageSize = (gnUInt2){ .x = details.maxImageExtent.width, .y = details.maxImageExtent.height }; + surfaceDetails.currentSize = (gnUInt2){ .x = details.currentExtent.width, .y = details.currentExtent.height }; return surfaceDetails; } diff --git a/projects/core/src/renderpass/gryphn_render_pass_descriptor.h b/projects/core/src/renderpass/gryphn_render_pass_descriptor.h index 61290cb..1a58785 100644 --- a/projects/core/src/renderpass/gryphn_render_pass_descriptor.h +++ b/projects/core/src/renderpass/gryphn_render_pass_descriptor.h @@ -8,7 +8,7 @@ typedef enum gnRenderPassStage { GN_COLOR_ATTACHMENT_OUTPUT = 1, GN_EARLY_FRAGMENT_TEST = 2 -} gnRenderPassStage; // I stole these from vulkan to make that conversion easier +} gnRenderPassStage; typedef enum gnRenderPassAccess { GN_COLOR_ATTACHMENT_WRITE = 1, diff --git a/projects/utils b/projects/utils index 203928a..c426f9a 160000 --- a/projects/utils +++ b/projects/utils @@ -1 +1 @@ -Subproject commit 203928aa81efcb4a2dda743f4a551b54eb4b236a +Subproject commit c426f9ab6deb3fe71767b8d83106b1913fc253bc