From a04085c5e465736ab52c896aeafd77d023f1a706 Mon Sep 17 00:00:00 2001 From: Andy Leiserson Date: Fri, 30 May 2025 15:02:05 -0700 Subject: [PATCH] Update naga benchmarks and add a compaction benchmark (#7715) --- benches/benches/wgpu-benchmark/shader.rs | 40 ++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/benches/benches/wgpu-benchmark/shader.rs b/benches/benches/wgpu-benchmark/shader.rs index 0abcd1cd3..3c77efd44 100644 --- a/benches/benches/wgpu-benchmark/shader.rs +++ b/benches/benches/wgpu-benchmark/shader.rs @@ -108,6 +108,10 @@ impl Inputs { self.inner.retain(|input| input.module_info.is_some()); } + + fn is_empty(&self) -> bool { + self.inner.is_empty() + } } fn parse_glsl(stage: naga::ShaderStage, inputs: &Inputs) { @@ -124,13 +128,15 @@ fn parse_glsl(stage: naga::ShaderStage, inputs: &Inputs) { } fn get_wgsl_inputs() -> Inputs { - let mut inputs = Inputs::from_dir("../naga/tests/in", "wgsl"); + let mut inputs = Inputs::from_dir("../naga/tests/in/wgsl", "wgsl"); // remove "large-source" tests, they skew the results inputs .inner .retain(|input| !input.filename.contains("large-source")); + assert!(!inputs.is_empty()); + inputs } @@ -168,6 +174,7 @@ fn frontends(c: &mut Criterion) { }); let inputs_spirv = Inputs::from_dir("../naga/tests/in/spv", "spvasm"); + assert!(!inputs_spirv.is_empty()); // Assemble all the SPIR-V assembly. let mut assembled_spirv = Vec::>::new(); @@ -216,6 +223,8 @@ fn frontends(c: &mut Criterion) { let mut inputs_vertex = Inputs::from_dir("../naga/tests/in/glsl", "vert"); let mut inputs_fragment = Inputs::from_dir("../naga/tests/in/glsl", "frag"); + assert!(!inputs_vertex.is_empty()); + assert!(!inputs_fragment.is_empty()); // let mut inputs_compute = Inputs::from_dir("../naga/tests/in/glsl", "comp"); group.throughput(Throughput::Bytes( inputs_vertex.bytes() + inputs_fragment.bytes(), // + inputs_compute.bytes() @@ -259,6 +268,24 @@ fn validation(c: &mut Criterion) { group.finish(); } +fn compact(c: &mut Criterion) { + let mut inputs = get_wgsl_inputs(); + + inputs.validate(); + assert!(!inputs.is_empty()); + + let mut group = c.benchmark_group("compact"); + group.throughput(Throughput::Bytes(inputs.bytes())); + group.bench_function("shader: compact", |b| { + b.iter(|| { + for input in &mut inputs.inner { + naga::compact::compact(input.module.as_mut().unwrap()); + } + }); + }); + group.finish(); +} + fn backends(c: &mut Criterion) { let mut inputs = get_wgsl_inputs(); @@ -267,6 +294,7 @@ fn backends(c: &mut Criterion) { // run this to properly know the size of the inputs, as any that fail validation // will be removed. inputs.validate(); + assert!(!inputs.is_empty()); group.throughput(Throughput::Bytes(inputs.bytes())); group.bench_function("shader: wgsl-out", |b| { @@ -289,6 +317,10 @@ fn backends(c: &mut Criterion) { let mut data = Vec::new(); let options = naga::back::spv::Options::default(); for input in &inputs.inner { + if input.filename.contains("pointer-function-arg") { + // These fail due to https://github.com/gfx-rs/wgpu/issues/7315 + continue; + } let mut writer = naga::back::spv::Writer::new(&options).unwrap(); let _ = writer.write( input.module.as_ref().unwrap(), @@ -306,6 +338,10 @@ fn backends(c: &mut Criterion) { let mut data = Vec::new(); let options = naga::back::spv::Options::default(); for input in &inputs.inner { + if input.filename.contains("pointer-function-arg") { + // These fail due to https://github.com/gfx-rs/wgpu/issues/7315 + continue; + } let mut writer = naga::back::spv::Writer::new(&options).unwrap(); let module = input.module.as_ref().unwrap(); for ep in module.entry_points.iter() { @@ -400,4 +436,4 @@ fn backends(c: &mut Criterion) { }); } -criterion_group!(shader, frontends, validation, backends); +criterion_group!(shader, frontends, validation, compact, backends);