-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexture.py
More file actions
467 lines (439 loc) · 21.6 KB
/
Copy pathtexture.py
File metadata and controls
467 lines (439 loc) · 21.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# Copyright (C) 2019 by [email protected]
# This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
import vulkan as vk
import vks.vulkanbuffer
import vks.vulkanexamplebase
import vks.vulkanglobals
import vks.vulkantexture
import glm
import numpy as np
import imgui
VERTEX_BUFFER_BIND_ID = 0
class VulkanExample(vks.vulkanexamplebase.VulkanExampleBase):
def __init__(self):
super().__init__(enableValidation=False)
self.texture = vks.vulkantexture.Texture2D()
self.vertices = {'inputState': None, 'bindingDescriptions': [], 'attributeDescriptions': []}
self.vertexBuffer = None
self.vertexShape = None
self.indexBuffer = None
self.indexCount = 0
self.uniformBufferVS = None
self.uboVS = {'projection': glm.mat4(), 'model': glm.mat4(), 'viewPos': glm.vec4(), 'lodBias': glm.vec1(0.0)}
self.pipelines = {'solid': None}
self.pipelineLayout = None
self.descriptorSetLayout = None
self.descriptorSet = None
self.zoom = -2.5
self.title = "Vulkan Example - Texture loading"
self.rotation = glm.vec3(0.0, 15.0, 0.0)
self.settings['overlay'] = True
def __del__(self):
self.texture.destroy()
if self.pipelines['solid']:
vk.vkDestroyPipeline(self.device, self.pipelines['solid'], None)
if self.pipelineLayout:
vk.vkDestroyPipelineLayout(self.device, self.pipelineLayout, None)
if self.descriptorSetLayout:
vk.vkDestroyDescriptorSetLayout(self.device, self.descriptorSetLayout, None)
if self.vertexBuffer:
self.vertexBuffer.destroy()
if self.indexBuffer:
self.indexBuffer.destroy()
if self.uniformBufferVS:
self.uniformBufferVS.destroy()
def getEnabledFeatures(self):
# Enable anisotropic filtering if supported
if (self.deviceFeatures.samplerAnisotropy):
self.enabledFeatures.samplerAnisotropy = vk.VK_TRUE
def loadTexture(self):
filename = self.getAssetPath() + "textures/metalplate01_rgba.ktx"
self.texture.loadFromFile(filename, vk.VK_FORMAT_R8G8B8A8_UNORM, self.vulkanDevice, self.queue)
def generateQuad(self):
self.vertexShape = np.dtype([('pos', np.float32, (3,)), ('uv', np.float32, (2,)), ('normal', np.float32, (3,))]) #position, uv, normal
# Setup vertices for a single uv-mapped quad made from two triangles
vertexdata = np.array(
[
( [ 1.0, 1.0, 0.0 ], [ 1.0, 1.0 ],[ 0.0, 0.0, 1.0 ] ),
( [ -1.0, 1.0, 0.0 ], [ 0.0, 1.0 ],[ 0.0, 0.0, 1.0 ] ),
( [ -1.0, -1.0, 0.0 ], [ 0.0, 0.0 ],[ 0.0, 0.0, 1.0 ] ),
( [ 1.0, -1.0, 0.0 ], [ 1.0, 0.0 ],[ 0.0, 0.0, 1.0 ] )
],
dtype=self.vertexShape)
vertexBufferSize = vertexdata.size * vertexdata.itemsize
indexdata = np.array([ 0, 1, 2 , 2, 3, 0 ], dtype = np.uint32)
indexBufferSize = indexdata.size * indexdata.itemsize
self.indexCount = len(indexdata)
# Create buffers
# For the sake of simplicity we won't stage the vertex data to the gpu memory
# Vertex buffer
self.vertexBuffer = self.vulkanDevice.createvksBuffer(vk.VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
vk.VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | vk.VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
vertexBufferSize, vertexdata
)
# Index buffer
self.indexBuffer = self.vulkanDevice.createvksBuffer(vk.VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
vk.VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | vk.VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
indexBufferSize, indexdata
)
def setupVertexDescriptions(self):
vertexInputBinding = vk.VkVertexInputBindingDescription(
binding = VERTEX_BUFFER_BIND_ID,
stride = self.vertexShape.itemsize,
inputRate = vk.VK_VERTEX_INPUT_RATE_VERTEX
)
self.vertices['bindingDescriptions'].append(vertexInputBinding)
vertexInputAttribut = vk.VkVertexInputAttributeDescription(
binding = VERTEX_BUFFER_BIND_ID,
location = 0,
# Position attribute is three 32 bit signed (SFLOAT) floats (R32 G32 B32)
format = vk.VK_FORMAT_R32G32B32_SFLOAT,
offset = self.vertexShape.fields['pos'][1] # offsetof(vertexShape, pos)
)
self.vertices['attributeDescriptions'].append(vertexInputAttribut)
vertexInputAttribut = vk.VkVertexInputAttributeDescription(
binding = VERTEX_BUFFER_BIND_ID,
location = 1,
# UV attribute is two 32 bit signed (SFLOAT) floats (R32 G32)
format = vk.VK_FORMAT_R32G32_SFLOAT,
offset = self.vertexShape.fields['uv'][1] # offsetof(vertexShape, pos)
)
self.vertices['attributeDescriptions'].append(vertexInputAttribut)
vertexInputAttribut = vk.VkVertexInputAttributeDescription(
binding = VERTEX_BUFFER_BIND_ID,
location = 2,
# Normal attribute is threeo 32 bit signed (SFLOAT) floats (R32 G32 B32)
format = vk.VK_FORMAT_R32G32B32_SFLOAT,
offset = self.vertexShape.fields['normal'][1] # offsetof(vertexShape, pos)
)
self.vertices['attributeDescriptions'].append(vertexInputAttribut)
self.vertices['inputState'] = vk.VkPipelineVertexInputStateCreateInfo(
sType = vk.VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
vertexBindingDescriptionCount = len(self.vertices['bindingDescriptions']),
pVertexBindingDescriptions = self.vertices['bindingDescriptions'],
vertexAttributeDescriptionCount = len(self.vertices['attributeDescriptions']),
pVertexAttributeDescriptions = self.vertices['attributeDescriptions']
)
def prepareUniformBuffers(self):
uboVSSize = sum([glm.sizeof(ubo) for ubo in self.uboVS.values()])
self.uniformBufferVS = self.vulkanDevice.createvksBuffer(
vk.VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
vk.VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | vk.VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
uboVSSize
)
self.updateUniformBuffers()
def updateUniformBuffers(self):
self.uboVS['projection'] = glm.transpose(glm.perspectiveRH_ZO(glm.radians(60.0), self.width / self.height, 0.001, 256.0))
view = glm.transpose(glm.translate(glm.mat4(1.0), glm.vec3(0.0, 0.0, self.zoom)))
self.uboVS['model'] = view * glm.translate(glm.mat4(1.0), self.cameraPos)
self.uboVS['model'] = glm.rotate(self.uboVS['model'], glm.radians(self.rotation.x), glm.vec3(1.0, 0.0, 0.0))
self.uboVS['model'] = glm.rotate(self.uboVS['model'], glm.radians(self.rotation.y), glm.vec3(0.0, 1.0, 0.0))
self.uboVS['model'] = glm.rotate(self.uboVS['model'], glm.radians(self.rotation.z), glm.vec3(0.0, 0.0, 1.0))
self.uboVS['viewPos'] = glm.vec4(0.0, 0.0, -self.zoom, 0.0)
uboVSSize = sum([glm.sizeof(ubo) for ubo in self.uboVS.values()])
uboVSBuffer = np.concatenate((
np.array(self.uboVS['projection']).flatten(order='C'),
np.array(self.uboVS['model']).flatten(order='C'),
np.array(self.uboVS['viewPos']).flatten(order='C'),
np.array(self.uboVS['lodBias']).flatten(order='C')
))
self.uniformBufferVS.map()
self.uniformBufferVS.copyTo(uboVSBuffer, uboVSSize)
self.uniformBufferVS.unmap()
def setupDescriptorSetLayout(self):
setLayoutBindings = []
layoutBinding = vk.VkDescriptorSetLayoutBinding(
descriptorType = vk.VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
descriptorCount = 1,
stageFlags = vk.VK_SHADER_STAGE_VERTEX_BIT,
binding = 0
)
setLayoutBindings.append(layoutBinding)
layoutBinding = vk.VkDescriptorSetLayoutBinding(
descriptorType = vk.VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
descriptorCount = 1,
stageFlags = vk.VK_SHADER_STAGE_FRAGMENT_BIT,
binding = 1
)
setLayoutBindings.append(layoutBinding)
descriptorLayout = vk.VkDescriptorSetLayoutCreateInfo(
sType = vk.VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
pNext = None,
bindingCount = len(setLayoutBindings),
pBindings = setLayoutBindings
)
self.descriptorSetLayout = vk.vkCreateDescriptorSetLayout(self.device, descriptorLayout, None)
pPipelineLayoutCreateInfo = vk.VkPipelineLayoutCreateInfo(
sType = vk.VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
pNext = None,
setLayoutCount = 1,
pSetLayouts = [self.descriptorSetLayout]
)
self.pipelineLayout = vk.vkCreatePipelineLayout(self.device, pPipelineLayoutCreateInfo, None)
def preparePipelines(self):
inputAssemblyState = vk.VkPipelineInputAssemblyStateCreateInfo(
sType = vk.VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
topology = vk.VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
flags= 0,
primitiveRestartEnable = vk.VK_FALSE
)
rasterizationState = vk.VkPipelineRasterizationStateCreateInfo(
sType = vk.VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
polygonMode = vk.VK_POLYGON_MODE_FILL,
cullMode = vk.VK_CULL_MODE_NONE,
frontFace = vk.VK_FRONT_FACE_COUNTER_CLOCKWISE,
flags = 0,
depthClampEnable = vk.VK_FALSE,
lineWidth = 1.0
)
blendAttachmentState = vk.VkPipelineColorBlendAttachmentState(
colorWriteMask = 0xf,
blendEnable = vk.VK_FALSE
)
colorBlendState = vk.VkPipelineColorBlendStateCreateInfo(
sType = vk.VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
attachmentCount = 1,
pAttachments = [blendAttachmentState]
)
opState = vk.VkStencilOpState(
#failOp = vk.VK_STENCIL_OP_KEEP,
#passOp = vk.VK_STENCIL_OP_KEEP,
compareOp = vk.VK_COMPARE_OP_ALWAYS
)
depthStencilState = vk.VkPipelineDepthStencilStateCreateInfo(
sType = vk.VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
depthTestEnable = vk.VK_TRUE,
depthWriteEnable = vk.VK_TRUE,
depthCompareOp = vk.VK_COMPARE_OP_LESS_OR_EQUAL,
#depthBoundsTestEnable = vk.VK_FALSE,
#stencilTestEnable = vk.VK_FALSE,
front = opState,
back = opState
)
viewportState = vk.VkPipelineViewportStateCreateInfo(
sType = vk.VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
viewportCount = 1,
scissorCount = 1,
flags = 0
)
multisampleState = vk.VkPipelineMultisampleStateCreateInfo(
sType = vk.VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
rasterizationSamples = vk.VK_SAMPLE_COUNT_1_BIT,
flags = 0
)
dynamicStateEnables = [vk.VK_DYNAMIC_STATE_VIEWPORT, vk.VK_DYNAMIC_STATE_SCISSOR]
dynamicState = vk.VkPipelineDynamicStateCreateInfo(
sType = vk.VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
dynamicStateCount = len(dynamicStateEnables),
pDynamicStates = dynamicStateEnables,
flags = 0
)
shaderStages = []
# Vertex shader
shaderStage = vk.VkPipelineShaderStageCreateInfo(
sType = vk.VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
stage = vk.VK_SHADER_STAGE_VERTEX_BIT,
module = vks.vulkantools.loadShader(self.getAssetPath() + "shaders/texture/texture.vert.spv", self.device),
pName = "main"
)
shaderStages.append(shaderStage)
# Fragment shader
shaderStage = vk.VkPipelineShaderStageCreateInfo(
sType = vk.VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
stage = vk.VK_SHADER_STAGE_FRAGMENT_BIT,
module = vks.vulkantools.loadShader(self.getAssetPath() + "shaders/texture/texture.frag.spv", self.device),
pName = "main"
)
shaderStages.append(shaderStage)
pipelineCreateInfo = vk.VkGraphicsPipelineCreateInfo(
sType = vk.VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
layout = self.pipelineLayout,
renderPass = self.renderPass,
pVertexInputState = self.vertices['inputState'],
pInputAssemblyState = inputAssemblyState,
pRasterizationState = rasterizationState,
pColorBlendState = colorBlendState,
pMultisampleState = multisampleState,
pViewportState = viewportState,
pDepthStencilState = depthStencilState,
pDynamicState = dynamicState,
stageCount = len(shaderStages),
pStages = shaderStages,
flags = 0,
basePipelineIndex = -1,
basePipelineHandle = vk.VK_NULL_HANDLE
)
pipe = vk.vkCreateGraphicsPipelines(self.device, self.pipelineCache, 1, [pipelineCreateInfo], None)
try:
self.pipelines['solid'] = pipe[0]
except TypeError:
self.pipelines['solid'] = pipe
def setupDescriptorPool(self):
poolSizes = []
poolSize = vk.VkDescriptorPoolSize(
type = vk.VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
descriptorCount = 1
)
poolSizes.append(poolSize)
poolSize = vk.VkDescriptorPoolSize(
type = vk.VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
descriptorCount = 1
)
poolSizes.append(poolSize)
descriptorPoolInfo = vk.VkDescriptorPoolCreateInfo(
sType = vk.VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
poolSizeCount = len(poolSizes),
pPoolSizes = poolSizes,
maxSets = 2
)
self.descriptorPool = vk.vkCreateDescriptorPool(self.device, descriptorPoolInfo, None)
def setupDescriptorSet(self):
allocInfo = vk.VkDescriptorSetAllocateInfo(
sType = vk.VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
descriptorPool = self.descriptorPool,
descriptorSetCount = 1,
pSetLayouts = [self.descriptorSetLayout]
)
descriptorSets = vk.vkAllocateDescriptorSets(self.device, allocInfo)
self.descriptorSet = descriptorSets[0]
# Setup a descriptor image info for the current texture to be used as a combined image sampler
textureDescriptor = vk.VkDescriptorImageInfo(
sampler = self.texture.sampler, # The sampler (Telling the pipeline how to sample the texture, including repeat, border, etc.)
imageView = self.texture.view, # The image's view (images are never directly accessed by the shader, but rather through views defining subresources)
imageLayout = self.texture.imageLayout # The current layout of the image (Note: Should always fit the actual use, e.g. shader read)
)
writeDescriptorSets = []
# Binding 0 : Vertex shader uniform buffer
writeDescriptorSet = vk.VkWriteDescriptorSet(
sType = vk.VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
dstSet = self.descriptorSet,
descriptorType = vk.VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
dstBinding = 0,
pBufferInfo = [ self.uniformBufferVS.descriptor ],
descriptorCount = 1
)
writeDescriptorSets.append(writeDescriptorSet)
# Binding 1 : Fragment shader texture sampler
# Fragment shader: layout (binding = 1) uniform sampler2D samplerColor
writeDescriptorSet = vk.VkWriteDescriptorSet(
sType = vk.VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
dstSet = self.descriptorSet,
descriptorType = vk.VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, # // The descriptor set will use a combined image sampler (sampler and image could be split)
dstBinding = 1, # Shader binding point 1
pImageInfo = [ textureDescriptor ], # Pointer to the descriptor image for our texture
descriptorCount = 1
)
writeDescriptorSets.append(writeDescriptorSet)
vk.vkUpdateDescriptorSets(self.device, len(writeDescriptorSets), writeDescriptorSets, 0, None)
def buildCommandBuffers(self):
cmdBufInfo = vk.VkCommandBufferBeginInfo(
sType = vk.VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
pNext = None
)
clearValues = []
clearValue = vk.VkClearValue(
color = self.defaultClearColor
)
clearValues.append(clearValue)
clearValue = vk.VkClearValue(
depthStencil = [1.0, 0 ]
)
clearValues.append(clearValue)
offset = vk.VkOffset2D(x = 0, y = 0)
extent = vk.VkExtent2D(width = self.width, height = self.height)
renderArea = vk.VkRect2D(offset = offset, extent = extent)
renderPassBeginInfo = vk.VkRenderPassBeginInfo(
sType = vk.VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
pNext = None,
renderPass = self.renderPass,
renderArea = renderArea,
clearValueCount = 2,
pClearValues = clearValues,
)
for i in range(len(self.drawCmdBuffers)):
renderPassBeginInfo.framebuffer = self.frameBuffers[i]
vk.vkBeginCommandBuffer(self.drawCmdBuffers[i], cmdBufInfo)
vk.vkCmdBeginRenderPass(self.drawCmdBuffers[i], renderPassBeginInfo, vk.VK_SUBPASS_CONTENTS_INLINE)
viewport = vk.VkViewport(
height = float(self.height),
width = float(self.width),
minDepth = 0.0,
maxDepth = 1.0
)
vk.vkCmdSetViewport(self.drawCmdBuffers[i], 0, 1, [viewport])
# Update dynamic scissor state
offsetscissor = vk.VkOffset2D(x = 0, y = 0)
extentscissor = vk.VkExtent2D(width = self.width, height = self.height)
scissor = vk.VkRect2D(offset = offsetscissor, extent = extentscissor)
vk.vkCmdSetScissor(self.drawCmdBuffers[i], 0, 1, [scissor])
vk.vkCmdBindDescriptorSets(self.drawCmdBuffers[i], vk.VK_PIPELINE_BIND_POINT_GRAPHICS, self.pipelineLayout, 0, 1, [self.descriptorSet], 0, None)
vk.vkCmdBindPipeline(self.drawCmdBuffers[i], vk.VK_PIPELINE_BIND_POINT_GRAPHICS, self.pipelines['solid'])
offsets = [ 0 ]
vk.vkCmdBindVertexBuffers(self.drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, [self.vertexBuffer.buffer], offsets)
vk.vkCmdBindIndexBuffer(self.drawCmdBuffers[i], self.indexBuffer.buffer, 0, vk.VK_INDEX_TYPE_UINT32)
# Draw indexed triangle
vk.vkCmdDrawIndexed(self.drawCmdBuffers[i], self.indexCount, 1, 0, 0, 0)
self.drawUI(self.drawCmdBuffers[i])
vk.vkCmdEndRenderPass(self.drawCmdBuffers[i])
vk.vkEndCommandBuffer(self.drawCmdBuffers[i])
def prepare(self):
super().prepare()
self.loadTexture()
self.generateQuad()
self.setupVertexDescriptions()
self.prepareUniformBuffers()
self.setupDescriptorSetLayout()
self.preparePipelines()
self.setupDescriptorPool()
self.setupDescriptorSet()
self.buildCommandBuffers()
# self.submitInfo = vk.VkSubmitInfo(sType = vk.VK_STRUCTURE_TYPE_SUBMIT_INFO,
# pWaitDstStageMask = self.submitPipelineStages,
# waitSemaphoreCount = 1,
# pWaitSemaphores = [self.semaphores['presentComplete']],
# signalSemaphoreCount = 1,
# pSignalSemaphores = [self.semaphores['renderComplete']],
# # To be able to set pCommandBuffers directly in draw()
# commandBufferCount = 1,
# pCommandBuffers = [ self.drawCmdBuffers[0] ]
# )
# # optimization to avoid creating a new array each time
# self.submit_list = vk.ffi.new('VkSubmitInfo[1]', [self.submitInfo])
self.prepared = True
def draw(self):
super().prepareFrame()
# self.submitInfo.commandBufferCount = 1
# TODO try to avoid creating submitInfo at each frame
# need to get CData pointer on drawCmdBuffers[*]
# self.submitInfo.pCommandBuffers[0] = self.drawCmdBuffers[self.currentBuffer]
# vk.vkQueueSubmit(self.queue, 1, self.submit_list, vk.VK_NULL_HANDLE)
submitInfo = vk.VkSubmitInfo(
sType = vk.VK_STRUCTURE_TYPE_SUBMIT_INFO,
pWaitDstStageMask = [ vk.VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT ],
pWaitSemaphores = [ self.semaphores['presentComplete'] ],
waitSemaphoreCount = 1,
signalSemaphoreCount = 1,
pSignalSemaphores = [ self.semaphores['renderComplete'] ],
pCommandBuffers = [ self.drawCmdBuffers[self.currentBuffer] ],
commandBufferCount = 1
)
vk.vkQueueSubmit(self.queue, 1, submitInfo , vk.VK_NULL_HANDLE)
super().submitFrame()
def render(self):
if not self.prepared:
return
# vk.vkDeviceWaitIdle(self.device)
self.draw()
def viewChanged(self):
self.updateUniformBuffers()
def onUpdateUIOverlay(self, overlay):
#return
if imgui.collapsing_header("Settings"):
res, value = imgui.slider_float("LOD bias", self.uboVS['lodBias'].x, 0.0, self.texture.mipLevels)
#res = False
if res:
overlay.updated = True
self.uboVS['lodBias'].x = value
self.updateUniformBuffers()
texture = VulkanExample()
texture.main()