aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/compute/skc/platforms/cl_12/kernels/rasterize.cl
blob: e622845d9c4e6aa21127437e62f4c3eeea02bac1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
/*
 * Copyright 2017 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can
 * be found in the LICENSE file.
 *
 */

//
//
//

#include "tile.h"
#include "common.h"
#include "atomic_cl.h"
#include "block_pool_cl.h"
#include "raster_builder_cl_12.h"
#include "device_cl_12.h"

// #define SKC_ARCH_AVX2
// #define SKC_RASTERIZE_SIMD_USES_SMEM

#define PRINTF_ENABLE       0
#define PRINTF_BLOCK_COUNT  0

//
// NOTE:
//
// ON SIMD DEVICES THE BIN COUNT MUST BE POW2 SO THAT WE CAN LOAD IT
// AS A VECTOR AND PERFORM A SWIZZLE/SHUFFLE
//
// NOTE:
//
// IGNORE FOR NOW ANY AVX2 CODE SNIPPETS.  THEY WILL BE MOVED ASAP.
//
//

#if 0 // SKC_ARCH_AVX2

// #define SKC_RASTERIZE_SUBGROUP_SIZE              1
// #define SKC_RASTERIZE_VECTOR_SIZE_LOG2           3
// #define SKC_RASTERIZE_WORKGROUP_COUNT_SUBGROUP   1

// #define SKC_TTXB_WORDS                           8

// #define SKC_RASTERIZE_FLOAT                      float8
// #define SKC_RASTERIZE_UINT                       uint8
// #define SKC_RASTERIZE_INT                        int8
// #define SKC_RASTERIZE_PREDICATE                  int8

// #define SKC_RASTERIZE_BIN_BLOCK                  uint16
// #define SKC_RASTERIZE_BIN                        uint8

// #define SKC_RASTERIZE_POOL                       uint8
// #define SKC_RASTERIZE_POOL_SCALE                 6

// #define SKC_RASTERIZE_TILE_HASH_X_BITS           1
// #define SKC_RASTERIZE_TILE_HASH_Y_BITS           2

// #define SKC_RASTERIZE_VECTOR_EXPAND()            SKC_EXPAND_8()

#endif

//
// SIMT
//

#define SKC_RASTERIZE_BLOCK_ID_V_SIZE        SKC_RASTERIZE_SUBGROUP_SIZE
#define SKC_RASTERIZE_TTSK_V_SIZE            SKC_RASTERIZE_SUBGROUP_SIZE
#define SKC_RASTERIZE_TTSK_V_MASK            (SKC_RASTERIZE_TTSK_V_SIZE - 1)

//
//
//

#define SKC_RASTERIZE_VECTOR_SIZE            (1 << SKC_RASTERIZE_VECTOR_SIZE_LOG2)
#define SKC_RASTERIZE_ELEMS_PER_SUBGROUP     (SKC_RASTERIZE_SUBGROUP_SIZE * SKC_RASTERIZE_VECTOR_SIZE)

//
//
//

#define SKC_RASTERIZE_YX_INIT                0x7FFF7FFF  // { +32767, +32767 }
#define SKC_RASTERIZE_YX_INVALID             0x80008000  // { -32768, -32768 }

//
//
//

#define SKC_RASTERIZE_TILE_HASH_X_MASK       SKC_BITS_TO_MASK(SKC_RASTERIZE_TILE_HASH_X_BITS)
#define SKC_RASTERIZE_TILE_HASH_Y_MASK       SKC_BITS_TO_MASK(SKC_RASTERIZE_TILE_HASH_Y_BITS)
#define SKC_RASTERIZE_TILE_HASH_BITS         (SKC_RASTERIZE_TILE_HASH_X_BITS + SKC_RASTERIZE_TILE_HASH_Y_BITS)
#define SKC_RASTERIZE_TILE_HASH_BIN_COUNT    (1 << SKC_RASTERIZE_TILE_HASH_BITS)
#define SKC_RASTERIZE_TILE_HASH_BIN_BITS     (SKC_RASTERIZE_TILE_HASH_BITS + 1) // FIXME -- LOG2_RU(BIN_COUNT)
#define SKC_RASTERIZE_TILE_HASH_BIN_MASK     SKC_BITS_TO_MASK(SKC_RASTERIZE_TILE_HASH_BIN_BITS)

//
// Norbert Juffa notes: "GPU Pro Tip: Lerp Faster in C++"
//
// https://devblogs.nvidia.com/parallelforall/lerp-faster-cuda/
//
// Lerp in two fma/mad ops:
//
//    t * b + ((-t) * a + a)
//
// Note: OpenCL documents mix() as being implemented as:
//
//    a + (b - a) * t
//
// But this may be a native instruction on some devices. For example,
// on GEN9 there is an LRP "linear interoplation" opcode but it
// doesn't appear to support half floats.
//
// Feel free to toggle this option and then benchmark and inspect the
// generated code.  We really want the double FMA to be generated when
// there isn't support for a LERP/MIX operation.
//

#if 1
#define SKC_LERP(a,b,t)      mad(t,b,mad(-(t),a,a))
#else
#define SKC_LERP(a,b,t)      mix(a,b,t)
#endif

//
// There is no integer MAD in OpenCL with "don't care" overflow
// semantics.
//
// FIXME -- verify if the platform needs explicit MAD operations even
// if a "--fastmath" option is available at compile time.  It might
// make sense to explicitly use MAD calls if the platform requires it.
//

#if 1
#define SKC_MAD_UINT(a,b,c)  ((a) * (b) + (c))
#else
#define SKC_MAD_UINT(a,b,c)  mad_sat(a,b,c)
#endif

//
//
//

#define SKC_RASTERIZE_SEGMENT(id) (id * SKC_DEVICE_SUBBLOCK_WORDS + skc_subgroup_lane())

//
//
//

union skc_bp_elem
{
  skc_uint              u32;
  skc_tagged_block_id_t tag_id;
  skc_float             coord;
};

//
//
//

struct skc_subgroup_smem
{
  //
  // SIMT subgroup scratchpad for max scan -- also shared with 'winner' member
  //
#if ( SKC_RASTERIZE_SUBGROUP_SIZE > 1 ) || defined ( SKC_RASTERIZE_SIMD_USES_SMEM )
  struct {
    union {

      skc_uint                winner;

      struct {
        skc_uint              scratch[SKC_RASTERIZE_SUBGROUP_SIZE];
      } aN;

      struct {
        SKC_RASTERIZE_UINT    scratch[SKC_RASTERIZE_SUBGROUP_SIZE];
      } vN;
    };
  } subgroup;
#endif

  //
  // work-in-progress TTSB blocks and associated YX keys
  //
  union {
    struct {
      // FIXME -- some typedefs are valid here
      skc_uint                ttsb [SKC_RASTERIZE_TILE_HASH_BIN_COUNT][SKC_DEVICE_SUBBLOCK_WORDS];
      skc_uint                yx   [SKC_RASTERIZE_TILE_HASH_BIN_COUNT];
      skc_uint                id   [SKC_RASTERIZE_TILE_HASH_BIN_COUNT];
      skc_uint                count[SKC_RASTERIZE_TILE_HASH_BIN_COUNT];
    } aN;
#if ( SKC_RASTERIZE_SUBGROUP_SIZE == 1 )
    struct {
      SKC_RASTERIZE_BIN_BLOCK ttsb[SKC_RASTERIZE_TILE_HASH_BIN_COUNT];
      SKC_RASTERIZE_BIN       yx;
      SKC_RASTERIZE_BIN       id;
      SKC_RASTERIZE_BIN       count;
    } vN;
#endif
  } bin;
};

//
//
//

#if ( SKC_RASTERIZE_SUBGROUP_SIZE == 1 )
#define skc_subgroup_lane()  0
#else
#define skc_subgroup_lane()  get_sub_group_local_id()
#endif

//
// replenish block ids
//
// note that you can't overrun the block id pool since it's a ring
//

static
void
skc_blocks_replenish(skc_uint                           * const blocks_next,
                     skc_block_id_v_t                   * const blocks,
                     __global SKC_ATOMIC_UINT  volatile * const bp_atomics,
                     skc_uint                             const bp_mask, // pow2 modulo mask for block pool ring
                     __global skc_block_id_t   const    * const bp_ids)
{
  //
  // get a new vector of block ids -- this is kind of a narrow
  // allocation but subblocks help stretch out the pool.
  //
  // FIXME -- there is now plenty of SMEM to allocate a LOT of block ids
  //
  skc_uint bp_idx = 0;

  if (skc_subgroup_lane() == 0)
    {
      bp_idx = SKC_ATOMIC_ADD_GLOBAL_RELAXED_DEVICE(bp_atomics+SKC_BP_ATOMIC_OFFSET_READS,
                                                    SKC_RASTERIZE_BLOCK_ID_V_SIZE); // ring_reads
#if 0
      printf("r+: %8u + %u\n",bp_idx,SKC_RASTERIZE_BLOCK_ID_V_SIZE);
#endif
    }

  bp_idx       = (sub_group_broadcast(bp_idx,0) + skc_subgroup_lane()) & bp_mask;
  *blocks      = bp_ids[bp_idx];
  *blocks_next = 0;
}

//
//
//

static
skc_block_id_t
skc_blocks_get_next(skc_uint                           * const blocks_next,
                    skc_block_id_v_t                   * const blocks,
                    __global SKC_ATOMIC_UINT  volatile * const bp_atomics,
                    skc_uint                             const bp_mask, // pow2 modulo mask for block pool ring
                    __global skc_block_id_t   const    * const bp_ids)
{
  // replenish?
  if (*blocks_next == SKC_RASTERIZE_BLOCK_ID_V_SIZE)
    {
      skc_blocks_replenish(blocks_next,blocks,bp_atomics,bp_mask,bp_ids);
    }

#if ( SKC_RASTERIZE_SUBGROUP_SIZE > 1 )
  //
  // SIMT
  //
  skc_block_id_t id = sub_group_broadcast(*blocks,*blocks_next);

#else
  //
  // SIMD
  //
  skc_block_id_t id = blocks->s0;

  skc_shuffle_down_1(*blocks);

#endif

  *blocks_next += 1;

  return id;
}

//
// subblock allocator
//

#if SKC_DEVICE_BLOCK_WORDS_LOG2 > SKC_DEVICE_SUBBLOCK_WORDS_LOG2

static
skc_block_id_t
skc_subblocks_get_next(skc_block_id_t                     * const subblocks,
                       skc_uint                           * const blocks_next,
                       skc_block_id_v_t                   * const blocks,
                       __global SKC_ATOMIC_UINT  volatile * const bp_atomics,
                       skc_uint                             const bp_mask, // pow2 modulo mask for block pool ring
                       __global skc_block_id_t   const    * const bp_ids)
{
  if ((*subblocks & SKC_DEVICE_SUBBLOCKS_PER_BLOCK_MASK) == 0)
    {
      *subblocks = skc_blocks_get_next(blocks_next,blocks,bp_atomics,bp_mask,bp_ids);
    }

  skc_block_id_t const sb_id = *subblocks;

  *subblocks += 1;

#if 0
  if (get_sub_group_local_id() == 0)
    printf("= %u\n",sb_id);
#endif

  return sb_id;
}


#define SKC_SUBBLOCKS_BLOCKS_PROTO() skc_block_id_t * const subblocks, skc_block_id_t * const blocks
#define SKC_SUBBLOCKS_BLOCKS_ARGS()  subblocks, blocks

#else

#define SKC_SUBBLOCKS_BLOCKS_PROTO() skc_block_id_t * const blocks
#define SKC_SUBBLOCKS_BLOCKS_ARGS()  blocks

#endif

//
//
//

static
skc_block_id_t
skc_ttsk_v_append(SKC_SUBBLOCKS_BLOCKS_PROTO(),
                  skc_uint                           * const blocks_next,
                  __global SKC_ATOMIC_UINT  volatile * const bp_atomics,
                  skc_uint                             const bp_mask, // pow2 modulo mask for block pool ring
                  __global skc_block_id_t   const    * const bp_ids,
                  __global SKC_ATOMIC_UINT  volatile * const cohort_atomics,
                  skc_ttsk_v_t                       * const sk_v,
                  skc_uint                           * const sk_v_next,
                  __global skc_ttsk_s_t              * const sk_extent,
                  skc_uint                             const new_yx)
{
#if SKC_DEVICE_BLOCK_WORDS_LOG2 > SKC_DEVICE_SUBBLOCK_WORDS_LOG2
  skc_block_id_t const new_id = skc_subblocks_get_next(subblocks,
                                                       blocks_next,
                                                       blocks,
                                                       bp_atomics,
                                                       bp_mask,
                                                       bp_ids);
#else
  skc_block_id_t const new_id = skc_blocks_get_next(blocks_next,
                                                    blocks,
                                                    bp_atomics,
                                                    bp_mask, // pow2 modulo mask for block pool ring
                                                    bp_ids);
#endif

  if (get_sub_group_local_id() == (*sk_v_next & SKC_RASTERIZE_TTSK_V_MASK))
    {
      sk_v->lo = new_id;
      sk_v->hi = (sk_v->hi & SKC_TTRK_HI_MASK_COHORT) | new_yx;
#if 0
      printf("@ ( %3u, %3u ) %u\n",
             (new_yx >> 12) & 0xFFF,
             (new_yx      ) & 0xFFF,
             new_id);
#endif
    }

  *sk_v_next += 1;

  if (*sk_v_next == SKC_RASTERIZE_TTSK_V_SIZE)
    {
      *sk_v_next = 0;

      skc_uint sk_idx = 0;

      if (skc_subgroup_lane() == 0)
        {
          sk_idx = SKC_ATOMIC_ADD_GLOBAL_RELAXED_DEVICE
            (cohort_atomics+SKC_RASTER_COHORT_ATOMIC_OFFSET_KEYS,SKC_RASTERIZE_TTSK_V_SIZE);
#if 0
          printf("+ %u\n",sk_idx);
#endif
        }

      sk_idx = sub_group_broadcast(sk_idx,0) + skc_subgroup_lane();

#if ( SKC_RASTERIZE_SUBGROUP_SIZE > SKC_RASTERIZE_TTSK_V_SIZE )
      if (skc_subgroup_lane() < SKC_RASTERIZE_TTSK_V_SIZE)
#endif
        {
          sk_extent[sk_idx] = *sk_v;
#if 0
          printf("> %u : %v2u\n",sk_idx,*sk_v);
#endif
        }
    }

  return new_id;
}

//
//
//

