Skip to content

TSL Support for data packing / unpacking functions #30663

@brutestack

Description

@brutestack

Description

Currently there is no way to rewrite GLSL shader that uses packing functions such as UnpackHalf2x16 to TSL. However, both GLSL and WGSL provide equivalent functions for packing/unpacking vectors to/from integers

GLSL:

PackSnorm4x8
PackUnorm4x8
PackSnorm2x16
PackUnorm2x16
PackHalf2x16
PackDouble2x32

UnpackSnorm4x8
UnpackUnorm4x8
UnpackSnorm2x16
UnpackUnorm2x16
UnpackHalf2x16
UnpackDouble2x32

WGSL:

pack4x8snorm
pack4x8unorm
pack4xI8
pack4xU8
pack4xI8Clamp
pack4xU8Clamp
pack2x16snorm
pack2x16unorm
pack2x16float

unpack4x8snorm
unpack4x8unorm
unpack4xI8
unpack4xU8
unpack2x16snorm
unpack2x16unorm
unpack2x16float

https://www.w3.org/TR/WGSL/#pack-builtin-functions
https://www.w3.org/TR/WGSL/#unpack-builtin-functions

Solution

Please add packing and unpacking functions to TSL like it is done for bitcast function in MathNode

Alternatives

Otherwise is there any simple way of adding new math functions to TSL by providing GLSL and WGSL code equivalents?

Additional context

GLSL example code:

uint packedValue = 0x3C001A00; // Example 32-bit unsigned integer
vec2 unpackedValue = unpackHalf2x16(packedValue);

After rewritten to TSL should look like this:

const packedValue = uint(0x3C001A00); // Example 32-bit unsigned integer
const unpackedValue = packedValue.unpack2x16float(); // vec2 result of unpacking

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions