11 const std::string& shader_path,
28 const std::string& name,
29 const std::shared_ptr<Nodes::Node>& node,
30 const std::string& descriptor_name,
32 vk::DescriptorType type)
36 "Cannot bind null node '{}'", name);
42 "Descriptor '{}' not found in shader config", descriptor_name);
52 .descriptor_name = descriptor_name,
54 .binding_index = binding_config.binding,
57 .gpu_buffer = gpu_buffer,
59 .buffer_size =
sizeof(float)
65 "Bound scalar node '{}' to descriptor '{}'", name, descriptor_name);
69 const std::string& name,
70 const std::shared_ptr<Nodes::Node>& node,
71 const std::string& descriptor_name,
73 vk::DescriptorType type)
77 "Cannot bind null node '{}'", name);
83 "Descriptor '{}' not found in shader config", descriptor_name);
89 size_t initial_size = 4096 *
sizeof(float);
94 .descriptor_name = descriptor_name,
96 .binding_index = binding_config.binding,
99 .gpu_buffer = gpu_buffer,
101 .buffer_size = initial_size
107 "Bound vector node '{}' to descriptor '{}'", name, descriptor_name);
111 const std::string& name,
112 const std::shared_ptr<Nodes::Node>& node,
113 const std::string& descriptor_name,
115 vk::DescriptorType type)
119 "Cannot bind null node '{}'", name);
125 "Descriptor '{}' not found in shader config", descriptor_name);
131 size_t initial_size =
static_cast<long>(1024) * 1024 *
sizeof(
float);
136 .descriptor_name = descriptor_name,
138 .binding_index = binding_config.binding,
141 .gpu_buffer = gpu_buffer,
143 .buffer_size = initial_size
149 "Bound matrix node '{}' to descriptor '{}'", name, descriptor_name);
160 "Unbound node '{}'", name);
171 std::vector<std::string> names;
174 names.push_back(name);
185 const std::shared_ptr<VKBuffer>& buffer)
197 "Pipeline created for DescriptorBindingsProcessor (ID: {}, {} node bindings)",
211 "Binding has null node");
219 auto value =
static_cast<float>(binding.
node->get_last_output());
228 if (!gpu_vec || !gpu_vec->has_gpu_data()) {
230 "Node context does not provide GpuVectorData");
234 auto data = gpu_vec->gpu_data();
243 if (!gpu_mat || !gpu_mat->has_gpu_data()) {
245 "Node context does not provide GpuMatrixData");
249 auto data = gpu_mat->gpu_data();
257 if (!gpu_struct || !gpu_struct->has_gpu_data()) {
259 "Node context does not provide GpuStructuredData");
263 auto data = gpu_struct->gpu_data();
272 const std::string& name,
273 const std::shared_ptr<Nodes::Node>& node,
274 const std::string& descriptor_name,
276 vk::DescriptorType type)
280 "Cannot bind null node '{}'", name);
286 "Descriptor '{}' not found in shader config", descriptor_name);
292 size_t initial_size =
static_cast<long>(1024) * 64;
297 .descriptor_name = descriptor_name,
299 .binding_index = binding_config.binding,
302 .gpu_buffer = gpu_buffer,
304 .buffer_size = initial_size
310 "Bound structured node '{}' to descriptor '{}'", name, descriptor_name);
315 size_t required_size)
317 if (required_size <= binding.gpu_buffer->get_size_bytes()) {
321 size_t new_size = required_size * 3 / 2;
324 "Resizing descriptor buffer '{}': {} → {} bytes",
336 vk::DescriptorType type)
340 if (type == vk::DescriptorType::eUniformBuffer) {
346 return std::make_shared<VKBuffer>(
#define MF_ERROR(comp, ctx,...)
#define MF_RT_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
void update_descriptor_from_node(DescriptorBinding &binding)
Update descriptor from node context.
void unbind_node(const std::string &name)
Remove a binding.
DescriptorBindingsProcessor(const std::string &shader_path, uint32_t workgroup_x=256)
Create DescriptorBindingsProcessor with shader path.
void bind_scalar_node(const std::string &name, const std::shared_ptr< Nodes::Node > &node, const std::string &descriptor_name, uint32_t set, vk::DescriptorType type=vk::DescriptorType::eUniformBuffer)
Bind scalar node output to descriptor.
void on_before_dispatch(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer) override
Called before shader dispatch - updates all descriptors.
void bind_matrix_node(const std::string &name, const std::shared_ptr< Nodes::Node > &node, const std::string &descriptor_name, uint32_t set, vk::DescriptorType type=vk::DescriptorType::eStorageBuffer)
Bind matrix node (MatrixContext) to descriptor.
void on_pipeline_created(Portal::Graphics::ComputePipelineID pipeline_id) override
Called after pipeline creation - allocates GPU buffers for descriptors.
void ensure_buffer_capacity(DescriptorBinding &binding, size_t required_size)
Ensure descriptor buffer has sufficient capacity.
std::shared_ptr< VKBuffer > create_descriptor_buffer(size_t size, vk::DescriptorType type)
Create GPU buffer for a descriptor binding.
bool has_binding(const std::string &name) const
Check if binding exists.
void bind_structured_node(const std::string &name, const std::shared_ptr< Nodes::Node > &node, const std::string &descriptor_name, uint32_t set, vk::DescriptorType type=vk::DescriptorType::eStorageBuffer)
Bind structured node (arrays of POD structs) to descriptor.
std::unordered_map< std::string, DescriptorBinding > m_bindings
void bind_vector_node(const std::string &name, const std::shared_ptr< Nodes::Node > &node, const std::string &descriptor_name, uint32_t set, vk::DescriptorType type=vk::DescriptorType::eStorageBuffer)
Bind vector node (VectorContext) to descriptor.
@ MATRIX
2D grid from MatrixContext
@ VECTOR
Array from VectorContext.
@ SCALAR
Single value from node output.
@ STRUCTURED
Array of structs from StructuredContext.
std::vector< std::string > get_binding_names() const
Get all binding names.
virtual void on_before_dispatch(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer)
Called before each dispatch.
void unbind_buffer(const std::string &descriptor_name)
Unbind a buffer from a descriptor.
bool m_needs_descriptor_rebuild
virtual void on_pipeline_created(Portal::Graphics::ComputePipelineID pipeline_id)
Called after pipeline is created.
ShaderProcessorConfig m_config
void bind_buffer(const std::string &descriptor_name, const std::shared_ptr< VKBuffer > &buffer)
Bind a VKBuffer to a named shader descriptor.
Generic compute shader processor for VKBuffers.
@ UNIFORM
Uniform buffer (host-visible when requested)
@ COMPUTE
Storage buffer for compute shaders.
GPU-uploadable 2D grid data interface.
GPU-uploadable structured data (arrays of POD structs)
GPU-uploadable 1D array data interface.
Base context class for node callbacks.
void upload_to_gpu(const void *data, size_t size, const std::shared_ptr< VKBuffer > &target, const std::shared_ptr< VKBuffer > &staging)
Upload raw data to GPU buffer (auto-detects host-visible vs device-local)
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.
@ UNKNOWN
Unknown or undefined modality.
uint64_t ComputePipelineID
size_t buffer_size
Size to write.
std::string descriptor_name
Matches ShaderProcessor binding name.
std::shared_ptr< Nodes::Node > node
std::shared_ptr< VKBuffer > gpu_buffer
UBO/SSBO backing storage.
std::unordered_map< std::string, ShaderBinding > bindings
Complete configuration for shader processor.