diff options
Diffstat (limited to 'testing/web-platform/mozilla/tests/webgpu/webgpu/shader/validation/expression/call/builtin/atan2.spec.js')
-rw-r--r-- | testing/web-platform/mozilla/tests/webgpu/webgpu/shader/validation/expression/call/builtin/atan2.spec.js | 293 |
1 files changed, 268 insertions, 25 deletions
diff --git a/testing/web-platform/mozilla/tests/webgpu/webgpu/shader/validation/expression/call/builtin/atan2.spec.js b/testing/web-platform/mozilla/tests/webgpu/webgpu/shader/validation/expression/call/builtin/atan2.spec.js index e0fded50b1..999e07298d 100644 --- a/testing/web-platform/mozilla/tests/webgpu/webgpu/shader/validation/expression/call/builtin/atan2.spec.js +++ b/testing/web-platform/mozilla/tests/webgpu/webgpu/shader/validation/expression/call/builtin/atan2.spec.js @@ -6,13 +6,13 @@ Validation tests for the ${builtin}() builtin. import { makeTestGroup } from '../../../../../../common/framework/test_group.js'; import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { - TypeF16, - TypeF32, - Vector, - VectorType, - elementType, - kAllFloatScalarsAndVectors, - kAllIntegerScalarsAndVectors } from + VectorValue, + kFloatScalarsAndVectors, + kConcreteIntegerScalarsAndVectors, + kAllMatrices, + kAllBoolScalarsAndVectors, + scalarTypeOf, + Type } from '../../../../../util/conversion.js'; import { isRepresentable } from '../../../../../util/floating_point.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -20,7 +20,7 @@ import { ShaderValidationTest } from '../../../shader_validation_test.js'; import { fullRangeForType, kConstantAndOverrideStages, - kSparseMinus3PiTo3Pi, + sparseMinusThreePiToThreePiRangeForType, stageSupportsType, unique, validateConstOrOverrideBuiltinEval } from @@ -28,7 +28,7 @@ import { export const g = makeTestGroup(ShaderValidationTest); -const kValuesTypes = objectsToRecord(kAllFloatScalarsAndVectors); +const kValuesTypes = objectsToRecord(kFloatScalarsAndVectors); g.test('values'). desc( @@ -42,19 +42,29 @@ combine('stage', kConstantAndOverrideStages). combine('type', keysOf(kValuesTypes)). filter((u) => stageSupportsType(u.stage, kValuesTypes[u.type])). beginSubcases(). -expand('y', (u) => unique(kSparseMinus3PiTo3Pi, fullRangeForType(kValuesTypes[u.type], 4))). -expand('x', (u) => unique(kSparseMinus3PiTo3Pi, fullRangeForType(kValuesTypes[u.type], 4))) +expand('y', (u) => +unique( + sparseMinusThreePiToThreePiRangeForType(kValuesTypes[u.type]), + fullRangeForType(kValuesTypes[u.type], 4) +) +). +expand('x', (u) => +unique( + sparseMinusThreePiToThreePiRangeForType(kValuesTypes[u.type]), + fullRangeForType(kValuesTypes[u.type], 4) +) +) ). beforeAllSubcases((t) => { - if (elementType(kValuesTypes[t.params.type]) === TypeF16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }). fn((t) => { const type = kValuesTypes[t.params.type]; const expectedResult = isRepresentable( - Math.abs(Math.atan2(t.params.y, t.params.x)), - elementType(type) + Math.abs(Math.atan2(Number(t.params.x), Number(t.params.y))), + scalarTypeOf(type) ); validateConstOrOverrideBuiltinEval( t, @@ -65,42 +75,275 @@ fn((t) => { ); }); -const kIntegerArgumentTypes = objectsToRecord([TypeF32, ...kAllIntegerScalarsAndVectors]); +const kInvalidArgumentTypes = objectsToRecord([ +Type.f32, +...kConcreteIntegerScalarsAndVectors, +...kAllBoolScalarsAndVectors, +...kAllMatrices] +); -g.test('integer_argument_y'). +g.test('invalid_argument_y'). desc( ` Validates that scalar and vector integer arguments are rejected by ${builtin}() ` ). -params((u) => u.combine('type', keysOf(kIntegerArgumentTypes))). +params((u) => u.combine('type', keysOf(kInvalidArgumentTypes))). fn((t) => { - const yTy = kIntegerArgumentTypes[t.params.type]; - const xTy = yTy instanceof Vector ? new VectorType(yTy.size, TypeF32) : TypeF32; + const yTy = kInvalidArgumentTypes[t.params.type]; + const xTy = yTy instanceof VectorValue ? Type.vec(yTy.size, Type.f32) : Type.f32; validateConstOrOverrideBuiltinEval( t, builtin, - /* expectedResult */yTy === TypeF32, + /* expectedResult */yTy === Type.f32, [yTy.create(1), xTy.create(1)], 'constant' ); }); -g.test('integer_argument_x'). +g.test('invalid_argument_x'). desc( ` Validates that scalar and vector integer arguments are rejected by ${builtin}() ` ). -params((u) => u.combine('type', keysOf(kIntegerArgumentTypes))). +params((u) => u.combine('type', keysOf(kInvalidArgumentTypes))). fn((t) => { - const xTy = kIntegerArgumentTypes[t.params.type]; - const yTy = xTy instanceof Vector ? new VectorType(xTy.size, TypeF32) : TypeF32; + const xTy = kInvalidArgumentTypes[t.params.type]; + const yTy = xTy instanceof VectorValue ? Type.vec(xTy.size, Type.f32) : Type.f32; validateConstOrOverrideBuiltinEval( t, builtin, - /* expectedResult */xTy === TypeF32, + /* expectedResult */xTy === Type.f32, [yTy.create(1), xTy.create(1)], 'constant' ); +}); + +const kTests = { + af: { + src: `_ = atan2(1.2, 2.2);`, + pass: true, + is_f16: false + }, + ai: { + src: `_ = atan2(1, 2);`, + pass: true, + is_f16: false + }, + ai_af: { + src: `_ = atan2(1, 2.1);`, + pass: true, + is_f16: false + }, + af_ai: { + src: `_ = atan2(1.2, 2);`, + pass: true, + is_f16: false + }, + ai_f32: { + src: `_ = atan2(1, 1.2f);`, + pass: true, + is_f16: false + }, + f32_ai: { + src: `_ = atan2(1.2f, 1);`, + pass: true, + is_f16: false + }, + af_f32: { + src: `_ = atan2(1.2, 2.2f);`, + pass: true, + is_f16: false + }, + f32_af: { + src: `_ = atan2(2.2f, 1.2);`, + pass: true, + is_f16: false + }, + f16_ai: { + src: `_ = atan2(1.2h, 1);`, + pass: true, + is_f16: true + }, + ai_f16: { + src: `_ = atan2(1, 1.2h);`, + pass: true, + is_f16: true + }, + af_f16: { + src: `_ = atan2(1.2, 1.2h);`, + pass: true, + is_f16: true + }, + f16_af: { + src: `_ = atan2(1.2h, 1.2);`, + pass: true, + is_f16: true + }, + + mixed_types: { + src: `_ = atan2(1.2f, vec2(1.2f));`, + pass: false, + is_f16: false + }, + mixed_types_2: { + src: `_ = atan2(vec2(1.2f), 1.2f);`, + pass: false, + is_f16: false + }, + f16_f32: { + src: `_ = atan2(1.2h, 1.2f);`, + pass: false, + is_f16: true + }, + u32_f32: { + src: `_ = atan2(1u, 1.2f);`, + pass: false, + is_f16: false + }, + f32_u32: { + src: `_ = atan2(1.2f, 1u);`, + pass: false, + is_f16: false + }, + f32_i32: { + src: `_ = atan2(1.2f, 1i);`, + pass: false, + is_f16: false + }, + i32_f32: { + src: `_ = atan2(1i, 1.2f);`, + pass: false, + is_f16: false + }, + f32_bool: { + src: `_ = atan2(1.2f, true);`, + pass: false, + is_f16: false + }, + bool_f32: { + src: `_ = atan2(false, 1.2f);`, + pass: false, + is_f16: false + }, + vec_f32: { + src: `_ = atan2(vec2(1i), vec2(1.2f));`, + pass: false, + is_f16: false + }, + f32_vec: { + src: `_ = atan2(vec2(1.2f), vec2(1i));`, + pass: false, + is_f16: false + }, + matrix: { + src: `_ = atan2(mat2x2(1, 1, 1, 1), mat2x2(1, 1, 1, 1));`, + pass: false, + is_f16: false + }, + atomic: { + src: ` _ = atan2(a, a);`, + pass: false, + is_f16: false + }, + array: { + src: `var a: array<u32, 5>; + _ = atan2(a, a);`, + pass: false, + is_f16: false + }, + array_runtime: { + src: `_ = atan2(k.arry, k.arry);`, + pass: false, + is_f16: false + }, + struct: { + src: `var a: A; + _ = atan2(a, a);`, + pass: false, + is_f16: false + }, + enumerant: { + src: `_ = atan2(read_write, read_write);`, + pass: false, + is_f16: false + }, + ptr: { + src: `var<function> a = 1f; + let p: ptr<function, f32> = &a; + _ = atan2(p, p);`, + pass: false, + is_f16: false + }, + ptr_deref: { + src: `var<function> a = 1f; + let p: ptr<function, f32> = &a; + _ = atan2(*p, *p);`, + pass: true, + is_f16: false + }, + sampler: { + src: `_ = atan2(s, s);`, + pass: false, + is_f16: false + }, + texture: { + src: `_ = atan2(t, t);`, + pass: false, + is_f16: false + }, + no_params: { + src: `_ = atan2();`, + pass: false, + is_f16: false + }, + too_many_params: { + src: `_ = atan2(1, 2, 3);`, + pass: false, + is_f16: false + } +}; + +g.test('parameters'). +desc(`Test that ${builtin} is validated correctly.`). +params((u) => u.combine('test', keysOf(kTests))). +beforeAllSubcases((t) => { + if (kTests[t.params.test].is_f16 === true) { + t.selectDeviceOrSkipTestCase('shader-f16'); + } +}). +fn((t) => { + const src = kTests[t.params.test].src; + const code = ` +alias f32_alias = f32; + +@group(0) @binding(0) var s: sampler; +@group(0) @binding(1) var t: texture_2d<f32>; + +var<workgroup> a: atomic<u32>; + +struct A { + i: u32, +} +struct B { + arry: array<u32>, +} +@group(0) @binding(3) var<storage> k: B; + + +@vertex +fn main() -> @builtin(position) vec4<f32> { + ${src} + return vec4<f32>(.4, .2, .3, .1); +}`; + t.expectCompileResult(kTests[t.params.test].pass, code); +}); + +g.test('must_use'). +desc(`Result of ${builtin} must be used`). +params((u) => u.combine('use', [true, false])). +fn((t) => { + const use_it = t.params.use ? '_ = ' : ''; + t.expectCompileResult(t.params.use, `fn f() { ${use_it}${builtin}(1, 2); }`); });
\ No newline at end of file |