Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/logging: robust logging using spdlog #10

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions 3dgs/GSScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "../vulkan/Utils.h"
#include "../vulkan/DescriptorSet.h"
#include "../vulkan/pipelines/ComputePipeline.h"
#include "spdlog/spdlog.h"

struct VertexStorage {
glm::vec3 position;
Expand Down Expand Up @@ -58,9 +59,8 @@ void GSScene::load(const std::shared_ptr<VulkanContext>&context) {
vertexBuffer->uploadFrom(vertexStagingBuffer);

auto endTime = std::chrono::high_resolution_clock::now();
std::cout << "Loaded " << filename << " in "
<< std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count() << "ms"
<< std::endl;
spdlog::info("Loaded {} in {}ms", filename,
std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count());

precomputeCov3D(context);
}
Expand Down Expand Up @@ -176,5 +176,5 @@ void GSScene::precomputeCov3D(const std::shared_ptr<VulkanContext>&context) {
commandBuffer->dispatch(numGroups, 1, 1);
context->endOneTimeCommandBuffer(std::move(commandBuffer), VulkanContext::Queue::COMPUTE);

std::cout << "Precomputed Cov3D" << std::endl;
spdlog::info("Precomputed Cov3D");
}
17 changes: 15 additions & 2 deletions 3dgs/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

#include "../vulkan/Utils.h"

#include <spdlog/spdlog.h>

#define SORT_ALLOCATE_MULTIPLIER 10

void Renderer::initialize() {
Expand Down Expand Up @@ -77,7 +79,8 @@ void Renderer::retrieveTimestamps() {
}

void Renderer::initializeVulkan() {
window = std::make_shared<Window>("Vulkan Splatting", 1920, 1080);
spdlog::debug("Initializing Vulkan");
window = std::make_shared<Window>("Vulkan Splatting", 800, 600);
context = std::make_shared<VulkanContext>(Window::getRequiredInstanceExtensions(), std::vector<std::string>{},
configuration.enableVulkanValidationLayers);

Expand Down Expand Up @@ -112,6 +115,7 @@ void Renderer::initializeVulkan() {
}

void Renderer::loadSceneToGPU() {
spdlog::debug("Loading scene to GPU");
scene = std::make_shared<GSScene>(configuration.scene);
scene->load(context);

Expand All @@ -120,6 +124,7 @@ void Renderer::loadSceneToGPU() {
}

void Renderer::createPreprocessPipeline() {
spdlog::debug("Creating preprocess pipeline");
uniformBuffer = Buffer::uniform(context, sizeof(UniformBuffer));
vertexAttributeBuffer = Buffer::storage(context, scene->getNumVertices() * sizeof(VertexAttributeBuffer), false);
tileOverlapBuffer = Buffer::storage(context, scene->getNumVertices() * sizeof(uint32_t), false);
Expand Down Expand Up @@ -153,6 +158,7 @@ Renderer::Renderer(RendererConfiguration configuration) : configuration(std::mov
}

void Renderer::createGui() {
spdlog::debug("Creating GUI");
if (!configuration.enableGui) {
return;
}
Expand All @@ -163,6 +169,7 @@ void Renderer::createGui() {
}

void Renderer::createPrefixSumPipeline() {
spdlog::debug("Creating prefix sum pipeline");
prefixSumPingBuffer = Buffer::storage(context, scene->getNumVertices() * sizeof(uint32_t), false);
prefixSumPongBuffer = Buffer::storage(context, scene->getNumVertices() * sizeof(uint32_t), false);
totalSumBufferHost = Buffer::staging(context, sizeof(uint32_t));
Expand All @@ -181,6 +188,7 @@ void Renderer::createPrefixSumPipeline() {
}

void Renderer::createRadixSortPipeline() {
spdlog::debug("Creating radix sort pipeline");
sortKBufferEven = Buffer::storage(context, scene->getNumVertices() * sizeof(uint64_t) * SORT_ALLOCATE_MULTIPLIER,
false);
sortKBufferOdd = Buffer::storage(context, scene->getNumVertices() * sizeof(uint64_t) * SORT_ALLOCATE_MULTIPLIER,
Expand Down Expand Up @@ -239,6 +247,7 @@ void Renderer::createRadixSortPipeline() {
}

void Renderer::createPreprocessSortPipeline() {
spdlog::debug("Creating preprocess sort pipeline");
preprocessSortPipeline = std::make_shared<ComputePipeline>(context, "preprocess_sort");
auto descriptorSet = std::make_shared<DescriptorSet>(context, FRAMES_IN_FLIGHT);
descriptorSet->bindBufferToDescriptorSet(0, vk::DescriptorType::eStorageBuffer, vk::ShaderStageFlagBits::eCompute,
Expand All @@ -259,6 +268,7 @@ void Renderer::createPreprocessSortPipeline() {
}

void Renderer::createTileBoundaryPipeline() {
spdlog::debug("Creating tile boundary pipeline");
auto [width, height] = window->getFramebufferSize();
auto tileX = (width + 16 - 1) / 16;
auto tileY = (height + 16 - 1) / 16;
Expand All @@ -280,6 +290,7 @@ void Renderer::createTileBoundaryPipeline() {
}

void Renderer::createRenderPipeline() {
spdlog::debug("Creating render pipeline");
renderPipeline = std::make_shared<ComputePipeline>(context, "render");
auto inputSet = std::make_shared<DescriptorSet>(context, FRAMES_IN_FLIGHT);
inputSet->bindBufferToDescriptorSet(0, vk::DescriptorType::eStorageBuffer, vk::ShaderStageFlagBits::eCompute,
Expand Down Expand Up @@ -366,7 +377,7 @@ void Renderer::run() {
auto now = std::chrono::high_resolution_clock::now();
auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(now - lastFpsTime).count();
if (diff > 1000) {
std::cout << "FPS: " << fpsCounter << std::endl;
spdlog::debug("FPS: {}", fpsCounter);
fpsCounter = 0;
lastFpsTime = now;
} else {
Expand Down Expand Up @@ -400,6 +411,7 @@ void Renderer::run() {
}

void Renderer::createCommandPool() {
spdlog::debug("Creating command pool");
vk::CommandPoolCreateInfo poolInfo = {};
poolInfo.queueFamilyIndex = context->queues[VulkanContext::Queue::COMPUTE].queueFamily;
poolInfo.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer;
Expand All @@ -408,6 +420,7 @@ void Renderer::createCommandPool() {
}

void Renderer::recordPreprocessCommandBuffer() {
spdlog::debug("Recording preprocess command buffer");
vk::CommandBufferAllocateInfo allocateInfo = {commandPool.get(), vk::CommandBufferLevel::ePrimary, 1};
auto buffers = context->device->allocateCommandBuffersUnique(allocateInfo);
preprocessCommandBuffer = std::move(buffers[0]);
Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ FetchContent_Declare(libenvpp
)
FetchContent_MakeAvailable(libenvpp)

FetchContent_Declare(spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.13.0
)
FetchContent_MakeAvailable(spdlog)

FetchContent_Declare(imgui
GIT_REPOSITORY https://github.com/ocornut/imgui.git
GIT_TAG v1.90.3
Expand Down Expand Up @@ -145,6 +151,7 @@ target_include_directories(vulkan_splatting PUBLIC
${glm_SOURCE_DIR}
${imgui_SOURCE_DIR}
${imgui_SOURCE_DIR}/backends
${spdlog_SOURCE_DIR}/include
)

target_link_libraries(vulkan_splatting PUBLIC glfw libenvpp::libenvpp)
Expand Down
27 changes: 18 additions & 9 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@

#include "3dgs/Renderer.h"
#include "args.hxx"
#include "spdlog/spdlog.h"

int main(int argc, char** argv) {
spdlog::set_pattern("[%H:%M:%S] [%^%L%$] %v");

args::ArgumentParser parser("Vulkan Splatting");
args::HelpFlag helpFlag{parser, "help", "Display this help menu", {'h', "help"}};
args::Flag validationLayersFlag{
parser, "validation-layers", "Enable Vulkan validation layers", {'v', "validation-layers"}
parser, "validation-layers", "Enable Vulkan validation layers", {"validation"}
};
args::Flag verboseFlag{parser, "verbose", "Enable verbose logging", {'v', "verbose"}};
args::ValueFlag<uint8_t> physicalDeviceIdFlag{
parser, "physical-device", "Select physical device by index", {'d', "device"}
};
Expand All @@ -31,14 +35,8 @@ int main(int argc, char** argv) {
return 0;
}
catch (const args::ParseError& e) {
std::cerr << e.what() << std::endl;
std::cerr << parser;
return 1;
}

if (!scenePath) {
std::cerr << "Scene path is required" << std::endl;
std::cerr << parser;
std::cout << e.what() << std::endl;
std::cout << parser;
return 1;
}

Expand All @@ -48,6 +46,10 @@ int main(int argc, char** argv) {
auto immediateSwapchain = pre.register_variable<bool>("IMMEDIATE_SWAPCHAIN");
auto envVars = pre.parse_and_validate();

if (args::get(verboseFlag)) {
spdlog::set_level(spdlog::level::debug);
}

RendererConfiguration config{
envVars.get_or(validationLayers, false),
envVars.get(physicalDeviceId).has_value()
Expand All @@ -57,6 +59,12 @@ int main(int argc, char** argv) {
args::get(scenePath)
};

// check that the scene file exists
if (!std::filesystem::exists(config.scene)) {
spdlog::critical("File does not exist: {}", config.scene);
return 0;
}

if (validationLayersFlag) {
config.enableVulkanValidationLayers = args::get(validationLayersFlag);
}
Expand All @@ -81,6 +89,7 @@ int main(int argc, char** argv) {
renderer.run();
#ifndef DEBUG
} catch (const std::exception& e) {
spdlog::critical(e.what());
std::cout << e.what() << std::endl;
return 0;
}
Expand Down
Loading
Loading