/* * Copyright 2022 Google LLC * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #include "src/gpu/graphite/vk/VulkanQueueManager.h" #include "src/gpu/graphite/GpuWorkSubmission.h" #include "src/gpu/graphite/vk/VulkanCommandBuffer.h" #include "src/gpu/graphite/vk/VulkanResourceProvider.h" #include "src/gpu/graphite/vk/VulkanSharedContext.h" namespace skgpu::graphite { VulkanQueueManager::VulkanQueueManager(VkQueue queue, const SharedContext* sharedContext) : QueueManager(sharedContext) , fQueue(queue) { } const VulkanSharedContext* VulkanQueueManager::vkSharedContext() const { return static_cast(fSharedContext); } std::unique_ptr VulkanQueueManager::getNewCommandBuffer( ResourceProvider* resourceProvider, Protected isProtected) { VulkanResourceProvider* vkResourceProvider = static_cast(resourceProvider); auto cmdBuffer = VulkanCommandBuffer::Make(this->vkSharedContext(), vkResourceProvider, isProtected); return cmdBuffer; } class VulkanWorkSubmission final : public GpuWorkSubmission { public: VulkanWorkSubmission(std::unique_ptr cmdBuffer, QueueManager* queueManager) : GpuWorkSubmission(std::move(cmdBuffer), queueManager) {} ~VulkanWorkSubmission() override {} private: bool onIsFinished(const SharedContext*) override { return static_cast(this->commandBuffer())->isFinished(); } void onWaitUntilFinished(const SharedContext*) override { return static_cast(this->commandBuffer())->waitUntilFinished(); } }; QueueManager::OutstandingSubmission VulkanQueueManager::onSubmitToGpu() { SkASSERT(fCurrentCommandBuffer); VulkanCommandBuffer* vkCmdBuffer = static_cast(fCurrentCommandBuffer.get()); if (!vkCmdBuffer->submit(fQueue)) { fCurrentCommandBuffer->callFinishedProcs(/*success=*/false); return nullptr; } std::unique_ptr submission( new VulkanWorkSubmission(std::move(fCurrentCommandBuffer), this)); return submission; } } // namespace skgpu::graphite