VirtualBox

Changeset 59741 in vbox


Ignore:
Timestamp:
Feb 19, 2016 3:11:35 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
105608
Message:

SVGA3d: Applied patch for supporting pretransformed vertices (SVGA3D_DECLUSAGE_POSITIONT) from trivirt.

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

Legend:

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

    r58132 r59741  
    36623662    case SVGA3D_TRANSFORM_PROJECTION:
    36633663    {
    3664         int rc = ShaderTransformProjection(pContext->state.RectViewPort.w, pContext->state.RectViewPort.h, matrix);
     3664        int rc = ShaderTransformProjection(pContext->state.RectViewPort.w, pContext->state.RectViewPort.h, matrix, false /* fPretransformed */);
    36653665        AssertRCReturn(rc, rc);
    36663666        break;
     
    58625862}
    58635863
    5864 int vmsvga3dDrawPrimitivesProcessVertexDecls(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t iVertexDeclBase, uint32_t numVertexDecls, SVGA3dVertexDecl *pVertexDecl)
    5865 {
     5864int vmsvga3dResetTransformMatrices(PVGASTATE pThis, PVMSVGA3DCONTEXT pContext)
     5865{
     5866    int rc;
     5867
     5868    /* Reset the view matrix (also takes the world matrix into account). */
     5869    if (pContext->state.aTransformState[SVGA3D_TRANSFORM_VIEW].fValid == true)
     5870    {
     5871        rc = vmsvga3dSetTransform(pThis, pContext->id, SVGA3D_TRANSFORM_VIEW, pContext->state.aTransformState[SVGA3D_TRANSFORM_VIEW].matrix);
     5872    }
     5873    else
     5874    {
     5875        float matrix[16];
     5876
     5877        /* identity matrix if no matrix set. */
     5878        memset(matrix, 0, sizeof(matrix));
     5879        matrix[0]  = 1.0;
     5880        matrix[5]  = 1.0;
     5881        matrix[10] = 1.0;
     5882        matrix[15] = 1.0;
     5883        rc = vmsvga3dSetTransform(pThis, pContext->id, SVGA3D_TRANSFORM_VIEW, matrix);
     5884    }
     5885
     5886    /* Reset the projection matrix. */
     5887    if (pContext->state.aTransformState[SVGA3D_TRANSFORM_PROJECTION].fValid == true)
     5888    {
     5889        rc = vmsvga3dSetTransform(pThis, pContext->id, SVGA3D_TRANSFORM_PROJECTION, pContext->state.aTransformState[SVGA3D_TRANSFORM_PROJECTION].matrix);
     5890    }
     5891    else
     5892    {
     5893        float matrix[16];
     5894
     5895        /* identity matrix if no matrix set. */
     5896        memset(matrix, 0, sizeof(matrix));
     5897        matrix[0]  = 1.0;
     5898        matrix[5]  = 1.0;
     5899        matrix[10] = 1.0;
     5900        matrix[15] = 1.0;
     5901        rc = vmsvga3dSetTransform(pThis, pContext->id, SVGA3D_TRANSFORM_PROJECTION, matrix);
     5902    }
     5903    AssertRC(rc);
     5904    return rc;
     5905}
     5906
     5907int vmsvga3dDrawPrimitivesProcessVertexDecls(PVGASTATE pThis, PVMSVGA3DCONTEXT pContext, uint32_t iVertexDeclBase, uint32_t numVertexDecls, SVGA3dVertexDecl *pVertexDecl)
     5908{
     5909    PVMSVGA3DSTATE      pState = pThis->svga.p3dState;
    58665910    unsigned            sidVertex = pVertexDecl[0].array.surfaceId;
    58675911    PVMSVGA3DSURFACE    pVertexSurface;
     
    59365980            switch (pVertexDecl[iVertex].identity.usage)
    59375981            {
     5982            case SVGA3D_DECLUSAGE_POSITIONT:
    59385983            case SVGA3D_DECLUSAGE_POSITION:
     5984            {
    59395985                glEnableClientState(GL_VERTEX_ARRAY);
    59405986                VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
     
    59435989                VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    59445990                break;
     5991            }
    59455992            case SVGA3D_DECLUSAGE_BLENDWEIGHT:
    59465993                AssertFailed();
     
    59816028                AssertFailed();
    59826029                break;
    5983             case SVGA3D_DECLUSAGE_POSITIONT:
    5984                 AssertFailed(); /* see position_transformed in Wine */
    5985                 break;
    59866030            case SVGA3D_DECLUSAGE_COLOR:    /** @todo color component order not identical!! test GL_BGRA!! */
    59876031                glEnableClientState(GL_COLOR_ARRAY);
     
    60176061}
    60186062
    6019 int vmsvga3dDrawPrimitivesCleanupVertexDecls(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t iVertexDeclBase, uint32_t numVertexDecls, SVGA3dVertexDecl *pVertexDecl)
    6020 {
    6021     /* Setup the vertex declarations. */
     6063int vmsvga3dDrawPrimitivesCleanupVertexDecls(PVGASTATE pThis, PVMSVGA3DCONTEXT pContext, uint32_t iVertexDeclBase, uint32_t numVertexDecls, SVGA3dVertexDecl *pVertexDecl)
     6064{
     6065    PVMSVGA3DSTATE pState = pThis->svga.p3dState;
     6066
     6067    /* Clean up the vertex declarations. */
    60226068    for (unsigned iVertex = 0; iVertex < numVertexDecls; iVertex++)
    60236069    {
     6070        if (pVertexDecl[iVertex].identity.usage == SVGA3D_DECLUSAGE_POSITIONT)
     6071        {
     6072            /* Reset the transformation matrices in case of a switch back from pretransformed mode. */
     6073            Log(("vmsvga3dDrawPrimitivesCleanupVertexDecls: reset world and projection matrices after transformation reset (pre-transformed -> transformed)\n"));
     6074            vmsvga3dResetTransformMatrices(pThis, pContext);
     6075        }
     6076
    60246077        if (pContext->state.shidVertex != SVGA_ID_INVALID)
    60256078        {
     
    60346087            {
    60356088            case SVGA3D_DECLUSAGE_POSITION:
     6089            case SVGA3D_DECLUSAGE_POSITIONT:
    60366090                glDisableClientState(GL_VERTEX_ARRAY);
    60376091                VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
     
    60636117            case SVGA3D_DECLUSAGE_TESSFACTOR:
    60646118                break;
    6065             case SVGA3D_DECLUSAGE_POSITIONT:
    6066                 break;
    60676119            case SVGA3D_DECLUSAGE_COLOR:    /** @todo color component order not identical!! */
    60686120                glDisableClientState(GL_COLOR_ARRAY);
     
    60896141int vmsvga3dDrawPrimitives(PVGASTATE pThis, uint32_t cid, uint32_t numVertexDecls, SVGA3dVertexDecl *pVertexDecl, uint32_t numRanges, SVGA3dPrimitiveRange *pRange, uint32_t cVertexDivisor, SVGA3dVertexDivisor *pVertexDivisor)
    60906142{
     6143    PVMSVGA3DSTATE               pState = pThis->svga.p3dState;
    60916144    PVMSVGA3DCONTEXT             pContext;
    6092     PVMSVGA3DSTATE               pState = pThis->svga.p3dState;
    60936145    AssertReturn(pState, VERR_INTERNAL_ERROR);
    60946146    int                          rc = VERR_NOT_IMPLEMENTED;
     
    61126164    VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
    61136165
    6114     /* Flush any shader changes. */
     6166    /* Check for pretransformed vertex declarations. */
     6167    for (unsigned iVertex = 0; iVertex < numVertexDecls; iVertex++)
     6168    {
     6169        switch (pVertexDecl[iVertex].identity.usage)
     6170        {
     6171        case SVGA3D_DECLUSAGE_POSITIONT:
     6172            Log(("ShaderSetPositionTransformed: (%d,%d)\n", pContext->state.RectViewPort.w, pContext->state.RectViewPort.h));
     6173        case SVGA3D_DECLUSAGE_POSITION:
     6174            ShaderSetPositionTransformed(pContext->pShaderContext, pContext->state.RectViewPort.w, pContext->state.RectViewPort.h,
     6175                                         pVertexDecl[iVertex].identity.usage == SVGA3D_DECLUSAGE_POSITIONT);
     6176            break;
     6177        }
     6178    }
     6179
     6180    /* Flush any shader changes; after (!) checking the vertex declarations to deal with pre-transformed vertices. */
    61156181    if (pContext->pShaderContext)
    61166182    {
     
    61426208        }
    61436209
    6144         rc = vmsvga3dDrawPrimitivesProcessVertexDecls(pState, pContext, iCurrentVertex, iVertex - iCurrentVertex, &pVertexDecl[iCurrentVertex]);
     6210        rc = vmsvga3dDrawPrimitivesProcessVertexDecls(pThis, pContext, iCurrentVertex, iVertex - iCurrentVertex, &pVertexDecl[iCurrentVertex]);
    61456211        AssertRCReturn(rc, rc);
    61466212
     
    62236289        else
    62246290        {
     6291            GLenum indexType;
     6292
    62256293            Assert(pRange[iPrimitive].indexBias >= 0);  /** @todo  indexBias */
    62266294            Assert(pRange[iPrimitive].indexWidth == pRange[iPrimitive].indexArray.stride);
     6295
     6296            if (pRange[iPrimitive].indexWidth == sizeof(uint8_t))
     6297            {
     6298                indexType = GL_UNSIGNED_BYTE;
     6299            }
     6300            else
     6301            if (pRange[iPrimitive].indexWidth == sizeof(uint16_t))
     6302            {
     6303                indexType = GL_UNSIGNED_SHORT;
     6304            }
     6305            else
     6306            {
     6307                Assert(pRange[iPrimitive].indexWidth == sizeof(uint32_t));
     6308                indexType = GL_UNSIGNED_INT;
     6309            }
    62276310
    62286311            /* Render with an index buffer */
     
    62316314                glDrawElements(modeDraw,
    62326315                               cVertices,
    6233                                (pRange[iPrimitive].indexWidth == sizeof(uint16_t)) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT,
     6316                               indexType,
    62346317                               (GLvoid *)(uintptr_t)pRange[iPrimitive].indexArray.offset);   /* byte offset in indices buffer */
    62356318            else
    62366319                pState->ext.glDrawElementsBaseVertex(modeDraw,
    62376320                                                     cVertices,
    6238                                                      (pRange[iPrimitive].indexWidth == sizeof(uint16_t)) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT,
     6321                                                     indexType,
    62396322                                                     (GLvoid *)(uintptr_t)pRange[iPrimitive].indexArray.offset, /* byte offset in indices buffer */
    62406323                                                     pRange[iPrimitive].indexBias);  /* basevertex */
     
    62656348        }
    62666349
    6267         rc = vmsvga3dDrawPrimitivesCleanupVertexDecls(pState, pContext, iCurrentVertex, iVertex - iCurrentVertex, &pVertexDecl[iCurrentVertex]);
     6350        rc = vmsvga3dDrawPrimitivesCleanupVertexDecls(pThis, pContext, iCurrentVertex, iVertex - iCurrentVertex, &pVertexDecl[iCurrentVertex]);
    62686351        AssertRCReturn(rc, rc);
    62696352
     
    63086391
    63096392#ifdef DEBUG_GFX_WINDOW
    6310     if (pContext->aSidActiveTexture[0])
     6393    if (pContext->sidRenderTarget)
    63116394    {
    63126395        SVGA3dCopyRect rect;
    63136396
    63146397        rect.srcx = rect.srcy = rect.x = rect.y = 0;
    6315         rect.w = 800;
    6316         rect.h = 600;
     6398        rect.w = pContext->state.RectViewPort.w;
     6399        rect.h = pContext->state.RectViewPort.h;
    63176400        vmsvga3dCommandPresent(pThis, pContext->sidRenderTarget, 0, NULL);
    63186401    }
    63196402#endif
     6403
    63206404    return rc;
    63216405}
  • trunk/src/VBox/Devices/Graphics/VBoxSVGA3D.def

    r56333 r59741  
    3636    ShaderUpdateState
    3737    ShaderTransformProjection
     38    ShaderSetPositionTransformed
    3839
     40
  • trunk/src/VBox/Devices/Graphics/shaderlib/glsl_shader.c

    r54765 r59741  
    42624262}
    42634263
     4264#ifdef VBOX_WITH_VMSVGA
     4265static GLhandleARB generate_passthrough_vshader(const struct wined3d_gl_info *gl_info)
     4266{
     4267    GLhandleARB ret = 0;
     4268    static const char *passthrough_vshader[] =
     4269    {
     4270        "#version 120\n"
     4271        "vec4 R0;\n"
     4272        "void main(void)\n"
     4273        "{\n"
     4274        "    R0   = gl_Vertex;\n"
     4275        "    R0.w = 1.0;\n"
     4276        "    R0.z = 0.0;\n"
     4277        "    gl_Position   = gl_ModelViewProjectionMatrix * R0;\n"
     4278        "}\n"
     4279    };
     4280
     4281    ret = GL_EXTCALL(glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB));
     4282    checkGLcall("glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB)");
     4283    GL_EXTCALL(glShaderSourceARB(ret, 1, passthrough_vshader, NULL));
     4284    checkGLcall("glShaderSourceARB(ret, 1, passthrough_vshader, NULL)");
     4285    GL_EXTCALL(glCompileShaderARB(ret));
     4286    checkGLcall("glCompileShaderARB(ret)");
     4287    shader_glsl_validate_compile_link(gl_info, ret, FALSE);
     4288
     4289    return ret;
     4290}
     4291
     4292#endif
     4293
    42644294/* GL locking is done by the caller */
    42654295static void hardcode_local_constants(IWineD3DBaseShaderImpl *shader, const struct wined3d_gl_info *gl_info,
     
    47104740        list_add_head(&((IWineD3DBaseShaderImpl *)vshader)->baseShader.linked_programs, &entry->vshader_entry);
    47114741    }
     4742#ifdef VBOX_WITH_VMSVGA
     4743    else
     4744    if (device->strided_streams.position_transformed)
     4745    {
     4746        GLhandleARB passthrough_vshader_id;
     4747
     4748        passthrough_vshader_id = generate_passthrough_vshader(gl_info);
     4749        TRACE("Attaching GLSL shader object %p to program %p\n", (void *)(uintptr_t)passthrough_vshader_id, (void *)(uintptr_t)programId);
     4750        GL_EXTCALL(glAttachObjectARB(programId, passthrough_vshader_id));
     4751        checkGLcall("glAttachObjectARB");
     4752        /* Flag the reorder function for deletion, then it will be freed automatically when the program
     4753         * is destroyed
     4754         */
     4755        GL_EXTCALL(glDeleteObjectARB(passthrough_vshader_id));
     4756    }
     4757#endif
     4758
    47124759
    47134760    /* Attach GLSL pshader */
  • trunk/src/VBox/Devices/Graphics/shaderlib/shaderapi.c

    r53755 r59741  
    1515 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
    1616 */
    17 
    1817#include <iprt/err.h>
    1918#include <iprt/mem.h>
     
    626625}
    627626
     627SHADERDECL(int) ShaderSetPositionTransformed(void *pShaderContext, unsigned cxViewPort, unsigned cyViewPort, bool fPreTransformed)
     628{
     629    IWineD3DDeviceImpl *This;
     630    int rc;
     631
     632    SHADER_SET_CURRENT_CONTEXT(pShaderContext);
     633    This = g_pCurrentContext->pDeviceContext;
     634
     635    if (This->strided_streams.position_transformed == fPreTransformed)
     636        return VINF_SUCCESS;    /* no changes; nothing to do. */
     637
     638    Log(("ShaderSetPositionTransformed viewport (%d,%d) fPreTransformed=%d\n", cxViewPort, cyViewPort, fPreTransformed));
     639   
     640    if (fPreTransformed)
     641    {   /* In the pre-transformed vertex coordinate case we need to disable all transformations as we're already using screen coordinates. */
     642        /* Load the identity matrix for the model view */
     643        glMatrixMode(GL_MODELVIEW);
     644        glLoadIdentity();
     645
     646        /* Reset the projection matrix too */
     647        rc = ShaderTransformProjection(cxViewPort, cyViewPort, NULL, fPreTransformed);
     648        AssertRCReturn(rc, rc);
     649    }
     650
     651    This->strided_streams.position_transformed = fPreTransformed;
     652    ((IWineD3DVertexDeclarationImpl *)(This->stateBlock->vertexDecl))->position_transformed = fPreTransformed;
     653    return VINF_SUCCESS;
     654}
     655
    628656SHADERDECL(int) ShaderUpdateState(void *pShaderContext, uint32_t rtHeight)
    629657{
     
    668696}
    669697
    670 SHADERDECL(int) ShaderTransformProjection(unsigned cxViewPort, unsigned cyViewPort, float matrix[16])
     698SHADERDECL(int) ShaderTransformProjection(unsigned cxViewPort, unsigned cyViewPort, float matrix[16], bool fPretransformed)
    671699{
    672700#ifdef DEBUG
     
    723751
    724752    glTranslatef(xoffset, -yoffset, -1.0f);
    725     /* flip y coordinate origin too */
    726     glScalef(1.0f, -1.0f, 2.0f);
    727 
    728     glMultMatrixf(matrix);
    729 
     753
     754    if (fPretransformed)
     755    {
     756        /* One world coordinate equals one screen pixel; y-inversion no longer an issue */
     757        glOrtho(0, cxViewPort, 0, cyViewPort, -1, 1);
     758    }
     759    else
     760    {
     761        /* flip y coordinate origin too */
     762        glScalef(1.0f, -1.0f, 2.0f);
     763
     764        /* Apply the supplied projection matrix */
     765        glMultMatrixf(matrix);
     766    }
    730767#ifdef DEBUG
    731768    lastError = glGetError();                                     \
  • trunk/src/VBox/Devices/Graphics/shaderlib/shaderlib.h

    r53755 r59741  
    8787SHADERDECL(int) ShaderSetPixelShaderConstantF(void *pShaderContext, uint32_t reg, const float *pValues, uint32_t cRegisters);
    8888
     89SHADERDECL(int) ShaderSetPositionTransformed(void *pShaderContext, unsigned cxViewPort, unsigned cyViewPort, bool fPreTransformed);
     90
    8991SHADERDECL(int) ShaderUpdateState(void *pShaderContext, uint32_t rtHeight);
    9092
    91 SHADERDECL(int) ShaderTransformProjection(unsigned cxViewPort, unsigned cyViewPort, float matrix[16]);
     93SHADERDECL(int) ShaderTransformProjection(unsigned cxViewPort, unsigned cyViewPort, float matrix[16], bool fPretransformed);
    9294
    9395RT_C_DECLS_END
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