@react-three/test-renderer 10.0.0-canary.04087d8 → 10.0.0-canary.0aed646
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/README.md +19 -27
- package/dist/index.cjs +412 -66
- package/dist/index.d.cts +11 -1
- package/dist/index.d.mts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.mjs +411 -67
- package/dist/legacy.cjs +6 -0
- package/dist/legacy.mjs +6 -0
- package/package.json +3 -8
- package/dist/webgpu/index.cjs +0 -1575
- package/dist/webgpu/index.d.cts +0 -128
- package/dist/webgpu/index.d.mts +0 -126
- package/dist/webgpu/index.d.ts +0 -128
- package/dist/webgpu/index.mjs +0 -1566
package/README.md
CHANGED
|
@@ -32,11 +32,10 @@ Essentially, this package makes it easy to grab a snapshot of the Scene Graph re
|
|
|
32
32
|
|
|
33
33
|
Choose the entry point that matches your `@react-three/fiber` import:
|
|
34
34
|
|
|
35
|
-
| Your Fiber Import | Test Renderer Import | Use Case
|
|
36
|
-
| --------------------------- | ----------------------------------- |
|
|
37
|
-
| `@react-three/fiber` | `@react-three/test-renderer` | Default (
|
|
38
|
-
| `@react-three/fiber/legacy` | `@react-three/test-renderer/legacy` | WebGL only
|
|
39
|
-
| `@react-three/fiber/webgpu` | `@react-three/test-renderer/webgpu` | WebGPU, with the mocked GPU context |
|
|
35
|
+
| Your Fiber Import | Test Renderer Import | Use Case |
|
|
36
|
+
| --------------------------- | ----------------------------------- | ------------------------------------ |
|
|
37
|
+
| `@react-three/fiber` | `@react-three/test-renderer` | Default (WebGPU, mocked GPU context) |
|
|
38
|
+
| `@react-three/fiber/legacy` | `@react-three/test-renderer/legacy` | WebGL only |
|
|
40
39
|
|
|
41
40
|
Whichever entry you pick, the root resolves JSX elements from the three namespace of the renderer it loads, exactly as in the app: node materials exist under WebGPU and not under WebGL.
|
|
42
41
|
|
|
@@ -74,15 +73,16 @@ import { Canvas } from '@react-three/fiber/legacy'
|
|
|
74
73
|
const renderer = await ReactThreeTestRenderer.create(<MyScene />)
|
|
75
74
|
```
|
|
76
75
|
|
|
77
|
-
###
|
|
76
|
+
### TSL (Three Shading Language)
|
|
78
77
|
|
|
79
|
-
|
|
78
|
+
The default entry renders with `WebGPURenderer`, so node materials and the TSL hooks work without
|
|
79
|
+
any setup. It replaces `@react-three/test-renderer/webgpu`, which is removed.
|
|
80
80
|
|
|
81
81
|
```tsx
|
|
82
|
-
import ReactThreeTestRenderer from '@react-three/test-renderer
|
|
83
|
-
import {
|
|
82
|
+
import ReactThreeTestRenderer from '@react-three/test-renderer'
|
|
83
|
+
import { color } from 'three/tsl'
|
|
84
84
|
// The TSL hooks come from @react-three/tsl, in tests as in app code
|
|
85
|
-
import {
|
|
85
|
+
import { useUniforms, useNodes } from '@react-three/tsl'
|
|
86
86
|
|
|
87
87
|
// Component using WebGPU hooks
|
|
88
88
|
function MyWebGPUScene() {
|
|
@@ -133,12 +133,12 @@ console.log(renderer.toGraph())
|
|
|
133
133
|
|
|
134
134
|
## Testing WebGPU Hooks
|
|
135
135
|
|
|
136
|
-
|
|
136
|
+
Test TSL uniforms and nodes with the default entry and the hooks from `@react-three/tsl`:
|
|
137
137
|
|
|
138
138
|
```tsx
|
|
139
|
-
import ReactThreeTestRenderer from '@react-three/test-renderer
|
|
140
|
-
import {
|
|
141
|
-
import {
|
|
139
|
+
import ReactThreeTestRenderer from '@react-three/test-renderer'
|
|
140
|
+
import { color } from 'three/tsl'
|
|
141
|
+
import { useUniforms, useNodes } from '@react-three/tsl'
|
|
142
142
|
|
|
143
143
|
describe('My WebGPU Scene', () => {
|
|
144
144
|
it('should create and use uniforms', async () => {
|
|
@@ -188,23 +188,15 @@ describe('My WebGPU Scene', () => {
|
|
|
188
188
|
|
|
189
189
|
---
|
|
190
190
|
|
|
191
|
-
##
|
|
191
|
+
## Upgrading from v9
|
|
192
192
|
|
|
193
|
-
|
|
193
|
+
v9 had one entry, which rendered with WebGL. In v10 the default entry renders with WebGPU, to match
|
|
194
|
+
`@react-three/fiber`. If your app imports `Canvas` from `@react-three/fiber/legacy`, test with the
|
|
195
|
+
`/legacy` entry:
|
|
194
196
|
|
|
195
197
|
```diff
|
|
196
|
-
// Before (v8) - single entry point
|
|
197
198
|
-import ReactThreeTestRenderer from '@react-three/test-renderer'
|
|
198
|
-
|
|
199
|
-
// After (v9+) - choose matching entry
|
|
200
|
-
// For WebGPU apps:
|
|
201
|
-
+import ReactThreeTestRenderer from '@react-three/test-renderer/webgpu'
|
|
202
|
-
|
|
203
|
-
// For legacy WebGL apps:
|
|
204
199
|
+import ReactThreeTestRenderer from '@react-three/test-renderer/legacy'
|
|
205
|
-
|
|
206
|
-
// For default (auto-detection):
|
|
207
|
-
+import ReactThreeTestRenderer from '@react-three/test-renderer'
|
|
208
200
|
```
|
|
209
201
|
|
|
210
202
|
---
|
|
@@ -213,4 +205,4 @@ If you're upgrading from v8 and using WebGPU features:
|
|
|
213
205
|
|
|
214
206
|
- [React Three Test Renderer API](./markdown/rttr.md)
|
|
215
207
|
- [React Three Test Instance API](./markdown/rttr-instance.md)
|
|
216
|
-
- [WebGPU
|
|
208
|
+
- [Testing WebGPU and TSL](https://r3f.docs.pmnd.rs/next/api/testing#testing-webgpu-and-tsl)
|
package/dist/index.cjs
CHANGED
|
@@ -5,6 +5,399 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
const react = require('react');
|
|
6
6
|
const fiber = require('@react-three/fiber');
|
|
7
7
|
|
|
8
|
+
var __defProp$2 = Object.defineProperty;
|
|
9
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
11
|
+
class MockGPUBuffer {
|
|
12
|
+
constructor(descriptor) {
|
|
13
|
+
__publicField$2(this, "size");
|
|
14
|
+
__publicField$2(this, "usage");
|
|
15
|
+
__publicField$2(this, "mapState", "unmapped");
|
|
16
|
+
this.size = descriptor.size;
|
|
17
|
+
this.usage = descriptor.usage;
|
|
18
|
+
}
|
|
19
|
+
getMappedRange(_offset, _size) {
|
|
20
|
+
return new ArrayBuffer(this.size);
|
|
21
|
+
}
|
|
22
|
+
unmap() {
|
|
23
|
+
}
|
|
24
|
+
destroy() {
|
|
25
|
+
}
|
|
26
|
+
async mapAsync(_mode, _offset, _size) {
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
class MockGPUTexture {
|
|
30
|
+
constructor(descriptor) {
|
|
31
|
+
__publicField$2(this, "width");
|
|
32
|
+
__publicField$2(this, "height");
|
|
33
|
+
__publicField$2(this, "depthOrArrayLayers");
|
|
34
|
+
__publicField$2(this, "mipLevelCount");
|
|
35
|
+
__publicField$2(this, "sampleCount");
|
|
36
|
+
__publicField$2(this, "dimension");
|
|
37
|
+
__publicField$2(this, "format");
|
|
38
|
+
__publicField$2(this, "usage");
|
|
39
|
+
this.width = typeof descriptor.size === "number" ? descriptor.size : descriptor.size.width ?? 1;
|
|
40
|
+
this.height = typeof descriptor.size === "number" ? 1 : descriptor.size.height ?? 1;
|
|
41
|
+
this.depthOrArrayLayers = typeof descriptor.size === "number" ? 1 : descriptor.size.depthOrArrayLayers ?? 1;
|
|
42
|
+
this.mipLevelCount = descriptor.mipLevelCount ?? 1;
|
|
43
|
+
this.sampleCount = descriptor.sampleCount ?? 1;
|
|
44
|
+
this.dimension = descriptor.dimension ?? "2d";
|
|
45
|
+
this.format = descriptor.format;
|
|
46
|
+
this.usage = descriptor.usage;
|
|
47
|
+
}
|
|
48
|
+
createView(_descriptor) {
|
|
49
|
+
return new MockGPUTextureView();
|
|
50
|
+
}
|
|
51
|
+
destroy() {
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
class MockGPUTextureView {
|
|
55
|
+
constructor() {
|
|
56
|
+
__publicField$2(this, "label");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
class MockGPUSampler {
|
|
60
|
+
constructor(_descriptor) {
|
|
61
|
+
__publicField$2(this, "label");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
class MockGPUShaderModule {
|
|
65
|
+
constructor(_descriptor) {
|
|
66
|
+
__publicField$2(this, "label");
|
|
67
|
+
}
|
|
68
|
+
getCompilationInfo() {
|
|
69
|
+
return Promise.resolve({ messages: [] });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
class MockGPUBindGroupLayout {
|
|
73
|
+
constructor(_descriptor) {
|
|
74
|
+
__publicField$2(this, "label");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
class MockGPUBindGroup {
|
|
78
|
+
constructor(_descriptor) {
|
|
79
|
+
__publicField$2(this, "label");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
class MockGPUPipelineLayout {
|
|
83
|
+
constructor(_descriptor) {
|
|
84
|
+
__publicField$2(this, "label");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
class MockGPURenderPipeline {
|
|
88
|
+
constructor(_descriptor) {
|
|
89
|
+
__publicField$2(this, "label");
|
|
90
|
+
}
|
|
91
|
+
getBindGroupLayout(_index) {
|
|
92
|
+
return new MockGPUBindGroupLayout({ entries: [] });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
class MockGPUComputePipeline {
|
|
96
|
+
constructor(_descriptor) {
|
|
97
|
+
__publicField$2(this, "label");
|
|
98
|
+
}
|
|
99
|
+
getBindGroupLayout(_index) {
|
|
100
|
+
return new MockGPUBindGroupLayout({ entries: [] });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
class MockGPUCommandEncoder {
|
|
104
|
+
constructor() {
|
|
105
|
+
__publicField$2(this, "label");
|
|
106
|
+
}
|
|
107
|
+
beginRenderPass(_descriptor) {
|
|
108
|
+
return new MockGPURenderPassEncoder();
|
|
109
|
+
}
|
|
110
|
+
beginComputePass(_descriptor) {
|
|
111
|
+
return new MockGPUComputePassEncoder();
|
|
112
|
+
}
|
|
113
|
+
copyBufferToBuffer(_source, _sourceOffset, _destination, _destinationOffset, _size) {
|
|
114
|
+
}
|
|
115
|
+
copyBufferToTexture(_source, _destination, _copySize) {
|
|
116
|
+
}
|
|
117
|
+
copyTextureToBuffer(_source, _destination, _copySize) {
|
|
118
|
+
}
|
|
119
|
+
copyTextureToTexture(_source, _destination, _copySize) {
|
|
120
|
+
}
|
|
121
|
+
finish(_descriptor) {
|
|
122
|
+
return new MockGPUCommandBuffer();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
class MockGPURenderPassEncoder {
|
|
126
|
+
setPipeline(_pipeline) {
|
|
127
|
+
}
|
|
128
|
+
setBindGroup(_index, _bindGroup, _dynamicOffsets) {
|
|
129
|
+
}
|
|
130
|
+
setVertexBuffer(_slot, _buffer, _offset, _size) {
|
|
131
|
+
}
|
|
132
|
+
setIndexBuffer(_buffer, _indexFormat, _offset, _size) {
|
|
133
|
+
}
|
|
134
|
+
setViewport(_x, _y, _width, _height, _minDepth, _maxDepth) {
|
|
135
|
+
}
|
|
136
|
+
setScissorRect(_x, _y, _width, _height) {
|
|
137
|
+
}
|
|
138
|
+
setBlendConstant(_color) {
|
|
139
|
+
}
|
|
140
|
+
setStencilReference(_reference) {
|
|
141
|
+
}
|
|
142
|
+
draw(_vertexCount, _instanceCount, _firstVertex, _firstInstance) {
|
|
143
|
+
}
|
|
144
|
+
drawIndexed(_indexCount, _instanceCount, _firstIndex, _baseVertex, _firstInstance) {
|
|
145
|
+
}
|
|
146
|
+
drawIndirect(_indirectBuffer, _indirectOffset) {
|
|
147
|
+
}
|
|
148
|
+
drawIndexedIndirect(_indirectBuffer, _indirectOffset) {
|
|
149
|
+
}
|
|
150
|
+
end() {
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
class MockGPUComputePassEncoder {
|
|
154
|
+
setPipeline(_pipeline) {
|
|
155
|
+
}
|
|
156
|
+
setBindGroup(_index, _bindGroup, _dynamicOffsets) {
|
|
157
|
+
}
|
|
158
|
+
dispatchWorkgroups(_workgroupCountX, _workgroupCountY, _workgroupCountZ) {
|
|
159
|
+
}
|
|
160
|
+
dispatchWorkgroupsIndirect(_indirectBuffer, _indirectOffset) {
|
|
161
|
+
}
|
|
162
|
+
end() {
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
class MockGPUCommandBuffer {
|
|
166
|
+
constructor() {
|
|
167
|
+
__publicField$2(this, "label");
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
class MockGPUQueue {
|
|
171
|
+
constructor() {
|
|
172
|
+
__publicField$2(this, "label");
|
|
173
|
+
}
|
|
174
|
+
submit(_commandBuffers) {
|
|
175
|
+
}
|
|
176
|
+
writeBuffer(_buffer, _bufferOffset, _data, _dataOffset, _size) {
|
|
177
|
+
}
|
|
178
|
+
writeTexture(_destination, _data, _dataLayout, _size) {
|
|
179
|
+
}
|
|
180
|
+
copyExternalImageToTexture(_source, _destination, _copySize) {
|
|
181
|
+
}
|
|
182
|
+
onSubmittedWorkDone() {
|
|
183
|
+
return Promise.resolve();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
class MockGPUQuerySet {
|
|
187
|
+
constructor(descriptor) {
|
|
188
|
+
__publicField$2(this, "type");
|
|
189
|
+
__publicField$2(this, "count");
|
|
190
|
+
this.type = descriptor.type;
|
|
191
|
+
this.count = descriptor.count;
|
|
192
|
+
}
|
|
193
|
+
destroy() {
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
class MockGPUDevice extends EventTarget {
|
|
197
|
+
constructor() {
|
|
198
|
+
super();
|
|
199
|
+
__publicField$2(this, "features", /* @__PURE__ */ new Set());
|
|
200
|
+
__publicField$2(this, "limits", createMockLimits());
|
|
201
|
+
__publicField$2(this, "queue", new MockGPUQueue());
|
|
202
|
+
__publicField$2(this, "lost");
|
|
203
|
+
__publicField$2(this, "label");
|
|
204
|
+
__publicField$2(this, "_destroyed", false);
|
|
205
|
+
this.lost = new Promise(() => {
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
destroy() {
|
|
209
|
+
this._destroyed = true;
|
|
210
|
+
}
|
|
211
|
+
// Buffer Creation --
|
|
212
|
+
createBuffer(descriptor) {
|
|
213
|
+
return new MockGPUBuffer(descriptor);
|
|
214
|
+
}
|
|
215
|
+
// Texture Creation --
|
|
216
|
+
createTexture(descriptor) {
|
|
217
|
+
return new MockGPUTexture(descriptor);
|
|
218
|
+
}
|
|
219
|
+
createSampler(descriptor) {
|
|
220
|
+
return new MockGPUSampler(descriptor);
|
|
221
|
+
}
|
|
222
|
+
// Shader/Pipeline Creation --
|
|
223
|
+
createShaderModule(descriptor) {
|
|
224
|
+
return new MockGPUShaderModule(descriptor);
|
|
225
|
+
}
|
|
226
|
+
createBindGroupLayout(descriptor) {
|
|
227
|
+
return new MockGPUBindGroupLayout(descriptor);
|
|
228
|
+
}
|
|
229
|
+
createBindGroup(descriptor) {
|
|
230
|
+
return new MockGPUBindGroup(descriptor);
|
|
231
|
+
}
|
|
232
|
+
createPipelineLayout(descriptor) {
|
|
233
|
+
return new MockGPUPipelineLayout(descriptor);
|
|
234
|
+
}
|
|
235
|
+
createRenderPipeline(descriptor) {
|
|
236
|
+
return new MockGPURenderPipeline(descriptor);
|
|
237
|
+
}
|
|
238
|
+
async createRenderPipelineAsync(descriptor) {
|
|
239
|
+
return new MockGPURenderPipeline(descriptor);
|
|
240
|
+
}
|
|
241
|
+
createComputePipeline(descriptor) {
|
|
242
|
+
return new MockGPUComputePipeline(descriptor);
|
|
243
|
+
}
|
|
244
|
+
async createComputePipelineAsync(descriptor) {
|
|
245
|
+
return new MockGPUComputePipeline(descriptor);
|
|
246
|
+
}
|
|
247
|
+
// Command Encoding --
|
|
248
|
+
createCommandEncoder(_descriptor) {
|
|
249
|
+
return new MockGPUCommandEncoder();
|
|
250
|
+
}
|
|
251
|
+
// Query Sets --
|
|
252
|
+
createQuerySet(descriptor) {
|
|
253
|
+
return new MockGPUQuerySet(descriptor);
|
|
254
|
+
}
|
|
255
|
+
// Error Handling --
|
|
256
|
+
pushErrorScope(_filter) {
|
|
257
|
+
}
|
|
258
|
+
popErrorScope() {
|
|
259
|
+
return Promise.resolve(null);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
class MockGPUAdapter {
|
|
263
|
+
constructor() {
|
|
264
|
+
__publicField$2(this, "features", /* @__PURE__ */ new Set());
|
|
265
|
+
__publicField$2(this, "limits", createMockLimits());
|
|
266
|
+
__publicField$2(this, "isFallbackAdapter", false);
|
|
267
|
+
}
|
|
268
|
+
async requestDevice(_descriptor) {
|
|
269
|
+
return new MockGPUDevice();
|
|
270
|
+
}
|
|
271
|
+
async requestAdapterInfo() {
|
|
272
|
+
return {
|
|
273
|
+
vendor: "Mock",
|
|
274
|
+
architecture: "Mock",
|
|
275
|
+
device: "Mock Test Renderer",
|
|
276
|
+
description: "Mock WebGPU Adapter for Testing"
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
class MockGPU {
|
|
281
|
+
constructor() {
|
|
282
|
+
__publicField$2(this, "wgslLanguageFeatures", /* @__PURE__ */ new Set());
|
|
283
|
+
}
|
|
284
|
+
async requestAdapter(_options) {
|
|
285
|
+
return new MockGPUAdapter();
|
|
286
|
+
}
|
|
287
|
+
getPreferredCanvasFormat() {
|
|
288
|
+
return "bgra8unorm";
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
class MockGPUCanvasContext {
|
|
292
|
+
constructor(canvas) {
|
|
293
|
+
__publicField$2(this, "canvas");
|
|
294
|
+
__publicField$2(this, "_configuration", null);
|
|
295
|
+
this.canvas = canvas;
|
|
296
|
+
}
|
|
297
|
+
configure(configuration) {
|
|
298
|
+
this._configuration = configuration;
|
|
299
|
+
}
|
|
300
|
+
unconfigure() {
|
|
301
|
+
this._configuration = null;
|
|
302
|
+
}
|
|
303
|
+
getCurrentTexture() {
|
|
304
|
+
const width = this.canvas instanceof HTMLCanvasElement ? this.canvas.width : this.canvas.width;
|
|
305
|
+
const height = this.canvas instanceof HTMLCanvasElement ? this.canvas.height : this.canvas.height;
|
|
306
|
+
return new MockGPUTexture({
|
|
307
|
+
size: { width, height },
|
|
308
|
+
format: this._configuration?.format ?? "bgra8unorm",
|
|
309
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
function createMockLimits() {
|
|
314
|
+
return {
|
|
315
|
+
maxTextureDimension1D: 8192,
|
|
316
|
+
maxTextureDimension2D: 8192,
|
|
317
|
+
maxTextureDimension3D: 2048,
|
|
318
|
+
maxTextureArrayLayers: 256,
|
|
319
|
+
maxBindGroups: 4,
|
|
320
|
+
maxBindGroupsPlusVertexBuffers: 24,
|
|
321
|
+
maxBindingsPerBindGroup: 1e3,
|
|
322
|
+
maxDynamicUniformBuffersPerPipelineLayout: 8,
|
|
323
|
+
maxDynamicStorageBuffersPerPipelineLayout: 4,
|
|
324
|
+
maxSampledTexturesPerShaderStage: 16,
|
|
325
|
+
maxSamplersPerShaderStage: 16,
|
|
326
|
+
maxStorageBuffersPerShaderStage: 8,
|
|
327
|
+
maxStorageTexturesPerShaderStage: 4,
|
|
328
|
+
maxUniformBuffersPerShaderStage: 12,
|
|
329
|
+
maxUniformBufferBindingSize: 65536,
|
|
330
|
+
maxStorageBufferBindingSize: 134217728,
|
|
331
|
+
minUniformBufferOffsetAlignment: 256,
|
|
332
|
+
minStorageBufferOffsetAlignment: 256,
|
|
333
|
+
maxVertexBuffers: 8,
|
|
334
|
+
maxBufferSize: 268435456,
|
|
335
|
+
maxVertexAttributes: 16,
|
|
336
|
+
maxVertexBufferArrayStride: 2048,
|
|
337
|
+
maxInterStageShaderVariables: 16,
|
|
338
|
+
maxColorAttachments: 8,
|
|
339
|
+
maxColorAttachmentBytesPerSample: 32,
|
|
340
|
+
maxComputeWorkgroupStorageSize: 16384,
|
|
341
|
+
maxComputeInvocationsPerWorkgroup: 256,
|
|
342
|
+
maxComputeWorkgroupSizeX: 256,
|
|
343
|
+
maxComputeWorkgroupSizeY: 256,
|
|
344
|
+
maxComputeWorkgroupSizeZ: 64,
|
|
345
|
+
maxComputeWorkgroupsPerDimension: 65535
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
function mockWebGPU() {
|
|
349
|
+
const mockGPU = new MockGPU();
|
|
350
|
+
if (typeof globalThis.navigator === "undefined") {
|
|
351
|
+
globalThis.navigator = {};
|
|
352
|
+
}
|
|
353
|
+
globalThis.navigator.gpu = mockGPU;
|
|
354
|
+
globalThis.GPUTextureUsage = {
|
|
355
|
+
COPY_SRC: 1,
|
|
356
|
+
COPY_DST: 2,
|
|
357
|
+
TEXTURE_BINDING: 4,
|
|
358
|
+
STORAGE_BINDING: 8,
|
|
359
|
+
RENDER_ATTACHMENT: 16
|
|
360
|
+
};
|
|
361
|
+
globalThis.GPUBufferUsage = {
|
|
362
|
+
MAP_READ: 1,
|
|
363
|
+
MAP_WRITE: 2,
|
|
364
|
+
COPY_SRC: 4,
|
|
365
|
+
COPY_DST: 8,
|
|
366
|
+
INDEX: 16,
|
|
367
|
+
VERTEX: 32,
|
|
368
|
+
UNIFORM: 64,
|
|
369
|
+
STORAGE: 128,
|
|
370
|
+
INDIRECT: 256,
|
|
371
|
+
QUERY_RESOLVE: 512
|
|
372
|
+
};
|
|
373
|
+
globalThis.GPUMapMode = {
|
|
374
|
+
READ: 1,
|
|
375
|
+
WRITE: 2
|
|
376
|
+
};
|
|
377
|
+
globalThis.GPUShaderStage = {
|
|
378
|
+
VERTEX: 1,
|
|
379
|
+
FRAGMENT: 2,
|
|
380
|
+
COMPUTE: 4
|
|
381
|
+
};
|
|
382
|
+
globalThis.GPUColorWrite = {
|
|
383
|
+
RED: 1,
|
|
384
|
+
GREEN: 2,
|
|
385
|
+
BLUE: 4,
|
|
386
|
+
ALPHA: 8,
|
|
387
|
+
ALL: 15
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
function unmockWebGPU() {
|
|
391
|
+
if (typeof globalThis.navigator !== "undefined") {
|
|
392
|
+
delete globalThis.navigator.gpu;
|
|
393
|
+
}
|
|
394
|
+
delete globalThis.GPUTextureUsage;
|
|
395
|
+
delete globalThis.GPUBufferUsage;
|
|
396
|
+
delete globalThis.GPUMapMode;
|
|
397
|
+
delete globalThis.GPUShaderStage;
|
|
398
|
+
delete globalThis.GPUColorWrite;
|
|
399
|
+
}
|
|
400
|
+
|
|
8
401
|
const lowerCaseFirstLetter = (str) => `${str.charAt(0).toLowerCase()}${str.slice(1)}`;
|
|
9
402
|
const toEventHandlerName = (eventName) => `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;
|
|
10
403
|
|
|
@@ -47,9 +440,9 @@ const toGraph = (object) => {
|
|
|
47
440
|
});
|
|
48
441
|
};
|
|
49
442
|
|
|
50
|
-
var __defProp$
|
|
51
|
-
var __defNormalProp$
|
|
52
|
-
var __publicField$
|
|
443
|
+
var __defProp$1 = Object.defineProperty;
|
|
444
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
445
|
+
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
53
446
|
const functions = [
|
|
54
447
|
"activeTexture",
|
|
55
448
|
"attachShader",
|
|
@@ -769,18 +1162,18 @@ const extensions = {
|
|
|
769
1162
|
const returnsHandle = (method) => method.startsWith("create") || method === "fenceSync";
|
|
770
1163
|
class WebGL2RenderingContext {
|
|
771
1164
|
constructor(canvas) {
|
|
772
|
-
__publicField$
|
|
1165
|
+
__publicField$1(this, "getShaderPrecisionFormat", () => {
|
|
773
1166
|
return {
|
|
774
1167
|
rangeMin: 127,
|
|
775
1168
|
rangeMax: 127,
|
|
776
1169
|
precision: 23
|
|
777
1170
|
};
|
|
778
1171
|
});
|
|
779
|
-
__publicField$
|
|
780
|
-
__publicField$
|
|
781
|
-
__publicField$
|
|
782
|
-
__publicField$
|
|
783
|
-
__publicField$
|
|
1172
|
+
__publicField$1(this, "GL_VERSION", 7938);
|
|
1173
|
+
__publicField$1(this, "SCISSOR_BOX", 3088);
|
|
1174
|
+
__publicField$1(this, "VIEWPORT", 2978);
|
|
1175
|
+
__publicField$1(this, "getProgramInfoLog", () => "");
|
|
1176
|
+
__publicField$1(this, "getShaderInfoLog", () => "");
|
|
784
1177
|
this.canvas = canvas;
|
|
785
1178
|
this.drawingBufferWidth = canvas.width;
|
|
786
1179
|
this.drawingBufferHeight = canvas.height;
|
|
@@ -802,61 +1195,10 @@ class WebGL2RenderingContext {
|
|
|
802
1195
|
getExtension(ext) {
|
|
803
1196
|
return extensions[ext];
|
|
804
1197
|
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
810
|
-
class MockGPUTexture {
|
|
811
|
-
constructor(descriptor) {
|
|
812
|
-
__publicField$1(this, "width");
|
|
813
|
-
__publicField$1(this, "height");
|
|
814
|
-
__publicField$1(this, "depthOrArrayLayers");
|
|
815
|
-
__publicField$1(this, "mipLevelCount");
|
|
816
|
-
__publicField$1(this, "sampleCount");
|
|
817
|
-
__publicField$1(this, "dimension");
|
|
818
|
-
__publicField$1(this, "format");
|
|
819
|
-
__publicField$1(this, "usage");
|
|
820
|
-
this.width = typeof descriptor.size === "number" ? descriptor.size : descriptor.size.width ?? 1;
|
|
821
|
-
this.height = typeof descriptor.size === "number" ? 1 : descriptor.size.height ?? 1;
|
|
822
|
-
this.depthOrArrayLayers = typeof descriptor.size === "number" ? 1 : descriptor.size.depthOrArrayLayers ?? 1;
|
|
823
|
-
this.mipLevelCount = descriptor.mipLevelCount ?? 1;
|
|
824
|
-
this.sampleCount = descriptor.sampleCount ?? 1;
|
|
825
|
-
this.dimension = descriptor.dimension ?? "2d";
|
|
826
|
-
this.format = descriptor.format;
|
|
827
|
-
this.usage = descriptor.usage;
|
|
828
|
-
}
|
|
829
|
-
createView(_descriptor) {
|
|
830
|
-
return new MockGPUTextureView();
|
|
831
|
-
}
|
|
832
|
-
destroy() {
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
class MockGPUTextureView {
|
|
836
|
-
constructor() {
|
|
837
|
-
__publicField$1(this, "label");
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
class MockGPUCanvasContext {
|
|
841
|
-
constructor(canvas) {
|
|
842
|
-
__publicField$1(this, "canvas");
|
|
843
|
-
__publicField$1(this, "_configuration", null);
|
|
844
|
-
this.canvas = canvas;
|
|
845
|
-
}
|
|
846
|
-
configure(configuration) {
|
|
847
|
-
this._configuration = configuration;
|
|
848
|
-
}
|
|
849
|
-
unconfigure() {
|
|
850
|
-
this._configuration = null;
|
|
851
|
-
}
|
|
852
|
-
getCurrentTexture() {
|
|
853
|
-
const width = this.canvas instanceof HTMLCanvasElement ? this.canvas.width : this.canvas.width;
|
|
854
|
-
const height = this.canvas instanceof HTMLCanvasElement ? this.canvas.height : this.canvas.height;
|
|
855
|
-
return new MockGPUTexture({
|
|
856
|
-
size: { width, height },
|
|
857
|
-
format: this._configuration?.format ?? "bgra8unorm",
|
|
858
|
-
usage: GPUTextureUsage.RENDER_ATTACHMENT
|
|
859
|
-
});
|
|
1198
|
+
// WebGPURenderer's WebGL2 fallback backend lists the supported extensions up front and checks
|
|
1199
|
+
// them with `.includes()`, so this has to return an array rather than the no-op stub's undefined
|
|
1200
|
+
getSupportedExtensions() {
|
|
1201
|
+
return Object.keys(extensions);
|
|
860
1202
|
}
|
|
861
1203
|
}
|
|
862
1204
|
|
|
@@ -1046,6 +1388,7 @@ const createVirtualInstance = (object, parent) => {
|
|
|
1046
1388
|
object,
|
|
1047
1389
|
eventCount: 0,
|
|
1048
1390
|
handlers: {},
|
|
1391
|
+
previousVisible: void 0,
|
|
1049
1392
|
isHidden: false
|
|
1050
1393
|
};
|
|
1051
1394
|
if (object.children && object.children.length > 0) {
|
|
@@ -1217,13 +1560,14 @@ const index$1 = {
|
|
|
1217
1560
|
ReactThreeTestInstance: ReactThreeTestInstance
|
|
1218
1561
|
};
|
|
1219
1562
|
|
|
1563
|
+
mockWebGPU();
|
|
1220
1564
|
const renderer = createTestRenderer({
|
|
1221
1565
|
createRoot: fiber.createRoot,
|
|
1222
1566
|
mockRoots: fiber._roots,
|
|
1223
1567
|
reconciler: fiber.reconciler,
|
|
1224
1568
|
act: react.act,
|
|
1225
|
-
mode: "
|
|
1226
|
-
// The root entry renders with
|
|
1569
|
+
mode: "webgpu"
|
|
1570
|
+
// The root entry renders with WebGPURenderer
|
|
1227
1571
|
});
|
|
1228
1572
|
const { create } = renderer;
|
|
1229
1573
|
const index = { create, act: react.act, waitFor };
|
|
@@ -1232,4 +1576,6 @@ exports.act = react.act;
|
|
|
1232
1576
|
exports.ReactThreeTest = index$1;
|
|
1233
1577
|
exports.create = create;
|
|
1234
1578
|
exports.default = index;
|
|
1579
|
+
exports.mockWebGPU = mockWebGPU;
|
|
1580
|
+
exports.unmockWebGPU = unmockWebGPU;
|
|
1235
1581
|
exports.waitFor = waitFor;
|
package/dist/index.d.cts
CHANGED
|
@@ -88,6 +88,16 @@ interface WaitOptions {
|
|
|
88
88
|
}
|
|
89
89
|
declare function waitFor(callback: () => boolean | void, { interval, timeout }?: WaitOptions): Promise<void>;
|
|
90
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Installs WebGPU mocks into the global scope
|
|
93
|
+
* Call this before running tests that use WebGPU
|
|
94
|
+
*/
|
|
95
|
+
declare function mockWebGPU(): void;
|
|
96
|
+
/**
|
|
97
|
+
* Removes WebGPU mocks from the global scope
|
|
98
|
+
*/
|
|
99
|
+
declare function unmockWebGPU(): void;
|
|
100
|
+
|
|
91
101
|
declare const index_Act: typeof Act;
|
|
92
102
|
type index_CreateOptions = CreateOptions;
|
|
93
103
|
type index_MockSyntheticEvent = MockSyntheticEvent;
|
|
@@ -113,5 +123,5 @@ declare const _default: {
|
|
|
113
123
|
|
|
114
124
|
// @ts-ignore
|
|
115
125
|
export = _default;
|
|
116
|
-
export { index as ReactThreeTest, create, waitFor };
|
|
126
|
+
export { index as ReactThreeTest, create, mockWebGPU, unmockWebGPU, waitFor };
|
|
117
127
|
export type { WaitOptions };
|
package/dist/index.d.mts
CHANGED
|
@@ -88,6 +88,16 @@ interface WaitOptions {
|
|
|
88
88
|
}
|
|
89
89
|
declare function waitFor(callback: () => boolean | void, { interval, timeout }?: WaitOptions): Promise<void>;
|
|
90
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Installs WebGPU mocks into the global scope
|
|
93
|
+
* Call this before running tests that use WebGPU
|
|
94
|
+
*/
|
|
95
|
+
declare function mockWebGPU(): void;
|
|
96
|
+
/**
|
|
97
|
+
* Removes WebGPU mocks from the global scope
|
|
98
|
+
*/
|
|
99
|
+
declare function unmockWebGPU(): void;
|
|
100
|
+
|
|
91
101
|
declare const index_Act: typeof Act;
|
|
92
102
|
type index_CreateOptions = CreateOptions;
|
|
93
103
|
type index_MockSyntheticEvent = MockSyntheticEvent;
|
|
@@ -111,5 +121,5 @@ declare const _default: {
|
|
|
111
121
|
waitFor: typeof waitFor;
|
|
112
122
|
};
|
|
113
123
|
|
|
114
|
-
export { index as ReactThreeTest, create, _default as default, waitFor };
|
|
124
|
+
export { index as ReactThreeTest, create, _default as default, mockWebGPU, unmockWebGPU, waitFor };
|
|
115
125
|
export type { WaitOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -88,6 +88,16 @@ interface WaitOptions {
|
|
|
88
88
|
}
|
|
89
89
|
declare function waitFor(callback: () => boolean | void, { interval, timeout }?: WaitOptions): Promise<void>;
|
|
90
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Installs WebGPU mocks into the global scope
|
|
93
|
+
* Call this before running tests that use WebGPU
|
|
94
|
+
*/
|
|
95
|
+
declare function mockWebGPU(): void;
|
|
96
|
+
/**
|
|
97
|
+
* Removes WebGPU mocks from the global scope
|
|
98
|
+
*/
|
|
99
|
+
declare function unmockWebGPU(): void;
|
|
100
|
+
|
|
91
101
|
declare const index_Act: typeof Act;
|
|
92
102
|
type index_CreateOptions = CreateOptions;
|
|
93
103
|
type index_MockSyntheticEvent = MockSyntheticEvent;
|
|
@@ -113,5 +123,5 @@ declare const _default: {
|
|
|
113
123
|
|
|
114
124
|
// @ts-ignore
|
|
115
125
|
export = _default;
|
|
116
|
-
export { index as ReactThreeTest, create, waitFor };
|
|
126
|
+
export { index as ReactThreeTest, create, mockWebGPU, unmockWebGPU, waitFor };
|
|
117
127
|
export type { WaitOptions };
|