@@ -132,32 +132,34 @@ VulkanImage Allocator::create_image(
132
132
allocate_memory);
133
133
}
134
134
135
+ VulkanBuffer Allocator::create_staging_buffer (const VkDeviceSize size) {
136
+ const VkBufferUsageFlags buffer_usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
137
+
138
+ VmaAllocationCreateInfo alloc_create_info = {};
139
+ alloc_create_info.flags = DEFAULT_ALLOCATION_STRATEGY;
140
+ alloc_create_info.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE;
141
+
142
+ // Staging buffers are accessed by both the CPU and GPU, so set the
143
+ // appropriate flags to indicate that the host device will be accessing
144
+ // the data from this buffer.
145
+ alloc_create_info.flags |= VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT;
146
+ alloc_create_info.usage = VMA_MEMORY_USAGE_AUTO_PREFER_HOST;
147
+ alloc_create_info.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
148
+ alloc_create_info.preferredFlags =
149
+ VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
150
+
151
+ return VulkanBuffer (allocator_, size, alloc_create_info, buffer_usage);
152
+ }
153
+
135
154
VulkanBuffer Allocator::create_storage_buffer (
136
155
const VkDeviceSize size,
137
- const bool gpu_only,
138
156
const bool allocate_memory) {
139
157
const VkBufferUsageFlags buffer_usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
140
158
141
159
VmaAllocationCreateInfo alloc_create_info = {};
142
160
alloc_create_info.flags = DEFAULT_ALLOCATION_STRATEGY;
143
161
alloc_create_info.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE;
144
162
145
- // The create storage buffer will be accessed by both the CPU and GPU, so set
146
- // the appropriate flags to indicate that the host device will be accessing
147
- // the data from this buffer.
148
- if (!gpu_only) {
149
- // Deferred memory allocation should only be used for GPU only buffers.
150
- VK_CHECK_COND (
151
- allocate_memory,
152
- " Only GPU-only buffers should use deferred memory allocation" );
153
-
154
- alloc_create_info.flags |= VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT;
155
- alloc_create_info.usage = VMA_MEMORY_USAGE_AUTO_PREFER_HOST;
156
- alloc_create_info.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
157
- alloc_create_info.preferredFlags = VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
158
- VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
159
- }
160
-
161
163
return VulkanBuffer (
162
164
allocator_, size, alloc_create_info, buffer_usage, allocate_memory);
163
165
}
@@ -170,9 +172,7 @@ VulkanBuffer Allocator::create_uniform_buffer(const VkDeviceSize size) {
170
172
171
173
VkBufferUsageFlags buffer_usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
172
174
173
- VulkanBuffer uniform_buffer (
174
- allocator_, size, alloc_create_info, buffer_usage);
175
- return uniform_buffer;
175
+ return VulkanBuffer (allocator_, size, alloc_create_info, buffer_usage);
176
176
}
177
177
178
178
} // namespace vkapi
0 commit comments