|
Lines 5451-5456
tests.halfSimpleMath = function() {
a/Tools/WebGPUShadingLanguageRI/Test.js_sec1
|
| 5451 |
checkHalf(program, callFunction(program, "foo", [makeHalf(program, 7), makeHalf(program, -2)]), -3.5); |
5451 |
checkHalf(program, callFunction(program, "foo", [makeHalf(program, 7), makeHalf(program, -2)]), -3.5); |
| 5452 |
} |
5452 |
} |
| 5453 |
|
5453 |
|
|
|
5454 |
tests.matrixMultiplication = function() { |
| 5455 |
let program = doPrep(` |
| 5456 |
float2x4 multiply(float2x3 x, float3x4 y) { |
| 5457 |
// Copied and pasted from the standard library |
| 5458 |
float2x4 result; |
| 5459 |
result[0][0] = 0; |
| 5460 |
result[0][0] += x[0][0] * y[0][0]; |
| 5461 |
result[0][0] += x[0][1] * y[1][0]; |
| 5462 |
result[0][0] += x[0][2] * y[2][0]; |
| 5463 |
result[0][1] = 0; |
| 5464 |
result[0][1] += x[0][0] * y[0][1]; |
| 5465 |
result[0][1] += x[0][1] * y[1][1]; |
| 5466 |
result[0][1] += x[0][2] * y[2][1]; |
| 5467 |
result[0][2] = 0; |
| 5468 |
result[0][2] += x[0][0] * y[0][2]; |
| 5469 |
result[0][2] += x[0][1] * y[1][2]; |
| 5470 |
result[0][2] += x[0][2] * y[2][2]; |
| 5471 |
result[0][3] = 0; |
| 5472 |
result[0][3] += x[0][0] * y[0][3]; |
| 5473 |
result[0][3] += x[0][1] * y[1][3]; |
| 5474 |
result[0][3] += x[0][2] * y[2][3]; |
| 5475 |
result[1][0] = 0; |
| 5476 |
result[1][0] += x[1][0] * y[0][0]; |
| 5477 |
result[1][0] += x[1][1] * y[1][0]; |
| 5478 |
result[1][0] += x[1][2] * y[2][0]; |
| 5479 |
result[1][1] = 0; |
| 5480 |
result[1][1] += x[1][0] * y[0][1]; |
| 5481 |
result[1][1] += x[1][1] * y[1][1]; |
| 5482 |
result[1][1] += x[1][2] * y[2][1]; |
| 5483 |
result[1][2] = 0; |
| 5484 |
result[1][2] += x[1][0] * y[0][2]; |
| 5485 |
result[1][2] += x[1][1] * y[1][2]; |
| 5486 |
result[1][2] += x[1][2] * y[2][2]; |
| 5487 |
result[1][3] = 0; |
| 5488 |
result[1][3] += x[1][0] * y[0][3]; |
| 5489 |
result[1][3] += x[1][1] * y[1][3]; |
| 5490 |
result[1][3] += x[1][2] * y[2][3]; |
| 5491 |
return result; |
| 5492 |
} |
| 5493 |
float2x3 matrix1() { |
| 5494 |
float2x3 x; |
| 5495 |
x[0][0] = 2; |
| 5496 |
x[0][1] = 3; |
| 5497 |
x[0][2] = 5; |
| 5498 |
x[1][0] = 7; |
| 5499 |
x[1][1] = 11; |
| 5500 |
x[1][2] = 13; |
| 5501 |
return x; |
| 5502 |
} |
| 5503 |
float3x4 matrix2() { |
| 5504 |
float3x4 y; |
| 5505 |
y[0][0] = 17; |
| 5506 |
y[0][1] = 19; |
| 5507 |
y[0][2] = 23; |
| 5508 |
y[0][3] = 29; |
| 5509 |
y[1][0] = 31; |
| 5510 |
y[1][1] = 37; |
| 5511 |
y[1][2] = 41; |
| 5512 |
y[1][3] = 43; |
| 5513 |
y[2][0] = 47; |
| 5514 |
y[2][1] = 53; |
| 5515 |
y[2][2] = 59; |
| 5516 |
y[2][3] = 61; |
| 5517 |
return y; |
| 5518 |
} |
| 5519 |
float foo00() { |
| 5520 |
return multiply(matrix1(), matrix2())[0][0]; |
| 5521 |
} |
| 5522 |
float foo01() { |
| 5523 |
return multiply(matrix1(), matrix2())[0][1]; |
| 5524 |
} |
| 5525 |
float foo02() { |
| 5526 |
return multiply(matrix1(), matrix2())[0][2]; |
| 5527 |
} |
| 5528 |
float foo03() { |
| 5529 |
return multiply(matrix1(), matrix2())[0][3]; |
| 5530 |
} |
| 5531 |
float foo10() { |
| 5532 |
return multiply(matrix1(), matrix2())[1][0]; |
| 5533 |
} |
| 5534 |
float foo11() { |
| 5535 |
return multiply(matrix1(), matrix2())[1][1]; |
| 5536 |
} |
| 5537 |
float foo12() { |
| 5538 |
return multiply(matrix1(), matrix2())[1][2]; |
| 5539 |
} |
| 5540 |
float foo13() { |
| 5541 |
return multiply(matrix1(), matrix2())[1][3]; |
| 5542 |
} |
| 5543 |
`); |
| 5544 |
checkFloat(program, callFunction(program, "foo00", []), 17 * 2 + 31 * 3 + 47 * 5); |
| 5545 |
checkFloat(program, callFunction(program, "foo01", []), 19 * 2 + 37 * 3 + 53 * 5); |
| 5546 |
checkFloat(program, callFunction(program, "foo02", []), 23 * 2 + 41 * 3 + 59 * 5); |
| 5547 |
checkFloat(program, callFunction(program, "foo03", []), 29 * 2 + 43 * 3 + 61 * 5); |
| 5548 |
checkFloat(program, callFunction(program, "foo10", []), 17 * 7 + 31 * 11 + 47 * 13); |
| 5549 |
checkFloat(program, callFunction(program, "foo11", []), 19 * 7 + 37 * 11 + 53 * 13); |
| 5550 |
checkFloat(program, callFunction(program, "foo12", []), 23 * 7 + 41 * 11 + 59 * 13); |
| 5551 |
checkFloat(program, callFunction(program, "foo13", []), 29 * 7 + 43 * 11 + 61 * 13); |
| 5552 |
} |
| 5553 |
|
| 5454 |
okToTest = true; |
5554 |
okToTest = true; |
| 5455 |
|
5555 |
|
| 5456 |
let testFilter = /.*/; // run everything by default |
5556 |
let testFilter = /.*/; // run everything by default |