# HG changeset patch # User sam # Date 1711699713 -25200 # Node ID e02d8e65d68e41dec382e37e76383687292f5a3e # Parent cdf7ad53965a8890608fbad65d9cb8854da50407 fix: a few small (vulkan) API optimizations diff -r cdf7ad53965a -r e02d8e65d68e semicongine/engine.nim --- a/semicongine/engine.nim Mon Mar 25 22:26:58 2024 +0700 +++ b/semicongine/engine.nim Fri Mar 29 15:08:33 2024 +0700 @@ -68,7 +68,9 @@ debug = DEBUG, exitHandler: proc(engine: var Engine) = nil, resizeHandler: proc(engine: var Engine) = nil, - eventHandler: proc(engine: var Engine, event: Event) = nil + eventHandler: proc(engine: var Engine, event: Event) = nil, + vulkanVersion = VK_MAKE_API_VERSION(0, 1, 3, 0), + vulkanLayers: openArray[string] = [], ): Engine = echo "Set log level to ", ENGINE_LOGLEVEL setLogFilter(ENGINE_LOGLEVEL) @@ -80,21 +82,21 @@ result.window = createWindow(applicationName) var + layers = @vulkanLayers instanceExtensions: seq[string] - enabledLayers: seq[string] if debug: instanceExtensions.add "VK_EXT_debug_utils" - enabledLayers.add "VK_LAYER_KHRONOS_validation" + layers.add "VK_LAYER_KHRONOS_validation" # putEnv("VK_LAYER_ENABLES", "VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT") - putEnv("VK_LAYER_ENABLES", "") + putEnv("VK_LAYER_ENABLES", "VALIDATION_CHECK_ENABLE_VENDOR_SPECIFIC_ALL,VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT,VK_VALIDATION_FEATURE_ENABLE_SYNCHRONIZATION_VALIDATION_EXTVK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_EXT") if defined(linux) and DEBUG: - enabledLayers.add "VK_LAYER_MESA_overlay" + layers.add "VK_LAYER_MESA_overlay" result.instance = result.window.createInstance( - vulkanVersion = VK_MAKE_API_VERSION(0, 1, 3, 0), + vulkanVersion = vulkanVersion, instanceExtensions = instanceExtensions, - layers = enabledLayers, + layers = layers, ) if debug: result.debugger = result.instance.createDebugMessenger() diff -r cdf7ad53965a -r e02d8e65d68e semicongine/renderer.nim --- a/semicongine/renderer.nim Mon Mar 25 22:26:58 2024 +0700 +++ b/semicongine/renderer.nim Fri Mar 29 15:08:33 2024 +0700 @@ -415,7 +415,7 @@ return commandBuffer = commandBufferResult.get() - commandBuffer.beginRenderCommands(renderer.renderPass, renderer.swapchain.currentFramebuffer()) + commandBuffer.beginRenderCommands(renderer.renderPass, renderer.swapchain.currentFramebuffer(), oneTimeSubmit = true) debug "Scene buffers:" for (location, buffer) in renderer.scenedata[scene].vertexBuffers.pairs: diff -r cdf7ad53965a -r e02d8e65d68e semicongine/vulkan/image.nim --- a/semicongine/vulkan/image.nim Mon Mar 25 22:26:58 2024 +0700 +++ b/semicongine/vulkan/image.nim Fri Mar 29 15:08:33 2024 +0700 @@ -79,7 +79,7 @@ ) checkVkResult image.device.vk.vkBindImageMemory(image.vk, image.memory.vk, VkDeviceSize(0)) -proc transitionImageLayout*(image: VulkanImage, oldLayout, newLayout: VkImageLayout) = +proc transitionImageLayout(image: VulkanImage, oldLayout, newLayout: VkImageLayout) = var barrier = VkImageMemoryBarrier( sType: VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, oldLayout: oldLayout, @@ -150,7 +150,7 @@ ) # currently only usable for texture access from shader -proc createImage*(device: Device, width, height: int, depth: PixelDepth, data: pointer): VulkanImage = +proc createImage(device: Device, width, height: int, depth: PixelDepth, data: pointer): VulkanImage = assert device.vk.valid assert width > 0 assert height > 0 diff -r cdf7ad53965a -r e02d8e65d68e semicongine/vulkan/renderpass.nim --- a/semicongine/vulkan/renderpass.nim Mon Mar 25 22:26:58 2024 +0700 +++ b/semicongine/vulkan/renderpass.nim Fri Mar 29 15:08:33 2024 +0700 @@ -102,7 +102,7 @@ result.subpasses[0].shaderPipelines.add (materialtype, device.createPipeline(result.vk, shaderconfig, inFlightFrames, 0, backFaceCulling = backFaceCulling)) -proc beginRenderCommands*(commandBuffer: VkCommandBuffer, renderpass: RenderPass, framebuffer: Framebuffer) = +proc beginRenderCommands*(commandBuffer: VkCommandBuffer, renderpass: RenderPass, framebuffer: Framebuffer, oneTimeSubmit: bool) = assert commandBuffer.valid assert renderpass.vk.valid assert framebuffer.vk.valid @@ -117,6 +117,7 @@ beginInfo = VkCommandBufferBeginInfo( sType: VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, pInheritanceInfo: nil, + flags: if oneTimeSubmit: VkCommandBufferUsageFlags(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) else: VkCommandBufferUsageFlags(0), ) renderPassInfo = VkRenderPassBeginInfo( sType: VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,