sandbox
Loading...
Searching...
No Matches
frustum_culling_task.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_MODELS_FRUSTUM_CULL_TASK_HPP_
3#define LIBSBX_MODELS_FRUSTUM_CULL_TASK_HPP_
4
5#include <cstdint>
6#include <filesystem>
7#include <vector>
8#include <array>
9
10#include <vulkan/vulkan.h>
11
12#include <libsbx/math/matrix4x4.hpp>
13#include <libsbx/math/vector4.hpp>
14#include <libsbx/math/plane.hpp>
15
16#include <libsbx/core/engine.hpp>
17
18#include <libsbx/graphics/task.hpp>
19#include <libsbx/graphics/graphics_module.hpp>
20#include <libsbx/graphics/commands/command_buffer.hpp>
21#include <libsbx/graphics/buffers/storage_buffer.hpp>
22#include <libsbx/graphics/buffers/push_handler.hpp>
23#include <libsbx/graphics/pipeline/compute_pipeline.hpp>
24
25namespace sbx::models {
26
27struct aabb {
28 math::vector4f min; // xyz = world-space min, w = unused
29 math::vector4f max; // xyz = world-space max, w = unused
30}; // struct aabb
31
32class frustum_cull_task final : public graphics::task {
33
34public:
35
36 frustum_cull_task(const std::filesystem::path& path);
37
38 ~frustum_cull_task() override;
39
40 auto submit_commands(const std::vector<VkDrawIndexedIndirectCommand>& commands, const std::vector<aabb>& bounds) -> void;
41
42 auto execute(graphics::command_buffer& command_buffer) -> void override;
43
44 auto output_command_buffer_handle() const -> graphics::storage_buffer_handle;
45
46 auto draw_count_buffer_handle() const -> graphics::storage_buffer_handle;
47
48 auto submitted_command_count() const -> std::uint32_t;
49
50private:
51
52 template<typename Type>
53 static auto _resize_buffer(graphics::storage_buffer& buffer, std::uint32_t element_count) -> void {
54 const auto required_size = static_cast<std::size_t>(element_count) * sizeof(Type);
55
56 if (buffer.size() < required_size) {
57 buffer.resize(required_size + required_size / 2);
58 }
59 }
60
61 template<typename Type>
62 static auto _update_buffer(graphics::storage_buffer& buffer, const std::vector<Type>& data) -> void {
63 _resize_buffer<Type>(buffer, static_cast<std::uint32_t>(data.size()));
64
65 if (!data.empty()) {
66 buffer.update(data.data(), data.size() * sizeof(Type));
67 }
68 }
69
70 graphics::storage_buffer_handle _input_commands_buffer{};
71 graphics::storage_buffer_handle _bounds_buffer{};
72 graphics::storage_buffer_handle _output_commands_buffer{};
73 graphics::storage_buffer_handle _draw_count_buffer{};
74
76 graphics::push_handler _push_handler;
77
78 std::uint32_t _command_count{0};
79
80}; // class frustum_cull_task
81
82} // namespace sbx::models
83
84#endif // LIBSBX_MODELS_FRUSTUM_CULL_TASK_HPP_
Definition: command_buffer.hpp:15
Definition: compute_pipeline.hpp:18
Definition: push_handler.hpp:18
Definition: resource_storage.hpp:18
Definition: storage_buffer.hpp:17
Definition: task.hpp:9
Definition: vector4.hpp:24
Definition: frustum_culling_task.hpp:32
Definition: frustum_culling_task.hpp:27