diff --git a/include/vulkan/buffer.hpp b/include/vulkan/buffer.hpp index 691bb86..0302960 100644 --- a/include/vulkan/buffer.hpp +++ b/include/vulkan/buffer.hpp @@ -16,6 +16,7 @@ public: VmaAllocation allocation = VK_NULL_HANDLE; VmaAllocationInfo allocationInfo {}; VkDeviceSize size; + void setName(const std::string& name); Buffer(const Buffer& other) = delete; Buffer& operator =(const Buffer& other) = delete; private: diff --git a/include/vulkan/instance.hpp b/include/vulkan/instance.hpp index dafddfe..88953e6 100644 --- a/include/vulkan/instance.hpp +++ b/include/vulkan/instance.hpp @@ -11,6 +11,8 @@ using std::optional, std::vector; class CommandPool; +void printVmaStats(); + class Instance { public: explicit Instance(); diff --git a/src/application.cpp b/src/application.cpp index 796dbb1..426f204 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -29,8 +29,7 @@ Application::Application() { 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); - - descriptorPool->bindBuffer(*cameraUniformBuffer, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, DescriptorSet::WORLD, 0); + cameraUniformBuffer->setName("Camera"); camera = make_unique(swapchain->extent); struct GrabInformation { @@ -42,6 +41,7 @@ Application::Application() { initialGrabInformation.distanceToFace = 1e20; grabBuffer = make_unique(sizeof(GrabInformation), &initialGrabInformation, sizeof(GrabInformation), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE, 0); + grabBuffer->setName("Grab"); grabber = make_unique(); createMeshBuffers(); @@ -54,6 +54,7 @@ Application::Application() { sizeof(SizeInformation), &sizeInformation, sizeof(sizeInformation), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE, 0); + sizeInformationBuffer->setName("Sizes"); properties.gravity = {0, -9.81, 0}; properties.k = 10; @@ -63,6 +64,10 @@ Application::Application() { sizeof(Properties), &properties, sizeof(properties), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE, 0); + propertiesBuffer->setName("Simulation properties"); + + + descriptorPool->bindBuffer(*cameraUniformBuffer, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, DescriptorSet::WORLD, 0); descriptorPool->bindBuffer(*vertexBuffers[1 - currentDrawVertexBuffer], VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, DescriptorSet::MESH, 0); descriptorPool->bindBuffer(*faceBuffer, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, DescriptorSet::MESH, 1); @@ -76,10 +81,7 @@ Application::Application() { createComputePipelines(); - char* stats; - vmaBuildStatsString(Instance::GetAllocator(), &stats, VK_TRUE); - // printf("%s", stats); - vmaFreeStatsString(Instance::GetAllocator(), stats); + printVmaStats(); } #include @@ -238,6 +240,13 @@ void Application::createMeshBuffers() { edgeBuffer = make_unique(constraintData.edges.data(), constraintData.edges.size() * sizeof(Edge)); triangleBuffer = make_unique(constraintData.triangles.data(), constraintData.triangles.size() * sizeof(Triangle)); tetrahedronBuffer = make_unique(constraintData.tetrahedra.data(), constraintData.tetrahedra.size() * sizeof(Tetrahedron)); + + vertexBuffers[0]->setName("Vertices 0"); + vertexBuffers[1]->setName("Vertices 1"); + faceBuffer->setName("Faces"); + edgeBuffer->setName("Edges"); + triangleBuffer->setName("Triangles"); + tetrahedronBuffer->setName("Tetrahedra"); } void Application::createComputePipelines() { diff --git a/src/vulkan/buffer.cpp b/src/vulkan/buffer.cpp index 39e6007..150a614 100644 --- a/src/vulkan/buffer.cpp +++ b/src/vulkan/buffer.cpp @@ -18,6 +18,8 @@ Buffer::Buffer(VkDeviceSize size, VkBufferUsageFlags bufferUsage, VmaMemoryUsage allocationCreateInfo.flags = flags; vmaCreateBuffer(Instance::GetAllocator(), &bufferCreateInfo, &allocationCreateInfo, &handle, &allocation, &allocationInfo); + + vmaSetAllocationName(Instance::GetAllocator(), allocation, "My Custom name"); } Buffer::Buffer(VkDeviceSize size, void *data, VkDeviceSize dataSize, VkBufferUsageFlags bufferUsage, @@ -69,3 +71,7 @@ void Buffer::copyTo(Buffer *dst) { vkFreeCommandBuffers(Instance::GetDevice(), Instance::instance->renderingCommandPool->handle, 1, &commandBuffer); } + +void Buffer::setName(const std::string &name) { + vmaSetAllocationName(Instance::GetAllocator(), allocation, name.data()); +} diff --git a/src/vulkan/instance.cpp b/src/vulkan/instance.cpp index 046efac..e0c93f6 100644 --- a/src/vulkan/instance.cpp +++ b/src/vulkan/instance.cpp @@ -172,6 +172,16 @@ void Instance::createLogicalDevice() { vkGetDeviceQueue(device, indices.tryComputeAndTransferDedicated(), 0, &computeAndTransferQueue); } +#include +void printVmaStats(){ + char* stats; + vmaBuildStatsString(Instance::GetAllocator(), &stats, VK_TRUE); + std::ofstream stream("stats.json"); + stream << stats; + stream.close(); + vmaFreeStatsString(Instance::GetAllocator(), stats); +} + void Instance::createAllocator() { VmaVulkanFunctions functions {}; functions.vkGetInstanceProcAddr = &vkGetInstanceProcAddr;