usecrate::{proc::Layouter, FastHashMap, FastHashSet, Handle, Module, ShaderStage, Span, Type}; use ast::{EntryArg, FunctionDeclaration, GlobalLookup}; use parser::ParsingContext;
mod ast; mod builtins; mod context; mod error; mod functions; mod lex; mod offset; mod parser; #[cfg(test)] mod parser_tests; mod token; mod types; mod variables;
type Result<T> = std::result::Result<T, Error>;
/// Per-shader options passed to [`parse`](Frontend::parse). /// /// The [`From`] trait is implemented for [`ShaderStage`] to provide a quick way /// to create an `Options` instance. /// /// ```rust /// # use naga::ShaderStage; /// # use naga::front::glsl::Options; /// Options::from(ShaderStage::Vertex); /// ``` #[derive(Debug)] pubstruct Options { /// The shader stage in the pipeline. pub stage: ShaderStage, /// Preprocessor definitions to be used, akin to having /// ```glsl /// #define key value /// ``` /// for each key value pair in the map. pub defines: FastHashMap<String, String>,
}
/// Additional information about the GLSL shader. /// /// Stores additional information about the GLSL shader which might not be /// stored in the shader [`Module`]. #[derive(Debug)] pubstruct ShaderMetadata { /// The GLSL version specified in the shader through the use of the /// `#version` preprocessor directive. pub version: u16, /// The GLSL profile specified in the shader through the use of the /// `#version` preprocessor directive. pub profile: Profile, /// The shader stage in the pipeline, passed to the [`parse`](Frontend::parse) /// method via the [`Options`] struct. pub stage: ShaderStage,
/// The workgroup size for compute shaders, defaults to `[1; 3]` for /// compute shaders and `[0; 3]` for non compute shaders. pub workgroup_size: [u32; 3], /// Whether or not early fragment tests where requested by the shader. /// Defaults to `false`. pub early_fragment_tests: bool,
/// The shader can request extensions via the /// `#extension` preprocessor directive, in the directive a behavior /// parameter is used to control whether the extension should be disabled, /// warn on usage, enabled if possible or required. /// /// This field only stores extensions which were required or requested to /// be enabled if possible and they are supported. pub extensions: FastHashSet<String>,
}
/// The `Frontend` is the central structure of the GLSL frontend. /// /// To instantiate a new `Frontend` the [`Default`] trait is used, so a /// call to the associated function [`Frontend::default`](Frontend::default) will /// return a new `Frontend` instance. /// /// To parse a shader simply call the [`parse`](Frontend::parse) method with a /// [`Options`] struct and a [`&str`](str) holding the glsl code. /// /// The `Frontend` also provides the [`metadata`](Frontend::metadata) to get some /// further information about the previously parsed shader, like version and /// extensions used (see the documentation for /// [`ShaderMetadata`] to see all the returned information) /// /// # Example usage /// ```rust /// use naga::ShaderStage; /// use naga::front::glsl::{Frontend, Options}; /// /// let glsl = r#" /// #version 450 core /// /// void main() {} /// "#; /// /// let mut frontend = Frontend::default(); /// let options = Options::from(ShaderStage::Vertex); /// frontend.parse(&options, glsl); /// ``` /// /// # Reusability /// /// If there's a need to parse more than one shader reusing the same `Frontend` /// instance may be beneficial since internal allocations will be reused. /// /// Calling the [`parse`](Frontend::parse) method multiple times will reset the /// `Frontend` so no extra care is needed when reusing. #[derive(Debug, Default)] pubstruct Frontend {
meta: ShaderMetadata,
/// Parses a shader either outputting a shader [`Module`] or a list of /// [`Error`]s. /// /// Multiple calls using the same `Frontend` and different shaders are supported. pubfn parse(
&mutself,
options: &Options,
source: &str,
) -> std::result::Result<Module, ParseErrors> { self.reset(options.stage);
let lexer = lex::Lexer::new(source, &options.defines); letmut ctx = ParsingContext::new(lexer);
/// Returns additional information about the parsed shader which might not /// be stored in the [`Module`], see the documentation for /// [`ShaderMetadata`] for more information about the returned data. /// /// # Notes /// /// Following an unsuccessful parsing the state of the returned information /// is undefined, it might contain only partial information about the /// current shader, the previous shader or both. pubconstfn metadata(&self) -> &ShaderMetadata {
&self.meta
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet am 2026-06-18)
¤
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.