MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
VolumeSurfaceProcessor.cpp
Go to the documentation of this file.
3
6
7namespace MayaFlux::Buffers {
8
9namespace {
10 constexpr uint32_t k_workgroup_x = 64;
11}
12
14 std::shared_ptr<VolumeGridBuffer> volume,
15 std::string field_name,
16 Kinesis::Lattice3D lattice,
17 float threshold,
18 const std::string& shader_path)
19 : ComputeProcessor(shader_path, k_workgroup_x)
20 , m_volume(std::move(volume))
21 , m_field_name(std::move(field_name))
22 , m_lattice(std::move(lattice))
23 , m_threshold(threshold)
24{
25 m_config.bindings["field_in"] = ShaderBinding(0, 0, vk::DescriptorType::eStorageBuffer);
26 m_config.bindings["grid_out"] = ShaderBinding(0, 1, vk::DescriptorType::eStorageBuffer);
27
29
31 set_manual_dispatch((corner_count() + k_workgroup_x - 1) / k_workgroup_x, 1, 1);
32
34}
35
37{
40
41 m_grid_buf = std::make_shared<VKBuffer>(
42 corner_count() * sizeof(float),
43 VKBuffer::Usage::HOST_STORAGE,
45
46 svc->initialize_buffer(m_grid_buf);
47}
48
56
57void VolumeSurfaceProcessor::on_attach(const std::shared_ptr<Buffer>& buffer)
58{
60
61 bind_buffer("grid_out", m_grid_buf);
62
64}
65
67{
68 auto& data = get_push_constant_data();
69 if (data.size() < sizeof(SurfaceParams)) {
70 data.resize(sizeof(SurfaceParams));
71 }
72
73 const SurfaceParams params {
74 .width = m_volume->get_width(),
75 .height = m_volume->get_height(),
76 .depth = m_volume->get_depth(),
77 .pad0 = 0,
78 .res_x = m_lattice.resolution.x,
79 .res_y = m_lattice.resolution.y,
80 .res_z = m_lattice.resolution.z,
81 .threshold = m_threshold,
82 };
83
84 std::memcpy(data.data(), &params, sizeof(SurfaceParams));
85}
86
88{
89 if (!m_volume || m_descriptor_set_ids.empty()) {
90 return;
91 }
92
94 m_descriptor_set_ids[0], 0, vk::DescriptorType::eStorageBuffer,
95 m_volume->read_handle(m_field_name), 0,
96 m_volume->get_field_bytes(m_field_name));
97}
98
103
104void VolumeSurfaceProcessor::processing_function(const std::shared_ptr<Buffer>& buffer)
105{
108 }
109
111}
112
115 const std::shared_ptr<VKBuffer>& /*buffer*/)
116{
117 // return m_volume && std::dynamic_pointer_cast<VolumeGridBuffer>(buffer) != nullptr;
118 return m_volume != nullptr;
119}
120
121} // namespace MayaFlux::Buffers
float threshold
virtual void on_attach(const std::shared_ptr< Buffer > &)
Called when this processor is attached to a buffer.
virtual void processing_function(const std::shared_ptr< Buffer > &buffer)=0
The core processing function that must be implemented by derived classes.
void set_dispatch_mode(ShaderDispatchConfig::DispatchMode mode)
Set dispatch mode.
void set_manual_dispatch(uint32_t x, uint32_t y=1, uint32_t z=1)
Set manual dispatch group counts.
Specialized ShaderProcessor for Compute Pipelines.
const std::vector< uint8_t > & get_push_constant_data() const
Get current push constant data.
bool are_descriptors_ready() const
Check if descriptors are initialized.
void bind_buffer(const std::string &descriptor_name, const std::shared_ptr< VKBuffer > &buffer)
Bind a VKBuffer to a named shader descriptor.
std::vector< Portal::Graphics::DescriptorSetID > m_descriptor_set_ids
void write_field_descriptor()
Issue the direct ShaderFoundry descriptor write for the field read slot.
void set_threshold(float threshold)
Set the field value the surface is placed at.
void rebuild_grid_buffer()
Allocate the corner grid buffer for the current resolution.
void on_attach(const std::shared_ptr< Buffer > &buffer) override
Validate the named field, bind the grid, and size the dispatch.
std::shared_ptr< VolumeGridBuffer > m_volume
The attached volume, cached for the descriptor write.
void on_descriptors_created() override
Write the field descriptor for the current slot assignment.
VolumeSurfaceProcessor(std::shared_ptr< VolumeGridBuffer > volume, std::string field_name, Kinesis::Lattice3D lattice, float threshold, const std::string &shader_path="volume_to_sdf_grid.comp.spv")
Construct a surface extraction bridge.
void processing_function(const std::shared_ptr< Buffer > &buffer) override
Write the field descriptor for this cycle's slot assignment, then run the normal shader processing pa...
void write_params()
Size the push constant block to at least SurfaceParams and write the lattice dimensions,...
uint32_t corner_count() const noexcept
Corner count of the grid, one greater per axis than the extraction resolution.
bool on_before_execute(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer) override
Reject buffers that are not VolumeGridBuffer.
void update_descriptor_buffer(DescriptorSetID descriptor_set_id, uint32_t binding, vk::DescriptorType type, vk::Buffer buffer, size_t offset, size_t size)
Update descriptor set with buffer binding.
Interface * get_service()
Query for a backend service.
static BackendRegistry & instance()
Get the global registry instance.
@ UNKNOWN
Unknown or undefined modality.
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
Describes how a VKBuffer binds to a shader descriptor.
std::unordered_map< std::string, ShaderBinding > bindings
Push constant block the resample shader receives.
glm::uvec3 resolution
Cell count per axis. Zero on any axis is invalid.
Definition Lattice.hpp:26
A regular subdivision of an AABB3D into a cell count per axis.
Definition Lattice.hpp:25
Backend buffer management service interface.