Browse Source

Vk: command pool and buffer reset.

pull/234/head
Vladimír Vondruš 6 years ago
parent
commit
b45c9c310f
  1. 4
      doc/vulkan-mapping.dox
  2. 5
      src/Magnum/Vk/CommandBuffer.cpp
  3. 39
      src/Magnum/Vk/CommandBuffer.h
  4. 4
      src/Magnum/Vk/CommandPool.cpp
  5. 45
      src/Magnum/Vk/CommandPool.h
  6. 19
      src/Magnum/Vk/Test/CommandBufferVkTest.cpp
  7. 12
      src/Magnum/Vk/Test/CommandPoolVkTest.cpp

4
doc/vulkan-mapping.dox

@ -251,8 +251,8 @@ Vulkan function | Matching API
Vulkan function | Matching API
--------------------------------------- | ------------
@fn_vk{ResetCommandBuffer} | |
@fn_vk{ResetCommandPool} | |
@fn_vk{ResetCommandBuffer} | @ref CommandBuffer::reset()
@fn_vk{ResetCommandPool} | @ref CommandPool::reset()
@fn_vk{ResetDescriptorPool} | |
@fn_vk{ResetFences} | |
@fn_vk{ResetQueryPool} @m_class{m-label m-flat m-success} **EXT, 1.2** | |

5
src/Magnum/Vk/CommandBuffer.cpp

