summaryrefslogtreecommitdiffstats
path: root/src/VBox/Devices/Graphics/svgadump/svga_dump.c
blob: 6985ce75b4a04e6818846b003776ceade2d65544 (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
/**********************************************************
 * Copyright 2009 VMware, Inc.  All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 **********************************************************/

/**
 * @file
 * Dump SVGA commands.
 *
 * Generated automatically from svga3d_reg.h by svga_dump.py.
 *
 * Modified for VirtualBox.
 */

#include "svga_types.h"
#include "vmsvga_headers_begin.h"
#pragma pack(1) /* VMSVGA structures are '__packed'. */
#include "svga3d_reg.h"
#pragma pack()
#include "vmsvga_headers_end.h"

#include "svga_dump.h"

#define LOG_GROUP LOG_GROUP_DEV_VMSVGA
#include <VBox/log.h>

#define _debug_printf(...) Log7((__VA_ARGS__));

#ifdef LOG_ENABLED
struct SVGAFormatName
{
    SVGA3dSurfaceFormat f;
    const char *pszName;
};

static struct SVGAFormatName g_formats[] =
{
    { SVGA3D_FORMAT_INVALID                , "INVALID" },
    { SVGA3D_X8R8G8B8                      , "X8R8G8B8" },
    { SVGA3D_A8R8G8B8                      , "A8R8G8B8" },
    { SVGA3D_R5G6B5                        , "R5G6B5" },
    { SVGA3D_X1R5G5B5                      , "X1R5G5B5" },
    { SVGA3D_A1R5G5B5                      , "A1R5G5B5" },
    { SVGA3D_A4R4G4B4                      , "A4R4G4B4" },
    { SVGA3D_Z_D32                         , "Z_D32" },
    { SVGA3D_Z_D16                         , "Z_D16" },
    { SVGA3D_Z_D24S8                       , "Z_D24S8" },
    { SVGA3D_Z_D15S1                       , "Z_D15S1" },
    { SVGA3D_LUMINANCE8                    , "LUMINANCE8" },
    { SVGA3D_LUMINANCE4_ALPHA4             , "LUMINANCE4_ALPHA4" },
    { SVGA3D_LUMINANCE16                   , "LUMINANCE16" },
    { SVGA3D_LUMINANCE8_ALPHA8             , "LUMINANCE8_ALPHA8" },
    { SVGA3D_DXT1                          , "DXT1" },
    { SVGA3D_DXT2                          , "DXT2" },
    { SVGA3D_DXT3                          , "DXT3" },
    { SVGA3D_DXT4                          , "DXT4" },
    { SVGA3D_DXT5                          , "DXT5" },
    { SVGA3D_BUMPU8V8                      , "BUMPU8V8" },
    { SVGA3D_BUMPL6V5U5                    , "BUMPL6V5U5" },
    { SVGA3D_BUMPX8L8V8U8                  , "BUMPX8L8V8U8" },
    { SVGA3D_FORMAT_DEAD1                  , "FORMAT_DEAD1" },
    { SVGA3D_ARGB_S10E5                    , "ARGB_S10E5" },
    { SVGA3D_ARGB_S23E8                    , "ARGB_S23E8" },
    { SVGA3D_A2R10G10B10                   , "A2R10G10B10" },
    { SVGA3D_V8U8                          , "V8U8" },
    { SVGA3D_Q8W8V8U8                      , "Q8W8V8U8" },
    { SVGA3D_CxV8U8                        , "CxV8U8" },
    { SVGA3D_X8L8V8U8                      , "X8L8V8U8" },
    { SVGA3D_A2W10V10U10                   , "A2W10V10U10" },
    { SVGA3D_ALPHA8                        , "ALPHA8" },
    { SVGA3D_R_S10E5                       , "R_S10E5" },
    { SVGA3D_R_S23E8                       , "R_S23E8" },
    { SVGA3D_RG_S10E5                      , "RG_S10E5" },
    { SVGA3D_RG_S23E8                      , "RG_S23E8" },
    { SVGA3D_BUFFER                        , "BUFFER" },
    { SVGA3D_Z_D24X8                       , "Z_D24X8" },
    { SVGA3D_V16U16                        , "V16U16" },
    { SVGA3D_G16R16                        , "G16R16" },
    { SVGA3D_A16B16G16R16                  , "A16B16G16R16" },
    { SVGA3D_UYVY                          , "UYVY" },
    { SVGA3D_YUY2                          , "YUY2" },
    { SVGA3D_NV12                          , "NV12" },
    { SVGA3D_FORMAT_DEAD2                  , "FORMAT_DEAD2" },
    { SVGA3D_R32G32B32A32_TYPELESS         , "R32G32B32A32_TYPELESS" },
    { SVGA3D_R32G32B32A32_UINT             , "R32G32B32A32_UINT" },
    { SVGA3D_R32G32B32A32_SINT             , "R32G32B32A32_SINT" },
    { SVGA3D_R32G32B32_TYPELESS            , "R32G32B32_TYPELESS" },
    { SVGA3D_R32G32B32_FLOAT               , "R32G32B32_FLOAT" },
    { SVGA3D_R32G32B32_UINT                , "R32G32B32_UINT" },
    { SVGA3D_R32G32B32_SINT                , "R32G32B32_SINT" },
    { SVGA3D_R16G16B16A16_TYPELESS         , "R16G16B16A16_TYPELESS" },
    { SVGA3D_R16G16B16A16_UINT             , "R16G16B16A16_UINT" },
    { SVGA3D_R16G16B16A16_SNORM            , "R16G16B16A16_SNORM" },
    { SVGA3D_R16G16B16A16_SINT             , "R16G16B16A16_SINT" },
    { SVGA3D_R32G32_TYPELESS               , "R32G32_TYPELESS" },
    { SVGA3D_R32G32_UINT                   , "R32G32_UINT" },
    { SVGA3D_R32G32_SINT                   , "R32G32_SINT" },
    { SVGA3D_R32G8X24_TYPELESS             , "R32G8X24_TYPELESS" },
    { SVGA3D_D32_FLOAT_S8X24_UINT          , "D32_FLOAT_S8X24_UINT" },
    { SVGA3D_R32_FLOAT_X8X24               , "R32_FLOAT_X8X24" },
    { SVGA3D_X32_G8X24_UINT                , "X32_G8X24_UINT" },
    { SVGA3D_R10G10B10A2_TYPELESS          , "R10G10B10A2_TYPELESS" },
    { SVGA3D_R10G10B10A2_UINT              , "R10G10B10A2_UINT" },
    { SVGA3D_R11G11B10_FLOAT               , "R11G11B10_FLOAT" },
    { SVGA3D_R8G8B8A8_TYPELESS             , "R8G8B8A8_TYPELESS" },
    { SVGA3D_R8G8B8A8_UNORM                , "R8G8B8A8_UNORM" },
    { SVGA3D_R8G8B8A8_UNORM_SRGB           , "R8G8B8A8_UNORM_SRGB" },
    { SVGA3D_R8G8B8A8_UINT                 , "R8G8B8A8_UINT" },
    { SVGA3D_R8G8B8A8_SINT                 , "R8G8B8A8_SINT" },
    { SVGA3D_R16G16_TYPELESS               , "R16G16_TYPELESS" },
    { SVGA3D_R16G16_UINT                   , "R16G16_UINT" },
    { SVGA3D_R16G16_SINT                   , "R16G16_SINT" },
    { SVGA3D_R32_TYPELESS                  , "R32_TYPELESS" },
    { SVGA3D_D32_FLOAT                     , "D32_FLOAT" },
    { SVGA3D_R32_UINT                      , "R32_UINT" },
    { SVGA3D_R32_SINT                      , "R32_SINT" },
    { SVGA3D_R24G8_TYPELESS                , "R24G8_TYPELESS" },
    { SVGA3D_D24_UNORM_S8_UINT             , "D24_UNORM_S8_UINT" },
    { SVGA3D_R24_UNORM_X8                  , "R24_UNORM_X8" },
    { SVGA3D_X24_G8_UINT                   , "X24_G8_UINT" },
    { SVGA3D_R8G8_TYPELESS                 , "R8G8_TYPELESS" },
    { SVGA3D_R8G8_UNORM                    , "R8G8_UNORM" },
    { SVGA3D_R8G8_UINT                     , "R8G8_UINT" },
    { SVGA3D_R8G8_SINT                     , "R8G8_SINT" },
    { SVGA3D_R16_TYPELESS                  , "R16_TYPELESS" },
    { SVGA3D_R16_UNORM                     , "R16_UNORM" },
    { SVGA3D_R16_UINT                      , "R16_UINT" },
    { SVGA3D_R16_SNORM                     , "R16_SNORM" },
    { SVGA3D_R16_SINT                      , "R16_SINT" },
    { SVGA3D_R8_TYPELESS                   , "R8_TYPELESS" },
    { SVGA3D_R8_UNORM                      , "R8_UNORM" },
    { SVGA3D_R8_UINT                       , "R8_UINT" },
    { SVGA3D_R8_SNORM                      , "R8_SNORM" },
    { SVGA3D_R8_SINT                       , "R8_SINT" },
    { SVGA3D_P8                            , "P8" },
    { SVGA3D_R9G9B9E5_SHAREDEXP            , "R9G9B9E5_SHAREDEXP" },
    { SVGA3D_R8G8_B8G8_UNORM               , "R8G8_B8G8_UNORM" },
    { SVGA3D_G8R8_G8B8_UNORM               , "G8R8_G8B8_UNORM" },
    { SVGA3D_BC1_TYPELESS                  , "BC1_TYPELESS" },
    { SVGA3D_BC1_UNORM_SRGB                , "BC1_UNORM_SRGB" },
    { SVGA3D_BC2_TYPELESS                  , "BC2_TYPELESS" },
    { SVGA3D_BC2_UNORM_SRGB                , "BC2_UNORM_SRGB" },
    { SVGA3D_BC3_TYPELESS                  , "BC3_TYPELESS" },
    { SVGA3D_BC3_UNORM_SRGB                , "BC3_UNORM_SRGB" },
    { SVGA3D_BC4_TYPELESS                  , "BC4_TYPELESS" },
    { SVGA3D_ATI1                          , "ATI1" },
    { SVGA3D_BC4_SNORM                     , "BC4_SNORM" },
    { SVGA3D_BC5_TYPELESS                  , "BC5_TYPELESS" },
    { SVGA3D_ATI2                          , "ATI2" },
    { SVGA3D_BC5_SNORM                     , "BC5_SNORM" },
    { SVGA3D_R10G10B10_XR_BIAS_A2_UNORM    , "R10G10B10_XR_BIAS_A2_UNORM" },
    { SVGA3D_B8G8R8A8_TYPELESS             , "B8G8R8A8_TYPELESS" },
    { SVGA3D_B8G8R8A8_UNORM_SRGB           , "B8G8R8A8_UNORM_SRGB" },
    { SVGA3D_B8G8R8X8_TYPELESS             , "B8G8R8X8_TYPELESS" },
    { SVGA3D_B8G8R8X8_UNORM_SRGB           , "B8G8R8X8_UNORM_SRGB" },
    { SVGA3D_Z_DF16                        , "Z_DF16" },
    { SVGA3D_Z_DF24                        , "Z_DF24" },
    { SVGA3D_Z_D24S8_INT                   , "Z_D24S8_INT" },
    { SVGA3D_YV12                          , "YV12" },
    { SVGA3D_R32G32B32A32_FLOAT            , "R32G32B32A32_FLOAT" },
    { SVGA3D_R16G16B16A16_FLOAT            , "R16G16B16A16_FLOAT" },
    { SVGA3D_R16G16B16A16_UNORM            , "R16G16B16A16_UNORM" },
    { SVGA3D_R32G32_FLOAT                  , "R32G32_FLOAT" },
    { SVGA3D_R10G10B10A2_UNORM             , "R10G10B10A2_UNORM" },
    { SVGA3D_R8G8B8A8_SNORM                , "R8G8B8A8_SNORM" },
    { SVGA3D_R16G16_FLOAT                  , "R16G16_FLOAT" },
    { SVGA3D_R16G16_UNORM                  , "R16G16_UNORM" },
    { SVGA3D_R16G16_SNORM                  , "R16G16_SNORM" },
    { SVGA3D_R32_FLOAT                     , "R32_FLOAT" },
    { SVGA3D_R8G8_SNORM                    , "R8G8_SNORM" },
    { SVGA3D_R16_FLOAT                     , "R16_FLOAT" },
    { SVGA3D_D16_UNORM                     , "D16_UNORM" },
    { SVGA3D_A8_UNORM                      , "A8_UNORM" },
    { SVGA3D_BC1_UNORM                     , "BC1_UNORM" },
    { SVGA3D_BC2_UNORM                     , "BC2_UNORM" },
    { SVGA3D_BC3_UNORM                     , "BC3_UNORM" },
    { SVGA3D_B5G6R5_UNORM                  , "B5G6R5_UNORM" },
    { SVGA3D_B5G5R5A1_UNORM                , "B5G5R5A1_UNORM" },
    { SVGA3D_B8G8R8A8_UNORM                , "B8G8R8A8_UNORM" },
    { SVGA3D_B8G8R8X8_UNORM                , "B8G8R8X8_UNORM" },
    { SVGA3D_BC4_UNORM                     , "BC4_UNORM" },
    { SVGA3D_BC5_UNORM                     , "BC5_UNORM" },
    { SVGA3D_B4G4R4A4_UNORM                , "B4G4R4A4_UNORM" },
    { SVGA3D_BC6H_TYPELESS                 , "BC6H_TYPELESS" },
    { SVGA3D_BC6H_UF16                     , "BC6H_UF16" },
    { SVGA3D_BC6H_SF16                     , "BC6H_SF16" },
    { SVGA3D_BC7_TYPELESS                  , "BC7_TYPELESS" },
    { SVGA3D_BC7_UNORM                     , "BC7_UNORM" },
    { SVGA3D_BC7_UNORM_SRGB                , "BC7_UNORM_SRGB" },
    { SVGA3D_AYUV                          , "AYUV" },
};


static const char *
svga_format_name(SVGA3dSurfaceFormat format)
{
   if (format < RT_ELEMENTS(g_formats))
      return g_formats[format].pszName;
   return "???";
}


static const char *
shader_name(unsigned type)
{
   switch (type) {
   case SVGA3D_SHADERTYPE_VS:
      return "SVGA3D_SHADERTYPE_VS";
   case SVGA3D_SHADERTYPE_PS:
      return "SVGA3D_SHADERTYPE_PS";
   case SVGA3D_SHADERTYPE_GS:
      return "SVGA3D_SHADERTYPE_GS";
   case SVGA3D_SHADERTYPE_HS:
      return "SVGA3D_SHADERTYPE_HS";
   case SVGA3D_SHADERTYPE_DS:
      return "SVGA3D_SHADERTYPE_DS";
   case SVGA3D_SHADERTYPE_CS:
      return "SVGA3D_SHADERTYPE_CS";
   default:
      return "unknown shader type!";
   }
}


static void
dump_SVGA3dVertexDecl(const SVGA3dVertexDecl *cmd)
{
   switch((*cmd).identity.type) {
   case SVGA3D_DECLTYPE_FLOAT1:
      _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_FLOAT1\n");
      break;
   case SVGA3D_DECLTYPE_FLOAT2:
      _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_FLOAT2\n");
      break;
   case SVGA3D_DECLTYPE_FLOAT3:
      _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_FLOAT3\n");
      break;
   case SVGA3D_DECLTYPE_FLOAT4:
      _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_FLOAT4\n");
      break;
   case SVGA3D_DECLTYPE_D3DCOLOR:
      _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_D3DCOLOR\n");
      break;
   case SVGA3D_DECLTYPE_UBYTE4:
      _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_UBYTE4\n");
      break;
   case SVGA3D_DECLTYPE_SHORT2:
      _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_SHORT2\n");
      break;
   case SVGA3D_DECLTYPE_SHORT4:
      _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_SHORT4\n");
      break;
   case SVGA3D_DECLTYPE_UBYTE4N:
      _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_UBYTE4N\n");
      break;
   case SVGA3D_DECLTYPE_SHORT2N:
      _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_SHORT2N\n");
      break;
   case SVGA3D_DECLTYPE_SHORT4N:
      _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_SHORT4N\n");
      break;
   case SVGA3D_DECLTYPE_USHORT2N:
      _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_USHORT2N\n");
      break;
   case SVGA3D_DECLTYPE_USHORT4N:
      _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_USHORT4N\n");
      break;
   case SVGA3D_DECLTYPE_UDEC3:
      _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_UDEC3\n");
      break;
   case SVGA3D_DECLTYPE_DEC3N:
      _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_DEC3N\n");
      break;
   case SVGA3D_DECLTYPE_FLOAT16_2:
      _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_FLOAT16_2\n");
      break;
   case SVGA3D_DECLTYPE_FLOAT16_4:
      _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_FLOAT16_4\n");
      break;
   case SVGA3D_DECLTYPE_MAX:
      _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_MAX\n");
      break;
   default:
      _debug_printf("\t\t.identity.type = %i\n", (*cmd).identity.type);
      break;
   }
   switch((*cmd).identity.method) {
   case SVGA3D_DECLMETHOD_DEFAULT:
      _debug_printf("\t\t.identity.method = SVGA3D_DECLMETHOD_DEFAULT\n");
      break;
   case SVGA3D_DECLMETHOD_PARTIALU:
      _debug_printf("\t\t.identity.method = SVGA3D_DECLMETHOD_PARTIALU\n");
      break;
   case SVGA3D_DECLMETHOD_PARTIALV:
      _debug_printf("\t\t.identity.method = SVGA3D_DECLMETHOD_PARTIALV\n");
      break;
   case SVGA3D_DECLMETHOD_CROSSUV:
      _debug_printf("\t\t.identity.method = SVGA3D_DECLMETHOD_CROSSUV\n");
      break;
   case SVGA3D_DECLMETHOD_UV:
      _debug_printf("\t\t.identity.method = SVGA3D_DECLMETHOD_UV\n");
      break;
   case SVGA3D_DECLMETHOD_LOOKUP:
      _debug_printf("\t\t.identity.method = SVGA3D_DECLMETHOD_LOOKUP\n");
      break;
   case SVGA3D_DECLMETHOD_LOOKUPPRESAMPLED:
      _debug_printf("\t\t.identity.method = SVGA3D_DECLMETHOD_LOOKUPPRESAMPLED\n");
      break;
   default:
      _debug_printf("\t\t.identity.method = %i\n", (*cmd).identity.method);
      break;
   }
   switch((*cmd).identity.usage) {
   case SVGA3D_DECLUSAGE_POSITION:
      _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_POSITION\n");
      break;
   case SVGA3D_DECLUSAGE_BLENDWEIGHT:
      _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_BLENDWEIGHT\n");
      break;
   case SVGA3D_DECLUSAGE_BLENDINDICES:
      _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_BLENDINDICES\n");
      break;
   case SVGA3D_DECLUSAGE_NORMAL:
      _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_NORMAL\n");
      break;
   case SVGA3D_DECLUSAGE_PSIZE:
      _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_PSIZE\n");
      break;
   case SVGA3D_DECLUSAGE_TEXCOORD:
      _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_TEXCOORD\n");
      break;
   case SVGA3D_DECLUSAGE_TANGENT:
      _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_TANGENT\n");
      break;
   case SVGA3D_DECLUSAGE_BINORMAL:
      _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_BINORMAL\n");
      break;
   case SVGA3D_DECLUSAGE_TESSFACTOR:
      _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_TESSFACTOR\n");
      break;
   case SVGA3D_DECLUSAGE_POSITIONT:
      _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_POSITIONT\n");
      break;
   case SVGA3D_DECLUSAGE_COLOR:
      _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_COLOR\n");
      break;
   case SVGA3D_DECLUSAGE_FOG:
      _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_FOG\n");
      break;
   case SVGA3D_DECLUSAGE_DEPTH:
      _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_DEPTH\n");
      break;
   case SVGA3D_DECLUSAGE_SAMPLE:
      _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_SAMPLE\n");
      break;
   case SVGA3D_DECLUSAGE_MAX:
      _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_MAX\n");
      break;
   default:
      _debug_printf("\t\t.identity.usage = %i\n", (*cmd).identity.usage);
      break;
   }
   _debug_printf("\t\t.identity.usageIndex = %u\n", (*cmd).identity.usageIndex);
   _debug_printf("\t\t.array.surfaceId = %u\n", (*cmd).array.surfaceId);
   _debug_printf("\t\t.array.offset = %u\n", (*cmd).array.offset);
   _debug_printf("\t\t.array.stride = %u\n", (*cmd).array.stride);
   _debug_printf("\t\t.rangeHint.first = %u\n", (*cmd).rangeHint.first);
   _debug_printf("\t\t.rangeHint.last = %u\n", (*cmd).rangeHint.last);
}

static void
dump_SVGA3dTextureState(const SVGA3dTextureState *cmd)
{
   _debug_printf("\t\t.stage = %u\n", (*cmd).stage);
   switch((*cmd).name) {
   case SVGA3D_TS_INVALID:
      _debug_printf("\t\t.name = SVGA3D_TS_INVALID\n");
      break;
   case SVGA3D_TS_BIND_TEXTURE:
      _debug_printf("\t\t.name = SVGA3D_TS_BIND_TEXTURE\n");
      break;
   case SVGA3D_TS_COLOROP:
      _debug_printf("\t\t.name = SVGA3D_TS_COLOROP\n");
      break;
   case SVGA3D_TS_COLORARG1:
      _debug_printf("\t\t.name = SVGA3D_TS_COLORARG1\n");
      break;
   case SVGA3D_TS_COLORARG2:
      _debug_printf("\t\t.name = SVGA3D_TS_COLORARG2\n");
      break;
   case SVGA3D_TS_ALPHAOP:
      _debug_printf("\t\t.name = SVGA3D_TS_ALPHAOP\n");
      break;
   case SVGA3D_TS_ALPHAARG1:
      _debug_printf("\t\t.name = SVGA3D_TS_ALPHAARG1\n");
      break;
   case SVGA3D_TS_ALPHAARG2:
      _debug_printf("\t\t.name = SVGA3D_TS_ALPHAARG2\n");
      break;
   case SVGA3D_TS_ADDRESSU:
      _debug_printf("\t\t.name = SVGA3D_TS_ADDRESSU\n");
      break;
   case SVGA3D_TS_ADDRESSV:
      _debug_printf("\t\t.name = SVGA3D_TS_ADDRESSV\n");
      break;
   case SVGA3D_TS_MIPFILTER:
      _debug_printf("\t\t.name = SVGA3D_TS_MIPFILTER\n");
      break;
   case SVGA3D_TS_MAGFILTER:
      _debug_printf("\t\t.name = SVGA3D_TS_MAGFILTER\n");
      break;
   case SVGA3D_TS_MINFILTER:
      _debug_printf("\t\t.name = SVGA3D_TS_MINFILTER\n");
      break;
   case SVGA3D_TS_BORDERCOLOR:
      _debug_printf("\t\t.name = SVGA3D_TS_BORDERCOLOR\n");
      break;
   case SVGA3D_TS_TEXCOORDINDEX:
      _debug_printf("\t\t.name = SVGA3D_TS_TEXCOORDINDEX\n");
      break;
   case SVGA3D_TS_TEXTURETRANSFORMFLAGS:
      _debug_printf("\t\t.name = SVGA3D_TS_TEXTURETRANSFORMFLAGS\n");
      break;
   case SVGA3D_TS_TEXCOORDGEN:
      _debug_printf("\t\t.name = SVGA3D_TS_TEXCOORDGEN\n");
      break;
   case SVGA3D_TS_BUMPENVMAT00:
      _debug_printf("\t\t.name = SVGA3D_TS_BUMPENVMAT00\n");
      break;
   case SVGA3D_TS_BUMPENVMAT01:
      _debug_printf("\t\t.name = SVGA3D_TS_BUMPENVMAT01\n");
      break;
   case SVGA3D_TS_BUMPENVMAT10:
      _debug_printf("\t\t.name = SVGA3D_TS_BUMPENVMAT10\n");
      break;
   case SVGA3D_TS_BUMPENVMAT11:
      _debug_printf("\t\t.name = SVGA3D_TS_BUMPENVMAT11\n");
      break;
   case SVGA3D_TS_TEXTURE_MIPMAP_LEVEL:
      _debug_printf("\t\t.name = SVGA3D_TS_TEXTURE_MIPMAP_LEVEL\n");
      break;
   case SVGA3D_TS_TEXTURE_LOD_BIAS:
      _debug_printf("\t\t.name = SVGA3D_TS_TEXTURE_LOD_BIAS\n");
      break;
   case SVGA3D_TS_TEXTURE_ANISOTROPIC_LEVEL:
      _debug_printf("\t\t.name = SVGA3D_TS_TEXTURE_ANISOTROPIC_LEVEL\n");
      break;
   case SVGA3D_TS_ADDRESSW:
      _debug_printf("\t\t.name = SVGA3D_TS_ADDRESSW\n");
      break;
   case SVGA3D_TS_GAMMA:
      _debug_printf("\t\t.name = SVGA3D_TS_GAMMA\n");
      break;
   case SVGA3D_TS_BUMPENVLSCALE:
      _debug_printf("\t\t.name = SVGA3D_TS_BUMPENVLSCALE\n");
      break;
   case SVGA3D_TS_BUMPENVLOFFSET:
      _debug_printf("\t\t.name = SVGA3D_TS_BUMPENVLOFFSET\n");
      break;
   case SVGA3D_TS_COLORARG0:
      _debug_printf("\t\t.name = SVGA3D_TS_COLORARG0\n");
      break;
   case SVGA3D_TS_ALPHAARG0:
      _debug_printf("\t\t.name = SVGA3D_TS_ALPHAARG0\n");
      break;
   case SVGA3D_TS_MAX:
      _debug_printf("\t\t.name = SVGA3D_TS_MAX\n");
      break;
   default:
      _debug_printf("\t\t.name = %i\n", (*cmd).name);
      break;
   }
   _debug_printf("\t\t.value = %u\n", (*cmd).value);
   _debug_printf("\t\t.floatValue = %R[float]\n", (*cmd).floatValue);
}

static void
dump_SVGA3dViewport(const SVGA3dViewport *cmd)
{
   _debug_printf("\t\t.x = %R[float]\n", (*cmd).x);
   _debug_printf("\t\t.y = %R[float]\n", (*cmd).y);
   _debug_printf("\t\t.width = %R[float]\n", (*cmd).width);
   _debug_printf("\t\t.height = %R[float]\n", (*cmd).height);
   _debug_printf("\t\t.minDepth = %R[float]\n", (*cmd).minDepth);
   _debug_printf("\t\t.maxDepth = %R[float]\n", (*cmd).maxDepth);
}

static void
dump_SVGA3dSamplerId(const SVGA3dSamplerId *cmd)
{
   _debug_printf("\t\t.id = %u\n", *cmd);
}

static void
dump_SVGA3dSoTarget(const SVGA3dSoTarget *cmd)
{
   _debug_printf("\t\t.sid = %u\n", (*cmd).sid);
   _debug_printf("\t\t.offset = %u\n", (*cmd).offset);
}

static void
dump_SVGA3dInputElementDesc(const SVGA3dInputElementDesc *cmd)
{
   _debug_printf("\t\t.inputSlot = %u\n", (*cmd).inputSlot);
   _debug_printf("\t\t.alignedByteOffset = %u\n", (*cmd).alignedByteOffset);
   _debug_printf("\t\t.format = %s\n", svga_format_name((*cmd).format));
   _debug_printf("\t\t.inputSlotClass = %u\n", (*cmd).inputSlotClass);
   _debug_printf("\t\t.instanceDataStepRate = %u\n", (*cmd).instanceDataStepRate);
   _debug_printf("\t\t.inputRegister = %u\n", (*cmd).inputRegister);
}

static void
dump_SVGA3dVertexBuffer(const SVGA3dVertexBuffer *cmd)
{
   _debug_printf("\t\t.sid = %u\n", (*cmd).sid);
   _debug_printf("\t\t.stride = %u\n", (*cmd).stride);
   _debug_printf("\t\t.offset = %u\n", (*cmd).offset);
}

static void
dump_SVGA3dCopyBox(const SVGA3dCopyBox *cmd)
{
   _debug_printf("\t\t.x = %u\n", (*cmd).x);
   _debug_printf("\t\t.y = %u\n", (*cmd).y);
   _debug_printf("\t\t.z = %u\n", (*cmd).z);
   _debug_printf("\t\t.w = %u\n", (*cmd).w);
   _debug_printf("\t\t.h = %u\n", (*cmd).h);
   _debug_printf("\t\t.d = %u\n", (*cmd).d);
   _debug_printf("\t\t.srcx = %u\n", (*cmd).srcx);
   _debug_printf("\t\t.srcy = %u\n", (*cmd).srcy);
   _debug_printf("\t\t.srcz = %u\n", (*cmd).srcz);
}

static void
dump_SVGA3dShaderResourceViewId(const SVGA3dShaderResourceViewId *id)
{
   _debug_printf("\t\t.id = %u\n", *id);
}

static void
dump_SVGA3dCmdSetClipPlane(const SVGA3dCmdSetClipPlane *cmd)
{
   _debug_printf("\t\t.cid = %u\n", (*cmd).cid);
   _debug_printf("\t\t.index = %u\n", (*cmd).index);
   _debug_printf("\t\t.plane[0] = %R[float]\n", (*cmd).plane[0]);
   _debug_printf("\t\t.plane[1] = %R[float]\n", (*cmd).plane[1]);
   _debug_printf("\t\t.plane[2] = %R[float]\n", (*cmd).plane[2]);
   _debug_printf("\t\t.plane[3] = %R[float]\n", (*cmd).plane[3]);
}

static void
dump_SVGA3dCmdWaitForQuery(const SVGA3dCmdWaitForQuery *cmd)
{
   _debug_printf("\t\t.cid = %u\n", (*cmd).cid);
   switch((*cmd).type) {
   case SVGA3D_QUERYTYPE_OCCLUSION:
      _debug_printf("\t\t.type = SVGA3D_QUERYTYPE_OCCLUSION\n");
      break;
   case SVGA3D_QUERYTYPE_MAX:
      _debug_printf("\t\t.type = SVGA3D_QUERYTYPE_MAX\n");
      break;
   default:
      _debug_printf("\t\t.type = %i\n", (*cmd).type);
      break;
   }
   _debug_printf("\t\t.guestResult.gmrId = %u\n", (*cmd).guestResult.gmrId);
   _debug_printf("\t\t.guestResult.offset = %u\n", (*cmd).guestResult.offset);
}

static void
dump_SVGA3dCmdSetRenderTarget(const SVGA3dCmdSetRenderTarget *cmd)
{
   _debug_printf("\t\t.cid = %u\n", (*cmd).cid);
   switch((*cmd).type) {
   case SVGA3D_RT_DEPTH:
      _debug_printf("\t\t.type = SVGA3D_RT_DEPTH\n");
      break;
   case SVGA3D_RT_STENCIL:
      _debug_printf("\t\t.type = SVGA3D_RT_STENCIL\n");
      break;
   default:
      _debug_printf("\t\t.type = SVGA3D_RT_COLOR%u\n", (*cmd).type - SVGA3D_RT_COLOR0);
      break;
   }
   _debug_printf("\t\t.target.sid = %u\n", (*cmd).target.sid);
   _debug_printf("\t\t.target.face = %u\n", (*cmd).target.face);
   _debug_printf("\t\t.target.mipmap = %u\n", (*cmd).target.mipmap);
}

static void
dump_SVGA3dCmdSetTextureState(const SVGA3dCmdSetTextureState *cmd)
{
   _debug_printf("\t\t.cid = %u\n", (*cmd).cid);
}

static void
dump_SVGA3dCmdSurfaceCopy(const SVGA3dCmdSurfaceCopy *cmd)
{
   _debug_printf("\t\t.src.sid = %u\n", (*cmd).src.sid);
   _debug_printf("\t\t.src.face = %u\n", (*cmd).src.face);
   _debug_printf("\t\t.src.mipmap = %u\n", (*cmd).src.mipmap);
   _debug_printf("\t\t.dest.sid = %u\n", (*cmd).dest.sid);
   _debug_printf("\t\t.dest.face = %u\n", (*cmd).dest.face);
   _debug_printf("\t\t.dest.mipmap = %u\n", (*cmd).dest.mipmap);
}

static void
dump_SVGA3dCmdSetMaterial(const SVGA3dCmdSetMaterial *cmd)
{
   _debug_printf("\t\t.cid = %u\n", (*cmd).cid);
   switch((*cmd).face) {
   case SVGA3D_FACE_INVALID:
      _debug_printf("\t\t.face = SVGA3D_FACE_INVALID\n");
      break;
   case SVGA3D_FACE_NONE:
      _debug_printf("\t\t.face = SVGA3D_FACE_NONE\n");
      break;
   case SVGA3D_FACE_FRONT:
      _debug_printf("\t\t.face = SVGA3D_FACE_FRONT\n");
      break;
   case SVGA3D_FACE_BACK:
      _debug_printf("\t\t.face = SVGA3D_FACE_BACK\n");
      break;
   case SVGA3D_FACE_FRONT_BACK:
      _debug_printf("\t\t.face = SVGA3D_FACE_FRONT_BACK\n");
      break;
   case SVGA3D_FACE_MAX:
      _debug_printf("\t\t.face = SVGA3D_FACE_MAX\n");
      break;
   default:
      _debug_printf("\t\t.face = %i\n", (*cmd).face);
      break;
   }
   _debug_printf("\t\t.material.diffuse[0] = %R[float]\n", (*cmd).material.diffuse[0]);
   _debug_printf("\t\t.material.diffuse[1] = %R[float]\n", (*cmd).material.diffuse[1]);
   _debug_printf("\t\t.material.diffuse[2] = %R[float]\n", (*cmd).material.diffuse[2]);
   _debug_printf("\t\t.material.diffuse[3] = %R[float]\n", (*cmd).material.diffuse[3]);
   _debug_printf("\t\t.material.ambient[0] = %R[float]\n", (*cmd).material.ambient[0]);
   _debug_printf("\t\t.material.ambient[1] = %R[float]\n", (*cmd).material.ambient[1]);
   _debug_printf("\t\t.material.ambient[2] = %R[float]\n", (*cmd).material.ambient[2]);
   _debug_printf("\t\t.material.ambient[3] = %R[float]\n", (*cmd).material.ambient[3]);
   _debug_printf("\t\t.material.specular[0] = %R[float]\n", (*cmd).material.specular[0]);
   _debug_printf("\t\t.material.specular[1] = %R[float]\n", (*cmd).material.specular[1]);
   _debug_printf("\t\t.material.specular[2] = %R[float]\n", (*cmd).material.specular[2]);
   _debug_printf("\t\t.material.specular[3] = %R[float]\n", (*cmd).material.specular[3]);
   _debug_printf("\t\t.material.emissive[0] = %R[float]\n", (*cmd).material.emissive[0]);
   _debug_printf("\t\t.material.emissive[1] = %R[float]\n", (*cmd).material.emissive[1]);
   _debug_printf("\t\t.material.emissive[2] = %R[float]\n", (*cmd).material.emissive[2]);
   _debug_printf("\t\t.material.emissive[3] = %R[float]\n", (*cmd).material.emissive[3]);
   _debug_printf("\t\t.material.shininess = %R[float]\n", (*cmd).material.shininess);
}

static void
dump_SVGA3dCmdSetLightData(const SVGA3dCmdSetLightData *cmd)
{
   _debug_printf("\t\t.cid = %u\n", (*cmd).cid);
   _debug_printf("\t\t.index = %u\n", (*cmd).index);
   switch((*cmd).data.type) {
   case SVGA3D_LIGHTTYPE_INVALID:
      _debug_printf("\t\t.data.type = SVGA3D_LIGHTTYPE_INVALID\n");
      break;
   case SVGA3D_LIGHTTYPE_POINT:
      _debug_printf("\t\t.data.type = SVGA3D_LIGHTTYPE_POINT\n");
      break;
   case SVGA3D_LIGHTTYPE_SPOT1:
      _debug_printf("\t\t.data.type = SVGA3D_LIGHTTYPE_SPOT1\n");
      break;
   case SVGA3D_LIGHTTYPE_SPOT2:
      _debug_printf("\t\t.data.type = SVGA3D_LIGHTTYPE_SPOT2\n");
      break;
   case SVGA3D_LIGHTTYPE_DIRECTIONAL:
      _debug_printf("\t\t.data.type = SVGA3D_LIGHTTYPE_DIRECTIONAL\n");
      break;
   case SVGA3D_LIGHTTYPE_MAX:
      _debug_printf("\t\t.data.type = SVGA3D_LIGHTTYPE_MAX\n");
      break;
   default:
      _debug_printf("\t\t.data.type = %i\n", (*cmd).data.type);
      break;
   }
   _debug_printf("\t\t.data.inWorldSpace = %u\n", (*cmd).data.inWorldSpace);
   _debug_printf("\t\t.data.diffuse[0] = %R[float]\n", (*cmd).data.diffuse[0]);
   _debug_printf("\t\t.data.diffuse[1] = %R[float]\n", (*cmd).data.diffuse[1]);
   _debug_printf("\t\t.data.diffuse[2] = %R[float]\n", (*cmd).data.diffuse[2]);
   _debug_printf("\t\t.data.diffuse[3] = %R[float]\n", (*cmd).data.diffuse[3]);
   _debug_printf("\t\t.data.specular[0] = %R[float]\n", (*cmd).data.specular[0]);
   _debug_printf("\t\t.data.specular[1] = %R[float]\n", (*cmd).data.specular[1]);
   _debug_printf("\t\t.data.specular[2] = %R[float]\n", (*cmd).data.specular[2]);
   _debug_printf("\t\t.data.specular[3] = %R[float]\n", (*cmd).data.specular[3]);
   _debug_printf("\t\t.data.ambient[0] = %R[float]\n", (*cmd).data.ambient[0]);
   _debug_printf("\t\t.data.ambient[1] = %R[float]\n", (*cmd).data.ambient[1]);
   _debug_printf("\t\t.data.ambient[2] = %R[float]\n", (*cmd).data.ambient[2]);
   _debug_printf("\t\t.data.ambient[3] = %R[float]\n", (*cmd).data.ambient[3]);
   _debug_printf("\t\t.data.position[0] = %R[float]\n", (*cmd).data.position[0]);
   _debug_printf("\t\t.data.position[1] = %R[float]\n", (*cmd).data.position[1]);
   _debug_printf("\t\t.data.position[2] = %R[float]\n", (*cmd).data.position[2]);
   _debug_printf("\t\t.data.position[3] = %R[float]\n", (*cmd).data.position[3]);
   _debug_printf("\t\t.data.direction[0] = %R[float]\n", (*cmd).data.direction[0]);
   _debug_printf("\t\t.data.direction[1] = %R[float]\n", (*cmd).data.direction[1]);
   _debug_printf("\t\t.data.direction[2] = %R[float]\n", (*cmd).data.direction[2]);
   _debug_printf("\t\t.data.direction[3] = %R[float]\n", (*cmd).data.direction[3]);
   _debug_printf("\t\t.data.range = %R[float]\n", (*cmd).data.range);
   _debug_printf("\t\t.data.falloff = %R[float]\n", (*cmd).data.falloff);
   _debug_printf("\t\t.data.attenuation0 = %R[float]\n", (*cmd).data.attenuation0);
   _debug_printf("\t\t.data.attenuation1 = %R[float]\n", (*cmd).data.attenuation1);
   _debug_printf("\t\t.data.attenuation2 = %R[float]\n", (*cmd).data.attenuation2);
   _debug_printf("\t\t.data.theta = %R[float]\n", (*cmd).data.theta);
   _debug_printf("\t\t.data.phi = %R[float]\n", (*cmd).data.phi);
}

static void
dump_SVGA3dCmdSetViewport(const SVGA3dCmdSetViewport *cmd)
{
   _debug_printf("\t\t.cid = %u\n", (*cmd).cid);
   _debug_printf("\t\t.rect.x = %u\n", (*cmd).rect.x);
   _debug_printf("\t\t.rect.y = %u\n", (*cmd).rect.y);
   _debug_printf("\t\t.rect.w = %u\n", (*cmd).rect.w);
   _debug_printf("\t\t.rect.h = %u\n", (*cmd).rect.h);
}

static void
dump_SVGA3dCmdSetScissorRect(const SVGA3dCmdSetScissorRect *cmd)
{
   _debug_printf("\t\t.cid = %u\n", (*cmd).cid);
   _debug_printf("\t\t.rect.x = %u\n", (*cmd).rect.x);
   _debug_printf("\t\t.rect.y = %u\n", (*cmd).rect.y);
   _debug_printf("\t\t.rect.w = %u\n", (*cmd).rect.w);
   _debug_printf("\t\t.rect.h = %u\n", (*cmd).rect.h);
}

static void
dump_SVGA3dCopyRect(const SVGA3dCopyRect *cmd)
{
   _debug_printf("\t\t.x = %u\n", (*cmd).x);
   _debug_printf("\t\t.y = %u\n", (*cmd).y);
   _debug_printf("\t\t.w = %u\n", (*cmd).w);
   _debug_printf("\t\t.h = %u\n", (*cmd).h);
   _debug_printf("\t\t.srcx = %u\n", (*cmd).srcx);
   _debug_printf("\t\t.srcy = %u\n", (*cmd).srcy);
}

static void
dump_SVGA3dCmdSetShader(const SVGA3dCmdSetShader *cmd)
{
   _debug_printf("\t\t.cid = %u\n", (*cmd).cid);
   _debug_printf("\t\t.type = %s\n", shader_name(cmd->type));
   _debug_printf("\t\t.shid = %u\n", (*cmd).shid);
}

static void
dump_SVGA3dCmdEndQuery(const SVGA3dCmdEndQuery *cmd)
{
   _debug_printf("\t\t.cid = %u\n", (*cmd).cid);
   switch((*cmd).type) {
   case SVGA3D_QUERYTYPE_OCCLUSION:
      _debug_printf("\t\t.type = SVGA3D_QUERYTYPE_OCCLUSION\n");
      break;
   case SVGA3D_QUERYTYPE_MAX:
      _debug_printf("\t\t.type = SVGA3D_QUERYTYPE_MAX\n");
      break;
   default:
      _debug_printf("\t\t.type = %i\n", (*cmd).type);
      break;
   }
   _debug_printf("\t\t.guestResult.gmrId = %u\n", (*cmd).guestResult.gmrId);
   _debug_printf("\t\t.guestResult.offset = %u\n", (*cmd).guestResult.offset);
}

static void
dump_SVGA3dSize(const SVGA3dSize *cmd)
{
   _debug_printf("\t\t.width = %u\n", (*cmd).width);
   _debug_printf("\t\t.height = %u\n", (*cmd).height);
   _debug_printf("\t\t.depth = %u\n", (*cmd).depth);
}

static void
dump_SVGA3dCmdDestroySurface(const SVGA3dCmdDestroySurface *cmd)
{
   _debug_printf("\t\t.sid = %u\n", (*cmd).sid);
}

static void
dump_SVGA3dCmdDefineContext(const SVGA3dCmdDefineContext *cmd)
{
   _debug_printf("\t\t.cid = %u\n", (*cmd).cid);
}

static void
dump_SVGA3dRect(const SVGA3dRect *cmd)
{
   _debug_printf("\t\t.x = %u\n", (*cmd).x);
   _debug_printf("\t\t.y = %u\n", (*cmd).y);
   _debug_printf("\t\t.w = %u\n", (*cmd).w);
   _debug_printf("\t\t.h = %u\n", (*cmd).h);
}

static void
dump_SVGA3dCmdBeginQuery(const SVGA3dCmdBeginQuery *cmd)
{
   _debug_printf("\t\t.cid = %u\n", (*cmd).cid);
   switch((*cmd).type) {
   case SVGA3D_QUERYTYPE_OCCLUSION:
      _debug_printf("\t\t.type = SVGA3D_QUERYTYPE_OCCLUSION\n");
      break;
   case SVGA3D_QUERYTYPE_MAX:
      _debug_printf("\t\t.type = SVGA3D_QUERYTYPE_MAX\n");
      break;
   default:
      _debug_printf("\t\t.type = %i\n", (*cmd).type);
      break;
   }
}

static void
dump_SVGA3dRenderState(const SVGA3dRenderState *cmd)
{
   switch((*cmd).state) {
   case SVGA3D_RS_INVALID:
      _debug_printf("\t\t.state = SVGA3D_RS_INVALID\n");
      break;
   case SVGA3D_RS_ZENABLE:
      _debug_printf("\t\t.state = SVGA3D_RS_ZENABLE\n");
      break;
   case SVGA3D_RS_ZWRITEENABLE:
      _debug_printf("\t\t.state = SVGA3D_RS_ZWRITEENABLE\n");
      break;
   case SVGA3D_RS_ALPHATESTENABLE:
      _debug_printf("\t\t.state = SVGA3D_RS_ALPHATESTENABLE\n");
      break;
   case SVGA3D_RS_DITHERENABLE:
      _debug_printf("\t\t.state = SVGA3D_RS_DITHERENABLE\n");
      break;
   case SVGA3D_RS_BLENDENABLE:
      _debug_printf("\t\t.state = SVGA3D_RS_BLENDENABLE\n");
      break;
   case SVGA3D_RS_FOGENABLE:
      _debug_printf("\t\t.state = SVGA3D_RS_FOGENABLE\n");
      break;
   case SVGA3D_RS_SPECULARENABLE:
      _debug_printf("\t\t.state = SVGA3D_RS_SPECULARENABLE\n");
      break;
   case SVGA3D_RS_STENCILENABLE:
      _debug_printf("\t\t.state = SVGA3D_RS_STENCILENABLE\n");
      break;
   case SVGA3D_RS_LIGHTINGENABLE:
      _debug_printf("\t\t.state = SVGA3D_RS_LIGHTINGENABLE\n");
      break;
   case SVGA3D_RS_NORMALIZENORMALS:
      _debug_printf("\t\t.state = SVGA3D_RS_NORMALIZENORMALS\n");
      break;
   case SVGA3D_RS_POINTSPRITEENABLE:
      _debug_printf("\t\t.state = SVGA3D_RS_POINTSPRITEENABLE\n");
      break;
   case SVGA3D_RS_POINTSCALEENABLE:
      _debug_printf("\t\t.state = SVGA3D_RS_POINTSCALEENABLE\n");
      break;
   case SVGA3D_RS_STENCILREF:
      _debug_printf("\t\t.state = SVGA3D_RS_STENCILREF\n");
      break;
   case SVGA3D_RS_STENCILMASK:
      _debug_printf("\t\t.state = SVGA3D_RS_STENCILMASK\n");
      break;
   case SVGA3D_RS_STENCILWRITEMASK:
      _debug_printf("\t\t.state = SVGA3D_RS_STENCILWRITEMASK\n");
      break;
   case SVGA3D_RS_FOGSTART:
      _debug_printf("\t\t.state = SVGA3D_RS_FOGSTART\n");
      break;
   case SVGA3D_RS_FOGEND:
      _debug_printf("\t\t.state = SVGA3D_RS_FOGEND\n");
      break;
   case SVGA3D_RS_FOGDENSITY:
      _debug_printf("\t\t.state = SVGA3D_RS_FOGDENSITY\n");
      break;
   case SVGA3D_RS_POINTSIZE:
      _debug_printf("\t\t.state = SVGA3D_RS_POINTSIZE\n");
      break;
   case SVGA3D_RS_POINTSIZEMIN:
      _debug_printf("\t\t.state = SVGA3D_RS_POINTSIZEMIN\n");
      break;
   case SVGA3D_RS_POINTSIZEMAX:
      _debug_printf("\t\t.state = SVGA3D_RS_POINTSIZEMAX\n");
      break;
   case SVGA3D_RS_POINTSCALE_A:
      _debug_printf("\t\t.state = SVGA3D_RS_POINTSCALE_A\n");
      break;
   case SVGA3D_RS_POINTSCALE_B:
      _debug_printf("\t\t.state = SVGA3D_RS_POINTSCALE_B\n");
      break;
   case SVGA3D_RS_POINTSCALE_C:
      _debug_printf("\t\t.state = SVGA3D_RS_POINTSCALE_C\n");
      break;
   case SVGA3D_RS_FOGCOLOR:
      _debug_printf("\t\t.state = SVGA3D_RS_FOGCOLOR\n");
      break;
   case SVGA3D_RS_AMBIENT:
      _debug_printf("\t\t.state = SVGA3D_RS_AMBIENT\n");
      break;
   case SVGA3D_RS_CLIPPLANEENABLE:
      _debug_printf("\t\t.state = SVGA3D_RS_CLIPPLANEENABLE\n");
      break;
   case SVGA3D_RS_FOGMODE:
      _debug_printf("\t\t.state = SVGA3D_RS_FOGMODE\n");
      break;
   case SVGA3D_RS_FILLMODE:
      _debug_printf("\t\t.state = SVGA3D_RS_FILLMODE\n");
      break;
   case SVGA3D_RS_SHADEMODE:
      _debug_printf("\t\t.state = SVGA3D_RS_SHADEMODE\n");
      break;
   case SVGA3D_RS_LINEPATTERN:
      _debug_printf("\t\t.state = SVGA3D_RS_LINEPATTERN\n");
      break;
   case SVGA3D_RS_SRCBLEND:
      _debug_printf("\t\t.state = SVGA3D_RS_SRCBLEND\n");
      break;
   case SVGA3D_RS_DSTBLEND:
      _debug_printf("\t\t.state = SVGA3D_RS_DSTBLEND\n");
      break;
   case SVGA3D_RS_BLENDEQUATION:
      _debug_printf("\t\t.state = SVGA3D_RS_BLENDEQUATION\n");
      break;
   case SVGA3D_RS_CULLMODE:
      _debug_printf("\t\t.state = SVGA3D_RS_CULLMODE\n");
      break;
   case SVGA3D_RS_ZFUNC:
      _debug_printf("\t\t.state = SVGA3D_RS_ZFUNC\n");
      break;
   case SVGA3D_RS_ALPHAFUNC:
      _debug_printf("\t\t.state = SVGA3D_RS_ALPHAFUNC\n");
      break;
   case SVGA3D_RS_STENCILFUNC:
      _debug_printf("\t\t.state = SVGA3D_RS_STENCILFUNC\n");
      break;
   case SVGA3D_RS_STENCILFAIL:
      _debug_printf("\t\t.state = SVGA3D_RS_STENCILFAIL\n");
      break;
   case SVGA3D_RS_STENCILZFAIL:
      _debug_printf("\t\t.state = SVGA3D_RS_STENCILZFAIL\n");
      break;
   case SVGA3D_RS_STENCILPASS:
      _debug_printf("\t\t.state = SVGA3D_RS_STENCILPASS\n");
      break;
   case SVGA3D_RS_ALPHAREF:
      _debug_printf("\t\t.state = SVGA3D_RS_ALPHAREF\n");
      break;
   case SVGA3D_RS_FRONTWINDING:
      _debug_printf("\t\t.state = SVGA3D_RS_FRONTWINDING\n");
      break;
   case SVGA3D_RS_COORDINATETYPE:
      _debug_printf("\t\t.state = SVGA3D_RS_COORDINATETYPE\n");
      break;
   case SVGA3D_RS_ZBIAS:
      _debug_printf("\t\t.state = SVGA3D_RS_ZBIAS\n");
      break;
   case SVGA3D_RS_RANGEFOGENABLE:
      _debug_printf("\t\t.state = SVGA3D_RS_RANGEFOGENABLE\n");
      break;
   case SVGA3D_RS_COLORWRITEENABLE:
      _debug_printf("\t\t.state = SVGA3D_RS_COLORWRITEENABLE\n");
      break;
   case SVGA3D_RS_VERTEXMATERIALENABLE:
      _debug_printf("\t\t.state = SVGA3D_RS_VERTEXMATERIALENABLE\n");
      break;
   case SVGA3D_RS_DIFFUSEMATERIALSOURCE:
      _debug_printf("\t\t.state = SVGA3D_RS_DIFFUSEMATERIALSOURCE\n");
      break;
   case SVGA3D_RS_SPECULARMATERIALSOURCE:
      _debug_printf("\t\t.state = SVGA3D_RS_SPECULARMATERIALSOURCE\n");
      break;
   case SVGA3D_RS_AMBIENTMATERIALSOURCE:
      _debug_printf("\t\t.state = SVGA3D_RS_AMBIENTMATERIALSOURCE\n");
      break;
   case SVGA3D_RS_EMISSIVEMATERIALSOURCE:
      _debug_printf("\t\t.state = SVGA3D_RS_EMISSIVEMATERIALSOURCE\n");
      break;
   case SVGA3D_RS_TEXTUREFACTOR:
      _debug_printf("\t\t.state = SVGA3D_RS_TEXTUREFACTOR\n");
      break;
   case SVGA3D_RS_LOCALVIEWER:
      _debug_printf("\t\t.state = SVGA3D_RS_LOCALVIEWER\n");
      break;
   case SVGA3D_RS_SCISSORTESTENABLE:
      _debug_printf("\t\t.state = SVGA3D_RS_SCISSORTESTENABLE\n");
      break;
   case SVGA3D_RS_BLENDCOLOR:
      _debug_printf("\t\t.state = SVGA3D_RS_BLENDCOLOR\n");
      break;
   case SVGA3D_RS_STENCILENABLE2SIDED:
      _debug_printf("\t\t.state = SVGA3D_RS_STENCILENABLE2SIDED\n");
      break;
   case SVGA3D_RS_CCWSTENCILFUNC:
      _debug_printf("\t\t.state = SVGA3D_RS_CCWSTENCILFUNC\n");
      break;
   case SVGA3D_RS_CCWSTENCILFAIL:
      _debug_printf("\t\t.state = SVGA3D_RS_CCWSTENCILFAIL\n");
      break;
   case SVGA3D_RS_CCWSTENCILZFAIL:
      _debug_printf("\t\t.state = SVGA3D_RS_CCWSTENCILZFAIL\n");
      break;
   case SVGA3D_RS_CCWSTENCILPASS:
      _debug_printf("\t\t.state = SVGA3D_RS_CCWSTENCILPASS\n");
      break;
   case SVGA3D_RS_VERTEXBLEND:
      _debug_printf("\t\t.state = SVGA3D_RS_VERTEXBLEND\n");
      break;
   case SVGA3D_RS_SLOPESCALEDEPTHBIAS:
      _debug_printf("\t\t.state = SVGA3D_RS_SLOPESCALEDEPTHBIAS\n");
      break;
   case SVGA3D_RS_DEPTHBIAS:
      _debug_printf("\t\t.state = SVGA3D_RS_DEPTHBIAS\n");
      break;
   case SVGA3D_RS_OUTPUTGAMMA:
      _debug_printf("\t\t.state = SVGA3D_RS_OUTPUTGAMMA\n");
      break;
   case SVGA3D_RS_ZVISIBLE:
      _debug_printf("\t\t.state = SVGA3D_RS_ZVISIBLE\n");
      break;
   case SVGA3D_RS_LASTPIXEL:
      _debug_printf("\t\t.state = SVGA3D_RS_LASTPIXEL\n");
      break;
   case SVGA3D_RS_CLIPPING:
      _debug_printf("\t\t.state = SVGA3D_RS_CLIPPING\n");
      break;
   case SVGA3D_RS_WRAP0:
      _debug_printf("\t\t.state = SVGA3D_RS_WRAP0\n");
      break;
   case SVGA3D_RS_WRAP1:
      _debug_printf("\t\t.state = SVGA3D_RS_WRAP1\n");
      break;
   case SVGA3D_RS_WRAP2:
      _debug_printf("\t\t.state = SVGA3D_RS_WRAP2\n");
      break;
   case SVGA3D_RS_WRAP3:
      _debug_printf("\t\t.state = SVGA3D_RS_WRAP3\n");
      break;
   case SVGA3D_RS_WRAP4:
      _debug_printf("\t\t.state = SVGA3D_RS_WRAP4\n");
      break;
   case SVGA3D_RS_WRAP5:
      _debug_printf("\t\t.state = SVGA3D_RS_WRAP5\n");
      break;
   case SVGA3D_RS_WRAP6:
      _debug_printf("\t\t.state = SVGA3D_RS_WRAP6\n");
      break;
   case SVGA3D_RS_WRAP7:
      _debug_printf("\t\t.state = SVGA3D_RS_WRAP7\n");
      break;
   case SVGA3D_RS_WRAP8:
      _debug_printf("\t\t.state = SVGA3D_RS_WRAP8\n");
      break;
   case SVGA3D_RS_WRAP9:
      _debug_printf("\t\t.state = SVGA3D_RS_WRAP9\n");
      break;
   case SVGA3D_RS_WRAP10:
      _debug_printf("\t\t.state = SVGA3D_RS_WRAP10\n");
      break;
   case SVGA3D_RS_WRAP11:
      _debug_printf("\t\t.state = SVGA3D_RS_WRAP11\n");
      break;
   case SVGA3D_RS_WRAP12:
      _debug_printf("\t\t.state = SVGA3D_RS_WRAP12\n");
      break;
   case SVGA3D_RS_WRAP13:
      _debug_printf("\t\t.state = SVGA3D_RS_WRAP13\n");
      break;
   case SVGA3D_RS_WRAP14:
      _debug_printf("\t\t.state = SVGA3D_RS_WRAP14\n");
      break;
   case SVGA3D_RS_WRAP15:
      _debug_printf("\t\t.state = SVGA3D_RS_WRAP15\n");
      break;
   case SVGA3D_RS_MULTISAMPLEANTIALIAS:
      _debug_printf("\t\t.state = SVGA3D_RS_MULTISAMPLEANTIALIAS\n");
      break;
   case SVGA3D_RS_MULTISAMPLEMASK:
      _debug_printf("\t\t.state = SVGA3D_RS_MULTISAMPLEMASK\n");
      break;
   case SVGA3D_RS_INDEXEDVERTEXBLENDENABLE:
      _debug_printf("\t\t.state = SVGA3D_RS_INDEXEDVERTEXBLENDENABLE\n");
      break;
   case SVGA3D_RS_TWEENFACTOR:
      _debug_printf("\t\t.state = SVGA3D_RS_TWEENFACTOR\n");
      break;
   case SVGA3D_RS_ANTIALIASEDLINEENABLE:
      _debug_printf("\t\t.state = SVGA3D_RS_ANTIALIASEDLINEENABLE\n");
      break;
   case SVGA3D_RS_COLORWRITEENABLE1:
      _debug_printf("\t\t.state = SVGA3D_RS_COLORWRITEENABLE1\n");
      break;
   case SVGA3D_RS_COLORWRITEENABLE2:
      _debug_printf("\t\t.state = SVGA3D_RS_COLORWRITEENABLE2\n");
      break;
   case SVGA3D_RS_COLORWRITEENABLE3:
      _debug_printf("\t\t.state = SVGA3D_RS_COLORWRITEENABLE3\n");
      break;
   case SVGA3D_RS_SEPARATEALPHABLENDENABLE:
      _debug_printf("\t\t.state = SVGA3D_RS_SEPARATEALPHABLENDENABLE\n");
      break;
   case SVGA3D_RS_SRCBLENDALPHA:
      _debug_printf("\t\t.state = SVGA3D_RS_SRCBLENDALPHA\n");
      break;
   case SVGA3D_RS_DSTBLENDALPHA:
      _debug_printf("\t\t.state = SVGA3D_RS_DSTBLENDALPHA\n");
      break;
   case SVGA3D_RS_BLENDEQUATIONALPHA:
      _debug_printf("\t\t.state = SVGA3D_RS_BLENDEQUATIONALPHA\n");
      break;
   case SVGA3D_RS_MAX:
      _debug_printf("\t\t.state = SVGA3D_RS_MAX\n");
      break;
   default:
      _debug_printf("\t\t.state = %i\n", (*cmd).state);
      break;
   }
   _debug_printf("\t\t.uintValue = %u\n", (*cmd).uintValue);
   _debug_printf("\t\t.floatValue = %R[float]\n", (*cmd).floatValue);
}

static void
dump_SVGA3dVertexDivisor(const SVGA3dVertexDivisor *cmd)
{
   _debug_printf("\t\t.value = %u\n", (*cmd).value);
   _debug_printf("\t\t.count = %u\n", (*cmd).count);
   _debug_printf("\t\t.indexedData = %u\n", (*cmd).indexedData);
   _debug_printf("\t\t.instanceData = %u\n", (*cmd).instanceData);
}

static void
dump_SVGA3dCmdDefineShader(const SVGA3dCmdDefineShader *cmd)
{
   _debug_printf("\t\t.cid = %u\n", (*cmd).cid);
   _debug_printf("\t\t.shid = %u\n", (*cmd).shid);
   switch((*cmd).type) {
   case SVGA3D_SHADERTYPE_VS:
      _debug_printf("\t\t.type = SVGA3D_SHADERTYPE_VS\n");
      break;
   case SVGA3D_SHADERTYPE_PS:
      _debug_printf("\t\t.type = SVGA3D_SHADERTYPE_PS\n");
      break;
   default:
      _debug_printf("\t\t.type = %i\n", (*cmd).type);
      break;
   }
}

static void
dump_constants(SVGA3dShaderConstType type, unsigned start,
               unsigned numConsts, const void *buf)
{
   unsigned i;
   const float (*fvalues)[4];
   const int32 (*ivalues)[4];

   switch (type) {
   case SVGA3D_CONST_TYPE_FLOAT:
      _debug_printf("\t\t.ctype = SVGA3D_CONST_TYPE_FLOAT\n");
      fvalues = (const float (*)[4]) buf;
      for (i = 0; i < numConsts; ++i) {
         _debug_printf("\t\t.values[%u] = {%R[float], %R[float], %R[float], %R[float]}\n",
                       start + i, 
                       fvalues[i][0],
                       fvalues[i][1],
                       fvalues[i][2],
                       fvalues[i][3]);
      }
      break;
   case SVGA3D_CONST_TYPE_INT:
      _debug_printf("\t\t.ctype = SVGA3D_CONST_TYPE_INT\n");
      ivalues = (const int32 (*)[4]) buf;
      for (i = 0; i < numConsts; ++i) {
         _debug_printf("\t\t.values[%u] = {%i, %i, %i, %i}\n",
                       start + i,
                       ivalues[i][0],
                       ivalues[i][1],
                       ivalues[i][2],
                       ivalues[i][3]);
      }
      break;
   case SVGA3D_CONST_TYPE_BOOL:
      _debug_printf("\t\t.ctype = SVGA3D_CONST_TYPE_BOOL\n");
      ivalues = (const int32 (*)[4]) buf;
      for (i = 0; i < numConsts; ++i) {
         _debug_printf("\t\t.values[%u] = {%i, %i, %i, %i}\n",
                       start + i,
                       ivalues[i][0],
                       ivalues[i][1],
                       ivalues[i][2],
                       ivalues[i][3]);
      }
      break;
   default:
      _debug_printf("\t\t.ctype = %i\n", type);
      ivalues = (const int32 (*)[4]) buf;
      for (i = 0; i < numConsts; ++i) {
         _debug_printf("\t\t.values[%u] = {%i, %i, %i, %i}\n",
                       start + i,
                       ivalues[i][0],
                       ivalues[i][1],
                       ivalues[i][2],
                       ivalues[i][3]);
      }
      break;
   }
}

static void
dump_SVGA3dCmdSetShaderConst(const SVGA3dCmdSetShaderConst *cmd, uint32 numConsts)
{
   _debug_printf("\t\t.cid = %u\n", (*cmd).cid);
   _debug_printf("\t\t.reg = %u\n", (*cmd).reg);
   _debug_printf("\t\t.type = %s\n", shader_name((*cmd).type));
   dump_constants((*cmd).ctype, cmd->reg, numConsts, cmd->values);
}

static void
dump_SVGA3dCmdSetGBShaderConstInline(const SVGA3dCmdSetGBShaderConstInline *cmd, uint32 numConsts)
{
   _debug_printf("\t\t.cid = %u\n", (*cmd).cid);
   _debug_printf("\t\t.reg = %u\n", (*cmd).regStart);
   _debug_printf("\t\t.type = %s\n", shader_name((*cmd).shaderType));
   dump_constants((*cmd).constType, cmd->regStart, numConsts, &cmd[1]);
}


static void
dump_SVGA3dCmdSetZRange(const SVGA3dCmdSetZRange *cmd)
{
   _debug_printf("\t\t.cid = %u\n", (*cmd).cid);
   _debug_printf("\t\t.zRange.min = %R[float]\n", (*cmd).zRange.min);
   _debug_printf("\t\t.zRange.max = %R[float]\n", (*cmd).zRange.max);
}

static void
dump_SVGA3dCmdDrawPrimitives(const SVGA3dCmdDrawPrimitives *cmd)
{
   _debug_printf("\t\t.cid = %u\n", (*cmd).cid);
   _debug_printf("\t\t.numVertexDecls = %u\n", (*cmd).numVertexDecls);
   _debug_printf("\t\t.numRanges = %u\n", (*cmd).numRanges);
}

static void
dump_SVGA3dCmdSetLightEnabled(const SVGA3dCmdSetLightEnabled *cmd)
{
   _debug_printf("\t\t.cid = %u\n", (*cmd).cid);
   _debug_printf("\t\t.index = %u\n", (*cmd).index);
   _debug_printf("\t\t.enabled = %u\n", (*cmd).enabled);
}

static void
dump_SVGA3dPrimitiveRange(const SVGA3dPrimitiveRange *cmd)
{
   switch((*cmd).primType) {
   case SVGA3D_PRIMITIVE_INVALID:
      _debug_printf("\t\t.primType = SVGA3D_PRIMITIVE_INVALID\n");
      break;
   case SVGA3D_PRIMITIVE_TRIANGLELIST:
      _debug_printf("\t\t.primType = SVGA3D_PRIMITIVE_TRIANGLELIST\n");
      break;
   case SVGA3D_PRIMITIVE_POINTLIST:
      _debug_printf("\t\t.primType = SVGA3D_PRIMITIVE_POINTLIST\n");
      break;
   case SVGA3D_PRIMITIVE_LINELIST:
      _debug_printf("\t\t.primType = SVGA3D_PRIMITIVE_LINELIST\n");
      break;
   case SVGA3D_PRIMITIVE_LINESTRIP:
      _debug_printf("\t\t.primType = SVGA3D_PRIMITIVE_LINESTRIP\n");
      break;
   case SVGA3D_PRIMITIVE_TRIANGLESTRIP:
      _debug_printf("\t\t.primType = SVGA3D_PRIMITIVE_TRIANGLESTRIP\n");
      break;
   case SVGA3D_PRIMITIVE_TRIANGLEFAN:
      _debug_printf("\t\t.primType = SVGA3D_PRIMITIVE_TRIANGLEFAN\n");
      break;
   case SVGA3D_PRIMITIVE_MAX:
      _debug_printf("\t\t.primType = SVGA3D_PRIMITIVE_MAX\n");
      break;
   default:
      _debug_printf("\t\t.primType = %i\n", (*cmd).primType);
      break;
   }
   _debug_printf("\t\t.primitiveCount = %u\n", (*cmd).primitiveCount);
   _debug_printf("\t\t.indexArray.surfaceId = %u\n", (*cmd).indexArray.surfaceId);
   _debug_printf("\t\t.indexArray.offset = %u\n", (*cmd).indexArray.offset);
   _debug_printf("\t\t.indexArray.stride = %u\n", (*cmd).indexArray.stride);
   _debug_printf("\t\t.indexWidth = %u\n", (*cmd).indexWidth);
   _debug_printf("\t\t.indexBias = %i\n", (*cmd).indexBias);
}

static void
dump_SVGA3dCmdPresent(const SVGA3dCmdPresent *cmd)
{
   _debug_printf("\t\t.sid = %u\n", (*cmd).sid);
}

static void
dump_SVGA3dCmdSetRenderState(const SVGA3dCmdSetRenderState *cmd)
{
   _debug_printf("\t\t.cid = %u\n", (*cmd).cid);
}

static void
dump_SVGA3dCmdSurfaceStretchBlt(const SVGA3dCmdSurfaceStretchBlt *cmd)
{
   _debug_printf("\t\t.src.sid = %u\n", (*cmd).src.sid);
   _debug_printf("\t\t.src.face = %u\n", (*cmd).src.face);
   _debug_printf("\t\t.src.mipmap = %u\n", (*cmd).src.mipmap);
   _debug_printf("\t\t.dest.sid = %u\n", (*cmd).dest.sid);
   _debug_printf("\t\t.dest.face = %u\n", (*cmd).dest.face);
   _debug_printf("\t\t.dest.mipmap = %u\n", (*cmd).dest.mipmap);
   _debug_printf("\t\t.boxSrc.x = %u\n", (*cmd).boxSrc.x);
   _debug_printf("\t\t.boxSrc.y = %u\n", (*cmd).boxSrc.y);
   _debug_printf("\t\t.boxSrc.z = %u\n", (*cmd).boxSrc.z);
   _debug_printf("\t\t.boxSrc.w = %u\n", (*cmd).boxSrc.w);
   _debug_printf("\t\t.boxSrc.h = %u\n", (*cmd).boxSrc.h);
   _debug_printf("\t\t.boxSrc.d = %u\n", (*cmd).boxSrc.d);
   _debug_printf("\t\t.boxDest.x = %u\n", (*cmd).boxDest.x);
   _debug_printf("\t\t.boxDest.y = %u\n", (*cmd).boxDest.y);
   _debug_printf("\t\t.boxDest.z = %u\n", (*cmd).boxDest.z);
   _debug_printf("\t\t.boxDest.w = %u\n", (*cmd).boxDest.w);
   _debug_printf("\t\t.boxDest.h = %u\n", (*cmd).boxDest.h);
   _debug_printf("\t\t.boxDest.d = %u\n", (*cmd).boxDest.d);
   switch((*cmd).mode) {
   case SVGA3D_STRETCH_BLT_POINT:
      _debug_printf("\t\t.mode = SVGA3D_STRETCH_BLT_POINT\n");
      break;
   case SVGA3D_STRETCH_BLT_LINEAR:
      _debug_printf("\t\t.mode = SVGA3D_STRETCH_BLT_LINEAR\n");
      break;
   case SVGA3D_STRETCH_BLT_MAX:
      _debug_printf("\t\t.mode = SVGA3D_STRETCH_BLT_MAX\n");
      break;
   default:
      _debug_printf("\t\t.mode = %i\n", (*cmd).mode);
      break;
   }
}

static void
dump_SVGA3dCmdSurfaceDMA(const SVGA3dCmdSurfaceDMA *cmd)
{
   _debug_printf("\t\t.guest.ptr.gmrId = %u\n", (*cmd).guest.ptr.gmrId);
   _debug_printf("\t\t.guest.ptr.offset = %u\n", (*cmd).guest.ptr.offset);
   _debug_printf("\t\t.guest.pitch = %u\n", (*cmd).guest.pitch);
   _debug_printf("\t\t.host.sid = %u\n", (*cmd).host.sid);
   _debug_printf("\t\t.host.face = %u\n", (*cmd).host.face);
   _debug_printf("\t\t.host.mipmap = %u\n", (*cmd).host.mipmap);
   switch((*cmd).transfer) {
   case SVGA3D_WRITE_HOST_VRAM:
      _debug_printf("\t\t.transfer = SVGA3D_WRITE_HOST_VRAM\n");
      break;
   case SVGA3D_READ_HOST_VRAM:
      _debug_printf("\t\t.transfer = SVGA3D_READ_HOST_VRAM\n");
      break;
   default:
      _debug_printf("\t\t.transfer = %i\n", (*cmd).transfer);
      break;
   }
}

static void
dump_SVGA3dCmdSurfaceDMASuffix(const SVGA3dCmdSurfaceDMASuffix *cmd)
{
   _debug_printf("\t\t.suffixSize = %u\n", (*cmd).suffixSize);
   _debug_printf("\t\t.maximumOffset = %u\n", (*cmd).maximumOffset);
   _debug_printf("\t\t.flags.discard = %u\n", (*cmd).flags.discard);
   _debug_printf("\t\t.flags.unsynchronized = %u\n", (*cmd).flags.unsynchronized);
}

static void
dump_SVGA3dCmdSetTransform(const SVGA3dCmdSetTransform *cmd)
{
   _debug_printf("\t\t.cid = %u\n", (*cmd).cid);
   switch((*cmd).type) {
   case SVGA3D_TRANSFORM_INVALID:
      _debug_printf("\t\t.type = SVGA3D_TRANSFORM_INVALID\n");
      break;
   case SVGA3D_TRANSFORM_WORLD:
      _debug_printf("\t\t.type = SVGA3D_TRANSFORM_WORLD\n");
      break;
   case SVGA3D_TRANSFORM_VIEW:
      _debug_printf("\t\t.type = SVGA3D_TRANSFORM_VIEW\n");
      break;
   case SVGA3D_TRANSFORM_PROJECTION:
      _debug_printf("\t\t.type = SVGA3D_TRANSFORM_PROJECTION\n");
      break;
   case SVGA3D_TRANSFORM_TEXTURE0:
      _debug_printf("\t\t.type = SVGA3D_TRANSFORM_TEXTURE0\n");
      break;
   case SVGA3D_TRANSFORM_TEXTURE1:
      _debug_printf("\t\t.type = SVGA3D_TRANSFORM_TEXTURE1\n");
      break;
   case SVGA3D_TRANSFORM_TEXTURE2:
      _debug_printf("\t\t.type = SVGA3D_TRANSFORM_TEXTURE2\n");
      break;
   case SVGA3D_TRANSFORM_TEXTURE3:
      _debug_printf("\t\t.type = SVGA3D_TRANSFORM_TEXTURE3\n");
      break;
   case SVGA3D_TRANSFORM_TEXTURE4:
      _debug_printf("\t\t.type = SVGA3D_TRANSFORM_TEXTURE4\n");
      break;
   case SVGA3D_TRANSFORM_TEXTURE5:
      _debug_printf("\t\t.type = SVGA3D_TRANSFORM_TEXTURE5\n");
      break;
   case SVGA3D_TRANSFORM_TEXTURE6:
      _debug_printf("\t\t.type = SVGA3D_TRANSFORM_TEXTURE6\n");
      break;
   case SVGA3D_TRANSFORM_TEXTURE7:
      _debug_printf("\t\t.type = SVGA3D_TRANSFORM_TEXTURE7\n");
      break;
   case SVGA3D_TRANSFORM_WORLD1:
      _debug_printf("\t\t.type = SVGA3D_TRANSFORM_WORLD1\n");
      break;
   case SVGA3D_TRANSFORM_WORLD2:
      _debug_printf("\t\t.type = SVGA3D_TRANSFORM_WORLD2\n");
      break;
   case SVGA3D_TRANSFORM_WORLD3:
      _debug_printf("\t\t.type = SVGA3D_TRANSFORM_WORLD3\n");
      break;
   case SVGA3D_TRANSFORM_MAX:
      _debug_printf("\t\t.type = SVGA3D_TRANSFORM_MAX\n");
      break;
   default:
      _debug_printf("\t\t.type = %i\n", (*cmd).type);
      break;
   }
   _debug_printf("\t\t.matrix[0] = %R[float]\n", (*cmd).matrix[0]);
   _debug_printf("\t\t.matrix[1] = %R[float]\n", (*cmd).matrix[1]);
   _debug_printf("\t\t.matrix[2] = %R[float]\n", (*cmd).matrix[2]);
   _debug_printf("\t\t.matrix[3] = %R[float]\n", (*cmd).matrix[3]);
   _debug_printf("\t\t.matrix[4] = %R[float]\n", (*cmd).matrix[4]);
   _debug_printf("\t\t.matrix[5] = %R[float]\n", (*cmd).matrix[5]);
   _debug_printf("\t\t.matrix[6] = %R[float]\n", (*cmd).matrix[6]);
   _debug_printf("\t\t.matrix[7] = %R[float]\n", (*cmd).matrix[7]);
   _debug_printf("\t\t.matrix[8] = %R[float]\n", (*cmd).matrix[8]);
   _debug_printf("\t\t.matrix[9] = %R[float]\n", (*cmd).matrix[9]);
   _debug_printf("\t\t.matrix[10] = %R[float]\n", (*cmd).matrix[10]);
   _debug_printf("\t\t.matrix[11] = %R[float]\n", (*cmd).matrix[11]);
   _debug_printf("\t\t.matrix[12] = %R[float]\n", (*cmd).matrix[12]);
   _debug_printf("\t\t.matrix[13] = %R[float]\n", (*cmd).matrix[13]);
   _debug_printf("\t\t.matrix[14] = %R[float]\n", (*cmd).matrix[14]);
   _debug_printf("\t\t.matrix[15] = %R[float]\n", (*cmd).matrix[15]);
}

static void
dump_SVGA3dCmdDestroyShader(const SVGA3dCmdDestroyShader *cmd)
{
   _debug_printf("\t\t.cid = %u\n", (*cmd).cid);
   _debug_printf("\t\t.shid = %u\n", (*cmd).shid);
   switch((*cmd).type) {
   case SVGA3D_SHADERTYPE_VS:
      _debug_printf("\t\t.type = SVGA3D_SHADERTYPE_VS\n");
      break;
   case SVGA3D_SHADERTYPE_PS:
      _debug_printf("\t\t.type = SVGA3D_SHADERTYPE_PS\n");
      break;
   default:
      _debug_printf("\t\t.type = %i\n", (*cmd).type);
      break;
   }
}

static void
dump_SVGA3dCmdDestroyContext(const SVGA3dCmdDestroyContext *cmd)
{
   _debug_printf("\t\t.cid = %u\n", (*cmd).cid);
}

static void
dump_SVGA3dCmdClear(const SVGA3dCmdClear *cmd)
{
   _debug_printf("\t\t.cid = %u\n", (*cmd).cid);
   switch((*cmd).clearFlag) {
   case SVGA3D_CLEAR_COLOR:
      _debug_printf("\t\t.clearFlag = SVGA3D_CLEAR_COLOR\n");
      break;
   case SVGA3D_CLEAR_DEPTH:
      _debug_printf("\t\t.clearFlag = SVGA3D_CLEAR_DEPTH\n");
      break;
   case SVGA3D_CLEAR_STENCIL:
      _debug_printf("\t\t.clearFlag = SVGA3D_CLEAR_STENCIL\n");
      break;
   default:
      _debug_printf("\t\t.clearFlag = %i\n", (*cmd).clearFlag);
      break;
   }
   _debug_printf("\t\t.color = %u\n", (*cmd).color);
   _debug_printf("\t\t.depth = %R[float]\n", (*cmd).depth);
   _debug_printf("\t\t.stencil = %u\n", (*cmd).stencil);
}

static void
dump_SVGA3dCmdDefineSurface(const SVGA3dCmdDefineSurface *cmd)
{
   _debug_printf("\t\t.sid = %u\n", (*cmd).sid);
   switch((*cmd).surfaceFlags) {
   case SVGA3D_SURFACE_CUBEMAP:
      _debug_printf("\t\t.surfaceFlags = SVGA3D_SURFACE_CUBEMAP\n");
      break;
   case SVGA3D_SURFACE_HINT_STATIC:
      _debug_printf("\t\t.surfaceFlags = SVGA3D_SURFACE_HINT_STATIC\n");
      break;
   case SVGA3D_SURFACE_HINT_DYNAMIC:
      _debug_printf("\t\t.surfaceFlags = SVGA3D_SURFACE_HINT_DYNAMIC\n");
      break;
   case SVGA3D_SURFACE_HINT_INDEXBUFFER:
      _debug_printf("\t\t.surfaceFlags = SVGA3D_SURFACE_HINT_INDEXBUFFER\n");
      break;
   case SVGA3D_SURFACE_HINT_VERTEXBUFFER:
      _debug_printf("\t\t.surfaceFlags = SVGA3D_SURFACE_HINT_VERTEXBUFFER\n");
      break;
   default:
      _debug_printf("\t\t.surfaceFlags = %i\n", (*cmd).surfaceFlags);
      break;
   }
   _debug_printf("\t\t.format = %s\n", svga_format_name((*cmd).format));
   _debug_printf("\t\t.face[0].numMipLevels = %u\n", (*cmd).face[0].numMipLevels);
   _debug_printf("\t\t.face[1].numMipLevels = %u\n", (*cmd).face[1].numMipLevels);
   _debug_printf("\t\t.face[2].numMipLevels = %u\n", (*cmd).face[2].numMipLevels);
   _debug_printf("\t\t.face[3].numMipLevels = %u\n", (*cmd).face[3].numMipLevels);
   _debug_printf("\t\t.face[4].numMipLevels = %u\n", (*cmd).face[4].numMipLevels);
   _debug_printf("\t\t.face[5].numMipLevels = %u\n", (*cmd).face[5].numMipLevels);
}

static void
dump_SVGASignedRect(const SVGASignedRect *cmd)
{
   _debug_printf("\t\t.left = %i\n", (*cmd).left);
   _debug_printf("\t\t.top = %i\n", (*cmd).top);
   _debug_printf("\t\t.right = %i\n", (*cmd).right);
   _debug_printf("\t\t.bottom = %i\n", (*cmd).bottom);
}

static void
dump_SVGA3dBox(const SVGA3dBox *box)
{
   _debug_printf("\t\t.box = %u, %u, %u  %u x %u x %u\n",
                 box->x, box->y, box->z, 
                 box->w, box->h, box->d);
}

static void
dump_SVGA3dCmdBlitSurfaceToScreen(const SVGA3dCmdBlitSurfaceToScreen *cmd)
{
   _debug_printf("\t\t.srcImage.sid = %u\n", (*cmd).srcImage.sid);
   _debug_printf("\t\t.srcImage.face = %u\n", (*cmd).srcImage.face);
   _debug_printf("\t\t.srcImage.mipmap = %u\n", (*cmd).srcImage.mipmap);
   _debug_printf("\t\t.srcRect.left = %i\n", (*cmd).srcRect.left);
   _debug_printf("\t\t.srcRect.top = %i\n", (*cmd).srcRect.top);
   _debug_printf("\t\t.srcRect.right = %i\n", (*cmd).srcRect.right);
   _debug_printf("\t\t.srcRect.bottom = %i\n", (*cmd).srcRect.bottom);
   _debug_printf("\t\t.destScreenId = %u\n", (*cmd).destScreenId);
   _debug_printf("\t\t.destRect.left = %i\n", (*cmd).destRect.left);
   _debug_printf("\t\t.destRect.top = %i\n", (*cmd).destRect.top);
   _debug_printf("\t\t.destRect.right = %i\n", (*cmd).destRect.right);
   _debug_printf("\t\t.destRect.bottom = %i\n", (*cmd).destRect.bottom);
}

static void
dump_SVGA3dCmdDefineGBContext(const SVGA3dCmdDefineGBContext *cmd)
{
   _debug_printf("\t\t.cid = %u\n", cmd->cid);
}
         
static void
dump_SVGA3dCmdBindGBContext(const SVGA3dCmdBindGBContext *cmd)
{
   _debug_printf("\t\t.cid = %u\n", cmd->cid);
   _debug_printf("\t\t.mobid = %u\n", cmd->mobid);
   _debug_printf("\t\t.validContents = %u\n", cmd->validContents);
}
         
static void
dump_SVGA3dCmdDestroyGBContext(const SVGA3dCmdDestroyGBContext *cmd)
{
   _debug_printf("\t\t.cid = %u\n", cmd->cid);
}

static void
dump_SVGA3dCmdDefineGBShader(const SVGA3dCmdDefineGBShader *cmd)
{
   _debug_printf("\t\t.shid = %u\n", cmd->shid);
   _debug_printf("\t\t.type = %s\n", shader_name(cmd->type));
   _debug_printf("\t\t.sizeInBytes = %u\n", cmd->sizeInBytes);
}

static void
dump_SVGA3dCmdBindGBShader(const SVGA3dCmdBindGBShader *cmd)
{
   _debug_printf("\t\t.shid = %u\n", cmd->shid);
   _debug_printf("\t\t.mobid = %u\n", cmd->mobid);
   _debug_printf("\t\t.offsetInBytes = %u\n", cmd->offsetInBytes);
}

static void
dump_SVGA3dCmdDestroyGBShader(const SVGA3dCmdDestroyGBShader *cmd)
{
   _debug_printf("\t\t.shid = %u\n", cmd->shid);
}

static void
dump_SVGA3dCmdBindGBSurface(const SVGA3dCmdBindGBSurface *cmd)
{
   _debug_printf("\t\t.sid = %u\n", cmd->sid);
   _debug_printf("\t\t.mobid = %u\n", cmd->mobid);
}

static void
dump_SVGA3dCmdUpdateGBSurface(const SVGA3dCmdUpdateGBSurface *cmd)
{
   _debug_printf("\t\t.sid = %u\n", cmd->sid);
}

static void
dump_SVGA3dCmdUpdateGBImage(const SVGA3dCmdUpdateGBImage *cmd)
{
   _debug_printf("\t\t.image.sid = %u\n", cmd->image.sid);
   _debug_printf("\t\t.image.face = %u\n", cmd->image.face);
   _debug_printf("\t\t.image.mipmap = %u\n", cmd->image.mipmap);
   dump_SVGA3dBox(&cmd->box);
}

static void
dump_SVGA3dCmdReadbackGBImage(const SVGA3dCmdReadbackGBImage *cmd)
{
   _debug_printf("\t\t.image.sid = %u\n", cmd->image.sid);
   _debug_printf("\t\t.image.face = %u\n", cmd->image.face);
   _debug_printf("\t\t.image.mipmap = %u\n", cmd->image.mipmap);
}

static void
dump_SVGA3dCmdInvalidateGBImage(const SVGA3dCmdInvalidateGBImage *cmd)
{
   _debug_printf("\t\t.image.sid = %u\n", cmd->image.sid);
   _debug_printf("\t\t.image.face = %u\n", cmd->image.face);
   _debug_printf("\t\t.image.mipmap = %u\n", cmd->image.mipmap);
}

static void
dump_SVGA3dCmdInvalidateGBImagePartial(const SVGA3dCmdInvalidateGBImagePartial *cmd)
{
   _debug_printf("\t\t.image.sid = %u\n", cmd->image.sid);
   _debug_printf("\t\t.image.face = %u\n", cmd->image.face);
   _debug_printf("\t\t.image.mipmap = %u\n", cmd->image.mipmap);
   dump_SVGA3dBox(&cmd->box);
   _debug_printf("\t\t.invertBox = %u\n", cmd->invertBox);
}

/// SVGA_3D_CMD_DX

#define __SVGA3D_DUMP_STRINGIFY(a) #a
#define SVGA3D_DUMP_STRINGIFY(a) __SVGA3D_DUMP_STRINGIFY(a)

#define SVGA3D_DUMP_HEADER(CommandName) \
static void \
dump_SVGA3dCmdDX##CommandName(const SVGA3dCmdDX##CommandName *cmd)

#define SVGA3D_DUMP_PARAMETER(ParameterName, ParameterType) \
_debug_printf(SVGA3D_DUMP_STRINGIFY(\t\t.ParameterName = %ParameterType\n), cmd->ParameterName)

#define SVGA3D_DUMP_TYPE_CASE(TypeVariableName, CaseName) \
case CaseName: \
  _debug_printf(SVGA3D_DUMP_STRINGIFY(\t\t.TypeVariableName = CaseName) "\n"); \
   break;

#define SVGA3D_DUMP_TYPE_DEFAULT(TypeVariableName) \
default: \
   _debug_printf(SVGA3D_DUMP_STRINGIFY(\t\t.TypeVariableName = %i\n), (*cmd).TypeVariableName); \
   break;

SVGA3D_DUMP_HEADER(SetShader)
{
   SVGA3D_DUMP_PARAMETER(shaderId, u);
   _debug_printf("\t\t.type = %s\n", shader_name(cmd->type));
}

SVGA3D_DUMP_HEADER(SetSamplers)
{
   SVGA3D_DUMP_PARAMETER(startSampler, u);
   _debug_printf("\t\t.type = %s\n", shader_name(cmd->type));
   /* XXX: note we're not printing the sampler IDs at this time */
}

SVGA3D_DUMP_HEADER(Draw)
{
   SVGA3D_DUMP_PARAMETER(vertexCount, u);
   SVGA3D_DUMP_PARAMETER(startVertexLocation, u);
}

SVGA3D_DUMP_HEADER(DrawIndexed)
{
   SVGA3D_DUMP_PARAMETER(indexCount, u);
   SVGA3D_DUMP_PARAMETER(startIndexLocation, u);
   SVGA3D_DUMP_PARAMETER(baseVertexLocation, i);
}

SVGA3D_DUMP_HEADER(DrawInstanced)
{
   SVGA3D_DUMP_PARAMETER(vertexCountPerInstance, u);
   SVGA3D_DUMP_PARAMETER(instanceCount, u);
   SVGA3D_DUMP_PARAMETER(startVertexLocation, u);
   SVGA3D_DUMP_PARAMETER(startInstanceLocation, u);
}

SVGA3D_DUMP_HEADER(DrawIndexedInstanced)
{
   SVGA3D_DUMP_PARAMETER(indexCountPerInstance, u);
   SVGA3D_DUMP_PARAMETER(instanceCount, u);
   SVGA3D_DUMP_PARAMETER(startIndexLocation, u);
   SVGA3D_DUMP_PARAMETER(baseVertexLocation, i);
   SVGA3D_DUMP_PARAMETER(startInstanceLocation, u);
}

SVGA3D_DUMP_HEADER(DrawAuto)
{
   (void)cmd;
}

SVGA3D_DUMP_HEADER(SetBlendState)
{
   SVGA3D_DUMP_PARAMETER(blendId, u);
   _debug_printf("\t\t.blendFactor[4] = %R[float] %R[float] %R[float] %R[float]\n", cmd->blendFactor[0],
                                                        cmd->blendFactor[1],
                                                        cmd->blendFactor[2],
                                                        cmd->blendFactor[3]);
  SVGA3D_DUMP_PARAMETER(sampleMask, u);
}

SVGA3D_DUMP_HEADER(SetDepthStencilState)
{
   SVGA3D_DUMP_PARAMETER(depthStencilId, u);
   SVGA3D_DUMP_PARAMETER(stencilRef, u);
}

SVGA3D_DUMP_HEADER(SetRasterizerState)
{
   SVGA3D_DUMP_PARAMETER(rasterizerId, u);
}

SVGA3D_DUMP_HEADER(DefineQuery)
{
   SVGA3D_DUMP_PARAMETER(queryId, u);
   switch (cmd->type)
   {
      SVGA3D_DUMP_TYPE_CASE(type, SVGA3D_QUERYTYPE_OCCLUSION);
      SVGA3D_DUMP_TYPE_CASE(type, SVGA3D_QUERYTYPE_MAX);
      SVGA3D_DUMP_TYPE_DEFAULT(type);
   }
   switch (cmd->flags)
   {
      SVGA3D_DUMP_TYPE_CASE(flags, SVGA3D_DXQUERY_FLAG_PREDICATEHINT);
      SVGA3D_DUMP_TYPE_DEFAULT(flags);
   }
}

SVGA3D_DUMP_HEADER(DestroyQuery)
{
   SVGA3D_DUMP_PARAMETER(queryId, u);
}

SVGA3D_DUMP_HEADER(BindAllQuery)
{
   SVGA3D_DUMP_PARAMETER(cid, u);
   SVGA3D_DUMP_PARAMETER(mobid, u);
}

SVGA3D_DUMP_HEADER(BindQuery)
{
   SVGA3D_DUMP_PARAMETER(queryId, u);
   SVGA3D_DUMP_PARAMETER(mobid, u);
}

SVGA3D_DUMP_HEADER(MoveQuery)
{
   SVGA3D_DUMP_PARAMETER(queryId, u);
   SVGA3D_DUMP_PARAMETER(mobid, u);
   SVGA3D_DUMP_PARAMETER(mobOffset, u);
}

SVGA3D_DUMP_HEADER(ReadbackAllQuery)
{
   SVGA3D_DUMP_PARAMETER(cid, u);
}

SVGA3D_DUMP_HEADER(SetQueryOffset)
{
   SVGA3D_DUMP_PARAMETER(queryId, u);
   SVGA3D_DUMP_PARAMETER(mobOffset, u);
}

SVGA3D_DUMP_HEADER(BeginQuery)
{
   SVGA3D_DUMP_PARAMETER(queryId, u);
}

SVGA3D_DUMP_HEADER(EndQuery)
{
   SVGA3D_DUMP_PARAMETER(queryId, u);
}

SVGA3D_DUMP_HEADER(SetPredication)
{
   SVGA3D_DUMP_PARAMETER(queryId, u);
   SVGA3D_DUMP_PARAMETER(predicateValue, u);
}

SVGA3D_DUMP_HEADER(SetSOTargets)
{
   (void)cmd;
}


SVGA3D_DUMP_HEADER(BindContext)
{
   SVGA3D_DUMP_PARAMETER(mobid, u);
   SVGA3D_DUMP_PARAMETER(validContents, u);
}

SVGA3D_DUMP_HEADER(SetViewports)
{
   (void)cmd;
   /* XXX: note we're not printing the SVGA3dViewport list at this time */
}

SVGA3D_DUMP_HEADER(SetScissorRects)
{
   (void)cmd;
   /* XXX: note we're not printing the SVGASignedRect list at this time */
}

SVGA3D_DUMP_HEADER(ClearRenderTargetView)
{
   SVGA3D_DUMP_PARAMETER(renderTargetViewId, u);
   SVGA3D_DUMP_PARAMETER(rgba.r, R[float]);
   SVGA3D_DUMP_PARAMETER(rgba.g, R[float]);
   SVGA3D_DUMP_PARAMETER(rgba.b, R[float]);
   SVGA3D_DUMP_PARAMETER(rgba.a, R[float]);
}

SVGA3D_DUMP_HEADER(ClearDepthStencilView)
{
   SVGA3D_DUMP_PARAMETER(flags, u);
   SVGA3D_DUMP_PARAMETER(stencil, u);
   SVGA3D_DUMP_PARAMETER(depthStencilViewId, u);
   SVGA3D_DUMP_PARAMETER(depth, R[float]);
}

SVGA3D_DUMP_HEADER(DefineShaderResourceView)
{
   SVGA3D_DUMP_PARAMETER(shaderResourceViewId, u);
   SVGA3D_DUMP_PARAMETER(sid, u);
   _debug_printf("\t\t.format = %s\n", svga_format_name(cmd->format));
   switch (cmd->resourceDimension)
   {
      SVGA3D_DUMP_TYPE_CASE(resourceDimension, SVGA3D_RESOURCE_BUFFER);
      SVGA3D_DUMP_TYPE_CASE(resourceDimension, SVGA3D_RESOURCE_TEXTURE1D);
      SVGA3D_DUMP_TYPE_CASE(resourceDimension, SVGA3D_RESOURCE_TEXTURE2D);
      SVGA3D_DUMP_TYPE_CASE(resourceDimension, SVGA3D_RESOURCE_TEXTURE3D);
      SVGA3D_DUMP_TYPE_CASE(resourceDimension, SVGA3D_RESOURCE_TEXTURECUBE);
      SVGA3D_DUMP_TYPE_CASE(resourceDimension, SVGA3D_RESOURCE_TYPE_MAX);
      SVGA3D_DUMP_TYPE_DEFAULT(resourceDimension);
   }
   if (cmd->resourceDimension == SVGA3D_RESOURCE_BUFFER) {
      SVGA3D_DUMP_PARAMETER(desc.buffer.firstElement, u);
      SVGA3D_DUMP_PARAMETER(desc.buffer.numElements, u);
   } 
   else {
      SVGA3D_DUMP_PARAMETER(desc.tex.mostDetailedMip, u);
      SVGA3D_DUMP_PARAMETER(desc.tex.firstArraySlice, u);
      SVGA3D_DUMP_PARAMETER(desc.tex.mipLevels, u);
      SVGA3D_DUMP_PARAMETER(desc.tex.arraySize, u);
   }
}

SVGA3D_DUMP_HEADER(SetShaderResources)
{
   SVGA3D_DUMP_PARAMETER(startView, u);
   _debug_printf("\t\t.type = %s\n", shader_name(cmd->type));
}


SVGA3D_DUMP_HEADER(DestroyShaderResourceView)
{
   SVGA3D_DUMP_PARAMETER(shaderResourceViewId, u);
}

SVGA3D_DUMP_HEADER(DefineRenderTargetView)
{
   SVGA3D_DUMP_PARAMETER(renderTargetViewId, u);
   SVGA3D_DUMP_PARAMETER(sid, u);
   _debug_printf("\t\t.format = %s\n", svga_format_name(cmd->format));
   switch (cmd->resourceDimension)
   {
      SVGA3D_DUMP_TYPE_CASE(resourceDimension, SVGA3D_RESOURCE_BUFFER);
      SVGA3D_DUMP_TYPE_CASE(resourceDimension, SVGA3D_RESOURCE_TEXTURE1D);
      SVGA3D_DUMP_TYPE_CASE(resourceDimension, SVGA3D_RESOURCE_TEXTURE2D);
      SVGA3D_DUMP_TYPE_CASE(resourceDimension, SVGA3D_RESOURCE_TEXTURE3D);
      SVGA3D_DUMP_TYPE_CASE(resourceDimension, SVGA3D_RESOURCE_TEXTURECUBE);
      SVGA3D_DUMP_TYPE_CASE(resourceDimension, SVGA3D_RESOURCE_TYPE_MAX);
      SVGA3D_DUMP_TYPE_DEFAULT(resourceDimension);
   }
   SVGA3D_DUMP_PARAMETER(desc.buffer.firstElement, u);
   SVGA3D_DUMP_PARAMETER(desc.buffer.numElements, u);
   SVGA3D_DUMP_PARAMETER(desc.tex.mipSlice, u);
   SVGA3D_DUMP_PARAMETER(desc.tex.firstArraySlice, u);
   SVGA3D_DUMP_PARAMETER(desc.tex.arraySize, u);
   SVGA3D_DUMP_PARAMETER(desc.tex3D.mipSlice, u);
   SVGA3D_DUMP_PARAMETER(desc.tex3D.firstW, u);
   SVGA3D_DUMP_PARAMETER(desc.tex3D.wSize, u);
}

SVGA3D_DUMP_HEADER(DestroyRenderTargetView)
{
   SVGA3D_DUMP_PARAMETER(renderTargetViewId, u);
}

SVGA3D_DUMP_HEADER(DefineDepthStencilView)
{
   SVGA3D_DUMP_PARAMETER(depthStencilViewId, u);
   SVGA3D_DUMP_PARAMETER(sid, u);
   _debug_printf("\t\t.format = %s\n", svga_format_name(cmd->format));
   switch (cmd->resourceDimension)
   {
      SVGA3D_DUMP_TYPE_CASE(resourceDimension, SVGA3D_RESOURCE_BUFFER);
      SVGA3D_DUMP_TYPE_CASE(resourceDimension, SVGA3D_RESOURCE_TEXTURE1D);
      SVGA3D_DUMP_TYPE_CASE(resourceDimension, SVGA3D_RESOURCE_TEXTURE2D);
      SVGA3D_DUMP_TYPE_CASE(resourceDimension, SVGA3D_RESOURCE_TEXTURE3D);
      SVGA3D_DUMP_TYPE_CASE(resourceDimension, SVGA3D_RESOURCE_TEXTURECUBE);
      SVGA3D_DUMP_TYPE_CASE(resourceDimension, SVGA3D_RESOURCE_TYPE_MAX);
      SVGA3D_DUMP_TYPE_DEFAULT(resourceDimension);
   }
   SVGA3D_DUMP_PARAMETER(mipSlice, u);
   SVGA3D_DUMP_PARAMETER(firstArraySlice, u);
   SVGA3D_DUMP_PARAMETER(arraySize, u);
}

SVGA3D_DUMP_HEADER(DestroyDepthStencilView)
{
   SVGA3D_DUMP_PARAMETER(depthStencilViewId, u);
}

SVGA3D_DUMP_HEADER(DefineElementLayout)
{
   SVGA3D_DUMP_PARAMETER(elementLayoutId, u);
}

SVGA3D_DUMP_HEADER(DestroyElementLayout)
{
   SVGA3D_DUMP_PARAMETER(elementLayoutId, u);
}

static void
dump_SVGA3dCmdDXDefineBlendState(const SVGA3dCmdDXDefineBlendState *cmd)
{
   unsigned i;

   SVGA3D_DUMP_PARAMETER(blendId, u);
   SVGA3D_DUMP_PARAMETER(alphaToCoverageEnable, u);
   SVGA3D_DUMP_PARAMETER(independentBlendEnable, u);
   for (i = 0; i < SVGA3D_DX_MAX_RENDER_TARGETS; i++) {
      const SVGA3dDXBlendStatePerRT *rt = cmd->perRT + i;
      _debug_printf("\t\t.perRT[%u].blendEnable = %u\n", i, rt->blendEnable);
      if (rt->blendEnable) {
         _debug_printf("\t\t.perRT[%u].srcBlend = %u\n", i, rt->srcBlend);
         _debug_printf("\t\t.perRT[%u].destBlend = %u\n", i, rt->destBlend);
         _debug_printf("\t\t.perRT[%u].blendOp = %u\n", i, rt->blendOp);
         _debug_printf("\t\t.perRT[%u].srcBlendAlpha = %u\n", i, rt->srcBlendAlpha);
         _debug_printf("\t\t.perRT[%u].destBlendAlpha = %u\n", i, rt->destBlendAlpha);
         _debug_printf("\t\t.perRT[%u].blendOpAlpha = %u\n", i, rt->blendOpAlpha);
      }
      _debug_printf("\t\t.perRT[%u].renderTargetWriteMask = %u\n", i, rt->renderTargetWriteMask);
      _debug_printf("\t\t.perRT[%u].logicOpEnable = %u\n", i, rt->logicOpEnable);
      if (rt->logicOpEnable) {
         _debug_printf("\t\t.perRT[%u].logicOp = %u\n", i, rt->logicOp);
      }
   }
}

SVGA3D_DUMP_HEADER(DestroyBlendState)
{
   SVGA3D_DUMP_PARAMETER(blendId, u);
}

SVGA3D_DUMP_HEADER(DefineDepthStencilState)
{
   SVGA3D_DUMP_PARAMETER(depthStencilId, u);
   SVGA3D_DUMP_PARAMETER(depthEnable, u);
   SVGA3D_DUMP_PARAMETER(depthWriteMask, u);
   SVGA3D_DUMP_PARAMETER(depthFunc, u);
   SVGA3D_DUMP_PARAMETER(stencilEnable, u);
   SVGA3D_DUMP_PARAMETER(frontEnable, u);
   SVGA3D_DUMP_PARAMETER(backEnable, u);
   SVGA3D_DUMP_PARAMETER(stencilReadMask, u);
   SVGA3D_DUMP_PARAMETER(stencilWriteMask, u);
   SVGA3D_DUMP_PARAMETER(frontStencilFailOp, u);
   SVGA3D_DUMP_PARAMETER(frontStencilDepthFailOp, u);
   SVGA3D_DUMP_PARAMETER(frontStencilPassOp, u);
   SVGA3D_DUMP_PARAMETER(frontStencilFunc, u);
   SVGA3D_DUMP_PARAMETER(backStencilFailOp, u);
   SVGA3D_DUMP_PARAMETER(backStencilDepthFailOp, u);
   SVGA3D_DUMP_PARAMETER(backStencilPassOp, u);
   SVGA3D_DUMP_PARAMETER(backStencilFunc, u);
}

SVGA3D_DUMP_HEADER(DestroyDepthStencilState)
{
   SVGA3D_DUMP_PARAMETER(depthStencilId, u);
}

SVGA3D_DUMP_HEADER(DefineRasterizerState)
{
   SVGA3D_DUMP_PARAMETER(rasterizerId, u);
   SVGA3D_DUMP_PARAMETER(fillMode, u);
   SVGA3D_DUMP_PARAMETER(cullMode, u);
   SVGA3D_DUMP_PARAMETER(frontCounterClockwise, u);
   SVGA3D_DUMP_PARAMETER(depthBias, u);
   SVGA3D_DUMP_PARAMETER(depthBiasClamp, R[float]);
   SVGA3D_DUMP_PARAMETER(slopeScaledDepthBias, R[float]);
   SVGA3D_DUMP_PARAMETER(depthClipEnable, u);
   SVGA3D_DUMP_PARAMETER(scissorEnable, u);
   SVGA3D_DUMP_PARAMETER(multisampleEnable, u);
   SVGA3D_DUMP_PARAMETER(antialiasedLineEnable, u);
   SVGA3D_DUMP_PARAMETER(lineWidth, R[float]);
   SVGA3D_DUMP_PARAMETER(lineStippleEnable, u);
   SVGA3D_DUMP_PARAMETER(lineStippleFactor, u);
   SVGA3D_DUMP_PARAMETER(lineStipplePattern, u);
   SVGA3D_DUMP_PARAMETER(provokingVertexLast, u);
}

SVGA3D_DUMP_HEADER(DestroyRasterizerState)
{
   SVGA3D_DUMP_PARAMETER(rasterizerId, u);
}

SVGA3D_DUMP_HEADER(DefineSamplerState)
{
   SVGA3D_DUMP_PARAMETER(samplerId, u);
   SVGA3D_DUMP_PARAMETER(filter, u);
   SVGA3D_DUMP_PARAMETER(addressU, u);
   SVGA3D_DUMP_PARAMETER(addressV, u);
   SVGA3D_DUMP_PARAMETER(addressW, u);
   SVGA3D_DUMP_PARAMETER(mipLODBias, R[float]);
   SVGA3D_DUMP_PARAMETER(maxAnisotropy, u);
   SVGA3D_DUMP_PARAMETER(comparisonFunc, u);
   SVGA3D_DUMP_PARAMETER(borderColor.r, R[float]);
   SVGA3D_DUMP_PARAMETER(borderColor.g, R[float]);
   SVGA3D_DUMP_PARAMETER(borderColor.b, R[float]);
   SVGA3D_DUMP_PARAMETER(borderColor.a, R[float]);
   SVGA3D_DUMP_PARAMETER(minLOD, R[float]);
   SVGA3D_DUMP_PARAMETER(maxLOD, R[float]);
}

SVGA3D_DUMP_HEADER(DestroySamplerState)
{
   SVGA3D_DUMP_PARAMETER(samplerId, u);
}

SVGA3D_DUMP_HEADER(DefineShader)
{
   SVGA3D_DUMP_PARAMETER(shaderId, u);
   _debug_printf("\t\t.type = %s\n", shader_name(cmd->type));
   SVGA3D_DUMP_PARAMETER(sizeInBytes, u);
}

SVGA3D_DUMP_HEADER(DestroyShader)
{
   SVGA3D_DUMP_PARAMETER(shaderId, u);
}

SVGA3D_DUMP_HEADER(BindShader)
{
   SVGA3D_DUMP_PARAMETER(cid, u);
   SVGA3D_DUMP_PARAMETER(shid, u);
   SVGA3D_DUMP_PARAMETER(mobid, u);
   SVGA3D_DUMP_PARAMETER(offsetInBytes, u);
}

SVGA3D_DUMP_HEADER(DefineStreamOutput)
{
   int i;
   SVGA3D_DUMP_PARAMETER(soid, u);
   SVGA3D_DUMP_PARAMETER(numOutputStreamEntries, u);
   for (i = 0; i < SVGA3D_DX_MAX_SOTARGETS; i++) {
      _debug_printf("\t\t.streamOutputStrideInBytes[%d] = %u\n",
                    i, cmd->streamOutputStrideInBytes[i]);
   }
   for (i = 0; i < 16; i++)
   {
      _debug_printf("\t\t.decl[%d].outputSlot = %u\n", i, cmd->decl[i].outputSlot);
      _debug_printf("\t\t.decl[%d].registerIndex = %u\n", i, cmd->decl[i].registerIndex);
      _debug_printf("\t\t.decl[%d].registerMask = %u\n", i, cmd->decl[i].registerMask);
   }
}

SVGA3D_DUMP_HEADER(DestroyStreamOutput)
{
   SVGA3D_DUMP_PARAMETER(soid, u);
}

SVGA3D_DUMP_HEADER(SetStreamOutput)
{
   SVGA3D_DUMP_PARAMETER(soid, u);
}

SVGA3D_DUMP_HEADER(SetSingleConstantBuffer)
{
   SVGA3D_DUMP_PARAMETER(slot, u);
   SVGA3D_DUMP_PARAMETER(sid, u);
   _debug_printf("\t\t.type = %s\n", shader_name(cmd->type));
   SVGA3D_DUMP_PARAMETER(offsetInBytes, u);
   SVGA3D_DUMP_PARAMETER(sizeInBytes, u);
}

SVGA3D_DUMP_HEADER(SetInputLayout)
{
   SVGA3D_DUMP_PARAMETER(elementLayoutId, u);
}

SVGA3D_DUMP_HEADER(SetVertexBuffers)
{
   SVGA3D_DUMP_PARAMETER(startBuffer, u);

   /* XXX: note we're not printing the SVGA3dVertexBuffer list at this time */
}

SVGA3D_DUMP_HEADER(SetTopology)
{
   switch (cmd->topology)
   {
      SVGA3D_DUMP_TYPE_CASE(topology, SVGA3D_PRIMITIVE_INVALID);
      SVGA3D_DUMP_TYPE_CASE(topology, SVGA3D_PRIMITIVE_TRIANGLELIST);
      SVGA3D_DUMP_TYPE_CASE(topology, SVGA3D_PRIMITIVE_POINTLIST);
      SVGA3D_DUMP_TYPE_CASE(topology, SVGA3D_PRIMITIVE_LINELIST);
      SVGA3D_DUMP_TYPE_CASE(topology, SVGA3D_PRIMITIVE_LINESTRIP);
      SVGA3D_DUMP_TYPE_CASE(topology, SVGA3D_PRIMITIVE_TRIANGLESTRIP);
      SVGA3D_DUMP_TYPE_CASE(topology, SVGA3D_PRIMITIVE_TRIANGLEFAN);
      SVGA3D_DUMP_TYPE_CASE(topology, SVGA3D_PRIMITIVE_MAX);
      SVGA3D_DUMP_TYPE_DEFAULT(topology);
   }
}

SVGA3D_DUMP_HEADER(SetIndexBuffer)
{
   SVGA3D_DUMP_PARAMETER(sid, u);
   _debug_printf("\t\t.format = %s\n", svga_format_name(cmd->format));
   SVGA3D_DUMP_PARAMETER(offset, u);
}

SVGA3D_DUMP_HEADER(PredCopyRegion)
{
   SVGA3D_DUMP_PARAMETER(dstSid, u);
   SVGA3D_DUMP_PARAMETER(dstSubResource, u);
   SVGA3D_DUMP_PARAMETER(srcSid, u);
   SVGA3D_DUMP_PARAMETER(srcSubResource, u);
   dump_SVGA3dCopyBox(&cmd->box);
}

SVGA3D_DUMP_HEADER(PredCopy)
{
   SVGA3D_DUMP_PARAMETER(dstSid, u);
   SVGA3D_DUMP_PARAMETER(srcSid, u);
}

static void
dump_SVGA3dCmdDXUpdateSubResource(const SVGA3dCmdDXUpdateSubResource *cmd)
{
   SVGA3D_DUMP_PARAMETER(sid, u);
   SVGA3D_DUMP_PARAMETER(subResource, u);
   dump_SVGA3dBox(&cmd->box);
}

static void
dump_SVGA3dCmdDXReadbackSubResource(const SVGA3dCmdDXReadbackSubResource *cmd)
{
   SVGA3D_DUMP_PARAMETER(sid, u);
   SVGA3D_DUMP_PARAMETER(subResource, u);
}

SVGA3D_DUMP_HEADER(BufferCopy)
{
   SVGA3D_DUMP_PARAMETER(dest, u);
   SVGA3D_DUMP_PARAMETER(src, u);
   SVGA3D_DUMP_PARAMETER(destX, u);
   SVGA3D_DUMP_PARAMETER(srcX, u);
   SVGA3D_DUMP_PARAMETER(width, u);

}

SVGA3D_DUMP_HEADER(BufferUpdate)
{
   SVGA3D_DUMP_PARAMETER(sid, u);
   SVGA3D_DUMP_PARAMETER(x, u);
   SVGA3D_DUMP_PARAMETER(width, u);

}

SVGA3D_DUMP_HEADER(GenMips)
{
   SVGA3D_DUMP_PARAMETER(shaderResourceViewId, u);
}

SVGA3D_DUMP_HEADER(TransferFromBuffer)
{
   SVGA3D_DUMP_PARAMETER(srcSid, u);
   SVGA3D_DUMP_PARAMETER(srcOffset, u);
   SVGA3D_DUMP_PARAMETER(srcPitch, u);
   SVGA3D_DUMP_PARAMETER(srcSlicePitch, u);
   SVGA3D_DUMP_PARAMETER(destSid, u);
   SVGA3D_DUMP_PARAMETER(destSubResource, u);
   dump_SVGA3dBox(&cmd->destBox);
}

static void
dump_SVGA3dCmdIntraSurfaceCopy(const SVGA3dCmdIntraSurfaceCopy *cmd)
{
   SVGA3D_DUMP_PARAMETER(surface.sid, u);
   SVGA3D_DUMP_PARAMETER(surface.face, u);
   SVGA3D_DUMP_PARAMETER(surface.mipmap, u);
   dump_SVGA3dCopyBox(&cmd->box);
}

static void
dump_SVGA3dCmdInvalidateGBSurface(const SVGA3dCmdInvalidateGBSurface *cmd)
{
   SVGA3D_DUMP_PARAMETER(sid, u);
}

#define SVGA3D_DUMP_CASE_BASIC(CommandName, CommandCode) \
case SVGA_3D_CMD_DX_##CommandCode: \
   _debug_printf(SVGA3D_DUMP_STRINGIFY(\tSVGA_3D_CMD_DX_##CommandCode) "\n"); \
   { \
      const SVGA3dCmdDX##CommandName *cmd = (const SVGA3dCmdDX##CommandName *)body; \
      dump_SVGA3dCmdDX##CommandName(cmd); \
      body = (const uint8_t *)&cmd[1]; \
   } \
   break

#define SVGA3D_DUMP_CASE_LIST(CommandName, CommandCode, ElementType) \
case SVGA_3D_CMD_DX_##CommandCode: \
   _debug_printf(SVGA3D_DUMP_STRINGIFY(\tSVGA_3D_CMD_DX_##CommandCode) "\n"); \
   { \
      const SVGA3dCmdDX##CommandName *cmd = (const SVGA3dCmdDX##CommandName *)body; \
      dump_SVGA3dCmdDX##CommandName(cmd); \
      body = (const uint8_t *)&cmd[1]; \
      while (body + sizeof(ElementType) <= next) \
      { \
         dump_##ElementType((const ElementType *)body); \
         body += sizeof(ElementType); \
      } \
   } \
   break

void            
svga_dump_command(uint32_t cmd_id, const void *data, uint32_t size)
{
   const uint8_t *body = (const uint8_t *)data;
   const uint8_t *next = body + size;
  
   switch(cmd_id) {
   SVGA3D_DUMP_CASE_BASIC(BindContext, BIND_CONTEXT);
   SVGA3D_DUMP_CASE_LIST(SetViewports, SET_VIEWPORTS, SVGA3dViewport);
   SVGA3D_DUMP_CASE_BASIC(SetShader, SET_SHADER);
   SVGA3D_DUMP_CASE_LIST(SetSamplers, SET_SAMPLERS, SVGA3dSamplerId);
   SVGA3D_DUMP_CASE_BASIC(SetBlendState, SET_BLEND_STATE);
   SVGA3D_DUMP_CASE_BASIC(SetDepthStencilState, SET_DEPTHSTENCIL_STATE);
   SVGA3D_DUMP_CASE_BASIC(SetRasterizerState, SET_RASTERIZER_STATE);
   SVGA3D_DUMP_CASE_BASIC(SetPredication, SET_PREDICATION);
   SVGA3D_DUMP_CASE_LIST(SetSOTargets, SET_SOTARGETS, SVGA3dSoTarget);
   SVGA3D_DUMP_CASE_LIST(SetScissorRects, SET_SCISSORRECTS, SVGASignedRect);
   SVGA3D_DUMP_CASE_BASIC(SetStreamOutput, SET_STREAMOUTPUT);
   SVGA3D_DUMP_CASE_BASIC(SetSingleConstantBuffer, SET_SINGLE_CONSTANT_BUFFER);
   SVGA3D_DUMP_CASE_BASIC(Draw, DRAW);
   SVGA3D_DUMP_CASE_BASIC(DrawIndexed, DRAW_INDEXED);
   SVGA3D_DUMP_CASE_BASIC(DrawInstanced, DRAW_INSTANCED);
   SVGA3D_DUMP_CASE_BASIC(DrawIndexedInstanced, DRAW_INDEXED_INSTANCED);
   SVGA3D_DUMP_CASE_BASIC(DrawAuto, DRAW_AUTO);
   SVGA3D_DUMP_CASE_BASIC(DefineQuery, DEFINE_QUERY);
   SVGA3D_DUMP_CASE_BASIC(DestroyQuery, DESTROY_QUERY);
   SVGA3D_DUMP_CASE_BASIC(BindAllQuery, BIND_ALL_QUERY);
   SVGA3D_DUMP_CASE_BASIC(BindQuery, BIND_QUERY);
   SVGA3D_DUMP_CASE_BASIC(MoveQuery, MOVE_QUERY);
   SVGA3D_DUMP_CASE_BASIC(ReadbackAllQuery, READBACK_ALL_QUERY);
   SVGA3D_DUMP_CASE_BASIC(SetQueryOffset, SET_QUERY_OFFSET);
   SVGA3D_DUMP_CASE_BASIC(BeginQuery, BEGIN_QUERY);
   SVGA3D_DUMP_CASE_BASIC(EndQuery, END_QUERY);
   SVGA3D_DUMP_CASE_BASIC(ClearRenderTargetView, CLEAR_RENDERTARGET_VIEW);
   SVGA3D_DUMP_CASE_BASIC(ClearDepthStencilView, CLEAR_DEPTHSTENCIL_VIEW);
   SVGA3D_DUMP_CASE_BASIC(DefineShaderResourceView, DEFINE_SHADERRESOURCE_VIEW);
   SVGA3D_DUMP_CASE_LIST(SetShaderResources, SET_SHADER_RESOURCES, SVGA3dShaderResourceViewId);
   SVGA3D_DUMP_CASE_BASIC(DestroyShaderResourceView, DESTROY_SHADERRESOURCE_VIEW);
   SVGA3D_DUMP_CASE_BASIC(DefineRenderTargetView, DEFINE_RENDERTARGET_VIEW);
   SVGA3D_DUMP_CASE_BASIC(DestroyRenderTargetView, DESTROY_RENDERTARGET_VIEW);
   SVGA3D_DUMP_CASE_BASIC(DefineDepthStencilView, DEFINE_DEPTHSTENCIL_VIEW);
   SVGA3D_DUMP_CASE_BASIC(DestroyDepthStencilView, DESTROY_DEPTHSTENCIL_VIEW);
   SVGA3D_DUMP_CASE_LIST(DefineElementLayout, DEFINE_ELEMENTLAYOUT, SVGA3dInputElementDesc);
   SVGA3D_DUMP_CASE_BASIC(DestroyElementLayout, DESTROY_ELEMENTLAYOUT);
   SVGA3D_DUMP_CASE_BASIC(DefineBlendState, DEFINE_BLEND_STATE);
   SVGA3D_DUMP_CASE_BASIC(DestroyBlendState, DESTROY_BLEND_STATE);
   SVGA3D_DUMP_CASE_BASIC(DefineDepthStencilState, DEFINE_DEPTHSTENCIL_STATE);
   SVGA3D_DUMP_CASE_BASIC(DestroyDepthStencilState, DESTROY_DEPTHSTENCIL_STATE);
   SVGA3D_DUMP_CASE_BASIC(DefineRasterizerState, DEFINE_RASTERIZER_STATE);
   SVGA3D_DUMP_CASE_BASIC(DestroyRasterizerState, DESTROY_RASTERIZER_STATE);
   SVGA3D_DUMP_CASE_BASIC(DefineSamplerState, DEFINE_SAMPLER_STATE);
   SVGA3D_DUMP_CASE_BASIC(DestroySamplerState, DESTROY_SAMPLER_STATE);
   SVGA3D_DUMP_CASE_BASIC(DefineShader, DEFINE_SHADER);
   SVGA3D_DUMP_CASE_BASIC(DestroyShader, DESTROY_SHADER);
   SVGA3D_DUMP_CASE_BASIC(BindShader, BIND_SHADER);
   SVGA3D_DUMP_CASE_BASIC(DefineStreamOutput, DEFINE_STREAMOUTPUT);
   SVGA3D_DUMP_CASE_BASIC(DestroyStreamOutput, DESTROY_STREAMOUTPUT);
   SVGA3D_DUMP_CASE_BASIC(SetInputLayout, SET_INPUT_LAYOUT);
   SVGA3D_DUMP_CASE_LIST(SetVertexBuffers, SET_VERTEX_BUFFERS, SVGA3dVertexBuffer);
   SVGA3D_DUMP_CASE_BASIC(SetTopology, SET_TOPOLOGY);
   SVGA3D_DUMP_CASE_BASIC(SetIndexBuffer, SET_INDEX_BUFFER);

   SVGA3D_DUMP_CASE_BASIC(PredCopy, PRED_COPY);
   SVGA3D_DUMP_CASE_BASIC(UpdateSubResource, UPDATE_SUBRESOURCE);
   SVGA3D_DUMP_CASE_BASIC(ReadbackSubResource, READBACK_SUBRESOURCE);
   SVGA3D_DUMP_CASE_BASIC(PredCopyRegion, PRED_COPY_REGION);
   SVGA3D_DUMP_CASE_BASIC(BufferCopy, BUFFER_COPY);
   SVGA3D_DUMP_CASE_BASIC(BufferUpdate, BUFFER_UPDATE);
   SVGA3D_DUMP_CASE_BASIC(GenMips, GENMIPS);
   SVGA3D_DUMP_CASE_BASIC(TransferFromBuffer, TRANSFER_FROM_BUFFER);

   case SVGA_3D_CMD_DX_SET_RENDERTARGETS:
      _debug_printf("\tSVGA_3D_CMD_DX_SET_RENDERTARGETS\n");
      {
         const SVGA3dCmdDXSetRenderTargets *cmd =
            (const SVGA3dCmdDXSetRenderTargets *) body;
         _debug_printf("\t\t.depthStencilViewId = %u\n",
                       cmd->depthStencilViewId);
         body = (const uint8_t *) &cmd[1];
         while (body + sizeof(SVGA3dRenderTargetViewId) <= next) {
            _debug_printf("\t\t.renderTargetViewId = %u\n",
                          *((SVGA3dRenderTargetViewId *) body));
            body += sizeof(SVGA3dRenderTargetViewId);
         }
      }
      break;

   case SVGA_3D_CMD_SURFACE_DEFINE:
      _debug_printf("\tSVGA_3D_CMD_SURFACE_DEFINE\n");
      {
         const SVGA3dCmdDefineSurface *cmd = (const SVGA3dCmdDefineSurface *)body;
         dump_SVGA3dCmdDefineSurface(cmd);
         body = (const uint8_t *)&cmd[1];
         while(body + sizeof(SVGA3dSize) <= next) {
            dump_SVGA3dSize((const SVGA3dSize *)body);
            body += sizeof(SVGA3dSize);
         }
      }
      break;
   case SVGA_3D_CMD_SURFACE_DESTROY:
      _debug_printf("\tSVGA_3D_CMD_SURFACE_DESTROY\n");
      {
         const SVGA3dCmdDestroySurface *cmd = (const SVGA3dCmdDestroySurface *)body;
         dump_SVGA3dCmdDestroySurface(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_SURFACE_COPY:
      _debug_printf("\tSVGA_3D_CMD_SURFACE_COPY\n");
      {
         const SVGA3dCmdSurfaceCopy *cmd = (const SVGA3dCmdSurfaceCopy *)body;
         dump_SVGA3dCmdSurfaceCopy(cmd);
         body = (const uint8_t *)&cmd[1];
         while(body + sizeof(SVGA3dCopyBox) <= next) {
            dump_SVGA3dCopyBox((const SVGA3dCopyBox *)body);
            body += sizeof(SVGA3dCopyBox);
         }
      }
      break;
   case SVGA_3D_CMD_SURFACE_STRETCHBLT:
      _debug_printf("\tSVGA_3D_CMD_SURFACE_STRETCHBLT\n");
      {
         const SVGA3dCmdSurfaceStretchBlt *cmd = (const SVGA3dCmdSurfaceStretchBlt *)body;
         dump_SVGA3dCmdSurfaceStretchBlt(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_SURFACE_DMA:
      _debug_printf("\tSVGA_3D_CMD_SURFACE_DMA\n");
      {
         const SVGA3dCmdSurfaceDMA *cmd = (const SVGA3dCmdSurfaceDMA *)body;
         dump_SVGA3dCmdSurfaceDMA(cmd);
         body = (const uint8_t *)&cmd[1];
         while(body + sizeof(SVGA3dCopyBox) <= next) {
            dump_SVGA3dCopyBox((const SVGA3dCopyBox *)body);
            body += sizeof(SVGA3dCopyBox);
         }
         while(body + sizeof(SVGA3dCmdSurfaceDMASuffix) <= next) {
            dump_SVGA3dCmdSurfaceDMASuffix((const SVGA3dCmdSurfaceDMASuffix *)body);
            body += sizeof(SVGA3dCmdSurfaceDMASuffix);
         }
      }
      break;
   case SVGA_3D_CMD_CONTEXT_DEFINE:
      _debug_printf("\tSVGA_3D_CMD_CONTEXT_DEFINE\n");
      {
         const SVGA3dCmdDefineContext *cmd = (const SVGA3dCmdDefineContext *)body;
         dump_SVGA3dCmdDefineContext(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_CONTEXT_DESTROY:
      _debug_printf("\tSVGA_3D_CMD_CONTEXT_DESTROY\n");
      {
         const SVGA3dCmdDestroyContext *cmd = (const SVGA3dCmdDestroyContext *)body;
         dump_SVGA3dCmdDestroyContext(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_SETTRANSFORM:
      _debug_printf("\tSVGA_3D_CMD_SETTRANSFORM\n");
      {
         const SVGA3dCmdSetTransform *cmd = (const SVGA3dCmdSetTransform *)body;
         dump_SVGA3dCmdSetTransform(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_SETZRANGE:
      _debug_printf("\tSVGA_3D_CMD_SETZRANGE\n");
      {
         const SVGA3dCmdSetZRange *cmd = (const SVGA3dCmdSetZRange *)body;
         dump_SVGA3dCmdSetZRange(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_SETRENDERSTATE:
      _debug_printf("\tSVGA_3D_CMD_SETRENDERSTATE\n");
      {
         const SVGA3dCmdSetRenderState *cmd = (const SVGA3dCmdSetRenderState *)body;
         dump_SVGA3dCmdSetRenderState(cmd);
         body = (const uint8_t *)&cmd[1];
         while(body + sizeof(SVGA3dRenderState) <= next) {
            dump_SVGA3dRenderState((const SVGA3dRenderState *)body);
            body += sizeof(SVGA3dRenderState);
         }
      }
      break;
   case SVGA_3D_CMD_SETRENDERTARGET:
      _debug_printf("\tSVGA_3D_CMD_SETRENDERTARGET\n");
      {
         const SVGA3dCmdSetRenderTarget *cmd = (const SVGA3dCmdSetRenderTarget *)body;
         dump_SVGA3dCmdSetRenderTarget(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_SETTEXTURESTATE:
      _debug_printf("\tSVGA_3D_CMD_SETTEXTURESTATE\n");
      {
         const SVGA3dCmdSetTextureState *cmd = (const SVGA3dCmdSetTextureState *)body;
         dump_SVGA3dCmdSetTextureState(cmd);
         body = (const uint8_t *)&cmd[1];
         while(body + sizeof(SVGA3dTextureState) <= next) {
            dump_SVGA3dTextureState((const SVGA3dTextureState *)body);
            body += sizeof(SVGA3dTextureState);
         }
      }
      break;
   case SVGA_3D_CMD_SETMATERIAL:
      _debug_printf("\tSVGA_3D_CMD_SETMATERIAL\n");
      {
         const SVGA3dCmdSetMaterial *cmd = (const SVGA3dCmdSetMaterial *)body;
         dump_SVGA3dCmdSetMaterial(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_SETLIGHTDATA:
      _debug_printf("\tSVGA_3D_CMD_SETLIGHTDATA\n");
      {
         const SVGA3dCmdSetLightData *cmd = (const SVGA3dCmdSetLightData *)body;
         dump_SVGA3dCmdSetLightData(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_SETLIGHTENABLED:
      _debug_printf("\tSVGA_3D_CMD_SETLIGHTENABLED\n");
      {
         const SVGA3dCmdSetLightEnabled *cmd = (const SVGA3dCmdSetLightEnabled *)body;
         dump_SVGA3dCmdSetLightEnabled(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_SETVIEWPORT:
      _debug_printf("\tSVGA_3D_CMD_SETVIEWPORT\n");
      {
         const SVGA3dCmdSetViewport *cmd = (const SVGA3dCmdSetViewport *)body;
         dump_SVGA3dCmdSetViewport(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_SETCLIPPLANE:
      _debug_printf("\tSVGA_3D_CMD_SETCLIPPLANE\n");
      {
         const SVGA3dCmdSetClipPlane *cmd = (const SVGA3dCmdSetClipPlane *)body;
         dump_SVGA3dCmdSetClipPlane(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_CLEAR:
      _debug_printf("\tSVGA_3D_CMD_CLEAR\n");
      {
         const SVGA3dCmdClear *cmd = (const SVGA3dCmdClear *)body;
         dump_SVGA3dCmdClear(cmd);
         body = (const uint8_t *)&cmd[1];
         while(body + sizeof(SVGA3dRect) <= next) {
            dump_SVGA3dRect((const SVGA3dRect *)body);
            body += sizeof(SVGA3dRect);
         }
      }
      break;
   case SVGA_3D_CMD_PRESENT:
      _debug_printf("\tSVGA_3D_CMD_PRESENT\n");
      {
         const SVGA3dCmdPresent *cmd = (const SVGA3dCmdPresent *)body;
         dump_SVGA3dCmdPresent(cmd);
         body = (const uint8_t *)&cmd[1];
         while(body + sizeof(SVGA3dCopyRect) <= next) {
            dump_SVGA3dCopyRect((const SVGA3dCopyRect *)body);
            body += sizeof(SVGA3dCopyRect);
         }
      }
      break;
   case SVGA_3D_CMD_SHADER_DEFINE:
      _debug_printf("\tSVGA_3D_CMD_SHADER_DEFINE\n");
      {
         const SVGA3dCmdDefineShader *cmd = (const SVGA3dCmdDefineShader *)body;
         dump_SVGA3dCmdDefineShader(cmd);
         body = (const uint8_t *)&cmd[1];
         //svga_shader_dump((const uint32_t *)body, 
         //             (unsigned)(next - body)/sizeof(uint32_t),
         //             FALSE );
         body = next;
      }
      break;
   case SVGA_3D_CMD_SHADER_DESTROY:
      _debug_printf("\tSVGA_3D_CMD_SHADER_DESTROY\n");
      {
         const SVGA3dCmdDestroyShader *cmd = (const SVGA3dCmdDestroyShader *)body;
         dump_SVGA3dCmdDestroyShader(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_SET_SHADER:
      _debug_printf("\tSVGA_3D_CMD_SET_SHADER\n");
      {
         const SVGA3dCmdSetShader *cmd = (const SVGA3dCmdSetShader *)body;
         dump_SVGA3dCmdSetShader(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_SET_SHADER_CONST:
      _debug_printf("\tSVGA_3D_CMD_SET_SHADER_CONST\n");
      {
         const SVGA3dCmdSetShaderConst *cmd = (const SVGA3dCmdSetShaderConst *)body;
         uint32 numConsts = 1 + (size - sizeof *cmd) / (4 * sizeof(uint32));
         dump_SVGA3dCmdSetShaderConst(cmd, numConsts);
         body = next;
      }
      break;
   case SVGA_3D_CMD_DRAW_PRIMITIVES:
      _debug_printf("\tSVGA_3D_CMD_DRAW_PRIMITIVES\n");
      {
         const SVGA3dCmdDrawPrimitives *cmd = (const SVGA3dCmdDrawPrimitives *)body;
         unsigned i, j;
         dump_SVGA3dCmdDrawPrimitives(cmd);
         body = (const uint8_t *)&cmd[1];
         for(i = 0; i < cmd->numVertexDecls; ++i) {
            dump_SVGA3dVertexDecl((const SVGA3dVertexDecl *)body);
            body += sizeof(SVGA3dVertexDecl);
         }
         for(j = 0; j < cmd->numRanges; ++j) {
            dump_SVGA3dPrimitiveRange((const SVGA3dPrimitiveRange *)body);
            body += sizeof(SVGA3dPrimitiveRange);
         }
         while(body + sizeof(SVGA3dVertexDivisor) <= next) {
            dump_SVGA3dVertexDivisor((const SVGA3dVertexDivisor *)body);
            body += sizeof(SVGA3dVertexDivisor);
         }
      }
      break;
   case SVGA_3D_CMD_SETSCISSORRECT:
      _debug_printf("\tSVGA_3D_CMD_SETSCISSORRECT\n");
      {
         const SVGA3dCmdSetScissorRect *cmd = (const SVGA3dCmdSetScissorRect *)body;
         dump_SVGA3dCmdSetScissorRect(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_BEGIN_QUERY:
      _debug_printf("\tSVGA_3D_CMD_BEGIN_QUERY\n");
      {
         const SVGA3dCmdBeginQuery *cmd = (const SVGA3dCmdBeginQuery *)body;
         dump_SVGA3dCmdBeginQuery(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_END_QUERY:
      _debug_printf("\tSVGA_3D_CMD_END_QUERY\n");
      {
         const SVGA3dCmdEndQuery *cmd = (const SVGA3dCmdEndQuery *)body;
         dump_SVGA3dCmdEndQuery(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_WAIT_FOR_QUERY:
      _debug_printf("\tSVGA_3D_CMD_WAIT_FOR_QUERY\n");
      {
         const SVGA3dCmdWaitForQuery *cmd = (const SVGA3dCmdWaitForQuery *)body;
         dump_SVGA3dCmdWaitForQuery(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN:
      _debug_printf("\tSVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN\n");
      {
         const SVGA3dCmdBlitSurfaceToScreen *cmd = (const SVGA3dCmdBlitSurfaceToScreen *)body;
         dump_SVGA3dCmdBlitSurfaceToScreen(cmd);
         body = (const uint8_t *)&cmd[1];
         while(body + sizeof(SVGASignedRect) <= next) {
            dump_SVGASignedRect((const SVGASignedRect *)body);
            body += sizeof(SVGASignedRect);
         }
      }
      break;
   case SVGA_3D_CMD_DEFINE_GB_CONTEXT:
      _debug_printf("\tSVGA_3D_CMD_DEFINE_GB_CONTEXT\n");
      {
         const SVGA3dCmdDefineGBContext *cmd = (const SVGA3dCmdDefineGBContext *) body;
         dump_SVGA3dCmdDefineGBContext(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_BIND_GB_CONTEXT:
      _debug_printf("\tSVGA_3D_CMD_BIND_GB_CONTEXT\n");
      {
         const SVGA3dCmdBindGBContext *cmd = (const SVGA3dCmdBindGBContext *) body;
         dump_SVGA3dCmdBindGBContext(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_DESTROY_GB_CONTEXT:
      _debug_printf("\tSVGA_3D_CMD_DESTROY_GB_CONTEXT\n");
      {
         const SVGA3dCmdDestroyGBContext *cmd = (const SVGA3dCmdDestroyGBContext *) body;
         dump_SVGA3dCmdDestroyGBContext(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_DEFINE_GB_SHADER:
      _debug_printf("\tSVGA_3D_CMD_DEFINE_GB_SHADER\n");
      {
         const SVGA3dCmdDefineGBShader *cmd = (const SVGA3dCmdDefineGBShader *) body;
         dump_SVGA3dCmdDefineGBShader(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_BIND_GB_SHADER:
      _debug_printf("\tSVGA_3D_CMD_BIND_GB_SHADER\n");
      {
         const SVGA3dCmdBindGBShader *cmd = (const SVGA3dCmdBindGBShader *) body;
         dump_SVGA3dCmdBindGBShader(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_DESTROY_GB_SHADER:
      _debug_printf("\tSVGA_3D_CMD_DESTROY_GB_SHADER\n");
      {
         const SVGA3dCmdDestroyGBShader *cmd = (const SVGA3dCmdDestroyGBShader *) body;
         dump_SVGA3dCmdDestroyGBShader(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_BIND_GB_SURFACE:
      _debug_printf("\tSVGA_3D_CMD_BIND_GB_SURFACE\n");
      {
         const SVGA3dCmdBindGBSurface *cmd = (const SVGA3dCmdBindGBSurface *) body;
         dump_SVGA3dCmdBindGBSurface(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_UPDATE_GB_SURFACE:
      _debug_printf("\tSVGA_3D_CMD_UPDATE_GB_SURFACE\n");
      {
         const SVGA3dCmdUpdateGBSurface *cmd = (const SVGA3dCmdUpdateGBSurface *) body;
         dump_SVGA3dCmdUpdateGBSurface(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_READBACK_GB_IMAGE:
      _debug_printf("\tSVGA_3D_CMD_READBACK_GB_IMAGE:\n");
      {
         const SVGA3dCmdReadbackGBImage *cmd = (SVGA3dCmdReadbackGBImage *) body;
         dump_SVGA3dCmdReadbackGBImage(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_UPDATE_GB_IMAGE:
      _debug_printf("\tSVGA_3D_CMD_UPDATE_GB_IMAGE\n");
      {
         const SVGA3dCmdUpdateGBImage *cmd = (const SVGA3dCmdUpdateGBImage *) body;
         dump_SVGA3dCmdUpdateGBImage(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_INVALIDATE_GB_IMAGE:
      _debug_printf("\tSVGA_3D_CMD_INVALIDATE_GB_IMAGE\n");
      {
         const SVGA3dCmdInvalidateGBImage *cmd = (const SVGA3dCmdInvalidateGBImage *) body;
         dump_SVGA3dCmdInvalidateGBImage(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_INVALIDATE_GB_IMAGE_PARTIAL:
      _debug_printf("\tSVGA_3D_CMD_INVALIDATE_GB_IMAGE_PARTIAL\n");
      {
         const SVGA3dCmdInvalidateGBImagePartial *cmd = (const SVGA3dCmdInvalidateGBImagePartial *) body;
         dump_SVGA3dCmdInvalidateGBImagePartial(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_SET_GB_SHADERCONSTS_INLINE:
      _debug_printf("\tSVGA_3D_CMD_SET_GB_SHADERCONSTS_INLINE\n");
      {
         /* XXX Note: re-using the SVGA3dCmdSetShaderConst code here */
         const SVGA3dCmdSetGBShaderConstInline *cmd = (const SVGA3dCmdSetGBShaderConstInline *)body;
         uint32 numConsts = (size - sizeof *cmd) / (4 * sizeof(uint32));
         dump_SVGA3dCmdSetGBShaderConstInline(cmd, numConsts);
         body = next;
      }
      break;
   case SVGA_3D_CMD_INVALIDATE_GB_SURFACE:
      _debug_printf("\tSVGA_3D_CMD_INVALIDATE_GB_SURFACE\n");
      {
         const SVGA3dCmdInvalidateGBSurface *cmd = (const SVGA3dCmdInvalidateGBSurface *)body;
         dump_SVGA3dCmdInvalidateGBSurface(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   case SVGA_3D_CMD_INTRA_SURFACE_COPY:
      _debug_printf("\tSVGA_3D_CMD_INTRA_SURFACE_COPY\n");
      {
         const SVGA3dCmdIntraSurfaceCopy *cmd = (const SVGA3dCmdIntraSurfaceCopy *)body;
         dump_SVGA3dCmdIntraSurfaceCopy(cmd);
         body = (const uint8_t *)&cmd[1];
      }
      break;
   default:
      _debug_printf("\t0x%08x\n", cmd_id);
      break;
   }

   while(body + sizeof(uint32_t) <= next) {
      _debug_printf("\t\t0x%08x\n", *(const uint32_t *)body);
      body += sizeof(uint32_t);
   }
   while(body + sizeof(uint32_t) <= next)
      _debug_printf("\t\t0x%02x\n", *body++);
}


void            
svga_dump_commands(const void *commands, uint32_t size)
{
   const uint8_t *next = commands;
   const uint8_t *last = next + size;
   
   //assert(size % sizeof(uint32_t) == 0);
   
   while(next < last) {
      const uint32_t cmd_id = *(const uint32_t *)next;

      if(SVGA_3D_CMD_BASE <= cmd_id && cmd_id < SVGA_3D_CMD_MAX) {
         const SVGA3dCmdHeader *header = (const SVGA3dCmdHeader *)next;
         const uint8_t *body = (const uint8_t *)&header[1];

         next = body + header->size;
         if(next > last)
            break;

         svga_dump_command(cmd_id, body, header->size);
      }
      else if(cmd_id == SVGA_CMD_FENCE) {
         _debug_printf("\tSVGA_CMD_FENCE\n");
         _debug_printf("\t\t0x%08x\n", ((const uint32_t *)next)[1]);
         next += 2*sizeof(uint32_t);
      }
      else {
         _debug_printf("\t0x%08x\n", cmd_id);
         next += sizeof(uint32_t);
      }
   }
}
#endif /* LOG_ENABLED */