@@ -13,7 +13,6 @@ const enableValidationLayers = std.debug.runtime_safety;
13
13
const validationLayers = [][* ]const u8 {c"VK_LAYER_LUNARG_standard_validation" };
14
14
const deviceExtensions = [][* ]const u8 {c .VK_KHR_SWAPCHAIN_EXTENSION_NAME };
15
15
16
- var inflightFences : std .ArrayList (c .VkFence ) = undefined ;
17
16
var currentFrame : usize = 0 ;
18
17
var instance : c.VkInstance = undefined ;
19
18
var callback : c.VkDebugReportCallbackEXT = undefined ;
@@ -91,7 +90,7 @@ pub fn main() !void {
91
90
92
91
while (c .glfwWindowShouldClose (window ) == 0 ) {
93
92
c .glfwPollEvents ();
94
- drawFrame ();
93
+ try drawFrame ();
95
94
}
96
95
try checkSuccess (c .vkDeviceWaitIdle (global_device ));
97
96
@@ -968,50 +967,52 @@ fn checkValidationLayerSupport(allocator: *Allocator) !bool {
968
967
return true ;
969
968
}
970
969
971
- fn drawFrame () void {
972
- // TODO
973
- //c.vkWaitForFences(device, 1, &inFlightFences[currentFrame], c.VK_TRUE, @maxValue(u64));
974
- //c.vkResetFences(device, 1, &inFlightFences[currentFrame]);
970
+ fn drawFrame () ! void {
971
+ try checkSuccess (c .vkWaitForFences (global_device , 1 , (* [1 ]c .VkFence )(& inFlightFences [currentFrame ]), c .VK_TRUE , @maxValue (u64 )));
972
+ try checkSuccess (c .vkResetFences (global_device , 1 , (* [1 ]c .VkFence )(& inFlightFences [currentFrame ])));
975
973
976
- // var imageIndex: u32 = undefined;
977
- // c.vkAcquireNextImageKHR(device , swapChain, std::numeric_limits<uint64_t>::max( ), imageAvailableSemaphores[currentFrame], VK_NULL_HANDLE , &imageIndex);
974
+ var imageIndex : u32 = undefined ;
975
+ try checkSuccess ( c .vkAcquireNextImageKHR (global_device , swapChain , @maxValue ( u64 ), imageAvailableSemaphores [currentFrame ], null , & imageIndex ) );
978
976
979
- // var waitSemaphores = []c.VkSemaphore{imageAvailableSemaphores.at( currentFrame) };
980
- // var waitStages = []c.VkPipelineStageFlags{VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT};
977
+ var waitSemaphores = []c.VkSemaphore {imageAvailableSemaphores [ currentFrame ] };
978
+ var waitStages = []c.VkPipelineStageFlags {c . VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT };
981
979
982
- //var submitInfo = VkSubmitInfo{
983
- // .sType = c.VK_STRUCTURE_TYPE_SUBMIT_INFO,
984
- // .waitSemaphoreCount = 1,
985
- // .pWaitSemaphores = &waitSemaphores,
986
- // .pWaitDstStageMask = &waitStages,
987
- //};
980
+ const signalSemaphores = []c.VkSemaphore {renderFinishedSemaphores [currentFrame ]};
988
981
989
- //submitInfo.commandBufferCount = 1;
990
- //submitInfo.pCommandBuffers = &commandBuffers[imageIndex];
982
+ var submitInfo = []c.VkSubmitInfo {c.VkSubmitInfo {
983
+ .sType = c .VK_STRUCTURE_TYPE_SUBMIT_INFO ,
984
+ .waitSemaphoreCount = 1 ,
985
+ .pWaitSemaphores = & waitSemaphores ,
986
+ .pWaitDstStageMask = & waitStages ,
987
+ .commandBufferCount = 1 ,
988
+ .pCommandBuffers = commandBuffers .ptr + imageIndex ,
989
+ .signalSemaphoreCount = 1 ,
990
+ .pSignalSemaphores = & signalSemaphores ,
991
991
992
- //VkSemaphore signalSemaphores[] = {renderFinishedSemaphores[currentFrame]};
993
- //submitInfo.signalSemaphoreCount = 1;
994
- //submitInfo.pSignalSemaphores = signalSemaphores;
992
+ .pNext = null ,
993
+ }};
994
+
995
+ try checkSuccess (c .vkQueueSubmit (graphicsQueue , 1 , & submitInfo , inFlightFences [currentFrame ]));
995
996
996
- //if (c.vkQueueSubmit(graphicsQueue, 1, &submitInfo, inFlightFences[currentFrame]) != VK_SUCCESS) {
997
- // throw std::runtime_error("failed to submit draw command buffer!");
998
- //}
997
+ const swapChains = [] c.VkSwapchainKHR { swapChain };
998
+ const presentInfo = c.VkPresentInfoKHR {
999
+ . sType = c . VK_STRUCTURE_TYPE_PRESENT_INFO_KHR ,
999
1000
1000
- //VkPresentInfoKHR presentInfo = {};
1001
- //presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
1001
+ . waitSemaphoreCount = 1 ,
1002
+ . pWaitSemaphores = & signalSemaphores ,
1002
1003
1003
- //presentInfo.waitSemaphoreCount = 1;
1004
- //presentInfo.pWaitSemaphores = signalSemaphores;
1004
+ . swapchainCount = 1 ,
1005
+ . pSwapchains = & swapChains ,
1005
1006
1006
- //VkSwapchainKHR swapChains[] = {swapChain};
1007
- //presentInfo.swapchainCount = 1;
1008
- //presentInfo.pSwapchains = swapChains;
1007
+ .pImageIndices = (* [1 ]u32 )(& imageIndex ),
1009
1008
1010
- //presentInfo.pImageIndices = &imageIndex;
1009
+ .pNext = null ,
1010
+ .pResults = null ,
1011
+ };
1011
1012
1012
- // c.vkQueuePresentKHR(presentQueue, &presentInfo);
1013
+ try checkSuccess ( c .vkQueuePresentKHR (presentQueue , & presentInfo ) );
1013
1014
1014
- // currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
1015
+ currentFrame = (currentFrame + 1 ) % MAX_FRAMES_IN_FLIGHT ;
1015
1016
}
1016
1017
1017
1018
fn hash_cstr (a : [* ]const u8 ) u32 {
0 commit comments