MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ShaderSpecBinding.hpp
Go to the documentation of this file.
1#pragma once
2
6
7namespace MayaFlux::Yantra {
8
9/**
10 * @brief Translate a BindingDirection to a GpuBufferBinding::Direction.
11 */
24
25/**
26 * @brief Translate a BindingSlot modality to a GpuBufferBinding::ElementType.
27 */
50
51/**
52 * @brief Derive a GpuBufferBinding list from a ShaderSpec.
53 *
54 * Translates ShaderSpec binding declarations to the GpuBufferBinding
55 * vocabulary understood by GpuResourceManager and any GpuExecutionContext
56 * subclass. The result is suitable for passing to declare_buffer_bindings()
57 * overrides or directly to GpuResourceManager::initialise().
58 */
59[[nodiscard]] inline std::vector<GpuBufferBinding> bindings_from_spec(
61{
62 std::vector<GpuBufferBinding> out;
63 out.reserve(spec.bindings.size());
64 for (const auto& b : spec.bindings) {
65 out.push_back({
66 .set = b.set,
67 .binding = b.binding_index,
68 .direction = to_binding_direction(b.direction),
69 .element_type = to_element_type(b.modality, b.format),
70 });
71 }
72 return out;
73}
74
75/**
76 * @brief Derive a GpuComputeConfig from a ShaderSpec.
77 *
78 * Compiles (or retrieves cached) the shader via ShaderFoundry and
79 * packages the result with workgroup size and push constant size.
80 * Returns a config with INVALID_SHADER on compilation failure.
81 *
82 * Callers use this alongside bindings_from_spec() to configure any
83 * concrete GpuExecutionContext subclass without depending on a specific
84 * executor type.
85 *
86 * @code
87 * auto spec = ShaderSpec::Assemble{}
88 * .ssbo("sig", BindingDirection::InOut, Kakshya::GpuDataFormat::FLOAT32)
89 * .pc("gain")
90 * .op(KernelOp::Scale)
91 * .build();
92 *
93 * auto cfg = config_from_spec(spec);
94 * auto bindings = bindings_from_spec(spec);
95 *
96 * auto exec = std::make_shared<ShaderExecutionContext<>>(cfg, bindings);
97 * my_op->set_gpu_backend(exec);
98 * @endcode
99 */
102{
103 return GpuComputeConfig {
105 .push_constant_size = spec.push_constant_bytes,
107 };
108}
109
110} // namespace MayaFlux::Yantra
size_t b
ShaderID load_shader(const std::string &content, std::optional< ShaderStage > stage=std::nullopt, const std::string &entry_point="main")
Universal shader loader - auto-detects source type.
DataModality
Data modality types for cross-modal analysis.
Definition NDData.hpp:164
@ IMAGE_2D
2D image (grayscale or single channel)
GpuDataFormat
GPU data formats with explicit precision levels.
Definition NDData.hpp:25
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
BindingDirection
Data flow direction for a shader binding slot.
GpuBufferBinding::Direction to_binding_direction(Portal::Graphics::BindingDirection d) noexcept
Translate a BindingDirection to a GpuBufferBinding::Direction.
GpuComputeConfig config_from_spec(const Portal::Graphics::ShaderSpec &spec)
Derive a GpuComputeConfig from a ShaderSpec.
std::vector< GpuBufferBinding > bindings_from_spec(const Portal::Graphics::ShaderSpec &spec)
Derive a GpuBufferBinding list from a ShaderSpec.
GpuBufferBinding::ElementType to_element_type(Kakshya::DataModality m, Kakshya::GpuDataFormat fmt) noexcept
Translate a BindingSlot modality to a GpuBufferBinding::ElementType.
ElementType
Element type the shader expects in this binding.
Direction
Data flow direction for this binding.
enum MayaFlux::Portal::Graphics::GpuBufferBinding::Direction INPUT
enum MayaFlux::Portal::Graphics::GpuBufferBinding::ElementType FLOAT32
Plain-data description of the compute shader to dispatch.
std::vector< BindingSlot > bindings
std::array< uint32_t, 3 > workgroup_size
Complete declarative description of a generated compute shader.