Skip to content

Commit

Permalink
Reland "Simplify device selection" with fix (#1386)
Browse files Browse the repository at this point in the history
REVERT AGAIN IF THIS CAUSES BREAKAGE

* Revert "Revert "Simplify device selection" and dependent commits (#1384)"

This reverts commit 0a1288f.

* Free DeviceHolder even on TestFailedButDeviceReusable
  • Loading branch information
kainino0x authored May 11, 2022
1 parent 999e396 commit d7d7544
Show file tree
Hide file tree
Showing 49 changed files with 390 additions and 393 deletions.
15 changes: 13 additions & 2 deletions src/common/framework/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,20 @@ export class SubcaseBatchState {
return this._params;
}

/** @internal MAINTENANCE_TODO: Make this not visible to test code? */
/**
* Runs before the `.before()` function.
* @internal MAINTENANCE_TODO: Make this not visible to test code?
*/
async init() {}
/** @internal MAINTENANCE_TODO: Make this not visible to test code? */
/**
* Runs between the `.before()` function and the subcases.
* @internal MAINTENANCE_TODO: Make this not visible to test code?
*/
async postInit() {}
/**
* Runs after all subcases finish.
* @internal MAINTENANCE_TODO: Make this not visible to test code?
*/
async finalize() {}
}