static
SKC_RASTERIZE_FLOAT
skc_subgroup_scan_inclusive_add_float(SKC_RASTERIZE_FLOAT const v)
{
#if ( SKC_RASTERIZE_SUBGROUP_SIZE == 1 )
  //
  // SIMD
  //
  // Note that there isn't a built-in horizontal scan for vectors so
  // we'll define some here for various widths.
  //
  // FIXME -- a scalar version might be faster so put in a
  // compile-time switch to selection between implementations
  //

#if   ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 0 )
  return v;

#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 1 )
  // 01
  //  0 +
  // --
  // 01
  SKC_RASTERIZE_FLOAT const w = mad(v.s10,(SKC_RASTERIZE_FLOAT)(0,1),v);
  return w;

#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 2 )
  // 0123
  //  012 +
  // ----
  // 0123
  //   01 +
  // ----
  // 0123
  //
  SKC_RASTERIZE_FLOAT const w = mad(v.s3012,(SKC_RASTERIZE_FLOAT)(0,1,1,1),v);
  SKC_RASTERIZE_FLOAT const x = mad(w.s2301,(SKC_RASTERIZE_FLOAT)(0,0,1,1),w);
  return x;

#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 3 )
  // 01234567
  //  0123456 +
  // --------
  // 01234567
  //   012345 +
  // --------
  // 01234567
  //     0123 +
  // --------
  // 01234567
  //
  SKC_RASTERIZE_FLOAT const w = mad(v.s70123456,(SKC_RASTERIZE_FLOAT)(0,1,1,1,1,1,1,1),v);
  SKC_RASTERIZE_FLOAT const x = mad(w.s67012345,(SKC_RASTERIZE_FLOAT)(0,0,1,1,1,1,1,1),w);
  SKC_RASTERIZE_FLOAT const y = mad(x.s45670123,(SKC_RASTERIZE_FLOAT)(0,0,0,0,1,1,1,1),x);
  return y;

#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 4 )
  // 0123456789abcdef
  //  0123456789abcde +
  // ----------------
  // 0123456789abcdef
  //   0123456789abcd +
  // ----------------
  // 0123456789abcdef
  //     0123456789ab +
  // ----------------
  // 0123456789abcdef
  //         01234567 +
  // ----------------
  // 0123456789abcdef
  //
  SKC_RASTERIZE_FLOAT const w = mad(v.sf0123456789abcde,(SKC_RASTERIZE_FLOAT)(0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),v);
  SKC_RASTERIZE_FLOAT const x = mad(w.sef0123456789abcd,(SKC_RASTERIZE_FLOAT)(0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1),w);
  SKC_RASTERIZE_FLOAT const y = mad(x.scdef0123456789ab,(SKC_RASTERIZE_FLOAT)(0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1),x);
  SKC_RASTERIZE_FLOAT const z = mad(y.s89abcdef01234567,(SKC_RASTERIZE_FLOAT)(0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1),y);
  return z;

#endif

#else
  //
  // SIMT
  //

  return sub_group_scan_inclusive_add(v);

#endif
}

//
//
//

static
SKC_RASTERIZE_UINT
skc_subgroup_scan_inclusive_add_uint(SKC_RASTERIZE_UINT const v)
{
#if ( SKC_RASTERIZE_SUBGROUP_SIZE == 1 )
  //
  // SIMD
  //
  // Note that there isn't a built-in horizontal scan for vectors so
  // we'll define some here for various widths.
  //
  // FIXME -- a scalar version might be faster so put in a
  // compile-time switch to selection between implementations
  //

#if   ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 0 )
  return v;

#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 1 )
  // 01
  //  0 +
  // --
  // 01
  SKC_RASTERIZE_UINT const w = SKC_MAD_UINT(v.s10,(SKC_RASTERIZE_UINT)(0,1),v);
  return w;

#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 2 )
  // 0123
  //  012 +
  // ----
  // 0123
  //   01 +
  // ----
  // 0123
  //
  SKC_RASTERIZE_UINT const w = SKC_MAD_UINT(v.s3012,(SKC_RASTERIZE_UINT)(0,1,1,1),v);
  SKC_RASTERIZE_UINT const x = SKC_MAD_UINT(w.s2301,(SKC_RASTERIZE_UINT)(0,0,1,1),w);
  return x;

#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 3 )
  // 01234567
  //  0123456 +
  // --------
  // 01234567
  //   012345 +
  // --------
  // 01234567
  //     0123 +
  // --------
  // 01234567
  //
  SKC_RASTERIZE_UINT const w = SKC_MAD_UINT(v.s70123456,(SKC_RASTERIZE_UINT)(0,1,1,1,1,1,1,1),v);
  SKC_RASTERIZE_UINT const x = SKC_MAD_UINT(w.s67012345,(SKC_RASTERIZE_UINT)(0,0,1,1,1,1,1,1),w);
  SKC_RASTERIZE_UINT const y = SKC_MAD_UINT(x.s45670123,(SKC_RASTERIZE_UINT)(0,0,0,0,1,1,1,1),x);
  return y;

#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 4 )
  // 0123456789abcdef
  //  0123456789abcde +
  // ----------------
  // 0123456789abcdef
  //   0123456789abcd +
  // ----------------
  // 0123456789abcdef
  //     0123456789ab +
  // ----------------
  // 0123456789abcdef
  //         01234567 +
  // ----------------
  // 0123456789abcdef
  //
  SKC_RASTERIZE_UINT const w = SKC_MAD_UINT(v.sf0123456789abcde,(SKC_RASTERIZE_UINT)(0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),v);
  SKC_RASTERIZE_UINT const x = SKC_MAD_UINT(w.sef0123456789abcd,(SKC_RASTERIZE_UINT)(0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1),w);
  SKC_RASTERIZE_UINT const y = SKC_MAD_UINT(x.scdef0123456789ab,(SKC_RASTERIZE_UINT)(0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1),x);
  SKC_RASTERIZE_UINT const z = SKC_MAD_UINT(y.s89abcdef01234567,(SKC_RASTERIZE_UINT)(0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1),y);
  return z;

#endif

#else
  //
  // SIMT
  //

  return sub_group_scan_inclusive_add(v);

#endif
}

//
//
//

static
SKC_RASTERIZE_UINT
skc_subgroup_scan_inclusive_max(SKC_RASTERIZE_UINT const v)
{
#if ( SKC_RASTERIZE_SUBGROUP_SIZE == 1 )
  //
  // SIMD
  //
  // Note that there isn't a built-in horizontal scan for vectors so
  // we'll define some here for various widths.
  //
  // FIXME -- a scalar version might be faster so put in a
  // compile-time switch to selection between implementations
  //

#if   ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 0 )
  return v;

#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 1 )
  // 01
  // 00 max
  // --
  // 01
  SKC_RASTERIZE_UINT const w = max(v.s00,v);
  return w;

#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 2 )
  // 0123
  // 0012 +
  // ----
  // 0123
  // 0101 +
  // ----
  // 0123
  //
  SKC_RASTERIZE_UINT const w = max(v.s0012,v);
  SKC_RASTERIZE_UINT const x = max(w.s0101,w);
  return x;

#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 3 )
  // 01234567
  // 00123456 +
  // --------
  // 01234567
  // 01012345 +
  // --------
  // 01234567
  // 01230123 +
  // --------
  // 01234567
  //
  SKC_RASTERIZE_UINT const w = max(v.s00123456,v);
  SKC_RASTERIZE_UINT const x = max(w.s01012345,w);
  SKC_RASTERIZE_UINT const y = max(x.s01230123,x);
  return y;

#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 4 )
  // 0123456789abcdef
  // 00123456789abcde +
  // ----------------
  // 0123456789abcdef
  // 010123456789abcd +
  // ----------------
  // 0123456789abcdef
  // 01230123456789ab +
  // ----------------
  // 0123456789abcdef
  // 0123456701234567 +
  // ----------------
  // 0123456789abcdef
  //
  SKC_RASTERIZE_UINT const w = max(v.s00123456789abcde,v);
  SKC_RASTERIZE_UINT const x = max(w.s010123456789abcd,w);
  SKC_RASTERIZE_UINT const y = max(x.s01230123456789ab,x);
  SKC_RASTERIZE_UINT const z = max(y.s0123456701234567,y);
  return z;

#endif

#else
  //
  // SIMT
  //

  return sub_group_scan_inclusive_max(v);

#endif
}

//
//
//

static
float
skc_subgroup_last_float(SKC_RASTERIZE_FLOAT const v)
{
#if ( SKC_RASTERIZE_SUBGROUP_SIZE == 1 )
  //
  // SIMD
  //
#if   ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 0 )
  return v;
#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 1 )
  return v.s1;
#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 2 )
  return v.s3;
#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 3 )
  return v.s7;
#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 4 )
  return v.sf;
#endif

#else
  //
  // SIMT
  //
  return sub_group_broadcast(v,SKC_RASTERIZE_SUBGROUP_SIZE-1);

#endif
}

//
//
//

static
SKC_RASTERIZE_UINT
skc_subgroup_last_uint(SKC_RASTERIZE_UINT const v)
{
#if ( SKC_RASTERIZE_SUBGROUP_SIZE == 1 )
  //
  // SIMD
  //
#if   ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 0 )
  return v;
#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 1 )
  return v.s1;
#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 2 )
  return v.s3;
#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 3 )
  return v.s7;
#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 4 )
  return v.sf;
#endif

#else
  //
  // SIMT
  //
  return sub_group_broadcast(v,SKC_RASTERIZE_SUBGROUP_SIZE-1);

#endif
}

//
//
//

static
float
skc_subgroup_first(SKC_RASTERIZE_FLOAT const v)
{
#if ( SKC_RASTERIZE_SUBGROUP_SIZE == 1 )
  //
  // SIMD
  //
#if   ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 0 )
  return v;
#else
  return v.s0;
#endif

#else
  //
  // SIMT
  //
  return sub_group_broadcast(v,0);

#endif
}

//
//
//

static
SKC_RASTERIZE_FLOAT
skc_subgroup_shuffle(SKC_RASTERIZE_FLOAT const v,
                      SKC_RASTERIZE_UINT  const i)
{
#if ( SKC_RASTERIZE_SUBGROUP_SIZE == 1 )
  //
  // SIMD
  //
#if   ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 0 )
  return v;
#else
  return shuffle(v,i);
#endif

#else
  //
  // SIMT
  //
  return intel_sub_group_shuffle(v,i);

#endif
}

//
//
//

static
SKC_RASTERIZE_FLOAT
skc_subgroup_shuffle_up_1(SKC_RASTERIZE_FLOAT const p, // previous
                          SKC_RASTERIZE_FLOAT const c) // current
{
#if ( SKC_RASTERIZE_SUBGROUP_SIZE == 1 )
  //
  // SIMD
  //
  // FIXME -- there are alternative formulations here:
  //
  // Option 1:
  //
  //   select(c.rotate(+1),p.rotate(-1),(1,0,0,...))
  //
  // Option 2:
  //
  //   p is a scalar
  //   t    = c.rotate(+1)
  //   t.s0 = p;
  //
  // Option 3: ...
  //
#if   ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 0 )
  return p;
#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 1 )
  return shuffle2(p,c,(uint2)(1,2));
#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 2 )
  return shuffle2(p,c,(uint4)(3,4,5,6));
#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 3 )
  return shuffle2(p,c,(uint8)(7,8,9,10,11,12,13,14));
#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 4 )
  return shuffle2(p,c,(uint16)(15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30));
#endif

#else
  //
  // SIMT
  //
  return intel_sub_group_shuffle_up(p,c,1);

#endif
}

//
//
//

static
bool
skc_is_lane_first()
{
#if ( SKC_RASTERIZE_SUBGROUP_SIZE == 1)
  //
  // SIMD
  //
  return true;
#else
  //
  // SIMT
  //
  return get_sub_group_local_id() == 0;
#endif
}

//
//
//

