Skip to content

Commit 4fee03f

Browse files
committed
Refactor api/validation/* with format_info.ts changes
Most of these files required changed to format_info.ts so bundling them together. Otherwise I just included all changes in valdiation/image_copy/* Issue gpuweb#4178 Issue gpuweb#4181
1 parent 5b12644 commit 4fee03f

File tree

8 files changed

+178
-265
lines changed

8 files changed

+178
-265
lines changed

src/webgpu/api/validation/image_copy/buffer_related.spec.ts

+9-13
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import { makeTestGroup } from '../../../../common/framework/test_group.js';
44
import { kTextureDimensions } from '../../../capability_info.js';
55
import { GPUConst } from '../../../constants.js';
66
import {
7+
getBlockInfoForSizedTextureFormat,
8+
isDepthOrStencilTextureFormat,
79
kSizedTextureFormats,
8-
kTextureFormatInfo,
910
textureDimensionAndFormatCompatible,
1011
} from '../../../format_info.js';
1112
import { kResourceStates } from '../../../gpu_test.js';
@@ -62,9 +63,7 @@ g.test('buffer,device_mismatch')
6263
.paramsSubcasesOnly(u =>
6364
u.combine('method', ['CopyB2T', 'CopyT2B'] as const).combine('mismatched', [true, false])
6465
)
65-
.beforeAllSubcases(t => {
66-
t.selectMismatchedDeviceOrSkipTestCase(undefined);
67-
})
66+
.beforeAllSubcases(t => t.usesMismatchedDevice())
6867
.fn(t => {
6968
const { method, mismatched } = t.params;
7069
const sourceDevice = mismatched ? t.mismatchedDevice : t.device;
@@ -170,29 +169,26 @@ Test that bytesPerRow must be a multiple of 256 for CopyB2T and CopyT2B if it is
170169
.unless(p => p.dimension === '1d' && p.copyHeightInBlocks > 1)
171170
// Depth/stencil format copies must copy the whole subresource.
172171
.unless(p => {
173-
const info = kTextureFormatInfo[p.format];
174172
return (
175-
(!!info.depth || !!info.stencil) && p.copyHeightInBlocks !== p._textureHeightInBlocks
173+
isDepthOrStencilTextureFormat(p.format) &&
174+
p.copyHeightInBlocks !== p._textureHeightInBlocks
176175
);
177176
})
178177
// bytesPerRow must be specified and it must be equal or greater than the bytes size of each row if we are copying multiple rows.
179178
// Note that we are copying one single block on each row in this test.
180179
.filter(
181180
({ format, bytesPerRow, copyHeightInBlocks }) =>
182181
(bytesPerRow === undefined && copyHeightInBlocks <= 1) ||
183-
(bytesPerRow !== undefined && bytesPerRow >= kTextureFormatInfo[format].bytesPerBlock)
182+
(bytesPerRow !== undefined &&
183+
bytesPerRow >= getBlockInfoForSizedTextureFormat(format).bytesPerBlock)
184184
)
185185
)
186-
.beforeAllSubcases(t => {
187-
const info = kTextureFormatInfo[t.params.format];
188-
t.skipIfTextureFormatNotSupportedDeprecated(t.params.format);
189-
t.selectDeviceOrSkipTestCase(info.feature);
190-
})
191186
.fn(t => {
192187
const { method, dimension, format, bytesPerRow, copyHeightInBlocks, _textureHeightInBlocks } =
193188
t.params;
189+
t.skipIfTextureFormatNotSupported(format);
194190

195-
const info = kTextureFormatInfo[format];
191+
const info = getBlockInfoForSizedTextureFormat(format);
196192

197193
const buffer = t.createBufferTracked({
198194
size: 512 * 8 * 16,

src/webgpu/api/validation/image_copy/buffer_texture_copies.spec.ts

+6-17
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import {
1414
} from '../../../format_info.js';
1515
import { align } from '../../../util/math.js';
1616
import { kBufferCopyAlignment, kBytesPerRowAlignment } from '../../../util/texture/layout.js';
17-
import { ValidationTest } from '../validation_test.js';
17+
import { AllFeaturesMaxLimitsValidationTest } from '../validation_test.js';
1818

19-
class ImageCopyTest extends ValidationTest {
19+
class ImageCopyTest extends AllFeaturesMaxLimitsValidationTest {
2020
testCopyBufferToTexture(
2121
source: GPUTexelCopyBufferInfo,
2222
destination: GPUTexelCopyTextureInfo,
@@ -70,12 +70,9 @@ g.test('depth_stencil_format,copy_usage_and_aspect')
7070
.beginSubcases()
7171
.combine('aspect', ['all', 'depth-only', 'stencil-only'] as const)
7272
)
73-
.beforeAllSubcases(t => {
74-
const { format } = t.params;
75-
t.selectDeviceForTextureFormatOrSkipTestCase(format);
76-
})
7773
.fn(t => {
7874
const { format, aspect } = t.params;
75+
t.skipIfTextureFormatNotSupported(format);
7976

8077
const textureSize = { width: 1, height: 1, depthOrArrayLayers: 1 };
8178
const texture = t.createTextureTracked({
@@ -135,12 +132,9 @@ g.test('depth_stencil_format,copy_buffer_size')
135132
{ width: 4, height: 4, depthOrArrayLayers: 3 },
136133
])
137134
)
138-
.beforeAllSubcases(t => {
139-
const { format } = t.params;
140-
t.selectDeviceForTextureFormatOrSkipTestCase(format);
141-
})
142135
.fn(t => {
143136
const { format, aspect, copyType, copySize } = t.params;
137+
t.skipIfTextureFormatNotSupported(format);
144138

145139
const texture = t.createTextureTracked({
146140
size: copySize,
@@ -242,12 +236,9 @@ g.test('depth_stencil_format,copy_buffer_offset')
242236
.beginSubcases()
243237
.combine('offset', [1, 2, 4, 6, 8])
244238
)
245-
.beforeAllSubcases(t => {
246-
const { format } = t.params;
247-
t.selectDeviceForTextureFormatOrSkipTestCase(format);
248-
})
249239
.fn(t => {
250240
const { format, aspect, copyType, offset } = t.params;
241+
t.skipIfTextureFormatNotSupported(format);
251242

252243
const textureSize = { width: 4, height: 4, depthOrArrayLayers: 1 };
253244

@@ -422,9 +413,7 @@ g.test('device_mismatch')
422413
{ bufMismatched: false, texMismatched: true },
423414
] as const)
424415
)
425-
.beforeAllSubcases(t => {
426-
t.selectMismatchedDeviceOrSkipTestCase(undefined);
427-
})
416+
.beforeAllSubcases(t => t.usesMismatchedDevice())
428417
.fn(t => {
429418
const { copyType, bufMismatched, texMismatched } = t.params;
430419

src/webgpu/api/validation/image_copy/image_copy.ts

+15-16
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import {
22
depthStencilFormatCopyableAspects,
33
DepthStencilFormat,
44
SizedTextureFormat,
5-
kTextureFormatInfo,
65
isCompressedTextureFormat,
6+
getBlockInfoForTextureFormat,
7+
isDepthOrStencilTextureFormat,
8+
canCopyFromAllAspectsOfTextureFormat,
79
} from '../../../format_info.js';
810
import { align } from '../../../util/math.js';
911
import { ImageCopyType } from '../../../util/texture/layout.js';
10-
import { ValidationTest } from '../validation_test.js';
12+
import { AllFeaturesMaxLimitsValidationTest } from '../validation_test.js';
1113

12-
export class ImageCopyTest extends ValidationTest {
14+
export class ImageCopyTest extends AllFeaturesMaxLimitsValidationTest {
1315
testRun(
1416
textureCopyView: GPUTexelCopyTextureInfo,
1517
textureDataLayout: GPUTexelCopyBufferLayout,
@@ -105,7 +107,7 @@ export class ImageCopyTest extends ValidationTest {
105107
origin: Required<GPUOrigin3DDict> = { x: 0, y: 0, z: 0 },
106108
dimension: Required<GPUTextureDimension> = '2d'
107109
): GPUTexture {
108-
const info = kTextureFormatInfo[format];
110+
const info = getBlockInfoForTextureFormat(format);
109111
const alignedSize = {
110112
width: align(Math.max(1, size.width + origin.x), info.blockWidth),
111113
height: align(Math.max(1, size.height + origin.y), info.blockHeight),
@@ -209,17 +211,16 @@ interface WithFormatAndMethod extends WithFormat {
209211

210212
// This is a helper function used for expanding test parameters for offset alignment, by spec
211213
export function texelBlockAlignmentTestExpanderForOffset({ format }: WithFormat) {
212-
const info = kTextureFormatInfo[format];
213-
if (info.depth || info.stencil) {
214+
if (isDepthOrStencilTextureFormat(format)) {
214215
return valuesToTestDivisibilityBy(4);
215216
}
216217

217-
return valuesToTestDivisibilityBy(kTextureFormatInfo[format].bytesPerBlock);
218+
return valuesToTestDivisibilityBy(getBlockInfoForTextureFormat(format).bytesPerBlock!);
218219
}
219220

220221
// This is a helper function used for expanding test parameters for texel block alignment tests on rowsPerImage
221222
export function texelBlockAlignmentTestExpanderForRowsPerImage({ format }: WithFormat) {
222-
return valuesToTestDivisibilityBy(kTextureFormatInfo[format].blockHeight);
223+
return valuesToTestDivisibilityBy(getBlockInfoForTextureFormat(format).blockHeight);
223224
}
224225

225226
// This is a helper function used for expanding test parameters for texel block alignment tests on origin and size
@@ -230,11 +231,11 @@ export function texelBlockAlignmentTestExpanderForValueToCoordinate({
230231
switch (coordinateToTest) {
231232
case 'x':
232233
case 'width':
233-
return valuesToTestDivisibilityBy(kTextureFormatInfo[format].blockWidth);
234+
return valuesToTestDivisibilityBy(getBlockInfoForTextureFormat(format).blockWidth);
234235

235236
case 'y':
236237
case 'height':
237-
return valuesToTestDivisibilityBy(kTextureFormatInfo[format].blockHeight);
238+
return valuesToTestDivisibilityBy(getBlockInfoForTextureFormat(format).blockHeight);
238239

239240
case 'z':
240241
case 'depthOrArrayLayers':
@@ -244,18 +245,17 @@ export function texelBlockAlignmentTestExpanderForValueToCoordinate({
244245

245246
// This is a helper function used for filtering test parameters
246247
export function formatCopyableWithMethod({ format, method }: WithFormatAndMethod): boolean {
247-
const info = kTextureFormatInfo[format];
248-
if (info.depth || info.stencil) {
248+
if (isDepthOrStencilTextureFormat(format)) {
249249
const supportedAspects: readonly GPUTextureAspect[] = depthStencilFormatCopyableAspects(
250250
method,
251251
format as DepthStencilFormat
252252
);
253253
return supportedAspects.length > 0;
254254
}
255255
if (method === 'CopyT2B') {
256-
return info.color.copySrc;
256+
return canCopyFromAllAspectsOfTextureFormat(format);
257257
} else {
258-
return info.color.copyDst;
258+
return canCopyFromAllAspectsOfTextureFormat(format);
259259
}
260260
}
261261

@@ -264,8 +264,7 @@ export function getACopyableAspectWithMethod({
264264
format,
265265
method,
266266
}: WithFormatAndMethod): GPUTextureAspect {
267-
const info = kTextureFormatInfo[format];
268-
if (info.depth || info.stencil) {
267+
if (isDepthOrStencilTextureFormat(format)) {
269268
const supportedAspects: readonly GPUTextureAspect[] = depthStencilFormatCopyableAspects(
270269
method,
271270
format as DepthStencilFormat

src/webgpu/api/validation/image_copy/layout_related.spec.ts

+27-39
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import { makeTestGroup } from '../../../../common/framework/test_group.js';
66
import { assert } from '../../../../common/util/util.js';
77
import { kTextureDimensions } from '../../../capability_info.js';
88
import {
9-
kTextureFormatInfo,
109
kSizedTextureFormats,
1110
textureDimensionAndFormatCompatible,
11+
getBlockInfoForTextureFormat,
12+
isDepthOrStencilTextureFormat,
13+
getBlockInfoForSizedTextureFormat,
14+
getBlockInfoForColorTextureFormat,
1215
} from '../../../format_info.js';
1316
import { align } from '../../../util/math.js';
1417
import {
@@ -58,7 +61,7 @@ Test that rowsPerImage must be at least the copy height (if defined).
5861
const { rowsPerImage, copyHeightInBlocks, copyDepth, dimension, size, method } = t.params;
5962

6063
const format = 'rgba8unorm';
61-
const copyHeight = copyHeightInBlocks * kTextureFormatInfo[format].blockHeight;
64+
const copyHeight = copyHeightInBlocks * getBlockInfoForTextureFormat(format).blockHeight;
6265

6366
const texture = t.createTextureTracked({
6467
size,
@@ -162,26 +165,19 @@ Test the computation of requiredBytesInCopy by computing the minimum data size f
162165
// If the format is a depth/stencil format, its copy size must equal to subresource's size.
163166
// So filter out depth/stencil cases where the rounded-up texture size would be different from the copy size.
164167
.filter(({ format, copyWidthInBlocks, copyHeightInBlocks, copyDepth }) => {
165-
const info = kTextureFormatInfo[format];
166168
return (
167-
(!info.depth && !info.stencil) ||
169+
!isDepthOrStencilTextureFormat(format) ||
168170
(copyWidthInBlocks > 0 && copyHeightInBlocks > 0 && copyDepth > 0)
169171
);
170172
})
171173
.unless(p => p.dimension === '1d' && (p.copyHeightInBlocks > 1 || p.copyDepth > 1))
172174
.expand('offset', p => {
173-
const info = kTextureFormatInfo[p.format];
174-
if (info.depth || info.stencil) {
175+
if (isDepthOrStencilTextureFormat(p.format)) {
175176
return [p._offsetMultiplier * 4];
176177
}
177-
return [p._offsetMultiplier * info.color.bytes];
178+
return [p._offsetMultiplier * getBlockInfoForSizedTextureFormat(p.format).bytesPerBlock];
178179
})
179180
)
180-
.beforeAllSubcases(t => {
181-
const info = kTextureFormatInfo[t.params.format];
182-
t.skipIfTextureFormatNotSupportedDeprecated(t.params.format);
183-
t.selectDeviceOrSkipTestCase(info.feature);
184-
})
185181
.fn(t => {
186182
const {
187183
offset,
@@ -194,7 +190,8 @@ Test the computation of requiredBytesInCopy by computing the minimum data size f
194190
dimension,
195191
method,
196192
} = t.params;
197-
const info = kTextureFormatInfo[format];
193+
t.skipIfTextureFormatNotSupported(format);
194+
const info = getBlockInfoForSizedTextureFormat(format);
198195

199196
// In the CopyB2T and CopyT2B cases we need to have bytesPerRow 256-aligned,
200197
// to make this happen we align the bytesInACompleteRow value and multiply
@@ -248,16 +245,15 @@ Test that rowsPerImage has no alignment constraints.
248245
.beginSubcases()
249246
.expand('rowsPerImage', texelBlockAlignmentTestExpanderForRowsPerImage)
250247
// Copy height is info.blockHeight, so rowsPerImage must be equal or greater than it.
251-
.filter(({ rowsPerImage, format }) => rowsPerImage >= kTextureFormatInfo[format].blockHeight)
248+
.filter(
249+
({ rowsPerImage, format }) =>
250+
rowsPerImage >= getBlockInfoForSizedTextureFormat(format).blockHeight
251+
)
252252
)
253-
.beforeAllSubcases(t => {
254-
const info = kTextureFormatInfo[t.params.format];
255-
t.skipIfTextureFormatNotSupportedDeprecated(t.params.format);
256-
t.selectDeviceOrSkipTestCase(info.feature);
257-
})
258253
.fn(t => {
259254
const { rowsPerImage, format, method } = t.params;
260-
const info = kTextureFormatInfo[format];
255+
t.skipIfTextureFormatNotSupported(format);
256+
const info = getBlockInfoForSizedTextureFormat(format);
261257

262258
const size = { width: info.blockWidth, height: info.blockHeight, depthOrArrayLayers: 1 };
263259
const texture = t.createTextureTracked({
@@ -293,14 +289,10 @@ Test the alignment requirement on the linear data offset (block size, or 4 for d
293289
.beginSubcases()
294290
.expand('offset', texelBlockAlignmentTestExpanderForOffset)
295291
)
296-
.beforeAllSubcases(t => {
297-
const info = kTextureFormatInfo[t.params.format];
298-
t.skipIfTextureFormatNotSupportedDeprecated(t.params.format);
299-
t.selectDeviceOrSkipTestCase(info.feature);
300-
})
301292
.fn(t => {
302293
const { format, offset, method } = t.params;
303-
const info = kTextureFormatInfo[format];
294+
t.skipIfTextureFormatNotSupported(format);
295+
const info = getBlockInfoForSizedTextureFormat(format);
304296

305297
const size = { width: info.blockWidth, height: info.blockHeight, depthOrArrayLayers: 1 };
306298
const texture = t.createTextureTracked({
@@ -311,10 +303,10 @@ Test the alignment requirement on the linear data offset (block size, or 4 for d
311303

312304
let success = false;
313305
if (method === 'WriteTexture') success = true;
314-
if (info.depth || info.stencil) {
306+
if (isDepthOrStencilTextureFormat(format)) {
315307
if (offset % 4 === 0) success = true;
316308
} else {
317-
if (offset % info.color.bytes === 0) success = true;
309+
if (offset % info.bytesPerBlock === 0) success = true;
318310
}
319311

320312
t.testRun({ texture }, { offset, bytesPerRow: 256 }, size, {
@@ -348,7 +340,7 @@ Test that bytesPerRow, if specified must be big enough for a full copy row.
348340
.combine('copyDepth', [1, 2])
349341
.unless(p => p.dimension === '1d' && (p.copyHeightInBlocks > 1 || p.copyDepth > 1))
350342
.expandWithParams(p => {
351-
const info = kTextureFormatInfo[p.format];
343+
const info = getBlockInfoForSizedTextureFormat(p.format);
352344
// We currently have a built-in assumption that for all formats, 128 % bytesPerBlock === 0.
353345
// This assumption ensures that all division below results in integers.
354346
assert(128 % info.bytesPerBlock === 0);
@@ -366,7 +358,7 @@ Test that bytesPerRow, if specified must be big enough for a full copy row.
366358
bytesPerRow: 256,
367359
widthInBlocks: 256 / info.bytesPerBlock,
368360
copyWidthInBlocks: 256 / info.bytesPerBlock - 1,
369-
_success: !(info.stencil || info.depth),
361+
_success: !isDepthOrStencilTextureFormat(p.format),
370362
},
371363
// Unaligned bytesPerRow should not work unless the method is 'WriteTexture'.
372364
{
@@ -398,11 +390,6 @@ Test that bytesPerRow, if specified must be big enough for a full copy row.
398390
];
399391
})
400392
)
401-
.beforeAllSubcases(t => {
402-
const info = kTextureFormatInfo[t.params.format];
403-
t.skipIfTextureFormatNotSupportedDeprecated(t.params.format);
404-
t.selectDeviceOrSkipTestCase(info.feature);
405-
})
406393
.fn(t => {
407394
const {
408395
method,
@@ -414,7 +401,8 @@ Test that bytesPerRow, if specified must be big enough for a full copy row.
414401
copyDepth,
415402
_success,
416403
} = t.params;
417-
const info = kTextureFormatInfo[format];
404+
t.skipIfTextureFormatNotSupported(format);
405+
const info = getBlockInfoForSizedTextureFormat(format);
418406

419407
// We create an aligned texture using the widthInBlocks which may be different from the
420408
// copyWidthInBlocks. This allows us to test scenarios where the two may be different.
@@ -462,9 +450,9 @@ Test that the offset cannot be larger than the linear data size (even for an emp
462450
const { offsetInBlocks, dataSizeInBlocks, method } = t.params;
463451

464452
const format = 'rgba8unorm';
465-
const info = kTextureFormatInfo[format];
466-
const offset = offsetInBlocks * info.color.bytes;
467-
const dataSize = dataSizeInBlocks * info.color.bytes;
453+
const info = getBlockInfoForColorTextureFormat(format);
454+
const offset = offsetInBlocks * info.bytesPerBlock;
455+
const dataSize = dataSizeInBlocks * info.bytesPerBlock;
468456

469457
const texture = t.createTextureTracked({
470458
size: { width: 4, height: 4, depthOrArrayLayers: 1 },

0 commit comments

Comments
 (0)