summaryrefslogtreecommitdiffstats
path: root/src/VBox/Devices/Graphics/DevVGA-SVGA3d-shared.cpp
blob: c7c8e4403fc35cacdc2188546a001de54d06b3b0 (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
/* $Id: DevVGA-SVGA3d-shared.cpp $ */
/** @file
 * DevVMWare - VMWare SVGA device
 */

/*
 * Copyright (C) 2013-2023 Oracle and/or its affiliates.
 *
 * This file is part of VirtualBox base platform packages, as
 * available from https://www.virtualbox.org.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, in version 3 of the
 * License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <https://www.gnu.org/licenses>.
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */


/*********************************************************************************************************************************
*   Header Files                                                                                                                 *
*********************************************************************************************************************************/
#define LOG_GROUP LOG_GROUP_DEV_VMSVGA
#include <VBox/vmm/pdmdev.h>
#include <VBox/version.h>
#include <iprt/errcore.h>
#include <VBox/log.h>
#include <VBox/vmm/pgm.h>

#include <iprt/assert.h>
#include <iprt/semaphore.h>
#include <iprt/uuid.h>
#include <iprt/mem.h>
#include <iprt/avl.h>

#include <VBoxVideo.h> /* required by DevVGA.h */

/* should go BEFORE any other DevVGA include to make all DevVGA.h config defines be visible */
#include "DevVGA.h"

#include "DevVGA-SVGA.h"
#include "DevVGA-SVGA3d.h"
#define VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
#include "DevVGA-SVGA3d-internal.h"


#ifdef RT_OS_WINDOWS
# define VMSVGA3D_WNDCLASSNAME  L"VMSVGA3DWNDCLS"

static LONG WINAPI vmsvga3dWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);


/**
 * Send a message to the async window thread and wait for a reply
 *
 * @returns VBox status code.
 * @param   pWindowThread   Thread handle
 * @param   WndRequestSem   Semaphore handle for waiting
 * @param   msg             Message id
 * @param   wParam          First parameter
 * @param   lParam          Second parameter
 */
int vmsvga3dSendThreadMessage(RTTHREAD pWindowThread, RTSEMEVENT WndRequestSem, UINT msg, WPARAM wParam, LPARAM lParam)
{
    int  rc;
    BOOL ret;

    ret = PostThreadMessage(RTThreadGetNative(pWindowThread), msg, wParam, lParam);
    AssertMsgReturn(ret, ("PostThreadMessage %x failed with %d\n", RTThreadGetNative(pWindowThread), GetLastError()), VERR_INTERNAL_ERROR);

    rc = RTSemEventWait(WndRequestSem, RT_INDEFINITE_WAIT);
    Assert(RT_SUCCESS(rc));

    return rc;
}

/**
 * The async window handling thread
 *
 * @returns VBox status code.
 * @param   hThreadSelf     This thread.
 * @param   pvUser          Request sempahore handle.
 */
