use vulkan memory allocator for buffers and images

main
Benjamin Kraft 2 weeks ago
parent c01d18aa1b
commit 3acf80b3ee
  1. 14
      CMakeLists.txt
  2. 6
      include/glm.h
  3. 3
      include/vulkan/application.hpp
  4. 21
      include/vulkan/buffer.hpp
  5. 6
      include/vulkan/image.hpp
  6. 9
      include/vulkan/instance.hpp
  7. 2
      include/vulkan/pipeline.hpp
  8. 2
      include/vulkan/vertex.hpp
  9. 68
      src/vulkan/application.cpp
  10. 89
      src/vulkan/buffer.cpp
  11. 21
      src/vulkan/image.cpp
  12. 34
      src/vulkan/instance.cpp
  13. 3
      src/vulkan/swapchain.cpp
  14. 2
      src/vulkan/vma.cpp

@ -10,5 +10,17 @@ find_package(Vulkan REQUIRED)
find_package(glfw3 REQUIRED)
find_package(glm REQUIRED)
target_link_libraries(VulkanSimulation glfw Vulkan::Vulkan)
include(FetchContent)
FetchContent_Declare(vma
GIT_REPOSITORY https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator.git
GIT_TAG v3.1.0
GIT_PROGRESS ON
FIND_PACKAGE_ARGS 3.1.0)
FetchContent_MakeAvailable(vma)
target_link_libraries(VulkanSimulation glm::glm glfw Vulkan::Vulkan GPUOpen::VulkanMemoryAllocator)
target_include_directories(VulkanSimulation PRIVATE include)
target_compile_definitions(VulkanSimulation PRIVATE
GLM_FORCE_RADIANS
GLM_FORCE_DEPTH_ZERO_TO_ONE
)

@ -1,6 +0,0 @@
#pragma once
#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>

@ -46,12 +46,9 @@ private:
Buffer* vertexBuffer = nullptr;
Buffer* indexBuffer = nullptr;
Buffer* uniformBuffer = nullptr;
CommandPool* commandPool = nullptr;
ComputePipeline* computePipeline = nullptr;
void* uniformBufferMapped = nullptr;
void updateUniformBuffer();
void recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex);

@ -3,27 +3,22 @@
#include <vulkan/vulkan_core.h>
#include <stdexcept>
#include "vertex.hpp"
const std::vector<uint32_t> indices = {
0, 1, 2, 0, 3, 1,
4, 5, 6, 4, 7, 5
};
#include "vk_mem_alloc.h"
class Instance;
class CommandPool;
class Buffer {
public:
explicit Buffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties);
explicit Buffer(VkDeviceSize size, VkBufferUsageFlags bufferUsage,
VmaMemoryUsage memoryUsage, VmaAllocationCreateFlags flags);
explicit Buffer(VkDeviceSize size, void* data, VkDeviceSize dataSize, VkBufferUsageFlags bufferUsage,
VmaMemoryUsage memoryUsage, VmaAllocationCreateFlags flags);
~Buffer();
VkBuffer handle = VK_NULL_HANDLE;
VkDeviceMemory memory = VK_NULL_HANDLE;
VmaAllocation allocation = VK_NULL_HANDLE;
VmaAllocationInfo allocationInfo {};
VkDeviceSize size;
static Buffer* createStagedVertexBuffer();
static Buffer* createStagedIndexBuffer();
void copyTo(Buffer* dst, CommandPool* commandPool);
private:
void copyTo(Buffer* dst);
};

@ -1,13 +1,14 @@
#pragma once
#include <vulkan/vulkan.h>
#include "vk_mem_alloc.h"
class Instance;
class Image {
public:
explicit Image(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling,
VkImageUsageFlags usage, VkMemoryPropertyFlags properties);
VkImageUsageFlags usage);
~Image();
VkImageView createView(VkFormat format, VkImageAspectFlags aspectFlags);
@ -15,5 +16,6 @@ public:
VkImage handle = VK_NULL_HANDLE;
VkImageView view = VK_NULL_HANDLE;
private:
VkDeviceMemory memory = VK_NULL_HANDLE;
VmaAllocation allocation = VK_NULL_HANDLE;
VmaAllocationInfo allocationInfo {};
};

