Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use slot instead of another $with
  • Loading branch information
Aleksander Katan committed Sep 19, 2025
commit b3dd1ba750a9332826b8249670157592a945cac4
9 changes: 7 additions & 2 deletions packages/typegpu/src/tgsl/consoleLog/serializers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { TgpuMutable } from '../../core/buffer/bufferShorthand.ts';
import { fn, type TgpuFn } from '../../core/function/tgpuFn.ts';
import { slot } from '../../core/slot/slot.ts';
import { privateVar } from '../../core/variable/tgpuVariable.ts';
import { u32 } from '../../data/numeric.ts';
import { sizeOf } from '../../data/sizeOf.ts';
Expand All @@ -25,6 +26,7 @@ type SerializerMap = {

const dataBlockIndex = privateVar(u32, 0);
const dataByteIndex = privateVar(u32, 0);
const dataBufferSlot = slot();

const nextByteIndex = fn([], u32)`() {
let i = dataByteIndex;
Expand Down Expand Up @@ -129,7 +131,7 @@ export const serializerMap: SerializerMap = {
for (const [name, serializer] of Object.entries(serializerMap)) {
serializer.$name(
`serialize${(name[0] as string).toLocaleUpperCase()}${name.slice(1)}`,
).$uses({ dataBlockIndex, nextByteIndex });
).$uses({ dataBlockIndex, nextByteIndex, dataBuffer: dataBufferSlot });
}

// -------
Expand All @@ -153,7 +155,10 @@ function createCompoundSerializer(
if (!serializer) {
throw new Error(`Cannot serialize data of type ${arg.type}`);
}
usedSerializers[`serializer${i}`] = serializer.$uses({ dataBuffer });
usedSerializers[`serializer${i}`] = (serializer as TgpuFn).with(
dataBufferSlot,
dataBuffer,
);
return ` serializer${i}(_arg_${i});`;
}).join('\n');

Expand Down