Skip to content

feat: Handle compatible Math functions in TypeGPU functions#2152

Merged
aleksanderkatan merged 8 commits intomainfrom
feat/handle-compatible-math-functions-in-typegpu-functions
Feb 11, 2026
Merged

feat: Handle compatible Math functions in TypeGPU functions#2152
aleksanderkatan merged 8 commits intomainfrom
feat/handle-compatible-math-functions-in-typegpu-functions

Conversation

@aleksanderkatan
Copy link
Contributor

@aleksanderkatan aleksanderkatan commented Feb 10, 2026

Right now, the conversion happens during Math prop access (just like console). If we want to also support the functions directly, (e.g. when the user uses const { sin, cos } = Math, we can rewrite both in another ticket. Though, if we do so, we will not be able to lint this as discouraged.

I patched the std.round cpu impl, since it was not compliant with the spec.

@aleksanderkatan aleksanderkatan linked an issue Feb 10, 2026 that may be closed by this pull request
@github-actions
Copy link

github-actions bot commented Feb 10, 2026

📊 Bundle Size Comparison

🟢 Decreased ➖ Unchanged 🔴 Increased ❔ Unknown
0 265 71 0

👀 Notable results

Static test results:

No major changes.

Dynamic test results:

No major changes.

📋 All results

Click to reveal the results table (335 entries).
Test tsdown
dataImportEverything.ts 81.23 kB (➖)
dataImportOneDirect.ts 40.49 kB (➖)
dataImportOneStar.ts 40.49 kB (➖)
functionWithUseGpu.ts 268 B (➖)
functionWithoutUseGpu.ts 24 B (➖)
importEntireLibrary.ts 266.94 kB ($${\color{red}+0.2\%}$$)
stdImportEverything.ts 115.36 kB ($${\color{red}+0.0\%}$$)
stdImportOneDirect.ts 63.35 kB (➖)
stdImportOneStar.ts 63.35 kB (➖)
tgpuImportEverything.ts 247.10 kB ($${\color{red}+0.3\%}$$)
tgpuImportOne.ts 247.11 kB ($${\color{red}+0.3\%}$$)
MissingBindGroupsError from typegpu.ts 1.29 kB (➖)
MissingLinksError from typegpu.ts 208 B (➖)
MissingSlotValueError from typegpu.ts 153 B (➖)
MissingVertexBuffersError from typegpu.ts 1.29 kB (➖)
NotUniformError from typegpu.ts 1.25 kB (➖)
ResolutionError from typegpu.ts 1.48 kB (➖)
Void from typegpudata.ts 675 B (➖)
abs from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
acos from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
acosh from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
add from typegpustd.ts 63.35 kB (➖)
align from typegpudata.ts 42.17 kB (➖)
alignmentOf from typegpudata.ts 38.60 kB (➖)
allEq from typegpustd.ts 65.88 kB (➖)
all from typegpustd.ts 65.88 kB (➖)
and from typegpustd.ts 65.87 kB (➖)
any from typegpustd.ts 65.88 kB (➖)
arrayLength from typegpustd.ts 12.13 kB (➖)
arrayOf from typegpudata.ts 42.38 kB (➖)
asin from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
asinh from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
atan2 from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
atan from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
atanh from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
atomicAdd from typegpustd.ts 13.50 kB (➖)
atomicAnd from typegpustd.ts 13.50 kB (➖)
atomicLoad from typegpustd.ts 13.49 kB (➖)
atomicMax from typegpustd.ts 13.50 kB (➖)
atomicMin from typegpustd.ts 13.50 kB (➖)
atomicOr from typegpustd.ts 13.50 kB (➖)
atomicStore from typegpustd.ts 13.50 kB (➖)
atomicSub from typegpustd.ts 13.50 kB (➖)
atomicXor from typegpustd.ts 13.50 kB (➖)
atomic from typegpudata.ts 714 B (➖)
bitcastU32toF32 from typegpustd.ts 60.75 kB (➖)
bitcastU32toI32 from typegpustd.ts 60.75 kB (➖)
bool from typegpudata.ts 10.69 kB (➖)
builtin from typegpudata.ts 44.73 kB (➖)
ceil from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
clamp from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
common from typegpu.ts 54.70 kB (➖)
comparisonSampler from typegpudata.ts 694 B (➖)
cos from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
cosh from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
countLeadingZeros from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
countOneBits from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
countTrailingZeros from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
cross from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
d from typegpu.ts 81.24 kB (➖)
deepEqual from typegpudata.ts 2.71 kB (➖)
degrees from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
determinant from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
disarrayOf from typegpudata.ts 12.64 kB (➖)
discard from typegpustd.ts 11.88 kB (➖)
distance from typegpustd.ts 80.65 kB ($${\color{red}+0.1\%}$$)
div from typegpustd.ts 63.35 kB (➖)
dot4I8Packed from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
dot4U8Packed from typegpustd.ts 80.65 kB ($${\color{red}+0.1\%}$$)
dot from typegpustd.ts 80.65 kB ($${\color{red}+0.1\%}$$)
dpdxCoarse from typegpustd.ts 12.74 kB (➖)
dpdxFine from typegpustd.ts 12.74 kB (➖)
dpdx from typegpustd.ts 12.73 kB (➖)
dpdyCoarse from typegpustd.ts 12.74 kB (➖)
dpdyFine from typegpustd.ts 12.74 kB (➖)
dpdy from typegpustd.ts 12.74 kB (➖)
eq from typegpustd.ts 65.88 kB (➖)
exp2 from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
exp from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
extensionEnabled from typegpustd.ts 12.20 kB (➖)
extractBits from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
f16 from typegpudata.ts 10.69 kB (➖)
f32 from typegpudata.ts 10.69 kB (➖)
faceForward from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
firstLeadingBit from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
firstTrailingBit from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
float16 from typegpudata.ts 37.58 kB (➖)
float16x2 from typegpudata.ts 37.58 kB (➖)
float16x4 from typegpudata.ts 37.58 kB (➖)
float32 from typegpudata.ts 37.58 kB (➖)
float32x2 from typegpudata.ts 37.58 kB (➖)
float32x3 from typegpudata.ts 37.58 kB (➖)
float32x4 from typegpudata.ts 37.58 kB (➖)
floor from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
fma from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
formatToWGSLType from typegpudata.ts 37.57 kB (➖)
fract from typegpustd.ts 80.65 kB ($${\color{red}+0.1\%}$$)
frexp from typegpustd.ts 80.65 kB ($${\color{red}+0.1\%}$$)
fwidthCoarse from typegpustd.ts 12.74 kB (➖)
fwidthFine from typegpustd.ts 12.74 kB (➖)
fwidth from typegpustd.ts 12.74 kB (➖)
ge from typegpustd.ts 65.88 kB (➖)
gt from typegpustd.ts 65.88 kB (➖)
i32 from typegpudata.ts 10.69 kB (➖)
identity2 from typegpustd.ts 43.99 kB (➖)
identity3 from typegpustd.ts 43.99 kB (➖)
identity4 from typegpustd.ts 43.99 kB (➖)
insertBits from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
interpolate from typegpudata.ts 42.17 kB (➖)
invariant from typegpudata.ts 42.54 kB (➖)
inverseSqrt from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
isAccessor from typegpu.ts 72 B (➖)
isAlignAttrib from typegpudata.ts 696 B (➖)
isAtomic from typegpudata.ts 696 B (➖)
isBufferShorthand from typegpu.ts 1.69 kB (➖)
isBuffer from typegpu.ts 104.49 kB (➖)
isBuiltinAttrib from typegpudata.ts 698 B (➖)
isBuiltin from typegpudata.ts 40.58 kB (➖)
isCloseTo from typegpustd.ts 65.88 kB (➖)
isComparisonSampler from typegpu.ts 76.04 kB (➖)
isData from typegpudata.ts 2.32 kB (➖)
isDecorated from typegpudata.ts 699 B (➖)
isDisarray from typegpudata.ts 1.62 kB (➖)
isInterpolateAttrib from typegpudata.ts 702 B (➖)
isLazy from typegpu.ts 68 B (➖)
isLocationAttrib from typegpudata.ts 699 B (➖)
isLooseData from typegpudata.ts 1.67 kB (➖)
isLooseDecorated from typegpudata.ts 1.63 kB (➖)
isMutableAccessor from typegpu.ts 80 B (➖)
isPackedData from typegpudata.ts 37.64 kB (➖)
isPtr from typegpudata.ts 693 B (➖)
isSampler from typegpu.ts 76.03 kB (➖)
isSizeAttrib from typegpudata.ts 695 B (➖)
isSlot from typegpu.ts 68 B (➖)
isTexture from typegpu.ts 76.02 kB (➖)
isTgpuComputeFn from typegpu.ts 76 B (➖)
isTgpuFn from typegpu.ts 706 B (➖)
isTgpuFragmentFn from typegpu.ts 77 B (➖)
isTgpuVertexFn from typegpu.ts 75 B (➖)
isUnstruct from typegpudata.ts 1.62 kB (➖)
isUsableAsRender from typegpu.ts 62 B (➖)
isUsableAsSampled from typegpu.ts 63 B (➖)
isUsableAsStorage from typegpu.ts 63 B (➖)
isUsableAsUniform from typegpu.ts 76.01 kB (➖)
isUsableAsVertex from typegpu.ts 104.48 kB (➖)
isVariable from typegpu.ts 77.81 kB (➖)
isWgslArray from typegpudata.ts 695 B (➖)
isWgslData from typegpudata.ts 1.25 kB (➖)
isWgslStruct from typegpudata.ts 696 B (➖)
ldexp from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
le from typegpustd.ts 65.88 kB (➖)
length from typegpustd.ts 80.65 kB ($${\color{red}+0.1\%}$$)
location from typegpudata.ts 42.17 kB (➖)
log2 from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
log from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
lt from typegpustd.ts 65.88 kB (➖)
mat2x2f from typegpudata.ts 43.99 kB (➖)
mat3x3f from typegpudata.ts 43.99 kB (➖)
mat4x4f from typegpudata.ts 43.99 kB (➖)
matToArray from typegpudata.ts 44.12 kB (➖)
max from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
min from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
mix from typegpustd.ts 80.65 kB ($${\color{red}+0.1\%}$$)
mod from typegpustd.ts 63.35 kB (➖)
modf from typegpustd.ts 80.65 kB ($${\color{red}+0.1\%}$$)
mul from typegpustd.ts 63.35 kB (➖)
ne from typegpustd.ts 65.88 kB (➖)
neg from typegpustd.ts 63.35 kB (➖)
normalize from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
not from typegpustd.ts 65.87 kB (➖)
or from typegpustd.ts 65.87 kB (➖)
pack2x16float from typegpustd.ts 52.60 kB (➖)
pack4x8unorm from typegpustd.ts 52.60 kB (➖)
packedFormats from typegpudata.ts 37.60 kB (➖)
pow from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
ptrFn from typegpudata.ts 800 B (➖)
ptrHandle from typegpudata.ts 792 B (➖)
ptrPrivate from typegpudata.ts 799 B (➖)
ptrStorage from typegpudata.ts 797 B (➖)
ptrUniform from typegpudata.ts 793 B (➖)
ptrWorkgroup from typegpudata.ts 801 B (➖)
quantizeToF16 from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
radians from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
ref from typegpudata.ts 4.09 kB (➖)
reflect from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
refract from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
reverseBits from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
rotateX4 from typegpustd.ts 64.07 kB (➖)
rotateY4 from typegpustd.ts 64.07 kB (➖)
rotateZ4 from typegpustd.ts 64.07 kB (➖)
rotationX4 from typegpustd.ts 43.99 kB (➖)
rotationY4 from typegpustd.ts 43.99 kB (➖)
rotationZ4 from typegpustd.ts 43.99 kB (➖)
round from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
sampler from typegpudata.ts 683 B (➖)
saturate from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
scale4 from typegpustd.ts 64.07 kB (➖)
scaling4 from typegpustd.ts 43.99 kB (➖)
select from typegpustd.ts 65.88 kB (➖)
sign from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
sin from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
sinh from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
sint16 from typegpudata.ts 37.58 kB (➖)
sint16x2 from typegpudata.ts 37.58 kB (➖)
sint16x4 from typegpudata.ts 37.58 kB (➖)
sint32 from typegpudata.ts 37.58 kB (➖)
sint32x2 from typegpudata.ts 37.58 kB (➖)
sint32x3 from typegpudata.ts 37.58 kB (➖)
sint32x4 from typegpudata.ts 37.58 kB (➖)
sint8 from typegpudata.ts 37.58 kB (➖)
sint8x2 from typegpudata.ts 37.58 kB (➖)
sint8x4 from typegpudata.ts 37.58 kB (➖)
sizeOf from typegpudata.ts 40.50 kB (➖)
size from typegpudata.ts 42.16 kB (➖)
smoothstep from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
snorm16 from typegpudata.ts 37.58 kB (➖)
snorm16x2 from typegpudata.ts 37.58 kB (➖)
snorm16x4 from typegpudata.ts 37.58 kB (➖)
snorm8 from typegpudata.ts 37.58 kB (➖)
snorm8x2 from typegpudata.ts 37.58 kB (➖)
snorm8x4 from typegpudata.ts 37.58 kB (➖)
sqrt from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
std from typegpu.ts 115.37 kB ($${\color{red}+0.0\%}$$)
step from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
storageBarrier from typegpustd.ts 13.50 kB (➖)
struct from typegpudata.ts 3.31 kB (➖)
sub from typegpustd.ts 63.35 kB (➖)
subgroupAdd from typegpustd.ts 40.65 kB (➖)
subgroupAll from typegpustd.ts 40.66 kB (➖)
subgroupAnd from typegpustd.ts 40.66 kB (➖)
subgroupAny from typegpustd.ts 40.66 kB (➖)
subgroupBallot from typegpustd.ts 40.66 kB (➖)
subgroupBroadcastFirst from typegpustd.ts 40.66 kB (➖)
subgroupBroadcast from typegpustd.ts 40.66 kB (➖)
subgroupElect from typegpustd.ts 40.66 kB (➖)
subgroupExclusiveAdd from typegpustd.ts 40.66 kB (➖)
subgroupExclusiveMul from typegpustd.ts 40.66 kB (➖)
subgroupInclusiveAdd from typegpustd.ts 40.66 kB (➖)
subgroupInclusiveMul from typegpustd.ts 40.66 kB (➖)
subgroupMax from typegpustd.ts 40.66 kB (➖)
subgroupMin from typegpustd.ts 40.66 kB (➖)
subgroupMul from typegpustd.ts 40.66 kB (➖)
subgroupOr from typegpustd.ts 40.66 kB (➖)
subgroupShuffleDown from typegpustd.ts 40.66 kB (➖)
subgroupShuffleUp from typegpustd.ts 40.66 kB (➖)
subgroupShuffleXor from typegpustd.ts 40.66 kB (➖)
subgroupShuffle from typegpustd.ts 40.66 kB (➖)
subgroupXor from typegpustd.ts 40.66 kB (➖)
tan from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
tanh from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
texture1d from typegpudata.ts 11.14 kB (➖)
texture2dArray from typegpudata.ts 11.16 kB (➖)
texture2d from typegpudata.ts 11.14 kB (➖)
texture3d from typegpudata.ts 11.14 kB (➖)
textureBarrier from typegpustd.ts 13.50 kB (➖)
textureCubeArray from typegpudata.ts 11.16 kB (➖)
textureCube from typegpudata.ts 11.15 kB (➖)
textureDepth2dArray from typegpudata.ts 11.15 kB (➖)
textureDepth2d from typegpudata.ts 11.13 kB (➖)
textureDepthCubeArray from typegpudata.ts 11.15 kB (➖)
textureDepthCube from typegpudata.ts 11.13 kB (➖)
textureDepthMultisampled2d from typegpudata.ts 11.15 kB (➖)
textureDimensions from typegpustd.ts 42.03 kB (➖)
textureExternal from typegpudata.ts 814 B (➖)
textureGather from typegpustd.ts 42.03 kB (➖)
textureLoad from typegpustd.ts 42.04 kB (➖)
textureMultisampled2d from typegpudata.ts 11.17 kB (➖)
textureSampleBaseClampToEdge from typegpustd.ts 42.04 kB (➖)
textureSampleBias from typegpustd.ts 42.04 kB (➖)
textureSampleCompareLevel from typegpustd.ts 42.04 kB (➖)
textureSampleCompare from typegpustd.ts 42.04 kB (➖)
textureSampleLevel from typegpustd.ts 42.04 kB (➖)
textureSample from typegpustd.ts 42.04 kB (➖)
textureStorage1d from typegpudata.ts 978 B (➖)
textureStorage2dArray from typegpudata.ts 996 B (➖)
textureStorage2d from typegpudata.ts 978 B (➖)
textureStorage3d from typegpudata.ts 978 B (➖)
textureStore from typegpustd.ts 42.04 kB (➖)
tgpu.bindGroupLayout from typegpu.ts 84.92 kB (➖)
tgpu.comptime from typegpu.ts 11.98 kB (➖)
tgpu.const from typegpu.ts 76.89 kB (➖)
tgpu.fn from typegpu.ts 51.67 kB (➖)
tgpu.initFromDevice from typegpu.ts 238.59 kB ($${\color{red}+0.3\%}$$)
tgpu.init from typegpu.ts 239.11 kB ($${\color{red}+0.3\%}$$)
tgpu.lazy from typegpu.ts 1.15 kB (➖)
tgpu.privateVar from typegpu.ts 77.82 kB (➖)
tgpu.resolveWithContext from typegpu.ts 185.49 kB ($${\color{red}+0.4\%}$$)
tgpu.resolve from typegpu.ts 185.55 kB ($${\color{red}+0.4\%}$$)
tgpu.slot from typegpu.ts 1.58 kB (➖)
tgpu.vertexLayout from typegpu.ts 42.51 kB (➖)
tgpu.workgroupVar from typegpu.ts 77.82 kB (➖)
tgpu from typegpu.ts 247.11 kB ($${\color{red}+0.3\%}$$)
translate4 from typegpustd.ts 64.07 kB (➖)
translation4 from typegpustd.ts 43.99 kB (➖)
transpose from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
trunc from typegpustd.ts 80.66 kB ($${\color{red}+0.1\%}$$)
u16 from typegpudata.ts 10.71 kB (➖)
u32 from typegpudata.ts 10.69 kB (➖)
uint16 from typegpudata.ts 37.58 kB (➖)
uint16x2 from typegpudata.ts 37.58 kB (➖)
uint16x4 from typegpudata.ts 37.58 kB (➖)
uint32 from typegpudata.ts 37.58 kB (➖)
uint32x2 from typegpudata.ts 37.58 kB (➖)
uint32x3 from typegpudata.ts 37.58 kB (➖)
uint32x4 from typegpudata.ts 37.58 kB (➖)
uint8 from typegpudata.ts 37.57 kB (➖)
uint8x2 from typegpudata.ts 37.58 kB (➖)
uint8x4 from typegpudata.ts 37.58 kB (➖)
unorm10 10 10 2 from typegpudata.ts 37.58 kB (➖)
unorm16 from typegpudata.ts 37.58 kB (➖)
unorm16x2 from typegpudata.ts 37.58 kB (➖)
unorm16x4 from typegpudata.ts 37.58 kB (➖)
unorm8 from typegpudata.ts 37.58 kB (➖)
unorm8x2 from typegpudata.ts 37.58 kB (➖)
unorm8x4 bgra from typegpudata.ts 37.58 kB (➖)
unorm8x4 from typegpudata.ts 37.58 kB (➖)
unpack2x16float from typegpustd.ts 52.60 kB (➖)
unpack4x8unorm from typegpustd.ts 52.60 kB (➖)
unstruct from typegpudata.ts 1.58 kB (➖)
vec2b from typegpudata.ts 36.09 kB (➖)
vec2f from typegpudata.ts 36.09 kB (➖)
vec2h from typegpudata.ts 36.09 kB (➖)
vec2i from typegpudata.ts 36.09 kB (➖)
vec2u from typegpudata.ts 36.09 kB (➖)
vec3b from typegpudata.ts 36.09 kB (➖)
vec3f from typegpudata.ts 36.09 kB (➖)
vec3h from typegpudata.ts 36.09 kB (➖)
vec3i from typegpudata.ts 36.09 kB (➖)
vec3u from typegpudata.ts 36.09 kB (➖)
vec4b from typegpudata.ts 36.09 kB (➖)
vec4f from typegpudata.ts 36.09 kB (➖)
vec4h from typegpudata.ts 36.09 kB (➖)
vec4i from typegpudata.ts 36.09 kB (➖)
vec4u from typegpudata.ts 36.09 kB (➖)
workgroupBarrier from typegpustd.ts 13.50 kB (➖)

If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.

@github-actions
Copy link

github-actions bot commented Feb 10, 2026

pkg.pr.new

packages
Ready to be installed by your favorite package manager ⬇️

https://pkg.pr.new/software-mansion/TypeGPU/typegpu@caa6f2bdf4e3720e722288f5a92499edb282a926
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@caa6f2bdf4e3720e722288f5a92499edb282a926
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@caa6f2bdf4e3720e722288f5a92499edb282a926

benchmark
view benchmark

commit
view commit

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends TypeGPU’s TGSL resolution so that certain Math.* function member accesses inside GPU functions are treated as compatible std/WGSL equivalents, updates documentation to reflect the new behavior, and fixes the CPU implementation of std.round to match WGSL “ties-to-even” rounding.

Changes:

  • Add Math.*std.* function mapping during member access resolution (e.g. Math.sinstd.sin).
  • Fix std.round CPU behavior to use round-to-even for .5 ties and add a dedicated unit test.
  • Add tests for supported/unsupported Math usage patterns and update docs guidance.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
packages/typegpu/src/tgsl/wgslGenerator.ts Intercepts Math member access to return std-callable snippets or throw for unsupported Math functions.
packages/typegpu/src/tgsl/math.ts Introduces the mathToStd mapping table used by the generator.
packages/typegpu/src/std/numeric.ts Adjusts CPU round implementation to match WGSL tie-to-even rounding.
packages/typegpu/tests/jsMath.test.ts Adds coverage for Math.PI, Math.sin (including coercion and precompute), variadic Math.min, Math.fround, and unsupported error messaging.
packages/typegpu/tests/std/numeric/round.test.ts Adds a targeted test validating tie-to-even behavior for std.round, plus WGSL emission snapshot.
apps/typegpu-docs/src/content/docs/fundamentals/functions/index.mdx Updates docs to mention Math support and cautions about using it vs std.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@software-mansion software-mansion deleted a comment from Copilot AI Feb 10, 2026
@software-mansion software-mansion deleted a comment from Copilot AI Feb 10, 2026
@software-mansion software-mansion deleted a comment from Copilot AI Feb 10, 2026
@software-mansion software-mansion deleted a comment from Copilot AI Feb 10, 2026
@software-mansion software-mansion deleted a comment from Copilot AI Feb 10, 2026
@software-mansion software-mansion deleted a comment from Copilot AI Feb 10, 2026
@software-mansion software-mansion deleted a comment from Copilot AI Feb 10, 2026
@software-mansion software-mansion deleted a comment from Copilot AI Feb 10, 2026
@software-mansion software-mansion deleted a comment from Copilot AI Feb 10, 2026
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@aleksanderkatan aleksanderkatan marked this pull request as ready for review February 10, 2026 14:01
Copy link
Collaborator

@iwoplaza iwoplaza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing 👏

Copy link
Contributor

@reczkok reczkok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clean 🧹

@aleksanderkatan aleksanderkatan merged commit 34b6d60 into main Feb 11, 2026
4 checks passed
@aleksanderkatan aleksanderkatan deleted the feat/handle-compatible-math-functions-in-typegpu-functions branch February 11, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Handle compatible Math.* functions in TypeGPU functions

3 participants