VirtualBox

Changeset 94832 in vbox


Ignore:
Timestamp:
May 5, 2022 6:45:48 AM (3 years ago)
Author:
vboxsync
Message:

Devices/Graphics: guest shader signatures do not need sorting: bugref:9830

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-dx-shader.cpp

    r94741 r94832  
    8181    uint32_t enmComponentType;          /* 1 - unsigned, 2 - integer, 3 - float. */
    8282    uint32_t idxRegister;               /* Shader register index. Elements must be sorted by register index. */
    83     uint32_t mask  : 8;                 /* Component mask. Lower 4 bits represent X, Y, Z, W channels. */
    84     uint32_t mask2 : 8;                 /* Which components are used in the shader. */
    85     uint32_t pad : 16;
     83    union
     84    {
     85        struct
     86        {
     87            uint32_t mask  : 8;         /* Component mask. Lower 4 bits represent X, Y, Z, W channels. */
     88            uint32_t mask2 : 8;         /* Which components are used in the shader. */
     89            uint32_t pad : 16;
     90        } m;
     91        uint32_t mask;
     92    } u;
    8693} DXBCBlobIOSGNElement;
    8794
     
    21722179                               uint32_t cSignature, SVGA3dDXSignatureEntry const *paSignature, DXBCByteWriter *w)
    21732180{
    2174     /* aIdxSignature contains signature indices. aIdxSignature[0] = signature index for register 0. */
    2175     uint32_t aIdxSignature[32];
    2176     memset(aIdxSignature, 0xFF, sizeof(aIdxSignature));
    2177     AssertReturn(cSignature <= RT_ELEMENTS(aIdxSignature), VERR_INTERNAL_ERROR);
    2178     for (uint32_t i = 0; i < cSignature; ++i)
    2179     {
    2180         SVGA3dDXSignatureEntry const *src = &paSignature[i];
    2181         if (src->registerIndex == 0xFFFFFFFF)
    2182         {
    2183             /* oDepth for PS output. */
    2184             ASSERT_GUEST_RETURN(pInfo->enmProgramType == VGPU10_PIXEL_SHADER, VERR_INVALID_PARAMETER);
    2185 
    2186             /* Must be placed last in the signature. */
    2187             ASSERT_GUEST_RETURN(aIdxSignature[cSignature - 1] == 0xFFFFFFFF, VERR_INVALID_PARAMETER);
    2188             aIdxSignature[cSignature - 1] = i;
    2189             continue;
    2190         }
    2191 
    2192         ASSERT_GUEST_RETURN(src->registerIndex < RT_ELEMENTS(aIdxSignature), VERR_INVALID_PARAMETER);
    2193         ASSERT_GUEST_RETURN(aIdxSignature[src->registerIndex] == 0xFFFFFFFF, VERR_INVALID_PARAMETER);
    2194         aIdxSignature[src->registerIndex] = i;
    2195     }
    2196 
    21972181    uint32_t cbBlob = RT_UOFFSETOF_DYN(DXBCBlobIOSGN, aElement[cSignature])
    21982182                    + cSignature * RT_SIZEOFMEMB(DXBCBlobIOSGN, aElement[0]);
     
    22082192    pHdrISGN->offElement = RT_UOFFSETOF(DXBCBlobIOSGN, aElement[0]);
    22092193
    2210     uint32_t aSemanticIdx[SVGADX_SIGNATURE_SEMANTIC_NAME_MAX];
    2211     RT_ZERO(aSemanticIdx);
    2212     uint32_t iSignature = 0;
    2213     for (uint32_t iReg = 0; iReg < RT_ELEMENTS(aIdxSignature); ++iReg)
    2214     {
    2215         if (aIdxSignature[iReg] == 0xFFFFFFFF) /* This register is unused. */
    2216             continue;
    2217 
    2218         AssertReturn(iSignature < cSignature, VERR_INTERNAL_ERROR);
    2219 
    2220         SVGA3dDXSignatureEntry const *src = &paSignature[aIdxSignature[iReg]];
    2221         DXBCBlobIOSGNElement *dst = &pHdrISGN->aElement[iSignature];
    2222 
    2223         ASSERT_GUEST_RETURN(src->semanticName < SVGADX_SIGNATURE_SEMANTIC_NAME_MAX, VERR_INVALID_PARAMETER);
    2224         VGPUSemanticInfo const *pSemanticInfo = dxbcSemanticInfo(pInfo, src->semanticName, u32BlobType);
    2225 
    2226         dst->offElementName   = cbBlob; /* Offset of the semantic's name relative to the start of the blob (without hdr). */
    2227         /* Use the register index as the semantic index for generic attributes in order to
    2228          * produce compatible semantic names between shaders.
     2194    if (pInfo->fGuestSignatures)
     2195    {
     2196        uint32_t aSemanticIdx[SVGADX_SIGNATURE_SEMANTIC_NAME_MAX];
     2197        RT_ZERO(aSemanticIdx);
     2198        for (uint32_t iSignature = 0; iSignature < cSignature; ++iSignature)
     2199        {
     2200            SVGA3dDXSignatureEntry const *src = &paSignature[iSignature];
     2201            DXBCBlobIOSGNElement *dst = &pHdrISGN->aElement[iSignature];
     2202
     2203            ASSERT_GUEST_RETURN(src->semanticName < SVGADX_SIGNATURE_SEMANTIC_NAME_MAX, VERR_INVALID_PARAMETER);
     2204            VGPUSemanticInfo const *pSemanticInfo = dxbcSemanticInfo(pInfo, src->semanticName, u32BlobType);
     2205
     2206            dst->offElementName   = cbBlob; /* Offset of the semantic's name relative to the start of the blob (without hdr). */
     2207            /* Use the register index as the semantic index for generic attributes in order to
     2208             * produce compatible semantic names between shaders.
     2209             */
     2210            dst->idxSemantic      = src->semanticName == SVGADX_SIGNATURE_SEMANTIC_NAME_UNDEFINED
     2211                                  ? src->registerIndex
     2212                                  : aSemanticIdx[src->semanticName]++;
     2213            dst->enmSystemValue   = src->semanticName;
     2214            dst->enmComponentType = src->componentType;
     2215            dst->idxRegister      = src->registerIndex;
     2216            dst->u.mask           = src->mask;
     2217
     2218            /* Figure out the semantic name for this element. */
     2219            char const * const pszElementName = pSemanticInfo->pszName;
     2220            uint32_t const cbElementName = (uint32_t)strlen(pszElementName) + 1;
     2221
     2222            if (!dxbcByteWriterCanWrite(w, cbBlob + cbElementName))
     2223                return VERR_NO_MEMORY;
     2224
     2225            char *pszElementNameDst = (char *)pHdrISGN + dst->offElementName;
     2226            memcpy(pszElementNameDst, pszElementName, cbElementName);
     2227
     2228            cbBlob += cbElementName;
     2229        }
     2230    }
     2231    else
     2232    {
     2233        /* If the signature has been created from the shader code, then sort the signature entries
     2234         * by the register index in order to write them into the blob sorted.
     2235         * This is necessary to match signatures between shader stages.
    22292236         */
    2230         dst->idxSemantic      = src->semanticName == SVGADX_SIGNATURE_SEMANTIC_NAME_UNDEFINED
    2231                               ? src->registerIndex
    2232                               : aSemanticIdx[src->semanticName]++;
    2233         dst->enmSystemValue   = src->semanticName;
    2234         dst->enmComponentType = src->componentType ? src->componentType : pSemanticInfo->u32Type;
    2235         dst->idxRegister      = src->registerIndex;
    2236         dst->mask             = src->mask;
    2237         if (u32BlobType == DXBC_BLOB_TYPE_OSGN)
    2238             dst->mask2            = 0;
    2239         else
    2240             dst->mask2            = src->mask;
    2241 
    2242         /* Figure out the semantic name for this element. */
    2243         char const * const pszElementName = pSemanticInfo->pszName;
    2244         uint32_t const cbElementName = (uint32_t)strlen(pszElementName) + 1;
    2245 
    2246         if (!dxbcByteWriterCanWrite(w, cbBlob + cbElementName))
    2247             return VERR_NO_MEMORY;
    2248 
    2249         char *pszElementNameDst = (char *)pHdrISGN + dst->offElementName;
    2250         memcpy(pszElementNameDst, pszElementName, cbElementName);
    2251 
    2252         cbBlob += cbElementName;
    2253         ++iSignature;
     2237        /* aIdxSignature contains signature indices. aIdxSignature[0] = signature index for register 0. */
     2238        uint32_t aIdxSignature[32];
     2239        memset(aIdxSignature, 0xFF, sizeof(aIdxSignature));
     2240        AssertReturn(cSignature <= RT_ELEMENTS(aIdxSignature), VERR_INTERNAL_ERROR);
     2241        for (uint32_t i = 0; i < cSignature; ++i)
     2242        {
     2243            SVGA3dDXSignatureEntry const *src = &paSignature[i];
     2244            if (src->registerIndex == 0xFFFFFFFF)
     2245            {
     2246                /* oDepth for PS output. */
     2247                ASSERT_GUEST_RETURN(pInfo->enmProgramType == VGPU10_PIXEL_SHADER, VERR_INVALID_PARAMETER);
     2248
     2249                /* Must be placed last in the signature. */
     2250                ASSERT_GUEST_RETURN(aIdxSignature[cSignature - 1] == 0xFFFFFFFF, VERR_INVALID_PARAMETER);
     2251                aIdxSignature[cSignature - 1] = i;
     2252                continue;
     2253            }
     2254
     2255            ASSERT_GUEST_RETURN(src->registerIndex < RT_ELEMENTS(aIdxSignature), VERR_INVALID_PARAMETER);
     2256            ASSERT_GUEST_RETURN(aIdxSignature[src->registerIndex] == 0xFFFFFFFF, VERR_INVALID_PARAMETER);
     2257            aIdxSignature[src->registerIndex] = i;
     2258        }
     2259
     2260        uint32_t aSemanticIdx[SVGADX_SIGNATURE_SEMANTIC_NAME_MAX];
     2261        RT_ZERO(aSemanticIdx);
     2262        uint32_t iSignature = 0;
     2263        for (uint32_t iReg = 0; iReg < RT_ELEMENTS(aIdxSignature); ++iReg)
     2264        {
     2265            if (aIdxSignature[iReg] == 0xFFFFFFFF) /* This register is unused. */
     2266                continue;
     2267
     2268            AssertReturn(iSignature < cSignature, VERR_INTERNAL_ERROR);
     2269
     2270            SVGA3dDXSignatureEntry const *src = &paSignature[aIdxSignature[iReg]];
     2271            DXBCBlobIOSGNElement *dst = &pHdrISGN->aElement[iSignature];
     2272
     2273            ASSERT_GUEST_RETURN(src->semanticName < SVGADX_SIGNATURE_SEMANTIC_NAME_MAX, VERR_INVALID_PARAMETER);
     2274            VGPUSemanticInfo const *pSemanticInfo = dxbcSemanticInfo(pInfo, src->semanticName, u32BlobType);
     2275
     2276            dst->offElementName   = cbBlob; /* Offset of the semantic's name relative to the start of the blob (without hdr). */
     2277            /* Use the register index as the semantic index for generic attributes in order to
     2278             * produce compatible semantic names between shaders.
     2279             */
     2280            dst->idxSemantic      = src->semanticName == SVGADX_SIGNATURE_SEMANTIC_NAME_UNDEFINED
     2281                                  ? src->registerIndex
     2282                                  : aSemanticIdx[src->semanticName]++;
     2283            dst->enmSystemValue   = src->semanticName;
     2284            dst->enmComponentType = src->componentType ? src->componentType : pSemanticInfo->u32Type;
     2285            dst->idxRegister      = src->registerIndex;
     2286            dst->u.m.mask         = src->mask;
     2287            if (u32BlobType == DXBC_BLOB_TYPE_OSGN)
     2288                dst->u.m.mask2    = 0;
     2289            else
     2290                dst->u.m.mask2    = src->mask;
     2291
     2292            /* Figure out the semantic name for this element. */
     2293            char const * const pszElementName = pSemanticInfo->pszName;
     2294            uint32_t const cbElementName = (uint32_t)strlen(pszElementName) + 1;
     2295
     2296            if (!dxbcByteWriterCanWrite(w, cbBlob + cbElementName))
     2297                return VERR_NO_MEMORY;
     2298
     2299            char *pszElementNameDst = (char *)pHdrISGN + dst->offElementName;
     2300            memcpy(pszElementNameDst, pszElementName, cbElementName);
     2301
     2302            cbBlob += cbElementName;
     2303            ++iSignature;
     2304        }
    22542305    }
    22552306
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