Compare commits

..

No commits in common. '3dde0fee204e68573823f1d061c5b2c2322eff5d' and '296235288f4925849d1c64b03c33cc097250e090' have entirely different histories.

  1. 6
      imgui.ini
  2. 10
      include/application.hpp
  3. 12
      include/fixed_list.hpp
  4. 2024
      models/icosphere.ply
  5. 2021
      models/icosphere_medium.ply
  6. BIN
      models/vulkanscene.blend
  7. 1
      shaders/compile.sh
  8. 49
      src/application.cpp
  9. 17
      src/fixed_list.cpp

@ -29,8 +29,8 @@ Size=249,166
Collapsed=0 Collapsed=0
[Window][Performance] [Window][Performance]
Pos=1716,2 Pos=1617,2
Size=203,1002 Size=302,1002
Collapsed=0 Collapsed=0
DockId=0x00000001,0 DockId=0x00000001,0
@ -41,5 +41,5 @@ Collapsed=0
DockId=0x00000001,1 DockId=0x00000001,1
[Docking][Data] [Docking][Data]
DockNode ID=0x00000001 Pos=1716,2 Size=203,1002 Selected=0x60B79D0E DockNode ID=0x00000001 Pos=1617,2 Size=302,1002 Selected=0x60B79D0E

@ -16,10 +16,8 @@
#include <map> #include <map>
#include <glm/vec2.hpp> #include <glm/vec2.hpp>
#include "constraints.hpp" #include "constraints.hpp"
#include "fixed_list.hpp"
#include <glm/mat4x4.hpp> #include <glm/mat4x4.hpp>
#include <glm/vec3.hpp> #include <glm/vec3.hpp>
#include <list>
using std::unique_ptr, std::make_unique; using std::unique_ptr, std::make_unique;
using std::vector; using std::vector;
@ -46,12 +44,10 @@ public:
private: private:
void imGuiWindows(); void imGuiWindows();
struct PerformanceInformation { struct PerformanceInformation {
static const size_t saves = 30; float totalUpdateDuration;
FixedList recentTotalUpdateDurations = FixedList(saves);
float updateDuration; float updateDuration;
FixedList recentFrameDurations = FixedList(saves); float frameDuration;
} performanceInformation {};
} performanceInformation;
void createSyncObjects(); void createSyncObjects();

