|
|
@ -20,6 +20,7 @@ |
|
|
|
#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; |
|
|
|
|
|
|
|
|
|
|
@ -151,7 +152,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.totalUpdateDuration = std::max(requestedUpdateDuration, measuredUpdateDuration).count(); |
|
|
|
performanceInformation.recentTotalUpdateDurations.push(std::max(requestedUpdateDuration, measuredUpdateDuration).count()); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -162,7 +163,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.frameDuration = seconds; |
|
|
|
performanceInformation.recentFrameDurations.push(seconds); |
|
|
|
t1 = system_clock::now(); |
|
|
|
t1 = system_clock::now(); |
|
|
|
drawFrame(seconds); |
|
|
|
drawFrame(seconds); |
|
|
|
} |
|
|
|
} |
|
|
@ -178,24 +179,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>(true); |
|
|
|
computeFence = make_unique<Fence>(false); |
|
|
|
transferFence = make_unique<Fence>(true); |
|
|
|
transferFence = make_unique<Fence>(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Application::createMeshBuffers() { |
|
|
|
void Application::createMeshBuffers() { |
|
|
|
Mesh sphere("models/icosphere.ply"); |
|
|
|
Mesh sphere("models/icosphere_medium.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 < 2; i++){ |
|
|
|
for (size_t i = 0; i < 10; 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 < 2; i++){ |
|
|
|
for (size_t i = 0; i < 10; 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)); |
|
|
@ -496,16 +497,6 @@ 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; |
|
|
@ -561,6 +552,17 @@ 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) { |
|
|
@ -711,9 +713,14 @@ void Application::imGuiWindows() { |
|
|
|
ImGui::NewFrame(); |
|
|
|
ImGui::NewFrame(); |
|
|
|
|
|
|
|
|
|
|
|
ImGui::Begin("Performance"); |
|
|
|
ImGui::Begin("Performance"); |
|
|
|
ImGui::Text("Update time: %f", performanceInformation.updateDuration); |
|
|
|
|
|
|
|
ImGui::Text("Updates per second: %f", 1 / performanceInformation.totalUpdateDuration); |
|
|
|
float updateMS = performanceInformation.updateDuration * 1000.f; |
|
|
|
ImGui::Text("Frame time: %f", performanceInformation.frameDuration); |
|
|
|
float updateHZ = 1 / performanceInformation.recentTotalUpdateDurations.average(); |
|
|
|
ImGui::Text("Frames per second: %f", 1 / performanceInformation.frameDuration); |
|
|
|
ImGui::Text("Updates: %.0fms | %.1fHz", updateMS, updateHZ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float frameMS = performanceInformation.recentFrameDurations.average() * 1000.f; |
|
|
|
|
|
|
|
float frameHZ = 1 / performanceInformation.recentFrameDurations.average(); |
|
|
|
|
|
|
|
ImGui::Text("Frames: %.2fms | %.1fHz", frameMS, frameHZ); |
|
|
|
|
|
|
|
|
|
|
|
ImGui::End(); |
|
|
|
ImGui::End(); |
|
|
|
} |
|
|
|
} |
|
|
|