Initial changes to get a triangle on linux
Signed-off-by: Robear Selwans <robear.selwans@outlook.com>
This commit is contained in:
54
main.c
54
main.c
@@ -19,7 +19,12 @@ int main(void)
|
||||
}),
|
||||
.extensions = svec_init(evstring, {
|
||||
evstr("VK_KHR_surface"),
|
||||
// TODO Get these from GLFW
|
||||
#if EV_OS_WINDOWS
|
||||
evstr("VK_KHR_win32_surface"),
|
||||
#elif EV_OS_LINUX
|
||||
evstr("VK_KHR_xcb_surface"),
|
||||
#endif
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -32,7 +37,9 @@ int main(void)
|
||||
|
||||
evkDevice device = evkCreateDevice((evkDeviceCreateInfo) {
|
||||
.instance = instance,
|
||||
.physicalDeviceType = VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU,
|
||||
// TODO Add a fallback physical device option.
|
||||
// .physicalDeviceType = VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU,
|
||||
.physicalDeviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU,
|
||||
.queueRequirements = svec_init(evkDeviceQueueRequirement, {
|
||||
{ VK_QUEUE_GRAPHICS_BIT, 1 },
|
||||
{ VK_QUEUE_COMPUTE_BIT , 1 },
|
||||
@@ -54,6 +61,7 @@ int main(void)
|
||||
puts("Couldn't create a VkDevice");
|
||||
goto DeviceCreationFailed;
|
||||
}
|
||||
|
||||
puts("Logical Device created successfully.");
|
||||
VkQueue graphicsQueue;
|
||||
vkGetDeviceQueue(device.vk, device.queueFamilies[VK_QUEUE_GRAPHICS_BIT].familyIndex, 0, &graphicsQueue);
|
||||
@@ -201,19 +209,30 @@ int main(void)
|
||||
|
||||
evkPipeline graphicsPipeline = evkCreatePipeline(device, pipelineCreateInfo);
|
||||
|
||||
VkFence drawFence = evkCreateFence(device, false);
|
||||
VkSemaphore imageAcquiredSemaphore = evkCreateSemaphore(device);
|
||||
VkSemaphore drawFinishedSemaphore = evkCreateSemaphore(device);
|
||||
u32 imageCount = vec_len(&swapChain.images);
|
||||
|
||||
VkFence drawFence = evkCreateFence(device, false);
|
||||
vec(VkSemaphore) imageAcquiredSemaphores = vec_init(VkSemaphore);
|
||||
vec(VkSemaphore) drawFinishedSemaphores = vec_init(VkSemaphore);
|
||||
for(u32 i = 0; i < imageCount; i++)
|
||||
{
|
||||
imageAcquiredSemaphores[i] = evkCreateSemaphore(device);
|
||||
drawFinishedSemaphores[i] = evkCreateSemaphore(device);
|
||||
}
|
||||
// VkSemaphore imageAcquiredSemaphore = evkCreateSemaphore(device);
|
||||
// VkSemaphore drawFinishedSemaphore = evkCreateSemaphore(device);
|
||||
|
||||
i32 imageIdx = -1;
|
||||
while(!glfwWindowShouldClose(window))
|
||||
{
|
||||
u32 imageIdx;
|
||||
vkAcquireNextImageKHR(device.vk, swapChain.vk, UInt64.MAX, imageAcquiredSemaphore, VK_NULL_HANDLE, &imageIdx);
|
||||
imageIdx = (imageIdx + 1) % imageCount;
|
||||
u32 swapChainImageIdx;
|
||||
EVK_ASSERT(vkAcquireNextImageKHR(device.vk, swapChain.vk, UInt64.MAX, imageAcquiredSemaphores[imageIdx], VK_NULL_HANDLE, &swapChainImageIdx));
|
||||
|
||||
evkCommandBuffer cmdbuf = commandBuffers[imageIdx];
|
||||
|
||||
VkRenderingAttachmentInfoKHR colorAttachment = EV_DEFAULT(VkRenderingAttachmentInfoKHR,
|
||||
imageView = swapChain.imageViews[imageIdx].vk,
|
||||
imageView = swapChain.imageViews[swapChainImageIdx].vk,
|
||||
loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
|
||||
storeOp= VK_ATTACHMENT_STORE_OP_STORE,
|
||||
);
|
||||
@@ -243,7 +262,7 @@ int main(void)
|
||||
|
||||
VkImageMemoryBarrier imageMemoryBarrier = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
||||
.image = swapChain.images[imageIdx].vk,
|
||||
.image = swapChain.images[swapChainImageIdx].vk,
|
||||
.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
|
||||
.subresourceRange = {
|
||||
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
@@ -260,13 +279,13 @@ int main(void)
|
||||
|
||||
VkSubmitInfo submitInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
|
||||
.pCommandBuffers = &cmdbuf, // TODO This won't work with more than a single cmdbuf
|
||||
.pCommandBuffers = &cmdbuf.vk, // TODO This won't work with more than a single cmdbuf
|
||||
.commandBufferCount = 1,
|
||||
.waitSemaphoreCount = 1,
|
||||
.pWaitSemaphores = &imageAcquiredSemaphore,
|
||||
.pWaitSemaphores = &imageAcquiredSemaphores[imageIdx],
|
||||
.pWaitDstStageMask = waitStages,
|
||||
.signalSemaphoreCount = 1,
|
||||
.pSignalSemaphores = &drawFinishedSemaphore,
|
||||
.pSignalSemaphores = &drawFinishedSemaphores[swapChainImageIdx],
|
||||
};
|
||||
|
||||
vkQueueSubmit(graphicsQueue, 1, &submitInfo, drawFence);
|
||||
@@ -276,10 +295,10 @@ int main(void)
|
||||
VkPresentInfoKHR presentInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
|
||||
.waitSemaphoreCount = 1,
|
||||
.pWaitSemaphores = &drawFinishedSemaphore,
|
||||
.pWaitSemaphores = &drawFinishedSemaphores[swapChainImageIdx],
|
||||
.swapchainCount = 1,
|
||||
.pSwapchains = &swapChain.vk,
|
||||
.pImageIndices = &imageIdx,
|
||||
.pImageIndices = &swapChainImageIdx,
|
||||
};
|
||||
vkQueuePresentKHR(graphicsQueue, &presentInfo);
|
||||
|
||||
@@ -292,8 +311,13 @@ int main(void)
|
||||
vkQueueWaitIdle(graphicsQueue);
|
||||
|
||||
vkDestroyFence(device.vk, drawFence, NULL);
|
||||
vkDestroySemaphore(device.vk, imageAcquiredSemaphore, NULL);
|
||||
vkDestroySemaphore(device.vk, drawFinishedSemaphore, NULL);
|
||||
for(u32 i = 0; i < imageCount; i++)
|
||||
{
|
||||
vkDestroySemaphore(device.vk, imageAcquiredSemaphores[i], NULL);
|
||||
vkDestroySemaphore(device.vk, drawFinishedSemaphores[i], NULL);
|
||||
}
|
||||
// vkDestroySemaphore(device.vk, imageAcquiredSemaphore, NULL);
|
||||
// vkDestroySemaphore(device.vk, drawFinishedSemaphore, NULL);
|
||||
|
||||
evkDestroyPipeline(graphicsPipeline);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user