DevVGA-SVGA3d-shared.h revision aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * VMware SVGA device -- 3D part
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * Copyright (C) 2013 Oracle Corporation
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * available from http://www.virtualbox.org. This file is free software;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * you can redistribute it and/or modify it under the terms of the GNU
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * General Public License (GPL) as published by the Free Software
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsyncint vmsvga3dLoadExec(PVGASTATE pThis, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync /* Must initialize now as the recreation calls below rely on an initialized 3d subsystem. */
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync /* Get the generic 3d state first. */
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync rc = SSMR3GetStructEx(pSSM, pState, sizeof(*pState), 0, g_aVMSVGA3DSTATEFields, NULL);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync /* Fetch all active contexts. */
50f0e2e83362e100d306a411980d555d46aa00a8vboxsync /* Get the context id */
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync uint32_t cPixelShaderConst, cVertexShaderConst, cPixelShaders, cVertexShaders;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync AssertReturn(pContext->id == cid, VERR_INTERNAL_ERROR);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync rc = SSMR3GetStructEx(pSSM, pContext, sizeof(*pContext), 0, g_aVMSVGA3DCONTEXTFields, NULL);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync cPixelShaderConst = pContext->state.cPixelShaderConst;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync cVertexShaderConst = pContext->state.cVertexShaderConst;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync /* Fetch all pixel shaders. */
50f0e2e83362e100d306a411980d555d46aa00a8vboxsync /* Fetch the id first. */
54828795a553ed0731f308ebda81675ad2c39d58vboxsync /* Fetch a copy of the shader struct. */
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync rc = SSMR3GetStructEx(pSSM, &shader, sizeof(shader), 0, g_aVMSVGA3DSHADERFields, NULL);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync rc = vmsvga3dShaderDefine(pThis, cid, shid, shader.type, shader.cbData, pData);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync /* Fetch all vertex shaders. */
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync /* Fetch the id first. */
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync /* Fetch a copy of the shader struct. */
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync rc = SSMR3GetStructEx(pSSM, &shader, sizeof(shader), 0, g_aVMSVGA3DSHADERFields, NULL);
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync rc = vmsvga3dShaderDefine(pThis, cid, shid, shader.type, shader.cbData, pData);
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync /* Fetch pixel shader constants. */
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync rc = SSMR3GetStructEx(pSSM, &ShaderConst, sizeof(ShaderConst), 0, g_aVMSVGASHADERCONSTFields, NULL);
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync rc = vmsvga3dShaderSetConst(pThis, cid, j, SVGA3D_SHADERTYPE_PS, ShaderConst.ctype, 1, ShaderConst.value);
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync /* Fetch vertex shader constants. */
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync rc = SSMR3GetStructEx(pSSM, &ShaderConst, sizeof(ShaderConst), 0, g_aVMSVGASHADERCONSTFields, NULL);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync rc = vmsvga3dShaderSetConst(pThis, cid, j, SVGA3D_SHADERTYPE_VS, ShaderConst.ctype, 1, ShaderConst.value);
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync /* Fetch all surfaces. */
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync /* Fetch the id first. */
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync /* Fetch the surface structure first. */
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync rc = SSMR3GetStructEx(pSSM, &surface, sizeof(surface), 0, g_aVMSVGA3DSURFACEFields, NULL);
755f4438e1e3a66f23230126b7df46d51006ac24vboxsync uint32_t cMipLevels = surface.faces[0].numMipLevels * surface.cFaces;
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync PVMSVGA3DMIPMAPLEVEL pMipmapLevel = (PVMSVGA3DMIPMAPLEVEL)RTMemAlloc(cMipLevels * sizeof(VMSVGA3DMIPMAPLEVEL));
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync SVGA3dSize *pMipmapLevelSize = (SVGA3dSize *)RTMemAlloc(cMipLevels * sizeof(SVGA3dSize));
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync /* Load the mip map level info. */
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync for (uint32_t face=0; face < surface.cFaces; face++)
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync for (uint32_t j = 0; j < surface.faces[0].numMipLevels; j++)
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync uint32_t idx = j + face * surface.faces[0].numMipLevels;
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync /* Load the mip map level struct. */
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync rc = SSMR3GetStructEx(pSSM, &pMipmapLevel[idx], sizeof(pMipmapLevel[idx]), 0, g_aVMSVGA3DMIPMAPLEVELFields, NULL);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync rc = vmsvga3dSurfaceDefine(pThis, sid, surface.flags, surface.format, surface.faces, surface.multiSampleCount, surface.autogenFilter, cMipLevels, pMipmapLevelSize);
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync PVMSVGA3DSURFACE pSurface = &pState->paSurface[sid];
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync /* Load the mip map level data. */
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync for (uint32_t j = 0; j < pSurface->faces[0].numMipLevels * pSurface->cFaces; j++)
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->pMipmapLevels[j];
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync bool fDataPresent = false;
26bef2fb65df80a28b9972e0a43a92be367417d9vboxsync pMipmapLevel->pSurfaceData = RTMemAllocZ(pMipmapLevel->cbSurface);
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync AssertReturn(pMipmapLevel->pSurfaceData, VERR_NO_MEMORY);
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync /* Fetch the data present boolean first. */
39a628c9e979cb2355caa57eb099b13cb922783cvboxsync Log(("Surface sid=%x: load mipmap level %d with %x bytes data (present=%d).\n", sid, j, pMipmapLevel->cbSurface, fDataPresent));
d308e8fdb9e4d827ed10d26d1581d265602f6f46vboxsync rc = SSMR3GetMem(pSSM, pMipmapLevel->pSurfaceData, pMipmapLevel->cbSurface);
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync /* Reinitialize all active contexts. */
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync PVMSVGA3DCONTEXT pContext = pState->papContexts[i];
7dbde0174637fbfd00c50b383f654e46878eaa8evboxsync /* First set the render targets as they change the internal state (reset viewport etc) */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync Log(("vmsvga3dLoadExec: Recreate render targets BEGIN\n"));
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aRenderTargets); j++)
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync if (pContext->state.aRenderTargets[j] != SVGA3D_INVALID_ID)
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync rc = vmsvga3dSetRenderTarget(pThis, cid, (SVGA3dRenderTargetType)j, target);
7dbde0174637fbfd00c50b383f654e46878eaa8evboxsync Log(("vmsvga3dLoadExec: Recreate render targets END\n"));
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync /* Recreate the render state */
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync Log(("vmsvga3dLoadExec: Recreate render state BEGIN\n"));
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aRenderState); j++)
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync SVGA3dRenderState *pRenderState = &pContext->state.aRenderState[j];
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync vmsvga3dSetRenderState(pThis, pContext->id, 1, pRenderState);
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync Log(("vmsvga3dLoadExec: Recreate render state END\n"));
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* Recreate the texture state */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync Log(("vmsvga3dLoadExec: Recreate texture state BEGIN\n"));
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync for (uint32_t iStage = 0; iStage < SVGA3D_MAX_TEXTURE_STAGE; iStage++)
6c09ee027ad80a5fe6b70ad652253ae6edd09121vboxsync SVGA3dTextureState *pTextureState = &pContext->state.aTextureState[iStage][j];
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync vmsvga3dSetTextureState(pThis, pContext->id, 1, pTextureState);
2673f120424ba2bb67c6da0eb851b65b22b0cba4vboxsync Log(("vmsvga3dLoadExec: Recreate texture state END\n"));
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* Reprogram the clip planes. */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aClipPlane); j++)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync vmsvga3dSetClipPlane(pThis, cid, j, pContext->state.aClipPlane[j].plane);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* Reprogram the light data. */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aLightData); j++)
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync if (pContext->state.aLightData[j].fValidData == true)
7dbde0174637fbfd00c50b383f654e46878eaa8evboxsync vmsvga3dSetLightData(pThis, cid, j, &pContext->state.aLightData[j].data);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* Recreate the transform state. */
846739bf4fe90231599e8de3a8c792ae2851b1d1vboxsync if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_TRANSFORM)
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aTransformState); j++)
5b5f34343f19663d77572b58d4cc70bf57e64b51vboxsync if (pContext->state.aTransformState[j].fValid == true)
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync vmsvga3dSetTransform(pThis, cid, (SVGA3dTransformType)j, pContext->state.aTransformState[j].matrix);
846739bf4fe90231599e8de3a8c792ae2851b1d1vboxsync /* Reprogram the material data. */
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_MATERIAL)
5b5f34343f19663d77572b58d4cc70bf57e64b51vboxsync for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aMaterial); j++)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync vmsvga3dSetMaterial(pThis, cid, (SVGA3dFace)j, &pContext->state.aMaterial[j].material);
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_SCISSORRECT)
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync vmsvga3dSetScissorRect(pThis, cid, &pContext->state.RectScissor);
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_ZRANGE)
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync vmsvga3dSetZRange(pThis, cid, pContext->state.zRange);
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_VIEWPORT)
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync vmsvga3dSetViewPort(pThis, cid, &pContext->state.RectViewPort);
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_VERTEXSHADER)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync vmsvga3dShaderSet(pThis, cid, SVGA3D_SHADERTYPE_VS, pContext->state.shidVertex);
b83d9b1072dd8491c7ffe37830e8fd10f2dba561vboxsync if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_PIXELSHADER)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync vmsvga3dShaderSet(pThis, cid, SVGA3D_SHADERTYPE_PS, pContext->state.shidPixel);
return VINF_SUCCESS;
int rc;
rc = SSMR3PutStructEx(pSSM, &pContext->state.paPixelShaderConst[j], sizeof(pContext->state.paPixelShaderConst[j]), 0, g_aVMSVGASHADERCONSTFields, NULL);
rc = SSMR3PutStructEx(pSSM, &pContext->state.paVertexShaderConst[j], sizeof(pContext->state.paVertexShaderConst[j]), 0, g_aVMSVGASHADERCONSTFields, NULL);
rc = SSMR3PutStructEx(pSSM, pMipmapLevel, sizeof(*pMipmapLevel), 0, g_aVMSVGA3DMIPMAPLEVELFields, NULL);
Log(("Surface sid=%d: save mipmap level %d with %x bytes data.\n", sid, i, pMipmapLevel->cbSurface));
#ifdef VMSVGA3D_DIRECT3D
#ifdef VMSVGA3D_DIRECT3D
void *pData;
bool fRenderTargetTexture = false;
bool fTexture = false;
bool fVertex = false;
bool fSkipSave = false;
switch (pSurface->flags & (SVGA3D_SURFACE_HINT_INDEXBUFFER | SVGA3D_SURFACE_HINT_VERTEXBUFFER | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET | SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_CUBEMAP))
fSkipSave = true;
fRenderTargetTexture = true;
fTexture = true;
if (fTexture)
Log(("vmsvga3dSaveExec invalid context id (%x - %x)!\n", cid, (cid >= pState->cContexts) ? -1 : pState->papContexts[cid]->id));
AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSaveExec: GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR);
AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSaveExec: GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR);
AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSaveExec: GetRenderTargetData failed with %x\n", hr), VERR_INTERNAL_ERROR);
NULL,
NULL,
NULL,
AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSaveExec: LockRect failed with %x\n", hr), VERR_INTERNAL_ERROR);
memcpy((uint8_t *)pData + j * pMipmapLevel->cbSurfacePitch, (uint8_t *)LockedRect.pBits + j * LockedRect.Pitch, pMipmapLevel->cbSurfacePitch);
if (fTexture)
AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSaveExec: UnlockRect failed with %x\n", hr), VERR_INTERNAL_ERROR);
AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSaveExec: UnlockRect failed with %x\n", hr), VERR_INTERNAL_ERROR);
fVertex = true;
if (fVertex)
AssertMsg(hr == D3D_OK, ("vmsvga3dSaveExec: Lock %s failed with %x\n", (fVertex) ? "vertex" : "index", hr));
if (fVertex)
AssertMsg(hr == D3D_OK, ("vmsvga3dSaveExec: Unlock %s failed with %x\n", (fVertex) ? "vertex" : "index", hr));
AssertFailed();
if (!fSkipSave)
# ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
Log(("vmsvga3dSaveExec: invalid context id (%x - %x)!\n", cid, (cid >= pState->cContexts) ? -1 : pState->papContexts[cid]->id));
switch (pSurface->flags & (SVGA3D_SURFACE_HINT_INDEXBUFFER | SVGA3D_SURFACE_HINT_VERTEXBUFFER | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET | SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_CUBEMAP))
AssertFailed();
pData);
if (pData)
return VINF_SUCCESS;
static uint32_t vmsvga3dSaveShaderConst(PVMSVGA3DCONTEXT pContext, uint32_t reg, SVGA3dShaderType type, SVGA3dShaderConstType ctype, uint32_t val1, uint32_t val2, uint32_t val3, uint32_t val4)
pContext->state.paVertexShaderConst = (PVMSVGASHADERCONST)RTMemRealloc(pContext->state.paVertexShaderConst, sizeof(VMSVGASHADERCONST) * (reg + 1));
pContext->state.paPixelShaderConst = (PVMSVGASHADERCONST)RTMemRealloc(pContext->state.paPixelShaderConst, sizeof(VMSVGASHADERCONST) * (reg + 1));
return VINF_SUCCESS;