diff options
Diffstat (limited to 'dom/webgpu/tests/cts/checkout/src/webgpu/shader/execution/expression/call/builtin/pack2x16unorm.spec.ts')
-rw-r--r-- | dom/webgpu/tests/cts/checkout/src/webgpu/shader/execution/expression/call/builtin/pack2x16unorm.spec.ts | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/dom/webgpu/tests/cts/checkout/src/webgpu/shader/execution/expression/call/builtin/pack2x16unorm.spec.ts b/dom/webgpu/tests/cts/checkout/src/webgpu/shader/execution/expression/call/builtin/pack2x16unorm.spec.ts new file mode 100644 index 0000000000..a875a9c7e1 --- /dev/null +++ b/dom/webgpu/tests/cts/checkout/src/webgpu/shader/execution/expression/call/builtin/pack2x16unorm.spec.ts @@ -0,0 +1,55 @@ +export const description = ` +Converts two normalized floating point values to 16-bit unsigned integers, and then combines them into one u32 value. +Component e[i] of the input is converted to a 16-bit unsigned integer value +⌊ 0.5 + 65535 × min(1, max(0, e[i])) ⌋ which is then placed in +bits 16 × i through 16 × i + 15 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, + pack2x16unorm, + TypeF32, + TypeU32, + TypeVec, + u32, + vec2, +} from '../../../../../util/conversion.js'; +import { quantizeToF32, vectorF32Range } from '../../../../../util/math.js'; +import { allInputSources, Case, 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 pack2x16unorm(e: vec2<f32>) -> u32 +` + ) + .params(u => u.combine('inputSource', allInputSources)) + .fn(async t => { + const makeCase = (x: number, y: number): Case => { + x = quantizeToF32(x); + y = quantizeToF32(y); + return { input: [vec2(f32(x), f32(y))], expected: u32(pack2x16unorm(x, y)) }; + }; + + // Returns a value normalized to [0, 1]. + const normalizeF32 = (n: number): number => { + return n > 0 ? n / kValue.f32.positive.max : n / kValue.f32.negative.min; + }; + + const cases: Array<Case> = vectorF32Range(2).flatMap(v => { + return [ + makeCase(...(v as [number, number])), + makeCase(...(v.map(normalizeF32) as [number, number])), + ]; + }); + + await run(t, builtin('pack2x16unorm'), [TypeVec(2, TypeF32)], TypeU32, t.params, cases); + }); |