Skip to content

Commit abd3c6d

Browse files
authored
[merge] Merge pull request #613 from inexorgame/hanni/cleanup
Cleanup
2 parents bbb3bb6 + 074bb1f commit abd3c6d

33 files changed

+190
-167
lines changed

example/main.cpp

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,15 @@
11
#include "inexor/vulkan-renderer/application.hpp"
22

3-
#include <spdlog/async.h>
4-
#include <spdlog/sinks/basic_file_sink.h>
5-
#include <spdlog/sinks/stdout_color_sinks.h>
6-
#include <spdlog/spdlog.h>
7-
83
#include <stdexcept>
94

105
int main(int argc, char *argv[]) {
11-
spdlog::init_thread_pool(8192, 2);
12-
13-
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
14-
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("vulkan-renderer.log", true);
15-
auto vulkan_renderer_log =
16-
std::make_shared<spdlog::async_logger>("vulkan-renderer", spdlog::sinks_init_list{console_sink, file_sink},
17-
spdlog::thread_pool(), spdlog::async_overflow_policy::block);
18-
vulkan_renderer_log->set_level(spdlog::level::trace);
19-
vulkan_renderer_log->set_pattern("%Y-%m-%d %T.%f %^%l%$ %5t [%-10n] %v");
20-
vulkan_renderer_log->flush_on(spdlog::level::debug); // TODO: as long as we don't have a flush on crash
21-
22-
spdlog::set_default_logger(vulkan_renderer_log);
23-
24-
spdlog::trace("Inexor vulkan-renderer, BUILD " + std::string(__DATE__) + ", " + __TIME__);
25-
spdlog::trace("Parsing command line arguments");
26-
27-
std::unique_ptr<inexor::vulkan_renderer::Application> renderer;
28-
296
try {
30-
renderer = std::make_unique<inexor::vulkan_renderer::Application>(argc, argv);
31-
} catch (const std::runtime_error &exception) {
32-
spdlog::critical(exception.what());
33-
return 1;
7+
using inexor::vulkan_renderer::Application;
8+
auto renderer = std::make_unique<Application>(argc, argv);
9+
renderer->run();
3410
} catch (const std::exception &exception) {
3511
spdlog::critical(exception.what());
3612
return 1;
3713
}
38-
39-
renderer->run();
40-
spdlog::trace("Window closed");
14+
return 0;
4115
}

