@@ -393,10 +393,18 @@ class VulkanBuffer : public offloadtest::Buffer {
393393
394394class VulkanQueue : public offloadtest ::Queue {
395395public:
396+ using Queue::submit;
397+
396398 VkQueue Queue = VK_NULL_HANDLE;
397399 uint32_t QueueFamilyIdx = 0 ;
398- VulkanQueue (VkQueue Q, uint32_t QueueFamilyIdx)
399- : Queue(Q), QueueFamilyIdx(QueueFamilyIdx) {}
400+ // TODO: Ensure device lifetime is managed (e.g. via shared_ptr).
401+ VkDevice Device = VK_NULL_HANDLE;
402+ VulkanQueue (VkQueue Q, uint32_t QueueFamilyIdx, VkDevice Device)
403+ : Queue(Q), QueueFamilyIdx(QueueFamilyIdx), Device(Device) {}
404+
405+ llvm::Error
406+ submit (llvm::SmallVector<std::unique_ptr<offloadtest::CommandBuffer>> CBs)
407+ override ;
400408};
401409
402410class VulkanCommandBuffer : public offloadtest ::CommandBuffer {
@@ -449,6 +457,37 @@ class VulkanCommandBuffer : public offloadtest::CommandBuffer {
449457 VulkanCommandBuffer () : CommandBuffer(GPUAPI::Vulkan) {}
450458};
451459
460+ llvm::Error VulkanQueue::submit (
461+ llvm::SmallVector<std::unique_ptr<offloadtest::CommandBuffer>> CBs) {
462+ for (auto &CB : CBs) {
463+ auto &VCB = CB->as <VulkanCommandBuffer>();
464+ if (vkEndCommandBuffer (VCB.CmdBuffer ))
465+ return llvm::createStringError (std::errc::device_or_resource_busy,
466+ " Could not end command buffer." );
467+
468+ VkSubmitInfo SubmitInfo = {};
469+ SubmitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
470+ SubmitInfo.commandBufferCount = 1 ;
471+ SubmitInfo.pCommandBuffers = &VCB.CmdBuffer ;
472+
473+ VkFenceCreateInfo FenceInfo = {};
474+ FenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
475+ VkFence Fence;
476+ if (vkCreateFence (Device, &FenceInfo, nullptr , &Fence))
477+ return llvm::createStringError (std::errc::device_or_resource_busy,
478+ " Could not create fence." );
479+
480+ if (vkQueueSubmit (Queue, 1 , &SubmitInfo, Fence))
481+ return llvm::createStringError (std::errc::device_or_resource_busy,
482+ " Failed to submit to queue." );
483+ if (vkWaitForFences (Device, 1 , &Fence, VK_TRUE, UINT64_MAX))
484+ return llvm::createStringError (std::errc::device_or_resource_busy,
485+ " Failed waiting for fence." );
486+
487+ vkDestroyFence (Device, Fence, nullptr );
488+ }
489+ return llvm::Error::success ();
490+ }
452491class VulkanDevice : public offloadtest ::Device {
453492private:
454493 std::shared_ptr<VulkanInstance> Instance;
@@ -645,7 +684,8 @@ class VulkanDevice : public offloadtest::Device {
645684 VkQueue DeviceQueue = VK_NULL_HANDLE;
646685 vkGetDeviceQueue (Device, QueueFamilyIdx, 0 , &DeviceQueue);
647686
648- const VulkanQueue GraphicsQueue = VulkanQueue (DeviceQueue, QueueFamilyIdx);
687+ const VulkanQueue GraphicsQueue =
688+ VulkanQueue (DeviceQueue, QueueFamilyIdx, Device);
649689
650690 return std::make_unique<VulkanDevice>(Instance, PhysicalDevice, Props,
651691 Device, std::move (GraphicsQueue),
@@ -1179,34 +1219,8 @@ class VulkanDevice : public offloadtest::Device {
11791219 return llvm::Error::success ();
11801220 }
11811221
1182- llvm::Error executeCommandBuffer (InvocationState &IS,
1183- VkPipelineStageFlags WaitMask = 0 ) {
1184- if (vkEndCommandBuffer (IS.CB ->CmdBuffer ))
1185- return llvm::createStringError (std::errc::device_or_resource_busy,
1186- " Could not end command buffer." );
1187-
1188- VkSubmitInfo SubmitInfo = {};
1189- SubmitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1190- SubmitInfo.commandBufferCount = 1 ;
1191- SubmitInfo.pCommandBuffers = &IS.CB ->CmdBuffer ;
1192- SubmitInfo.pWaitDstStageMask = &WaitMask;
1193- VkFenceCreateInfo FenceInfo = {};
1194- FenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1195- VkFence Fence;
1196- if (vkCreateFence (Device, &FenceInfo, nullptr , &Fence))
1197- return llvm::createStringError (std::errc::device_or_resource_busy,
1198- " Could not create fence." );
1199-
1200- // Submit to the queue
1201- if (vkQueueSubmit (GraphicsQueue.Queue , 1 , &SubmitInfo, Fence))
1202- return llvm::createStringError (std::errc::device_or_resource_busy,
1203- " Failed to submit to queue." );
1204- if (vkWaitForFences (Device, 1 , &Fence, VK_TRUE, UINT64_MAX))
1205- return llvm::createStringError (std::errc::device_or_resource_busy,
1206- " Failed waiting for fence." );
1207-
1208- vkDestroyFence (Device, Fence, nullptr );
1209- return llvm::Error::success ();
1222+ llvm::Error executeCommandBuffer (InvocationState &IS) {
1223+ return GraphicsQueue.submit (std::move (IS.CB ));
12101224 }
12111225
12121226 llvm::Error createDescriptorPool (Pipeline &P, InvocationState &IS) {
@@ -2392,7 +2406,7 @@ class VulkanDevice : public offloadtest::Device {
23922406 if (auto Err = createCommands (P, State))
23932407 return Err;
23942408 llvm::outs () << " Commands created.\n " ;
2395- if (auto Err = executeCommandBuffer (State, VK_PIPELINE_STAGE_TRANSFER_BIT ))
2409+ if (auto Err = executeCommandBuffer (State))
23962410 return Err;
23972411 llvm::outs () << " Executed compute command buffer.\n " ;
23982412 if (auto Err = readBackData (P, State))
0 commit comments