summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Halase <jordan@halase.me>2019-11-01 14:09:50 -0500
committerJordan Halase <jordan@halase.me>2019-11-01 14:09:50 -0500
commita6662f92f19459f013ec2168d0b7ccbce349f458 (patch)
tree01b0da39951a35830254246e93d49831ec310400
parent3ece0bd80226a2550592dfeee3b9cc9d88e6109e (diff)
Create command pool and fix bug where rvkCreate does not set vk to anything
-rw-r--r--main.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/main.c b/main.c
index f126251..d117d17 100644
--- a/main.c
+++ b/main.c
@@ -91,6 +91,8 @@ struct VulkanDev {
PFN_vkDestroyDevice vkDestroyDevice;
PFN_vkDeviceWaitIdle vkDeviceWaitIdle;
PFN_vkGetDeviceQueue vkGetDeviceQueue;
+ PFN_vkCreateCommandPool vkCreateCommandPool;
+ PFN_vkDestroyCommandPool vkDestroyCommandPool;
};
/** Vulkan application that uses Pugl for windows and events */
@@ -107,6 +109,7 @@ struct RenderVulkan {
uint32_t graphicsIndex;
VkDevice device;
VkQueue graphicsQueue;
+ VkCommandPool commandPool;
};
#define RVK_ERRMSG_LEN 4096
@@ -412,6 +415,7 @@ int rvkCreate(PuglWorld *world, struct RenderVulkan **vkOut)
const uint32_t nInstanceExtensions = sizeof(instanceExtensions) / sizeof(instanceExtensions[0]);
struct RenderVulkan *vk = calloc(1, sizeof(*vk));
+ *vkOut = vk;
if (!world) {
rvkSetErrMsg(vk, "No PuglWorld provided");
return -1;
@@ -560,7 +564,6 @@ int rvkCreate(PuglWorld *world, struct RenderVulkan **vkOut)
}
}
- *vkOut = vk;
return 0;
}
@@ -763,10 +766,24 @@ static int rvkLoadDeviceFunctions(struct RenderVulkan *vk, VkDevice device)
return -1;
}
+ static const char *const _vkCreateCommandPool = "vkCreateCommandPool";
+ vk->dev->vkCreateCommandPool = (PFN_vkCreateCommandPool)vk->api->vkGetDeviceProcAddr(device, _vkCreateCommandPool);
+ if (!vk->dev->vkCreateCommandPool) {
+ rvkSetErrMsg(vk, strErrLd, _vkCreateCommandPool);
+ return -1;
+ }
+
+ static const char *const _vkDestroyCommandPool = "vkDestroyCommandPool";
+ vk->dev->vkDestroyCommandPool = (PFN_vkDestroyCommandPool)vk->api->vkGetDeviceProcAddr(device, _vkDestroyCommandPool);
+ if (!vk->dev->vkDestroyCommandPool) {
+ rvkSetErrMsg(vk, strErrLd, _vkDestroyCommandPool);
+ return -1;
+ }
+
return 0;
}
-/** Opens the logical device and retrieves the queue(s) for this application. */
+/** Opens the logical device, retrieves queue(s), and creates command pool for this application. */
int rvkOpenDevice(struct RenderVulkan *vk)
{
if (vk->device) {
@@ -806,11 +823,26 @@ int rvkOpenDevice(struct RenderVulkan *vk)
return -1;
}
vk->dev->vkGetDeviceQueue(vk->device, vk->graphicsIndex, 0, &vk->graphicsQueue);
+
+ VkCommandPoolCreateInfo commandInfo = { 0 };
+ commandInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
+ commandInfo.queueFamilyIndex = vk->graphicsIndex;
+ VkCommandPool commandPool;
+ if ((result = vk->dev->vkCreateCommandPool(vk->device, &commandInfo, ALLOC_VK, &commandPool))) {
+ rvkSetErrMsg(vk, "Could not create command pool: %d\n", result);
+ return -1;
+ }
+ vk->commandPool = commandPool;
return 0;
}
static void rvkCloseDevice(struct RenderVulkan *vk)
{
+ if (vk->commandPool) {
+ vk->dev->vkDestroyCommandPool(vk->device, vk->commandPool, ALLOC_VK);
+ vk->commandPool = VK_NULL_HANDLE;
+ }
+ vk->graphicsQueue = VK_NULL_HANDLE;
if (vk->dev->vkDestroyDevice) {
vk->dev->vkDestroyDevice(vk->device, ALLOC_VK);
} else {