Lugdunum  0.1.0
Buffer.cpp
Go to the documentation of this file.
2 
3 #include <vector>
4 
6 
7 namespace lug {
8 namespace Graphics {
9 namespace Vulkan {
10 namespace API {
11 namespace Builder {
12 
13 Buffer::Buffer(const API::Device& device) : _device{device} {}
14 
15 bool Buffer::build(API::Buffer& buffer, VkResult* returnResult) {
16  const std::vector<uint32_t> queueFamilyIndices(_queueFamilyIndices.begin(), _queueFamilyIndices.end());
17 
18  VkSharingMode sharingMode = VK_SHARING_MODE_EXCLUSIVE;
19  // If we have move than one queueFamilyIndices and exclusive was not manually set
20  if (queueFamilyIndices.size() > 1 && !_exclusive) {
21  sharingMode = VK_SHARING_MODE_CONCURRENT;
22  }
23 
24  // Create the buffer creation information for vkCreateBuffer
25  const VkBufferCreateInfo createInfo{
26  /* createInfo.sType */ VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
27  /* createInfo.pNext */ nullptr,
28  /* createInfo.flags */ _flags,
29  /* createInfo.size */ _size,
30  /* createInfo.usage */ _usage,
31  /* createInfo.sharingMode */ sharingMode,
32  /* createInfo.queueFamilyIndexCount */ static_cast<uint32_t>(queueFamilyIndices.size()),
33  /* createInfo.pQueueFamilyIndices */ queueFamilyIndices.data(), // Convert the set to raw data
34  };
35 
36  // Create the buffer
37  VkBuffer vkBuffer{VK_NULL_HANDLE};
38  VkResult result = vkCreateBuffer(static_cast<VkDevice>(_device), &createInfo, nullptr, &vkBuffer);
39 
40  if (returnResult) {
41  *returnResult = result;
42  }
43 
44  if (result != VK_SUCCESS) {
45  return false;
46  }
47 
48  buffer = API::Buffer(vkBuffer, &_device);
49 
50  return true;
51 }
52 
53 std::unique_ptr<API::Buffer> Buffer::build(VkResult* returnResult) {
54  std::unique_ptr<API::Buffer> buffer = std::make_unique<API::Buffer>();
55  return build(*buffer, returnResult) ? std::move(buffer) : nullptr;
56 }
57 
58 } // Builder
59 } // API
60 } // Vulkan
61 } // Graphics
62 } // lug
Buffer(const API::Device &device)
Definition: Buffer.cpp:13
bool build(API::Buffer &instance, VkResult *returnResult=nullptr)
Definition: Buffer.cpp:15
std::set< uint32_t > _queueFamilyIndices
Definition: Buffer.hpp:46