Skip to content

Commit

Permalink
Move limits from capability_info.ts to limits.ts
Browse files Browse the repository at this point in the history
This is because navigator_gpu.ts needs the limits.
  • Loading branch information
greggman committed Jan 4, 2025
1 parent c88c1a0 commit e9dd8a1
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 126 deletions.
101 changes: 101 additions & 0 deletions src/common/util/limits.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/* eslint-disable no-sparse-arrays */

import { keysOf, makeTableRenameAndFilter } from './data_tables.js';

export const kMaxUnsignedLongValue = 4294967295;
export const kMaxUnsignedLongLongValue = Number.MAX_SAFE_INTEGER;

/** Info for each entry of GPUSupportedLimits */
const [kLimitInfoKeys, kLimitInfoDefaults, kLimitInfoData] =
/* prettier-ignore */ [
[ 'class', 'core', 'compatibility', 'maximumValue'] as const,
[ 'maximum', , , kMaxUnsignedLongValue] as const, {
'maxTextureDimension1D': [ , 8192, 4096, ],
'maxTextureDimension2D': [ , 8192, 4096, ],
'maxTextureDimension3D': [ , 2048, 1024, ],
'maxTextureArrayLayers': [ , 256, 256, ],

'maxBindGroups': [ , 4, 4, ],
'maxBindGroupsPlusVertexBuffers': [ , 24, 24, ],
'maxBindingsPerBindGroup': [ , 1000, 1000, ],
'maxDynamicUniformBuffersPerPipelineLayout': [ , 8, 8, ],
'maxDynamicStorageBuffersPerPipelineLayout': [ , 4, 4, ],
'maxSampledTexturesPerShaderStage': [ , 16, 16, ],
'maxSamplersPerShaderStage': [ , 16, 16, ],
'maxStorageBuffersPerShaderStage': [ , 8, 4, ],
'maxStorageTexturesPerShaderStage': [ , 4, 4, ],
'maxUniformBuffersPerShaderStage': [ , 12, 12, ],

'maxUniformBufferBindingSize': [ , 65536, 16384, kMaxUnsignedLongLongValue],
'maxStorageBufferBindingSize': [ , 134217728, 134217728, kMaxUnsignedLongLongValue],
'minUniformBufferOffsetAlignment': ['alignment', 256, 256, ],
'minStorageBufferOffsetAlignment': ['alignment', 256, 256, ],

'maxVertexBuffers': [ , 8, 8, ],
'maxBufferSize': [ , 268435456, 268435456, kMaxUnsignedLongLongValue],
'maxVertexAttributes': [ , 16, 16, ],
'maxVertexBufferArrayStride': [ , 2048, 2048, ],
'maxInterStageShaderVariables': [ , 16, 15, ],

'maxColorAttachments': [ , 8, 4, ],
'maxColorAttachmentBytesPerSample': [ , 32, 32, ],

'maxComputeWorkgroupStorageSize': [ , 16384, 16384, ],
'maxComputeInvocationsPerWorkgroup': [ , 256, 128, ],
'maxComputeWorkgroupSizeX': [ , 256, 128, ],
'maxComputeWorkgroupSizeY': [ , 256, 128, ],
'maxComputeWorkgroupSizeZ': [ , 64, 64, ],
'maxComputeWorkgroupsPerDimension': [ , 65535, 65535, ],
} as const];

/**
* Feature levels corresponding to core WebGPU and WebGPU
* in compatibility mode. They can be passed to
* getDefaultLimits though if you have access to an adapter
* it's preferred to use getDefaultLimitsForAdapter.
*/
export const kFeatureLevels = ['core', 'compatibility'] as const;
export type FeatureLevel = (typeof kFeatureLevels)[number];

const kLimitKeys = ['class', 'default', 'maximumValue'] as const;

const kLimitInfoCore = makeTableRenameAndFilter(
{ default: 'core' },
kLimitKeys,
kLimitInfoKeys,
kLimitInfoDefaults,
kLimitInfoData
);

const kLimitInfoCompatibility = makeTableRenameAndFilter(
{ default: 'compatibility' },
kLimitKeys,
kLimitInfoKeys,
kLimitInfoDefaults,
kLimitInfoData
);

const kLimitInfos = {
core: kLimitInfoCore,
compatibility: kLimitInfoCompatibility,
} as const;

