SHARE
TWEET

Untitled

a guest Aug 26th, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. void StardustOpenXRFrame::createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer& buffer, VkDeviceMemory& bufferMemory, int &fd, VkMemoryRequirements& memRequirements) {
  3.     VkExternalMemoryBufferCreateInfo externalBufferInfo = {
  4.         VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO,
  5.         nullptr,
  6.         VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
  7.     };
  8.  
  9.     VkBufferCreateInfo bufferInfo = {};
  10.     bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
  11. //    bufferInfo.pNext = &externalBufferInfo;
  12.     bufferInfo.pNext = nullptr;
  13.     bufferInfo.size = size;
  14.     bufferInfo.usage = usage;
  15.     bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
  16.     bufferInfo.queueFamilyIndexCount = 1;
  17.     bufferInfo.pQueueFamilyIndices = &graphics->openxr->vulkan->queueFamilyIndex;
  18.  
  19.     if (vkCreateBuffer(graphics->openxr->vulkan->device, &bufferInfo, nullptr, &buffer) != VK_SUCCESS) {
  20.         throw std::runtime_error("failed to create buffer!");
  21.     }
  22.  
  23.     vkGetBufferMemoryRequirements(graphics->openxr->vulkan->device, buffer, &memRequirements);
  24.  
  25.     const int align_mod = memRequirements.size % memRequirements.alignment;
  26.     const int aligned_size = ((memRequirements.size % memRequirements.alignment) == 0)
  27.                              ? memRequirements.size
  28.                              : (memRequirements.size + memRequirements.alignment - align_mod);
  29.  
  30.  
  31.     VkImportMemoryFdInfoKHR import_memory_info = {
  32.         VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR,
  33.         nullptr,
  34.         VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT,
  35.         fd
  36.     };
  37.  
  38.     VkMemoryAllocateInfo allocInfo = {};
  39.     allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
  40. //    allocInfo.pNext = &import_memory_info;
  41.     allocInfo.pNext = nullptr;
  42.     allocInfo.allocationSize = aligned_size;
  43.     allocInfo.memoryTypeIndex = findMemoryType(memRequirements.memoryTypeBits, properties);
  44.  
  45.     if (vkAllocateMemory(graphics->openxr->vulkan->device, &allocInfo, nullptr, &bufferMemory) != VK_SUCCESS) {
  46.         throw std::runtime_error("failed to allocate buffer memory!");
  47.     }
  48.  
  49.     VkResult result = vkBindBufferMemory(graphics->openxr->vulkan->device, buffer, bufferMemory, 0);
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top