DevVGA-SVGA3d-shared.h revision aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync/** @file
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * VMware SVGA device -- 3D part
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync */
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync/*
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * Copyright (C) 2013 Oracle Corporation
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync *
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.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync */
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync#ifndef __DEVVMWARE3D_STATE_H__
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync#define __DEVVMWARE3D_STATE_H__
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsyncint vmsvga3dLoadExec(PVGASTATE pThis, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync{
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync AssertReturn(pState, VERR_NO_MEMORY);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync int rc;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync uint32_t cContexts, cSurfaces;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync /* Must initialize now as the recreation calls below rely on an initialized 3d subsystem. */
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync vmsvga3dPowerOn(pThis);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync /* Get the generic 3d state first. */
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync rc = SSMR3GetStructEx(pSSM, pState, sizeof(*pState), 0, g_aVMSVGA3DSTATEFields, NULL);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync AssertRCReturn(rc, rc);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
c312e1b81dffe42e0fb766020fb8defaeade05d6vboxsync cContexts = pState->cContexts;
c312e1b81dffe42e0fb766020fb8defaeade05d6vboxsync cSurfaces = pState->cSurfaces;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pState->cContexts = 0;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync pState->cSurfaces = 0;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync /* Fetch all active contexts. */
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync for (uint32_t i = 0; i < cContexts; i++)
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync {
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync PVMSVGA3DCONTEXT pContext;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync uint32_t cid;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
50f0e2e83362e100d306a411980d555d46aa00a8vboxsync /* Get the context id */
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync rc = SSMR3GetU32(pSSM, &cid);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync AssertRCReturn(rc, rc);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync if (cid != SVGA3D_INVALID_ID)
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync {
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync uint32_t cPixelShaderConst, cVertexShaderConst, cPixelShaders, cVertexShaders;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync rc = vmsvga3dContextDefine(pThis, cid);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync AssertRCReturn(rc, rc);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync pContext = pState->papContexts[i];
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync AssertReturn(pContext->id == cid, VERR_INTERNAL_ERROR);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync rc = SSMR3GetStructEx(pSSM, pContext, sizeof(*pContext), 0, g_aVMSVGA3DCONTEXTFields, NULL);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync AssertRCReturn(rc, rc);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync cPixelShaders = pContext->cPixelShaders;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync cVertexShaders = pContext->cVertexShaders;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync cPixelShaderConst = pContext->state.cPixelShaderConst;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync cVertexShaderConst = pContext->state.cVertexShaderConst;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync pContext->cPixelShaders = 0;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync pContext->cVertexShaders = 0;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync pContext->state.cPixelShaderConst = 0;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync pContext->state.cVertexShaderConst = 0;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync /* Fetch all pixel shaders. */
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync for (uint32_t j = 0; j < cPixelShaders; j++)
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync {
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync VMSVGA3DSHADER shader;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync uint32_t shid;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
50f0e2e83362e100d306a411980d555d46aa00a8vboxsync /* Fetch the id first. */
50f0e2e83362e100d306a411980d555d46aa00a8vboxsync rc = SSMR3GetU32(pSSM, &shid);
50f0e2e83362e100d306a411980d555d46aa00a8vboxsync AssertRCReturn(rc, rc);
54828795a553ed0731f308ebda81675ad2c39d58vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync if (shid != SVGA3D_INVALID_ID)
54828795a553ed0731f308ebda81675ad2c39d58vboxsync {
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync uint32_t *pData;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
54828795a553ed0731f308ebda81675ad2c39d58vboxsync /* Fetch a copy of the shader struct. */
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync rc = SSMR3GetStructEx(pSSM, &shader, sizeof(shader), 0, g_aVMSVGA3DSHADERFields, NULL);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync AssertRCReturn(rc, rc);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync pData = (uint32_t *)RTMemAlloc(shader.cbData);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync AssertReturn(pData, VERR_NO_MEMORY);
50f0e2e83362e100d306a411980d555d46aa00a8vboxsync
50f0e2e83362e100d306a411980d555d46aa00a8vboxsync rc = SSMR3GetMem(pSSM, pData, shader.cbData);
50f0e2e83362e100d306a411980d555d46aa00a8vboxsync AssertRCReturn(rc, rc);
54828795a553ed0731f308ebda81675ad2c39d58vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync rc = vmsvga3dShaderDefine(pThis, cid, shid, shader.type, shader.cbData, pData);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync AssertRCReturn(rc, rc);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync RTMemFree(pData);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync }
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync }
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync /* Fetch all vertex shaders. */
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync for (uint32_t j = 0; j < cVertexShaders; j++)
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync {
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync VMSVGA3DSHADER shader;
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync uint32_t shid;
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync /* Fetch the id first. */
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync rc = SSMR3GetU32(pSSM, &shid);
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync AssertRCReturn(rc, rc);
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync if (shid != SVGA3D_INVALID_ID)
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync {
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync uint32_t *pData;
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync /* Fetch a copy of the shader struct. */
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync rc = SSMR3GetStructEx(pSSM, &shader, sizeof(shader), 0, g_aVMSVGA3DSHADERFields, NULL);
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync AssertRCReturn(rc, rc);
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync pData = (uint32_t *)RTMemAlloc(shader.cbData);
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync AssertReturn(pData, VERR_NO_MEMORY);
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync rc = SSMR3GetMem(pSSM, pData, shader.cbData);
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync AssertRCReturn(rc, rc);
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync rc = vmsvga3dShaderDefine(pThis, cid, shid, shader.type, shader.cbData, pData);
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync AssertRCReturn(rc, rc);
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync RTMemFree(pData);
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync }
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync }
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync /* Fetch pixel shader constants. */
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync for (uint32_t j = 0; j < cPixelShaderConst; j++)
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync {
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync VMSVGASHADERCONST ShaderConst;
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync rc = SSMR3GetStructEx(pSSM, &ShaderConst, sizeof(ShaderConst), 0, g_aVMSVGASHADERCONSTFields, NULL);
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync AssertRCReturn(rc, rc);
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync if (ShaderConst.fValid)
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync {
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync rc = vmsvga3dShaderSetConst(pThis, cid, j, SVGA3D_SHADERTYPE_PS, ShaderConst.ctype, 1, ShaderConst.value);
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync AssertRCReturn(rc, rc);
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync }
b60e4b0625949fd68ed97f1353e2174c5b3192e5vboxsync }
b60e4b0625949fd68ed97f1353e2174c5b3192e5vboxsync
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync /* Fetch vertex shader constants. */
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync for (uint32_t j = 0; j < cVertexShaderConst; j++)
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync {
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync VMSVGASHADERCONST ShaderConst;
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync rc = SSMR3GetStructEx(pSSM, &ShaderConst, sizeof(ShaderConst), 0, g_aVMSVGASHADERCONSTFields, NULL);
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync AssertRCReturn(rc, rc);
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync if (ShaderConst.fValid)
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync {
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync rc = vmsvga3dShaderSetConst(pThis, cid, j, SVGA3D_SHADERTYPE_VS, ShaderConst.ctype, 1, ShaderConst.value);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync AssertRCReturn(rc, rc);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync }
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync }
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync }
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync }
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync /* Fetch all surfaces. */
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync for (uint32_t i = 0; i < cSurfaces; i++)
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync {
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync uint32_t sid;
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync /* Fetch the id first. */
755f4438e1e3a66f23230126b7df46d51006ac24vboxsync rc = SSMR3GetU32(pSSM, &sid);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync AssertRCReturn(rc, rc);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync if (sid != SVGA3D_INVALID_ID)
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync {
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync VMSVGA3DSURFACE surface;
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync /* Fetch the surface structure first. */
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync rc = SSMR3GetStructEx(pSSM, &surface, sizeof(surface), 0, g_aVMSVGA3DSURFACEFields, NULL);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync AssertRCReturn(rc, rc);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync
755f4438e1e3a66f23230126b7df46d51006ac24vboxsync {
755f4438e1e3a66f23230126b7df46d51006ac24vboxsync uint32_t cMipLevels = surface.faces[0].numMipLevels * surface.cFaces;
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync PVMSVGA3DMIPMAPLEVEL pMipmapLevel = (PVMSVGA3DMIPMAPLEVEL)RTMemAlloc(cMipLevels * sizeof(VMSVGA3DMIPMAPLEVEL));
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync AssertReturn(pMipmapLevel, VERR_NO_MEMORY);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync SVGA3dSize *pMipmapLevelSize = (SVGA3dSize *)RTMemAlloc(cMipLevels * sizeof(SVGA3dSize));
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync AssertReturn(pMipmapLevelSize, VERR_NO_MEMORY);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync /* Load the mip map level info. */
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync for (uint32_t face=0; face < surface.cFaces; face++)
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync {
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync for (uint32_t j = 0; j < surface.faces[0].numMipLevels; j++)
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync {
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 AssertRCReturn(rc, rc);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync pMipmapLevelSize[idx] = pMipmapLevel[idx].size;
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync }
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync }
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync rc = vmsvga3dSurfaceDefine(pThis, sid, surface.flags, surface.format, surface.faces, surface.multiSampleCount, surface.autogenFilter, cMipLevels, pMipmapLevelSize);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync AssertRCReturn(rc, rc);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync RTMemFree(pMipmapLevelSize);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync RTMemFree(pMipmapLevel);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync }
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync PVMSVGA3DSURFACE pSurface = &pState->paSurface[sid];
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync Assert(pSurface->id == sid);
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync pSurface->fDirty = false;
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync /* Load the mip map level data. */
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync for (uint32_t j = 0; j < pSurface->faces[0].numMipLevels * pSurface->cFaces; j++)
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync {
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->pMipmapLevels[j];
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync bool fDataPresent = false;
39a628c9e979cb2355caa57eb099b13cb922783cvboxsync
39a628c9e979cb2355caa57eb099b13cb922783cvboxsync Assert(pMipmapLevel->cbSurface);
26bef2fb65df80a28b9972e0a43a92be367417d9vboxsync pMipmapLevel->pSurfaceData = RTMemAllocZ(pMipmapLevel->cbSurface);
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync AssertReturn(pMipmapLevel->pSurfaceData, VERR_NO_MEMORY);
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync /* Fetch the data present boolean first. */
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync rc = SSMR3GetBool(pSSM, &fDataPresent);
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync AssertRCReturn(rc, rc);
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync
39a628c9e979cb2355caa57eb099b13cb922783cvboxsync Log(("Surface sid=%x: load mipmap level %d with %x bytes data (present=%d).\n", sid, j, pMipmapLevel->cbSurface, fDataPresent));
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync if (fDataPresent)
d308e8fdb9e4d827ed10d26d1581d265602f6f46vboxsync {
d308e8fdb9e4d827ed10d26d1581d265602f6f46vboxsync rc = SSMR3GetMem(pSSM, pMipmapLevel->pSurfaceData, pMipmapLevel->cbSurface);
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync AssertRCReturn(rc, rc);
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync pMipmapLevel->fDirty = true;
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync pSurface->fDirty = true;
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync }
7dbde0174637fbfd00c50b383f654e46878eaa8evboxsync else
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync {
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync pMipmapLevel->fDirty = false;
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync }
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync }
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync }
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync }
7dbde0174637fbfd00c50b383f654e46878eaa8evboxsync
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync /* Reinitialize all active contexts. */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync for (uint32_t i = 0; i < pState->cContexts; i++)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync PVMSVGA3DCONTEXT pContext = pState->papContexts[i];
2673f120424ba2bb67c6da0eb851b65b22b0cba4vboxsync uint32_t cid = pContext->id;
2673f120424ba2bb67c6da0eb851b65b22b0cba4vboxsync
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync if (cid != SVGA3D_INVALID_ID)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
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++)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync if (pContext->state.aRenderTargets[j] != SVGA3D_INVALID_ID)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync SVGA3dSurfaceImageId target;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
b83d9b1072dd8491c7ffe37830e8fd10f2dba561vboxsync target.sid = pContext->state.aRenderTargets[j];
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync target.face = 0;
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync target.mipmap = 0;
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync rc = vmsvga3dSetRenderTarget(pThis, cid, (SVGA3dRenderTargetType)j, target);
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync AssertRCReturn(rc, rc);
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
7dbde0174637fbfd00c50b383f654e46878eaa8evboxsync Log(("vmsvga3dLoadExec: Recreate render targets END\n"));
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync
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 {
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync SVGA3dRenderState *pRenderState = &pContext->state.aRenderState[j];
7dbde0174637fbfd00c50b383f654e46878eaa8evboxsync
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync if (pRenderState->state != SVGA3D_RS_INVALID)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync vmsvga3dSetRenderState(pThis, pContext->id, 1, pRenderState);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync Log(("vmsvga3dLoadExec: Recreate render state END\n"));
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
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++)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync for (uint32_t j = 0; j < SVGA3D_TS_MAX; j++)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
6c09ee027ad80a5fe6b70ad652253ae6edd09121vboxsync SVGA3dTextureState *pTextureState = &pContext->state.aTextureState[iStage][j];
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync if (pTextureState->name != SVGA3D_TS_INVALID)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync vmsvga3dSetTextureState(pThis, pContext->id, 1, pTextureState);
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync }
7dbde0174637fbfd00c50b383f654e46878eaa8evboxsync }
2673f120424ba2bb67c6da0eb851b65b22b0cba4vboxsync Log(("vmsvga3dLoadExec: Recreate texture state END\n"));
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* Reprogram the clip planes. */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aClipPlane); j++)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
7dbde0174637fbfd00c50b383f654e46878eaa8evboxsync if (pContext->state.aClipPlane[j].fValid == true)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync vmsvga3dSetClipPlane(pThis, cid, j, pContext->state.aClipPlane[j].plane);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* Reprogram the light data. */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aLightData); j++)
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync {
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync if (pContext->state.aLightData[j].fValidData == true)
7dbde0174637fbfd00c50b383f654e46878eaa8evboxsync vmsvga3dSetLightData(pThis, cid, j, &pContext->state.aLightData[j].data);
846739bf4fe90231599e8de3a8c792ae2851b1d1vboxsync if (pContext->state.aLightData[j].fEnabled)
5b5f34343f19663d77572b58d4cc70bf57e64b51vboxsync vmsvga3dSetLightEnabled(pThis, cid, j, true);
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync }
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* Recreate the transform state. */
846739bf4fe90231599e8de3a8c792ae2851b1d1vboxsync if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_TRANSFORM)
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync {
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aTransformState); j++)
846739bf4fe90231599e8de3a8c792ae2851b1d1vboxsync {
5b5f34343f19663d77572b58d4cc70bf57e64b51vboxsync if (pContext->state.aTransformState[j].fValid == true)
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync vmsvga3dSetTransform(pThis, cid, (SVGA3dTransformType)j, pContext->state.aTransformState[j].matrix);
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
846739bf4fe90231599e8de3a8c792ae2851b1d1vboxsync
846739bf4fe90231599e8de3a8c792ae2851b1d1vboxsync /* Reprogram the material data. */
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_MATERIAL)
846739bf4fe90231599e8de3a8c792ae2851b1d1vboxsync {
5b5f34343f19663d77572b58d4cc70bf57e64b51vboxsync for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aMaterial); j++)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (pContext->state.aMaterial[j].fValid == true)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync vmsvga3dSetMaterial(pThis, cid, (SVGA3dFace)j, &pContext->state.aMaterial[j].material);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
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);
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync }
}
return VINF_SUCCESS;
}
int vmsvga3dSaveExec(PVGASTATE pThis, PSSMHANDLE pSSM)
{
PVMSVGA3DSTATE pState = (PVMSVGA3DSTATE)pThis->svga.p3dState;
AssertReturn(pState, VERR_NO_MEMORY);
int rc;
/* Save a copy of the generic 3d state first. */
rc = SSMR3PutStructEx(pSSM, pState, sizeof(*pState), 0, g_aVMSVGA3DSTATEFields, NULL);
AssertRCReturn(rc, rc);
/* Save all active contexts. */
for (uint32_t i = 0; i < pState->cContexts; i++)
{
PVMSVGA3DCONTEXT pContext = pState->papContexts[i];
uint32_t cid = pContext->id;
/* Save the id first. */
rc = SSMR3PutU32(pSSM, cid);
AssertRCReturn(rc, rc);
if (cid != SVGA3D_INVALID_ID)
{
/* Save a copy of the context structure first. */
rc = SSMR3PutStructEx(pSSM, pContext, sizeof(*pContext), 0, g_aVMSVGA3DCONTEXTFields, NULL);
AssertRCReturn(rc, rc);
/* Save all pixel shaders. */
for (uint32_t j = 0; j < pContext->cPixelShaders; j++)
{
PVMSVGA3DSHADER pShader = &pContext->paPixelShader[j];
/* Save the id first. */
rc = SSMR3PutU32(pSSM, pShader->id);
AssertRCReturn(rc, rc);
if (pShader->id != SVGA3D_INVALID_ID)
{
uint32_t cbData = pShader->cbData;
/* Save a copy of the shader struct. */
rc = SSMR3PutStructEx(pSSM, pShader, sizeof(*pShader), 0, g_aVMSVGA3DSHADERFields, NULL);
AssertRCReturn(rc, rc);
Log(("Save pixelshader shid=%d with %x bytes code.\n", pShader->id, cbData));
rc = SSMR3PutMem(pSSM, pShader->pShaderProgram, cbData);
AssertRCReturn(rc, rc);
}
}
/* Save all vertex shaders. */
for (uint32_t j = 0; j < pContext->cVertexShaders; j++)
{
PVMSVGA3DSHADER pShader = &pContext->paVertexShader[j];
/* Save the id first. */
rc = SSMR3PutU32(pSSM, pShader->id);
AssertRCReturn(rc, rc);
if (pShader->id != SVGA3D_INVALID_ID)
{
uint32_t cbData = pShader->cbData;
/* Save a copy of the shader struct. */
rc = SSMR3PutStructEx(pSSM, pShader, sizeof(*pShader), 0, g_aVMSVGA3DSHADERFields, NULL);
AssertRCReturn(rc, rc);
Log(("Save vertex shader shid=%d with %x bytes code.\n", pShader->id, cbData));
/* Fetch the shader code and save it. */
rc = SSMR3PutMem(pSSM, pShader->pShaderProgram, cbData);
AssertRCReturn(rc, rc);
}
}
/* Save pixel shader constants. */
for (uint32_t j = 0; j < pContext->state.cPixelShaderConst; j++)
{
rc = SSMR3PutStructEx(pSSM, &pContext->state.paPixelShaderConst[j], sizeof(pContext->state.paPixelShaderConst[j]), 0, g_aVMSVGASHADERCONSTFields, NULL);
AssertRCReturn(rc, rc);
}
/* Save vertex shader constants. */
for (uint32_t j = 0; j < pContext->state.cVertexShaderConst; j++)
{
rc = SSMR3PutStructEx(pSSM, &pContext->state.paVertexShaderConst[j], sizeof(pContext->state.paVertexShaderConst[j]), 0, g_aVMSVGASHADERCONSTFields, NULL);
AssertRCReturn(rc, rc);
}
}
}
/* Save all active surfaces. */
for (uint32_t sid = 0; sid < pState->cSurfaces; sid++)
{
PVMSVGA3DSURFACE pSurface = &pState->paSurface[sid];
/* Save the id first. */
rc = SSMR3PutU32(pSSM, pSurface->id);
AssertRCReturn(rc, rc);
if (pSurface->id != SVGA3D_INVALID_ID)
{
/* Save a copy of the surface structure first. */
rc = SSMR3PutStructEx(pSSM, pSurface, sizeof(*pSurface), 0, g_aVMSVGA3DSURFACEFields, NULL);
AssertRCReturn(rc, rc);
/* Save the mip map level info. */
for (uint32_t face=0; face < pSurface->cFaces; face++)
{
for (uint32_t i = 0; i < pSurface->faces[0].numMipLevels; i++)
{
uint32_t idx = i + face * pSurface->faces[0].numMipLevels;
PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->pMipmapLevels[idx];
/* Save a copy of the mip map level struct. */
rc = SSMR3PutStructEx(pSSM, pMipmapLevel, sizeof(*pMipmapLevel), 0, g_aVMSVGA3DMIPMAPLEVELFields, NULL);
AssertRCReturn(rc, rc);
}
}
/* Save the mip map level data. */
for (uint32_t face=0; face < pSurface->cFaces; face++)
{
for (uint32_t i = 0; i < pSurface->faces[0].numMipLevels; i++)
{
uint32_t idx = i + face * pSurface->faces[0].numMipLevels;
PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->pMipmapLevels[idx];
Log(("Surface sid=%d: save mipmap level %d with %x bytes data.\n", sid, i, pMipmapLevel->cbSurface));
#ifdef VMSVGA3D_DIRECT3D
if (!pSurface->u.pSurface)
#else
if (pSurface->oglId.texture == OPENGL_INVALID_ID)
#endif
{
if (pMipmapLevel->fDirty)
{
/* Data follows */
rc = SSMR3PutBool(pSSM, true);
AssertRCReturn(rc, rc);
Assert(pMipmapLevel->cbSurface);
rc = SSMR3PutMem(pSSM, pMipmapLevel->pSurfaceData, pMipmapLevel->cbSurface);
AssertRCReturn(rc, rc);
}
else
{
/* No data follows */
rc = SSMR3PutBool(pSSM, false);
AssertRCReturn(rc, rc);
}
}
else
{
#ifdef VMSVGA3D_DIRECT3D
void *pData;
bool fRenderTargetTexture = false;
bool fTexture = false;
bool fVertex = false;
bool fSkipSave = false;
HRESULT hr;
Assert(pMipmapLevel->cbSurface);
pData = RTMemAllocZ(pMipmapLevel->cbSurface);
AssertReturn(pData, VERR_NO_MEMORY);
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))
{
case SVGA3D_SURFACE_HINT_DEPTHSTENCIL:
case SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_HINT_TEXTURE:
/* @todo unable to easily fetch depth surface data in d3d 9 */
fSkipSave = true;
break;
case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET:
fRenderTargetTexture = true;
/* no break */
case SVGA3D_SURFACE_HINT_TEXTURE:
fTexture = true;
/* no break */
case SVGA3D_SURFACE_HINT_RENDERTARGET:
{
D3DLOCKED_RECT LockedRect;
if (fTexture)
{
if (pSurface->bounce.pTexture)
{
if ( !pSurface->fDirty
&& fRenderTargetTexture
&& i == 0 /* only the first time */)
{
IDirect3DSurface9 *pSrc, *pDest;
/* @todo stricter checks for associated context */
uint32_t cid = pSurface->idAssociatedContext;
if ( cid >= pState->cContexts
|| pState->papContexts[cid]->id != cid)
{
Log(("vmsvga3dSaveExec invalid context id (%x - %x)!\n", cid, (cid >= pState->cContexts) ? -1 : pState->papContexts[cid]->id));
AssertFailedReturn(VERR_INVALID_PARAMETER);
}
PVMSVGA3DCONTEXT pContext = pState->papContexts[cid];
hr = pSurface->bounce.pTexture->GetSurfaceLevel(i, &pDest);
AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSaveExec: GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR);
hr = pSurface->u.pTexture->GetSurfaceLevel(i, &pSrc);
AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSaveExec: GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR);
hr = pContext->pDevice->GetRenderTargetData(pSrc, pDest);
AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSaveExec: GetRenderTargetData failed with %x\n", hr), VERR_INTERNAL_ERROR);
pSrc->Release();
pDest->Release();
}
hr = pSurface->bounce.pTexture->LockRect(i, /* texture level */
&LockedRect,
NULL,
D3DLOCK_READONLY);
}
else
hr = pSurface->u.pTexture->LockRect(i, /* texture level */
&LockedRect,
NULL,
D3DLOCK_READONLY);
}
else
hr = pSurface->u.pSurface->LockRect(&LockedRect,
NULL,
D3DLOCK_READONLY);
AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSaveExec: LockRect failed with %x\n", hr), VERR_INTERNAL_ERROR);
/* Copy the data one line at a time in case the internal pitch is different. */
for (uint32_t j = 0; j < pMipmapLevel->size.height; j++)
{
memcpy((uint8_t *)pData + j * pMipmapLevel->cbSurfacePitch, (uint8_t *)LockedRect.pBits + j * LockedRect.Pitch, pMipmapLevel->cbSurfacePitch);
}
if (fTexture)
{
if (pSurface->bounce.pTexture)
{
hr = pSurface->bounce.pTexture->UnlockRect(i);
AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSaveExec: UnlockRect failed with %x\n", hr), VERR_INTERNAL_ERROR);
}
else
hr = pSurface->u.pTexture->UnlockRect(i);
}
else
hr = pSurface->u.pSurface->UnlockRect();
AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSaveExec: UnlockRect failed with %x\n", hr), VERR_INTERNAL_ERROR);
break;
}
case SVGA3D_SURFACE_HINT_VERTEXBUFFER:
fVertex = true;
/* no break */
case SVGA3D_SURFACE_HINT_INDEXBUFFER:
{
uint8_t *pD3DData;
if (fVertex)
hr = pSurface->u.pVertexBuffer->Lock(0, 0, (void **)&pD3DData, D3DLOCK_READONLY);
else
hr = pSurface->u.pIndexBuffer->Lock(0, 0, (void **)&pD3DData, D3DLOCK_READONLY);
AssertMsg(hr == D3D_OK, ("vmsvga3dSaveExec: Lock %s failed with %x\n", (fVertex) ? "vertex" : "index", hr));
memcpy(pData, pD3DData, pMipmapLevel->cbSurface);
if (fVertex)
hr = pSurface->u.pVertexBuffer->Unlock();
else
hr = pSurface->u.pIndexBuffer->Unlock();
AssertMsg(hr == D3D_OK, ("vmsvga3dSaveExec: Unlock %s failed with %x\n", (fVertex) ? "vertex" : "index", hr));
break;
}
default:
AssertFailed();
break;
}
if (!fSkipSave)
{
/* Data follows */
rc = SSMR3PutBool(pSSM, true);
AssertRCReturn(rc, rc);
/* And write the surface data. */
rc = SSMR3PutMem(pSSM, pData, pMipmapLevel->cbSurface);
AssertRCReturn(rc, rc);
}
else
{
/* No data follows */
rc = SSMR3PutBool(pSSM, false);
AssertRCReturn(rc, rc);
}
RTMemFree(pData);
#elif defined(VMSVGA3D_OPENGL)
void *pData = NULL;
# ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
PVMSVGA3DCONTEXT pContext = &pState->SharedCtx;
VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
# else
/* @todo stricter checks for associated context */
uint32_t cid = pSurface->idAssociatedContext;
if ( cid >= pState->cContexts
|| pState->papContexts[cid]->id != cid)
{
Log(("vmsvga3dSaveExec: invalid context id (%x - %x)!\n", cid, (cid >= pState->cContexts) ? -1 : pState->papContexts[cid]->id));
AssertFailedReturn(VERR_INVALID_PARAMETER);
}
PVMSVGA3DCONTEXT pContext = pState->papContexts[cid];
VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
# endif
Assert(pMipmapLevel->cbSurface);
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))
{
default:
AssertFailed();
/* no break */
case SVGA3D_SURFACE_HINT_DEPTHSTENCIL:
case SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_HINT_TEXTURE:
/* @todo fetch data from the renderbuffer */
/* No data follows */
rc = SSMR3PutBool(pSSM, false);
AssertRCReturn(rc, rc);
break;
case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET:
case SVGA3D_SURFACE_HINT_TEXTURE:
case SVGA3D_SURFACE_HINT_RENDERTARGET:
{
GLint activeTexture;
pData = RTMemAllocZ(pMipmapLevel->cbSurface);
AssertReturn(pData, VERR_NO_MEMORY);
glGetIntegerv(GL_TEXTURE_BINDING_2D, &activeTexture);
VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
glBindTexture(GL_TEXTURE_2D, pSurface->oglId.texture);
VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
/* Set row length and alignment of the output data. */
VMSVGAPACKPARAMS SavedParams;
vmsvga3dSetPackParams(pState, pContext, pSurface, &SavedParams);
glGetTexImage(GL_TEXTURE_2D,
i,
pSurface->formatGL,
pSurface->typeGL,
pData);
VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
vmsvga3dRestorePackParams(pState, pContext, pSurface, &SavedParams);
/* Data follows */
rc = SSMR3PutBool(pSSM, true);
AssertRCReturn(rc, rc);
/* And write the surface data. */
rc = SSMR3PutMem(pSSM, pData, pMipmapLevel->cbSurface);
AssertRCReturn(rc, rc);
/* Restore the old active texture. */
glBindTexture(GL_TEXTURE_2D, activeTexture);
VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
break;
}
case SVGA3D_SURFACE_HINT_VERTEXBUFFER:
case SVGA3D_SURFACE_HINT_INDEXBUFFER:
{
uint8_t *pBufferData;
pState->ext.glBindBuffer(GL_ARRAY_BUFFER, pSurface->oglId.buffer);
VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
pBufferData = (uint8_t *)pState->ext.glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);
VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
Assert(pBufferData);
/* Data follows */
rc = SSMR3PutBool(pSSM, true);
AssertRCReturn(rc, rc);
/* And write the surface data. */
rc = SSMR3PutMem(pSSM, pBufferData, pMipmapLevel->cbSurface);
AssertRCReturn(rc, rc);
pState->ext.glUnmapBuffer(GL_ARRAY_BUFFER);
VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
pState->ext.glBindBuffer(GL_ARRAY_BUFFER, 0);
VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
}
}
if (pData)
RTMemFree(pData);
#else
#error "Unexpected 3d backend"
#endif
}
}
}
}
}
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)
{
/* Choose a sane upper limit. */
AssertReturn(reg < _32K, VERR_INVALID_PARAMETER);
if (type == SVGA3D_SHADERTYPE_VS)
{
if (pContext->state.cVertexShaderConst <= reg)
{
pContext->state.paVertexShaderConst = (PVMSVGASHADERCONST)RTMemRealloc(pContext->state.paVertexShaderConst, sizeof(VMSVGASHADERCONST) * (reg + 1));
AssertReturn(pContext->state.paVertexShaderConst, VERR_NO_MEMORY);
for (uint32_t i = pContext->state.cVertexShaderConst; i < reg + 1; i++)
pContext->state.paVertexShaderConst[i].fValid = false;
pContext->state.cVertexShaderConst = reg + 1;
}
pContext->state.paVertexShaderConst[reg].fValid = true;
pContext->state.paVertexShaderConst[reg].ctype = ctype;
pContext->state.paVertexShaderConst[reg].value[0] = val1;
pContext->state.paVertexShaderConst[reg].value[1] = val2;
pContext->state.paVertexShaderConst[reg].value[2] = val3;
pContext->state.paVertexShaderConst[reg].value[3] = val4;
}
else
{
Assert(type == SVGA3D_SHADERTYPE_PS);
if (pContext->state.cPixelShaderConst <= reg)
{
pContext->state.paPixelShaderConst = (PVMSVGASHADERCONST)RTMemRealloc(pContext->state.paPixelShaderConst, sizeof(VMSVGASHADERCONST) * (reg + 1));
AssertReturn(pContext->state.paPixelShaderConst, VERR_NO_MEMORY);
for (uint32_t i = pContext->state.cPixelShaderConst; i < reg + 1; i++)
pContext->state.paPixelShaderConst[i].fValid = false;
pContext->state.cPixelShaderConst = reg + 1;
}
pContext->state.paPixelShaderConst[reg].fValid = true;
pContext->state.paPixelShaderConst[reg].ctype = ctype;
pContext->state.paPixelShaderConst[reg].value[0] = val1;
pContext->state.paPixelShaderConst[reg].value[1] = val2;
pContext->state.paPixelShaderConst[reg].value[2] = val3;
pContext->state.paPixelShaderConst[reg].value[3] = val4;
}
return VINF_SUCCESS;
}
#endif /* __DEVVMWARE3D_STATE_H__ */