@@ -34,7 +34,7 @@ void Compute::Init(VkDevice& device)
34
34
35
35
// SetupImage(device, image, extent, format, imageMemory, properties, usage);
36
36
37
- VkDeviceSize size = sizeof (float );
37
+ VkDeviceSize size = sizeof (float )* 2 ;
38
38
39
39
properties = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
40
40
usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
@@ -68,17 +68,23 @@ void Compute::Destroy(VkDevice& device)
68
68
vkDestroyDescriptorSetLayout (device, descriptorSetLayout, nullptr );
69
69
vkDestroyDescriptorPool (device, descriptorPool, nullptr );
70
70
71
- // vkDestroyPipeline(device, pipeline, nullptr);
71
+ vkDestroyPipeline (device, pipeline, nullptr );
72
72
vkDestroyPipelineLayout (device, pipelineLayout, nullptr );
73
73
vkDestroyShaderModule (device, shaderModule, nullptr );
74
+
75
+ vkFreeCommandBuffers (device, commandPool, 1 , &commandBuffer);
76
+
77
+ vkDestroyCommandPool (device, commandPool, nullptr );
78
+
79
+ vkDestroyFence (device, fence, nullptr );
74
80
}
75
81
76
82
void Compute::SetupBuffers (VkDevice& device)
77
83
{
78
84
79
85
}
80
86
81
- void Compute::SetupQueue (VkDevice& device)
87
+ void Compute::SetupQueue (VkDevice& device, uint32_t queueFamilyId )
82
88
{
83
89
/* VkDeviceQueueCreateInfo queueCreateInfo = {};
84
90
queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
@@ -244,7 +250,7 @@ void Compute::SetupQueue(VkDevice& device)
244
250
std::cout << " Pipeline layout creation failed" << std::cout;
245
251
}
246
252
247
- /* VkComputePipelineCreateInfo pipelineCreateInfo = {};
253
+ VkComputePipelineCreateInfo pipelineCreateInfo = {};
248
254
pipelineCreateInfo.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO;
249
255
pipelineCreateInfo.stage = shaderStageCreateInfo;
250
256
pipelineCreateInfo.layout = pipelineLayout;
@@ -253,7 +259,7 @@ void Compute::SetupQueue(VkDevice& device)
253
259
254
260
VkCommandPoolCreateInfo cmdPoolInfo = {};
255
261
cmdPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
256
- cmdPoolInfo.queueFamilyIndex = computeQueueFamilyId ;
262
+ cmdPoolInfo.queueFamilyIndex = queueFamilyId ;
257
263
cmdPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
258
264
result = vkCreateCommandPool (device, &cmdPoolInfo, nullptr , &commandPool);
259
265
@@ -265,15 +271,13 @@ void Compute::SetupQueue(VkDevice& device)
265
271
266
272
vkAllocateCommandBuffers (device, &cmdBufAllocInfo, &commandBuffer);
267
273
268
- VkFence fence;
269
-
270
- VkFenceCreateInfo fenceCreateInfo;
274
+ VkFenceCreateInfo fenceCreateInfo = {};
271
275
fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
272
276
fenceCreateInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
273
- vkCreateFence(device, &fenceCreateInfo, nullptr, &fence);*/
277
+ vkCreateFence (device, &fenceCreateInfo, nullptr , &fence);
274
278
}
275
279
276
- VkCommandBuffer* Compute::SetupCommandBuffer (VkDevice& device, uint32_t graphicsQueueFamilyId, uint32_t computeQueueFamilyId )
280
+ VkCommandBuffer* Compute::SetupCommandBuffer (VkDevice& device, uint32_t queueFamilyId )
277
281
{
278
282
VkCommandBufferBeginInfo beginInfo = {};
279
283
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
@@ -286,15 +290,15 @@ VkCommandBuffer* Compute::SetupCommandBuffer(VkDevice& device, uint32_t graphics
286
290
throw std::runtime_error (" Compute command buffer beign failed" );
287
291
}
288
292
289
- /* memoryBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER ;
290
- memoryBarrier.buffer = storageBuffer;
291
- memoryBarrier.size = storageBufferSize;
292
- memoryBarrier.srcAccessMask = VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT;
293
- memoryBarrier.dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
294
- memoryBarrier.srcQueueFamilyIndex = graphicsQueueFamilyId;
295
- memoryBarrier.dstQueueFamilyIndex = computeQueueFamilyId;
293
+ // memoryBarrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER ;
294
+ // memoryBarrier.buffer = storageBuffer;
295
+ // memoryBarrier.size = storageBufferSize;
296
+ // memoryBarrier.srcAccessMask = VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT;
297
+ // memoryBarrier.dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
298
+ // memoryBarrier.srcQueueFamilyIndex = graphicsQueueFamilyId;
299
+ // memoryBarrier.dstQueueFamilyIndex = computeQueueFamilyId;
296
300
297
- vkCmdPipelineBarrier(commandBuffer,
301
+ /* vkCmdPipelineBarrier(commandBuffer,
298
302
VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,
299
303
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
300
304
0,
@@ -306,20 +310,21 @@ VkCommandBuffer* Compute::SetupCommandBuffer(VkDevice& device, uint32_t graphics
306
310
vkCmdBindDescriptorSets (commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout, 0 , 1 , &descriptorSet, 0 , 0 );
307
311
vkCmdDispatch (commandBuffer, extent.width , extent.height , 1 );
308
312
309
- /* memoryBarrier.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
313
+ memoryBarrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
314
+ memoryBarrier.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
310
315
memoryBarrier.dstAccessMask = VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT;
311
316
memoryBarrier.buffer = storageBuffer;
312
317
memoryBarrier.size = storageBufferSize;
313
- memoryBarrier.srcQueueFamilyIndex = computeQueueFamilyId ;
314
- memoryBarrier.dstQueueFamilyIndex = graphicsQueueFamilyId ;
318
+ memoryBarrier.srcQueueFamilyIndex = queueFamilyId ;
319
+ memoryBarrier.dstQueueFamilyIndex = queueFamilyId ;
315
320
316
321
vkCmdPipelineBarrier (commandBuffer,
317
322
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
318
323
VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,
319
324
0 ,
320
325
0 , nullptr ,
321
326
1 , &memoryBarrier,
322
- 0, nullptr);*/
327
+ 0 , nullptr );
323
328
324
329
vkEndCommandBuffer (commandBuffer);
325
330
0 commit comments