Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Jan 6, 2025
1 parent e3d58ff commit 6cea535
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ g.test('maxStorageBuffersTexturesInVertexFragmentStage')
: 'maxStorageTexturesPerShaderStage';
const perStageLimit = device.limits[perStageLimitName];

t.debug(`{${limit}(${inStageLimit}), ${perStageLimitName}(${perStageLimit}})`);
t.debug(`${limit}(${inStageLimit}), ${perStageLimitName}(${perStageLimit})`);

t.skipIf(inStageLimit === 0, `${limit} is 0`);
t.skipIf(
!(inStageLimit < perStageLimit),
`{${limit}(${inStageLimit}) is not less than ${perStageLimitName}(${perStageLimit}})`
`${limit}(${inStageLimit}) is not less than ${perStageLimitName}(${perStageLimit})`
);

const visibility = limit.includes('Fragment') ? GPUShaderStage.FRAGMENT : GPUShaderStage.VERTEX;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ g.test('maxStorageBuffersTexturesInVertexFragmentStage')
: 'maxStorageTexturesPerShaderStage';
const perStageLimit = device.limits[perStageLimitName];

t.debug(`{${limit}(${inStageLimit}), ${perStageLimitName}(${perStageLimit}})`);
t.debug(`${limit}(${inStageLimit}), ${perStageLimitName}(${perStageLimit})`);

t.skipIf(inStageLimit === 0, `${limit} is 0`);
t.skipIf(
!(inStageLimit < perStageLimit),
`{${limit}(${inStageLimit}) is not less than ${perStageLimitName}(${perStageLimit}})`
`${limit}(${inStageLimit}) is not less than ${perStageLimitName}(${perStageLimit})`
);

const typeWGSLFn = isBuffer
Expand Down
23 changes: 22 additions & 1 deletion src/webgpu/gpu_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,27 @@ function getAdapterLimitsAsDeviceRequiredLimits(adapter: GPUAdapter) {
return requiredLimits;
}

/**
* Removes limits that don't exist on the adapter.
* A test might request a new limit that not all implementions support. The test itself
* should check the requested limit using code that expects undefined.
*
* ```ts
* t.skipIf(limit < 2); // BAD! Doesn't skip if unsupported beause undefined is never less than 2.
* t.skipIf(!(limit >= 2)); // Good. Skips if limits is not >= 2. undefined is not >= 2.
* ```
*/
function removeNonExistantLimits(adapter: GPUAdapter, limits: Record<string, GPUSize64>) {
const filteredLimits: Record<string, GPUSize64> = {};
const adapterLimits = adapter.limits as unknown as Record<string, GPUSize64>;
for (const [limit, value] of Object.entries(limits)) {
if (adapterLimits[limit] !== undefined) {
filteredLimits[limit] = value;
}
}
return filteredLimits;
}

function applyLimitsToDescriptor(
adapter: GPUAdapter,
desc: CanonicalDeviceDescriptor | undefined,
Expand All @@ -1307,7 +1328,7 @@ function applyLimitsToDescriptor(
requiredFeatures: [],
defaultQueue: {},
...desc,
requiredLimits: getRequiredLimits(adapter),
requiredLimits: removeNonExistantLimits(adapter, getRequiredLimits(adapter)),
};
return descWithMaxLimits;
}
Expand Down

0 comments on commit 6cea535

Please sign in to comment.