|
| 1 | +export const description = ` |
| 2 | +Execution Tests for the 'all' builtin function |
| 3 | +`; |
| 4 | + |
| 5 | +import { makeTestGroup } from '../../../../common/framework/test_group.js'; |
| 6 | +import { assert } from '../../../../common/util/util.js'; |
| 7 | +import { GPUTest } from '../../../gpu_test.js'; |
| 8 | +import { generateTypes } from '../../types.js'; |
| 9 | + |
| 10 | +import { OperandType, runShaderTest } from './builtin.js'; |
| 11 | + |
| 12 | +export const g = makeTestGroup(GPUTest); |
| 13 | + |
| 14 | +g.test('abs_float') |
| 15 | + .uniqueId(0x1f3fc889e2b1727f) |
| 16 | + .desc( |
| 17 | + ` |
| 18 | +https://www.w3.org/TR/2021/WD-WGSL-20210831#float-builtin-functions |
| 19 | +float abs: |
| 20 | +T is f32 or vecN<f32> abs(e: T ) -> T |
| 21 | +Returns the absolute value of e (e.g. e with a positive sign bit). |
| 22 | +Component-wise when T is a vector. |
| 23 | +(GLSLstd450Fabs) |
| 24 | +` |
| 25 | + ) |
| 26 | + .params(u => |
| 27 | + u |
| 28 | + .combineWithParams([ |
| 29 | + { storageClass: 'storage', storageMode: 'read_write', access: 'read' }, |
| 30 | + ] as const) |
| 31 | + .combine('containerType', ['scalar', 'vector'] as const) |
| 32 | + .combine('isAtomic', [false]) |
| 33 | + .combine('baseType', ['f32'] as const) |
| 34 | + .beginSubcases() |
| 35 | + .expandWithParams(generateTypes) |
| 36 | + ) |
| 37 | + .fn(async t => { |
| 38 | + assert(t.params._kTypeInfo !== undefined, 'generated type is undefined'); |
| 39 | + runShaderTest( |
| 40 | + t, |
| 41 | + t.params.storageClass, |
| 42 | + t.params.storageMode, |
| 43 | + t.params.baseType, |
| 44 | + t.params.type, |
| 45 | + t.params._kTypeInfo.arrayLength, |
| 46 | + 'abs', |
| 47 | + OperandType.Float, |
| 48 | + [ |
| 49 | + { input: 0.0, expected: [0.0] }, |
| 50 | + { input: 1.0, expected: [1.0] }, |
| 51 | + { input: 2.0, expected: [2.0] }, |
| 52 | + { input: 4.0, expected: [4.0] }, |
| 53 | + { input: 8.0, expected: [8.0] }, |
| 54 | + { input: 16.0, expected: [16.0] }, |
| 55 | + { input: 32.0, expected: [32.0] }, |
| 56 | + { input: 64.0, expected: [64.0] }, |
| 57 | + { input: 128.0, expected: [128.0] }, |
| 58 | + { input: 256.0, expected: [256.0] }, |
| 59 | + { input: 512.0, expected: [512.0] }, |
| 60 | + { input: 1024.0, expected: [1024.0] }, |
| 61 | + { input: 2048.0, expected: [2048.0] }, |
| 62 | + { input: 4096.0, expected: [4096.0] }, |
| 63 | + { input: 8192.0, expected: [8192.0] }, |
| 64 | + { input: 16384.0, expected: [16384.0] }, |
| 65 | + { input: 32768.0, expected: [32768.0] }, |
| 66 | + { input: 65536.0, expected: [65536.0] }, |
| 67 | + { input: 131072.0, expected: [131072.0] }, |
| 68 | + { input: 262144.0, expected: [262144.0] }, |
| 69 | + { input: 524288.0, expected: [524288.0] }, |
| 70 | + { input: 1048576.0, expected: [1048576.0] }, |
| 71 | + { input: 8388607.0, expected: [8388607.0] }, //2^23 - 1 |
| 72 | + { input: 16777215.0, expected: [16777215.0] }, //2^24 - 1 |
| 73 | + { input: 16777216.0, expected: [16777216.0] }, //2^24 |
| 74 | + { input: 0.0, expected: [0.0] }, |
| 75 | + { input: -1.0, expected: [1.0] }, |
| 76 | + { input: -2.0, expected: [2.0] }, |
| 77 | + { input: -4.0, expected: [4.0] }, |
| 78 | + { input: -8.0, expected: [8.0] }, |
| 79 | + { input: -16.0, expected: [16.0] }, |
| 80 | + { input: -32.0, expected: [32.0] }, |
| 81 | + { input: -64.0, expected: [64.0] }, |
| 82 | + { input: -128.0, expected: [128.0] }, |
| 83 | + { input: -256.0, expected: [256.0] }, |
| 84 | + { input: -512.0, expected: [512.0] }, |
| 85 | + { input: -1024.0, expected: [1024.0] }, |
| 86 | + { input: -2048.0, expected: [2048.0] }, |
| 87 | + { input: -4096.0, expected: [4096.0] }, |
| 88 | + { input: -8192.0, expected: [8192.0] }, |
| 89 | + { input: -16384.0, expected: [16384.0] }, |
| 90 | + { input: -32768.0, expected: [32768.0] }, |
| 91 | + { input: -65536.0, expected: [65536.0] }, |
| 92 | + { input: -131072.0, expected: [131072.0] }, |
| 93 | + { input: -262144.0, expected: [262144.0] }, |
| 94 | + { input: -524288.0, expected: [524288.0] }, |
| 95 | + { input: -1048576.0, expected: [1048576.0] }, |
| 96 | + { input: -8388607.0, expected: [8388607.0] }, //2^23 - 1 |
| 97 | + { input: -16777215.0, expected: [16777215.0] }, //2^24 - 1 |
| 98 | + { input: -16777216.0, expected: [16777216.0] }, //2^24 |
| 99 | + ] |
| 100 | + ); |
| 101 | + }); |
| 102 | + |
| 103 | +g.test('abs_int') |
| 104 | + .uniqueId(0xfab878e682c16d42) |
| 105 | + .desc( |
| 106 | + ` |
| 107 | +https://www.w3.org/TR/2021/WD-WGSL-20210831#integer-builtin-functions |
| 108 | +signed abs: |
| 109 | +T is i32 or vecN<i32> abs(e: T ) -> T The absolute value of e. |
| 110 | +Component-wise when T is a vector. |
| 111 | +If e evaluates to the largest negative value, then the result is e. |
| 112 | +` |
| 113 | + ) |
| 114 | + .params(u => |
| 115 | + u |
| 116 | + .combineWithParams([ |
| 117 | + { storageClass: 'storage', storageMode: 'read_write', access: 'read' }, |
| 118 | + ] as const) |
| 119 | + .combine('containerType', ['scalar', 'vector'] as const) |
| 120 | + .combine('isAtomic', [false]) |
| 121 | + .combine('baseType', ['i32'] as const) |
| 122 | + .beginSubcases() |
| 123 | + .expandWithParams(generateTypes) |
| 124 | + ) |
| 125 | + .fn(async t => { |
| 126 | + assert(t.params._kTypeInfo !== undefined, 'generated type is undefined'); |
| 127 | + runShaderTest( |
| 128 | + t, |
| 129 | + t.params.storageClass, |
| 130 | + t.params.storageMode, |
| 131 | + t.params.baseType, |
| 132 | + t.params.type, |
| 133 | + t.params._kTypeInfo.arrayLength, |
| 134 | + 'abs', |
| 135 | + OperandType.Int, |
| 136 | + [ |
| 137 | + { input: -1, expected: [1] }, |
| 138 | + { input: -2, expected: [2] }, |
| 139 | + { input: -4, expected: [4] }, |
| 140 | + { input: -8, expected: [8] }, |
| 141 | + { input: -16, expected: [16] }, |
| 142 | + { input: -32, expected: [32] }, |
| 143 | + { input: -64, expected: [64] }, |
| 144 | + { input: -128, expected: [128] }, |
| 145 | + { input: -256, expected: [256] }, |
| 146 | + { input: -512, expected: [512] }, |
| 147 | + { input: -1024, expected: [1024] }, |
| 148 | + { input: -2048, expected: [2048] }, |
| 149 | + { input: -4096, expected: [4096] }, |
| 150 | + { input: -8192, expected: [8192] }, |
| 151 | + { input: -16384, expected: [16384] }, |
| 152 | + { input: -32768, expected: [32768] }, |
| 153 | + { input: -65536, expected: [65536] }, |
| 154 | + { input: -131072, expected: [131072] }, |
| 155 | + { input: -262144, expected: [262144] }, |
| 156 | + { input: -524288, expected: [524288] }, |
| 157 | + { input: -1048576, expected: [1048576] }, |
| 158 | + { input: -8388607, expected: [8388607] }, |
| 159 | + { input: -16777215, expected: [16777215] }, |
| 160 | + { input: -16777216, expected: [16777216] }, |
| 161 | + { input: -134217727, expected: [134217727] }, |
| 162 | + { input: -1073741823, expected: [1073741823] }, |
| 163 | + { input: -2147483647, expected: [2147483647] }, |
| 164 | + { input: 0, expected: [0] }, |
| 165 | + { input: 1, expected: [1] }, |
| 166 | + { input: 2, expected: [2] }, |
| 167 | + { input: 4, expected: [4] }, |
| 168 | + { input: 8, expected: [8] }, |
| 169 | + { input: 16, expected: [16] }, |
| 170 | + { input: 32, expected: [32] }, |
| 171 | + { input: 64, expected: [64] }, |
| 172 | + { input: 128, expected: [128] }, |
| 173 | + { input: 256, expected: [256] }, |
| 174 | + { input: 512, expected: [512] }, |
| 175 | + { input: 1024, expected: [1024] }, |
| 176 | + { input: 2048, expected: [2048] }, |
| 177 | + { input: 4096, expected: [4096] }, |
| 178 | + { input: 8192, expected: [8192] }, |
| 179 | + { input: 16384, expected: [16384] }, |
| 180 | + { input: 32768, expected: [32768] }, |
| 181 | + { input: 65536, expected: [65536] }, |
| 182 | + { input: 131072, expected: [131072] }, |
| 183 | + { input: 262144, expected: [262144] }, |
| 184 | + { input: 524288, expected: [524288] }, |
| 185 | + { input: 1048576, expected: [1048576] }, |
| 186 | + { input: 8388607, expected: [8388607] }, //2^23 - 1 |
| 187 | + { input: 16777215, expected: [16777215] }, //2^24 - 1 |
| 188 | + { input: 16777216, expected: [16777216] }, //2^24 |
| 189 | + { input: 134217727, expected: [134217727] }, //2^27 - 1 |
| 190 | + { input: 1073741823, expected: [1073741823] }, //2^30 - 1 |
| 191 | + ] |
| 192 | + ); |
| 193 | + }); |
| 194 | + |
| 195 | +g.test('abs_uint') |
| 196 | + .uniqueId(0x59ff84968a839124) |
| 197 | + .desc( |
| 198 | + ` |
| 199 | +https://www.w3.org/TR/2021/WD-WGSL-20210831#integer-builtin-function |
| 200 | +scalar case, unsigned abs: |
| 201 | +T is u32 or vecN<u32> abs(e: T ) -> T Result is e. |
| 202 | +This is provided for symmetry with abs for signed integers. |
| 203 | +Component-wise when T is a vector. |
| 204 | +` |
| 205 | + ) |
| 206 | + .params(u => |
| 207 | + u |
| 208 | + .combineWithParams([ |
| 209 | + { storageClass: 'storage', storageMode: 'read_write', access: 'read' }, |
| 210 | + ] as const) |
| 211 | + .combine('containerType', ['scalar', 'vector'] as const) |
| 212 | + .combine('isAtomic', [false]) |
| 213 | + .combine('baseType', ['u32'] as const) |
| 214 | + .beginSubcases() |
| 215 | + .expandWithParams(generateTypes) |
| 216 | + ) |
| 217 | + .fn(async t => { |
| 218 | + assert(t.params._kTypeInfo !== undefined, 'generated type is undefined'); |
| 219 | + runShaderTest( |
| 220 | + t, |
| 221 | + t.params.storageClass, |
| 222 | + t.params.storageMode, |
| 223 | + t.params.baseType, |
| 224 | + t.params.type, |
| 225 | + t.params._kTypeInfo.arrayLength, |
| 226 | + 'abs', |
| 227 | + OperandType.Uint, |
| 228 | + [ |
| 229 | + { input: 0, expected: [0] }, |
| 230 | + { input: 1, expected: [1] }, |
| 231 | + { input: 2, expected: [2] }, |
| 232 | + { input: 4, expected: [4] }, |
| 233 | + { input: 8, expected: [8] }, |
| 234 | + { input: 16, expected: [16] }, |
| 235 | + { input: 32, expected: [32] }, |
| 236 | + { input: 64, expected: [64] }, |
| 237 | + { input: 128, expected: [128] }, |
| 238 | + { input: 256, expected: [256] }, |
| 239 | + { input: 512, expected: [512] }, |
| 240 | + { input: 1024, expected: [1024] }, |
| 241 | + { input: 2048, expected: [2048] }, |
| 242 | + { input: 4096, expected: [4096] }, |
| 243 | + { input: 8192, expected: [8192] }, |
| 244 | + { input: 16384, expected: [16384] }, |
| 245 | + { input: 32768, expected: [32768] }, |
| 246 | + { input: 65536, expected: [65536] }, |
| 247 | + { input: 131072, expected: [131072] }, |
| 248 | + { input: 262144, expected: [262144] }, |
| 249 | + { input: 524288, expected: [524288] }, |
| 250 | + { input: 1048576, expected: [1048576] }, |
| 251 | + { input: 8388607, expected: [8388607] }, //2^23 - 1 |
| 252 | + { input: 16777215, expected: [16777215] }, //2^24 - 1 |
| 253 | + { input: 16777216, expected: [16777216] }, //2^24 |
| 254 | + { input: 134217727, expected: [134217727] }, //2^27 - 1 |
| 255 | + { input: 2147483647, expected: [2147483647] }, //2^31 - 1 |
| 256 | + ] |
| 257 | + ); |
| 258 | + }); |
| 259 | + |
| 260 | +g.test('abs_uint_hex') |
| 261 | + .uniqueId(0x59ff84968a839124) |
| 262 | + .desc( |
| 263 | + ` |
| 264 | +https://www.w3.org/TR/2021/WD-WGSL-20210831#integer-builtin-functions |
| 265 | +scalar case, unsigned abs: |
| 266 | +T is u32 or vecN<u32> abs(e: T ) -> T Result is e. |
| 267 | +This is provided for symmetry with abs for signed integers. |
| 268 | +Component-wise when T is a vector. |
| 269 | +` |
| 270 | + ) |
| 271 | + .params(u => |
| 272 | + u |
| 273 | + .combineWithParams([ |
| 274 | + { storageClass: 'storage', storageMode: 'read_write', access: 'read' }, |
| 275 | + ] as const) |
| 276 | + .combine('containerType', ['scalar', 'vector'] as const) |
| 277 | + .combine('isAtomic', [false]) |
| 278 | + .combine('baseType', ['u32'] as const) |
| 279 | + .beginSubcases() |
| 280 | + .expandWithParams(generateTypes) |
| 281 | + ) |
| 282 | + .fn(async t => { |
| 283 | + assert(t.params._kTypeInfo !== undefined, 'generated type is undefined'); |
| 284 | + runShaderTest( |
| 285 | + t, |
| 286 | + t.params.storageClass, |
| 287 | + t.params.storageMode, |
| 288 | + t.params.baseType, |
| 289 | + t.params.type, |
| 290 | + t.params._kTypeInfo.arrayLength, |
| 291 | + 'abs', |
| 292 | + OperandType.Hex, |
| 293 | + [ |
| 294 | + { input: 0xffffffff, expected: [0xffffffff] }, // -Inf f32 |
| 295 | + { input: 0x477fe000, expected: [0x477fe000] }, // 65504 - largest positive f16 |
| 296 | + { input: 0xc77fe000, expected: [0xc77fe000] }, // -65504 - largest negative f16 |
| 297 | + { input: 0x3380346c, expected: [0x3380346c] }, // 0.0000000597 - smallest positive f16 |
| 298 | + ] |
| 299 | + ); |
| 300 | + }); |
0 commit comments