wgsl-parser 0.5.0

A zero-copy recursive-descent parser for WebGPU shading language
Documentation
use crate::{
	utils::{WithComments, WithErrors, WithTokens},
	SyntaxTree,
};
use snapshot::{begin_snapshots, snapshot, snapshot_test};

begin_snapshots!();

#[snapshot_test]
fn ill_formed_fn_expr_argument() {
	snapshot!(SyntaxTree(WithErrors, WithTokens) r#"
		fn cascade_debug_visualization(
			output_color: vec3<f32>,
			light_id: u32,
			view_z: f32,
		) -> vec3<f32> {
			let overlay_alpha = 0.95;
			let cascade_index = get_cascade_index(light_id, view_z);
			let cascade_color = hsv2rgb(f32(cascade_index) / f32(#{MAX_CASCADES_PER_LIGHT}u + 1u), 1.0, 0.5);
			return vec3<f32>(
				(1.0 - overlay_alpha) * output_color.rgb + overlay_alpha * cascade_color
			);
		}
	"#);
}

#[snapshot_test]
fn ill_formed_struct_field() {
	snapshot!(SyntaxTree(WithComments, WithErrors, WithTokens) r#"
		struct Lights {
			// NOTE: this array size must be kept in sync with the constants defined in bevy_pbr/src/render/light.rs
			directional_lights: array<DirectionalLight, #{MAX_DIRECTIONAL_LIGHTS}u>,
			ambient_color: vec4<f32>,
			// x/y/z dimensions and n_clusters in w
			cluster_dimensions: vec4<u32>,
			// xy are vec2<f32>(cluster_dimensions.xy) / vec2<f32>(view.width, view.height)
			//
			// For perspective projections:
			// z is cluster_dimensions.z / log(far / near)
			// w is cluster_dimensions.z * log(near) / log(far / near)
			//
			// For orthographic projections:
			// NOTE: near and far are +ve but -z is infront of the camera
			// z is -near
			// w is cluster_dimensions.z / (-far - -near)
			cluster_factors: vec4<f32>,
			n_directional_lights: u32,
			spot_light_shadowmap_offset: i32,
			environment_map_smallest_specular_mip_level: u32,
			environment_map_intensity: f32,
		};
	"#);
}