@ -27,6 +27,7 @@
#include "Magnum/Vk/Device.h"
#include "Magnum/Vk/Handle.h"
#include "Magnum/Vk/Result.h"
namespace Magnum { namespace Vk {
@ -59,6 +60,10 @@ CommandBuffer& CommandBuffer::operator=(CommandBuffer&& other) noexcept {
return *this;
}
void CommandBuffer::reset(const CommandBufferResetFlags flags) {
MAGNUM_VK_INTERNAL_ASSERT_RESULT((**_device).ResetCommandBuffer(_handle, VkCommandBufferResetFlags(flags)));
}
VkCommandBuffer CommandBuffer::release() {
const VkCommandBuffer handle = _handle;
_handle = nullptr;

39
src/Magnum/Vk/CommandBuffer.h

@ -26,7 +26,7 @@
*/
/** @file
* @brief Class @ref Magnum::Vk::CommandBuffer
* @brief Class @ref Magnum::Vk::CommandBuffer, enum @ref Magnum::Vk::CommandPoolResetFlag, enum set @ref Magnum::Vk::CommandPoolResetFlags
* @m_since_latest
*/
@ -41,6 +41,32 @@
namespace Magnum { namespace Vk {
/**
@brief Command buffer reset flag
@m_since_latest
Wraps @type_vk_keyword{CommandBufferResetFlagBits}.
@m_enum_values_as_keywords
@see @ref CommandBufferResetFlags, @ref CommandBuffer::reset(),
@ref CommandPoolResetFlag, @ref CommandPool::reset()
*/
enum class CommandBufferResetFlag: UnsignedInt {
/** Recycle all resources from the command pool back to the system */
ReleaseResources = VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT
};
/**
@brief Command buffer reset flags
@m_since_latest
Wraps @type_vk_keyword{CommandBufferResetFlags}.
@see @ref CommandBuffer::reset(), @ref CommandPoolResetFlags,
@ref CommandPool::reset()
*/
typedef Containers::EnumSet<CommandBufferResetFlag> CommandBufferResetFlags;
CORRADE_ENUMSET_OPERATORS(CommandBufferResetFlags)
/**
@brief Command buffer
@m_since_latest
@ -103,6 +129,17 @@ class MAGNUM_VK_EXPORT CommandBuffer {
/** @brief Handle flags */
HandleFlags handleFlags() const { return _flags; }
/**
* @brief Reset the command buffer
*
* This operation is allowed only if the originating @ref CommandPool
* was created with @ref CommandPoolCreateInfo::Flag::ResetCommandBuffer.
* If not, the only way to reset is to reset the whole command pool
* using @ref CommandPool::reset().
* @see @fn_vk_keyword{ResetCommandBuffer}
*/
void reset(CommandBufferResetFlags flags = {});
/**
* @brief Release the underlying Vulkan command buffer
*

4
src/Magnum/Vk/CommandPool.cpp

@ -92,6 +92,10 @@ CommandBuffer CommandPool::allocate(const CommandBufferLevel level) {
return out;
}
void CommandPool::reset(const CommandPoolResetFlags flags) {
MAGNUM_VK_INTERNAL_ASSERT_RESULT((**_device).ResetCommandPool(*_device, _handle, VkCommandPoolResetFlags(flags)));
}
VkCommandPool CommandPool::release() {
const VkCommandPool handle = _handle;
_handle = {};

45
src/Magnum/Vk/CommandPool.h

@ -26,7 +26,7 @@
*/
/** @file
* @brief Class @ref Magnum::Vk::CommandPoolCreateInfo, @ref Magnum::Vk::CommandPool, enum @ref Magnum::Vk::CommandBufferLevel
* @brief Class @ref Magnum::Vk::CommandPoolCreateInfo, @ref Magnum::Vk::CommandPool, enum @ref Magnum::Vk::CommandBufferLevel, @ref Magnum::Vk::CommandPoolResetFlag, enum set @ref Magnum::Vk::CommandPoolResetFlags
* @m_since_latest
*/
@ -44,8 +44,8 @@ namespace Magnum { namespace Vk {
@brief Command pool creation info
@m_since_latest
Wraps a @type_vk_keyword{CommandPoolCreateInfo}.
@see @ref CommandPool
Wraps a @type_vk_keyword{CommandPoolCreateInfo}. See @ref CommandPool for usage
information.
*/
class MAGNUM_VK_EXPORT CommandPoolCreateInfo {
public:
@ -62,7 +62,8 @@ class MAGNUM_VK_EXPORT CommandPoolCreateInfo {
/**
* Allow individual command buffers to be reset to initial state
* instead of just the whole pool.
* using @ref CommandBuffer::reset() instead of just the whole pool
* using @ref CommandPool::reset().
*
* @m_class{m-note m-success}
*
@ -146,6 +147,32 @@ enum class CommandBufferLevel: Int {
Secondary = VK_COMMAND_BUFFER_LEVEL_SECONDARY
};
/**
@brief Command buffer reset flag
@m_since_latest
Wraps @type_vk_keyword{CommandPoolResetFlagBits}.
@m_enum_values_as_keywords
@see @ref CommandPoolResetFlags, @ref CommandPool::reset(),
@ref CommandBufferResetFlag, @ref CommandBuffer::reset()
*/
enum class CommandPoolResetFlag: UnsignedInt {
/** Recycle all resources from the command pool back to the system */
ReleaseResources = VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT
};
/**
@brief Command pool reset flags
@m_since_latest
Wraps @type_vk_keyword{CommandPoolResetFlags}.
@see @ref CommandPool::reset(), @ref CommandBufferResetFlags,
@ref CommandBuffer::reset()
*/
typedef Containers::EnumSet<CommandPoolResetFlag> CommandPoolResetFlags;
CORRADE_ENUMSET_OPERATORS(CommandPoolResetFlags)
/**
@brief Command pool
@m_since_latest
@ -222,6 +249,16 @@ class MAGNUM_VK_EXPORT CommandPool {
*/
CommandBuffer allocate(CommandBufferLevel level = CommandBufferLevel::Primary);
/**
* @brief Reset the command pool
*
* All command buffers allocated from this command pool are reset as
* well. See @ref CommandBuffer::reset() for a way to reset a single
* command buffer.
* @see @fn_vk_keyword{ResetCommandPool}
*/
void reset(CommandPoolResetFlags flags = {});
/**
* @brief Release the underlying Vulkan command pool
*

19
src/Magnum/Vk/Test/CommandBufferVkTest.cpp

@ -38,12 +38,16 @@ struct CommandBufferVkTest: VulkanTester {
void construct();
void constructMove();
void wrap();
void reset();
};
CommandBufferVkTest::CommandBufferVkTest() {
addTests({&CommandBufferVkTest::construct,
&CommandBufferVkTest::constructMove,
&CommandBufferVkTest::wrap});
&CommandBufferVkTest::wrap,
&CommandBufferVkTest::reset});
}
void CommandBufferVkTest::construct() {
@ -105,6 +109,19 @@ void CommandBufferVkTest::wrap() {
device()->FreeCommandBuffers(device(), pool, 1, &buffer);
}
void CommandBufferVkTest::reset() {
CommandPool pool{device(), CommandPoolCreateInfo{
deviceProperties().pickQueueFamily(QueueFlag::Graphics),
CommandPoolCreateInfo::Flag::ResetCommandBuffer}};
CommandBuffer a = pool.allocate();
a.reset(CommandBufferResetFlag::ReleaseResources);
/* Does not do anything visible, so just test that it didn't blow up */
CORRADE_VERIFY(true);
}
}}}}
CORRADE_TEST_MAIN(Magnum::Vk::Test::CommandBufferVkTest)

12
src/Magnum/Vk/Test/CommandPoolVkTest.cpp

@ -39,6 +39,7 @@ struct CommandPoolVkTest: VulkanTester {
void constructMove();
void wrap();
void reset();
void allocate();
};
@ -47,6 +48,7 @@ CommandPoolVkTest::CommandPoolVkTest() {
&CommandPoolVkTest::constructMove,
&CommandPoolVkTest::wrap,
&CommandPoolVkTest::reset,
&CommandPoolVkTest::allocate});
}
@ -102,6 +104,16 @@ void CommandPoolVkTest::wrap() {
device()->DestroyCommandPool(device(), pool, nullptr);
}
void CommandPoolVkTest::reset() {
CommandPool pool{device(), CommandPoolCreateInfo{
deviceProperties().pickQueueFamily(QueueFlag::Graphics)}};
pool.reset(CommandPoolResetFlag::ReleaseResources);
/* Does not do anything visible, so just test that it didn't blow up */
CORRADE_VERIFY(true);
}
void CommandPoolVkTest::allocate() {
CommandPool pool{device(), CommandPoolCreateInfo{
deviceProperties().pickQueueFamily(QueueFlag::Graphics)}};

Loading…
Cancel
Save