Crates.io | wgsl-minifier |
lib.rs | wgsl-minifier |
version | 0.6.0 |
source | src |
created_at | 2023-08-01 15:04:49.101972 |
updated_at | 2024-08-15 12:09:40.739664 |
description | A command-line tool for minifying WGSL shaders. |
homepage | https://github.com/LucentFlux/wgsl-minifier |
repository | https://github.com/LucentFlux/wgsl-minifier |
max_upload_size | |
id | 931918 |
size | 27,900 |
A small tool built on top of Naga that makes WGSL shaders smaller by performing simple dead code elimination, stripping names of non-exported functions and local variables, and removing as much whitespace as possible.
To minify your WGSL shader, simply run the following:
cargo install wgsl-minifier
wgsl-minifier path/to/your/shader.wgsl path/to/minified/output.wgsl
To use this crate as a library, for example in a game engine or larger preprocessor, two calls must be made. The first strips identifiers to smaller ones where possible. The second removes unnecessary whitespace, commas, and parentheses in a source string:
let mut module = /* your source here, or */ naga::Module::default();
// Now minify!
wgsl_minifier::minify_module(&mut module);
// Write to WGSL string
let mut validator = naga::valid::Validator::new(
naga::valid::ValidationFlags::all(),
naga::valid::Capabilities::all(),
);
let info = validator.validate(&module).unwrap();
let output = naga::back::wgsl::write_string(&module, &info, naga::back::wgsl::WriterFlags::empty()).unwrap();
// Minify string
let output = wgsl_minifier::minify_wgsl_source(&output);