# HG changeset patch # User sam # Date 1720800389 -25200 # Node ID f6a0dc7ad0521e745c2f35c8c43f7b182b00a742 # Parent 82feceae80b15f60ed7b87ea188d163c30646f39 sync from bedroom to office diff -r 82feceae80b1 -r f6a0dc7ad052 semicongine/rendering.nim --- 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 diff -r 82feceae80b1 -r f6a0dc7ad052 semicongine/rendering/swapchain.nim --- 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, diff -r 82feceae80b1 -r f6a0dc7ad052 test1.nim --- 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()