dot4U8Packed
On this page

dot4U8Packed

Function

A packed dot product reads byte-sized lanes from two words and sums their pairwise products.

Compare examples

Compare the unpacked lanes with the sum of products. Each lane has its own signedness.

Example 1a = [1,2,3,4]; b = [4,3,2,1]
Result
(1 × 4) + (2 × 3) + (3 × 2) + (4 × 1) = 20
Example 2a = [0,0,0,0]; b = [1,1,1,1]
Result
(0 × 1) + (0 × 1) + (0 × 1) + (0 × 1) = 0
Example 3a = [2,2,2,2]; b = [2,2,2,2]
Result
(2 × 2) + (2 × 2) + (2 × 2) + (2 × 2) = 16

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 for compact integer-vector arithmetic, including quantized inference.

Inputs and limits

This example uses unsigned bytes. The compiler requires WebGPU and the packed integer dot-product language feature.

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.

Reads both u32 arguments as four UNSIGNED bytes and sums the four products into a u32.

Syntax

declare function dot4U8Packed(a0: u32, a1: u32): u32
declare function dot4U8Packed(a: u32, b: u32): u32

Parameters

Return value

u32

Description

Not supported yet on the WebGL2 tier: TypeShade emits no GLSL ES 3.00 form of it, so a module using it emits WGSL alone. The host should check navigator.gpu.wgslLanguageFeatures for packed_4x8_integer_dot_product, which reflect().requiredLanguageFeatures reports.

Targets

WGSL
dot4U8Packed(a, b)
GLSL ES 3.00
dot4U8Packed is not supported yet on the WebGL2 tier

Examples

See also

Edit this page Report a problem