Changeset 57135 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Jul 30, 2015 7:41:09 PM (9 years ago)
- Location:
- trunk/src/VBox/Devices/Graphics
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA.cpp
r57084 r57135 3950 3950 if (pThis->svga.f3DEnabled) 3951 3951 { 3952 # ifdef RT_OS_DARWIN /** @todo r=bird: this is normally done on the EMT, so for DARWIN we do that when loading saved state too now. See DevVGA-SVGA3d-shared.h. */ 3953 vmsvga3dPowerOn(pThis); 3954 # endif 3955 3952 3956 VMSVGA_STATE_LOAD LoadState; 3953 3957 LoadState.pSSM = pSSM; -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-cocoa.m
r57131 r57135 93 93 /** The OpenGL context associated with this view. */ 94 94 NSOpenGLContext *m_pCtx; 95 /** Number of times we've tried to set the view (shut up noisy NSLog). */ 96 uint32_t m_cSetViewAttempts; 95 97 #endif 96 98 … … 111 113 #endif 112 114 - (void)vboxRemoveFromSuperviewAndHide; 113 - (void)vboxClearBuffers;114 115 - (void)vboxUpdateCtxIfNecessary; 115 116 - (void)vboxClearBackBufferIfNecessary; … … 173 174 Frame.origin.x = 0; 174 175 Frame.origin.y = 0; 175 Frame.size.width = pParams->cx < _1M ? pParams->cx : 0;176 Frame.size.height = pParams->cy < _1M ? pParams->cy : 0;176 Frame.size.width = pParams->cx < _1M && pParams->cx > 0 ? pParams->cx : 1; /* 'invalid drawable' if 0,0 size? */ 177 Frame.size.height = pParams->cy < _1M && pParams->cy > 0 ? pParams->cy : 1; 177 178 VMSVGA3DOverlayView *pView = [[VMSVGA3DOverlayView alloc] initWithFrameAndFormat:Frame 178 179 parentView:pParams->pParentView … … 265 266 } 266 267 267 - (id)initWithFrameAndFormat:(NSRect) frame parentView:(NSView *)pParentView pixelFormat:(NSOpenGLPixelFormat *)pFmt268 - (id)initWithFrameAndFormat:(NSRect) frame parentView:(NSView *)pParentView pixelFormat:(NSOpenGLPixelFormat *)pFmt 268 269 { 269 270 LogFlow(("OvlView(%p) initWithFrameAndFormat:\n", (void *)self)); … … 279 280 self = [super initWithFrame:frame pixelFormat:pFmt]; 280 281 #else 282 m_cSetViewAttempts = 0; 283 m_pCtx = NULL; 281 284 self = [super initWithFrame:frame]; 282 285 #endif … … 330 333 } 331 334 332 333 - (void)vboxClearBuffers334 {335 #if 1 /* experiment */336 if ([NSThread isMainThread])337 Log(("OvlView(%p) vboxClearBuffers: skip, main thread\n", (void *)self));338 else339 {340 Log(("OvlView(%p) vboxClearBuffers: clears\n", (void *)self));341 NSOpenGLContext *pSavedCtx = [self makeCurrentGLContext];342 343 /* Clear errors. */344 GLenum rc;345 while ((rc = glGetError()) != GL_NO_ERROR)346 continue;347 348 /* Save the old buffer setting and make it GL_BACK (shall be GL_BACK already actually). */349 GLint iOldDrawBuf = GL_BACK;350 glGetIntegerv(GL_DRAW_BUFFER, &iOldDrawBuf);351 glDrawBuffer(GL_BACK);352 while ((rc = glGetError()) != GL_NO_ERROR)353 AssertMsgFailed(("rc=%x\n", rc));354 355 /* Clear the current GL_BACK. */356 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);357 glClear(GL_COLOR_BUFFER_BIT /*|GL_DEPTH_BUFFER_BIT*/ );358 [[self openGLContext] flushBuffer];359 while ((rc = glGetError()) != GL_NO_ERROR)360 AssertMsgFailed(("rc=%x\n", rc));361 362 /* Clear the previous GL_FRONT. */363 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);364 glClear(GL_COLOR_BUFFER_BIT /*|GL_DEPTH_BUFFER_BIT*/ );365 [[self openGLContext] flushBuffer];366 while ((rc = glGetError()) != GL_NO_ERROR)367 AssertMsgFailed(("rc=%x\n", rc));368 369 /* We're back to the orignal back buffer now. Just restore GL_DRAW_BUFFER. */370 glDrawBuffer(iOldDrawBuf);371 372 while ((rc = glGetError()) != GL_NO_ERROR)373 AssertMsgFailed(("rc=%x\n", rc));374 375 [self restoreSavedGLContext:pSavedCtx];376 }377 #endif378 }379 335 380 336 - (void)vboxUpdateCtxIfNecessary … … 579 535 - (NSOpenGLContext *)openGLContext 580 536 { 581 /* Stupid hack to work around setView failing early. */ 537 /* Stupid hacks to work around setView failing early. This can get kind of 538 noisy on some OS versions, so shut it up a little bit. */ 539 /** @todo use NSOpenGLView for the non-visible contexts. */ 582 540 if (m_pCtx && [m_pCtx view] != self) 583 [m_pCtx setView:self]; 541 { 542 m_cSetViewAttempts++; 543 if ( m_pParentView 544 || m_cSetViewAttempts < 64 545 || (m_cSetViewAttempts & (m_cSetViewAttempts < _64K ? 0xfff : 0x7fff)) == 0 ) 546 [m_pCtx setView:self]; 547 } 584 548 return m_pCtx; 585 549 } … … 759 723 760 724 [pPool release]; 761 LogFlow(("vmsvga3dCocoa SwapBuffers: returns\n"));725 LogFlow(("vmsvga3dCocoaViewMakeCurrentContext: returns\n")); 762 726 } 763 727 -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp
r57131 r57135 4736 4736 } 4737 4737 4738 /** 4739 * Worker for vmsvga3dChangeMode that resizes a context. 4740 * 4741 * @param pThis The VMSVGA state. 4742 * @param pContext The context. 4743 */ 4744 static void vmsvga3dChangeModeOneContext(PVGASTATE pThis, PVMSVGA3DCONTEXT pContext) 4745 { 4746 #ifdef RT_OS_WINDOWS 4747 CREATESTRUCT cs; 4748 4749 memset(&cs, 0, sizeof(cs)); 4750 cs.cx = pThis->svga.uWidth; 4751 cs.cy = pThis->svga.uHeight; 4752 4753 /* Resize the window. */ 4754 int rc = vmsvga3dSendThreadMessage(pState->pWindowThread, pState->WndRequestSem, WM_VMSVGA3D_RESIZEWINDOW, (WPARAM)pContext->hwnd, (LPARAM)&cs); 4755 AssertRC(rc); 4756 #elif defined(RT_OS_DARWIN) 4757 vmsvga3dCocoaViewSetSize(pContext->cocoaView, pThis->svga.uWidth, pThis->svga.uHeight); 4758 #elif defined(RT_OS_LINUX) 4759 XWindowChanges wc; 4760 wc.width = pThis->svga.uWidth; 4761 wc.height = pThis->svga.uHeight; 4762 XConfigureWindow(pState->display, pContext->window, CWWidth | CWHeight, &wc); 4763 #endif 4764 } 4765 4738 4766 /* Handle resize */ 4739 4767 int vmsvga3dChangeMode(PVGASTATE pThis) … … 4742 4770 AssertReturn(pState, VERR_NO_MEMORY); 4743 4771 4772 #ifdef VMSVGA3D_OGL_WITH_SHARED_CTX 4773 /* Resize the shared context too. */ 4774 if (pState->SharedCtx.id == VMSVGA3D_SHARED_CTX_ID) 4775 vmsvga3dChangeModeOneContext(pThis, &pState->SharedCtx); 4776 #endif 4777 4744 4778 /* Resize all active contexts. */ 4745 4779 for (uint32_t i = 0; i < pState->cContexts; i++) 4746 4780 { 4747 4781 PVMSVGA3DCONTEXT pContext = pState->papContexts[i]; 4748 uint32_t cid = pContext->id; 4749 4750 if (cid != SVGA3D_INVALID_ID) 4751 { 4752 #ifdef RT_OS_WINDOWS 4753 CREATESTRUCT cs; 4754 4755 memset(&cs, 0, sizeof(cs)); 4756 cs.cx = pThis->svga.uWidth; 4757 cs.cy = pThis->svga.uHeight; 4758 4759 /* Resize the window. */ 4760 int rc = vmsvga3dSendThreadMessage(pState->pWindowThread, pState->WndRequestSem, WM_VMSVGA3D_RESIZEWINDOW, (WPARAM)pContext->hwnd, (LPARAM)&cs); 4761 AssertRC(rc); 4762 #elif defined(RT_OS_DARWIN) 4763 vmsvga3dCocoaViewSetSize(pContext->cocoaView, pThis->svga.uWidth, pThis->svga.uHeight); 4764 #elif defined(RT_OS_LINUX) 4765 XWindowChanges wc; 4766 wc.width = pThis->svga.uWidth; 4767 wc.height = pThis->svga.uHeight; 4768 XConfigureWindow(pState->display, pContext->window, CWWidth | CWHeight, &wc); 4769 #endif 4770 } 4771 } 4782 if (pContext->id != SVGA3D_INVALID_ID) 4783 vmsvga3dChangeModeOneContext(pThis, pContext); 4784 } 4785 4772 4786 return VINF_SUCCESS; 4773 4787 } … … 4966 4980 return GL_MAX; 4967 4981 default: 4968 Assert Failed();4982 AssertMsgFailed(("blendEq=%d (%#x)\n", blendEq, blendEq)); 4969 4983 return GL_FUNC_ADD; 4970 4984 } -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-shared.h
r57084 r57135 329 329 330 330 331 /** 332 * Reinitializes an active context. 333 * 334 * @returns VBox status code. 335 * @param pThis The VMSVGA device state. 336 * @param pContext The freshly loaded context to reinitialize. 337 */ 338 static int vmsvga3dLoadReinitContext(PVGASTATE pThis, PVMSVGA3DCONTEXT pContext) 339 { 340 int rc; 341 uint32_t cid = pContext->id; 342 Assert(cid != SVGA3D_INVALID_ID); 343 344 /* First set the render targets as they change the internal state (reset viewport etc) */ 345 Log(("vmsvga3dLoadReinitContext: Recreate render targets BEGIN [cid=%#x]\n", cid)); 346 for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aRenderTargets); j++) 347 { 348 if (pContext->state.aRenderTargets[j] != SVGA3D_INVALID_ID) 349 { 350 SVGA3dSurfaceImageId target; 351 352 target.sid = pContext->state.aRenderTargets[j]; 353 target.face = 0; 354 target.mipmap = 0; 355 rc = vmsvga3dSetRenderTarget(pThis, cid, (SVGA3dRenderTargetType)j, target); 356 AssertRCReturn(rc, rc); 357 } 358 } 359 Log(("vmsvga3dLoadReinitContext: Recreate render targets END\n")); 360 361 /* Recreate the render state */ 362 Log(("vmsvga3dLoadReinitContext: Recreate render state BEGIN\n")); 363 for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aRenderState); j++) 364 { 365 SVGA3dRenderState *pRenderState = &pContext->state.aRenderState[j]; 366 367 if (pRenderState->state != SVGA3D_RS_INVALID) 368 vmsvga3dSetRenderState(pThis, pContext->id, 1, pRenderState); 369 } 370 Log(("vmsvga3dLoadReinitContext: Recreate render state END\n")); 371 372 /* Recreate the texture state */ 373 Log(("vmsvga3dLoadReinitContext: Recreate texture state BEGIN\n")); 374 for (uint32_t iStage = 0; iStage < SVGA3D_MAX_TEXTURE_STAGE; iStage++) 375 { 376 for (uint32_t j = 0; j < SVGA3D_TS_MAX; j++) 377 { 378 SVGA3dTextureState *pTextureState = &pContext->state.aTextureState[iStage][j]; 379 380 if (pTextureState->name != SVGA3D_TS_INVALID) 381 vmsvga3dSetTextureState(pThis, pContext->id, 1, pTextureState); 382 } 383 } 384 Log(("vmsvga3dLoadReinitContext: Recreate texture state END\n")); 385 386 /* Reprogram the clip planes. */ 387 for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aClipPlane); j++) 388 { 389 if (pContext->state.aClipPlane[j].fValid == true) 390 vmsvga3dSetClipPlane(pThis, cid, j, pContext->state.aClipPlane[j].plane); 391 } 392 393 /* Reprogram the light data. */ 394 for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aLightData); j++) 395 { 396 if (pContext->state.aLightData[j].fValidData == true) 397 vmsvga3dSetLightData(pThis, cid, j, &pContext->state.aLightData[j].data); 398 if (pContext->state.aLightData[j].fEnabled) 399 vmsvga3dSetLightEnabled(pThis, cid, j, true); 400 } 401 402 /* Recreate the transform state. */ 403 if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_TRANSFORM) 404 { 405 for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aTransformState); j++) 406 { 407 if (pContext->state.aTransformState[j].fValid == true) 408 vmsvga3dSetTransform(pThis, cid, (SVGA3dTransformType)j, pContext->state.aTransformState[j].matrix); 409 } 410 } 411 412 /* Reprogram the material data. */ 413 if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_MATERIAL) 414 { 415 for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aMaterial); j++) 416 { 417 if (pContext->state.aMaterial[j].fValid == true) 418 vmsvga3dSetMaterial(pThis, cid, (SVGA3dFace)j, &pContext->state.aMaterial[j].material); 419 } 420 } 421 422 if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_SCISSORRECT) 423 vmsvga3dSetScissorRect(pThis, cid, &pContext->state.RectScissor); 424 if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_ZRANGE) 425 vmsvga3dSetZRange(pThis, cid, pContext->state.zRange); 426 if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_VIEWPORT) 427 vmsvga3dSetViewPort(pThis, cid, &pContext->state.RectViewPort); 428 if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_VERTEXSHADER) 429 vmsvga3dShaderSet(pThis, pContext, cid, SVGA3D_SHADERTYPE_VS, pContext->state.shidVertex); 430 if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_PIXELSHADER) 431 vmsvga3dShaderSet(pThis, pContext, cid, SVGA3D_SHADERTYPE_PS, pContext->state.shidPixel); 432 433 Log(("vmsvga3dLoadReinitContext: returns [cid=%#x]\n", cid)); 434 return VINF_SUCCESS; 435 } 436 331 437 int vmsvga3dLoadExec(PVGASTATE pThis, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass) 332 438 { … … 335 441 int rc; 336 442 uint32_t cContexts, cSurfaces; 337 443 LogFlow(("vmsvga3dLoadExec:\n")); 444 445 #ifndef RT_OS_DARWIN /** @todo r=bird: this is normally done on the EMT, so for DARWIN we do that when loading saved state too now. See DevVGA-SVGA.cpp */ 338 446 /* Must initialize now as the recreation calls below rely on an initialized 3d subsystem. */ 339 447 vmsvga3dPowerOn(pThis); 448 #endif 340 449 341 450 /* Get the generic 3d state first. */ … … 361 470 { 362 471 uint32_t cPixelShaderConst, cVertexShaderConst, cPixelShaders, cVertexShaders; 363 364 rc = vmsvga3dContextDefine(pThis, cid); 365 AssertRCReturn(rc, rc); 366 367 pContext = pState->papContexts[i]; 472 LogFlow(("vmsvga3dLoadExec: Loading cid=%#x\n", cid)); 473 474 #ifdef VMSVGA3D_OGL_WITH_SHARED_CTX 475 if (cid == VMSVGA3D_SHARED_CTX_ID) 476 { 477 i--; /* Not included in cContexts. */ 478 pContext = &pState->SharedCtx; 479 if (pContext->id != VMSVGA3D_SHARED_CTX_ID) 480 { 481 rc = vmsvga3dContextDefineOgl(pThis, VMSVGA3D_SHARED_CTX_ID, VMSVGA3D_DEF_CTX_F_SHARED_CTX); 482 AssertRCReturn(rc, rc); 483 } 484 } 485 else 486 #endif 487 { 488 rc = vmsvga3dContextDefine(pThis, cid); 489 AssertRCReturn(rc, rc); 490 491 pContext = pState->papContexts[i]; 492 } 368 493 AssertReturn(pContext->id == cid, VERR_INTERNAL_ERROR); 369 494 … … 471 596 } 472 597 } 473 474 } 475 } 598 } 599 } 600 601 #ifdef VMSVGA3D_OGL_WITH_SHARED_CTX 602 /* Make the shared context the current one. */ 603 if (pState->SharedCtx.id == VMSVGA3D_SHARED_CTX_ID) 604 VMSVGA3D_SET_CURRENT_CONTEXT(pState, &pState->SharedCtx); 605 #endif 476 606 477 607 /* Fetch all surfaces. */ … … 487 617 { 488 618 VMSVGA3DSURFACE surface; 619 LogFlow(("vmsvga3dLoadExec: Loading sid=%#x\n", sid)); 489 620 490 621 /* Fetch the surface structure first. */ … … 556 687 } 557 688 689 #ifdef VMSVGA3D_OGL_WITH_SHARED_CTX 690 /* Reinitialize the shared context. */ 691 LogFlow(("vmsvga3dLoadExec: pState->SharedCtx.id=%#x\n", pState->SharedCtx.id)); 692 if (pState->SharedCtx.id == VMSVGA3D_SHARED_CTX_ID) 693 { 694 rc = vmsvga3dLoadReinitContext(pThis, &pState->SharedCtx); 695 AssertRCReturn(rc, rc); 696 } 697 #endif 698 558 699 /* Reinitialize all active contexts. */ 559 700 for (uint32_t i = 0; i < pState->cContexts; i++) 560 701 { 561 702 PVMSVGA3DCONTEXT pContext = pState->papContexts[i]; 562 uint32_t cid = pContext->id; 563 564 if (cid != SVGA3D_INVALID_ID) 565 { 566 /* First set the render targets as they change the internal state (reset viewport etc) */ 567 Log(("vmsvga3dLoadExec: Recreate render targets BEGIN\n")); 568 for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aRenderTargets); j++) 703 if (pContext->id != SVGA3D_INVALID_ID) 704 { 705 rc = vmsvga3dLoadReinitContext(pThis, pContext); 706 AssertRCReturn(rc, rc); 707 } 708 } 709 710 LogFlow(("vmsvga3dLoadExec: return success\n")); 711 return VINF_SUCCESS; 712 } 713 714 715 static int vmsvga3dSaveContext(PVGASTATE pThis, PSSMHANDLE pSSM, PVMSVGA3DCONTEXT pContext) 716 { 717 uint32_t cid = pContext->id; 718 719 /* Save the id first. */ 720 int rc = SSMR3PutU32(pSSM, cid); 721 AssertRCReturn(rc, rc); 722 723 if (cid != SVGA3D_INVALID_ID) 724 { 725 /* Save a copy of the context structure first. */ 726 rc = SSMR3PutStructEx(pSSM, pContext, sizeof(*pContext), 0, g_aVMSVGA3DCONTEXTFields, NULL); 727 AssertRCReturn(rc, rc); 728 729 /* Save all pixel shaders. */ 730 for (uint32_t j = 0; j < pContext->cPixelShaders; j++) 731 { 732 PVMSVGA3DSHADER pShader = &pContext->paPixelShader[j]; 733 734 /* Save the id first. */ 735 rc = SSMR3PutU32(pSSM, pShader->id); 736 AssertRCReturn(rc, rc); 737 738 if (pShader->id != SVGA3D_INVALID_ID) 569 739 { 570 if (pContext->state.aRenderTargets[j] != SVGA3D_INVALID_ID) 571 { 572 SVGA3dSurfaceImageId target; 573 574 target.sid = pContext->state.aRenderTargets[j]; 575 target.face = 0; 576 target.mipmap = 0; 577 rc = vmsvga3dSetRenderTarget(pThis, cid, (SVGA3dRenderTargetType)j, target); 578 AssertRCReturn(rc, rc); 579 } 740 uint32_t cbData = pShader->cbData; 741 742 /* Save a copy of the shader struct. */ 743 rc = SSMR3PutStructEx(pSSM, pShader, sizeof(*pShader), 0, g_aVMSVGA3DSHADERFields, NULL); 744 AssertRCReturn(rc, rc); 745 746 Log(("Save pixelshader shid=%d with %x bytes code.\n", pShader->id, cbData)); 747 rc = SSMR3PutMem(pSSM, pShader->pShaderProgram, cbData); 748 AssertRCReturn(rc, rc); 580 749 } 581 Log(("vmsvga3dLoadExec: Recreate render targets END\n")); 582 583 /* Recreate the render state */ 584 Log(("vmsvga3dLoadExec: Recreate render state BEGIN\n")); 585 for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aRenderState); j++) 750 } 751 752 /* Save all vertex shaders. */ 753 for (uint32_t j = 0; j < pContext->cVertexShaders; j++) 754 { 755 PVMSVGA3DSHADER pShader = &pContext->paVertexShader[j]; 756 757 /* Save the id first. */ 758 rc = SSMR3PutU32(pSSM, pShader->id); 759 AssertRCReturn(rc, rc); 760 761 if (pShader->id != SVGA3D_INVALID_ID) 586 762 { 587 SVGA3dRenderState *pRenderState = &pContext->state.aRenderState[j]; 588 589 if (pRenderState->state != SVGA3D_RS_INVALID) 590 vmsvga3dSetRenderState(pThis, pContext->id, 1, pRenderState); 763 uint32_t cbData = pShader->cbData; 764 765 /* Save a copy of the shader struct. */ 766 rc = SSMR3PutStructEx(pSSM, pShader, sizeof(*pShader), 0, g_aVMSVGA3DSHADERFields, NULL); 767 AssertRCReturn(rc, rc); 768 769 Log(("Save vertex shader shid=%d with %x bytes code.\n", pShader->id, cbData)); 770 /* Fetch the shader code and save it. */ 771 rc = SSMR3PutMem(pSSM, pShader->pShaderProgram, cbData); 772 AssertRCReturn(rc, rc); 591 773 } 592 Log(("vmsvga3dLoadExec: Recreate render state END\n")); 593 594 /* Recreate the texture state */ 595 Log(("vmsvga3dLoadExec: Recreate texture state BEGIN\n")); 596 for (uint32_t iStage = 0; iStage < SVGA3D_MAX_TEXTURE_STAGE; iStage++) 597 { 598 for (uint32_t j = 0; j < SVGA3D_TS_MAX; j++) 599 { 600 SVGA3dTextureState *pTextureState = &pContext->state.aTextureState[iStage][j]; 601 602 if (pTextureState->name != SVGA3D_TS_INVALID) 603 vmsvga3dSetTextureState(pThis, pContext->id, 1, pTextureState); 604 } 605 } 606 Log(("vmsvga3dLoadExec: Recreate texture state END\n")); 607 608 /* Reprogram the clip planes. */ 609 for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aClipPlane); j++) 610 { 611 if (pContext->state.aClipPlane[j].fValid == true) 612 vmsvga3dSetClipPlane(pThis, cid, j, pContext->state.aClipPlane[j].plane); 613 } 614 615 /* Reprogram the light data. */ 616 for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aLightData); j++) 617 { 618 if (pContext->state.aLightData[j].fValidData == true) 619 vmsvga3dSetLightData(pThis, cid, j, &pContext->state.aLightData[j].data); 620 if (pContext->state.aLightData[j].fEnabled) 621 vmsvga3dSetLightEnabled(pThis, cid, j, true); 622 } 623 624 /* Recreate the transform state. */ 625 if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_TRANSFORM) 626 { 627 for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aTransformState); j++) 628 { 629 if (pContext->state.aTransformState[j].fValid == true) 630 vmsvga3dSetTransform(pThis, cid, (SVGA3dTransformType)j, pContext->state.aTransformState[j].matrix); 631 } 632 } 633 634 /* Reprogram the material data. */ 635 if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_MATERIAL) 636 { 637 for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aMaterial); j++) 638 { 639 if (pContext->state.aMaterial[j].fValid == true) 640 vmsvga3dSetMaterial(pThis, cid, (SVGA3dFace)j, &pContext->state.aMaterial[j].material); 641 } 642 } 643 644 if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_SCISSORRECT) 645 vmsvga3dSetScissorRect(pThis, cid, &pContext->state.RectScissor); 646 if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_ZRANGE) 647 vmsvga3dSetZRange(pThis, cid, pContext->state.zRange); 648 if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_VIEWPORT) 649 vmsvga3dSetViewPort(pThis, cid, &pContext->state.RectViewPort); 650 if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_VERTEXSHADER) 651 vmsvga3dShaderSet(pThis, pContext, cid, SVGA3D_SHADERTYPE_VS, pContext->state.shidVertex); 652 if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_PIXELSHADER) 653 vmsvga3dShaderSet(pThis, pContext, cid, SVGA3D_SHADERTYPE_PS, pContext->state.shidPixel); 654 } 655 } 774 } 775 776 /* Save pixel shader constants. */ 777 for (uint32_t j = 0; j < pContext->state.cPixelShaderConst; j++) 778 { 779 rc = SSMR3PutStructEx(pSSM, &pContext->state.paPixelShaderConst[j], sizeof(pContext->state.paPixelShaderConst[j]), 0, g_aVMSVGASHADERCONSTFields, NULL); 780 AssertRCReturn(rc, rc); 781 } 782 783 /* Save vertex shader constants. */ 784 for (uint32_t j = 0; j < pContext->state.cVertexShaderConst; j++) 785 { 786 rc = SSMR3PutStructEx(pSSM, &pContext->state.paVertexShaderConst[j], sizeof(pContext->state.paVertexShaderConst[j]), 0, g_aVMSVGASHADERCONSTFields, NULL); 787 AssertRCReturn(rc, rc); 788 } 789 } 790 656 791 return VINF_SUCCESS; 657 792 } … … 667 802 AssertRCReturn(rc, rc); 668 803 804 #ifdef VMSVGA3D_OGL_WITH_SHARED_CTX 805 /* Save the shared context. */ 806 if (pState->SharedCtx.id == VMSVGA3D_SHARED_CTX_ID) 807 { 808 rc = vmsvga3dSaveContext(pThis, pSSM, &pState->SharedCtx); 809 AssertRCReturn(rc, rc); 810 } 811 #endif 812 669 813 /* Save all active contexts. */ 670 814 for (uint32_t i = 0; i < pState->cContexts; i++) 671 815 { 672 PVMSVGA3DCONTEXT pContext = pState->papContexts[i]; 673 uint32_t cid = pContext->id; 674 675 /* Save the id first. */ 676 rc = SSMR3PutU32(pSSM, cid); 816 rc = vmsvga3dSaveContext(pThis, pSSM, pState->papContexts[i]); 677 817 AssertRCReturn(rc, rc); 678 679 if (cid != SVGA3D_INVALID_ID)680 {681 /* Save a copy of the context structure first. */682 rc = SSMR3PutStructEx(pSSM, pContext, sizeof(*pContext), 0, g_aVMSVGA3DCONTEXTFields, NULL);683 AssertRCReturn(rc, rc);684 685 /* Save all pixel shaders. */686 for (uint32_t j = 0; j < pContext->cPixelShaders; j++)687 {688 PVMSVGA3DSHADER pShader = &pContext->paPixelShader[j];689 690 /* Save the id first. */691 rc = SSMR3PutU32(pSSM, pShader->id);692 AssertRCReturn(rc, rc);693 694 if (pShader->id != SVGA3D_INVALID_ID)695 {696 uint32_t cbData = pShader->cbData;697 698 /* Save a copy of the shader struct. */699 rc = SSMR3PutStructEx(pSSM, pShader, sizeof(*pShader), 0, g_aVMSVGA3DSHADERFields, NULL);700 AssertRCReturn(rc, rc);701 702 Log(("Save pixelshader shid=%d with %x bytes code.\n", pShader->id, cbData));703 rc = SSMR3PutMem(pSSM, pShader->pShaderProgram, cbData);704 AssertRCReturn(rc, rc);705 }706 }707 708 /* Save all vertex shaders. */709 for (uint32_t j = 0; j < pContext->cVertexShaders; j++)710 {711 PVMSVGA3DSHADER pShader = &pContext->paVertexShader[j];712 713 /* Save the id first. */714 rc = SSMR3PutU32(pSSM, pShader->id);715 AssertRCReturn(rc, rc);716 717 if (pShader->id != SVGA3D_INVALID_ID)718 {719 uint32_t cbData = pShader->cbData;720 721 /* Save a copy of the shader struct. */722 rc = SSMR3PutStructEx(pSSM, pShader, sizeof(*pShader), 0, g_aVMSVGA3DSHADERFields, NULL);723 AssertRCReturn(rc, rc);724 725 Log(("Save vertex shader shid=%d with %x bytes code.\n", pShader->id, cbData));726 /* Fetch the shader code and save it. */727 rc = SSMR3PutMem(pSSM, pShader->pShaderProgram, cbData);728 AssertRCReturn(rc, rc);729 }730 }731 732 /* Save pixel shader constants. */733 for (uint32_t j = 0; j < pContext->state.cPixelShaderConst; j++)734 {735 rc = SSMR3PutStructEx(pSSM, &pContext->state.paPixelShaderConst[j], sizeof(pContext->state.paPixelShaderConst[j]), 0, g_aVMSVGASHADERCONSTFields, NULL);736 AssertRCReturn(rc, rc);737 }738 739 /* Save vertex shader constants. */740 for (uint32_t j = 0; j < pContext->state.cVertexShaderConst; j++)741 {742 rc = SSMR3PutStructEx(pSSM, &pContext->state.paVertexShaderConst[j], sizeof(pContext->state.paVertexShaderConst[j]), 0, g_aVMSVGASHADERCONSTFields, NULL);743 AssertRCReturn(rc, rc);744 }745 }746 818 } 747 819
Note:
See TracChangeset
for help on using the changeset viewer.