@@ -11,8 +11,8 @@ const HEIGHT = 600;
11
11
const MAX_FRAMES_IN_FLIGHT = 2 ;
12
12
13
13
const enableValidationLayers = std .debug .runtime_safety ;
14
- const validationLayers = [][* ]const u8 {c"VK_LAYER_LUNARG_standard_validation" };
15
- const deviceExtensions = [][* ]const u8 {c .VK_KHR_SWAPCHAIN_EXTENSION_NAME };
14
+ const validationLayers = [_ ][* ]const u8 {c"VK_LAYER_LUNARG_standard_validation" };
15
+ const deviceExtensions = [_ ][* ]const u8 {c .VK_KHR_SWAPCHAIN_EXTENSION_NAME };
16
16
17
17
var currentFrame : usize = 0 ;
18
18
var instance : c.VkInstance = undefined ;
@@ -170,7 +170,7 @@ fn createCommandBuffers(allocator: *Allocator) !void {
170
170
171
171
try checkSuccess (c .vkBeginCommandBuffer (commandBuffers [i ], & beginInfo ));
172
172
173
- const clearColor = c.VkClearValue { .color = c.VkClearColorValue { .float32 = []f32 { 0.0 , 0.0 , 0.0 , 1.0 } } };
173
+ const clearColor = c.VkClearValue { .color = c.VkClearColorValue { .float32 = [_ ]f32 { 0.0 , 0.0 , 0.0 , 1.0 } } };
174
174
175
175
const renderPassInfo = c.VkRenderPassBeginInfo {
176
176
.sType = c .VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO ,
@@ -236,7 +236,7 @@ fn createFramebuffers(allocator: *Allocator) !void {
236
236
swapChainFramebuffers = try allocator .alloc (c .VkFramebuffer , swapChainImageViews .len );
237
237
238
238
for (swapChainImageViews ) | swap_chain_image_view , i | {
239
- const attachments = []c.VkImageView {swap_chain_image_view };
239
+ const attachments = [_ ]c.VkImageView {swap_chain_image_view };
240
240
241
241
const framebufferInfo = c.VkFramebufferCreateInfo {
242
242
.sType = c .VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO ,
@@ -303,7 +303,7 @@ fn createGraphicsPipeline(allocator: *Allocator) !void {
303
303
.pSpecializationInfo = null ,
304
304
};
305
305
306
- const shaderStages = []c.VkPipelineShaderStageCreateInfo { vertShaderStageInfo , fragShaderStageInfo };
306
+ const shaderStages = [_ ]c.VkPipelineShaderStageCreateInfo { vertShaderStageInfo , fragShaderStageInfo };
307
307
308
308
const vertexInputInfo = c.VkPipelineVertexInputStateCreateInfo {
309
309
.sType = c .VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO ,
@@ -324,7 +324,7 @@ fn createGraphicsPipeline(allocator: *Allocator) !void {
324
324
.flags = 0 ,
325
325
};
326
326
327
- const viewport = []c.VkViewport {c.VkViewport {
327
+ const viewport = [_ ]c.VkViewport {c.VkViewport {
328
328
.x = 0.0 ,
329
329
.y = 0.0 ,
330
330
.width = @intToFloat (f32 , swapChainExtent .width ),
@@ -333,7 +333,7 @@ fn createGraphicsPipeline(allocator: *Allocator) !void {
333
333
.maxDepth = 1.0 ,
334
334
}};
335
335
336
- const scissor = []c.VkRect2D {c.VkRect2D {
336
+ const scissor = [_ ]c.VkRect2D {c.VkRect2D {
337
337
.offset = c.VkOffset2D { .x = 0 , .y = 0 },
338
338
.extent = swapChainExtent ,
339
339
}};
@@ -396,7 +396,7 @@ fn createGraphicsPipeline(allocator: *Allocator) !void {
396
396
.logicOp = c .VK_LOGIC_OP_COPY ,
397
397
.attachmentCount = 1 ,
398
398
.pAttachments = & colorBlendAttachment ,
399
- .blendConstants = []f32 { 0 , 0 , 0 , 0 },
399
+ .blendConstants = [_ ]f32 { 0 , 0 , 0 , 0 },
400
400
401
401
.pNext = null ,
402
402
.flags = 0 ,
@@ -414,7 +414,7 @@ fn createGraphicsPipeline(allocator: *Allocator) !void {
414
414
415
415
try checkSuccess (c .vkCreatePipelineLayout (global_device , & pipelineLayoutInfo , null , & pipelineLayout ));
416
416
417
- const pipelineInfo = []c.VkGraphicsPipelineCreateInfo {c.VkGraphicsPipelineCreateInfo {
417
+ const pipelineInfo = [_ ]c.VkGraphicsPipelineCreateInfo {c.VkGraphicsPipelineCreateInfo {
418
418
.sType = c .VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO ,
419
419
.stageCount = @intCast (u32 , shaderStages .len ),
420
420
.pStages = & shaderStages ,
@@ -468,7 +468,7 @@ fn createRenderPass() !void {
468
468
.layout = c .VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL ,
469
469
};
470
470
471
- const subpass = []c.VkSubpassDescription {c.VkSubpassDescription {
471
+ const subpass = [_ ]c.VkSubpassDescription {c.VkSubpassDescription {
472
472
.pipelineBindPoint = c .VK_PIPELINE_BIND_POINT_GRAPHICS ,
473
473
.colorAttachmentCount = 1 ,
474
474
.pColorAttachments = (* const [1 ]c .VkAttachmentReference )(& colorAttachmentRef ),
@@ -482,7 +482,7 @@ fn createRenderPass() !void {
482
482
.pPreserveAttachments = null ,
483
483
}};
484
484
485
- const dependency = []c.VkSubpassDependency {c.VkSubpassDependency {
485
+ const dependency = [_ ]c.VkSubpassDependency {c.VkSubpassDependency {
486
486
.srcSubpass = c .VK_SUBPASS_EXTERNAL ,
487
487
.dstSubpass = 0 ,
488
488
.srcStageMask = c .VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT ,
@@ -591,8 +591,9 @@ fn chooseSwapExtent(capabilities: c.VkSurfaceCapabilitiesKHR) c.VkExtent2D {
591
591
}
592
592
593
593
fn createSwapChain (allocator : * Allocator ) ! void {
594
- const swapChainSupport = try querySwapChainSupport (allocator , physicalDevice );
595
-
594
+ var swapChainSupport = try querySwapChainSupport (allocator , physicalDevice );
595
+ defer swapChainSupport .deinit ();
596
+
596
597
const surfaceFormat = chooseSwapSurfaceFormat (swapChainSupport .formats .toSlice ());
597
598
const presentMode = chooseSwapPresentMode (swapChainSupport .presentModes .toSlice ());
598
599
const extent = chooseSwapExtent (swapChainSupport .capabilities );
@@ -605,7 +606,7 @@ fn createSwapChain(allocator: *Allocator) !void {
605
606
}
606
607
607
608
const indices = try findQueueFamilies (allocator , physicalDevice );
608
- const queueFamilyIndices = []u32 { indices .graphicsFamily .? , indices .presentFamily .? };
609
+ const queueFamilyIndices = [_ ]u32 { indices .graphicsFamily .? , indices .presentFamily .? };
609
610
610
611
const different_families = indices .graphicsFamily .? != indices .presentFamily .? ;
611
612
@@ -622,7 +623,7 @@ fn createSwapChain(allocator: *Allocator) !void {
622
623
623
624
.imageSharingMode = if (different_families ) c .VK_SHARING_MODE_CONCURRENT else c .VK_SHARING_MODE_EXCLUSIVE ,
624
625
.queueFamilyIndexCount = if (different_families ) u32 (2 ) else u32 (0 ),
625
- .pQueueFamilyIndices = if (different_families ) & queueFamilyIndices else &([]u32 { 0 , 0 }),
626
+ .pQueueFamilyIndices = if (different_families ) & queueFamilyIndices else &([_ ]u32 { 0 , 0 }),
626
627
627
628
.preTransform = swapChainSupport .capabilities .currentTransform ,
628
629
.compositeAlpha = c .VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR ,
@@ -650,7 +651,7 @@ fn createLogicalDevice(allocator: *Allocator) !void {
650
651
651
652
var queueCreateInfos = std .ArrayList (c .VkDeviceQueueCreateInfo ).init (allocator );
652
653
defer queueCreateInfos .deinit ();
653
- const all_queue_families = []u32 { indices .graphicsFamily .? , indices .presentFamily .? };
654
+ const all_queue_families = [_ ]u32 { indices .graphicsFamily .? , indices .presentFamily .? };
654
655
const uniqueQueueFamilies = if (indices .graphicsFamily .? == indices .presentFamily .? )
655
656
all_queue_families [0.. 1]
656
657
else
@@ -811,7 +812,8 @@ fn isDeviceSuitable(allocator: *Allocator, device: c.VkPhysicalDevice) !bool {
811
812
812
813
var swapChainAdequate = false ;
813
814
if (extensionsSupported ) {
814
- const swapChainSupport = try querySwapChainSupport (allocator , device );
815
+ var swapChainSupport = try querySwapChainSupport (allocator , device );
816
+ defer swapChainSupport .deinit ();
815
817
swapChainAdequate = swapChainSupport .formats .len != 0 and swapChainSupport .presentModes .len != 0 ;
816
818
}
817
819
@@ -820,7 +822,6 @@ fn isDeviceSuitable(allocator: *Allocator, device: c.VkPhysicalDevice) !bool {
820
822
821
823
fn querySwapChainSupport (allocator : * Allocator , device : c.VkPhysicalDevice ) ! SwapChainSupportDetails {
822
824
var details = SwapChainSupportDetails .init (allocator );
823
- defer details .deinit ();
824
825
825
826
try checkSuccess (c .vkGetPhysicalDeviceSurfaceCapabilitiesKHR (device , surface , & details .capabilities ));
826
827
@@ -1018,12 +1019,12 @@ fn drawFrame() !void {
1018
1019
var imageIndex : u32 = undefined ;
1019
1020
try checkSuccess (c .vkAcquireNextImageKHR (global_device , swapChain , maxInt (u64 ), imageAvailableSemaphores [currentFrame ], null , & imageIndex ));
1020
1021
1021
- var waitSemaphores = []c.VkSemaphore {imageAvailableSemaphores [currentFrame ]};
1022
- var waitStages = []c.VkPipelineStageFlags {c .VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT };
1022
+ var waitSemaphores = [_ ]c.VkSemaphore {imageAvailableSemaphores [currentFrame ]};
1023
+ var waitStages = [_ ]c.VkPipelineStageFlags {c .VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT };
1023
1024
1024
- const signalSemaphores = []c.VkSemaphore {renderFinishedSemaphores [currentFrame ]};
1025
+ const signalSemaphores = [_ ]c.VkSemaphore {renderFinishedSemaphores [currentFrame ]};
1025
1026
1026
- var submitInfo = []c.VkSubmitInfo {c.VkSubmitInfo {
1027
+ var submitInfo = [_ ]c.VkSubmitInfo {c.VkSubmitInfo {
1027
1028
.sType = c .VK_STRUCTURE_TYPE_SUBMIT_INFO ,
1028
1029
.waitSemaphoreCount = 1 ,
1029
1030
.pWaitSemaphores = & waitSemaphores ,
@@ -1038,7 +1039,7 @@ fn drawFrame() !void {
1038
1039
1039
1040
try checkSuccess (c .vkQueueSubmit (graphicsQueue , 1 , & submitInfo , inFlightFences [currentFrame ]));
1040
1041
1041
- const swapChains = []c.VkSwapchainKHR {swapChain };
1042
+ const swapChains = [_ ]c.VkSwapchainKHR {swapChain };
1042
1043
const presentInfo = c.VkPresentInfoKHR {
1043
1044
.sType = c .VK_STRUCTURE_TYPE_PRESENT_INFO_KHR ,
1044
1045
0 commit comments