static
SKC_RASTERIZE_FLOAT
skc_delta_offset()
{
#if ( SKC_RASTERIZE_SUBGROUP_SIZE == 1 )
  //
  // SIMD
  //
#if   ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 0 )
  return 1;
#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 1 )
  return (SKC_RASTERIZE_FLOAT)( 1, 2 );
#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 2 )
  return (SKC_RASTERIZE_FLOAT)( 1, 2, 3, 4 );
#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 3 )
  return (SKC_RASTERIZE_FLOAT)( 1, 2, 3, 4, 5, 6, 7, 8 );
#elif ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 4 )
  return (SKC_RASTERIZE_FLOAT)( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
#endif

#else
  //
  // SIMT
  //
  return 1.0f + get_sub_group_local_id();

#endif

}

//
//
//

static
int
skc_subgroup_any(SKC_RASTERIZE_PREDICATE const p)
{
#if ( SKC_RASTERIZE_SUBGROUP_SIZE == 1 )
  //
  // SIMD
  //
  return any(p);
#else
  //
  // SIMT
  //
  return sub_group_any(p);
#endif
}

//
//
//

#define SKC_PATH_NODEWORD_IS_LAST(n)  (((n) & SKC_DEVICE_BLOCK_WORDS_MASK) == SKC_DEVICE_BLOCK_WORDS_MASK)

void
skc_segment_next(__global union skc_bp_elem * const bp_elems,
                 skc_uint                   * const nodeword,
                 skc_block_id_t             * const id)
{
  if ((++*id & SKC_DEVICE_SUBBLOCKS_PER_BLOCK_MASK) == 0)
    {
      if (SKC_PATH_NODEWORD_IS_LAST(++*nodeword))
        {
          *nodeword = SKC_TAGGED_BLOCK_ID_GET_ID(bp_elems[*nodeword].tag_id) * SKC_DEVICE_SUBBLOCK_WORDS;
        }

      skc_tagged_block_id_t const tag_id = bp_elems[*nodeword].tag_id;

      *id = SKC_TAGGED_BLOCK_ID_GET_ID(tag_id);
    }
}

//
//
//

static
SKC_RASTERIZE_FLOAT
skc_native_length(SKC_RASTERIZE_FLOAT const x, SKC_RASTERIZE_FLOAT const y)
{
  return native_sqrt(x * x + y * y);
}

//
// Wang's Formula (1985)
//

#define SKC_WANG_PIXEL_RESL   0.25f // <-- this can be tuned

#define SKC_WANG_EPSILON      (SKC_WANG_PIXEL_RESL * SKC_SUBPIXEL_RESL_X_F32)

#define SKC_WANG_CUBIC        ((3.0f * 2.0f) / (8.0f * SKC_WANG_EPSILON))
#define SKC_WANG_QUADRATIC    ((2.0f       ) / (8.0f * SKC_WANG_EPSILON))

#define SKC_WANG_LENGTH(x,y)  skc_native_length(x,y)
#define SKC_WANG_SQRT(x)      native_sqrt(x)

//
//
//

static
SKC_RASTERIZE_FLOAT
skc_wangs_formula_cubic(SKC_RASTERIZE_FLOAT const t0x, SKC_RASTERIZE_FLOAT const t0y,
                        SKC_RASTERIZE_FLOAT const t1x, SKC_RASTERIZE_FLOAT const t1y,
                        SKC_RASTERIZE_FLOAT const t2x, SKC_RASTERIZE_FLOAT const t2y,
                        SKC_RASTERIZE_FLOAT const t3x, SKC_RASTERIZE_FLOAT const t3y)
{
  //
  // Return the number of evenly spaced (in the parametric sense) line
  // segments that are guaranteed to be within "epsilon" error of the
  // curve.
  //
  // We're then going to take multiples of the reciprocal of this
  // number so that the segmentation can be distributed across the
  // subgroup.
  //
  // Note, this can probably be slightly optimized per architecture
  // but it's probably far from being a hotspot since it's all
  // straight-line unpredicated code.
  //
  // The result is an integer ranging from [1.0,#segments]
  //
  // Note that even if all of the control points are coincident, the
  // max(1.0f) will categorize this as a line of 1 segment.
  //
  // This is what we want!  We want to convert cubics to lines as
  // easily as possible and *then* cull lines that are either
  // horizontal or zero length.
  //
  return max(1.0f,
             ceil(SKC_WANG_SQRT(SKC_WANG_CUBIC *
                                SKC_WANG_LENGTH(max(fabs(t2x - 2.0f * t1x + t0x),
                                                    fabs(t3x - 2.0f * t2x + t1x)),
                                                max(fabs(t2y - 2.0f * t1y + t0y),
                                                    fabs(t3y - 2.0f * t2y + t1y))))));
}

static
SKC_RASTERIZE_FLOAT
skc_wangs_formula_quadratic(SKC_RASTERIZE_FLOAT const t0x, SKC_RASTERIZE_FLOAT const t0y,
                            SKC_RASTERIZE_FLOAT const t1x, SKC_RASTERIZE_FLOAT const t1y,
                            SKC_RASTERIZE_FLOAT const t2x, SKC_RASTERIZE_FLOAT const t2y)
{
  return max(1.0f,
             ceil(SKC_WANG_SQRT(SKC_WANG_QUADRATIC *
                                SKC_WANG_LENGTH(fabs(t2x - 2.0f * t1x + t0x),
                                                fabs(t2y - 2.0f * t1y + t0y)))));
}

//
// rational curves
//

static
SKC_RASTERIZE_FLOAT
skc_wangs_formula_cubic_rat()
{
  return 0.0f;
}

static
SKC_RASTERIZE_FLOAT
skc_wangs_formula_quad_rat()
{
  return 0.0f;
}

//
// flush any work-in-progress blocks and return unused block ids
//

static
void
skc_finalize(__global SKC_ATOMIC_UINT          volatile * const bp_atomics,
             __global union skc_bp_elem                 * const bp_elems,
             __global uint                              * const bp_ids,
             skc_uint                                     const bp_mask,
             __global SKC_ATOMIC_UINT          volatile * const cohort_atomics,
             skc_block_id_v_t                           * const blocks,
             skc_uint                                     const blocks_next,
             skc_ttsk_v_t                               * const sk_v,
             skc_uint                                     const sk_v_next,
             __global skc_ttsk_s_t                      * const sk_extent,
             __local  struct skc_subgroup_smem volatile * const smem)
{
  //
  // flush non-empty bins
  //
  // FIXME -- accelerate this iteration/search with a subgroup operation
  //
  for (skc_uint ii=0; ii<SKC_RASTERIZE_TILE_HASH_BIN_COUNT; ii++)
    {
      if (smem->bin.aN.count[ii] > 0)
        {
          skc_block_id_v_t const id  = smem->bin.aN.id[ii];
          skc_uint         const idx = id * SKC_DEVICE_SUBBLOCK_WORDS + skc_subgroup_lane();
          skc_uint         const tts = smem->bin.aN.ttsb[ii][skc_subgroup_lane()];
#if 0
          printf("???????? : [ %10u = %10u : %08X ]\n",id,idx,tts);
#endif
          bp_elems[idx].u32 = tts;
        }

      //
      // FIXME -- vectorize with vstoreN()
      //
    }

  //
  // return remaining block ids back to the pool
  //
  skc_uint const blocks_rem = SKC_RASTERIZE_BLOCK_ID_V_SIZE - blocks_next;

  if (blocks_rem > 0)
    {
      skc_uint bp_idx = 0;

      if (skc_subgroup_lane() == 0)
        {
          bp_idx = SKC_ATOMIC_ADD_GLOBAL_RELAXED_DEVICE(bp_atomics+SKC_BP_ATOMIC_OFFSET_WRITES,blocks_rem);

#if 0
          printf("r-: %8u + %u\n",bp_idx,blocks_rem);
#endif
        }

      bp_idx = (sub_group_broadcast(bp_idx,0) + skc_subgroup_lane() - blocks_next) & bp_mask;

      if (skc_subgroup_lane() >= blocks_next)
        {
          bp_ids[bp_idx] = *blocks;
        }
    }

  //
  // flush work-in-progress ryx keys
  //
  if (sk_v_next > 0)
    {
      skc_uint sk_idx = 0;

      if (skc_subgroup_lane() == 0)
        {
          sk_idx = SKC_ATOMIC_ADD_GLOBAL_RELAXED_DEVICE
            (cohort_atomics+SKC_RASTER_COHORT_ATOMIC_OFFSET_KEYS,sk_v_next);
#if 0
          printf("* %u\n",sk_idx);
#endif
        }

      sk_idx = sub_group_broadcast(sk_idx,0) + skc_subgroup_lane();

      if (skc_subgroup_lane() < sk_v_next)
        {
          sk_extent[sk_idx] = *sk_v;
        }
    }
}

//
// If there are lanes that were unable to append to a bin because
// their hashes collided with a bin's current ryx key then those bins
// must be ejected.
//
// Note that we do not eject "full" bins because lazily waiting for a
// collision results in simpler code.
//

static
void
skc_flush(__global SKC_ATOMIC_UINT          volatile * const bp_atomics,
          __global union skc_bp_elem                 * const bp_elems,
          __global uint                              * const bp_ids,
          skc_uint                                     const bp_mask,
          __global SKC_ATOMIC_UINT          volatile * const cohort_atomics,
          skc_block_id_t                             * const subblocks,
          skc_block_id_v_t                           * const blocks,
          skc_uint                                   * const blocks_next,
          skc_ttsk_v_t                               * const sk_v,
          skc_uint                                   * const sk_v_next,
          __global skc_ttsk_s_t                      * const sk_extent,
          __local  struct skc_subgroup_smem volatile * const smem,
          SKC_RASTERIZE_UINT                           const hash,
          SKC_RASTERIZE_UINT                           const yx,
          SKC_RASTERIZE_PREDICATE                            is_collision) // pass by value
{
#if ( SKC_RASTERIZE_SUBGROUP_SIZE == 1 )
  //
  // SIMD
  //

  //
  // FIXME -- this code is now stale with the changes to the
  // subblock/block allocation strategy
  //

  //
  // get local TTSB ID queue count
  //
  skc_uint ttsb_id_count  = smem->pool.count; // scalar

  // init hash bit mask
  skc_uint component_mask = 0;

  for (int cc=0; cc<SKC_RASTERIZE_VECTOR_SIZE; cc++)
    {
      // if no collision continue
      if (((int*)&is_collision)[cc] == 0)
        continue;

      uint const winner        = ((uint*)&hash)[cc];
      uint const component_bit = 1u << winner;

      // if already processed this hash then continue
      if (component_mask & component_bit)
        continue;

      // update component mask
      component_mask |= component_bit;

      //
      // new winner requires ejecting the old TTSB
      //
      if (smem->bin.aN.count[winner] > 0)
        {
          skc_uint const elem_idx = smem->bin.aN.id[winner] * SKC_DEVICE_SUBBLOCK_WORDS + skc_subgroup_lane();

          bp_elems[elem_idx].u32 = smem->bin.aN.ttsb[winner][skc_subgroup_lane()];
        }

        //
        // ensure there is at least one TTSK and TTSB ID
        //
        if (ttsb_id_count == SKC_RASTERIZE_POOL_SIZE)
          {
            //
            // update remaining count
            //
            ttsb_id_count = 0;

            //
            // flush accumulated ttsk_ryx keys
            //
            uint const idx = SKC_ATOMIC_ADD_GLOBAL_RELAXED_DEVICE
              (cohort_atomics+SKC_RASTER_COHORT_ATOMIC_OFFSET_KEYS,SKC_RASTERIZE_POOL_SIZE); // ttsk_ryx_count

#if 0
            printf("# %u\n",idx);
#endif

            for (uint ii=0; ii<SKC_RASTERIZE_POOL_SIZE; ii+=SKC_RASTERIZE_SUBGROUP_SIZE)
              {
                ttsk_ryx[idx + ii] = skc_make_ttsk_ryx(smem,SKC_CMD_RASTERIZE_GET_COHORT(cmd),ii);
              }

            //
            // allocate more ttsb ids from pool
            //
            uint const id = SKC_ATOMIC_ADD_GLOBAL_RELAXED_DEVICE(bp_atomics+0,SKC_RASTERIZE_POOL_SIZE); // ring_reads

            for (uint ii=0; ii<SKC_RASTERIZE_POOL_SIZE; ii+=SKC_RASTERIZE_SUBGROUP_SIZE)
              smem->pool.aN.id[ii] = bp_ids[id + ii];
          }

      //
      // invalidate the winning block
      //

      //
      // update bin with winning yx, new ttsb id and zero count
      //
      // all lanes are loading/storing from/to the same index
      //
      smem->bin.vN.ttsb [winner] = ( SKC_TTS_INVALID );
      smem->bin.aN.id   [winner] = smem->pool.aN.id[ttsb_id_count];
      smem->bin.aN.yx   [winner] = smem->pool.aN.yx[ttsb_id_count] = ((uint*)&yx)[cc];
      smem->bin.aN.count[winner] = 0;

      //
      // update count
      //
      ttsb_id_count += 1;
    }

  //
  // save count
  //
  smem->pool.count = ttsb_id_count;

#else
  //
  // SIMT
  //

  do {
    //
    // only one lane will win!
    //
    if (is_collision)
      smem->subgroup.winner = hash;

    barrier(CLK_LOCAL_MEM_FENCE);

    //
    // which bin is being ejected?
    //
    skc_uint const winner = smem->subgroup.winner;

    //
    // which colliding hash is taking over the bin?
    //
    SKC_RASTERIZE_PREDICATE const is_winner = is_collision && (hash == winner);

    //
    // all lanes with the same hash will try to store but only one
    // lane will win
    //
    if (is_winner)
      smem->subgroup.winner = yx;

    barrier(CLK_LOCAL_MEM_FENCE);

    //
    // flush this block to the pool
    //
    if (smem->bin.aN.count[winner] > 0)
      {
        skc_block_id_v_t const id  = smem->bin.aN.id[winner];
        skc_uint         const idx = id * SKC_DEVICE_SUBBLOCK_WORDS + skc_subgroup_lane();
        skc_uint         const tts = smem->bin.aN.ttsb[winner][skc_subgroup_lane()];
#if 0
        printf("%08X : [ %10u = %10u : %08X ]\n",yx,id,idx,tts);
#endif
        bp_elems[idx].u32 = tts;
      }

    //
    // append new ttsk
    //
    skc_uint       const new_yx = smem->subgroup.winner;
    skc_block_id_t const new_id = skc_ttsk_v_append(SKC_SUBBLOCKS_BLOCKS_ARGS(),
                                                    blocks_next,
                                                    bp_atomics,
                                                    bp_mask, // pow2 modulo mask for block pool ring
                                                    bp_ids,
                                                    cohort_atomics,
                                                    sk_v,
                                                    sk_v_next,
                                                    sk_extent,
                                                    new_yx);

#if 0
    if (get_sub_group_local_id() == 0) {
      printf(">>> %9u\n",new_id);
    }
#endif

    //
    // update bin with winning yx, new ttsb id and zero count
    //
    smem->bin.aN.ttsb [winner][skc_subgroup_lane()] = SKC_TTS_INVALID;
    smem->bin.aN.yx   [winner]                      = new_yx;
    smem->bin.aN.id   [winner]                      = new_id;
    smem->bin.aN.count[winner]                      = 0;

    //
    // remove all lanes matching this hash
    //
    is_collision = is_collision && !is_winner;

    //
    // exit if nothing left to do
    //
  } while (sub_group_any(is_collision));

#endif
}

//
// scatter scan max
//
static
SKC_RASTERIZE_UINT
skc_scatter_scan_max(__local struct skc_subgroup_smem volatile * const smem,
                     SKC_RASTERIZE_FLOAT                         const iss,
                     SKC_RASTERIZE_FLOAT                         const ess)
{
  //
  // prefix sums determine which lanes we're going to work on next
  //
  SKC_RASTERIZE_PREDICATE const is_scratch_store = (iss > 0.0f) && (ess < (float)SKC_RASTERIZE_ELEMS_PER_SUBGROUP);
  SKC_RASTERIZE_UINT      const scratch_idx      = SKC_CONVERT(SKC_RASTERIZE_UINT)(max(ess,0.0f));

#if ( SKC_RASTERIZE_SUBGROUP_SIZE == 1 )
  //
  // SIMD
  //
#ifdef SKC_RASTERIZE_SIMD_USES_SMEM
  //
  // SIMD APPROACH 1: SIMT'ISH
  //

  // zero the volatile smem scratchpad using vector syntax
  smem->subgroup.vN.scratch[0] = ( 0 );

#undef  SKC_EXPAND_X
#define SKC_EXPAND_X(I,S,C,P,A)                         \
  if (is_scratch_store C)                               \
    smem->subgroup.aN.scratch[scratch_idx C] = I;

  SKC_RASTERIZE_VECTOR_EXPAND();

  // propagate lanes to right using max scan
  SKC_RASTERIZE_UINT const scratch = smem->subgroup.vN.scratch[0];
  SKC_RASTERIZE_UINT const source  = skc_subgroup_scan_inclusive_max(scratch);

#else
  //
  // SIMD APPROACH 2: SCALAR'ISH
  //

  SKC_RASTERIZE_UINT source = ( 0 );

#undef  SKC_EXPAND_X
#define SKC_EXPAND_X(I,S,C,P,A)                 \
  if (is_scratch_store C)                       \
    ((uint *)&source)[scratch_idx C] = I;

  SKC_RASTERIZE_VECTOR_EXPAND();

  for (uint ii=1; ii<SKC_RASTERIZE_ELEMS_PER_SUBGROUP; ii++)
    ((uint *)&source)[ii] = max(((uint *)&source)[ii-1],((uint *)&source)[ii]);
#endif

#else
  //
  // SIMT
  //

  //
  // zero the volatile smem scratchpad using vector syntax
  //
  smem->subgroup.vN.scratch[skc_subgroup_lane()] = ( 0 );

  //
  // store source lane at starting lane
  //
  if (is_scratch_store)
    smem->subgroup.aN.scratch[scratch_idx] = skc_subgroup_lane();

  //
  // propagate lanes to right using max scan
  //
  SKC_RASTERIZE_UINT const scratch = smem->subgroup.vN.scratch[skc_subgroup_lane()];
  SKC_RASTERIZE_UINT const source  = skc_subgroup_scan_inclusive_max(scratch);
#endif

  return source;
}

//
// sliver lines into subpixels
//

static
void
skc_sliver(__global SKC_ATOMIC_UINT          volatile * const bp_atomics,
           __global union skc_bp_elem                 * const bp_elems,
           __global uint                              * const bp_ids,
           skc_uint                                     const bp_mask,
           __global SKC_ATOMIC_UINT          volatile * const cohort_atomics,
           skc_block_id_t                             * const subblocks,
           skc_block_id_v_t                           * const blocks,
           skc_uint                                   * const blocks_next,
           skc_ttsk_v_t                               * const sk_v,
           skc_uint                                   * const sk_v_next,
           __global skc_ttsk_s_t                      * const sk_extent,
           __local  struct skc_subgroup_smem volatile * const smem,
           SKC_RASTERIZE_FLOAT                          const l0x,
           SKC_RASTERIZE_FLOAT                          const l0y,
           SKC_RASTERIZE_FLOAT                          const l1x,
           SKC_RASTERIZE_FLOAT                          const l1y)
{
  //
  // Y-SLIVERING
  // -----------
  //
  // immediately sliver all multi-pixel lines in into 1-pixel high
  // lines
  //
  // note this implicitly squelches horizontal lines
  //
  // there is another test for horizontal lines after x-slivering
  // is complete
  //

  //
  // will we need to flip the sign of y_delta ?
  //
  SKC_RASTERIZE_PREDICATE const y_lt   = (l0y <= l1y);
  SKC_RASTERIZE_UINT      const dy_xor = y_lt ? 0 : 0x80000000;

  //
  // save 1/dy
  //
  SKC_RASTERIZE_FLOAT const y_denom = native_recip(l1y - l0y);

  //
  // how many non-horizontal subpixel y-axis slivers are there?
  //
  SKC_RASTERIZE_FLOAT const y_min   = floor(fmin(l0y,l1y) * SKC_SUBPIXEL_Y_SCALE_DOWN);
  SKC_RASTERIZE_FLOAT const y_max   = ceil (fmax(l0y,l1y) * SKC_SUBPIXEL_Y_SCALE_DOWN);
  SKC_RASTERIZE_FLOAT const y_base  = y_lt ? y_min : y_max;
  SKC_RASTERIZE_FLOAT       y_segs  = y_max - y_min;

  //
  // inclusive subgroup scan of y_segs
  //
  SKC_RASTERIZE_FLOAT       y_iss   = skc_subgroup_scan_inclusive_add_float(y_segs);
  SKC_RASTERIZE_FLOAT       y_ess   = y_iss - y_segs;
  float                     y_rem   = skc_subgroup_last_float(y_iss);

  //
  // if this is a horizontal line then tweak y_iss so "is_scratch_store" always fails
  //
  if (y_segs == 0.0f)
    y_iss = 0.0f;

#if 0
  printf("{ { %5.0f, %5.0f }, { %5.0f, %5.0f } (* %5.0f / %5.0f / %5.0f / %5.0f *) }, \n",a0x,a0y,a1x,a1y,y_segs,y_iss,y_ess,y_rem);
#endif

  //
  // these values don't matter on first iteration
  //
  SKC_RASTERIZE_FLOAT n1x_prev = 0;
  SKC_RASTERIZE_FLOAT n1y_prev = 0;

  //
  // loop until done
  //
  while (y_rem > 0.0f)
    {
      //
      // distribute work across lanes
      //
      SKC_RASTERIZE_UINT const y_source = skc_scatter_scan_max(smem,y_iss,y_ess);

      //
      // get line at y_source line
      //
      SKC_RASTERIZE_FLOAT const m0x = skc_subgroup_shuffle(l0x,y_source);
      SKC_RASTERIZE_FLOAT const m0y = skc_subgroup_shuffle(l0y,y_source);
      SKC_RASTERIZE_FLOAT const m1x = skc_subgroup_shuffle(l1x,y_source);
      SKC_RASTERIZE_FLOAT const m1y = skc_subgroup_shuffle(l1y,y_source);

      //
      // every lane will create a 1 pixel tall line "sliver"
      //
      // FIXME -- this gets expanded on SIMD
      //
      // if numerator == 1 then this is the first lane
      // if numerator == s then this is the last  lane
      //
      SKC_RASTERIZE_FLOAT     const y_delta    = skc_delta_offset() - skc_subgroup_shuffle(y_ess,y_source);
      SKC_RASTERIZE_FLOAT     const y_count    = skc_subgroup_shuffle(y_segs,y_source);

      SKC_RASTERIZE_PREDICATE const is_y_first = (y_delta == 1.0f);
      SKC_RASTERIZE_PREDICATE const is_y_last  = (y_delta >= y_count);

      // toggle y_delta sign
      SKC_RASTERIZE_FLOAT     const y_offset   = as_float((as_uint(y_delta) ^ intel_sub_group_shuffle(dy_xor,y_source)));

      //
      // calculate "right" line segment endpoint
      //
      SKC_RASTERIZE_FLOAT       n1y = (y_offset + skc_subgroup_shuffle(y_base,y_source)) * SKC_SUBPIXEL_Y_SCALE_UP;
      SKC_RASTERIZE_FLOAT const n_t = (n1y - m0y) * skc_subgroup_shuffle(y_denom,y_source);
      SKC_RASTERIZE_FLOAT       n1x = round(SKC_LERP(m0x,m1x,n_t));

      //
      // override c1 if this is last point
      //
      n1y = select(n1y,m1y,is_y_last);
      n1x = select(n1x,m1x,is_y_last);

      //
      // shuffle up "left" line segment endpoint
      //
      // NOTE: Intel's shuffle_up is unique with its elegant
      // "previous" argument so don't get used to it
      //
      SKC_RASTERIZE_FLOAT n0y = skc_subgroup_shuffle_up_1(n1y_prev,n1y);
      SKC_RASTERIZE_FLOAT n0x = skc_subgroup_shuffle_up_1(n1x_prev,n1x);

      //
      // override shuffle up if this is the first line segment
      //
      n0y = select(n0y,m0y,is_y_first);
      n0x = select(n0x,m0x,is_y_first);

      //
      // save previous right endpoint
      //
      n1x_prev = n1x;
      n1y_prev = n1y;

      //
      // decrement by subgroup size
      //
      y_iss -= (float)SKC_RASTERIZE_ELEMS_PER_SUBGROUP;
      y_ess -= (float)SKC_RASTERIZE_ELEMS_PER_SUBGROUP;
      y_rem -= (float)SKC_RASTERIZE_ELEMS_PER_SUBGROUP;

#if 0
      //
      // debug
      //
      if (n0y != n1y) {
        printf("{ { %5.0f, %5.0f }, { %5.0f, %5.0f } },\n",n0x,n0y,n1x,n1y);
      }
#endif

      //
      // X-SLIVERING
      // -----------
      //
      // now sliver 1-pixel high lines into at either vertical or
      // 1-pixel wide lines
      //
      // save original direction and work with increasing x
      //
      SKC_RASTERIZE_PREDICATE const x_lt   = (n0x <= n1x);
      SKC_RASTERIZE_UINT      const dx_xor = x_lt ? 0 : 0x80000000;

      //
      // save 1/dy
      //
      SKC_RASTERIZE_FLOAT const x_denom  = native_recip(n1x - n0x);

      //
      // how many non-horizontal subpixel y-axis slivers are there?
      //
      SKC_RASTERIZE_FLOAT const x_min    = floor(fmin(n0x,n1x) * SKC_SUBPIXEL_X_SCALE_DOWN);
      SKC_RASTERIZE_FLOAT const x_max    = ceil (fmax(n0x,n1x) * SKC_SUBPIXEL_X_SCALE_DOWN);
      SKC_RASTERIZE_FLOAT const x_base   = x_lt ? x_min : x_max;
      SKC_RASTERIZE_FLOAT const x_segs   = fmax(x_max - x_min,1.0f);

      //
      // inclusive subgroup scan of y_segs
      //
      SKC_RASTERIZE_FLOAT       x_iss    = skc_subgroup_scan_inclusive_add_float(x_segs);
      SKC_RASTERIZE_FLOAT       x_ess    = x_iss - x_segs;
      float                     x_rem    = skc_subgroup_last_float(x_iss);

      //
      // if this is a horizontal line then tweak x_iss so "is_scratch_store" always fails
      //
      //if (x_segs == 0.0f)
      // x_iss = 0.0f;

      //
      // these values don't matter on first iteration
      //
      SKC_RASTERIZE_FLOAT       p1x_prev = 0;
      SKC_RASTERIZE_FLOAT       p1y_prev = 0;

      //
      // loop until done
      //
      while (x_rem > 0)
        {
          //
          // distribute work across lanes
          //
          SKC_RASTERIZE_UINT const x_source = skc_scatter_scan_max(smem,x_iss,x_ess);

          //
          // get line at y_source line
          //
          SKC_RASTERIZE_FLOAT const o0x = skc_subgroup_shuffle(n0x,x_source);
          SKC_RASTERIZE_FLOAT const o0y = skc_subgroup_shuffle(n0y,x_source);
          SKC_RASTERIZE_FLOAT const o1x = skc_subgroup_shuffle(n1x,x_source);
          SKC_RASTERIZE_FLOAT const o1y = skc_subgroup_shuffle(n1y,x_source);

          //
          // every lane will create a 1 pixel tall line "sliver"
          //
          // FIXME -- this gets expanded on SIMD
          //
          // if numerator == 1 then this is the first lane
          // if numerator == s then this is the last  lane
          //
          SKC_RASTERIZE_FLOAT     const x_delta    = skc_delta_offset() - skc_subgroup_shuffle(x_ess,x_source);
          SKC_RASTERIZE_FLOAT     const x_count    = skc_subgroup_shuffle(x_segs,x_source);

          SKC_RASTERIZE_PREDICATE const is_x_first = (x_delta == 1.0f);
          SKC_RASTERIZE_PREDICATE const is_x_last  = (x_delta >= x_count);

          // toggle x_delta sign
          SKC_RASTERIZE_FLOAT     const x_offset   = as_float((as_uint(x_delta) ^ intel_sub_group_shuffle(dx_xor,x_source)));

          //
          // calculate "right" line segment endpoint
          //
          SKC_RASTERIZE_FLOAT       p1x = (x_offset + skc_subgroup_shuffle(x_base,x_source)) * SKC_SUBPIXEL_X_SCALE_UP;
          SKC_RASTERIZE_FLOAT const p_t = (p1x - o0x) * skc_subgroup_shuffle(x_denom,x_source);
          SKC_RASTERIZE_FLOAT       p1y = round(SKC_LERP(o0y,o1y,p_t));

          //
          // override c1 if this is last point
          //
          p1x = select(p1x,o1x,is_x_last);
          p1y = select(p1y,o1y,is_x_last);

          //
          // shuffle up "left" line segment endpoint
          //
          // NOTE: Intel's shuffle_up is unique with its elegant
          // "previous" argument so don't get used to it
          //
          SKC_RASTERIZE_FLOAT p0x = skc_subgroup_shuffle_up_1(p1x_prev,p1x);
          SKC_RASTERIZE_FLOAT p0y = skc_subgroup_shuffle_up_1(p1y_prev,p1y);

          //
          // override shuffle up if this is the first line segment
          //
          p0x = select(p0x,o0x,is_x_first);
          p0y = select(p0y,o0y,is_x_first);

          //
          // save previous right endpoint
          //
          p1x_prev = p1x;
          p1y_prev = p1y;

          //
          // decrement by subgroup size
          //
          x_iss -= SKC_RASTERIZE_ELEMS_PER_SUBGROUP;
          x_ess -= SKC_RASTERIZE_ELEMS_PER_SUBGROUP;
          x_rem -= SKC_RASTERIZE_ELEMS_PER_SUBGROUP;

          //
          // only non-horizontal subpixel lines are valid
          //
          SKC_RASTERIZE_PREDICATE is_active = (p0y != p1y);

          //
          // if no lanes are active then continue
          //
          // FIXME -- THIS SIMPLE SUB_GROUP_ANY TEST SIGNIFICANTLY
          // IMPACTS PERFORMANCE (+12% ?)
          //
          // IT SHOULDN'T !!!
          //
#if 0
          if (!skc_subgroup_any(is_active))
            continue;
#endif

          //
          // Option 1: use SLM for explicitly managed coalesced stores
          //
          // 1. which tile does this line belong?
          // 2. hash tile coordinates
          // 3. lookup hash
          // 4. if tile matches then SLM append keys
          // 5. if tile doesn't match
          //   a. flush
          //   b. create new TTSK_RYX
          //   c. obtain TTSB block from pool
          //   d. goto 3.
          //

          //
          // Option 2: rely on L1/L2/L3 to mitigate non-coalesced stores
          //
          // 1. which tile does this line belong?
          // 2. hash tile coordinates
          // 3. lookup hash
          // 4. if tile matches then GMEM append keys
          // 5. if tile doesn't match
          //   a. flush (and invalidate empty elems)
          //   b. create new TTSK_RYX
          //   c. obtain TTSB block from pool
          //   d. goto 3.
          //

          //
          // The virtual rasterization surface is very large and
          // signed: +/- ~64K-256K, depending on the architecture.
          //
          // Rasters must be clipped to the virtual surface and,
          // optionally, clipped even further on a per raster
          // basis.
          //

          //
          // Clip to the per-raster clip
          //

          /*

            CLIP HERE

          */

          //
          // Hash the tile coordinates
          //
          // This table lists nominal values for each architecture.
          // We want to choose values that are naturally fit the
          // "width" of the architecture.
          //
          //   SIMD   RANGE   BITS  MAX RANGE  MAX BINS  HASH BITS
          //   ----  -------  ----  ---------  --------  ---------
          //     4   [0,  4]    3    [0,  7]      10      mod(10)  <-- SSE42, ?
          //     8   [0,  8]    4    [0, 15]       8         3     <-- GEN*,AVX*
          //    16   [0, 16]    5    [0, 31]       6      mod(6)   <-- GEN*,?
          //    32   [0, 32]    6    [0, 63]       5      mod(5)   <-- CUDA,PowerVR,Adreno,GEN*
          //    64   [0, 64]    7    [0,127]       4         2     <-- AMD Radeon
          //
          // NOTE: When possible, bias the hash toward using more y
          // bits because of:
          //
          //   1. the 90 degree counter-clockwise rotation that we put
          //      in place to offset the render-time clockwise
          //      rotation
          //
          //   2. the likely presence of left-to-right or
          //      right-to-left glyphs.
          //
          // For power-of-two bins, the hash is easy.
          //
          // For non-power-of-two, we may want to either implement a
          // fast mod (compiler should do this for us... hahahaha) or
          // drop down to the next power-of-two.
          //

          //
          // FIXME -- this snarl is not good -- can probably reduce
          // some of the sign casting but some is there to vectorize a
          // scalar
          //
          SKC_RASTERIZE_INT       const z0y    = SKC_CONVERT(SKC_RASTERIZE_INT)(p0y);
          SKC_RASTERIZE_INT       const z1y    = SKC_CONVERT(SKC_RASTERIZE_INT)(p1y);

          SKC_RASTERIZE_INT       const z0x    = SKC_CONVERT(SKC_RASTERIZE_INT)(p0x);
          SKC_RASTERIZE_INT       const z1x    = SKC_CONVERT(SKC_RASTERIZE_INT)(p1x);

          SKC_RASTERIZE_INT       const min_y  = min(z0y,z1y);
          SKC_RASTERIZE_INT       const max_y  = max(z0y,z1y);

          SKC_RASTERIZE_INT       const tile_y = min_y >> SKC_SUBTILE_RESL_Y_LOG2;

          SKC_RASTERIZE_UINT      const ty     = SKC_AS(SKC_RASTERIZE_UINT)(min_y) & SKC_SUBTILE_MASK_Y;
          SKC_RASTERIZE_INT             dy     = SKC_AS(SKC_RASTERIZE_INT)(z1y - z0y);

          //
          // map [+1,+32] to [ 0,+31]
          // map [-1,-32] to [-1,-32]
          //
          SKC_RASTERIZE_INT             dys    = (dy + (~dy >> 31)) << 26;

          SKC_RASTERIZE_INT       const min_x  = min(z0x,z1x);
          SKC_RASTERIZE_INT       const max_x  = max(z0x,z1x);
          SKC_RASTERIZE_INT       const tile_x = min_x >> SKC_SUBTILE_RESL_X_LOG2;

          SKC_RASTERIZE_UINT      const tx     = SKC_AS(SKC_RASTERIZE_UINT)(min_x) & SKC_SUBTILE_MASK_X;
          SKC_RASTERIZE_UINT      const sx     = SKC_AS(SKC_RASTERIZE_UINT)(max_x - min_x);

          SKC_RASTERIZE_UINT      const tts    = dys | (ty << 16) | (sx << 10) | tx;

          SKC_RASTERIZE_UINT      const hash   = (((SKC_AS(SKC_RASTERIZE_UINT)(tile_y) & SKC_RASTERIZE_TILE_HASH_Y_MASK) << SKC_RASTERIZE_TILE_HASH_X_BITS) |
                                                   (SKC_AS(SKC_RASTERIZE_UINT)(tile_x) & SKC_RASTERIZE_TILE_HASH_X_MASK));

          SKC_RASTERIZE_UINT      const yx     = (((SKC_AS(SKC_RASTERIZE_UINT)(tile_y) & 0xFFF) << 12) | (SKC_AS(SKC_RASTERIZE_UINT)(tile_x) & 0xFFF));

#if 0
          printf("(%3u, %3u)\n",tile_y,tile_x);
#endif

#if 0
          if (is_active)
            printf("( %3u, %3u ) : [ %3u, %3u, %3d, %3d, %3u ]\n",tile_y,tile_x,ty,tx,dy,((int)dys)>>26,sx);
#endif

          //
          // debug
          //
#if 0 // PRINTF_ENABLE

#if ( SKC_RASTERIZE_SUBGROUP_SIZE == 1 )

#undef  SKC_EXPAND_X
#define SKC_EXPAND_X(I,S,C,P,A)                                         \
          if (is_active C)                                              \
            printf("{ { %5d, %5d }, { %5d, %5d } (* %2u *) },\n",z0x C,z0y C,z1x C,z1y C,hash C);

          SKC_RASTERIZE_VECTOR_EXPAND();
#else
          if (is_active)
            printf("{ { %5d, %5d }, { %5d, %5d } } (* %2u *),\n",z0x,z0y,z1x,z1y,hash);
#endif

#endif
          //
          // flush all active lanes
          //
          while (true)
            {
              //
              // either gather load or vector load+shuffle the yx keys
              //
#if ( SKC_RASTERIZE_SUBGROUP_SIZE == 1 )
              SKC_RASTERIZE_BIN       const yx_bin     = smem->bin.vN.yx;
              SKC_RASTERIZE_UINT      const yx_cur     = shuffle(yx_bin,hash);
#else
              SKC_RASTERIZE_UINT      const yx_cur     = smem->bin.aN.yx[hash];
#endif

              //
              // does yx for lane match yx for hash?
              //
              SKC_RASTERIZE_UINT      const active_yx  = is_active ? yx : SKC_RASTERIZE_YX_INVALID;
              SKC_RASTERIZE_PREDICATE const is_match   = (yx_cur == active_yx);

              //
              // OpenCL spec: "When casting a bool to a vector integer
              // data type, the vector components will be set to -1
              // (i.e. all bits set) if the vector bool value is true
              // and 0 otherwise.
              //
#if ( SKC_RASTERIZE_VECTOR_SIZE_LOG2 == 0 )
              SKC_RASTERIZE_UINT      const h_match    = (SKC_RASTERIZE_UINT)is_match;
#else
              SKC_RASTERIZE_UINT      const h_match    = abs(is_match); // {-1,0} -> {+1,0}
#endif
              //
              // how many new elements for each matching hash bin?
              //
              SKC_RASTERIZE_UINT      const h_shl      = hash * SKC_RASTERIZE_TILE_HASH_BIN_BITS;
              SKC_RASTERIZE_UINT      const h          = h_match << h_shl;

              //
              // prefix sum all of the bins in parallel
              //
              SKC_RASTERIZE_UINT      const h_iss      = skc_subgroup_scan_inclusive_add_uint(h);
              SKC_RASTERIZE_UINT      const h_total    = skc_subgroup_last_uint(h_iss);

              //
              // current bin counts
              //
#if ( SKC_RASTERIZE_SUBGROUP_SIZE == 1 )
              SKC_RASTERIZE_BIN       const count_bin  = smem->bin.vN.count;
              SKC_RASTERIZE_UINT      const count_cur  = shuffle(count_bin,hash);
#else
              SKC_RASTERIZE_UINT      const count_cur  = smem->bin.aN.count[hash];
#endif

              //
              // calculate where each cache-hit and in-bounds tts should be stored
              //
              SKC_RASTERIZE_UINT      const ttsb_index = (h_iss   >> h_shl & SKC_RASTERIZE_TILE_HASH_BIN_MASK) + count_cur - 1;
              SKC_RASTERIZE_UINT      const count_new  = (h_total >> h_shl & SKC_RASTERIZE_TILE_HASH_BIN_MASK) + count_cur;

              //
              // which lanes can append to a matching bin?
              //
              SKC_RASTERIZE_PREDICATE const is_append  = is_match && (ttsb_index < SKC_DEVICE_SUBBLOCK_WORDS);

              //
              // scatter append tts elements to bin blocks
              //
#if ( SKC_RASTERIZE_SUBGROUP_SIZE == 1)
              //
              // SIMD
              //
#undef  SKC_EXPAND_X
#define SKC_EXPAND_X(I,S,C,P,A)                                         \
              if (is_append C)                                          \
                {                                                       \
                  smem->bin.aN.ttsb [hash C][ttsb_index C] = tts       C; \
                  smem->bin.aN.count[hash C]               = count_new C; \
                }

              SKC_RASTERIZE_VECTOR_EXPAND();
#else
              //
              // SIMT
              //
              if (is_append)
                {
                  smem->bin.aN.ttsb [hash][ttsb_index] = tts;
                  smem->bin.aN.count[hash]             = count_new; // it's ok if this is > SKC_DEVICE_SUBBLOCK_WORDS
                }
#endif
              //
              // try to keep predicate updates SIMD-friendly and
              // outside of predicated code paths -- this is not
              // always how we would normally do things on SIMT but
              // either approach is acceptable
              //

              //
              // mask off lanes/components that successfully appended
              //
              is_active = is_active && !is_append;

              //
              // are there any active lanes left?
              //
              if (!skc_subgroup_any(is_active))
                break;

              //
              // There are active lanes that couldn't be appended to a
              // bin because their hashes collided with the bin's
              // current ryx key then those bins must be ejected.
              //
              // Note that we do not eject "full" bins because lazily
              // waiting for a collision results in simpler code.
              //
              skc_flush(bp_atomics,
                        bp_elems,
                        bp_ids,
                        bp_mask,
                        cohort_atomics,
                        subblocks,
                        blocks,
                        blocks_next,
                        sk_v,
                        sk_v_next,
                        sk_extent,
                        smem,
                        hash,
                        yx,
                        is_active);
            }
        }
    }
}

//
// INITIALIZE SMEM
//
// Note that SIMD/SIMT have nearly the same syntax.
//
static
void
skc_smem_init(__local struct skc_subgroup_smem volatile * const smem)
{
  //
  // initialize smem bins
  //
#if ( SKC_RASTERIZE_SUBGROUP_SIZE == 1 )
  //
  // SIMD
  //
  smem->bin.vN.yx    = ( SKC_RASTERIZE_YX_INIT );
  smem->bin.vN.count = ( 0 );
#else
  //
  // SIMT
  //
  int idx = skc_subgroup_lane();

#if   ( SKC_RASTERIZE_TILE_HASH_BIN_COUNT < SKC_RASTERIZE_ELEMS_PER_SUBGROUP )
  if (idx < SKC_RASTERIZE_TILE_HASH_BIN_COUNT)
#elif ( SKC_RASTERIZE_TILE_HASH_BIN_COUNT > SKC_RASTERIZE_ELEMS_PER_SUBGROUP )
  for (; idx<SKC_RASTERIZE_TILE_HASH_BIN_COUNT; idx+=SKC_RASTERIZE_SUBGROUP_SIZE)
#endif
    {
      smem->bin.aN.yx   [idx] = ( SKC_RASTERIZE_YX_INIT );
      smem->bin.aN.count[idx] = ( 0 );
    }
#endif
}

//
// RASTERIZE CUBIC KERNEL
//

static
void
skc_rasterize_cubics(__global SKC_ATOMIC_UINT         volatile * const bp_atomics,
                     __global union skc_bp_elem                * const bp_elems,
                     __global uint                             * const bp_ids,
                     skc_uint                                    const bp_mask,

                     __global SKC_ATOMIC_UINT         volatile * const cohort_atomics,
                     __global skc_ttsk_s_t                     * const sk_extent,

                     __local struct skc_subgroup_smem volatile * const smem,

                     skc_uint                                  * const nodeword,
                     skc_block_id_t                            * const id,

                     union skc_transform              const    * const tv,
                     union skc_path_clip              const    * const cv,
                     skc_uint                                    const cohort)
{
  //
  // the initial segment idx and segments-per-block constant determine
  // how many block ids will need to be loaded
  //
  SKC_RASTERIZE_FLOAT const c0x = bp_elems[SKC_RASTERIZE_SEGMENT(*id)].coord;

  skc_segment_next(bp_elems,nodeword,id);

  SKC_RASTERIZE_FLOAT const c0y = bp_elems[SKC_RASTERIZE_SEGMENT(*id)].coord;

  skc_segment_next(bp_elems,nodeword,id);

  SKC_RASTERIZE_FLOAT const c1x = bp_elems[SKC_RASTERIZE_SEGMENT(*id)].coord;

  skc_segment_next(bp_elems,nodeword,id);

  SKC_RASTERIZE_FLOAT const c1y = bp_elems[SKC_RASTERIZE_SEGMENT(*id)].coord;

  skc_segment_next(bp_elems,nodeword,id);

  SKC_RASTERIZE_FLOAT const c2x = bp_elems[SKC_RASTERIZE_SEGMENT(*id)].coord;

  skc_segment_next(bp_elems,nodeword,id);

  SKC_RASTERIZE_FLOAT const c2y = bp_elems[SKC_RASTERIZE_SEGMENT(*id)].coord;

  skc_segment_next(bp_elems,nodeword,id);

  SKC_RASTERIZE_FLOAT const c3x = bp_elems[SKC_RASTERIZE_SEGMENT(*id)].coord;

  skc_segment_next(bp_elems,nodeword,id);

  SKC_RASTERIZE_FLOAT const c3y = bp_elems[SKC_RASTERIZE_SEGMENT(*id)].coord;

  //
  // apply transform
  //
  // note that we only care if the end points are rounded to subpixel precision
  //
  // FIXME -- transformation is currently affine-only support perspective later
  //
  // the affine transformation requires 8 FMA + 2 ROUND operations
  //
  SKC_RASTERIZE_FLOAT const b0x = round(c0x * tv->sx  + c0y * tv->shx + tv->tx);
  SKC_RASTERIZE_FLOAT const b0y = round(c0x * tv->shy + c0y * tv->sy  + tv->ty);

  SKC_RASTERIZE_FLOAT const t1x = c1x * tv->sx  + c1y * tv->shx + tv->tx;
  SKC_RASTERIZE_FLOAT const t1y = c1x * tv->shy + c1y * tv->sy  + tv->ty;

  SKC_RASTERIZE_FLOAT const t2x = c2x * tv->sx  + c2y * tv->shx + tv->tx;
  SKC_RASTERIZE_FLOAT const t2y = c2x * tv->shy + c2y * tv->sy  + tv->ty;

  SKC_RASTERIZE_FLOAT const t3x = round(c3x * tv->sx  + c3y * tv->shx + tv->tx);
  SKC_RASTERIZE_FLOAT const t3y = round(c3x * tv->shy + c3y * tv->sy  + tv->ty);

  //
  //
  //
#if PRINTF_ENABLE

#if ( SKC_RASTERIZE_SUBGROUP_SIZE == 1 )

#undef  SKC_EXPAND_X
#define SKC_EXPAND_X(I,S,C,P,A)                                         \
  printf("{ { %.02f, %.02f }, { %.02f, %.02f },"                        \
         "  { %.02f, %.02f }, { %.02f, %.02f } },\n",                   \
         b0x C,b0y C,t1x C,t1y C,                                       \
         t2x C,t2y C,t3x C,t3y C);

  SKC_RASTERIZE_VECTOR_EXPAND();

#else

  printf("{ { %.02f, %.02f }, { %.02f, %.02f }, { %.02f, %.02f }, { %.02f, %.02f } },\n",
         b0x,b0y,t1x,t1y,t2x,t2y,t3x,t3y);

#endif

#endif

  //
  // OLD APPROACH
  // ------------
  //
  // The Spinel CUDA rasterizer was significantly more complex and
  // performed a few different tasks that are probably best kept
  // separate.
  //
  // The Spinel rasterizer Bezier held 4-element x and y coordinates
  // in adjacent lanes. This simplified intermingling of single lane
  // 4-coordinate line segments with two-lane cubic Beziers.
  //
  // After transformation of the input segments, the Spinel rasterizer
  // would test cubics for flatness and, if flat, collapse the
  // adjacent lanes into a single line lane and an empty lane.
  //
  // Any lines would then be appended to a line queue.
  //
  // Any cubics would then be subdivided.
  //
  // The reclassification process would be repeated.
  //
  // NEW APPROACH
  // ------------
  //
  // Assume we're only working with cubics in this kernel.
  //
  // Optimization: if the line segment is a special case -- a cusp,
  // has 1+ inflections, or a loop -- it might be beneficial to
  // subdivide the control cage 1+ times in order to separate the
  // flatter segments the high-velocity region(s).
  //
  // This means we want to split using [a,b] formulation to _directly_
  // subdivide producing a new control cage.
  //
  // Wang's Formula is still useful even if we subdivide once or twice
  // as it's so cheap that it might give some useful hints about where
  // the high-velocity sections of curve reside.
  //
  // But it seems like using Wang's and directly flattening to line
  // segments without any subdivision is good enough for the limited
  // set of test cases that I've tried.
  //
  // So... use Wang's Formula to estimate how many line segment are
  // required to properly flatten the cubics.
  //
  // Then use inclusive/exclusive scans to put all the lanes to work:
  //
  //   1. segmenting cubics to line segments
  //
  //   2. slivering line segments into 1-pixel high line segments
  //
  //   3. slivering 1-pixel high line segments into 1-pixel wide line
  //      segments
  //
  // MORE BACKGROUND ON NEW APPROACH
  // -------------------------------
  //
  // Two options for handling line segments:
  //
  // 1. append the line segments onto an SLM array until enough
  //    work has been accrued (Spinel does this)
  //
  // 2. immediately sliver the potentially multi-pixel line
  //    segments into subpixel lines
  //
  // The advantage of (1) is that it guarantees the slivering
  // process will, on average, always be emitting a full subgroup
  // of subpixel lines.
  //
  // The advantage of (2) is that it reduces code complexity and
  // leaves more room for SLM tile bins. The difference between Spinel
  // and Skia Compute is that Wang's Formula guarantees there will be
  // a full subgroup of multi-pixel lines unless this is the final
  // iteration of the warp of multi-pixel lines.
  //
  // Note that wider GPU architectures might benefit from (1) and
  // other work accumulation strategies because it will minimize
  // partial warp workloads in the final iteration of each stage.  It
  // also minimizes the sunk cost of the uniform control logic steps.
  //
  // So let's implement (2) for now...
  //

  //
  // And... begin!
  //
  // Estimate how many line segments are in quad/cubic curve.
  //
  // Wang's Formula will return zero if the control points are
  // collinear but we bump it up to 1.0f.
  //
  SKC_RASTERIZE_FLOAT const s_segs  = skc_wangs_formula_cubic(b0x,b0y,t1x,t1y,t2x,t2y,t3x,t3y);

  //
  // if there are free registers then precalculate the reciprocal for
  // each estimated segments since it will never change
  //
  SKC_RASTERIZE_FLOAT const s_denom = native_recip(s_segs);


  //
  // inclusive add scan of estimated line segments
  // exclusive add scan of estimated line segments
  // total number       of estimated line segments
  //
  SKC_RASTERIZE_FLOAT       s_iss   = skc_subgroup_scan_inclusive_add_float(s_segs);
  SKC_RASTERIZE_FLOAT       s_ess   = s_iss - s_segs;
  float                     s_rem   = skc_subgroup_last_float(s_iss); // scalar

  //
  // Precompute cubic polynomial coefficients from transformed control
  // cage so we can shuffle them in on each iteration of the outer
  // loop and then evaluate the polynomial in Horner form.
  //
  //                            |  1  0  0  0 | | c0 |
  //                            |             | |    |
  //                            | -3  3  0  0 | | c1 |
  //   B(t) = [ 1 t^1 t^2 t^3 ] |             | |    |
  //                            |  3 -6  3  0 | | c2 |
  //                            |             | |    |
  //                            | -1  3 -3  1 | | c3 |
  //
  //
  SKC_RASTERIZE_FLOAT const b1x = mad(-3.0f,b0x,3.0f*t1x);                // 2 - 1 MAD + MUL
  SKC_RASTERIZE_FLOAT const b1y = mad(-3.0f,b0y,3.0f*t1y);                // 2 - 1 MAD + MUL

  SKC_RASTERIZE_FLOAT const b2x = mad(3.0f,b0x,mad(-6.0f,t1x,3.0f*t2x));  // 3 - 2 MAD + MUL
  SKC_RASTERIZE_FLOAT const b2y = mad(3.0f,b0y,mad(-6.0f,t1y,3.0f*t2y));  // 3 - 2 MAD + MUL

  SKC_RASTERIZE_FLOAT const b3x = mad(3.0f,t1x,mad(-3.0f,t2x,t3x)) - b0x; // 3 - 2 MAD + SUB
  SKC_RASTERIZE_FLOAT const b3y = mad(3.0f,t1y,mad(-3.0f,t2y,t3y)) - b0y; // 3 - 2 MAD + SUB

  //
  // these values don't matter on the first iteration
  //
  SKC_RASTERIZE_FLOAT l1x_prev  = 0;
  SKC_RASTERIZE_FLOAT l1y_prev  = 0;

  //
  // allocate and init in-register TTSK keys
  //
  skc_uint     sk_v_next = 0;
  skc_ttsk_v_t sk_v; 

  sk_v.hi = cohort;

  //
  // initialize smem
  //
  skc_smem_init(smem);

  //
  // initialize blocks / subblocks
  //
  skc_block_id_v_t blocks;
  skc_uint         blocks_next = SKC_RASTERIZE_BLOCK_ID_V_SIZE;

#if SKC_DEVICE_BLOCK_WORDS_LOG2 > SKC_DEVICE_SUBBLOCK_WORDS_LOG2
  skc_block_id_t   subblocks   = 0;
#endif

  //
  // loop until done
  //
  while (s_rem > 0)
    {
      //
      // distribute work across lanes
      //
      SKC_RASTERIZE_UINT const s_source = skc_scatter_scan_max(smem,s_iss,s_ess);

      //
      // every lane has a fraction to work off of
      //
      // FIXME -- this gets expanded on SIMD
      //
      // if delta == 1      then this is the first lane
      // if count == s_segs then this is the last  lane
      //
      SKC_RASTERIZE_FLOAT     const s_delta    = skc_delta_offset() - skc_subgroup_shuffle(s_ess,s_source);
      SKC_RASTERIZE_FLOAT     const s_count    = skc_subgroup_shuffle(s_segs,s_source);

      SKC_RASTERIZE_PREDICATE const is_s_first = (s_delta == 1.0f);
      SKC_RASTERIZE_PREDICATE const is_s_last  = (s_delta >= s_count);

      //
      // init parametric t
      //
      SKC_RASTERIZE_FLOAT s_t = s_delta * skc_subgroup_shuffle(s_denom,s_source); // faster than native_recip(s_count)?

      //
      // if last then override to a hard 1.0f
      //
      s_t    = is_s_last ? 1.0f : s_t;

      //
      // decrement by subgroup size
      //
      s_iss -= SKC_RASTERIZE_ELEMS_PER_SUBGROUP;
      s_ess -= SKC_RASTERIZE_ELEMS_PER_SUBGROUP;
      s_rem -= SKC_RASTERIZE_ELEMS_PER_SUBGROUP;

      //
      // now every lane knows what to do and the following lines will
      // pump out up to SUBGROUP_SIZE line segments
      //
      // obtain the src vertices through shared or via a shuffle
      //

      //
      // shuffle in the polynomial coefficients their source lane
      //
      SKC_RASTERIZE_FLOAT const s0x = skc_subgroup_shuffle(b0x,s_source);
      SKC_RASTERIZE_FLOAT const s0y = skc_subgroup_shuffle(b0y,s_source);

      SKC_RASTERIZE_FLOAT const s1x = skc_subgroup_shuffle(b1x,s_source);
      SKC_RASTERIZE_FLOAT const s1y = skc_subgroup_shuffle(b1y,s_source);

      SKC_RASTERIZE_FLOAT const s2x = skc_subgroup_shuffle(b2x,s_source);
      SKC_RASTERIZE_FLOAT const s2y = skc_subgroup_shuffle(b2y,s_source);

      SKC_RASTERIZE_FLOAT const s3x = skc_subgroup_shuffle(b3x,s_source);
      SKC_RASTERIZE_FLOAT const s3y = skc_subgroup_shuffle(b3y,s_source);

      //
      // calculate "right" line segment endpoint using Horner form
      //
      SKC_RASTERIZE_FLOAT       l1x = round(mad(mad(mad(s3x,s_t,s2x),s_t,s1x),s_t,s0x)); // 3 MAD + ROUND
      SKC_RASTERIZE_FLOAT       l1y = round(mad(mad(mad(s3y,s_t,s2y),s_t,s1y),s_t,s0y)); // 3 MAD + ROUND

      //
      // shuffle up "left" line segment endpoint
      //
      // NOTE: Intel's shuffle_up is unique with its elegant
      // "previous" argument so don't get used to it
      //
      SKC_RASTERIZE_FLOAT       l0x = skc_subgroup_shuffle_up_1(l1x_prev,l1x);
      SKC_RASTERIZE_FLOAT       l0y = skc_subgroup_shuffle_up_1(l1y_prev,l1y);

      //
      // save previous right endpoint
      //
      l1x_prev = l1x;
      l1y_prev = l1y;

      //
      // override shuffle up if this is the first line segment
      //
      l0x = select(l0x,s0x,is_s_first);
      l0y = select(l0y,s0y,is_s_first);

      //
      // sliver lines
      //
      skc_sliver(bp_atomics,
                 bp_elems,
                 bp_ids,
                 bp_mask,
                 cohort_atomics,
                 &subblocks,
                 &blocks,
                 &blocks_next,
                 &sk_v,
                 &sk_v_next,
                 sk_extent,
                 smem,
                 l0x,l0y,l1x,l1y);
    }

  //
  // - flush work-in-progress blocks
  // - return unused block ids
  //
  skc_finalize(bp_atomics,
               bp_elems,
               bp_ids,
               bp_mask,
               cohort_atomics,
               &blocks,
               blocks_next,
               &sk_v,
               sk_v_next,
               sk_extent,
               smem);
}

//
// RASTERIZE QUAD KERNEL
//

static
void
skc_rasterize_quads(__global SKC_ATOMIC_UINT         volatile * const bp_atomics,
                    __global union skc_bp_elem                * const bp_elems,
                    __global uint                             * const bp_ids,
                    skc_uint                                    const bp_mask,

                    __global SKC_ATOMIC_UINT         volatile * const cohort_atomics,
                    __global skc_ttsk_s_t                     * const sk_extent,

                    __local struct skc_subgroup_smem volatile * const smem,
                    
                    skc_uint                                  * const nodeword,
                    skc_block_id_t                            * const id,

                    union skc_transform              const    * const tv,
                    union skc_path_clip              const    * const cv,
                    skc_uint                                    const cohort)
{
  //
  // the initial segment idx and segments-per-block constant determine
  // how many block ids will need to be loaded
  //
  SKC_RASTERIZE_FLOAT const c0x = bp_elems[SKC_RASTERIZE_SEGMENT(*id)].coord;

  skc_segment_next(bp_elems,nodeword,id);

  SKC_RASTERIZE_FLOAT const c0y = bp_elems[SKC_RASTERIZE_SEGMENT(*id)].coord;

  skc_segment_next(bp_elems,nodeword,id);

  SKC_RASTERIZE_FLOAT const c1x = bp_elems[SKC_RASTERIZE_SEGMENT(*id)].coord;

  skc_segment_next(bp_elems,nodeword,id);

  SKC_RASTERIZE_FLOAT const c1y = bp_elems[SKC_RASTERIZE_SEGMENT(*id)].coord;

  skc_segment_next(bp_elems,nodeword,id);

  SKC_RASTERIZE_FLOAT const c2x = bp_elems[SKC_RASTERIZE_SEGMENT(*id)].coord;

  skc_segment_next(bp_elems,nodeword,id);

  SKC_RASTERIZE_FLOAT const c2y = bp_elems[SKC_RASTERIZE_SEGMENT(*id)].coord;

  //
  // apply transform
  //
  // note that we only care if the end points are rounded to subpixel precision
  //
  // FIXME -- transformation is currently affine-only support perspective later
  //
  // the affine transformation requires 8 FMA + 2 ROUND operations
  //
  SKC_RASTERIZE_FLOAT const b0x = round(c0x * tv->sx  + c0y * tv->shx + tv->tx);
  SKC_RASTERIZE_FLOAT const b0y = round(c0x * tv->shy + c0y * tv->sy  + tv->ty);

  SKC_RASTERIZE_FLOAT const t1x = c1x * tv->sx  + c1y * tv->shx + tv->tx;
  SKC_RASTERIZE_FLOAT const t1y = c1x * tv->shy + c1y * tv->sy  + tv->ty;

  SKC_RASTERIZE_FLOAT const t2x = round(c2x * tv->sx  + c2y * tv->shx + tv->tx);
  SKC_RASTERIZE_FLOAT const t2y = round(c2x * tv->shy + c2y * tv->sy  + tv->ty);

  //
  // Estimate how many line segments are in quad/cubic curve.
  //
  // Wang's Formula will return zero if the control points are
  // collinear but we bump it up to 1.0f.
  //
  SKC_RASTERIZE_FLOAT const s_segs  = skc_wangs_formula_quadratic(b0x,b0y,t1x,t1y,t2x,t2y);

  //
  // if there are free registers then precalculate the reciprocal for
  // each estimated segments since it will never change
  //
  SKC_RASTERIZE_FLOAT const s_denom = native_recip(s_segs);


  //
  // inclusive add scan of estimated line segments
  // exclusive add scan of estimated line segments
  // total number       of estimated line segments
  //
  SKC_RASTERIZE_FLOAT       s_iss   = skc_subgroup_scan_inclusive_add_float(s_segs);
  SKC_RASTERIZE_FLOAT       s_ess   = s_iss - s_segs;
  float                     s_rem   = skc_subgroup_last_float(s_iss); // scalar

  //
  // Precompute quadratic polynomial coefficients from control cage so
  // we can shuffle them in on each iteration of the outer loop and
  // then evaluate the polynomial in Horner form.
  //

  //                        |  1  0  0  | | c0 |
  //                        |           | |    |
  //   B(t) = [ 1 t^1 t^2 ] | -2  2  0  | | c1 |
  //                        |           | |    |
  //                        |  1 -2  1  | | c2 |
  //
  //
  SKC_RASTERIZE_FLOAT const b1x = mad(-2.0f,b0x,2.0f*t1x); // 2 - 1 MAD + MUL
  SKC_RASTERIZE_FLOAT const b1y = mad(-2.0f,b0y,2.0f*t1y); // 2 - 1 MAD + MUL

  SKC_RASTERIZE_FLOAT const b2x = mad(-2.0f,t1x,b0x+t2x);  // 2 - 1 MAD + ADD
  SKC_RASTERIZE_FLOAT const b2y = mad(-2.0f,t1y,b0y+t2y);  // 2 - 1 MAD + ADD

  //
  // these values don't matter on the first iteration
  //
  SKC_RASTERIZE_FLOAT l1x_prev  = 0;
  SKC_RASTERIZE_FLOAT l1y_prev  = 0;

  //
  // allocate and init in-register TTSK keys
  //
  skc_uint     sk_v_next = 0;
  skc_ttsk_v_t sk_v; 

  sk_v.hi = cohort;

  //
  // initialize smem
  //
  skc_smem_init(smem);

  //
  // initialize blocks / subblocks
  //
  skc_block_id_v_t blocks;
  skc_uint         blocks_next = SKC_RASTERIZE_BLOCK_ID_V_SIZE;

#if SKC_DEVICE_BLOCK_WORDS_LOG2 > SKC_DEVICE_SUBBLOCK_WORDS_LOG2
  skc_block_id_t   subblocks   = 0;
#endif

  //
  // loop until done
  //
  while (s_rem > 0)
    {
      //
      // distribute work across lanes
      //
      SKC_RASTERIZE_UINT const s_source = skc_scatter_scan_max(smem,s_iss,s_ess);

      //
      // every lane has a fraction to work off of
      //
      // FIXME -- this gets expanded on SIMD
      //
      // if delta == 1      then this is the first lane
      // if count == s_segs then this is the last  lane
      //
      SKC_RASTERIZE_FLOAT     const s_delta    = skc_delta_offset() - skc_subgroup_shuffle(s_ess,s_source);
      SKC_RASTERIZE_FLOAT     const s_count    = skc_subgroup_shuffle(s_segs,s_source);

      SKC_RASTERIZE_PREDICATE const is_s_first = (s_delta == 1.0f);
      SKC_RASTERIZE_PREDICATE const is_s_last  = (s_delta >= s_count);

      //
      // init parametric t
      //
      SKC_RASTERIZE_FLOAT s_t = s_delta * skc_subgroup_shuffle(s_denom,s_source); // faster than native_recip(s_count)?

      //
      // if last then override to a hard 1.0f
      //
      s_t    = is_s_last ? 1.0f : s_t;

      //
      // decrement by subgroup size
      //
      s_iss -= SKC_RASTERIZE_ELEMS_PER_SUBGROUP;
      s_ess -= SKC_RASTERIZE_ELEMS_PER_SUBGROUP;
      s_rem -= SKC_RASTERIZE_ELEMS_PER_SUBGROUP;

      //
      // now every lane knows what to do and the following lines will
      // pump out up to SUBGROUP_SIZE line segments
      //
      // obtain the src vertices through shared or via a shuffle
      //

      //
      // shuffle in the polynomial coefficients their source lane
      //
      SKC_RASTERIZE_FLOAT const s0x = skc_subgroup_shuffle(b0x,s_source);
      SKC_RASTERIZE_FLOAT const s0y = skc_subgroup_shuffle(b0y,s_source);

      SKC_RASTERIZE_FLOAT const s1x = skc_subgroup_shuffle(b1x,s_source);
      SKC_RASTERIZE_FLOAT const s1y = skc_subgroup_shuffle(b1y,s_source);

      SKC_RASTERIZE_FLOAT const s2x = skc_subgroup_shuffle(b2x,s_source);
      SKC_RASTERIZE_FLOAT const s2y = skc_subgroup_shuffle(b2y,s_source);

      //
      // calculate "right" line segment endpoint using Horner form
      //
      SKC_RASTERIZE_FLOAT       l1x = round(mad(mad(s2x,s_t,s1x),s_t,s0x)); // 2 MAD + ROUND
      SKC_RASTERIZE_FLOAT       l1y = round(mad(mad(s2y,s_t,s1y),s_t,s0y)); // 2 MAD + ROUND

      //
      // shuffle up "left" line segment endpoint
      //
      // NOTE: Intel's shuffle_up is unique with its elegant
      // "previous" argument so don't get used to it
      //
      SKC_RASTERIZE_FLOAT       l0x = skc_subgroup_shuffle_up_1(l1x_prev,l1x);
      SKC_RASTERIZE_FLOAT       l0y = skc_subgroup_shuffle_up_1(l1y_prev,l1y);

      //
      // save previous right endpoint
      //
      l1x_prev = l1x;
      l1y_prev = l1y;

      //
      // override shuffle up if this is the first line segment
      //
      l0x = select(l0x,s0x,is_s_first);
      l0y = select(l0y,s0y,is_s_first);

      //
      // sliver lines
      //
      skc_sliver(bp_atomics,
                 bp_elems,
                 bp_ids,
                 bp_mask,
                 cohort_atomics,
                 &subblocks,
                 &blocks,
                 &blocks_next,
                 &sk_v,
                 &sk_v_next,
                 sk_extent,
                 smem,
                 l0x,l0y,l1x,l1y);
    }

  //
  // - flush work-in-progress blocks
  // - return unused block ids
  //
  skc_finalize(bp_atomics,
               bp_elems,
               bp_ids,
               bp_mask,
               cohort_atomics,
               &blocks,
               blocks_next,
               &sk_v,
               sk_v_next,
               sk_extent,
               smem);
}

//
// RASTERIZE LINE KERNEL
//

static
void
skc_rasterize_lines(__global SKC_ATOMIC_UINT         volatile * const bp_atomics,
                    __global union skc_bp_elem                * const bp_elems,
                    __global uint                             * const bp_ids,
                    skc_uint                                    const bp_mask,

                    __global SKC_ATOMIC_UINT         volatile * const cohort_atomics,
                    __global skc_ttsk_s_t                     * const sk_extent,

                    __local struct skc_subgroup_smem volatile * const smem,
                    
                    skc_uint                                  * const nodeword,
                    skc_block_id_t                            * const id,

                    union skc_transform              const    * const tv,
                    union skc_path_clip              const    * const cv,
                    skc_uint                                    const cohort)
{
  //
  // the initial segment idx and segments-per-block constant determine
  // how many block ids will need to be loaded
  //
  SKC_RASTERIZE_FLOAT const c0x = bp_elems[SKC_RASTERIZE_SEGMENT(*id)].coord;

  skc_segment_next(bp_elems,nodeword,id);

  SKC_RASTERIZE_FLOAT const c0y = bp_elems[SKC_RASTERIZE_SEGMENT(*id)].coord;

  skc_segment_next(bp_elems,nodeword,id);

  SKC_RASTERIZE_FLOAT const c1x = bp_elems[SKC_RASTERIZE_SEGMENT(*id)].coord;

  skc_segment_next(bp_elems,nodeword,id);

  SKC_RASTERIZE_FLOAT const c1y = bp_elems[SKC_RASTERIZE_SEGMENT(*id)].coord;

#if 0
  // printf("%5u : { { %5.0f, %5.0f }, { %5.0f, %5.0f } },\n",(skc_uint)get_global_id(0),c0x,c0y,c1x,c1y);
  printf("{ { %5.0f, %5.0f }, { %5.0f, %5.0f } },\n",c0x,c0y,c1x,c1y);
#endif

  //
  // apply transform
  //
  // note that we only care if the end points are rounded to subpixel precision
  //
  // FIXME -- transformation is currently affine-only
  // FIXME -- support perspective later
  //
  // the affine transformation requires 8 FMA + 4 ROUND operations
  //
  SKC_RASTERIZE_FLOAT const l0x = round(c0x * tv->sx  + c0y * tv->shx + tv->tx);
  SKC_RASTERIZE_FLOAT const l0y = round(c0x * tv->shy + c0y * tv->sy  + tv->ty);

  SKC_RASTERIZE_FLOAT const l1x = round(c1x * tv->sx  + c1y * tv->shx + tv->tx);
  SKC_RASTERIZE_FLOAT const l1y = round(c1x * tv->shy + c1y * tv->sy  + tv->ty);

#if 0
  printf("{ { %5.0f, %5.0f }, { %5.0f, %5.0f } },\n",l0x,l0y,l1x,l1y);
#endif

  //
  // allocate and init in-register TTSK keys
  //
  skc_uint     sk_v_next = 0;
  skc_ttsk_v_t sk_v; 

  sk_v.hi = cohort;

  //
  // initialize smem
  //
  skc_smem_init(smem);

  //
  // initialize blocks / subblocks
  //
  skc_block_id_v_t blocks;
  skc_uint         blocks_next = SKC_RASTERIZE_BLOCK_ID_V_SIZE;

#if SKC_DEVICE_BLOCK_WORDS_LOG2 > SKC_DEVICE_SUBBLOCK_WORDS_LOG2
  skc_block_id_t   subblocks   = 0;
#endif

  //
  // sliver lines
  //
  skc_sliver(bp_atomics,
             bp_elems,
             bp_ids,
             bp_mask,
             cohort_atomics,
             &subblocks,
             &blocks,
             &blocks_next,
             &sk_v,
             &sk_v_next,
             sk_extent,
             smem,
             l0x,l0y,l1x,l1y);

  //
  // - flush work-in-progress blocks
  // - return unused block ids
  //
  skc_finalize(bp_atomics,
               bp_elems,
               bp_ids,
               bp_mask,
               cohort_atomics,
               &blocks,
               blocks_next,
               &sk_v,
               sk_v_next,
               sk_extent,
               smem);
}

//
//
//

__kernel
SKC_RASTERIZE_KERNEL_ATTRIBS
void
skc_kernel_rasterize_all(__global SKC_ATOMIC_UINT         volatile * const bp_atomics,
                         __global union skc_bp_elem                * const bp_elems,
                         __global uint                             * const bp_ids,
                         skc_uint                                    const bp_mask,

                         __global SKC_ATOMIC_UINT         volatile * const cohort_atomics,
                         __global skc_ttsk_s_t                     * const sk_extent,

                         __global float8                  const    * const transforms, // FIXME -- __constant
                         __global float4                  const    * const clips,      // FIXME -- __constant
                         __global union skc_cmd_rasterize const    * const cmds,       // FIXME -- __constant
                         skc_uint                                    const count)
{
  //
  // declare shared memory block
  //
#if ( SKC_RASTERIZE_WORKGROUP_SUBGROUPS == 1 )
  __local struct skc_subgroup_smem volatile                smem[1];
#else
  __local struct skc_subgroup_smem volatile                smem_wg[SKC_RASTERIZE_WORKGROUP_SUBGROUPS];
  __local struct skc_subgroup_smem volatile * const smem = smem_wg + get_sub_group_id();
#endif
  
  //
  // this is a subgroup/warp-centric kernel
  //
  // which subgroup in the grid is this?
  //
  // TAKE NOTE: the Intel GEN compiler appears to be recognizing
  // get_group_id(0) as a uniform but the alternative calculation used
  // when there are multiple subgroups per workgroup is not
  // cooperating and driving spillage elsewhere.
  //
#if ( SKC_RASTERIZE_WORKGROUP_SUBGROUPS == 1 )
  uint const cmd_idx = get_group_id(0);
#else
  uint const cmd_idx = get_group_id(0) * SKC_RASTERIZE_WORKGROUP_SUBGROUPS + get_sub_group_id();
#endif

#if 0
  if (get_sub_group_local_id() == 0)
    printf("+cmd_idx = %u\n",cmd_idx);
#endif

  //
  // if worksgroups are multi-subgroup then there may be excess
  // subgroups in the final workgroup
  //
  if (cmd_idx >= count)
    return;

#if 0
  if (get_sub_group_local_id() == 0)
    printf("-cmd_idx = %u\n",cmd_idx);
#endif

  //
  // load a single command for this subgroup
  //
  union skc_cmd_rasterize const cmd = cmds[cmd_idx];

#if 0
  if (get_sub_group_local_id() == 0)
    printf("[ %u ]< %u, %u, %u, %u >\n",
           cmd_idx,
           cmd.nodeword,
           SKC_CMD_RASTERIZE_GET_TRANSFORM(cmd),
           SKC_CMD_RASTERIZE_GET_CLIP(cmd),
           SKC_CMD_RASTERIZE_GET_COHORT(cmd));
#endif

  //
  // get first block node command word and its subblock
  //
  skc_uint              nodeword = cmd.nodeword; // nodeword has word-addressing
  skc_tagged_block_id_t tag_id   = bp_elems[nodeword].tag_id;
  skc_block_id_tag      tag      = SKC_TAGGED_BLOCK_ID_GET_TAG(tag_id);
  skc_block_id_t        id       = SKC_TAGGED_BLOCK_ID_GET_ID(tag_id);

  //
  // load transform -- uniform across subgroup
  //
  // v8: { sx shx tx shy sy ty w0 w1 }
  //
  // NOTE THAT WE'RE SCALING UP THE TRANSFORM BY:
  //
  //   [ SKC_SUBPIXEL_RESL_X_F32, SKC_SUBPIXEL_RESL_Y_F32, 1.0f ]
  //
  // Coordinates are scaled to subpixel resolution.  All that matters
  // is that continuity is maintained between end path element
  // endpoints.
  //
  // It's the responsibility of the host to ensure that the transforms
  // are properly scaled either via intitializing a transform stack
  // with the subpixel resolution scaled identity or scaling the
  // transform before its loaded by a rasterization grid.
  //
  // FIXME -- horizontal load might be better than this broadcast load
  //
  union skc_transform const tv     = { .f32v8 = transforms[SKC_CMD_RASTERIZE_GET_TRANSFORM(cmd)] }; // uniform load
  union skc_path_clip const cv     = { .f32v4 = clips     [SKC_CMD_RASTERIZE_GET_CLIP(cmd)     ] }; // uniform load
  skc_uint            const cohort = SKC_CMD_RASTERIZE_MASK_COHORT(cmd); // shifted

  switch (tag)
    {
    case SKC_BLOCK_ID_TAG_PATH_LINE:
      skc_rasterize_lines(bp_atomics,
                          bp_elems,
                          bp_ids,
                          bp_mask,
                          cohort_atomics,
                          sk_extent,
                          smem,
                          &nodeword,&id,
                          &tv,&cv,cohort);
      break;

    case SKC_BLOCK_ID_TAG_PATH_QUAD:
      skc_rasterize_quads(bp_atomics,
                          bp_elems,
                          bp_ids,
                          bp_mask,
                          cohort_atomics,
                          sk_extent,
                          smem,
                          &nodeword,&id,
                          &tv,&cv,cohort);
      break;

    case SKC_BLOCK_ID_TAG_PATH_CUBIC:
      skc_rasterize_cubics(bp_atomics,
                           bp_elems,
                           bp_ids,
                           bp_mask,
                           cohort_atomics,
                           sk_extent,
                           smem,
                           &nodeword,&id,
                           &tv,&cv,cohort);
      break;

    case SKC_BLOCK_ID_TAG_PATH_RAT_QUAD:
      break;
    case SKC_BLOCK_ID_TAG_PATH_RAT_CUBIC:
      break;

    default:
      break;
    }
}

//
//
//

__kernel
SKC_RASTERIZE_KERNEL_ATTRIBS
void
skc_kernel_rasterize_lines(__global SKC_ATOMIC_UINT         volatile * const bp_atomics,
                           __global union skc_bp_elem                * const bp_elems,
                           __global uint                             * const bp_ids,
                           skc_uint                                    const bp_mask,

                           __global SKC_ATOMIC_UINT         volatile * const cohort_atomics,
                           __global skc_ttsk_s_t                     * const sk_extent,

                           __global float8                  const    * const transforms, // FIXME -- __constant
                           __global float4                  const    * const clips,      // FIXME -- __constant
                           __global union skc_cmd_rasterize const    * const cmds,       // FIXME -- __constant
                           skc_uint                                    const count)
{
  //
  // declare shared memory block
  //
#if ( SKC_RASTERIZE_WORKGROUP_SUBGROUPS == 1 )
  __local struct skc_subgroup_smem volatile                smem[1];
#else
  __local struct skc_subgroup_smem volatile                smem_wg[SKC_RASTERIZE_WORKGROUP_SUBGROUPS];
  __local struct skc_subgroup_smem volatile * const smem = smem_wg + get_sub_group_id();
#endif
  
  //
  // this is a subgroup/warp-centric kernel
  //
  // which subgroup in the grid is this?
  //
  // TAKE NOTE: the Intel GEN compiler appears to be recognizing
  // get_group_id(0) as a uniform but the alternative calculation used
  // when there are multiple subgroups per workgroup is not
  // cooperating and driving spillage elsewhere.
  //
#if ( SKC_RASTERIZE_WORKGROUP_SUBGROUPS == 1 )
  uint const cmd_idx = get_group_id(0);
#else
  uint const cmd_idx = get_group_id(0) * SKC_RASTERIZE_WORKGROUP_SUBGROUPS + get_sub_group_id();
#endif

  //
  // if worksgroups are multi-subgroup then there may be excess
  // subgroups in the final workgroup
  //
  if (cmd_idx >= count)
    return;

#if 0
  if (get_sub_group_local_id() == 0)
    printf("cmd_idx = %u\n",cmd_idx);
#endif

  //
  // load a single command for this subgroup
  //
  union skc_cmd_rasterize const cmd = cmds[cmd_idx];

  //
  // get first block node command word and its subblock
  //
  skc_uint              nodeword = cmd.nodeword; // nodeword has word-addressing
  skc_tagged_block_id_t tag_id   = bp_elems[nodeword].tag_id;
  skc_block_id_t        id       = SKC_TAGGED_BLOCK_ID_GET_ID(tag_id);

  //
  // load transform -- uniform across subgroup
  //
  // v8: { sx shx tx shy sy ty w0 w1 }
  //
  // NOTE THAT WE'RE SCALING UP THE TRANSFORM BY:
  //
  //   [ SKC_SUBPIXEL_RESL_X_F32, SKC_SUBPIXEL_RESL_Y_F32, 1.0f ]
  //
  // Coordinates are scaled to subpixel resolution.  All that matters
  // is that continuity is maintained between end path element
  // endpoints.
  //
  // It's the responsibility of the host to ensure that the transforms
  // are properly scaled either via intitializing a transform stack
  // with the subpixel resolution scaled identity or scaling the
  // transform before its loaded by a rasterization grid.
  //
  // FIXME -- horizontal load might be better than this broadcast load
  //
  union skc_transform const tv     = { .f32v8 = transforms[SKC_CMD_RASTERIZE_GET_TRANSFORM(cmd)] }; // uniform load
  union skc_path_clip const cv     = { .f32v4 = clips     [SKC_CMD_RASTERIZE_GET_CLIP(cmd)     ] }; // uniform load
  skc_uint            const cohort = SKC_CMD_RASTERIZE_MASK_COHORT(cmd); // shifted

  skc_rasterize_lines(bp_atomics,
                      bp_elems,
                      bp_ids,
                      bp_mask,
                      cohort_atomics,
                      sk_extent,
                      smem,
                      &nodeword,&id,
                      &tv,&cv,cohort);
}

//
//
//

//
//
//

__kernel
SKC_RASTERIZE_KERNEL_ATTRIBS
void
skc_kernel_rasterize_quads(__global SKC_ATOMIC_UINT         volatile * const bp_atomics,
                           __global union skc_bp_elem                * const bp_elems,
                           __global uint                             * const bp_ids,
                           skc_uint                                    const bp_mask,

                           __global SKC_ATOMIC_UINT         volatile * const cohort_atomics,
                           __global skc_ttsk_s_t                     * const sk_extent,

                           __global float8                  const    * const transforms, // FIXME -- __constant
                           __global float4                  const    * const clips,      // FIXME -- __constant
                           __global union skc_cmd_rasterize const    * const cmds,       // FIXME -- __constant
                           skc_uint                                    const count)
{
  //
  // declare shared memory block
  //
#if ( SKC_RASTERIZE_WORKGROUP_SUBGROUPS == 1 )
  __local struct skc_subgroup_smem volatile                smem[1];
#else
  __local struct skc_subgroup_smem volatile                smem_wg[SKC_RASTERIZE_WORKGROUP_SUBGROUPS];
  __local struct skc_subgroup_smem volatile * const smem = smem_wg + get_sub_group_id();
#endif
  
  //
  // this is a subgroup/warp-centric kernel
  //
  // which subgroup in the grid is this?
  //
  // TAKE NOTE: the Intel GEN compiler appears to be recognizing
  // get_group_id(0) as a uniform but the alternative calculation used
  // when there are multiple subgroups per workgroup is not
  // cooperating and driving spillage elsewhere.
  //
#if ( SKC_RASTERIZE_WORKGROUP_SUBGROUPS == 1 )
  uint const cmd_idx = get_group_id(0);
#else
  uint const cmd_idx = get_group_id(0) * SKC_RASTERIZE_WORKGROUP_SUBGROUPS + get_sub_group_id();
#endif

  //
  // if worksgroups are multi-subgroup then there may be excess
  // subgroups in the final workgroup
  //
  if (cmd_idx >= count)
    return;

#if 0
  if (get_sub_group_local_id() == 0)
    printf("cmd_idx = %u\n",cmd_idx);
#endif

  //
  // load a single command for this subgroup
  //
  union skc_cmd_rasterize const cmd = cmds[cmd_idx];

  //
  // get first block node command word and its subblock
  //
  skc_uint              nodeword = cmd.nodeword; // nodeword has word-addressing
  skc_tagged_block_id_t tag_id   = bp_elems[nodeword].tag_id;
  skc_block_id_t        id       = SKC_TAGGED_BLOCK_ID_GET_ID(tag_id);

  //
  // load transform -- uniform across subgroup
  //
  // v8: { sx shx tx shy sy ty w0 w1 }
  //
  // NOTE THAT WE'RE SCALING UP THE TRANSFORM BY:
  //
  //   [ SKC_SUBPIXEL_RESL_X_F32, SKC_SUBPIXEL_RESL_Y_F32, 1.0f ]
  //
  // Coordinates are scaled to subpixel resolution.  All that matters
  // is that continuity is maintained between end path element
  // endpoints.
  //
  // It's the responsibility of the host to ensure that the transforms
  // are properly scaled either via intitializing a transform stack
  // with the subpixel resolution scaled identity or scaling the
  // transform before its loaded by a rasterization grid.
  //
  // FIXME -- horizontal load might be better than this broadcast load
  //
  union skc_transform const tv     = { .f32v8 = transforms[SKC_CMD_RASTERIZE_GET_TRANSFORM(cmd)] }; // uniform load
  union skc_path_clip const cv     = { .f32v4 = clips     [SKC_CMD_RASTERIZE_GET_CLIP(cmd)     ] }; // uniform load
  skc_uint            const cohort = SKC_CMD_RASTERIZE_MASK_COHORT(cmd); // shifted

  skc_rasterize_quads(bp_atomics,
                      bp_elems,
                      bp_ids,
                      bp_mask,
                      cohort_atomics,
                      sk_extent,
                      smem,
                      &nodeword,&id,
                      &tv,&cv,cohort);
}

//
//
//

__kernel
SKC_RASTERIZE_KERNEL_ATTRIBS
void
skc_kernel_rasterize_cubics(__global SKC_ATOMIC_UINT         volatile * const bp_atomics,
                            __global union skc_bp_elem                * const bp_elems,
                            __global uint                             * const bp_ids,
                            skc_uint                                    const bp_mask,

                            __global SKC_ATOMIC_UINT         volatile * const cohort_atomics,
                            __global skc_ttsk_s_t                     * const sk_extent,

                            __global float8                  const    * const transforms, // FIXME -- __constant
                            __global float4                  const    * const clips,      // FIXME -- __constant
                            __global union skc_cmd_rasterize const    * const cmds,       // FIXME -- __constant
                            skc_uint                                    const count)
{
  //
  // declare shared memory block
  //
#if ( SKC_RASTERIZE_WORKGROUP_SUBGROUPS == 1 )
  __local struct skc_subgroup_smem volatile                smem[1];
#else
  __local struct skc_subgroup_smem volatile                smem_wg[SKC_RASTERIZE_WORKGROUP_SUBGROUPS];
  __local struct skc_subgroup_smem volatile * const smem = smem_wg + get_sub_group_id();
#endif
  
  //
  // this is a subgroup/warp-centric kernel
  //
  // which subgroup in the grid is this?
  //
  // TAKE NOTE: the Intel GEN compiler appears to be recognizing
  // get_group_id(0) as a uniform but the alternative calculation used
  // when there are multiple subgroups per workgroup is not
  // cooperating and driving spillage elsewhere.
  //
#if ( SKC_RASTERIZE_WORKGROUP_SUBGROUPS == 1 )
  uint const cmd_idx = get_group_id(0);
#else
  uint const cmd_idx = get_group_id(0) * SKC_RASTERIZE_WORKGROUP_SUBGROUPS + get_sub_group_id();
#endif

  //
  // if worksgroups are multi-subgroup then there may be excess
  // subgroups in the final workgroup
  //
  if (cmd_idx >= count)
    return;

#if 0
  if (get_sub_group_local_id() == 0)
    printf("cmd_idx = %u\n",cmd_idx);
#endif

  //
  // load a single command for this subgroup
  //
  union skc_cmd_rasterize const cmd = cmds[cmd_idx];

  //
  // get first block node command word and its subblock
  //
  skc_uint              nodeword = cmd.nodeword; // nodeword has word-addressing
  skc_tagged_block_id_t tag_id   = bp_elems[nodeword].tag_id;
  skc_block_id_t        id       = SKC_TAGGED_BLOCK_ID_GET_ID(tag_id);

  //
  // load transform -- uniform across subgroup
  //
  // v8: { sx shx tx shy sy ty w0 w1 }
  //
  // NOTE THAT WE'RE SCALING UP THE TRANSFORM BY:
  //
  //   [ SKC_SUBPIXEL_RESL_X_F32, SKC_SUBPIXEL_RESL_Y_F32, 1.0f ]
  //
  // Coordinates are scaled to subpixel resolution.  All that matters
  // is that continuity is maintained between end path element
  // endpoints.
  //
  // It's the responsibility of the host to ensure that the transforms
  // are properly scaled either via intitializing a transform stack
  // with the subpixel resolution scaled identity or scaling the
  // transform before its loaded by a rasterization grid.
  //
  // FIXME -- horizontal load might be better than this broadcast load
  //
  union skc_transform const tv     = { .f32v8 = transforms[SKC_CMD_RASTERIZE_GET_TRANSFORM(cmd)] }; // uniform load
  union skc_path_clip const cv     = { .f32v4 = clips     [SKC_CMD_RASTERIZE_GET_CLIP(cmd)     ] }; // uniform load
  skc_uint            const cohort = SKC_CMD_RASTERIZE_MASK_COHORT(cmd); // shifted

  skc_rasterize_cubics(bp_atomics,
                       bp_elems,
                       bp_ids,
                       bp_mask,
                       cohort_atomics,
                       sk_extent,
                       smem,
                       &nodeword,&id,
                       &tv,&cv,cohort);
}

//
//
//

__kernel
SKC_RASTERIZE_KERNEL_ATTRIBS
void
skc_kernel_rasterize_rat_quads(__global SKC_ATOMIC_UINT         volatile * const bp_atomics,
                               __global union skc_bp_elem                * const bp_elems,
                               __global uint                             * const bp_ids,
                               skc_uint                                    const bp_mask,

                               __global SKC_ATOMIC_UINT         volatile * const cohort_atomics,
                               __global skc_ttsk_s_t                     * const sk_extent,

                               __global float8                  const    * const transforms, // FIXME -- __constant
                               __global float4                  const    * const clips,      // FIXME -- __constant
                               __global union skc_cmd_rasterize const    * const cmds,       // FIXME -- __constant
                               skc_uint                                    const count)
{
  ;
}

//
//
//

__kernel
SKC_RASTERIZE_KERNEL_ATTRIBS
void
skc_kernel_rasterize_rat_cubics(__global SKC_ATOMIC_UINT         volatile * const bp_atomics,
                                __global union skc_bp_elem                * const bp_elems,
                                __global uint                             * const bp_ids,
                                skc_uint                                    const bp_mask,

                                __global SKC_ATOMIC_UINT         volatile * const cohort_atomics,
                                __global skc_ttsk_s_t                     * const sk_extent,

                                __global float8                  const    * const transforms, // FIXME -- __constant
                                __global float4                  const    * const clips,      // FIXME -- __constant
                                __global union skc_cmd_rasterize const    * const cmds,       // FIXME -- __constant
                                skc_uint                                    const count)
{
  ;
}

//
//
//