DECLCALLBACK(int) vmsvga3dWindowThread(RTTHREAD hThreadSelf, void *pvUser)
{
    RT_NOREF(hThreadSelf);
    RTSEMEVENT      WndRequestSem = (RTSEMEVENT)pvUser;
    WNDCLASSEXW     wc;

    /* Register our own window class. */
    wc.cbSize           = sizeof(wc);
    wc.style            = CS_OWNDC;
    wc.lpfnWndProc      = (WNDPROC)vmsvga3dWndProc;
    wc.cbClsExtra       = 0;
    wc.cbWndExtra       = 0;
    wc.hInstance        = GetModuleHandle("VBoxDD.dll");    /** @todo hardcoded name.. */
    wc.hIcon            = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor          = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground    = NULL;
    wc.lpszMenuName     = NULL;
    wc.lpszClassName    = VMSVGA3D_WNDCLASSNAME;
    wc.hIconSm          = NULL;

    if (!RegisterClassExW(&wc))
    {
        Log(("RegisterClass failed with %x\n", GetLastError()));
        return VERR_INTERNAL_ERROR;
    }

    LogFlow(("vmsvga3dWindowThread: started loop\n"));
    while (true)
    {
        MSG msg;
        if (GetMessage(&msg, 0, 0, 0))
        {
            if (msg.message == WM_VMSVGA3D_EXIT)
            {
                /* Signal to the caller that we're done. */
                RTSemEventSignal(WndRequestSem);
                break;
            }

            if (msg.message == WM_VMSVGA3D_WAKEUP)
            {
                continue;
            }

            if (msg.message == WM_VMSVGA3D_CREATEWINDOW)
            {
                /* Create a context window with minimal 4x4 size. We will never use the swapchain
                 * to present the rendered image. Rendered images from the guest will be copied to
                 * the VMSVGA SCREEN object, which can be either an offscreen render target or
                 * system memory in the guest VRAM. */
                HWND *phWnd = (HWND *)msg.wParam;
                HWND  hWnd;
                *phWnd = hWnd = CreateWindowExW(WS_EX_NOACTIVATE | WS_EX_NOPARENTNOTIFY,
                                                VMSVGA3D_WNDCLASSNAME,
                                                NULL /*pwszName*/,
                                                WS_DISABLED,
                                                0 /*x*/,
                                                0 /*y*/,
                                                4 /*cx*/,
                                                4 /*cy*/,
                                                HWND_DESKTOP /*hwndParent*/,
                                                NULL /*hMenu*/,
                                                (HINSTANCE)msg.lParam /*hInstance*/,
                                                NULL /*WM_CREATE param*/);
                AssertMsg(hWnd, ("CreateWindowEx %ls, WS_EX_NOACTIVATE | WS_EX_NOPARENTNOTIFY, WS_DISABLED, (0,0)(4,4), HWND_DESKTOP hInstance=%p -> error=%x\n",
                                 VMSVGA3D_WNDCLASSNAME, msg.lParam, GetLastError()));

#ifdef VBOX_STRICT
                /* Must have a non-zero client rectangle! */
                RECT ClientRect;
                GetClientRect(hWnd, &ClientRect);
                Assert(ClientRect.right > ClientRect.left);
                Assert(ClientRect.bottom > ClientRect.top);
#endif

                /* Signal to the caller that we're done. */
                RTSemEventSignal(WndRequestSem);
                continue;
            }

            if (msg.message == WM_VMSVGA3D_DESTROYWINDOW)
            {
                BOOL fRc = DestroyWindow((HWND)msg.wParam);
                Assert(fRc); NOREF(fRc);

                /* Signal to the caller that we're done. */
                RTSemEventSignal(WndRequestSem);
                continue;
            }

#if 0 /* in case CreateDeviceEx fails again and we want to eliminat wrong-thread. */
            if (msg.message == WM_VMSVGA3D_CREATE_DEVICE)
            {
                VMSVGA3DCREATEDEVICEPARAMS *pParams = (VMSVGA3DCREATEDEVICEPARAMS *)msg.lParam;
                pParams->hrc = pParams->pState->pD3D9->CreateDeviceEx(D3DADAPTER_DEFAULT,
                                                                      D3DDEVTYPE_HAL,
                                                                      pParams->pContext->hwnd,
                                                                      D3DCREATE_MULTITHREADED | D3DCREATE_MIXED_VERTEXPROCESSING, //D3DCREATE_HARDWARE_VERTEXPROCESSING,
                                                                      pParams->pPresParams,
                                                                      NULL,
                                                                      &pParams->pContext->pDevice);
                AssertMsg(pParams->hrc == D3D_OK, ("WM_VMSVGA3D_CREATE_DEVICE: CreateDevice failed with %x\n", pParams->hrc));

                RTSemEventSignal(WndRequestSem);
                continue;
            }
#endif

            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else
        {
            Log(("GetMessage failed with %x\n", GetLastError()));
            break;
        }
    }

    Log(("vmsvga3dWindowThread: end loop\n"));
    return VINF_SUCCESS;
}

/* Window procedure for our top level window overlays. */
static LONG WINAPI vmsvga3dWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
        case WM_CREATE:
        {
            /* Ditch the title bar (caption) to avoid having a zero height
               client area as that makes IDirect3D9Ex::CreateDeviceEx fail.
               For the style adjustment to take place, we must apply the
               SWP_FRAMECHANGED thru SetWindowPos. */
            LONG flStyle = GetWindowLongW(hwnd, GWL_STYLE);
            flStyle &= ~(WS_CAPTION /* both titlebar and border. Some paranoia: */ | WS_THICKFRAME | WS_SYSMENU);
            SetWindowLong(hwnd, GWL_STYLE, flStyle);
            SetWindowPos(hwnd, NULL, 0, 0, 0, 0,
                         SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
            break;
        }

        case WM_CLOSE:
            Log7(("vmsvga3dWndProc(%p): WM_CLOSE\n", hwnd));
            break;

        case WM_DESTROY:
            Log7(("vmsvga3dWndProc(%p): WM_DESTROY\n", hwnd));
            break;

        case WM_NCHITTEST:
            Log7(("vmsvga3dWndProc(%p): WM_NCHITTEST\n", hwnd));
            return HTNOWHERE;

# if 0 /* flicker experiment, no help here. */
        case WM_PAINT:
            Log7(("vmsvga3dWndProc(%p): WM_PAINT %p %p\n", hwnd, wParam, lParam));
            ValidateRect(hwnd, NULL);
            return 0;
        case WM_ERASEBKGND:
            Log7(("vmsvga3dWndProc(%p): WM_ERASEBKGND %p %p\n", hwnd, wParam, lParam));
            return TRUE;
        case WM_NCPAINT:
            Log7(("vmsvga3dWndProc(%p): WM_NCPAINT %p %p\n", hwnd, wParam, lParam));
            break;
        case WM_WINDOWPOSCHANGING:
        {
            PWINDOWPOS pPos = (PWINDOWPOS)lParam;
            Log7(("vmsvga3dWndProc(%p): WM_WINDOWPOSCHANGING %p %p pos=(%d,%d) size=(%d,%d) flags=%#x\n",
                  hwnd, wParam, lParam, pPos->x, pPos->y, pPos->cx, pPos->cy, pPos->flags));
            break;
        }
        case WM_WINDOWPOSCHANGED:
        {
            PWINDOWPOS pPos = (PWINDOWPOS)lParam;
            Log7(("vmsvga3dWndProc(%p): WM_WINDOWPOSCHANGED %p %p pos=(%d,%d) size=(%d,%d) flags=%#x\n",
                  hwnd, wParam, lParam, pPos->x, pPos->y, pPos->cx, pPos->cy, pPos->flags));
            break;
        }
        case WM_MOVE:
            Log7(("vmsvga3dWndProc(%p): WM_MOVE %p %p\n", hwnd, wParam, lParam));
            break;
        case WM_SIZE:
            Log7(("vmsvga3dWndProc(%p): WM_SIZE %p %p\n", hwnd, wParam, lParam));
            break;

        default:
            Log7(("vmsvga3dWndProc(%p): %#x %p %p\n", hwnd, uMsg, wParam, lParam));
# endif
    }
    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

int vmsvga3dContextWindowCreate(HINSTANCE hInstance, RTTHREAD pWindowThread, RTSEMEVENT WndRequestSem, HWND *pHwnd)
{
    return vmsvga3dSendThreadMessage(pWindowThread, WndRequestSem, WM_VMSVGA3D_CREATEWINDOW, (WPARAM)pHwnd, (LPARAM)hInstance);
}

#endif /* RT_OS_WINDOWS */


/**
 * Calculate the size and dimensions of one block.
 */
uint32_t vmsvga3dSurfaceFormatSize(SVGA3dSurfaceFormat format,
                                   uint32_t *pcxBlock,
                                   uint32_t *pcyBlock)
{
    uint32_t u32 = 0;
    if (!pcxBlock) pcxBlock = &u32;
    if (!pcyBlock) pcyBlock = &u32;

    switch (format)
    {
    case SVGA3D_X8R8G8B8:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_A8R8G8B8:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R5G6B5:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_X1R5G5B5:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_A1R5G5B5:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_A4R4G4B4:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_Z_D32:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_Z_D16:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_Z_D24S8:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_Z_D15S1:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_LUMINANCE8:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 1;

    case SVGA3D_LUMINANCE4_ALPHA4:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 1;

    case SVGA3D_LUMINANCE16:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_LUMINANCE8_ALPHA8:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_DXT1:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 8;

    case SVGA3D_DXT2:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 16;

    case SVGA3D_DXT3:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 16;

    case SVGA3D_DXT4:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 16;

    case SVGA3D_DXT5:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 16;

    case SVGA3D_BUMPU8V8:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_BUMPL6V5U5:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_BUMPX8L8V8U8:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_FORMAT_DEAD1:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 3;

    case SVGA3D_ARGB_S10E5:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 8;

    case SVGA3D_ARGB_S23E8:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 16;

    case SVGA3D_A2R10G10B10:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_V8U8:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_Q8W8V8U8:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_CxV8U8:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_X8L8V8U8:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_A2W10V10U10:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_ALPHA8:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 1;

    case SVGA3D_R_S10E5:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_R_S23E8:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_RG_S10E5:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_RG_S23E8:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 8;

    case SVGA3D_BUFFER:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 1;

    case SVGA3D_Z_D24X8:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_V16U16:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_G16R16:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_A16B16G16R16:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 8;

    case SVGA3D_UYVY:
        *pcxBlock = 2;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_YUY2:
        *pcxBlock = 2;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_NV12:
        *pcxBlock = 2;
        *pcyBlock = 2;
        return 6;

    case SVGA3D_FORMAT_DEAD2:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R32G32B32A32_TYPELESS:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 16;

    case SVGA3D_R32G32B32A32_UINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 16;

    case SVGA3D_R32G32B32A32_SINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 16;

    case SVGA3D_R32G32B32_TYPELESS:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 12;

    case SVGA3D_R32G32B32_FLOAT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 12;

    case SVGA3D_R32G32B32_UINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 12;

    case SVGA3D_R32G32B32_SINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 12;

    case SVGA3D_R16G16B16A16_TYPELESS:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 8;

    case SVGA3D_R16G16B16A16_UINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 8;

    case SVGA3D_R16G16B16A16_SNORM:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 8;

    case SVGA3D_R16G16B16A16_SINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 8;

    case SVGA3D_R32G32_TYPELESS:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 8;

    case SVGA3D_R32G32_UINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 8;

    case SVGA3D_R32G32_SINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 8;

    case SVGA3D_R32G8X24_TYPELESS:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 8;

    case SVGA3D_D32_FLOAT_S8X24_UINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 8;

    case SVGA3D_R32_FLOAT_X8X24:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 8;

    case SVGA3D_X32_G8X24_UINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 8;

    case SVGA3D_R10G10B10A2_TYPELESS:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R10G10B10A2_UINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R11G11B10_FLOAT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R8G8B8A8_TYPELESS:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R8G8B8A8_UNORM:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R8G8B8A8_UNORM_SRGB:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R8G8B8A8_UINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R8G8B8A8_SINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R16G16_TYPELESS:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R16G16_UINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R16G16_SINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R32_TYPELESS:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_D32_FLOAT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R32_UINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R32_SINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R24G8_TYPELESS:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_D24_UNORM_S8_UINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R24_UNORM_X8:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_X24_G8_UINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R8G8_TYPELESS:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_R8G8_UNORM:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_R8G8_UINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_R8G8_SINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_R16_TYPELESS:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_R16_UNORM:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_R16_UINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_R16_SNORM:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_R16_SINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_R8_TYPELESS:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 1;

    case SVGA3D_R8_UNORM:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 1;

    case SVGA3D_R8_UINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 1;

    case SVGA3D_R8_SNORM:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 1;

    case SVGA3D_R8_SINT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 1;

    case SVGA3D_P8:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 1;

    case SVGA3D_R9G9B9E5_SHAREDEXP:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R8G8_B8G8_UNORM:
        *pcxBlock = 2;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_G8R8_G8B8_UNORM:
        *pcxBlock = 2;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_BC1_TYPELESS:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 8;

    case SVGA3D_BC1_UNORM_SRGB:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 8;

    case SVGA3D_BC2_TYPELESS:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 16;

    case SVGA3D_BC2_UNORM_SRGB:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 16;

    case SVGA3D_BC3_TYPELESS:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 16;

    case SVGA3D_BC3_UNORM_SRGB:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 16;

    case SVGA3D_BC4_TYPELESS:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 8;

    case SVGA3D_ATI1:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 8;

    case SVGA3D_BC4_SNORM:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 8;

    case SVGA3D_BC5_TYPELESS:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 16;

    case SVGA3D_ATI2:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 16;

    case SVGA3D_BC5_SNORM:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 16;

    case SVGA3D_R10G10B10_XR_BIAS_A2_UNORM:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_B8G8R8A8_TYPELESS:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_B8G8R8A8_UNORM_SRGB:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_B8G8R8X8_TYPELESS:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_B8G8R8X8_UNORM_SRGB:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_Z_DF16:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_Z_DF24:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_Z_D24S8_INT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_YV12:
        *pcxBlock = 2;
        *pcyBlock = 2;
        return 6;

    case SVGA3D_R32G32B32A32_FLOAT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 16;

    case SVGA3D_R16G16B16A16_FLOAT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 8;

    case SVGA3D_R16G16B16A16_UNORM:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 8;

    case SVGA3D_R32G32_FLOAT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 8;

    case SVGA3D_R10G10B10A2_UNORM:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R8G8B8A8_SNORM:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R16G16_FLOAT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R16G16_UNORM:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R16G16_SNORM:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R32_FLOAT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_R8G8_SNORM:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_R16_FLOAT:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_D16_UNORM:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_A8_UNORM:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 1;

    case SVGA3D_BC1_UNORM:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 8;

    case SVGA3D_BC2_UNORM:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 16;

    case SVGA3D_BC3_UNORM:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 16;

    case SVGA3D_B5G6R5_UNORM:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_B5G5R5A1_UNORM:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_B8G8R8A8_UNORM:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_B8G8R8X8_UNORM:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    case SVGA3D_BC4_UNORM:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 8;

    case SVGA3D_BC5_UNORM:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 16;

    case SVGA3D_B4G4R4A4_UNORM:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 2;

    case SVGA3D_BC6H_TYPELESS:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 16;

    case SVGA3D_BC6H_UF16:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 16;

    case SVGA3D_BC6H_SF16:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 16;

    case SVGA3D_BC7_TYPELESS:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 16;

    case SVGA3D_BC7_UNORM:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 16;

    case SVGA3D_BC7_UNORM_SRGB:
        *pcxBlock = 4;
        *pcyBlock = 4;
        return 16;

    case SVGA3D_AYUV:
        *pcxBlock = 1;
        *pcyBlock = 1;
        return 4;

    default:
        *pcxBlock = 1;
        *pcyBlock = 1;
        AssertFailedReturn(4);
    }
}

#ifdef LOG_ENABLED

const char *vmsvga3dGetCapString(uint32_t idxCap)
{
    switch (idxCap)
    {
    case SVGA3D_DEVCAP_3D:
        return "SVGA3D_DEVCAP_3D";
    case SVGA3D_DEVCAP_MAX_LIGHTS:
        return "SVGA3D_DEVCAP_MAX_LIGHTS";
    case SVGA3D_DEVCAP_MAX_TEXTURES:
        return "SVGA3D_DEVCAP_MAX_TEXTURES";
    case SVGA3D_DEVCAP_MAX_CLIP_PLANES:
        return "SVGA3D_DEVCAP_MAX_CLIP_PLANES";
    case SVGA3D_DEVCAP_VERTEX_SHADER_VERSION:
        return "SVGA3D_DEVCAP_VERTEX_SHADER_VERSION";
    case SVGA3D_DEVCAP_VERTEX_SHADER:
        return "SVGA3D_DEVCAP_VERTEX_SHADER";
    case SVGA3D_DEVCAP_FRAGMENT_SHADER_VERSION:
        return "SVGA3D_DEVCAP_FRAGMENT_SHADER_VERSION";
    case SVGA3D_DEVCAP_FRAGMENT_SHADER:
        return "SVGA3D_DEVCAP_FRAGMENT_SHADER";
    case SVGA3D_DEVCAP_MAX_RENDER_TARGETS:
        return "SVGA3D_DEVCAP_MAX_RENDER_TARGETS";
    case SVGA3D_DEVCAP_S23E8_TEXTURES:
        return "SVGA3D_DEVCAP_S23E8_TEXTURES";
    case SVGA3D_DEVCAP_S10E5_TEXTURES:
        return "SVGA3D_DEVCAP_S10E5_TEXTURES";
    case SVGA3D_DEVCAP_MAX_FIXED_VERTEXBLEND:
        return "SVGA3D_DEVCAP_MAX_FIXED_VERTEXBLEND";
    case SVGA3D_DEVCAP_D16_BUFFER_FORMAT:
        return "SVGA3D_DEVCAP_D16_BUFFER_FORMAT";
    case SVGA3D_DEVCAP_D24S8_BUFFER_FORMAT:
        return "SVGA3D_DEVCAP_D24S8_BUFFER_FORMAT";
    case SVGA3D_DEVCAP_D24X8_BUFFER_FORMAT:
        return "SVGA3D_DEVCAP_D24X8_BUFFER_FORMAT";
    case SVGA3D_DEVCAP_QUERY_TYPES:
        return "SVGA3D_DEVCAP_QUERY_TYPES";
    case SVGA3D_DEVCAP_TEXTURE_GRADIENT_SAMPLING:
        return "SVGA3D_DEVCAP_TEXTURE_GRADIENT_SAMPLING";
    case SVGA3D_DEVCAP_MAX_POINT_SIZE:
        return "SVGA3D_DEVCAP_MAX_POINT_SIZE";
    case SVGA3D_DEVCAP_MAX_SHADER_TEXTURES:
        return "SVGA3D_DEVCAP_MAX_SHADER_TEXTURES";
    case SVGA3D_DEVCAP_MAX_TEXTURE_WIDTH:
        return "SVGA3D_DEVCAP_MAX_TEXTURE_WIDTH";
    case SVGA3D_DEVCAP_MAX_TEXTURE_HEIGHT:
        return "SVGA3D_DEVCAP_MAX_TEXTURE_HEIGHT";
    case SVGA3D_DEVCAP_MAX_VOLUME_EXTENT:
        return "SVGA3D_DEVCAP_MAX_VOLUME_EXTENT";
    case SVGA3D_DEVCAP_MAX_TEXTURE_REPEAT:
        return "SVGA3D_DEVCAP_MAX_TEXTURE_REPEAT";
    case SVGA3D_DEVCAP_MAX_TEXTURE_ASPECT_RATIO:
        return "SVGA3D_DEVCAP_MAX_TEXTURE_ASPECT_RATIO";
    case SVGA3D_DEVCAP_MAX_TEXTURE_ANISOTROPY:
        return "SVGA3D_DEVCAP_MAX_TEXTURE_ANISOTROPY";
    case SVGA3D_DEVCAP_MAX_PRIMITIVE_COUNT:
        return "SVGA3D_DEVCAP_MAX_PRIMITIVE_COUNT";
    case SVGA3D_DEVCAP_MAX_VERTEX_INDEX:
        return "SVGA3D_DEVCAP_MAX_VERTEX_INDEX";
    case SVGA3D_DEVCAP_MAX_VERTEX_SHADER_INSTRUCTIONS:
        return "SVGA3D_DEVCAP_MAX_VERTEX_SHADER_INSTRUCTIONS";
    case SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_INSTRUCTIONS:
        return "SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_INSTRUCTIONS";
    case SVGA3D_DEVCAP_MAX_VERTEX_SHADER_TEMPS:
        return "SVGA3D_DEVCAP_MAX_VERTEX_SHADER_TEMPS";
    case SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_TEMPS:
        return "SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_TEMPS";
    case SVGA3D_DEVCAP_TEXTURE_OPS:
        return "SVGA3D_DEVCAP_TEXTURE_OPS";
    case SVGA3D_DEVCAP_DEAD4: /* SVGA3D_DEVCAP_MULTISAMPLE_NONMASKABLESAMPLES */
        return "SVGA3D_DEVCAP_MULTISAMPLE_NONMASKABLESAMPLES";
    case SVGA3D_DEVCAP_DEAD5: /* SVGA3D_DEVCAP_MULTISAMPLE_MASKABLESAMPLES */
        return "SVGA3D_DEVCAP_MULTISAMPLE_MASKABLESAMPLES";
    case SVGA3D_DEVCAP_DEAD7: /* SVGA3D_DEVCAP_ALPHATOCOVERAGE */
        return "SVGA3D_DEVCAP_ALPHATOCOVERAGE";
    case SVGA3D_DEVCAP_DEAD6: /* SVGA3D_DEVCAP_SUPERSAMPLE */
        return "SVGA3D_DEVCAP_SUPERSAMPLE";
    case SVGA3D_DEVCAP_AUTOGENMIPMAPS:
        return "SVGA3D_DEVCAP_AUTOGENMIPMAPS";
    case SVGA3D_DEVCAP_MAX_VERTEX_SHADER_TEXTURES:
        return "SVGA3D_DEVCAP_MAX_VERTEX_SHADER_TEXTURES";
    case SVGA3D_DEVCAP_MAX_SIMULTANEOUS_RENDER_TARGETS:
        return "SVGA3D_DEVCAP_MAX_SIMULTANEOUS_RENDER_TARGETS";
    case SVGA3D_DEVCAP_MAX_CONTEXT_IDS:
        return "SVGA3D_DEVCAP_MAX_CONTEXT_IDS";
    case SVGA3D_DEVCAP_MAX_SURFACE_IDS:
        return "SVGA3D_DEVCAP_MAX_SURFACE_IDS";
    case SVGA3D_DEVCAP_SURFACEFMT_X8R8G8B8:
        return "SVGA3D_DEVCAP_SURFACEFMT_X8R8G8B8";
    case SVGA3D_DEVCAP_SURFACEFMT_A8R8G8B8:
        return "SVGA3D_DEVCAP_SURFACEFMT_A8R8G8B8";
    case SVGA3D_DEVCAP_SURFACEFMT_A2R10G10B10:
        return "SVGA3D_DEVCAP_SURFACEFMT_A2R10G10B10";
    case SVGA3D_DEVCAP_SURFACEFMT_X1R5G5B5:
        return "SVGA3D_DEVCAP_SURFACEFMT_X1R5G5B5";
    case SVGA3D_DEVCAP_SURFACEFMT_A1R5G5B5:
        return "SVGA3D_DEVCAP_SURFACEFMT_A1R5G5B5";
    case SVGA3D_DEVCAP_SURFACEFMT_A4R4G4B4:
        return "SVGA3D_DEVCAP_SURFACEFMT_A4R4G4B4";
    case SVGA3D_DEVCAP_SURFACEFMT_R5G6B5:
        return "SVGA3D_DEVCAP_SURFACEFMT_R5G6B5";
    case SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE16:
        return "SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE16";
    case SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8_ALPHA8:
        return "SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8_ALPHA8";
    case SVGA3D_DEVCAP_SURFACEFMT_ALPHA8:
        return "SVGA3D_DEVCAP_SURFACEFMT_ALPHA8";
    case SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8:
        return "SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8";
    case SVGA3D_DEVCAP_SURFACEFMT_Z_D16:
        return "SVGA3D_DEVCAP_SURFACEFMT_Z_D16";
    case SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8:
        return "SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8";
    case SVGA3D_DEVCAP_SURFACEFMT_Z_D24X8:
        return "SVGA3D_DEVCAP_SURFACEFMT_Z_D24X8";
    case SVGA3D_DEVCAP_SURFACEFMT_Z_DF16:
        return "SVGA3D_DEVCAP_SURFACEFMT_Z_DF16";
    case SVGA3D_DEVCAP_SURFACEFMT_Z_DF24:
        return "SVGA3D_DEVCAP_SURFACEFMT_Z_DF24";
    case SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8_INT:
        return "SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8_INT";
    case SVGA3D_DEVCAP_SURFACEFMT_DXT1:
        return "SVGA3D_DEVCAP_SURFACEFMT_DXT1";
    case SVGA3D_DEVCAP_SURFACEFMT_DXT2:
        return "SVGA3D_DEVCAP_SURFACEFMT_DXT2";
    case SVGA3D_DEVCAP_SURFACEFMT_DXT3:
        return "SVGA3D_DEVCAP_SURFACEFMT_DXT3";
    case SVGA3D_DEVCAP_SURFACEFMT_DXT4:
        return "SVGA3D_DEVCAP_SURFACEFMT_DXT4";
    case SVGA3D_DEVCAP_SURFACEFMT_DXT5:
        return "SVGA3D_DEVCAP_SURFACEFMT_DXT5";
    case SVGA3D_DEVCAP_SURFACEFMT_BUMPX8L8V8U8:
        return "SVGA3D_DEVCAP_SURFACEFMT_BUMPX8L8V8U8";
    case SVGA3D_DEVCAP_SURFACEFMT_A2W10V10U10:
        return "SVGA3D_DEVCAP_SURFACEFMT_A2W10V10U10";
    case SVGA3D_DEVCAP_SURFACEFMT_BUMPU8V8:
        return "SVGA3D_DEVCAP_SURFACEFMT_BUMPU8V8";
    case SVGA3D_DEVCAP_SURFACEFMT_Q8W8V8U8:
        return "SVGA3D_DEVCAP_SURFACEFMT_Q8W8V8U8";
    case SVGA3D_DEVCAP_SURFACEFMT_CxV8U8:
        return "SVGA3D_DEVCAP_SURFACEFMT_CxV8U8";
    case SVGA3D_DEVCAP_SURFACEFMT_R_S10E5:
        return "SVGA3D_DEVCAP_SURFACEFMT_R_S10E5";
    case SVGA3D_DEVCAP_SURFACEFMT_R_S23E8:
        return "SVGA3D_DEVCAP_SURFACEFMT_R_S23E8";
    case SVGA3D_DEVCAP_SURFACEFMT_RG_S10E5:
        return "SVGA3D_DEVCAP_SURFACEFMT_RG_S10E5";
    case SVGA3D_DEVCAP_SURFACEFMT_RG_S23E8:
        return "SVGA3D_DEVCAP_SURFACEFMT_RG_S23E8";
    case SVGA3D_DEVCAP_SURFACEFMT_ARGB_S10E5:
        return "SVGA3D_DEVCAP_SURFACEFMT_ARGB_S10E5";
    case SVGA3D_DEVCAP_SURFACEFMT_ARGB_S23E8:
        return "SVGA3D_DEVCAP_SURFACEFMT_ARGB_S23E8";
    case SVGA3D_DEVCAP_SURFACEFMT_V16U16:
        return "SVGA3D_DEVCAP_SURFACEFMT_V16U16";
    case SVGA3D_DEVCAP_SURFACEFMT_G16R16:
        return "SVGA3D_DEVCAP_SURFACEFMT_G16R16";
    case SVGA3D_DEVCAP_SURFACEFMT_A16B16G16R16:
        return "SVGA3D_DEVCAP_SURFACEFMT_A16B16G16R16";
    case SVGA3D_DEVCAP_SURFACEFMT_UYVY:
        return "SVGA3D_DEVCAP_SURFACEFMT_UYVY";
    case SVGA3D_DEVCAP_SURFACEFMT_YUY2:
        return "SVGA3D_DEVCAP_SURFACEFMT_YUY2";
    case SVGA3D_DEVCAP_SURFACEFMT_NV12:
        return "SVGA3D_DEVCAP_SURFACEFMT_NV12";
    case SVGA3D_DEVCAP_DEAD10: /* SVGA3D_DEVCAP_SURFACEFMT_AYUV */
        return "SVGA3D_DEVCAP_SURFACEFMT_AYUV";
    case SVGA3D_DEVCAP_SURFACEFMT_ATI1:
        return "SVGA3D_DEVCAP_SURFACEFMT_ATI1";
    case SVGA3D_DEVCAP_SURFACEFMT_ATI2:
        return "SVGA3D_DEVCAP_SURFACEFMT_ATI2";
    default:
        return "UNEXPECTED";
    }
}

const char *vmsvga3dGet3dFormatString(uint32_t format)
{
    static char szFormat[1024];

    szFormat[0] = 0;

    if (format & SVGA3DFORMAT_OP_TEXTURE)
        strcat(szFormat, "   - SVGA3DFORMAT_OP_TEXTURE\n");
    if (format & SVGA3DFORMAT_OP_VOLUMETEXTURE)
        strcat(szFormat, "   - SVGA3DFORMAT_OP_VOLUMETEXTURE\n");
    if (format & SVGA3DFORMAT_OP_CUBETEXTURE)
        strcat(szFormat, "   - SVGA3DFORMAT_OP_CUBETEXTURE\n");
    if (format & SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET)
        strcat(szFormat, "   - SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET\n");
    if (format & SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET)
        strcat(szFormat, "   - SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET\n");
    if (format & SVGA3DFORMAT_OP_ZSTENCIL)
        strcat(szFormat, "   - SVGA3DFORMAT_OP_ZSTENCIL\n");
    if (format & SVGA3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH)
        strcat(szFormat, "   - SVGA3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH\n");
    if (format & SVGA3DFORMAT_OP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET)
        strcat(szFormat, "   - SVGA3DFORMAT_OP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET\n");
    if (format & SVGA3DFORMAT_OP_DISPLAYMODE)
        strcat(szFormat, "   - SVGA3DFORMAT_OP_DISPLAYMODE\n");
    if (format & SVGA3DFORMAT_OP_3DACCELERATION)
        strcat(szFormat, "   - SVGA3DFORMAT_OP_3DACCELERATION\n");
    if (format & SVGA3DFORMAT_OP_PIXELSIZE)
        strcat(szFormat, "   - SVGA3DFORMAT_OP_PIXELSIZE\n");
    if (format & SVGA3DFORMAT_OP_CONVERT_TO_ARGB)
        strcat(szFormat, "   - SVGA3DFORMAT_OP_CONVERT_TO_ARGB\n");
    if (format & SVGA3DFORMAT_OP_OFFSCREENPLAIN)
        strcat(szFormat, "   - SVGA3DFORMAT_OP_OFFSCREENPLAIN\n");
    if (format & SVGA3DFORMAT_OP_SRGBREAD)
        strcat(szFormat, "   - SVGA3DFORMAT_OP_SRGBREAD\n");
    if (format & SVGA3DFORMAT_OP_BUMPMAP)
        strcat(szFormat, "   - SVGA3DFORMAT_OP_BUMPMAP\n");
    if (format & SVGA3DFORMAT_OP_DMAP)
        strcat(szFormat, "   - SVGA3DFORMAT_OP_DMAP\n");
    if (format & SVGA3DFORMAT_OP_NOFILTER)
        strcat(szFormat, "   - SVGA3DFORMAT_OP_NOFILTER\n");
    if (format & SVGA3DFORMAT_OP_MEMBEROFGROUP_ARGB)
        strcat(szFormat, "   - SVGA3DFORMAT_OP_MEMBEROFGROUP_ARGB\n");
    if (format & SVGA3DFORMAT_OP_SRGBWRITE)
        strcat(szFormat, "   - SVGA3DFORMAT_OP_SRGBWRITE\n");
    if (format & SVGA3DFORMAT_OP_NOALPHABLEND)
        strcat(szFormat, "   - SVGA3DFORMAT_OP_NOALPHABLEND\n");
    if (format & SVGA3DFORMAT_OP_AUTOGENMIPMAP)
        strcat(szFormat, "   - SVGA3DFORMAT_OP_AUTOGENMIPMAP\n");
    if (format & SVGA3DFORMAT_OP_VERTEXTEXTURE)
        strcat(szFormat, "   - SVGA3DFORMAT_OP_VERTEXTEXTURE\n");
    if (format & SVGA3DFORMAT_OP_NOTEXCOORDWRAPNORMIP)
        strcat(szFormat, "   - SVGA3DFORMAT_OP_NOTEXCOORDWRAPNORMIP\n");
   return szFormat;
}

const char *vmsvga3dGetRenderStateName(uint32_t state)
{
    switch (state)
    {
    case SVGA3D_RS_ZENABLE:                /* SVGA3dBool */
        return "SVGA3D_RS_ZENABLE";
    case SVGA3D_RS_ZWRITEENABLE:           /* SVGA3dBool */
        return "SVGA3D_RS_ZWRITEENABLE";
    case SVGA3D_RS_ALPHATESTENABLE:        /* SVGA3dBool */
        return "SVGA3D_RS_ALPHATESTENABLE";
    case SVGA3D_RS_DITHERENABLE:           /* SVGA3dBool */
        return "SVGA3D_RS_DITHERENABLE";
    case SVGA3D_RS_BLENDENABLE:            /* SVGA3dBool */
        return "SVGA3D_RS_BLENDENABLE";
    case SVGA3D_RS_FOGENABLE:              /* SVGA3dBool */
        return "SVGA3D_RS_FOGENABLE";
    case SVGA3D_RS_SPECULARENABLE:         /* SVGA3dBool */
        return "SVGA3D_RS_SPECULARENABLE";
    case SVGA3D_RS_STENCILENABLE:          /* SVGA3dBool */
        return "SVGA3D_RS_STENCILENABLE";
    case SVGA3D_RS_LIGHTINGENABLE:         /* SVGA3dBool */
        return "SVGA3D_RS_LIGHTINGENABLE";
    case SVGA3D_RS_NORMALIZENORMALS:       /* SVGA3dBool */
        return "SVGA3D_RS_NORMALIZENORMALS";
    case SVGA3D_RS_POINTSPRITEENABLE:      /* SVGA3dBool */
        return "SVGA3D_RS_POINTSPRITEENABLE";
    case SVGA3D_RS_POINTSCALEENABLE:       /* SVGA3dBool */
        return "SVGA3D_RS_POINTSCALEENABLE";
    case SVGA3D_RS_STENCILREF:             /* uint32_t */
        return "SVGA3D_RS_STENCILREF";
    case SVGA3D_RS_STENCILMASK:            /* uint32_t */
        return "SVGA3D_RS_STENCILMASK";
    case SVGA3D_RS_STENCILWRITEMASK:       /* uint32_t */
        return "SVGA3D_RS_STENCILWRITEMASK";
    case SVGA3D_RS_POINTSIZE:              /* float */
        return "SVGA3D_RS_POINTSIZE";
    case SVGA3D_RS_POINTSIZEMIN:           /* float */
        return "SVGA3D_RS_POINTSIZEMIN";
    case SVGA3D_RS_POINTSIZEMAX:           /* float */
        return "SVGA3D_RS_POINTSIZEMAX";
    case SVGA3D_RS_POINTSCALE_A:           /* float */
        return "SVGA3D_RS_POINTSCALE_A";
    case SVGA3D_RS_POINTSCALE_B:           /* float */
        return "SVGA3D_RS_POINTSCALE_B";
    case SVGA3D_RS_POINTSCALE_C:           /* float */
        return "SVGA3D_RS_POINTSCALE_C";
    case SVGA3D_RS_AMBIENT:                /* SVGA3dColor - identical */
        return "SVGA3D_RS_AMBIENT";
    case SVGA3D_RS_CLIPPLANEENABLE:        /* SVGA3dClipPlanes - identical */
        return "SVGA3D_RS_CLIPPLANEENABLE";
    case SVGA3D_RS_FOGCOLOR:               /* SVGA3dColor - identical */
        return "SVGA3D_RS_FOGCOLOR";
    case SVGA3D_RS_FOGSTART:               /* float */
        return "SVGA3D_RS_FOGSTART";
    case SVGA3D_RS_FOGEND:                 /* float */
        return "SVGA3D_RS_FOGEND";
    case SVGA3D_RS_FOGDENSITY:             /* float */
        return "SVGA3D_RS_FOGDENSITY";
    case SVGA3D_RS_RANGEFOGENABLE:         /* SVGA3dBool */
        return "SVGA3D_RS_RANGEFOGENABLE";
    case SVGA3D_RS_FOGMODE:                /* SVGA3dFogMode */
        return "SVGA3D_RS_FOGMODE";
    case SVGA3D_RS_FILLMODE:               /* SVGA3dFillMode */
        return "SVGA3D_RS_FILLMODE";
    case SVGA3D_RS_SHADEMODE:              /* SVGA3dShadeMode */
        return "SVGA3D_RS_SHADEMODE";
    case SVGA3D_RS_LINEPATTERN:            /* SVGA3dLinePattern */
        return "SVGA3D_RS_LINEPATTERN";
    case SVGA3D_RS_SRCBLEND:               /* SVGA3dBlendOp */
        return "SVGA3D_RS_SRCBLEND";
    case SVGA3D_RS_DSTBLEND:               /* SVGA3dBlendOp */
        return "SVGA3D_RS_DSTBLEND";
    case SVGA3D_RS_BLENDEQUATION:          /* SVGA3dBlendEquation */
        return "SVGA3D_RS_BLENDEQUATION";
    case SVGA3D_RS_CULLMODE:               /* SVGA3dFace */
        return "SVGA3D_RS_CULLMODE";
    case SVGA3D_RS_ZFUNC:                  /* SVGA3dCmpFunc */
        return "SVGA3D_RS_ZFUNC";
    case SVGA3D_RS_ALPHAFUNC:              /* SVGA3dCmpFunc */
        return "SVGA3D_RS_ALPHAFUNC";
    case SVGA3D_RS_STENCILFUNC:            /* SVGA3dCmpFunc */
        return "SVGA3D_RS_STENCILFUNC";
    case SVGA3D_RS_STENCILFAIL:            /* SVGA3dStencilOp */
        return "SVGA3D_RS_STENCILFAIL";
    case SVGA3D_RS_STENCILZFAIL:           /* SVGA3dStencilOp */
        return "SVGA3D_RS_STENCILZFAIL";
    case SVGA3D_RS_STENCILPASS:            /* SVGA3dStencilOp */
        return "SVGA3D_RS_STENCILPASS";
    case SVGA3D_RS_ALPHAREF:               /* float (0.0 .. 1.0) */
        return "SVGA3D_RS_ALPHAREF";
    case SVGA3D_RS_FRONTWINDING:           /* SVGA3dFrontWinding */
        return "SVGA3D_RS_FRONTWINDING";
    case SVGA3D_RS_COORDINATETYPE:         /* SVGA3dCoordinateType */
        return "SVGA3D_RS_COORDINATETYPE";
    case SVGA3D_RS_ZBIAS:                  /* float */
        return "SVGA3D_RS_ZBIAS";
    case SVGA3D_RS_COLORWRITEENABLE:       /* SVGA3dColorMask */
        return "SVGA3D_RS_COLORWRITEENABLE";
    case SVGA3D_RS_VERTEXMATERIALENABLE:   /* SVGA3dBool */
        return "SVGA3D_RS_VERTEXMATERIALENABLE";
    case SVGA3D_RS_DIFFUSEMATERIALSOURCE:  /* SVGA3dVertexMaterial */
        return "SVGA3D_RS_DIFFUSEMATERIALSOURCE";
    case SVGA3D_RS_SPECULARMATERIALSOURCE: /* SVGA3dVertexMaterial */
        return "SVGA3D_RS_SPECULARMATERIALSOURCE";
    case SVGA3D_RS_AMBIENTMATERIALSOURCE:  /* SVGA3dVertexMaterial */
        return "SVGA3D_RS_AMBIENTMATERIALSOURCE";
    case SVGA3D_RS_EMISSIVEMATERIALSOURCE: /* SVGA3dVertexMaterial */
        return "SVGA3D_RS_EMISSIVEMATERIALSOURCE";
    case SVGA3D_RS_TEXTUREFACTOR:          /* SVGA3dColor */
        return "SVGA3D_RS_TEXTUREFACTOR";
    case SVGA3D_RS_LOCALVIEWER:            /* SVGA3dBool */
        return "SVGA3D_RS_LOCALVIEWER";
    case SVGA3D_RS_SCISSORTESTENABLE:      /* SVGA3dBool */
        return "SVGA3D_RS_SCISSORTESTENABLE";
    case SVGA3D_RS_BLENDCOLOR:             /* SVGA3dColor */
        return "SVGA3D_RS_BLENDCOLOR";
    case SVGA3D_RS_STENCILENABLE2SIDED:    /* SVGA3dBool */
        return "SVGA3D_RS_STENCILENABLE2SIDED";
    case SVGA3D_RS_CCWSTENCILFUNC:         /* SVGA3dCmpFunc */
        return "SVGA3D_RS_CCWSTENCILFUNC";
    case SVGA3D_RS_CCWSTENCILFAIL:         /* SVGA3dStencilOp */
        return "SVGA3D_RS_CCWSTENCILFAIL";
    case SVGA3D_RS_CCWSTENCILZFAIL:        /* SVGA3dStencilOp */
        return "SVGA3D_RS_CCWSTENCILZFAIL";
    case SVGA3D_RS_CCWSTENCILPASS:         /* SVGA3dStencilOp */
        return "SVGA3D_RS_CCWSTENCILPASS";
    case SVGA3D_RS_VERTEXBLEND:            /* SVGA3dVertexBlendFlags */
        return "SVGA3D_RS_VERTEXBLEND";
    case SVGA3D_RS_SLOPESCALEDEPTHBIAS:    /* float */
        return "SVGA3D_RS_SLOPESCALEDEPTHBIAS";
    case SVGA3D_RS_DEPTHBIAS:              /* float */
        return "SVGA3D_RS_DEPTHBIAS";
    case SVGA3D_RS_OUTPUTGAMMA:            /* float */
        return "SVGA3D_RS_OUTPUTGAMMA";
    case SVGA3D_RS_ZVISIBLE:               /* SVGA3dBool */
        return "SVGA3D_RS_ZVISIBLE";
    case SVGA3D_RS_LASTPIXEL:              /* SVGA3dBool */
        return "SVGA3D_RS_LASTPIXEL";
    case SVGA3D_RS_CLIPPING:               /* SVGA3dBool */
        return "SVGA3D_RS_CLIPPING";
    case SVGA3D_RS_WRAP0:                  /* SVGA3dWrapFlags */
        return "SVGA3D_RS_WRAP0";
    case SVGA3D_RS_WRAP1:                  /* SVGA3dWrapFlags */
        return "SVGA3D_RS_WRAP1";
    case SVGA3D_RS_WRAP2:                  /* SVGA3dWrapFlags */
        return "SVGA3D_RS_WRAP2";
    case SVGA3D_RS_WRAP3:                  /* SVGA3dWrapFlags */
        return "SVGA3D_RS_WRAP3";
    case SVGA3D_RS_WRAP4:                  /* SVGA3dWrapFlags */
        return "SVGA3D_RS_WRAP4";
    case SVGA3D_RS_WRAP5:                  /* SVGA3dWrapFlags */
        return "SVGA3D_RS_WRAP5";
    case SVGA3D_RS_WRAP6:                  /* SVGA3dWrapFlags */
        return "SVGA3D_RS_WRAP6";
    case SVGA3D_RS_WRAP7:                  /* SVGA3dWrapFlags */
        return "SVGA3D_RS_WRAP7";
    case SVGA3D_RS_WRAP8:                  /* SVGA3dWrapFlags */
        return "SVGA3D_RS_WRAP8";
    case SVGA3D_RS_WRAP9:                  /* SVGA3dWrapFlags */
        return "SVGA3D_RS_WRAP9";
    case SVGA3D_RS_WRAP10:                 /* SVGA3dWrapFlags */
        return "SVGA3D_RS_WRAP10";
    case SVGA3D_RS_WRAP11:                 /* SVGA3dWrapFlags */
        return "SVGA3D_RS_WRAP11";
    case SVGA3D_RS_WRAP12:                 /* SVGA3dWrapFlags */
        return "SVGA3D_RS_WRAP12";
    case SVGA3D_RS_WRAP13:                 /* SVGA3dWrapFlags */
        return "SVGA3D_RS_WRAP13";
    case SVGA3D_RS_WRAP14:                 /* SVGA3dWrapFlags */
        return "SVGA3D_RS_WRAP14";
    case SVGA3D_RS_WRAP15:                 /* SVGA3dWrapFlags */
        return "SVGA3D_RS_WRAP15";
    case SVGA3D_RS_MULTISAMPLEANTIALIAS:   /* SVGA3dBool */
        return "SVGA3D_RS_MULTISAMPLEANTIALIAS";
    case SVGA3D_RS_MULTISAMPLEMASK:        /* uint32_t */
        return "SVGA3D_RS_MULTISAMPLEMASK";
    case SVGA3D_RS_INDEXEDVERTEXBLENDENABLE: /* SVGA3dBool */
        return "SVGA3D_RS_INDEXEDVERTEXBLENDENABLE";
    case SVGA3D_RS_TWEENFACTOR:            /* float */
        return "SVGA3D_RS_TWEENFACTOR";
    case SVGA3D_RS_ANTIALIASEDLINEENABLE:  /* SVGA3dBool */
        return "SVGA3D_RS_ANTIALIASEDLINEENABLE";
    case SVGA3D_RS_COLORWRITEENABLE1:      /* SVGA3dColorMask */
        return "SVGA3D_RS_COLORWRITEENABLE1";
    case SVGA3D_RS_COLORWRITEENABLE2:      /* SVGA3dColorMask */
        return "SVGA3D_RS_COLORWRITEENABLE2";
    case SVGA3D_RS_COLORWRITEENABLE3:      /* SVGA3dColorMask */
        return "SVGA3D_RS_COLORWRITEENABLE3";
    case SVGA3D_RS_SEPARATEALPHABLENDENABLE: /* SVGA3dBool */
        return "SVGA3D_RS_SEPARATEALPHABLENDENABLE";
    case SVGA3D_RS_SRCBLENDALPHA:          /* SVGA3dBlendOp */
        return "SVGA3D_RS_SRCBLENDALPHA";
    case SVGA3D_RS_DSTBLENDALPHA:          /* SVGA3dBlendOp */
        return "SVGA3D_RS_DSTBLENDALPHA";
    case SVGA3D_RS_BLENDEQUATIONALPHA:     /* SVGA3dBlendEquation */
        return "SVGA3D_RS_BLENDEQUATIONALPHA";
    case SVGA3D_RS_TRANSPARENCYANTIALIAS:  /* SVGA3dTransparencyAntialiasType */
        return "SVGA3D_RS_TRANSPARENCYANTIALIAS";
    case SVGA3D_RS_LINEWIDTH:              /* float */
        return "SVGA3D_RS_LINEWIDTH";
    default:
        return "UNKNOWN";
    }
}

const char *vmsvga3dTextureStateToString(SVGA3dTextureStateName textureState)
{
    switch (textureState)
    {
    case SVGA3D_TS_BIND_TEXTURE:
        return "SVGA3D_TS_BIND_TEXTURE";
    case SVGA3D_TS_COLOROP:
        return "SVGA3D_TS_COLOROP";
    case SVGA3D_TS_COLORARG1:
        return "SVGA3D_TS_COLORARG1";
    case SVGA3D_TS_COLORARG2:
        return "SVGA3D_TS_COLORARG2";
    case SVGA3D_TS_ALPHAOP:
        return "SVGA3D_TS_ALPHAOP";
    case SVGA3D_TS_ALPHAARG1:
        return "SVGA3D_TS_ALPHAARG1";
    case SVGA3D_TS_ALPHAARG2:
        return "SVGA3D_TS_ALPHAARG2";
    case SVGA3D_TS_ADDRESSU:
        return "SVGA3D_TS_ADDRESSU";
    case SVGA3D_TS_ADDRESSV:
        return "SVGA3D_TS_ADDRESSV";
    case SVGA3D_TS_MIPFILTER:
        return "SVGA3D_TS_MIPFILTER";
    case SVGA3D_TS_MAGFILTER:
        return "SVGA3D_TS_MAGFILTER";
    case SVGA3D_TS_MINFILTER:
        return "SVGA3D_TS_MINFILTER";
    case SVGA3D_TS_BORDERCOLOR:
        return "SVGA3D_TS_BORDERCOLOR";
    case SVGA3D_TS_TEXCOORDINDEX:
        return "SVGA3D_TS_TEXCOORDINDEX";
    case SVGA3D_TS_TEXTURETRANSFORMFLAGS:
        return "SVGA3D_TS_TEXTURETRANSFORMFLAGS";
    case SVGA3D_TS_TEXCOORDGEN:
        return "SVGA3D_TS_TEXCOORDGEN";
    case SVGA3D_TS_BUMPENVMAT00:
        return "SVGA3D_TS_BUMPENVMAT00";
    case SVGA3D_TS_BUMPENVMAT01:
        return "SVGA3D_TS_BUMPENVMAT01";
    case SVGA3D_TS_BUMPENVMAT10:
        return "SVGA3D_TS_BUMPENVMAT10";
    case SVGA3D_TS_BUMPENVMAT11:
        return "SVGA3D_TS_BUMPENVMAT11";
    case SVGA3D_TS_TEXTURE_MIPMAP_LEVEL:
        return "SVGA3D_TS_TEXTURE_MIPMAP_LEVEL";
    case SVGA3D_TS_TEXTURE_LOD_BIAS:
        return "SVGA3D_TS_TEXTURE_LOD_BIAS";
    case SVGA3D_TS_TEXTURE_ANISOTROPIC_LEVEL:
        return "SVGA3D_TS_TEXTURE_ANISOTROPIC_LEVEL";
    case SVGA3D_TS_ADDRESSW:
        return "SVGA3D_TS_ADDRESSW";
    case SVGA3D_TS_GAMMA:
        return "SVGA3D_TS_GAMMA";
    case SVGA3D_TS_BUMPENVLSCALE:
        return "SVGA3D_TS_BUMPENVLSCALE";
    case SVGA3D_TS_BUMPENVLOFFSET:
        return "SVGA3D_TS_BUMPENVLOFFSET";
    case SVGA3D_TS_COLORARG0:
        return "SVGA3D_TS_COLORARG0";
    case SVGA3D_TS_ALPHAARG0:
        return "SVGA3D_TS_ALPHAARG0";
    default:
        return "UNKNOWN";
    }
}

const char *vmsvgaTransformToString(SVGA3dTransformType type)
{
    switch (type)
    {
    case SVGA3D_TRANSFORM_INVALID:
        return "SVGA3D_TRANSFORM_INVALID";
    case SVGA3D_TRANSFORM_WORLD:
        return "SVGA3D_TRANSFORM_WORLD";
    case SVGA3D_TRANSFORM_VIEW:
        return "SVGA3D_TRANSFORM_VIEW";
    case SVGA3D_TRANSFORM_PROJECTION:
        return "SVGA3D_TRANSFORM_PROJECTION";
    case SVGA3D_TRANSFORM_TEXTURE0:
        return "SVGA3D_TRANSFORM_TEXTURE0";
    case SVGA3D_TRANSFORM_TEXTURE1:
        return "SVGA3D_TRANSFORM_TEXTURE1";
    case SVGA3D_TRANSFORM_TEXTURE2:
        return "SVGA3D_TRANSFORM_TEXTURE2";
    case SVGA3D_TRANSFORM_TEXTURE3:
        return "SVGA3D_TRANSFORM_TEXTURE3";
    case SVGA3D_TRANSFORM_TEXTURE4:
        return "SVGA3D_TRANSFORM_TEXTURE4";
    case SVGA3D_TRANSFORM_TEXTURE5:
        return "SVGA3D_TRANSFORM_TEXTURE5";
    case SVGA3D_TRANSFORM_TEXTURE6:
        return "SVGA3D_TRANSFORM_TEXTURE6";
    case SVGA3D_TRANSFORM_TEXTURE7:
        return "SVGA3D_TRANSFORM_TEXTURE7";
    case SVGA3D_TRANSFORM_WORLD1:
        return "SVGA3D_TRANSFORM_WORLD1";
    case SVGA3D_TRANSFORM_WORLD2:
        return "SVGA3D_TRANSFORM_WORLD2";
    case SVGA3D_TRANSFORM_WORLD3:
        return "SVGA3D_TRANSFORM_WORLD3";
    default:
        return "UNKNOWN";
    }
}

const char *vmsvgaDeclUsage2String(SVGA3dDeclUsage usage)
{
    switch (usage)
    {
    case SVGA3D_DECLUSAGE_POSITION:
        return "SVGA3D_DECLUSAGE_POSITION";
    case SVGA3D_DECLUSAGE_BLENDWEIGHT:
        return "SVGA3D_DECLUSAGE_BLENDWEIGHT";
    case SVGA3D_DECLUSAGE_BLENDINDICES:
        return "SVGA3D_DECLUSAGE_BLENDINDICES";
    case SVGA3D_DECLUSAGE_NORMAL:
        return "SVGA3D_DECLUSAGE_NORMAL";
    case SVGA3D_DECLUSAGE_PSIZE:
        return "SVGA3D_DECLUSAGE_PSIZE";
    case SVGA3D_DECLUSAGE_TEXCOORD:
        return "SVGA3D_DECLUSAGE_TEXCOORD";
    case SVGA3D_DECLUSAGE_TANGENT:
        return "SVGA3D_DECLUSAGE_TANGENT";
    case SVGA3D_DECLUSAGE_BINORMAL:
        return "SVGA3D_DECLUSAGE_BINORMAL";
    case SVGA3D_DECLUSAGE_TESSFACTOR:
        return "SVGA3D_DECLUSAGE_TESSFACTOR";
    case SVGA3D_DECLUSAGE_POSITIONT:
        return "SVGA3D_DECLUSAGE_POSITIONT";
    case SVGA3D_DECLUSAGE_COLOR:
        return "SVGA3D_DECLUSAGE_COLOR";
    case SVGA3D_DECLUSAGE_FOG:
        return "SVGA3D_DECLUSAGE_FOG";
    case SVGA3D_DECLUSAGE_DEPTH:
        return "SVGA3D_DECLUSAGE_DEPTH";
    case SVGA3D_DECLUSAGE_SAMPLE:
        return "SVGA3D_DECLUSAGE_SAMPLE";
    default:
        return "UNKNOWN!!";
    }
}

const char *vmsvgaDeclMethod2String(SVGA3dDeclMethod method)
{
    switch (method)
    {
    case SVGA3D_DECLMETHOD_DEFAULT:
        return "SVGA3D_DECLMETHOD_DEFAULT";
    case SVGA3D_DECLMETHOD_PARTIALU:
        return "SVGA3D_DECLMETHOD_PARTIALU";
    case SVGA3D_DECLMETHOD_PARTIALV:
        return "SVGA3D_DECLMETHOD_PARTIALV";
    case SVGA3D_DECLMETHOD_CROSSUV:
        return "SVGA3D_DECLMETHOD_CROSSUV";
    case SVGA3D_DECLMETHOD_UV:
        return "SVGA3D_DECLMETHOD_UV";
    case SVGA3D_DECLMETHOD_LOOKUP:
        return "SVGA3D_DECLMETHOD_LOOKUP";
    case SVGA3D_DECLMETHOD_LOOKUPPRESAMPLED:
        return "SVGA3D_DECLMETHOD_LOOKUPPRESAMPLED";
    default:
        return "UNKNOWN!!";
    }
}

const char *vmsvgaDeclType2String(SVGA3dDeclType type)
{
    switch (type)
    {
    case SVGA3D_DECLTYPE_FLOAT1:
        return "SVGA3D_DECLTYPE_FLOAT1";
    case SVGA3D_DECLTYPE_FLOAT2:
        return "SVGA3D_DECLTYPE_FLOAT2";
    case SVGA3D_DECLTYPE_FLOAT3:
        return "SVGA3D_DECLTYPE_FLOAT3";
    case SVGA3D_DECLTYPE_FLOAT4:
        return "SVGA3D_DECLTYPE_FLOAT4";
    case SVGA3D_DECLTYPE_D3DCOLOR:
        return "SVGA3D_DECLTYPE_D3DCOLOR";
    case SVGA3D_DECLTYPE_UBYTE4:
        return "SVGA3D_DECLTYPE_UBYTE4";
    case SVGA3D_DECLTYPE_SHORT2:
        return "SVGA3D_DECLTYPE_SHORT2";
    case SVGA3D_DECLTYPE_SHORT4:
        return "SVGA3D_DECLTYPE_SHORT4";
    case SVGA3D_DECLTYPE_UBYTE4N:
        return "SVGA3D_DECLTYPE_UBYTE4N";
    case SVGA3D_DECLTYPE_SHORT2N:
        return "SVGA3D_DECLTYPE_SHORT2N";
    case SVGA3D_DECLTYPE_SHORT4N:
        return "SVGA3D_DECLTYPE_SHORT4N";
    case SVGA3D_DECLTYPE_USHORT2N:
        return "SVGA3D_DECLTYPE_USHORT2N";
    case SVGA3D_DECLTYPE_USHORT4N:
        return "SVGA3D_DECLTYPE_USHORT4N";
    case SVGA3D_DECLTYPE_UDEC3:
        return "SVGA3D_DECLTYPE_UDEC3";
    case SVGA3D_DECLTYPE_DEC3N:
        return "SVGA3D_DECLTYPE_DEC3N";
    case SVGA3D_DECLTYPE_FLOAT16_2:
        return "SVGA3D_DECLTYPE_FLOAT16_2";
    case SVGA3D_DECLTYPE_FLOAT16_4:
        return "SVGA3D_DECLTYPE_FLOAT16_4";
    default:
        return "UNKNOWN!!";
    }
}

const char *vmsvga3dPrimitiveType2String(SVGA3dPrimitiveType PrimitiveType)
{
    switch (PrimitiveType)
    {
    case SVGA3D_PRIMITIVE_TRIANGLELIST:
        return "SVGA3D_PRIMITIVE_TRIANGLELIST";
    case SVGA3D_PRIMITIVE_POINTLIST:
        return "SVGA3D_PRIMITIVE_POINTLIST";
    case SVGA3D_PRIMITIVE_LINELIST:
        return "SVGA3D_PRIMITIVE_LINELIST";
    case SVGA3D_PRIMITIVE_LINESTRIP:
        return "SVGA3D_PRIMITIVE_LINESTRIP";
    case SVGA3D_PRIMITIVE_TRIANGLESTRIP:
        return "SVGA3D_PRIMITIVE_TRIANGLESTRIP";
    case SVGA3D_PRIMITIVE_TRIANGLEFAN:
        return "SVGA3D_PRIMITIVE_TRIANGLEFAN";
    default:
        return "UNKNOWN";
    }
}

#endif /* LOG_ENABLED */