|
|
|
@ -146,6 +146,7 @@ private: |
|
|
|
|
createRenderPass(); |
|
|
|
|
createGraphicsPipeline(); |
|
|
|
|
createFramebuffers(); |
|
|
|
|
createVertexBuffer(); |
|
|
|
|
createCommandPool(); |
|
|
|
|
createCommandBuffers(); |
|
|
|
|
createSyncObjects(); |
|
|
|
@ -685,6 +686,50 @@ private: |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
VkBuffer vertexBuffer = VK_NULL_HANDLE; |
|
|
|
|
VkDeviceMemory vertexBufferMemory = VK_NULL_HANDLE; |
|
|
|
|
|
|
|
|
|
uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags propertyFlags){ |
|
|
|
|
VkPhysicalDeviceMemoryProperties memoryProperties; |
|
|
|
|
vkGetPhysicalDeviceMemoryProperties(physicalDevice, &memoryProperties); |
|
|
|
|
|
|
|
|
|
for (uint32_t type = 0; type < memoryProperties.memoryTypeCount; type++){ |
|
|
|
|
if ((typeFilter & (1 << type)) && (memoryProperties.memoryTypes[type].propertyFlags & propertyFlags)){ |
|
|
|
|
return type; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
throw std::runtime_error("failed to find suitable memory type!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void createVertexBuffer(){ |
|
|
|
|
VkBufferCreateInfo bufferInfo{}; |
|
|
|
|
bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
|
|
|
|
bufferInfo.size = vertices.size() * sizeof(Vertex); |
|
|
|
|
bufferInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; |
|
|
|
|
bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
|
|
|
|
|
|
|
|
|
vkCreateBuffer(device, &bufferInfo, nullptr, &vertexBuffer); |
|
|
|
|
|
|
|
|
|
VkMemoryRequirements memoryRequirements; |
|
|
|
|
vkGetBufferMemoryRequirements(device, vertexBuffer, &memoryRequirements); |
|
|
|
|
|
|
|
|
|
VkMemoryAllocateInfo allocateInfo {}; |
|
|
|
|
allocateInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
|
|
|
|
allocateInfo.allocationSize = memoryRequirements.size; |
|
|
|
|
allocateInfo.memoryTypeIndex = findMemoryType(memoryRequirements.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); |
|
|
|
|
|
|
|
|
|
vkAllocateMemory(device, &allocateInfo, nullptr, &vertexBufferMemory); |
|
|
|
|
|
|
|
|
|
vkBindBufferMemory(device, vertexBuffer, vertexBufferMemory, 0); |
|
|
|
|
|
|
|
|
|
void* data; |
|
|
|
|
vkMapMemory(device, vertexBufferMemory, 0, bufferInfo.size, 0, &data); |
|
|
|
|
memcpy(data, vertices.data(), bufferInfo.size); |
|
|
|
|
vkUnmapMemory(device, vertexBufferMemory); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VkCommandPool commandPool = VK_NULL_HANDLE; |
|
|
|
|
|
|
|
|
|
std::vector<VkCommandBuffer> commandBuffers; |
|
|
|
@ -746,7 +791,11 @@ private: |
|
|
|
|
scissor.extent = swapchainExtent; |
|
|
|
|
vkCmdSetScissor(commandBuffer, 0, 1, &scissor); |
|
|
|
|
|
|
|
|
|
vkCmdDraw(commandBuffer, 3, 1, 0, 0); |
|
|
|
|
VkBuffer buffers[] = {vertexBuffer}; |
|
|
|
|
VkDeviceSize offsets[] = {0}; |
|
|
|
|
vkCmdBindVertexBuffers(commandBuffer, 0, 1, buffers, offsets); |
|
|
|
|
|
|
|
|
|
vkCmdDraw(commandBuffer, vertices.size(), 1, 0, 0); |
|
|
|
|
|
|
|
|
|
vkCmdEndRenderPass(commandBuffer); |
|
|
|
|
vkEndCommandBuffer(commandBuffer); |
|
|
|
@ -838,6 +887,8 @@ private: |
|
|
|
|
} |
|
|
|
|
void cleanup(){ |
|
|
|
|
cleanupSwapchain(); |
|
|
|
|
vkDestroyBuffer(device, vertexBuffer, nullptr); |
|
|
|
|
vkFreeMemory(device, vertexBufferMemory, nullptr); |
|
|
|
|
for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++){ |
|
|
|
|
vkDestroySemaphore(device, imageAvailableSemaphores[i], nullptr); |
|
|
|
|
vkDestroySemaphore(device, renderFinishedSemaphores[i], nullptr); |
|
|
|
|