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

[pull] main from gpuweb:main #68

Merged
merged 2 commits into from
Jan 11, 2025
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
56 changes: 0 additions & 56 deletions src/webgpu/api/operation/texture_view/read.spec.ts

This file was deleted.

129 changes: 116 additions & 13 deletions src/webgpu/api/validation/capability_checks/limits/limit_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,19 @@ export function addMaximumLimitUpToDependentLimit(
limits[limit] = value;
}

type LimitCheckParams = {
limit: GPUSupportedLimit;
actualLimit: number;
defaultLimit: number;
};

type LimitCheckFn = (t: LimitTestsImpl, device: GPUDevice, params: LimitCheckParams) => boolean;

export class LimitTestsImpl extends GPUTestBase {
_adapter: GPUAdapter | null = null;
_device: GPUDevice | undefined = undefined;
limit: GPUSupportedLimit = '' as GPUSupportedLimit;
limitTestParams: LimitTestParams = {};
defaultLimit = 0;
adapterLimit = 0;

Expand All @@ -398,6 +407,11 @@ export class LimitTestsImpl extends GPUTestBase {
const gpu = getGPU(this.rec);
this._adapter = await gpu.requestAdapter();
const limit = this.limit;
// MAINTENANCE_TODO: consider removing this skip if the spec has no optional limits.
this.skipIf(
this._adapter?.limits[limit] === undefined && !!this.limitTestParams.limitOptional,
`${limit} is missing but optional for now`
);
this.defaultLimit = getDefaultLimitForAdapter(this.adapter, limit);
this.adapterLimit = this.adapter.limits[limit] as number;
assert(!Number.isNaN(this.defaultLimit));
Expand Down Expand Up @@ -504,16 +518,21 @@ export class LimitTestsImpl extends GPUTestBase {
);
}
} else {
if (requestedLimit <= defaultLimit) {
this.expect(
actualLimit === defaultLimit,
`expected actual actualLimit: ${actualLimit} to equal defaultLimit: ${defaultLimit}`
);
} else {
this.expect(
actualLimit === requestedLimit,
`expected actual actualLimit: ${actualLimit} to equal requestedLimit: ${requestedLimit}`
);
const checked = this.limitTestParams.limitCheckFn
? this.limitTestParams.limitCheckFn(this, device!, { limit, actualLimit, defaultLimit })
: false;
if (!checked) {
if (requestedLimit <= defaultLimit) {
this.expect(
actualLimit === defaultLimit,
`expected actual actualLimit: ${actualLimit} to equal defaultLimit: ${defaultLimit}`
);
} else {
this.expect(
actualLimit === requestedLimit,
`expected actual actualLimit: ${actualLimit} to equal requestedLimit: ${requestedLimit}`
);
}
}
}
}
Expand All @@ -534,6 +553,10 @@ export class LimitTestsImpl extends GPUTestBase {
const { defaultLimit, adapterLimit: maximumLimit } = this;

const requestedLimit = getLimitValue(defaultLimit, maximumLimit, limitValueTest);
this.skipIf(
requestedLimit < 0 && limitValueTest === 'underDefault',
`requestedLimit(${requestedLimit}) for ${this.limit} is < 0`
);
return this._getDeviceWithSpecificLimit(requestedLimit, extraLimits, features);
}

Expand Down Expand Up @@ -1209,12 +1232,21 @@ export class LimitTestsImpl extends GPUTestBase {
}
}

type LimitTestParams = {
limitCheckFn?: LimitCheckFn;
limitOptional?: boolean;
};

/**
* Makes a new LimitTest class so that the tests have access to `limit`
*/
function makeLimitTestFixture(limit: GPUSupportedLimit): typeof LimitTestsImpl {
function makeLimitTestFixture(
limit: GPUSupportedLimit,
params?: LimitTestParams
): typeof LimitTestsImpl {
class LimitTests extends LimitTestsImpl {
override limit = limit;
override limitTestParams = params ?? {};
}

return LimitTests;
Expand All @@ -1225,8 +1257,79 @@ function makeLimitTestFixture(limit: GPUSupportedLimit): typeof LimitTestsImpl {
* writing these tests where I'd copy a test, need to rename a limit in 3-4 places,
* forget one place, and then spend 20-30 minutes wondering why the test was failing.
*/
export function makeLimitTestGroup(limit: GPUSupportedLimit) {
export function makeLimitTestGroup(limit: GPUSupportedLimit, params?: LimitTestParams) {
const description = `API Validation Tests for ${limit}.`;
const g = makeTestGroup(makeLimitTestFixture(limit));
const g = makeTestGroup(makeLimitTestFixture(limit, params));
return { g, description, limit };
}

/**
* Test that limit must be less than dependentLimitName when requesting a device.
*/
export function testMaxStorageXXXInYYYStageDeviceCreationWithDependentLimit(
g: ReturnType<typeof makeLimitTestGroup>['g'],
limit:
| 'maxStorageBuffersInFragmentStage'
| 'maxStorageBuffersInVertexStage'
| 'maxStorageTexturesInFragmentStage'
| 'maxStorageTexturesInVertexStage',
dependentLimitName: 'maxStorageBuffersPerShaderStage' | 'maxStorageTexturesPerShaderStage'
) {
g.test(`validate,${dependentLimitName}`)
.desc(
`Test that adapter.limit.${limit} and requiredLimits.${limit} must be <= ${dependentLimitName}`
)
.params(u => u.combine('useMax', [true, false] as const)) // true case should not reject.
.fn(async t => {
const { useMax } = t.params;
const { adapterLimit: maximumLimit, adapter } = t;

const dependentLimit = adapter.limits[dependentLimitName]!;
t.expect(
maximumLimit <= dependentLimit,
`maximumLimit(${maximumLimit}) is <= adapter.limits.${dependentLimitName}(${dependentLimit})`
);

const dependentEffectiveLimits = useMax
? dependentLimit
: t.getDefaultLimit(dependentLimitName);
const shouldReject = maximumLimit > dependentEffectiveLimits;
t.debug(
`${limit}(${maximumLimit}) > ${dependentLimitName}(${dependentEffectiveLimits}) shouldReject: ${shouldReject}`
);
const device = await t.requestDeviceWithLimits(
adapter,
{
[limit]: maximumLimit,
...(useMax && {
[dependentLimitName]: dependentLimit,
}),
},
shouldReject
);
device?.destroy();
});

g.test(`auto_upgrade,${dependentLimitName}`)
.desc(
`Test that adapter.limit.${limit} is automatically upgraded to ${dependentLimitName} except in compat.`
)
.fn(async t => {
const { adapter, defaultLimit } = t;
const dependentAdapterLimit = adapter.limits[dependentLimitName];
const shouldReject = false;
const device = await t.requestDeviceWithLimits(
adapter,
{
[dependentLimitName]: dependentAdapterLimit,
},
shouldReject
);

const expectedLimit = t.isCompatibility ? defaultLimit : dependentAdapterLimit;
t.expect(
device!.limits[limit] === expectedLimit,
`${limit}(${device!.limits[limit]}) === ${expectedLimit}`
);
});
}
Loading
Loading