Toast Engine
Loading...
Searching...
No Matches
debug_pass.hpp
Go to the documentation of this file.
1
4
5#pragma once
6#include "../render_pass_base.hpp"
7#include "../shader_layout.hpp"
8#include "../vulkan_common.hpp"
9#include "../vulkan_pipeline.hpp"
10
11#include <array>
12#include <chrono>
13#include <glm/glm.hpp>
14#include <memory>
16#include <unordered_map>
17#include <vector>
18
19namespace renderer {
20class VulkanCore;
22
23class PerfWindow;
24
25namespace voxel_debug {
26class Monitor;
27}
28
29class DebugPass : public IRenderPass {
30public:
31 DebugPass(
32 const renderer::VulkanCore& core, vk::Format color_format, vk::Format depth_format, vk::Extent2D extent,
33 const ClusterLightingPass* cluster_lighting_pass = nullptr
34 );
35
36 ~DebugPass() override;
37
38 [[nodiscard]]
39 auto stage() const -> RenderStage override {
40 return RenderStage::overlay;
41 }
42
43 void record(vk::CommandBuffer cmd, uint32_t frame_index, uint32_t image_index) override;
44
45 void update(uint32_t frame_index, float dt) override;
46
47 void setEditorPanelsEnabled(bool enabled) noexcept { m_editor_panels = enabled; }
48
49 [[nodiscard]]
50 auto name() const -> std::string_view override {
51 return "Debug";
52 }
53
54private:
55 struct DrawPushConstants {
56 glm::mat4 model;
57 glm::vec4 tint {1.0f};
58 };
59
60 struct GizmoHandleRange {
61 uint32_t first_vertex = 0;
62 uint32_t vertex_count = 0;
63 glm::vec4 base_color {1.0f};
64 };
65
66 struct DynamicVertexBuffer {
67 vma::raii::Buffer buffer = nullptr;
68 void* mapped = nullptr;
69 vk::DeviceSize capacity_bytes = 0;
70 };
71
72 void createResources(const renderer::VulkanCore& core);
73
74 void initImGui(const renderer::VulkanCore& core, vk::Format color_format, vk::Format depth_format);
75 void createGizmoGeometry(const renderer::VulkanCore& core);
76 void createTranslateGizmoGeometry(const renderer::VulkanCore& core);
77 void createRotateGizmoGeometry(const renderer::VulkanCore& core);
78 void createScaleGizmoGeometry(const renderer::VulkanCore& core);
79
80 void createSizeGizmoGeometry(const renderer::VulkanCore& core);
81
82 void createBillboardResources(
83 const renderer::VulkanCore& core, vk::Format color_format, vk::Format depth_format, vk::Extent2D extent
84 );
85
86 auto billboardTextureSet(const renderer::VulkanCore& core, vk::ImageView view) -> vk::DescriptorSet;
87
88 void ensureLineCapacity(const renderer::VulkanCore& core, DynamicVertexBuffer& buffer, size_t required_vertex_count);
89
90 VulkanPipeline m_line_pipeline;
91 VulkanPipeline m_fill_pipeline;
92 VulkanPipeline m_gizmo_pipeline;
93
94 ShaderLayout m_shader_layout;
95 std::vector<vk::raii::DescriptorSet> m_frame_descriptor_sets;
96
97 std::vector<DynamicVertexBuffer> m_line_vertex_buffers;
98 std::vector<uint32_t> m_line_vertex_counts;
99 std::vector<DynamicVertexBuffer> m_fill_vertex_buffers;
100 std::vector<uint32_t> m_fill_vertex_counts;
101
102 std::vector<uint32_t> m_fill_sort_order;
103 std::vector<float> m_fill_sort_depths;
104
105 vma::raii::Buffer m_gizmo_vertex_buffer = nullptr;
106 uint32_t m_gizmo_vertex_count = 0;
107
108 vma::raii::Buffer m_translate_gizmo_vertex_buffer = nullptr;
109 std::array<GizmoHandleRange, 7> m_translate_gizmo_handles;
110
111 vma::raii::Buffer m_rotate_gizmo_vertex_buffer = nullptr;
112 std::array<GizmoHandleRange, 7> m_rotate_gizmo_handles;
113
114 vma::raii::Buffer m_scale_gizmo_vertex_buffer = nullptr;
115 std::array<GizmoHandleRange, 7> m_scale_gizmo_handles;
116
117 vma::raii::Buffer m_size_gizmo_vertex_buffer = nullptr;
118 uint32_t m_size_gizmo_vertex_count = 0;
119
120 VulkanPipeline m_mesh_pipeline;
121
122 struct BillboardPushConstants {
123 glm::vec4 center_size; // xyz centre w edge length
124 glm::vec4 tint {1.0f};
125 };
126
127 VulkanPipeline m_billboard_pipeline;
128 ShaderLayout m_billboard_layout;
129 std::vector<vk::raii::DescriptorSet> m_billboard_frame_sets;
130 vk::raii::Sampler m_billboard_sampler = nullptr;
131 std::unordered_map<VkImageView, vk::raii::DescriptorSet> m_billboard_texture_sets;
132
133 bool m_imgui_ready = false;
134 bool m_editor_panels = true;
135
136 std::unique_ptr<PerfWindow> m_perf;
137
138 std::unique_ptr<voxel_debug::Monitor> m_voxels;
139
140 const ClusterLightingPass* m_cluster_lighting_pass = nullptr;
141
142 float m_sky_intensity_ui = -1.0f;
143
144 std::array<char, 256> m_environment_uri_ui {};
145};
146
147}
Definition render_pass_base.hpp:19
Definition cluster_lighting_pass.hpp:20
Definition perf_window.hpp:17
Definition shader_layout.hpp:12
Definition vulkan_core.hpp:48
Definition vulkan_pipeline.hpp:19
Render thread only.
Definition voxel_debug.hpp:93
Geometry + hit-test constants shared between DebugPass (renders the gizmos) and Workspace (hit-tests/...