export const kLimitClasses = Object.fromEntries(
Object.entries(kLimitInfoCore).map(([k, { class: c }]) => [k, c])
);

export function getDefaultLimits(featureLevel: FeatureLevel) {
return kLimitInfos[featureLevel];
}

export function getDefaultLimitsForAdapter(adapter: GPUAdapter) {
// MAINTENANCE_TODO: Remove casts when GPUAdapter IDL has isCompatibilityMode.
return getDefaultLimits(
(adapter as unknown as { isCompatibilityMode: boolean }).isCompatibilityMode
? 'compatibility'
: 'core'
);
}

/** List of all entries of GPUSupportedLimits. */
export const kLimits = keysOf(kLimitInfoCore);
2 changes: 1 addition & 1 deletion src/common/util/navigator_gpu.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// eslint-disable-next-line import/no-restricted-paths
import { getDefaultLimitsForAdapter } from '../../webgpu/capability_info.js';
import { TestCaseRecorder } from '../framework/fixture.js';
import { globalTestConfig } from '../framework/test_config.js';

import { getDefaultLimitsForAdapter } from './limits.js';
import { ErrorWithExtra, assert, objectEquals } from './util.js';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/stress/adapter/device_allocation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { Fixture } from '../../common/framework/fixture.js';
import { makeTestGroup } from '../../common/framework/test_group.js';
import { attemptGarbageCollection } from '../../common/util/collect_garbage.js';
import { keysOf } from '../../common/util/data_tables.js';
import { getDefaultLimitsForAdapter } from '../../common/util/limits.js';
import { getGPU } from '../../common/util/navigator_gpu.js';
import { assert, iterRange } from '../../common/util/util.js';
import { getDefaultLimitsForAdapter } from '../../webgpu/capability_info.js';

export const g = makeTestGroup(Fixture);

Expand Down
8 changes: 4 additions & 4 deletions src/webgpu/api/operation/adapter/requestDevice.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ potentially limited native resources.

import { Fixture } from '../../../../common/framework/fixture.js';
import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { getGPU } from '../../../../common/util/navigator_gpu.js';
import { assert, assertReject, raceWithRejectOnTimeout } from '../../../../common/util/util.js';
import {
getDefaultLimitsForAdapter,
kFeatureNames,
kLimits,
kLimitClasses,
} from '../../../capability_info.js';
} from '../../../../common/util/limits.js';
import { getGPU } from '../../../../common/util/navigator_gpu.js';
import { assert, assertReject, raceWithRejectOnTimeout } from '../../../../common/util/util.js';
import { kFeatureNames } from '../../../capability_info.js';
import { clamp, isPowerOfTwo } from '../../../util/math.js';

export const g = makeTestGroup(Fixture);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { kUnitCaseParamsBuilder } from '../../../../../common/framework/params_builder.js';
import { makeTestGroup } from '../../../../../common/framework/test_group.js';
import { getDefaultLimitsForAdapter } from '../../../../../common/util/limits.js';
import { getGPU } from '../../../../../common/util/navigator_gpu.js';
import { assert, range, reorder, ReorderOrder } from '../../../../../common/util/util.js';
import { getDefaultLimitsForAdapter } from '../../../../capability_info.js';
import { GPUTestBase } from '../../../../gpu_test.js';

type GPUSupportedLimit = keyof GPUSupportedLimits;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Validation tests for multiDrawIndirect/multiDrawIndexedIndirect on render pass.
import { kUnitCaseParamsBuilder } from '../../../../../../common/framework/params_builder.js';
import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
import {
GPUConst,
kMaxUnsignedLongValue,
kMaxUnsignedLongLongValue,
} from '../../../../../constants.js';
} from '../../../../../../common/util/limits.js';
import { GPUConst } from '../../../../../constants.js';
import { kResourceStates } from '../../../../../gpu_test.js';
import { ValidationTest } from '../../../validation_test.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ TODO(#3363): Make this into a MaxLimitTest and increase kMaxColorAttachments.
`;

import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { getDefaultLimits } from '../../../../common/util/limits.js';
import { range } from '../../../../common/util/util.js';
import { getDefaultLimits } from '../../../capability_info.js';
import {
computeBytesPerSampleFromFormats,
kAllTextureFormats,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ TODO(#3363): Make this into a MaxLimitTest and increase kMaxColorAttachments.
`;

