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

Compat: createBGL, createPipelineLayout, etc... #4121

Merged
merged 1 commit into from
Jan 3, 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
26 changes: 21 additions & 5 deletions src/webgpu/api/operation/adapter/requestDevice.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ g.test('limits,supported')
result = value;
break;
case 'adapter':
value = adapter.limits[limit];
value = adapter.limits[limit]!;
result = value;
break;
case 'undefined':
Expand All @@ -283,11 +283,27 @@ g.test('limits,supported')
break;
}

const device = await t.requestDeviceTracked(adapter, { requiredLimits: { [limit]: value } });
const requiredLimits: Record<string, number | undefined> = { [limit]: value };

if (
limit === 'maxStorageBuffersInFragmentStage' ||
limit === 'maxStorageBuffersInVertexStage'
) {
requiredLimits['maxStorageBuffersPerShaderStage'] = value;
}

if (
limit === 'maxStorageTexturesInFragmentStage' ||
limit === 'maxStorageTexturesInVertexStage'
) {
requiredLimits['maxStorageTexturesPerShaderStage'] = value;
}

const device = await t.requestDeviceTracked(adapter, { requiredLimits });
assert(device !== null);
t.expect(
device.limits[limit] === result,
'Devices reported limit should match the required limit'
`Devices reported limit for ${limit}(${device.limits[limit]}) should match the required limit (${result})`
);
});

Expand Down Expand Up @@ -327,7 +343,7 @@ g.test('limit,better_than_supported')
assert(adapter !== null);

const limitInfo = getDefaultLimitsForAdapter(adapter);
const value = adapter.limits[limit] * mul + add;
const value = adapter.limits[limit]! * mul + add;
const requiredLimits = {
[limit]: clamp(value, { min: 0, max: limitInfo[limit].maximumValue }),
};
Expand Down Expand Up @@ -381,7 +397,7 @@ g.test('limit,out_of_range')
const errorName =
value < 0 || value > Number.MAX_SAFE_INTEGER
? 'TypeError'
: limitInfo.class === 'maximum' && value > adapter.limits[limit]
: limitInfo.class === 'maximum' && value > adapter.limits[limit]!
? 'OperationError'
: limitInfo.class === 'alignment' && (value > 2 ** 31 || !isPowerOfTwo(value))
? 'OperationError'
Expand Down
18 changes: 1 addition & 17 deletions src/webgpu/api/operation/vertex_state/correctness.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import {
memcpy,
unreachable,
} from '../../../../common/util/util.js';
import {
kPerStageBindingLimits,
kVertexFormatInfo,
kVertexFormats,
} from '../../../capability_info.js';
import { kVertexFormatInfo, kVertexFormats } from '../../../capability_info.js';
import { GPUTest, MaxLimitsTestMixin } from '../../../gpu_test.js';
import { float32ToFloat16Bits, normalizedIntegerAsFloat } from '../../../util/conversion.js';
import { align, clamp } from '../../../util/math.js';
Expand Down Expand Up @@ -105,18 +101,6 @@ class VertexStateTest extends GPUTest {
vertexCount: number,
instanceCount: number
): string {
// In the base WebGPU spec maxVertexAttributes is larger than maxUniformBufferPerStage. We'll
// use a combination of uniform and storage buffers to cover all possible attributes. This
// happens to work because maxUniformBuffer + maxStorageBuffer = 12 + 8 = 20 which is larger
// than maxVertexAttributes = 16.
// However this might not work in the future for implementations that allow even more vertex
// attributes so there will need to be larger changes when that happens.
const maxUniformBuffers = this.getDefaultLimit(kPerStageBindingLimits['uniformBuf'].maxLimit);
assert(
maxUniformBuffers + this.getDefaultLimit(kPerStageBindingLimits['storageBuf'].maxLimit) >=
this.device.limits.maxVertexAttributes
);

let vsInputs = '';
let vsChecks = '';
let providedDataDefs = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { kUnitCaseParamsBuilder } from '../../../../../common/framework/params_b
import { makeTestGroup } from '../../../../../common/framework/test_group.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 {
getDefaultLimits,
getDefaultLimitsForAdapter,
kLimits,
} from '../../../../capability_info.js';
import { GPUTestBase } from '../../../../gpu_test.js';

type GPUSupportedLimit = keyof GPUSupportedLimits;
Expand Down Expand Up @@ -362,6 +366,14 @@ export class LimitTestsImpl extends GPUTestBase {
return this._device;
}

getDefaultLimits() {
return getDefaultLimits(this.isCompatibility ? 'compatibility' : 'core');
}

getDefaultLimit(limit: (typeof kLimits)[number]) {
return this.getDefaultLimits()[limit].default;
}

