|
| 1 | +export const description = ` |
| 2 | +Validation tests for the subgroup_size_control extension |
| 3 | +`; |
| 4 | + |
| 5 | +import { makeTestGroup } from '../../../../common/framework/test_group.js'; |
| 6 | +import { UniqueFeaturesAndLimitsShaderValidationTest } from '../shader_validation_test.js'; |
| 7 | + |
| 8 | +export const g = makeTestGroup(UniqueFeaturesAndLimitsShaderValidationTest); |
| 9 | + |
| 10 | +g.test('enable_subgroup_size_control_requires_subgroups') |
| 11 | + .desc( |
| 12 | + `Checks that enabling the WGSL extension subgroup_size_control without also enabling the |
| 13 | + subgroups extension is a compilation error.` |
| 14 | + ) |
| 15 | + .params(u => u.combine('enableSubgroups', [false, true] as const)) |
| 16 | + .beforeAllSubcases(t => { |
| 17 | + t.selectDeviceOrSkipTestCase({ |
| 18 | + requiredFeatures: ['subgroup-size-control' as GPUFeatureName], |
| 19 | + }); |
| 20 | + }) |
| 21 | + .fn(t => { |
| 22 | + const { enableSubgroups } = t.params; |
| 23 | + |
| 24 | + t.expectCompileResult( |
| 25 | + enableSubgroups, |
| 26 | + ` |
| 27 | + ${enableSubgroups ? 'enable subgroups;' : ''} |
| 28 | + enable subgroup_size_control; |
| 29 | + @compute @workgroup_size(1) |
| 30 | + fn main() {} |
| 31 | + ` |
| 32 | + ); |
| 33 | + }); |
| 34 | + |
| 35 | +g.test('use_subgroup_size_attribute_requires_subgroup_size_control_extension_enabled') |
| 36 | + .desc( |
| 37 | + `Checks that the @subgroup_size attribute is only allowed with the WGSL extension |
| 38 | + subgroup_size_control enabled in the shader and the WebGPU extension subgroup-size-control |
| 39 | + supported on the device.` |
| 40 | + ) |
| 41 | + .params(u => u.combine('enableExtension', [false, true] as const)) |
| 42 | + .beforeAllSubcases(t => { |
| 43 | + t.selectDeviceOrSkipTestCase({ |
| 44 | + requiredFeatures: ['subgroup-size-control' as GPUFeatureName], |
| 45 | + }); |
| 46 | + }) |
| 47 | + .fn(t => { |
| 48 | + const { enableExtension } = t.params; |
| 49 | + |
| 50 | + const kSubgroupSize = 4; |
| 51 | + t.expectCompileResult( |
| 52 | + enableExtension, |
| 53 | + ` |
| 54 | + enable subgroups; |
| 55 | + ${enableExtension ? 'enable subgroup_size_control;' : ''} |
| 56 | + @compute @workgroup_size(${kSubgroupSize}) @subgroup_size(${kSubgroupSize}) |
| 57 | + fn main() {} |
| 58 | + ` |
| 59 | + ); |
| 60 | + }); |
| 61 | + |
| 62 | +g.test('subgroup_size_attribute_only_valid_in_compute_stage') |
| 63 | + .desc( |
| 64 | + `Checks that the @subgroup_size attribute is only valid on a compute shader entry point. |
| 65 | + Applying it to a vertex or fragment entry point must be a compilation error.` |
| 66 | + ) |
| 67 | + .params(u => u.combine('stage', ['compute', 'vertex', 'fragment'] as const)) |
| 68 | + .beforeAllSubcases(t => { |
| 69 | + t.selectDeviceOrSkipTestCase({ |
| 70 | + requiredFeatures: ['subgroup-size-control' as GPUFeatureName], |
| 71 | + }); |
| 72 | + }) |
| 73 | + .fn(t => { |
| 74 | + const { stage } = t.params; |
| 75 | + const kSubgroupSize = 4; |
| 76 | + |
| 77 | + const kStageShaders = { |
| 78 | + compute: ` |
| 79 | + enable subgroups; |
| 80 | + enable subgroup_size_control; |
| 81 | + @compute @workgroup_size(${kSubgroupSize}) @subgroup_size(${kSubgroupSize}) |
| 82 | + fn main() {} |
| 83 | + `, |
| 84 | + vertex: ` |
| 85 | + enable subgroups; |
| 86 | + enable subgroup_size_control; |
| 87 | + @vertex @subgroup_size(${kSubgroupSize}) |
| 88 | + fn main() -> @builtin(position) vec4f { |
| 89 | + return vec4f(0); |
| 90 | + } |
| 91 | + `, |
| 92 | + fragment: ` |
| 93 | + enable subgroups; |
| 94 | + enable subgroup_size_control; |
| 95 | + @fragment @subgroup_size(${kSubgroupSize}) |
| 96 | + fn main() -> @location(0) vec4f { |
| 97 | + return vec4f(0); |
| 98 | + } |
| 99 | + `, |
| 100 | + } as const; |
| 101 | + |
| 102 | + t.expectCompileResult(stage === 'compute', kStageShaders[stage]); |
| 103 | + }); |
0 commit comments