From 1bb5f6c3fef092f900e88e3af83fdfad21aed165 Mon Sep 17 00:00:00 2001 From: agg22 Date: Fri, 23 Oct 2026 11:58:42 +0100 Subject: [PATCH 1/7] Add tests found by mutation testing Mesa --- src/webgpu/mutation/mesa/no_input.spec.ts | 154 ++++++++++ .../mutation/mesa/uniform_input.spec.ts | 272 ++++++++++++++++++ src/webgpu/mutation/mutation_info.ts | 16 ++ 3 files changed, 442 insertions(+) create mode 100644 src/webgpu/mutation/mesa/no_input.spec.ts create mode 100644 src/webgpu/mutation/mesa/uniform_input.spec.ts create mode 100644 src/webgpu/mutation/mutation_info.ts diff --git a/src/webgpu/mutation/mesa/no_input.spec.ts b/src/webgpu/mutation/mesa/no_input.spec.ts new file mode 100644 index 000000000000..6a75f407ed69 --- /dev/null +++ b/src/webgpu/mutation/mesa/no_input.spec.ts @@ -0,0 +1,154 @@ +export const description = ` +Execution tests that read no input, found by mutation testing Mesa. + +Each test is a compute shader generated by the WGSL fuzzer wgslsmith and then reduced +automatically. They were found by mutation testing a shader compiler: each program produces +different output when a specific bug is injected into the compiler, and no existing CTS test +detected that bug. + +Each shader writes its result to a storage buffer at @group(0) @binding(1). +Buffers are given as bytes, in the form the fuzzer reports them, with a comment showing the +values of each struct member. + +Test names are shader_ followed by the first 8 hex digits of the SHA-256 hash of the +shader text. kMutations records, for each test, the implementation that was mutated to find it +and where the mutation was. +`; + +import { makeTestGroup } from '../../../common/framework/test_group.js'; +import { AllFeaturesMaxLimitsGPUTest, GPUTest } from '../../gpu_test.js'; +import { Mutation } from '../mutation_info.js'; + +export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest); + +/** + * For each test: the packages used to find it, and the mutation that it detects. Each entry is + * added just above its test. + */ +export const kMutations: Record = {}; + +/** + * Runs a shader (entry point `main`, one invocation) and checks the contents of its output + * buffer. + * + * @param t The test object + * @param buffers `output`: the expected bytes of the storage buffer at @group(0) @binding(1). + * The buffer starts zero-filled, so padding bytes are expected to be 0. + * @param wgsl The shader + */ +function runGeneratedTest(t: GPUTest, buffers: { output: Uint8Array }, wgsl: string) { + const pipeline = t.device.createComputePipeline({ + layout: 'auto', + compute: { + module: t.device.createShaderModule({ code: wgsl }), + entryPoint: 'main', + }, + }); + + // New buffers are zero-filled. + const outputBuffer = t.createBufferTracked({ + size: buffers.output.byteLength, + usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC, + }); + const bindGroup = t.device.createBindGroup({ + layout: pipeline.getBindGroupLayout(0), + entries: [{ binding: 1, resource: { buffer: outputBuffer } }], + }); + + // Run the shader. + const encoder = t.device.createCommandEncoder(); + const pass = encoder.beginComputePass(); + pass.setPipeline(pipeline); + pass.setBindGroup(0, bindGroup); + pass.dispatchWorkgroups(1); + pass.end(); + t.queue.submit([encoder.finish()]); + + t.expectGPUBufferValuesEqual(outputBuffer, buffers.output); +} + +kMutations['shader_101299f4'] = [ + { package: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }, + { + package: 'mesa', + version: 'ba8eaab4f07e33c0b74fa92c60852cba2518bf2e', + mutated: { + file: 'src/compiler/nir/nir_constant_expressions.c', + line: 48527, + generatedFrom: 'src/compiler/nir/nir_constant_expressions.py', + }, + }, +]; +g.test('shader_101299f4') + .desc( + `A fuzzer-generated compute shader. Found by mutation testing a constant folding compiler pass.` + ) + .fn(t => { + runGeneratedTest( + t, + { + // s_output: a = (0, 0) + output: new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0]), + }, + ` +struct StorageBuffer { + a: vec2, +} + +@group(0) +@binding(1) +var s_output: StorageBuffer; + +var v: array; + +@compute +@workgroup_size(1i) +fn main() { + s_output = StorageBuffer(max(vec3(), vec3(v[select(abs(5i) % 7i, 0i, 5i == i32(-2147483648))])).xy); +} +` + ); + }); + +kMutations['shader_10c2ef9c'] = [ + { package: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }, + { + package: 'mesa', + version: 'ba8eaab4f07e33c0b74fa92c60852cba2518bf2e', + mutated: { + file: 'src/compiler/nir/nir_constant_expressions.c', + line: 50895, + generatedFrom: 'src/compiler/nir/nir_constant_expressions.py', + }, + }, +]; +g.test('shader_10c2ef9c') + .desc( + `A fuzzer-generated compute shader. Found by mutation testing a constant folding compiler pass.` + ) + .fn(t => { + runGeneratedTest( + t, + { + // s_output: c = 4 + output: new Uint8Array([4, 0, 0, 0]), + }, + ` +struct StorageBuffer { + c: i32, +} + +@group(0) +@binding(1) +var s_output: StorageBuffer; + +var v: array = array(1i, 8i, 4i, 8i, 0i); + +@compute +@workgroup_size(1i) +fn main(@builtin(local_invocation_id) builtin_local_invocation_id: vec3) { + s_output = StorageBuffer(v[countTrailingZeros(vec2(builtin_local_invocation_id.x, 6u)).x % 5u]); +} +` + ); + }); \ No newline at end of file diff --git a/src/webgpu/mutation/mesa/uniform_input.spec.ts b/src/webgpu/mutation/mesa/uniform_input.spec.ts new file mode 100644 index 000000000000..50993f58d97a --- /dev/null +++ b/src/webgpu/mutation/mesa/uniform_input.spec.ts @@ -0,0 +1,272 @@ +export const description = ` +Execution tests that read a uniform buffer, found by mutation testing Mesa. + +Each test is a compute shader generated by the WGSL fuzzer wgslsmith and then reduced +automatically. They were found by mutation testing a shader compiler: each program produces +different output when a specific bug is injected into the compiler, and no existing CTS test +detected that bug. + +Each shader writes its result to a storage buffer at @group(0) @binding(1). +Each also reads a uniform buffer at @group(0) @binding(0), filled with the fuzzer's random +input (cut to the size of the binding). +Buffers are given as bytes, in the form the fuzzer reports them, with a comment showing the +values of each struct member. + +Test names are shader_ followed by the first 8 hex digits of the SHA-256 hash of the +shader text. kMutations records, for each test, the implementation that was mutated to find it +and where the mutation was. +`; + +import { makeTestGroup } from '../../../common/framework/test_group.js'; +import { AllFeaturesMaxLimitsGPUTest, GPUTest } from '../../gpu_test.js'; +import { Mutation } from '../mutation_info.js'; + +export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest); + +/** + * For each test: the packages used to find it, and the mutation that it detects. Each entry is + * added just above its test. + */ +export const kMutations: Record = {}; + +/** + * Runs a shader (entry point `main`, one invocation) and checks the contents of its output + * buffer. + * + * @param t The test object + * @param buffers `input`: the bytes of the uniform buffer at @group(0) @binding(0). + * `output`: the expected bytes of the storage buffer at @group(0) @binding(1). The buffer + * starts zero-filled, so padding bytes are expected to be 0. + * @param wgsl The shader + */ +function runGeneratedTest( + t: GPUTest, + buffers: { input: Uint8Array; output: Uint8Array }, + wgsl: string +) { + const pipeline = t.device.createComputePipeline({ + layout: 'auto', + compute: { + module: t.device.createShaderModule({ code: wgsl }), + entryPoint: 'main', + }, + }); + + const inputBuffer = t.makeBufferWithContents(buffers.input, GPUBufferUsage.UNIFORM); + // New buffers are zero-filled. + const outputBuffer = t.createBufferTracked({ + size: buffers.output.byteLength, + usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC, + }); + const bindGroup = t.device.createBindGroup({ + layout: pipeline.getBindGroupLayout(0), + entries: [ + { binding: 0, resource: { buffer: inputBuffer } }, + { binding: 1, resource: { buffer: outputBuffer } }, + ], + }); + + // Run the shader. + const encoder = t.device.createCommandEncoder(); + const pass = encoder.beginComputePass(); + pass.setPipeline(pipeline); + pass.setBindGroup(0, bindGroup); + pass.dispatchWorkgroups(1); + pass.end(); + t.queue.submit([encoder.finish()]); + + t.expectGPUBufferValuesEqual(outputBuffer, buffers.output); +} + +kMutations['shader_429a8325'] = [ + { package: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }, + { + package: 'mesa', + version: 'ba8eaab4f07e33c0b74fa92c60852cba2518bf2e', + mutated: { + file: 'src/compiler/nir/nir_constant_expressions.c', + line: 51437, + generatedFrom: 'src/compiler/nir/nir_constant_expressions.py', + }, + }, +]; +g.test('shader_429a8325') + .desc( + `A fuzzer-generated compute shader. Found by mutation testing a constant folding compiler pass.` + ) + .fn(t => { + runGeneratedTest( + t, + { + // u_input: b = (2558390668, 1882584399, 2302723328, 2974181364), c = 1672505790, + // then 12 bytes of padding + input: new Uint8Array([ + 140, 241, 125, 152, 79, 245, 53, 112, 0, 197, 64, 137, 244, 103, 70, 177, 190, 105, 176, + 99, 182, 225, 107, 28, 89, 82, 1, 211, 34, 217, 48, 22, + ]), + // s_output: b = 6, c = (1, 1) (padding bytes are 0) + output: new Uint8Array([0, 0, 192, 64, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0]), + }, + ` +struct UniformBuffer { + b: vec4, + c: u32, +} + +struct StorageBuffer { + b: f32, + c: vec2, +} + +@group(0) +@binding(0) +var u_input: UniformBuffer; + +@group(0) +@binding(1) +var s_output: StorageBuffer; + +var LOOP_COUNTERS: array; + +@compute +@workgroup_size(1i) +fn main(@builtin(local_invocation_id) builtin_local_invocation_id: vec3) { + while ((max(vec2(), u_input.b.yz).x < u_input.c)) { + if (LOOP_COUNTERS[0u] >= 1u) { + break; + } + (LOOP_COUNTERS)[0u] = LOOP_COUNTERS[0u] + 1u; + } + s_output = StorageBuffer(6f, extractBits(vec3(1i), builtin_local_invocation_id.x, 5u).zz); +} +` + ); + }); + +kMutations['shader_7be24930'] = [ + { package: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }, + { + package: 'mesa', + version: 'ba8eaab4f07e33c0b74fa92c60852cba2518bf2e', + mutated: { file: 'src/compiler/nir/nir_opt_if.c', line: 839 }, + }, +]; +g.test('shader_7be24930') + .desc( + `A fuzzer-generated compute shader. Found by mutation testing an if optimization compiler pass.` + ) + .fn(t => { + runGeneratedTest( + t, + { + // u_input: b = (-432204898, 845770051, 1736441713), then 4 bytes of padding + input: new Uint8Array([ + 158, 19, 61, 230, 67, 109, 105, 50, 113, 255, 127, 103, 120, 80, 165, 3, + ]), + // s_output: a = ((1, 1), (0, 0), (10, 10)), b = (0, 0, 0, 0) + // (padding bytes are 0) + output: new Uint8Array([ + 0, 0, 128, 63, 0, 0, 128, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 65, 0, 0, 32, 65, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ]), + }, + ` +struct UniformBuffer { + b: vec3, +} + +struct StorageBuffer { + a: mat3x2, + b: vec4, +} + +@group(0) +@binding(0) +var u_input: UniformBuffer; + +@group(0) +@binding(1) +var s_output: StorageBuffer; + +fn f(v: vec3) -> vec3 { + return select(v, vec3(10f), any((abs(v) < vec3(0.1f))) || any(abs(v) >= vec3(16777216f))); +} + +fn g(v: vec4) -> vec4 { + return select(v, vec4(10f), any((abs(v) < vec4(0.1f))) || any(abs(v) >= vec4(16777216f))); +} + +fn h() -> mat3x2 { + switch (7i) { + case 2i: { + } + case 1i: { + return mat3x2(vec2(), f(step(f(-vec3()), vec3())).zx, vec2()); + } + default: { + return mat3x2(vec2(1f, 1f), vec4().ww, g(select(vec4(), vec4(), u_input.b.x <= u_input.b.x)).zz); + } + } + return mat3x2(); +} + +@compute +@workgroup_size(1i) +fn main() { + s_output = StorageBuffer(h(), vec4()); +} +` + ); + }); + +kMutations['shader_7ea91b04'] = [ + { package: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }, + { + package: 'mesa', + version: 'ba8eaab4f07e33c0b74fa92c60852cba2518bf2e', + mutated: { file: 'src/compiler/nir/nir_range_analysis.c', line: 1178 }, + }, +]; +g.test('shader_7ea91b04') + .desc( + `A fuzzer-generated compute shader. Found by mutation testing a value range analysis compiler pass.` + ) + .fn(t => { + runGeneratedTest( + t, + { + // u_input: c = (1437411845, 2007253413) + input: new Uint8Array([5, 42, 173, 85, 165, 65, 164, 119]), + // s_output: a = (-7, -7, -7), c = 0 + output: new Uint8Array([0, 0, 224, 192, 0, 0, 224, 192, 0, 0, 224, 192, 0, 0, 0, 0]), + }, + ` +struct UniformBuffer { + c: vec2, +} + +struct StorageBuffer { + a: vec3, + c: f32, +} + +@group(0) +@binding(0) +var u_input: UniformBuffer; + +@group(0) +@binding(1) +var s_output: StorageBuffer; + +fn f(v: vec3) -> vec3 { + return select(v, vec3(10f), any((abs(v) < vec3(0.1f))) || any(abs(v) >= vec3(16777216f))); +} + +@compute +@workgroup_size(1i) +fn main() { + s_output = StorageBuffer(f(round(f(vec3(-7f) + mat4x4()[u_input.c.x % 4u].zzy))), vec4().x); +} +` + ); + }); \ No newline at end of file diff --git a/src/webgpu/mutation/mutation_info.ts b/src/webgpu/mutation/mutation_info.ts new file mode 100644 index 000000000000..8a13e7bf10c3 --- /dev/null +++ b/src/webgpu/mutation/mutation_info.ts @@ -0,0 +1,16 @@ +/** + * Labels for tests found by mutation testing: which packages (and versions) were used to find + * each test, and where the mutation was. + */ + +/** A package (and version) used to find a test, and the mutation made to it, if any. */ +export interface Mutation { + package: string; + /** Git commit. */ + version: string; + /** + * The mutated source: `file` and `line` in the package. `generatedFrom` is set if `file` is + * generated during the build. + */ + mutated?: { file: string; line: number; generatedFrom?: string }; +} \ No newline at end of file From b9445ec54c5238b9a4592cdc2ea1a645105717e1 Mon Sep 17 00:00:00 2001 From: agg22 Date: Fri, 23 Oct 2026 12:01:58 +0100 Subject: [PATCH 2/7] Fix lint and formatting --- src/webgpu/mutation/mesa/no_input.spec.ts | 2 +- src/webgpu/mutation/mesa/uniform_input.spec.ts | 2 +- src/webgpu/mutation/mutation_info.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/webgpu/mutation/mesa/no_input.spec.ts b/src/webgpu/mutation/mesa/no_input.spec.ts index 6a75f407ed69..605cb12c85f6 100644 --- a/src/webgpu/mutation/mesa/no_input.spec.ts +++ b/src/webgpu/mutation/mesa/no_input.spec.ts @@ -151,4 +151,4 @@ fn main(@builtin(local_invocation_id) builtin_local_invocation_id: vec3) { } ` ); - }); \ No newline at end of file + }); diff --git a/src/webgpu/mutation/mesa/uniform_input.spec.ts b/src/webgpu/mutation/mesa/uniform_input.spec.ts index 50993f58d97a..bc74d8ce3b99 100644 --- a/src/webgpu/mutation/mesa/uniform_input.spec.ts +++ b/src/webgpu/mutation/mesa/uniform_input.spec.ts @@ -269,4 +269,4 @@ fn main() { } ` ); - }); \ No newline at end of file + }); diff --git a/src/webgpu/mutation/mutation_info.ts b/src/webgpu/mutation/mutation_info.ts index 8a13e7bf10c3..c7e4e9162599 100644 --- a/src/webgpu/mutation/mutation_info.ts +++ b/src/webgpu/mutation/mutation_info.ts @@ -13,4 +13,4 @@ export interface Mutation { * generated during the build. */ mutated?: { file: string; line: number; generatedFrom?: string }; -} \ No newline at end of file +} From ff6d17b713dfa5b3351d419d1168f718cf2a5daa Mon Sep 17 00:00:00 2001 From: agg22 Date: Mon, 9 Nov 2026 13:58:58 +0000 Subject: [PATCH 3/7] Add more information to mutation documentation --- src/webgpu/mutation/mesa/no_input.spec.ts | 40 +++++++--------- .../mutation/mesa/uniform_input.spec.ts | 48 +++++++++---------- src/webgpu/mutation/mutation_info.ts | 35 +++++++++----- 3 files changed, 66 insertions(+), 57 deletions(-) diff --git a/src/webgpu/mutation/mesa/no_input.spec.ts b/src/webgpu/mutation/mesa/no_input.spec.ts index 605cb12c85f6..10936759320a 100644 --- a/src/webgpu/mutation/mesa/no_input.spec.ts +++ b/src/webgpu/mutation/mesa/no_input.spec.ts @@ -17,7 +17,7 @@ and where the mutation was. import { makeTestGroup } from '../../../common/framework/test_group.js'; import { AllFeaturesMaxLimitsGPUTest, GPUTest } from '../../gpu_test.js'; -import { Mutation } from '../mutation_info.js'; +import { MutationInfo } from '../mutation_info.js'; export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest); @@ -25,7 +25,7 @@ export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest); * For each test: the packages used to find it, and the mutation that it detects. Each entry is * added just above its test. */ -export const kMutations: Record = {}; +const kMutations: Record = {}; /** * Runs a shader (entry point `main`, one invocation) and checks the contents of its output @@ -67,18 +67,16 @@ function runGeneratedTest(t: GPUTest, buffers: { output: Uint8Array }, wgsl: str t.expectGPUBufferValuesEqual(outputBuffer, buffers.output); } -kMutations['shader_101299f4'] = [ - { package: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }, - { - package: 'mesa', +kMutations['shader_101299f4'] = { + mutant: { + component: 'mesa', version: 'ba8eaab4f07e33c0b74fa92c60852cba2518bf2e', - mutated: { - file: 'src/compiler/nir/nir_constant_expressions.c', - line: 48527, - generatedFrom: 'src/compiler/nir/nir_constant_expressions.py', - }, + file: 'src/compiler/nir/nir_constant_expressions.c', + line: 48527, + generatedFrom: 'src/compiler/nir/nir_constant_expressions.py', }, -]; + environment: [{ component: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }], +}; g.test('shader_101299f4') .desc( `A fuzzer-generated compute shader. Found by mutation testing a constant folding compiler pass.` @@ -110,18 +108,16 @@ fn main() { ); }); -kMutations['shader_10c2ef9c'] = [ - { package: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }, - { - package: 'mesa', +kMutations['shader_10c2ef9c'] = { + mutant: { + component: 'mesa', version: 'ba8eaab4f07e33c0b74fa92c60852cba2518bf2e', - mutated: { - file: 'src/compiler/nir/nir_constant_expressions.c', - line: 50895, - generatedFrom: 'src/compiler/nir/nir_constant_expressions.py', - }, + file: 'src/compiler/nir/nir_constant_expressions.c', + line: 50895, + generatedFrom: 'src/compiler/nir/nir_constant_expressions.py', }, -]; + environment: [{ component: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3'}], +}; g.test('shader_10c2ef9c') .desc( `A fuzzer-generated compute shader. Found by mutation testing a constant folding compiler pass.` diff --git a/src/webgpu/mutation/mesa/uniform_input.spec.ts b/src/webgpu/mutation/mesa/uniform_input.spec.ts index bc74d8ce3b99..0c7063299d50 100644 --- a/src/webgpu/mutation/mesa/uniform_input.spec.ts +++ b/src/webgpu/mutation/mesa/uniform_input.spec.ts @@ -19,7 +19,7 @@ and where the mutation was. import { makeTestGroup } from '../../../common/framework/test_group.js'; import { AllFeaturesMaxLimitsGPUTest, GPUTest } from '../../gpu_test.js'; -import { Mutation } from '../mutation_info.js'; +import { MutationInfo } from '../mutation_info.js'; export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest); @@ -27,7 +27,7 @@ export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest); * For each test: the packages used to find it, and the mutation that it detects. Each entry is * added just above its test. */ -export const kMutations: Record = {}; +const kMutations: Record = {}; /** * Runs a shader (entry point `main`, one invocation) and checks the contents of its output @@ -78,18 +78,16 @@ function runGeneratedTest( t.expectGPUBufferValuesEqual(outputBuffer, buffers.output); } -kMutations['shader_429a8325'] = [ - { package: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }, - { - package: 'mesa', +kMutations['shader_429a8325'] = { + mutant: { + component: 'mesa', version: 'ba8eaab4f07e33c0b74fa92c60852cba2518bf2e', - mutated: { - file: 'src/compiler/nir/nir_constant_expressions.c', - line: 51437, - generatedFrom: 'src/compiler/nir/nir_constant_expressions.py', - }, + file: 'src/compiler/nir/nir_constant_expressions.c', + line: 51437, + generatedFrom: 'src/compiler/nir/nir_constant_expressions.py', }, -]; + environment: [{ component: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3'}], +}; g.test('shader_429a8325') .desc( `A fuzzer-generated compute shader. Found by mutation testing a constant folding compiler pass.` @@ -143,14 +141,15 @@ fn main(@builtin(local_invocation_id) builtin_local_invocation_id: vec3) { ); }); -kMutations['shader_7be24930'] = [ - { package: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }, - { - package: 'mesa', +kMutations['shader_7be24930'] = { + mutant: { + component: 'mesa', version: 'ba8eaab4f07e33c0b74fa92c60852cba2518bf2e', - mutated: { file: 'src/compiler/nir/nir_opt_if.c', line: 839 }, + file: 'src/compiler/nir/nir_opt_if.c', + line: 839, }, -]; + environment: [{ component: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3'}], +}; g.test('shader_7be24930') .desc( `A fuzzer-generated compute shader. Found by mutation testing an if optimization compiler pass.` @@ -219,14 +218,15 @@ fn main() { ); }); -kMutations['shader_7ea91b04'] = [ - { package: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }, - { - package: 'mesa', +kMutations['shader_7ea91b04'] = { + mutant: { + component: 'mesa', version: 'ba8eaab4f07e33c0b74fa92c60852cba2518bf2e', - mutated: { file: 'src/compiler/nir/nir_range_analysis.c', line: 1178 }, + file: 'src/compiler/nir/nir_range_analysis.c', + line: 1178, }, -]; + environment: [{ component: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }], +}; g.test('shader_7ea91b04') .desc( `A fuzzer-generated compute shader. Found by mutation testing a value range analysis compiler pass.` diff --git a/src/webgpu/mutation/mutation_info.ts b/src/webgpu/mutation/mutation_info.ts index c7e4e9162599..c7eb186192e8 100644 --- a/src/webgpu/mutation/mutation_info.ts +++ b/src/webgpu/mutation/mutation_info.ts @@ -1,16 +1,29 @@ /** - * Labels for tests found by mutation testing: which packages (and versions) were used to find - * each test, and where the mutation was. + * Provenance for tests found by mutation testing. + * + * Each test was found by deliberately injecting a small change (a "mutant") into one component's + * source, here the Mesa NIR compiler, and searching for a shader whose result differs between the + * mutated and unmutated builds. The rest of the CTS did not detect these mutants, which means that + * the tests checks behaviour that existing tests did not. */ -/** A package (and version) used to find a test, and the mutation made to it, if any. */ -export interface Mutation { - package: string; - /** Git commit. */ +/** A component of the WebGPU stack used to run the test, e.g. Dawn or Mesa. */ +export interface ComponentVersion { + component: string; + /** Git commit in the component's repository. */ version: string; - /** - * The mutated source: `file` and `line` in the package. `generatedFrom` is set if `file` is - * generated during the build. - */ - mutated?: { file: string; line: number; generatedFrom?: string }; } + +/** The configuration in which a test detected a mutant. */ +export interface MutationInfo { + /** The mutated component, at the commit the mutation was applied to. */ + mutant: ComponentVersion & { + /** Location of the mutation in the component's source. */ + file: string; + line: number; + /** Set if `file` is generated during the build: the script that generates it. */ + generatedFrom?: string; + }; + /** Other components used unmodified to run the test (e.g. Dawn). */ + environment: ComponentVersion[]; +} \ No newline at end of file From aa78e846cc4f8dd13e18ed72e201c7af06851cbd Mon Sep 17 00:00:00 2001 From: agg22 Date: Mon, 9 Nov 2026 14:10:50 +0000 Subject: [PATCH 4/7] Address PR nits --- src/webgpu/mutation/mesa/no_input.spec.ts | 33 +++++++------------ .../mutation/mesa/uniform_input.spec.ts | 30 +++++------------ src/webgpu/mutation/mutation_info.ts | 2 +- 3 files changed, 22 insertions(+), 43 deletions(-) diff --git a/src/webgpu/mutation/mesa/no_input.spec.ts b/src/webgpu/mutation/mesa/no_input.spec.ts index 10936759320a..978c019ddbc8 100644 --- a/src/webgpu/mutation/mesa/no_input.spec.ts +++ b/src/webgpu/mutation/mesa/no_input.spec.ts @@ -3,8 +3,8 @@ Execution tests that read no input, found by mutation testing Mesa. Each test is a compute shader generated by the WGSL fuzzer wgslsmith and then reduced automatically. They were found by mutation testing a shader compiler: each program produces -different output when a specific bug is injected into the compiler, and no existing CTS test -detected that bug. +different output when a specific change is injected into the compiler, and no existing CTS test +detected that change. Each shader writes its result to a storage buffer at @group(0) @binding(1). Buffers are given as bytes, in the form the fuzzer reports them, with a comment showing the @@ -22,7 +22,7 @@ import { MutationInfo } from '../mutation_info.js'; export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest); /** - * For each test: the packages used to find it, and the mutation that it detects. Each entry is + * For each test: the components used to find it, and the mutation that it detects. Each entry is * added just above its test. */ const kMutations: Record = {}; @@ -32,11 +32,12 @@ const kMutations: Record = {}; * buffer. * * @param t The test object - * @param buffers `output`: the expected bytes of the storage buffer at @group(0) @binding(1). + * @param expectedOutput The expected bytes of the storage buffer at @group(0) @binding(1). * The buffer starts zero-filled, so padding bytes are expected to be 0. * @param wgsl The shader */ -function runGeneratedTest(t: GPUTest, buffers: { output: Uint8Array }, wgsl: string) { +function runGeneratedTest(t: GPUTest, expectedOutput: Uint8Array, wgsl: string) { + const pipeline = t.device.createComputePipeline({ layout: 'auto', compute: { @@ -47,7 +48,7 @@ function runGeneratedTest(t: GPUTest, buffers: { output: Uint8Array }, wgsl: str // New buffers are zero-filled. const outputBuffer = t.createBufferTracked({ - size: buffers.output.byteLength, + size: expectedOutput.byteLength, usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC, }); const bindGroup = t.device.createBindGroup({ @@ -64,7 +65,7 @@ function runGeneratedTest(t: GPUTest, buffers: { output: Uint8Array }, wgsl: str pass.end(); t.queue.submit([encoder.finish()]); - t.expectGPUBufferValuesEqual(outputBuffer, buffers.output); + t.expectGPUBufferValuesEqual(outputBuffer, expectedOutput); } kMutations['shader_101299f4'] = { @@ -84,18 +85,13 @@ g.test('shader_101299f4') .fn(t => { runGeneratedTest( t, - { - // s_output: a = (0, 0) - output: new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0]), - }, + new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0]), // s_output: a = (0, 0) ` struct StorageBuffer { a: vec2, } -@group(0) -@binding(1) -var s_output: StorageBuffer; +@group(0) @binding(1) var s_output: StorageBuffer; var v: array; @@ -125,18 +121,13 @@ g.test('shader_10c2ef9c') .fn(t => { runGeneratedTest( t, - { - // s_output: c = 4 - output: new Uint8Array([4, 0, 0, 0]), - }, + new Uint8Array([4, 0, 0, 0]), // s_output: c = 4 ` struct StorageBuffer { c: i32, } -@group(0) -@binding(1) -var s_output: StorageBuffer; +@group(0) @binding(1) var s_output: StorageBuffer; var v: array = array(1i, 8i, 4i, 8i, 0i); diff --git a/src/webgpu/mutation/mesa/uniform_input.spec.ts b/src/webgpu/mutation/mesa/uniform_input.spec.ts index 0c7063299d50..85f4aa6de798 100644 --- a/src/webgpu/mutation/mesa/uniform_input.spec.ts +++ b/src/webgpu/mutation/mesa/uniform_input.spec.ts @@ -3,8 +3,8 @@ Execution tests that read a uniform buffer, found by mutation testing Mesa. Each test is a compute shader generated by the WGSL fuzzer wgslsmith and then reduced automatically. They were found by mutation testing a shader compiler: each program produces -different output when a specific bug is injected into the compiler, and no existing CTS test -detected that bug. +different output when a specific change is injected into the compiler, and no existing CTS test +detected that change. Each shader writes its result to a storage buffer at @group(0) @binding(1). Each also reads a uniform buffer at @group(0) @binding(0), filled with the fuzzer's random @@ -24,7 +24,7 @@ import { MutationInfo } from '../mutation_info.js'; export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest); /** - * For each test: the packages used to find it, and the mutation that it detects. Each entry is + * For each test: the components used to find it, and the mutation that it detects. Each entry is * added just above its test. */ const kMutations: Record = {}; @@ -116,13 +116,9 @@ struct StorageBuffer { c: vec2, } -@group(0) -@binding(0) -var u_input: UniformBuffer; +@group(0) @binding(0) var u_input: UniformBuffer; -@group(0) -@binding(1) -var s_output: StorageBuffer; +@group(0) @binding(1) var s_output: StorageBuffer; var LOOP_COUNTERS: array; @@ -179,13 +175,9 @@ struct StorageBuffer { b: vec4, } -@group(0) -@binding(0) -var u_input: UniformBuffer; +@group(0) @binding(0) var u_input: UniformBuffer; -@group(0) -@binding(1) -var s_output: StorageBuffer; +@group(0) @binding(1) var s_output: StorageBuffer; fn f(v: vec3) -> vec3 { return select(v, vec3(10f), any((abs(v) < vec3(0.1f))) || any(abs(v) >= vec3(16777216f))); @@ -250,13 +242,9 @@ struct StorageBuffer { c: f32, } -@group(0) -@binding(0) -var u_input: UniformBuffer; +@group(0) @binding(0) var u_input: UniformBuffer; -@group(0) -@binding(1) -var s_output: StorageBuffer; +@group(0) @binding(1) var s_output: StorageBuffer; fn f(v: vec3) -> vec3 { return select(v, vec3(10f), any((abs(v) < vec3(0.1f))) || any(abs(v) >= vec3(16777216f))); diff --git a/src/webgpu/mutation/mutation_info.ts b/src/webgpu/mutation/mutation_info.ts index c7eb186192e8..e43024097f67 100644 --- a/src/webgpu/mutation/mutation_info.ts +++ b/src/webgpu/mutation/mutation_info.ts @@ -4,7 +4,7 @@ * Each test was found by deliberately injecting a small change (a "mutant") into one component's * source, here the Mesa NIR compiler, and searching for a shader whose result differs between the * mutated and unmutated builds. The rest of the CTS did not detect these mutants, which means that - * the tests checks behaviour that existing tests did not. + * the tests check behaviour that existing tests did not. */ /** A component of the WebGPU stack used to run the test, e.g. Dawn or Mesa. */ From 57551a19bda2d23668b5b529313800e6f45ad6ea Mon Sep 17 00:00:00 2001 From: agg22 Date: Mon, 9 Nov 2026 14:15:48 +0000 Subject: [PATCH 5/7] Fix lint and formatting --- src/webgpu/mutation/mesa/no_input.spec.ts | 3 +-- src/webgpu/mutation/mesa/uniform_input.spec.ts | 8 ++++---- src/webgpu/mutation/mutation_info.ts | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/webgpu/mutation/mesa/no_input.spec.ts b/src/webgpu/mutation/mesa/no_input.spec.ts index 978c019ddbc8..a2ca80688947 100644 --- a/src/webgpu/mutation/mesa/no_input.spec.ts +++ b/src/webgpu/mutation/mesa/no_input.spec.ts @@ -37,7 +37,6 @@ const kMutations: Record = {}; * @param wgsl The shader */ function runGeneratedTest(t: GPUTest, expectedOutput: Uint8Array, wgsl: string) { - const pipeline = t.device.createComputePipeline({ layout: 'auto', compute: { @@ -112,7 +111,7 @@ kMutations['shader_10c2ef9c'] = { line: 50895, generatedFrom: 'src/compiler/nir/nir_constant_expressions.py', }, - environment: [{ component: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3'}], + environment: [{ component: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }], }; g.test('shader_10c2ef9c') .desc( diff --git a/src/webgpu/mutation/mesa/uniform_input.spec.ts b/src/webgpu/mutation/mesa/uniform_input.spec.ts index 85f4aa6de798..79576f6d14b8 100644 --- a/src/webgpu/mutation/mesa/uniform_input.spec.ts +++ b/src/webgpu/mutation/mesa/uniform_input.spec.ts @@ -86,7 +86,7 @@ kMutations['shader_429a8325'] = { line: 51437, generatedFrom: 'src/compiler/nir/nir_constant_expressions.py', }, - environment: [{ component: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3'}], + environment: [{ component: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }], }; g.test('shader_429a8325') .desc( @@ -141,10 +141,10 @@ kMutations['shader_7be24930'] = { mutant: { component: 'mesa', version: 'ba8eaab4f07e33c0b74fa92c60852cba2518bf2e', - file: 'src/compiler/nir/nir_opt_if.c', + file: 'src/compiler/nir/nir_opt_if.c', line: 839, }, - environment: [{ component: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3'}], + environment: [{ component: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }], }; g.test('shader_7be24930') .desc( @@ -214,7 +214,7 @@ kMutations['shader_7ea91b04'] = { mutant: { component: 'mesa', version: 'ba8eaab4f07e33c0b74fa92c60852cba2518bf2e', - file: 'src/compiler/nir/nir_range_analysis.c', + file: 'src/compiler/nir/nir_range_analysis.c', line: 1178, }, environment: [{ component: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }], diff --git a/src/webgpu/mutation/mutation_info.ts b/src/webgpu/mutation/mutation_info.ts index e43024097f67..5a7b8207bcfb 100644 --- a/src/webgpu/mutation/mutation_info.ts +++ b/src/webgpu/mutation/mutation_info.ts @@ -26,4 +26,4 @@ export interface MutationInfo { }; /** Other components used unmodified to run the test (e.g. Dawn). */ environment: ComponentVersion[]; -} \ No newline at end of file +} From 268b3cc1904d321b781f25aeecae2bd44d68ea29 Mon Sep 17 00:00:00 2001 From: agg22 Date: Mon, 9 Nov 2026 14:26:27 +0000 Subject: [PATCH 6/7] Move mutation tests into shader,execution subtree --- .../{ => shader/execution}/mutation/mesa/no_input.spec.ts | 4 ++-- .../execution}/mutation/mesa/uniform_input.spec.ts | 4 ++-- src/webgpu/{ => shader/execution}/mutation/mutation_info.ts | 0 3 files changed, 4 insertions(+), 4 deletions(-) rename src/webgpu/{ => shader/execution}/mutation/mesa/no_input.spec.ts (96%) rename src/webgpu/{ => shader/execution}/mutation/mesa/uniform_input.spec.ts (98%) rename src/webgpu/{ => shader/execution}/mutation/mutation_info.ts (100%) diff --git a/src/webgpu/mutation/mesa/no_input.spec.ts b/src/webgpu/shader/execution/mutation/mesa/no_input.spec.ts similarity index 96% rename from src/webgpu/mutation/mesa/no_input.spec.ts rename to src/webgpu/shader/execution/mutation/mesa/no_input.spec.ts index a2ca80688947..aa3891dcf3ac 100644 --- a/src/webgpu/mutation/mesa/no_input.spec.ts +++ b/src/webgpu/shader/execution/mutation/mesa/no_input.spec.ts @@ -15,8 +15,8 @@ shader text. kMutations records, for each test, the implementation that was muta and where the mutation was. `; -import { makeTestGroup } from '../../../common/framework/test_group.js'; -import { AllFeaturesMaxLimitsGPUTest, GPUTest } from '../../gpu_test.js'; +import { makeTestGroup } from '../../../../../common/framework/test_group.js'; +import { AllFeaturesMaxLimitsGPUTest, GPUTest } from '../../../../gpu_test.js'; import { MutationInfo } from '../mutation_info.js'; export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest); diff --git a/src/webgpu/mutation/mesa/uniform_input.spec.ts b/src/webgpu/shader/execution/mutation/mesa/uniform_input.spec.ts similarity index 98% rename from src/webgpu/mutation/mesa/uniform_input.spec.ts rename to src/webgpu/shader/execution/mutation/mesa/uniform_input.spec.ts index 79576f6d14b8..4de360eb881a 100644 --- a/src/webgpu/mutation/mesa/uniform_input.spec.ts +++ b/src/webgpu/shader/execution/mutation/mesa/uniform_input.spec.ts @@ -17,8 +17,8 @@ shader text. kMutations records, for each test, the implementation that was muta and where the mutation was. `; -import { makeTestGroup } from '../../../common/framework/test_group.js'; -import { AllFeaturesMaxLimitsGPUTest, GPUTest } from '../../gpu_test.js'; +import { makeTestGroup } from '../../../../../common/framework/test_group.js'; +import { AllFeaturesMaxLimitsGPUTest, GPUTest } from '../../../../gpu_test.js'; import { MutationInfo } from '../mutation_info.js'; export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest); diff --git a/src/webgpu/mutation/mutation_info.ts b/src/webgpu/shader/execution/mutation/mutation_info.ts similarity index 100% rename from src/webgpu/mutation/mutation_info.ts rename to src/webgpu/shader/execution/mutation/mutation_info.ts From 02cc56cf043eb974467dba84d41e58519ef1d660 Mon Sep 17 00:00:00 2001 From: agg22 Date: Tue, 10 Nov 2026 11:57:34 +0000 Subject: [PATCH 7/7] Combine mutation tests into one parameterized test per file Move the shader, buffer data and mutation info for each test into a single kTestData table, and run them as cases of one test per file. --- .../execution/mutation/mesa/no_input.spec.ts | 105 +++++----- .../mutation/mesa/uniform_input.spec.ts | 187 +++++++++--------- .../execution/mutation/mutation_info.ts | 2 +- 3 files changed, 141 insertions(+), 153 deletions(-) diff --git a/src/webgpu/shader/execution/mutation/mesa/no_input.spec.ts b/src/webgpu/shader/execution/mutation/mesa/no_input.spec.ts index aa3891dcf3ac..fbe1e97989ce 100644 --- a/src/webgpu/shader/execution/mutation/mesa/no_input.spec.ts +++ b/src/webgpu/shader/execution/mutation/mesa/no_input.spec.ts @@ -1,31 +1,35 @@ export const description = ` Execution tests that read no input, found by mutation testing Mesa. -Each test is a compute shader generated by the WGSL fuzzer wgslsmith and then reduced +Each case is a compute shader generated by the WGSL fuzzer WGSLsmith and then reduced automatically. They were found by mutation testing a shader compiler: each program produces different output when a specific change is injected into the compiler, and no existing CTS test detected that change. Each shader writes its result to a storage buffer at @group(0) @binding(1). -Buffers are given as bytes, in the form the fuzzer reports them, with a comment showing the +Expected output is given as bytes, in the form the fuzzer reports it, with a comment showing the values of each struct member. -Test names are shader_ followed by the first 8 hex digits of the SHA-256 hash of the -shader text. kMutations records, for each test, the implementation that was mutated to find it -and where the mutation was. +Case names are "shader_" followed by the first 8 hex digits of the SHA-256 hash of the +shader text. kTestData holds each case's shader, its expected output, and the location of the +mutation it detects. `; import { makeTestGroup } from '../../../../../common/framework/test_group.js'; +import { keysOf } from '../../../../../common/util/data_tables.js'; import { AllFeaturesMaxLimitsGPUTest, GPUTest } from '../../../../gpu_test.js'; import { MutationInfo } from '../mutation_info.js'; export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest); -/** - * For each test: the components used to find it, and the mutation that it detects. Each entry is - * added just above its test. - */ -const kMutations: Record = {}; +interface TestData { + /** Where the mutation this test detects was made. */ + mutation: MutationInfo; + /** The shader. */ + code: string; + /** The expected bytes of the output buffer. */ + expectedOutput: number[]; +} /** * Runs a shader (entry point `main`, one invocation) and checks the contents of its output @@ -67,25 +71,19 @@ function runGeneratedTest(t: GPUTest, expectedOutput: Uint8Array, wgsl: string) t.expectGPUBufferValuesEqual(outputBuffer, expectedOutput); } -kMutations['shader_101299f4'] = { - mutant: { - component: 'mesa', - version: 'ba8eaab4f07e33c0b74fa92c60852cba2518bf2e', - file: 'src/compiler/nir/nir_constant_expressions.c', - line: 48527, - generatedFrom: 'src/compiler/nir/nir_constant_expressions.py', - }, - environment: [{ component: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }], -}; -g.test('shader_101299f4') - .desc( - `A fuzzer-generated compute shader. Found by mutation testing a constant folding compiler pass.` - ) - .fn(t => { - runGeneratedTest( - t, - new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0]), // s_output: a = (0, 0) - ` +const kTestData: Record = { + shader_101299f4: { + mutation: { + mutant: { + component: 'mesa', + version: 'ba8eaab4f07e33c0b74fa92c60852cba2518bf2e', + file: 'src/compiler/nir/nir_constant_expressions.c', + line: 48527, + generatedFrom: 'src/compiler/nir/nir_constant_expressions.py', + }, + environment: [{ component: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }], + }, + code: ` struct StorageBuffer { a: vec2, } @@ -99,29 +97,21 @@ var v: array; fn main() { s_output = StorageBuffer(max(vec3(), vec3(v[select(abs(5i) % 7i, 0i, 5i == i32(-2147483648))])).xy); } -` - ); - }); - -kMutations['shader_10c2ef9c'] = { - mutant: { - component: 'mesa', - version: 'ba8eaab4f07e33c0b74fa92c60852cba2518bf2e', - file: 'src/compiler/nir/nir_constant_expressions.c', - line: 50895, - generatedFrom: 'src/compiler/nir/nir_constant_expressions.py', +`, + expectedOutput: [0, 0, 0, 0, 0, 0, 0, 0], // s_output: a = (0, 0) }, - environment: [{ component: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }], -}; -g.test('shader_10c2ef9c') - .desc( - `A fuzzer-generated compute shader. Found by mutation testing a constant folding compiler pass.` - ) - .fn(t => { - runGeneratedTest( - t, - new Uint8Array([4, 0, 0, 0]), // s_output: c = 4 - ` + shader_10c2ef9c: { + mutation: { + mutant: { + component: 'mesa', + version: 'ba8eaab4f07e33c0b74fa92c60852cba2518bf2e', + file: 'src/compiler/nir/nir_constant_expressions.c', + line: 50895, + generatedFrom: 'src/compiler/nir/nir_constant_expressions.py', + }, + environment: [{ component: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }], + }, + code: ` struct StorageBuffer { c: i32, } @@ -135,6 +125,15 @@ var v: array = array(1i, 8i, 4i, 8i, 0i); fn main(@builtin(local_invocation_id) builtin_local_invocation_id: vec3) { s_output = StorageBuffer(v[countTrailingZeros(vec2(builtin_local_invocation_id.x, 6u)).x % 5u]); } -` - ); +`, + expectedOutput: [4, 0, 0, 0], // s_output: c = 4 + }, +}; + +g.test('no_input') + .desc(`Tests compute shaders that read no input, found by mutation testing Mesa.`) + .params(u => u.combine('case', keysOf(kTestData))) + .fn(t => { + const c = kTestData[t.params.case]; + runGeneratedTest(t, new Uint8Array(c.expectedOutput), c.code); }); diff --git a/src/webgpu/shader/execution/mutation/mesa/uniform_input.spec.ts b/src/webgpu/shader/execution/mutation/mesa/uniform_input.spec.ts index 4de360eb881a..14df40b34f79 100644 --- a/src/webgpu/shader/execution/mutation/mesa/uniform_input.spec.ts +++ b/src/webgpu/shader/execution/mutation/mesa/uniform_input.spec.ts @@ -1,7 +1,7 @@ export const description = ` Execution tests that read a uniform buffer, found by mutation testing Mesa. -Each test is a compute shader generated by the WGSL fuzzer wgslsmith and then reduced +Each case is a compute shader generated by the WGSL fuzzer WGSLsmith and then reduced automatically. They were found by mutation testing a shader compiler: each program produces different output when a specific change is injected into the compiler, and no existing CTS test detected that change. @@ -9,25 +9,31 @@ detected that change. Each shader writes its result to a storage buffer at @group(0) @binding(1). Each also reads a uniform buffer at @group(0) @binding(0), filled with the fuzzer's random input (cut to the size of the binding). -Buffers are given as bytes, in the form the fuzzer reports them, with a comment showing the -values of each struct member. +Input and expected output are given as bytes, in the form the fuzzer reports them, +with a comment showing the values of each struct member. -Test names are shader_ followed by the first 8 hex digits of the SHA-256 hash of the -shader text. kMutations records, for each test, the implementation that was mutated to find it -and where the mutation was. +Case names are "shader_" followed by the first 8 hex digits of the SHA-256 hash of the +shader text. kTestData holds each case's shader, its input and expected output, and the +mutation it detects. `; import { makeTestGroup } from '../../../../../common/framework/test_group.js'; +import { keysOf } from '../../../../../common/util/data_tables.js'; import { AllFeaturesMaxLimitsGPUTest, GPUTest } from '../../../../gpu_test.js'; import { MutationInfo } from '../mutation_info.js'; export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest); -/** - * For each test: the components used to find it, and the mutation that it detects. Each entry is - * added just above its test. - */ -const kMutations: Record = {}; +interface TestData { + /** Where the mutation this test detects was made. */ + mutation: MutationInfo; + /** The shader. */ + code: string; + /** The bytes of the uniform buffer. */ + input: number[]; + /** The expected bytes of the output buffer. */ + expectedOutput: number[]; +} /** * Runs a shader (entry point `main`, one invocation) and checks the contents of its output @@ -35,13 +41,13 @@ const kMutations: Record = {}; * * @param t The test object * @param buffers `input`: the bytes of the uniform buffer at @group(0) @binding(0). - * `output`: the expected bytes of the storage buffer at @group(0) @binding(1). The buffer + * `expectedOutput`: the expected bytes of the storage buffer at @group(0) @binding(1). The buffer * starts zero-filled, so padding bytes are expected to be 0. * @param wgsl The shader */ function runGeneratedTest( t: GPUTest, - buffers: { input: Uint8Array; output: Uint8Array }, + buffers: { input: Uint8Array; expectedOutput: Uint8Array }, wgsl: string ) { const pipeline = t.device.createComputePipeline({ @@ -55,7 +61,7 @@ function runGeneratedTest( const inputBuffer = t.makeBufferWithContents(buffers.input, GPUBufferUsage.UNIFORM); // New buffers are zero-filled. const outputBuffer = t.createBufferTracked({ - size: buffers.output.byteLength, + size: buffers.expectedOutput.byteLength, usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC, }); const bindGroup = t.device.createBindGroup({ @@ -75,37 +81,22 @@ function runGeneratedTest( pass.end(); t.queue.submit([encoder.finish()]); - t.expectGPUBufferValuesEqual(outputBuffer, buffers.output); + t.expectGPUBufferValuesEqual(outputBuffer, buffers.expectedOutput); } -kMutations['shader_429a8325'] = { - mutant: { - component: 'mesa', - version: 'ba8eaab4f07e33c0b74fa92c60852cba2518bf2e', - file: 'src/compiler/nir/nir_constant_expressions.c', - line: 51437, - generatedFrom: 'src/compiler/nir/nir_constant_expressions.py', - }, - environment: [{ component: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }], -}; -g.test('shader_429a8325') - .desc( - `A fuzzer-generated compute shader. Found by mutation testing a constant folding compiler pass.` - ) - .fn(t => { - runGeneratedTest( - t, - { - // u_input: b = (2558390668, 1882584399, 2302723328, 2974181364), c = 1672505790, - // then 12 bytes of padding - input: new Uint8Array([ - 140, 241, 125, 152, 79, 245, 53, 112, 0, 197, 64, 137, 244, 103, 70, 177, 190, 105, 176, - 99, 182, 225, 107, 28, 89, 82, 1, 211, 34, 217, 48, 22, - ]), - // s_output: b = 6, c = (1, 1) (padding bytes are 0) - output: new Uint8Array([0, 0, 192, 64, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0]), +const kTestData: Record = { + shader_429a8325: { + mutation: { + mutant: { + component: 'mesa', + version: 'ba8eaab4f07e33c0b74fa92c60852cba2518bf2e', + file: 'src/compiler/nir/nir_constant_expressions.c', + line: 51437, + generatedFrom: 'src/compiler/nir/nir_constant_expressions.py', }, - ` + environment: [{ component: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }], + }, + code: ` struct UniformBuffer { b: vec4, c: u32, @@ -133,39 +124,27 @@ fn main(@builtin(local_invocation_id) builtin_local_invocation_id: vec3) { } s_output = StorageBuffer(6f, extractBits(vec3(1i), builtin_local_invocation_id.x, 5u).zz); } -` - ); - }); - -kMutations['shader_7be24930'] = { - mutant: { - component: 'mesa', - version: 'ba8eaab4f07e33c0b74fa92c60852cba2518bf2e', - file: 'src/compiler/nir/nir_opt_if.c', - line: 839, +`, + // u_input: b = (2558390668, 1882584399, 2302723328, 2974181364), c = 1672505790, + // then 12 bytes of padding + input: [ + 140, 241, 125, 152, 79, 245, 53, 112, 0, 197, 64, 137, 244, 103, 70, 177, 190, 105, 176, 99, + 182, 225, 107, 28, 89, 82, 1, 211, 34, 217, 48, 22, + ], + // s_output: b = 6, c = (1, 1) (padding bytes are 0) + expectedOutput: [0, 0, 192, 64, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0], }, - environment: [{ component: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }], -}; -g.test('shader_7be24930') - .desc( - `A fuzzer-generated compute shader. Found by mutation testing an if optimization compiler pass.` - ) - .fn(t => { - runGeneratedTest( - t, - { - // u_input: b = (-432204898, 845770051, 1736441713), then 4 bytes of padding - input: new Uint8Array([ - 158, 19, 61, 230, 67, 109, 105, 50, 113, 255, 127, 103, 120, 80, 165, 3, - ]), - // s_output: a = ((1, 1), (0, 0), (10, 10)), b = (0, 0, 0, 0) - // (padding bytes are 0) - output: new Uint8Array([ - 0, 0, 128, 63, 0, 0, 128, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 65, 0, 0, 32, 65, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]), + shader_7be24930: { + mutation: { + mutant: { + component: 'mesa', + version: 'ba8eaab4f07e33c0b74fa92c60852cba2518bf2e', + file: 'src/compiler/nir/nir_opt_if.c', + line: 839, }, - ` + environment: [{ component: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }], + }, + code: ` struct UniformBuffer { b: vec3, } @@ -206,33 +185,27 @@ fn h() -> mat3x2 { fn main() { s_output = StorageBuffer(h(), vec4()); } -` - ); - }); - -kMutations['shader_7ea91b04'] = { - mutant: { - component: 'mesa', - version: 'ba8eaab4f07e33c0b74fa92c60852cba2518bf2e', - file: 'src/compiler/nir/nir_range_analysis.c', - line: 1178, +`, + // u_input: b = (-432204898, 845770051, 1736441713), then 4 bytes of padding + input: [158, 19, 61, 230, 67, 109, 105, 50, 113, 255, 127, 103, 120, 80, 165, 3], + // s_output: a = ((1, 1), (0, 0), (10, 10)), b = (0, 0, 0, 0) + // (padding bytes are 0) + expectedOutput: [ + 0, 0, 128, 63, 0, 0, 128, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 65, 0, 0, 32, 65, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], }, - environment: [{ component: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }], -}; -g.test('shader_7ea91b04') - .desc( - `A fuzzer-generated compute shader. Found by mutation testing a value range analysis compiler pass.` - ) - .fn(t => { - runGeneratedTest( - t, - { - // u_input: c = (1437411845, 2007253413) - input: new Uint8Array([5, 42, 173, 85, 165, 65, 164, 119]), - // s_output: a = (-7, -7, -7), c = 0 - output: new Uint8Array([0, 0, 224, 192, 0, 0, 224, 192, 0, 0, 224, 192, 0, 0, 0, 0]), + shader_7ea91b04: { + mutation: { + mutant: { + component: 'mesa', + version: 'ba8eaab4f07e33c0b74fa92c60852cba2518bf2e', + file: 'src/compiler/nir/nir_range_analysis.c', + line: 1178, }, - ` + environment: [{ component: 'dawn', version: '9de0fd67086127228e8aa28e69616da37220cfc3' }], + }, + code: ` struct UniformBuffer { c: vec2, } @@ -255,6 +228,22 @@ fn f(v: vec3) -> vec3 { fn main() { s_output = StorageBuffer(f(round(f(vec3(-7f) + mat4x4()[u_input.c.x % 4u].zzy))), vec4().x); } -` +`, + // u_input: c = (1437411845, 2007253413) + input: [5, 42, 173, 85, 165, 65, 164, 119], + // s_output: a = (-7, -7, -7), c = 0 + expectedOutput: [0, 0, 224, 192, 0, 0, 224, 192, 0, 0, 224, 192, 0, 0, 0, 0], + }, +}; + +g.test('uniform_input') + .desc(`Tests compute shaders that read a uniform buffer, found by mutation testing Mesa.`) + .params(u => u.combine('case', keysOf(kTestData))) + .fn(t => { + const c = kTestData[t.params.case]; + runGeneratedTest( + t, + { input: new Uint8Array(c.input), expectedOutput: new Uint8Array(c.expectedOutput) }, + c.code ); }); diff --git a/src/webgpu/shader/execution/mutation/mutation_info.ts b/src/webgpu/shader/execution/mutation/mutation_info.ts index 5a7b8207bcfb..cde358fe8fe4 100644 --- a/src/webgpu/shader/execution/mutation/mutation_info.ts +++ b/src/webgpu/shader/execution/mutation/mutation_info.ts @@ -2,7 +2,7 @@ * Provenance for tests found by mutation testing. * * Each test was found by deliberately injecting a small change (a "mutant") into one component's - * source, here the Mesa NIR compiler, and searching for a shader whose result differs between the + * source (e.g. the Mesa NIR compiler) and searching for a shader whose result differs between the * mutated and unmutated builds. The rest of the CTS did not detect these mutants, which means that * the tests check behaviour that existing tests did not. */