//! SPIR-V transpiler. //! //! The current implementation uses the [shaderc](https://crates.io/crates/shaderc) crate to //! transpile GLSL to SPIR-V. This is not ideal but will provide a default and starting //! implementation.
use shaderc;
usecrate::syntax; usecrate::transpiler::glsl as glsl_transpiler;
/// Transpile a GLSL AST into a SPIR-V internal buffer and write it to the given buffer. /// /// The current implementation is highly inefficient as it relies on internal allocations and /// [shaderc](https://crates.io/crates/shaderc). /// /// If any error happens while transpiling, they’re returned as an opaque string. pubfn transpile_translation_unit_to_binary<F>(
f: &mut F,
tu: &syntax::TranslationUnit,
kind: ShaderKind,
) -> Result<(), String> where
F: std::io::Write,
{ // write as GLSL in an intermediate buffer letmut glsl_buffer = String::new();
glsl_transpiler::show_translation_unit(&mut glsl_buffer, tu);
// pass the GLSL-formatted string to shaderc letmut compiler = shaderc::Compiler::new().unwrap(); let options = shaderc::CompileOptions::new().unwrap(); let kind = kind.into(); let output = compiler
.compile_into_spirv(&glsl_buffer, kind, "glsl input", "main", Some(&options))
.map_err(|e| format!("{}", e))?;
let _ = f.write_all(output.as_binary_u8());
Ok(())
}
/// Transpile a GLSL AST into a SPIR-V internal buffer and write it to the given buffer. /// /// The current implementation is highly inefficient as it relies on internal allocations and /// [shaderc](https://crates.io/crates/shaderc). /// /// If any error happens while transpiling, they’re returned as an opaque string. pubfn transpile_translation_unit<F>(
f: &mut F,
tu: &syntax::TranslationUnit,
kind: ShaderKind,
) -> Result<(), String> where
F: std::fmt::Write,
{ // write as GLSL in an intermediate buffer letmut glsl_buffer = String::new();
glsl_transpiler::show_translation_unit(&mut glsl_buffer, tu);
// pass the GLSL-formatted string to shaderc letmut compiler = shaderc::Compiler::new().unwrap(); let options = shaderc::CompileOptions::new().unwrap(); let kind = kind.into(); let output = compiler
.compile_into_spirv_assembly(&glsl_buffer, kind, "glsl input", "main", Some(&options))
.map_err(|e| format!("{}", e))?;
let _ = f.write_str(&output.as_text());
Ok(())
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.19 Sekunden
(vorverarbeitet am 2026-06-19)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.