20 [[nodiscard]] Portal::Graphics::ShaderSpec require_spec(
21 const std::shared_ptr<Nodes::Network::GpuFieldOperator>& op)
24 error<std::invalid_argument>(
27 std::source_location::current(),
28 "VertexFieldProcessor: null field operator");
31 auto spec = op->build_spec();
32 if (!spec.has_value()) {
33 error<std::invalid_argument>(
36 std::source_location::current(),
37 "VertexFieldProcessor: operator produced no spec. Bind at least "
38 "one field, and supply a layout carrying a position attribute, "
39 "before constructing the processor.");
48 std::shared_ptr<Nodes::Network::GpuFieldOperator> field_operator)
50 , m_operator(
std::move(field_operator))
51 , m_built_revision(m_operator->revision())
52 , m_needs_cluster_id(m_operator->needs_cluster_id())
87 auto vk_buf = std::dynamic_pointer_cast<VKBuffer>(buffer);
90 "VertexFieldProcessor requires a VKBuffer");
101 m_epoch = std::chrono::steady_clock::now();
104 "VertexFieldProcessor attached: {} bytes, stride {} words, {} bound fields",
105 vk_buf->get_size_bytes(),
112 return std::chrono::duration<float>(
113 std::chrono::steady_clock::now() -
m_epoch)
118 const std::shared_ptr<VKBuffer>& buffer)
const
121 if (stride_bytes == 0)
124 return static_cast<uint32_t
>(buffer->get_size_bytes() / stride_bytes);
133 if (!spec.has_value()) {
135 "VertexFieldProcessor: operator no longer yields a spec after rebind. "
136 "Dispatch suppressed; the previous pipeline is not reused because it "
137 "no longer describes the bindings.");
159 "VertexFieldProcessor: rebuilt for revision {} ({} bound fields)",
167 const std::shared_ptr<VKBuffer>& buffer)
182 "VertexFieldProcessor: range starts at {} but the buffer holds {} "
183 "records. Dispatch suppressed.",
201 "VertexFieldProcessor dispatch: [{}, {}) of {} records, stride {} words, t={:.3f}",
213 const std::shared_ptr<VKBuffer>& )
216 const uint32_t local_x = std::max(1U, dispatch.workgroup_x);
219 return { std::max(1U, groups), 1U, 1U };
230 "VertexFieldProcessor: operator has a cluster-scoped binding but the "
231 "attached buffer is not a NetworkGeometryBuffer, so hash_cluster_id "
232 "has nowhere to live. Dispatch suppressed.");
238 "VertexFieldProcessor: operator has a cluster-scoped binding but "
239 "hash_cluster_id could not be derived (no primary GraphicsOperator, "
240 "or it reports zero points). Dispatch suppressed.");
257 foundry.update_descriptor_buffer(
259 vk::DescriptorType::eStorageBuffer, handle, 0, bytes);
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_RT_ERROR(comp, ctx,...)
#define MF_RT_TRACE(comp, ctx,...)
virtual void on_attach(const std::shared_ptr< Buffer > &)
Called when this processor is attached to a buffer.
ProcessingToken m_processing_token
const ShaderDispatchConfig & get_dispatch_config() const
Get current dispatch configuration.
Specialized ShaderProcessor for Compute Pipelines.
void set_push_constant_data(const T &data)
Update push constant data (type-safe)
void add_binding(const std::string &descriptor_name, const ShaderBinding &binding)
Add descriptor binding configuration.
void set_config(const ShaderConfig &config)
Update entire configuration.
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
bool ensure_cluster_binding()
Ensure the backing hash_cluster_id state field exists, when m_needs_cluster_id is true.
bool on_before_execute(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer) override
Rebuild on a stale revision, resolve the range, write push constants.
std::chrono::steady_clock::time_point m_epoch
std::shared_ptr< NetworkGeometryBuffer > m_network_buffer
uint32_t m_explicit_count
std::array< uint32_t, 3 > calculate_dispatch_size(const std::shared_ptr< VKBuffer > &buffer) override
One thread per record in the resolved range.
void clear_vertex_range()
Drop an explicit range and cover the whole buffer again.
uint32_t buffer_capacity(const std::shared_ptr< VKBuffer > &buffer) const
Records the buffer can hold at the operator's stride.
uint32_t m_explicit_first
std::shared_ptr< Nodes::Network::GpuFieldOperator > m_operator
void set_vertex_range(uint32_t first_vertex, uint32_t vertex_count)
Restrict the dispatch to a slice of the buffer.
bool sync_revision()
Recompile and rebuild the pipeline when the operator has changed.
void on_descriptors_created() override
Write the cluster_id descriptor when the operator needs one.
void on_attach(const std::shared_ptr< Buffer > &buffer) override
Called when this processor is attached to a buffer.
uint64_t m_built_revision
VertexFieldProcessor(std::shared_ptr< Nodes::Network::GpuFieldOperator > field_operator)
float elapsed() const
Seconds since construction, the value bound to the time parameter.
@ GRAPHICS_BACKEND
Standard graphics processing backend configuration.
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.
@ STORAGE
Large arrays or buffers the shader may write (SSBO)
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
Describes how a VKBuffer binds to a shader descriptor.