mirror of https://github.com/mosra/magnum.git
13 changed files with 788 additions and 8 deletions
@ -0,0 +1,131 @@ |
|||||||
|
/*
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||||
|
2020, 2021 Vladimír Vondruš <mosra@centrum.cz> |
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a |
||||||
|
copy of this software and associated documentation files (the "Software"), |
||||||
|
to deal in the Software without restriction, including without limitation |
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||||
|
and/or sell copies of the Software, and to permit persons to whom the |
||||||
|
Software is furnished to do so, subject to the following conditions: |
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included |
||||||
|
in all copies or substantial portions of the Software. |
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||||
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||||
|
DEALINGS IN THE SOFTWARE. |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "DescriptorPool.h" |
||||||
|
#include "DescriptorPoolCreateInfo.h" |
||||||
|
|
||||||
|
#include <Corrade/Containers/ArrayView.h> |
||||||
|
|
||||||
|
#include "Magnum/Vk/Assert.h" |
||||||
|
#include "Magnum/Vk/DescriptorType.h" |
||||||
|
#include "Magnum/Vk/Device.h" |
||||||
|
#include "Magnum/Vk/Result.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Vk { |
||||||
|
|
||||||
|
DescriptorPoolCreateInfo::DescriptorPoolCreateInfo(const UnsignedInt maxSets, const Containers::ArrayView<const std::pair<DescriptorType, UnsignedInt>> poolSizes, const Flags flags): _info{} { |
||||||
|
CORRADE_ASSERT(maxSets, |
||||||
|
"Vk::DescriptorPoolCreateInfo: there has to be at least one set", ); |
||||||
|
CORRADE_ASSERT(poolSizes, |
||||||
|
"Vk::DescriptorPoolCreateInfo: there has to be at least one pool", ); |
||||||
|
|
||||||
|
Containers::ArrayView<VkDescriptorPoolSize> poolSizesCopy; |
||||||
|
_data = Containers::ArrayTuple{ |
||||||
|
{Containers::NoInit, poolSizes.size(), poolSizesCopy} |
||||||
|
}; |
||||||
|
for(std::size_t i = 0; i != poolSizes.size(); ++i) { |
||||||
|
CORRADE_ASSERT(poolSizes[i].second, |
||||||
|
"Vk::DescriptorPoolCreateInfo: pool" << i << "of" << poolSizes[i].first << "has no descriptors", ); |
||||||
|
poolSizesCopy[i].type = VkDescriptorType(poolSizes[i].first); |
||||||
|
poolSizesCopy[i].descriptorCount = poolSizes[i].second; |
||||||
|
} |
||||||
|
|
||||||
|
_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
||||||
|
_info.flags = VkDescriptorPoolCreateFlags(flags); |
||||||
|
_info.maxSets = maxSets; |
||||||
|
_info.poolSizeCount = poolSizesCopy.size(); |
||||||
|
_info.pPoolSizes = poolSizesCopy; |
||||||
|
} |
||||||
|
|
||||||
|
DescriptorPoolCreateInfo::DescriptorPoolCreateInfo(const UnsignedInt maxSets, const std::initializer_list<std::pair<DescriptorType, UnsignedInt>> poolSizes, const Flags flags): DescriptorPoolCreateInfo{maxSets, Containers::arrayView(poolSizes), flags} {} |
||||||
|
|
||||||
|
DescriptorPoolCreateInfo::DescriptorPoolCreateInfo(NoInitT) noexcept {} |
||||||
|
|
||||||
|
DescriptorPoolCreateInfo::DescriptorPoolCreateInfo(const VkDescriptorPoolCreateInfo& info): |
||||||
|
/* Can't use {} with GCC 4.8 here because it tries to initialize the first
|
||||||
|
member instead of doing a copy */ |
||||||
|
_info(info) {} |
||||||
|
|
||||||
|
DescriptorPoolCreateInfo::DescriptorPoolCreateInfo(DescriptorPoolCreateInfo&& other) noexcept: |
||||||
|
/* Can't use {} with GCC 4.8 here because it tries to initialize the first
|
||||||
|
member instead of doing a copy */ |
||||||
|
_info(other._info), |
||||||
|
_data{std::move(other._data)} |
||||||
|
{ |
||||||
|
/* Ensure the previous instance doesn't reference state that's now ours */ |
||||||
|
/** @todo this is now more like a destructible move, do it more selectively
|
||||||
|
and clear only what's really ours and not external? */ |
||||||
|
other._info.pNext = nullptr; |
||||||
|
other._info.poolSizeCount = 0; |
||||||
|
other._info.pPoolSizes = nullptr; |
||||||
|
} |
||||||
|
|
||||||
|
DescriptorPoolCreateInfo::~DescriptorPoolCreateInfo() = default; |
||||||
|
|
||||||
|
DescriptorPoolCreateInfo& DescriptorPoolCreateInfo::operator=(DescriptorPoolCreateInfo&& other) noexcept { |
||||||
|
using std::swap; |
||||||
|
swap(other._info, _info); |
||||||
|
swap(other._data, _data); |
||||||
|
return *this; |
||||||
|
} |
||||||
|
|
||||||
|
DescriptorPool DescriptorPool::wrap(Device& device, const VkDescriptorPool handle, const HandleFlags flags) { |
||||||
|
DescriptorPool out{NoCreate}; |
||||||
|
out._device = &device; |
||||||
|
out._handle = handle; |
||||||
|
out._flags = flags; |
||||||
|
return out; |
||||||
|
} |
||||||
|
|
||||||
|
DescriptorPool::DescriptorPool(Device& device, const DescriptorPoolCreateInfo& info): _device{&device}, _flags{HandleFlag::DestroyOnDestruction} { |
||||||
|
MAGNUM_VK_INTERNAL_ASSERT_SUCCESS(device->CreateDescriptorPool(device, info, nullptr, &_handle)); |
||||||
|
} |
||||||
|
|
||||||
|
DescriptorPool::DescriptorPool(NoCreateT): _device{}, _handle{} {} |
||||||
|
|
||||||
|
DescriptorPool::DescriptorPool(DescriptorPool&& other) noexcept: _device{other._device}, _handle{other._handle}, _flags{other._flags} { |
||||||
|
other._handle = {}; |
||||||
|
} |
||||||
|
|
||||||
|
DescriptorPool::~DescriptorPool() { |
||||||
|
if(_handle && (_flags & HandleFlag::DestroyOnDestruction)) |
||||||
|
(**_device).DestroyDescriptorPool(*_device, _handle, nullptr); |
||||||
|
} |
||||||
|
|
||||||
|
DescriptorPool& DescriptorPool::operator=(DescriptorPool&& other) noexcept { |
||||||
|
using std::swap; |
||||||
|
swap(other._device, _device); |
||||||
|
swap(other._handle, _handle); |
||||||
|
swap(other._flags, _flags); |
||||||
|
return *this; |
||||||
|
} |
||||||
|
|
||||||
|
VkDescriptorPool DescriptorPool::release() { |
||||||
|
const VkDescriptorPool handle = _handle; |
||||||
|
_handle = {}; |
||||||
|
return handle; |
||||||
|
} |
||||||
|
|
||||||
|
}} |
||||||
@ -0,0 +1,144 @@ |
|||||||
|
#ifndef Magnum_Vk_DescriptorPool_h |
||||||
|
#define Magnum_Vk_DescriptorPool_h |
||||||
|
/*
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||||
|
2020, 2021 Vladimír Vondruš <mosra@centrum.cz> |
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a |
||||||
|
copy of this software and associated documentation files (the "Software"), |
||||||
|
to deal in the Software without restriction, including without limitation |
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||||
|
and/or sell copies of the Software, and to permit persons to whom the |
||||||
|
Software is furnished to do so, subject to the following conditions: |
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included |
||||||
|
in all copies or substantial portions of the Software. |
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||||
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||||
|
DEALINGS IN THE SOFTWARE. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** @file
|
||||||
|
* @brief Class @ref Magnum::Vk::DescriptorPool |
||||||
|
* @m_since_latest |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "Magnum/Tags.h" |
||||||
|
#include "Magnum/Vk/Handle.h" |
||||||
|
#include "Magnum/Vk/visibility.h" |
||||||
|
#include "Magnum/Vk/Vk.h" |
||||||
|
#include "Magnum/Vk/Vulkan.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Vk { |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Descriptor pool |
||||||
|
@m_since_latest |
||||||
|
|
||||||
|
Wraps @type_vk_keyword{DescriptorPool}, which is used for allocating descriptor |
||||||
|
sets. |
||||||
|
|
||||||
|
@section Vk-DescriptorPool-creation Descriptor pool creation |
||||||
|
|
||||||
|
The @ref DescriptorPoolCreateInfo class takes a maximum number of descriptor |
||||||
|
sets that can be allocated from a pool and then a list of total available |
||||||
|
descriptor counts for desired @ref DescriptorType "DescriptorTypes". The |
||||||
|
following snippet creates a pool allowing to allocate at most 8 descriptor sets |
||||||
|
with 24 sampler bindings and 16 uniform bindings: |
||||||
|
|
||||||
|
@snippet MagnumVk.cpp DescriptorPool-creation |
||||||
|
*/ |
||||||
|
class MAGNUM_VK_EXPORT DescriptorPool { |
||||||
|
public: |
||||||
|
/**
|
||||||
|
* @brief Wrap existing Vulkan handle |
||||||
|
* @param device Vulkan device the descriptor pool is |
||||||
|
* created on |
||||||
|
* @param handle The @type_vk{DescriptorPool} handle |
||||||
|
* @param flags Handle flags |
||||||
|
* |
||||||
|
* The @p handle is expected to be originating from @p device. Unlike |
||||||
|
* a descriptor pool created using a constructor, the Vulkan descriptor |
||||||
|
* pool is by default not deleted on destruction, use @p flags for |
||||||
|
* different behavior. |
||||||
|
* @see @ref release() |
||||||
|
*/ |
||||||
|
static DescriptorPool wrap(Device& device, VkDescriptorPool handle, HandleFlags flags = {}); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructor |
||||||
|
* @param device Vulkan device to create the descriptor pool on |
||||||
|
* @param info Descriptor pool creation info |
||||||
|
* |
||||||
|
* @see @fn_vk_keyword{CreateDescriptorPool} |
||||||
|
*/ |
||||||
|
explicit DescriptorPool(Device& device, const DescriptorPoolCreateInfo& info); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct without creating the fence |
||||||
|
* |
||||||
|
* The constructed instance is equivalent to moved-from state. Useful |
||||||
|
* in cases where you will overwrite the instance later anyway. Move |
||||||
|
* another object over it to make it useful. |
||||||
|
*/ |
||||||
|
explicit DescriptorPool(NoCreateT); |
||||||
|
|
||||||
|
/** @brief Copying is not allowed */ |
||||||
|
DescriptorPool(const DescriptorPool&) = delete; |
||||||
|
|
||||||
|
/** @brief Move constructor */ |
||||||
|
DescriptorPool(DescriptorPool&& other) noexcept; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Destructor |
||||||
|
* |
||||||
|
* Destroys associated @type_vk{DescriptorPool} handle, unless the |
||||||
|
* instance was created using @ref wrap() without |
||||||
|
* @ref HandleFlag::DestroyOnDestruction specified. |
||||||
|
* @see @fn_vk_keyword{DestroyDescriptorPool}, @ref release() |
||||||
|
*/ |
||||||
|
~DescriptorPool(); |
||||||
|
|
||||||
|
/** @brief Copying is not allowed */ |
||||||
|
DescriptorPool& operator=(const DescriptorPool&) = delete; |
||||||
|
|
||||||
|
/** @brief Move assignment */ |
||||||
|
DescriptorPool& operator=(DescriptorPool&& other) noexcept; |
||||||
|
|
||||||
|
/** @brief Underlying @type_vk{DescriptorPool} handle */ |
||||||
|
VkDescriptorPool handle() { return _handle; } |
||||||
|
/** @overload */ |
||||||
|
operator VkDescriptorPool() { return _handle; } |
||||||
|
|
||||||
|
/** @brief Handle flags */ |
||||||
|
HandleFlags handleFlags() const { return _flags; } |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Release the underlying Vulkan descriptor pool |
||||||
|
* |
||||||
|
* Releases ownership of the Vulkan descriptor pool and returns its |
||||||
|
* handle so @fn_vk{DestroyDescriptorPool} is not called on |
||||||
|
* destruction. The internal state is then equivalent to moved-from |
||||||
|
* state. |
||||||
|
* @see @ref wrap() |
||||||
|
*/ |
||||||
|
VkDescriptorPool release(); |
||||||
|
|
||||||
|
private: |
||||||
|
/* Can't be a reference because of the NoCreate constructor */ |
||||||
|
Device* _device; |
||||||
|
|
||||||
|
VkDescriptorPool _handle; |
||||||
|
HandleFlags _flags; |
||||||
|
}; |
||||||
|
|
||||||
|
}} |
||||||
|
|
||||||
|
#endif |
||||||
@ -0,0 +1,183 @@ |
|||||||
|
#ifndef Magnum_Vk_DescriptorPoolCreateInfo_h |
||||||
|
#define Magnum_Vk_DescriptorPoolCreateInfo_h |
||||||
|
/*
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||||
|
2020, 2021 Vladimír Vondruš <mosra@centrum.cz> |
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a |
||||||
|
copy of this software and associated documentation files (the "Software"), |
||||||
|
to deal in the Software without restriction, including without limitation |
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||||
|
and/or sell copies of the Software, and to permit persons to whom the |
||||||
|
Software is furnished to do so, subject to the following conditions: |
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included |
||||||
|
in all copies or substantial portions of the Software. |
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||||
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||||
|
DEALINGS IN THE SOFTWARE. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** @file
|
||||||
|
* @brief Class @ref Magnum::Vk::DescriptorPoolCreateInfo |
||||||
|
* @m_since_latest |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <utility> |
||||||
|
#include <Corrade/Containers/ArrayTuple.h> |
||||||
|
#include <Corrade/Containers/EnumSet.h> |
||||||
|
|
||||||
|
#include "Magnum/Magnum.h" |
||||||
|
#include "Magnum/Tags.h" |
||||||
|
#include "Magnum/Vk/visibility.h" |
||||||
|
#include "Magnum/Vk/Vk.h" |
||||||
|
#include "Magnum/Vk/Vulkan.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Vk { |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Descriptor pool creation info |
||||||
|
@m_since_latest |
||||||
|
|
||||||
|
Wraps a @type_vk_keyword{DescriptorPoolCreateInfo} and the nested |
||||||
|
@type_vk_keyword{DescriptorPoolSize} structures. See |
||||||
|
@ref Vk-DescriptorPool-creation "Descriptor pool creation" for usage |
||||||
|
information. |
||||||
|
*/ |
||||||
|
class MAGNUM_VK_EXPORT DescriptorPoolCreateInfo { |
||||||
|
public: |
||||||
|
/**
|
||||||
|
* @brief Descriptor pool creation flag |
||||||
|
* |
||||||
|
* Wraps @type_vk_keyword{DescriptorPoolCreateFlagBits}. |
||||||
|
* @see @ref Flags, @ref DescriptorPoolCreateInfo() |
||||||
|
* @m_enum_values_as_keywords |
||||||
|
*/ |
||||||
|
enum class Flag: UnsignedInt { |
||||||
|
/**
|
||||||
|
* Allow individual descriptor sets to be freed instead of just the |
||||||
|
* whole pool. |
||||||
|
* @todoc reference relevant functions once they exist |
||||||
|
* |
||||||
|
* @m_class{m-note m-success} |
||||||
|
* |
||||||
|
* @par |
||||||
|
* Not using this flag may help the driver to use simpler |
||||||
|
* per-pool allocators instead of per-set. Without this flag |
||||||
|
* set, descriptor pool fragmentation can't occur. |
||||||
|
*/ |
||||||
|
FreeDescriptorSet = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, |
||||||
|
|
||||||
|
/**
|
||||||
|
* Descriptor sets allocated from this pool can use bindings with |
||||||
|
* the @ref DescriptorSetLayoutBinding::Flag::UpdateAfterBind set. |
||||||
|
* @requires_vk_feature @ref DeviceFeature::DescriptorBindingSampledImageUpdateAfterBind |
||||||
|
* if used on a @ref DescriptorType::CombinedImageSampler / |
||||||
|
* @relativeref{DescriptorType,SampledImage} |
||||||
|
* @requires_vk_feature @ref DeviceFeature::DescriptorBindingStorageImageUpdateAfterBind |
||||||
|
* if used on a @ref DescriptorType::StorageImage |
||||||
|
* @requires_vk_feature @ref DeviceFeature::DescriptorBindingUniformTexelBufferUpdateAfterBind |
||||||
|
* if used on a @ref DescriptorType::UniformTexelBuffer |
||||||
|
* @requires_vk_feature @ref DeviceFeature::DescriptorBindingStorageTexelBufferUpdateAfterBind |
||||||
|
* if used on a @ref DescriptorType::StorageTexelBuffer |
||||||
|
* @requires_vk_feature @ref DeviceFeature::DescriptorBindingUniformBufferUpdateAfterBind |
||||||
|
* if used on a @ref DescriptorType::UniformBuffer / |
||||||
|
* @relativeref{DescriptorType,UniformBufferDynamic} |
||||||
|
* @requires_vk_feature @ref DeviceFeature::DescriptorBindingStorageBufferUpdateAfterBind |
||||||
|
* if used on a @ref DescriptorType::StorageBuffer / |
||||||
|
* @relativeref{DescriptorType,StorageBufferDynamic} |
||||||
|
*/ |
||||||
|
UpdateAfterBind = VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT |
||||||
|
}; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DescriptorPool creation flags |
||||||
|
* |
||||||
|
* Type-safe wrapper for @type_vk_keyword{DescriptorPoolCreateFlags}. |
||||||
|
* @see @ref DescriptorPoolCreateInfo() |
||||||
|
*/ |
||||||
|
typedef Containers::EnumSet<Flag> Flags; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructor |
||||||
|
* @param maxSets Maximum count of descriptor sets that can be |
||||||
|
* allocated from this pool. Has to be at least one. |
||||||
|
* @param poolSizes Pool sizes for each descriptor type. There has |
||||||
|
* to be at least one, and pool sizes can't be zero. |
||||||
|
* @param flags DescriptorPool creation flags |
||||||
|
* |
||||||
|
* The following @type_vk{DescriptorPoolCreateInfo} fields are |
||||||
|
* pre-filled in addition to `sType`, everything else is zero-filled: |
||||||
|
* |
||||||
|
* - `flags` |
||||||
|
* - `maxSets` |
||||||
|
* - `poolSizeCount` and `pPoolSizes` to @p poolSizes converted to |
||||||
|
* a list of @type_vk{DescriptorPoolSize} structures |
||||||
|
*/ |
||||||
|
explicit DescriptorPoolCreateInfo(UnsignedInt maxSets, Containers::ArrayView<const std::pair<DescriptorType, UnsignedInt>> poolSizes, Flags flags = {}); |
||||||
|
/** @overload */ |
||||||
|
explicit DescriptorPoolCreateInfo(UnsignedInt maxSets, std::initializer_list<std::pair<DescriptorType, UnsignedInt>> poolSizes, Flags flags = {}); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct without initializing the contents |
||||||
|
* |
||||||
|
* Note that not even the `sType` field is set --- the structure has to |
||||||
|
* be fully initialized afterwards in order to be usable. |
||||||
|
*/ |
||||||
|
explicit DescriptorPoolCreateInfo(NoInitT) noexcept; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct from existing data |
||||||
|
* |
||||||
|
* Copies the existing values verbatim, pointers are kept unchanged |
||||||
|
* without taking over the ownership. Modifying the newly created |
||||||
|
* instance will not modify the original data nor the pointed-to data. |
||||||
|
*/ |
||||||
|
explicit DescriptorPoolCreateInfo(const VkDescriptorPoolCreateInfo& info); |
||||||
|
|
||||||
|
/** @brief Copying is not allowed */ |
||||||
|
DescriptorPoolCreateInfo(const DescriptorPoolCreateInfo&) = delete; |
||||||
|
|
||||||
|
/** @brief Move constructor */ |
||||||
|
DescriptorPoolCreateInfo(DescriptorPoolCreateInfo&& other) noexcept; |
||||||
|
|
||||||
|
~DescriptorPoolCreateInfo(); |
||||||
|
|
||||||
|
/** @brief Copying is not allowed */ |
||||||
|
DescriptorPoolCreateInfo& operator=(const DescriptorPoolCreateInfo&) = delete; |
||||||
|
|
||||||
|
/** @brief Move assignment */ |
||||||
|
DescriptorPoolCreateInfo& operator=(DescriptorPoolCreateInfo&& other) noexcept; |
||||||
|
|
||||||
|
/** @brief Underlying @type_vk{DescriptorPoolCreateInfo} structure */ |
||||||
|
VkDescriptorPoolCreateInfo& operator*() { return _info; } |
||||||
|
/** @overload */ |
||||||
|
const VkDescriptorPoolCreateInfo& operator*() const { return _info; } |
||||||
|
/** @overload */ |
||||||
|
VkDescriptorPoolCreateInfo* operator->() { return &_info; } |
||||||
|
/** @overload */ |
||||||
|
const VkDescriptorPoolCreateInfo* operator->() const { return &_info; } |
||||||
|
/** @overload */ |
||||||
|
operator const VkDescriptorPoolCreateInfo*() const { return &_info; } |
||||||
|
|
||||||
|
private: |
||||||
|
VkDescriptorPoolCreateInfo _info; |
||||||
|
Containers::ArrayTuple _data; |
||||||
|
}; |
||||||
|
|
||||||
|
CORRADE_ENUMSET_OPERATORS(DescriptorPoolCreateInfo::Flags) |
||||||
|
|
||||||
|
}} |
||||||
|
|
||||||
|
/* Make the definition complete -- it doesn't make sense to have a CreateInfo
|
||||||
|
without the corresponding object anyway. */ |
||||||
|
#include "Magnum/Vk/DescriptorPool.h" |
||||||
|
|
||||||
|
#endif |
||||||
@ -0,0 +1,183 @@ |
|||||||
|
/*
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||||
|
2020, 2021 Vladimír Vondruš <mosra@centrum.cz> |
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a |
||||||
|
copy of this software and associated documentation files (the "Software"), |
||||||
|
to deal in the Software without restriction, including without limitation |
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||||
|
and/or sell copies of the Software, and to permit persons to whom the |
||||||
|
Software is furnished to do so, subject to the following conditions: |
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included |
||||||
|
in all copies or substantial portions of the Software. |
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||||
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||||
|
DEALINGS IN THE SOFTWARE. |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <new> |
||||||
|
#include <sstream> |
||||||
|
#include <Corrade/TestSuite/Tester.h> |
||||||
|
#include <Corrade/Utility/DebugStl.h> |
||||||
|
|
||||||
|
#include "Magnum/Vk/DescriptorPoolCreateInfo.h" |
||||||
|
#include "Magnum/Vk/DescriptorType.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Vk { namespace Test { namespace { |
||||||
|
|
||||||
|
struct DescriptorPoolTest: TestSuite::Tester { |
||||||
|
explicit DescriptorPoolTest(); |
||||||
|
|
||||||
|
void createInfoConstruct(); |
||||||
|
void createInfoConstructNoSets(); |
||||||
|
void createInfoConstructNoPools(); |
||||||
|
void createInfoConstructEmptyPool(); |
||||||
|
void createInfoConstructNoInit(); |
||||||
|
void createInfoConstructFromVk(); |
||||||
|
void createInfoConstructCopy(); |
||||||
|
void createInfoConstructMove(); |
||||||
|
|
||||||
|
void constructNoCreate(); |
||||||
|
void constructCopy(); |
||||||
|
}; |
||||||
|
|
||||||
|
DescriptorPoolTest::DescriptorPoolTest() { |
||||||
|
addTests({&DescriptorPoolTest::createInfoConstruct, |
||||||
|
&DescriptorPoolTest::createInfoConstructNoSets, |
||||||
|
&DescriptorPoolTest::createInfoConstructNoPools, |
||||||
|
&DescriptorPoolTest::createInfoConstructEmptyPool, |
||||||
|
&DescriptorPoolTest::createInfoConstructNoInit, |
||||||
|
&DescriptorPoolTest::createInfoConstructFromVk, |
||||||
|
&DescriptorPoolTest::createInfoConstructCopy, |
||||||
|
&DescriptorPoolTest::createInfoConstructMove, |
||||||
|
|
||||||
|
&DescriptorPoolTest::constructNoCreate, |
||||||
|
&DescriptorPoolTest::constructCopy}); |
||||||
|
} |
||||||
|
|
||||||
|
void DescriptorPoolTest::createInfoConstruct() { |
||||||
|
DescriptorPoolCreateInfo info{5, { |
||||||
|
{DescriptorType::CombinedImageSampler, 7}, |
||||||
|
{DescriptorType::UniformBuffer, 3} |
||||||
|
}, DescriptorPoolCreateInfo::Flag::FreeDescriptorSet|DescriptorPoolCreateInfo::Flag::UpdateAfterBind}; |
||||||
|
CORRADE_COMPARE(info->flags, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT|VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT); |
||||||
|
CORRADE_COMPARE(info->maxSets, 5); |
||||||
|
CORRADE_COMPARE(info->poolSizeCount, 2); |
||||||
|
CORRADE_VERIFY(info->pPoolSizes); |
||||||
|
CORRADE_COMPARE(info->pPoolSizes[0].type, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER); |
||||||
|
CORRADE_COMPARE(info->pPoolSizes[0].descriptorCount, 7); |
||||||
|
CORRADE_COMPARE(info->pPoolSizes[1].type, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER); |
||||||
|
CORRADE_COMPARE(info->pPoolSizes[1].descriptorCount, 3); |
||||||
|
} |
||||||
|
|
||||||
|
void DescriptorPoolTest::createInfoConstructNoSets() { |
||||||
|
#ifdef CORRADE_NO_ASSERT |
||||||
|
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); |
||||||
|
#endif |
||||||
|
|
||||||
|
std::ostringstream out; |
||||||
|
Error redirectError{&out}; |
||||||
|
DescriptorPoolCreateInfo{0, {}}; |
||||||
|
CORRADE_COMPARE(out.str(), "Vk::DescriptorPoolCreateInfo: there has to be at least one set\n"); |
||||||
|
} |
||||||
|
|
||||||
|
void DescriptorPoolTest::createInfoConstructNoPools() { |
||||||
|
#ifdef CORRADE_NO_ASSERT |
||||||
|
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); |
||||||
|
#endif |
||||||
|
|
||||||
|
std::ostringstream out; |
||||||
|
Error redirectError{&out}; |
||||||
|
DescriptorPoolCreateInfo{5, {}}; |
||||||
|
CORRADE_COMPARE(out.str(), "Vk::DescriptorPoolCreateInfo: there has to be at least one pool\n"); |
||||||
|
} |
||||||
|
|
||||||
|
void DescriptorPoolTest::createInfoConstructEmptyPool() { |
||||||
|
#ifdef CORRADE_NO_ASSERT |
||||||
|
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); |
||||||
|
#endif |
||||||
|
|
||||||
|
std::ostringstream out; |
||||||
|
Error redirectError{&out}; |
||||||
|
DescriptorPoolCreateInfo{5, { |
||||||
|
{DescriptorType::InputAttachment, 2}, |
||||||
|
{DescriptorType::UniformBuffer, 0}, |
||||||
|
}}; |
||||||
|
CORRADE_COMPARE(out.str(), "Vk::DescriptorPoolCreateInfo: pool 1 of Vk::DescriptorType::UniformBuffer has no descriptors\n"); |
||||||
|
} |
||||||
|
|
||||||
|
void DescriptorPoolTest::createInfoConstructNoInit() { |
||||||
|
DescriptorPoolCreateInfo info{NoInit}; |
||||||
|
info->sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2; |
||||||
|
new(&info) DescriptorPoolCreateInfo{NoInit}; |
||||||
|
CORRADE_COMPARE(info->sType, VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2); |
||||||
|
|
||||||
|
CORRADE_VERIFY(std::is_nothrow_constructible<DescriptorPoolCreateInfo, NoInitT>::value); |
||||||
|
|
||||||
|
/* Implicit construction is not allowed */ |
||||||
|
CORRADE_VERIFY(!std::is_convertible<NoInitT, DescriptorPoolCreateInfo>::value); |
||||||
|
} |
||||||
|
|
||||||
|
void DescriptorPoolTest::createInfoConstructFromVk() { |
||||||
|
VkDescriptorPoolCreateInfo vkInfo; |
||||||
|
vkInfo.sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2; |
||||||
|
|
||||||
|
DescriptorPoolCreateInfo info{vkInfo}; |
||||||
|
CORRADE_COMPARE(info->sType, VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2); |
||||||
|
} |
||||||
|
|
||||||
|
void DescriptorPoolTest::createInfoConstructCopy() { |
||||||
|
CORRADE_VERIFY(!std::is_copy_constructible<DescriptorPoolCreateInfo>{}); |
||||||
|
CORRADE_VERIFY(!std::is_copy_assignable<DescriptorPoolCreateInfo>{}); |
||||||
|
} |
||||||
|
|
||||||
|
void DescriptorPoolTest::createInfoConstructMove() { |
||||||
|
DescriptorPoolCreateInfo a{5, { |
||||||
|
{DescriptorType::CombinedImageSampler, 7}, |
||||||
|
{DescriptorType::UniformBuffer, 3} |
||||||
|
}}; |
||||||
|
CORRADE_COMPARE(a->poolSizeCount, 2); |
||||||
|
CORRADE_VERIFY(a->pPoolSizes); |
||||||
|
|
||||||
|
DescriptorPoolCreateInfo b = std::move(a); |
||||||
|
CORRADE_COMPARE(a->poolSizeCount, 0); |
||||||
|
CORRADE_VERIFY(!a->pPoolSizes); |
||||||
|
CORRADE_COMPARE(b->poolSizeCount, 2); |
||||||
|
CORRADE_VERIFY(b->pPoolSizes); |
||||||
|
CORRADE_COMPARE(b->pPoolSizes[1].type, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER); |
||||||
|
|
||||||
|
DescriptorPoolCreateInfo c{VkDescriptorPoolCreateInfo{}}; |
||||||
|
c = std::move(b); |
||||||
|
CORRADE_COMPARE(b->poolSizeCount, 0); |
||||||
|
CORRADE_VERIFY(!b->pPoolSizes); |
||||||
|
CORRADE_COMPARE(c->poolSizeCount, 2); |
||||||
|
CORRADE_VERIFY(c->pPoolSizes); |
||||||
|
CORRADE_COMPARE(c->pPoolSizes[1].type, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER); |
||||||
|
} |
||||||
|
|
||||||
|
void DescriptorPoolTest::constructNoCreate() { |
||||||
|
{ |
||||||
|
DescriptorPool pool{NoCreate}; |
||||||
|
CORRADE_VERIFY(!pool.handle()); |
||||||
|
} |
||||||
|
|
||||||
|
/* Implicit construction is not allowed */ |
||||||
|
CORRADE_VERIFY(!std::is_convertible<NoCreateT, DescriptorPool>::value); |
||||||
|
} |
||||||
|
|
||||||
|
void DescriptorPoolTest::constructCopy() { |
||||||
|
CORRADE_VERIFY(!std::is_copy_constructible<DescriptorPool>{}); |
||||||
|
CORRADE_VERIFY(!std::is_copy_assignable<DescriptorPool>{}); |
||||||
|
} |
||||||
|
|
||||||
|
}}}} |
||||||
|
|
||||||
|
CORRADE_TEST_MAIN(Magnum::Vk::Test::DescriptorPoolTest) |
||||||
@ -0,0 +1,103 @@ |
|||||||
|
/*
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||||
|
2020, 2021 Vladimír Vondruš <mosra@centrum.cz> |
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a |
||||||
|
copy of this software and associated documentation files (the "Software"), |
||||||
|
to deal in the Software without restriction, including without limitation |
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||||
|
and/or sell copies of the Software, and to permit persons to whom the |
||||||
|
Software is furnished to do so, subject to the following conditions: |
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included |
||||||
|
in all copies or substantial portions of the Software. |
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||||
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||||
|
DEALINGS IN THE SOFTWARE. |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "Magnum/Vk/DescriptorPoolCreateInfo.h" |
||||||
|
#include "Magnum/Vk/DescriptorType.h" |
||||||
|
#include "Magnum/Vk/Result.h" |
||||||
|
#include "Magnum/Vk/VulkanTester.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Vk { namespace Test { namespace { |
||||||
|
|
||||||
|
struct DescriptorPoolVkTest: VulkanTester { |
||||||
|
explicit DescriptorPoolVkTest(); |
||||||
|
|
||||||
|
void construct(); |
||||||
|
void constructMove(); |
||||||
|
|
||||||
|
void wrap(); |
||||||
|
}; |
||||||
|
|
||||||
|
DescriptorPoolVkTest::DescriptorPoolVkTest() { |
||||||
|
addTests({&DescriptorPoolVkTest::construct, |
||||||
|
&DescriptorPoolVkTest::constructMove, |
||||||
|
|
||||||
|
&DescriptorPoolVkTest::wrap}); |
||||||
|
} |
||||||
|
|
||||||
|
void DescriptorPoolVkTest::construct() { |
||||||
|
{ |
||||||
|
DescriptorPool pool{device(), DescriptorPoolCreateInfo{5, { |
||||||
|
{DescriptorType::UniformBuffer, 2} |
||||||
|
}}}; |
||||||
|
CORRADE_VERIFY(pool.handle()); |
||||||
|
CORRADE_COMPARE(pool.handleFlags(), HandleFlag::DestroyOnDestruction); |
||||||
|
} |
||||||
|
|
||||||
|
/* Shouldn't crash or anything */ |
||||||
|
CORRADE_VERIFY(true); |
||||||
|
} |
||||||
|
|
||||||
|
void DescriptorPoolVkTest::constructMove() { |
||||||
|
DescriptorPool a{device(), DescriptorPoolCreateInfo{5, { |
||||||
|
{DescriptorType::UniformBuffer, 2} |
||||||
|
}}}; |
||||||
|
VkDescriptorPool handle = a.handle(); |
||||||
|
|
||||||
|
DescriptorPool b = std::move(a); |
||||||
|
CORRADE_VERIFY(!a.handle()); |
||||||
|
CORRADE_COMPARE(b.handle(), handle); |
||||||
|
CORRADE_COMPARE(b.handleFlags(), HandleFlag::DestroyOnDestruction); |
||||||
|
|
||||||
|
DescriptorPool c{NoCreate}; |
||||||
|
c = std::move(b); |
||||||
|
CORRADE_VERIFY(!b.handle()); |
||||||
|
CORRADE_COMPARE(b.handleFlags(), HandleFlags{}); |
||||||
|
CORRADE_COMPARE(c.handle(), handle); |
||||||
|
CORRADE_COMPARE(c.handleFlags(), HandleFlag::DestroyOnDestruction); |
||||||
|
|
||||||
|
CORRADE_VERIFY(std::is_nothrow_move_constructible<DescriptorPool>::value); |
||||||
|
CORRADE_VERIFY(std::is_nothrow_move_assignable<DescriptorPool>::value); |
||||||
|
} |
||||||
|
|
||||||
|
void DescriptorPoolVkTest::wrap() { |
||||||
|
VkDescriptorPool pool{}; |
||||||
|
CORRADE_COMPARE(Result(device()->CreateDescriptorPool(device(), |
||||||
|
DescriptorPoolCreateInfo{5, { |
||||||
|
{DescriptorType::UniformBuffer, 2} |
||||||
|
}}, |
||||||
|
nullptr, &pool)), Result::Success); |
||||||
|
|
||||||
|
auto wrapped = DescriptorPool::wrap(device(), pool, HandleFlag::DestroyOnDestruction); |
||||||
|
CORRADE_COMPARE(wrapped.handle(), pool); |
||||||
|
|
||||||
|
/* Release the handle again, destroy by hand */ |
||||||
|
CORRADE_COMPARE(wrapped.release(), pool); |
||||||
|
CORRADE_VERIFY(!wrapped.handle()); |
||||||
|
device()->DestroyDescriptorPool(device(), pool, nullptr); |
||||||
|
} |
||||||
|
|
||||||
|
}}}} |
||||||
|
|
||||||
|
CORRADE_TEST_MAIN(Magnum::Vk::Test::DescriptorPoolVkTest) |
||||||
Loading…
Reference in new issue