@quake2ts/test-utils 0.0.749 → 0.0.751
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +38 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +38 -12
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/src/engine/helpers/webgpu-rendering.ts +48 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quake2ts/test-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.751",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"pngjs": "^7.0.0",
|
|
40
40
|
"vitest": "^1.6.0",
|
|
41
41
|
"webgpu": "^0.3.8",
|
|
42
|
-
"@quake2ts/engine": "^0.0.
|
|
43
|
-
"@quake2ts/game": "0.0.
|
|
44
|
-
"@quake2ts/
|
|
45
|
-
"@quake2ts/
|
|
42
|
+
"@quake2ts/engine": "^0.0.751",
|
|
43
|
+
"@quake2ts/game": "0.0.751",
|
|
44
|
+
"@quake2ts/server": "0.0.751",
|
|
45
|
+
"@quake2ts/shared": "0.0.751"
|
|
46
46
|
},
|
|
47
47
|
"peerDependenciesMeta": {
|
|
48
48
|
"@quake2ts/engine": {
|
|
@@ -92,10 +92,10 @@
|
|
|
92
92
|
"typescript": "^5.4.5",
|
|
93
93
|
"vitest": "^1.6.0",
|
|
94
94
|
"webgpu": "^0.3.8",
|
|
95
|
-
"@quake2ts/engine": "^0.0.
|
|
96
|
-
"@quake2ts/
|
|
97
|
-
"@quake2ts/shared": "0.0.
|
|
98
|
-
"@quake2ts/
|
|
95
|
+
"@quake2ts/engine": "^0.0.751",
|
|
96
|
+
"@quake2ts/game": "0.0.751",
|
|
97
|
+
"@quake2ts/shared": "0.0.751",
|
|
98
|
+
"@quake2ts/server": "0.0.751"
|
|
99
99
|
},
|
|
100
100
|
"scripts": {
|
|
101
101
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
@@ -7,6 +7,8 @@ export interface RenderTestSetup {
|
|
|
7
7
|
context: WebGPUContextState;
|
|
8
8
|
renderTarget: GPUTexture;
|
|
9
9
|
renderTargetView: GPUTextureView;
|
|
10
|
+
depthTarget?: GPUTexture;
|
|
11
|
+
depthTargetView?: GPUTextureView;
|
|
10
12
|
commandEncoder: GPUCommandEncoder;
|
|
11
13
|
cleanup: () => Promise<void>;
|
|
12
14
|
width: number;
|
|
@@ -19,7 +21,8 @@ export interface RenderTestSetup {
|
|
|
19
21
|
*/
|
|
20
22
|
export async function createRenderTestSetup(
|
|
21
23
|
width: number = 256,
|
|
22
|
-
height: number = 256
|
|
24
|
+
height: number = 256,
|
|
25
|
+
options: { depth?: boolean } = {}
|
|
23
26
|
): Promise<RenderTestSetup> {
|
|
24
27
|
const setup = await initHeadlessWebGPU();
|
|
25
28
|
const { device } = setup;
|
|
@@ -34,6 +37,18 @@ export async function createRenderTestSetup(
|
|
|
34
37
|
|
|
35
38
|
const renderTargetView = renderTarget.createView();
|
|
36
39
|
|
|
40
|
+
let depthTarget: GPUTexture | undefined;
|
|
41
|
+
let depthTargetView: GPUTextureView | undefined;
|
|
42
|
+
|
|
43
|
+
if (options.depth) {
|
|
44
|
+
depthTarget = device.createTexture({
|
|
45
|
+
size: { width, height, depthOrArrayLayers: 1 },
|
|
46
|
+
format: 'depth24plus',
|
|
47
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT,
|
|
48
|
+
});
|
|
49
|
+
depthTargetView = depthTarget.createView();
|
|
50
|
+
}
|
|
51
|
+
|
|
37
52
|
const commandEncoder = device.createCommandEncoder();
|
|
38
53
|
|
|
39
54
|
// We need to create a context state object compatible with our engine expectations
|
|
@@ -48,11 +63,14 @@ export async function createRenderTestSetup(
|
|
|
48
63
|
context,
|
|
49
64
|
renderTarget,
|
|
50
65
|
renderTargetView,
|
|
66
|
+
depthTarget,
|
|
67
|
+
depthTargetView,
|
|
51
68
|
commandEncoder,
|
|
52
69
|
width,
|
|
53
70
|
height,
|
|
54
71
|
cleanup: async () => {
|
|
55
72
|
renderTarget.destroy();
|
|
73
|
+
depthTarget?.destroy();
|
|
56
74
|
await setup.cleanup();
|
|
57
75
|
}
|
|
58
76
|
};
|
|
@@ -135,19 +153,32 @@ export async function renderAndCapture(
|
|
|
135
153
|
renderFn: (pass: GPURenderPassEncoder) => void
|
|
136
154
|
): Promise<Uint8ClampedArray> {
|
|
137
155
|
const { device, queue } = setup.context;
|
|
138
|
-
const { renderTargetView, commandEncoder, width, height } = setup;
|
|
156
|
+
const { renderTargetView, commandEncoder, width, height, depthTargetView } = setup;
|
|
157
|
+
|
|
158
|
+
const colorAttachment: GPURenderPassColorAttachment = {
|
|
159
|
+
view: renderTargetView,
|
|
160
|
+
clearValue: { r: 0, g: 0, b: 0, a: 0 },
|
|
161
|
+
loadOp: 'clear',
|
|
162
|
+
storeOp: 'store',
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const descriptor: GPURenderPassDescriptor = {
|
|
166
|
+
colorAttachments: [colorAttachment],
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
if (depthTargetView) {
|
|
170
|
+
descriptor.depthStencilAttachment = {
|
|
171
|
+
view: depthTargetView,
|
|
172
|
+
depthClearValue: 1.0,
|
|
173
|
+
depthLoadOp: 'clear',
|
|
174
|
+
depthStoreOp: 'discard',
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
device.pushErrorScope('validation');
|
|
139
179
|
|
|
140
180
|
// Begin render pass
|
|
141
|
-
const passEncoder = commandEncoder.beginRenderPass(
|
|
142
|
-
colorAttachments: [
|
|
143
|
-
{
|
|
144
|
-
view: renderTargetView,
|
|
145
|
-
clearValue: { r: 0, g: 0, b: 0, a: 0 },
|
|
146
|
-
loadOp: 'clear',
|
|
147
|
-
storeOp: 'store',
|
|
148
|
-
},
|
|
149
|
-
],
|
|
150
|
-
});
|
|
181
|
+
const passEncoder = commandEncoder.beginRenderPass(descriptor);
|
|
151
182
|
|
|
152
183
|
// Invoke user render function
|
|
153
184
|
renderFn(passEncoder);
|
|
@@ -158,6 +189,11 @@ export async function renderAndCapture(
|
|
|
158
189
|
// Submit the render commands
|
|
159
190
|
queue.submit([commandEncoder.finish()]);
|
|
160
191
|
|
|
192
|
+
const error = await device.popErrorScope();
|
|
193
|
+
if (error) {
|
|
194
|
+
throw new Error(`WebGPU validation error: ${error.message}`);
|
|
195
|
+
}
|
|
196
|
+
|
|
161
197
|
// Capture the texture (using a new encoder)
|
|
162
198
|
return captureTexture(device, setup.renderTarget, width, height);
|
|
163
199
|
}
|