CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/GPU/Directx9/GPU_DX9.cpp
Views: 1401
// Copyright (c) 2012- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#include <string>1819#include "Common/Serialize/Serializer.h"20#include "Common/GraphicsContext.h"21#include "Common/System/OSD.h"22#include "Common/Profiler/Profiler.h"23#include "Common/Data/Text/I18n.h"24#include "Core/Debugger/Breakpoints.h"25#include "Core/MemMapHelpers.h"26#include "Core/MIPS/MIPS.h"27#include "Core/Config.h"28#include "Core/ConfigValues.h"29#include "Core/System.h"3031#include "Common/GPU/D3D9/D3D9StateCache.h"3233#include "GPU/GPUState.h"34#include "GPU/ge_constants.h"35#include "GPU/GeDisasm.h"3637#include "GPU/Common/FramebufferManagerCommon.h"38#include "GPU/Directx9/ShaderManagerDX9.h"39#include "GPU/Directx9/GPU_DX9.h"40#include "GPU/Directx9/FramebufferManagerDX9.h"41#include "GPU/Directx9/DrawEngineDX9.h"42#include "GPU/Directx9/TextureCacheDX9.h"4344GPU_DX9::GPU_DX9(GraphicsContext *gfxCtx, Draw::DrawContext *draw)45: GPUCommonHW(gfxCtx, draw),46drawEngine_(draw) {47device_ = (LPDIRECT3DDEVICE9)draw->GetNativeObject(Draw::NativeObject::DEVICE);48deviceEx_ = (LPDIRECT3DDEVICE9EX)draw->GetNativeObject(Draw::NativeObject::DEVICE_EX);4950shaderManagerDX9_ = new ShaderManagerDX9(draw, device_);51framebufferManagerDX9_ = new FramebufferManagerDX9(draw);52framebufferManager_ = framebufferManagerDX9_;53textureCacheDX9_ = new TextureCacheDX9(draw, framebufferManager_->GetDraw2D());54textureCache_ = textureCacheDX9_;55drawEngineCommon_ = &drawEngine_;56shaderManager_ = shaderManagerDX9_;5758drawEngine_.SetShaderManager(shaderManagerDX9_);59drawEngine_.SetTextureCache(textureCacheDX9_);60drawEngine_.SetFramebufferManager(framebufferManagerDX9_);61drawEngine_.Init();62framebufferManagerDX9_->SetTextureCache(textureCacheDX9_);63framebufferManagerDX9_->SetShaderManager(shaderManagerDX9_);64framebufferManagerDX9_->SetDrawEngine(&drawEngine_);65framebufferManagerDX9_->Init(msaaLevel_);66textureCacheDX9_->SetFramebufferManager(framebufferManagerDX9_);67textureCacheDX9_->SetShaderManager(shaderManagerDX9_);6869// Sanity check gstate70if ((int *)&gstate.transferstart - (int *)&gstate != 0xEA) {71ERROR_LOG(Log::G3D, "gstate has drifted out of sync!");72}7374// No need to flush before the tex scale/offset commands if we are baking75// the tex scale/offset into the vertices anyway.76UpdateCmdInfo();77gstate_c.SetUseFlags(CheckGPUFeatures());7879BuildReportingInfo();8081// Some of our defaults are different from hw defaults, let's assert them.82// We restore each frame anyway, but here is convenient for tests.83dxstate.Restore();84textureCache_->NotifyConfigChanged();8586if (g_Config.bHardwareTessellation) {87// Disable hardware tessellation bacause DX9 is still unsupported.88ERROR_LOG(Log::G3D, "Hardware Tessellation is unsupported, falling back to software tessellation");89auto gr = GetI18NCategory(I18NCat::GRAPHICS);90// TODO: Badly formulated91g_OSD.Show(OSDType::MESSAGE_WARNING, gr->T("Turn off Hardware Tessellation - unsupported"));92}93}9495u32 GPU_DX9::CheckGPUFeatures() const {96u32 features = GPUCommonHW::CheckGPUFeatures();97features |= GPU_USE_16BIT_FORMATS;98features |= GPU_USE_TEXTURE_LOD_CONTROL;99100// Accurate depth is required because the Direct3D API does not support inverse Z.101// So we cannot incorrectly use the viewport transform as the depth range on Direct3D.102features |= GPU_USE_ACCURATE_DEPTH;103104return CheckGPUFeaturesLate(features);105}106107void GPU_DX9::DeviceLost() {108GPUCommonHW::DeviceLost();109}110111void GPU_DX9::DeviceRestore(Draw::DrawContext *draw) {112GPUCommonHW::DeviceRestore(draw);113}114115void GPU_DX9::ReapplyGfxState() {116dxstate.Restore();117GPUCommonHW::ReapplyGfxState();118}119120void GPU_DX9::BeginHostFrame() {121GPUCommonHW::BeginHostFrame();122123textureCache_->StartFrame();124drawEngine_.BeginFrame();125126shaderManagerDX9_->DirtyLastShader();127128framebufferManager_->BeginFrame();129130if (gstate_c.useFlagsChanged) {131// TODO: It'd be better to recompile them in the background, probably?132// This most likely means that saw equal depth changed.133WARN_LOG(Log::G3D, "Shader use flags changed, clearing all shaders and depth buffers");134shaderManager_->ClearShaders();135framebufferManager_->ClearAllDepthBuffers();136gstate_c.useFlagsChanged = false;137}138}139140void GPU_DX9::FinishDeferred() {141// This finishes reading any vertex data that is pending.142drawEngine_.FinishDeferred();143}144145void GPU_DX9::GetStats(char *buffer, size_t bufsize) {146size_t offset = FormatGPUStatsCommon(buffer, bufsize);147buffer += offset;148bufsize -= offset;149if ((int)bufsize < 0)150return;151snprintf(buffer, bufsize,152"Vertex, Fragment shaders loaded: %i, %i\n",153shaderManagerDX9_->GetNumVertexShaders(),154shaderManagerDX9_->GetNumFragmentShaders()155);156}157158159