void TransformDrawEngine::GLLost() { ILOG("TransformDrawEngine::GLLost()"); // The objects have already been deleted. memset(vbo_, 0, sizeof(vbo_)); memset(ebo_, 0, sizeof(ebo_)); ClearTrackedVertexArrays(); InitDeviceObjects(); }
TransformDrawEngine::TransformDrawEngine() : collectedVerts(0), prevPrim_(GE_PRIM_INVALID), dec_(0), lastVType_(-1), curVbo_(0), shaderManager_(0), textureCache_(0), framebufferManager_(0), numDrawCalls(0), vertexCountInDrawCalls(0), uvScale(0) { decimationCounter_ = VERTEXCACHE_DECIMATION_INTERVAL; // Allocate nicely aligned memory. Maybe graphics drivers will // appreciate it. // All this is a LOT of memory, need to see if we can cut down somehow. decoded = (u8 *)AllocateMemoryPages(DECODED_VERTEX_BUFFER_SIZE); decIndex = (u16 *)AllocateMemoryPages(DECODED_INDEX_BUFFER_SIZE); transformed = (TransformedVertex *)AllocateMemoryPages(TRANSFORMED_VERTEX_BUFFER_SIZE); transformedExpanded = (TransformedVertex *)AllocateMemoryPages(3 * TRANSFORMED_VERTEX_BUFFER_SIZE); quadIndices_ = new u16[6 * QUAD_INDICES_MAX]; for (int i = 0; i < QUAD_INDICES_MAX; i++) { quadIndices_[i * 6 + 0] = i * 4; quadIndices_[i * 6 + 1] = i * 4 + 2; quadIndices_[i * 6 + 2] = i * 4 + 1; quadIndices_[i * 6 + 3] = i * 4 + 1; quadIndices_[i * 6 + 4] = i * 4 + 2; quadIndices_[i * 6 + 5] = i * 4 + 3; } if (g_Config.bPrescaleUV) { uvScale = new UVScale[MAX_DEFERRED_DRAW_CALLS]; } memset(vbo_, 0, sizeof(vbo_)); memset(ebo_, 0, sizeof(ebo_)); indexGen.Setup(decIndex); decJitCache_ = new VertexDecoderJitCache(); InitDeviceObjects(); register_gl_resource_holder(this); }
HRESULT CTailEffectBelt::ChangeTexture( LPDIRECT3DDEVICE9 pd3dDevice, LPCTSTR szFileName, int nType ) { SAFE_RELEASE( m_pTexture ); m_nType = nType; return InitDeviceObjects( pd3dDevice, szFileName ); }
//----------------------------------------------------------------------------- // Name: Initialize3DEnvironment() // Desc: Usually this function is not overridden. Here's what this function does: // - Sets the windowed flag to be either windowed or fullscreen // - Sets parameters for z-buffer depth and back buffer // - Creates the D3D device // - Sets the window position (if windowed, that is) // - Makes some determinations as to the abilites of the driver (HAL, etc) // - Sets up some cursor stuff // - Calls InitDeviceObjects() // - Calls RestoreDeviceObjects() // - If all goes well, m_bActive is set to TRUE, and the function returns // - Otherwise, initialization is reattempted using the reference device //----------------------------------------------------------------------------- HRESULT CMyD3DApplication::Initialize3DEnvironment() { HRESULT hr; D3DAdapterInfo* pAdapterInfo = m_d3dSettings.PAdapterInfo(); D3DDeviceInfo* pDeviceInfo = m_d3dSettings.PDeviceInfo(); m_bWindowed = m_d3dSettings.IsWindowed; // Prepare window for possible windowed/fullscreen change AdjustWindowForChange(); // Set up the presentation parameters BuildPresentParamsFromSettings(); if( pDeviceInfo->Caps.PrimitiveMiscCaps & D3DPMISCCAPS_NULLREFERENCE ) { // Warn user about null ref device that can't render anything DisplayErrorMsg( D3DAPPERR_NULLREFDEVICE, 0 ); } DWORD behaviorFlags; if (m_d3dSettings.GetVertexProcessingType() == SOFTWARE_VP) behaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING; else if (m_d3dSettings.GetVertexProcessingType() == MIXED_VP) behaviorFlags = D3DCREATE_MIXED_VERTEXPROCESSING; else if (m_d3dSettings.GetVertexProcessingType() == HARDWARE_VP) behaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING; else if (m_d3dSettings.GetVertexProcessingType() == PURE_HARDWARE_VP) behaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE; else behaviorFlags = 0; // TODO: throw exception // Add multithreaded flag if requested by app if( m_bCreateMultithreadDevice ) behaviorFlags |= D3DCREATE_MULTITHREADED; // Create the device hr = m_pD3D->CreateDevice( m_d3dSettings.AdapterOrdinal(), pDeviceInfo->DevType, m_hWndFocus, behaviorFlags, &m_d3dpp, &m_pd3dDevice ); if( SUCCEEDED(hr) ) { // When moving from fullscreen to windowed mode, it is important to // adjust the window size after recreating the device rather than // beforehand to ensure that you get the window size you want. For // example, when switching from 640x480 fullscreen to windowed with // a 1000x600 window on a 1024x768 desktop, it is impossible to set // the window size to 1000x600 until after the display mode has // changed to 1024x768, because windows cannot be larger than the // desktop. if( m_bWindowed ) { SetWindowPos( m_hWnd, HWND_NOTOPMOST, m_rcWindowBounds.left, m_rcWindowBounds.top, ( m_rcWindowBounds.right - m_rcWindowBounds.left ), ( m_rcWindowBounds.bottom - m_rcWindowBounds.top ), SWP_HIDEWINDOW ); } // Store device Caps m_pd3dDevice->GetDeviceCaps( &m_d3dCaps ); m_dwCreateFlags = behaviorFlags; // Store device description if( pDeviceInfo->DevType == D3DDEVTYPE_REF ) lstrcpy( m_strDeviceStats, TEXT("REF") ); else if( pDeviceInfo->DevType == D3DDEVTYPE_HAL ) lstrcpy( m_strDeviceStats, TEXT("HAL") ); else if( pDeviceInfo->DevType == D3DDEVTYPE_SW ) lstrcpy( m_strDeviceStats, TEXT("SW") ); if( behaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING && behaviorFlags & D3DCREATE_PUREDEVICE ) { if( pDeviceInfo->DevType == D3DDEVTYPE_HAL ) lstrcat( m_strDeviceStats, TEXT(" (pure hw vp)") ); else lstrcat( m_strDeviceStats, TEXT(" (simulated pure hw vp)") ); } else if( behaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING ) { if( pDeviceInfo->DevType == D3DDEVTYPE_HAL ) lstrcat( m_strDeviceStats, TEXT(" (hw vp)") ); else lstrcat( m_strDeviceStats, TEXT(" (simulated hw vp)") ); } else if( behaviorFlags & D3DCREATE_MIXED_VERTEXPROCESSING ) { if( pDeviceInfo->DevType == D3DDEVTYPE_HAL ) lstrcat( m_strDeviceStats, TEXT(" (mixed vp)") ); else lstrcat( m_strDeviceStats, TEXT(" (simulated mixed vp)") ); } else if( behaviorFlags & D3DCREATE_SOFTWARE_VERTEXPROCESSING ) { lstrcat( m_strDeviceStats, TEXT(" (sw vp)") ); } if( pDeviceInfo->DevType == D3DDEVTYPE_HAL ) { // Be sure not to overflow m_strDeviceStats when appending the adapter // description, since it can be long. Note that the adapter description // is initially CHAR and must be converted to TCHAR. lstrcat( m_strDeviceStats, TEXT(": ") ); const int cchDesc = sizeof(pAdapterInfo->AdapterIdentifier.Description); TCHAR szDescription[cchDesc]; DXUtil_ConvertAnsiStringToGenericCch( szDescription, pAdapterInfo->AdapterIdentifier.Description, cchDesc ); int maxAppend = sizeof(m_strDeviceStats) / sizeof(TCHAR) - lstrlen( m_strDeviceStats ) - 1; _tcsncat( m_strDeviceStats, szDescription, maxAppend ); } // Store render target surface desc LPDIRECT3DSURFACE9 pBackBuffer = NULL; m_pd3dDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer ); pBackBuffer->GetDesc( &m_d3dsdBackBuffer ); pBackBuffer->Release(); // Set up the fullscreen cursor if( m_bShowCursorWhenFullscreen && !m_bWindowed ) { HCURSOR hCursor; #ifdef _WIN64 hCursor = (HCURSOR)GetClassLongPtr( m_hWnd, GCLP_HCURSOR ); #else hCursor = (HCURSOR)ULongToHandle( GetClassLong( m_hWnd, GCL_HCURSOR ) ); #endif D3DUtil_SetDeviceCursor( m_pd3dDevice, hCursor, true ); m_pd3dDevice->ShowCursor( true ); } // Confine cursor to fullscreen window if( m_bClipCursorWhenFullscreen ) { if (!m_bWindowed ) { RECT rcWindow; GetWindowRect( m_hWnd, &rcWindow ); ClipCursor( &rcWindow ); } else { ClipCursor( NULL ); } } // Initialize the app's device-dependent objects hr = InitDeviceObjects(); if( FAILED(hr) ) { DeleteDeviceObjects(); } else { m_bDeviceObjectsInited = true; hr = RestoreDeviceObjects(); if( FAILED(hr) ) { InvalidateDeviceObjects(); } else { m_bDeviceObjectsRestored = true; return S_OK; } } // Cleanup before we try again Cleanup3DEnvironment(); } // If that failed, fall back to the reference rasterizer if( hr != D3DAPPERR_MEDIANOTFOUND && hr != HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND ) && pDeviceInfo->DevType == D3DDEVTYPE_HAL ) { if (FindBestWindowedMode(false, true)) { m_bWindowed = true; AdjustWindowForChange(); // Make sure main window isn't topmost, so error message is visible SetWindowPos( m_hWnd, HWND_NOTOPMOST, m_rcWindowBounds.left, m_rcWindowBounds.top, ( m_rcWindowBounds.right - m_rcWindowBounds.left ), ( m_rcWindowBounds.bottom - m_rcWindowBounds.top ), SWP_SHOWWINDOW ); // Let the user know we are switching from HAL to the reference rasterizer DisplayErrorMsg( hr, MSGWARN_SWITCHEDTOREF ); hr = Initialize3DEnvironment(); } } return hr; }
Vulkan2D::Vulkan2D(VulkanContext *vulkan) : vulkan_(vulkan) { InitDeviceObjects(); }
void Vulkan2D::DeviceRestore(VulkanContext *vulkan) { vulkan_ = vulkan; InitDeviceObjects(); }
//----------------------------------------------------------------------------- // Name: MsgProc() // Desc: Message proc function to handle key and menu input //----------------------------------------------------------------------------- LRESULT CMyD3DApplication::MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { // Pass mouse messages to the ArcBall so it can build internal matrices m_ArcBall.HandleMouseMessages( hWnd, uMsg, wParam, lParam ); // Trap the context menu if( WM_CONTEXTMENU==uMsg ) return 0; if( uMsg == WM_COMMAND ) { // Toggle mesh optimization if( LOWORD(wParam) == IDM_SHOWNONOPTIMIZEDMESH ) { m_bShowVertexCacheOptimized = FALSE; m_bShowStripReordered = FALSE; CheckMenuItem( GetMenu(hWnd), IDM_SHOWNONOPTIMIZEDMESH, MF_CHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWVCACHEOPTIMIZED, MF_UNCHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWSTRIPREORDERED, MF_UNCHECKED ); } else if( LOWORD(wParam) == IDM_SHOWVCACHEOPTIMIZED ) { m_bShowVertexCacheOptimized = TRUE; m_bShowStripReordered = FALSE; CheckMenuItem( GetMenu(hWnd), IDM_SHOWNONOPTIMIZEDMESH, MF_UNCHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWVCACHEOPTIMIZED, MF_CHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWSTRIPREORDERED, MF_UNCHECKED ); } else if( LOWORD(wParam) == IDM_SHOWSTRIPREORDERED ) { m_bShowVertexCacheOptimized = FALSE; m_bShowStripReordered = TRUE; CheckMenuItem( GetMenu(hWnd), IDM_SHOWNONOPTIMIZEDMESH, MF_UNCHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWVCACHEOPTIMIZED, MF_UNCHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWSTRIPREORDERED, MF_CHECKED ); } // Toggle strips else if( LOWORD(wParam) == IDM_SHOWTRILIST ) { m_bShowStrips = FALSE; m_bShowSingleStrip = FALSE; CheckMenuItem( GetMenu(hWnd), IDM_SHOWTRILIST, MF_CHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWONESTRIP, MF_UNCHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWMANYSTRIPS, MF_UNCHECKED ); } else if( LOWORD(wParam) == IDM_SHOWONESTRIP ) { m_bShowStrips = FALSE; m_bShowSingleStrip = TRUE; CheckMenuItem( GetMenu(hWnd), IDM_SHOWTRILIST, MF_UNCHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWONESTRIP, MF_CHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWMANYSTRIPS, MF_UNCHECKED ); } else if( LOWORD(wParam) == IDM_SHOWMANYSTRIPS ) { m_bShowStrips = TRUE; m_bShowSingleStrip = FALSE; CheckMenuItem( GetMenu(hWnd), IDM_SHOWTRILIST, MF_UNCHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWONESTRIP, MF_UNCHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWMANYSTRIPS, MF_CHECKED ); } // Toggle vertex buffer mode else if( LOWORD(wParam) == IDM_DYNAMICVB ) { if (m_dwMemoryOptions == D3DXMESH_DYNAMIC) { m_dwMemoryOptions = D3DXMESH_MANAGED; CheckMenuItem( GetMenu(hWnd), IDM_DYNAMICVB, MF_UNCHECKED ); } else { m_dwMemoryOptions = D3DXMESH_DYNAMIC; CheckMenuItem( GetMenu(hWnd), IDM_DYNAMICVB, MF_CHECKED ); } // Destroy and recreate everything InvalidateDeviceObjects(); RestoreDeviceObjects(); } else if( LOWORD(wParam) == IDM_FORCE32BYTEVERTEX ) { m_bForce32ByteFVF = !m_bForce32ByteFVF; CheckMenuItem( GetMenu(hWnd), IDM_FORCE32BYTEVERTEX, m_bForce32ByteFVF ? MF_CHECKED : MF_UNCHECKED ); // Destroy and recreate everything InvalidateDeviceObjects(); DeleteDeviceObjects(); InitDeviceObjects(); RestoreDeviceObjects(); } // Handle the open file command else if( LOWORD(wParam) == IDM_OPENFILE ) { TCHAR g_strFilename[512] = _T(""); // Display the OpenFileName dialog. Then, try to load the specified file OPENFILENAME ofn = { sizeof(OPENFILENAME), NULL, NULL, _T(".X Files (.x)\0*.x\0\0"), NULL, 0, 1, m_strMeshFilename, 512, g_strFilename, 512, m_strInitialDir, _T("Open Mesh File"), OFN_FILEMUSTEXIST, 0, 1, NULL, 0, NULL, NULL }; if( TRUE == GetOpenFileName( &ofn ) ) { _tcscpy( m_strInitialDir, m_strMeshFilename ); TCHAR* pLastSlash = _tcsrchr( m_strInitialDir, _T('\\') ); if( pLastSlash ) *pLastSlash = 0; SetCurrentDirectory( m_strInitialDir ); // Destroy and recreate everything InvalidateDeviceObjects(); DeleteDeviceObjects(); InitDeviceObjects(); RestoreDeviceObjects(); } } else if ((LOWORD(wParam) >= ID_OPTIONS_DISPLAY1) && (LOWORD(wParam) <= ID_OPTIONS_DISPLAY36)) { // uncheck old item CheckMenuItem( GetMenu(hWnd), ID_OPTIONS_DISPLAY1 + (m_cObjectsPerSide-1), MF_UNCHECKED ); // calc new item m_cObjectsPerSide = LOWORD(wParam) - ID_OPTIONS_DISPLAY1 + 1; // check new item CheckMenuItem( GetMenu(hWnd), ID_OPTIONS_DISPLAY1 + (m_cObjectsPerSide-1), MF_CHECKED ); } } return CD3DApplication::MsgProc( hWnd, uMsg, wParam, lParam ); }
GPU_Vulkan::GPU_Vulkan(GraphicsContext *gfxCtx, Draw::DrawContext *draw) : GPUCommon(gfxCtx, draw), vulkan_((VulkanContext *)gfxCtx->GetAPIContext()), drawEngine_(vulkan_, draw), depalShaderCache_(draw, vulkan_), vulkan2D_(vulkan_) { UpdateVsyncInterval(true); CheckGPUFeatures(); shaderManagerVulkan_ = new ShaderManagerVulkan(vulkan_); pipelineManager_ = new PipelineManagerVulkan(vulkan_); framebufferManagerVulkan_ = new FramebufferManagerVulkan(draw, vulkan_); framebufferManager_ = framebufferManagerVulkan_; textureCacheVulkan_ = new TextureCacheVulkan(draw, vulkan_); textureCache_ = textureCacheVulkan_; drawEngineCommon_ = &drawEngine_; shaderManager_ = shaderManagerVulkan_; drawEngine_.SetTextureCache(textureCacheVulkan_); drawEngine_.SetFramebufferManager(framebufferManagerVulkan_); drawEngine_.SetShaderManager(shaderManagerVulkan_); drawEngine_.SetPipelineManager(pipelineManager_); framebufferManagerVulkan_->SetVulkan2D(&vulkan2D_); framebufferManagerVulkan_->Init(); framebufferManagerVulkan_->SetTextureCache(textureCacheVulkan_); framebufferManagerVulkan_->SetDrawEngine(&drawEngine_); framebufferManagerVulkan_->SetShaderManager(shaderManagerVulkan_); textureCacheVulkan_->SetDepalShaderCache(&depalShaderCache_); textureCacheVulkan_->SetFramebufferManager(framebufferManagerVulkan_); textureCacheVulkan_->SetShaderManager(shaderManagerVulkan_); textureCacheVulkan_->SetDrawEngine(&drawEngine_); textureCacheVulkan_->SetVulkan2D(&vulkan2D_); InitDeviceObjects(); // Sanity check gstate if ((int *)&gstate.transferstart - (int *)&gstate != 0xEA) { ERROR_LOG(G3D, "gstate has drifted out of sync!"); } BuildReportingInfo(); // Update again after init to be sure of any silly driver problems. UpdateVsyncInterval(true); textureCacheVulkan_->NotifyConfigChanged(); if (vulkan_->GetFeaturesEnabled().wideLines) { drawEngine_.SetLineWidth(PSP_CoreParameter().renderWidth / 480.0f); } // Load shader cache. std::string discID = g_paramSFO.GetDiscID(); if (discID.size()) { File::CreateFullPath(GetSysDirectory(DIRECTORY_APP_CACHE)); shaderCachePath_ = GetSysDirectory(DIRECTORY_APP_CACHE) + "/" + discID + ".vkshadercache"; shaderCacheLoaded_ = false; std::thread th([&] { LoadCache(shaderCachePath_); shaderCacheLoaded_ = true; }); th.detach(); } }