VirtualBox

Changeset 106119 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Sep 23, 2024 3:27:08 PM (2 months ago)
Author:
vboxsync
Message:

Devices/Graphics: helper to tweak host 3D capabilities. bugref:10717

File:
1 edited

Legend:

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

    r106098 r106119  
    68016801# ifdef VBOX_WITH_VMSVGA3D
    68026802/**
     6803 * Tweak the host 3D capabilities (pThis->svga.au32DevCaps).
     6804 *
     6805 * @returns VBox status code.
     6806 * @param   pThis     The shared VGA/VMSVGA instance data.
     6807 * @param   pThisCC   The VGA/VMSVGA state for ring-3.
     6808 */
     6809static void vmsvgaR3Censor3DCaps(PVGASTATE pThis, PVGASTATECC pThisCC)
     6810{
     6811    RT_NOREF(pThisCC);
     6812
     6813    /*
     6814     * Hide extended VBoxSVGA capabilities if they are not enabled.
     6815     */
     6816    if (!pThis->svga.fVBoxExtensions)
     6817        pThis->svga.au32DevCaps[SVGA3D_DEVCAP_3D] &= VBSVGA3D_CAP_3D;
     6818
     6819    /*
     6820     * D3D11 does not support multisampling for a number of formats:
     6821     * https://learn.microsoft.com/en-us/windows/win32/direct3ddxgi/format-support-for-direct3d-11-1-feature-level-hardware
     6822     * "Format support for Direct3D Feature Level 11.1 hardware"
     6823     * Implementations on non-Windows hosts may report such support.
     6824     * Windows 11 guest actually checks this.
     6825     */
     6826    static const uint32_t aDevCapNoMsaa[] =
     6827    {
     6828        SVGA3D_DEVCAP_DXFMT_R32_FLOAT_X8X24,
     6829        SVGA3D_DEVCAP_DXFMT_X32_G8X24_UINT,
     6830        SVGA3D_DEVCAP_DXFMT_R10G10B10_XR_BIAS_A2_UNORM,
     6831        SVGA3D_DEVCAP_DXFMT_R24_UNORM_X8,
     6832        SVGA3D_DEVCAP_DXFMT_X24_G8_UINT,
     6833        SVGA3D_DEVCAP_DXFMT_R9G9B9E5_SHAREDEXP,
     6834        SVGA3D_DEVCAP_DXFMT_R8G8_B8G8_UNORM,
     6835        SVGA3D_DEVCAP_DXFMT_G8R8_G8B8_UNORM,
     6836        SVGA3D_DEVCAP_DXFMT_BC1_TYPELESS,
     6837        SVGA3D_DEVCAP_DXFMT_BC1_UNORM,
     6838        SVGA3D_DEVCAP_DXFMT_BC1_UNORM_SRGB,
     6839        SVGA3D_DEVCAP_DXFMT_BC2_TYPELESS,
     6840        SVGA3D_DEVCAP_DXFMT_BC2_UNORM,
     6841        SVGA3D_DEVCAP_DXFMT_BC2_UNORM_SRGB,
     6842        SVGA3D_DEVCAP_DXFMT_BC3_TYPELESS,
     6843        SVGA3D_DEVCAP_DXFMT_BC3_UNORM,
     6844        SVGA3D_DEVCAP_DXFMT_BC3_UNORM_SRGB,
     6845        SVGA3D_DEVCAP_DXFMT_BC4_TYPELESS,
     6846        SVGA3D_DEVCAP_DXFMT_BC4_UNORM,
     6847        SVGA3D_DEVCAP_DXFMT_BC4_SNORM,
     6848        SVGA3D_DEVCAP_DXFMT_BC5_TYPELESS,
     6849        SVGA3D_DEVCAP_DXFMT_BC5_UNORM,
     6850        SVGA3D_DEVCAP_DXFMT_BC5_SNORM,
     6851        SVGA3D_DEVCAP_DXFMT_BC6H_TYPELESS,
     6852        SVGA3D_DEVCAP_DXFMT_BC6H_UF16,
     6853        SVGA3D_DEVCAP_DXFMT_BC6H_SF16,
     6854        SVGA3D_DEVCAP_DXFMT_BC7_TYPELESS,
     6855        SVGA3D_DEVCAP_DXFMT_BC7_UNORM,
     6856        SVGA3D_DEVCAP_DXFMT_BC7_UNORM_SRGB,
     6857        SVGA3D_DEVCAP_DXFMT_NV12,
     6858        SVGA3D_DEVCAP_DXFMT_YUY2,
     6859        SVGA3D_DEVCAP_DXFMT_P8
     6860    };
     6861
     6862    for (unsigned i = 0; i < RT_ELEMENTS(aDevCapNoMsaa); ++i)
     6863        pThis->svga.au32DevCaps[aDevCapNoMsaa[i]] &= ~SVGA3D_DXFMT_MULTISAMPLE;
     6864
     6865    /*
     6866     * Formats belonging to the same group must have the same multisample capability.
     6867     */
     6868    static const uint32_t aDevCapR32G32B32A32[] =
     6869    {
     6870        SVGA3D_DEVCAP_DXFMT_R32G32B32A32_TYPELESS,
     6871        SVGA3D_DEVCAP_DXFMT_R32G32B32A32_UINT,
     6872        SVGA3D_DEVCAP_DXFMT_R32G32B32A32_SINT,
     6873        SVGA3D_DEVCAP_DXFMT_R32G32B32A32_FLOAT
     6874    };
     6875
     6876    static const uint32_t aDevCapR32G32B32[] =
     6877    {
     6878        SVGA3D_DEVCAP_DXFMT_R32G32B32_TYPELESS,
     6879        SVGA3D_DEVCAP_DXFMT_R32G32B32_FLOAT,
     6880        SVGA3D_DEVCAP_DXFMT_R32G32B32_UINT,
     6881        SVGA3D_DEVCAP_DXFMT_R32G32B32_SINT
     6882    };
     6883
     6884    static const uint32_t aDevCapR16G16B16A16[] =
     6885    {
     6886        SVGA3D_DEVCAP_DXFMT_R16G16B16A16_TYPELESS,
     6887        SVGA3D_DEVCAP_DXFMT_R16G16B16A16_UINT,
     6888        SVGA3D_DEVCAP_DXFMT_R16G16B16A16_SNORM,
     6889        SVGA3D_DEVCAP_DXFMT_R16G16B16A16_SINT,
     6890        SVGA3D_DEVCAP_DXFMT_R16G16B16A16_FLOAT,
     6891        SVGA3D_DEVCAP_DXFMT_R16G16B16A16_UNORM
     6892    };
     6893
     6894    static const uint32_t aDevCapR32G32[] =
     6895    {
     6896        SVGA3D_DEVCAP_DXFMT_R32G32_TYPELESS,
     6897        SVGA3D_DEVCAP_DXFMT_R32G32_UINT,
     6898        SVGA3D_DEVCAP_DXFMT_R32G32_SINT,
     6899        SVGA3D_DEVCAP_DXFMT_R32G32_FLOAT
     6900    };
     6901
     6902    static const uint32_t aDevCapR32G8X24[] =
     6903    {
     6904        SVGA3D_DEVCAP_DXFMT_R32G8X24_TYPELESS,
     6905        SVGA3D_DEVCAP_DXFMT_D32_FLOAT_S8X24_UINT
     6906    };
     6907
     6908    static const uint32_t aDevCapR10G10B10A2[] =
     6909    {
     6910        SVGA3D_DEVCAP_DXFMT_R10G10B10A2_TYPELESS,
     6911        SVGA3D_DEVCAP_DXFMT_R10G10B10A2_UINT,
     6912        SVGA3D_DEVCAP_DXFMT_R10G10B10A2_UNORM
     6913    };
     6914
     6915    static const uint32_t aDevCapR8G8B8A8[] =
     6916    {
     6917        SVGA3D_DEVCAP_DXFMT_R8G8B8A8_TYPELESS,
     6918        SVGA3D_DEVCAP_DXFMT_R8G8B8A8_UNORM,
     6919        SVGA3D_DEVCAP_DXFMT_R8G8B8A8_UNORM_SRGB,
     6920        SVGA3D_DEVCAP_DXFMT_R8G8B8A8_UINT,
     6921        SVGA3D_DEVCAP_DXFMT_R8G8B8A8_SINT,
     6922        SVGA3D_DEVCAP_DXFMT_R8G8B8A8_SNORM
     6923    };
     6924
     6925    static const uint32_t aDevCapR16G16[] =
     6926    {
     6927        SVGA3D_DEVCAP_DXFMT_R16G16_TYPELESS,
     6928        SVGA3D_DEVCAP_DXFMT_R16G16_UINT,
     6929        SVGA3D_DEVCAP_DXFMT_R16G16_SINT,
     6930        SVGA3D_DEVCAP_DXFMT_R16G16_FLOAT,
     6931        SVGA3D_DEVCAP_DXFMT_R16G16_UNORM,
     6932        SVGA3D_DEVCAP_DXFMT_R16G16_SNORM
     6933    };
     6934
     6935    static const uint32_t aDevCapR32[] =
     6936    {
     6937        SVGA3D_DEVCAP_DXFMT_R32_TYPELESS,
     6938        SVGA3D_DEVCAP_DXFMT_D32_FLOAT,
     6939        SVGA3D_DEVCAP_DXFMT_R32_UINT,
     6940        SVGA3D_DEVCAP_DXFMT_R32_SINT,
     6941        SVGA3D_DEVCAP_DXFMT_R32_FLOAT
     6942    };
     6943
     6944    static const uint32_t aDevCapR24G8[] =
     6945    {
     6946        SVGA3D_DEVCAP_DXFMT_R24G8_TYPELESS,
     6947        SVGA3D_DEVCAP_DXFMT_D24_UNORM_S8_UINT
     6948    };
     6949
     6950    static const uint32_t aDevCapR8G8[] =
     6951    {
     6952        SVGA3D_DEVCAP_DXFMT_R8G8_TYPELESS,
     6953        SVGA3D_DEVCAP_DXFMT_R8G8_UNORM,
     6954        SVGA3D_DEVCAP_DXFMT_R8G8_UINT,
     6955        SVGA3D_DEVCAP_DXFMT_R8G8_SINT,
     6956        SVGA3D_DEVCAP_DXFMT_R8G8_SNORM
     6957    };
     6958
     6959    static const uint32_t aDevCapR16[] =
     6960    {
     6961        SVGA3D_DEVCAP_DXFMT_R16_TYPELESS,
     6962        SVGA3D_DEVCAP_DXFMT_R16_UNORM,
     6963        SVGA3D_DEVCAP_DXFMT_R16_UINT,
     6964        SVGA3D_DEVCAP_DXFMT_R16_SNORM,
     6965        SVGA3D_DEVCAP_DXFMT_R16_SINT,
     6966        SVGA3D_DEVCAP_DXFMT_R16_FLOAT,
     6967        SVGA3D_DEVCAP_DXFMT_D16_UNORM
     6968    };
     6969
     6970    static const uint32_t aDevCapR8[] =
     6971    {
     6972        SVGA3D_DEVCAP_DXFMT_R8_TYPELESS,
     6973        SVGA3D_DEVCAP_DXFMT_R8_UNORM,
     6974        SVGA3D_DEVCAP_DXFMT_R8_UINT,
     6975        SVGA3D_DEVCAP_DXFMT_R8_SNORM,
     6976        SVGA3D_DEVCAP_DXFMT_R8_SINT
     6977    };
     6978
     6979    static const uint32_t aDevCapB8G8R8A8[] =
     6980    {
     6981        SVGA3D_DEVCAP_DXFMT_B8G8R8A8_TYPELESS,
     6982        SVGA3D_DEVCAP_DXFMT_B8G8R8A8_UNORM_SRGB,
     6983        SVGA3D_DEVCAP_DXFMT_B8G8R8A8_UNORM
     6984    };
     6985
     6986    static const uint32_t aDevCapB8G8R8X8[] =
     6987    {
     6988        SVGA3D_DEVCAP_DXFMT_B8G8R8X8_TYPELESS,
     6989        SVGA3D_DEVCAP_DXFMT_B8G8R8X8_UNORM_SRGB,
     6990        SVGA3D_DEVCAP_DXFMT_B8G8R8X8_UNORM
     6991    };
     6992
     6993    typedef struct _FormatGroup
     6994    {
     6995        uint32_t cFormats;
     6996        uint32_t const *pau32DevCaps;
     6997        char const *szGroupName;
     6998    } FormatGroup;
     6999
     7000    #define FORMAT_GROUP_ENTRY(aFormat) { RT_ELEMENTS(aDevCap##aFormat), aDevCap##aFormat, #aFormat }
     7001    static const FormatGroup aFormatGroup[] =
     7002    {
     7003        FORMAT_GROUP_ENTRY(R32G32B32A32),
     7004        FORMAT_GROUP_ENTRY(R32G32B32),
     7005        FORMAT_GROUP_ENTRY(R16G16B16A16),
     7006        FORMAT_GROUP_ENTRY(R32G32),
     7007        FORMAT_GROUP_ENTRY(R32G8X24),
     7008        FORMAT_GROUP_ENTRY(R10G10B10A2),
     7009        FORMAT_GROUP_ENTRY(R8G8B8A8),
     7010        FORMAT_GROUP_ENTRY(R16G16),
     7011        FORMAT_GROUP_ENTRY(R32),
     7012        FORMAT_GROUP_ENTRY(R24G8),
     7013        FORMAT_GROUP_ENTRY(R8G8),
     7014        FORMAT_GROUP_ENTRY(R16),
     7015        FORMAT_GROUP_ENTRY(R8),
     7016        FORMAT_GROUP_ENTRY(B8G8R8A8),
     7017        FORMAT_GROUP_ENTRY(B8G8R8X8)
     7018    };
     7019    #undef FORMAT_GROUP_ENTRY
     7020
     7021    for (unsigned iGroup = 0; iGroup < RT_ELEMENTS(aFormatGroup); ++iGroup)
     7022    {
     7023        FormatGroup const *pGroup = &aFormatGroup[iGroup];
     7024
     7025        /* Verify that all formats have the same MSAA capability. */
     7026        uint32_t const fMSAA = pThis->svga.au32DevCaps[pGroup->pau32DevCaps[0]] & SVGA3D_DXFMT_MULTISAMPLE;
     7027        for (unsigned i = 1; i < pGroup->cFormats; ++i)
     7028        {
     7029            if (fMSAA != (pThis->svga.au32DevCaps[pGroup->pau32DevCaps[i]] & SVGA3D_DXFMT_MULTISAMPLE))
     7030            {
     7031                /* If different MSAA capabilities have been detected. then disable MSAA for the group. */
     7032                LogRel(("VMSVGA3d: disabling MSAA for %s\n", pGroup->szGroupName));
     7033                for (unsigned j = 0; j < pGroup->cFormats; ++j)
     7034                    pThis->svga.au32DevCaps[pGroup->pau32DevCaps[j]] &= ~SVGA3D_DXFMT_MULTISAMPLE;
     7035                break;
     7036            }
     7037        }
     7038    }
     7039}
     7040
     7041/**
    68037042 * Initializes the host 3D capabilities (pThis->svga.au32DevCaps).
    68047043 *
     
    68107049{
    68117050    /* Query the capabilities and store them in the pThis->svga.au32DevCaps array. */
    6812     bool const fSavedBuffering = RTLogRelSetBuffering(true);
     7051
     7052    uint32_t au32FailedCapsBitmap[(RT_ELEMENTS(pThis->svga.au32DevCaps) + 31) / 32];
     7053    RT_ZERO(au32FailedCapsBitmap);
    68137054
    68147055    for (unsigned i = 0; i < RT_ELEMENTS(pThis->svga.au32DevCaps); ++i)
     
    68177058        int rc = vmsvga3dQueryCaps(pThisCC, (SVGA3dDevCapIndex)i, &val);
    68187059        if (RT_SUCCESS(rc))
    6819         {
    6820             if (!pThis->svga.fVBoxExtensions)
    6821             {
    6822                 /* Hide extended VBoxSVGA capabilities. */
    6823                 if (i == SVGA3D_DEVCAP_3D)
    6824                     val &= VBSVGA3D_CAP_3D;
    6825             }
    68267060            pThis->svga.au32DevCaps[i] = val;
    6827         }
    68287061        else
     7062        {
     7063            ASMBitSet(au32FailedCapsBitmap, i);
    68297064            pThis->svga.au32DevCaps[i] = 0;
    6830 
     7065        }
     7066    }
     7067
     7068    vmsvgaR3Censor3DCaps(pThis, pThisCC);
     7069
     7070    bool const fSavedBuffering = RTLogRelSetBuffering(true);
     7071
     7072    for (unsigned i = 0; i < RT_ELEMENTS(pThis->svga.au32DevCaps); ++i)
     7073    {
    68317074        /* LogRel the capability value. */
     7075        uint32_t const val = pThis->svga.au32DevCaps[i];
    68327076        if (i < SVGA3D_DEVCAP_MAX)
    68337077        {
    68347078            char const *pszDevCapName = &vmsvgaDevCapIndexToString((SVGA3dDevCapIndex)i)[sizeof("SVGA3D_DEVCAP")];
    6835             if (RT_SUCCESS(rc))
     7079            if (!ASMBitTest(au32FailedCapsBitmap, i))
    68367080            {
    68377081                if (   i == SVGA3D_DEVCAP_MAX_POINT_SIZE
     
    68467090            }
    68477091            else
    6848                 LogRel(("VMSVGA3d: cap[%u]=failed rc=%Rrc {%s}\n", i, rc, pszDevCapName));
     7092                LogRel(("VMSVGA3d: cap[%u]=%#010x -{%s}\n", i, val, pszDevCapName));
    68497093        }
    68507094        else
    6851             LogRel(("VMSVGA3d: new cap[%u]=%#010x rc=%Rrc\n", i, val, rc));
     7095            LogRel(("VMSVGA3d: new cap[%u]=%#010x%s\n", i, val, ASMBitTest(au32FailedCapsBitmap, i) ? " -" : ""));
    68527096    }
    68537097
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