some bugs in memory allocation
This commit is contained in:
@@ -7,50 +7,47 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL vk_debuggerDebugCallback(
|
|||||||
VkDebugUtilsMessageTypeFlagsEXT messageType,
|
VkDebugUtilsMessageTypeFlagsEXT messageType,
|
||||||
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
|
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
|
||||||
void* pUserData) {
|
void* pUserData) {
|
||||||
printf("Created instance: %s\n", pCallbackData->pMessage);
|
|
||||||
|
|
||||||
|
gnMessageSeverity severity;
|
||||||
|
gnMessageType type;
|
||||||
|
gnMessageData data = {
|
||||||
|
.message = gnCreateString(pCallbackData->pMessage)
|
||||||
|
};
|
||||||
|
|
||||||
// gnMessageSeverity severity;
|
switch (messageSeverity) {
|
||||||
// gnMessageType type;
|
default: break;
|
||||||
// gnMessageData data = {
|
case VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT: severity = GN_MESSAGE_VERBOSE; break;
|
||||||
// .message = gnCreateString(pCallbackData->pMessage)
|
case VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT: severity = GN_MESSAGE_INFO; break;
|
||||||
// };
|
case VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT: severity = GN_MESSAGE_WARNING; break;
|
||||||
|
case VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT: severity = GN_MESSAGE_ERROR; break;
|
||||||
|
}
|
||||||
|
|
||||||
// switch (messageSeverity) {
|
switch (messageType) {
|
||||||
// default: break;
|
default: break;
|
||||||
// case VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT: severity = GN_MESSAGE_VERBOSE; break;
|
case VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT: type = GN_DEBUG_MESSAGE_GENERAL; break;
|
||||||
// case VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT: severity = GN_MESSAGE_INFO; break;
|
case VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT: type = GN_DEBUG_MESSAGE_VALIDATION; break;
|
||||||
// case VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT: severity = GN_MESSAGE_WARNING; break;
|
case VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT: type = GN_DEBUG_MESSAGE_PERFORMANCE; break;
|
||||||
// case VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT: severity = GN_MESSAGE_ERROR; break;
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// switch (messageType) {
|
gnInstanceHandle instance = (gnInstanceHandle)pUserData;
|
||||||
// default: break;
|
|
||||||
// case VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT: type = GN_DEBUG_MESSAGE_GENERAL; break;
|
|
||||||
// case VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT: type = GN_DEBUG_MESSAGE_VALIDATION; break;
|
|
||||||
// case VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT: type = GN_DEBUG_MESSAGE_PERFORMANCE; break;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// gnInstanceHandle instance = (gnInstanceHandle)pUserData;
|
if (instance->debugger) {
|
||||||
|
instance->debugger->info.callback(
|
||||||
|
severity, type, data, instance->debugger->info.userData
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
instance->instance->instanceMessageCount++;
|
||||||
|
if (instance->instance->instanceMessageCount == 1)
|
||||||
|
instance->instance->instanceMessages = malloc(sizeof(struct gnInstanceMessage) * instance->instance->instanceMessageCount);
|
||||||
|
else
|
||||||
|
instance->instance->instanceMessages = realloc(instance->instance->instanceMessages, sizeof(struct gnInstanceMessage) * instance->instance->instanceMessageCount);
|
||||||
|
|
||||||
// if (instance->debugger) {
|
instance->instance->instanceMessages[instance->instance->instanceMessageCount - 1] = (struct gnInstanceMessage){
|
||||||
// instance->debugger->info.callback(
|
.data = data,
|
||||||
// severity, type, data, instance->debugger->info.userData
|
.severity = severity,
|
||||||
// );
|
.type = type
|
||||||
// } else {
|
};
|
||||||
// instance->instance->instanceMessageCount++;
|
}
|
||||||
// if (instance->instance->instanceMessageCount == 1) {
|
|
||||||
// instance->instance->instanceMessages = malloc(sizeof(struct gnInstanceMessage) * instance->instance->instanceMessageCount);
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// instance->instance->instanceMessages = realloc(instance->instance->instanceMessages, sizeof(struct gnInstanceMessage) * instance->instance->instanceMessageCount);
|
|
||||||
// }
|
|
||||||
// instance->instance->instanceMessages[instance->instance->instanceMessageCount - 1] = (struct gnInstanceMessage){
|
|
||||||
// .data = data,
|
|
||||||
// .severity = severity,
|
|
||||||
// .type = type
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
||||||
return VK_FALSE;
|
return VK_FALSE;
|
||||||
}
|
}
|
||||||
|
@@ -76,9 +76,11 @@ gnReturnCode gnCreateOutputDeviceFn(gnOutputDeviceHandle outputDevice, gnInstanc
|
|||||||
.queueFamilyIndex = transferQueueIndex
|
.queueFamilyIndex = transferQueueIndex
|
||||||
};
|
};
|
||||||
|
|
||||||
if (vkCreateCommandPool(outputDevice->outputDevice->device, &poolInfo, NULL, &outputDevice->outputDevice->transferCommandPool) != VK_SUCCESS) {
|
if (vkCreateCommandPool(outputDevice->outputDevice->device, &poolInfo, NULL, &outputDevice->outputDevice->transferCommandPool) != VK_SUCCESS)
|
||||||
return GN_FAILED_TO_CREATE_COMMAND_POOL;
|
return GN_FAILED_TO_CREATE_COMMAND_POOL;
|
||||||
}
|
|
||||||
|
free(queueCreateInfos);
|
||||||
|
free(queueFamilies);
|
||||||
|
|
||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,9 @@
|
|||||||
#include "renderpass/vulkan_render_pass_descriptor.h"
|
#include "renderpass/vulkan_render_pass_descriptor.h"
|
||||||
#include "uniforms/vulkan_uniform_layout.h"
|
#include "uniforms/vulkan_uniform_layout.h"
|
||||||
|
|
||||||
|
#include "stdio.h"
|
||||||
|
|
||||||
|
|
||||||
VkDynamicState vkGryphnDynamicStateToVulkanDynamicState(enum gnDynamicState_e state) {
|
VkDynamicState vkGryphnDynamicStateToVulkanDynamicState(enum gnDynamicState_e state) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case GN_DYNAMIC_VIEWPORT: return VK_DYNAMIC_STATE_VIEWPORT;
|
case GN_DYNAMIC_VIEWPORT: return VK_DYNAMIC_STATE_VIEWPORT;
|
||||||
@@ -63,37 +66,35 @@ VkFormat vkGryphnVertexFormat(gnVertexFormat format) {
|
|||||||
|
|
||||||
gnReturnCode gnCreateGraphicsPipelineFn(gnGraphicsPipeline graphicsPipeline, gnDevice device, gnGraphicsPipelineInfo info) {
|
gnReturnCode gnCreateGraphicsPipelineFn(gnGraphicsPipeline graphicsPipeline, gnDevice device, gnGraphicsPipelineInfo info) {
|
||||||
graphicsPipeline->graphicsPipeline = malloc(sizeof(gnPlatformGraphicsPipeline));
|
graphicsPipeline->graphicsPipeline = malloc(sizeof(gnPlatformGraphicsPipeline));
|
||||||
|
|
||||||
for (int i = 0; i < GN_DYNAMIC_STATE_MAX; i++) graphicsPipeline->graphicsPipeline->isDynamic[i] = gnFalse;
|
for (int i = 0; i < GN_DYNAMIC_STATE_MAX; i++) graphicsPipeline->graphicsPipeline->isDynamic[i] = gnFalse;
|
||||||
|
|
||||||
VkDynamicState* dynamicStates = malloc(sizeof(VkDynamicState) * info.dynamicState.dynamicStateCount);
|
graphicsPipeline->graphicsPipeline->dynamicStates = malloc(sizeof(VkDynamicState) * info.dynamicState.dynamicStateCount);
|
||||||
for (int i = 0; i < info.dynamicState.dynamicStateCount; i++) {
|
for (int i = 0; i < info.dynamicState.dynamicStateCount; i++) {
|
||||||
graphicsPipeline->graphicsPipeline->isDynamic[info.dynamicState.dynamicStates[i]] = gnTrue;
|
graphicsPipeline->graphicsPipeline->isDynamic[info.dynamicState.dynamicStates[i]] = gnTrue;
|
||||||
dynamicStates[i] = vkGryphnDynamicStateToVulkanDynamicState(info.dynamicState.dynamicStates[i]);
|
graphicsPipeline->graphicsPipeline->dynamicStates[i] = vkGryphnDynamicStateToVulkanDynamicState(info.dynamicState.dynamicStates[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
graphicsPipeline->graphicsPipeline->dynamicState = (VkPipelineDynamicStateCreateInfo){
|
graphicsPipeline->graphicsPipeline->dynamicState = (VkPipelineDynamicStateCreateInfo){
|
||||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
|
||||||
.dynamicStateCount = info.dynamicState.dynamicStateCount,
|
.dynamicStateCount = info.dynamicState.dynamicStateCount,
|
||||||
.pDynamicStates = dynamicStates
|
.pDynamicStates = graphicsPipeline->graphicsPipeline->dynamicStates
|
||||||
};
|
};
|
||||||
|
|
||||||
int vertexAttributeCount = 0;
|
int vertexAttributeCount = 0;
|
||||||
VkVertexInputAttributeDescription* attributeDescriptions = NULL;
|
graphicsPipeline->graphicsPipeline->bindingDescriptions = malloc(sizeof(VkVertexInputBindingDescription) * info.shaderInputLayout.bufferCount);
|
||||||
VkVertexInputBindingDescription* bindingDescriptions = malloc(sizeof(VkVertexInputBindingDescription) * info.shaderInputLayout.bufferCount);
|
|
||||||
for (int i = 0; i < info.shaderInputLayout.bufferCount; i++) {
|
for (int i = 0; i < info.shaderInputLayout.bufferCount; i++) {
|
||||||
bindingDescriptions[i].binding = info.shaderInputLayout.bufferAttributes[i].binding;
|
graphicsPipeline->graphicsPipeline->bindingDescriptions[i].binding = info.shaderInputLayout.bufferAttributes[i].binding;
|
||||||
bindingDescriptions[i].stride = info.shaderInputLayout.bufferAttributes[i].size;
|
graphicsPipeline->graphicsPipeline->bindingDescriptions[i].stride = info.shaderInputLayout.bufferAttributes[i].size;
|
||||||
bindingDescriptions[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
|
graphicsPipeline->graphicsPipeline->bindingDescriptions[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
|
||||||
vertexAttributeCount += info.shaderInputLayout.bufferAttributes[i].attributeCount;
|
vertexAttributeCount += info.shaderInputLayout.bufferAttributes[i].attributeCount;
|
||||||
}
|
}
|
||||||
attributeDescriptions = malloc(sizeof(VkVertexInputBindingDescription) * vertexAttributeCount);
|
graphicsPipeline->graphicsPipeline->attributeDescriptions = malloc(sizeof(VkVertexInputAttributeDescription) * vertexAttributeCount);
|
||||||
for (int i = 0, j = 0; j < info.shaderInputLayout.bufferCount; j++) {
|
for (int i = 0, j = 0; j < info.shaderInputLayout.bufferCount; j++) {
|
||||||
for (int k = 0; k < info.shaderInputLayout.bufferAttributes[j].attributeCount; k++) {
|
for (int k = 0; k < info.shaderInputLayout.bufferAttributes[j].attributeCount; k++) {
|
||||||
attributeDescriptions[i].binding = j;
|
graphicsPipeline->graphicsPipeline->attributeDescriptions[i].binding = j;
|
||||||
attributeDescriptions[i].location = info.shaderInputLayout.bufferAttributes[j].attributes[k].location;
|
graphicsPipeline->graphicsPipeline->attributeDescriptions[i].location = info.shaderInputLayout.bufferAttributes[j].attributes[k].location;
|
||||||
attributeDescriptions[i].offset = info.shaderInputLayout.bufferAttributes[j].attributes[k].offset;
|
graphicsPipeline->graphicsPipeline->attributeDescriptions[i].offset = info.shaderInputLayout.bufferAttributes[j].attributes[k].offset;
|
||||||
attributeDescriptions[i].format = vkGryphnVertexFormat(info.shaderInputLayout.bufferAttributes[j].attributes[k].format);
|
graphicsPipeline->graphicsPipeline->attributeDescriptions[i].format = vkGryphnVertexFormat(info.shaderInputLayout.bufferAttributes[j].attributes[k].format);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,9 +102,9 @@ gnReturnCode gnCreateGraphicsPipelineFn(gnGraphicsPipeline graphicsPipeline, gnD
|
|||||||
graphicsPipeline->graphicsPipeline->vertexInfo = (VkPipelineVertexInputStateCreateInfo){
|
graphicsPipeline->graphicsPipeline->vertexInfo = (VkPipelineVertexInputStateCreateInfo){
|
||||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
|
||||||
.vertexBindingDescriptionCount = info.shaderInputLayout.bufferCount,
|
.vertexBindingDescriptionCount = info.shaderInputLayout.bufferCount,
|
||||||
.pVertexBindingDescriptions = bindingDescriptions,
|
.pVertexBindingDescriptions = graphicsPipeline->graphicsPipeline->bindingDescriptions,
|
||||||
.vertexAttributeDescriptionCount = vertexAttributeCount,
|
.vertexAttributeDescriptionCount = vertexAttributeCount,
|
||||||
.pVertexAttributeDescriptions = attributeDescriptions
|
.pVertexAttributeDescriptions = graphicsPipeline->graphicsPipeline->attributeDescriptions
|
||||||
};
|
};
|
||||||
|
|
||||||
graphicsPipeline->graphicsPipeline->inputAssembly = (VkPipelineInputAssemblyStateCreateInfo){
|
graphicsPipeline->graphicsPipeline->inputAssembly = (VkPipelineInputAssemblyStateCreateInfo){
|
||||||
@@ -191,19 +192,18 @@ gnReturnCode gnCreateGraphicsPipelineFn(gnGraphicsPipeline graphicsPipeline, gnD
|
|||||||
pipelineLayoutInfo.pPushConstantRanges = NULL
|
pipelineLayoutInfo.pPushConstantRanges = NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
if (vkCreatePipelineLayout(device->outputDevice->device, &pipelineLayoutInfo, NULL, &graphicsPipeline->graphicsPipeline->pipelineLayout) != VK_SUCCESS) {
|
if (vkCreatePipelineLayout(device->outputDevice->device, &pipelineLayoutInfo, NULL, &graphicsPipeline->graphicsPipeline->pipelineLayout) != VK_SUCCESS)
|
||||||
return GN_FAILED_TO_CREATE_UNIFORM_LAYOUT;
|
return GN_FAILED_TO_CREATE_UNIFORM_LAYOUT;
|
||||||
}
|
|
||||||
|
|
||||||
VkPipelineShaderStageCreateInfo* modules = malloc(sizeof(VkPipelineShaderStageCreateInfo) * info.shaderModuleCount);
|
graphicsPipeline->graphicsPipeline->modules = malloc(sizeof(VkPipelineShaderStageCreateInfo) * info.shaderModuleCount);
|
||||||
for (int i = 0; i < info.shaderModuleCount; i++) {
|
for (int i = 0; i < info.shaderModuleCount; i++) {
|
||||||
modules[i] = info.shaderModules[i]->shaderModule->shaderStageInfo;
|
graphicsPipeline->graphicsPipeline->modules[i] = info.shaderModules[i]->shaderModule->shaderStageInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkGraphicsPipelineCreateInfo pipelineInfo = {
|
VkGraphicsPipelineCreateInfo pipelineInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
||||||
.stageCount = info.shaderModuleCount,
|
.stageCount = info.shaderModuleCount,
|
||||||
.pStages = modules,
|
.pStages = graphicsPipeline->graphicsPipeline->modules,
|
||||||
.pVertexInputState = &graphicsPipeline->graphicsPipeline->vertexInfo,
|
.pVertexInputState = &graphicsPipeline->graphicsPipeline->vertexInfo,
|
||||||
.pInputAssemblyState = &graphicsPipeline->graphicsPipeline->inputAssembly,
|
.pInputAssemblyState = &graphicsPipeline->graphicsPipeline->inputAssembly,
|
||||||
.pViewportState = &graphicsPipeline->graphicsPipeline->viewportState,
|
.pViewportState = &graphicsPipeline->graphicsPipeline->viewportState,
|
||||||
@@ -219,21 +219,21 @@ gnReturnCode gnCreateGraphicsPipelineFn(gnGraphicsPipeline graphicsPipeline, gnD
|
|||||||
.basePipelineIndex = -1,
|
.basePipelineIndex = -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (vkCreateGraphicsPipelines(device->outputDevice->device, VK_NULL_HANDLE, 1, &pipelineInfo, NULL, &graphicsPipeline->graphicsPipeline->graphicsPipeline) != VK_SUCCESS) {
|
if (vkCreateGraphicsPipelines(device->outputDevice->device, VK_NULL_HANDLE, 1, &pipelineInfo, NULL, &graphicsPipeline->graphicsPipeline->graphicsPipeline) != VK_SUCCESS)
|
||||||
return GN_FAILED_TO_CREATE_GRAPHICS_PIPELINE;
|
return GN_FAILED_TO_CREATE_GRAPHICS_PIPELINE;
|
||||||
}
|
|
||||||
|
|
||||||
free(dynamicStates);
|
|
||||||
free(bindingDescriptions);
|
|
||||||
free(attributeDescriptions);
|
|
||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gnDestroyGraphicsPipelineFn(struct gnGraphicsPipeline_t *graphicsPipeline) {
|
void gnDestroyGraphicsPipelineFn(struct gnGraphicsPipeline_t *graphicsPipeline) {
|
||||||
|
free(graphicsPipeline->graphicsPipeline->dynamicStates);
|
||||||
|
free(graphicsPipeline->graphicsPipeline->bindingDescriptions);
|
||||||
|
free(graphicsPipeline->graphicsPipeline->attributeDescriptions);
|
||||||
for (int i = 0; i < graphicsPipeline->graphicsPipeline->setCount; i++)
|
for (int i = 0; i < graphicsPipeline->graphicsPipeline->setCount; i++)
|
||||||
vkDestroyDescriptorSetLayout(graphicsPipeline->device->outputDevice->device, graphicsPipeline->graphicsPipeline->sets[i], NULL);
|
vkDestroyDescriptorSetLayout(graphicsPipeline->device->outputDevice->device, graphicsPipeline->graphicsPipeline->sets[i], NULL);
|
||||||
vkDestroyPipelineLayout(graphicsPipeline->device->outputDevice->device, graphicsPipeline->graphicsPipeline->pipelineLayout, NULL);
|
free(graphicsPipeline->graphicsPipeline->modules);
|
||||||
vkDestroyPipeline(graphicsPipeline->device->outputDevice->device, graphicsPipeline->graphicsPipeline->graphicsPipeline, NULL);
|
|
||||||
|
|
||||||
|
vkDestroyPipeline(graphicsPipeline->device->outputDevice->device, graphicsPipeline->graphicsPipeline->graphicsPipeline, NULL);
|
||||||
|
vkDestroyPipelineLayout(graphicsPipeline->device->outputDevice->device, graphicsPipeline->graphicsPipeline->pipelineLayout, NULL);
|
||||||
free(graphicsPipeline->graphicsPipeline);
|
free(graphicsPipeline->graphicsPipeline);
|
||||||
}
|
}
|
||||||
|
@@ -22,4 +22,12 @@ typedef struct gnPlatformGraphicsPipeline_t {
|
|||||||
|
|
||||||
|
|
||||||
VkPipeline graphicsPipeline;
|
VkPipeline graphicsPipeline;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// memory that needs to be freeed
|
||||||
|
VkDynamicState* dynamicStates;
|
||||||
|
VkVertexInputBindingDescription* bindingDescriptions;
|
||||||
|
VkVertexInputAttributeDescription* attributeDescriptions;
|
||||||
|
VkPipelineShaderStageCreateInfo* modules;
|
||||||
} gnPlatformGraphicsPipeline;
|
} gnPlatformGraphicsPipeline;
|
||||||
|
@@ -102,9 +102,8 @@ gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueueHandle presentationQ
|
|||||||
presentationQueue->images[i] = malloc(sizeof(struct gnTexture_t));
|
presentationQueue->images[i] = malloc(sizeof(struct gnTexture_t));
|
||||||
presentationQueue->images[i]->texture = malloc(sizeof(gnPlatformTexture));
|
presentationQueue->images[i]->texture = malloc(sizeof(gnPlatformTexture));
|
||||||
imageViewCreateInfo.image = presentationQueue->presentationQueue->swapChainImages[i];
|
imageViewCreateInfo.image = presentationQueue->presentationQueue->swapChainImages[i];
|
||||||
if (vkCreateImageView(device->outputDevice->device, &imageViewCreateInfo, NULL, &presentationQueue->presentationQueue->swapChainImageViews[i]) != VK_SUCCESS) {
|
if (vkCreateImageView(device->outputDevice->device, &imageViewCreateInfo, NULL, &presentationQueue->presentationQueue->swapChainImageViews[i]) != VK_SUCCESS)
|
||||||
return GN_FAILED_TO_CREATE_IMAGE_VIEW;
|
return GN_FAILED_TO_CREATE_IMAGE_VIEW;
|
||||||
}
|
|
||||||
|
|
||||||
presentationQueue->images[i]->texture->image = presentationQueue->presentationQueue->swapChainImages[i];
|
presentationQueue->images[i]->texture->image = presentationQueue->presentationQueue->swapChainImages[i];
|
||||||
presentationQueue->images[i]->texture->imageView = presentationQueue->presentationQueue->swapChainImageViews[i];
|
presentationQueue->images[i]->texture->imageView = presentationQueue->presentationQueue->swapChainImageViews[i];
|
||||||
@@ -129,4 +128,7 @@ void gnDestroyPresentationQueueFn(gnPresentationQueueHandle queue) {
|
|||||||
for (int i = 0; i < queue->imageCount; i++)
|
for (int i = 0; i < queue->imageCount; i++)
|
||||||
vkDestroyImageView(queue->outputDevice->outputDevice->device, queue->presentationQueue->swapChainImageViews[i], NULL);
|
vkDestroyImageView(queue->outputDevice->outputDevice->device, queue->presentationQueue->swapChainImageViews[i], NULL);
|
||||||
vkDestroySwapchainKHR(queue->outputDevice->outputDevice->device, queue->presentationQueue->swapChain, NULL);
|
vkDestroySwapchainKHR(queue->outputDevice->outputDevice->device, queue->presentationQueue->swapChain, NULL);
|
||||||
|
free(queue->presentationQueue->swapChainImageViews);
|
||||||
|
free(queue->presentationQueue->swapChainImages);
|
||||||
|
free(queue->presentationQueue);
|
||||||
}
|
}
|
||||||
|
@@ -30,24 +30,26 @@ VkImageLayout vkGryphnImageLayout(gnImageLayout layout) {
|
|||||||
gnReturnCode gnCreateRenderPassDescriptorFn(struct gnRenderPassDescriptor_t* renderPass, struct gnOutputDevice_t* device, struct gnRenderPassDescriptorInfo_t info) {
|
gnReturnCode gnCreateRenderPassDescriptorFn(struct gnRenderPassDescriptor_t* renderPass, struct gnOutputDevice_t* device, struct gnRenderPassDescriptorInfo_t info) {
|
||||||
renderPass->renderPassDescriptor = malloc(sizeof(gnPlatformRenderPassDescriptor));
|
renderPass->renderPassDescriptor = malloc(sizeof(gnPlatformRenderPassDescriptor));
|
||||||
|
|
||||||
VkAttachmentDescription* attachments = malloc(sizeof(VkAttachmentDescription) * info.attachmentCount);
|
renderPass->renderPassDescriptor->attachmentCount = info.attachmentCount;
|
||||||
|
renderPass->renderPassDescriptor->attachments = malloc(sizeof(VkAttachmentDescription) * info.attachmentCount);
|
||||||
for (int i = 0; i < info.attachmentCount; i++) {
|
for (int i = 0; i < info.attachmentCount; i++) {
|
||||||
attachments[i].format = vkGryphnFormatToVulkanFormat(info.attachmentInfos[i].format);
|
renderPass->renderPassDescriptor->attachments[i].format = vkGryphnFormatToVulkanFormat(info.attachmentInfos[i].format);
|
||||||
attachments[i].flags = 0;
|
renderPass->renderPassDescriptor->attachments[i].flags = 0;
|
||||||
attachments[i].samples = VK_SAMPLE_COUNT_1_BIT;
|
renderPass->renderPassDescriptor->attachments[i].samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
|
||||||
attachments[i].loadOp = vkGryphnLoadOperation(info.attachmentInfos[i].loadOperation);
|
renderPass->renderPassDescriptor->attachments[i].loadOp = vkGryphnLoadOperation(info.attachmentInfos[i].loadOperation);
|
||||||
attachments[i].storeOp = vkGryphnStoreOperation(info.attachmentInfos[i].storeOperation);
|
renderPass->renderPassDescriptor->attachments[i].storeOp = vkGryphnStoreOperation(info.attachmentInfos[i].storeOperation);
|
||||||
|
|
||||||
attachments[i].stencilLoadOp = vkGryphnLoadOperation(info.attachmentInfos[i].stencilLoadOperation);
|
renderPass->renderPassDescriptor->attachments[i].stencilLoadOp = vkGryphnLoadOperation(info.attachmentInfos[i].stencilLoadOperation);
|
||||||
attachments[i].stencilStoreOp = vkGryphnStoreOperation(info.attachmentInfos[i].stencilStoreOperation);
|
renderPass->renderPassDescriptor->attachments[i].stencilStoreOp = vkGryphnStoreOperation(info.attachmentInfos[i].stencilStoreOperation);
|
||||||
|
|
||||||
attachments[i].initialLayout = vkGryphnImageLayout(info.attachmentInfos[i].initialLayout);
|
renderPass->renderPassDescriptor->attachments[i].initialLayout = vkGryphnImageLayout(info.attachmentInfos[i].initialLayout);
|
||||||
attachments[i].finalLayout = vkGryphnImageLayout(info.attachmentInfos[i].finalLayout);
|
renderPass->renderPassDescriptor->attachments[i].finalLayout = vkGryphnImageLayout(info.attachmentInfos[i].finalLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
VkSubpassDescription* subpasses = malloc(sizeof(VkSubpassDescription) * info.subpassCount);
|
renderPass->renderPassDescriptor->subpassCount = info.subpassCount;
|
||||||
VkAttachmentReference** colorAttachments = malloc(sizeof(VkAttachmentReference*) * info.subpassCount);
|
renderPass->renderPassDescriptor->subpasses = malloc(sizeof(VkSubpassDescription) * info.subpassCount);
|
||||||
|
renderPass->renderPassDescriptor->colorAttachments = malloc(sizeof(VkAttachmentReference*) * info.subpassCount);
|
||||||
|
|
||||||
VkAttachmentReference ref = {
|
VkAttachmentReference ref = {
|
||||||
.attachment = 0,
|
.attachment = 0,
|
||||||
@@ -55,27 +57,27 @@ gnReturnCode gnCreateRenderPassDescriptorFn(struct gnRenderPassDescriptor_t* ren
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (int i = 0; i < info.subpassCount; i++) {
|
for (int i = 0; i < info.subpassCount; i++) {
|
||||||
colorAttachments[i] = malloc(sizeof(VkAttachmentReference) * info.subpassInfos[i].colorAttachmentCount);
|
renderPass->renderPassDescriptor->colorAttachments[i] = malloc(sizeof(VkAttachmentReference) * info.subpassInfos[i].colorAttachmentCount);
|
||||||
|
|
||||||
for (int c = 0; c < info.subpassInfos[i].colorAttachmentCount; c++) {
|
for (int c = 0; c < info.subpassInfos[i].colorAttachmentCount; c++) {
|
||||||
colorAttachments[i][c] = (VkAttachmentReference){
|
renderPass->renderPassDescriptor->colorAttachments[i][c] = (VkAttachmentReference){
|
||||||
.attachment = info.subpassInfos[i].colorAttachments[c].index,
|
.attachment = info.subpassInfos[i].colorAttachments[c].index,
|
||||||
.layout = vkGryphnImageLayout(info.subpassInfos[i].colorAttachments[c].imageLayout)
|
.layout = vkGryphnImageLayout(info.subpassInfos[i].colorAttachments[c].imageLayout)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
subpasses[i] = (VkSubpassDescription){
|
renderPass->renderPassDescriptor->subpasses[i] = (VkSubpassDescription){
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
|
.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||||
.colorAttachmentCount = info.subpassInfos[i].colorAttachmentCount,
|
.colorAttachmentCount = info.subpassInfos[i].colorAttachmentCount,
|
||||||
.pColorAttachments = colorAttachments[i]
|
.pColorAttachments = renderPass->renderPassDescriptor->colorAttachments[i]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
VkSubpassDependency* dependencies = malloc(sizeof(VkSubpassDependency) * info.dependencyCount);
|
renderPass->renderPassDescriptor->dependencies = malloc(sizeof(VkSubpassDependency) * info.dependencyCount);
|
||||||
for (int i = 0; i < info.dependencyCount; i++) {
|
for (int i = 0; i < info.dependencyCount; i++) {
|
||||||
dependencies[i] = (VkSubpassDependency) {
|
renderPass->renderPassDescriptor->dependencies[i] = (VkSubpassDependency) {
|
||||||
.srcSubpass = (info.dependencies[i].source == GN_SUBPASS_EXTERNAL) ? VK_SUBPASS_EXTERNAL : info.dependencies[i].source,
|
.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,
|
.dstSubpass = (info.dependencies[i].destination == GN_SUBPASS_EXTERNAL) ? VK_SUBPASS_EXTERNAL : info.dependencies[i].destination,
|
||||||
.srcStageMask = info.dependencies[i].soruceStageMask,
|
.srcStageMask = info.dependencies[i].soruceStageMask,
|
||||||
@@ -90,24 +92,25 @@ gnReturnCode gnCreateRenderPassDescriptorFn(struct gnRenderPassDescriptor_t* ren
|
|||||||
.pNext = NULL,
|
.pNext = NULL,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
.attachmentCount = info.attachmentCount,
|
.attachmentCount = info.attachmentCount,
|
||||||
.pAttachments = attachments,
|
.pAttachments = renderPass->renderPassDescriptor->attachments,
|
||||||
.subpassCount = info.subpassCount,
|
.subpassCount = info.subpassCount,
|
||||||
.pSubpasses = subpasses,
|
.pSubpasses = renderPass->renderPassDescriptor->subpasses,
|
||||||
.dependencyCount = info.dependencyCount,
|
.dependencyCount = info.dependencyCount,
|
||||||
.pDependencies = dependencies,
|
.pDependencies = renderPass->renderPassDescriptor->dependencies,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (vkCreateRenderPass(device->outputDevice->device, &renderPassInfo, NULL, &renderPass->renderPassDescriptor->renderPass) != VK_SUCCESS)
|
if (vkCreateRenderPass(device->outputDevice->device, &renderPassInfo, NULL, &renderPass->renderPassDescriptor->renderPass) != VK_SUCCESS)
|
||||||
return GN_FAILED_TO_CREATE_RENDER_PASS;
|
return GN_FAILED_TO_CREATE_RENDER_PASS;
|
||||||
|
|
||||||
free(attachments);
|
|
||||||
free(subpasses);
|
|
||||||
free(dependencies);
|
|
||||||
|
|
||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void gnDestroyRenderPassDescriptorFn(struct gnRenderPassDescriptor_t* renderPass) {
|
void gnDestroyRenderPassDescriptorFn(gnRenderPassDescriptor renderPass) {
|
||||||
vkDestroyRenderPass(renderPass->device->outputDevice->device, renderPass->renderPassDescriptor->renderPass, NULL);
|
vkDestroyRenderPass(renderPass->device->outputDevice->device, renderPass->renderPassDescriptor->renderPass, NULL);
|
||||||
|
|
||||||
|
|
||||||
|
free(renderPass->renderPassDescriptor->attachments);
|
||||||
|
free(renderPass->renderPassDescriptor->subpasses);
|
||||||
|
free(renderPass->renderPassDescriptor->dependencies);
|
||||||
}
|
}
|
||||||
|
@@ -4,4 +4,13 @@
|
|||||||
|
|
||||||
typedef struct gnPlatformRenderPassDescriptor_t {
|
typedef struct gnPlatformRenderPassDescriptor_t {
|
||||||
VkRenderPass renderPass;
|
VkRenderPass renderPass;
|
||||||
|
|
||||||
|
uint32_t attachmentCount;
|
||||||
|
VkAttachmentDescription* attachments;
|
||||||
|
|
||||||
|
uint32_t subpassCount;
|
||||||
|
VkSubpassDescription* subpasses;
|
||||||
|
VkSubpassDependency* dependencies;
|
||||||
|
|
||||||
|
VkAttachmentReference** colorAttachments;
|
||||||
} gnPlatformRenderPassDescriptor;
|
} gnPlatformRenderPassDescriptor;
|
||||||
|
@@ -1,13 +1,11 @@
|
|||||||
#include "gryphn_command_buffer.h"
|
#include "gryphn_command_buffer.h"
|
||||||
#include "core/gryphn_platform_functions.h"
|
#include "core/gryphn_platform_functions.h"
|
||||||
#include "stdio.h"
|
|
||||||
|
|
||||||
gnReturnCode gnCommandPoolAllocateCommandBuffers(gnCommandBufferHandle* buffers, uint32_t count, gnCommandPoolHandle commandPool) {
|
gnReturnCode gnCommandPoolAllocateCommandBuffers(gnCommandBufferHandle* buffers, uint32_t count, gnCommandPoolHandle commandPool) {
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
buffers[i] = malloc(sizeof(struct gnCommandBuffer_t));
|
buffers[i] = malloc(sizeof(struct gnCommandBuffer_t));
|
||||||
buffers[i]->commandPool = commandPool;
|
buffers[i]->commandPool = commandPool;
|
||||||
}
|
}
|
||||||
printf("Created the graphics pipeline: %p\n", commandPool->commandFunctions->_gnCommandBindGraphicsPipeline);
|
|
||||||
return commandPool->commandFunctions->_gnCommandPoolAllocateCommandBuffers(buffers, count, commandPool);
|
return commandPool->commandFunctions->_gnCommandPoolAllocateCommandBuffers(buffers, count, commandPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7,5 +7,5 @@ gnReturnCode gnCreateDebugger(gnDebuggerHandle* debugger, const struct gnDebugge
|
|||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
void gnDestroyDebugger(gnDebuggerHandle debugger) {
|
void gnDestroyDebugger(gnDebuggerHandle debugger) {
|
||||||
free(debugger);
|
// free(debugger);
|
||||||
}
|
}
|
||||||
|
@@ -6,9 +6,9 @@
|
|||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
|
|
||||||
gnReturnCode gnCreateInstance(gnInstanceHandle* instanceHandlePtr, struct gnInstanceInfo_t info) {
|
gnReturnCode gnCreateInstance(gnInstanceHandle* instanceHandlePtr, struct gnInstanceInfo_t info) {
|
||||||
|
|
||||||
*instanceHandlePtr = malloc(sizeof(struct gnInstance_t));
|
*instanceHandlePtr = malloc(sizeof(struct gnInstance_t));
|
||||||
gnInstanceHandle instance = *instanceHandlePtr;
|
gnInstanceHandle instance = *instanceHandlePtr;
|
||||||
|
instance->debugger = NULL;
|
||||||
|
|
||||||
if (!gnIsAPISupported(info.renderingAPI)) return GN_UNSUPPORTED_RENDERING_API;
|
if (!gnIsAPISupported(info.renderingAPI)) return GN_UNSUPPORTED_RENDERING_API;
|
||||||
instance->loadDeviceFunctions = gnFalse;
|
instance->loadDeviceFunctions = gnFalse;
|
||||||
@@ -22,8 +22,6 @@ gnReturnCode gnCreateInstance(gnInstanceHandle* instanceHandlePtr, struct gnInst
|
|||||||
return instance->functions->_gnCreateInstance(instance, info);
|
return instance->functions->_gnCreateInstance(instance, info);
|
||||||
}
|
}
|
||||||
void gnInstanceAttachDebugger(gnInstanceHandle instance, struct gnDebugger_t *debugger) {
|
void gnInstanceAttachDebugger(gnInstanceHandle instance, struct gnDebugger_t *debugger) {
|
||||||
|
|
||||||
|
|
||||||
if (instance->debugger != NULL) {
|
if (instance->debugger != NULL) {
|
||||||
gnDebuggerSetErrorMessage(debugger, (gnMessageData){
|
gnDebuggerSetErrorMessage(debugger, (gnMessageData){
|
||||||
.message = gnCreateString("Debugger already attached to instance")
|
.message = gnCreateString("Debugger already attached to instance")
|
||||||
@@ -39,15 +37,11 @@ void gnInstanceAttachDebugger(gnInstanceHandle instance, struct gnDebugger_t *de
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "stdio.h"
|
|
||||||
void gnDestroyInstance(gnInstanceHandle instance) {
|
void gnDestroyInstance(gnInstanceHandle instance) {
|
||||||
if (instance->debugger) {
|
if (instance->debugger) instance->functions->_gnDestroyDebugger(instance->debugger);
|
||||||
instance->functions->_gnDestroyDebugger(instance->debugger);
|
|
||||||
}
|
|
||||||
instance->functions->_gnDestroyInstance(instance);
|
instance->functions->_gnDestroyInstance(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gnInstanceReleaseDebugger(gnInstanceHandle instance) {
|
void gnInstanceReleaseDebugger(gnInstanceHandle instance) {
|
||||||
instance->debugger = NULL;
|
instance->debugger = NULL;
|
||||||
free(instance);
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user