xref: /aosp_15_r20/external/skia/src/gpu/graphite/vk/VulkanQueueManager.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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,Protected isProtected)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:
VulkanWorkSubmission(std::unique_ptr<CommandBuffer> cmdBuffer,QueueManager * queueManager)39     VulkanWorkSubmission(std::unique_ptr<CommandBuffer> cmdBuffer, QueueManager* queueManager)
40         : GpuWorkSubmission(std::move(cmdBuffer), queueManager) {}
~VulkanWorkSubmission()41     ~VulkanWorkSubmission() override {}
42 
43 private:
onIsFinished(const SharedContext *)44     bool onIsFinished(const SharedContext*) override {
45         return static_cast<VulkanCommandBuffer*>(this->commandBuffer())->isFinished();
46     }
onWaitUntilFinished(const SharedContext *)47     void onWaitUntilFinished(const SharedContext*) override {
48         return static_cast<VulkanCommandBuffer*>(this->commandBuffer())->waitUntilFinished();
49     }
50 };
51 
onSubmitToGpu()52 QueueManager::OutstandingSubmission VulkanQueueManager::onSubmitToGpu() {
53     SkASSERT(fCurrentCommandBuffer);
54     VulkanCommandBuffer* vkCmdBuffer =
55             static_cast<VulkanCommandBuffer*>(fCurrentCommandBuffer.get());
56     if (!vkCmdBuffer->submit(fQueue)) {
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
67