import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { getDefaultLimits } from '../../../../common/util/limits.js';
import { range } from '../../../../common/util/util.js';
import { getDefaultLimits, kTextureSampleCounts } from '../../../capability_info.js';
import { kTextureSampleCounts } from '../../../capability_info.js';
import {
kRegularTextureFormats,
kSizedDepthStencilFormats,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ TODO: review for completeness
`;

import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { getDefaultLimits } from '../../../../common/util/limits.js';
import { range } from '../../../../common/util/util.js';
import { getDefaultLimits, kQueryTypes } from '../../../capability_info.js';
import { kQueryTypes } from '../../../capability_info.js';
import { GPUConst } from '../../../constants.js';
import {
computeBytesPerSampleFromFormats,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ TODO(#3363): Make this into a MaxLimitTest and increase kMaxColorAttachments.
`;

import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { getDefaultLimits } from '../../../../common/util/limits.js';
import { assert, range } from '../../../../common/util/util.js';
import {
getDefaultLimits,
IsDualSourceBlendingFactor,
kBlendFactors,
kBlendOperations,
Expand Down
106 changes: 3 additions & 103 deletions src/webgpu/capability_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@

/* eslint-disable no-sparse-arrays */

import {
keysOf,
makeTable,
makeTableRenameAndFilter,
numericKeysOf,
valueof,
} from '../common/util/data_tables.js';
import { keysOf, makeTable, numericKeysOf, valueof } from '../common/util/data_tables.js';
import { kLimits } from '../common/util/limits.js';
import { assertTypeTrue, TypeEqual } from '../common/util/types.js';
import { unreachable } from '../common/util/util.js';

import { GPUConst, kMaxUnsignedLongValue, kMaxUnsignedLongLongValue } from './constants.js';
import { GPUConst } from './constants.js';

// Base device limits can be found in constants.ts.

Expand Down Expand Up @@ -710,101 +705,6 @@ assertTypeTrue<TypeEqual<GPUPrimitiveTopology, (typeof kPrimitiveTopology)[numbe
export const kIndexFormat: readonly GPUIndexFormat[] = ['uint16', 'uint32'];
assertTypeTrue<TypeEqual<GPUIndexFormat, (typeof kIndexFormat)[number]>>();

/** Info for each entry of GPUSupportedLimits */
const [kLimitInfoKeys, kLimitInfoDefaults, kLimitInfoData] =
/* prettier-ignore */ [
[ 'class', 'core', 'compatibility', 'maximumValue'] as const,
[ 'maximum', , , kMaxUnsignedLongValue] as const, {
'maxTextureDimension1D': [ , 8192, 4096, ],
'maxTextureDimension2D': [ , 8192, 4096, ],
'maxTextureDimension3D': [ , 2048, 1024, ],
'maxTextureArrayLayers': [ , 256, 256, ],

'maxBindGroups': [ , 4, 4, ],
'maxBindGroupsPlusVertexBuffers': [ , 24, 24, ],
'maxBindingsPerBindGroup': [ , 1000, 1000, ],
'maxDynamicUniformBuffersPerPipelineLayout': [ , 8, 8, ],
'maxDynamicStorageBuffersPerPipelineLayout': [ , 4, 4, ],
'maxSampledTexturesPerShaderStage': [ , 16, 16, ],
'maxSamplersPerShaderStage': [ , 16, 16, ],
'maxStorageBuffersPerShaderStage': [ , 8, 4, ],
'maxStorageTexturesPerShaderStage': [ , 4, 4, ],
'maxUniformBuffersPerShaderStage': [ , 12, 12, ],

'maxUniformBufferBindingSize': [ , 65536, 16384, kMaxUnsignedLongLongValue],
'maxStorageBufferBindingSize': [ , 134217728, 134217728, kMaxUnsignedLongLongValue],
'minUniformBufferOffsetAlignment': ['alignment', 256, 256, ],
'minStorageBufferOffsetAlignment': ['alignment', 256, 256, ],

'maxVertexBuffers': [ , 8, 8, ],
'maxBufferSize': [ , 268435456, 268435456, kMaxUnsignedLongLongValue],
'maxVertexAttributes': [ , 16, 16, ],
'maxVertexBufferArrayStride': [ , 2048, 2048, ],
'maxInterStageShaderVariables': [ , 16, 15, ],

'maxColorAttachments': [ , 8, 4, ],
'maxColorAttachmentBytesPerSample': [ , 32, 32, ],

'maxComputeWorkgroupStorageSize': [ , 16384, 16384, ],
'maxComputeInvocationsPerWorkgroup': [ , 256, 128, ],
'maxComputeWorkgroupSizeX': [ , 256, 128, ],
'maxComputeWorkgroupSizeY': [ , 256, 128, ],
'maxComputeWorkgroupSizeZ': [ , 64, 64, ],
'maxComputeWorkgroupsPerDimension': [ , 65535, 65535, ],
} as const];

/**
* Feature levels corresponding to core WebGPU and WebGPU
* in compatibility mode. They can be passed to
* getDefaultLimits though if you have access to an adapter
* it's preferred to use getDefaultLimitsForAdapter.
*/
export const kFeatureLevels = ['core', 'compatibility'] as const;
export type FeatureLevel = (typeof kFeatureLevels)[number];

const kLimitKeys = ['class', 'default', 'maximumValue'] as const;

const kLimitInfoCore = makeTableRenameAndFilter(
{ default: 'core' },
kLimitKeys,
kLimitInfoKeys,
kLimitInfoDefaults,
kLimitInfoData
);

const kLimitInfoCompatibility = makeTableRenameAndFilter(
{ default: 'compatibility' },
kLimitKeys,
kLimitInfoKeys,
kLimitInfoDefaults,
kLimitInfoData
);

const kLimitInfos = {
core: kLimitInfoCore,
compatibility: kLimitInfoCompatibility,
} as const;

export const kLimitClasses = Object.fromEntries(
Object.entries(kLimitInfoCore).map(([k, { class: c }]) => [k, c])
);

export function getDefaultLimits(featureLevel: FeatureLevel) {
return kLimitInfos[featureLevel];
}

export function getDefaultLimitsForAdapter(adapter: GPUAdapter) {
// MAINTENANCE_TODO: Remove casts when GPUAdapter IDL has isCompatibilityMode.
return getDefaultLimits(
(adapter as unknown as { isCompatibilityMode: boolean }).isCompatibilityMode
? 'compatibility'
: 'core'
);
}

/** List of all entries of GPUSupportedLimits. */
export const kLimits = keysOf(kLimitInfoCore);

/**
* The number of color attachments to test.
* The CTS needs to generate a consistent list of tests.
Expand Down
3 changes: 0 additions & 3 deletions src/webgpu/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ export const GPUConst = {
MapMode,
} as const;

export const kMaxUnsignedLongValue = 4294967295;
export const kMaxUnsignedLongLongValue = Number.MAX_SAFE_INTEGER;

export const kInterpolationSampling = ['center', 'centroid', 'sample', 'first', 'either'] as const;
export const kInterpolationType = ['perspective', 'linear', 'flat'] as const;
export type InterpolationType = (typeof kInterpolationType)[number];
Expand Down
8 changes: 2 additions & 6 deletions src/webgpu/gpu_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
TestParams,
} from '../common/framework/fixture.js';
import { globalTestConfig } from '../common/framework/test_config.js';
import { getDefaultLimits, kLimits } from '../common/util/limits.js';
import { getGPU } from '../common/util/navigator_gpu.js';
import {
assert,
Expand All @@ -21,12 +22,7 @@ import {
unreachable,
} from '../common/util/util.js';

import {
getDefaultLimits,
kLimits,
kQueryTypeInfo,
WGSLLanguageFeature,
} from './capability_info.js';
import { kQueryTypeInfo, WGSLLanguageFeature } from './capability_info.js';
import { InterpolationType, InterpolationSampling } from './constants.js';
import {
kTextureFormatInfo,
Expand Down
2 changes: 1 addition & 1 deletion src/webgpu/util/device_pool.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { SkipTestCase, TestCaseRecorder } from '../../common/framework/fixture.js';
import { attemptGarbageCollection } from '../../common/util/collect_garbage.js';
import { getDefaultLimits, kLimits } from '../../common/util/limits.js';
import { getGPU, getDefaultRequestAdapterOptions } from '../../common/util/navigator_gpu.js';
import {
assert,
raceWithRejectOnTimeout,
assertReject,
unreachable,
} from '../../common/util/util.js';
import { getDefaultLimits, kLimits } from '../capability_info.js';

// MUST_NOT_BE_IMPORTED_BY_DATA_CACHE
// This file should not be transitively imported by .cache.ts files
Expand Down

0 comments on commit e9dd8a1

Please sign in to comment.