Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/typegpu/src/resolutionCtx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,10 @@ export class ResolutionCtxImpl implements ResolutionCtx {
}

withSlots<T>(pairs: SlotValuePair<unknown>[], callback: () => T): T {
if (pairs.length === 0) {
return callback();
}

this._itemStateStack.pushSlotBindings(pairs);

try {
Expand Down
51 changes: 30 additions & 21 deletions packages/typegpu/src/tgsl/wgslGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,27 +549,36 @@ ${this.ctx.pre}}`;
return callee.value.operator(callee.value.lhs, rhs);
}

if (!isMarkedInternal(callee.value)) {
const args = argNodes.map((arg) => this.expression(arg));
const shellless = this.ctx.shelllessRepo.get(
callee.value as (...args: never[]) => unknown,
args,
);
if (shellless) {
const converted = args.map((s, idx) => {
const argType = shellless.argTypes[idx] as AnyData;
return tryConvertSnippet(s, argType, /* verbose */ false);
});

return this.ctx.withResetIndentLevel(() => {
const snippet = this.ctx.resolve(shellless);
return snip(
stitch`${snippet.value}(${converted})`,
snippet.dataType,
/* origin */ 'runtime',
);
});
}
if (!isMarkedInternal(callee.value) || isGenericFn(callee.value)) {
const slotPairs = isGenericFn(callee.value)
? callee.value[$providing]?.pairs
: [];
const callback = isGenericFn(callee.value)
? callee.value.callback
: (callee.value as (...args: never[]) => unknown);

this.ctx.withSlots(slotPairs, () => {
const args = argNodes.map((arg) => this.expression(arg));
const shellless = this.ctx.shelllessRepo.get(
callback,
args,
);
if (shellless) {
const converted = args.map((s, idx) => {
const argType = shellless.argTypes[idx] as AnyData;
return tryConvertSnippet(s, argType, /* verbose */ false);
});

return this.ctx.withResetIndentLevel(() => {
const snippet = this.ctx.resolve(shellless);
return snip(
stitch`${snippet.value}(${converted})`,
snippet.dataType,
/* origin */ 'runtime',
);
});
}
});

throw new Error(
`Function '${
Expand Down
Loading