added buffer naming for stats json

feature/softbody-runtime-control
Benjamin Kraft 3 months ago
parent 2cc08361ac
commit 1c03a0a90c
  1. 1
      include/vulkan/buffer.hpp
  2. 2
      include/vulkan/instance.hpp
  3. 21
      src/application.cpp
  4. 6
      src/vulkan/buffer.cpp
  5. 10
      src/vulkan/instance.cpp

@ -16,6 +16,7 @@ public:
VmaAllocation allocation = VK_NULL_HANDLE; VmaAllocation allocation = VK_NULL_HANDLE;
VmaAllocationInfo allocationInfo {}; VmaAllocationInfo allocationInfo {};
VkDeviceSize size; VkDeviceSize size;
void setName(const std::string& name);
Buffer(const Buffer& other) = delete; Buffer(const Buffer& other) = delete;
Buffer& operator =(const Buffer& other) = delete; Buffer& operator =(const Buffer& other) = delete;
private: private:

@ -11,6 +11,8 @@ using std::optional, std::vector;
class CommandPool; class CommandPool;
void printVmaStats();
class Instance { class Instance {
public: public:
explicit Instance(); explicit Instance();

@ -29,8 +29,7 @@ Application::Application() {
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE, VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE,
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT); VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT);
cameraUniformBuffer->setName("Camera");
descriptorPool->bindBuffer(*cameraUniformBuffer, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, DescriptorSet::WORLD, 0);
camera = make_unique<Camera>(swapchain->extent); camera = make_unique<Camera>(swapchain->extent);
struct GrabInformation { struct GrabInformation {
@ -42,6 +41,7 @@ Application::Application() {
initialGrabInformation.distanceToFace = 1e20; initialGrabInformation.distanceToFace = 1e20;
grabBuffer = make_unique<Buffer>(sizeof(GrabInformation), &initialGrabInformation, sizeof(GrabInformation), grabBuffer = make_unique<Buffer>(sizeof(GrabInformation), &initialGrabInformation, sizeof(GrabInformation),
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE, 0); VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE, 0);
grabBuffer->setName("Grab");
grabber = make_unique<Grabber>(); grabber = make_unique<Grabber>();
createMeshBuffers(); createMeshBuffers();
@ -54,6 +54,7 @@ Application::Application() {
sizeof(SizeInformation), &sizeInformation, sizeof(sizeInformation), sizeof(SizeInformation), &sizeInformation, sizeof(sizeInformation),
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE, 0); VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE, 0);
sizeInformationBuffer->setName("Sizes");
properties.gravity = {0, -9.81, 0}; properties.gravity = {0, -9.81, 0};
properties.k = 10; properties.k = 10;
@ -63,6 +64,10 @@ Application::Application() {
sizeof(Properties), &properties, sizeof(properties), sizeof(Properties), &properties, sizeof(properties),
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE, 0); 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(*vertexBuffers[1 - currentDrawVertexBuffer], VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, DescriptorSet::MESH, 0);
descriptorPool->bindBuffer(*faceBuffer, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, DescriptorSet::MESH, 1); descriptorPool->bindBuffer(*faceBuffer, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, DescriptorSet::MESH, 1);
@ -76,10 +81,7 @@ Application::Application() {
createComputePipelines(); createComputePipelines();
char* stats; printVmaStats();
vmaBuildStatsString(Instance::GetAllocator(), &stats, VK_TRUE);
// printf("%s", stats);
vmaFreeStatsString(Instance::GetAllocator(), stats);
} }
#include <future> #include <future>
@ -238,6 +240,13 @@ void Application::createMeshBuffers() {
edgeBuffer = make_unique<SimulationBuffer>(constraintData.edges.data(), constraintData.edges.size() * sizeof(Edge)); edgeBuffer = make_unique<SimulationBuffer>(constraintData.edges.data(), constraintData.edges.size() * sizeof(Edge));
triangleBuffer = make_unique<SimulationBuffer>(constraintData.triangles.data(), constraintData.triangles.size() * sizeof(Triangle)); triangleBuffer = make_unique<SimulationBuffer>(constraintData.triangles.data(), constraintData.triangles.size() * sizeof(Triangle));
tetrahedronBuffer = make_unique<SimulationBuffer>(constraintData.tetrahedra.data(), constraintData.tetrahedra.size() * sizeof(Tetrahedron)); tetrahedronBuffer = make_unique<SimulationBuffer>(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() { void Application::createComputePipelines() {

@ -18,6 +18,8 @@ Buffer::Buffer(VkDeviceSize size, VkBufferUsageFlags bufferUsage, VmaMemoryUsage
allocationCreateInfo.flags = flags; allocationCreateInfo.flags = flags;
vmaCreateBuffer(Instance::GetAllocator(), &bufferCreateInfo, &allocationCreateInfo, &handle, &allocation, &allocationInfo); 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, 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); vkFreeCommandBuffers(Instance::GetDevice(), Instance::instance->renderingCommandPool->handle, 1, &commandBuffer);
} }
void Buffer::setName(const std::string &name) {
vmaSetAllocationName(Instance::GetAllocator(), allocation, name.data());
}

@ -172,6 +172,16 @@ void Instance::createLogicalDevice() {
vkGetDeviceQueue(device, indices.tryComputeAndTransferDedicated(), 0, &computeAndTransferQueue); vkGetDeviceQueue(device, indices.tryComputeAndTransferDedicated(), 0, &computeAndTransferQueue);
} }
#include <fstream>
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() { void Instance::createAllocator() {
VmaVulkanFunctions functions {}; VmaVulkanFunctions functions {};
functions.vkGetInstanceProcAddr = &vkGetInstanceProcAddr; functions.vkGetInstanceProcAddr = &vkGetInstanceProcAddr;

Loading…
Cancel
Save