changeset 1201:d4a206b5e5b0 compiletime-tests

add: rest of the cleanup stuff
author sam <sam@basx.dev>
date Sun, 14 Jul 2024 21:30:52 +0700
parents 5c6491f28dcd
children a8864fe6fe6e
files semicongine.nim semicongine/rendering.nim semicongine/rendering/renderer.nim semicongine/rendering/shaders.nim semicongine/rendering/swapchain.nim test1.nim
diffstat 6 files changed, 32 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/semicongine.nim	Sun Jul 14 19:15:43 2024 +0700
+++ b/semicongine.nim	Sun Jul 14 21:30:52 2024 +0700
@@ -14,7 +14,7 @@
 import std/strformat
 import std/strutils
 import std/tables
-import std/typetraits as typetraits
+import std/typetraits
 
 include ./semicongine/rendering/vulkan/api
 include ./semicongine/core
--- a/semicongine/rendering.nim	Sun Jul 14 19:15:43 2024 +0700
+++ b/semicongine/rendering.nim	Sun Jul 14 21:30:52 2024 +0700
@@ -128,6 +128,7 @@
     buffers: array[BufferType, seq[Buffer]]
     images: seq[VkImage]
     imageViews: seq[VkImageView]
+    samplers: seq[VkSampler]
 
 template ForDescriptorFields(shader: typed, fieldname, valuename, typename, countname, bindingNumber, body: untyped): untyped =
   var `bindingNumber` {.inject.} = 1'u32
@@ -303,6 +304,8 @@
 
 proc DestroyVulkan*() =
   vkDestroyDevice(vulkan.device, nil)
+  vkDestroySurfaceKHR(vulkan.instance, vulkan.surface, nil)
+  vkDestroyDebugUtilsMessengerEXT(vulkan.instance, vulkan.debugMessenger, nil)
   vkDestroyInstance(vulkan.instance, nil)
 
 vulkan = InitVulkan()
--- a/semicongine/rendering/renderer.nim	Sun Jul 14 19:15:43 2024 +0700
+++ b/semicongine/rendering/renderer.nim	Sun Jul 14 21:30:52 2024 +0700
@@ -331,6 +331,9 @@
   for imageView in renderData.imageViews:
     vkDestroyImageView(vulkan.device, imageView, nil)
 
+  for sampler in renderData.samplers:
+    vkDestroySampler(vulkan.device, sampler, nil)
+
   for image in renderData.images:
     vkDestroyImage(vulkan.device, image, nil)
 
@@ -420,6 +423,7 @@
   texture.vk = svkCreate2DImage(texture.width, texture.height, format, usage)
   renderData.images.add texture.vk
   texture.sampler = createSampler()
+  renderData.samplers.add texture.sampler
 
   let memoryRequirements = texture.vk.svkGetImageMemoryRequirements()
   let memoryType = BestMemory(mappable = false, filter = memoryRequirements.memoryTypes)
@@ -520,7 +524,7 @@
 
     # descriptors
     elif typeof(shaderAttribute) is DescriptorSet:
-      assert descriptorSetCount <= DescriptorSetType.high.int, &"{typetraits.name(TShader)}: maximum {DescriptorSetType.high} allowed"
+      assert descriptorSetCount <= DescriptorSetType.high.int, typetraits.name(TShader) & ": maximum " & $DescriptorSetType.high & " allowed"
       descriptorSetCount.inc
 
 
@@ -532,7 +536,7 @@
         assert typeof(shaderAttribute) is TMaterial, "Shader has materialdescriptor type '" & typetraits.name(get(genericParams(typeof(shaderAttribute)), 0)) & "' but provided type is " & typetraits.name(TMaterial)
 
 
-proc Render[TShader, TGlobals, TMaterial, TMesh, TInstance](
+proc Render*[TShader, TGlobals, TMaterial, TMesh, TInstance](
   commandBuffer: VkCommandBuffer,
   pipeline: Pipeline[TShader],
   globalSet: TGlobals,
--- a/semicongine/rendering/shaders.nim	Sun Jul 14 19:15:43 2024 +0700
+++ b/semicongine/rendering/shaders.nim	Sun Jul 14 21:30:52 2024 +0700
@@ -461,5 +461,11 @@
   )
 
 proc DestroyPipeline*(pipeline: Pipeline) =
+
+  for descriptorSetLayout in pipeline.descriptorSetLayouts:
+    vkDestroyDescriptorSetLayout(vulkan.device, descriptorSetLayout, nil)
+
   vkDestroyShaderModule(vulkan.device, pipeline.vertexShaderModule, nil)
   vkDestroyShaderModule(vulkan.device, pipeline.fragmentShaderModule, nil)
+  vkDestroyPipelineLayout(vulkan.device, pipeline.layout, nil)
+  vkDestroyPipeline(vulkan.device, pipeline.vk, nil)
--- a/semicongine/rendering/swapchain.nim	Sun Jul 14 19:15:43 2024 +0700
+++ b/semicongine/rendering/swapchain.nim	Sun Jul 14 21:30:52 2024 +0700
@@ -126,8 +126,13 @@
   for imageView in swapchain.framebufferViews:
     vkDestroyImageView(vulkan.device, imageView, nil)
 
+  for framebuffer in swapchain.framebuffers:
+    vkDestroyFramebuffer(vulkan.device, framebuffer, nil)
+
   vkDestroyCommandPool(vulkan.device, swapchain.commandBufferPool, nil)
 
+  vkDestroySwapchainKHR(vulkan.device, swapchain.vk, nil)
+
 proc TryAcquireNextImage(swapchain: var Swapchain): Option[VkFramebuffer] =
   if not swapchain.queueFinishedFence[swapchain.currentFiF].Await(100_000_000):
     return none(VkFramebuffer)
@@ -184,7 +189,6 @@
       DestroySwapchain(swapchain.oldSwapchain[])
       swapchain.oldSwapchain = nil
 
-
   if presentResult != VK_SUCCESS:
     return false
 
--- a/test1.nim	Sun Jul 14 19:15:43 2024 +0700
+++ b/test1.nim	Sun Jul 14 21:30:52 2024 +0700
@@ -117,12 +117,21 @@
   WithNextFrame(swapchain, framebuffer, commandbuffer):
     WithRenderPass(mainRenderpass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(1, 0, 0, 0)):
       vkCmdBindPipeline(commandbuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline1.vk)
+
+      Render(
+        commandbuffer = commandbuffer,
+        pipeline = pipeline1,
+        globalSet = myGlobals,
+        materialSet = uniforms1,
+        mesh = myMesh1,
+        instances = instances1,
+      )
       echo (getMonoTime() - t).inMicroseconds.float / 1000.0
       t = getMonoTime()
 
+checkVkResult vkDeviceWaitIdle(vulkan.device)
 DestroyPipeline(pipeline1)
-
+vkDestroyRenderPass(vulkan.device, mainRenderpass, nil)
 DestroyRenderData(renderdata)
-checkVkResult vkDeviceWaitIdle(vulkan.device)
 DestroySwapchain(swapchain)
 DestroyVulkan()