VirtualBox

Changeset 81080 in vbox


Ignore:
Timestamp:
Sep 30, 2019 12:52:30 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
133684
Message:

Devices/Graphics: correctly process the vertex attribute arrays with zero stride in the OpenGL backend.

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

Legend:

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

    r79668 r81080  
    28082808
    28092809                uint32_t const offHst = pBox->x * pSurface->cbBlock;
     2810                uint32_t const cbWidth = pBox->w * pSurface->cbBlock;
    28102811
    28112812                rc = vmsvgaGMRTransfer(pThis,
     
    28182819                                       pBox->srcx * pSurface->cbBlock,
    28192820                                       cbGuestPitch,
    2820                                        pBox->w * pSurface->cbBlock,
     2821                                       cbWidth,
    28212822                                       pBox->h);
    28222823                AssertRC(rc);
    28232824
    2824                 Log4(("first line:\n%.*Rhxd\n", cbGuestPitch, pbData + offHst));
     2825                Log4(("Buffer content (updated at [0x%x;0x%x):\n%.*Rhxd\n", offHst, offHst + cbWidth, pMipLevel->cbSurface, pbData));
    28252826
    28262827                pState->ext.glUnmapBuffer(GL_ARRAY_BUFFER);
     
    57995800            VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    58005801
    5801             GLuint const divisor = paVertexDivisors && paVertexDivisors[index].s.instanceData ? 1 : 0;
     5802            GLuint divisor = paVertexDivisors && paVertexDivisors[index].s.instanceData ? 1 : 0;
     5803            if (pVertexDecl[iVertex].array.stride == 0 && divisor == 0)
     5804            {
     5805                /* Zero stride means that the attribute pointer must not be increased.
     5806                 * See comment about stride in vmsvga3dDrawPrimitives.
     5807                 */
     5808                LogRelMax(8, ("VMSVGA: Warning: zero stride array (instancing %s)\n", paVertexDivisors ? "on" : "off"));
     5809                AssertFailed();
     5810                divisor = 1;
     5811            }
    58025812            pState->ext.glVertexAttribDivisor(index, divisor);
    58035813            VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
     
    58075817        else
    58085818        {
     5819            if (pVertexDecl[iVertex].array.stride == 0)
     5820            {
     5821                /* Zero stride means that the attribute pointer must not be increased.
     5822                 * See comment about stride in vmsvga3dDrawPrimitives.
     5823                 */
     5824                LogRelMax(8, ("VMSVGA: Warning: zero stride array in fixed function pipeline\n"));
     5825                AssertFailed();
     5826            }
     5827
    58095828            /* Use the predefined selection of vertex streams for the fixed pipeline. */
    58105829            switch (pVertexDecl[iVertex].identity.usage)
     
    59085927        {
    59095928            /* Use numbered vertex arrays when shaders are active. */
     5929            pState->ext.glVertexAttribDivisor(iVertexDeclBase + iVertex, 0);
     5930            VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    59105931            pState->ext.glDisableVertexAttribArray(iVertexDeclBase + iVertex);
    59115932            VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
     
    60136034                break;
    60146035            default:  /* Shut up MSC. */ break;
     6036        }
     6037    }
     6038
     6039    /*
     6040     * D3D and OpenGL have a different meaning of value zero for the vertex array stride:
     6041     * - D3D and VMSVGA: "use a zero stride to tell the runtime not to increment the vertex buffer offset."
     6042     * - OpenGL: "If stride is 0, the generic vertex attributes are understood to be tightly packed in the array."
     6043     * VMSVGA uses the D3D semantics.
     6044     *
     6045     * In order to tell OpenGL to reuse the zero stride attributes for each vertex
     6046     * such attributes could be declared as instance data, then OpenGL applies them once
     6047     * for all vertices of the one drawn instance.
     6048     *
     6049     * If instancing is already used (cVertexDivisor > 0), then the code does nothing and assumes that
     6050     * all instance data is already correctly marked as such.
     6051     *
     6052     * If instancing is not requisted (cVertexDivisor == 0), then the code creates a description for
     6053     * one instance where all arrays with zero stride are marked as instance data, and all arrays
     6054     * with non-zero stride as indexed data.
     6055     */
     6056    bool fZeroStrideArray = false;
     6057    if (cVertexDivisor == 0)
     6058    {
     6059        unsigned i;
     6060        for (i = 0; i < numVertexDecls; ++i)
     6061        {
     6062            if (pVertexDecl[i].array.stride == 0)
     6063            {
     6064                fZeroStrideArray = true;
     6065                break;
     6066            }
     6067        }
     6068
     6069        if (fZeroStrideArray)
     6070        {
     6071            cVertexDivisor = numVertexDecls;
     6072            pVertexDivisor = (SVGA3dVertexDivisor *)RTMemTmpAlloc(sizeof(SVGA3dVertexDivisor) * cVertexDivisor);
     6073            AssertPtrReturn(pVertexDivisor, VERR_NO_MEMORY);
     6074
     6075            for (i = 0; i < numVertexDecls; ++i)
     6076            {
     6077                pVertexDivisor[i].s.count = 1;
     6078                if (pVertexDecl[i].array.stride == 0)
     6079                {
     6080                    pVertexDivisor[i].s.instanceData = 1;
     6081                }
     6082                else
     6083                {
     6084                    pVertexDivisor[i].s.indexedData = 1;
     6085                }
     6086            }
    60156087        }
    60166088    }
     
    62326304        iCurrentVertex = iVertex;
    62336305    }
     6306
     6307    if (fZeroStrideArray)
     6308    {
     6309        RTMemTmpFree(pVertexDivisor);
     6310        pVertexDivisor = NULL;
     6311    }
     6312
    62346313#ifdef DEBUG
    62356314    /* Check whether 'activeTexture' on texture unit 'i' matches what we expect. */
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win.cpp

    r81022 r81080  
    24812481        AssertRC(rc);
    24822482
    2483         Log4(("Buffer first line:\n%.*Rhxd\n", cbWidth, (uint8_t *)pMipLevel->pSurfaceData + offHst));
     2483        Log4(("Buffer content (updated at [0x%x;0x%x):\n%.*Rhxd\n", offHst, offHst + cbWidth, pMipLevel->cbSurface, pMipLevel->pSurfaceData));
    24842484
    24852485        /* Do not bother to copy the data to the D3D resource now. vmsvga3dDrawPrimitives will do that.
Note: See TracChangeset for help on using the changeset viewer.

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