|
| 1 | +import { |
| 2 | + range, |
| 3 | + reorder, |
| 4 | + kReorderOrderKeys, |
| 5 | + ReorderOrder, |
| 6 | + assert, |
| 7 | +} from '../../../../../common/util/util.js'; |
| 8 | + |
| 9 | +import { |
| 10 | + kMaximumLimitBaseParams, |
| 11 | + makeLimitTestGroup, |
| 12 | + kBindGroupTests, |
| 13 | + getPipelineTypeForBindingCombination, |
| 14 | + getPerStageWGSLForBindingCombination, |
| 15 | + LimitsRequest, |
| 16 | + getStageVisibilityForBinidngCombination, |
| 17 | + testMaxStorageXXXInYYYStageDeviceCreationWithDependentLimit, |
| 18 | +} from './limit_utils.js'; |
| 19 | + |
| 20 | +const limit = 'maxStorageBuffersInFragmentStage'; |
| 21 | +const dependentLimitName = 'maxStorageBuffersPerShaderStage'; |
| 22 | + |
| 23 | +const kExtraLimits: LimitsRequest = { |
| 24 | + maxBindingsPerBindGroup: 'adapterLimit', |
| 25 | + maxBindGroups: 'adapterLimit', |
| 26 | + [dependentLimitName]: 'adapterLimit', |
| 27 | +}; |
| 28 | + |
| 29 | +export const { g, description } = makeLimitTestGroup(limit, { |
| 30 | + // MAINTAINANCE_TODO: remove once this limit is required. |
| 31 | + limitOptional: true, |
| 32 | + limitCheckFn(t, device, { actualLimit }) { |
| 33 | + if (!t.isCompatibility) { |
| 34 | + const expectedLimit = device.limits[dependentLimitName]; |
| 35 | + t.expect( |
| 36 | + actualLimit === expectedLimit, |
| 37 | + `expected actual actualLimit: ${actualLimit} to equal ${dependentLimitName}: ${expectedLimit}` |
| 38 | + ); |
| 39 | + return true; |
| 40 | + } |
| 41 | + return false; |
| 42 | + }, |
| 43 | +}); |
| 44 | + |
| 45 | +function createBindGroupLayout( |
| 46 | + device: GPUDevice, |
| 47 | + visibility: number, |
| 48 | + type: GPUBufferBindingType, |
| 49 | + order: ReorderOrder, |
| 50 | + numBindings: number |
| 51 | +) { |
| 52 | + const bindGroupLayoutDescription: GPUBindGroupLayoutDescriptor = { |
| 53 | + entries: reorder( |
| 54 | + order, |
| 55 | + range(numBindings, i => ({ |
| 56 | + binding: i, |
| 57 | + visibility, |
| 58 | + buffer: { type }, |
| 59 | + })) |
| 60 | + ), |
| 61 | + }; |
| 62 | + return device.createBindGroupLayout(bindGroupLayoutDescription); |
| 63 | +} |
| 64 | + |
| 65 | +g.test('createBindGroupLayout,at_over') |
| 66 | + .desc( |
| 67 | + ` |
| 68 | + Test using at and over ${limit} limit in createBindGroupLayout |
| 69 | +
|
| 70 | + Note: We also test order to make sure the implementation isn't just looking |
| 71 | + at just the last entry. |
| 72 | + ` |
| 73 | + ) |
| 74 | + .params( |
| 75 | + kMaximumLimitBaseParams |
| 76 | + .combine('type', ['storage', 'read-only-storage'] as GPUBufferBindingType[]) |
| 77 | + .combine('order', kReorderOrderKeys) |
| 78 | + ) |
| 79 | + .fn(async t => { |
| 80 | + const { limitTest, testValueName, order, type } = t.params; |
| 81 | + |
| 82 | + await t.testDeviceWithRequestedMaximumLimits( |
| 83 | + limitTest, |
| 84 | + testValueName, |
| 85 | + async ({ device, testValue, shouldError }) => { |
| 86 | + t.skipIf( |
| 87 | + t.adapter.limits.maxBindingsPerBindGroup < testValue, |
| 88 | + `maxBindingsPerBindGroup = ${t.adapter.limits.maxBindingsPerBindGroup} which is less than ${testValue}` |
| 89 | + ); |
| 90 | + |
| 91 | + const visibility = GPUShaderStage.FRAGMENT; |
| 92 | + await t.expectValidationError(() => { |
| 93 | + createBindGroupLayout(device, visibility, type, order, testValue); |
| 94 | + }, shouldError); |
| 95 | + }, |
| 96 | + kExtraLimits |
| 97 | + ); |
| 98 | + }); |
| 99 | + |
| 100 | +g.test('createPipelineLayout,at_over') |
| 101 | + .desc( |
| 102 | + ` |
| 103 | + Test using at and over ${limit} limit in createPipelineLayout |
| 104 | +
|
| 105 | + Note: We also test order to make sure the implementation isn't just looking |
| 106 | + at just the last entry. |
| 107 | + ` |
| 108 | + ) |
| 109 | + .params( |
| 110 | + kMaximumLimitBaseParams |
| 111 | + .combine('type', ['storage', 'read-only-storage'] as GPUBufferBindingType[]) |
| 112 | + .combine('order', kReorderOrderKeys) |
| 113 | + ) |
| 114 | + .fn(async t => { |
| 115 | + const { limitTest, testValueName, order, type } = t.params; |
| 116 | + |
| 117 | + await t.testDeviceWithRequestedMaximumLimits( |
| 118 | + limitTest, |
| 119 | + testValueName, |
| 120 | + async ({ device, testValue, shouldError, actualLimit }) => { |
| 121 | + const visibility = GPUShaderStage.FRAGMENT; |
| 122 | + |
| 123 | + t.skipIf( |
| 124 | + actualLimit === 0, |
| 125 | + `can not make a bindGroupLayout to test createPipelineLaoyout if the actaul limit is 0` |
| 126 | + ); |
| 127 | + |
| 128 | + const maxBindingsPerBindGroup = Math.min( |
| 129 | + t.device.limits.maxBindingsPerBindGroup, |
| 130 | + actualLimit |
| 131 | + ); |
| 132 | + |
| 133 | + const kNumGroups = Math.ceil(testValue / maxBindingsPerBindGroup); |
| 134 | + |
| 135 | + // Not sure what to do in this case but best we get notified if it happens. |
| 136 | + assert(kNumGroups <= t.device.limits.maxBindGroups); |
| 137 | + |
| 138 | + const bindGroupLayouts = range(kNumGroups, i => { |
| 139 | + const numInGroup = Math.min( |
| 140 | + testValue - i * maxBindingsPerBindGroup, |
| 141 | + maxBindingsPerBindGroup |
| 142 | + ); |
| 143 | + return createBindGroupLayout(device, visibility, type, order, numInGroup); |
| 144 | + }); |
| 145 | + |
| 146 | + await t.expectValidationError( |
| 147 | + () => device.createPipelineLayout({ bindGroupLayouts }), |
| 148 | + shouldError |
| 149 | + ); |
| 150 | + }, |
| 151 | + kExtraLimits |
| 152 | + ); |
| 153 | + }); |
| 154 | + |
| 155 | +g.test('createPipeline,at_over') |
| 156 | + .desc( |
| 157 | + ` |
| 158 | + Test using createRenderPipeline(Async) and createComputePipeline(Async) at and over ${limit} limit |
| 159 | +
|
| 160 | + Note: We also test order to make sure the implementation isn't just looking |
| 161 | + at just the last entry. |
| 162 | + ` |
| 163 | + ) |
| 164 | + .params( |
| 165 | + kMaximumLimitBaseParams |
| 166 | + .combine('async', [false, true] as const) |
| 167 | + .beginSubcases() |
| 168 | + .combine('order', kReorderOrderKeys) |
| 169 | + .combine('bindGroupTest', kBindGroupTests) |
| 170 | + ) |
| 171 | + .fn(async t => { |
| 172 | + const { limitTest, testValueName, async, order, bindGroupTest } = t.params; |
| 173 | + const bindingCombination = 'fragment'; |
| 174 | + const pipelineType = getPipelineTypeForBindingCombination(bindingCombination); |
| 175 | + |
| 176 | + await t.testDeviceWithRequestedMaximumLimits( |
| 177 | + limitTest, |
| 178 | + testValueName, |
| 179 | + async ({ device, testValue, actualLimit, shouldError }) => { |
| 180 | + t.skipIf( |
| 181 | + bindGroupTest === 'sameGroup' && testValue > device.limits.maxBindingsPerBindGroup, |
| 182 | + `can not test ${testValue} bindings in same group because maxBindingsPerBindGroup = ${device.limits.maxBindingsPerBindGroup}` |
| 183 | + ); |
| 184 | + |
| 185 | + const visibility = getStageVisibilityForBinidngCombination(bindingCombination); |
| 186 | + t.skipIfNotEnoughStorageBuffersInStage(visibility, testValue); |
| 187 | + |
| 188 | + const code = getPerStageWGSLForBindingCombination( |
| 189 | + bindingCombination, |
| 190 | + order, |
| 191 | + bindGroupTest, |
| 192 | + (i, j) => `var<storage> u${j}_${i}: f32`, |
| 193 | + (i, j) => `_ = u${j}_${i};`, |
| 194 | + device.limits.maxBindGroups, |
| 195 | + testValue |
| 196 | + ); |
| 197 | + const module = device.createShaderModule({ code }); |
| 198 | + |
| 199 | + await t.testCreatePipeline( |
| 200 | + pipelineType, |
| 201 | + async, |
| 202 | + module, |
| 203 | + shouldError, |
| 204 | + `actualLimit: ${actualLimit}, testValue: ${testValue}\n:${code}` |
| 205 | + ); |
| 206 | + }, |
| 207 | + kExtraLimits |
| 208 | + ); |
| 209 | + }); |
| 210 | + |
| 211 | +testMaxStorageXXXInYYYStageDeviceCreationWithDependentLimit(g, limit, dependentLimitName); |
0 commit comments