feature/softbody-runtime-control
Benjamin Kraft 3 months ago
parent c51a9f6552
commit 9b9fcef3fe
  1. 11
      include/application.hpp
  2. 8
      include/vulkan/buffer.hpp
  3. 17
      src/application.cpp
  4. 4
      src/vulkan/buffer.cpp

@ -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<unique_ptr<Buffer>> vertexBuffers[2];
optional<unique_ptr<Buffer>> faceBuffer;
optional<unique_ptr<Buffer>> edgeBuffer;
optional<unique_ptr<Buffer>> triangleBuffer;
optional<unique_ptr<Buffer>> tetrahedronBuffer;
unique_ptr<SimulationBuffer> vertexBuffers[2];
unique_ptr<SimulationBuffer> faceBuffer;
unique_ptr<SimulationBuffer> edgeBuffer;
unique_ptr<SimulationBuffer> triangleBuffer;
unique_ptr<SimulationBuffer> tetrahedronBuffer;
ConstraintData constraintData {};
vector<unique_ptr<SoftBody>> softBodies;

@ -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<Buffer> Append(const Buffer& old, void* data, VkDeviceSize size, VkCommandBuffer commandBuffer=VK_NULL_HANDLE);
static unique_ptr<Buffer> Replace(const Buffer& old, void* data, VkDeviceSize size, VkCommandBuffer commandBuffer=VK_NULL_HANDLE);
@ -46,3 +46,9 @@ private:
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) {}
};

@ -253,16 +253,11 @@ void Application::addSoftBody(const std::string &modelFile, size_t count) {
vertexBuffers[0] = make_unique<SimulationBuffer>(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT);
vertexBuffers[1] = make_unique<SimulationBuffer>(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT);
faceBuffer = make_unique<SimulationBuffer>(VK_BUFFER_USAGE_INDEX_BUFFER_BIT);
edgeBuffer = make_unique<SimulationBuffer>();
// triangleBuffer = make_unique<SimulationBuffer>();
tetrahedronBuffer = make_unique<SimulationBuffer>();
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> &softBody) {
// cpu: erase vector element
}
void Application::updateConstraintBuffers(VkCommandBuffer commandBuffer) {
edgeBuffer = make_unique<SimulationBuffer>(constraintData.edges.size() * sizeof(Edge), constraintData.edges.data());
// triangleBuffer = make_unique<SimulationBuffer>();
tetrahedronBuffer = make_unique<SimulationBuffer>(constraintData.tetrahedra.size() * sizeof(Tetrahedron), constraintData.tetrahedra.data());
edgeBuffer.value()->setName("Edges");
// triangleBuffer->setName("Triangles");
tetrahedronBuffer.value()->setName("Tetrahedra");
}
void Application::createComputePipelines() {
vector<VkDescriptorSetLayout> layouts;
vector<VkPushConstantRange> pushRanges;

@ -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);
}

Loading…
Cancel
Save