fix: Check for context instead of comptime mode in comptime#2561
fix: Check for context instead of comptime mode in comptime#2561reczkok wants to merge 5 commits into
Conversation
|
pkg.pr.new packages benchmark commit |
📊 Bundle Size Comparison
👀 Notable resultsStatic test results:No major changes. Dynamic test results:No major changes. 📋 All resultsClick to reveal the results table (355 entries).
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu. |
Resolution Time Benchmark---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Random Branching (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.76, 1.49, 3.39, 4.76, 5.69, 8.55, 17.00, 19.22]
line [0.70, 1.47, 3.17, 4.48, 5.15, 7.83, 15.21, 16.22]
line [0.69, 1.33, 3.02, 4.74, 5.41, 7.82, 16.31, 18.26]
---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Linear Recursion (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.23, 0.44, 0.57, 0.69, 0.89, 0.92, 1.12, 1.25]
line [0.24, 0.42, 0.53, 0.65, 0.88, 0.86, 1.04, 1.17]
line [0.23, 0.37, 0.50, 0.57, 0.79, 0.81, 0.98, 1.14]
---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Full Tree (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.64, 1.63, 3.29, 5.33, 9.34, 19.32, 41.71, 86.76]
line [0.77, 1.50, 2.49, 5.19, 8.66, 18.13, 39.35, 80.53]
line [0.67, 1.62, 2.84, 4.48, 8.80, 18.72, 43.79, 84.35]
|
There was a problem hiding this comment.
Pull request overview
This PR adjusts how tgpu.accessor.$ / tgpu.mutableAccessor.$ determine whether they can be dereferenced, so that accessors can be read inside tgpu.comptime(...) while WGSL is being resolved (where the resolution context exists but the exec mode is temporarily switched away from codegen).
Changes:
- Added comptime tests verifying accessors can be read during shader resolution and still error when unbound.
- Updated accessor
$getters to check for presence of a resolution context (getResolutionCtx()) instead of requiringcodegenmode (inCodegenMode()).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/typegpu/tests/tgsl/comptime.test.ts | Adds coverage for reading accessors from within comptime during WGSL resolution and for the missing-binding error path. |
| packages/typegpu/src/core/slot/accessor.ts | Changes accessor dereference gating from inCodegenMode() to getResolutionCtx() to support comptime execution during resolution. |
Comments suppressed due to low confidence (2)
packages/typegpu/src/core/slot/accessor.ts:183
getResolutionCtx()is also set duringtgpu['~unstable'].simulate(...), so this change makesaccessor.$return a GPU proxy in simulate mode instead of throwing. That proxy will not behave like a JS value in simulation (e.g. arithmetic/coercion will produce strings/NaN), which is a behavioral regression vs the previous explicit error. Consider gating ongetExecMode()as well (e.g. keep throwing insimulateuntil explicitly supported, or implement a proper simulate-mode value path) so simulation doesn’t silently produce incorrect results.
get $(): InferGPU<T> {
if (getResolutionCtx()) {
return this[$gpuValueOf];
}
throw new Error(
'`tgpu.accessor` relies on GPU resources and cannot be accessed outside of a compute dispatch or draw call',
);
packages/typegpu/src/core/slot/accessor.ts:207
- Same issue as above for
mutableAccessor.$: usinggetResolutionCtx()alone makes this return a GPU proxy insimulatemode, which is unlikely to behave correctly as a JS value during simulation. Either keep throwing insimulate(to avoid silent wrong results) or add explicit simulate-mode support usinggetExecMode()branching.
get $(): InferGPU<T> {
if (getResolutionCtx()) {
return this[$gpuValueOf];
}
throw new Error(
'`tgpu.mutableAccessor` relies on GPU resources and cannot be accessed outside of a compute dispatch or draw call',
);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I added a test showcasing that this isn't a complete solution, we need to iterate on this |
Look at #2571. Maybe it is good enough |
No description provided.