@ -4,6 +4,9 @@
#include <GLFW/glfw3.h>
#include <optional>
#include <set>
#include "vk_mem_alloc.h"
class CommandPool;
class Instance {
public:
@ -14,10 +17,13 @@ public:
VkSurfaceKHR surface = VK_NULL_HANDLE;
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
VkDevice device = VK_NULL_HANDLE;
VmaAllocator allocator = VK_NULL_HANDLE;
VkQueue graphicsQueue = VK_NULL_HANDLE;
VkQueue presentQueue = VK_NULL_HANDLE;
VkQueue computeQueue = VK_NULL_HANDLE;
CommandPool* commandPool = nullptr;
struct QueueFamilyIndices {
std::optional<uint32_t> graphicsFamily;
std::optional<uint32_t> computeFamily;
@ -49,8 +55,9 @@ private:
void createSurface();
void pickPhysicalDevice();
void createLogicalDevice();
void createAllocator();
bool isDeviceSuitable(VkPhysicalDevice physicalDevice);
bool isDeviceSuitable(VkPhysicalDevice potentialPhysicalDevice);
static bool checkDeviceExtensionSupport(VkPhysicalDevice device);

@ -1,6 +1,6 @@
#pragma once
#include "../glm.h"
#include <glm/mat4x4.hpp>
#include <vulkan/vulkan.h>
class Instance;

@ -1,6 +1,6 @@
#pragma once
#include "../glm.h"
#include <glm/vec3.hpp>
#include <vulkan/vulkan.h>
#include <array>

@ -6,41 +6,58 @@
#include "vulkan/command_pool.hpp"
#include "vulkan/image.hpp"
#include <glm/gtc/matrix_transform.hpp>
Application::Application() {
new Instance;
swapchain = new Swapchain();
graphicsPipeline = new Pipeline(swapchain->renderPass);
auto stagedVertexBuffer = Buffer::createStagedVertexBuffer();
vertexBuffer = new Buffer(stagedVertexBuffer->size,
VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
std::vector<Vertex> vertices = {
{{0.0, -0.5, 0}, {1, 0, 0}},
{{0.5, 0.5, 0}, {0, 1, 0}},
{{-0.5, 0.5, 0}, {0, 0, 1}},
{{0.8, -0.5, 0}, {1, 1, 1}}
};
vertices.insert(vertices.end(), vertices.begin(), vertices.end());
for (size_t i = 4; i < vertices.size(); i++){
vertices[i].pos.z -= 0.5f;
}
VkDeviceSize size = vertices.size() * sizeof(Vertex);
vertexBuffer = new Buffer(size, vertices.data(), size,
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE, 0);
auto stagedIndexBuffer = Buffer::createStagedIndexBuffer();
indexBuffer = new Buffer(stagedIndexBuffer->size,
VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
std::vector<uint32_t> indices = {
0, 1, 2, 0, 3, 1,
4, 5, 6, 4, 7, 5
};
size = indices.size() * sizeof(uint32_t);
indexBuffer = new Buffer(size, indices.data(), size,
VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE, 0);
VkDeviceSize bufferSize = sizeof(UniformBufferObject);
uniformBuffer = new Buffer(bufferSize,
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
vkMapMemory(Instance::instance->device, uniformBuffer->memory, 0, bufferSize, 0, &uniformBufferMapped);
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE,
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT);
graphicsPipeline->createDescriptorSet(uniformBuffer, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
computePipeline = new ComputePipeline(vertexBuffer);
commandPool = new CommandPool();
stagedVertexBuffer->copyTo(vertexBuffer, commandPool);
stagedIndexBuffer->copyTo(indexBuffer, commandPool);
delete stagedVertexBuffer;
delete stagedIndexBuffer;
createSyncObjects();
recordComputeCommandBuffer();
char* stats;
vmaBuildStatsString(Instance::instance->allocator, &stats, VK_TRUE);
// printf("%s", stats);
}
void Application::updateUniformBuffer() {
@ -56,7 +73,7 @@ void Application::updateUniformBuffer() {
0.1f, 10.f);
ubo.projection[1][1] *= -1;
memcpy(uniformBufferMapped, &ubo, sizeof(UniformBufferObject));
memcpy(uniformBuffer->allocationInfo.pMappedData, &ubo, sizeof(UniformBufferObject));
}
void Application::recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) {
@ -102,7 +119,7 @@ void Application::recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t im
vkCmdBindIndexBuffer(commandBuffer, indexBuffer->handle, 0, VK_INDEX_TYPE_UINT32);
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline->layout, 0, 1, &graphicsPipeline->descriptorSet, 0, nullptr);
vkCmdDrawIndexed(commandBuffer, indices.size(), 1, 0, 0, 0);
vkCmdDrawIndexed(commandBuffer, 12, 1, 0, 0, 0);
vkCmdEndRenderPass(commandBuffer);
vkEndCommandBuffer(commandBuffer);
@ -144,8 +161,8 @@ void Application::drawFrame() {
vkResetFences(Instance::instance->device, 1, &renderInFlightFence);
vkResetCommandBuffer(commandPool->graphicsBuffer, 0);
recordCommandBuffer(commandPool->graphicsBuffer, imageIndex);
vkResetCommandBuffer(Instance::instance->commandPool->graphicsBuffer, 0);
recordCommandBuffer(Instance::instance->commandPool->graphicsBuffer, imageIndex);
updateUniformBuffer();
@ -158,7 +175,7 @@ void Application::drawFrame() {
submitInfo.pWaitSemaphores = waitSemaphores;
submitInfo.pWaitDstStageMask = waitStages;
submitInfo.commandBufferCount = 1;
submitInfo.pCommandBuffers = &commandPool->graphicsBuffer;
submitInfo.pCommandBuffers = &Instance::instance->commandPool->graphicsBuffer;
VkSemaphore signalSemaphores[] = {renderFinishedSemaphore};
submitInfo.signalSemaphoreCount = 1;
@ -190,7 +207,7 @@ void Application::update() {
VkSubmitInfo submit {};
submit.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
submit.commandBufferCount = 1;
submit.pCommandBuffers = &commandPool->computeBuffer;
submit.pCommandBuffers = &Instance::instance->commandPool->computeBuffer;
submit.signalSemaphoreCount = 1;
submit.pSignalSemaphores = &computeFinishedSemaphore;
@ -198,7 +215,7 @@ void Application::update() {
}
void Application::recordComputeCommandBuffer() {
VkCommandBuffer buffer = commandPool->computeBuffer;
VkCommandBuffer buffer = Instance::instance->commandPool->computeBuffer;
VkCommandBufferBeginInfo beginInfo {};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
@ -219,7 +236,6 @@ Application::~Application() {
vkDestroySemaphore(Instance::instance->device, computeFinishedSemaphore, nullptr);
vkDestroyFence(Instance::instance->device, renderInFlightFence, nullptr);
vkDestroyFence(Instance::instance->device, computeInFlightFence, nullptr);
delete commandPool;
delete vertexBuffer;
delete indexBuffer;
delete uniformBuffer;

@ -1,85 +1,50 @@
#include <vector>
#include <cstring>
#include "vulkan/buffer.hpp"
#include "vulkan/vertex.hpp"
#include "vulkan/instance.hpp"
#include "vulkan/command_pool.hpp"
#include "vulkan/utils.h"
Buffer::Buffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties) : size(size){
VkBufferCreateInfo bufferInfo{};
bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
bufferInfo.size = size;
bufferInfo.usage = usage;
bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
#include "vk_mem_alloc.h"
vkCreateBuffer(Instance::instance->device, &bufferInfo, nullptr, &handle);
Buffer::Buffer(VkDeviceSize size, VkBufferUsageFlags bufferUsage, VmaMemoryUsage memoryUsage, VmaAllocationCreateFlags flags) : size(size) {
VkBufferCreateInfo bufferCreateInfo {};
bufferCreateInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
bufferCreateInfo.size = size;
bufferCreateInfo.usage = bufferUsage;
bufferCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
VkMemoryRequirements memoryRequirements;
vkGetBufferMemoryRequirements(Instance::instance->device, handle, &memoryRequirements);
VmaAllocationCreateInfo allocationCreateInfo {};
allocationCreateInfo.usage = memoryUsage;
allocationCreateInfo.flags = flags;
VkMemoryAllocateInfo allocateInfo {};
allocateInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
allocateInfo.allocationSize = memoryRequirements.size;
allocateInfo.memoryTypeIndex = findMemoryType(memoryRequirements.memoryTypeBits, properties);
vkAllocateMemory(Instance::instance->device, &allocateInfo, nullptr, &memory);
vkBindBufferMemory(Instance::instance->device, handle, memory, 0);
}
Buffer::~Buffer() {
vkFreeMemory(Instance::instance->device, memory, nullptr);
vkDestroyBuffer(Instance::instance->device, handle, nullptr);
vmaCreateBuffer(Instance::instance->allocator, &bufferCreateInfo, &allocationCreateInfo, &handle, &allocation, &allocationInfo);;
}
Buffer* Buffer::createStagedVertexBuffer() {
std::vector<Vertex> vertices = {
{{0.0, -0.5, 0}, {1, 0, 0}},
{{0.5, 0.5, 0}, {0, 1, 0}},
{{-0.5, 0.5, 0}, {0, 0, 1}},
{{0.8, -0.5, 0}, {1, 1, 1}}
};
vertices.insert(vertices.end(), vertices.begin(), vertices.end());
Buffer::Buffer(VkDeviceSize size, void *data, VkDeviceSize dataSize, VkBufferUsageFlags bufferUsage,
VmaMemoryUsage memoryUsage, VmaAllocationCreateFlags flags)
: Buffer(size, bufferUsage | VK_BUFFER_USAGE_TRANSFER_DST_BIT, memoryUsage, flags){
for (size_t i = 4; i < vertices.size(); i++){
vertices[i].pos.z -= 0.5f;
}
Buffer stagingBuffer(
size,
VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
VMA_MEMORY_USAGE_AUTO,
VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT
);
VkDeviceSize size = vertices.size() * sizeof(Vertex);
VkBufferUsageFlags usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
VkMemoryPropertyFlags properties = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
auto stagingBuffer = new Buffer(size, usage, properties);
void* data;
vkMapMemory(Instance::instance->device, stagingBuffer->memory, 0, size, 0, &data);
memcpy(data, vertices.data(), size);
vkUnmapMemory(Instance::instance->device, stagingBuffer->memory);
return stagingBuffer;
memcpy(stagingBuffer.allocationInfo.pMappedData, data, dataSize);
stagingBuffer.copyTo(this);
}
Buffer *Buffer::createStagedIndexBuffer() {
VkDeviceSize size = indices.size() * sizeof(uint32_t);
VkBufferUsageFlags usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
VkMemoryPropertyFlags properties = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
auto stagingBuffer = new Buffer(size, usage, properties);
uint32_t *data;
vkMapMemory(Instance::instance->device, stagingBuffer->memory, 0, size, 0, reinterpret_cast<void**>(&data));
memcpy(data, indices.data(), sizeof(uint32_t) * indices.size());
vkUnmapMemory(Instance::instance->device, stagingBuffer->memory);
return stagingBuffer;
Buffer::~Buffer() {
vmaDestroyBuffer(Instance::instance->allocator, handle, allocation);
}
void Buffer::copyTo(Buffer *dst, CommandPool* commandPool) {
void Buffer::copyTo(Buffer *dst) {
VkCommandBufferAllocateInfo allocateInfo {};
allocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
allocateInfo.commandPool = commandPool->handle;
allocateInfo.commandPool = Instance::instance->commandPool->handle;
allocateInfo.commandBufferCount = 1;
VkCommandBuffer commandBuffer;
@ -103,5 +68,5 @@ void Buffer::copyTo(Buffer *dst, CommandPool* commandPool) {
vkQueueSubmit(Instance::instance->graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE);
vkDeviceWaitIdle(Instance::instance->device);
vkFreeCommandBuffers(Instance::instance->device, commandPool->handle, 1, &commandBuffer);
vkFreeCommandBuffers(Instance::instance->device, Instance::instance->commandPool->handle, 1, &commandBuffer);
}

@ -1,10 +1,11 @@
#include <cstdio>
#include "vulkan/image.hpp"
#include "vulkan/instance.hpp"
#include "vulkan/utils.h"
Image::Image(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling,
VkImageUsageFlags usage, VkMemoryPropertyFlags properties) {
VkImageUsageFlags usage) {
VkImageCreateInfo imageCreateInfo {};
imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
@ -21,25 +22,17 @@ Image::Image(uint32_t width, uint32_t height, VkFormat format, VkImageTiling til
imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
imageCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
vkCreateImage(Instance::instance->device, &imageCreateInfo, nullptr, &handle);
VmaAllocationCreateInfo allocationCreateInfo {};
allocationCreateInfo.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE;
allocationCreateInfo.flags = 0;
VkMemoryRequirements memoryRequirements;
vkGetImageMemoryRequirements(Instance::instance->device, handle, &memoryRequirements);
VkMemoryAllocateInfo allocateInfo {};
allocateInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
allocateInfo.allocationSize = memoryRequirements.size;
allocateInfo.memoryTypeIndex = findMemoryType(memoryRequirements.memoryTypeBits, properties);
vkAllocateMemory(Instance::instance->device, &allocateInfo, nullptr, &memory);
vkBindImageMemory(Instance::instance->device, handle, memory, 0);
vmaCreateImage(Instance::instance->allocator, &imageCreateInfo, &allocationCreateInfo, &handle, &allocation, &allocationInfo);
}
Image::~Image() {
vkFreeMemory(Instance::instance->device, memory, nullptr);
if (view)
vkDestroyImageView(Instance::instance->device, view, nullptr);
vkDestroyImage(Instance::instance->device, handle, nullptr);
vmaDestroyImage(Instance::instance->allocator, handle, allocation);
}
VkImageView Image::createView(VkFormat format, VkImageAspectFlags aspectFlags) {

@ -2,6 +2,8 @@
#include <vector>
#include "vulkan/instance.hpp"
#include "vulkan/swapchain.hpp"
#include "vulkan/command_pool.hpp"
#include "vk_mem_alloc.h"
#include <cstring>
const std::vector<const char*> deviceExtensions = {
@ -50,13 +52,14 @@ Instance* Instance::instance = nullptr;
Instance::Instance() {
instance = this;
initWindow();
createInstance();
createSurface();
pickPhysicalDevice();
createLogicalDevice();
createAllocator();
commandPool = new CommandPool;
}
void Instance::initWindow() {
@ -79,7 +82,7 @@ void Instance::createInstance() {
applicationInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
applicationInfo.pEngineName = "No Engine";
applicationInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
applicationInfo.apiVersion = VK_API_VERSION_1_0;
applicationInfo.apiVersion = VK_API_VERSION_1_2;
uint32_t glfwExtensionCount = 0;
const char** glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
@ -166,6 +169,19 @@ void Instance::createLogicalDevice() {
vkGetDeviceQueue(device, indices.graphicsAndComputeFamily.value(), 0, &computeQueue);
}
void Instance::createAllocator() {
VmaVulkanFunctions functions {};
functions.vkGetInstanceProcAddr = &vkGetInstanceProcAddr;
functions.vkGetDeviceProcAddr = &vkGetDeviceProcAddr;
VmaAllocatorCreateInfo allocatorCreateInfo {};
allocatorCreateInfo.instance = handle;
allocatorCreateInfo.device = device;
allocatorCreateInfo.physicalDevice = physicalDevice;
vmaCreateAllocator(&allocatorCreateInfo, &allocator);
}
Instance::QueueFamilyIndices Instance::findQueueFamilies(VkPhysicalDevice device, VkSurfaceKHR surface) {
uint32_t queueFamilyCount = 0;
vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, nullptr);
@ -199,20 +215,20 @@ Instance::QueueFamilyIndices Instance::findQueueFamilies(VkPhysicalDevice device
return indices;
}
bool Instance::isDeviceSuitable(VkPhysicalDevice physicalDevice) {
bool Instance::isDeviceSuitable(VkPhysicalDevice potentialPhysicalDevice) {
VkPhysicalDeviceProperties deviceProperties;
vkGetPhysicalDeviceProperties(physicalDevice, &deviceProperties);
vkGetPhysicalDeviceProperties(potentialPhysicalDevice, &deviceProperties);
VkPhysicalDeviceFeatures deviceFeatures;
vkGetPhysicalDeviceFeatures(physicalDevice, &deviceFeatures);
vkGetPhysicalDeviceFeatures(potentialPhysicalDevice, &deviceFeatures);
QueueFamilyIndices indices = findQueueFamilies(physicalDevice, surface);
QueueFamilyIndices indices = findQueueFamilies(potentialPhysicalDevice, surface);
bool extensionsSupported = checkDeviceExtensionSupport(physicalDevice);
bool extensionsSupported = checkDeviceExtensionSupport(potentialPhysicalDevice);
bool swapChainAdequate = false;
if (extensionsSupported){
SwapchainSupportDetails details = querySwapchainSupport(physicalDevice, surface);
SwapchainSupportDetails details = querySwapchainSupport(potentialPhysicalDevice, surface);
swapChainAdequate = !details.formats.empty() && !details.presentModes.empty();
}
@ -236,6 +252,8 @@ bool Instance::checkDeviceExtensionSupport(VkPhysicalDevice device) {
}
Instance::~Instance() {
delete commandPool;
vmaDestroyAllocator(allocator);
vkDestroyDevice(device, nullptr);
vkDestroySurfaceKHR(handle, surface, nullptr);
vkDestroyInstance(handle, nullptr);

@ -210,8 +210,7 @@ void Swapchain::createDepthResources() {
extent.height,
VK_FORMAT_D32_SFLOAT,
VK_IMAGE_TILING_OPTIMAL,
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
);
depthImage->createView(VK_FORMAT_D32_SFLOAT, VK_IMAGE_ASPECT_DEPTH_BIT);
}

@ -0,0 +1,2 @@
#define VMA_IMPLEMENTATION
#include "vk_mem_alloc.h"
Loading…
Cancel
Save