/wgslsmith

A toolkit for randomized testing of WGSL compilers

Primary LanguageRustApache License 2.0Apache-2.0

wgslsmith

CI

wgslsmith provides a set of tools for randomized testing of WGSL shader compilers. This includes a random program generator, as well as tools for executing arbitrary compute shaders and performing automated test case reduction on WGSL programs.

The compilers that are supported for testing currently include naga via wgpu and tint via dawn.

This was developed for @hasali19's final year project at Imperial College London, and went on to win a prize. The project report is available here.

Requirements

  • Rust - Latest stable toolchain

A more complete list of requirements is available here.

Building

The full set of tools requires compiling Dawn and wgpu. Full instructions can be found in the docs.

Alternatively, some of the tools can be used without any WebGPU implementations/compilers (e.g. generator and reconditioner). To compile these, run:

$ git clone --recursive https://github.com/wgslsmith/wgslsmith
$ cd wgslsmith
$ cargo build -p wgslsmith --release
$ target/release/wgslsmith --help

Usage

All the tools can be used through the wgslsmith command:

# Do some fuzzing
$ wgslsmith fuzz
# Recondition a shader
$ wgslsmith recondition /path/to/shader.wgsl
# Reduce a crash
$ wgslsmith reduce crash path/to/shader.wgsl --config wgpu:dx12:9348 --regex '...'
# Run a shader
$ wgslsmith run path/to/shader.wgsl

Some options can be configured through a config file. Run wgslsmith config to open the default config file in a text editor. You can also specify a custom config file with the --config-file option.

[reducer]
tmpdir = "/home/hasan/dev/wgslsmith/tmp"
parallelism = 24

[reducer.creduce]
path = "/optional/path/to/creduce"

[reducer.cvise]
path = "/optional/path/to/cvise"

[reducer.perses]
# You need this if you want to reduce with perses
jar = "/path/to/perses_deploy.jar"

To use perses for reduction, grab and build it from https://github.com/wgslsmith/perses, then add it to the config as above.

Development

Insta is used for snapshot testing the parser.

Install the tool with cargo install cargo-insta and use cargo insta test -p parser to run the parser tests.