Currently we treat slots that carry strings like WGSL-code containers:
const fooSlot = tgpu.slot<string>();
const bar = tgpu.fn([d.f32], d.f32)`(x) {
return fooSlot;
}`.$uses({ fooSlot });
const shader = tgpu.resolve([bar.with(fooSlot, 'x + 5')]);
Generates:
fn bar(x: f32) -> f32 {
return x + 5;
}
In JS-implemented functions, string-carrying slots have more uses than that, for example for comptime checks:
const modeSlot = tgpu.slot<'fast' | 'precise'>();
function bar() {
'use gpu';
if (modeSlot.$ === 'fast') {
// ...
} else {
// ...
}
}
The same WGSL-injection functionality can be achieved using tgpu.rawCodeSnippet, and provides more context when used from a JS-implemented function.
Solution
I suggest we just throw an Error when a string of type UnknownData is about to be injected into source code.
Currently we treat slots that carry strings like WGSL-code containers:
Generates:
In JS-implemented functions, string-carrying slots have more uses than that, for example for comptime checks:
The same WGSL-injection functionality can be achieved using
tgpu.rawCodeSnippet, and provides more context when used from a JS-implemented function.Solution
I suggest we just throw an Error when a string of type
UnknownDatais about to be injected into source code.