• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
VulkanQueueManager(VkQueue queue,const SharedContext * sharedContext)17 VulkanQueueManager::VulkanQueueManager(VkQueue queue, const SharedContext* sharedContext)
18         : QueueManager(sharedContext)
19         , fQueue(queue) {
20 }
21 
vkSharedContext() const22 const VulkanSharedContext* VulkanQueueManager::vkSharedContext() const {
23     return static_cast<const VulkanSharedContext*>(fSharedContext);
24 }
25 
getNewCommandBuffer(ResourceProvider * resourceProvider)26 std::unique_ptr<CommandBuffer> VulkanQueueManager::getNewCommandBuffer(
27         ResourceProvider* resourceProvider) {
28     VulkanResourceProvider* vkResourceProvider =
29             static_cast<VulkanResourceProvider*>(resourceProvider);
30 
31     auto cmdBuffer = VulkanCommandBuffer::Make(this->vkSharedContext(), vkResourceProvider);
32     return cmdBuffer;
33 }
34 
35 class VulkanWorkSubmission final : public GpuWorkSubmission {
36 public:
VulkanWorkSubmission(std::unique_ptr<CommandBuffer> cmdBuffer,QueueManager * queueManager)37     VulkanWorkSubmission(std::unique_ptr<CommandBuffer> cmdBuffer, QueueManager* queueManager)
38         : GpuWorkSubmission(std::move(cmdBuffer), queueManager) {}
~VulkanWorkSubmission()39     ~VulkanWorkSubmission() override {}
40 
41 private:
onIsFinished(const SharedContext *)42     bool onIsFinished(const SharedContext*) override {
43         return static_cast<VulkanCommandBuffer*>(this->commandBuffer())->isFinished();
44     }
onWaitUntilFinished(const SharedContext *)45     void onWaitUntilFinished(const SharedContext*) override {
46         return static_cast<VulkanCommandBuffer*>(this->commandBuffer())->waitUntilFinished();
47     }
48 };
49 
onSubmitToGpu()50 QueueManager::OutstandingSubmission VulkanQueueManager::onSubmitToGpu() {
51     SkASSERT(fCurrentCommandBuffer);
52     VulkanCommandBuffer* vkCmdBuffer =
53             static_cast<VulkanCommandBuffer*>(fCurrentCommandBuffer.get());
54     if (!vkCmdBuffer->submit(fQueue)) {
55         fCurrentCommandBuffer->callFinishedProcs(/*success=*/false);
56         return nullptr;
57     }
58 
59     std::unique_ptr<GpuWorkSubmission> submission(
60             new VulkanWorkSubmission(std::move(fCurrentCommandBuffer), this));
61     return submission;
62 }
63 
64 } // namespace skgpu::graphite
65