Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the number of subcases in null_bind_group_layouts #4107

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/common/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,15 @@ export function mapLazy<T, R>(xs: Iterable<T>, f: (x: T) => R): Iterable<R> {
};
}

/** Count the number of elements `x` for which `predicate(x)` is true. */
export function count<T>(xs: Iterable<T>, predicate: (x: T) => boolean): number {
let count = 0;
for (const x of xs) {
if (predicate(x)) count++;
}
return count;
}

const ReorderOrders = {
forward: true,
backward: true,
Expand Down
220 changes: 110 additions & 110 deletions src/resources/cache/hashes.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 16 additions & 58 deletions src/webgpu/api/validation/createPipelineLayout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ TODO: review existing tests, write descriptions, and make sure tests are complet
`;

import { makeTestGroup } from '../../../common/framework/test_group.js';
import { count } from '../../../common/util/util.js';
import { bufferBindingTypeInfo, kBufferBindingTypes } from '../../capability_info.js';
import { GPUConst } from '../../constants.js';

Expand Down Expand Up @@ -174,41 +175,17 @@ g.test('bind_group_layouts,null_bind_group_layouts')
)
.paramsSubcasesOnly(u =>
u //
.combine('bindGroupLayoutCount', [1, 2, 3, 4] as const)
.combine('bindGroupLayout0', MaybeNullBindGroupLayoutTypes)
.expand('bindGroupLayout1', p =>
p.bindGroupLayoutCount > 1 ? MaybeNullBindGroupLayoutTypes : (['Null'] as const)
)
.expand('bindGroupLayout2', p =>
p.bindGroupLayoutCount > 2 ? MaybeNullBindGroupLayoutTypes : (['Null'] as const)
)
.expand('bindGroupLayout3', p =>
p.bindGroupLayoutCount > 3 ? MaybeNullBindGroupLayoutTypes : (['Null'] as const)
)
.filter(p => {
// Only test cases where at least one of the bind group layouts is null.
const allBGLs = [
p.bindGroupLayout0,
p.bindGroupLayout1,
p.bindGroupLayout2,
p.bindGroupLayout3,
];
const bgls = allBGLs.slice(0, p.bindGroupLayoutCount);
return bgls.includes('Null') || bgls.includes('Undefined');
})
.combine('_bglCount', [1, 2, 3, 4] as const)
.combine('_bgl0', MaybeNullBindGroupLayoutTypes)
.expand('_bgl1', p => (p._bglCount > 1 ? MaybeNullBindGroupLayoutTypes : (['Null'] as const)))
.expand('_bgl2', p => (p._bglCount > 2 ? MaybeNullBindGroupLayoutTypes : (['Null'] as const)))
.expand('_bgl3', p => (p._bglCount > 3 ? MaybeNullBindGroupLayoutTypes : (['Null'] as const)))
// Flatten the result down into a single subcase arg which is an array of BGL types.
.expand('bindGroupLayouts', p => [[p._bgl0, p._bgl1, p._bgl2, p._bgl3].slice(0, p._bglCount)])
// Only test combinations where exactly one of the BGLs is null|undefined|empty.
.filter(p => count(p.bindGroupLayouts, x => x !== 'NonEmpty') === 1)
)
.fn(t => {
const {
bindGroupLayoutCount,
bindGroupLayout0,
bindGroupLayout1,
bindGroupLayout2,
bindGroupLayout3,
} = t.params;

const emptyBindGroupLayout = t.device.createBindGroupLayout({
entries: [],
});
const nonEmptyBindGroupLayout = t.device.createBindGroupLayout({
entries: [
{
Expand All @@ -219,37 +196,18 @@ g.test('bind_group_layouts,null_bind_group_layouts')
],
});

const bindGroupLayouts: (GPUBindGroupLayout | null | undefined)[] = [];

const AddBindGroupLayout = function (
bindGroupLayoutType: (typeof MaybeNullBindGroupLayoutTypes)[number]
) {
const bindGroupLayouts = t.params.bindGroupLayouts.map(bindGroupLayoutType => {
switch (bindGroupLayoutType) {
case 'Null':
bindGroupLayouts.push(null);
break;
return null;
case 'Undefined':
bindGroupLayouts.push(undefined);
break;
return undefined;
case 'Empty':
bindGroupLayouts.push(emptyBindGroupLayout);
break;
return t.device.createBindGroupLayout({ entries: [] });
case 'NonEmpty':
bindGroupLayouts.push(nonEmptyBindGroupLayout);
break;
return nonEmptyBindGroupLayout;
}
};

AddBindGroupLayout(bindGroupLayout0);
if (bindGroupLayoutCount > 1) {
AddBindGroupLayout(bindGroupLayout1);
}
if (bindGroupLayoutCount > 2) {
AddBindGroupLayout(bindGroupLayout2);
}
if (bindGroupLayoutCount > 3) {
AddBindGroupLayout(bindGroupLayout3);
}
});

const kShouldError = false;
t.expectValidationError(() => {
Expand Down
Loading