VirtualBox

Changeset 94223 in vbox


Ignore:
Timestamp:
Mar 14, 2022 1:09:42 PM (3 years ago)
Author:
vboxsync
Message:

Devices/Graphics: extended debug code to support float textures: bugref:9830

Location:
trunk/src/VBox/Devices/Graphics
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA-cmd.cpp

    r94205 r94223  
    14151415
    14161416
     1417typedef union
     1418{
     1419    float f;
     1420    uint32_t u;
     1421} Unsigned2Float;
     1422
     1423float float16ToFloat(uint16_t f16)
     1424{
     1425    /* Format specs from Wiki: [15] = sign, [14:10] = exponent, [9:0] = fraction */
     1426    uint16_t const f = f16 & 0x3FF;
     1427    uint16_t const e = (f16 >> 10) & 0x1F;
     1428    uint16_t const s = (f16 >> 15) & 0x1;
     1429    Unsigned2Float u2f;
     1430
     1431    if (e == 0)
     1432    {
     1433        if (f == 0)
     1434        {
     1435            /* zero, -0 */
     1436            u2f.u = (s << 31) | (0 << 23) | 0;
     1437            return u2f.f;
     1438        }
     1439
     1440        /* subnormal numbers: (-1)^signbit * 2^-14 * 0.significantbits */
     1441        float const k = 1.0f / 16384.0f; /* 2^-14 */
     1442        return (s ? -1.0f : 1.0f) * k * (float)f / 1024.0f;
     1443    }
     1444
     1445    if (e == 31)
     1446    {
     1447        if (f == 0)
     1448        {
     1449            /* +-infinity */
     1450            u2f.u = (s << 31) | (0xFF << 23) | 0;
     1451            return u2f.f;
     1452        }
     1453
     1454        /* NaN */
     1455        u2f.u = (s << 31) | (0xFF << 23) | 1;
     1456        return u2f.f;
     1457    }
     1458
     1459    /* normalized value: (-1)^signbit * 2^(exponent - 15) * 1.significantbits */
     1460    /* Build the float, adjusting for exponent bias (float32 bias is 127, float16 is 15)
     1461     * and number of bits in the fraction (float32 has 23, float16 has 10). */
     1462    u2f.u = (s << 31) | ((e + 127 - 15) << 23) | (f << (23 - 10));
     1463    return u2f.f;
     1464}
     1465
     1466
    14171467static int vmsvga3dBmpWrite(const char *pszFilename, VMSVGA3D_MAPPED_SURFACE const *pMap)
    14181468{
    1419     if (pMap->cbPixel != 4)
     1469    if (pMap->cbPixel != 4 && pMap->format != SVGA3D_R16G16B16A16_FLOAT)
    14201470        return VERR_NOT_SUPPORTED;
    14211471
     
    14551505        {
    14561506            fwrite(s, 1, w * pMap->cbPixel, f);
     1507
     1508            s += pMap->cbRowPitch;
     1509        }
     1510    }
     1511    else if (pMap->format == SVGA3D_R16G16B16A16_FLOAT)
     1512    {
     1513        const uint8_t *s = (uint8_t *)pMap->pvData;
     1514        for (int32_t y = 0; y < h; ++y)
     1515        {
     1516            for (int32_t x = 0; x < w; ++x)
     1517            {
     1518                uint16_t const *pu16Pixel = (uint16_t *)(s + x * 8);
     1519                uint8_t r = (uint8_t)(255.0 * float16ToFloat(pu16Pixel[0]));
     1520                uint8_t g = (uint8_t)(255.0 * float16ToFloat(pu16Pixel[1]));
     1521                uint8_t b = (uint8_t)(255.0 * float16ToFloat(pu16Pixel[2]));
     1522                uint8_t a = (uint8_t)(255.0 * float16ToFloat(pu16Pixel[3]));
     1523                uint32_t u32Pixel = b + (g << 8) + (r << 16) + (a << 24);
     1524                fwrite(&u32Pixel, 1, 4, f);
     1525            }
    14571526
    14581527            s += pMap->cbRowPitch;
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win-dx.cpp

    r94215 r94223  
    32403240        {
    32413241            pMap->enmMapType   = enmMapType;
     3242            pMap->format       = pSurface->format;
    32423243            pMap->box          = clipBox;
    32433244            pMap->cbPixel      = pSurface->cbBlock;
     
    33133314        {
    33143315            pMap->enmMapType   = enmMapType;
     3316            pMap->format       = pSurface->format;
    33153317            pMap->box          = clipBox;
    33163318            pMap->cbPixel      = pSurface->cbBlock;
     
    33623364            {
    33633365                pMap->enmMapType   = enmMapType;
     3366                pMap->format       = pSurface->format;
    33643367                pMap->box          = clipBox;
    33653368                pMap->cbPixel      = pSurface->cbBlock;
     
    53895392
    53905393                LogFunc(("srv[%d][%d] sid = %u, srvid = %u\n", idxShaderState, idxSR, sid, shaderResourceViewId));
     5394
     5395#ifdef DUMP_BITMAPS
     5396                SVGA3dSurfaceImageId image;
     5397                image.sid = sid;
     5398                image.face = 0;
     5399                image.mipmap = 0;
     5400                VMSVGA3D_MAPPED_SURFACE map;
     5401                int rc2 = vmsvga3dSurfaceMap(pThisCC, &image, NULL, VMSVGA3D_SURFACE_MAP_READ, &map);
     5402                if (RT_SUCCESS(rc2))
     5403                {
     5404                    vmsvga3dMapWriteBmpFile(&map, "sr-");
     5405                    vmsvga3dSurfaceUnmap(pThisCC, &image, &map, /* fWritten =  */ false);
     5406                }
     5407                else
     5408                    Log(("Map failed %Rrc\n", rc));
     5409#endif
    53915410            }
    53925411        }
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d.cpp

    r94063 r94223  
    14281428
    14291429    pMap->enmMapType   = enmMapType;
     1430    pMap->format       = pSurface->format;
    14301431    pMap->box          = clipBox;
    14311432    pMap->cbPixel      = pSurface->cbBlock;
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d.h

    r94205 r94223  
    5353{
    5454    VMSVGA3D_SURFACE_MAP enmMapType;
     55    SVGA3dSurfaceFormat format;
    5556    SVGA3dBox box;
    5657    uint32_t cbPixel;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette