changeset 937:d27e28f9d8ab

fix: a few small (vulkan) API optimizations
author sam <sam@basx.dev>
date Fri, 29 Mar 2024 15:08:33 +0700
parents 4b7914fa615f
children 5838b9ef52db
files semicongine/engine.nim semicongine/renderer.nim semicongine/vulkan/image.nim semicongine/vulkan/renderpass.nim
diffstat 4 files changed, 14 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- 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()
--- 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:
--- 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
--- 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,