Mercurial > games > semicongine
diff semiconginev2/rendering/renderer.nim @ 1231:70f6c1cfe005
add: incomplete cube demo
author | sam <sam@basx.dev> |
---|---|
date | Thu, 18 Jul 2024 23:48:57 +0700 |
parents | 5dcb503ef0c0 |
children | 841e12f33c47 |
line wrap: on
line diff
--- a/semiconginev2/rendering/renderer.nim Fri Jul 19 04:49:18 2024 +0700 +++ b/semiconginev2/rendering/renderer.nim Thu Jul 18 23:48:57 2024 +0700 @@ -216,6 +216,15 @@ ppData = addr(result.rawPointer) ) +proc FlushBuffer*(buffer: Buffer) = + var flushRegion = VkMappedMemoryRange( + sType: VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, + memory: buffer.memory, + offset: buffer.memoryOffset, + size: buffer.size, + ) + checkVkResult vkFlushMappedMemoryRanges(vulkan.device, 1, addr(flushRegion)) + proc FlushAllMemory*(renderData: RenderData) = var flushRegions = newSeq[VkMappedMemoryRange]() for memoryBlocks in renderData.memory: @@ -265,14 +274,18 @@ selectedBlock.vk, selectedBlock.offsetNextFree, ) + result.memory = selectedBlock.vk + result.memoryOffset = selectedBlock.offsetNextFree result.rawPointer = selectedBlock.rawPointer.pointerAddOffset(selectedBlock.offsetNextFree) renderData.memory[memoryType][selectedBlockI].offsetNextFree += memoryRequirements.size -proc UpdateGPUBuffer*(gpuData: GPUData) = +proc UpdateGPUBuffer*(gpuData: GPUData, flush = false) = if gpuData.size == 0: return when NeedsMapping(gpuData): copyMem(pointerAddOffset(gpuData.buffer.rawPointer, gpuData.offset), gpuData.rawPointer, gpuData.size) + if flush: + FlushBuffer(gpuData.buffer) else: WithStagingBuffer((gpuData.buffer.vk, gpuData.offset), gpuData.size, stagingPtr): copyMem(stagingPtr, gpuData.rawPointer, gpuData.size)