@@ -359,10 +359,18 @@ class VulkanBuffer : public offloadtest::Buffer {
359359
360360class VulkanQueue : public offloadtest ::Queue {
361361public:
362+ using Queue::submit;
363+
362364 VkQueue Queue = VK_NULL_HANDLE;
363365 uint32_t QueueFamilyIdx = 0 ;
364- VulkanQueue (VkQueue Q, uint32_t QueueFamilyIdx)
365- : Queue(Q), QueueFamilyIdx(QueueFamilyIdx) {}
366+ // TODO: Ensure device lifetime is managed (e.g. via shared_ptr).
367+ VkDevice Device = VK_NULL_HANDLE;
368+ VulkanQueue (VkQueue Q, uint32_t QueueFamilyIdx, VkDevice Device)
369+ : Queue(Q), QueueFamilyIdx(QueueFamilyIdx), Device(Device) {}
370+
371+ llvm::Error submit (
372+ llvm::SmallVectorImpl<std::unique_ptr<offloadtest::CommandBuffer>> &CBs)
373+ override ;
366374};
367375
368376class VulkanCommandBuffer : public offloadtest ::CommandBuffer {
@@ -491,6 +499,38 @@ VulkanCommandBuffer::createComputeEncoder(offloadtest::EncoderMode Mode) {
491499 return std::make_unique<VKComputeEncoder>(*this , Mode);
492500}
493501
502+ llvm::Error VulkanQueue::submit (
503+ llvm::SmallVectorImpl<std::unique_ptr<offloadtest::CommandBuffer>> &CBs) {
504+ for (auto &CB : CBs) {
505+ auto &VCB = CB->as <VulkanCommandBuffer>();
506+ if (vkEndCommandBuffer (VCB.CmdBuffer ))
507+ return llvm::createStringError (std::errc::device_or_resource_busy,
508+ " Could not end command buffer." );
509+
510+ VkSubmitInfo SubmitInfo = {};
511+ SubmitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
512+ SubmitInfo.commandBufferCount = 1 ;
513+ SubmitInfo.pCommandBuffers = &VCB.CmdBuffer ;
514+
515+ VkFenceCreateInfo FenceInfo = {};
516+ FenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
517+ VkFence Fence;
518+ if (vkCreateFence (Device, &FenceInfo, nullptr , &Fence))
519+ return llvm::createStringError (std::errc::device_or_resource_busy,
520+ " Could not create fence." );
521+
522+ if (vkQueueSubmit (Queue, 1 , &SubmitInfo, Fence))
523+ return llvm::createStringError (std::errc::device_or_resource_busy,
524+ " Failed to submit to queue." );
525+ if (vkWaitForFences (Device, 1 , &Fence, VK_TRUE, UINT64_MAX))
526+ return llvm::createStringError (std::errc::device_or_resource_busy,
527+ " Failed waiting for fence." );
528+
529+ vkDestroyFence (Device, Fence, nullptr );
530+ }
531+ return llvm::Error::success ();
532+ }
533+
494534class VulkanDevice : public offloadtest ::Device {
495535private:
496536 VkPhysicalDevice PhysicalDevice;
@@ -685,7 +725,8 @@ class VulkanDevice : public offloadtest::Device {
685725 VkQueue DeviceQueue = VK_NULL_HANDLE;
686726 vkGetDeviceQueue (Device, QueueFamilyIdx, 0 , &DeviceQueue);
687727
688- const VulkanQueue GraphicsQueue = VulkanQueue (DeviceQueue, QueueFamilyIdx);
728+ const VulkanQueue GraphicsQueue =
729+ VulkanQueue (DeviceQueue, QueueFamilyIdx, Device);
689730
690731 return std::make_shared<VulkanDevice>(PhysicalDevice, Props, Device,
691732 std::move (GraphicsQueue),
@@ -1208,34 +1249,8 @@ class VulkanDevice : public offloadtest::Device {
12081249 return llvm::Error::success ();
12091250 }
12101251
1211- llvm::Error executeCommandBuffer (InvocationState &IS,
1212- VkPipelineStageFlags WaitMask = 0 ) {
1213- if (vkEndCommandBuffer (IS.CB ->CmdBuffer ))
1214- return llvm::createStringError (std::errc::device_or_resource_busy,
1215- " Could not end command buffer." );
1216-
1217- VkSubmitInfo SubmitInfo = {};
1218- SubmitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1219- SubmitInfo.commandBufferCount = 1 ;
1220- SubmitInfo.pCommandBuffers = &IS.CB ->CmdBuffer ;
1221- SubmitInfo.pWaitDstStageMask = &WaitMask;
1222- VkFenceCreateInfo FenceInfo = {};
1223- FenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1224- VkFence Fence;
1225- if (vkCreateFence (Device, &FenceInfo, nullptr , &Fence))
1226- return llvm::createStringError (std::errc::device_or_resource_busy,
1227- " Could not create fence." );
1228-
1229- // Submit to the queue
1230- if (vkQueueSubmit (GraphicsQueue.Queue , 1 , &SubmitInfo, Fence))
1231- return llvm::createStringError (std::errc::device_or_resource_busy,
1232- " Failed to submit to queue." );
1233- if (vkWaitForFences (Device, 1 , &Fence, VK_TRUE, UINT64_MAX))
1234- return llvm::createStringError (std::errc::device_or_resource_busy,
1235- " Failed waiting for fence." );
1236-
1237- vkDestroyFence (Device, Fence, nullptr );
1238- return llvm::Error::success ();
1252+ llvm::Error executeCommandBuffer (InvocationState &IS) {
1253+ return GraphicsQueue.submit (std::move (IS.CB ));
12391254 }
12401255
12411256 llvm::Error createDescriptorPool (Pipeline &P, InvocationState &IS) {
@@ -2414,7 +2429,7 @@ class VulkanDevice : public offloadtest::Device {
24142429 if (auto Err = createCommands (P, State))
24152430 return Err;
24162431 llvm::outs () << " Commands created.\n " ;
2417- if (auto Err = executeCommandBuffer (State, VK_PIPELINE_STAGE_TRANSFER_BIT ))
2432+ if (auto Err = executeCommandBuffer (State))
24182433 return Err;
24192434 llvm::outs () << " Executed compute command buffer.\n " ;
24202435 if (auto Err = readBackData (P, State))
0 commit comments