diff options
| author | slopgobblercobbler <336610228+slopgobblercobbler@users.noreply.github.com> | 2026-11-22 17:36:55 +0100 |
|---|---|---|
| committer | slopgobblercobbler <336610228+slopgobblercobbler@users.noreply.github.com> | 2026-11-22 17:36:55 +0100 |
| commit | d58343b1e4c8decfc0a8ccd3a040c5b4f9da02a9 (patch) | |
| tree | 25817891d99eefbd22313aba89bed6836d9eaa46 | |
| parent | 73a0237296eb606f68782297a5a164f66886dbc0 (diff) | |
test(semantic): add two's complement signed boundaries, return value retention, and negative controls
| -rw-r--r-- | tests/semantic/test_lds_atomic_max_i32.py | 495 |
1 files changed, 495 insertions, 0 deletions
diff --git a/tests/semantic/test_lds_atomic_max_i32.py b/tests/semantic/test_lds_atomic_max_i32.py index e2560c6e0..33cc4bac6 100644 --- a/tests/semantic/test_lds_atomic_max_i32.py +++ b/tests/semantic/test_lds_atomic_max_i32.py | |||
| @@ -1303,5 +1303,500 @@ OpFunctionEnd | |||
| 1303 | self.assertEqual(to_signed_i32(final_lds[s]), expected) | 1303 | self.assertEqual(to_signed_i32(final_lds[s]), expected) |
| 1304 | 1304 | ||
| 1305 | 1305 | ||
| 1306 | class TestTwosComplementSignedBoundaries(unittest.TestCase): | ||
| 1307 | """Verifies signed 32-bit extreme boundaries, identity elements, and sign-bit coverage.""" | ||
| 1308 | |||
| 1309 | def test_signed_32bit_extreme_boundaries(self): | ||
| 1310 | # INT32_MIN = -2147483648 (0x80000000) | ||
| 1311 | # INT32_MAX = 2147483647 (0x7FFFFFFF) | ||
| 1312 | # -1 = 0xFFFFFFFF | ||
| 1313 | # 0 = 0x00000000 | ||
| 1314 | # +1 = 0x00000001 | ||
| 1315 | cases = [ | ||
| 1316 | (INT32_MIN, INT32_MAX, INT32_MAX), | ||
| 1317 | (INT32_MAX, INT32_MIN, INT32_MAX), | ||
| 1318 | (INT32_MIN, 0xFFFFFFFF, 0xFFFFFFFF), # -2147483648 vs -1 -> -1 | ||
| 1319 | (0xFFFFFFFF, INT32_MIN, 0xFFFFFFFF), | ||
| 1320 | (0xFFFFFFFF, 0, 0), # -1 vs 0 -> 0 | ||
| 1321 | (0, 0xFFFFFFFF, 0), | ||
| 1322 | (0xFFFFFFFF, 1, 1), # -1 vs +1 -> +1 | ||
| 1323 | (1, 0xFFFFFFFF, 1), | ||
| 1324 | (INT32_MIN, INT32_MIN + 1, INT32_MIN + 1), # -2147483648 vs -2147483647 -> -2147483647 | ||
| 1325 | (INT32_MAX - 1, INT32_MAX, INT32_MAX), # 2147483646 vs 2147483647 -> 2147483647 | ||
| 1326 | ] | ||
| 1327 | for a, b, expected in cases: | ||
| 1328 | with self.subTest(a=hex(a), b=hex(b)): | ||
| 1329 | self.assertEqual(reference_atomic_max_i32(a, b), expected) | ||
| 1330 | |||
| 1331 | def test_int32_min_identity_element(self): | ||
| 1332 | # max(INT32_MIN, x) == x for all x | ||
| 1333 | test_values = [ | ||
| 1334 | INT32_MIN, | ||
| 1335 | INT32_MIN + 1, | ||
| 1336 | -1000000, | ||
| 1337 | -65536, | ||
| 1338 | -1, | ||
| 1339 | 0, | ||
| 1340 | 1, | ||
| 1341 | 65535, | ||
| 1342 | 1000000, | ||
| 1343 | INT32_MAX - 1, | ||
| 1344 | INT32_MAX, | ||
| 1345 | ] | ||
| 1346 | for val in test_values: | ||
| 1347 | with self.subTest(val=val): | ||
| 1348 | u_val = to_unsigned_u32(val) | ||
| 1349 | self.assertEqual(reference_atomic_max_i32(INT32_MIN, u_val), u_val) | ||
| 1350 | self.assertEqual(reference_atomic_max_i32(u_val, INT32_MIN), u_val) | ||
| 1351 | |||
| 1352 | # SPIR-V execution with INT32_MIN seed | ||
| 1353 | spvasm = """ | ||
| 1354 | OpCapability Shader | ||
| 1355 | OpMemoryModel Logical GLSL450 | ||
| 1356 | OpEntryPoint GLCompute %main "main" | ||
| 1357 | OpExecutionMode %main LocalSize 1 1 1 | ||
| 1358 | %uint = OpTypeInt 32 0 | ||
| 1359 | %c16 = OpConstant %uint 16 | ||
| 1360 | %c2 = OpConstant %uint 2 | ||
| 1361 | %c0 = OpConstant %uint 0 | ||
| 1362 | %c0_slot = OpConstant %uint 0 | ||
| 1363 | %lds_arr = OpTypeArray %uint %c16 | ||
| 1364 | %_ptr_WG_lds = OpTypePointer Workgroup %lds_arr | ||
| 1365 | %_ptr_WG_uint = OpTypePointer Workgroup %uint | ||
| 1366 | %lds = OpVariable %_ptr_WG_lds Workgroup | ||
| 1367 | %void = OpTypeVoid | ||
| 1368 | %fn = OpTypeFunction %void | ||
| 1369 | %main = OpFunction %void None %fn | ||
| 1370 | %entry = OpLabel | ||
| 1371 | %ptr = OpAccessChain %_ptr_WG_uint %lds %c0_slot | ||
| 1372 | %dummy = OpAtomicSMax %uint %ptr %c2 %c0 %v_data | ||
| 1373 | OpReturn | ||
| 1374 | OpFunctionEnd | ||
| 1375 | """ | ||
| 1376 | interp = LdsAtomicMaxI32Interp(spvasm) | ||
| 1377 | for val in test_values: | ||
| 1378 | u_val = to_unsigned_u32(val) | ||
| 1379 | final_lds, _ = interp.run(seed_lds={0: INT32_MIN}, lane_inputs=[{"%v_data": u_val}]) | ||
| 1380 | self.assertEqual(final_lds[0], u_val) | ||
| 1381 | |||
| 1382 | def test_int32_max_absorbing_element(self): | ||
| 1383 | # max(INT32_MAX, x) == INT32_MAX for all x | ||
| 1384 | test_values = [ | ||
| 1385 | INT32_MIN, | ||
| 1386 | INT32_MIN + 1, | ||
| 1387 | -500, | ||
| 1388 | -1, | ||
| 1389 | 0, | ||
| 1390 | 1, | ||
| 1391 | 10000, | ||
| 1392 | INT32_MAX - 1, | ||
| 1393 | INT32_MAX, | ||
| 1394 | ] | ||
| 1395 | for val in test_values: | ||
| 1396 | with self.subTest(val=val): | ||
| 1397 | u_val = to_unsigned_u32(val) | ||
| 1398 | self.assertEqual(reference_atomic_max_i32(INT32_MAX, u_val), INT32_MAX) | ||
| 1399 | self.assertEqual(reference_atomic_max_i32(u_val, INT32_MAX), INT32_MAX) | ||
| 1400 | |||
| 1401 | # SPIR-V execution with INT32_MAX seed | ||
| 1402 | spvasm = """ | ||
| 1403 | OpCapability Shader | ||
| 1404 | OpMemoryModel Logical GLSL450 | ||
| 1405 | OpEntryPoint GLCompute %main "main" | ||
| 1406 | OpExecutionMode %main LocalSize 1 1 1 | ||
| 1407 | %uint = OpTypeInt 32 0 | ||
| 1408 | %c16 = OpConstant %uint 16 | ||
| 1409 | %c2 = OpConstant %uint 2 | ||
| 1410 | %c0 = OpConstant %uint 0 | ||
| 1411 | %c0_slot = OpConstant %uint 0 | ||
| 1412 | %lds_arr = OpTypeArray %uint %c16 | ||
| 1413 | %_ptr_WG_lds = OpTypePointer Workgroup %lds_arr | ||
| 1414 | %_ptr_WG_uint = OpTypePointer Workgroup %uint | ||
| 1415 | %lds = OpVariable %_ptr_WG_lds Workgroup | ||
| 1416 | %void = OpTypeVoid | ||
| 1417 | %fn = OpTypeFunction %void | ||
| 1418 | %main = OpFunction %void None %fn | ||
| 1419 | %entry = OpLabel | ||
| 1420 | %ptr = OpAccessChain %_ptr_WG_uint %lds %c0_slot | ||
| 1421 | %dummy = OpAtomicSMax %uint %ptr %c2 %c0 %v_data | ||
| 1422 | OpReturn | ||
| 1423 | OpFunctionEnd | ||
| 1424 | """ | ||
| 1425 | interp = LdsAtomicMaxI32Interp(spvasm) | ||
| 1426 | for val in test_values: | ||
| 1427 | u_val = to_unsigned_u32(val) | ||
| 1428 | final_lds, _ = interp.run(seed_lds={0: INT32_MAX}, lane_inputs=[{"%v_data": u_val}]) | ||
| 1429 | self.assertEqual(final_lds[0], INT32_MAX) | ||
| 1430 | |||
| 1431 | def test_sign_bit_matrix_coverage(self): | ||
| 1432 | # Exhaustive sign combinations: (+, +), (+, -), (-, +), (-, -) | ||
| 1433 | sign_matrix = [ | ||
| 1434 | (10, 20, 20), # (+, +) | ||
| 1435 | (20, 10, 20), | ||
| 1436 | (15, -30, 15), # (+, -) | ||
| 1437 | (-30, 15, 15), # (-, +) | ||
| 1438 | (-50, -20, -20), # (-, -) | ||
| 1439 | (-20, -50, -20), | ||
| 1440 | (0x7FFFFFFF, 0x80000000, 0x7FFFFFFF), # sign bit 0 vs 1 | ||
| 1441 | (0x80000000, 0x7FFFFFFF, 0x7FFFFFFF), # sign bit 1 vs 0 | ||
| 1442 | ] | ||
| 1443 | for a, b, exp in sign_matrix: | ||
| 1444 | ua = to_unsigned_u32(a) | ||
| 1445 | ub = to_unsigned_u32(b) | ||
| 1446 | uexp = to_unsigned_u32(exp) | ||
| 1447 | self.assertEqual(reference_atomic_max_i32(ua, ub), uexp) | ||
| 1448 | |||
| 1449 | |||
| 1450 | class TestReturnValueRetention(unittest.TestCase): | ||
| 1451 | """Verifies that returning forms preserve prior values and non-returning forms do not clobber.""" | ||
| 1452 | |||
| 1453 | def test_returning_form_preserves_unmodified_old_value(self): | ||
| 1454 | spvasm = """ | ||
| 1455 | OpCapability Shader | ||
| 1456 | OpMemoryModel Logical GLSL450 | ||
| 1457 | OpEntryPoint GLCompute %main "main" %out | ||
| 1458 | OpExecutionMode %main LocalSize 1 1 1 | ||
| 1459 | %uint = OpTypeInt 32 0 | ||
| 1460 | %_ptr_Output_uint = OpTypePointer Output %uint | ||
| 1461 | %out = OpVariable %_ptr_Output_uint Output | ||
| 1462 | %c16 = OpConstant %uint 16 | ||
| 1463 | %c2 = OpConstant %uint 2 | ||
| 1464 | %c0 = OpConstant %uint 0 | ||
| 1465 | %c0_slot = OpConstant %uint 0 | ||
| 1466 | %lds_arr = OpTypeArray %uint %c16 | ||
| 1467 | %_ptr_WG_lds = OpTypePointer Workgroup %lds_arr | ||
| 1468 | %_ptr_WG_uint = OpTypePointer Workgroup %uint | ||
| 1469 | %lds = OpVariable %_ptr_WG_lds Workgroup | ||
| 1470 | %void = OpTypeVoid | ||
| 1471 | %fn = OpTypeFunction %void | ||
| 1472 | %main = OpFunction %void None %fn | ||
| 1473 | %entry = OpLabel | ||
| 1474 | %ptr = OpAccessChain %_ptr_WG_uint %lds %c0_slot | ||
| 1475 | %old = OpAtomicSMax %uint %ptr %c2 %c0 %v_data | ||
| 1476 | OpStore %out %old | ||
| 1477 | OpReturn | ||
| 1478 | OpFunctionEnd | ||
| 1479 | """ | ||
| 1480 | interp = LdsAtomicMaxI32Interp(spvasm) | ||
| 1481 | # Test 1: Memory updates from negative to positive | ||
| 1482 | final_lds, lane_out = interp.run(seed_lds={0: to_unsigned_u32(-40)}, lane_inputs=[{"%v_data": 70}]) | ||
| 1483 | self.assertEqual(lane_out[0]["%out"], to_unsigned_u32(-40)) | ||
| 1484 | self.assertEqual(final_lds[0], 70) | ||
| 1485 | |||
| 1486 | # Test 2: Memory stays same because input is smaller | ||
| 1487 | final_lds2, lane_out2 = interp.run(seed_lds={0: 70}, lane_inputs=[{"%v_data": to_unsigned_u32(-10)}]) | ||
| 1488 | self.assertEqual(lane_out2[0]["%out"], 70) | ||
| 1489 | self.assertEqual(final_lds2[0], 70) | ||
| 1490 | |||
| 1491 | # Test 3: Input is INT32_MIN, memory is INT32_MAX | ||
| 1492 | final_lds3, lane_out3 = interp.run(seed_lds={0: INT32_MAX}, lane_inputs=[{"%v_data": INT32_MIN}]) | ||
| 1493 | self.assertEqual(lane_out3[0]["%out"], INT32_MAX) | ||
| 1494 | self.assertEqual(final_lds3[0], INT32_MAX) | ||
| 1495 | |||
| 1496 | def test_multi_step_return_value_chain(self): | ||
| 1497 | # 5 sequential atomic operations chain through LDS[0] | ||
| 1498 | spvasm = """ | ||
| 1499 | OpCapability Shader | ||
| 1500 | OpMemoryModel Logical GLSL450 | ||
| 1501 | OpEntryPoint GLCompute %main "main" %out1 %out2 %out3 %out4 %out5 | ||
| 1502 | OpExecutionMode %main LocalSize 1 1 1 | ||
| 1503 | %uint = OpTypeInt 32 0 | ||
| 1504 | %_ptr_Output_uint = OpTypePointer Output %uint | ||
| 1505 | %out1 = OpVariable %_ptr_Output_uint Output | ||
| 1506 | %out2 = OpVariable %_ptr_Output_uint Output | ||
| 1507 | %out3 = OpVariable %_ptr_Output_uint Output | ||
| 1508 | %out4 = OpVariable %_ptr_Output_uint Output | ||
| 1509 | %out5 = OpVariable %_ptr_Output_uint Output | ||
| 1510 | %c16 = OpConstant %uint 16 | ||
| 1511 | %c2 = OpConstant %uint 2 | ||
| 1512 | %c0 = OpConstant %uint 0 | ||
| 1513 | %c0_slot = OpConstant %uint 0 | ||
| 1514 | %c_minus50 = OpConstant %uint 4294967246 | ||
| 1515 | %c_minus20 = OpConstant %uint 4294967276 | ||
| 1516 | %c_minus30 = OpConstant %uint 4294967266 | ||
| 1517 | %c_plus10 = OpConstant %uint 10 | ||
| 1518 | %c_plus5 = OpConstant %uint 5 | ||
| 1519 | %lds_arr = OpTypeArray %uint %c16 | ||
| 1520 | %_ptr_WG_lds = OpTypePointer Workgroup %lds_arr | ||
| 1521 | %_ptr_WG_uint = OpTypePointer Workgroup %uint | ||
| 1522 | %lds = OpVariable %_ptr_WG_lds Workgroup | ||
| 1523 | %void = OpTypeVoid | ||
| 1524 | %fn = OpTypeFunction %void | ||
| 1525 | %main = OpFunction %void None %fn | ||
| 1526 | %entry = OpLabel | ||
| 1527 | %ptr = OpAccessChain %_ptr_WG_uint %lds %c0_slot | ||
| 1528 | %r1 = OpAtomicSMax %uint %ptr %c2 %c0 %c_minus50 | ||
| 1529 | OpStore %out1 %r1 | ||
| 1530 | %r2 = OpAtomicSMax %uint %ptr %c2 %c0 %c_minus20 | ||
| 1531 | OpStore %out2 %r2 | ||
| 1532 | %r3 = OpAtomicSMax %uint %ptr %c2 %c0 %c_minus30 | ||
| 1533 | OpStore %out3 %r3 | ||
| 1534 | %r4 = OpAtomicSMax %uint %ptr %c2 %c0 %c_plus10 | ||
| 1535 | OpStore %out4 %r4 | ||
| 1536 | %r5 = OpAtomicSMax %uint %ptr %c2 %c0 %c_plus5 | ||
| 1537 | OpStore %out5 %r5 | ||
| 1538 | OpReturn | ||
| 1539 | OpFunctionEnd | ||
| 1540 | """ | ||
| 1541 | interp = LdsAtomicMaxI32Interp(spvasm) | ||
| 1542 | # Seed LDS[0] with -100 (0xFFFFFF9C) | ||
| 1543 | seed_val = to_unsigned_u32(-100) | ||
| 1544 | final_lds, lane_out = interp.run(seed_lds={0: seed_val}) | ||
| 1545 | |||
| 1546 | # Op 1: max(-100, -50) -> returns -100, memory becomes -50 | ||
| 1547 | self.assertEqual(to_signed_i32(lane_out[0]["%out1"]), -100) | ||
| 1548 | # Op 2: max(-50, -20) -> returns -50, memory becomes -20 | ||
| 1549 | self.assertEqual(to_signed_i32(lane_out[0]["%out2"]), -50) | ||
| 1550 | # Op 3: max(-20, -30) -> returns -20, memory remains -20 (-20 > -30) | ||
| 1551 | self.assertEqual(to_signed_i32(lane_out[0]["%out3"]), -20) | ||
| 1552 | # Op 4: max(-20, +10) -> returns -20, memory becomes +10 | ||
| 1553 | self.assertEqual(to_signed_i32(lane_out[0]["%out4"]), -20) | ||
| 1554 | # Op 5: max(+10, +5) -> returns +10, memory remains +10 (+10 > +5) | ||
| 1555 | self.assertEqual(to_signed_i32(lane_out[0]["%out5"]), 10) | ||
| 1556 | |||
| 1557 | # Final memory state | ||
| 1558 | self.assertEqual(final_lds[0], 10) | ||
| 1559 | |||
| 1560 | |||
| 1561 | class TestNegativeControlsAndErrors(unittest.TestCase): | ||
| 1562 | """Verifies that invalid constructs, unmodelled opcodes, and malformed headers fail.""" | ||
| 1563 | |||
| 1564 | def test_unsupported_storage_class_rejected(self): | ||
| 1565 | spvasm = """ | ||
| 1566 | OpCapability Shader | ||
| 1567 | OpMemoryModel Logical GLSL450 | ||
| 1568 | OpEntryPoint GLCompute %main "main" | ||
| 1569 | OpExecutionMode %main LocalSize 1 1 1 | ||
| 1570 | %uint = OpTypeInt 32 0 | ||
| 1571 | %_ptr_UC = OpTypePointer UniformConstant %uint | ||
| 1572 | %u = OpVariable %_ptr_UC UniformConstant | ||
| 1573 | %void = OpTypeVoid | ||
| 1574 | %fn = OpTypeFunction %void | ||
| 1575 | %main = OpFunction %void None %fn | ||
| 1576 | %entry = OpLabel | ||
| 1577 | OpReturn | ||
| 1578 | OpFunctionEnd | ||
| 1579 | """ | ||
| 1580 | with self.assertRaises(UnsupportedConstruct): | ||
| 1581 | LdsAtomicMaxI32Interp(spvasm) | ||
| 1582 | |||
| 1583 | def test_unsupported_opcode_rejected(self): | ||
| 1584 | spvasm = """ | ||
| 1585 | OpCapability Shader | ||
| 1586 | OpMemoryModel Logical GLSL450 | ||
| 1587 | OpEntryPoint GLCompute %main "main" | ||
| 1588 | OpExecutionMode %main LocalSize 1 1 1 | ||
| 1589 | %uint = OpTypeInt 32 0 | ||
| 1590 | %c16 = OpConstant %uint 16 | ||
| 1591 | %lds_arr = OpTypeArray %uint %c16 | ||
| 1592 | %_ptr_WG_lds = OpTypePointer Workgroup %lds_arr | ||
| 1593 | %lds = OpVariable %_ptr_WG_lds Workgroup | ||
| 1594 | %void = OpTypeVoid | ||
| 1595 | %fn = OpTypeFunction %void | ||
| 1596 | %main = OpFunction %void None %fn | ||
| 1597 | %entry = OpLabel | ||
| 1598 | %bad = OpSDiv %uint %c16 %c16 | ||
| 1599 | OpReturn | ||
| 1600 | OpFunctionEnd | ||
| 1601 | """ | ||
| 1602 | interp = LdsAtomicMaxI32Interp(spvasm) | ||
| 1603 | with self.assertRaises(UnsupportedConstruct): | ||
| 1604 | interp.run() | ||
| 1605 | |||
| 1606 | def test_invalid_workgroup_size_rejected(self): | ||
| 1607 | for dims in [(0, 1, 1), (1025, 1, 1), (32, 33, 1)]: | ||
| 1608 | with self.subTest(dims=dims): | ||
| 1609 | spvasm = f""" | ||
| 1610 | OpCapability Shader | ||
| 1611 | OpMemoryModel Logical GLSL450 | ||
| 1612 | OpEntryPoint GLCompute %main "main" | ||
| 1613 | OpExecutionMode %main LocalSize {dims[0]} {dims[1]} {dims[2]} | ||
| 1614 | %void = OpTypeVoid | ||
| 1615 | %fn = OpTypeFunction %void | ||
| 1616 | %main = OpFunction %void None %fn | ||
| 1617 | %entry = OpLabel | ||
| 1618 | OpReturn | ||
| 1619 | OpFunctionEnd | ||
| 1620 | """ | ||
| 1621 | with self.assertRaises(WorkgroupBoundsError): | ||
| 1622 | LdsAtomicMaxI32Interp(spvasm) | ||
| 1623 | |||
| 1624 | def test_atomic_on_non_lds_pointer_rejected(self): | ||
| 1625 | spvasm = """ | ||
| 1626 | OpCapability Shader | ||
| 1627 | OpMemoryModel Logical GLSL450 | ||
| 1628 | OpEntryPoint GLCompute %main "main" | ||
| 1629 | OpExecutionMode %main LocalSize 1 1 1 | ||
| 1630 | %uint = OpTypeInt 32 0 | ||
| 1631 | %_ptr_fn_uint = OpTypePointer Function %uint | ||
| 1632 | %c2 = OpConstant %uint 2 | ||
| 1633 | %c0 = OpConstant %uint 0 | ||
| 1634 | %c5 = OpConstant %uint 5 | ||
| 1635 | %void = OpTypeVoid | ||
| 1636 | %fn = OpTypeFunction %void | ||
| 1637 | %main = OpFunction %void None %fn | ||
| 1638 | %entry = OpLabel | ||
| 1639 | %local_v = OpVariable %_ptr_fn_uint Function | ||
| 1640 | %bad = OpAtomicSMax %uint %local_v %c2 %c0 %c5 | ||
| 1641 | OpReturn | ||
| 1642 | OpFunctionEnd | ||
| 1643 | """ | ||
| 1644 | interp = LdsAtomicMaxI32Interp(spvasm) | ||
| 1645 | with self.assertRaises(UnsupportedConstruct): | ||
| 1646 | interp.run() | ||
| 1647 | |||
| 1648 | def test_lds_access_out_of_bounds_rejected(self): | ||
| 1649 | spvasm = """ | ||
| 1650 | OpCapability Shader | ||
| 1651 | OpMemoryModel Logical GLSL450 | ||
| 1652 | OpEntryPoint GLCompute %main "main" | ||
| 1653 | OpExecutionMode %main LocalSize 1 1 1 | ||
| 1654 | %uint = OpTypeInt 32 0 | ||
| 1655 | %c16 = OpConstant %uint 16 | ||
| 1656 | %c2 = OpConstant %uint 2 | ||
| 1657 | %c0 = OpConstant %uint 0 | ||
| 1658 | %c999 = OpConstant %uint 999 | ||
| 1659 | %c5 = OpConstant %uint 5 | ||
| 1660 | %lds_arr = OpTypeArray %uint %c16 | ||
| 1661 | %_ptr_WG_lds = OpTypePointer Workgroup %lds_arr | ||
| 1662 | %_ptr_WG_uint = OpTypePointer Workgroup %uint | ||
| 1663 | %lds = OpVariable %_ptr_WG_lds Workgroup | ||
| 1664 | %void = OpTypeVoid | ||
| 1665 | %fn = OpTypeFunction %void | ||
| 1666 | %main = OpFunction %void None %fn | ||
| 1667 | %entry = OpLabel | ||
| 1668 | %ptr = OpAccessChain %_ptr_WG_uint %lds %c999 | ||
| 1669 | %bad = OpAtomicSMax %uint %ptr %c2 %c0 %c5 | ||
| 1670 | OpReturn | ||
| 1671 | OpFunctionEnd | ||
| 1672 | """ | ||
| 1673 | interp = LdsAtomicMaxI32Interp(spvasm) | ||
| 1674 | with self.assertRaises(WorkgroupBoundsError): | ||
| 1675 | interp.run() | ||
| 1676 | |||
| 1677 | def test_multiple_workgroup_variables_rejected(self): | ||
| 1678 | spvasm = """ | ||
| 1679 | OpCapability Shader | ||
| 1680 | OpMemoryModel Logical GLSL450 | ||
| 1681 | OpEntryPoint GLCompute %main "main" | ||
| 1682 | OpExecutionMode %main LocalSize 1 1 1 | ||
| 1683 | %uint = OpTypeInt 32 0 | ||
| 1684 | %c16 = OpConstant %uint 16 | ||
| 1685 | %lds_arr = OpTypeArray %uint %c16 | ||
| 1686 | %_ptr_WG_lds = OpTypePointer Workgroup %lds_arr | ||
| 1687 | %lds1 = OpVariable %_ptr_WG_lds Workgroup | ||
| 1688 | %lds2 = OpVariable %_ptr_WG_lds Workgroup | ||
| 1689 | %void = OpTypeVoid | ||
| 1690 | %fn = OpTypeFunction %void | ||
| 1691 | %main = OpFunction %void None %fn | ||
| 1692 | %entry = OpLabel | ||
| 1693 | OpReturn | ||
| 1694 | OpFunctionEnd | ||
| 1695 | """ | ||
| 1696 | with self.assertRaises(UnsupportedConstruct): | ||
| 1697 | LdsAtomicMaxI32Interp(spvasm) | ||
| 1698 | |||
| 1699 | def test_non_array_workgroup_variable_rejected(self): | ||
| 1700 | spvasm = """ | ||
| 1701 | OpCapability Shader | ||
| 1702 | OpMemoryModel Logical GLSL450 | ||
| 1703 | OpEntryPoint GLCompute %main "main" | ||
| 1704 | OpExecutionMode %main LocalSize 1 1 1 | ||
| 1705 | %uint = OpTypeInt 32 0 | ||
| 1706 | %_ptr_WG_uint = OpTypePointer Workgroup %uint | ||
| 1707 | %lds = OpVariable %_ptr_WG_uint Workgroup | ||
| 1708 | %void = OpTypeVoid | ||
| 1709 | %fn = OpTypeFunction %void | ||
| 1710 | %main = OpFunction %void None %fn | ||
| 1711 | %entry = OpLabel | ||
| 1712 | OpReturn | ||
| 1713 | OpFunctionEnd | ||
| 1714 | """ | ||
| 1715 | with self.assertRaises(UnsupportedConstruct): | ||
| 1716 | LdsAtomicMaxI32Interp(spvasm) | ||
| 1717 | |||
| 1718 | def test_non_32bit_int_rejected(self): | ||
| 1719 | spvasm = """ | ||
| 1720 | OpCapability Shader | ||
| 1721 | OpMemoryModel Logical GLSL450 | ||
| 1722 | OpEntryPoint GLCompute %main "main" | ||
| 1723 | OpExecutionMode %main LocalSize 1 1 1 | ||
| 1724 | %ulong = OpTypeInt 64 0 | ||
| 1725 | %void = OpTypeVoid | ||
| 1726 | %fn = OpTypeFunction %void | ||
| 1727 | %main = OpFunction %void None %fn | ||
| 1728 | %entry = OpLabel | ||
| 1729 | OpReturn | ||
| 1730 | OpFunctionEnd | ||
| 1731 | """ | ||
| 1732 | with self.assertRaises(UnsupportedConstruct): | ||
| 1733 | LdsAtomicMaxI32Interp(spvasm) | ||
| 1734 | |||
| 1735 | def test_variable_storage_class_mismatch_rejected(self): | ||
| 1736 | spvasm = """ | ||
| 1737 | OpCapability Shader | ||
| 1738 | OpMemoryModel Logical GLSL450 | ||
| 1739 | OpEntryPoint GLCompute %main "main" | ||
| 1740 | OpExecutionMode %main LocalSize 1 1 1 | ||
| 1741 | %uint = OpTypeInt 32 0 | ||
| 1742 | %_ptr_WG_uint = OpTypePointer Workgroup %uint | ||
| 1743 | %bad_var = OpVariable %_ptr_WG_uint Function | ||
| 1744 | %void = OpTypeVoid | ||
| 1745 | %fn = OpTypeFunction %void | ||
| 1746 | %main = OpFunction %void None %fn | ||
| 1747 | %entry = OpLabel | ||
| 1748 | OpReturn | ||
| 1749 | OpFunctionEnd | ||
| 1750 | """ | ||
| 1751 | with self.assertRaises(UnsupportedConstruct): | ||
| 1752 | LdsAtomicMaxI32Interp(spvasm) | ||
| 1753 | |||
| 1754 | def test_undefined_identifier_rejected(self): | ||
| 1755 | spvasm = """ | ||
| 1756 | OpCapability Shader | ||
| 1757 | OpMemoryModel Logical GLSL450 | ||
| 1758 | OpEntryPoint GLCompute %main "main" | ||
| 1759 | OpExecutionMode %main LocalSize 1 1 1 | ||
| 1760 | %uint = OpTypeInt 32 0 | ||
| 1761 | %c16 = OpConstant %uint 16 | ||
| 1762 | %c2 = OpConstant %uint 2 | ||
| 1763 | %c0 = OpConstant %uint 0 | ||
| 1764 | %c0_slot = OpConstant %uint 0 | ||
| 1765 | %lds_arr = OpTypeArray %uint %c16 | ||
| 1766 | %_ptr_WG_lds = OpTypePointer Workgroup %lds_arr | ||
| 1767 | %_ptr_WG_uint = OpTypePointer Workgroup %uint | ||
| 1768 | %lds = OpVariable %_ptr_WG_lds Workgroup | ||
| 1769 | %void = OpTypeVoid | ||
| 1770 | %fn = OpTypeFunction %void | ||
| 1771 | %main = OpFunction %void None %fn | ||
| 1772 | %entry = OpLabel | ||
| 1773 | %ptr = OpAccessChain %_ptr_WG_uint %lds %c0_slot | ||
| 1774 | %old = OpAtomicSMax %uint %ptr %c2 %c0 %undefined_val | ||
| 1775 | OpReturn | ||
| 1776 | OpFunctionEnd | ||
| 1777 | """ | ||
| 1778 | interp = LdsAtomicMaxI32Interp(spvasm) | ||
| 1779 | with self.assertRaises(UnsupportedConstruct): | ||
| 1780 | interp.run() | ||
| 1781 | |||
| 1782 | def test_unknown_branch_label_rejected(self): | ||
| 1783 | spvasm = """ | ||
| 1784 | OpCapability Shader | ||
| 1785 | OpMemoryModel Logical GLSL450 | ||
| 1786 | OpEntryPoint GLCompute %main "main" | ||
| 1787 | OpExecutionMode %main LocalSize 1 1 1 | ||
| 1788 | %void = OpTypeVoid | ||
| 1789 | %fn = OpTypeFunction %void | ||
| 1790 | %main = OpFunction %void None %fn | ||
| 1791 | %entry = OpLabel | ||
| 1792 | OpBranch %ghost_label | ||
| 1793 | OpReturn | ||
| 1794 | OpFunctionEnd | ||
| 1795 | """ | ||
| 1796 | interp = LdsAtomicMaxI32Interp(spvasm) | ||
| 1797 | with self.assertRaises(UnsupportedConstruct): | ||
| 1798 | interp.run() | ||
| 1799 | |||
| 1800 | |||
| 1306 | if __name__ == "__main__": | 1801 | if __name__ == "__main__": |
| 1307 | unittest.main() | 1802 | unittest.main() |