Skip to content

Commit d8af8bf

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 1a34648 commit d8af8bf

File tree

9 files changed

+180
-267
lines changed

9 files changed

+180
-267
lines changed

src/webgpu/api/validation/encoding/createRenderBundleEncoder.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
isTextureFormatColorRenderable,
1515
kAllTextureFormats,
1616
kDepthStencilFormats,
17-
kRenderableColorTextureFormats,
17+
kPossibleColorRenderableTextureFormats,
1818
} from '../../../format_info.js';
1919
import { AllFeaturesMaxLimitsValidationTest } from '../validation_test.js';
2020

@@ -56,7 +56,7 @@ g.test('attachment_state,limits,maxColorAttachmentBytesPerSample,aligned')
5656
)
5757
.params(u =>
5858
u
59-
.combine('format', kRenderableColorTextureFormats)
59+
.combine('format', kPossibleColorRenderableTextureFormats)
6060
.beginSubcases()
6161
.combine(
6262
'colorFormatCount',

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

0 commit comments

Comments
 (0)