rayzee 5.4.0 → 5.4.2

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.
@@ -1,60 +0,0 @@
1
- /**
2
- * Monkey-patch to disable WGSL global-variable promotion for compute shaders.
3
- *
4
- * Three.js r184 introduced `WGSLNodeBuilder.allowGlobalVariables = true` which
5
- * emits `.toVar()` declarations at WGSL module scope as `var<private> name : T`
6
- * instead of function-local `var name : T` inside `fn main()` (as r183 did).
7
- *
8
- * For shaders with hundreds of `.toVar()` calls inside loops (e.g. our BVH
9
- * traversal + BRDF path tracer), `var<private>` increases GPU register pressure
10
- * because the Dawn/Chromium WGSL compiler cannot aggressively register-allocate
11
- * variables with a stable per-invocation memory address. We measured a ~8% fps
12
- * regression (120 → 110) on the path tracer after upgrading r183 → r184 that
13
- * traced entirely to GPU execution, not CPU.
14
- *
15
- * This patch wraps `WebGPUBackend.createNodeBuilder` so every newly constructed
16
- * node builder reports `allowGlobalVariables = false`, restoring r183's
17
- * function-scoped `var` emission inside `fn main()`. No behavior change —
18
- * WGSL spec guarantees `var<private>` and function-local `var` are semantically
19
- * equivalent for per-invocation storage; only the compiler's register-allocation
20
- * latitude differs.
21
- *
22
- * Relevant upstream lines:
23
- * - `node_modules/three/src/renderers/webgpu/nodes/WGSLNodeBuilder.js:247`
24
- * (`this.allowGlobalVariables = true`)
25
- * - `...WGSLNodeBuilder.js:2458` (module-scope vars block)
26
- * - `...WGSLNodeBuilder.js:2467` (function-body vars block)
27
- *
28
- * Revisit if upstream adds an official opt-out or fixes register pressure.
29
- * Import this module once at app startup (side-effect only).
30
- */
31
-
32
- import { WebGPUBackend } from 'three/webgpu';
33
-
34
- const _origCreateNodeBuilder = WebGPUBackend.prototype.createNodeBuilder;
35
-
36
- // WGSLNodeBuilder's `allowGlobalVariables` switch is ONLY consumed by the
37
- // compute-shader template (see `_getWGSLComputeCode`). The vertex/fragment
38
- // templates always emit `shaderData.vars` at module scope and therefore
39
- // REQUIRE `allowGlobalVariables=true` (emitting function-local `var` at
40
- // module scope is invalid WGSL and crashes pipeline creation with
41
- // "Invalid ShaderModule"). We install a per-instance accessor that returns
42
- // `false` only when the builder is for a compute node (material === null)
43
- // and `true` otherwise, so render pipelines keep r184 behavior untouched.
44
- WebGPUBackend.prototype.createNodeBuilder = function ( object, renderer ) {
45
-
46
- const builder = _origCreateNodeBuilder.call( this, object, renderer );
47
-
48
- Object.defineProperty( builder, 'allowGlobalVariables', {
49
- get() {
50
-
51
- return this.material !== null;
52
-
53
- },
54
- set() { /* ignore — the value is derived from material presence */ },
55
- configurable: true,
56
- } );
57
-
58
- return builder;
59
-
60
- };