Expand Down
1 change: 1 addition & 0 deletions src/common/internal/test_group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ class RunCaseSpecific implements RunCase {
if (this.beforeFn) {
await this.beforeFn(sharedState);
}
await sharedState.postInit();

let allPreviousSubcasesFinalizedPromise: Promise<void> = Promise.resolve();
if (this.subcases) {
Expand Down
11 changes: 11 additions & 0 deletions src/common/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ export function raceWithRejectOnTimeout<T>(p: Promise<T>, ms: number, msg: strin
return Promise.race([p, timeoutPromise]) as Promise<T>;
}

/**
* Returns a `Promise.reject()`, but also registers a dummy `.catch()` handler so it doesn't count
* as an uncaught promise rejection in the runtime.
*/
export function rejectWithoutUncaught<T>(err: unknown): Promise<T> {
const p = Promise.reject(err);
// Suppress uncaught promise rejection.
p.catch(() => {});
return p;
}

/**
* Makes a copy of a JS `object`, with the keys reordered into sorted order.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -778,9 +778,9 @@ g.test('color_textures,compressed,non_array')
.combine('srcCopyLevel', [0, 2])
.combine('dstCopyLevel', [0, 2])
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
const { srcFormat, dstFormat } = t.params;
await t.selectDeviceOrSkipTestCase([
t.selectDeviceOrSkipTestCase([
kTextureFormatInfo[srcFormat].feature,
kTextureFormatInfo[dstFormat].feature,
]);
Expand Down Expand Up @@ -932,10 +932,10 @@ g.test('color_textures,compressed,array')
.combine('srcCopyLevel', [0, 2])
.combine('dstCopyLevel', [0, 2])
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
const { srcFormat, dstFormat } = t.params;

await t.selectDeviceOrSkipTestCase([
t.selectDeviceOrSkipTestCase([
kTextureFormatInfo[srcFormat].feature,
kTextureFormatInfo[dstFormat].feature,
]);
Expand Down Expand Up @@ -1116,9 +1116,9 @@ g.test('copy_depth_stencil')
);
})
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
const { format } = t.params;
await t.selectDeviceForTextureFormatOrSkipTestCase(format);
t.selectDeviceForTextureFormatOrSkipTestCase(format);
})
.fn(async t => {
const {
Expand Down
24 changes: 12 additions & 12 deletions src/webgpu/api/operation/command_buffer/image_copy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1287,9 +1287,9 @@ bytes in copy works for every format.
return kRowsPerImageAndBytesPerRowParams.copySizes;
})
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
const info = kTextureFormatInfo[t.params.format];
await t.selectDeviceOrSkipTestCase(info.feature);
t.selectDeviceOrSkipTestCase(info.feature);
})
.fn(async t => {
const {
Expand Down Expand Up @@ -1383,9 +1383,9 @@ works for every format with 2d and 2d-array textures.
.combine('copyDepth', kOffsetsAndSizesParams.copyDepth) // 2d and 2d-array textures
.unless(p => p.dimension === '1d' && p.copyDepth !== 1)
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
const info = kTextureFormatInfo[t.params.format];
await t.selectDeviceOrSkipTestCase(info.feature);
t.selectDeviceOrSkipTestCase(info.feature);
})
.fn(async t => {
const {
Expand Down Expand Up @@ -1462,9 +1462,9 @@ for all formats. We pass origin and copyExtent as [number, number, number].`
.combine('coordinateToTest', [0, 1, 2] as const)
.unless(p => p.dimension === '1d' && p.coordinateToTest !== 0)
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
const info = kTextureFormatInfo[t.params.format];
await t.selectDeviceOrSkipTestCase(info.feature);
t.selectDeviceOrSkipTestCase(info.feature);
})
.fn(async t => {
const {
Expand Down Expand Up @@ -1661,9 +1661,9 @@ TODO: Make a variant for depth-stencil formats.
])
.expand('textureSize', generateTestTextureSizes)
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
const info = kTextureFormatInfo[t.params.format];
await t.selectDeviceOrSkipTestCase(info.feature);
t.selectDeviceOrSkipTestCase(info.feature);
})
.fn(async t => {
const {
Expand Down Expand Up @@ -1828,9 +1828,9 @@ aspect and copyTextureToBuffer() with depth aspect.
})
.combine('mipLevel', [0, 2])
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
const info = kTextureFormatInfo[t.params.format];
await t.selectDeviceOrSkipTestCase(info.feature);
t.selectDeviceOrSkipTestCase(info.feature);
})
.fn(async t => {
const {
Expand Down Expand Up @@ -1919,9 +1919,9 @@ copyTextureToBuffer() with depth aspect.
.combine('copyDepth', kOffsetsAndSizesParams.copyDepth)
.combine('mipLevel', [0, 2])
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
const info = kTextureFormatInfo[t.params.format];
await t.selectDeviceOrSkipTestCase(info.feature);
t.selectDeviceOrSkipTestCase(info.feature);
})
.fn(async t => {
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ g.test('color,attachments')
.combine('attachmentCount', [2, 3, 4])
.expand('emptyAttachmentId', p => range(p.attachmentCount, i => i))
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
const info = kTextureFormatInfo[t.params.format];
await t.selectDeviceOrSkipTestCase(info.feature);
t.selectDeviceOrSkipTestCase(info.feature);
})
.fn(async t => {
const { format, attachmentCount, emptyAttachmentId } = t.params;
Expand Down Expand Up @@ -254,9 +254,9 @@ g.test('color,component_count')
.combine('componentCount', [1, 2, 3, 4])
.filter(x => x.componentCount >= kTexelRepresentationInfo[x.format].componentOrder.length)
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
const info = kTextureFormatInfo[t.params.format];
await t.selectDeviceOrSkipTestCase(info.feature);
t.selectDeviceOrSkipTestCase(info.feature);
})
.fn(async t => {
const { format, componentCount } = t.params;
Expand Down Expand Up @@ -459,9 +459,9 @@ The attachment has a load value of [1, 0, 0, 1]
] as const)
.filter(x => x.output.length >= kTexelRepresentationInfo[x.format].componentOrder.length)
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
const info = kTextureFormatInfo[t.params.format];
await t.selectDeviceOrSkipTestCase(info.feature);
t.selectDeviceOrSkipTestCase(info.feature);
})
.fn(async t => {
const {
Expand Down
4 changes: 2 additions & 2 deletions src/webgpu/api/operation/rendering/depth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ g.test('depth_compare_func')
{ depthCompare: 'always', depthClearValue: 0.0, _expected: triangleColor },
] as const)
)
.beforeAllSubcases(async t => {
await t.selectDeviceForTextureFormatOrSkipTestCase(t.params.format);
.beforeAllSubcases(t => {
t.selectDeviceForTextureFormatOrSkipTestCase(t.params.format);
})
.fn(async t => {
const { depthCompare, depthClearValue, _expected, format } = t.params;
Expand Down
8 changes: 4 additions & 4 deletions src/webgpu/api/operation/rendering/depth_clip_clamp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ have unexpected values then get drawn to the color buffer, which is later checke
.combine('writeDepth', [false, true])
.combine('multisampled', [false, true])
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
const info = kTextureFormatInfo[t.params.format];

await t.selectDeviceOrSkipTestCase([
t.selectDeviceOrSkipTestCase([
t.params.unclippedDepth ? 'depth-clip-control' : undefined,
info.feature,
]);
Expand Down Expand Up @@ -354,10 +354,10 @@ to be empty.`
.combine('unclippedDepth', [false, true])
.combine('multisampled', [false, true])
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
const info = kTextureFormatInfo[t.params.format];

await t.selectDeviceOrSkipTestCase([
t.selectDeviceOrSkipTestCase([
t.params.unclippedDepth ? 'depth-clip-control' : undefined,
info.feature,
]);
Expand Down
4 changes: 2 additions & 2 deletions src/webgpu/api/operation/rendering/draw.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ Params:
.expand('index_buffer_offset', p => (p.indexed ? ([0, 16] as const) : [undefined]))
.expand('base_vertex', p => (p.indexed ? ([0, 9] as const) : [undefined]))
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
if (t.params.first_instance > 0 && t.params.indirect) {
await t.selectDeviceOrSkipTestCase('indirect-first-instance');
t.selectDeviceOrSkipTestCase('indirect-first-instance');
}
})
.fn(async t => {
Expand Down
4 changes: 2 additions & 2 deletions src/webgpu/api/operation/resource_init/texture_zero.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,8 @@ export const g = makeTestGroup(TextureZeroInitTest);

g.test('uninitialized_texture_is_zero')
.params(kTestParams)
.beforeAllSubcases(async t => {
await t.selectDeviceOrSkipTestCase(kTextureFormatInfo[t.params.format].feature);
.beforeAllSubcases(t => {
t.selectDeviceOrSkipTestCase(kTextureFormatInfo[t.params.format].feature);
})
.fn(async t => {
const usage = getRequiredTextureUsage(
Expand Down
12 changes: 6 additions & 6 deletions src/webgpu/api/validation/attachment_compatibility.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ g.test('render_pass_and_bundle,depth_format')
filterFormatsByFeature(bundleFeature, kDepthStencilAttachmentFormats)
)
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
const { passFeature, bundleFeature } = t.params;
await t.selectDeviceOrSkipTestCase([passFeature, bundleFeature]);
t.selectDeviceOrSkipTestCase([passFeature, bundleFeature]);
})
.fn(async t => {
const { passFormat, bundleFormat } = t.params;
Expand Down Expand Up @@ -431,9 +431,9 @@ Test that the depth attachment format in render passes or bundles match the pipe
filterFormatsByFeature(pipelineFormatFeature, kDepthStencilAttachmentFormats)
)
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
const { encoderFormatFeature, pipelineFormatFeature } = t.params;
await t.selectDeviceOrSkipTestCase([encoderFormatFeature, pipelineFormatFeature]);
t.selectDeviceOrSkipTestCase([encoderFormatFeature, pipelineFormatFeature]);
})
.fn(async t => {
const { encoderType, encoderFormat, pipelineFormat } = t.params;
Expand Down Expand Up @@ -503,8 +503,8 @@ Test that the depth stencil read only state in render passes or bundles is compa
return true;
})
)
.beforeAllSubcases(async t => {
await t.selectDeviceForTextureFormatOrSkipTestCase(t.params.format);
.beforeAllSubcases(t => {
t.selectDeviceForTextureFormatOrSkipTestCase(t.params.format);
})
.fn(async t => {
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ As of this writing, the spec needs to be fixed as well.
.combine('type', ['occlusion', 'timestamp'] as const)
.combine('timestampQueryEnable', [false, true])
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
const { timestampQueryEnable } = t.params;

const requiredFeatures: GPUFeatureName[] = [];
if (timestampQueryEnable) {
requiredFeatures.push('timestamp-query');
}

await t.selectDeviceOrSkipTestCase({ requiredFeatures });
t.selectDeviceOrSkipTestCase({ requiredFeatures });
})
.fn(async t => {
const { type, timestampQueryEnable } = t.params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ g.test('texture_descriptor')
.params(u =>
u.combine('format', kOptionalTextureFormats).combine('enable_required_feature', [true, false])
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
const { format, enable_required_feature } = t.params;

const formatInfo = kTextureFormatInfo[format];
if (enable_required_feature) {
await t.selectDeviceOrSkipTestCase(formatInfo.feature);
t.selectDeviceOrSkipTestCase(formatInfo.feature);
}
})
.fn(async t => {
Expand Down Expand Up @@ -66,12 +66,12 @@ g.test('storage_texture_binding_layout')
.filter(t => kTextureFormatInfo[t.format].storage)
.combine('enable_required_feature', [true, false])
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
const { format, enable_required_feature } = t.params;

const formatInfo = kTextureFormatInfo[format];
if (enable_required_feature) {
await t.selectDeviceOrSkipTestCase(formatInfo.feature);
t.selectDeviceOrSkipTestCase(formatInfo.feature);
}
})
.fn(async t => {
Expand Down Expand Up @@ -107,12 +107,12 @@ g.test('color_target_state')
.filter(t => kTextureFormatInfo[t.format].renderable && kTextureFormatInfo[t.format].color)
.combine('enable_required_feature', [true, false])
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
const { format, enable_required_feature } = t.params;

const formatInfo = kTextureFormatInfo[format];
if (enable_required_feature) {
await t.selectDeviceOrSkipTestCase(formatInfo.feature);
t.selectDeviceOrSkipTestCase(formatInfo.feature);
}
})
.fn(async t => {
Expand Down Expand Up @@ -162,12 +162,12 @@ g.test('depth_stencil_state')
)
.combine('enable_required_feature', [true, false])
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
const { format, enable_required_feature } = t.params;

const formatInfo = kTextureFormatInfo[format];
if (enable_required_feature) {
await t.selectDeviceOrSkipTestCase(formatInfo.feature);
t.selectDeviceOrSkipTestCase(formatInfo.feature);
}
})
.fn(async t => {
Expand Down Expand Up @@ -218,12 +218,12 @@ g.test('render_bundle_encoder_descriptor_color_format')
.filter(t => kTextureFormatInfo[t.format].renderable && kTextureFormatInfo[t.format].color)
.combine('enable_required_feature', [true, false])
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
const { format, enable_required_feature } = t.params;

const formatInfo = kTextureFormatInfo[format];
if (enable_required_feature) {
await t.selectDeviceOrSkipTestCase(formatInfo.feature);
t.selectDeviceOrSkipTestCase(formatInfo.feature);
}
})
.fn(async t => {
Expand Down Expand Up @@ -253,12 +253,12 @@ g.test('render_bundle_encoder_descriptor_depth_stencil_format')
)
.combine('enable_required_feature', [true, false])
)
.beforeAllSubcases(async t => {
.beforeAllSubcases(t => {
const { format, enable_required_feature } = t.params;

const formatInfo = kTextureFormatInfo[format];
if (enable_required_feature) {
await t.selectDeviceOrSkipTestCase(formatInfo.feature);
t.selectDeviceOrSkipTestCase(formatInfo.feature);
}
})
.fn(async t => {
Expand Down
Loading

0 comments on commit d7d7544

Please sign in to comment.