mirror of https://github.com/mosra/magnum.git
Browse Source
After I implemented the render pass wrapper, seeing how the RenderPassCreateInfo structure and its dependencies were HUGE compared to the actual tiny and lean RenderPass, I felt uneasy dragging their definition along to every place where a RenderPass gets used. It's not as bad with the others, but as new extensions are implemented I expect that to get the same. This change makes it easier for me to accept that Image.h / Buffer.h depends on Memory.h. There isn't a real measurable difference when building Magnum itself (50 ms out of 7 seconds for the Vk library alone), but that's because most of the code (and tests) needs the CreateInfo structures anyway.pull/491/head
48 changed files with 2817 additions and 2328 deletions
@ -0,0 +1,178 @@
|
||||
#ifndef Magnum_Vk_BufferCreateInfo_h |
||||
#define Magnum_Vk_BufferCreateInfo_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020 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::BufferCreateInfo, enum @ref Magnum::Vk::BufferUsage, enum set @ref Magnum::Vk::BufferUsages |
||||
* @m_since_latest |
||||
*/ |
||||
|
||||
#include <Corrade/Containers/EnumSet.h> |
||||
|
||||
#include "Magnum/Magnum.h" |
||||
#include "Magnum/Tags.h" |
||||
#include "Magnum/Vk/Vk.h" |
||||
#include "Magnum/Vk/Vulkan.h" |
||||
#include "Magnum/Vk/visibility.h" |
||||
|
||||
namespace Magnum { namespace Vk { |
||||
|
||||
/**
|
||||
@brief Buffer usage |
||||
@m_since_latest |
||||
|
||||
Wraps a @type_vk_keyword{BufferUsageFlagBits}. |
||||
@see @ref BufferUsages, @ref BufferCreateInfo |
||||
@m_enum_values_as_keywords |
||||
*/ |
||||
enum class BufferUsage: UnsignedInt { |
||||
/** Source of a transfer command */ |
||||
TransferSource = VK_BUFFER_USAGE_TRANSFER_SRC_BIT, |
||||
|
||||
/** Destination of a transfer command */ |
||||
TransferDestination = VK_BUFFER_USAGE_TRANSFER_DST_BIT, |
||||
|
||||
/** Suitable for creating a uniform texel buffer view */ |
||||
UniformTexelBuffer = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, |
||||
|
||||
/** Suitable for creating a storage texel buffer view */ |
||||
StorageTexelBuffer = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, |
||||
|
||||
/** Suitable for a uniform buffer */ |
||||
UniformBuffer = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, |
||||
|
||||
/** Suitable for a storage buffer */ |
||||
StorageBuffer = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, |
||||
|
||||
/** Suitable for an index buffer */ |
||||
IndexBuffer = VK_BUFFER_USAGE_INDEX_BUFFER_BIT, |
||||
|
||||
/** Suitable for a vertex buffer */ |
||||
VertexBuffer = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, |
||||
|
||||
/** Suitable for a indirect draw buffer */ |
||||
IndirectBuffer = VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT, |
||||
|
||||
/** @todo VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, 1.2 */ |
||||
}; |
||||
|
||||
/**
|
||||
@brief Buffer usages |
||||
@m_since_latest |
||||
|
||||
Type-safe wrapper for @type_vk_keyword{BufferUsageFlags}. |
||||
@see @ref BufferCreateInfo |
||||
*/ |
||||
typedef Containers::EnumSet<BufferUsage> BufferUsages; |
||||
|
||||
CORRADE_ENUMSET_OPERATORS(BufferUsages) |
||||
|
||||
/**
|
||||
@brief Buffer creation info |
||||
@m_since_latest |
||||
|
||||
Wraps a @type_vk_keyword{BufferCreateInfo}. See |
||||
@ref Vk-Buffer-creation "Buffer creation" for usage information. |
||||
*/ |
||||
class MAGNUM_VK_EXPORT BufferCreateInfo { |
||||
public: |
||||
/**
|
||||
* @brief Buffer creation flag |
||||
* |
||||
* Wraps @type_vk_keyword{BufferCreateFlagBits}. |
||||
* @see @ref Flags, @ref BufferCreateInfo() |
||||
* @m_enum_values_as_keywords |
||||
*/ |
||||
enum class Flag: UnsignedInt { |
||||
/** @todo sparse binding, protected ... */ |
||||
}; |
||||
|
||||
/**
|
||||
* @brief Buffer creation flags |
||||
* |
||||
* Type-safe wrapper for @type_vk_keyword{BufferCreateFlags}. |
||||
* @see @ref BufferCreateInfo() |
||||
*/ |
||||
typedef Containers::EnumSet<Flag> Flags; |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* @param usages Desired buffer usage. At least one flag is |
||||
* required. |
||||
* @param size Buffer size |
||||
* @param flags Buffer creation flags |
||||
* |
||||
* The following @type_vk{BufferCreateInfo} fields are pre-filled in |
||||
* addition to `sType`, everything else is zero-filled: |
||||
* |
||||
* - `flags` |
||||
* - `size` |
||||
* - `usage` to @p usages |
||||
* - `sharingMode` to @val_vk{SHARING_MODE_EXCLUSIVE,SharingMode} |
||||
*/ |
||||
explicit BufferCreateInfo(BufferUsages usages, UnsignedLong size, 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 BufferCreateInfo(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 BufferCreateInfo(const VkBufferCreateInfo& info); |
||||
|
||||
/** @brief Underlying @type_vk{BufferCreateInfo} structure */ |
||||
VkBufferCreateInfo& operator*() { return _info; } |
||||
/** @overload */ |
||||
const VkBufferCreateInfo& operator*() const { return _info; } |
||||
/** @overload */ |
||||
VkBufferCreateInfo* operator->() { return &_info; } |
||||
/** @overload */ |
||||
const VkBufferCreateInfo* operator->() const { return &_info; } |
||||
/** @overload */ |
||||
operator const VkBufferCreateInfo*() const { return &_info; } |
||||
|
||||
private: |
||||
VkBufferCreateInfo _info; |
||||
}; |
||||
|
||||
CORRADE_ENUMSET_OPERATORS(BufferCreateInfo::Flags) |
||||
|
||||
}} |
||||
|
||||
/* Make the definition complete -- it doesn't make sense to have a CreateInfo
|
||||
without the corresponding object anyway. */ |
||||
#include "Magnum/Vk/Buffer.h" |
||||
|
||||
#endif |
||||
@ -0,0 +1,140 @@
|
||||
#ifndef Magnum_Vk_CommandPoolCreateInfo_h |
||||
#define Magnum_Vk_CommandPoolCreateInfo_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020 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::CommandPoolCreateInfo |
||||
* @m_since_latest |
||||
*/ |
||||
|
||||
#include <Corrade/Containers/EnumSet.h> |
||||
|
||||
#include "Magnum/Tags.h" |
||||
#include "Magnum/Magnum.h" |
||||
#include "Magnum/Vk/Vk.h" |
||||
#include "Magnum/Vk/Vulkan.h" |
||||
#include "Magnum/Vk/visibility.h" |
||||
|
||||
namespace Magnum { namespace Vk { |
||||
|
||||
/**
|
||||
@brief Command pool creation info |
||||
@m_since_latest |
||||
|
||||
Wraps a @type_vk_keyword{CommandPoolCreateInfo}. See |
||||
@ref Vk-CommandPool-creation "Command pool creation" for usage information. |
||||
*/ |
||||
class MAGNUM_VK_EXPORT CommandPoolCreateInfo { |
||||
public: |
||||
/**
|
||||
* @brief Command pool creation flag |
||||
* |
||||
* Wraps @type_vk_keyword{CommandPoolCreateFlagBits}. |
||||
* @see @ref Flags, @ref CommandPoolCreateInfo(UnsignedInt, Flags) |
||||
* @m_enum_values_as_keywords |
||||
*/ |
||||
enum class Flag: UnsignedInt { |
||||
/** Command buffers allocated from this pool will be short-lived */ |
||||
Transient = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, |
||||
|
||||
/**
|
||||
* Allow individual command buffers to be reset to initial state |
||||
* using @ref CommandBuffer::reset() instead of just the whole pool |
||||
* using @ref CommandPool::reset(). |
||||
* |
||||
* @m_class{m-note m-success} |
||||
* |
||||
* @par |
||||
* Not using this flag may help the driver to use simpler |
||||
* per-pool allocators instead of per-buffer. |
||||
*/ |
||||
ResetCommandBuffer = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT |
||||
}; |
||||
|
||||
/**
|
||||
* @brief Command pool creation flags |
||||
* |
||||
* Type-safe wrapper for @type_vk_keyword{CommandPoolCreateFlags}. |
||||
* @see @ref CommandPoolCreateInfo(UnsignedInt, Flags) |
||||
*/ |
||||
typedef Containers::EnumSet<Flag> Flags; |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* @param queueFamilyIndex Queue family index |
||||
* @param flags Command pool creation flags |
||||
* |
||||
* The following @type_vk{CommandPoolCreateInfo} fields are pre-filled |
||||
* in addition to `sType`, everything else is zero-filled: |
||||
* |
||||
* - `flags` |
||||
* - `queueFamilyIndex` |
||||
* |
||||
* @see @ref DeviceProperties::pickQueueFamily() |
||||
*/ |
||||
explicit CommandPoolCreateInfo(UnsignedInt queueFamilyIndex, 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 CommandPoolCreateInfo(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 CommandPoolCreateInfo(const VkCommandPoolCreateInfo& info); |
||||
|
||||
/** @brief Underlying @type_vk{CommandPoolCreateInfo} structure */ |
||||
VkCommandPoolCreateInfo& operator*() { return _info; } |
||||
/** @overload */ |
||||
const VkCommandPoolCreateInfo& operator*() const { return _info; } |
||||
/** @overload */ |
||||
VkCommandPoolCreateInfo* operator->() { return &_info; } |
||||
/** @overload */ |
||||
const VkCommandPoolCreateInfo* operator->() const { return &_info; } |
||||
/** @overload */ |
||||
operator const VkCommandPoolCreateInfo*() const { return &_info; } |
||||
|
||||
private: |
||||
VkCommandPoolCreateInfo _info; |
||||
}; |
||||
|
||||
CORRADE_ENUMSET_OPERATORS(CommandPoolCreateInfo::Flags) |
||||
|
||||
}} |
||||
|
||||
/* Make the definition complete -- it doesn't make sense to have a CreateInfo
|
||||
without the corresponding object anyway. */ |
||||
#include "Magnum/Vk/CommandPool.h" |
||||
|
||||
#endif |
||||
@ -0,0 +1,288 @@
|
||||
#ifndef Magnum_Vk_DeviceCreateInfo_h |
||||
#define Magnum_Vk_DeviceCreateInfo_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020 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::DeviceCreateInfo |
||||
* @m_since_latest |
||||
*/ |
||||
|
||||
#include <cstddef> |
||||
#include <Corrade/Containers/Pointer.h> |
||||
|
||||
#include "Magnum/Tags.h" |
||||
#include "Magnum/Vk/TypeTraits.h" |
||||
#include "Magnum/Vk/Vk.h" |
||||
#include "Magnum/Vk/Vulkan.h" |
||||
#include "Magnum/Vk/visibility.h" |
||||
|
||||
namespace Magnum { namespace Vk { |
||||
|
||||
/**
|
||||
@brief Device creation info |
||||
@m_since_latest |
||||
|
||||
Wraps a @type_vk_keyword{DeviceCreateInfo}. See |
||||
@ref Vk-Device-creation "Device creation" for usage information. |
||||
*/ |
||||
class MAGNUM_VK_EXPORT DeviceCreateInfo { |
||||
public: |
||||
/**
|
||||
* @brief Device creation flag |
||||
* |
||||
* Wraps @type_vk_keyword{DeviceCreateFlagBits}. |
||||
* @see @ref Flags, @ref DeviceCreateInfo(DeviceProperties&, const ExtensionProperties*, Flags) |
||||
*/ |
||||
enum class Flag: UnsignedInt { |
||||
/* Any magnum-specific flags added here have to be filtered out
|
||||
when passing them to _info.flags in the constructor. Using the |
||||
highest bits in a hope to prevent conflicts with Vulkan instance |
||||
flags added in the future. */ |
||||
|
||||
/**
|
||||
* Don't implicitly enable any extensions. |
||||
* |
||||
* By default, the engine enables various extensions such as |
||||
* @vk_extension{KHR,get_memory_requirements2} to provide a broader |
||||
* functionality. If you want to have a complete control over what |
||||
* gets enabled, set this flag. |
||||
*/ |
||||
NoImplicitExtensions = 1u << 31 |
||||
}; |
||||
|
||||
/**
|
||||
* @brief Device creation flags |
||||
* |
||||
* Type-safe wrapper for @type_vk_keyword{DeviceCreateFlags}. |
||||
* @see @ref DeviceCreateInfo(DeviceProperties&, const ExtensionProperties*, Flags) |
||||
*/ |
||||
typedef Containers::EnumSet<Flag> Flags; |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* @param deviceProperties A device to use |
||||
* @param extensionProperties Existing @ref ExtensionProperties |
||||
* instance for querying available Vulkan extensions. If |
||||
* @cpp nullptr @ce, a new instance may be created internally if |
||||
* needed. If a r-value is passed, the instance is later available |
||||
* through @ref Device::properties(). |
||||
* @param flags Device creation flags |
||||
* |
||||
* The following @type_vk{DeviceCreateInfo} fields are pre-filled in |
||||
* addition to `sType`: |
||||
* |
||||
* - `flags` |
||||
* |
||||
* You need to call at least @ref addQueues() for a valid setup. |
||||
*/ |
||||
explicit DeviceCreateInfo(DeviceProperties& deviceProperties, const ExtensionProperties* extensionProperties, Flags flags = {}); |
||||
|
||||
/** @overload */ |
||||
explicit DeviceCreateInfo(DeviceProperties& deviceProperties, Flags flags = {}): DeviceCreateInfo{deviceProperties, nullptr, flags} {} |
||||
|
||||
/**
|
||||
* @brief Construct with allowing to reuse already populated device properties |
||||
* |
||||
* Compared to @ref DeviceCreateInfo(DeviceProperties&, const ExtensionProperties*, Flags), |
||||
* if the @ref Device is subsequently constructed via |
||||
* @ref Device::Device(Instance&, DeviceCreateInfo&&), the |
||||
* @p deviceProperties instance gets directly transferred to the |
||||
* device, meaning @ref Device::properties() and any APIs relying on it |
||||
* can reuse what was possibly already queried without having to repeat |
||||
* the potentially complex queries second time. |
||||
*/ |
||||
explicit DeviceCreateInfo(DeviceProperties&& deviceProperties, const ExtensionProperties* extensionProperties, Flags flags = {}); |
||||
|
||||
/** @overload */ |
||||
explicit DeviceCreateInfo(DeviceProperties&& deviceProperties, Flags flags = {}): DeviceCreateInfo{std::move(deviceProperties), nullptr, 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 DeviceCreateInfo(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 DeviceCreateInfo(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo& info); |
||||
|
||||
/** @brief Copying is not allowed */ |
||||
DeviceCreateInfo(const DeviceCreateInfo&) = delete; |
||||
|
||||
/** @brief Move constructor */ |
||||
DeviceCreateInfo(DeviceCreateInfo&& other) noexcept; |
||||
|
||||
~DeviceCreateInfo(); |
||||
|
||||
/** @brief Copying is not allowed */ |
||||
DeviceCreateInfo& operator=(const DeviceCreateInfo&) = delete; |
||||
|
||||
/** @brief Move assignment */ |
||||
DeviceCreateInfo& operator=(DeviceCreateInfo&& other) noexcept; |
||||
|
||||
/* All the && overloads below are there in order to allow code like
|
||||
|
||||
Device device{instance, DeviceCreateInfo{pickDevice(instance)} |
||||
.addQueues(...) |
||||
.addEnabledExtensions(...) |
||||
... |
||||
}; |
||||
|
||||
to work and correctly move the DeviceProperties to the Device. |
||||
When adding new APIs, expand DeviceVkTest::createInfoRvalue() to |
||||
verify everything still works. */ |
||||
|
||||
/**
|
||||
* @brief Add enabled device extensions |
||||
* @return Reference to self (for method chaining) |
||||
* |
||||
* All listed extensions are expected to be supported either globally |
||||
* or in at least one of the enabled layers, use |
||||
* @ref ExtensionProperties::isSupported() to check for their presence. |
||||
* |
||||
* The function makes copies of string views that are not owning or |
||||
* null-terminated, use the @link Containers::Literals::operator""_s() @endlink |
||||
* literal to prevent that where possible. |
||||
*/ |
||||
DeviceCreateInfo& addEnabledExtensions(Containers::ArrayView<const Containers::StringView> extensions) &; |
||||
/** @overload */ |
||||
DeviceCreateInfo&& addEnabledExtensions(Containers::ArrayView<const Containers::StringView> extensions) &&; |
||||
/** @overload */ |
||||
DeviceCreateInfo& addEnabledExtensions(std::initializer_list<Containers::StringView> extension) &; |
||||
/** @overload */ |
||||
DeviceCreateInfo&& addEnabledExtensions(std::initializer_list<Containers::StringView> extension) &&; |
||||
/** @overload */ |
||||
DeviceCreateInfo& addEnabledExtensions(Containers::ArrayView<const Extension> extensions) &; |
||||
/** @overload */ |
||||
DeviceCreateInfo&& addEnabledExtensions(Containers::ArrayView<const Extension> extensions) &&; |
||||
/** @overload */ |
||||
DeviceCreateInfo& addEnabledExtensions(std::initializer_list<Extension> extension) &; |
||||
/** @overload */ |
||||
DeviceCreateInfo&& addEnabledExtensions(std::initializer_list<Extension> extension) &&; |
||||
/** @overload */ |
||||
template<class ...E> DeviceCreateInfo& addEnabledExtensions() & { |
||||
static_assert(Implementation::IsExtension<E...>::value, "expected only Vulkan device extensions"); |
||||
return addEnabledExtensions(std::initializer_list<Extension>{E{}...}); |
||||
} |
||||
/** @overload */ |
||||
template<class ...E> DeviceCreateInfo&& addEnabledExtensions() && { |
||||
addEnabledExtensions<E...>(); |
||||
return std::move(*this); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Add queues |
||||
* @param[in] family Family index, smaller than |
||||
* @ref DeviceProperties::queueFamilyCount() |
||||
* @param[in] priorities Queue priorities. Size of the array implies |
||||
* how many queues to add and has to be at least one. |
||||
* @param[out] output Where to save resulting queues once the |
||||
* device is created. Has to have the same sizes as @p priorities. |
||||
* @return Reference to self (for method chaining) |
||||
* |
||||
* At least one queue has to be added. |
||||
* @see @ref DeviceProperties::pickQueueFamily() |
||||
* @todoc link to addQueues(QueueFlags) once doxygen finally GROWS UP |
||||
* and can link to &-qualified functions FFS |
||||
*/ |
||||
DeviceCreateInfo& addQueues(UnsignedInt family, Containers::ArrayView<const Float> priorities, Containers::ArrayView<const Containers::Reference<Queue>> output) &; |
||||
/** @overload */ |
||||
DeviceCreateInfo&& addQueues(UnsignedInt family, Containers::ArrayView<const Float> priorities, Containers::ArrayView<const Containers::Reference<Queue>> output) &&; |
||||
/** @overload */ |
||||
DeviceCreateInfo& addQueues(UnsignedInt family, std::initializer_list<Float> priorities, std::initializer_list<Containers::Reference<Queue>> output) &; |
||||
/** @overload */ |
||||
DeviceCreateInfo&& addQueues(UnsignedInt family, std::initializer_list<Float> priorities, std::initializer_list<Containers::Reference<Queue>> output) &&; |
||||
|
||||
/**
|
||||
* @brief Add queues of family matching given flags |
||||
* |
||||
* Equivalent to picking a queue family first using |
||||
* @ref DeviceProperties::pickQueueFamily() based on @p flags and then |
||||
* calling the above @ref addQueues() variant with the family index. |
||||
* |
||||
* Note that @ref DeviceProperties::pickQueueFamily() exits in case it |
||||
* doesn't find any family satisfying given @p flags --- for a |
||||
* failproof scenario you may want to go with the above overload and |
||||
* @ref DeviceProperties::tryPickQueueFamily() instead. |
||||
* @todoc link to addQueues(UnsignedInt) above once doxygen finally |
||||
* GROWS UP and can link to &-qualified functions FFS |
||||
*/ |
||||
DeviceCreateInfo& addQueues(QueueFlags flags, Containers::ArrayView<const Float> priorities, Containers::ArrayView<const Containers::Reference<Queue>> output) &; |
||||
/** @overload */ |
||||
DeviceCreateInfo&& addQueues(QueueFlags flags, Containers::ArrayView<const Float> priorities, Containers::ArrayView<const Containers::Reference<Queue>> output) &&; |
||||
/** @overload */ |
||||
DeviceCreateInfo& addQueues(QueueFlags flags, std::initializer_list<Float> priorities, std::initializer_list<Containers::Reference<Queue>> output) &; |
||||
/** @overload */ |
||||
DeviceCreateInfo&& addQueues(QueueFlags flags, std::initializer_list<Float> priorities, std::initializer_list<Containers::Reference<Queue>> output) &&; |
||||
|
||||
/**
|
||||
* @brief Add queues using raw info |
||||
* @return Reference to self (for method chaining) |
||||
* |
||||
* Compared to @ref addQueues() this allows you to specify additional |
||||
* queue properties using the `pNext` chain. The info is uses as-is, |
||||
* with all pointers expected to stay in scope until device creation. |
||||
*/ |
||||
DeviceCreateInfo& addQueues(const VkDeviceQueueCreateInfo& info) &; |
||||
/** @overload */ |
||||
DeviceCreateInfo&& addQueues(const VkDeviceQueueCreateInfo& info) &&; |
||||
|
||||
/** @brief Underlying @type_vk{DeviceCreateInfo} structure */ |
||||
VkDeviceCreateInfo& operator*() { return _info; } |
||||
/** @overload */ |
||||
const VkDeviceCreateInfo& operator*() const { return _info; } |
||||
/** @overload */ |
||||
VkDeviceCreateInfo* operator->() { return &_info; } |
||||
/** @overload */ |
||||
const VkDeviceCreateInfo* operator->() const { return &_info; } |
||||
/** @overload */ |
||||
operator const VkDeviceCreateInfo*() const { return &_info; } |
||||
|
||||
private: |
||||
friend Device; |
||||
|
||||
VkPhysicalDevice _physicalDevice; |
||||
VkDeviceCreateInfo _info; |
||||
struct State; |
||||
Containers::Pointer<State> _state; |
||||
}; |
||||
|
||||
CORRADE_ENUMSET_OPERATORS(DeviceCreateInfo::Flags) |
||||
|
||||
}} |
||||
|
||||
/* Make the definition complete -- it doesn't make sense to have a CreateInfo
|
||||
without the corresponding object anyway. */ |
||||
#include "Magnum/Vk/Device.h" |
||||
|
||||
#endif |
||||
@ -0,0 +1,420 @@
|
||||
#ifndef Magnum_Vk_ImageCreateInfo_h |
||||
#define Magnum_Vk_ImageCreateInfo_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020 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::ImageCreateInfo, @ref Magnum::Vk::ImageCreateInfo1D, @ref Magnum::Vk::ImageCreateInfo2D, @ref Magnum::Vk::ImageCreateInfo3D, @ref Magnum::Vk::ImageCreateInfo1DArray, @ref Magnum::Vk::ImageCreateInfo2DArray, @ref Magnum::Vk::ImageCreateInfoCubeMap, @ref Magnum::Vk::ImageCreateInfoCubeMapArray, enum @ref Magnum::Vk::ImageUsage, enum set @ref Magnum::Vk::ImageUsages |
||||
* @m_since_latest |
||||
*/ |
||||
|
||||
#include <Corrade/Containers/EnumSet.h> |
||||
|
||||
#include "Magnum/DimensionTraits.h" |
||||
#include "Magnum/Magnum.h" |
||||
#include "Magnum/Math/Vector3.h" |
||||
#include "Magnum/Vk/Vk.h" |
||||
#include "Magnum/Vk/Vulkan.h" |
||||
#include "Magnum/Vk/visibility.h" |
||||
|
||||
/* Make the definition complete -- it doesn't make sense to have a CreateInfo
|
||||
without the corresponding object anyway. Compared to other cases we do this |
||||
on top as we need the ImageLayout definition here. */ |
||||
#include "Magnum/Vk/Image.h" |
||||
|
||||
namespace Magnum { namespace Vk { |
||||
|
||||
/**
|
||||
@brief Image usage |
||||
@m_since_latest |
||||
|
||||
Wraps a @type_vk_keyword{ImageUsageFlagBits}. |
||||
@see @ref ImageUsages, @ref ImageCreateInfo |
||||
@m_enum_values_as_keywords |
||||
*/ |
||||
enum class ImageUsage: UnsignedInt { |
||||
/**
|
||||
* Source of a transfer command |
||||
* |
||||
* @see @ref ImageLayout::TransferSource |
||||
*/ |
||||
TransferSource = VK_IMAGE_USAGE_TRANSFER_SRC_BIT, |
||||
|
||||
/**
|
||||
* Destination of a transfer command |
||||
* |
||||
* @see @ref ImageLayout::TransferDestination |
||||
*/ |
||||
TransferDestination = VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
||||
|
||||
/**
|
||||
* Sampled by a shader |
||||
* |
||||
* @see @ref ImageLayout::ShaderReadOnly |
||||
*/ |
||||
Sampled = VK_IMAGE_USAGE_SAMPLED_BIT, |
||||
|
||||
/** Shader storage */ |
||||
Storage = VK_IMAGE_USAGE_STORAGE_BIT, |
||||
|
||||
/**
|
||||
* Color attachment |
||||
* |
||||
* @see @ref ImageLayout::ColorAttachment |
||||
*/ |
||||
ColorAttachment = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, |
||||
|
||||
/**
|
||||
* Depth/stencil attachment |
||||
* |
||||
* @see @ref ImageLayout::DepthStencilAttachment |
||||
*/ |
||||
DepthStencilAttachment = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, |
||||
|
||||
/** Transient attachment */ |
||||
TransientAttachment = VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, |
||||
|
||||
/**
|
||||
* Input attachment in a shader or framebuffer |
||||
* |
||||
* @see @ref ImageLayout::ShaderReadOnly |
||||
*/ |
||||
InputAttachment = VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT |
||||
}; |
||||
|
||||
/**
|
||||
@brief Image usages |
||||
@m_since_latest |
||||
|
||||
Type-safe wrapper for @type_vk_keyword{ImageUsageFlags}. |
||||
@see @ref ImageCreateInfo |
||||
*/ |
||||
typedef Containers::EnumSet<ImageUsage> ImageUsages; |
||||
|
||||
CORRADE_ENUMSET_OPERATORS(ImageUsages) |
||||
|
||||
/**
|
||||
@brief Image creation info |
||||
@m_since_latest |
||||
|
||||
Wraps a @type_vk_keyword{ImageCreateInfo}. See |
||||
@ref Vk-Image-creation "Image creation" for usage information. |
||||
@see @ref ImageCreateInfo1D, @ref ImageCreateInfo2D, @ref ImageCreateInfo3D, |
||||
@ref ImageCreateInfo1DArray, @ref ImageCreateInfo2DArray, |
||||
@ref ImageCreateInfoCubeMap, @ref ImageCreateInfoCubeMapArray |
||||
*/ |
||||
class MAGNUM_VK_EXPORT ImageCreateInfo { |
||||
public: |
||||
/**
|
||||
* @brief Image creation flag |
||||
* |
||||
* Wraps @type_vk_keyword{ImageCreateFlagBits}. |
||||
* @see @ref Flags, @ref ImageCreateInfo(VkImageType, ImageUsages, VkFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags) |
||||
* @m_enum_values_as_keywords |
||||
*/ |
||||
enum class Flag: UnsignedInt { |
||||
/** @todo sparse binding/residency/aliased */ |
||||
|
||||
/**
|
||||
* Allow creating a view of different format |
||||
* |
||||
* @todo implement @vk_extension{KHR,image_format_list} |
||||
*/ |
||||
MutableFormat = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT, |
||||
|
||||
/** Allow creating a cube map view */ |
||||
CubeCompatible = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, |
||||
|
||||
/** @todo alias, 2D array compatible ... (Vulkan 1.1+) */ |
||||
}; |
||||
|
||||
/**
|
||||
* @brief Image creation flags |
||||
* |
||||
* Type-safe wrapper for @type_vk_keyword{ImageCreateFlags}. |
||||
* @see @ref ImageCreateInfo(VkImageType, ImageUsages, VkFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags), |
||||
* @ref ImageCreateInfo1D, @ref ImageCreateInfo2D, |
||||
* @ref ImageCreateInfo3D, @ref ImageCreateInfo1DArray, |
||||
* @ref ImageCreateInfo2DArray, @ref ImageCreateInfoCubeMap, |
||||
* @ref ImageCreateInfoCubeMapArray |
||||
*/ |
||||
typedef Containers::EnumSet<Flag> Flags; |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* @param type Image type |
||||
* @param usages Desired image usage. At least one flag is |
||||
* required. |
||||
* @param format Image format |
||||
* @param size Image size |
||||
* @param layers Array layer count |
||||
* @param levels Mip level count |
||||
* @param samples Sample count |
||||
* @param initialLayout Initial layout. Can be only either |
||||
* @ref ImageLayout::Undefined or @ref ImageLayout::Preinitialized. |
||||
* @param flags Image creation flags |
||||
* |
||||
* The following @type_vk{ImageCreateInfo} fields are pre-filled in |
||||
* addition to `sType`, everything else is zero-filled: |
||||
* |
||||
* - `flags` |
||||
* - `imageType` to @p type |
||||
* - `format` |
||||
* - `extent` to @p size |
||||
* - `mipLevels` to @p levels |
||||
* - `arrayLayers` to @p layers |
||||
* - `samples` |
||||
* - `tiling` to @val_vk{IMAGE_TILING_OPTIMAL,ImageTiling} |
||||
* - `usage` to @p usages |
||||
* - `sharingMode` to @val_vk{SHARING_MODE_EXCLUSIVE,SharingMode} |
||||
* - `initialLayout` to @p initialLayout |
||||
* |
||||
* There are various restrictions on @p size, @p layers, @p levels for |
||||
* a particular @p type --- for common image types you're encouraged to |
||||
* make use of @ref ImageCreateInfo1D, @ref ImageCreateInfo2D, |
||||
* @ref ImageCreateInfo3D, @ref ImageCreateInfo1DArray, |
||||
* @ref ImageCreateInfo2DArray, @ref ImageCreateInfoCubeMap and |
||||
* @ref ImageCreateInfoCubeMapArray convenience classes instead of |
||||
* this constructor. |
||||
*/ |
||||
explicit ImageCreateInfo(VkImageType type, ImageUsages usages, VkFormat format, const Vector3i& size, Int layers, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}); |
||||
/* No overload w/o initialLayout here as the general public is expected
|
||||
to use the convenience classes anyway */ |
||||
|
||||
/**
|
||||
* @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 ImageCreateInfo(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 ImageCreateInfo(const VkImageCreateInfo& info); |
||||
|
||||
/** @brief Underlying @type_vk{ImageCreateInfo} structure */ |
||||
VkImageCreateInfo& operator*() { return _info; } |
||||
/** @overload */ |
||||
const VkImageCreateInfo& operator*() const { return _info; } |
||||
/** @overload */ |
||||
VkImageCreateInfo* operator->() { return &_info; } |
||||
/** @overload */ |
||||
const VkImageCreateInfo* operator->() const { return &_info; } |
||||
/** @overload */ |
||||
operator const VkImageCreateInfo*() const { return &_info; } |
||||
|
||||
private: |
||||
VkImageCreateInfo _info; |
||||
}; |
||||
|
||||
CORRADE_ENUMSET_OPERATORS(ImageCreateInfo::Flags) |
||||
|
||||
/**
|
||||
@brief Convenience constructor for 1D images |
||||
@m_since_latest |
||||
|
||||
Compared to the base @ref ImageCreateInfo constructor creates an image of type |
||||
@val_vk{IMAGE_TYPE_1D,ImageType} with the last two `size` components and |
||||
`layers` set to @cpp 1 @ce. |
||||
|
||||
Note that same as with the |
||||
@ref ImageCreateInfo::ImageCreateInfo(VkImageType, ImageUsages, VkFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags) |
||||
constructor, at least one @ref ImageUsage value is required. |
||||
*/ |
||||
class ImageCreateInfo1D: public ImageCreateInfo { |
||||
public: |
||||
/** @brief Constructor */ |
||||
explicit ImageCreateInfo1D(ImageUsages usages, VkFormat format, Int size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_1D, usages, format, {size, 1, 1}, 1, levels, samples, initialLayout, flags} {} |
||||
|
||||
/** @overload
|
||||
* |
||||
* Equivalent to the above with @p initialLayout set to |
||||
* @ref ImageLayout::Undefined. |
||||
*/ |
||||
explicit ImageCreateInfo1D(ImageUsages usages, VkFormat format, Int size, Int levels, Int samples, Flags flags): ImageCreateInfo1D{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {} |
||||
}; |
||||
|
||||
/**
|
||||
@brief Convenience constructor for 2D images |
||||
@m_since_latest |
||||
|
||||
Compared to the base @ref ImageCreateInfo constructor creates an image of type |
||||
@val_vk{IMAGE_TYPE_2D,ImageType} with the last `size` component and `layers` |
||||
set to @cpp 1 @ce. |
||||
|
||||
Note that same as with the |
||||
@ref ImageCreateInfo::ImageCreateInfo(VkImageType, ImageUsages, VkFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags) |
||||
constructor, at least one @ref ImageUsage value is required. |
||||
*/ |
||||
class ImageCreateInfo2D: public ImageCreateInfo { |
||||
public: |
||||
/** @brief Constructor */ |
||||
explicit ImageCreateInfo2D(ImageUsages usages, VkFormat format, const Vector2i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_2D, usages, format, {size, 1}, 1, levels, samples, initialLayout, flags} {} |
||||
|
||||
/** @overload
|
||||
* |
||||
* Equivalent to the above with @p initialLayout set to |
||||
* @ref ImageLayout::Undefined. |
||||
*/ |
||||
explicit ImageCreateInfo2D(ImageUsages usages, VkFormat format, const Vector2i& size, Int levels, Int samples, Flags flags): ImageCreateInfo2D{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {} |
||||
}; |
||||
|
||||
/**
|
||||
@brief Convenience constructor for 3D images |
||||
@m_since_latest |
||||
|
||||
Compared to the base @ref ImageCreateInfo constructor creates an image of type |
||||
@val_vk{IMAGE_TYPE_3D,ImageType} with `layers` set to @cpp 1 @ce. |
||||
|
||||
Note that same as with the |
||||
@ref ImageCreateInfo::ImageCreateInfo(VkImageType, ImageUsages, VkFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags) |
||||
constructor, at least one @ref ImageUsage value is required. |
||||
*/ |
||||
class ImageCreateInfo3D: public ImageCreateInfo { |
||||
public: |
||||
/** @brief Constructor */ |
||||
explicit ImageCreateInfo3D(ImageUsages usages, VkFormat format, const Vector3i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_3D, usages, format, size, 1, levels, samples, initialLayout, flags} {} |
||||
|
||||
/** @overload
|
||||
* |
||||
* Equivalent to the above with @p initialLayout set to |
||||
* @ref ImageLayout::Undefined. |
||||
*/ |
||||
explicit ImageCreateInfo3D(ImageUsages usages, VkFormat format, const Vector3i& size, Int levels, Int samples, Flags flags): ImageCreateInfo3D{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {} |
||||
}; |
||||
|
||||
/**
|
||||
@brief Convenience constructor for 1D array images |
||||
@m_since_latest |
||||
|
||||
Compared to the base @ref ImageCreateInfo constructor creates an image of type |
||||
@val_vk{IMAGE_TYPE_1D,ImageType} with the last two `size` components set to |
||||
@cpp 1 @ce and `layers` set to @cpp size.y() @ce. |
||||
|
||||
Note that same as with the |
||||
@ref ImageCreateInfo::ImageCreateInfo(VkImageType, ImageUsages, VkFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags) |
||||
constructor, at least one @ref ImageUsage value is required. |
||||
*/ |
||||
class ImageCreateInfo1DArray: public ImageCreateInfo { |
||||
public: |
||||
/** @brief Constructor */ |
||||
explicit ImageCreateInfo1DArray(ImageUsages usages, VkFormat format, const Vector2i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_1D, usages, format, {size.x(), 1, 1}, size.y(), levels, samples, initialLayout, flags} {} |
||||
|
||||
/** @overload
|
||||
* |
||||
* Equivalent to the above with @p initialLayout set to |
||||
* @ref ImageLayout::Undefined. |
||||
*/ |
||||
explicit ImageCreateInfo1DArray(ImageUsages usages, VkFormat format, const Vector2i& size, Int levels, Int samples, Flags flags): ImageCreateInfo1DArray{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {} |
||||
}; |
||||
|
||||
/**
|
||||
@brief Convenience constructor for 2D array images |
||||
@m_since_latest |
||||
|
||||
Compared to the base @ref ImageCreateInfo constructor creates an image of type |
||||
@val_vk{IMAGE_TYPE_2D,ImageType} with the last `size` component set to |
||||
@cpp 1 @ce and `layers` set to @cpp size.z() @ce. |
||||
|
||||
Note that same as with the |
||||
@ref ImageCreateInfo::ImageCreateInfo(VkImageType, ImageUsages, VkFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags) |
||||
constructor, at least one @ref ImageUsage value is required. |
||||
*/ |
||||
class ImageCreateInfo2DArray: public ImageCreateInfo { |
||||
public: |
||||
/** @brief Constructor */ |
||||
explicit ImageCreateInfo2DArray(ImageUsages usages, VkFormat format, const Vector3i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_2D, usages, format, {size.xy(), 1}, size.z(), levels, samples, initialLayout, flags} {} |
||||
|
||||
/** @overload
|
||||
* |
||||
* Equivalent to the above with @p initialLayout set to |
||||
* @ref ImageLayout::Undefined. |
||||
*/ |
||||
explicit ImageCreateInfo2DArray(ImageUsages usages, VkFormat format, const Vector3i& size, Int levels, Int samples, Flags flags): ImageCreateInfo2DArray{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {} |
||||
}; |
||||
|
||||
/**
|
||||
@brief Convenience constructor for cube map images |
||||
@m_since_latest |
||||
|
||||
Compared to the base @ref ImageCreateInfo constructor creates an image of type |
||||
@val_vk{IMAGE_TYPE_2D,ImageType} with the last `size` component set to |
||||
@cpp 1 @ce, `layers` set to @cpp 6 @ce and `flags` additionally having |
||||
@ref Flag::CubeCompatible. |
||||
|
||||
Note that same as with the |
||||
@ref ImageCreateInfo::ImageCreateInfo(VkImageType, ImageUsages, VkFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags) |
||||
constructor, at least one @ref ImageUsage value is required. |
||||
*/ |
||||
class ImageCreateInfoCubeMap: public ImageCreateInfo { |
||||
public: |
||||
/** @brief Constructor */ |
||||
explicit ImageCreateInfoCubeMap(ImageUsages usages, VkFormat format, const Vector2i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_2D, usages, format, {size, 1}, 6, levels, samples, initialLayout, flags|Flag::CubeCompatible} {} |
||||
|
||||
/** @overload
|
||||
* |
||||
* Equivalent to the above with @p initialLayout set to |
||||
* @ref ImageLayout::Undefined. |
||||
*/ |
||||
explicit ImageCreateInfoCubeMap(ImageUsages usages, VkFormat format, const Vector2i& size, Int levels, Int samples, Flags flags): ImageCreateInfoCubeMap{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {} |
||||
}; |
||||
|
||||
/**
|
||||
@brief Convenience constructor for cube map array images |
||||
@m_since_latest |
||||
|
||||
Compared to the base @ref ImageCreateInfo constructor creates an image of type |
||||
@val_vk{IMAGE_TYPE_2D,ImageType} with the last `size` component set to |
||||
@cpp 1 @ce, `layers` set to @cpp size.y() @ce and `flags` additionally having |
||||
@ref Flag::CubeCompatible. |
||||
|
||||
Note that same as with the |
||||
@ref ImageCreateInfo::ImageCreateInfo(VkImageType, ImageUsages, VkFormat, const Vector3i&, Int, Int, Int, ImageLayout, Flags) |
||||
constructor, at least one @ref ImageUsage value is required. |
||||
*/ |
||||
class ImageCreateInfoCubeMapArray: public ImageCreateInfo { |
||||
public: |
||||
/** @brief Constructor */ |
||||
explicit ImageCreateInfoCubeMapArray(ImageUsages usages, VkFormat format, const Vector3i& size, Int levels, Int samples = 1, ImageLayout initialLayout = ImageLayout::Undefined, Flags flags = {}): ImageCreateInfo{VK_IMAGE_TYPE_2D, usages, format, {size.xy(), 1}, size.z(), levels, samples, initialLayout, flags|Flag::CubeCompatible} {} |
||||
|
||||
/** @overload
|
||||
* |
||||
* Equivalent to the above with @p initialLayout set to |
||||
* @ref ImageLayout::Undefined. |
||||
*/ |
||||
explicit ImageCreateInfoCubeMapArray(ImageUsages usages, VkFormat format, const Vector3i& size, Int levels, Int samples, Flags flags): ImageCreateInfoCubeMapArray{usages, format, size, levels, samples, ImageLayout::Undefined, flags} {} |
||||
}; |
||||
|
||||
}} |
||||
|
||||
/* Image.h included at the top */ |
||||
|
||||
#endif |
||||
@ -0,0 +1,240 @@
|
||||
#ifndef Magnum_Vk_InstanceCreateInfo_h |
||||
#define Magnum_Vk_InstanceCreateInfo_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020 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::InstanceCreateInfo |
||||
* @m_since_latest |
||||
*/ |
||||
|
||||
#include <Corrade/Containers/Pointer.h> |
||||
|
||||
#include "Magnum/Tags.h" |
||||
#include "Magnum/Vk/TypeTraits.h" |
||||
#include "Magnum/Vk/Vk.h" |
||||
#include "Magnum/Vk/Vulkan.h" |
||||
#include "Magnum/Vk/visibility.h" |
||||
|
||||
namespace Magnum { namespace Vk { |
||||
|
||||
/**
|
||||
@brief Instance creation info |
||||
@m_since_latest |
||||
|
||||
Wraps a @type_vk_keyword{InstanceCreateInfo} and |
||||
@type_vk_keyword{ApplicationInfo}. See |
||||
@ref Vk-Instance-creation "Instance creation" for usage information. |
||||
*/ |
||||
class MAGNUM_VK_EXPORT InstanceCreateInfo { |
||||
public: |
||||
/**
|
||||
* @brief Instance creation flag |
||||
* |
||||
* Wraps @type_vk_keyword{InstanceCreateFlagBits}. |
||||
* @see @ref Flags, @ref InstanceCreateInfo(Int, const char**, const LayerProperties*, const InstanceExtensionProperties*, Flags) |
||||
*/ |
||||
enum class Flag: UnsignedInt { |
||||
/* Any magnum-specific flags added here have to be filtered out
|
||||
when passing them to _info.flags in the constructor. Using the |
||||
highest bits in a hope to prevent conflicts with Vulkan instance |
||||
flags added in the future. */ |
||||
|
||||
/**
|
||||
* Don't implicitly enable any extensions. |
||||
* |
||||
* By default, the engine enables various extensions such as |
||||
* @vk_extension{KHR,get_physical_device_properties2} to provide a |
||||
* broader functionality. If you want to have a complete control |
||||
* over what gets enabled, set this flag. |
||||
*/ |
||||
NoImplicitExtensions = 1u << 31 |
||||
}; |
||||
|
||||
/**
|
||||
* @brief Instance creation flags |
||||
* |
||||
* Type-safe wrapper for @type_vk_keyword{InstanceCreateFlags}. |
||||
* @see @ref InstanceCreateInfo(Int, const char**, const LayerProperties*, const InstanceExtensionProperties*, Flags) |
||||
*/ |
||||
typedef Containers::EnumSet<Flag> Flags; |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* @param argc Command-line argument count. Can be @cpp 0 @ce. |
||||
* @param argv Command-line argument values. Can be |
||||
* @cpp nullptr @ce. If set, is expected to stay in scope for the |
||||
* whole instance lifetime. |
||||
* @param layerProperties Existing @ref LayerProperties instance for |
||||
* querying available Vulkan layers. If @cpp nullptr @ce, a new |
||||
* instance may be created internally if needed. |
||||
* @param extensionProperties Existing @ref InstanceExtensionProperties |
||||
* instance for querying available Vulkan extensions. If |
||||
* @cpp nullptr @ce, a new instance may be created internally if |
||||
* needed. |
||||
* @param flags Instance creation flags |
||||
* |
||||
* The following @type_vk{InstanceCreateInfo} fields are pre-filled in |
||||
* addition to `sType`, everything else is zero-filled: |
||||
* |
||||
* - `pApplicationInfo` |
||||
* - @cpp pApplicationInfo->apiVersion @ce to |
||||
* @ref enumerateInstanceVersion() |
||||
* - @cpp pApplicationInfo->engineName @ce to @cpp "Magnum" @ce |
||||
*/ |
||||
/* All those are implicit in order to allow writing
|
||||
Instance instance{{argc, argv}}; |
||||
It's a tradeoff between a completely verbose way and |
||||
Instance instance{argc, argv}; |
||||
in which case all these overloads would need to be duplicated on |
||||
Instance as well. */ |
||||
/*implicit*/ InstanceCreateInfo(Int argc, const char** argv, const LayerProperties* layerProperties, const InstanceExtensionProperties* const extensionProperties, Flags flags = {}); |
||||
|
||||
/** @overload */ |
||||
/*implicit*/ InstanceCreateInfo(Int argc, char** argv, const LayerProperties* layerProperties, const InstanceExtensionProperties* extensionProperties, Flags flags = {}): InstanceCreateInfo{argc, const_cast<const char**>(argv), layerProperties, extensionProperties, flags} {} |
||||
|
||||
/** @overload */ |
||||
/*implicit*/ InstanceCreateInfo(Int argc, std::nullptr_t argv, const LayerProperties* layerProperties, const InstanceExtensionProperties* extensionProperties, Flags flags = {}): InstanceCreateInfo{argc, static_cast<const char**>(argv), layerProperties, extensionProperties, flags} {} |
||||
|
||||
/** @overload */ |
||||
/*implicit*/ InstanceCreateInfo(Int argc, const char** argv, Flags flags = {}): InstanceCreateInfo{argc, argv, nullptr, nullptr, flags} {} |
||||
|
||||
/** @overload */ |
||||
/*implicit*/ InstanceCreateInfo(Int argc, char** argv, Flags flags = {}): InstanceCreateInfo{argc, argv, nullptr, nullptr, flags} {} |
||||
|
||||
/** @overload */ |
||||
/*implicit*/ InstanceCreateInfo(Int argc, std::nullptr_t argv, Flags flags = {}): InstanceCreateInfo{argc, argv, nullptr, nullptr, flags} {} |
||||
|
||||
/** @overload */ |
||||
/*implicit*/ InstanceCreateInfo(Flags flags = {}): InstanceCreateInfo{0, nullptr, 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 InstanceCreateInfo(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 InstanceCreateInfo(const VkInstanceCreateInfo& info); |
||||
|
||||
~InstanceCreateInfo(); |
||||
|
||||
/**
|
||||
* @brief Set application info |
||||
* @return Reference to self (for method chaining) |
||||
* |
||||
* Use the @ref version() helper to create the @p version value. The |
||||
* name is @cpp nullptr @ce by default. |
||||
* |
||||
* The function makes copies of string views that are not owning or |
||||
* null-terminated, use the @link Containers::Literals::operator""_s() @endlink |
||||
* literal to prevent that where possible. |
||||
*/ |
||||
InstanceCreateInfo& setApplicationInfo(Containers::StringView name, Version version); |
||||
|
||||
/**
|
||||
* @brief Add enabled layers |
||||
* @return Reference to self (for method chaining) |
||||
* |
||||
* All listed layers are expected be supported, use |
||||
* @ref LayerProperties::isSupported() to check for their presence. If |
||||
* a particular layer is listed among `--magnum-disable-layers` in |
||||
* @ref Vk-Instance-command-line "command-line options", it's not |
||||
* added. |
||||
* |
||||
* The function makes copies of string views that are not owning or |
||||
* null-terminated, use the @link Containers::Literals::operator""_s() @endlink |
||||
* literal to prevent that where possible. |
||||
*/ |
||||
InstanceCreateInfo& addEnabledLayers(Containers::ArrayView<const Containers::StringView> layers); |
||||
/** @overload */ |
||||
InstanceCreateInfo& addEnabledLayers(std::initializer_list<Containers::StringView> layers); |
||||
|
||||
/**
|
||||
* @brief Add enabled instance extensions |
||||
* @return Reference to self (for method chaining) |
||||
* |
||||
* All listed extensions are expected to be supported either globally |
||||
* or in at least one of the enabled layers, use |
||||
* @ref InstanceExtensionProperties::isSupported() to check for their |
||||
* presence. If a particular extension is listed among |
||||
* `--magnum-disable-extensions` in |
||||
* @ref Vk-Instance-command-line "command-line options", it's not |
||||
* added. |
||||
* |
||||
* The function makes copies of string views that are not owning or |
||||
* null-terminated, use the @link Containers::Literals::operator""_s() @endlink |
||||
* literal to prevent that where possible. |
||||
*/ |
||||
InstanceCreateInfo& addEnabledExtensions(Containers::ArrayView<const Containers::StringView> extensions); |
||||
/** @overload */ |
||||
InstanceCreateInfo& addEnabledExtensions(std::initializer_list<Containers::StringView> extension); |
||||
/** @overload */ |
||||
InstanceCreateInfo& addEnabledExtensions(Containers::ArrayView<const InstanceExtension> extensions); |
||||
/** @overload */ |
||||
InstanceCreateInfo& addEnabledExtensions(std::initializer_list<InstanceExtension> extension); |
||||
/** @overload */ |
||||
template<class ...E> InstanceCreateInfo& addEnabledExtensions() { |
||||
static_assert(Implementation::IsInstanceExtension<E...>::value, "expected only Vulkan instance extensions"); |
||||
return addEnabledExtensions({E{}...}); |
||||
} |
||||
|
||||
/** @brief Underlying @type_vk{InstanceCreateInfo} structure */ |
||||
VkInstanceCreateInfo& operator*() { return _info; } |
||||
/** @overload */ |
||||
const VkInstanceCreateInfo& operator*() const { return _info; } |
||||
/** @overload */ |
||||
VkInstanceCreateInfo* operator->() { return &_info; } |
||||
/** @overload */ |
||||
const VkInstanceCreateInfo* operator->() const { return &_info; } |
||||
/** @overload */ |
||||
operator const VkInstanceCreateInfo*() const { return &_info; } |
||||
|
||||
private: |
||||
friend Instance; |
||||
|
||||
VkInstanceCreateInfo _info; |
||||
VkApplicationInfo _applicationInfo; |
||||
struct State; |
||||
Containers::Pointer<State> _state; |
||||
}; |
||||
|
||||
CORRADE_ENUMSET_OPERATORS(InstanceCreateInfo::Flags) |
||||
|
||||
}} |
||||
|
||||
/* Make the definition complete -- it doesn't make sense to have a CreateInfo
|
||||
without the corresponding object anyway. */ |
||||
#include "Magnum/Vk/Instance.h" |
||||
|
||||
#endif |
||||
@ -0,0 +1,189 @@
|
||||
#ifndef Magnum_Vk_MemoryAllocateInfo_h |
||||
#define Magnum_Vk_MemoryAllocateInfo_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020 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::MemoryRequirements, @ref Magnum::Vk::MemoryAllocateInfo |
||||
*/ |
||||
|
||||
#include "Magnum/Magnum.h" |
||||
#include "Magnum/Tags.h" |
||||
#include "Magnum/Vk/Vk.h" |
||||
#include "Magnum/Vk/Vulkan.h" |
||||
#include "Magnum/Vk/visibility.h" |
||||
|
||||
namespace Magnum { namespace Vk { |
||||
|
||||
/**
|
||||
@brief Device memory requirements |
||||
@m_since_latest |
||||
|
||||
Wraps a @type_vk_keyword{MemoryRequirements2}. Not constructible directly, |
||||
returned from @ref Image::memoryRequirements() and |
||||
@ref Buffer::memoryRequirements(). |
||||
@see @ref DeviceProperties::pickMemory() |
||||
*/ |
||||
class MAGNUM_VK_EXPORT MemoryRequirements { |
||||
public: |
||||
/**
|
||||
* @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 MemoryRequirements(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 MemoryRequirements(const VkMemoryRequirements2& requirements); |
||||
|
||||
/** @brief Underlying @type_vk{MemoryRequirements} structure */ |
||||
VkMemoryRequirements2& requirements() { return _requirements; } |
||||
/** @overload */ |
||||
const VkMemoryRequirements2& requirements() const { return _requirements; } |
||||
/** @overload */ |
||||
operator VkMemoryRequirements2&() { return _requirements; } |
||||
/** @overload */ |
||||
operator const VkMemoryRequirements2&() const { return _requirements; } |
||||
/** @overload */ |
||||
VkMemoryRequirements2* operator->() { return &_requirements; } |
||||
/** @overload */ |
||||
const VkMemoryRequirements2* operator->() const { return &_requirements; } |
||||
|
||||
/**
|
||||
* @brief Required memory size |
||||
* |
||||
* @see @ref alignedSize() |
||||
*/ |
||||
UnsignedLong size() const { |
||||
return _requirements.memoryRequirements.size; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Required memory alignment |
||||
* |
||||
* @see @ref alignedSize() |
||||
*/ |
||||
UnsignedLong alignment() const { |
||||
return _requirements.memoryRequirements.alignment; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Required memory size rounded up for given alignment |
||||
* |
||||
* Pads @ref size() with given alignment requirements. For example, a |
||||
* 13765-byte buffer aligned to 4 kB would be 16384 bytes. See the |
||||
* @ref Memory class for more information and example usage. |
||||
* |
||||
* The alignment is expected to be non-zero. |
||||
*/ |
||||
UnsignedLong alignedSize(UnsignedLong alignment) const; |
||||
|
||||
/** @brief Bits indicating which memory */ |
||||
UnsignedInt memories() const { |
||||
return _requirements.memoryRequirements.memoryTypeBits; |
||||
} |
||||
|
||||
private: |
||||
friend Buffer; |
||||
friend Image; |
||||
|
||||
explicit MemoryRequirements(); |
||||
|
||||
VkMemoryRequirements2 _requirements; |
||||
}; |
||||
|
||||
/**
|
||||
@brief Memory allocation info |
||||
@m_since_latest |
||||
|
||||
Wraps a @type_vk_keyword{MemoryAllocateInfo}. See |
||||
@ref Vk-Memory-allocation "Memory allocation" for usage information. |
||||
*/ |
||||
class MAGNUM_VK_EXPORT MemoryAllocateInfo { |
||||
public: |
||||
/** @todo Flags, in VkMemoryAllocateFlagsInfo (1.1) */ |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* @param size Allocation size in bytes |
||||
* @param memory Memory index, smaller than |
||||
* @ref DeviceProperties::memoryCount() |
||||
* |
||||
* The following @type_vk{MemoryAllocateInfo} fields are pre-filled in |
||||
* addition to `sType`, everything else is zero-filled: |
||||
* |
||||
* - `allocationSize` to @p size |
||||
* - `memoryTypeIndex` to @p memory |
||||
* |
||||
* @see @ref DeviceProperties::pickMemory() |
||||
*/ |
||||
explicit MemoryAllocateInfo(UnsignedLong size, UnsignedInt memory); |
||||
|
||||
/**
|
||||
* @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 MemoryAllocateInfo(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 MemoryAllocateInfo(const VkMemoryAllocateInfo& info); |
||||
|
||||
/** @brief Underlying @type_vk{MemoryAllocateInfo} structure */ |
||||
VkMemoryAllocateInfo& operator*() { return _info; } |
||||
/** @overload */ |
||||
const VkMemoryAllocateInfo& operator*() const { return _info; } |
||||
/** @overload */ |
||||
VkMemoryAllocateInfo* operator->() { return &_info; } |
||||
/** @overload */ |
||||
const VkMemoryAllocateInfo* operator->() const { return &_info; } |
||||
/** @overload */ |
||||
operator const VkMemoryAllocateInfo*() const { return &_info; } |
||||
|
||||
private: |
||||
VkMemoryAllocateInfo _info; |
||||
}; |
||||
|
||||
}} |
||||
|
||||
/* Make the definition complete -- it doesn't make sense to have a CreateInfo
|
||||
without the corresponding object anyway. */ |
||||
#include "Magnum/Vk/Memory.h" |
||||
|
||||
#endif |
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,191 @@
|
||||
#ifndef Magnum_Vk_ShaderCreateInfo_h |
||||
#define Magnum_Vk_ShaderCreateInfo_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020 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::ShaderCreateInfo |
||||
* @m_since_latest |
||||
*/ |
||||
|
||||
#include <Corrade/Containers/EnumSet.h> |
||||
|
||||
#include "Magnum/Magnum.h" |
||||
#include "Magnum/Tags.h" |
||||
#include "Magnum/Vk/Vk.h" |
||||
#include "Magnum/Vk/Vulkan.h" |
||||
#include "Magnum/Vk/visibility.h" |
||||
|
||||
namespace Magnum { namespace Vk { |
||||
|
||||
/**
|
||||
@brief Shader creation info |
||||
@m_since_latest |
||||
|
||||
Wraps a @type_vk_keyword{ShaderModuleCreateInfo}. See |
||||
@ref Vk-Shader-creation "Shader creation" for usage information. |
||||
*/ |
||||
class MAGNUM_VK_EXPORT ShaderCreateInfo { |
||||
public: |
||||
/**
|
||||
* @brief Shader creation flag |
||||
* |
||||
* Wraps @type_vk_keyword{ShaderModuleCreateFlagBits}. |
||||
* @see @ref Flags, @ref ShaderCreateInfo() |
||||
* @m_enum_values_as_keywords |
||||
*/ |
||||
enum class Flag: UnsignedInt {}; |
||||
|
||||
/**
|
||||
* @brief Shader creation flags |
||||
* |
||||
* Type-safe wrapper for @type_vk_keyword{ShaderModuleCreateFlags}. |
||||
* @see @ref ShaderCreateInfo() |
||||
*/ |
||||
typedef Containers::EnumSet<Flag> Flags; |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* @param code Shader code |
||||
* @param flags Shader creation flags |
||||
* |
||||
* The following @type_vk{ShaderModuleCreateInfo} fields are pre-filled |
||||
* in addition to `sType`, everything else is zero-filled: |
||||
* |
||||
* - `flags` |
||||
* - `pCode` and `codeSize` to @p code |
||||
* |
||||
* @attention The class doesn't make any copy of @p code, so you either |
||||
* have to ensure it stays in scope until @ref Shader is |
||||
* constructed, or instantiate a temporary @ref ShaderCreateInfo |
||||
* directly in @ref Shader constructor call expression, as shown |
||||
* in its usage docs. If you have the data in |
||||
* @ref Corrade::Containers::Array, there's also |
||||
* @ref ShaderCreateInfo(Containers::Array<T>&&, Flags). |
||||
*/ |
||||
explicit ShaderCreateInfo(Containers::ArrayView<const void> code, Flags flags = {}); |
||||
|
||||
/**
|
||||
* @brief Construct taking ownership of a r-value array instance |
||||
* |
||||
* Behaves like @ref ShaderCreateInfo(Containers::ArrayView<const void>, Flags) |
||||
* but in addition ensures @p code stays in scope until @ref Shader is |
||||
* created, deleting it on destruction. The cleanup relies on the |
||||
* pointer and size stored in @type_vk{ShaderModuleCreateInfo}, |
||||
* changing the `pCode` and `codeSize` members afterwards may result in |
||||
* memory corruption. |
||||
*/ |
||||
template<class T> explicit ShaderCreateInfo(Containers::Array<T>&& code, Flags flags = {}); |
||||
|
||||
/**
|
||||
* @overload |
||||
* |
||||
* Sorry, custom @ref Corrade::Containers::Array deleter types can't be |
||||
* taken over. |
||||
*/ |
||||
template<class T, class Deleter> explicit ShaderCreateInfo(Containers::Array<T, Deleter>&& code, Flags flags = {}) = delete; |
||||
|
||||
/**
|
||||
* @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 ShaderCreateInfo(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 ShaderCreateInfo(const VkShaderModuleCreateInfo& info); |
||||
|
||||
/** @brief Copying is not allowed */ |
||||
ShaderCreateInfo(const ShaderCreateInfo&) = delete; |
||||
|
||||
/** @brief Move constructor */ |
||||
ShaderCreateInfo(ShaderCreateInfo&& other) noexcept; |
||||
|
||||
/**
|
||||
* @brief Destructor |
||||
* |
||||
* If the @ref ShaderCreateInfo(Containers::Array<T>&&, Flags) |
||||
* constructor was used, calls deleter on the stored array. |
||||
*/ |
||||
~ShaderCreateInfo(); |
||||
|
||||
/** @brief Copying is not allowed */ |
||||
ShaderCreateInfo& operator=(const ShaderCreateInfo&) = delete; |
||||
|
||||
/** @brief Move assignment */ |
||||
ShaderCreateInfo& operator=(ShaderCreateInfo&& other) noexcept; |
||||
|
||||
/** @brief Underlying @type_vk{ShaderModuleCreateInfo} structure */ |
||||
VkShaderModuleCreateInfo& operator*() { return _info; } |
||||
/** @overload */ |
||||
const VkShaderModuleCreateInfo& operator*() const { return _info; } |
||||
/** @overload */ |
||||
VkShaderModuleCreateInfo* operator->() { return &_info; } |
||||
/** @overload */ |
||||
const VkShaderModuleCreateInfo* operator->() const { return &_info; } |
||||
/** @overload */ |
||||
operator const VkShaderModuleCreateInfo*() const { return &_info; } |
||||
|
||||
private: |
||||
VkShaderModuleCreateInfo _info; |
||||
|
||||
/* Used by the Array&& constructor. Instead of wrapping an Array of an
|
||||
arbitrary type we just take its deleter, the pointer + size pair is |
||||
stored in _info already. */ |
||||
void(*_originalDeleter)(){}; |
||||
void(*_deleter)(void(*)(), const void*, std::size_t){}; |
||||
}; |
||||
|
||||
CORRADE_ENUMSET_OPERATORS(ShaderCreateInfo::Flags) |
||||
|
||||
template<class T> /*implicit*/ ShaderCreateInfo::ShaderCreateInfo(Containers::Array<T>&& code, Flags flags): ShaderCreateInfo{code, flags} { |
||||
/* Remember the deleter. The pointer and size is stored in
|
||||
VkShaderModuleCreateInfo and we assume it won't get stomped on |
||||
afterwards */ |
||||
_originalDeleter = reinterpret_cast<void(*)()>(code.deleter() ? code.deleter() : static_cast<void(*)(T*, std::size_t)>([](T* data, std::size_t) { delete[] data; })); |
||||
_deleter = [](void(*originalDeleter)(), const void* data, std::size_t size) { |
||||
/* VkShaderModuleCreateInfo stores the size in bytes, convert it back
|
||||
to the element count for the deleter */ |
||||
reinterpret_cast<void(*)(T*, std::size_t)>(originalDeleter)(reinterpret_cast<T*>(const_cast<void*>(data)), size/sizeof(T)); |
||||
}; |
||||
|
||||
/* Release the original array so the deleter isn't called too early */ |
||||
code.release(); |
||||
} |
||||
|
||||
}} |
||||
|
||||
/* Make the definition complete -- it doesn't make sense to have a CreateInfo
|
||||
without the corresponding object anyway. */ |
||||
#include "Magnum/Vk/Shader.h" |
||||
|
||||
#endif |
||||
Loading…
Reference in new issue