changeset 1197:f6a0dc7ad052 compiletime-tests

sync from bedroom to office
author sam <sam@basx.dev>
date Fri, 12 Jul 2024 23:06:29 +0700
parents 82feceae80b1
children 96a094cd0c78
files semicongine/rendering.nim semicongine/rendering/swapchain.nim test1.nim
diffstat 3 files changed, 28 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/semicongine/rendering.nim	Tue Jul 09 22:53:38 2024 +0700
+++ b/semicongine/rendering.nim	Fri Jul 12 23:06:29 2024 +0700
@@ -7,7 +7,7 @@
 
 
 # const definitions
-const INFLIGHTFRAMES = 2'u32
+const INFLIGHTFRAMES* = 2'u32
 const BUFFER_ALIGNMENT = 64'u64 # align offsets inside buffers along this alignment
 const MEMORY_BLOCK_ALLOCATION_SIZE = 100_000_000'u64 # ca. 100mb per block, seems reasonable
 const BUFFER_ALLOCATION_SIZE = 9_000_000'u64 # ca. 9mb per block, seems reasonable, can put 10 buffers into one memory block
@@ -35,6 +35,8 @@
     window: NativeWindow
     graphicsQueueFamily*: uint32
     graphicsQueue*: VkQueue
+    # unclear as of yet
+    anisotropy*: float32 = 0 # needs to be enable during device creation
   Swapchain = object
     # parameters to InitSwapchain, required for swapchain recreation
     renderPass: VkRenderPass
@@ -47,12 +49,11 @@
     msaaImageView: VkImageView
     framebuffers: seq[VkFramebuffer]
     framebufferViews: seq[VkImageView]
-    queueFinishedFence*: array[INFLIGHTFRAMES, VkFence]
-    imageAvailableSemaphore*: array[INFLIGHTFRAMES, VkSemaphore]
-    renderFinishedSemaphore*: array[INFLIGHTFRAMES, VkSemaphore]
+    queueFinishedFence*: array[INFLIGHTFRAMES.int, VkFence]
+    imageAvailableSemaphore*: array[INFLIGHTFRAMES.int, VkSemaphore]
+    renderFinishedSemaphore*: array[INFLIGHTFRAMES.int, VkSemaphore]
     currentFiF: range[0 .. (INFLIGHTFRAMES - 1).int]
-    # unclear as of yet
-    anisotropy*: float32 = 0 # needs to be enable during device creation
+    currentFramebufferIndex: uint32
 
 var vulkan*: VulkanGlobals
 
--- a/semicongine/rendering/swapchain.nim	Tue Jul 09 22:53:38 2024 +0700
+++ b/semicongine/rendering/swapchain.nim	Fri Jul 12 23:06:29 2024 +0700
@@ -81,9 +81,9 @@
   for framebuffer in framebuffers:
     swapchain.framebufferViews.add svkCreate2DImageView(framebuffer, format)
     if samples == VK_SAMPLE_COUNT_1_BIT:
-      svkCreateFramebuffer(renderPass, width, height, [swapchain.framebufferViews[^1]])
+      swapchain.framebuffers.add svkCreateFramebuffer(renderPass, width, height, [swapchain.framebufferViews[^1]])
     else:
-      svkCreateFramebuffer(renderPass, width, height, [swapchain.msaaImageView, swapchain.framebufferViews[^1]])
+      swapchain.framebuffers.add svkCreateFramebuffer(renderPass, width, height, [swapchain.msaaImageView, swapchain.framebufferViews[^1]])
 
   # create sync primitives
   for i in 0 ..< INFLIGHTFRAMES:
@@ -110,7 +110,7 @@
     return none(VkFramebuffer)
   return some(swapchain.framebuffers[swapchain.currentFramebufferIndex])
 
-proc Swap*(swapchain: var Swapchain, queue: Queue, commandBuffer: VkCommandBuffer): bool =
+proc Swap*(swapchain: var Swapchain, queue: VkQueue, commandBuffer: VkCommandBuffer): bool =
   var
     waitStage = VkPipelineStageFlags(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT)
     submitInfo = VkSubmitInfo(
@@ -123,29 +123,30 @@
       signalSemaphoreCount: 1,
       pSignalSemaphores: addr(swapchain.renderFinishedSemaphore[swapchain.currentFiF]),
     )
-  checkVkResult queue.vk.vkQueueSubmit(
+  checkVkResult vkQueueSubmit(
+    queue = queue,
     submitCount = 1,
-    pSubmits = addr submitInfo,
-    fence = swapchain.queueFinishedFence[swapchain.currentInFlight].vk
+    pSubmits = addr(submitInfo),
+    fence = swapchain.queueFinishedFence[swapchain.currentFiF]
   )
 
   var presentInfo = VkPresentInfoKHR(
     sType: VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
     waitSemaphoreCount: 1,
-    pWaitSemaphores: addr swapchain.renderFinishedSemaphore[swapchain.currentInFlight].vk,
+    pWaitSemaphores: addr(swapchain.renderFinishedSemaphore[swapchain.currentFiF]),
     swapchainCount: 1,
-    pSwapchains: addr swapchain.vk,
-    pImageIndices: addr swapchain.currentFramebufferIndex,
+    pSwapchains: addr(swapchain.vk),
+    pImageIndices: addr(swapchain.currentFramebufferIndex),
     pResults: nil,
   )
-  let presentResult = vkQueuePresentKHR(swapchain.presentQueue.vk, addr presentInfo)
+  let presentResult = vkQueuePresentKHR(vulkan.graphicsQueue, addr(presentInfo))
   if presentResult != VK_SUCCESS:
     return false
 
   return true
 
-proc Recreate*(swapchain: Swapchain): Swapchain =
-  initSwapchain(
+proc Recreate*(swapchain: Swapchain): Option[Swapchain] =
+  InitSwapchain(
     renderPass = swapchain.renderPass,
     vSync = swapchain.vSync,
     samples = swapchain.samples,
--- a/test1.nim	Tue Jul 09 22:53:38 2024 +0700
+++ b/test1.nim	Fri Jul 12 23:06:29 2024 +0700
@@ -1,4 +1,5 @@
-import os
+import std/os
+import std/options
 
 import semicongine
 
@@ -133,6 +134,8 @@
   )
 checkVkResult vkAllocateCommandBuffers(vulkan.device, addr allocInfo, cmdBuffers.ToCPointer)
 
+
+
 # start command buffer
 block:
   let
@@ -180,12 +183,12 @@
     vkCmdSetScissor(cmd, firstScissor = 0, scissorCount = 1, addr(scissor))
 
     # bind pipeline, will be loop
-    block:
-      Bind(pipeline1, cmd, currentFrameInFlight = currentFrameInFlight)
+    # block:
+      # Bind(pipeline1, cmd, currentFrameInFlight = currentFrameInFlight)
 
       # render object, will be loop
-      block:
-        Render(cmd, pipeline1, myGlobals, uniforms1, myMesh1, instances1)
+      # block:
+        # Render(cmd, pipeline1, myGlobals, uniforms1, myMesh1, instances1)
 
     vkCmdEndRenderPass(cmd)
   checkVkResult cmd.vkEndCommandBuffer()