transhader/
glsl.rs

1use naga::back::glsl::{Options, PipelineOptions, Writer};
2use naga::proc::BoundsCheckPolicies;
3use naga::{Module, ShaderStage};
4
5use crate::util::validate;
6
7pub(crate) fn to_glsl(module: Module, stage: ShaderStage, entry_point: &str) -> String {
8    let mut out = String::new();
9
10    Writer::new(
11        &mut out,
12        &module,
13        &validate(&module),
14        &Options::default(), // TODO: custom options
15        &PipelineOptions {
16            shader_stage: stage,
17            entry_point: entry_point.to_string(),
18            multiview: None, // TODO: customize multiview
19        },
20        BoundsCheckPolicies::default(), // TODO: custom policies
21    )
22    .expect("Failed to generate GLSL output")
23    .write()
24    .expect("Failed to write GLSL output");
25
26    out
27}