| 1 |
/* |
| 2 |
* Copyright 2022 Google LLC |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "src/gpu/graphite/vk/VulkanQueueManager.h" |
| 9 |
|
| 10 |
#include "src/gpu/graphite/GpuWorkSubmission.h" |
| 11 |
#include "src/gpu/graphite/vk/VulkanCommandBuffer.h" |
| 12 |
#include "src/gpu/graphite/vk/VulkanResourceProvider.h" |
| 13 |
#include "src/gpu/graphite/vk/VulkanSharedContext.h" |
| 14 |
|
| 15 |
namespace skgpu::graphite { |
| 16 |
|
| 17 |
VulkanQueueManager::VulkanQueueManager(VkQueue queue, const SharedContext* sharedContext) |
| 18 |
: QueueManager(sharedContext) |
| 19 |
, fQueue(queue) { |
| 20 |
} |
| 21 |
|
| 22 |
const VulkanSharedContext* VulkanQueueManager::vkSharedContext() const { |
| 23 |
return static_cast<const VulkanSharedContext*>(fSharedContext); |
| 24 |
} |
| 25 |
|
| 26 |
std::unique_ptr<CommandBuffer> VulkanQueueManager::getNewCommandBuffer( |
| 27 |
ResourceProvider* resourceProvider, Protected isProtected) { |
| 28 |
VulkanResourceProvider* vkResourceProvider = |
| 29 |
static_cast<VulkanResourceProvider*>(resourceProvider); |
| 30 |
|
| 31 |
auto cmdBuffer = VulkanCommandBuffer::Make(this->vkSharedContext(), |
| 32 |
vkResourceProvider, |
| 33 |
isProtected); |
| 34 |
return cmdBuffer; |
| 35 |
} |
| 36 |
|
| 37 |
class VulkanWorkSubmission final : public GpuWorkSubmission { |
| 38 |
public: |
| 39 |
VulkanWorkSubmission(std::unique_ptr<CommandBuffer> cmdBuffer, QueueManager* queueManager) |
| 40 |
: GpuWorkSubmission(std::move(cmdBuffer), queueManager) {} |
| 41 |
~VulkanWorkSubmission() override {} |
| 42 |
|
| 43 |
private: |
| 44 |
bool onIsFinished(const SharedContext*) override { |
| 45 |
return static_cast<VulkanCommandBuffer*>(this->commandBuffer())->isFinished(); |
| 46 |
} |
| 47 |
void onWaitUntilFinished(const SharedContext*) override { |
| 48 |
return static_cast<VulkanCommandBuffer*>(this->commandBuffer())->waitUntilFinished(); |
| 49 |
} |
| 50 |
}; |
| 51 |
|
| 52 |
QueueManager::OutstandingSubmission VulkanQueueManager::onSubmitToGpu(const SubmitInfo& submitInfo) { |
| 53 |
SkASSERT(fCurrentCommandBuffer); |
| 54 |
VulkanCommandBuffer* vkCmdBuffer = |
| 55 |
static_cast<VulkanCommandBuffer*>(fCurrentCommandBuffer.get()); |
| 56 |
if (!vkCmdBuffer->submit(fQueue, submitInfo)) { |
| 57 |
fCurrentCommandBuffer->callFinishedProcs(/*success=*/false); |
| 58 |
return nullptr; |
| 59 |
} |
| 60 |
|
| 61 |
std::unique_ptr<GpuWorkSubmission> submission( |
| 62 |
new VulkanWorkSubmission(std::move(fCurrentCommandBuffer), this)); |
| 63 |
return submission; |
| 64 |
} |
| 65 |
|
| 66 |
} // namespace skgpu::graphite |