| 112 | } |
| 113 | |
| 114 | bool TextureVk::Init(ovrTextureType Type, int Width, int Height, int MipLevels, int SampleCount, |
| 115 | int ArraySize, ovrTextureFormat Format, unsigned int MiscFlags, unsigned int BindFlags) |
| 116 | { |
| 117 | VK_DEVICE_FUNCTION(m_device, vkCreateImage); |
| 118 | VK_DEVICE_FUNCTION(m_device, vkGetImageMemoryRequirements); |
| 119 | VK_DEVICE_FUNCTION(m_device, vkAllocateMemory); |
| 120 | VK_DEVICE_FUNCTION(m_device, vkBindImageMemory); |
| 121 | VK_DEVICE_FUNCTION(m_device, vkFreeMemory); |
| 122 | VK_DEVICE_FUNCTION(m_device, vkDestroyImage); |
| 123 | |
| 124 | VkExternalMemoryImageCreateInfoKHR external_create_info = { VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO_KHR }; |
| 125 | external_create_info.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR; |
| 126 | |
| 127 | VkImageCreateInfo create_info = { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO }; |
| 128 | if (Type == ovrTexture_2D_External) |
| 129 | create_info.pNext = &external_create_info; |
| 130 | create_info.imageType = VK_IMAGE_TYPE_2D; |
| 131 | create_info.format = TextureFormatToVkFormat(Format); |
| 132 | create_info.extent.width = Width; |
| 133 | create_info.extent.height = Height; |
| 134 | create_info.extent.depth = 1; |
| 135 | create_info.mipLevels = MipLevels; |
| 136 | create_info.arrayLayers = ArraySize; |
| 137 | create_info.samples = (VkSampleCountFlagBits)SampleCount; |
| 138 | create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 139 | create_info.usage = BindFlagsToVkImageUsageFlags(BindFlags); |
| 140 | create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 141 | |
| 142 | if (vkCreateImage(m_device, &create_info, nullptr, &m_image) != VK_SUCCESS) |
| 143 | return false; |
| 144 | |
| 145 | VkMemoryRequirements memReqs; |
| 146 | vkGetImageMemoryRequirements(m_device, m_image, &memReqs); |
| 147 | |
| 148 | VkExportMemoryAllocateInfoKHR export_allocate_info = { VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR }; |
| 149 | export_allocate_info.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR; |
| 150 | |
| 151 | VkMemoryAllocateInfo memAlloc = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO }; |
| 152 | if (Type == ovrTexture_2D_External) |
| 153 | memAlloc.pNext = &export_allocate_info; |
| 154 | memAlloc.allocationSize = memReqs.size; |
| 155 | if (!GetMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &memAlloc.memoryTypeIndex)) |
| 156 | return false; |
| 157 | |
| 158 | if (vkAllocateMemory(m_device, &memAlloc, nullptr, &m_memory) != VK_SUCCESS) |
| 159 | return false; |
| 160 | |
| 161 | if (vkBindImageMemory(m_device, m_image, m_memory, 0) != VK_SUCCESS) |
| 162 | return false; |
| 163 | |
| 164 | if (Type == ovrTexture_2D_External) |
| 165 | { |
| 166 | VK_DEVICE_FUNCTION(m_device, vkCreateCommandPool); |
| 167 | VK_DEVICE_FUNCTION(m_device, vkDestroyCommandPool); |
| 168 | VK_DEVICE_FUNCTION(m_device, vkAllocateCommandBuffers); |
| 169 | VK_DEVICE_FUNCTION(m_device, vkCmdPipelineBarrier); |
| 170 | VK_DEVICE_FUNCTION(m_device, vkQueueSubmit); |
| 171 | VK_DEVICE_FUNCTION(m_device, vkBeginCommandBuffer); |
no outgoing calls
no test coverage detected