Skip to content

Commit b959c30

Browse files
committed
Refactor createView test for texture formats.
Issue gpuweb#4181
1 parent 0d0ce46 commit b959c30

File tree

3 files changed

+76
-47
lines changed

3 files changed

+76
-47
lines changed

src/webgpu/api/validation/createView.spec.ts

+30-47
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ import {
1111
} from '../../capability_info.js';
1212
import { GPUConst } from '../../constants.js';
1313
import {
14-
kTextureFormatInfo,
1514
kAllTextureFormats,
1615
kFeaturesForFormats,
1716
filterFormatsByFeature,
18-
viewCompatibleDeprecated,
17+
textureFormatsAreViewCompatible,
18+
isDepthTextureFormat,
19+
isStencilTextureFormat,
20+
getBlockInfoForTextureFormat,
21+
isTextureFormatPossiblyUsableAsRenderAttachment,
1922
} from '../../format_info.js';
2023
import { kResourceStates } from '../../gpu_test.js';
2124
import {
@@ -25,9 +28,9 @@ import {
2528
} from '../../util/texture/base.js';
2629
import { reifyExtent3D } from '../../util/unions.js';
2730

28-
import { ValidationTest } from './validation_test.js';
31+
import { AllFeaturesMaxLimitsValidationTest } from './validation_test.js';
2932

30-
export const g = makeTestGroup(ValidationTest);
33+
export const g = makeTestGroup(AllFeaturesMaxLimitsValidationTest);
3134

3235
const kLevels = 6;
3336

@@ -48,19 +51,15 @@ g.test('format')
4851
)
4952
.combine('useViewFormatList', [false, true])
5053
)
51-
.beforeAllSubcases(t => {
52-
const { textureFormatFeature, viewFormatFeature } = t.params;
53-
t.selectDeviceOrSkipTestCase([textureFormatFeature, viewFormatFeature]);
54-
})
5554
.fn(t => {
5655
const { textureFormat, viewFormat, useViewFormatList } = t.params;
57-
const { blockWidth, blockHeight } = kTextureFormatInfo[textureFormat];
56+
const { blockWidth, blockHeight } = getBlockInfoForTextureFormat(textureFormat);
5857

59-
t.skipIfTextureFormatNotSupportedDeprecated(textureFormat, viewFormat);
58+
t.skipIfTextureFormatNotSupported(textureFormat, viewFormat);
6059

6160
const compatible =
6261
viewFormat === undefined ||
63-
viewCompatibleDeprecated(t.isCompatibility, textureFormat, viewFormat);
62+
textureFormatsAreViewCompatible(t.device, textureFormat, viewFormat);
6463

6564
const texture = t.createTextureTracked({
6665
format: textureFormat,
@@ -94,11 +93,9 @@ g.test('dimension')
9493
.combine('textureDimension', kTextureDimensions)
9594
.combine('viewDimension', [...kTextureViewDimensions, undefined])
9695
)
97-
.beforeAllSubcases(t => {
98-
t.skipIfTextureViewDimensionNotSupportedDeprecated(t.params.viewDimension);
99-
})
10096
.fn(t => {
10197
const { textureDimension, viewDimension } = t.params;
98+
t.skipIfTextureViewDimensionNotSupported(t.params.viewDimension);
10299

103100
const size = textureDimension === '1d' ? [4] : [4, 4, 6];
104101
const textureDescriptor = {
@@ -130,24 +127,22 @@ g.test('aspect')
130127
.combine('format', kAllTextureFormats)
131128
.combine('aspect', kTextureAspects)
132129
)
133-
.beforeAllSubcases(t => {
134-
const { format } = t.params;
135-
t.selectDeviceForTextureFormatOrSkipTestCase(format);
136-
})
137130
.fn(t => {
138131
const { format, aspect } = t.params;
139-
const info = kTextureFormatInfo[format];
132+
const { blockWidth, blockHeight } = getBlockInfoForTextureFormat(format);
133+
134+
t.skipIfTextureFormatNotSupported(format);
140135

141136
const texture = t.createTextureTracked({
142137
format,
143-
size: [info.blockWidth, info.blockHeight, 1],
138+
size: [blockWidth, blockHeight, 1],
144139
usage: GPUTextureUsage.TEXTURE_BINDING,
145140
});
146141

147142
const success =
148143
aspect === 'all' ||
149-
(aspect === 'depth-only' && info.depth) ||
150-
(aspect === 'stencil-only' && info.stencil);
144+
(aspect === 'depth-only' && isDepthTextureFormat(format)) ||
145+
(aspect === 'stencil-only' && isStencilTextureFormat(format));
151146
t.expectValidationError(() => {
152147
texture.createView({ aspect });
153148
}, !success);
@@ -277,7 +272,7 @@ g.test('mip_levels')
277272
const { textureDimension, viewDimension, textureLevels, baseMipLevel, mipLevelCount } =
278273
t.params;
279274

280-
t.skipIfTextureViewDimensionNotSupportedDeprecated(viewDimension);
275+
t.skipIfTextureViewDimensionNotSupported(viewDimension);
281276

282277
const textureDescriptor: GPUTextureDescriptor = {
283278
format: 'rgba8unorm',
@@ -317,7 +312,7 @@ g.test('cube_faces_square')
317312
.fn(t => {
318313
const { dimension, size } = t.params;
319314

320-
t.skipIfTextureViewDimensionNotSupportedDeprecated(dimension);
315+
t.skipIfTextureViewDimensionNotSupported(dimension);
321316

322317
const texture = t.createTextureTracked({
323318
format: 'rgba8unorm',
@@ -352,43 +347,31 @@ g.test('texture_view_usage')
352347
.combine('format', kAllTextureFormats)
353348
.combine('textureUsage0', kTextureUsages)
354349
.combine('textureUsage1', kTextureUsages)
355-
.filter(({ format, textureUsage0, textureUsage1 }) => {
356-
const info = kTextureFormatInfo[format];
350+
.unless(({ format, textureUsage0, textureUsage1 }) => {
357351
const textureUsage = textureUsage0 | textureUsage1;
358-
359-
if (
352+
return (
360353
(textureUsage & GPUConst.TextureUsage.RENDER_ATTACHMENT) !== 0 &&
361-
info.color &&
362-
!info.colorRender
363-
) {
364-
return false;
365-
}
366-
367-
return true;
354+
!isTextureFormatPossiblyUsableAsRenderAttachment(format)
355+
);
368356
})
369357
.beginSubcases()
370358
.combine('textureViewUsage0', [0, ...kTextureUsages])
371359
.combine('textureViewUsage1', [0, ...kTextureUsages])
372360
)
373-
.beforeAllSubcases(t => {
374-
const { format, textureUsage0, textureUsage1 } = t.params;
375-
const info = kTextureFormatInfo[format];
376-
const textureUsage = textureUsage0 | textureUsage1;
377-
t.skipIfTextureFormatNotSupportedDeprecated(format);
378-
t.selectDeviceOrSkipTestCase(info.feature);
379-
if (textureUsage & GPUTextureUsage.STORAGE_BINDING) {
380-
t.skipIfTextureFormatNotUsableAsStorageTextureDeprecated(format);
381-
}
382-
})
383361
.fn(t => {
384362
const { format, textureUsage0, textureUsage1, textureViewUsage0, textureViewUsage1 } = t.params;
385-
const info = kTextureFormatInfo[format];
386363

387-
const size = [info.blockWidth, info.blockHeight, 1];
364+
t.skipIfTextureFormatNotSupported(format);
365+
366+
const { blockWidth, blockHeight } = getBlockInfoForTextureFormat(format);
367+
368+
const size = [blockWidth, blockHeight, 1];
388369
const dimension = '2d';
389370
const mipLevelCount = 1;
390371
const usage = textureUsage0 | textureUsage1;
391372

373+
t.skipIfTextureFormatDoesNotSupportUsage(usage, format);
374+
392375
const textureDescriptor: GPUTextureDescriptor = {
393376
size,
394377
mipLevelCount,

src/webgpu/format_info.ts

+22
Original file line numberDiff line numberDiff line change
@@ -1784,6 +1784,19 @@ export function getBlockInfoForColorTextureFormat(format: ColorTextureFormat) {
17841784
};
17851785
}
17861786

1787+
/**
1788+
* Gets the block width, height, and bytes per block for a color texture format.
1789+
* Note that bytesPerBlock will be undefined if format's size is undefined.
1790+
*/
1791+
export function getBlockInfoForTextureFormat(format: GPUTextureFormat) {
1792+
const info = kTextureFormatInfo[format];
1793+
return {
1794+
blockWidth: info.blockWidth,
1795+
blockHeight: info.blockHeight,
1796+
bytesPerBlock: info.color?.bytes ?? info.depth?.bytes ?? info.stencil?.bytes,
1797+
};
1798+
}
1799+
17871800
/**
17881801
* Gets the baseFormat for a texture format.
17891802
*/
@@ -1863,6 +1876,15 @@ export function isTextureFormatColorRenderable(
18631876
return !!kAllTextureFormatInfo[format].colorRender;
18641877
}
18651878

1879+
/**
1880+
* Returns true of a texture can possibly be used as a render attachment.
1881+
* The texture may require certain features to be enabled.
1882+
*/
1883+
export function isTextureFormatPossiblyUsableAsRenderAttachment(format: GPUTextureFormat) {
1884+
const info = kTextureFormatInfo[format];
1885+
return format === 'rg11b10ufloat' || isDepthOrStencilTextureFormat(format) || !!info.colorRender;
1886+
}
1887+
18661888
export function is16Float(format: GPUTextureFormat) {
18671889
return format === 'r16float' || format === 'rg16float' || format === 'rgba16float';
18681890
}

src/webgpu/gpu_test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
isTextureFormatUsableAsStorageFormatDeprecated,
3636
isMultisampledTextureFormatDeprecated,
3737
isTextureFormatUsableAsStorageFormat,
38+
isTextureFormatUsableAsRenderAttachment,
3839
} from './format_info.js';
3940
import { checkElementsEqual, checkElementsBetween } from './util/check_contents.js';
4041
import { CommandBufferMaker, EncoderType } from './util/command_buffer_maker.js';
@@ -613,6 +614,29 @@ export class GPUTestBase extends Fixture<GPUTestSubcaseBatchState> {
613614
}
614615
}
615616

617+
skipIfTextureFormatNotUsableAsRenderAttachment(...formats: (GPUTextureFormat | undefined)[]) {
618+
for (const format of formats) {
619+
if (format && !isTextureFormatUsableAsRenderAttachment(this.device, format)) {
620+
this.skip(`Texture with ${format} is not usable as a render attachment`);
621+
}
622+
}
623+
}
624+
625+
skipIfTextureFormatDoesNotSupportUsage(
626+
usage: GPUTextureUsageFlags,
627+
...formats: (GPUTextureFormat | undefined)[]
628+
) {
629+
for (const format of formats) {
630+
if (!format) continue;
631+
if (usage & GPUTextureUsage.RENDER_ATTACHMENT) {
632+
this.skipIfTextureFormatNotUsableAsRenderAttachment(format);
633+
}
634+
if (usage & GPUTextureUsage.STORAGE_BINDING) {
635+
this.skipIfTextureFormatNotUsableAsStorageTexture(format);
636+
}
637+
}
638+
}
639+
616640
/** Skips this test case if the `langFeature` is *not* supported. */
617641
skipIfLanguageFeatureNotSupported(langFeature: WGSLLanguageFeature) {
618642
if (!this.hasLanguageFeature(langFeature)) {

0 commit comments

Comments
 (0)