From e9dd8a1dba8acae531a86f8f6bdf8a9b139e95c7 Mon Sep 17 00:00:00 2001 From: Gregg Tavares Date: Fri, 3 Jan 2025 22:28:08 -0800 Subject: [PATCH] Move limits from capability_info.ts to limits.ts This is because navigator_gpu.ts needs the limits. --- src/common/util/limits.ts | 101 +++++++++++++++++ src/common/util/navigator_gpu.ts | 2 +- src/stress/adapter/device_allocation.spec.ts | 2 +- .../operation/adapter/requestDevice.spec.ts | 8 +- .../capability_checks/limits/limit_utils.ts | 2 +- .../cmds/render/indirect_multi_draw.spec.ts | 4 +- .../createRenderBundleEncoder.spec.ts | 2 +- .../attachment_compatibility.spec.ts | 3 +- .../render_pass_descriptor.spec.ts | 3 +- .../render_pipeline/fragment_state.spec.ts | 2 +- src/webgpu/capability_info.ts | 106 +----------------- src/webgpu/constants.ts | 3 - src/webgpu/gpu_test.ts | 8 +- src/webgpu/util/device_pool.ts | 2 +- 14 files changed, 122 insertions(+), 126 deletions(-) create mode 100644 src/common/util/limits.ts diff --git a/src/common/util/limits.ts b/src/common/util/limits.ts new file mode 100644 index 000000000000..f0a6c9971902 --- /dev/null +++ b/src/common/util/limits.ts @@ -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); diff --git a/src/common/util/navigator_gpu.ts b/src/common/util/navigator_gpu.ts index 9f137dd933c6..805c08fc925b 100644 --- a/src/common/util/navigator_gpu.ts +++ b/src/common/util/navigator_gpu.ts @@ -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'; /** diff --git a/src/stress/adapter/device_allocation.spec.ts b/src/stress/adapter/device_allocation.spec.ts index 3d6b4c71e8f2..caf77ceeb106 100644 --- a/src/stress/adapter/device_allocation.spec.ts +++ b/src/stress/adapter/device_allocation.spec.ts @@ -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); diff --git a/src/webgpu/api/operation/adapter/requestDevice.spec.ts b/src/webgpu/api/operation/adapter/requestDevice.spec.ts index 9aa5ca22e20c..012a89d64347 100644 --- a/src/webgpu/api/operation/adapter/requestDevice.spec.ts +++ b/src/webgpu/api/operation/adapter/requestDevice.spec.ts @@ -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); diff --git a/src/webgpu/api/validation/capability_checks/limits/limit_utils.ts b/src/webgpu/api/validation/capability_checks/limits/limit_utils.ts index 14f1642cea9f..ac44859998ff 100644 --- a/src/webgpu/api/validation/capability_checks/limits/limit_utils.ts +++ b/src/webgpu/api/validation/capability_checks/limits/limit_utils.ts @@ -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; diff --git a/src/webgpu/api/validation/encoding/cmds/render/indirect_multi_draw.spec.ts b/src/webgpu/api/validation/encoding/cmds/render/indirect_multi_draw.spec.ts index f2ad688f8938..19a10f29a5d7 100644 --- a/src/webgpu/api/validation/encoding/cmds/render/indirect_multi_draw.spec.ts +++ b/src/webgpu/api/validation/encoding/cmds/render/indirect_multi_draw.spec.ts @@ -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'; diff --git a/src/webgpu/api/validation/encoding/createRenderBundleEncoder.spec.ts b/src/webgpu/api/validation/encoding/createRenderBundleEncoder.spec.ts index ade00417411b..a48e22cdab5e 100644 --- a/src/webgpu/api/validation/encoding/createRenderBundleEncoder.spec.ts +++ b/src/webgpu/api/validation/encoding/createRenderBundleEncoder.spec.ts @@ -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, diff --git a/src/webgpu/api/validation/render_pass/attachment_compatibility.spec.ts b/src/webgpu/api/validation/render_pass/attachment_compatibility.spec.ts index 8f5982f8af18..379ea8f8ed67 100644 --- a/src/webgpu/api/validation/render_pass/attachment_compatibility.spec.ts +++ b/src/webgpu/api/validation/render_pass/attachment_compatibility.spec.ts @@ -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, diff --git a/src/webgpu/api/validation/render_pass/render_pass_descriptor.spec.ts b/src/webgpu/api/validation/render_pass/render_pass_descriptor.spec.ts index 3ded92c5c022..c9828c41319b 100644 --- a/src/webgpu/api/validation/render_pass/render_pass_descriptor.spec.ts +++ b/src/webgpu/api/validation/render_pass/render_pass_descriptor.spec.ts @@ -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, diff --git a/src/webgpu/api/validation/render_pipeline/fragment_state.spec.ts b/src/webgpu/api/validation/render_pipeline/fragment_state.spec.ts index efbe8b0b5b94..bfc4c1b90b51 100644 --- a/src/webgpu/api/validation/render_pipeline/fragment_state.spec.ts +++ b/src/webgpu/api/validation/render_pipeline/fragment_state.spec.ts @@ -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, diff --git a/src/webgpu/capability_info.ts b/src/webgpu/capability_info.ts index 7fcab69d1b97..656e4b510d2c 100644 --- a/src/webgpu/capability_info.ts +++ b/src/webgpu/capability_info.ts @@ -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. @@ -710,101 +705,6 @@ assertTypeTrue>(); -/** 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. diff --git a/src/webgpu/constants.ts b/src/webgpu/constants.ts index b44b23144c77..1eb98dc9387a 100644 --- a/src/webgpu/constants.ts +++ b/src/webgpu/constants.ts @@ -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]; diff --git a/src/webgpu/gpu_test.ts b/src/webgpu/gpu_test.ts index 2719679b512e..54750ddb9ae5 100644 --- a/src/webgpu/gpu_test.ts +++ b/src/webgpu/gpu_test.ts @@ -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, @@ -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, diff --git a/src/webgpu/util/device_pool.ts b/src/webgpu/util/device_pool.ts index 262a567d7a2c..3d4be7e0cf34 100644 --- a/src/webgpu/util/device_pool.ts +++ b/src/webgpu/util/device_pool.ts @@ -1,5 +1,6 @@ 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, @@ -7,7 +8,6 @@ import { 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