comparison src/engine.nim @ 11:3415afff1d1a

Merge /mnt/Users/sam/git/vulkan
author Sam <sam@basx.dev>
date Sat, 24 Dec 2022 22:38:09 +0700
parents 227e53d1a853 0660ba9d1930
children b40466fa446a
comparison
equal deleted inserted replaced
9:227e53d1a853 11:3415afff1d1a
10 import ./events 10 import ./events
11 11
12 import ./glslang/glslang 12 import ./glslang/glslang
13 13
14 const MAX_FRAMES_IN_FLIGHT = 2 14 const MAX_FRAMES_IN_FLIGHT = 2
15 const DEBUG_LOG = not defined(release)
15 16
16 var logger = newConsoleLogger() 17 var logger = newConsoleLogger()
17 addHandler(logger) 18 addHandler(logger)
18 19
19 20
135 return VkExtent2D( 136 return VkExtent2D(
136 width: min(max(uint32(width), capabilities.minImageExtent.width), capabilities.maxImageExtent.width), 137 width: min(max(uint32(width), capabilities.minImageExtent.width), capabilities.maxImageExtent.width),
137 height: min(max(uint32(height), capabilities.minImageExtent.height), capabilities.maxImageExtent.height), 138 height: min(max(uint32(height), capabilities.minImageExtent.height), capabilities.maxImageExtent.height),
138 ) 139 )
139 140
140 when not defined(release): 141 when DEBUG_LOG:
141 proc setupDebugLog(instance: VkInstance): VkDebugUtilsMessengerEXT = 142 proc setupDebugLog(instance: VkInstance): VkDebugUtilsMessengerEXT =
142 var createInfo = VkDebugUtilsMessengerCreateInfoEXT( 143 var createInfo = VkDebugUtilsMessengerCreateInfoEXT(
143 sType: VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT, 144 sType: VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT,
144 messageSeverity: VkDebugUtilsMessageSeverityFlagsEXT( 145 messageSeverity: VkDebugUtilsMessageSeverityFlagsEXT(
145 ord(VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) or 146 ord(VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) or
420 result[0], 421 result[0],
421 vulkan.renderPass, 422 vulkan.renderPass,
422 vulkan.frameDimension 423 vulkan.frameDimension
423 ) 424 )
424 425
425 # createFramebuffers();
426
427 426
428 proc setupCommandBuffers(device: VkDevice, graphicsQueueFamily: uint32): (VkCommandPool, array[MAX_FRAMES_IN_FLIGHT, VkCommandBuffer]) = 427 proc setupCommandBuffers(device: VkDevice, graphicsQueueFamily: uint32): (VkCommandPool, array[MAX_FRAMES_IN_FLIGHT, VkCommandBuffer]) =
429 # set up command buffer 428 # set up command buffer
430 var poolInfo = VkCommandPoolCreateInfo( 429 var poolInfo = VkCommandPoolCreateInfo(
431 sType: VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, 430 sType: VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
463 462
464 # setup vulkan functions 463 # setup vulkan functions
465 vkLoad1_0() 464 vkLoad1_0()
466 vkLoad1_1() 465 vkLoad1_1()
467 vkLoad1_2() 466 vkLoad1_2()
467
468 checkGlslangResult glslang_initialize_process() 468 checkGlslangResult glslang_initialize_process()
469 469
470 # create vulkan instance 470 # create vulkan instance
471 result.vulkan.instance = createVulkanInstance(VULKAN_VERSION) 471 result.vulkan.instance = createVulkanInstance(VULKAN_VERSION)
472 when not defined(release): 472 when DEBUG_LOG:
473 result.vulkan.debugMessenger = result.vulkan.instance.setupDebugLog() 473 result.vulkan.debugMessenger = result.vulkan.instance.setupDebugLog()
474 result.vulkan.surface = result.vulkan.instance.createVulkanSurface(result.window) 474 result.vulkan.surface = result.vulkan.instance.createVulkanSurface(result.window)
475 result.vulkan.device = result.vulkan.instance.setupVulkanDeviceAndQueues(result.vulkan.surface) 475 result.vulkan.device = result.vulkan.instance.setupVulkanDeviceAndQueues(result.vulkan.surface)
476 476
477 # get basic frame information 477 # get basic frame information
636 for shaderStage in engine.vulkan.pipeline.shaderStages: 636 for shaderStage in engine.vulkan.pipeline.shaderStages:
637 engine.vulkan.device.device.vkDestroyShaderModule(shaderStage.module, nil) 637 engine.vulkan.device.device.vkDestroyShaderModule(shaderStage.module, nil)
638 638
639 engine.vulkan.instance.vkDestroySurfaceKHR(engine.vulkan.surface, nil) 639 engine.vulkan.instance.vkDestroySurfaceKHR(engine.vulkan.surface, nil)
640 engine.vulkan.device.device.vkDestroyDevice(nil) 640 engine.vulkan.device.device.vkDestroyDevice(nil)
641 when ENABLEVULKANVALIDATIONLAYERS: 641 when DEBUG_LOG:
642 engine.vulkan.instance.vkDestroyDebugUtilsMessengerEXT(engine.vulkan.debugMessenger, nil) 642 engine.vulkan.instance.vkDestroyDebugUtilsMessengerEXT(engine.vulkan.debugMessenger, nil)
643 glslang_finalize_process() 643 glslang_finalize_process()
644 engine.window.trash() 644 engine.window.trash()
645 engine.vulkan.instance.vkDestroyInstance(nil) 645 engine.vulkan.instance.vkDestroyInstance(nil)