-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test maxStorage(Buffers/Textures)In(Fragment/Vertex)Stage
- Loading branch information
Showing
5 changed files
with
943 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
211 changes: 211 additions & 0 deletions
211
src/webgpu/api/validation/capability_checks/limits/maxStorageBuffersInFragmentStage.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
import { | ||
range, | ||
reorder, | ||
kReorderOrderKeys, | ||
ReorderOrder, | ||
assert, | ||
} from '../../../../../common/util/util.js'; | ||
|
||
import { | ||
kMaximumLimitBaseParams, | ||
makeLimitTestGroup, | ||
kBindGroupTests, | ||
getPipelineTypeForBindingCombination, | ||
getPerStageWGSLForBindingCombination, | ||
LimitsRequest, | ||
getStageVisibilityForBinidngCombination, | ||
testMaxStorageXXXInYYYStageDeviceCreationWithDependentLimit, | ||
} from './limit_utils.js'; | ||
|
||
const limit = 'maxStorageBuffersInFragmentStage'; | ||
const dependentLimitName = 'maxStorageBuffersPerShaderStage'; | ||
|
||
const kExtraLimits: LimitsRequest = { | ||
maxBindingsPerBindGroup: 'adapterLimit', | ||
maxBindGroups: 'adapterLimit', | ||
[dependentLimitName]: 'adapterLimit', | ||
}; | ||
|
||
export const { g, description } = makeLimitTestGroup(limit, { | ||
// MAINTAINANCE_TODO: remove once this limit is required. | ||
limitOptional: true, | ||
limitCheckFn(t, device, { actualLimit }) { | ||
if (!t.isCompatibility) { | ||
const expectedLimit = device.limits[dependentLimitName]; | ||
t.expect( | ||
actualLimit === expectedLimit, | ||
`expected actual actualLimit: ${actualLimit} to equal ${dependentLimitName}: ${expectedLimit}` | ||
); | ||
return true; | ||
} | ||
return false; | ||
}, | ||
}); | ||
|
||
function createBindGroupLayout( | ||
device: GPUDevice, | ||
visibility: number, | ||
type: GPUBufferBindingType, | ||
order: ReorderOrder, | ||
numBindings: number | ||
) { | ||
const bindGroupLayoutDescription: GPUBindGroupLayoutDescriptor = { | ||
entries: reorder( | ||
order, | ||
range(numBindings, i => ({ | ||
binding: i, | ||
visibility, | ||
buffer: { type }, | ||
})) | ||
), | ||
}; | ||
return device.createBindGroupLayout(bindGroupLayoutDescription); | ||
} | ||
|
||
g.test('createBindGroupLayout,at_over') | ||
.desc( | ||
` | ||
Test using at and over ${limit} limit in createBindGroupLayout | ||
Note: We also test order to make sure the implementation isn't just looking | ||
at just the last entry. | ||
` | ||
) | ||
.params( | ||
kMaximumLimitBaseParams | ||
.combine('type', ['storage', 'read-only-storage'] as GPUBufferBindingType[]) | ||
.combine('order', kReorderOrderKeys) | ||
) | ||
.fn(async t => { | ||
const { limitTest, testValueName, order, type } = t.params; | ||
|
||
await t.testDeviceWithRequestedMaximumLimits( | ||
limitTest, | ||
testValueName, | ||
async ({ device, testValue, shouldError }) => { | ||
t.skipIf( | ||
t.adapter.limits.maxBindingsPerBindGroup < testValue, | ||
`maxBindingsPerBindGroup = ${t.adapter.limits.maxBindingsPerBindGroup} which is less than ${testValue}` | ||
); | ||
|
||
const visibility = GPUShaderStage.FRAGMENT; | ||
await t.expectValidationError(() => { | ||
createBindGroupLayout(device, visibility, type, order, testValue); | ||
}, shouldError); | ||
}, | ||
kExtraLimits | ||
); | ||
}); | ||
|
||
g.test('createPipelineLayout,at_over') | ||
.desc( | ||
` | ||
Test using at and over ${limit} limit in createPipelineLayout | ||
Note: We also test order to make sure the implementation isn't just looking | ||
at just the last entry. | ||
` | ||
) | ||
.params( | ||
kMaximumLimitBaseParams | ||
.combine('type', ['storage', 'read-only-storage'] as GPUBufferBindingType[]) | ||
.combine('order', kReorderOrderKeys) | ||
) | ||
.fn(async t => { | ||
const { limitTest, testValueName, order, type } = t.params; | ||
|
||
await t.testDeviceWithRequestedMaximumLimits( | ||
limitTest, | ||
testValueName, | ||
async ({ device, testValue, shouldError, actualLimit }) => { | ||
const visibility = GPUShaderStage.FRAGMENT; | ||
|
||
t.skipIf( | ||
actualLimit === 0, | ||
`can not make a bindGroupLayout to test createPipelineLaoyout if the actaul limit is 0` | ||
); | ||
|
||
const maxBindingsPerBindGroup = Math.min( | ||
t.device.limits.maxBindingsPerBindGroup, | ||
actualLimit | ||
); | ||
|
||
const kNumGroups = Math.ceil(testValue / maxBindingsPerBindGroup); | ||
|
||
// Not sure what to do in this case but best we get notified if it happens. | ||
assert(kNumGroups <= t.device.limits.maxBindGroups); | ||
|
||
const bindGroupLayouts = range(kNumGroups, i => { | ||
const numInGroup = Math.min( | ||
testValue - i * maxBindingsPerBindGroup, | ||
maxBindingsPerBindGroup | ||
); | ||
return createBindGroupLayout(device, visibility, type, order, numInGroup); | ||
}); | ||
|
||
await t.expectValidationError( | ||
() => device.createPipelineLayout({ bindGroupLayouts }), | ||
shouldError | ||
); | ||
}, | ||
kExtraLimits | ||
); | ||
}); | ||
|
||
g.test('createPipeline,at_over') | ||
.desc( | ||
` | ||
Test using createRenderPipeline(Async) and createComputePipeline(Async) at and over ${limit} limit | ||
Note: We also test order to make sure the implementation isn't just looking | ||
at just the last entry. | ||
` | ||
) | ||
.params( | ||
kMaximumLimitBaseParams | ||
.combine('async', [false, true] as const) | ||
.beginSubcases() | ||
.combine('order', kReorderOrderKeys) | ||
.combine('bindGroupTest', kBindGroupTests) | ||
) | ||
.fn(async t => { | ||
const { limitTest, testValueName, async, order, bindGroupTest } = t.params; | ||
const bindingCombination = 'fragment'; | ||
const pipelineType = getPipelineTypeForBindingCombination(bindingCombination); | ||
|
||
await t.testDeviceWithRequestedMaximumLimits( | ||
limitTest, | ||
testValueName, | ||
async ({ device, testValue, actualLimit, shouldError }) => { | ||
t.skipIf( | ||
bindGroupTest === 'sameGroup' && testValue > device.limits.maxBindingsPerBindGroup, | ||
`can not test ${testValue} bindings in same group because maxBindingsPerBindGroup = ${device.limits.maxBindingsPerBindGroup}` | ||
); | ||
|
||
const visibility = getStageVisibilityForBinidngCombination(bindingCombination); | ||
t.skipIfNotEnoughStorageBuffersInStage(visibility, testValue); | ||
|
||
const code = getPerStageWGSLForBindingCombination( | ||
bindingCombination, | ||
order, | ||
bindGroupTest, | ||
(i, j) => `var<storage> u${j}_${i}: f32`, | ||
(i, j) => `_ = u${j}_${i};`, | ||
device.limits.maxBindGroups, | ||
testValue | ||
); | ||
const module = device.createShaderModule({ code }); | ||
|
||
await t.testCreatePipeline( | ||
pipelineType, | ||
async, | ||
module, | ||
shouldError, | ||
`actualLimit: ${actualLimit}, testValue: ${testValue}\n:${code}` | ||
); | ||
}, | ||
kExtraLimits | ||
); | ||
}); | ||
|
||
testMaxStorageXXXInYYYStageDeviceCreationWithDependentLimit(g, limit, dependentLimitName); |
Oops, something went wrong.