diff --git a/framework/builder_base.h b/framework/builder_base.h index 61ed8b1d7d..b70cb7b1db 100644 --- a/framework/builder_base.h +++ b/framework/builder_base.h @@ -123,7 +123,7 @@ inline BuilderType &BuilderBase::with_ template inline BuilderType &BuilderBase::with_implicit_sharing_mode() { - create_info.sharingMode = (create_info.queueFamilyIndexCount != 0) ? vk::SharingMode::eConcurrent : vk::SharingMode::eExclusive; + create_info.sharingMode = (1 < create_info.queueFamilyIndexCount) ? vk::SharingMode::eConcurrent : vk::SharingMode::eExclusive; return *static_cast(this); } @@ -153,11 +153,11 @@ inline BuilderType &BuilderBase::with_ { if constexpr (bindingType == vkb::BindingType::Cpp) { - create_info.sharingMode = static_cast(sharing_mode); + create_info.sharingMode = sharing_mode; } else { - create_info.sharingMode = sharing_mode; + create_info.sharingMode = static_cast(sharing_mode); } return *static_cast(this); } diff --git a/framework/core/buffer.h b/framework/core/buffer.h index f451cb5735..211ed16d58 100644 --- a/framework/core/buffer.h +++ b/framework/core/buffer.h @@ -45,7 +45,7 @@ struct BufferBuilder using DeviceSizeType = typename std::conditional::type; using SharingModeType = typename std::conditional::type; - using DeviceType = typename std::conditional::type; + using DeviceType = typename std::conditional::type; private: using Parent = vkb::BuilderBase, BufferCreateInfoType>; @@ -56,8 +56,6 @@ struct BufferBuilder Buffer build(DeviceType &device) const; BufferPtr build_unique(DeviceType &device) const; BufferBuilder &with_flags(BufferCreateFlagsType flags); - BufferBuilder &with_implicit_sharing_mode(); - BufferBuilder &with_sharing_mode(SharingModeType sharing_mode); BufferBuilder &with_usage(BufferUsageFlagsType usage); }; @@ -94,23 +92,6 @@ inline BufferBuilder &BufferBuilder::with_flags(Buffer return *this; } -template -inline BufferBuilder &BufferBuilder::with_implicit_sharing_mode() -{ - if (this->create_info.queueFamilyIndexCount != 0) - { - this->create_info.sharingMode = vk::SharingMode::eConcurrent; - } - return *this; -} - -template -inline BufferBuilder &BufferBuilder::with_sharing_mode(SharingModeType sharing_mode) -{ - this->create_info.sharingMode = sharing_mode; - return *this; -} - template inline BufferBuilder &BufferBuilder::with_usage(BufferUsageFlagsType usage) { @@ -181,6 +162,9 @@ class Buffer */ DeviceSizeType get_size() const; + private: + static Buffer create_staging_buffer_impl(vkb::core::HPPDevice &device, vk::DeviceSize size, const void *data); + private: vk::DeviceSize size = 0; }; @@ -198,17 +182,24 @@ inline Buffer Buffer::create_staging_buffer(DeviceType template inline Buffer Buffer::create_staging_buffer(DeviceType &device, DeviceSizeType size, const void *data) { - BufferBuilder builder(size); - builder.with_vma_flags(VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT); if constexpr (bindingType == vkb::BindingType::Cpp) { - builder.with_usage(vk::BufferUsageFlagBits::eTransferSrc); + return create_staging_buffer_impl(device, size, data); } else { - builder.with_usage(static_cast(vk::BufferUsageFlagBits::eTransferSrc)); + BufferCpp buffer = create_staging_buffer_impl(reinterpret_cast(device), static_cast(size), data); + return std::move(*reinterpret_cast(&buffer)); } - Buffer result(device, builder); +} + +template +inline BufferCpp Buffer::create_staging_buffer_impl(vkb::core::HPPDevice &device, vk::DeviceSize size, const void *data) +{ + BufferBuilderCpp builder(size); + builder.with_vma_flags(VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT) + .with_usage(vk::BufferUsageFlagBits::eTransferSrc); + BufferCpp result(device, builder); if (data != nullptr) { result.update(data, size); diff --git a/framework/core/hpp_image.h b/framework/core/hpp_image.h index fe591e49fd..9a780e44b5 100644 --- a/framework/core/hpp_image.h +++ b/framework/core/hpp_image.h @@ -101,15 +101,6 @@ struct HPPImageBuilder : public vkb::BuilderBaseCpp return *this; } - ImageBuilder &with_sharing_mode(VkSharingMode sharing_mode) - { - get_create_info().sharingMode = sharing_mode; - return *this; - } - ImageBuilder &with_flags(VkImageCreateFlags flags) { get_create_info().flags = flags; @@ -112,16 +106,6 @@ struct ImageBuilder : public vkb::BuilderBaseC return *this; } - ImageBuilder &with_implicit_sharing_mode() - { - VkImageCreateInfo &create_info = get_create_info(); - if (create_info.queueFamilyIndexCount != 0) - { - create_info.sharingMode = VK_SHARING_MODE_CONCURRENT; - } - return *this; - } - template ImageBuilder &with_extension(ExtensionType &extension) {