Skip to content

Commit

Permalink
Refactor project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
shg8 committed Mar 14, 2024
1 parent 11bbd84 commit 03624bf
Show file tree
Hide file tree
Showing 54 changed files with 19,761 additions and 19,718 deletions.
136 changes: 16 additions & 120 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.26)
project(vulkan_splatting)
project(vulkan_splatting_root)

include(FetchContent)

Expand Down Expand Up @@ -43,7 +43,6 @@ else ()
find_package(glm REQUIRED)
endif ()


FetchContent_Declare(libenvpp
GIT_REPOSITORY https://github.com/ph3at/libenvpp.git
GIT_TAG v1.0.0
Expand All @@ -70,127 +69,24 @@ if (APPLE)
add_compile_definitions(__APPLE__)
endif ()

file(GLOB_RECURSE GLSL_SOURCE_FILES
"shaders/*.frag"
"shaders/*.vert"
"shaders/*.comp"
)

if (CMAKE_BUILD_TYPE MATCHES Debug)
add_compile_definitions(DEBUG)
else ()
add_compile_definitions(NDEBUG)
endif ()

if (CMAKE_BUILD_TYPE MATCHES Debug AND NOT APPLE)
list(APPEND GLSLC_DEFINE "-DDEBUG")
else ()
list(APPEND GLSLC_DEFINE "-DNDEBUG")
endif ()

if (APPLE)
# append -DAPPLE to GLSLC_DEFINE
list(APPEND GLSLC_DEFINE "-DAPPLE")
endif ()

add_executable(embedfile cmake/embedfile.c)

set(SHADER_HEADER "${PROJECT_BINARY_DIR}/shaders/shaders.h")
message(STATUS "Shader header file: ${SHADER_HEADER}")

# Delete old header file
add_custom_command(
OUTPUT ${SHADER_HEADER}
COMMAND ${CMAKE_COMMAND} -E remove ${SHADER_HEADER}
DEPENDS ${GLSL_SOURCE_FILES}
)

foreach (GLSL ${GLSL_SOURCE_FILES})
get_filename_component(FILE_NAME ${GLSL} NAME_WE)
string(TOUPPER ${FILE_NAME} FILE_NAME_UPPER)
set(FILE_NAME_UPPER "SPV_${FILE_NAME_UPPER}")
set(SPIRV "${PROJECT_BINARY_DIR}/shaders/${FILE_NAME}.spv")
SET(TEMP_HEADER "${PROJECT_BINARY_DIR}/shaders/${FILE_NAME}.h")
add_custom_command(
OUTPUT ${SPIRV}
COMMAND ${CMAKE_COMMAND} -E make_directory "${PROJECT_BINARY_DIR}/shaders/"
COMMAND ${Vulkan_GLSLANG_VALIDATOR_EXECUTABLE} "--target-env" "vulkan1.2" -V ${GLSL} -o ${SPIRV} ${GLSLC_DEFINE}
DEPENDS ${GLSL})
list(APPEND SPIRV_BINARY_FILES ${SPIRV})

add_custom_command(
OUTPUT ${SHADER_HEADER}
COMMAND embedfile ${FILE_NAME_UPPER} ${SPIRV} ${SHADER_HEADER}
DEPENDS ${SPIRV}
APPEND)

list(APPEND TEMP_HEADERS ${TEMP_HEADER})
endforeach (GLSL)

add_custom_target(
Shaders
DEPENDS ${SPIRV_BINARY_FILES} ${SHADER_HEADER}
)
include_directories(${PROJECT_BINARY_DIR}/shaders)

include_directories(third_party)

file(GLOB EXTERNAL_SOURCE
${imgui_SOURCE_DIR}/*.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_vulkan.cpp
third_party/implot/implot.cpp
third_party/implot/implot_demo.cpp
third_party/implot/implot_items.cpp
)

add_executable(vulkan_splatting main.cpp
vulkan/VulkanContext.cpp
3dgs/Renderer.cpp
vulkan/Window.cpp
3dgs/GSScene.cpp
vulkan/Shader.cpp
vulkan/Utils.cpp
vulkan/VMA.cpp
vulkan/Buffer.cpp
vulkan/Buffer.h
vulkan/pipelines/Pipeline.cpp
vulkan/pipelines/Pipeline.h
vulkan/DescriptorSet.cpp
vulkan/DescriptorSet.h
vulkan/pipelines/ComputePipeline.cpp
vulkan/pipelines/ComputePipeline.h
vulkan/Swapchain.cpp
vulkan/Swapchain.h
${EXTERNAL_SOURCE}
vulkan/ImguiManager.cpp
vulkan/ImguiManager.h
vulkan/QueryManager.cpp
vulkan/QueryManager.h
3dgs/GUIManager.cpp
3dgs/GUIManager.h
)

add_dependencies(vulkan_splatting Shaders)

target_include_directories(vulkan_splatting PUBLIC
${Vulkan_INCLUDE_DIRS}
${GLM_INCLUDE_DIRS}
${glm_SOURCE_DIR}
${imgui_SOURCE_DIR}
${imgui_SOURCE_DIR}/backends
${spdlog_SOURCE_DIR}/include
)

target_link_libraries(vulkan_splatting PUBLIC glfw libenvpp::libenvpp spdlog::spdlog)
target_link_libraries(vulkan_splatting PUBLIC Vulkan::Vulkan)
if (UNIX)
target_link_libraries(vulkan_splatting PUBLIC ${CMAKE_DL_LIBS})
endif ()

add_custom_command(TARGET vulkan_splatting POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:vulkan_splatting>/shaders/"
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${PROJECT_BINARY_DIR}/shaders"
"$<TARGET_FILE_DIR:vulkan_splatting>/shaders"
)
add_subdirectory(src)
add_subdirectory(apps)

#add_custom_target(
# Shaders
# DEPENDS ${SPIRV_BINARY_FILES} ${SHADER_HEADER}
#)
#include_directories(${PROJECT_BINARY_DIR}/shaders)

#add_custom_command(TARGET vulkan_splatting POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:vulkan_splatting>/shaders/"
# COMMAND ${CMAKE_COMMAND} -E copy_directory
# "${PROJECT_BINARY_DIR}/shaders"
# "$<TARGET_FILE_DIR:vulkan_splatting>/shaders"
#)
3 changes: 3 additions & 0 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.26)

add_subdirectory(viewer)
10 changes: 10 additions & 0 deletions apps/viewer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.26)
project(vulkan_splatting_viewer)

add_executable(vulkan_splatting_viewer main.cpp)

target_include_directories(vulkan_splatting_viewer PRIVATE third_party)

target_link_libraries(vulkan_splatting_viewer PRIVATE
libenvpp::libenvpp
vulkan_splatting)
20 changes: 15 additions & 5 deletions main.cpp → apps/viewer/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <filesystem>
#include <iostream>
#include <libenvpp/env.hpp>

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

Expand All @@ -21,6 +22,8 @@ int main(int argc, char** argv) {
parser, "immediate-swapchain", "Set swapchain mode to immediate (VK_PRESENT_MODE_IMMEDIATE_KHR)",
{'i', "immediate-swapchain"}
};
args::ValueFlag<uint32_t> widthFlag{parser, "width", "Set window width", {"width"}};
args::ValueFlag<uint32_t> heightFlag{parser, "height", "Set window height", {"height"}};
args::Flag noGuiFlag{parser, "no-gui", "Disable GUI", { "no-gui"}};
args::Positional<std::string> scenePath{parser, "scene", "Path to scene file", "scene.ply"};

Expand Down Expand Up @@ -50,7 +53,7 @@ int main(int argc, char** argv) {
spdlog::set_level(spdlog::level::debug);
}

RendererConfiguration config{
VulkanSplatting::RendererConfiguration config{
envVars.get_or(validationLayers, false),
envVars.get(physicalDeviceId).has_value()
? std::make_optional(envVars.get(physicalDeviceId).value())
Expand Down Expand Up @@ -81,12 +84,19 @@ int main(int argc, char** argv) {
config.enableGui = false;
}

if (widthFlag) {
config.width = args::get(widthFlag);
}

if (heightFlag) {
config.height = args::get(heightFlag);
}

#ifndef DEBUG
try {
#endif
auto renderer = Renderer(config);
renderer.initialize();
renderer.run();
auto renderer = VulkanSplatting(config);
renderer.start();
#ifndef DEBUG
} catch (const std::exception& e) {
spdlog::critical(e.what());
Expand Down
File renamed without changes.
30 changes: 30 additions & 0 deletions include/vulkan_splatting/VulkanSplatting.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef VULKANSPLATTING_H
#define VULKANSPLATTING_H

#include <optional>
#include <string>

class VulkanSplatting {
public:
struct RendererConfiguration {
bool enableVulkanValidationLayers = false;
std::optional<uint8_t> physicalDeviceId = std::nullopt;
bool immediateSwapchain = false;
std::string scene;

float fov = 45.0f;
float near = 0.2f;
float far = 1000.0f;
bool enableGui = true;
uint32_t width = 800;
uint32_t height = 600;
};

explicit VulkanSplatting(RendererConfiguration configuration) : configuration(configuration) {}

void start() const;
private:
RendererConfiguration configuration;
};

#endif //VULKANSPLATTING_H
43 changes: 43 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
cmake_minimum_required(VERSION 3.26)
project(vulkan_splatting)

add_subdirectory(shaders)

file(GLOB EXTERNAL_SOURCE
${imgui_SOURCE_DIR}/*.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_vulkan.cpp
third_party/implot/implot.cpp
third_party/implot/implot_demo.cpp
third_party/implot/implot_items.cpp
)

file(GLOB_RECURSE SOURCE
*.cpp
vulkan/*.cpp)

add_library(vulkan_splatting STATIC
${SOURCE}
${EXTERNAL_SOURCE}
)

target_include_directories(vulkan_splatting
PUBLIC
${CMAKE_SOURCE_DIR}/include/vulkan_splatting
PRIVATE
third_party
${Vulkan_INCLUDE_DIRS}
${GLM_INCLUDE_DIRS}
${glm_SOURCE_DIR}
${imgui_SOURCE_DIR}
${imgui_SOURCE_DIR}/backends
${spdlog_SOURCE_DIR}/include
${CMAKE_BINARY_DIR}/shaders
)

add_dependencies(vulkan_splatting shaders)

target_link_libraries(vulkan_splatting PUBLIC Vulkan::Vulkan glfw spdlog::spdlog)
if (UNIX)
target_link_libraries(vulkan_splatting PUBLIC ${CMAKE_DL_LIBS})
endif ()
7 changes: 4 additions & 3 deletions 3dgs/GSScene.cpp → src/GSScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
#include <random>
#include "shaders.h"

#include "../vulkan/Utils.h"
#include "../vulkan/DescriptorSet.h"
#include "../vulkan/pipelines/ComputePipeline.h"
#include "vulkan/Utils.h"
#include "vulkan/DescriptorSet.h"
#include "vulkan/pipelines/ComputePipeline.h"
#include "spdlog/spdlog.h"
#include "vulkan/Shader.h"

struct VertexStorage {
glm::vec3 position;
Expand Down
4 changes: 2 additions & 2 deletions 3dgs/GSScene.h → src/GSScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <filesystem>
#include <iostream>
#include <glm/glm.hpp>
#include "../vulkan/VulkanContext.h"
#include "../vulkan/Buffer.h"
#include "vulkan/VulkanContext.h"
#include "vulkan/Buffer.h"

struct PlyProperty {
std::string type;
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions 3dgs/GUIManager.h → src/GUIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <string>
#include <memory>

#include "imgui.h"
#include "implot/implot.h"
#include "../cmake-build-debug/_deps/imgui-src/imgui.h"
#include "../third_party/implot/implot.h"

struct ScrollingBuffer {
int maxSize;
Expand Down
8 changes: 4 additions & 4 deletions 3dgs/Renderer.cpp → src/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <fstream>

#include "../vulkan/Swapchain.h"
#include "vulkan/Swapchain.h"

#include <memory>
#include <shaders.h>
Expand All @@ -12,7 +12,7 @@
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/quaternion.hpp>

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

#include <spdlog/spdlog.h>

Expand Down Expand Up @@ -100,7 +100,7 @@ void Renderer::retrieveTimestamps() {

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

Expand Down Expand Up @@ -174,7 +174,7 @@ void Renderer::createPreprocessPipeline() {
preprocessPipeline->build();
}

Renderer::Renderer(RendererConfiguration configuration) : configuration(std::move(configuration)) {
Renderer::Renderer(VulkanSplatting::RendererConfiguration configuration) : configuration(std::move(configuration)) {
}

void Renderer::createGui() {
Expand Down
Loading

0 comments on commit 03624bf

Please sign in to comment.