moon_wgsl

    WGSL preprocess and composer utilities extracted from mgstudio.

    wgsl
    shader
    Download zip
    Author
    Version
    0.1.4
    License
    Apache-2.0
    Last updated
    6 months ago
    Downloads
    822

    #moon_wgsl

    Milky2018/moon_wgsl is a MoonBit library for WGSL preprocessing, import analysis, and shader composition.

    This package was extracted from mgstudio and keeps the former naga_oil surface at the root package so downstream code can continue to use the same high-level concepts. After adding the dependency, reference the package through @moon_wgsl:

    ///|
    test "README: root package surface" {
    let value_defines = @moon_wgsl.default_wgsl_value_defines()
    debug_inspect(value_defines.length() > 0, content="true")
    }

    #What This Library Provides

    moon_wgsl focuses on three related tasks:

    • Parse shader metadata such as #define_import_path, #define, used imports, and top-level WGSL directives.
    • Preprocess shader source with conditional compilation and shader-definition substitution.
    • Compose WGSL modules by resolving #import directives from a registered in-memory source registry.

    The library is intended for projects that want naga_oil-style shader module composition in MoonBit without introducing a separate CLI step.

    #Highlights

    • Supports #ifdef, #ifndef, #if, #else if, #else, and #endif.
    • Supports shader definition values of type Bool, Int, and UInt.
    • Parses grouped imports such as #import bevy_render::{view::View, maths::{PI_2, powsafe}}.
    • Supports import aliases such as #import bevy_render::maths as maths.
    • Supports quoted file-path imports such as #import "../shared/common.wgsl" SharedVertex, build_color.
    • Supports bulk source registration with register_wgsl_source_files.
    • Supports source-tree scanning and registration through moonbitlang/x/fs.
    • Supports preflight registry diagnostics with analyze_wgsl_source_files_for_registry and register_wgsl_source_files_checked.
    • Preserves and re-emits WGSL enable, requires, and diagnostic(...) directives.
    • Tracks only actually used imported items when extracting metadata.
    • Resolves composable modules from registered WGSL source strings.
    • Exports single-file WGSL with declaration-level tree-shaking, an explicit source catalog, source-map entries, and diagnostics.
    • Supports token-based source-level symbol redirects during composition and export.

    #Core Concepts

    #1. Metadata Extraction

    Use get_preprocessor_metadata or get_preprocessor_data when you want to inspect a shader without fully composing it.

    Metadata includes:

    • Optional module name from #define_import_path
    • Imported module/item pairs that are actually used
    • Module-local shader definitions declared with #define
    • Effective definition names referenced by conditional blocks or #NAME substitutions
    • Top-level WGSL directives

    Example:

    ///|
    test "README: metadata extraction" {
    let metadata : @moon_wgsl.PreprocessorMetaData = @moon_wgsl.get_preprocessor_metadata(
    "#define_import_path bevy_ui::ui_node\n#define HDR\n#define TONEMAP_MODE 2u\n#import bevy_render::{view::View, globals::Globals}\n#import bevy_render::maths as maths\nfn main(view: View, globals: Globals) -> f32 {\n return maths::tone_map(1.0);\n}\n",
    )

    debug_inspect(metadata.name, content="Some(\"bevy_ui::ui_node\")")
    debug_inspect(metadata.imports.length(), content="3")
    debug_inspect(metadata.wgsl_directives.is_empty(), content="true")
    }

    #2. Preprocessing a Single Shader

    Use Preprocessor::preprocess to evaluate conditional blocks, strip import declarations from the output, and substitute shader-definition values.

    ///|
    test "README: preprocess single shader" {
    let defs : @hashmap.HashMap[String, @moon_wgsl.ShaderDefValue] = @hashmap.HashMap::new()
    defs.set("TEXTURE", @moon_wgsl.ShaderDefValue::Bool(true))

    let source = "#ifdef TEXTURE\nvar sprite_texture: texture_2d<f32>;\n#else\nvar sprite_texture: texture_2d_array<f32>;\n#endif\n"

    let output : @moon_wgsl.PreprocessOutput = @moon_wgsl.Preprocessor::default().preprocess(
    source, defs,
    ) catch {
    _ => abort("preprocess failed")
    }

    debug_inspect(
    output.preprocessed_source.contains("texture_2d<f32>"),
    content="true",
    )
    debug_inspect(output.imports.length(), content="0")
    }

    #3. Composing Registered WGSL Modules

    Composer expands #import directives recursively, resolves aliases, and merges imported definitions into a final WGSL string.

    The recommended path is to register shaders on the Composer instance itself. Global registry helpers still exist for compatibility, but new code should prefer Composer-owned registry state. Composer::default() starts empty; use Composer::from_registered_wgsl_source_registry() only when you explicitly want a snapshot of the global compatibility registry.

    ///|
    test "README: compose registered modules" {
    let composer : @moon_wgsl.Composer = @moon_wgsl.Composer::default()
    let defines : @hashmap.HashMap[String, Bool] = @hashmap.HashMap::new()
    let redirects : Array[@moon_wgsl.WgslSymbolRedirect] = []
    composer.clear_registered_wgsl_source_registry()

    composer.register_wgsl_source(
    "render/maths.wgsl", "#define_import_path bevy_render::maths\nconst PI_2: f32 = 6.28318;\n",
    )

    composer.register_wgsl_source(
    "sprite_render/mesh2d/mesh2d_functions.wgsl", "#define_import_path bevy_sprite::mesh2d_functions\n#import bevy_render::maths::PI_2\nfn twice_pi() -> f32 {\n return PI_2;\n}\n",
    )

    composer.register_wgsl_source(
    "sprite_render/mesh2d/mesh2d.wgsl", "#import bevy_sprite::mesh2d_functions as mesh_functions\nfn demo() -> f32 {\n return mesh_functions::twice_pi();\n}\n",
    )

    let compose_options : @moon_wgsl.WgslComposeOptions = {
    assets_base: "",
    defines,
    value_defines: @moon_wgsl.default_wgsl_value_defines(),
    redirects,
    }
    let composed : String = composer.compose_wgsl(
    "sprite_render/mesh2d/mesh2d.wgsl", compose_options,
    ) catch {
    _ => abort("compose failed")
    }

    debug_inspect(composed.contains("fn demo"), content="true")
    debug_inspect(composed.contains("mesh_functions::"), content="false")
    }

    #4. Bulk Registry and Relative File Imports

    You can register a batch of shader files at once and use relative quoted paths between them. Composer instances expose the same registry APIs as the global compatibility helpers.

    ///|
    test "README: bulk registry and relative imports" {
    let composer : @moon_wgsl.Composer = @moon_wgsl.Composer::default()
    let defines : @hashmap.HashMap[String, Bool] = @hashmap.HashMap::new()
    let redirects : Array[@moon_wgsl.WgslSymbolRedirect] = []
    let files : Array[@moon_wgsl.WgslSourceFile] = [
    {
    rel_path: "shaders/shared/common.wgsl",
    source: "struct SharedValue {\n tint: vec4<f32>,\n}\n",
    },
    {
    rel_path: "shaders/effects/main.wgsl",
    source: "#import \"../shared/common.wgsl\" SharedValue\nfn shade(value: SharedValue) -> vec4<f32> {\n return value.tint;\n}\n",
    },
    ]

    composer.clear_registered_wgsl_source_registry()
    composer.register_wgsl_source_files(files)

    debug_inspect(
    composer.registered_wgsl_source("shaders/effects/main.wgsl") is Some(_),
    content="true",
    )
    let compose_options : @moon_wgsl.WgslComposeOptions = {
    assets_base: "",
    defines,
    value_defines: @moon_wgsl.default_wgsl_value_defines(),
    redirects,
    }
    let composed : String = composer.compose_wgsl(
    "shaders/effects/main.wgsl", compose_options,
    ) catch {
    _ => abort("compose failed")
    }
    debug_inspect(composed.contains("struct SharedValue"), content="true")
    }

    If you want collision diagnostics before mutating the registry, use the checked path:

    ///|
    test "README: checked bulk registry" {
    let files : Array[@moon_wgsl.WgslSourceFile] = [
    {
    rel_path: "shaders/demo/a.wgsl",
    source: "#define_import_path demo::dup\nfn a() -> f32 { return 1.0; }\n",
    },
    {
    rel_path: "shaders/demo/b.wgsl",
    source: "#define_import_path demo::dup\nfn b() -> f32 { return 2.0; }\n",
    },
    ]

    @moon_wgsl.clear_registered_wgsl_source_registry()
    let diagnostics : Array[@moon_wgsl.WgslDiagnostic] = @moon_wgsl.analyze_wgsl_source_files_for_registry(
    files,
    )
    debug_inspect(diagnostics.length(), content="1")

    let checked_diagnostics : Array[@moon_wgsl.WgslDiagnostic] = @moon_wgsl.register_wgsl_source_files_checked(
    files,
    )
    debug_inspect(checked_diagnostics.length(), content="1")
    }

    #5. Scanning a WGSL Source Tree

    If your shaders already live on disk, use scan_wgsl_source_files or the Composer convenience helpers built on top of moonbitlang/x/fs.

    Scanned rel_path values are relative to the scan root, so scanning assets/shaders yields registry keys such as effects/main.wgsl.

    ///|
    test "README: scan source tree" {
    let composer : @moon_wgsl.Composer = @moon_wgsl.Composer::default()
    let defines : @hashmap.HashMap[String, Bool] = @hashmap.HashMap::new()
    let redirects : Array[@moon_wgsl.WgslSymbolRedirect] = []
    let scan_options : @moon_wgsl.WgslSourceScanOptions = {
    recursive: true,
    extensions: [".wgsl"],
    exclude_prefixes: ["ignored"],
    }

    composer.clear_registered_wgsl_source_registry()
    composer.register_wgsl_source_tree("testdata/wgsl_scan", scan_options) catch {
    _ => abort("failed to scan WGSL shader tree")
    }

    let compose_options : @moon_wgsl.WgslComposeOptions = {
    assets_base: "",
    defines,
    value_defines: @moon_wgsl.default_wgsl_value_defines(),
    redirects,
    }
    let composed : String = composer.compose_wgsl(
    "effects/main.wgsl", compose_options,
    ) catch {
    _ => abort("compose failed")
    }

    debug_inspect(composed.contains("fn shade"), content="true")
    }

    If you want to preflight a tree before registration, use the checked scan path:

    ///|
    test "README: checked tree scan" {
    let (files, diagnostics) = @moon_wgsl.scan_wgsl_source_files_checked(
    "testdata/wgsl_scan_dups",
    @moon_wgsl.WgslSourceScanOptions::default(),
    ) catch {
    _ => abort("failed to scan WGSL shader tree")
    }

    debug_inspect(files.length(), content="2")
    debug_inspect(diagnostics.length(), content="1")
    }

    #6. Exporting a Single WGSL File

    Use Composer::export_wgsl_with_options to produce a fully expanded single-file WGSL output. The export path also supports declaration-level tree-shaking and returns source-map entries, the dependency-closure source catalog used for matching, plus diagnostics.

    ///|
    test "README: export single WGSL file" {
    let composer : @moon_wgsl.Composer = @moon_wgsl.Composer::default()
    let defines : @hashmap.HashMap[String, Bool] = @hashmap.HashMap::new()
    let redirects : Array[@moon_wgsl.WgslSymbolRedirect] = []
    let files : Array[@moon_wgsl.WgslSourceFile] = [
    {
    rel_path: "shaders/shared/common.wgsl",
    source: "struct SharedParams {\n tint: vec4<f32>,\n}\nstruct SharedVertex {\n params: SharedParams,\n}\nfn build_color(vertex: SharedVertex) -> vec4<f32> {\n return vertex.params.tint;\n}\n",
    },
    {
    rel_path: "shaders/effects/main.wgsl",
    source: "#import \"../shared/common.wgsl\" SharedVertex, build_color\nfn shade(vertex: SharedVertex) -> vec4<f32> {\n return build_color(vertex);\n}\n",
    },
    ]

    composer.clear_registered_wgsl_source_registry()
    composer.register_wgsl_source_files(files)

    let compose_options : @moon_wgsl.WgslComposeOptions = {
    assets_base: "",
    defines,
    value_defines: @moon_wgsl.default_wgsl_value_defines(),
    redirects,
    }
    let export_options : @moon_wgsl.WgslExportOptions = { root_items: ["shade"] }
    let exported : @moon_wgsl.WgslExportOutput = composer.export_wgsl_with_options(
    "shaders/effects/main.wgsl", compose_options, export_options,
    ) catch {
    _ => abort("export failed")
    }

    debug_inspect(exported.source.contains("#import"), content="false")
    debug_inspect(exported.source_catalog.length() > 0, content="true")
    debug_inspect(exported.source_map.length() > 0, content="true")
    debug_inspect(exported.diagnostics.length(), content="0")
    }

    If you need the declaration catalog directly, without exporting a specific entrypoint, use Composer::build_wgsl_source_catalog on the same Composer:

    ///|
    test "README: build source catalog" {
    let composer : @moon_wgsl.Composer = @moon_wgsl.Composer::default()
    let defines : @hashmap.HashMap[String, Bool] = @hashmap.HashMap::new()
    let redirects : Array[@moon_wgsl.WgslSymbolRedirect] = []
    let files : Array[@moon_wgsl.WgslSourceFile] = [
    {
    rel_path: "shaders/shared/common.wgsl",
    source: "struct SharedParams {\n tint: vec4<f32>,\n}\nstruct SharedVertex {\n params: SharedParams,\n}\nfn build_color(vertex: SharedVertex) -> vec4<f32> {\n return vertex.params.tint;\n}\n",
    },
    {
    rel_path: "shaders/effects/main.wgsl",
    source: "#import \"../shared/common.wgsl\" SharedVertex, build_color\nfn shade(vertex: SharedVertex) -> vec4<f32> {\n return build_color(vertex);\n}\n",
    },
    ]

    composer.clear_registered_wgsl_source_registry()
    composer.register_wgsl_source_files(files)

    let compose_options : @moon_wgsl.WgslComposeOptions = {
    assets_base: "",
    defines,
    value_defines: @moon_wgsl.default_wgsl_value_defines(),
    redirects,
    }
    let catalog : Array[@moon_wgsl.WgslSourceCatalogEntry] = composer.build_wgsl_source_catalog(
    compose_options,
    )
    debug_inspect(catalog.length() > 0, content="true")
    }

    The top-level build_registered_wgsl_source_catalog helper is still available when you intentionally want to inspect the global compatibility registry.

    #7. Applying Source-Level Redirects

    Use the redirect-aware APIs when you want to remap one imported symbol to another during composition/export without depending on Naga IR.

    ///|
    test "README: source-level redirects" {
    let composer : @moon_wgsl.Composer = @moon_wgsl.Composer::default()
    let defines : @hashmap.HashMap[String, Bool] = @hashmap.HashMap::new()
    let redirects : Array[@moon_wgsl.WgslSymbolRedirect] = [
    { from_name: "build_shadow", to_name: "build_color" },
    ]
    let files : Array[@moon_wgsl.WgslSourceFile] = [
    {
    rel_path: "shaders/shared/common.wgsl",
    source: "struct SharedParams {\n tint: vec4<f32>,\n}\nstruct SharedVertex {\n params: SharedParams,\n}\nfn build_color(vertex: SharedVertex) -> vec4<f32> {\n return vertex.params.tint;\n}\nfn build_shadow(vertex: SharedVertex) -> vec4<f32> {\n return vec4<f32>(0.0, 0.0, 0.0, 1.0);\n}\n",
    },
    {
    rel_path: "shaders/effects/redirect.wgsl",
    source: "#import \"../shared/common.wgsl\" SharedVertex, build_color, build_shadow\nfn shade(vertex: SharedVertex) -> vec4<f32> {\n return build_shadow(vertex);\n}\n",
    },
    ]

    composer.clear_registered_wgsl_source_registry()
    composer.register_wgsl_source_files(files)

    let compose_options : @moon_wgsl.WgslComposeOptions = {
    assets_base: "",
    defines,
    value_defines: @moon_wgsl.default_wgsl_value_defines(),
    redirects,
    }
    let export_options : @moon_wgsl.WgslExportOptions = { root_items: ["shade"] }
    let exported : @moon_wgsl.WgslExportOutput = composer.export_wgsl_with_options(
    "shaders/effects/redirect.wgsl", compose_options, export_options,
    ) catch {
    _ => abort("redirect export failed")
    }

    debug_inspect(exported.source.contains("build_shadow"), content="false")
    debug_inspect(exported.source.contains("build_color"), content="true")
    }

    Global compatibility helpers are still available when you intentionally want to inspect the package-level registry:

    ///|
    test "README: global catalog helper" {
    let defines : @hashmap.HashMap[String, Bool] = @hashmap.HashMap::new()

    @moon_wgsl.clear_registered_wgsl_source_registry()
    @moon_wgsl.register_wgsl_source(
    "shaders/demo/catalog.wgsl", "#define_import_path demo::catalog\nfn catalog_value() -> f32 {\n return 1.0;\n}\n",
    )

    let catalog : Array[@moon_wgsl.WgslSourceCatalogEntry] = @moon_wgsl.build_registered_wgsl_source_catalog(
    defines,
    @moon_wgsl.default_wgsl_value_defines(),
    )
    debug_inspect(catalog.length() > 0, content="true")
    }

    #Import Syntax Supported

    The parser supports several common import forms:

    #import bevy_render::view::View #import bevy_render::maths as maths #import bevy_render::{view::View, globals::Globals} #import bevy_render::{maths::{PI_2, powsafe}} #import "shaders/skills/shared.wgsl" Vertex, VertexOutput #import "../shared/common.wgsl" SharedVertex, build_color

    #Public API Overview

    Main public entry points:

    • Preprocessor Parses and preprocesses a single shader source string.
    • Composer Owns a WGSL registry and recursively composes registered shader modules.
    • get_preprocessor_metadata Returns a rich metadata object for a shader source string.
    • get_preprocessor_data Returns the simplified (name, imports, defines) tuple.
    • register_wgsl_source / registered_wgsl_source Manage the global compatibility WGSL source registry.
    • Composer::register_wgsl_source / Composer::register_wgsl_source_files Manage a Composer-owned WGSL source registry for hermetic composition.
    • Composer::compose_wgsl Composes WGSL from Composer-owned registry state and WgslComposeOptions.
    • register_wgsl_source_files Registers a batch of WGSL source files into the global compatibility registry.
    • analyze_wgsl_source_files_for_registry Performs preflight validation for duplicate module names and rel-path ownership conflicts.
    • register_wgsl_source_files_checked Runs preflight registry diagnostics and only mutates registry state when no errors are reported.
    • build_registered_wgsl_source_catalog Returns the declaration catalog for the global compatibility registry.
    • Composer::build_wgsl_source_catalog Returns the declaration catalog for a specific Composer registry.
    • build_wgsl_import_module_paths / resolve_wgsl_import_module Build and query module-path resolution data.
    • resolve_wgsl_import_file_path Resolves relative or quoted file-path imports against a source file path.
    • rewrite_wgsl_symbol_redirects Applies token-based source-level symbol redirects to WGSL source.
    • Composer::from_registered_wgsl_source_registry Creates an explicit Composer snapshot from the global compatibility registry.
    • Composer::compose_wgsl_source Composes a raw WGSL source string using WgslComposeOptions without exposing session internals.
    • Composer::export_wgsl_with_options Produces single-file WGSL from WgslComposeOptions without exposing legacy session internals.

    Important public data structures:

    • ShaderDefValue
    • ImportDefinition
    • PreprocessOutput
    • PreprocessorMetaData
    • ComposableModuleDescriptor
    • ComposableModuleDefinition
    • WgslDirectives
    • WgslSourceFile
    • WgslComposeOptions
    • WgslSymbolRedirect
    • WgslExportOptions
    • WgslExportOutput
    • WgslSourceCatalogEntry
    • WgslSourceMapEntry
    • WgslDiagnostic

    For the full exported surface, see pkg.generated.mbti.

    #Behavior Notes

    • #define_import_path is used as the canonical module name for composition.
    • Composer now owns registry/module resolution state; new code should prefer Composer::register_wgsl_source*, Composer::compose_wgsl, Composer::compose_wgsl_source, and Composer::export_wgsl_with_options.
    • Composer::default() is hermetic and does not inherit the global registry. Use Composer::from_registered_wgsl_source_registry() only when you intentionally want a compatibility snapshot of global state.
    • Relative quoted file imports are resolved against the importing shader's registered path in the active Composer/global registry.
    • register_wgsl_source_files_checked is the safe bulk-registration path when callers need deterministic diagnostics before mutating the global registry.
    • assets_base is still present in the API for compatibility, but current source resolution is driven by the registry.
    • get_preprocessor_metadata is forgiving by design: on parse failure it returns empty/default metadata instead of raising.
    • Preprocessor::preprocess is the strict path and raises PreprocessError when parsing or conditional evaluation fails.
    • Composer::export_wgsl_with_options scopes source_catalog and source_map to the dependency closure of the current compose/export session instead of the full registry.
    • Source-level redirects are token-based and intentionally skip declaration heads, field accesses (.), and attributes (@...); they are intended for imported helper/type names rather than locally shadowed identifiers.

    #Development

    Run the test suite from the module root:

    moon test

    The repository currently includes tests for:

    • metadata extraction
    • grouped and aliased imports
    • quoted relative file imports
    • bulk registry collision diagnostics
    • source catalog exposure for ambiguous source-map diagnostics
    • WGSL directive preservation
    • conditional preprocessing semantics
    • module registration and import resolution
    • recursive composition behavior
    • source-level symbol redirects during composition/export
    • single-file WGSL export with tree-shaking and diagnostics

    #Compatibility Goal

    This package aims to preserve the practical naga_oil programming model used by existing downstream shader pipelines. The tests intentionally exercise behavior that matches upstream usage patterns from the original extraction context.

    #License

    Apache-2.0

    ComposerError

    pub(all) suberror ComposerError {
    EmptyAssetsBase(String)
    FailedToResolveImport(String)
    ImportCycle(String)
    MissingRegisteredSource(String)
    MissingStartupRegisteredSource(String)
    NoModuleName(String)
    }

    ComposerError::message

    fn ComposerError::message(self : ComposerError) -> String

    ParseImportsError

    pub(all) suberror ParseImportsError {
    Parse(String, Int)
    }

    PreprocessError

    pub(all) suberror PreprocessError {
    GlslInvalidVersion(Int)
    ElseWithoutCondition(Int)
    TooManyEndIfs(Int)
    NotEnoughEndIfs(Int)
    UnknownShaderDef(String, Int)
    UnknownShaderDefOperator(String, Int)
    InvalidShaderDefComparisonValue(String, String, String, Int)
    ImportParseError(String, Int)
    DefineInModule(Int)
    }

    SubstituteIdentifiersError

    pub(all) suberror SubstituteIdentifiersError {
    AmbiguousImport(Int)
    }

    ComposableModuleDefinition

    pub(all) struct ComposableModuleDefinition {
    name : String
    sanitized_source : String
    language : ShaderLanguage
    file_path : String
    shader_defs :
    HashMap
    [String, ShaderDefValue]
    effective_defs : Array[String]
    all_imports :
    HashSet
    [String]
    additional_imports : Array[ImportDefinition]
    }

    ComposableModuleDescriptor

    pub(all) struct ComposableModuleDescriptor {
    source : String
    file_path : String
    language : ShaderLanguage
    as_name : String?
    additional_imports : Array[ImportDefinition]
    shader_defs :
    HashMap
    [String, ShaderDefValue]
    } derive(Eq,
    Debug
    )

    ComposableModuleDescriptor::default

    Composer

    pub struct Composer {
    module_sets :
    HashMap
    [String, ComposableModuleDefinition]
    registry : WgslSourceRegistry
    composable_module_registry_paths :
    HashMap
    [String, String]
    }

    Composer::add_composable_module

    fn Composer::add_composable_module(self : Composer, desc : ComposableModuleDescriptor) -> ComposableModuleDefinition raise ComposerError

    Composer::analyze_wgsl_source_files_for_registry

    fn Composer::analyze_wgsl_source_files_for_registry(self : Composer, files : Array[WgslSourceFile]) -> Array[WgslDiagnostic]

    Composer::build_wgsl_source_catalog

    fn Composer::build_wgsl_source_catalog(self : Composer, options : WgslComposeOptions) -> Array[WgslSourceCatalogEntry]

    Composer::clear_registered_wgsl_source_registry

    fn Composer::clear_registered_wgsl_source_registry(self : Composer) -> Unit

    Composer::compose_wgsl

    fn Composer::compose_wgsl(self : Composer, rel : String, options : WgslComposeOptions) -> String raise ComposerError

    Composer::compose_wgsl_source

    fn Composer::compose_wgsl_source(self : Composer, source : String, options : WgslComposeOptions) -> String raise ComposerError

    Composer::contains_module

    fn Composer::contains_module(self : Composer, module_name : String) -> Bool

    Composer::copy_registered_wgsl_import_module_paths

    fn Composer::copy_registered_wgsl_import_module_paths(self : Composer) ->
    HashMap
    [String, String]

    Composer::copy_registered_wgsl_source_files

    fn Composer::copy_registered_wgsl_source_files(self : Composer) -> Array[WgslSourceFile]

    Composer::default

    fn Composer::default() -> Composer

    Composer::export_wgsl_from_assets_base_required

    fn Composer::export_wgsl_from_assets_base_required(self : Composer, assets_base : String, rel : String, options : WgslExportOptions) -> WgslExportOutput raise ComposerError

    Composer::export_wgsl_from_assets_base_required_with_redirects

    fn Composer::export_wgsl_from_assets_base_required_with_redirects(self : Composer, assets_base : String, rel : String, options : WgslExportOptions, redirects : Array[WgslSymbolRedirect]) -> WgslExportOutput raise ComposerError

    Composer::export_wgsl_with_options

    fn Composer::export_wgsl_with_options(self : Composer, rel : String, compose_options : WgslComposeOptions, export_options : WgslExportOptions) -> WgslExportOutput raise ComposerError

    Composer::from_registered_wgsl_source_registry

    fn Composer::from_registered_wgsl_source_registry() -> Composer

    Composer::load_wgsl_from_assets_base_required

    fn Composer::load_wgsl_from_assets_base_required(self : Composer, assets_base : String, rel : String) -> String raise ComposerError

    Composer::load_wgsl_source_required_raw

    fn Composer::load_wgsl_source_required_raw(self : Composer, _assets_base : String, rel : String) -> String raise ComposerError

    Composer::register_wgsl_source

    fn Composer::register_wgsl_source(self : Composer, rel_path : String, source : String) -> Unit

    Composer::register_wgsl_source_files

    fn Composer::register_wgsl_source_files(self : Composer, files : Array[WgslSourceFile]) -> Unit

    Composer::register_wgsl_source_files_checked

    fn Composer::register_wgsl_source_files_checked(self : Composer, files : Array[WgslSourceFile]) -> Array[WgslDiagnostic]

    Composer::register_wgsl_source_tree

    fn Composer::register_wgsl_source_tree(self : Composer, root : String, options : WgslSourceScanOptions) -> Unit raise
    IOError

    Composer::register_wgsl_source_tree_checked

    fn Composer::register_wgsl_source_tree_checked(self : Composer, root : String, options : WgslSourceScanOptions) -> Array[WgslDiagnostic] raise
    IOError

    Composer::registered_wgsl_source

    fn Composer::registered_wgsl_source(self : Composer, rel_path : String) -> String?

    Composer::remove_composable_module

    fn Composer::remove_composable_module(self : Composer, module_name : String) -> Unit

    DiagnosticDirective

    pub struct DiagnosticDirective {
    severity : String
    rule : String
    source_location : Int
    } derive(Eq,
    Debug
    )

    EnableDirective

    pub struct EnableDirective {
    extensions : Array[String]
    source_location : Int
    } derive(Eq,
    Debug
    )

    ImportDefWithOffset

    pub struct ImportDefWithOffset {
    definition : ImportDefinition
    offset : Int
    } derive(Eq,
    Debug
    )

    ImportDefinition

    pub(all) struct ImportDefinition {
    import_path : String
    items : Array[String]
    } derive(Eq,
    Debug
    )

    ImportDefinition::default

    NagaModuleDescriptor

    pub(all) struct NagaModuleDescriptor {
    source : String
    file_path : String
    shader_type : ShaderType
    shader_defs :
    HashMap
    [String, ShaderDefValue]
    additional_imports : Array[ImportDefinition]
    } derive(Eq,
    Debug
    )

    NagaModuleDescriptor::default

    PreprocessOutput

    pub struct PreprocessOutput {
    preprocessed_source : String
    imports : Array[ImportDefWithOffset]
    }

    PreprocessOutput::default

    Preprocessor

    pub struct Preprocessor {
    }

    Preprocessor::default

    fn Preprocessor::default() -> Preprocessor

    Preprocessor::extract_wgsl_directives

    fn Preprocessor::extract_wgsl_directives(_self : Preprocessor, source : String) -> (String, WgslDirectives)

    Preprocessor::preprocess

    fn Preprocessor::preprocess(_self : Preprocessor, source : String, shader_defs :
    HashMap
    [String, ShaderDefValue]) -> PreprocessOutput raise PreprocessError

    PreprocessorMetaData

    pub struct PreprocessorMetaData {
    name : String?
    imports : Array[ImportDefWithOffset]
    defines :
    HashMap
    [String, ShaderDefValue]
    effective_defs :
    HashSet
    [String]
    wgsl_directives : WgslDirectives
    cleaned_source : String
    }

    RequiresDirective

    pub struct RequiresDirective {
    extensions : Array[String]
    source_location : Int
    } derive(Eq,
    Debug
    )

    ScopeLevel

    type ScopeLevel derive(Eq)

    ShaderDefValue

    pub(all) enum ShaderDefValue {
    Bool(Bool)
    Int(Int)
    UInt(UInt)
    } derive(Eq,
    Debug
    )

    ShaderDefValue::value_as_string

    fn ShaderDefValue::value_as_string(self : ShaderDefValue) -> String

    ShaderLanguage

    pub(all) enum ShaderLanguage {
    Wgsl
    Glsl
    } derive(Eq,
    Debug
    )

    ShaderType

    pub(all) enum ShaderType {
    Wgsl
    GlslVertex
    GlslFragment
    } derive(Eq,
    Debug
    )

    WgslComposeOptions

    pub(all) struct WgslComposeOptions {
    assets_base : String
    defines :
    HashMap
    [String, Bool]
    value_defines :
    HashMap
    [String, Int]
    redirects : Array[WgslSymbolRedirect]
    } derive(Eq,
    Debug
    )

    WgslComposeOptions::default

    WgslDiagnostic

    pub struct WgslDiagnostic {
    severity : WgslDiagnosticSeverity
    message : String
    rel_path : String?
    symbol_name : String?
    generated_start : Int?
    source_start : Int?
    } derive(Eq,
    Debug
    )

    WgslDiagnostic::default

    WgslDiagnosticSeverity

    pub(all) enum WgslDiagnosticSeverity {
    Info
    Warn
    Error
    } derive(Eq,
    Debug
    )

    WgslDirectives

    pub struct WgslDirectives {
    enables : Array[EnableDirective]
    requires : Array[RequiresDirective]
    diagnostics : Array[DiagnosticDirective]
    } derive(Eq,
    Debug
    )

    WgslDirectives::default

    WgslDirectives::is_empty

    fn WgslDirectives::is_empty(self : WgslDirectives) -> Bool

    WgslDirectives::to_wgsl_string

    fn WgslDirectives::to_wgsl_string(self : WgslDirectives) -> String

    WgslExportOptions

    pub(all) struct WgslExportOptions {
    root_items : Array[String]
    } derive(Eq,
    Debug
    )

    WgslExportOptions::default

    WgslExportOutput

    pub struct WgslExportOutput {
    source : String
    source_catalog : Array[WgslSourceCatalogEntry]
    source_map : Array[WgslSourceMapEntry]
    diagnostics : Array[WgslDiagnostic]
    } derive(Eq,
    Debug
    )

    WgslExportOutput::default

    WgslImportTarget

    pub struct WgslImportTarget {
    raw_path : String
    alias_name : String
    } derive(Eq,
    Debug
    )

    WgslResolvedImportModule

    pub struct WgslResolvedImportModule {
    module_path : String
    rel_path : String
    } derive(Eq,
    Debug
    )

    WgslSourceCatalogEntry

    pub struct WgslSourceCatalogEntry {
    rel_path : String
    symbol_name : String
    source_text : String
    source_start : Int
    source_end : Int
    } derive(Eq,
    Debug
    )

    WgslSourceCatalogEntry::default

    WgslSourceFile

    pub(all) struct WgslSourceFile {
    rel_path : String
    source : String
    } derive(Eq,
    Debug
    )

    WgslSourceFile::default

    WgslSourceMapEntry

    pub struct WgslSourceMapEntry {
    generated_start : Int
    generated_end : Int
    rel_path : String
    source_start : Int
    source_end : Int
    symbol_name : String?
    } derive(Eq,
    Debug
    )

    WgslSourceMapEntry::default

    WgslSourceRegistry

    type WgslSourceRegistry

    WgslSourceScanOptions

    pub(all) struct WgslSourceScanOptions {
    recursive : Bool
    extensions : Array[String]
    exclude_prefixes : Array[String]
    } derive(Eq,
    Debug
    )

    WgslSourceScanOptions::default

    WgslSymbolRedirect

    pub(all) struct WgslSymbolRedirect {
    from_name : String
    to_name : String
    } derive(Eq,
    Debug
    )

    WgslSymbolRedirect::default

    analyze_wgsl_source_files_for_registry

    fn analyze_wgsl_source_files_for_registry(files : Array[WgslSourceFile]) -> Array[WgslDiagnostic]

    build_registered_wgsl_source_catalog

    fn build_registered_wgsl_source_catalog(defines :
    HashMap
    [String, Bool], value_defines :
    HashMap
    [String, Int]) -> Array[WgslSourceCatalogEntry]

    build_wgsl_import_module_paths

    fn build_wgsl_import_module_paths(_assets_base : String) ->
    HashMap
    [String, String]

    clear_registered_wgsl_source_registry

    fn clear_registered_wgsl_source_registry() -> Unit

    collect_wgsl_import_targets

    fn collect_wgsl_import_targets(spec : String, prefix : String, targets : Array[WgslImportTarget]) -> Unit

    copy_registered_wgsl_import_module_paths

    fn copy_registered_wgsl_import_module_paths() ->
    HashMap
    [String, String]

    copy_registered_wgsl_source_files

    fn copy_registered_wgsl_source_files() -> Array[WgslSourceFile]

    default_wgsl_value_defines

    fn default_wgsl_value_defines() ->
    HashMap
    [String, Int]

    get_preprocessor_data

    fn get_preprocessor_data(source : String) -> (String?, Array[ImportDefinition],
    HashMap
    [String, ShaderDefValue])

    get_preprocessor_metadata

    fn get_preprocessor_metadata(source : String) -> PreprocessorMetaData

    normalize_shader_rel_path

    fn normalize_shader_rel_path(rel : String) -> String

    register_wgsl_source

    fn register_wgsl_source(rel_path : String, source : String) -> Unit

    register_wgsl_source_files

    fn register_wgsl_source_files(files : Array[WgslSourceFile]) -> Unit

    register_wgsl_source_files_checked

    fn register_wgsl_source_files_checked(files : Array[WgslSourceFile]) -> Array[WgslDiagnostic]

    registered_wgsl_source

    fn registered_wgsl_source(rel_path : String) -> String?

    registered_wgsl_source_required

    fn registered_wgsl_source_required(rel_path : String) -> String raise ComposerError

    resolve_wgsl_import_file_path

    fn resolve_wgsl_import_file_path(importer_rel_path : String, import_path : String) -> String?

    resolve_wgsl_import_module

    fn resolve_wgsl_import_module(_assets_base : String, import_path : String, modules :
    HashMap
    [String, String]) -> WgslResolvedImportModule?

    resolve_wgsl_source_file_path

    fn resolve_wgsl_source_file_path(_assets_base : String, rel : String) -> String?

    rewrite_wgsl_symbol_redirects

    fn rewrite_wgsl_symbol_redirects(source : String, redirects : Array[WgslSymbolRedirect]) -> String

    scan_wgsl_source_files

    fn scan_wgsl_source_files(root : String, options : WgslSourceScanOptions) -> Array[WgslSourceFile] raise
    IOError

    scan_wgsl_source_files_checked

    fn scan_wgsl_source_files_checked(root : String, options : WgslSourceScanOptions) -> (Array[WgslSourceFile], Array[WgslDiagnostic]) raise
    IOError