1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
import { kTextureFormatInfo } from '../../../format_info.js';
import {
getFragmentShaderCodeWithOutput,
getPlainTypeInfo,
kDefaultVertexShaderCode,
} from '../../../util/shader.js';
import { ValidationTest } from '../validation_test.js';
const values = [0, 1, 0, 1];
export class CreateRenderPipelineValidationTest extends ValidationTest {
getDescriptor(
options: {
primitive?: GPUPrimitiveState;
targets?: GPUColorTargetState[];
multisample?: GPUMultisampleState;
depthStencil?: GPUDepthStencilState;
fragmentShaderCode?: string;
noFragment?: boolean;
fragmentConstants?: Record<string, GPUPipelineConstantValue>;
} = {}
): GPURenderPipelineDescriptor {
const defaultTargets: GPUColorTargetState[] = [{ format: 'rgba8unorm' }];
const {
primitive = {},
targets = defaultTargets,
multisample = {},
depthStencil,
fragmentShaderCode = getFragmentShaderCodeWithOutput([
{
values,
plainType: getPlainTypeInfo(
kTextureFormatInfo[targets[0] ? targets[0].format : 'rgba8unorm'].sampleType
),
componentCount: 4,
},
]),
noFragment = false,
fragmentConstants = {},
} = options;
return {
vertex: {
module: this.device.createShaderModule({
code: kDefaultVertexShaderCode,
}),
entryPoint: 'main',
},
fragment: noFragment
? undefined
: {
module: this.device.createShaderModule({
code: fragmentShaderCode,
}),
entryPoint: 'main',
targets,
constants: fragmentConstants,
},
layout: this.getPipelineLayout(),
primitive,
multisample,
depthStencil,
};
}
getPipelineLayout(): GPUPipelineLayout {
return this.device.createPipelineLayout({ bindGroupLayouts: [] });
}
}
|