Skip to content

Commit 02d3423

Browse files
authored
Refactor float32_blendable.spec.ts (#4283)
Issue #4178 Issue #4181
1 parent 5aec5d6 commit 02d3423

File tree

2 files changed

+62
-47
lines changed

2 files changed

+62
-47
lines changed

src/webgpu/api/validation/render_pipeline/common.ts

+58-43
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,69 @@
1-
import { ColorTextureFormat, kTextureFormatInfo } from '../../../format_info.js';
1+
import { ColorTextureFormat, getTextureFormatType } from '../../../format_info.js';
22
import {
33
getFragmentShaderCodeWithOutput,
44
getPlainTypeInfo,
55
kDefaultVertexShaderCode,
66
} from '../../../util/shader.js';
7-
import { ValidationTest } from '../validation_test.js';
7+
import { AllFeaturesMaxLimitsValidationTest } from '../validation_test.js';
88

99
export type ColorTargetState = GPUColorTargetState & { format: ColorTextureFormat };
1010

1111
const values = [0, 1, 0, 1];
12-
export class CreateRenderPipelineValidationTest extends ValidationTest {
12+
export function getDescriptorForCreateRenderPipelineValidationTest(
13+
device: GPUDevice,
14+
options: {
15+
primitive?: GPUPrimitiveState;
16+
targets?: ColorTargetState[];
17+
multisample?: GPUMultisampleState;
18+
depthStencil?: GPUDepthStencilState;
19+
fragmentShaderCode?: string;
20+
noFragment?: boolean;
21+
fragmentConstants?: Record<string, GPUPipelineConstantValue>;
22+
} = {}
23+
): GPURenderPipelineDescriptor {
24+
const {
25+
primitive = {},
26+
targets = [{ format: 'rgba8unorm' }] as const,
27+
multisample = {},
28+
depthStencil,
29+
fragmentShaderCode = getFragmentShaderCodeWithOutput([
30+
{
31+
values,
32+
plainType: getPlainTypeInfo(
33+
getTextureFormatType(targets[0] ? targets[0].format : 'rgba8unorm')
34+
),
35+
componentCount: 4,
36+
},
37+
]),
38+
noFragment = false,
39+
fragmentConstants = {},
40+
} = options;
41+
42+
return {
43+
vertex: {
44+
module: device.createShaderModule({
45+
code: kDefaultVertexShaderCode,
46+
}),
47+
entryPoint: 'main',
48+
},
49+
fragment: noFragment
50+
? undefined
51+
: {
52+
module: device.createShaderModule({
53+
code: fragmentShaderCode,
54+
}),
55+
entryPoint: 'main',
56+
targets,
57+
constants: fragmentConstants,
58+
},
59+
layout: device.createPipelineLayout({ bindGroupLayouts: [] }),
60+
primitive,
61+
multisample,
62+
depthStencil,
63+
};
64+
}
65+
66+
export class CreateRenderPipelineValidationTest extends AllFeaturesMaxLimitsValidationTest {
1367
getDescriptor(
1468
options: {
1569
primitive?: GPUPrimitiveState;
@@ -21,46 +75,7 @@ export class CreateRenderPipelineValidationTest extends ValidationTest {
2175
fragmentConstants?: Record<string, GPUPipelineConstantValue>;
2276
} = {}
2377
): GPURenderPipelineDescriptor {
24-
const {
25-
primitive = {},
26-
targets = [{ format: 'rgba8unorm' }] as const,
27-
multisample = {},
28-
depthStencil,
29-
fragmentShaderCode = getFragmentShaderCodeWithOutput([
30-
{
31-
values,
32-
plainType: getPlainTypeInfo(
33-
kTextureFormatInfo[targets[0] ? targets[0].format : 'rgba8unorm'].color.type
34-
),
35-
componentCount: 4,
36-
},
37-
]),
38-
noFragment = false,
39-
fragmentConstants = {},
40-
} = options;
41-
42-
return {
43-
vertex: {
44-
module: this.device.createShaderModule({
45-
code: kDefaultVertexShaderCode,
46-
}),
47-
entryPoint: 'main',
48-
},
49-
fragment: noFragment
50-
? undefined
51-
: {
52-
module: this.device.createShaderModule({
53-
code: fragmentShaderCode,
54-
}),
55-
entryPoint: 'main',
56-
targets,
57-
constants: fragmentConstants,
58-
},
59-
layout: this.getPipelineLayout(),
60-
primitive,
61-
multisample,
62-
depthStencil,
63-
};
78+
return getDescriptorForCreateRenderPipelineValidationTest(this.device, options);
6479
}
6580

6681
getPipelineLayout(): GPUPipelineLayout {

src/webgpu/api/validation/render_pipeline/float32_blendable.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ Tests for capabilities added by float32-blendable flag.
44

55
import { makeTestGroup } from '../../../../common/framework/test_group.js';
66
import { ColorTextureFormat } from '../../../format_info.js';
7+
import { UniqueFeaturesAndLimitsValidationTest } from '../validation_test.js';
78

8-
import { CreateRenderPipelineValidationTest } from './common.js';
9+
import { getDescriptorForCreateRenderPipelineValidationTest } from './common.js';
910

10-
export const g = makeTestGroup(CreateRenderPipelineValidationTest);
11+
export const g = makeTestGroup(UniqueFeaturesAndLimitsValidationTest);
1112

1213
const kFloat32Formats: ColorTextureFormat[] = ['r32float', 'rg32float', 'rgba32float'];
1314

@@ -33,8 +34,7 @@ pipeline that uses blending with any float32-format attachment.
3334
})
3435
.fn(t => {
3536
const { isAsync, enabled, hasBlend, format } = t.params;
36-
37-
const descriptor = t.getDescriptor({
37+
const descriptor = getDescriptorForCreateRenderPipelineValidationTest(t.device, {
3838
targets: [
3939
{
4040
format,

0 commit comments

Comments
 (0)