Skip to content

Commit 2b8f77b

Browse files
committed
it's a triangle
1 parent 1c3eab6 commit 2b8f77b

File tree

2 files changed

+42
-41
lines changed

2 files changed

+42
-41
lines changed

src/main.zig

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const enableValidationLayers = std.debug.runtime_safety;
1313
const validationLayers = [][*]const u8{c"VK_LAYER_LUNARG_standard_validation"};
1414
const deviceExtensions = [][*]const u8{c.VK_KHR_SWAPCHAIN_EXTENSION_NAME};
1515

16-
var inflightFences: std.ArrayList(c.VkFence) = undefined;
1716
var currentFrame: usize = 0;
1817
var instance: c.VkInstance = undefined;
1918
var callback: c.VkDebugReportCallbackEXT = undefined;
@@ -91,7 +90,7 @@ pub fn main() !void {
9190

9291
while (c.glfwWindowShouldClose(window) == 0) {
9392
c.glfwPollEvents();
94-
drawFrame();
93+
try drawFrame();
9594
}
9695
try checkSuccess(c.vkDeviceWaitIdle(global_device));
9796

@@ -968,50 +967,52 @@ fn checkValidationLayerSupport(allocator: *Allocator) !bool {
968967
return true;
969968
}
970969

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])));
975973

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));
978976

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};
981979

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]};
988981

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,
991991

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]));
995996

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,
9991000

1000-
//VkPresentInfoKHR presentInfo = {};
1001-
//presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
1001+
.waitSemaphoreCount = 1,
1002+
.pWaitSemaphores = &signalSemaphores,
10021003

1003-
//presentInfo.waitSemaphoreCount = 1;
1004-
//presentInfo.pWaitSemaphores = signalSemaphores;
1004+
.swapchainCount = 1,
1005+
.pSwapchains = &swapChains,
10051006

1006-
//VkSwapchainKHR swapChains[] = {swapChain};
1007-
//presentInfo.swapchainCount = 1;
1008-
//presentInfo.pSwapchains = swapChains;
1007+
.pImageIndices = (*[1]u32)(&imageIndex),
10091008

1010-
//presentInfo.pImageIndices = &imageIndex;
1009+
.pNext = null,
1010+
.pResults = null,
1011+
};
10111012

1012-
//c.vkQueuePresentKHR(presentQueue, &presentInfo);
1013+
try checkSuccess(c.vkQueuePresentKHR(presentQueue, &presentInfo));
10131014

1014-
//currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
1015+
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
10151016
}
10161017

