annotate semiconginev2/old/vulkan/drawable.nim @ 1218:56781cc0fc7c compiletime-tests

did: renamge main package
author sam <sam@basx.dev>
date Wed, 17 Jul 2024 21:01:37 +0700
parents semicongine/old/vulkan/drawable.nim@a3eb305bcac2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
1 import std/tables
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
2 import std/strformat
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
3 import std/logging
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
4
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
5 import ../core
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
6 import ./buffer
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
7
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
8 type
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
9 Drawable* = object
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
10 name*: string
959
c104dbf5bbb8 did: adjust integer sizes to match vulkan API (more) directly
sam <sam@basx.dev>
parents: 920
diff changeset
11 elementCount*: int # number of vertices or indices
c104dbf5bbb8 did: adjust integer sizes to match vulkan API (more) directly
sam <sam@basx.dev>
parents: 920
diff changeset
12 bufferOffsets*: Table[VkPipeline, seq[(string, MemoryPerformanceHint, uint64)]] # list of buffers and list of offset for each attribute in that buffer
c104dbf5bbb8 did: adjust integer sizes to match vulkan API (more) directly
sam <sam@basx.dev>
parents: 920
diff changeset
13 instanceCount*: int # number of instance
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
14 case indexed*: bool
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
15 of true:
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
16 indexType*: VkIndexType
959
c104dbf5bbb8 did: adjust integer sizes to match vulkan API (more) directly
sam <sam@basx.dev>
parents: 920
diff changeset
17 indexBufferOffset*: uint64
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
18 of false:
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
19 discard
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
20
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
21 func `$`*(drawable: Drawable): string =
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
22 if drawable.indexed:
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
23 &"Drawable({drawable.name}, elementCount: {drawable.elementCount}, instanceCount: {drawable.instanceCount}, bufferOffsets: {drawable.bufferOffsets}, indexType: {drawable.indexType}, indexBufferOffset: {drawable.indexBufferOffset})"
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
24 else:
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
25 &"Drawable({drawable.name}, elementCount: {drawable.elementCount}, instanceCount: {drawable.instanceCount}, bufferOffsets: {drawable.bufferOffsets})"
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
26
1138
02e1d2658ff5 did: more renaming
sam <sam@basx.dev>
parents: 1137
diff changeset
27 proc Draw*(drawable: Drawable, commandBuffer: VkCommandBuffer, vertexBuffers: Table[MemoryPerformanceHint, Buffer], indexBuffer: Buffer, pipeline: VkPipeline) =
1001
46344b02df81 did: small cleanup
sam <sam@basx.dev>
parents: 963
diff changeset
28 debug &"Draw {drawable} with pipeline {pipeline}"
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
29
902
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
30 var buffers: seq[VkBuffer]
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
31 var offsets: seq[VkDeviceSize]
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
32
902
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
33 for (name, performanceHint, offset) in drawable.bufferOffsets[pipeline]:
1139
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
34 assert vertexBuffers[performanceHint].vk.Valid
902
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
35 buffers.add vertexBuffers[performanceHint].vk
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
36 offsets.add VkDeviceSize(offset)
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
37
963
9d3f6d742e65 add: some more debug log
sam <sam@basx.dev>
parents: 959
diff changeset
38 debug "Binding buffers: ", buffers
1001
46344b02df81 did: small cleanup
sam <sam@basx.dev>
parents: 963
diff changeset
39 debug "with offsets ", offsets
902
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
40 commandBuffer.vkCmdBindVertexBuffers(
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
41 firstBinding = 0'u32,
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
42 bindingCount = uint32(buffers.len),
1137
a4aa9f374d44 did: more renaming
sam <sam@basx.dev>
parents: 1001
diff changeset
43 pBuffers = buffers.ToCPointer(),
a4aa9f374d44 did: more renaming
sam <sam@basx.dev>
parents: 1001
diff changeset
44 pOffsets = offsets.ToCPointer()
902
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
45 )
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
46 if drawable.indexed:
1139
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
47 assert indexBuffer.vk.Valid
902
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
48 commandBuffer.vkCmdBindIndexBuffer(indexBuffer.vk, VkDeviceSize(drawable.indexBufferOffset), drawable.indexType)
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
49 commandBuffer.vkCmdDrawIndexed(
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
50 indexCount = uint32(drawable.elementCount),
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
51 instanceCount = uint32(drawable.instanceCount),
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
52 firstIndex = 0,
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
53 vertexOffset = 0,
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
54 firstInstance = 0
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
55 )
902
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
56 else:
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
57 commandBuffer.vkCmdDraw(
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
58 vertexCount = uint32(drawable.elementCount),
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
59 instanceCount = uint32(drawable.instanceCount),
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
60 firstVertex = 0,
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
61 firstInstance = 0
904e0a827ef3 did: auto-formatting
Sam <sam@basx.dev>
parents: 840
diff changeset
62 )