diff --git a/src/Magnum/Vk/DescriptorPool.cpp b/src/Magnum/Vk/DescriptorPool.cpp index 27d94a963..c949d706d 100644 --- a/src/Magnum/Vk/DescriptorPool.cpp +++ b/src/Magnum/Vk/DescriptorPool.cpp @@ -28,6 +28,7 @@ #include #include +#include #include "Magnum/Vk/Assert.h" #include "Magnum/Vk/DescriptorSet.h" @@ -128,7 +129,7 @@ DescriptorPool& DescriptorPool::operator=(DescriptorPool&& other) noexcept { return *this; } -std::pair DescriptorPool::allocateInternal(const VkDescriptorSetLayout layout) { +Containers::Pair DescriptorPool::allocateInternal(const VkDescriptorSetLayout layout) { DescriptorSet set{NoCreate}; set._device = _device; set._pool = _handle; @@ -161,19 +162,19 @@ std::pair DescriptorPool::allocateInternal(const VkDescri } DescriptorSet DescriptorPool::allocate(const VkDescriptorSetLayout layout) { - std::pair out = allocateInternal(layout); - CORRADE_ASSERT(out.first == Result::Success, - "Vk::DescriptorPool::allocate(): allocation failed with" << out.first, std::move(out.second)); - return std::move(out.second); + Containers::Pair out = allocateInternal(layout); + CORRADE_ASSERT(out.first() == Result::Success, + "Vk::DescriptorPool::allocate(): allocation failed with" << out.first(), std::move(out.second())); + return std::move(out.second()); } Containers::Optional DescriptorPool::tryAllocate(const VkDescriptorSetLayout layout) { - std::pair out = allocateInternal(layout); - if(out.first != Result::Success) return {}; - return std::move(out.second); + Containers::Pair out = allocateInternal(layout); + if(out.first() != Result::Success) return {}; + return std::move(out.second()); } -std::pair DescriptorPool::allocateInternal(const VkDescriptorSetLayout layout, const UnsignedInt variableDescriptorCount) { +Containers::Pair DescriptorPool::allocateInternal(const VkDescriptorSetLayout layout, const UnsignedInt variableDescriptorCount) { DescriptorSet set{NoCreate}; set._device = _device; set._pool = _handle; @@ -197,16 +198,16 @@ std::pair DescriptorPool::allocateInternal(const VkDescri } DescriptorSet DescriptorPool::allocate(const VkDescriptorSetLayout layout, const UnsignedInt variableDescriptorCount) { - std::pair out = allocateInternal(layout, variableDescriptorCount); - CORRADE_ASSERT(out.first == Result::Success, - "Vk::DescriptorPool::allocate(): allocation failed with" << out.first, std::move(out.second)); - return std::move(out.second); + Containers::Pair out = allocateInternal(layout, variableDescriptorCount); + CORRADE_ASSERT(out.first() == Result::Success, + "Vk::DescriptorPool::allocate(): allocation failed with" << out.first(), std::move(out.second())); + return std::move(out.second()); } Containers::Optional DescriptorPool::tryAllocate(const VkDescriptorSetLayout layout, const UnsignedInt variableDescriptorCount) { - std::pair out = allocateInternal(layout, variableDescriptorCount); - if(out.first != Result::Success) return {}; - return std::move(out.second); + Containers::Pair out = allocateInternal(layout, variableDescriptorCount); + if(out.first() != Result::Success) return {}; + return std::move(out.second()); } void DescriptorPool::reset() { diff --git a/src/Magnum/Vk/DescriptorPool.h b/src/Magnum/Vk/DescriptorPool.h index 58288dbad..9ac49b6bf 100644 --- a/src/Magnum/Vk/DescriptorPool.h +++ b/src/Magnum/Vk/DescriptorPool.h @@ -30,8 +30,6 @@ * @m_since_latest */ -#include - #include "Magnum/Tags.h" #include "Magnum/Vk/Handle.h" #include "Magnum/Vk/visibility.h" @@ -248,8 +246,8 @@ class MAGNUM_VK_EXPORT DescriptorPool { VkDescriptorPool release(); private: - MAGNUM_VK_LOCAL std::pair allocateInternal(VkDescriptorSetLayout layout); - MAGNUM_VK_LOCAL std::pair allocateInternal(VkDescriptorSetLayout layout, UnsignedInt variableDescriptorCount); + MAGNUM_VK_LOCAL Containers::Pair allocateInternal(VkDescriptorSetLayout layout); + MAGNUM_VK_LOCAL Containers::Pair allocateInternal(VkDescriptorSetLayout layout, UnsignedInt variableDescriptorCount); /* Can't be a reference because of the NoCreate constructor */ Device* _device; diff --git a/src/Magnum/Vk/Device.cpp b/src/Magnum/Vk/Device.cpp index bd6c3c885..90c905656 100644 --- a/src/Magnum/Vk/Device.cpp +++ b/src/Magnum/Vk/Device.cpp @@ -105,9 +105,9 @@ struct DeviceCreateInfo::State { Containers::String disabledExtensionsStorage; Containers::Array disabledExtensions; - /* .second = true means the workaround is disabled; the views always point - to the internal KnownWorkarounds array */ - Containers::Array> encounteredWorkarounds; + /* .second() = true means the workaround is disabled; the views always + point to the internal KnownWorkarounds array */ + Containers::Array> encounteredWorkarounds; Containers::Array queues; Containers::StaticArray<32, Float> queuePriorities; Containers::StaticArray<32, Queue*> queueOutput; @@ -665,7 +665,7 @@ void Device::wrap(Instance& instance, const VkPhysicalDevice physicalDevice, con /* Because we have no control over extensions / features, no workarounds are used here -- better to just do nothing than just a partial attempt */ - Containers::Array> encounteredWorkarounds = Implementation::disableAllWorkarounds(); + Containers::Array> encounteredWorkarounds = Implementation::disableAllWorkarounds(); initialize(instance, version, enabledExtensions, encounteredWorkarounds, enabledFeatures); } @@ -762,11 +762,8 @@ Result Device::tryCreateInternal(Instance& instance, const DeviceCreateInfo& inf /* Make a copy of the workarounds list coming from DeviceCreateInfo as initialize() may modify it */ - /** @todo switch to Containers::Pair once it exists and use Utility::copy() - (std::pair isn't trivially copyable, ffs) */ - Containers::Array> encounteredWorkarounds{info._state->encounteredWorkarounds.size()}; - for(std::size_t i = 0; i != encounteredWorkarounds.size(); ++i) - encounteredWorkarounds[i] = info._state->encounteredWorkarounds[i]; + Containers::Array> encounteredWorkarounds{NoInit, info._state->encounteredWorkarounds.size()}; + Utility::copy(info._state->encounteredWorkarounds, encounteredWorkarounds); /* Initialize the enabled extension list and feature-, extension-, workaround-dependent function pointers */ @@ -777,14 +774,14 @@ Result Device::tryCreateInternal(Instance& instance, const DeviceCreateInfo& inf bool workaroundHeaderPrinted = false; for(const auto& workaround: encounteredWorkarounds) { /* Skip disabled workarounds */ - if(workaround.second) continue; + if(workaround.second()) continue; if(!workaroundHeaderPrinted) { workaroundHeaderPrinted = true; Debug{} << "Using device driver workarounds:"; } - Debug{} << " " << workaround.first; + Debug{} << " " << workaround.first(); } } @@ -839,7 +836,7 @@ Result Device::tryCreateInternal(Instance& instance, const DeviceCreateInfo& inf return Result::Success; } -void Device::initialize(Instance& instance, const Version version, const Containers::StringIterable& enabledExtensions, Containers::Array>& encounteredWorkarounds, const DeviceFeatures& enabledFeatures) { +void Device::initialize(Instance& instance, const Version version, const Containers::StringIterable& enabledExtensions, Containers::Array>& encounteredWorkarounds, const DeviceFeatures& enabledFeatures) { /* Mark all known extensions as enabled */ for(const Containers::StringView extension: enabledExtensions) { for(const Version extensionVersion: KnownVersionsForExtensions) { diff --git a/src/Magnum/Vk/Device.h b/src/Magnum/Vk/Device.h index e71196f78..b08154a93 100644 --- a/src/Magnum/Vk/Device.h +++ b/src/Magnum/Vk/Device.h @@ -499,7 +499,7 @@ class MAGNUM_VK_EXPORT Device { tryCreate(Instance&, DeviceCreateInfo&&) */ Result tryCreateInternal(Instance& isntance, const DeviceCreateInfo&, DeviceProperties&&); - MAGNUM_VK_LOCAL void initialize(Instance& instance, Version version, const Containers::StringIterable& enabledExtensions, Containers::Array>& encounteredWorkarounds, const DeviceFeatures& enabledFeatures); + MAGNUM_VK_LOCAL void initialize(Instance& instance, Version version, const Containers::StringIterable& enabledExtensions, Containers::Array>& encounteredWorkarounds, const DeviceFeatures& enabledFeatures); MAGNUM_VK_LOCAL static void getQueueImplementationDefault(Device& self, const VkDeviceQueueInfo2& info, VkQueue& queue); MAGNUM_VK_LOCAL static void getQueueImplementation11(Device& self, const VkDeviceQueueInfo2& info, VkQueue& queue); diff --git a/src/Magnum/Vk/Implementation/DeviceState.cpp b/src/Magnum/Vk/Implementation/DeviceState.cpp index 311a9bc37..1c0e18a45 100644 --- a/src/Magnum/Vk/Implementation/DeviceState.cpp +++ b/src/Magnum/Vk/Implementation/DeviceState.cpp @@ -40,7 +40,7 @@ namespace Magnum { namespace Vk { namespace Implementation { using namespace Containers::Literals; -DeviceState::DeviceState(Device& device, Containers::Array>& encounteredWorkarounds) { +DeviceState::DeviceState(Device& device, Containers::Array>& encounteredWorkarounds) { if(device.isVersionSupported(Version::Vk11)) { if(device.properties().name().hasPrefix("SwiftShader"_s) && !Implementation::isDriverWorkaroundDisabled(encounteredWorkarounds, "swiftshader-crashy-getdevicequeue2"_s)) getDeviceQueueImplementation = &Device::getQueueImplementationDefault; diff --git a/src/Magnum/Vk/Implementation/DeviceState.h b/src/Magnum/Vk/Implementation/DeviceState.h index e4a7fc775..89a905852 100644 --- a/src/Magnum/Vk/Implementation/DeviceState.h +++ b/src/Magnum/Vk/Implementation/DeviceState.h @@ -25,8 +25,6 @@ DEALINGS IN THE SOFTWARE. */ -#include - #include "Magnum/Vk/Vk.h" #include "Magnum/Vk/Vulkan.h" @@ -39,7 +37,7 @@ class RenderPassCreateInfo; namespace Implementation { struct DeviceState { - explicit DeviceState(Device& device, Containers::Array>& encounteredWorkarounds); + explicit DeviceState(Device& device, Containers::Array>& encounteredWorkarounds); void(*getDeviceQueueImplementation)(Device&, const VkDeviceQueueInfo2&, VkQueue&); diff --git a/src/Magnum/Vk/Implementation/DriverWorkaround.cpp b/src/Magnum/Vk/Implementation/DriverWorkaround.cpp index e4b3151f7..7b1df3ed3 100644 --- a/src/Magnum/Vk/Implementation/DriverWorkaround.cpp +++ b/src/Magnum/Vk/Implementation/DriverWorkaround.cpp @@ -24,6 +24,7 @@ */ #include +#include #include #include @@ -90,7 +91,7 @@ Containers::StringView findWorkaround(const Containers::StringView workaround) { } -void disableWorkaround(Containers::Array>& encounteredWorkarounds, const Containers::StringView workaround) { +void disableWorkaround(Containers::Array>& encounteredWorkarounds, const Containers::StringView workaround) { /* Find the workaround. Note that we'll add the found view to the array and not the passed view, as the found view is guaranteed to stay in scope */ @@ -107,14 +108,14 @@ void disableWorkaround(Containers::Array arrayAppend(encounteredWorkarounds, InPlaceInit, found, true); } -Containers::Array> disableAllWorkarounds() { - Containers::Array> encounteredWorkarounds; +Containers::Array> disableAllWorkarounds() { + Containers::Array> encounteredWorkarounds; for(const Containers::StringView i: KnownWorkarounds) arrayAppend(encounteredWorkarounds, InPlaceInit, i, true); return encounteredWorkarounds; } -bool isDriverWorkaroundDisabled(Containers::Array>& encounteredWorkarounds, const Containers::StringView workaround) { +bool isDriverWorkaroundDisabled(Containers::Array>& encounteredWorkarounds, const Containers::StringView workaround) { /* Find the workaround. Note that we'll add the found view to the array and not the passed view, as the found view is guaranteed to stay in scope */ @@ -126,7 +127,7 @@ bool isDriverWorkaroundDisabled(Containers::Array>& encounteredWorkarounds, Containers::StringView workaround); +void disableWorkaround(Containers::Array>& encounteredWorkarounds, Containers::StringView workaround); -bool isDriverWorkaroundDisabled(Containers::Array>& encounteredWorkarounds, Containers::StringView workaround); +bool isDriverWorkaroundDisabled(Containers::Array>& encounteredWorkarounds, Containers::StringView workaround); /* Used by Device::wrap() -- because device extension setup is outside of our control and the function doesn't print anything on the output, it's better to just do nothing at all than silently enabling some subset */ -Containers::Array> disableAllWorkarounds(); +Containers::Array> disableAllWorkarounds(); }}} diff --git a/src/Magnum/Vk/RenderPass.cpp b/src/Magnum/Vk/RenderPass.cpp index cd698f42a..945eb4c4e 100644 --- a/src/Magnum/Vk/RenderPass.cpp +++ b/src/Magnum/Vk/RenderPass.cpp @@ -396,7 +396,7 @@ std::size_t vkSubpassDescriptionExtrasSize(const VkSubpassDescription2& descript (description.pDepthStencilAttachment ? 1 : 0)); } -std::pair vkSubpassDescriptionExtrasInto(const VkSubpassDescription2& description, char* const out) { +Containers::Pair vkSubpassDescriptionExtrasInto(const VkSubpassDescription2& description, char* const out) { /* Not using an array view nor arrayCast() because the output is not guaranteed to be divisible by the structure size and we have nothing else to do with the size either */ @@ -455,9 +455,9 @@ Containers::Array SubpassDescription::vkSubpassDescription /* Fill it with data and return, faking a size of 1 and with a custom deleter that correctly deletes as a char array again */ - std::pair out = vkSubpassDescriptionExtrasInto(_description, storage.exceptPrefix(sizeof(VkSubpassDescription))); - CORRADE_INTERNAL_ASSERT(out.second == extrasSize); - *reinterpret_cast(storage.data()) = out.first; + Containers::Pair out = vkSubpassDescriptionExtrasInto(_description, storage.exceptPrefix(sizeof(VkSubpassDescription))); + CORRADE_INTERNAL_ASSERT(out.second() == extrasSize); + *reinterpret_cast(storage.data()) = out.first(); return Containers::Array{ reinterpret_cast(storage.release()), 1, [](VkSubpassDescription* data, std::size_t) { @@ -726,10 +726,10 @@ Containers::Array RenderPassCreateInfo::vkRenderPassCrea std::size_t extrasOffset = sizeof(VkRenderPassCreateInfo) + structuresSize; info1.pSubpasses = reinterpret_cast(storage + offset); for(std::size_t i = 0; i != _info.subpassCount; ++i) { - std::pair out = vkSubpassDescriptionExtrasInto(_info.pSubpasses[i], storage + extrasOffset); - *reinterpret_cast(storage + offset) = out.first; + Containers::Pair out = vkSubpassDescriptionExtrasInto(_info.pSubpasses[i], storage + extrasOffset); + *reinterpret_cast(storage + offset) = out.first(); offset += sizeof(VkSubpassDescription); - extrasOffset += out.second; + extrasOffset += out.second(); } CORRADE_INTERNAL_ASSERT(extrasOffset == storage.size());