code cleanup

main
Benjamin Kraft 3 months ago
parent c3ad1f7009
commit 3e45f2eefd
  1. 14
      include/application.hpp
  2. 4
      include/constraints.hpp
  3. 3
      include/input.hpp
  4. 2
      include/vulkan/buffer.hpp
  5. 1
      include/vulkan/descriptor_pool.hpp
  6. 22
      include/vulkan/instance.hpp
  7. 1
      include/vulkan/swapchain.hpp
  8. 43
      src/application.cpp
  9. 19
      src/vulkan/instance.cpp

@ -26,19 +26,33 @@ using std::vector;
using std::optional; using std::optional;
class SoftBody; class SoftBody;
class Instance; class Instance;
class Swapchain; class Swapchain;
class GraphicsPipeline; class GraphicsPipeline;
class Buffer; class Buffer;
class Buffer; class Buffer;
class CommandPool; class CommandPool;
class Image; class Image;
class ComputePipeline; class ComputePipeline;
class Fence; class Fence;
class Semaphore; class Semaphore;
class Camera; class Camera;
class DescriptorPool; class DescriptorPool;
class Grabber; class Grabber;
struct SizesUniformData; struct SizesUniformData;
class Application { class Application {

@ -62,20 +62,24 @@ private:
struct Constraint { struct Constraint {
virtual ~Constraint() {} virtual ~Constraint() {}
virtual void writeData(ConstraintData &dataLists) const {}; virtual void writeData(ConstraintData &dataLists) const {};
}; };
struct DistanceConstraint : Edge, Constraint { struct DistanceConstraint : Edge, Constraint {
explicit DistanceConstraint(const Edge &edge) : Edge(edge) {} explicit DistanceConstraint(const Edge &edge) : Edge(edge) {}
void writeData(ConstraintData &dataLists) const override; void writeData(ConstraintData &dataLists) const override;
}; };
struct AreaConstraint : Triangle, Constraint { struct AreaConstraint : Triangle, Constraint {
explicit AreaConstraint(const Triangle &triangle) : Triangle(triangle) {} explicit AreaConstraint(const Triangle &triangle) : Triangle(triangle) {}
void writeData(ConstraintData &dataLists) const override; void writeData(ConstraintData &dataLists) const override;
}; };
struct VolumeConstraint : Tetrahedron, Constraint { struct VolumeConstraint : Tetrahedron, Constraint {
explicit VolumeConstraint(const Tetrahedron &tetrahedron) : Tetrahedron(tetrahedron) {} explicit VolumeConstraint(const Tetrahedron &tetrahedron) : Tetrahedron(tetrahedron) {}
void writeData(ConstraintData &dataLists) const override; void writeData(ConstraintData &dataLists) const override;
}; };

@ -6,6 +6,7 @@
#include "glm/vec2.hpp" #include "glm/vec2.hpp"
class Listener; class Listener;
class MouseListener; class MouseListener;
class Input { class Input {
@ -42,6 +43,8 @@ class KeyListener : Listener {
class MouseListener : public Listener { class MouseListener : public Listener {
public: public:
virtual void mouseMoved(const glm::vec2 &delta) {}; virtual void mouseMoved(const glm::vec2 &delta) {};
virtual void mouseButtonPressed(int button) {}; virtual void mouseButtonPressed(int button) {};
virtual void mouseButtonReleased(int button) {}; virtual void mouseButtonReleased(int button) {};
}; };

@ -28,10 +28,12 @@ public:
VmaAllocationInfo allocationInfo {}; VmaAllocationInfo allocationInfo {};
VkDeviceSize size; VkDeviceSize size;
void setName(const std::string &newName); void setName(const std::string &newName);
template<typename T> template<typename T>
T &access() { T &access() {
return *reinterpret_cast<T *>(allocationInfo.pMappedData); return *reinterpret_cast<T *>(allocationInfo.pMappedData);
} }
void copyTo(Buffer *buffer) const; void copyTo(Buffer *buffer) const;
void copyTo(Image *image) const; void copyTo(Image *image) const;
void setData(void *data, VkDeviceSize offset, VkDeviceSize dataSize, VkCommandBuffer commandBuffer = VK_NULL_HANDLE); void setData(void *data, VkDeviceSize offset, VkDeviceSize dataSize, VkCommandBuffer commandBuffer = VK_NULL_HANDLE);

@ -5,6 +5,7 @@
#include <map> #include <map>
class Buffer; class Buffer;
class Image; class Image;
enum class DescriptorSet { enum class DescriptorSet {

@ -14,6 +14,7 @@
using std::optional, std::vector; using std::optional, std::vector;
class CommandPool; class CommandPool;
class Swapchain; class Swapchain;
void printVmaStats(); void printVmaStats();
@ -36,24 +37,11 @@ public:
struct QueueFamilyIndices { struct QueueFamilyIndices {
vector<uint32_t> graphicsAndPresent; vector<uint32_t> graphicsAndPresent;
vector<uint32_t> computeAndTransfer; vector<uint32_t> computeAndTransfer;
std::set<uint32_t> uniqueQueueFamilies(){ std::set<uint32_t> uniqueQueueFamilies();
std::set<uint32_t> unique; uint32_t tryComputeAndTransferDedicated();
unique.insert(graphicsAndPresent.begin(), graphicsAndPresent.end()); bool isEnough();
unique.insert(computeAndTransfer.begin(), computeAndTransfer.end());
return unique;
}
uint32_t tryComputeAndTransferDedicated(){
for (uint32_t family : computeAndTransfer){
if (std::find(graphicsAndPresent.begin(), graphicsAndPresent.end(), family) == graphicsAndPresent.end()){
return family;
}
}
return computeAndTransfer[0];
}
bool isEnough(){
return !graphicsAndPresent.empty() && !computeAndTransfer.empty();
}
}; };
QueueFamilyIndices indices {}; QueueFamilyIndices indices {};
static Instance *instance; static Instance *instance;

@ -4,6 +4,7 @@
#include <vector> #include <vector>
class Image; class Image;
class Instance; class Instance;
struct SwapchainSupportDetails { struct SwapchainSupportDetails {

@ -273,17 +273,23 @@ void Application::addSoftBody(const std::string &modelFile, size_t count) {
newVertexBuffers[0] = make_unique<Buffer>( newVertexBuffers[0] = make_unique<Buffer>(
newVertices.size() * sizeof(Vertex), newVertices.size() * sizeof(Vertex),
bufferUsageFlags | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, bufferUsageFlags | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
memoryUsage, 0, "Vertices 0" memoryUsage,
0,
"Vertices 0"
); );
newVertexBuffers[1] = make_unique<Buffer>( newVertexBuffers[1] = make_unique<Buffer>(
newVertices.size() * sizeof(Vertex), newVertices.size() * sizeof(Vertex),
bufferUsageFlags | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, bufferUsageFlags | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
memoryUsage, 0, "Vertices 1" memoryUsage,
0,
"Vertices 1"
); );
newFaceBuffer = make_unique<Buffer>( newFaceBuffer = make_unique<Buffer>(
newFaces.size() * sizeof(Face), newFaces.size() * sizeof(Face),
bufferUsageFlags | VK_BUFFER_USAGE_INDEX_BUFFER_BIT, bufferUsageFlags | VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
memoryUsage, 0, "Faces" memoryUsage,
0,
"Faces"
); );
newEdgeBuffer = make_unique<Buffer>( newEdgeBuffer = make_unique<Buffer>(
constraintData.edges.size() * sizeof(Edge), constraintData.edges.size() * sizeof(Edge),
@ -293,7 +299,10 @@ void Application::addSoftBody(const std::string &modelFile, size_t count) {
"Edges" "Edges"
); );
newTetrahedronBuffer = make_unique<Buffer>( newTetrahedronBuffer = make_unique<Buffer>(
constraintData.tetrahedra.size() * sizeof(Tetrahedron), bufferUsageFlags, memoryUsage, 0, constraintData.tetrahedra.size() * sizeof(Tetrahedron),
bufferUsageFlags,
memoryUsage,
0,
"Tetrahedra" "Tetrahedra"
); );
@ -304,17 +313,29 @@ void Application::addSoftBody(const std::string &modelFile, size_t count) {
newTetrahedronBuffer->setData(constraintData.tetrahedra.data(), 0, newTetrahedronBuffer->size, commandBuffer); newTetrahedronBuffer->setData(constraintData.tetrahedra.data(), 0, newTetrahedronBuffer->size, commandBuffer);
} else { } else {
newVertexBuffers[0] = vertexBuffers[0]->appended( newVertexBuffers[0] = vertexBuffers[0]->appended(
newVertices.data(), newVertices.size() * sizeof(Vertex), commandBuffer newVertices.data(),
newVertices.size() * sizeof(Vertex),
commandBuffer
); );
newVertexBuffers[1] = vertexBuffers[1]->appended( newVertexBuffers[1] = vertexBuffers[1]->appended(
newVertices.data(), newVertices.size() * sizeof(Vertex), commandBuffer newVertices.data(),
newVertices.size() * sizeof(Vertex),
commandBuffer
);
newFaceBuffer = faceBuffer->appended(
newFaces.data(),
newFaces.size() * sizeof(Face),
commandBuffer
); );
newFaceBuffer = faceBuffer->appended(newFaces.data(), newFaces.size() * sizeof(Face), commandBuffer);
newEdgeBuffer = edgeBuffer->replaced( newEdgeBuffer = edgeBuffer->replaced(
constraintData.edges.data(), constraintData.edges.size() * sizeof(Edge), commandBuffer constraintData.edges.data(),
constraintData.edges.size() * sizeof(Edge),
commandBuffer
); );
newTetrahedronBuffer = tetrahedronBuffer->replaced( newTetrahedronBuffer = tetrahedronBuffer->replaced(
constraintData.tetrahedra.data(), constraintData.tetrahedra.size() * sizeof(Tetrahedron), commandBuffer constraintData.tetrahedra.data(),
constraintData.tetrahedra.size() * sizeof(Tetrahedron),
commandBuffer
); );
} }
@ -327,9 +348,7 @@ void Application::addSoftBody(const std::string &modelFile, size_t count) {
edgeBuffer = std::move(newEdgeBuffer); edgeBuffer = std::move(newEdgeBuffer);
tetrahedronBuffer = std::move(newTetrahedronBuffer); tetrahedronBuffer = std::move(newTetrahedronBuffer);
descriptorPool->bindBuffer( descriptorPool->bindBuffer(*vertexBuffers[1 - currentDrawVertexBuffer], VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, DescriptorSet::MESH, 0);
*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);
descriptorPool->bindBuffer(*edgeBuffer, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, DescriptorSet::MESH, 2); descriptorPool->bindBuffer(*edgeBuffer, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, DescriptorSet::MESH, 2);
descriptorPool->bindBuffer(*tetrahedronBuffer, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, DescriptorSet::MESH, 4); descriptorPool->bindBuffer(*tetrahedronBuffer, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, DescriptorSet::MESH, 4);

@ -355,3 +355,22 @@ void Instance::initImGui(const Swapchain &swapchain) {
ImGui_ImplVulkan_Init(&initInfo); ImGui_ImplVulkan_Init(&initInfo);
} }
std::set<uint32_t> Instance::QueueFamilyIndices::uniqueQueueFamilies() {
std::set<uint32_t> unique;
unique.insert(graphicsAndPresent.begin(), graphicsAndPresent.end());
unique.insert(computeAndTransfer.begin(), computeAndTransfer.end());
return unique;
}
uint32_t Instance::QueueFamilyIndices::tryComputeAndTransferDedicated() {
for (uint32_t family: computeAndTransfer)
if (std::find(graphicsAndPresent.begin(), graphicsAndPresent.end(), family) == graphicsAndPresent.end())
return family;
return computeAndTransfer[0];
}
bool Instance::QueueFamilyIndices::isEnough() {
return !graphicsAndPresent.empty() && !computeAndTransfer.empty();
}

Loading…
Cancel
Save