Skip to content

Commit ca11914

Browse files
committed
Refactor compat tests for texture formats
Issue gpuweb#4181
1 parent 88db5da commit ca11914

File tree

6 files changed

+62
-51
lines changed

6 files changed

+62
-51
lines changed

src/webgpu/compat/api/validation/encoding/cmds/copyTextureToBuffer.spec.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ Tests limitations of copyTextureToBuffer in compat mode.
33
`;
44

55
import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
6-
import { kCompressedTextureFormats, kTextureFormatInfo } from '../../../../../format_info.js';
6+
import {
7+
getBlockInfoForColorTextureFormat,
8+
kCompressedTextureFormats,
9+
} from '../../../../../format_info.js';
710
import { align } from '../../../../../util/math.js';
811
import { CompatibilityTest } from '../../../../compatibility_test.js';
912

@@ -12,14 +15,11 @@ export const g = makeTestGroup(CompatibilityTest);
1215
g.test('compressed')
1316
.desc(`Tests that you can not call copyTextureToBuffer with compressed textures in compat mode.`)
1417
.params(u => u.combine('format', kCompressedTextureFormats))
15-
.beforeAllSubcases(t => {
16-
const { format } = t.params;
17-
t.selectDeviceOrSkipTestCase([kTextureFormatInfo[format].feature]);
18-
})
1918
.fn(t => {
2019
const { format } = t.params;
20+
t.skipIfTextureFormatNotSupported(format);
2121

22-
const info = kTextureFormatInfo[format];
22+
const info = getBlockInfoForColorTextureFormat(format);
2323

2424
const textureSize = [info.blockWidth, info.blockHeight, 1];
2525
const texture = t.createTextureTracked({
@@ -28,7 +28,7 @@ g.test('compressed')
2828
usage: GPUTextureUsage.COPY_SRC,
2929
});
3030

31-
const bytesPerRow = align(info.color.bytes, 256);
31+
const bytesPerRow = align(info.bytesPerBlock, 256);
3232

3333
const buffer = t.createBufferTracked({
3434
size: bytesPerRow,

src/webgpu/compat/api/validation/encoding/cmds/copyTextureToTexture.spec.ts

+9-21
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ Tests limitations of copyTextureToTextures in compat mode.
44

55
import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
66
import {
7-
kAllTextureFormats,
7+
getBlockInfoForColorTextureFormat,
8+
getBlockInfoForTextureFormat,
89
kCompressedTextureFormats,
9-
kTextureFormatInfo,
10+
kPossibleMultisampledTextureFormats,
1011
} from '../../../../../format_info.js';
1112
import { CompatibilityTest } from '../../../../compatibility_test.js';
1213

@@ -15,14 +16,11 @@ export const g = makeTestGroup(CompatibilityTest);
1516
g.test('compressed')
1617
.desc(`Tests that you can not call copyTextureToTexture with compressed textures in compat mode.`)
1718
.params(u => u.combine('format', kCompressedTextureFormats))
18-
.beforeAllSubcases(t => {
19-
const { format } = t.params;
20-
t.selectDeviceOrSkipTestCase([kTextureFormatInfo[format].feature]);
21-
})
2219
.fn(t => {
2320
const { format } = t.params;
21+
t.skipIfTextureFormatNotSupported(format);
2422

25-
const { blockWidth, blockHeight } = kTextureFormatInfo[format];
23+
const { blockWidth, blockHeight } = getBlockInfoForColorTextureFormat(format);
2624

2725
const srcTexture = t.createTextureTracked({
2826
size: [blockWidth, blockHeight, 1],
@@ -49,23 +47,13 @@ g.test('compressed')
4947

5048
g.test('multisample')
5149
.desc(`Test that you can not call copyTextureToTexture with multisample textures in compat mode.`)
52-
.params(u =>
53-
u
54-
.combine('format', kAllTextureFormats)
55-
.beginSubcases()
56-
.filter(({ format }) => {
57-
const info = kTextureFormatInfo[format];
58-
return info.multisample && !info.feature;
59-
})
60-
)
61-
.beforeAllSubcases(t => {
62-
t.skipIfMultisampleNotSupportedForFormatDeprecated(t.params.format);
63-
})
50+
.params(u => u.combine('format', kPossibleMultisampledTextureFormats))
6451
.fn(t => {
6552
const { format } = t.params;
66-
const { blockWidth, blockHeight } = kTextureFormatInfo[format];
53+
const { blockWidth, blockHeight } = getBlockInfoForTextureFormat(format);
6754

68-
t.skipIfTextureFormatNotSupportedDeprecated(format as GPUTextureFormat);
55+
t.skipIfTextureFormatNotSupported(format);
56+
t.skipIfTextureFormatNotMultisampled(format);
6957

7058
const srcTexture = t.createTextureTracked({
7159
size: [blockWidth, blockHeight, 1],

src/webgpu/compat/api/validation/texture/createTexture.spec.ts

+11-18
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ Tests that textureBindingViewDimension must compatible with texture dimension
66
import { makeTestGroup } from '../../../../../common/framework/test_group.js';
77
import { kTextureDimensions, kTextureViewDimensions } from '../../../../capability_info.js';
88
import {
9-
kColorTextureFormats,
109
kCompatModeUnsupportedStorageTextureFormats,
11-
kTextureFormatInfo,
10+
kDifferentBaseFormatTextureFormats,
11+
getBlockInfoForTextureFormat,
12+
getBaseFormatForTextureFormat,
1213
} from '../../../../format_info.js';
1314
import { getTextureDimensionFromView } from '../../../../util/texture/base.js';
1415
import { CompatibilityTest } from '../../../compatibility_test.js';
@@ -121,27 +122,19 @@ g.test('format_reinterpretation')
121122
)
122123
.params(u =>
123124
u //
124-
.combine('format', kColorTextureFormats as GPUTextureFormat[])
125-
.filter(
126-
({ format }) =>
127-
!!kTextureFormatInfo[format].baseFormat &&
128-
kTextureFormatInfo[format].baseFormat !== format
129-
)
125+
.combine('format', kDifferentBaseFormatTextureFormats)
130126
)
131-
.beforeAllSubcases(t => {
132-
const info = kTextureFormatInfo[t.params.format];
133-
t.skipIfTextureFormatNotSupportedDeprecated(t.params.format);
134-
t.selectDeviceOrSkipTestCase(info.feature);
135-
})
136127
.fn(t => {
137128
const { format } = t.params;
138-
const info = kTextureFormatInfo[format];
129+
t.skipIfTextureFormatNotSupported(format);
130+
const info = getBlockInfoForTextureFormat(format);
131+
const baseFormat = getBaseFormatForTextureFormat(format);
139132

140133
const formatPairs = [
141-
{ format, viewFormats: [info.baseFormat!] },
142-
{ format: info.baseFormat!, viewFormats: [format] },
143-
{ format, viewFormats: [format, info.baseFormat!] },
144-
{ format: info.baseFormat!, viewFormats: [format, info.baseFormat!] },
134+
{ format, viewFormats: [baseFormat] },
135+
{ format: baseFormat, viewFormats: [format] },
136+
{ format, viewFormats: [format, baseFormat] },
137+
{ format: baseFormat, viewFormats: [format, baseFormat] },
145138
];
146139
for (const { format, viewFormats } of formatPairs) {
147140
t.expectGPUErrorInCompatibilityMode(

src/webgpu/compat/compatibility_test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { ValidationTest } from '../api/validation/validation_test.js';
1+
import { AllFeaturesMaxLimitsValidationTest } from '../api/validation/validation_test.js';
22

3-
export class CompatibilityTest extends ValidationTest {
3+
export class CompatibilityTest extends AllFeaturesMaxLimitsValidationTest {
44
override async init() {
55
await super.init();
66
}

src/webgpu/format_info.ts

+21-2
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,18 @@ export const kPossibleStorageTextureFormats = [
15601560
'bgra8unorm',
15611561
] as const;
15621562

1563+
// Texture formats that may possibly be multisampled.
1564+
// Some may require certain features to be enabled.
1565+
export const kPossibleMultisampledTextureFormats = [
1566+
...kAllTextureFormats.filter(f => kTextureFormatInfo[f].multisample),
1567+
'rg11b10ufloat',
1568+
] as const;
1569+
1570+
// Texture formats that have a different base format. This is effectively all -srgb formats.
1571+
export const kDifferentBaseFormatTextureFormats = kAllTextureFormats.filter(
1572+
f => kTextureFormatInfo[f].baseFormat && kTextureFormatInfo[f].baseFormat !== f
1573+
);
1574+
15631575
/** Valid GPUTextureFormats for `copyExternalImageToTexture`, by spec. */
15641576
export const kValidTextureFormatsForCopyE2T = [
15651577
'r8unorm',
@@ -1790,6 +1802,7 @@ export function textureFormatsAreViewCompatible(
17901802

17911803
/**
17921804
* Gets the block width, height, and bytes per block for a color texture format.
1805+
* This is for color textures only. For all texture formats @see {@link getBlockInfoForTextureFormat}
17931806
*/
17941807
export function getBlockInfoForColorTextureFormat(format: ColorTextureFormat) {
17951808
const info = kTextureFormatInfo[format];
@@ -1803,6 +1816,7 @@ export function getBlockInfoForColorTextureFormat(format: ColorTextureFormat) {
18031816
/**
18041817
* Gets the block width, height, and bytes per block for a color texture format.
18051818
* Note that bytesPerBlock will be undefined if format's size is undefined.
1819+
* If you are only using color formats, @see {@link getBlockInfoForColorTextureFormat}
18061820
*/
18071821
export function getBlockInfoForTextureFormat(format: GPUTextureFormat) {
18081822
const info = kTextureFormatInfo[format];
@@ -1816,8 +1830,10 @@ export function getBlockInfoForTextureFormat(format: GPUTextureFormat) {
18161830
/**
18171831
* Gets the baseFormat for a texture format.
18181832
*/
1819-
export function getBaseFormatForTextureFormat(format: GPUTextureFormat) {
1820-
return kTextureFormatInfo[format].baseFormat;
1833+
export function getBaseFormatForTextureFormat(
1834+
format: (typeof kDifferentBaseFormatTextureFormats)[number]
1835+
): GPUTextureFormat {
1836+
return kTextureFormatInfo[format].baseFormat!;
18211837
}
18221838

18231839
/**
@@ -2043,6 +2059,9 @@ export function isTextureFormatResolvable(device: GPUDevice, format: GPUTextureF
20432059
return !!info.colorRender?.resolve;
20442060
}
20452061

2062+
// MAINTENANCE_TODD: See if we can remove this. This doesn't seem useful since
2063+
// formats are not on/off by feature. Some are on but a feature allows them to be
2064+
// used in more cases, like going from un-renderable to renderable, etc...
20462065
export const kFeaturesForFormats = getFeaturesForFormats(kAllTextureFormats);
20472066

20482067
/**

src/webgpu/gpu_test.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,15 @@ export class GPUTestBase extends Fixture<GPUTestSubcaseBatchState> {
647647
}
648648
}
649649

650+
skipIfTextureFormatNotMultisampled(...formats: (GPUTextureFormat | undefined)[]) {
651+
for (const format of formats) {
652+
if (format === undefined) continue;
653+
if (!isTextureFormatMultisampled(this.device, format)) {
654+
this.skip(`texture format '${format}' is not supported to be multisampled`);
655+
}
656+
}
657+
}
658+
650659
skipIfTextureFormatDoesNotSupportUsage(
651660
usage: GPUTextureUsageFlags,
652661
...formats: (GPUTextureFormat | undefined)[]
@@ -1484,7 +1493,9 @@ function applyLimitsToDescriptor(
14841493
}
14851494

14861495
function getAdapterFeaturesAsDeviceRequiredFeatures(adapter: GPUAdapter): Iterable<GPUFeatureName> {
1487-
return adapter.features as Iterable<GPUFeatureName>;
1496+
return [...adapter.features].filter(
1497+
f => f !== 'core-features-and-limits'
1498+
) as Iterable<GPUFeatureName>;
14881499
}
14891500

14901501
function applyFeaturesToDescriptor(

0 commit comments

Comments
 (0)