Files
ppsspp/GPU/Directx9/GPU_DX9.cpp

158 lines
5.2 KiB
C++
Raw Permalink Normal View History

2013-08-17 11:23:51 +02:00
// Copyright (c) 2012- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <string>
2013-12-29 15:55:09 -08:00
#include "Common/Serialize/Serializer.h"
2016-02-13 10:53:28 -08:00
#include "Common/GraphicsContext.h"
#include "Common/System/OSD.h"
2020-10-04 10:04:01 +02:00
#include "Common/Profiler/Profiler.h"
#include "Common/Data/Text/I18n.h"
#include "Core/Debugger/Breakpoints.h"
#include "Core/MemMapHelpers.h"
#include "Core/MIPS/MIPS.h"
2013-08-17 11:23:51 +02:00
#include "Core/Config.h"
#include "Core/ConfigValues.h"
2013-08-17 11:23:51 +02:00
#include "Core/System.h"
#include "Common/GPU/D3D9/D3D9StateCache.h"
2013-08-17 11:23:51 +02:00
2013-08-25 13:56:29 +02:00
#include "GPU/GPUState.h"
#include "GPU/ge_constants.h"
#include "GPU/GeDisasm.h"
2013-08-17 11:23:51 +02:00
#include "GPU/Common/FramebufferManagerCommon.h"
#include "GPU/Directx9/ShaderManagerDX9.h"
#include "GPU/Directx9/GPU_DX9.h"
#include "GPU/Directx9/FramebufferManagerDX9.h"
#include "GPU/Directx9/DrawEngineDX9.h"
#include "GPU/Directx9/TextureCacheDX9.h"
2013-08-17 11:23:51 +02:00
GPU_DX9::GPU_DX9(GraphicsContext *gfxCtx, Draw::DrawContext *draw)
2023-02-25 14:24:59 +01:00
: GPUCommonHW(gfxCtx, draw),
2022-08-05 15:09:33 +02:00
drawEngine_(draw) {
device_ = (LPDIRECT3DDEVICE9)draw->GetNativeObject(Draw::NativeObject::DEVICE);
deviceEx_ = (LPDIRECT3DDEVICE9EX)draw->GetNativeObject(Draw::NativeObject::DEVICE_EX);
2013-08-17 11:23:51 +02:00
shaderManagerDX9_ = new ShaderManagerDX9(draw, device_);
framebufferManagerDX9_ = new FramebufferManagerDX9(draw);
framebufferManager_ = framebufferManagerDX9_;
textureCacheDX9_ = new TextureCacheDX9(draw, framebufferManager_->GetDraw2D());
textureCache_ = textureCacheDX9_;
drawEngineCommon_ = &drawEngine_;
shaderManager_ = shaderManagerDX9_;
drawEngine_.SetShaderManager(shaderManagerDX9_);
drawEngine_.SetTextureCache(textureCacheDX9_);
drawEngine_.SetFramebufferManager(framebufferManagerDX9_);
drawEngine_.Init();
framebufferManagerDX9_->SetTextureCache(textureCacheDX9_);
framebufferManagerDX9_->SetShaderManager(shaderManagerDX9_);
2017-02-04 11:47:19 +01:00
framebufferManagerDX9_->SetDrawEngine(&drawEngine_);
framebufferManagerDX9_->Init(msaaLevel_);
textureCacheDX9_->SetFramebufferManager(framebufferManagerDX9_);
textureCacheDX9_->SetShaderManager(shaderManagerDX9_);
2013-08-17 11:23:51 +02:00
// Sanity check gstate
if ((int *)&gstate.transferstart - (int *)&gstate != 0xEA) {
ERROR_LOG(Log::G3D, "gstate has drifted out of sync!");
2013-08-17 11:23:51 +02:00
}
// No need to flush before the tex scale/offset commands if we are baking
// the tex scale/offset into the vertices anyway.
UpdateCmdInfo();
2022-12-13 16:53:53 +01:00
gstate_c.SetUseFlags(CheckGPUFeatures());
2013-08-17 11:23:51 +02:00
BuildReportingInfo();
// Some of our defaults are different from hw defaults, let's assert them.
// We restore each frame anyway, but here is convenient for tests.
dxstate.Restore();
textureCache_->NotifyConfigChanged();
if (g_Config.bHardwareTessellation) {
// Disable hardware tessellation bacause DX9 is still unsupported.
ERROR_LOG(Log::G3D, "Hardware Tessellation is unsupported, falling back to software tessellation");
auto gr = GetI18NCategory(I18NCat::GRAPHICS);
// TODO: Badly formulated
g_OSD.Show(OSDType::MESSAGE_WARNING, gr->T("Turn off Hardware Tessellation - unsupported"));
}
2013-08-17 11:23:51 +02:00
}
u32 GPU_DX9::CheckGPUFeatures() const {
2023-02-25 16:12:24 +01:00
u32 features = GPUCommonHW::CheckGPUFeatures();
2022-10-17 08:30:27 +02:00
features |= GPU_USE_16BIT_FORMATS;
features |= GPU_USE_TEXTURE_LOD_CONTROL;
// Accurate depth is required because the Direct3D API does not support inverse Z.
// So we cannot incorrectly use the viewport transform as the depth range on Direct3D.
2022-10-17 08:30:27 +02:00
features |= GPU_USE_ACCURATE_DEPTH;
return CheckGPUFeaturesLate(features);
}
2023-02-26 11:05:52 +01:00
void GPU_DX9::DeviceLost() {
GPUCommonHW::DeviceLost();
}
void GPU_DX9::DeviceRestore(Draw::DrawContext *draw) {
GPUCommonHW::DeviceRestore(draw);
}
void GPU_DX9::ReapplyGfxState() {
dxstate.Restore();
2023-02-25 16:12:24 +01:00
GPUCommonHW::ReapplyGfxState();
}
void GPU_DX9::BeginHostFrame() {
GPUCommonHW::BeginHostFrame();
2023-02-25 15:59:35 +01:00
textureCache_->StartFrame();
drawEngine_.BeginFrame();
2013-08-17 11:23:51 +02:00
shaderManagerDX9_->DirtyLastShader();
2013-08-17 11:23:51 +02:00
framebufferManager_->BeginFrame();
2022-12-13 22:04:00 -08:00
if (gstate_c.useFlagsChanged) {
// TODO: It'd be better to recompile them in the background, probably?
// This most likely means that saw equal depth changed.
WARN_LOG(Log::G3D, "Shader use flags changed, clearing all shaders and depth buffers");
2023-02-25 15:59:35 +01:00
shaderManager_->ClearShaders();
framebufferManager_->ClearAllDepthBuffers();
2022-12-13 22:04:00 -08:00
gstate_c.useFlagsChanged = false;
}
2013-08-17 11:23:51 +02:00
}
void GPU_DX9::FinishDeferred() {
// This finishes reading any vertex data that is pending.
drawEngine_.FinishDeferred();
}
void GPU_DX9::GetStats(char *buffer, size_t bufsize) {
size_t offset = FormatGPUStatsCommon(buffer, bufsize);
buffer += offset;
bufsize -= offset;
if ((int)bufsize < 0)
return;
snprintf(buffer, bufsize,
"Vertex, Fragment shaders loaded: %i, %i\n",
shaderManagerDX9_->GetNumVertexShaders(),
shaderManagerDX9_->GetNumFragmentShaders()
);
2013-08-17 11:23:51 +02:00
}