Skip to content

Commit a4efbad

Browse files
authored
Change *Builder::with_implicit_sharing_mode to select concurrent sharing mode when the queueFamilyIndexCount is greater than 1, not different from zero. (#1218)
1 parent e6ec529 commit a4efbad

File tree

4 files changed

+19
-53
lines changed

4 files changed

+19
-53
lines changed

framework/builder_base.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ inline BuilderType &BuilderBase<bindingType, BuilderType, CreateInfoType>::with_
123123
template <vkb::BindingType bindingType, typename BuilderType, typename CreateInfoType>
124124
inline BuilderType &BuilderBase<bindingType, BuilderType, CreateInfoType>::with_implicit_sharing_mode()
125125
{
126-
create_info.sharingMode = (create_info.queueFamilyIndexCount != 0) ? vk::SharingMode::eConcurrent : vk::SharingMode::eExclusive;
126+
create_info.sharingMode = (1 < create_info.queueFamilyIndexCount) ? vk::SharingMode::eConcurrent : vk::SharingMode::eExclusive;
127127
return *static_cast<BuilderType *>(this);
128128
}
129129

@@ -153,11 +153,11 @@ inline BuilderType &BuilderBase<bindingType, BuilderType, CreateInfoType>::with_
153153
{
154154
if constexpr (bindingType == vkb::BindingType::Cpp)
155155
{
156-
create_info.sharingMode = static_cast<VkSharingMode>(sharing_mode);
156+
create_info.sharingMode = sharing_mode;
157157
}
158158
else
159159
{
160-
create_info.sharingMode = sharing_mode;
160+
create_info.sharingMode = static_cast<vk::SharingMode>(sharing_mode);
161161
}
162162
return *static_cast<BuilderType *>(this);
163163
}

framework/core/buffer.h

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct BufferBuilder
4545
using DeviceSizeType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::DeviceSize, VkDeviceSize>::type;
4646
using SharingModeType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::SharingMode, VkSharingMode>::type;
4747

48-
using DeviceType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vkb::core::HPPDevice, vkb::Device>::type;
48+
using DeviceType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vkb::core::HPPDevice, vkb::Device>::type;
4949

5050
private:
5151
using Parent = vkb::BuilderBase<bindingType, BufferBuilder<bindingType>, BufferCreateInfoType>;
@@ -56,8 +56,6 @@ struct BufferBuilder
5656
Buffer<bindingType> build(DeviceType &device) const;
5757
BufferPtr<bindingType> build_unique(DeviceType &device) const;
5858
BufferBuilder &with_flags(BufferCreateFlagsType flags);
59-
BufferBuilder &with_implicit_sharing_mode();
60-
BufferBuilder &with_sharing_mode(SharingModeType sharing_mode);
6159
BufferBuilder &with_usage(BufferUsageFlagsType usage);
6260
};
6361

@@ -94,23 +92,6 @@ inline BufferBuilder<bindingType> &BufferBuilder<bindingType>::with_flags(Buffer
9492
return *this;
9593
}
9694

