comparison tests/test_text.nim @ 1409:5a56f8ac328b

did: improve descriptor-set handling + last fixes for new font/text rendering api
author sam <sam@basx.dev>
date Mon, 23 Dec 2024 00:32:07 +0700
parents 17d960ff6a24
children 99d5b42cf32d
comparison
equal deleted inserted replaced
1408:17d960ff6a24 1409:5a56f8ac328b
20 var renderdata = initRenderData() 20 var renderdata = initRenderData()
21 var pipeline = createPipeline[GlyphShader[MAX_CODEPOINTS]]( 21 var pipeline = createPipeline[GlyphShader[MAX_CODEPOINTS]](
22 renderPass = vulkan.swapchain.renderPass 22 renderPass = vulkan.swapchain.renderPass
23 ) 23 )
24 var textbuffer = font.initTextBuffer(1000, baseScale = 0.1) 24 var textbuffer = font.initTextBuffer(1000, baseScale = 0.1)
25
26 assignBuffers(renderdata, textbuffer) 25 assignBuffers(renderdata, textbuffer)
27 assignBuffers(renderdata, font.descriptorSet) 26
28 uploadImages(renderdata, font.descriptorSet) 27 font.upload(renderdata)
29 initDescriptorSet(renderdata, pipeline.layout(0), font.descriptorSet) 28 font.addToPipeline(renderdata, pipeline)
30 29
31 discard textbuffer.add("Hello semicongine!", vec3()) 30 discard textbuffer.add("Hello semicongine!", vec3())
32 31
33 var start = getMonoTime() 32 var start = getMonoTime()
34 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: 33 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time:
35 let t = getMonoTime() 34 let t = getMonoTime()
36 if windowWasResized(): 35 if windowWasResized():
37 textbuffer.refresh() 36 textbuffer.refresh()
38 37
39 withNextFrame(framebuffer, commandbuffer): 38 withNextFrame(framebuffer, commandbuffer):
40 bindDescriptorSet(commandbuffer, font.descriptorSet, 0, pipeline) 39 font.bindTo(pipeline, commandbuffer)
41 withRenderPass( 40 withRenderPass(
42 vulkan.swapchain.renderPass, 41 vulkan.swapchain.renderPass,
43 framebuffer, 42 framebuffer,
44 commandbuffer, 43 commandbuffer,
45 vulkan.swapchain.width, 44 vulkan.swapchain.width,
62 61
63 var pipeline = createPipeline[GlyphShader[MAX_CODEPOINTS]]( 62 var pipeline = createPipeline[GlyphShader[MAX_CODEPOINTS]](
64 renderPass = vulkan.swapchain.renderPass 63 renderPass = vulkan.swapchain.renderPass
65 ) 64 )
66 65
67 assignBuffers(renderdata, font1.descriptorSet) 66 font1.upload(renderdata)
68 assignBuffers(renderdata, font2.descriptorSet) 67 font2.upload(renderdata)
69 assignBuffers(renderdata, font3.descriptorSet) 68 font3.upload(renderdata)
70 uploadImages(renderdata, font1.descriptorSet) 69 font1.addToPipeline(renderdata, pipeline)
71 uploadImages(renderdata, font2.descriptorSet) 70 font2.addToPipeline(renderdata, pipeline)
72 uploadImages(renderdata, font3.descriptorSet) 71 font3.addToPipeline(renderdata, pipeline)
73 initDescriptorSet(renderdata, pipeline.layout(0), font1.descriptorSet)
74 initDescriptorSet(renderdata, pipeline.layout(0), font2.descriptorSet)
75 initDescriptorSet(renderdata, pipeline.layout(0), font3.descriptorSet)
76 72
77 var textbuffer1 = font1.initTextBuffer(10, baseScale = 0.1) 73 var textbuffer1 = font1.initTextBuffer(10, baseScale = 0.1)
78 var textbuffer2 = font2.initTextBuffer(10, baseScale = 0.1) 74 var textbuffer2 = font2.initTextBuffer(10, baseScale = 0.1)
79 var textbuffer3 = font3.initTextBuffer(10, baseScale = 0.1) 75 var textbuffer3 = font3.initTextBuffer(10, baseScale = 0.1)
80 76
109 vulkan.swapchain.width, 105 vulkan.swapchain.width,
110 vulkan.swapchain.height, 106 vulkan.swapchain.height,
111 vec4(0, 0, 0, 0), 107 vec4(0, 0, 0, 0),
112 ): 108 ):
113 withPipeline(commandbuffer, pipeline): 109 withPipeline(commandbuffer, pipeline):
114 bindDescriptorSet(commandbuffer, font1.descriptorSet, 0, pipeline) 110 bindDescriptorSet(commandbuffer, font1.descriptorSet, 3, pipeline)
115 renderTextBuffer(commandbuffer, pipeline, textbuffer1) 111 renderTextBuffer(commandbuffer, pipeline, textbuffer1)
116 bindDescriptorSet(commandbuffer, font2.descriptorSet, 0, pipeline) 112 bindDescriptorSet(commandbuffer, font2.descriptorSet, 3, pipeline)
117 renderTextBuffer(commandbuffer, pipeline, textbuffer2) 113 renderTextBuffer(commandbuffer, pipeline, textbuffer2)
118 bindDescriptorSet(commandbuffer, font3.descriptorSet, 0, pipeline) 114 bindDescriptorSet(commandbuffer, font3.descriptorSet, 3, pipeline)
119 renderTextBuffer(commandbuffer, pipeline, textbuffer3) 115 renderTextBuffer(commandbuffer, pipeline, textbuffer3)
120 116
121 # cleanup 117 # cleanup
122 checkVkResult vkDeviceWaitIdle(vulkan.device) 118 checkVkResult vkDeviceWaitIdle(vulkan.device)
123 destroyPipeline(pipeline) 119 destroyPipeline(pipeline)
129 125
130 var pipeline = createPipeline[GlyphShader[MAX_CODEPOINTS]]( 126 var pipeline = createPipeline[GlyphShader[MAX_CODEPOINTS]](
131 renderPass = vulkan.swapchain.renderPass 127 renderPass = vulkan.swapchain.renderPass
132 ) 128 )
133 129
134 assignBuffers(renderdata, font.descriptorSet) 130 font.upload(renderdata)
135 uploadImages(renderdata, font.descriptorSet) 131 font.addToPipeline(renderdata, pipeline)
136 initDescriptorSet(renderdata, pipeline.layout(0), font.descriptorSet)
137 132
138 var textbuffer = font.initTextBuffer(1000, baseScale = 0.1) 133 var textbuffer = font.initTextBuffer(1000, baseScale = 0.1)
139 assignBuffers(renderdata, textbuffer) 134 assignBuffers(renderdata, textbuffer)
140 135
141 discard textbuffer.add("Anchor at center", vec3(0, 0), anchor = vec2(0, 0)) 136 discard textbuffer.add("Anchor at center", vec3(0, 0), anchor = vec2(0, 0))
159 let progress = ((getMonoTime() - start).inMilliseconds().int / 1000) / time 154 let progress = ((getMonoTime() - start).inMilliseconds().int / 1000) / time
160 if windowWasResized(): 155 if windowWasResized():
161 textbuffer.refresh() 156 textbuffer.refresh()
162 157
163 withNextFrame(framebuffer, commandbuffer): 158 withNextFrame(framebuffer, commandbuffer):
164 bindDescriptorSet(commandbuffer, font.descriptorSet, 0, pipeline) 159 bindDescriptorSet(commandbuffer, font.descriptorSet, 3, pipeline)
165 withRenderPass( 160 withRenderPass(
166 vulkan.swapchain.renderPass, 161 vulkan.swapchain.renderPass,
167 framebuffer, 162 framebuffer,
168 commandbuffer, 163 commandbuffer,
169 vulkan.swapchain.width, 164 vulkan.swapchain.width,
184 179
185 var pipeline = createPipeline[GlyphShader[MAX_CODEPOINTS]]( 180 var pipeline = createPipeline[GlyphShader[MAX_CODEPOINTS]](
186 renderPass = vulkan.swapchain.renderPass 181 renderPass = vulkan.swapchain.renderPass
187 ) 182 )
188 183
189 assignBuffers(renderdata, font.descriptorSet) 184 font.upload(renderdata)
190 uploadImages(renderdata, font.descriptorSet) 185 font.addToPipeline(renderdata, pipeline)
191 initDescriptorSet(renderdata, pipeline.layout(0), font.descriptorSet)
192 186
193 var textbuffer = font.initTextBuffer(3000, baseScale = 0.1) 187 var textbuffer = font.initTextBuffer(3000, baseScale = 0.1)
194 assignBuffers(renderdata, textbuffer) 188 assignBuffers(renderdata, textbuffer)
195 189
196 for i in 0 ..< 1000: 190 for i in 0 ..< 1000:
209 echo (n - last).inMicroseconds() / 1000 203 echo (n - last).inMicroseconds() / 1000
210 last = n 204 last = n
211 withNextFrame(framebuffer, commandbuffer): 205 withNextFrame(framebuffer, commandbuffer):
212 if windowWasResized(): 206 if windowWasResized():
213 textbuffer.refresh() 207 textbuffer.refresh()
214 bindDescriptorSet(commandbuffer, font.descriptorSet, 0, pipeline) 208 bindDescriptorSet(commandbuffer, font.descriptorSet, 3, pipeline)
215 withRenderPass( 209 withRenderPass(
216 vulkan.swapchain.renderPass, 210 vulkan.swapchain.renderPass,
217 framebuffer, 211 framebuffer,
218 commandbuffer, 212 commandbuffer,
219 vulkan.swapchain.width, 213 vulkan.swapchain.width,