@@ -358,10 +358,18 @@ class VulkanBuffer : public offloadtest::Buffer {
358358
359359class VulkanQueue : public offloadtest ::Queue {
360360public:
361+ using Queue::submit;
362+
361363 VkQueue Queue = VK_NULL_HANDLE;
362364 uint32_t QueueFamilyIdx = 0 ;
363- VulkanQueue (VkQueue Q, uint32_t QueueFamilyIdx)
364- : Queue(Q), QueueFamilyIdx(QueueFamilyIdx) {}
365+ // TODO: Ensure device lifetime is managed (e.g. via shared_ptr).
366+ VkDevice Device = VK_NULL_HANDLE;
367+ VulkanQueue (VkQueue Q, uint32_t QueueFamilyIdx, VkDevice Device)
368+ : Queue(Q), QueueFamilyIdx(QueueFamilyIdx), Device(Device) {}
369+
370+ llvm::Error
371+ submit (llvm::SmallVector<std::unique_ptr<offloadtest::CommandBuffer>> CBs)
372+ override ;
365373};
366374
367375class VulkanCommandBuffer : public offloadtest ::CommandBuffer {
@@ -414,6 +422,37 @@ class VulkanCommandBuffer : public offloadtest::CommandBuffer {
414422 VulkanCommandBuffer () : CommandBuffer(GPUAPI::Vulkan) {}
415423};
416424
425+ llvm::Error VulkanQueue::submit (
426+ llvm::SmallVector<std::unique_ptr<offloadtest::CommandBuffer>> CBs) {
427+ for (auto &CB : CBs) {
428+ auto &VCB = CB->as <VulkanCommandBuffer>();
429+ if (vkEndCommandBuffer (VCB.CmdBuffer ))
430+ return llvm::createStringError (std::errc::device_or_resource_busy,
431+ " Could not end command buffer." );
432+
433+ VkSubmitInfo SubmitInfo = {};
434+ SubmitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
435+ SubmitInfo.commandBufferCount = 1 ;
436+ SubmitInfo.pCommandBuffers = &VCB.CmdBuffer ;
437+
438+ VkFenceCreateInfo FenceInfo = {};
439+ FenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
440+ VkFence Fence;
441+ if (vkCreateFence (Device, &FenceInfo, nullptr , &Fence))
442+ return llvm::createStringError (std::errc::device_or_resource_busy,
443+ " Could not create fence." );
444+
445+ if (vkQueueSubmit (Queue, 1 , &SubmitInfo, Fence))
446+ return llvm::createStringError (std::errc::device_or_resource_busy,
447+ " Failed to submit to queue." );
448+ if (vkWaitForFences (Device, 1 , &Fence, VK_TRUE, UINT64_MAX))
449+ return llvm::createStringError (std::errc::device_or_resource_busy,
450+ " Failed waiting for fence." );
451+
452+ vkDestroyFence (Device, Fence, nullptr );
453+ }
454+ return llvm::Error::success ();
455+ }
417456class VulkanDevice : public offloadtest ::Device {
418457private:
419458 VkPhysicalDevice PhysicalDevice;
@@ -608,7 +647,8 @@ class VulkanDevice : public offloadtest::Device {
608647 VkQueue DeviceQueue = VK_NULL_HANDLE;
609648 vkGetDeviceQueue (Device, QueueFamilyIdx, 0 , &DeviceQueue);
610649
611- const VulkanQueue GraphicsQueue = VulkanQueue (DeviceQueue, QueueFamilyIdx);
650+ const VulkanQueue GraphicsQueue =
651+ VulkanQueue (DeviceQueue, QueueFamilyIdx, Device);
612652
613653 return std::make_shared<VulkanDevice>(PhysicalDevice, Props, Device,
614654 std::move (GraphicsQueue),
@@ -1131,34 +1171,8 @@ class VulkanDevice : public offloadtest::Device {
11311171 return llvm::Error::success ();
11321172 }
11331173
1134- llvm::Error executeCommandBuffer (InvocationState &IS,
1135- VkPipelineStageFlags WaitMask = 0 ) {
1136- if (vkEndCommandBuffer (IS.CB ->CmdBuffer ))
1137- return llvm::createStringError (std::errc::device_or_resource_busy,
1138- " Could not end command buffer." );
1139-
1140- VkSubmitInfo SubmitInfo = {};
1141- SubmitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1142- SubmitInfo.commandBufferCount = 1 ;
1143- SubmitInfo.pCommandBuffers = &IS.CB ->CmdBuffer ;
1144- SubmitInfo.pWaitDstStageMask = &WaitMask;
1145- VkFenceCreateInfo FenceInfo = {};
1146- FenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1147- VkFence Fence;
1148- if (vkCreateFence (Device, &FenceInfo, nullptr , &Fence))
1149- return llvm::createStringError (std::errc::device_or_resource_busy,
1150- " Could not create fence." );
1151-
1152- // Submit to the queue
1153- if (vkQueueSubmit (GraphicsQueue.Queue , 1 , &SubmitInfo, Fence))
1154- return llvm::createStringError (std::errc::device_or_resource_busy,
1155- " Failed to submit to queue." );
1156- if (vkWaitForFences (Device, 1 , &Fence, VK_TRUE, UINT64_MAX))
1157- return llvm::createStringError (std::errc::device_or_resource_busy,
1158- " Failed waiting for fence." );
1159-
1160- vkDestroyFence (Device, Fence, nullptr );
1161- return llvm::Error::success ();
1174+ llvm::Error executeCommandBuffer (InvocationState &IS) {
1175+ return GraphicsQueue.submit (std::move (IS.CB ));
11621176 }
11631177
11641178 llvm::Error createDescriptorPool (Pipeline &P, InvocationState &IS) {
@@ -2333,7 +2347,7 @@ class VulkanDevice : public offloadtest::Device {
23332347 if (auto Err = createCommands (P, State))
23342348 return Err;
23352349 llvm::outs () << " Commands created.\n " ;
2336- if (auto Err = executeCommandBuffer (State, VK_PIPELINE_STAGE_TRANSFER_BIT ))
2350+ if (auto Err = executeCommandBuffer (State))
23372351 return Err;
23382352 llvm::outs () << " Executed compute command buffer.\n " ;
23392353 if (auto Err = readBackData (P, State))
0 commit comments