97-
template <vkb::BindingType bindingType>
98-
inline BufferBuilder<bindingType> &BufferBuilder<bindingType>::with_implicit_sharing_mode()
99-
{
100-
if (this->create_info.queueFamilyIndexCount != 0)
101-
{
102-
this->create_info.sharingMode = vk::SharingMode::eConcurrent;
103-
}
104-
return *this;
105-
}
106-
107-
template <vkb::BindingType bindingType>
108-
inline BufferBuilder<bindingType> &BufferBuilder<bindingType>::with_sharing_mode(SharingModeType sharing_mode)
109-
{
110-
this->create_info.sharingMode = sharing_mode;
111-
return *this;
112-
}
113-
11495
template <vkb::BindingType bindingType>
11596
inline BufferBuilder<bindingType> &BufferBuilder<bindingType>::with_usage(BufferUsageFlagsType usage)
11697
{
@@ -181,6 +162,9 @@ class Buffer
181162
*/
182163
DeviceSizeType get_size() const;
183164

165+
private:
166+
static Buffer<vkb::BindingType::Cpp> create_staging_buffer_impl(vkb::core::HPPDevice &device, vk::DeviceSize size, const void *data);
167+
184168
private:
185169
vk::DeviceSize size = 0;
186170
};
@@ -198,17 +182,24 @@ inline Buffer<bindingType> Buffer<bindingType>::create_staging_buffer(DeviceType
198182
template <vkb::BindingType bindingType>
199183
inline Buffer<bindingType> Buffer<bindingType>::create_staging_buffer(DeviceType &device, DeviceSizeType size, const void *data)
200184
{
201-
BufferBuilder<bindingType> builder(size);
202-
builder.with_vma_flags(VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT);
203185
if constexpr (bindingType == vkb::BindingType::Cpp)
204186
{
205-
builder.with_usage(vk::BufferUsageFlagBits::eTransferSrc);
187+
return create_staging_buffer_impl(device, size, data);
206188
}
207189
else
208190
{
209-
builder.with_usage(static_cast<VkBufferUsageFlagBits>(vk::BufferUsageFlagBits::eTransferSrc));
191+
BufferCpp buffer = create_staging_buffer_impl(reinterpret_cast<vkb::core::HPPDevice &>(device), static_cast<vk::DeviceSize>(size), data);
192+
return std::move(*reinterpret_cast<BufferC *>(&buffer));
210193
}
211-
Buffer result(device, builder);
194+
}
195+
196+
template <vkb::BindingType bindingType>
197+
inline BufferCpp Buffer<bindingType>::create_staging_buffer_impl(vkb::core::HPPDevice &device, vk::DeviceSize size, const void *data)
198+
{
199+
BufferBuilderCpp builder(size);
200+
builder.with_vma_flags(VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT)
201+
.with_usage(vk::BufferUsageFlagBits::eTransferSrc);
202+
BufferCpp result(device, builder);
212203
if (data != nullptr)
213204
{
214205
result.update(data, size);

framework/core/hpp_image.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,6 @@ struct HPPImageBuilder : public vkb::BuilderBaseCpp<HPPImageBuilder, vk::ImageCr
101101
return *this;
102102
}
103103

104-
HPPImageBuilder &with_implicit_sharing_mode()
105-
{
106-
if (create_info.queueFamilyIndexCount != 0)
107-
{
108-
create_info.sharingMode = vk::SharingMode::eConcurrent;
109-
}
110-
return *this;
111-
}
112-
113104
HPPImage build(HPPDevice &device) const;
114105
HPPImagePtr build_unique(HPPDevice &device) const;
115106
};

framework/core/image.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@ struct ImageBuilder : public vkb::BuilderBaseC<ImageBuilder, VkImageCreateInfo>
7070
return *this;
7171
}
7272

73-
ImageBuilder &with_sharing_mode(VkSharingMode sharing_mode)
74-
{
75-
get_create_info().sharingMode = sharing_mode;
76-
return *this;
77-
}
78-
7973
ImageBuilder &with_flags(VkImageCreateFlags flags)
8074
{
8175
get_create_info().flags = flags;
@@ -112,16 +106,6 @@ struct ImageBuilder : public vkb::BuilderBaseC<ImageBuilder, VkImageCreateInfo>
112106
return *this;
113107
}
114108

115-
ImageBuilder &with_implicit_sharing_mode()
116-
{
117-
VkImageCreateInfo &create_info = get_create_info();
118-
if (create_info.queueFamilyIndexCount != 0)
119-
{
120-
create_info.sharingMode = VK_SHARING_MODE_CONCURRENT;
121-
}
122-
return *this;
123-
}
124-
125109
template <typename ExtensionType>
126110
ImageBuilder &with_extension(ExtensionType &extension)
127111
{

0 commit comments

Comments
 (0)