async requestDeviceWithLimits(
adapter: GPUAdapter,
requiredLimits: Record<string, number>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { GPUTestBase } from '../../../../gpu_test.js';

import {
kMaximumLimitBaseParams,
MaximumLimitValueTest,
MaximumTestValue,
makeLimitTestGroup,
LimitTestsImpl,
} from './limit_utils.js';

/**
Expand Down Expand Up @@ -77,7 +76,7 @@ function getDeviceLimitToRequest(
}

function getTestWorkgroupSize(
t: GPUTestBase,
t: LimitTestsImpl,
testValueName: MaximumTestValue,
requestedLimit: number
) {
Expand All @@ -96,7 +95,7 @@ function getTestWorkgroupSize(
}

function getDeviceLimitToRequestAndValueToTest(
t: GPUTestBase,
t: LimitTestsImpl,
limitValueTest: MaximumLimitValueTest,
testValueName: MaximumTestValue,
defaultLimit: number,
Expand Down
79 changes: 68 additions & 11 deletions src/webgpu/api/validation/createBindGroupLayout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,64 @@ import {
bufferBindingTypeInfo,
kBufferBindingTypes,
BGLEntry,
getBindingLimitForBindingType,
} from '../../capability_info.js';
import { kAllTextureFormats, kTextureFormatInfo } from '../../format_info.js';
import { MaxLimitsTestMixin } from '../../gpu_test.js';

import { ValidationTest } from './validation_test.js';

function clone<T extends GPUBindGroupLayoutDescriptor>(descriptor: T): T {
return JSON.parse(JSON.stringify(descriptor));
}

export const g = makeTestGroup(ValidationTest);
function isValidBufferTypeForStages(
device: GPUDevice,
visibility: number,
type: GPUBufferBindingType | undefined
) {
if (type === 'read-only-storage' || type === 'storage') {
if (visibility & GPUShaderStage.VERTEX) {
if (!(device.limits.maxStorageBuffersInVertexStage! > 0)) {
return false;
}
}

if (visibility & GPUShaderStage.FRAGMENT) {
if (!(device.limits.maxStorageBuffersInFragmentStage! > 0)) {
return false;
}
}
}

return true;
}

function isValidStorageTextureForStages(device: GPUDevice, visibility: number) {
if (visibility & GPUShaderStage.VERTEX) {
if (!(device.limits.maxStorageTexturesInVertexStage! > 0)) {
return false;
}
}

if (visibility & GPUShaderStage.FRAGMENT) {
if (!(device.limits.maxStorageTexturesInFragmentStage! > 0)) {
return false;
}
}

return true;
}

function isValidBGLEntryForStages(device: GPUDevice, visibility: number, entry: BGLEntry) {
return entry.storageTexture
? isValidStorageTextureForStages(device, visibility)
: entry.buffer
? isValidBufferTypeForStages(device, visibility, entry.buffer?.type)
: true;
}

export const g = makeTestGroup(MaxLimitsTestMixin(ValidationTest));

g.test('duplicate_bindings')
.desc('Test that uniqueness of binding numbers across entries is enforced.')
Expand Down Expand Up @@ -107,7 +155,9 @@ g.test('visibility')
const { visibility, entry } = t.params;
const info = bindingTypeInfo(entry);

const success = (visibility & ~info.validStages) === 0;
const success =
(visibility & ~info.validStages) === 0 &&
isValidBGLEntryForStages(t.device, visibility, entry);

t.expectValidationError(() => {
t.device.createBindGroupLayout({
Expand All @@ -132,7 +182,9 @@ g.test('visibility,VERTEX_shader_stage_buffer_type')
.fn(t => {
const { shaderStage, type } = t.params;

const success = !(type === 'storage' && shaderStage & GPUShaderStage.VERTEX);
const success =
!(type === 'storage' && shaderStage & GPUShaderStage.VERTEX) &&
isValidBufferTypeForStages(t.device, shaderStage, type);

t.expectValidationError(() => {
t.device.createBindGroupLayout({
Expand Down Expand Up @@ -164,10 +216,11 @@ g.test('visibility,VERTEX_shader_stage_storage_texture_access')
const { shaderStage, access } = t.params;

const appliedAccess = access ?? 'write-only';
const success = !(
// If visibility includes VERETX, storageTexture.access must be "read-only"
(shaderStage & GPUShaderStage.VERTEX && appliedAccess !== 'read-only')
);
const success =
!(
// If visibility includes VERETX, storageTexture.access must be "read-only"
(shaderStage & GPUShaderStage.VERTEX && appliedAccess !== 'read-only')
) && isValidStorageTextureForStages(t.device, shaderStage);

t.expectValidationError(() => {
t.device.createBindGroupLayout({
Expand Down Expand Up @@ -235,9 +288,9 @@ g.test('max_dynamic_buffers')
const info = bufferBindingTypeInfo({ type });

const limitName = info.perPipelineLimitClass.maxDynamicLimit;
const bufferCount = limitName ? t.getDefaultLimit(limitName) : 0;
const bufferCount = limitName ? t.device.limits[limitName]! : 0;
const dynamicBufferCount = bufferCount + extraDynamicBuffers;
const perStageLimit = t.getDefaultLimit(info.perStageLimitClass.maxLimit);
const perStageLimit = t.device.limits[info.perStageLimitClass.maxLimits.COMPUTE]!;

const entries = [];
for (let i = 0; i < dynamicBufferCount; i++) {
Expand Down Expand Up @@ -319,9 +372,11 @@ g.test('max_resources_per_stage,in_bind_group_layout')
.fn(t => {
const { maxedEntry, extraEntry, maxedVisibility, extraVisibility } = t.params;
const maxedTypeInfo = bindingTypeInfo(maxedEntry);
const maxedCount = t.getDefaultLimit(maxedTypeInfo.perStageLimitClass.maxLimit);
const maxedCount = getBindingLimitForBindingType(t.device, maxedVisibility, maxedEntry);
const extraTypeInfo = bindingTypeInfo(extraEntry);

t.skipIf(!isValidBGLEntryForStages(t.device, extraVisibility, extraEntry));

const maxResourceBindings: GPUBindGroupLayoutEntry[] = [];
for (let i = 0; i < maxedCount; i++) {
maxResourceBindings.push({
Expand Down Expand Up @@ -370,9 +425,11 @@ g.test('max_resources_per_stage,in_pipeline_layout')
.fn(t => {
const { maxedEntry, extraEntry, maxedVisibility, extraVisibility } = t.params;
const maxedTypeInfo = bindingTypeInfo(maxedEntry);
const maxedCount = t.getDefaultLimit(maxedTypeInfo.perStageLimitClass.maxLimit);
const maxedCount = getBindingLimitForBindingType(t.device, maxedVisibility, maxedEntry);
const extraTypeInfo = bindingTypeInfo(extraEntry);

t.skipIf(!isValidBGLEntryForStages(t.device, extraVisibility, extraEntry));

const maxResourceBindings: GPUBindGroupLayoutEntry[] = [];
for (let i = 0; i < maxedCount; i++) {
maxResourceBindings.push({
Expand Down
20 changes: 12 additions & 8 deletions src/webgpu/api/validation/createPipelineLayout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ 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 {
bufferBindingTypeInfo,
getBindingLimitForBindingType,
kBufferBindingTypes,
} from '../../capability_info.js';
import { GPUConst } from '../../constants.js';
import { MaxLimitsTestMixin } from '../../gpu_test.js';

import { ValidationTest } from './validation_test.js';

function clone<T extends GPUBindGroupLayoutDescriptor>(descriptor: T): T {
return JSON.parse(JSON.stringify(descriptor));
}

export const g = makeTestGroup(ValidationTest);
export const g = makeTestGroup(MaxLimitsTestMixin(ValidationTest));

g.test('number_of_dynamic_buffers_exceeds_the_maximum_value')
.desc(
Expand All @@ -37,11 +42,10 @@ g.test('number_of_dynamic_buffers_exceeds_the_maximum_value')
const { type, visibility } = t.params;
const info = bufferBindingTypeInfo({ type });
const { maxDynamicLimit } = info.perPipelineLimitClass;
const perStageLimit = t.getDefaultLimit(info.perStageLimitClass.maxLimit);
const maxDynamic = Math.min(
maxDynamicLimit ? t.getDefaultLimit(maxDynamicLimit) : 0,
perStageLimit
);
const limit = getBindingLimitForBindingType(t.device, visibility, { buffer: { type } });
const maxDynamic = Math.min(maxDynamicLimit ? t.device.limits[maxDynamicLimit]! : 0, limit);

t.skipIf(limit === 0, `binding limit for ${type} === 0`);

const maxDynamicBufferBindings: GPUBindGroupLayoutEntry[] = [];
for (let binding = 0; binding < maxDynamic; binding++) {
Expand All @@ -60,7 +64,7 @@ g.test('number_of_dynamic_buffers_exceeds_the_maximum_value')
entries: [{ binding: 0, visibility, buffer: { type, hasDynamicOffset: false } }],
};

if (perStageLimit > maxDynamic) {
if (limit > maxDynamic) {
const goodPipelineLayoutDescriptor = {
bindGroupLayouts: [
maxDynamicBufferBindGroupLayout,
Expand Down
Loading
Loading