10171018
fn hash_cstr(a: [*]const u8) u32 {

src/vulkan.zig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3955,7 +3955,7 @@ pub extern fn vkEnumerateDeviceExtensionProperties(
39553955
pub extern fn vkEnumerateInstanceLayerProperties(pPropertyCount: *u32, pProperties: ?[*]VkLayerProperties) VkResult;
39563956
pub extern fn vkEnumerateDeviceLayerProperties(physicalDevice: VkPhysicalDevice, pPropertyCount: ?[*]u32, pProperties: ?[*]VkLayerProperties) VkResult;
39573957
pub extern fn vkGetDeviceQueue(device: VkDevice, queueFamilyIndex: u32, queueIndex: u32, pQueue: *VkQueue) void;
3958-
pub extern fn vkQueueSubmit(queue: VkQueue, submitCount: u32, pSubmits: ?[*]const VkSubmitInfo, fence: VkFence) VkResult;
3958+
pub extern fn vkQueueSubmit(queue: VkQueue, submitCount: u32, pSubmits: [*]const VkSubmitInfo, fence: VkFence) VkResult;
39593959
pub extern fn vkQueueWaitIdle(queue: VkQueue) VkResult;
39603960
pub extern fn vkDeviceWaitIdle(device: VkDevice) VkResult;
39613961
pub extern fn vkAllocateMemory(device: VkDevice, pAllocateInfo: ?[*]const VkMemoryAllocateInfo, pAllocator: ?[*]const VkAllocationCallbacks, pMemory: ?[*]VkDeviceMemory) VkResult;
@@ -3974,9 +3974,9 @@ pub extern fn vkGetPhysicalDeviceSparseImageFormatProperties(physicalDevice: VkP
39743974
pub extern fn vkQueueBindSparse(queue: VkQueue, bindInfoCount: u32, pBindInfo: ?[*]const VkBindSparseInfo, fence: VkFence) VkResult;
39753975
pub extern fn vkCreateFence(device: VkDevice, pCreateInfo: *const VkFenceCreateInfo, pAllocator: ?[*]const VkAllocationCallbacks, pFence: *VkFence) VkResult;
39763976
pub extern fn vkDestroyFence(device: VkDevice, fence: VkFence, pAllocator: ?[*]const VkAllocationCallbacks) void;
3977-
pub extern fn vkResetFences(device: VkDevice, fenceCount: u32, pFences: ?[*]const VkFence) VkResult;
3977+
pub extern fn vkResetFences(device: VkDevice, fenceCount: u32, pFences: [*]const VkFence) VkResult;
39783978
pub extern fn vkGetFenceStatus(device: VkDevice, fence: VkFence) VkResult;
3979-
pub extern fn vkWaitForFences(device: VkDevice, fenceCount: u32, pFences: ?[*]const VkFence, waitAll: VkBool32, timeout: u64) VkResult;
3979+
pub extern fn vkWaitForFences(device: VkDevice, fenceCount: u32, pFences: [*]const VkFence, waitAll: VkBool32, timeout: u64) VkResult;
39803980
pub extern fn vkCreateSemaphore(device: VkDevice, pCreateInfo: *const VkSemaphoreCreateInfo, pAllocator: ?[*]const VkAllocationCallbacks, pSemaphore: *VkSemaphore) VkResult;
39813981
pub extern fn vkDestroySemaphore(device: VkDevice, semaphore: VkSemaphore, pAllocator: ?[*]const VkAllocationCallbacks) void;
39823982
pub extern fn vkCreateEvent(device: VkDevice, pCreateInfo: ?[*]const VkEventCreateInfo, pAllocator: ?[*]const VkAllocationCallbacks, pEvent: ?[*]VkEvent) VkResult;
@@ -5137,8 +5137,8 @@ pub const struct_VkPresentInfoKHR = extern struct {
51375137
waitSemaphoreCount: u32,
51385138
pWaitSemaphores: ?[*]const VkSemaphore,
51395139
swapchainCount: u32,
5140-
pSwapchains: ?[*]const VkSwapchainKHR,
5141-
pImageIndices: ?[*]const u32,
5140+
pSwapchains: [*]const VkSwapchainKHR,
5141+
pImageIndices: [*]const u32,
51425142
pResults: ?[*]VkResult,
51435143
};
51445144
pub const VkPresentInfoKHR = struct_VkPresentInfoKHR;
@@ -5198,8 +5198,8 @@ pub const PFN_vkAcquireNextImage2KHR = ?extern fn (VkDevice, ?[*]const VkAcquire
51985198
pub extern fn vkCreateSwapchainKHR(device: VkDevice, pCreateInfo: *const VkSwapchainCreateInfoKHR, pAllocator: ?[*]const VkAllocationCallbacks, pSwapchain: *VkSwapchainKHR) VkResult;
51995199
pub extern fn vkDestroySwapchainKHR(device: VkDevice, swapchain: VkSwapchainKHR, pAllocator: ?[*]const VkAllocationCallbacks) void;
52005200
pub extern fn vkGetSwapchainImagesKHR(device: VkDevice, swapchain: VkSwapchainKHR, pSwapchainImageCount: *u32, pSwapchainImages: ?[*]VkImage) VkResult;
5201-
pub extern fn vkAcquireNextImageKHR(device: VkDevice, swapchain: VkSwapchainKHR, timeout: u64, semaphore: VkSemaphore, fence: VkFence, pImageIndex: ?[*]u32) VkResult;
5202-
pub extern fn vkQueuePresentKHR(queue: VkQueue, pPresentInfo: ?[*]const VkPresentInfoKHR) VkResult;
5201+
pub extern fn vkAcquireNextImageKHR(device: VkDevice, swapchain: VkSwapchainKHR, timeout: u64, semaphore: VkSemaphore, fence: VkFence, pImageIndex: *u32) VkResult;
5202+
pub extern fn vkQueuePresentKHR(queue: VkQueue, pPresentInfo: *const VkPresentInfoKHR) VkResult;
52035203
pub extern fn vkGetDeviceGroupPresentCapabilitiesKHR(device: VkDevice, pDeviceGroupPresentCapabilities: ?[*]VkDeviceGroupPresentCapabilitiesKHR) VkResult;
52045204
pub extern fn vkGetDeviceGroupSurfacePresentModesKHR(device: VkDevice, surface: VkSurfaceKHR, pModes: ?[*]VkDeviceGroupPresentModeFlagsKHR) VkResult;
52055205
pub extern fn vkGetPhysicalDevicePresentRectanglesKHR(physicalDevice: VkPhysicalDevice, surface: VkSurfaceKHR, pRectCount: ?[*]u32, pRects: ?[*]VkRect2D) VkResult;

0 commit comments

Comments
 (0)