pack4xI8
On this page

pack4xI8

Function

Integer byte packing combines components into one word.

Compare examples

Compare the components, hexadecimal word, and recovered values. Notice which component occupies the low field.

Example 1pack4xI8(vec4i(1, 2, 3, 4))
1234
Components in this example
Result
0x04030201
Word in binary: 67305985
Example 2pack4xI8(vec4i(-1, -1, -1, -1))
-1-1-1-1
Components in this example
Result
0xffffffff
Word in binary: 4294967295
Example 3pack4xI8(vec4i(130, 130, 130, 130))
130130130130
Components in this example
Result
0x82828282
Word in binary: 2189591170

The examples are calculation models and do not run GPU work. The reference below gives the complete call signatures. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.

When to use it

Use it to reduce storage or bandwidth when the reduced precision is acceptable.

Inputs and limits

This variant keeps only the low byte of each component; it does not clamp. These integer byte operations are WebGPU-only in this compiler.

For shader input rules and precision, consult WGSL and GLSL ES 3.00.

The signature, the sentence and any message are the compiler's own text at commit af54ddad5.

Packs the low byte of each component of a vec4i into a u32, four bytes in a word.

Syntax

declare function pack4xI8(a0: vec4i): u32
declare function pack4xI8(e: vec4i): u32

Parameters

Return value

u32

Description

The result is unsigned even though the components are not; a component that does not fit is TRUNCATED, where pack4xI8Clamp saturates. Not supported yet on the WebGL2 tier.

Targets

WGSL
pack4xI8(a)
GLSL ES 3.00
pack4xI8 is not supported yet on the WebGL2 tier

Examples

See also

Edit this page Report a problem