2016-02-26 13:39:01 +11:00
|
|
|
/*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
* Copyright:
|
2017-09-13 23:26:15 +10:00
|
|
|
* 2016-2017 Danny Robson <danny@nerdcruft.net>
|
2016-02-26 13:39:01 +11:00
|
|
|
*/
|
|
|
|
|
2016-02-24 11:11:41 +11:00
|
|
|
#include "./command_buffer.hpp"
|
|
|
|
|
|
|
|
#include "./event.hpp"
|
|
|
|
#include "./pipeline.hpp"
|
|
|
|
|
2016-06-29 18:03:11 +10:00
|
|
|
#include <cruft/util/cast.hpp>
|
|
|
|
|
2017-05-26 16:30:48 +10:00
|
|
|
using cruft::vk::command_buffer;
|
2016-02-24 11:11:41 +11:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
void
|
|
|
|
command_buffer::reset (VkCommandBufferResetFlags flags)
|
|
|
|
{
|
2017-09-08 17:11:35 +10:00
|
|
|
auto err = vkResetCommandBuffer (native (), flags);
|
2016-02-24 11:11:41 +11:00
|
|
|
error::try_code (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
void
|
|
|
|
command_buffer::begin (const VkCommandBufferBeginInfo &info)
|
|
|
|
{
|
2017-09-08 17:11:35 +10:00
|
|
|
auto err = vkBeginCommandBuffer (native (), &info);
|
2016-02-24 11:11:41 +11:00
|
|
|
error::try_code (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
command_buffer::begin (const VkRenderPassBeginInfo &info, VkSubpassContents contents)
|
|
|
|
{
|
2017-09-08 17:11:35 +10:00
|
|
|
vkCmdBeginRenderPass (native (), &info, contents);
|
2016-02-24 11:11:41 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
command_buffer::end (void)
|
|
|
|
{
|
2017-09-08 17:11:35 +10:00
|
|
|
auto err = vkEndCommandBuffer (native ());
|
2016-02-24 11:11:41 +11:00
|
|
|
error::try_code (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
command_buffer::end_pass (void)
|
|
|
|
{
|
2017-09-08 17:11:35 +10:00
|
|
|
vkCmdEndRenderPass (native ());
|
2016-02-24 11:11:41 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
template <size_t N>
|
|
|
|
void
|
|
|
|
command_buffer::execute (const command_buffer (&buffers)[N])
|
|
|
|
{
|
2017-09-08 17:11:35 +10:00
|
|
|
vkCmdExecuteCOmmands (native (), N, buffers);
|
2016-02-24 11:11:41 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
command_buffer::next_subpass (const VkSubpassContents contents)
|
|
|
|
{
|
2017-09-08 17:11:35 +10:00
|
|
|
vkCmdNextSubpass (native (), contents);
|
2016-02-24 11:11:41 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2017-09-12 14:24:04 +10:00
|
|
|
template <cruft::vk::bindpoint BindpointV>
|
2016-02-24 11:11:41 +11:00
|
|
|
void
|
2017-09-12 14:24:04 +10:00
|
|
|
command_buffer::bind (const pipeline<BindpointV> &p)
|
2016-02-24 11:11:41 +11:00
|
|
|
{
|
2017-09-12 14:24:04 +10:00
|
|
|
vkCmdBindPipeline (native (), static_cast<VkPipelineBindPoint> (BindpointV), p.native ());
|
2016-02-24 11:11:41 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-12 14:24:04 +10:00
|
|
|
template void command_buffer::bind(const pipeline<bindpoint::GRAPHICS>&);
|
|
|
|
template void command_buffer::bind(const pipeline<bindpoint::COMPUTE>&);
|
|
|
|
|
|
|
|
|
2016-02-24 11:11:41 +11:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
void
|
|
|
|
command_buffer::set (const event &ev, VkPipelineStageFlags flags)
|
|
|
|
{
|
2017-09-08 17:11:35 +10:00
|
|
|
vkCmdSetEvent (native (), ev.native (), flags);
|
2016-02-24 11:11:41 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
command_buffer::reset (const event &ev, VkPipelineStageFlags flags)
|
|
|
|
{
|
2017-09-08 17:11:35 +10:00
|
|
|
vkCmdResetEvent (native (), ev.native (), flags);
|
2016-02-24 11:11:41 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
command_buffer::wait (util::view<const event*> events,
|
|
|
|
VkPipelineStageFlags src_mask,
|
|
|
|
VkPipelineStageFlags dst_mask,
|
|
|
|
util::view<const VkMemoryBarrier*> VkMemoryBarriers,
|
|
|
|
util::view<const VkBufferMemoryBarrier*> VkBufferMemoryBarriers,
|
|
|
|
util::view<const VkImageMemoryBarrier*> VkImageMemoryBarriers)
|
|
|
|
{
|
2018-01-16 15:12:54 +11:00
|
|
|
vkCmdWaitEvents (
|
|
|
|
native (),
|
|
|
|
util::cast::lossless<uint32_t> (events.size ()), &events.cbegin ()->native (),
|
|
|
|
src_mask, dst_mask,
|
|
|
|
util::cast::lossless<uint32_t> (VkMemoryBarriers.size ()), VkMemoryBarriers.cbegin (),
|
|
|
|
util::cast::lossless<uint32_t> (VkBufferMemoryBarriers.size ()), VkBufferMemoryBarriers.cbegin (),
|
|
|
|
util::cast::lossless<uint32_t> (VkImageMemoryBarriers.size ()), VkImageMemoryBarriers.cbegin ());
|
2016-02-24 11:11:41 +11:00
|
|
|
}
|