summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/mozilla/tests/webgpu/webgpu/shader/execution/expression/call/builtin/pack4x8snorm.spec.js
blob: 42db991e5380fde20bea66f7f5f509db36eb1951 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* AUTO-GENERATED - DO NOT EDIT. Source: https://github.com/gpuweb/cts
**/export const description = `
Converts four normalized floating point values to 8-bit signed integers, and then combines them into one u32 value.
Component e[i] of the input is converted to an 8-bit twos complement integer value
⌊ 0.5 + 127 × min(1, max(-1, e[i])) ⌋ which is then placed in
bits 8 × i through 8 × i + 7 of the result.
`;import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../../gpu_test.js';
import { kValue } from '../../../../../util/constants.js';
import { f32, pack4x8snorm, u32, vec4, Type } from '../../../../../util/conversion.js';
import { quantizeToF32, vectorF32Range } from '../../../../../util/math.js';

import { allInputSources, run } from '../../expression.js';

import { builtin } from './builtin.js';

export const g = makeTestGroup(GPUTest);

g.test('pack').
specURL('https://www.w3.org/TR/WGSL/#pack-builtin-functions').
desc(
  `
@const fn pack4x8snorm(e: vec4<f32>) -> u32
`
).
params((u) => u.combine('inputSource', allInputSources)).
fn(async (t) => {
  const makeCase = (vals) => {
    const vals_f32 = new Array(4);





    for (const idx in vals) {
      vals[idx] = quantizeToF32(vals[idx]);
      vals_f32[idx] = f32(vals[idx]);
    }

    return { input: [vec4(...vals_f32)], expected: u32(pack4x8snorm(...vals)) };
  };

  // Returns a value normalized to [-1, 1].
  const normalizeF32 = (n) => {
    return n / kValue.f32.positive.max;
  };

  const cases = vectorF32Range(4).flatMap((v) => {
    return [
    makeCase(v),
    makeCase(v.map(normalizeF32))];

  });

  await run(t, builtin('pack4x8snorm'), [Type.vec4f], Type.u32, t.params, cases);
});