8#include "shader_layout.hpp"
9#include "vulkan_pipeline.hpp"
22 void create(
const VulkanCore& core, vk::ImageView depth, vk::Extent2D depth_extent);
25 void record(vk::CommandBuffer cmd, vk::Extent2D scene_extent,
const glm::mat4& view_projection);
33 return m_view.has_value() && m_pipeline.isReady();
38 auto view() const -> vk::ImageView {
39 return m_view.has_value() ? **m_view : vk::ImageView {};
43 auto sampler() const -> vk::Sampler {
50 return m_built_extent;
54 auto builtLevels() const -> uint32_t {
55 return m_built_levels;
59 auto builtViewProjection() const -> const glm::mat4& {
60 return m_built_view_projection;
65 static auto levelCount(vk::Extent2D extent) -> uint32_t;
75 glm::uvec2 source_size {0};
76 uint32_t level_count = 0;
77 uint32_t group_count = 0;
80 ShaderLayout m_layout;
81 VulkanPipeline m_pipeline;
82 vk::raii::Sampler m_sampler =
nullptr;
84 std::optional<vma::raii::Image> m_image;
85 std::optional<vk::raii::ImageView> m_view;
86 std::vector<vk::raii::ImageView> m_level_views;
87 std::optional<vk::raii::DescriptorSet> m_set;
89 std::optional<vma::raii::Buffer> m_counter;
90 bool m_counter_cleared =
false;
91 sync::ImageState m_state;
92 uint32_t m_levels = 0;
94 vk::Extent2D m_built_extent {0, 0};
95 uint32_t m_built_levels = 0;
96 glm::mat4 m_built_view_projection {1.0f};
Farthest depth pyramid where level k texel t covers pixels t << (k + 1) to ((t + 1) << (k + 1)) - 1.
Definition hiz_pyramid.hpp:19
auto builtExtent() const -> vk::Extent2D
What the last record() covered and saw with zero levels before the first one.
Definition hiz_pyramid.hpp:49
void beforeRead(sync::BarrierBatch &barriers)
Earlier writes land before a compute shader samples view().
Definition hiz_pyramid.cpp:165
static auto levelCount(vk::Extent2D extent) -> uint32_t
Levels until the scene extent halves down to one texel.
Definition hiz_pyramid.cpp:61
void record(vk::CommandBuffer cmd, vk::Extent2D scene_extent, const glm::mat4 &view_projection)
Depth in depth_sampled and only its top left scene_extent is reduced.
Definition hiz_pyramid.cpp:169
auto view() const -> vk::ImageView
Every level in eShaderReadOnlyOptimal once recorded.
Definition hiz_pyramid.hpp:38
void create(const VulkanCore &core, vk::ImageView depth, vk::Extent2D depth_extent)
After a wait for idle since an in flight frame may still read the previous pyramid.
Definition hiz_pyramid.cpp:66
static constexpr uint32_t k_max_levels
Mirrors hiz_reduce.slang kMaxLevels so level 0 reaches 4096 texels.
Definition hiz_pyramid.hpp:68
auto isReady() const -> bool
view() can be bound without it but only a ready pyramid is ever built
Definition hiz_pyramid.hpp:32
Definition vulkan_core.hpp:48
Skips a barrier only when neither side writes and the layout and next read stages are already covered...
Definition gpu_sync.hpp:105