154 {})
155{
158 return {};
159 }
160
161 std::string text;
162 if (shape.
lanes > 1) {
163 text += " uint window = gl_WorkGroupID.x;\n";
164 text += " uint lane = gl_LocalInvocationID.x;\n";
165 text += " uint lanes = gl_WorkGroupSize.x;\n";
166 text += " if (window >= window_count) { return; }\n";
167 text += " uint window_base = offset + window * stride;\n";
168 text += " uint result_base = window * outputs;\n";
169 } else {
170 text += " if (i >= window_count) { return; }\n";
171 text += " uint window_base = offset + i * stride;\n";
172 text += " uint result_base = i * outputs;\n";
173 }
174 text += body;
175
176 auto assemble = Portal::Graphics::ShaderSpec::Assemble {};
178 for (uint32_t input = 2; input <= shape.
inputs; ++input) {
180 }
188 for (uint32_t input = 2; input <= shape.
inputs; ++input) {
191 }
192 assemble.function("float", "sample_at", "uint window, uint k",
193 " return samples[pc.offset + window * pc.stride + k];");
194 for (uint32_t input = 2; input <= shape.
inputs; ++input) {
195 const std::string tag = std::to_string(input);
196 assemble.function("float", "sample" + tag + "_at", "uint window, uint k",
197 " return samples" + tag + "[pc.offset" + tag + " + window * pc.stride" + tag + " + k];");
198 }
199 if (shape.
lanes > 1) {
201 .function("float", "lane_reduce_sum", "float v",
203 .function("float", "lane_reduce_max", "float v",
205 .function("float", "lane_reduce_min", "float v",
207 .function("uint", "lane_first", "bool condition",
208 " uint v = condition ? gl_LocalInvocationID.x : gl_WorkGroupSize.x;\n"
210 }
211
212 return config_from_spec(assemble.kernel(Portal::Graphics::KernelSource { .body = std::move(text) })
214 .build());
215}
@ FLOAT32
32-bit float (standard GPU)
BindingDirection
Data flow direction for a shader binding slot.
std::string lane_reduction(std::string_view scratch, std::string_view type, std::string_view combine)
std::string lane_preamble(uint32_t lanes)
std::string windowed_kernel_diagnose(const WindowedKernelShape &shape)
Why a shape cannot be used, empty when it can.
GpuComputeConfig config_from_spec(const Portal::Graphics::ShaderSpec &spec)
Derive a GpuComputeConfig from a ShaderSpec.
uint32_t workgroup() const noexcept