Mercurial > games > semicongine
comparison 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 |
comparison
equal
deleted
inserted
replaced
1230:51221494caeb | 1231:70f6c1cfe005 |
---|---|
214 size = result.size, | 214 size = result.size, |
215 flags = VkMemoryMapFlags(0), | 215 flags = VkMemoryMapFlags(0), |
216 ppData = addr(result.rawPointer) | 216 ppData = addr(result.rawPointer) |
217 ) | 217 ) |
218 | 218 |
219 proc FlushBuffer*(buffer: Buffer) = | |
220 var flushRegion = VkMappedMemoryRange( | |
221 sType: VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, | |
222 memory: buffer.memory, | |
223 offset: buffer.memoryOffset, | |
224 size: buffer.size, | |
225 ) | |
226 checkVkResult vkFlushMappedMemoryRanges(vulkan.device, 1, addr(flushRegion)) | |
227 | |
219 proc FlushAllMemory*(renderData: RenderData) = | 228 proc FlushAllMemory*(renderData: RenderData) = |
220 var flushRegions = newSeq[VkMappedMemoryRange]() | 229 var flushRegions = newSeq[VkMappedMemoryRange]() |
221 for memoryBlocks in renderData.memory: | 230 for memoryBlocks in renderData.memory: |
222 for memoryBlock in memoryBlocks: | 231 for memoryBlock in memoryBlocks: |
223 if memoryBlock.rawPointer != nil and memoryBlock.offsetNextFree > 0: | 232 if memoryBlock.rawPointer != nil and memoryBlock.offsetNextFree > 0: |
263 vulkan.device, | 272 vulkan.device, |
264 result.vk, | 273 result.vk, |
265 selectedBlock.vk, | 274 selectedBlock.vk, |
266 selectedBlock.offsetNextFree, | 275 selectedBlock.offsetNextFree, |
267 ) | 276 ) |
277 result.memory = selectedBlock.vk | |
278 result.memoryOffset = selectedBlock.offsetNextFree | |
268 result.rawPointer = selectedBlock.rawPointer.pointerAddOffset(selectedBlock.offsetNextFree) | 279 result.rawPointer = selectedBlock.rawPointer.pointerAddOffset(selectedBlock.offsetNextFree) |
269 renderData.memory[memoryType][selectedBlockI].offsetNextFree += memoryRequirements.size | 280 renderData.memory[memoryType][selectedBlockI].offsetNextFree += memoryRequirements.size |
270 | 281 |
271 proc UpdateGPUBuffer*(gpuData: GPUData) = | 282 proc UpdateGPUBuffer*(gpuData: GPUData, flush = false) = |
272 if gpuData.size == 0: | 283 if gpuData.size == 0: |
273 return | 284 return |
274 when NeedsMapping(gpuData): | 285 when NeedsMapping(gpuData): |
275 copyMem(pointerAddOffset(gpuData.buffer.rawPointer, gpuData.offset), gpuData.rawPointer, gpuData.size) | 286 copyMem(pointerAddOffset(gpuData.buffer.rawPointer, gpuData.offset), gpuData.rawPointer, gpuData.size) |
287 if flush: | |
288 FlushBuffer(gpuData.buffer) | |
276 else: | 289 else: |
277 WithStagingBuffer((gpuData.buffer.vk, gpuData.offset), gpuData.size, stagingPtr): | 290 WithStagingBuffer((gpuData.buffer.vk, gpuData.offset), gpuData.size, stagingPtr): |
278 copyMem(stagingPtr, gpuData.rawPointer, gpuData.size) | 291 copyMem(stagingPtr, gpuData.rawPointer, gpuData.size) |
279 | 292 |
280 proc UpdateAllGPUBuffers*[T](value: T) = | 293 proc UpdateAllGPUBuffers*[T](value: T) = |