45template <ComputeData InputType = std::vector<Kakshya::DataVariant>,
46 ComputeData OutputType = InputType>
64 std::vector<GpuBufferBinding> bindings = {},
65 std::string name =
"ShaderExecutionContext")
67 , m_bindings(
std::move(bindings))
68 , m_name(
std::move(name))
87 const uint32_t idx = next_binding_index();
88 m_bindings.push_back({ .set = 0,
90 .direction = GpuBufferBinding::Direction::INPUT,
91 .element_type = type });
92 this->set_binding_data(idx, data);
104 template <
typename T>
108 m_bindings.push_back({ .set = 0,
110 .direction = GpuBufferBinding::Direction::INPUT,
111 .element_type = type });
113 this->set_binding_data(binding, data);
124 template <
typename T>
128 const uint32_t idx = next_binding_index();
129 m_bindings.push_back({ .set = 0,
131 .direction = GpuBufferBinding::Direction::INPUT_OUTPUT,
132 .element_type = type });
134 this->set_binding_data(idx, data);
146 template <
typename T>
150 m_bindings.push_back({ .set = 0,
152 .direction = GpuBufferBinding::Direction::INPUT_OUTPUT,
153 .element_type = type });
155 this->set_binding_data(binding, data);
173 m_bindings.push_back({ .set = 0,
175 .direction = GpuBufferBinding::Direction::INPUT_OUTPUT,
176 .element_type = type });
192 const uint32_t idx = next_binding_index();
193 m_bindings.push_back({ .set = 0,
195 .direction = GpuBufferBinding::Direction::INPUT_OUTPUT,
196 .element_type = type });
210 const uint32_t idx = next_binding_index();
211 m_bindings.push_back({ .set = 0,
213 .direction = GpuBufferBinding::Direction::OUTPUT,
214 .element_type = type });
216 this->set_output_size(idx, byte_size);
230 m_bindings.push_back({ .set = 0,
232 .direction = GpuBufferBinding::Direction::OUTPUT,
233 .element_type = type });
235 this->set_output_size(binding, byte_size);
248 template <
typename T>
251 this->set_push_constants(data);
269 std::function<
void(uint32_t,
void*)> pc_updater)
271 m_multipass_count = pass_count;
272 m_multipass_updater = std::move(pc_updater);
298 template <
typename T>
300 const Datum<std::vector<Kakshya::DataVariant>>& result,
301 size_t binding_index)
303 const auto key =
"gpu_output_" + std::to_string(binding_index);
305 if (!result.metadata.contains(key)) {
306 error<std::runtime_error>(Journal::Component::Yantra, Journal::Context::Runtime,
307 std::source_location::current(),
308 "read_output: metadata key '{}' not found", key);
311 const auto& raw = safe_any_cast_or_throw<std::vector<uint8_t>>(result.metadata.at(key));
312 const size_t count = raw.size() /
sizeof(T);
313 std::vector<T> out(
count);
314 std::memcpy(out.data(), raw.data(),
count *
sizeof(T));
333 if (m_multipass_count > 0 && m_multipass_updater) {
335 chained.
mode = ExecutionMode::CHAINED;
346 uint32_t m_multipass_count { 0 };
357 if (m_bindings.empty())
359 return std::ranges::max(
360 m_bindings | std::views::transform([](
const GpuBufferBinding&
b) {
return b.binding; }))
382template <ComputeData InputType = std::vector<Kakshya::DataVariant>,
383 ComputeData OutputType = InputType>
384std::shared_ptr<ShaderExecutionContext<InputType, OutputType>>
387 std::vector<GpuBufferBinding> bindings,
388 std::string name =
"ShaderExecutionContext")
390 return std::make_shared<ShaderExecutionContext<InputType, OutputType>>(
Type-parameterised shell over GpuDispatchCore.
std::vector< GpuBufferBinding > m_bindings
static std::vector< T > read_output(const Datum< std::vector< Kakshya::DataVariant > > &result, size_t binding_index)
Read a typed output buffer from a pipeline result Datum.
std::vector< GpuBufferBinding > declare_buffer_bindings() const override
Returns the binding list declared via constructor or fluent API.
ShaderExecutionContext & in_out(uint32_t binding, const std::vector< T > &data, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
Add an INPUT_OUTPUT binding at an explicit index.
ShaderExecutionContext & push(const T &data)
Set push constants from a trivially copyable struct or value.
output_type execute(const input_type &input, const ExecutionContext &ctx) override
Injects multipass configuration into the context before dispatch when set_multipass() has been called...
ShaderExecutionContext & output(uint32_t binding, size_t byte_size, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
Add an OUTPUT binding at an explicit index.
uint32_t next_binding_index() const
Returns one past the highest binding index currently registered.
ShaderExecutionContext & input(const std::vector< T > &data, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
Add an INPUT binding, inferring the next available binding index.
ShaderExecutionContext & set_multipass(uint32_t pass_count, std::function< void(uint32_t, void *)> pc_updater)
Configure multi-pass (CHAINED) dispatch.
ShaderExecutionContext & in_out(uint32_t binding, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
Declare an INPUT_OUTPUT binding without pre-staging data.
ShaderExecutionContext(GpuShaderConfig config, std::vector< GpuBufferBinding > bindings={}, std::string name="ShaderExecutionContext")
Construct with shader config and optional pre-built binding list.
ShaderExecutionContext & in_out(GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
Declare an INPUT_OUTPUT binding at an explicit index without pre-staging data.
typename GpuExecutionContext< InputType, OutputType >::output_type output_type
ShaderExecutionContext & input(uint32_t binding, const std::vector< T > &data, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
Add an INPUT binding at an explicit index.
typename GpuExecutionContext< InputType, OutputType >::input_type input_type
std::function< void(uint32_t, void *)> m_multipass_updater
ShaderExecutionContext & in_out(const std::vector< T > &data, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
Add an INPUT_OUTPUT binding, inferring the next available binding index.
ShaderExecutionContext & output(size_t byte_size, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
Add an OUTPUT binding, inferring the next available binding index.
Concrete GpuExecutionContext for a single fixed shader with fixed bindings.
std::shared_ptr< ShaderExecutionContext< InputType, OutputType > > make_shader_executor(GpuShaderConfig config, std::vector< GpuBufferBinding > bindings, std::string name="ShaderExecutionContext")
Convenience factory for ShaderExecutionContext.
Input/Output container for computation pipeline data flow with structure preservation.
ExecutionMode mode
Execution mode controlling scheduling behavior.
std::unordered_map< std::string, std::any > execution_metadata
Arbitrary metadata parameters used by operations.
Context information controlling how a compute operation executes.
ElementType
Element type the shader expects in this buffer.
Declares a single storage buffer the shader expects.
Plain-data description of the compute shader to dispatch.