2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/graphics/vulkan/vulkan-graphics.h>
20 #include <dali/graphics/vulkan/vulkan-command-pool.h>
21 #include <dali/graphics/vulkan/vulkan-command-buffer.h>
32 * Class: CommandPool::Impl
35 struct CommandPool::Impl
37 Impl( Graphics& graphics, CommandPool& interface, const vk::CommandPoolCreateInfo& createInfo )
38 : mGraphics( graphics ),
39 mInterface( interface ),
40 mCreateInfo( createInfo ),
41 mCommandPool( nullptr )
49 mGraphics.GetDevice().destroyCommandPool( mCommandPool, mGraphics.GetAllocator());
55 mCommandPool = VkAssert(mGraphics.GetDevice().createCommandPool(mCreateInfo, mGraphics.GetAllocator()));
59 Handle<CommandBuffer> NewCommandBuffer( const vk::CommandBufferAllocateInfo& allocateInfo )
61 vk::CommandBufferAllocateInfo info( allocateInfo );
62 info.setCommandPool( mCommandPool );
63 info.setCommandBufferCount(1);
64 auto retval = VkAssert( mGraphics.GetDevice().allocateCommandBuffers( info ) );
65 mAllocatedCommandBuffers.emplace_back( new CommandBuffer( mInterface, info, retval[0]) );
66 return mAllocatedCommandBuffers.back();
70 CommandPool& mInterface;
71 vk::CommandPoolCreateInfo mCreateInfo;
72 vk::CommandPool mCommandPool;
74 std::vector<Handle<CommandBuffer>> mAllocatedCommandBuffers;
81 CommandPoolHandle CommandPool::New( Graphics& graphics, const vk::CommandPoolCreateInfo& createInfo )
83 auto retval = Handle<CommandPool>( new CommandPool(graphics, createInfo) );
85 if(retval && retval->mImpl->Initialise())
87 graphics.AddCommandPool( retval );
93 CommandPoolHandle CommandPool::New( Graphics& graphics )
95 return New( graphics, vk::CommandPoolCreateInfo{});
98 CommandPool::CommandPool() = default;
100 CommandPool::CommandPool(Graphics& graphics, const vk::CommandPoolCreateInfo& createInfo)
102 mImpl = MakeUnique<Impl>( graphics, *this, createInfo );
105 CommandPool::~CommandPool() = default;
107 vk::CommandPool CommandPool::GetPool() const
109 return mImpl->mCommandPool;
112 Graphics& CommandPool::GetGraphics() const
114 return mImpl->mGraphics;
117 bool CommandPool::OnDestroy()
122 Handle<CommandBuffer> CommandPool::NewCommandBuffer( const vk::CommandBufferAllocateInfo& allocateInfo )
124 return mImpl->NewCommandBuffer( allocateInfo );
127 Handle<CommandBuffer> CommandPool::NewCommandBuffer( bool isPrimary )
129 return mImpl->NewCommandBuffer( vk::CommandBufferAllocateInfo{}.setLevel(
130 isPrimary ? vk::CommandBufferLevel::ePrimary : vk::CommandBufferLevel::eSecondary
135 } // namespace Vulkan
136 } // namespace Graphics