@ -1,12 +0,0 @@
#pragma once
#include <list>
#include <cstddef>
class FixedList : private std::list<float> {
size_t maxSize;
public:
explicit FixedList(size_t maxSize);
void push(float value);
float average() const;
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

@ -1,3 +1,4 @@
#!/usr/bin/env bash
glslc shader.vert -o vert.spv glslc shader.vert -o vert.spv
glslc shader.frag -o frag.spv glslc shader.frag -o frag.spv
glslc --target-env=vulkan1.1 pbd.comp -o pbd.spv glslc --target-env=vulkan1.1 pbd.comp -o pbd.spv

@ -20,7 +20,6 @@
#include "imgui.h" #include "imgui.h"
#include "imgui/backends/imgui_impl_vulkan.h" #include "imgui/backends/imgui_impl_vulkan.h"
#include "imgui/backends/imgui_impl_glfw.h" #include "imgui/backends/imgui_impl_glfw.h"
#include "fixed_list.hpp"
using namespace std::chrono; using namespace std::chrono;
@ -152,7 +151,7 @@ void Application::mainLoop() {
std::this_thread::sleep_for(requestedUpdateDuration - measuredUpdateDuration); std::this_thread::sleep_for(requestedUpdateDuration - measuredUpdateDuration);
performanceInformation.updateDuration = measuredUpdateDuration.count(); performanceInformation.updateDuration = measuredUpdateDuration.count();
performanceInformation.recentTotalUpdateDurations.push(std::max(requestedUpdateDuration, measuredUpdateDuration).count()); performanceInformation.totalUpdateDuration = std::max(requestedUpdateDuration, measuredUpdateDuration).count();
} }
}); });
@ -163,7 +162,7 @@ void Application::mainLoop() {
auto t2 = system_clock::now(); auto t2 = system_clock::now();
float seconds = duration<float>(t2 - t1).count(); float seconds = duration<float>(t2 - t1).count();
performanceInformation.recentFrameDurations.push(seconds); performanceInformation.frameDuration = seconds;
t1 = system_clock::now(); t1 = system_clock::now();
drawFrame(seconds); drawFrame(seconds);
} }
@ -179,24 +178,24 @@ void Application::createSyncObjects() {
computeSemaphore = make_unique<Semaphore>(); computeSemaphore = make_unique<Semaphore>();
transferSemaphore = make_unique<Semaphore>(); transferSemaphore = make_unique<Semaphore>();
renderFence = make_unique<Fence>(true); renderFence = make_unique<Fence>(true);
computeFence = make_unique<Fence>(false); computeFence = make_unique<Fence>(true);
transferFence = make_unique<Fence>(false); transferFence = make_unique<Fence>(true);
} }
void Application::createMeshBuffers() { void Application::createMeshBuffers() {
Mesh sphere("models/icosphere_medium.ply"); Mesh sphere("models/icosphere.ply");
Mesh bunny("models/bunny_medium.ply"); Mesh bunny("models/bunny_medium.ply");
auto body = std::make_unique<SoftBody>(&sphere, 1.f / 60); auto body = std::make_unique<SoftBody>(&sphere, 1.f / 60);
for (size_t i = 0; i < 10; i++){ for (size_t i = 0; i < 2; i++){
auto copy = std::make_unique<SoftBody>(*body.get()); auto copy = std::make_unique<SoftBody>(*body.get());
copy->applyVertexOffset({i * 2, 0, 0}); copy->applyVertexOffset({i * 2, 0, 0});
softBodies.push_back(std::move(copy)); softBodies.push_back(std::move(copy));
} }
body = std::make_unique<SoftBody>(&bunny, 1.f / 10); body = std::make_unique<SoftBody>(&bunny, 1.f / 10);
for (size_t i = 0; i < 10; i++){ for (size_t i = 0; i < 2; i++){
auto copy = std::make_unique<SoftBody>(*body.get()); auto copy = std::make_unique<SoftBody>(*body.get());
copy->applyVertexOffset({i * 2, 0, 2}); copy->applyVertexOffset({i * 2, 0, 2});
softBodies.push_back(std::move(copy)); softBodies.push_back(std::move(copy));
@ -497,6 +496,16 @@ void Application::recordDrawCommands(VkCommandBuffer commandBuffer) {
} }
void Application::update() { void Application::update() {
vkWaitForFences(Instance::GetDevice(), 1, &computeFence->handle, VK_TRUE, UINT64_MAX);
vkResetFences(Instance::GetDevice(), 1, &computeFence->handle);
currentDrawVertexBuffer = 1 - currentDrawVertexBuffer;
vkWaitForFences(Instance::GetDevice(), 1, &transferFence->handle, VK_TRUE, UINT64_MAX);
vkResetFences(Instance::GetDevice(), 1, &transferFence->handle);
currentDrawVertexBuffer = 1 - currentDrawVertexBuffer;
VkCommandBufferBeginInfo beginInfo {}; VkCommandBufferBeginInfo beginInfo {};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
beginInfo.flags = 0; beginInfo.flags = 0;
@ -552,17 +561,6 @@ void Application::update() {
vkQueueSubmit(Instance::instance->computeAndTransferQueue, 1, &submit, transferFence->handle); vkQueueSubmit(Instance::instance->computeAndTransferQueue, 1, &submit, transferFence->handle);
submitMutex.unlock(); submitMutex.unlock();
} }
vkWaitForFences(Instance::GetDevice(), 1, &computeFence->handle, VK_TRUE, UINT64_MAX);
vkResetFences(Instance::GetDevice(), 1, &computeFence->handle);
currentDrawVertexBuffer = 1 - currentDrawVertexBuffer;
vkWaitForFences(Instance::GetDevice(), 1, &transferFence->handle, VK_TRUE, UINT64_MAX);
vkResetFences(Instance::GetDevice(), 1, &transferFence->handle);
currentDrawVertexBuffer = 1 - currentDrawVertexBuffer;
// descriptorPool->bindBuffer(*vertexBuffers[1 - currentDrawVertexBuffer], VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, DescriptorSet::MESH, 0);
} }
uint32_t Application::GetGroupCount(uint32_t threads, uint32_t blockSize) { uint32_t Application::GetGroupCount(uint32_t threads, uint32_t blockSize) {
@ -713,14 +711,9 @@ void Application::imGuiWindows() {
ImGui::NewFrame(); ImGui::NewFrame();
ImGui::Begin("Performance"); ImGui::Begin("Performance");
ImGui::Text("Update time: %f", performanceInformation.updateDuration);
float updateMS = performanceInformation.updateDuration * 1000.f; ImGui::Text("Updates per second: %f", 1 / performanceInformation.totalUpdateDuration);
float updateHZ = 1 / performanceInformation.recentTotalUpdateDurations.average(); ImGui::Text("Frame time: %f", performanceInformation.frameDuration);
ImGui::Text("Updates: %.0fms | %.1fHz", updateMS, updateHZ); ImGui::Text("Frames per second: %f", 1 / performanceInformation.frameDuration);
float frameMS = performanceInformation.recentFrameDurations.average() * 1000.f;
float frameHZ = 1 / performanceInformation.recentFrameDurations.average();
ImGui::Text("Frames: %.2fms | %.1fHz", frameMS, frameHZ);
ImGui::End(); ImGui::End();
} }

@ -1,17 +0,0 @@
#include <numeric>
#include "fixed_list.hpp"
FixedList::FixedList(size_t maxSize) : std::list<float>(), maxSize(maxSize) {}
void FixedList::push(float value) {
push_back(value);
if (size() > maxSize)
erase(begin());
}
float FixedList::average() const {
if (empty())
return 0.0f;
return std::reduce(begin(), end(), 0.0f) / static_cast<float>(size());
}
Loading…
Cancel
Save