MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ emit_glsl_kernel()

std::string MayaFlux::Portal::Graphics::detail::emit_glsl_kernel ( const ShaderSpec spec)

Emit a complete GLSL compute shader from spec metadata and a KernelSource body.

Binding names are used directly as GLSL identifiers. The body text from KernelSource::parse() is injected verbatim inside main() after uint i and optional ivec2 coord are declared. Push constant fields are accessible as pc.<name>. SSBO arrays are accessible as <name>[i].

Definition at line 1428 of file AsmGenerator.cpp.

1429{
1430 const auto& ws = spec.workgroup_size;
1431 const auto& ks = *spec.kernel;
1432
1433 bool has_image = false;
1434 for (const auto& b : spec.bindings) {
1435 if (b.modality == Kakshya::DataModality::IMAGE_2D)
1436 has_image = true;
1437 }
1438
1439 std::string o;
1440 o += "#version 460\n";
1441 o += "layout(local_size_x = " + std::to_string(ws[0])
1442 + ", local_size_y = " + std::to_string(ws[1])
1443 + ", local_size_z = " + std::to_string(ws[2]) + ") in;\n\n";
1444
1445 for (const auto& b : spec.bindings) {
1446 if (b.modality == Kakshya::DataModality::IMAGE_2D) {
1447 const std::string qual = (b.direction == BindingDirection::Input)
1448 ? "readonly"
1449 : "writeonly";
1450 o += "layout(set = 0, binding = " + std::to_string(b.binding_index)
1451 + ", rgba32f) " + qual + " uniform image2D " + b.name + ";\n";
1452 continue;
1453 }
1454 if (b.modality == Kakshya::DataModality::TEXTURE_2D) {
1455 o += "layout(set = 0, binding = " + std::to_string(b.binding_index)
1456 + ") uniform sampler2D " + b.name + ";\n";
1457 continue;
1458 }
1459 const auto t = std::string(glsl_type(b.format));
1460 o += "layout(set = 0, binding = " + std::to_string(b.binding_index)
1461 + ", std430) buffer Block_" + b.name
1462 + " { " + t + " " + b.name + "[]; };\n";
1463 }
1464
1465 if (!spec.pc_fields.empty()) {
1466 o += "\nlayout(push_constant) uniform PC {\n";
1467 for (const auto& f : spec.pc_fields)
1468 o += " " + std::string(glsl_type(f.format)) + " " + f.name + ";\n";
1469 o += "} pc;\n";
1470 }
1471
1472 o += "\nvoid main() {\n";
1473 o += " uint i = gl_GlobalInvocationID.x;\n";
1474 if (has_image)
1475 o += " ivec2 coord = ivec2(gl_GlobalInvocationID.xy);\n";
1476
1477 for (const auto& f : spec.pc_fields) {
1478 const auto t = std::string(glsl_type(f.format));
1479 o += " " + t + " " + f.name + " = pc." + f.name + ";\n";
1480 }
1481
1482 o += ks.body;
1483 o += "\n}\n";
1484 return o;
1485}
size_t b
std::vector< PushConstantField > pc_fields
std::array< uint32_t, 3 > workgroup_size
std::optional< KernelSource > kernel
When set, KernelOp is ignored.

References b, MayaFlux::Portal::Graphics::ShaderSpec::bindings, MayaFlux::Kakshya::IMAGE_2D, MayaFlux::Portal::Graphics::Input, MayaFlux::Portal::Graphics::ShaderSpec::kernel, MayaFlux::Portal::Graphics::ShaderSpec::pc_fields, MayaFlux::Kakshya::TEXTURE_2D, and MayaFlux::Portal::Graphics::ShaderSpec::workgroup_size.

Referenced by MayaFlux::Portal::Graphics::ShaderFoundry::load_shader().

+ Here is the caller graph for this function: