Skip to content

Commit e6703ac

Browse files
committed
Refactor render_pass_descriptor tests for texture formats.
Issue gpuweb#4181
1 parent b1b1ae6 commit e6703ac

File tree

2 files changed

+48
-35
lines changed

2 files changed

+48
-35
lines changed

src/webgpu/api/validation/render_pass/render_pass_descriptor.spec.ts

+18-35
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@ import {
1313
computeBytesPerSampleFromFormats,
1414
kDepthStencilFormats,
1515
kRenderableColorTextureFormats,
16-
kTextureFormatInfo,
16+
isTextureFormatColorRenderable,
17+
isDepthTextureFormat,
18+
isStencilTextureFormat,
19+
isTextureFormatResolvable,
1720
} from '../../../format_info.js';
18-
import { ValidationTest } from '../validation_test.js';
21+
import { AllFeaturesMaxLimitsValidationTest } from '../validation_test.js';
1922

2023
// MAINTENANCE_TODO: This should be changed to kMaxColorAttachmentsToTest
2124
// when this is made a MaxLimitTest (see above).
2225
const kMaxColorAttachments = getDefaultLimits('core').maxColorAttachments.default;
2326

24-
class F extends ValidationTest {
27+
class F extends AllFeaturesMaxLimitsValidationTest {
2528
createTestTexture(
2629
options: {
2730
format?: GPUTextureFormat;
@@ -214,7 +217,6 @@ g.test('color_attachments,limits,maxColorAttachmentBytesPerSample,aligned')
214217
})
215218
.fn(t => {
216219
const { format, attachmentCount } = t.params;
217-
const info = kTextureFormatInfo[format];
218220

219221
t.skipIf(
220222
attachmentCount > t.device.limits.maxColorAttachments,
@@ -227,7 +229,7 @@ g.test('color_attachments,limits,maxColorAttachmentBytesPerSample,aligned')
227229
colorAttachments.push(t.getColorAttachment(colorTexture));
228230
}
229231
const shouldError =
230-
info.colorRender === undefined ||
232+
isTextureFormatColorRenderable(t.device, format) === undefined ||
231233
computeBytesPerSampleFromFormats(range(attachmentCount, () => format)) >
232234
t.device.limits.maxColorAttachmentBytesPerSample;
233235

@@ -1049,10 +1051,6 @@ g.test('depth_stencil_attachment,loadOp_storeOp_match_depthReadOnly_stencilReadO
10491051
.combine('stencilLoadOp', [undefined, 'clear', 'load'] as GPULoadOp[])
10501052
.combine('stencilStoreOp', [undefined, 'discard', 'store'] as GPUStoreOp[])
10511053
)
1052-
.beforeAllSubcases(t => {
1053-
const info = kTextureFormatInfo[t.params.format as GPUTextureFormat];
1054-
t.selectDeviceOrSkipTestCase(info.feature);
1055-
})
10561054
.fn(t => {
10571055
const {
10581056
format,
@@ -1064,6 +1062,8 @@ g.test('depth_stencil_attachment,loadOp_storeOp_match_depthReadOnly_stencilReadO
10641062
stencilStoreOp,
10651063
} = t.params;
10661064

1065+
t.skipIfTextureFormatNotSupported(format);
1066+
10671067
const depthAttachment = t.createTextureTracked({
10681068
format,
10691069
size: { width: 1, height: 1, depthOrArrayLayers: 1 },
@@ -1092,11 +1092,10 @@ g.test('depth_stencil_attachment,loadOp_storeOp_match_depthReadOnly_stencilReadO
10921092
const pass = encoder.beginRenderPass(renderPassDescriptor);
10931093
pass.end();
10941094

1095-
const info = kTextureFormatInfo[format];
10961095
const hasDepthSettings = !!depthLoadOp && !!depthStoreOp && !depthReadOnly;
10971096
const hasStencilSettings = !!stencilLoadOp && !!stencilStoreOp && !stencilReadOnly;
1098-
const hasDepth = info.depth;
1099-
const hasStencil = info.stencil;
1097+
const hasDepth = isDepthTextureFormat(format);
1098+
const hasStencil = isStencilTextureFormat(format);
11001099

11011100
const goodAspectSettingsPresent =
11021101
(hasDepthSettings ? hasDepth : true) && (hasStencilSettings ? hasStencil : true);
@@ -1162,27 +1161,19 @@ g.test('resolveTarget,format_supports_resolve')
11621161
if and only if they support 'resolve'.
11631162
`
11641163
)
1165-
.params(u =>
1166-
u
1167-
.combine('format', kRenderableColorTextureFormats)
1168-
.filter(t => kTextureFormatInfo[t.format].multisample)
1169-
)
1170-
.beforeAllSubcases(t => {
1171-
const { format } = t.params;
1172-
t.skipIfTextureFormatNotSupportedDeprecated(format);
1173-
t.skipIfMultisampleNotSupportedForFormatDeprecated(format);
1174-
})
1164+
.params(u => u.combine('format', kRenderableColorTextureFormats))
11751165
.fn(t => {
11761166
const { format } = t.params;
1177-
const info = kTextureFormatInfo[format];
1167+
t.skipIfTextureFormatNotSupported(format);
1168+
t.skipIfMultisampleNotSupportedForFormat(format);
11781169

11791170
const multisampledColorTexture = t.createTestTexture({ format, sampleCount: 4 });
11801171
const resolveTarget = t.createTestTexture({ format });
11811172

11821173
const colorAttachment = t.getColorAttachment(multisampledColorTexture);
11831174
colorAttachment.resolveTarget = resolveTarget.createView();
11841175

1185-
t.tryRenderPass(!!info.colorRender?.resolve, {
1176+
t.tryRenderPass(isTextureFormatResolvable(t.device, format), {
11861177
colorAttachments: [colorAttachment],
11871178
});
11881179
});
@@ -1198,10 +1189,8 @@ g.test('timestampWrites,query_set_type')
11981189
u //
11991190
.combine('queryType', kQueryTypes)
12001191
)
1201-
.beforeAllSubcases(t => {
1202-
t.selectDeviceOrSkipTestCase(['timestamp-query']);
1203-
})
12041192
.fn(t => {
1193+
t.skipIfDeviceDoesNotSupportQueryType('timestamp');
12051194
const { queryType } = t.params;
12061195

12071196
const timestampWrites = {
@@ -1231,10 +1220,8 @@ g.test('timestampWrite,query_index')
12311220
.combine('beginningOfPassWriteIndex', [undefined, 0, 1, 2, 3] as const)
12321221
.combine('endOfPassWriteIndex', [undefined, 0, 1, 2, 3] as const)
12331222
)
1234-
.beforeAllSubcases(t => {
1235-
t.selectDeviceOrSkipTestCase(['timestamp-query']);
1236-
})
12371223
.fn(t => {
1224+
t.skipIfDeviceDoesNotSupportQueryType('timestamp');
12381225
const { beginningOfPassWriteIndex, endOfPassWriteIndex } = t.params;
12391226

12401227
const querySetCount = 2;
@@ -1262,13 +1249,9 @@ g.test('timestampWrite,query_index')
12621249
g.test('occlusionQuerySet,query_set_type')
12631250
.desc(`Test that occlusionQuerySet must have type 'occlusion'.`)
12641251
.params(u => u.combine('queryType', kQueryTypes))
1265-
.beforeAllSubcases(t => {
1266-
if (t.params.queryType === 'timestamp') {
1267-
t.selectDeviceOrSkipTestCase(['timestamp-query']);
1268-
}
1269-
})
12701252
.fn(t => {
12711253
const { queryType } = t.params;
1254+
t.skipIfDeviceDoesNotSupportQueryType(queryType);
12721255

12731256
const querySet = t.createQuerySetTracked({
12741257
type: queryType,

src/webgpu/gpu_test.ts

+30
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
isTextureFormatUsableAsStorageFormatDeprecated,
3636
isMultisampledTextureFormatDeprecated,
3737
isTextureFormatUsableAsStorageFormat,
38+
isTextureFormatMultisampled,
3839
} from './format_info.js';
3940
import { checkElementsEqual, checkElementsBetween } from './util/check_contents.js';
4041
import { CommandBufferMaker, EncoderType } from './util/command_buffer_maker.js';
@@ -523,6 +524,26 @@ export class GPUTestBase extends Fixture<GPUTestSubcaseBatchState> {
523524
}
524525
}
525526

527+
/**
528+
* Skips test if device does not have feature.
529+
* Note: Try to use one of the more specific skipIf tests if possible.
530+
*/
531+
skipIfDeviceDoesNotHaveFeature(feature: GPUFeatureName) {
532+
this.skipIf(!this.device.features.has(feature), `device does not have feature: '${feature}'`);
533+
}
534+
535+
/**
536+
* Skips test if device des not support query type.
537+
*/
538+
skipIfDeviceDoesNotSupportQueryType(...types: GPUQueryType[]) {
539+
for (const type of types) {
540+
const feature = kQueryTypeInfo[type].feature;
541+
if (feature) {
542+
this.skipIfDeviceDoesNotHaveFeature(feature);
543+
}
544+
}
545+
}
546+
526547
/**
527548
* Skips test if any format is not supported.
528549
*/
@@ -544,6 +565,15 @@ export class GPUTestBase extends Fixture<GPUTestSubcaseBatchState> {
544565
}
545566
}
546567

568+
skipIfMultisampleNotSupportedForFormat(...formats: (GPUTextureFormat | undefined)[]) {
569+
for (const format of formats) {
570+
if (format === undefined) continue;
571+
if (!isTextureFormatMultisampled(this.device, format)) {
572+
this.skip(`texture format '${format}' is not supported to be multisampled`);
573+
}
574+
}
575+
}
576+
547577
/** @deprecated */
548578
skipIfTextureViewDimensionNotSupportedDeprecated(
549579
...dimensions: (GPUTextureViewDimension | undefined)[]

0 commit comments

Comments
 (0)