include/inexor/vulkan-renderer/application.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class Application : public VulkanRenderer {
3232
/// @brief file_name The TOML configuration file.
3333
/// @note It was collectively decided not to use JSON for configuration files.
3434
void load_toml_configuration_file(const std::string &file_name);
35-
void load_textures();
3635
void load_shaders();
3736
/// @param initialize Initialize worlds with a fixed seed, which is useful for benchmarking and testing
3837
void load_octree_geometry(bool initialize);
@@ -43,6 +42,7 @@ class Application : public VulkanRenderer {
4342
/// Use the camera's position and view direction vector to check for ray-octree collisions with all octrees.
4443
void check_octree_collisions();
4544
void process_input();
45+
void initialize_spdlog();
4646

4747
public:
4848
Application(int argc, char **argv);

include/inexor/vulkan-renderer/render_graph.hpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,26 @@
1616
// TODO: Compute stages.
1717
// TODO: Uniform buffers.
1818

19-
// Forward declarations
2019
namespace inexor::vulkan_renderer::wrapper {
21-
class CommandBuffer;
20+
// Forward declaration
2221
class Shader;
2322
}; // namespace inexor::vulkan_renderer::wrapper
2423

24+
namespace inexor::vulkan_renderer::wrapper::commands {
25+
// Forward declaration
26+
class CommandBuffer;
27+
} // namespace inexor::vulkan_renderer::wrapper::commands
28+
2529
namespace inexor::vulkan_renderer {
2630

2731
// Forward declarations
2832
class PhysicalResource;
2933
class PhysicalStage;
3034
class RenderGraph;
3135

36+
// Using declaration
37+
using wrapper::commands::CommandBuffer;
38+
3239
/// @brief Base class of all render graph objects (resources and stages).
3340
/// @note This is just for internal use.
3441
struct RenderGraphObject {
@@ -167,7 +174,7 @@ class RenderStage : public RenderGraphObject {
167174

168175
std::vector<VkDescriptorSetLayout> m_descriptor_layouts;
169176
std::vector<VkPushConstantRange> m_push_constant_ranges;
170-
std::function<void(const PhysicalStage &, const wrapper::CommandBuffer &)> m_on_record{[](auto &, auto &) {}};
177+
std::function<void(const PhysicalStage &, const CommandBuffer &)> m_on_record{[](auto &, auto &) {}};
171178

172179
protected:
173180
explicit RenderStage(std::string name) : m_name(std::move(name)) {}
@@ -393,7 +400,7 @@ class RenderGraph {
393400

394401
// Functions for building stage related vulkan objects.
395402
void build_pipeline_layout(const RenderStage *, PhysicalStage &) const;
396-
void record_command_buffer(const RenderStage *, const wrapper::CommandBuffer &cmd_buf,
403+
void record_command_buffer(const RenderStage *, const wrapper::commands::CommandBuffer &cmd_buf,
397404
std::uint32_t image_index) const;
398405

399406
// Functions for building graphics stage related vulkan objects.
@@ -427,7 +434,7 @@ class RenderGraph {
427434
/// @brief Submits the command frame's command buffers for drawing.
428435
/// @param image_index The current image index, retrieved from Swapchain::acquire_next_image
429436
/// @param cmd_buf The command buffer
430-
void render(std::uint32_t image_index, const wrapper::CommandBuffer &cmd_buf);
437+
void render(std::uint32_t image_index, const wrapper::commands::CommandBuffer &cmd_buf);
431438
};
432439

433440
template <typename T>

include/inexor/vulkan-renderer/renderer.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
#include "inexor/vulkan-renderer/time_step.hpp"
88
#include "inexor/vulkan-renderer/wrapper/instance.hpp"
99
#include "inexor/vulkan-renderer/wrapper/uniform_buffer.hpp"
10-
#include "inexor/vulkan-renderer/wrapper/window.hpp"
11-
#include "inexor/vulkan-renderer/wrapper/window_surface.hpp"
10+
#include "inexor/vulkan-renderer/wrapper/window/surface.hpp"
11+
#include "inexor/vulkan-renderer/wrapper/window/window.hpp"
1212

1313
namespace inexor::vulkan_renderer {
1414

15+
using wrapper::window::Window;
16+
using wrapper::window::WindowSurface;
17+
1518
class VulkanRenderer {
1619
protected:
1720
std::vector<VkPipelineShaderStageCreateInfo> m_shader_stages;
@@ -24,7 +27,7 @@ class VulkanRenderer {
2427

2528
std::uint32_t m_window_width{0};
2629
std::uint32_t m_window_height{0};
27-
wrapper::Window::Mode m_window_mode{wrapper::Window::Mode::WINDOWED};
30+
Window::Mode m_window_mode{Window::Mode::WINDOWED};
2831

2932
std::string m_window_title;
3033

@@ -34,10 +37,10 @@ class VulkanRenderer {
3437

3538
std::unique_ptr<Camera> m_camera;
3639

37-
std::unique_ptr<wrapper::Window> m_window;
40+
std::unique_ptr<Window> m_window;
3841
std::unique_ptr<wrapper::Instance> m_instance;
3942
std::unique_ptr<wrapper::Device> m_device;
40-
std::unique_ptr<wrapper::WindowSurface> m_surface;
43+
std::unique_ptr<WindowSurface> m_surface;
4144
std::unique_ptr<wrapper::Swapchain> m_swapchain;
4245
std::unique_ptr<ImGUIOverlay> m_imgui_overlay;
4346
std::unique_ptr<RenderGraph> m_render_graph;

include/inexor/vulkan-renderer/vk_tools/device_info.hpp renamed to include/inexor/vulkan-renderer/tools/device_info.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <string>
66
#include <vector>
77

8-
namespace inexor::vulkan_renderer::vk_tools {
8+
namespace inexor::vulkan_renderer::tools {
99

1010
/// Transform a ``VkPhysicalDeviceFeatures`` into a ``std::vector<VkBool32>``
1111
/// @note The size of the vector will be determined by the number of ``VkBool32`` variables in the
@@ -19,4 +19,4 @@ namespace inexor::vulkan_renderer::vk_tools {
1919
/// @return The name of the physical device
2020
[[nodiscard]] std::string get_physical_device_name(VkPhysicalDevice physical_device);
2121

22-
} // namespace inexor::vulkan_renderer::vk_tools
22+
} // namespace inexor::vulkan_renderer::tools

include/inexor/vulkan-renderer/vk_tools/enumerate.hpp renamed to include/inexor/vulkan-renderer/tools/enumerate.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include <vector>
66

7-
namespace inexor::vulkan_renderer::vk_tools {
7+
namespace inexor::vulkan_renderer::tools {
88

99
/// All functions which contain the word "all" in it, call some vkEnumerate.. function,
1010
/// while all functions without it call vkGet..
@@ -45,4 +45,4 @@ namespace inexor::vulkan_renderer::vk_tools {
4545
[[nodiscard]] std::vector<VkPresentModeKHR> get_surface_present_modes(VkPhysicalDevice physical_device,
4646
VkSurfaceKHR surface);
4747

48-
} // namespace inexor::vulkan_renderer::vk_tools
48+
} // namespace inexor::vulkan_renderer::tools

include/inexor/vulkan-renderer/vk_tools/representation.hpp renamed to include/inexor/vulkan-renderer/tools/representation.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include <string>
66

7-
namespace inexor::vulkan_renderer::vk_tools {
7+
namespace inexor::vulkan_renderer::tools {
88

99
/// @brief This function returns a textual representation of the vulkan object T.
1010
template <typename T>
@@ -23,4 +23,4 @@ template <typename T>
2323
/// If you want to convert it into an std::string_view, see the matching ```as_string``` template
2424
[[nodiscard]] std::string_view result_to_description(VkResult result);
2525

26-
} // namespace inexor::vulkan_renderer::vk_tools
26+
} // namespace inexor::vulkan_renderer::tools

include/inexor/vulkan-renderer/wrapper/command_buffer.hpp renamed to include/inexor/vulkan-renderer/wrapper/commands/command_buffer.hpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
#pragma once
22

3-
#include "inexor/vulkan-renderer/wrapper/fence.hpp"
43
#include "inexor/vulkan-renderer/wrapper/gpu_memory_buffer.hpp"
4+
#include "inexor/vulkan-renderer/wrapper/synchronization/fence.hpp"
55

66
#include <cassert>
77
#include <memory>
88
#include <span>
99
#include <vector>
1010

1111
namespace inexor::vulkan_renderer::wrapper {
12-
1312
// Forward declaration
1413
class Device;
14+
} // namespace inexor::vulkan_renderer::wrapper
15+
16+
namespace inexor::vulkan_renderer::wrapper::synchronization {
17+
// Forward declaration
18+
class Fence;
19+
} // namespace inexor::vulkan_renderer::wrapper::synchronization
20+
21+
namespace inexor::vulkan_renderer::wrapper::commands {
22+
23+
// Using declarations
24+
using wrapper::Device;
25+
using wrapper::synchronization::Fence;
1526

1627
/// @brief RAII wrapper class for VkCommandBuffer.
1728
/// @todo Make trivially copyable (this class doesn't really "own" the command buffer, more just an OOP wrapper).
@@ -364,4 +375,4 @@ class CommandBuffer {
364375
const CommandBuffer &submit_and_wait() const; // NOLINT
365376
};
366377

367-
} // namespace inexor::vulkan_renderer::wrapper
378+
} // namespace inexor::vulkan_renderer::wrapper::commands

include/inexor/vulkan-renderer/wrapper/command_pool.hpp renamed to include/inexor/vulkan-renderer/wrapper/commands/command_pool.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
#include <spdlog/spdlog.h>
44
#include <volk.h>
55

6-
#include "inexor/vulkan-renderer/wrapper/command_buffer.hpp"
6+
#include "inexor/vulkan-renderer/wrapper/commands/command_buffer.hpp"
77

88
#include <cassert>
99

1010
namespace inexor::vulkan_renderer::wrapper {
11-
1211
// Forward declaration
1312
class Device;
13+
} // namespace inexor::vulkan_renderer::wrapper
14+
15+
namespace inexor::vulkan_renderer::wrapper::commands {
1416

1517
/// @brief RAII wrapper class for VkCommandPool.
1618
class CommandPool {
@@ -49,4 +51,4 @@ class CommandPool {
4951
[[nodiscard]] const CommandBuffer &request_command_buffer(const std::string &name);
5052
};
5153

52-
} // namespace inexor::vulkan_renderer::wrapper
54+
} // namespace inexor::vulkan_renderer::wrapper::commands

include/inexor/vulkan-renderer/wrapper/device.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include "inexor/vulkan-renderer/wrapper/command_pool.hpp"
3+
#include "inexor/vulkan-renderer/wrapper/commands/command_pool.hpp"
44

55
#include <array>
66
#include <functional>
@@ -13,6 +13,9 @@ namespace inexor::vulkan_renderer::wrapper {
1313
// Forward declaration
1414
class Instance;
1515

16+
using wrapper::commands::CommandBuffer;
17+
using wrapper::commands::CommandPool;
18+
1619
/// A wrapper struct for physical device data
1720
struct DeviceInfo {
1821
std::string name;

0 commit comments

Comments
 (0)