diff --git a/rocclr/runtime/device/pal/palvirtual.cpp b/rocclr/runtime/device/pal/palvirtual.cpp index 1b16da57eb..a0a1e2a2a3 100644 --- a/rocclr/runtime/device/pal/palvirtual.cpp +++ b/rocclr/runtime/device/pal/palvirtual.cpp @@ -314,12 +314,6 @@ void VirtualGPU::Queue::addCmdDoppRef(Pal::IGpuMemory* iMem, bool lastDoppCmd, b } bool VirtualGPU::Queue::flush() { - // Stop commands building - if (Pal::Result::Success != iCmdBuffs_[cmdBufIdSlot_]->End()) { - LogError("PAL failed to finalize a command buffer!"); - return false; - } - if (palMemRefs_.size() != 0) { if (Pal::Result::Success != iDev_->AddGpuMemoryReferences(palMemRefs_.size(), &palMemRefs_[0], iQueue_, @@ -330,6 +324,12 @@ bool VirtualGPU::Queue::flush() { palMemRefs_.clear(); } + // Stop commands building + if (Pal::Result::Success != iCmdBuffs_[cmdBufIdSlot_]->End()) { + LogError("PAL failed to finalize a command buffer!"); + return false; + } + // Reset the fence. PAL will reset OS event if (Pal::Result::Success != iDev_->ResetFences(1, &iCmdFences_[cmdBufIdSlot_])) { LogError("PAL failed to reset a fence!"); @@ -430,6 +430,11 @@ bool VirtualGPU::Queue::waitForEvent(uint id) { return true; } + if (id == cmdBufIdCurrent_) { + // There is an error in the flush() and wait is bogus + return false; + } + uint slotId = id % max_command_buffers_; constexpr bool IbReuse = true; bool result = waifForFence(slotId); @@ -444,7 +449,10 @@ bool VirtualGPU::Queue::isDone(uint id) { if (id == cmdBufIdCurrent_) { // Flush the current command buffer - flush(); + if (!flush()) { + // If flush failed, then exit earlier... + return false; + } } if (Pal::Result::Success != iCmdFences_[id % max_command_buffers_]->GetStatus()) {