diff --git a/include/application.hpp b/include/application.hpp index f76b00b..7d64868 100644 --- a/include/application.hpp +++ b/include/application.hpp @@ -30,6 +30,7 @@ class Instance; class Swapchain; class GraphicsPipeline; class Buffer; +class SimulationBuffer; class CommandPool; class Image; class ComputePipeline; @@ -82,11 +83,11 @@ private: void updateConstraintBuffers(VkCommandBuffer commandBuffer); size_t currentDrawVertexBuffer = 0; - optional> vertexBuffers[2]; - optional> faceBuffer; - optional> edgeBuffer; - optional> triangleBuffer; - optional> tetrahedronBuffer; + unique_ptr vertexBuffers[2]; + unique_ptr faceBuffer; + unique_ptr edgeBuffer; + unique_ptr triangleBuffer; + unique_ptr tetrahedronBuffer; ConstraintData constraintData {}; vector> softBodies; diff --git a/include/vulkan/buffer.hpp b/include/vulkan/buffer.hpp index c50c3d5..60a5060 100644 --- a/include/vulkan/buffer.hpp +++ b/include/vulkan/buffer.hpp @@ -19,7 +19,7 @@ class Buffer { public: Buffer(VkDeviceSize bufferSize, VkBufferUsageFlags bufferUsage, VmaMemoryUsage memoryUsage, VmaAllocationCreateFlags vmaAllocationFlags); - Buffer(VkDeviceSize bufferSize, void* initialData, VkDeviceSize initialDataSize, VkBufferUsageFlags bufferUsage, + Buffer(VkDeviceSize bufferSize, void* initialData, VkBufferUsageFlags bufferUsage, VmaMemoryUsage memoryUsage, VmaAllocationCreateFlags vmaAllocationFlags); static unique_ptr Append(const Buffer& old, void* data, VkDeviceSize size, VkCommandBuffer commandBuffer=VK_NULL_HANDLE); static unique_ptr Replace(const Buffer& old, void* data, VkDeviceSize size, VkCommandBuffer commandBuffer=VK_NULL_HANDLE); @@ -45,4 +45,10 @@ private: VkBufferUsageFlags bufferUsageFlags; VmaMemoryUsage memoryUsage; VmaAllocationCreateFlags allocationCreateFlags; +}; + +class SimulationBuffer : public Buffer { +public: + SimulationBuffer(VkDeviceSize bufferSize, VkBufferUsageFlags bufferUsage=0): + Buffer(bufferSize, initialData, bufferUsage | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE, 0) {} }; \ No newline at end of file diff --git a/src/application.cpp b/src/application.cpp index 3e8c049..ca8e415 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -253,16 +253,11 @@ void Application::addSoftBody(const std::string &modelFile, size_t count) { vertexBuffers[0] = make_unique(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT); vertexBuffers[1] = make_unique(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT); faceBuffer = make_unique(VK_BUFFER_USAGE_INDEX_BUFFER_BIT); - edgeBuffer = make_unique(); - // triangleBuffer = make_unique(); - tetrahedronBuffer = make_unique(); + vertexBuffers[0]->setName("Vertices 0"); vertexBuffers[1]->setName("Vertices 1"); faceBuffer->setName("Faces"); - edgeBuffer->setName("Edges"); - // triangleBuffer->setName("Triangles"); - tetrahedronBuffer->setName("Tetrahedra"); VkQueue queue = Instance::instance->graphicsAndPresentQueue; Instance::instance->renderingCommandPool->endSingleTimeCommandBuffer(commandBuffer, queue); @@ -279,6 +274,16 @@ void Application::removeSoftBody(const unique_ptr &softBody) { // cpu: erase vector element } +void Application::updateConstraintBuffers(VkCommandBuffer commandBuffer) { + edgeBuffer = make_unique(constraintData.edges.size() * sizeof(Edge), constraintData.edges.data()); + // triangleBuffer = make_unique(); + tetrahedronBuffer = make_unique(constraintData.tetrahedra.size() * sizeof(Tetrahedron), constraintData.tetrahedra.data()); + + edgeBuffer.value()->setName("Edges"); + // triangleBuffer->setName("Triangles"); + tetrahedronBuffer.value()->setName("Tetrahedra"); +} + void Application::createComputePipelines() { vector layouts; vector pushRanges; diff --git a/src/vulkan/buffer.cpp b/src/vulkan/buffer.cpp index c2f799f..d87aba3 100644 --- a/src/vulkan/buffer.cpp +++ b/src/vulkan/buffer.cpp @@ -22,7 +22,7 @@ Buffer::Buffer(VkDeviceSize bufferSize, VkBufferUsageFlags bufferUsageFlags, Vma vmaCreateBuffer(Instance::GetAllocator(), &bufferCreateInfo, &allocationCreateInfo, &handle, &allocation, &allocationInfo); } -Buffer::Buffer(VkDeviceSize bufferSize, void *initialData, VkDeviceSize initialDataSize, VkBufferUsageFlags bufferUsageFlags, +Buffer::Buffer(VkDeviceSize bufferSize, void *initialData, VkBufferUsageFlags bufferUsageFlags, VmaMemoryUsage memoryUsage, VmaAllocationCreateFlags allocationFlags) : Buffer(bufferSize, bufferUsageFlags | VK_BUFFER_USAGE_TRANSFER_DST_BIT, memoryUsage, allocationFlags){ @@ -33,7 +33,7 @@ Buffer::Buffer(VkDeviceSize bufferSize, void *initialData, VkDeviceSize initialD VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT ); - memcpy(stagingBuffer.allocationInfo.pMappedData, initialData, initialDataSize); + memcpy(stagingBuffer.allocationInfo.pMappedData, initialData, bufferSize); stagingBuffer.copyTo(this); }