Skip to content

Commit e6b1970

Browse files
committed
Refactor compat tests for texture formats
Issue gpuweb#4181
1 parent 1245e3f commit e6b1970

File tree

6 files changed

+63
-51
lines changed

6 files changed

+63
-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
@@ -1551,6 +1551,18 @@ export const kPossibleStorageTextureFormats = [
15511551
'bgra8unorm',
15521552
] as const;
15531553

1554+
// Texture formats that may possibly be multisampled.
1555+
// Some may require certain features to be enabled.
1556+
export const kPossibleMultisampledTextureFormats = [
1557+
...kAllTextureFormats.filter(f => kTextureFormatInfo[f].multisample),
1558+
'rg11b10ufloat',
1559+
] as const;
1560+
1561+
// Texture formats that have a different base format. This is effectively all -srgb formats.
1562+
export const kDifferentBaseFormatTextureFormats = kAllTextureFormats.filter(
1563+
f => kTextureFormatInfo[f].baseFormat && kTextureFormatInfo[f].baseFormat !== f
1564+
);
1565+
15541566
/** Valid GPUTextureFormats for `copyExternalImageToTexture`, by spec. */
15551567
export const kValidTextureFormatsForCopyE2T = [
15561568
'r8unorm',
@@ -1781,6 +1793,7 @@ export function textureFormatsAreViewCompatible(
17811793

17821794
/**
17831795
* Gets the block width, height, and bytes per block for a color texture format.
1796+
* This is for color textures only. For all texture formats @see {@link getBlockInfoForTextureFormat}
17841797
*/
17851798
export function getBlockInfoForColorTextureFormat(format: ColorTextureFormat) {
17861799
const info = kTextureFormatInfo[format];
@@ -1794,6 +1807,7 @@ export function getBlockInfoForColorTextureFormat(format: ColorTextureFormat) {
17941807
/**
17951808
* Gets the block width, height, and bytes per block for a color texture format.
17961809
* Note that bytesPerBlock will be undefined if format's size is undefined.
1810+
* If you are only using color formats, @see {@link getBlockInfoForColorTextureFormat}
17971811
*/
17981812
export function getBlockInfoForTextureFormat(format: GPUTextureFormat) {
17991813
const info = kTextureFormatInfo[format];
@@ -1807,8 +1821,10 @@ export function getBlockInfoForTextureFormat(format: GPUTextureFormat) {
18071821
/**
18081822
* Gets the baseFormat for a texture format.
18091823
*/
1810-
export function getBaseFormatForTextureFormat(format: GPUTextureFormat) {
1811-
return kTextureFormatInfo[format].baseFormat;
1824+
export function getBaseFormatForTextureFormat(
1825+
format: (typeof kDifferentBaseFormatTextureFormats)[number]
1826+
): GPUTextureFormat {
1827+
return kTextureFormatInfo[format].baseFormat!;
18121828
}
18131829

18141830
/**
@@ -2034,6 +2050,9 @@ export function isTextureFormatResolvable(device: GPUDevice, format: GPUTextureF
20342050
return !!info.colorRender?.resolve;
20352051
}
20362052

2053+
// MAINTENANCE_TODD: See if we can remove this. This doesn't seem useful since
2054+
// formats are not on/off by feature. Some are on but feature allow them to be
2055+
// used in more cases, like going from un-renderable to renderable, etc...
20372056
export const kFeaturesForFormats = getFeaturesForFormats(kAllTextureFormats);
20382057

20392058
/**

src/webgpu/gpu_test.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
isMultisampledTextureFormatDeprecated,
3737
isTextureFormatUsableAsStorageFormat,
3838
isTextureFormatUsableAsRenderAttachment,
39+
isTextureFormatMultisampled,
3940
} from './format_info.js';
4041
import { checkElementsEqual, checkElementsBetween } from './util/check_contents.js';
4142
import { CommandBufferMaker, EncoderType } from './util/command_buffer_maker.js';
@@ -617,6 +618,15 @@ export class GPUTestBase extends Fixture<GPUTestSubcaseBatchState> {
617618
}
618619
}
619620

621+
skipIfTextureFormatNotMultisampled(...formats: (GPUTextureFormat | undefined)[]) {
622+
for (const format of formats) {
623+
if (format === undefined) continue;
624+
if (!isTextureFormatMultisampled(this.device, format)) {
625+
this.skip(`texture format '${format}' is not supported to be multisampled`);
626+
}
627+
}
628+
}
629+
620630
skipIfTextureFormatDoesNotSupportUsage(
621631
usage: GPUTextureUsageFlags,
622632
...formats: (GPUTextureFormat | undefined)[]
@@ -1454,7 +1464,9 @@ function applyLimitsToDescriptor(
14541464
}
14551465

14561466
function getAdapterFeaturesAsDeviceRequiredFeatures(adapter: GPUAdapter): Iterable<GPUFeatureName> {
1457-
return adapter.features as Iterable<GPUFeatureName>;
1467+
return [...adapter.features].filter(
1468+
f => f !== 'core-features-and-limits'
1469+
) as Iterable<GPUFeatureName>;
14581470
}
14591471

14601472
function applyFeaturesToDescriptor(

0 commit comments

Comments
 (0)