Skip to content

Commit 4cd743e

Browse files
committed
Refactor api/operation/rendering/*
Issue gpuweb#4181 Issue gpuweb#4178
1 parent c8154cf commit 4cd743e

10 files changed

+159
-165
lines changed

src/webgpu/api/operation/rendering/3d_texture_slices.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ Test rendering to 3d texture slices.
55
`;
66

77
import { makeTestGroup } from '../../../../common/framework/test_group.js';
8-
import { kTextureFormatInfo } from '../../../format_info.js';
9-
import { GPUTest } from '../../../gpu_test.js';
8+
import { getColorRenderByteCost } from '../../../format_info.js';
9+
import { AllFeaturesMaxLimitsGPUTest } from '../../../gpu_test.js';
1010
import { kBytesPerRowAlignment } from '../../../util/texture/layout.js';
1111

1212
const kSize = 4;
1313
const kFormat = 'rgba8unorm' as const;
1414

15-
class F extends GPUTest {
15+
class F extends AllFeaturesMaxLimitsGPUTest {
1616
createShaderModule(attachmentCount: number = 1): GPUShaderModule {
1717
let locations = '';
1818
let outputs = '';
@@ -170,7 +170,7 @@ g.test('multiple_color_attachments,same_mip_level')
170170
.fn(t => {
171171
const { sameTexture, samePass, mipLevel } = t.params;
172172

173-
const formatByteCost = kTextureFormatInfo[kFormat].colorRender.byteCost;
173+
const formatByteCost = getColorRenderByteCost(kFormat);
174174
const maxAttachmentCountPerSample = Math.trunc(
175175
t.device.limits.maxColorAttachmentBytesPerSample / formatByteCost
176176
);
@@ -288,7 +288,7 @@ g.test('multiple_color_attachments,same_slice_with_diff_mip_levels')
288288

289289
const kBaseSize = 1;
290290

291-
const formatByteCost = kTextureFormatInfo[kFormat].colorRender.byteCost;
291+
const formatByteCost = getColorRenderByteCost(kFormat);
292292
const maxAttachmentCountPerSample = Math.trunc(
293293
t.device.limits.maxColorAttachmentBytesPerSample / formatByteCost
294294
);

src/webgpu/api/operation/rendering/basic.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ Basic command buffer rendering tests.
44

55
import { makeTestGroup } from '../../../../common/framework/test_group.js';
66
import { now } from '../../../../common/util/util.js';
7-
import { GPUTest } from '../../../gpu_test.js';
7+
import { AllFeaturesMaxLimitsGPUTest } from '../../../gpu_test.js';
88
import { checkElementsEqual } from '../../../util/check_contents.js';
99

10-
export const g = makeTestGroup(GPUTest);
10+
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);
1111

1212
g.test('clear').fn(t => {
1313
const dst = t.createBufferTracked({

src/webgpu/api/operation/rendering/color_target_state.spec.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ import {
1515
kBlendOperations,
1616
} from '../../../capability_info.js';
1717
import { GPUConst } from '../../../constants.js';
18-
import { kRegularTextureFormats, kTextureFormatInfo } from '../../../format_info.js';
19-
import { GPUTest, TextureTestMixin } from '../../../gpu_test.js';
18+
import {
19+
EncodableTextureFormat,
20+
kPossibleColorRenderableTextureFormats,
21+
} from '../../../format_info.js';
22+
import { AllFeaturesMaxLimitsGPUTest, TextureTestMixin } from '../../../gpu_test.js';
2023
import { clamp } from '../../../util/math.js';
2124
import { TexelView } from '../../../util/texture/texel_view.js';
2225

23-
class BlendingTest extends GPUTest {
26+
class BlendingTest extends AllFeaturesMaxLimitsGPUTest {
2427
createRenderPipelineForTest(colorTargetState: GPUColorTargetState): GPURenderPipeline {
2528
return this.device.createRenderPipeline({
2629
layout: 'auto',
@@ -378,25 +381,19 @@ struct FragOutput {
378381
);
379382
});
380383

381-
const kBlendableFormats = kRegularTextureFormats.filter(f => {
382-
const info = kTextureFormatInfo[f];
383-
return info.colorRender && info.color.type === 'float';
384-
});
385-
386384
g.test('blending,formats')
387385
.desc(
388386
`Test blending results works for all formats that support it, and that blending is not applied
389387
for formats that do not. Blending should be done in linear space for srgb formats.`
390388
)
391389
.params(u =>
392390
u //
393-
.combine('format', kBlendableFormats)
391+
.combine('format', kPossibleColorRenderableTextureFormats)
394392
)
395-
.beforeAllSubcases(t => {
396-
t.skipIfTextureFormatNotSupportedDeprecated(t.params.format);
397-
})
398393
.fn(t => {
399394
const { format } = t.params;
395+
t.skipIfTextureFormatNotSupported(format);
396+
t.skipIfTextureFormatNotBlendable(format);
400397

401398
const pipeline = t.device.createRenderPipeline({
402399
layout: 'auto',
@@ -457,7 +454,10 @@ g.test('blending,formats')
457454
t.device.queue.submit([commandEncoder.finish()]);
458455

459456
const expColor = { R: 0.6, G: 0.6, B: 0.6, A: 0.6 };
460-
const expTexelView = TexelView.fromTexelsAsColors(format, _coords => expColor);
457+
const expTexelView = TexelView.fromTexelsAsColors(
458+
format as EncodableTextureFormat,
459+
_coords => expColor
460+
);
461461
t.expectTexelViewComparisonIsOkInTexture({ texture: renderTarget }, expTexelView, [1, 1, 1]);
462462
});
463463

src/webgpu/api/operation/rendering/depth.spec.ts

+50-57
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Test related to depth buffer, depth op, compare func, etc.
44

55
import { makeTestGroup } from '../../../../common/framework/test_group.js';
66
import { TypedArrayBufferView } from '../../../../common/util/util.js';
7-
import { kDepthStencilFormats, kTextureFormatInfo } from '../../../format_info.js';
8-
import { GPUTest, TextureTestMixin } from '../../../gpu_test.js';
7+
import { isStencilTextureFormat, kDepthTextureFormats } from '../../../format_info.js';
8+
import { AllFeaturesMaxLimitsGPUTest, TextureTestMixin } from '../../../gpu_test.js';
99
import { TexelView } from '../../../util/texture/texel_view.js';
1010

1111
const backgroundColor = [0x00, 0x00, 0x00, 0xff];
@@ -21,7 +21,7 @@ type TestStates = {
2121
depth: number;
2222
};
2323

24-
class DepthTest extends TextureTestMixin(GPUTest) {
24+
class DepthTest extends TextureTestMixin(AllFeaturesMaxLimitsGPUTest) {
2525
runDepthStateTest(testStates: TestStates[], expectedColor: Float32Array) {
2626
const renderTargetFormat = 'rgba8unorm';
2727

@@ -187,7 +187,7 @@ g.test('depth_write_disabled')
187187
.fn(t => {
188188
const { depthWriteEnabled, lastDepth, _expectedColor } = t.params;
189189

190-
const depthSpencilFormat: GPUTextureFormat = 'depth24plus-stencil8';
190+
const depthStencilFormat: GPUTextureFormat = 'depth24plus-stencil8';
191191

192192
const stencilState = {
193193
compare: 'always',
@@ -197,7 +197,7 @@ g.test('depth_write_disabled')
197197
} as const;
198198

199199
const baseState = {
200-
format: depthSpencilFormat,
200+
format: depthStencilFormat,
201201
depthWriteEnabled: true,
202202
depthCompare: 'always',
203203
stencilFront: stencilState,
@@ -207,7 +207,7 @@ g.test('depth_write_disabled')
207207
} as const;
208208

209209
const depthWriteState = {
210-
format: depthSpencilFormat,
210+
format: depthStencilFormat,
211211
depthWriteEnabled,
212212
depthCompare: 'always',
213213
stencilFront: stencilState,
@@ -217,7 +217,7 @@ g.test('depth_write_disabled')
217217
} as const;
218218

219219
const checkState = {
220-
format: depthSpencilFormat,
220+
format: depthStencilFormat,
221221
depthWriteEnabled: false,
222222
depthCompare: 'equal',
223223
stencilFront: stencilState,
@@ -256,18 +256,18 @@ g.test('depth_test_fail')
256256
.fn(t => {
257257
const { secondDepth, lastDepth, _expectedColor } = t.params;
258258

259-
const depthSpencilFormat: GPUTextureFormat = 'depth24plus-stencil8';
259+
const depthStencilFormat: GPUTextureFormat = 'depth24plus-stencil8';
260260

261261
const baseState = {
262-
format: depthSpencilFormat,
262+
format: depthStencilFormat,
263263
depthWriteEnabled: true,
264264
depthCompare: 'always',
265265
stencilReadMask: 0xff,
266266
stencilWriteMask: 0xff,
267267
} as const;
268268

269269
const depthTestState = {
270-
format: depthSpencilFormat,
270+
format: depthStencilFormat,
271271
depthWriteEnabled: true,
272272
depthCompare: 'less',
273273
stencilReadMask: 0xff,
@@ -292,55 +292,48 @@ g.test('depth_compare_func')
292292
`Tests each depth compare function works properly. Clears the depth attachment to various values, and renders a point at depth 0.5 with various depthCompare modes.`
293293
)
294294
.params(u =>
295-
u
296-
.combine(
297-
'format',
298-
kDepthStencilFormats.filter(format => kTextureFormatInfo[format].depth)
299-
)
300-
.combineWithParams([
301-
{ depthCompare: 'never', depthClearValue: 1.0, _expected: backgroundColor },
302-
{ depthCompare: 'never', depthClearValue: kMiddleDepthValue, _expected: backgroundColor },
303-
{ depthCompare: 'never', depthClearValue: 0.0, _expected: backgroundColor },
304-
{ depthCompare: 'less', depthClearValue: 1.0, _expected: triangleColor },
305-
{ depthCompare: 'less', depthClearValue: kMiddleDepthValue, _expected: backgroundColor },
306-
{ depthCompare: 'less', depthClearValue: 0.0, _expected: backgroundColor },
307-
{ depthCompare: 'less-equal', depthClearValue: 1.0, _expected: triangleColor },
308-
{
309-
depthCompare: 'less-equal',
310-
depthClearValue: kMiddleDepthValue,
311-
_expected: triangleColor,
312-
},
313-
{ depthCompare: 'less-equal', depthClearValue: 0.0, _expected: backgroundColor },
314-
{ depthCompare: 'equal', depthClearValue: 1.0, _expected: backgroundColor },
315-
{ depthCompare: 'equal', depthClearValue: kMiddleDepthValue, _expected: triangleColor },
316-
{ depthCompare: 'equal', depthClearValue: 0.0, _expected: backgroundColor },
317-
{ depthCompare: 'not-equal', depthClearValue: 1.0, _expected: triangleColor },
318-
{
319-
depthCompare: 'not-equal',
320-
depthClearValue: kMiddleDepthValue,
321-
_expected: backgroundColor,
322-
},
323-
{ depthCompare: 'not-equal', depthClearValue: 0.0, _expected: triangleColor },
324-
{ depthCompare: 'greater-equal', depthClearValue: 1.0, _expected: backgroundColor },
325-
{
326-
depthCompare: 'greater-equal',
327-
depthClearValue: kMiddleDepthValue,
328-
_expected: triangleColor,
329-
},
330-
{ depthCompare: 'greater-equal', depthClearValue: 0.0, _expected: triangleColor },
331-
{ depthCompare: 'greater', depthClearValue: 1.0, _expected: backgroundColor },
332-
{ depthCompare: 'greater', depthClearValue: kMiddleDepthValue, _expected: backgroundColor },
333-
{ depthCompare: 'greater', depthClearValue: 0.0, _expected: triangleColor },
334-
{ depthCompare: 'always', depthClearValue: 1.0, _expected: triangleColor },
335-
{ depthCompare: 'always', depthClearValue: kMiddleDepthValue, _expected: triangleColor },
336-
{ depthCompare: 'always', depthClearValue: 0.0, _expected: triangleColor },
337-
] as const)
295+
u.combine('format', kDepthTextureFormats).combineWithParams([
296+
{ depthCompare: 'never', depthClearValue: 1.0, _expected: backgroundColor },
297+
{ depthCompare: 'never', depthClearValue: kMiddleDepthValue, _expected: backgroundColor },
298+
{ depthCompare: 'never', depthClearValue: 0.0, _expected: backgroundColor },
299+
{ depthCompare: 'less', depthClearValue: 1.0, _expected: triangleColor },
300+
{ depthCompare: 'less', depthClearValue: kMiddleDepthValue, _expected: backgroundColor },
301+
{ depthCompare: 'less', depthClearValue: 0.0, _expected: backgroundColor },
302+
{ depthCompare: 'less-equal', depthClearValue: 1.0, _expected: triangleColor },
303+
{
304+
depthCompare: 'less-equal',
305+
depthClearValue: kMiddleDepthValue,
306+
_expected: triangleColor,
307+
},
308+
{ depthCompare: 'less-equal', depthClearValue: 0.0, _expected: backgroundColor },
309+
{ depthCompare: 'equal', depthClearValue: 1.0, _expected: backgroundColor },
310+
{ depthCompare: 'equal', depthClearValue: kMiddleDepthValue, _expected: triangleColor },
311+
{ depthCompare: 'equal', depthClearValue: 0.0, _expected: backgroundColor },
312+
{ depthCompare: 'not-equal', depthClearValue: 1.0, _expected: triangleColor },
313+
{
314+
depthCompare: 'not-equal',
315+
depthClearValue: kMiddleDepthValue,
316+
_expected: backgroundColor,
317+
},
318+
{ depthCompare: 'not-equal', depthClearValue: 0.0, _expected: triangleColor },
319+
{ depthCompare: 'greater-equal', depthClearValue: 1.0, _expected: backgroundColor },
320+
{
321+
depthCompare: 'greater-equal',
322+
depthClearValue: kMiddleDepthValue,
323+
_expected: triangleColor,
324+
},
325+
{ depthCompare: 'greater-equal', depthClearValue: 0.0, _expected: triangleColor },
326+
{ depthCompare: 'greater', depthClearValue: 1.0, _expected: backgroundColor },
327+
{ depthCompare: 'greater', depthClearValue: kMiddleDepthValue, _expected: backgroundColor },
328+
{ depthCompare: 'greater', depthClearValue: 0.0, _expected: triangleColor },
329+
{ depthCompare: 'always', depthClearValue: 1.0, _expected: triangleColor },
330+
{ depthCompare: 'always', depthClearValue: kMiddleDepthValue, _expected: triangleColor },
331+
{ depthCompare: 'always', depthClearValue: 0.0, _expected: triangleColor },
332+
] as const)
338333
)
339-
.beforeAllSubcases(t => {
340-
t.selectDeviceForTextureFormatOrSkipTestCase(t.params.format);
341-
})
342334
.fn(t => {
343335
const { depthCompare, depthClearValue, _expected, format } = t.params;
336+
t.skipIfTextureFormatNotSupported(format);
344337

345338
const colorAttachmentFormat = 'rgba8unorm';
346339
const colorAttachment = t.createTextureTracked({
@@ -397,7 +390,7 @@ g.test('depth_compare_func')
397390
depthLoadOp: 'clear',
398391
depthStoreOp: 'store',
399392
};
400-
if (kTextureFormatInfo[format].stencil) {
393+
if (isStencilTextureFormat(format)) {
401394
depthStencilAttachment.stencilClearValue = 0;
402395
depthStencilAttachment.stencilLoadOp = 'clear';
403396
depthStencilAttachment.stencilStoreOp = 'store';

src/webgpu/api/operation/rendering/depth_bias.spec.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ Tests render results with different depth bias values like 'positive', 'negative
66
import { makeTestGroup } from '../../../../common/framework/test_group.js';
77
import { unreachable } from '../../../../common/util/util.js';
88
import {
9-
kTextureFormatInfo,
109
DepthStencilFormat,
1110
EncodableTextureFormat,
11+
isDepthTextureFormat,
12+
isStencilTextureFormat,
1213
} from '../../../format_info.js';
13-
import { GPUTest, TextureTestMixin } from '../../../gpu_test.js';
14+
import { AllFeaturesMaxLimitsGPUTest, TextureTestMixin } from '../../../gpu_test.js';
1415
import { TexelView } from '../../../util/texture/texel_view.js';
1516

1617
enum QuadAngle {
@@ -29,7 +30,7 @@ enum QuadAngle {
2930
// depthBias = 0.25 / (2 ** (-2 - 23)) = 8388608.
3031
const kPointTwoFiveBiasForPointTwoFiveZOnFloat = 8388608;
3132

32-
class DepthBiasTest extends TextureTestMixin(GPUTest) {
33+
class DepthBiasTest extends TextureTestMixin(AllFeaturesMaxLimitsGPUTest) {
3334
runDepthBiasTestInternal(
3435
depthFormat: DepthStencilFormat,
3536
{
@@ -47,7 +48,6 @@ class DepthBiasTest extends TextureTestMixin(GPUTest) {
4748
}
4849
): { renderTarget: GPUTexture; depthTexture: GPUTexture } {
4950
const renderTargetFormat = 'rgba8unorm';
50-
const depthFormatInfo = kTextureFormatInfo[depthFormat];
5151

5252
let vertexShaderCode: string;
5353
switch (quadAngle) {
@@ -103,10 +103,10 @@ class DepthBiasTest extends TextureTestMixin(GPUTest) {
103103

104104
const depthStencilAttachment: GPURenderPassDepthStencilAttachment = {
105105
view: depthTexture.createView(),
106-
depthLoadOp: depthFormatInfo.depth ? 'clear' : undefined,
107-
depthStoreOp: depthFormatInfo.depth ? 'store' : undefined,
108-
stencilLoadOp: depthFormatInfo.stencil ? 'clear' : undefined,
109-
stencilStoreOp: depthFormatInfo.stencil ? 'store' : undefined,
106+
depthLoadOp: isDepthTextureFormat(depthFormat) ? 'clear' : undefined,
107+
depthStoreOp: isDepthTextureFormat(depthFormat) ? 'store' : undefined,
108+
stencilLoadOp: isStencilTextureFormat(depthFormat) ? 'clear' : undefined,
109+
stencilStoreOp: isStencilTextureFormat(depthFormat) ? 'store' : undefined,
110110
depthClearValue: initialDepth,
111111
};
112112

0 commit comments

Comments
 (0)