2013-08-17 09:23:51 +00: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/.
|
|
|
|
|
2013-12-29 23:55:09 +00:00
|
|
|
#include <set>
|
|
|
|
|
2013-12-05 15:37:52 +00:00
|
|
|
#include "Common/ChunkFile.h"
|
2016-02-13 18:53:28 +00:00
|
|
|
#include "Common/GraphicsContext.h"
|
2016-02-13 17:51:09 +00:00
|
|
|
#include "base/NativeApp.h"
|
2013-12-05 15:37:52 +00:00
|
|
|
#include "base/logging.h"
|
2015-05-25 22:39:27 +00:00
|
|
|
#include "profiler/profiler.h"
|
2014-09-14 00:28:35 +00:00
|
|
|
#include "Core/Debugger/Breakpoints.h"
|
2015-04-06 01:03:50 +00:00
|
|
|
#include "Core/MemMapHelpers.h"
|
2014-09-14 00:28:35 +00:00
|
|
|
#include "Core/MIPS/MIPS.h"
|
2013-08-17 09:23:51 +00:00
|
|
|
#include "Core/Host.h"
|
|
|
|
#include "Core/Config.h"
|
|
|
|
#include "Core/Reporting.h"
|
|
|
|
#include "Core/System.h"
|
|
|
|
|
|
|
|
#include "helper/dx_state.h"
|
|
|
|
|
2013-08-25 11:56:29 +00:00
|
|
|
#include "GPU/GPUState.h"
|
|
|
|
#include "GPU/ge_constants.h"
|
|
|
|
#include "GPU/GeDisasm.h"
|
|
|
|
|
2014-09-09 15:12:42 +00:00
|
|
|
#include "GPU/Common/FramebufferCommon.h"
|
2013-09-16 06:22:10 +00:00
|
|
|
#include "GPU/Directx9/helper/global.h"
|
2013-09-15 10:46:14 +00:00
|
|
|
#include "GPU/Directx9/ShaderManagerDX9.h"
|
|
|
|
#include "GPU/Directx9/GPU_DX9.h"
|
|
|
|
#include "GPU/Directx9/FramebufferDX9.h"
|
2016-04-10 08:27:28 +00:00
|
|
|
#include "GPU/Directx9/DrawEngineDX9.h"
|
2013-09-15 10:46:14 +00:00
|
|
|
#include "GPU/Directx9/TextureCacheDX9.h"
|
2013-08-25 11:56:29 +00:00
|
|
|
|
|
|
|
#include "Core/HLE/sceKernelThread.h"
|
|
|
|
#include "Core/HLE/sceKernelInterrupt.h"
|
|
|
|
#include "Core/HLE/sceGe.h"
|
|
|
|
|
2013-09-15 15:53:21 +00:00
|
|
|
namespace DX9 {
|
|
|
|
|
2013-08-25 11:56:29 +00:00
|
|
|
enum {
|
|
|
|
FLAG_FLUSHBEFORE = 1,
|
|
|
|
FLAG_FLUSHBEFOREONCHANGE = 2,
|
|
|
|
FLAG_EXECUTE = 4, // needs to actually be executed. unused for now.
|
2014-09-13 10:11:34 +00:00
|
|
|
FLAG_EXECUTEONCHANGE = 8,
|
|
|
|
FLAG_READS_PC = 16,
|
|
|
|
FLAG_WRITES_PC = 32,
|
2017-01-23 22:15:54 +00:00
|
|
|
FLAG_DIRTYONCHANGE = 64, // NOTE: Either this or FLAG_EXECUTE*, not both!
|
2013-08-17 09:23:51 +00:00
|
|
|
};
|
|
|
|
|
2013-08-25 11:56:29 +00:00
|
|
|
struct CommandTableEntry {
|
2017-01-23 22:15:54 +00:00
|
|
|
uint8_t cmd;
|
|
|
|
uint8_t flags;
|
2017-01-24 11:53:42 +00:00
|
|
|
uint64_t dirty;
|
2016-04-10 08:21:48 +00:00
|
|
|
GPU_DX9::CmdFunc func;
|
2013-08-25 11:56:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const CommandTableEntry commandTable[] = {
|
|
|
|
// Changes that dirty the framebuffer
|
2017-01-24 12:13:09 +00:00
|
|
|
{ GE_CMD_FRAMEBUFPTR, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_FRAMEBUFWIDTH, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_FRAMEBUFPIXFORMAT, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS },
|
2013-08-25 11:56:29 +00:00
|
|
|
{GE_CMD_ZBUFPTR, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_ZBUFWIDTH, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
|
|
|
|
// Changes that dirty uniforms
|
2017-01-24 12:13:09 +00:00
|
|
|
{GE_CMD_FOGCOLOR, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FOGCOLOR},
|
|
|
|
{GE_CMD_FOG1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FOGCOEF},
|
|
|
|
{GE_CMD_FOG2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FOGCOEF},
|
2013-08-25 11:56:29 +00:00
|
|
|
|
2013-12-05 15:37:52 +00:00
|
|
|
// Should these maybe flush?
|
2017-01-24 11:53:42 +00:00
|
|
|
{GE_CMD_MINZ, FLAG_FLUSHBEFOREONCHANGE, DIRTY_DEPTHRANGE},
|
|
|
|
{GE_CMD_MAXZ, FLAG_FLUSHBEFOREONCHANGE, DIRTY_DEPTHRANGE},
|
2013-08-25 11:56:29 +00:00
|
|
|
|
|
|
|
// Changes that dirty texture scaling.
|
2017-01-24 12:13:09 +00:00
|
|
|
{ GE_CMD_TEXMAPMODE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_UVSCALEOFFSET },
|
2017-01-24 11:53:42 +00:00
|
|
|
{ GE_CMD_TEXSCALEU, FLAG_EXECUTEONCHANGE, DIRTY_UVSCALEOFFSET, &GPU_DX9::Execute_TexScaleU },
|
|
|
|
{ GE_CMD_TEXSCALEV, FLAG_EXECUTEONCHANGE, DIRTY_UVSCALEOFFSET, &GPU_DX9::Execute_TexScaleV },
|
|
|
|
{ GE_CMD_TEXOFFSETU, FLAG_EXECUTEONCHANGE, DIRTY_UVSCALEOFFSET, &GPU_DX9::Execute_TexOffsetU },
|
|
|
|
{ GE_CMD_TEXOFFSETV, FLAG_EXECUTEONCHANGE, DIRTY_UVSCALEOFFSET, &GPU_DX9::Execute_TexOffsetV },
|
2013-08-25 11:56:29 +00:00
|
|
|
|
2017-01-24 12:13:09 +00:00
|
|
|
// Changes that dirty the current texture.
|
|
|
|
{ GE_CMD_TEXSIZE0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTE, 0, &GPU_DX9::Execute_TexSize0 },
|
|
|
|
{ GE_CMD_TEXSIZE1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_TEXSIZE2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_TEXSIZE3, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_TEXSIZE4, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_TEXSIZE5, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_TEXSIZE6, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_TEXSIZE7, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_TEXFORMAT, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_IMAGE },
|
|
|
|
{ GE_CMD_TEXLEVEL, 0, DIRTY_TEXTURE_PARAMS }, // Flushing on this is EXPENSIVE in Gran Turismo and of little use
|
|
|
|
{ GE_CMD_TEXADDR0, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_IMAGE | DIRTY_UVSCALEOFFSET },
|
|
|
|
{ GE_CMD_TEXADDR1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_TEXADDR2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_TEXADDR3, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_TEXADDR4, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_TEXADDR5, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_TEXADDR6, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_TEXADDR7, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_TEXBUFWIDTH0, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_IMAGE },
|
|
|
|
{ GE_CMD_TEXBUFWIDTH1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_TEXBUFWIDTH2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_TEXBUFWIDTH3, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_TEXBUFWIDTH4, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_TEXBUFWIDTH5, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_TEXBUFWIDTH6, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_TEXBUFWIDTH7, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
|
|
|
// These must flush on change, so that LoadClut doesn't have to always flush.
|
|
|
|
{ GE_CMD_CLUTADDR, FLAG_FLUSHBEFOREONCHANGE },
|
|
|
|
{ GE_CMD_CLUTADDRUPPER, FLAG_FLUSHBEFOREONCHANGE },
|
|
|
|
{ GE_CMD_CLUTFORMAT, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
2013-08-25 11:56:29 +00:00
|
|
|
|
|
|
|
// These affect the fragment shader so need flushing.
|
|
|
|
{GE_CMD_CLEARMODE, FLAG_FLUSHBEFOREONCHANGE},
|
2014-09-13 10:11:34 +00:00
|
|
|
{GE_CMD_TEXTUREMAPENABLE, FLAG_FLUSHBEFOREONCHANGE},
|
2013-08-25 11:56:29 +00:00
|
|
|
{GE_CMD_FOGENABLE, FLAG_FLUSHBEFOREONCHANGE},
|
2017-01-24 12:13:09 +00:00
|
|
|
{GE_CMD_TEXMODE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS},
|
2013-08-25 11:56:29 +00:00
|
|
|
{GE_CMD_TEXSHADELS, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_SHADEMODE, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_TEXFUNC, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_COLORTEST, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_ALPHATESTENABLE, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_COLORTESTENABLE, FLAG_FLUSHBEFOREONCHANGE},
|
2017-01-24 12:13:09 +00:00
|
|
|
{GE_CMD_COLORTESTMASK, FLAG_FLUSHBEFOREONCHANGE, DIRTY_ALPHACOLORMASK},
|
2013-08-25 11:56:29 +00:00
|
|
|
|
|
|
|
// These change the vertex shader so need flushing.
|
2014-09-15 14:08:55 +00:00
|
|
|
{GE_CMD_REVERSENORMAL, FLAG_FLUSHBEFOREONCHANGE},
|
2013-08-25 11:56:29 +00:00
|
|
|
{GE_CMD_LIGHTINGENABLE, FLAG_FLUSHBEFOREONCHANGE},
|
2017-01-24 09:56:30 +00:00
|
|
|
{GE_CMD_LIGHTENABLE0, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_LIGHTENABLE1, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_LIGHTENABLE2, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_LIGHTENABLE3, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_LIGHTTYPE0, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_LIGHTTYPE1, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_LIGHTTYPE2, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_LIGHTTYPE3, FLAG_FLUSHBEFOREONCHANGE},
|
2013-08-25 11:56:29 +00:00
|
|
|
{GE_CMD_MATERIALUPDATE, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
|
|
|
|
// This changes both shaders so need flushing.
|
2017-01-24 12:13:09 +00:00
|
|
|
{ GE_CMD_LIGHTMODE, FLAG_FLUSHBEFOREONCHANGE },
|
|
|
|
{ GE_CMD_TEXFILTER, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_TEXWRAP, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
2013-08-25 11:56:29 +00:00
|
|
|
|
|
|
|
// Uniform changes
|
2017-01-24 12:13:09 +00:00
|
|
|
{ GE_CMD_ALPHATEST, FLAG_FLUSHBEFOREONCHANGE, DIRTY_ALPHACOLORREF | DIRTY_ALPHACOLORMASK },
|
|
|
|
{ GE_CMD_COLORREF, FLAG_FLUSHBEFOREONCHANGE, DIRTY_ALPHACOLORREF },
|
|
|
|
{ GE_CMD_TEXENVCOLOR, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXENV },
|
2013-08-25 11:56:29 +00:00
|
|
|
|
|
|
|
// Simple render state changes. Handled in StateMapping.cpp.
|
2013-12-05 15:37:52 +00:00
|
|
|
{GE_CMD_OFFSETX, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_OFFSETY, FLAG_FLUSHBEFOREONCHANGE},
|
2013-08-25 11:56:29 +00:00
|
|
|
{GE_CMD_CULL, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_CULLFACEENABLE, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_DITHERENABLE, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_STENCILOP, FLAG_FLUSHBEFOREONCHANGE},
|
2017-01-24 12:13:09 +00:00
|
|
|
{GE_CMD_STENCILTEST, FLAG_FLUSHBEFOREONCHANGE, DIRTY_STENCILREPLACEVALUE},
|
2013-08-25 11:56:29 +00:00
|
|
|
{GE_CMD_STENCILTESTENABLE, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_ALPHABLENDENABLE, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_BLENDMODE, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_BLENDFIXEDA, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_BLENDFIXEDB, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_MASKRGB, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_MASKALPHA, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_ZTEST, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_ZTESTENABLE, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_ZWRITEDISABLE, FLAG_FLUSHBEFOREONCHANGE},
|
2014-09-13 10:11:34 +00:00
|
|
|
|
|
|
|
// These can't be emulated in D3D (except a few special cases)
|
2013-08-25 11:56:29 +00:00
|
|
|
{GE_CMD_LOGICOP, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_LOGICOPENABLE, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
|
|
|
|
// Can probably ignore this one as we don't support AA lines.
|
|
|
|
{GE_CMD_ANTIALIASENABLE, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
|
|
|
|
// Morph weights. TODO: Remove precomputation?
|
2017-01-24 09:44:02 +00:00
|
|
|
{GE_CMD_MORPHWEIGHT0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, 0, &GPUCommon::Execute_MorphWeight},
|
|
|
|
{GE_CMD_MORPHWEIGHT1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, 0, &GPUCommon::Execute_MorphWeight},
|
|
|
|
{GE_CMD_MORPHWEIGHT2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, 0, &GPUCommon::Execute_MorphWeight},
|
|
|
|
{GE_CMD_MORPHWEIGHT3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, 0, &GPUCommon::Execute_MorphWeight},
|
|
|
|
{GE_CMD_MORPHWEIGHT4, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, 0, &GPUCommon::Execute_MorphWeight},
|
|
|
|
{GE_CMD_MORPHWEIGHT5, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, 0, &GPUCommon::Execute_MorphWeight},
|
|
|
|
{GE_CMD_MORPHWEIGHT6, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, 0, &GPUCommon::Execute_MorphWeight},
|
|
|
|
{GE_CMD_MORPHWEIGHT7, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, 0, &GPUCommon::Execute_MorphWeight},
|
2013-08-25 11:56:29 +00:00
|
|
|
|
|
|
|
// Control spline/bezier patches. Don't really require flushing as such, but meh.
|
|
|
|
{GE_CMD_PATCHDIVISION, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_PATCHPRIMITIVE, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_PATCHFACING, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
{GE_CMD_PATCHCULLENABLE, FLAG_FLUSHBEFOREONCHANGE},
|
|
|
|
|
|
|
|
// Viewport.
|
2017-01-24 12:13:09 +00:00
|
|
|
{ GE_CMD_VIEWPORTXSCALE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_VIEWPORTYSCALE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_VIEWPORTXCENTER, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_VIEWPORTYCENTER, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_VIEWPORTZSCALE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS | DIRTY_DEPTHRANGE | DIRTY_PROJMATRIX },
|
|
|
|
{ GE_CMD_VIEWPORTZCENTER, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS | DIRTY_DEPTHRANGE | DIRTY_PROJMATRIX },
|
2013-08-25 11:56:29 +00:00
|
|
|
|
2013-12-05 15:37:52 +00:00
|
|
|
// Region
|
2017-01-24 12:13:09 +00:00
|
|
|
{ GE_CMD_REGION1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_REGION2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS },
|
2013-12-05 15:37:52 +00:00
|
|
|
|
|
|
|
// Scissor
|
2017-01-24 12:13:09 +00:00
|
|
|
{ GE_CMD_SCISSOR1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS },
|
|
|
|
{ GE_CMD_SCISSOR2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS },
|
2013-08-25 11:56:29 +00:00
|
|
|
|
2017-01-24 11:53:42 +00:00
|
|
|
// Lighting base colors
|
2017-01-24 12:13:09 +00:00
|
|
|
{ GE_CMD_AMBIENTCOLOR, FLAG_FLUSHBEFOREONCHANGE, DIRTY_AMBIENT },
|
|
|
|
{ GE_CMD_AMBIENTALPHA, FLAG_FLUSHBEFOREONCHANGE, DIRTY_AMBIENT },
|
|
|
|
{ GE_CMD_MATERIALDIFFUSE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_MATDIFFUSE },
|
|
|
|
{ GE_CMD_MATERIALEMISSIVE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_MATEMISSIVE },
|
|
|
|
{ GE_CMD_MATERIALAMBIENT, FLAG_FLUSHBEFOREONCHANGE, DIRTY_MATAMBIENTALPHA },
|
|
|
|
{ GE_CMD_MATERIALALPHA, FLAG_FLUSHBEFOREONCHANGE, DIRTY_MATAMBIENTALPHA },
|
|
|
|
{ GE_CMD_MATERIALSPECULAR, FLAG_FLUSHBEFOREONCHANGE, DIRTY_MATSPECULAR },
|
|
|
|
{ GE_CMD_MATERIALSPECULARCOEF, FLAG_FLUSHBEFOREONCHANGE, DIRTY_MATSPECULAR },
|
2017-01-24 09:56:30 +00:00
|
|
|
|
2017-01-24 11:53:42 +00:00
|
|
|
// Light parameters
|
2017-01-24 12:13:09 +00:00
|
|
|
{GE_CMD_LX0, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT0},
|
|
|
|
{GE_CMD_LY0, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT0},
|
|
|
|
{GE_CMD_LZ0, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT0},
|
|
|
|
{GE_CMD_LX1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT1},
|
|
|
|
{GE_CMD_LY1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT1},
|
|
|
|
{GE_CMD_LZ1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT1},
|
|
|
|
{GE_CMD_LX2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT2},
|
|
|
|
{GE_CMD_LY2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT2},
|
|
|
|
{GE_CMD_LZ2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT2},
|
|
|
|
{GE_CMD_LX3, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT3},
|
|
|
|
{GE_CMD_LY3, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT3},
|
|
|
|
{GE_CMD_LZ3, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT3},
|
|
|
|
|
|
|
|
{GE_CMD_LDX0, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT0},
|
|
|
|
{GE_CMD_LDY0, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT0},
|
|
|
|
{GE_CMD_LDZ0, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT0},
|
|
|
|
{GE_CMD_LDX1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT1},
|
|
|
|
{GE_CMD_LDY1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT1},
|
|
|
|
{GE_CMD_LDZ1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT1},
|
|
|
|
{GE_CMD_LDX2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT2},
|
|
|
|
{GE_CMD_LDY2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT2},
|
|
|
|
{GE_CMD_LDZ2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT2},
|
|
|
|
{GE_CMD_LDX3, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT3},
|
|
|
|
{GE_CMD_LDY3, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT3},
|
|
|
|
{GE_CMD_LDZ3, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT3},
|
|
|
|
|
|
|
|
{GE_CMD_LKA0, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT0},
|
|
|
|
{GE_CMD_LKB0, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT0},
|
|
|
|
{GE_CMD_LKC0, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT0},
|
|
|
|
{GE_CMD_LKA1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT1},
|
|
|
|
{GE_CMD_LKB1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT1},
|
|
|
|
{GE_CMD_LKC1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT1},
|
|
|
|
{GE_CMD_LKA2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT2},
|
|
|
|
{GE_CMD_LKB2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT2},
|
|
|
|
{GE_CMD_LKC2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT2},
|
|
|
|
{GE_CMD_LKA3, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT3},
|
|
|
|
{GE_CMD_LKB3, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT3},
|
|
|
|
{GE_CMD_LKC3, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT3},
|
|
|
|
|
|
|
|
{GE_CMD_LKS0, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT0},
|
|
|
|
{GE_CMD_LKS1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT1},
|
|
|
|
{GE_CMD_LKS2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT2},
|
|
|
|
{GE_CMD_LKS3, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT3},
|
|
|
|
|
|
|
|
{GE_CMD_LKO0, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT0},
|
|
|
|
{GE_CMD_LKO1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT1},
|
|
|
|
{GE_CMD_LKO2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT2},
|
|
|
|
{GE_CMD_LKO3, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT3},
|
|
|
|
|
|
|
|
{GE_CMD_LAC0, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT0},
|
|
|
|
{GE_CMD_LDC0, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT0},
|
|
|
|
{GE_CMD_LSC0, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT0},
|
|
|
|
{GE_CMD_LAC1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT1},
|
|
|
|
{GE_CMD_LDC1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT1},
|
|
|
|
{GE_CMD_LSC1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT1},
|
|
|
|
{GE_CMD_LAC2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT2},
|
|
|
|
{GE_CMD_LDC2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT2},
|
|
|
|
{GE_CMD_LSC2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT2},
|
|
|
|
{GE_CMD_LAC3, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT3},
|
|
|
|
{GE_CMD_LDC3, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT3},
|
|
|
|
{GE_CMD_LSC3, FLAG_FLUSHBEFOREONCHANGE, DIRTY_LIGHT3},
|
2013-08-25 11:56:29 +00:00
|
|
|
|
|
|
|
// Ignored commands
|
2017-01-24 13:26:49 +00:00
|
|
|
{GE_CMD_CLIPENABLE, 0},
|
2013-08-25 11:56:29 +00:00
|
|
|
{GE_CMD_TEXFLUSH, 0},
|
|
|
|
{GE_CMD_TEXLODSLOPE, 0},
|
|
|
|
{GE_CMD_TEXSYNC, 0},
|
|
|
|
|
|
|
|
// These are just nop or part of other later commands.
|
|
|
|
{GE_CMD_NOP, 0},
|
|
|
|
{GE_CMD_BASE, 0},
|
|
|
|
{GE_CMD_TRANSFERSRC, 0},
|
|
|
|
{GE_CMD_TRANSFERSRCW, 0},
|
|
|
|
{GE_CMD_TRANSFERDST, 0},
|
|
|
|
{GE_CMD_TRANSFERDSTW, 0},
|
|
|
|
{GE_CMD_TRANSFERSRCPOS, 0},
|
|
|
|
{GE_CMD_TRANSFERDSTPOS, 0},
|
|
|
|
{GE_CMD_TRANSFERSIZE, 0},
|
|
|
|
|
|
|
|
// From Common. No flushing but definitely need execute.
|
2017-01-24 09:56:30 +00:00
|
|
|
{GE_CMD_OFFSETADDR, FLAG_EXECUTE, 0, &GPU_DX9::Execute_OffsetAddr},
|
|
|
|
{GE_CMD_ORIGIN, FLAG_EXECUTE | FLAG_READS_PC, 0, &GPU_DX9::Execute_Origin}, // Really?
|
|
|
|
{GE_CMD_PRIM, FLAG_EXECUTE, 0, &GPU_DX9::Execute_Prim},
|
|
|
|
{GE_CMD_JUMP, FLAG_EXECUTE | FLAG_READS_PC | FLAG_WRITES_PC, 0, &GPU_DX9::Execute_Jump},
|
|
|
|
{GE_CMD_CALL, FLAG_EXECUTE | FLAG_READS_PC | FLAG_WRITES_PC, 0, &GPU_DX9::Execute_Call},
|
|
|
|
{GE_CMD_RET, FLAG_EXECUTE | FLAG_READS_PC | FLAG_WRITES_PC, 0, &GPU_DX9::Execute_Ret},
|
|
|
|
{GE_CMD_END, FLAG_FLUSHBEFORE | FLAG_EXECUTE | FLAG_READS_PC | FLAG_WRITES_PC, 0, &GPU_DX9::Execute_End},
|
2017-01-23 22:15:54 +00:00
|
|
|
{GE_CMD_VADDR, FLAG_EXECUTE, 0, &GPU_DX9::Execute_Vaddr},
|
|
|
|
{GE_CMD_IADDR, FLAG_EXECUTE, 0, &GPU_DX9::Execute_Iaddr},
|
2017-01-24 09:56:30 +00:00
|
|
|
{GE_CMD_BJUMP, FLAG_EXECUTE | FLAG_READS_PC | FLAG_WRITES_PC, 0, &GPU_DX9::Execute_BJump}, // EXECUTE
|
2017-01-23 22:15:54 +00:00
|
|
|
{GE_CMD_BOUNDINGBOX, FLAG_EXECUTE, 0, &GPU_DX9::Execute_BoundingBox}, // + FLUSHBEFORE when we implement... or not, do we need to?
|
2013-08-25 11:56:29 +00:00
|
|
|
|
|
|
|
// Changing the vertex type requires us to flush.
|
2017-01-23 22:15:54 +00:00
|
|
|
{GE_CMD_VERTEXTYPE, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, 0, &GPU_DX9::Execute_VertexType},
|
2013-08-25 11:56:29 +00:00
|
|
|
|
2017-01-23 22:15:54 +00:00
|
|
|
{GE_CMD_BEZIER, FLAG_FLUSHBEFORE | FLAG_EXECUTE, 0, &GPU_DX9::Execute_Bezier},
|
|
|
|
{GE_CMD_SPLINE, FLAG_FLUSHBEFORE | FLAG_EXECUTE, 0, &GPU_DX9::Execute_Spline},
|
2013-08-25 11:56:29 +00:00
|
|
|
|
|
|
|
// These two are actually processed in CMD_END.
|
|
|
|
{GE_CMD_SIGNAL, FLAG_FLUSHBEFORE},
|
|
|
|
{GE_CMD_FINISH, FLAG_FLUSHBEFORE},
|
|
|
|
|
|
|
|
// Changes that trigger data copies. Only flushing on change for LOADCLUT must be a bit of a hack...
|
2017-01-23 22:15:54 +00:00
|
|
|
{GE_CMD_LOADCLUT, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTE, 0, &GPU_DX9::Execute_LoadClut},
|
|
|
|
{GE_CMD_TRANSFERSTART, FLAG_FLUSHBEFORE | FLAG_EXECUTE | FLAG_READS_PC, 0, &GPUCommon::Execute_BlockTransferStart},
|
2013-08-25 11:56:29 +00:00
|
|
|
|
|
|
|
// We don't use the dither table.
|
|
|
|
{GE_CMD_DITH0},
|
|
|
|
{GE_CMD_DITH1},
|
|
|
|
{GE_CMD_DITH2},
|
|
|
|
{GE_CMD_DITH3},
|
|
|
|
|
2013-08-17 09:23:51 +00:00
|
|
|
// These handle their own flushing.
|
2017-01-23 22:15:54 +00:00
|
|
|
{GE_CMD_WORLDMATRIXNUMBER, FLAG_EXECUTE | FLAG_READS_PC | FLAG_WRITES_PC, 0, &GPUCommon::Execute_WorldMtxNum},
|
|
|
|
{GE_CMD_WORLDMATRIXDATA, FLAG_EXECUTE, 0, &GPUCommon::Execute_WorldMtxData},
|
|
|
|
{GE_CMD_VIEWMATRIXNUMBER, FLAG_EXECUTE | FLAG_READS_PC | FLAG_WRITES_PC, 0, &GPUCommon::Execute_ViewMtxNum},
|
|
|
|
{GE_CMD_VIEWMATRIXDATA, FLAG_EXECUTE, 0, &GPUCommon::Execute_ViewMtxData},
|
|
|
|
{GE_CMD_PROJMATRIXNUMBER, FLAG_EXECUTE | FLAG_READS_PC | FLAG_WRITES_PC, 0, &GPUCommon::Execute_ProjMtxNum},
|
|
|
|
{GE_CMD_PROJMATRIXDATA, FLAG_EXECUTE, 0, &GPUCommon::Execute_ProjMtxData},
|
|
|
|
{GE_CMD_TGENMATRIXNUMBER, FLAG_EXECUTE | FLAG_READS_PC | FLAG_WRITES_PC, 0, &GPUCommon::Execute_TgenMtxNum},
|
|
|
|
{GE_CMD_TGENMATRIXDATA, FLAG_EXECUTE, 0, &GPUCommon::Execute_TgenMtxData},
|
|
|
|
{GE_CMD_BONEMATRIXNUMBER, FLAG_EXECUTE | FLAG_READS_PC | FLAG_WRITES_PC, 0, &GPUCommon::Execute_BoneMtxNum},
|
|
|
|
{GE_CMD_BONEMATRIXDATA, FLAG_EXECUTE, 0, &GPUCommon::Execute_BoneMtxData},
|
2013-08-25 11:56:29 +00:00
|
|
|
|
2013-12-05 15:37:52 +00:00
|
|
|
// Vertex Screen/Texture/Color
|
2017-01-24 09:56:30 +00:00
|
|
|
{ GE_CMD_VSCX, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{ GE_CMD_VSCY, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{ GE_CMD_VSCZ, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{ GE_CMD_VTCS, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{ GE_CMD_VTCT, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{ GE_CMD_VTCQ, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{ GE_CMD_VCV, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{ GE_CMD_VAP, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{ GE_CMD_VFC, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{ GE_CMD_VSCV, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
2013-12-05 15:37:52 +00:00
|
|
|
|
2013-08-25 11:56:29 +00:00
|
|
|
// "Missing" commands (gaps in the sequence)
|
2017-01-24 09:56:30 +00:00
|
|
|
{GE_CMD_UNKNOWN_03, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{GE_CMD_UNKNOWN_0D, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{GE_CMD_UNKNOWN_11, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{GE_CMD_UNKNOWN_29, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{GE_CMD_UNKNOWN_34, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{GE_CMD_UNKNOWN_35, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{GE_CMD_UNKNOWN_39, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{GE_CMD_UNKNOWN_4E, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{GE_CMD_UNKNOWN_4F, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{GE_CMD_UNKNOWN_52, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{GE_CMD_UNKNOWN_59, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{GE_CMD_UNKNOWN_5A, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{GE_CMD_UNKNOWN_B6, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{GE_CMD_UNKNOWN_B7, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{GE_CMD_UNKNOWN_D1, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{GE_CMD_UNKNOWN_ED, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{GE_CMD_UNKNOWN_EF, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{GE_CMD_UNKNOWN_FA, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{GE_CMD_UNKNOWN_FB, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{GE_CMD_UNKNOWN_FC, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{GE_CMD_UNKNOWN_FD, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
|
|
|
{GE_CMD_UNKNOWN_FE, FLAG_EXECUTE, 0, &GPUCommon::Execute_Unknown},
|
2014-09-13 10:11:34 +00:00
|
|
|
// Appears to be debugging related or something? Hit a lot in GoW.
|
|
|
|
{ GE_CMD_UNKNOWN_FF, 0 },
|
2013-08-17 09:23:51 +00:00
|
|
|
};
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
GPU_DX9::CommandInfo GPU_DX9::cmdInfo_[256];
|
2014-09-13 10:11:34 +00:00
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
GPU_DX9::GPU_DX9(GraphicsContext *gfxCtx)
|
2016-12-21 17:13:58 +00:00
|
|
|
: gfxCtx_(gfxCtx) {
|
2013-09-10 20:35:38 +00:00
|
|
|
lastVsync_ = g_Config.bVSync ? 1 : 0;
|
2013-08-17 09:23:51 +00:00
|
|
|
dxstate.SetVSyncInterval(g_Config.bVSync);
|
|
|
|
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerDX9_ = new ShaderManagerDX9();
|
2016-12-21 17:07:17 +00:00
|
|
|
framebufferManagerDX9_ = new FramebufferManagerDX9();
|
|
|
|
framebufferManager_ = framebufferManagerDX9_;
|
2016-12-21 17:51:19 +00:00
|
|
|
textureCacheDX9_ = new TextureCacheDX9();
|
|
|
|
textureCache_ = textureCacheDX9_;
|
2017-01-21 19:42:40 +00:00
|
|
|
drawEngineCommon_ = &drawEngine_;
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManager_ = shaderManagerDX9_;
|
2016-12-21 17:07:17 +00:00
|
|
|
|
2017-01-23 19:48:23 +00:00
|
|
|
drawEngine_.SetShaderManager(shaderManagerDX9_);
|
2016-12-21 17:51:19 +00:00
|
|
|
drawEngine_.SetTextureCache(textureCacheDX9_);
|
2016-12-21 17:07:17 +00:00
|
|
|
drawEngine_.SetFramebufferManager(framebufferManagerDX9_);
|
|
|
|
framebufferManagerDX9_->Init();
|
2016-12-21 17:51:19 +00:00
|
|
|
framebufferManagerDX9_->SetTextureCache(textureCacheDX9_);
|
2017-01-23 19:48:23 +00:00
|
|
|
framebufferManagerDX9_->SetShaderManager(shaderManagerDX9_);
|
2016-12-21 17:07:17 +00:00
|
|
|
framebufferManagerDX9_->SetTransformDrawEngine(&drawEngine_);
|
2016-12-21 17:51:19 +00:00
|
|
|
textureCacheDX9_->SetFramebufferManager(framebufferManagerDX9_);
|
|
|
|
textureCacheDX9_->SetDepalShaderCache(&depalShaderCache_);
|
2017-01-23 19:48:23 +00:00
|
|
|
textureCacheDX9_->SetShaderManager(shaderManagerDX9_);
|
2013-08-17 09:23:51 +00:00
|
|
|
|
|
|
|
// Sanity check gstate
|
|
|
|
if ((int *)&gstate.transferstart - (int *)&gstate != 0xEA) {
|
|
|
|
ERROR_LOG(G3D, "gstate has drifted out of sync!");
|
|
|
|
}
|
|
|
|
|
2014-09-13 10:11:34 +00:00
|
|
|
// Sanity check cmdInfo_ table - no dupes please
|
2013-08-25 11:56:29 +00:00
|
|
|
std::set<u8> dupeCheck;
|
2014-09-13 10:11:34 +00:00
|
|
|
memset(cmdInfo_, 0, sizeof(cmdInfo_));
|
2013-08-25 11:56:29 +00:00
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(commandTable); i++) {
|
2014-09-13 10:11:34 +00:00
|
|
|
const u8 cmd = commandTable[i].cmd;
|
2013-08-25 11:56:29 +00:00
|
|
|
if (dupeCheck.find(cmd) != dupeCheck.end()) {
|
|
|
|
ERROR_LOG(G3D, "Command table Dupe: %02x (%i)", (int)cmd, (int)cmd);
|
|
|
|
} else {
|
|
|
|
dupeCheck.insert(cmd);
|
|
|
|
}
|
2017-01-24 11:53:42 +00:00
|
|
|
cmdInfo_[cmd].flags |= (uint64_t)commandTable[i].flags | (commandTable[i].dirty << 8);
|
2014-09-13 10:11:34 +00:00
|
|
|
cmdInfo_[cmd].func = commandTable[i].func;
|
2017-01-24 09:56:30 +00:00
|
|
|
if ((cmdInfo_[cmd].flags & (FLAG_EXECUTE | FLAG_EXECUTEONCHANGE)) && !cmdInfo_[cmd].func) {
|
|
|
|
Crash();
|
2014-09-13 10:11:34 +00:00
|
|
|
}
|
2013-08-25 11:56:29 +00:00
|
|
|
}
|
|
|
|
// Find commands missing from the table.
|
|
|
|
for (int i = 0; i < 0xEF; i++) {
|
|
|
|
if (dupeCheck.find((u8)i) == dupeCheck.end()) {
|
|
|
|
ERROR_LOG(G3D, "Command missing from table: %02x (%i)", i, i);
|
2013-09-17 08:27:42 +00:00
|
|
|
}
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
2013-12-05 15:37:52 +00:00
|
|
|
// No need to flush before the tex scale/offset commands if we are baking
|
|
|
|
// the tex scale/offset into the vertices anyway.
|
2014-09-13 10:11:34 +00:00
|
|
|
UpdateCmdInfo();
|
2013-12-05 15:37:52 +00:00
|
|
|
|
2014-09-13 10:11:34 +00:00
|
|
|
BuildReportingInfo();
|
2014-12-30 23:26:16 +00:00
|
|
|
|
|
|
|
// 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();
|
2016-12-21 17:51:19 +00:00
|
|
|
textureCache_->NotifyConfigChanged();
|
2014-09-13 10:11:34 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::UpdateCmdInfo() {
|
2014-09-13 10:11:34 +00:00
|
|
|
if (g_Config.bSoftwareSkinning) {
|
|
|
|
cmdInfo_[GE_CMD_VERTEXTYPE].flags &= ~FLAG_FLUSHBEFOREONCHANGE;
|
2016-04-10 08:21:48 +00:00
|
|
|
cmdInfo_[GE_CMD_VERTEXTYPE].func = &GPU_DX9::Execute_VertexTypeSkinning;
|
2014-09-13 10:11:34 +00:00
|
|
|
} else {
|
|
|
|
cmdInfo_[GE_CMD_VERTEXTYPE].flags |= FLAG_FLUSHBEFOREONCHANGE;
|
2016-04-10 08:21:48 +00:00
|
|
|
cmdInfo_[GE_CMD_VERTEXTYPE].func = &GPU_DX9::Execute_VertexType;
|
2014-09-13 10:11:34 +00:00
|
|
|
}
|
2015-09-26 14:01:16 +00:00
|
|
|
|
2015-11-05 21:02:06 +00:00
|
|
|
CheckGPUFeatures();
|
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::CheckGPUFeatures() {
|
2015-09-26 14:01:16 +00:00
|
|
|
u32 features = 0;
|
|
|
|
|
|
|
|
features |= GPU_SUPPORTS_BLEND_MINMAX;
|
|
|
|
features |= GPU_SUPPORTS_TEXTURE_LOD_CONTROL;
|
2016-01-05 04:40:07 +00:00
|
|
|
features |= GPU_PREFER_CPU_DOWNLOAD;
|
2016-02-07 04:18:50 +00:00
|
|
|
features |= GPU_SUPPORTS_ACCURATE_DEPTH;
|
2015-09-26 14:01:16 +00:00
|
|
|
|
2016-03-18 04:56:04 +00:00
|
|
|
D3DCAPS9 caps;
|
|
|
|
ZeroMemory(&caps, sizeof(caps));
|
|
|
|
HRESULT result = 0;
|
|
|
|
if (pD3DdeviceEx) {
|
|
|
|
result = pD3DdeviceEx->GetDeviceCaps(&caps);
|
|
|
|
} else {
|
|
|
|
result = pD3Ddevice->GetDeviceCaps(&caps);
|
|
|
|
}
|
|
|
|
if (FAILED(result)) {
|
|
|
|
WARN_LOG_REPORT(G3D, "Direct3D9: Failed to get the device caps!");
|
|
|
|
} else {
|
|
|
|
if ((caps.RasterCaps & D3DPRASTERCAPS_ANISOTROPY) != 0 && caps.MaxAnisotropy > 1)
|
|
|
|
features |= GPU_SUPPORTS_ANISOTROPY;
|
|
|
|
if ((caps.TextureCaps & (D3DPTEXTURECAPS_NONPOW2CONDITIONAL | D3DPTEXTURECAPS_POW2)) == 0)
|
|
|
|
features |= GPU_SUPPORTS_OES_TEXTURE_NPOT;
|
|
|
|
}
|
|
|
|
|
2016-01-21 06:00:07 +00:00
|
|
|
if (!g_Config.bHighQualityDepth) {
|
|
|
|
features |= GPU_SCALE_DEPTH_FROM_24BIT_TO_16BIT;
|
2016-01-21 06:02:07 +00:00
|
|
|
} else if (PSP_CoreParameter().compat.flags().PixelDepthRounding) {
|
|
|
|
// Assume we always have a 24-bit depth buffer.
|
|
|
|
features |= GPU_SCALE_DEPTH_FROM_24BIT_TO_16BIT;
|
2016-01-21 06:00:07 +00:00
|
|
|
} else if (PSP_CoreParameter().compat.flags().VertexDepthRounding) {
|
2015-09-26 14:01:16 +00:00
|
|
|
features |= GPU_ROUND_DEPTH_TO_16BIT;
|
2015-11-05 21:02:06 +00:00
|
|
|
}
|
|
|
|
|
2015-09-26 14:01:16 +00:00
|
|
|
gstate_c.featureFlags = features;
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
GPU_DX9::~GPU_DX9() {
|
2016-12-21 17:07:17 +00:00
|
|
|
framebufferManagerDX9_->DestroyAllFBOs(true);
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerDX9_->ClearCache(true);
|
|
|
|
delete shaderManagerDX9_;
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Needs to be called on GPU thread, not reporting thread.
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::BuildReportingInfo() {
|
2016-12-25 17:18:19 +00:00
|
|
|
using namespace Draw;
|
2016-12-25 20:01:57 +00:00
|
|
|
DrawContext *thin3d = gfxCtx_->CreateThin3DContext();
|
2016-02-13 17:51:09 +00:00
|
|
|
|
2016-12-25 17:52:05 +00:00
|
|
|
reportingPrimaryInfo_ = thin3d->GetInfoString(InfoField::VENDORSTRING);
|
|
|
|
reportingFullInfo_ = reportingPrimaryInfo_ + " - " + System_GetProperty(SYSPROP_GPUDRIVER_VERSION) + " - " + thin3d->GetInfoString(InfoField::SHADELANGVERSION);
|
2016-02-13 18:53:28 +00:00
|
|
|
|
|
|
|
thin3d->Release();
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::DeviceLost() {
|
2013-08-17 09:23:51 +00:00
|
|
|
// Simply drop all caches and textures.
|
2013-08-19 18:36:43 +00:00
|
|
|
// FBOs appear to survive? Or no?
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerDX9_->ClearCache(false);
|
2016-12-21 17:51:19 +00:00
|
|
|
textureCacheDX9_->Clear(false);
|
2016-12-21 17:07:17 +00:00
|
|
|
framebufferManagerDX9_->DeviceLost();
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
2016-09-11 03:29:58 +00:00
|
|
|
void GPU_DX9::DeviceRestore() {
|
|
|
|
// Nothing needed.
|
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::InitClearInternal() {
|
2013-09-10 20:35:38 +00:00
|
|
|
bool useNonBufferedRendering = g_Config.iRenderingMode == FB_NON_BUFFERED_MODE;
|
|
|
|
if (useNonBufferedRendering) {
|
2013-08-17 09:23:51 +00:00
|
|
|
dxstate.depthWrite.set(true);
|
|
|
|
dxstate.colorMask.set(true, true, true, true);
|
2014-08-24 07:56:01 +00:00
|
|
|
pD3Ddevice->Clear(0, NULL, D3DCLEAR_STENCIL|D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.f, 0);
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::DumpNextFrame() {
|
2013-08-17 09:23:51 +00:00
|
|
|
dumpNextFrame_ = true;
|
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::BeginFrame() {
|
2013-08-19 18:36:43 +00:00
|
|
|
ScheduleEvent(GPU_EVENT_BEGIN_FRAME);
|
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::ReapplyGfxStateInternal() {
|
2015-11-12 13:47:43 +00:00
|
|
|
dxstate.Restore();
|
2015-09-06 10:23:14 +00:00
|
|
|
GPUCommon::ReapplyGfxStateInternal();
|
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::BeginFrameInternal() {
|
2014-09-13 10:11:34 +00:00
|
|
|
if (resized_) {
|
|
|
|
UpdateCmdInfo();
|
2016-04-10 08:21:48 +00:00
|
|
|
drawEngine_.Resized();
|
2016-12-21 17:51:19 +00:00
|
|
|
textureCacheDX9_->NotifyConfigChanged();
|
2014-09-13 10:11:34 +00:00
|
|
|
resized_ = false;
|
|
|
|
}
|
|
|
|
|
2013-08-17 09:23:51 +00:00
|
|
|
// Turn off vsync when unthrottled
|
2013-09-10 20:35:38 +00:00
|
|
|
int desiredVSyncInterval = g_Config.bVSync ? 1 : 0;
|
|
|
|
if ((PSP_CoreParameter().unthrottle) || (PSP_CoreParameter().fpsLimit == 1))
|
2013-08-17 09:23:51 +00:00
|
|
|
desiredVSyncInterval = 0;
|
|
|
|
if (desiredVSyncInterval != lastVsync_) {
|
|
|
|
dxstate.SetVSyncInterval(desiredVSyncInterval);
|
|
|
|
lastVsync_ = desiredVSyncInterval;
|
|
|
|
}
|
|
|
|
|
2016-12-21 17:51:19 +00:00
|
|
|
textureCacheDX9_->StartFrame();
|
2016-04-10 08:21:48 +00:00
|
|
|
drawEngine_.DecimateTrackedVertexArrays();
|
2014-09-17 21:26:20 +00:00
|
|
|
depalShaderCache_.Decimate();
|
2014-09-13 10:11:34 +00:00
|
|
|
// fragmentTestCache_.Decimate();
|
2013-08-17 09:23:51 +00:00
|
|
|
|
|
|
|
if (dumpNextFrame_) {
|
|
|
|
NOTICE_LOG(G3D, "DUMPING THIS FRAME");
|
|
|
|
dumpThisFrame_ = true;
|
|
|
|
dumpNextFrame_ = false;
|
|
|
|
} else if (dumpThisFrame_) {
|
|
|
|
dumpThisFrame_ = false;
|
|
|
|
}
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerDX9_->DirtyShader();
|
2013-08-17 09:23:51 +00:00
|
|
|
|
2016-12-21 17:07:17 +00:00
|
|
|
framebufferManagerDX9_->BeginFrame();
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat format) {
|
2013-09-22 07:18:46 +00:00
|
|
|
host->GPUNotifyDisplay(framebuf, stride, format);
|
2016-12-21 17:07:17 +00:00
|
|
|
framebufferManagerDX9_->SetDisplayFramebuffer(framebuf, stride, format);
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
bool GPU_DX9::FramebufferDirty() {
|
2013-08-19 18:36:43 +00:00
|
|
|
// FIXME: Workaround for displaylists sometimes hanging unprocessed. Not yet sure of the cause.
|
2014-12-21 00:11:19 +00:00
|
|
|
if (ThreadEnabled()) {
|
2013-08-19 18:36:43 +00:00
|
|
|
// FIXME: Workaround for displaylists sometimes hanging unprocessed. Not yet sure of the cause.
|
|
|
|
ScheduleEvent(GPU_EVENT_PROCESS_QUEUE);
|
|
|
|
// Allow it to process fully before deciding if it's dirty.
|
|
|
|
SyncThread();
|
|
|
|
}
|
2016-12-21 17:07:17 +00:00
|
|
|
VirtualFramebuffer *vfb = framebufferManager_->GetDisplayVFB();
|
2013-08-19 18:36:43 +00:00
|
|
|
if (vfb) {
|
|
|
|
bool dirty = vfb->dirtyAfterDisplay;
|
|
|
|
vfb->dirtyAfterDisplay = false;
|
|
|
|
return dirty;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2016-04-10 08:21:48 +00:00
|
|
|
bool GPU_DX9::FramebufferReallyDirty() {
|
2013-08-19 18:36:43 +00:00
|
|
|
// FIXME: Workaround for displaylists sometimes hanging unprocessed. Not yet sure of the cause.
|
2014-12-21 00:11:19 +00:00
|
|
|
if (ThreadEnabled()) {
|
2013-08-19 18:36:43 +00:00
|
|
|
// FIXME: Workaround for displaylists sometimes hanging unprocessed. Not yet sure of the cause.
|
|
|
|
ScheduleEvent(GPU_EVENT_PROCESS_QUEUE);
|
|
|
|
// Allow it to process fully before deciding if it's dirty.
|
|
|
|
SyncThread();
|
|
|
|
}
|
|
|
|
|
2016-12-21 17:07:17 +00:00
|
|
|
VirtualFramebuffer *vfb = framebufferManager_->GetDisplayVFB();
|
2013-08-19 18:36:43 +00:00
|
|
|
if (vfb) {
|
|
|
|
bool dirty = vfb->reallyDirtyAfterDisplay;
|
|
|
|
vfb->reallyDirtyAfterDisplay = false;
|
|
|
|
return dirty;
|
|
|
|
}
|
2013-08-17 09:23:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::CopyDisplayToOutputInternal() {
|
2013-08-17 09:23:51 +00:00
|
|
|
dxstate.depthWrite.set(true);
|
|
|
|
dxstate.colorMask.set(true, true, true, true);
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
drawEngine_.Flush();
|
2013-08-17 09:23:51 +00:00
|
|
|
|
2016-12-21 17:07:17 +00:00
|
|
|
framebufferManagerDX9_->CopyDisplayToOutput();
|
|
|
|
framebufferManagerDX9_->EndFrame();
|
2013-08-17 09:23:51 +00:00
|
|
|
|
2013-11-15 13:24:25 +00:00
|
|
|
// shaderManager_->EndFrame();
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerDX9_->DirtyLastShader();
|
2013-08-17 09:23:51 +00:00
|
|
|
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_TEXTURE_IMAGE);
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
2013-09-10 20:35:38 +00:00
|
|
|
// Maybe should write this in ASM...
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::FastRunLoop(DisplayList &list) {
|
2015-05-25 22:39:27 +00:00
|
|
|
PROFILE_THIS_SCOPE("gpuloop");
|
2014-09-13 10:11:34 +00:00
|
|
|
const CommandInfo *cmdInfo = cmdInfo_;
|
2013-08-17 09:23:51 +00:00
|
|
|
for (; downcount > 0; --downcount) {
|
2014-09-13 10:11:34 +00:00
|
|
|
// We know that display list PCs have the upper nibble == 0 - no need to mask the pointer
|
|
|
|
const u32 op = *(const u32 *)(Memory::base + list.pc);
|
2013-12-05 15:37:52 +00:00
|
|
|
const u32 cmd = op >> 24;
|
2014-09-13 10:11:34 +00:00
|
|
|
const CommandInfo info = cmdInfo[cmd];
|
|
|
|
const u8 cmdFlags = info.flags; // If we stashed the cmdFlags in the top bits of the cmdmem, we could get away with one table lookup instead of two
|
2013-12-05 15:37:52 +00:00
|
|
|
const u32 diff = op ^ gstate.cmdmem[cmd];
|
2013-08-19 18:36:43 +00:00
|
|
|
// Inlined CheckFlushOp here to get rid of the dumpThisFrame_ check.
|
2013-08-25 11:56:29 +00:00
|
|
|
if ((cmdFlags & FLAG_FLUSHBEFORE) || (diff && (cmdFlags & FLAG_FLUSHBEFOREONCHANGE))) {
|
2016-04-10 08:21:48 +00:00
|
|
|
drawEngine_.Flush();
|
2013-12-05 15:37:52 +00:00
|
|
|
}
|
2014-09-13 10:11:34 +00:00
|
|
|
gstate.cmdmem[cmd] = op; // TODO: no need to write if diff==0...
|
|
|
|
if ((cmdFlags & FLAG_EXECUTE) || (diff && (cmdFlags & FLAG_EXECUTEONCHANGE))) {
|
|
|
|
(this->*info.func)(op, diff);
|
2017-01-24 11:45:50 +00:00
|
|
|
} else if (diff) {
|
|
|
|
uint64_t dirty = info.flags >> 8;
|
|
|
|
if (dirty)
|
|
|
|
gstate_c.Dirty(dirty);
|
2014-09-13 10:11:34 +00:00
|
|
|
}
|
2013-08-17 09:23:51 +00:00
|
|
|
list.pc += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::FinishDeferred() {
|
2015-03-15 01:11:00 +00:00
|
|
|
// This finishes reading any vertex data that is pending.
|
2016-04-10 08:21:48 +00:00
|
|
|
drawEngine_.FinishDeferred();
|
2015-03-15 01:11:00 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
inline void GPU_DX9::CheckFlushOp(int cmd, u32 diff) {
|
2014-09-13 10:11:34 +00:00
|
|
|
const u8 cmdFlags = cmdInfo_[cmd].flags;
|
2013-08-25 11:56:29 +00:00
|
|
|
if ((cmdFlags & FLAG_FLUSHBEFORE) || (diff && (cmdFlags & FLAG_FLUSHBEFOREONCHANGE))) {
|
2013-08-17 09:23:51 +00:00
|
|
|
if (dumpThisFrame_) {
|
2013-09-10 20:35:38 +00:00
|
|
|
NOTICE_LOG(G3D, "================ FLUSH ================");
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
2016-04-10 08:21:48 +00:00
|
|
|
drawEngine_.Flush();
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::PreExecuteOp(u32 op, u32 diff) {
|
2013-08-19 18:36:43 +00:00
|
|
|
CheckFlushOp(op >> 24, diff);
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::ExecuteOp(u32 op, u32 diff) {
|
2014-09-13 10:11:34 +00:00
|
|
|
const u8 cmd = op >> 24;
|
|
|
|
const CommandInfo info = cmdInfo_[cmd];
|
|
|
|
const u8 cmdFlags = info.flags;
|
|
|
|
if ((cmdFlags & FLAG_EXECUTE) || (diff && (cmdFlags & FLAG_EXECUTEONCHANGE))) {
|
|
|
|
(this->*info.func)(op, diff);
|
2017-01-24 11:45:50 +00:00
|
|
|
} else if (diff) {
|
|
|
|
uint64_t dirty = info.flags >> 8;
|
|
|
|
if (dirty)
|
|
|
|
gstate_c.Dirty(dirty);
|
2014-09-13 10:11:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::Execute_Vaddr(u32 op, u32 diff) {
|
2014-09-13 10:11:34 +00:00
|
|
|
gstate_c.vertexAddr = gstate_c.getRelativeAddress(op & 0x00FFFFFF);
|
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::Execute_Iaddr(u32 op, u32 diff) {
|
2014-09-13 10:11:34 +00:00
|
|
|
gstate_c.indexAddr = gstate_c.getRelativeAddress(op & 0x00FFFFFF);
|
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::Execute_VertexType(u32 op, u32 diff) {
|
2014-09-13 10:11:34 +00:00
|
|
|
if (diff & (GE_VTYPE_TC_MASK | GE_VTYPE_THROUGH_MASK)) {
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_UVSCALEOFFSET);
|
2014-09-13 10:11:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::Execute_VertexTypeSkinning(u32 op, u32 diff) {
|
2014-09-13 10:11:34 +00:00
|
|
|
// Don't flush when weight count changes, unless morph is enabled.
|
|
|
|
if ((diff & ~GE_VTYPE_WEIGHTCOUNT_MASK) || (op & GE_VTYPE_MORPHCOUNT_MASK) != 0) {
|
|
|
|
// Restore and flush
|
|
|
|
gstate.vertType ^= diff;
|
|
|
|
Flush();
|
|
|
|
gstate.vertType ^= diff;
|
|
|
|
if (diff & (GE_VTYPE_TC_MASK | GE_VTYPE_THROUGH_MASK))
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_UVSCALEOFFSET);
|
2015-05-17 04:54:07 +00:00
|
|
|
// In this case, we may be doing weights and morphs.
|
|
|
|
// Update any bone matrix uniforms so it uses them correctly.
|
|
|
|
if ((op & GE_VTYPE_MORPHCOUNT_MASK) != 0) {
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(gstate_c.deferredVertTypeDirty);
|
2015-05-17 04:54:07 +00:00
|
|
|
gstate_c.deferredVertTypeDirty = 0;
|
|
|
|
}
|
2014-09-13 10:11:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::Execute_Prim(u32 op, u32 diff) {
|
2014-09-13 13:13:34 +00:00
|
|
|
// This drives all drawing. All other state we just buffer up, then we apply it only
|
|
|
|
// when it's time to draw. As most PSP games set state redundantly ALL THE TIME, this is a huge optimization.
|
|
|
|
|
|
|
|
u32 data = op & 0xFFFFFF;
|
|
|
|
u32 count = data & 0xFFFF;
|
2016-04-10 20:11:55 +00:00
|
|
|
// Upper bits are ignored.
|
|
|
|
GEPrimitiveType prim = static_cast<GEPrimitiveType>((data >> 16) & 7);
|
2014-09-13 13:13:34 +00:00
|
|
|
|
|
|
|
if (count == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Discard AA lines as we can't do anything that makes sense with these anyway. The SW plugin might, though.
|
|
|
|
|
|
|
|
if (gstate.isAntiAliasEnabled()) {
|
|
|
|
// Discard AA lines in DOA
|
|
|
|
if (prim == GE_PRIM_LINE_STRIP)
|
|
|
|
return;
|
|
|
|
// Discard AA lines in Summon Night 5
|
|
|
|
if ((prim == GE_PRIM_LINES) && gstate.isSkinningEnabled())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This also make skipping drawing very effective.
|
2017-01-23 22:25:09 +00:00
|
|
|
framebufferManagerDX9_->SetRenderFrameBuffer(gstate_c.IsDirty(DIRTY_FRAMEBUF), gstate_c.skipDrawReason);
|
2014-09-13 13:13:34 +00:00
|
|
|
if (gstate_c.skipDrawReason & (SKIPDRAW_SKIPFRAME | SKIPDRAW_NON_DISPLAYED_FB)) {
|
2016-04-10 08:21:48 +00:00
|
|
|
drawEngine_.SetupVertexDecoder(gstate.vertType);
|
2014-09-13 13:13:34 +00:00
|
|
|
// Rough estimate, not sure what's correct.
|
2017-01-23 20:00:44 +00:00
|
|
|
cyclesExecuted += EstimatePerVertexCost() * count;
|
2014-09-13 13:13:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-19 19:11:09 +00:00
|
|
|
u32 vertexAddr = gstate_c.vertexAddr;
|
|
|
|
if (!Memory::IsValidAddress(vertexAddr)) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "Bad vertex address %08x!", vertexAddr);
|
2014-09-13 13:13:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-19 19:11:09 +00:00
|
|
|
void *verts = Memory::GetPointerUnchecked(vertexAddr);
|
2014-09-13 13:13:34 +00:00
|
|
|
void *inds = 0;
|
2014-10-19 19:11:09 +00:00
|
|
|
u32 vertexType = gstate.vertType;
|
|
|
|
if ((vertexType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) {
|
|
|
|
u32 indexAddr = gstate_c.indexAddr;
|
|
|
|
if (!Memory::IsValidAddress(indexAddr)) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "Bad index address %08x!", indexAddr);
|
2014-09-13 13:13:34 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-10-19 19:11:09 +00:00
|
|
|
inds = Memory::GetPointerUnchecked(indexAddr);
|
2014-09-13 13:13:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef MOBILE_DEVICE
|
|
|
|
if (prim > GE_PRIM_RECTANGLES) {
|
|
|
|
ERROR_LOG_REPORT_ONCE(reportPrim, G3D, "Unexpected prim type: %d", prim);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int bytesRead = 0;
|
2016-04-10 08:21:48 +00:00
|
|
|
drawEngine_.SubmitPrim(verts, inds, prim, count, vertexType, &bytesRead);
|
2014-09-13 13:13:34 +00:00
|
|
|
|
2017-01-23 20:00:44 +00:00
|
|
|
int vertexCost = EstimatePerVertexCost() * count;
|
2014-10-19 19:11:09 +00:00
|
|
|
gpuStats.vertexGPUCycles += vertexCost;
|
|
|
|
cyclesExecuted += vertexCost;
|
2014-09-13 13:13:34 +00:00
|
|
|
|
|
|
|
// After drawing, we advance the vertexAddr (when non indexed) or indexAddr (when indexed).
|
|
|
|
// Some games rely on this, they don't bother reloading VADDR and IADDR.
|
|
|
|
// The VADDR/IADDR registers are NOT updated.
|
2016-04-10 20:07:08 +00:00
|
|
|
AdvanceVerts(vertexType, count, bytesRead);
|
2014-09-13 13:13:34 +00:00
|
|
|
}
|
|
|
|
|
2017-01-22 14:44:27 +00:00
|
|
|
void GPU_DX9::Execute_Bezier(u32 op, u32 diff) {
|
|
|
|
// This also make skipping drawing very effective.
|
2017-01-23 22:25:09 +00:00
|
|
|
framebufferManagerDX9_->SetRenderFrameBuffer(gstate_c.IsDirty(DIRTY_FRAMEBUF), gstate_c.skipDrawReason);
|
2017-01-22 14:44:27 +00:00
|
|
|
if (gstate_c.skipDrawReason & (SKIPDRAW_SKIPFRAME | SKIPDRAW_NON_DISPLAYED_FB)) {
|
|
|
|
// TODO: Should this eat some cycles? Probably yes. Not sure if important.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Memory::IsValidAddress(gstate_c.vertexAddr)) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "Bad vertex address %08x!", gstate_c.vertexAddr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *control_points = Memory::GetPointerUnchecked(gstate_c.vertexAddr);
|
|
|
|
void *indices = NULL;
|
|
|
|
if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) {
|
|
|
|
if (!Memory::IsValidAddress(gstate_c.indexAddr)) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "Bad index address %08x!", gstate_c.indexAddr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
indices = Memory::GetPointerUnchecked(gstate_c.indexAddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) {
|
|
|
|
DEBUG_LOG_REPORT(G3D, "Bezier + morph: %i", (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) >> GE_VTYPE_MORPHCOUNT_SHIFT);
|
|
|
|
}
|
|
|
|
if (vertTypeIsSkinningEnabled(gstate.vertType)) {
|
|
|
|
DEBUG_LOG_REPORT(G3D, "Bezier + skinning: %i", vertTypeGetNumBoneWeights(gstate.vertType));
|
|
|
|
}
|
|
|
|
|
|
|
|
GEPatchPrimType patchPrim = gstate.getPatchPrimitiveType();
|
|
|
|
int bz_ucount = op & 0xFF;
|
|
|
|
int bz_vcount = (op >> 8) & 0xFF;
|
|
|
|
bool computeNormals = gstate.isLightingEnabled();
|
|
|
|
bool patchFacing = gstate.patchfacing & 1;
|
|
|
|
int bytesRead = 0;
|
|
|
|
drawEngine_.SubmitBezier(control_points, indices, gstate.getPatchDivisionU(), gstate.getPatchDivisionV(), bz_ucount, bz_vcount, patchPrim, computeNormals, patchFacing, gstate.vertType, &bytesRead);
|
|
|
|
|
|
|
|
// After drawing, we advance pointers - see SubmitPrim which does the same.
|
|
|
|
int count = bz_ucount * bz_vcount;
|
|
|
|
AdvanceVerts(gstate.vertType, count, bytesRead);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_DX9::Execute_Spline(u32 op, u32 diff) {
|
|
|
|
// This also make skipping drawing very effective.
|
2017-01-23 22:25:09 +00:00
|
|
|
framebufferManagerDX9_->SetRenderFrameBuffer(gstate_c.IsDirty(DIRTY_FRAMEBUF), gstate_c.skipDrawReason);
|
2017-01-22 14:44:27 +00:00
|
|
|
if (gstate_c.skipDrawReason & (SKIPDRAW_SKIPFRAME | SKIPDRAW_NON_DISPLAYED_FB)) {
|
|
|
|
// TODO: Should this eat some cycles? Probably yes. Not sure if important.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Memory::IsValidAddress(gstate_c.vertexAddr)) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "Bad vertex address %08x!", gstate_c.vertexAddr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *control_points = Memory::GetPointerUnchecked(gstate_c.vertexAddr);
|
|
|
|
void *indices = NULL;
|
|
|
|
if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) {
|
|
|
|
if (!Memory::IsValidAddress(gstate_c.indexAddr)) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "Bad index address %08x!", gstate_c.indexAddr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
indices = Memory::GetPointerUnchecked(gstate_c.indexAddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) {
|
|
|
|
DEBUG_LOG_REPORT(G3D, "Spline + morph: %i", (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) >> GE_VTYPE_MORPHCOUNT_SHIFT);
|
|
|
|
}
|
|
|
|
if (vertTypeIsSkinningEnabled(gstate.vertType)) {
|
|
|
|
DEBUG_LOG_REPORT(G3D, "Spline + skinning: %i", vertTypeGetNumBoneWeights(gstate.vertType));
|
|
|
|
}
|
|
|
|
|
|
|
|
int sp_ucount = op & 0xFF;
|
|
|
|
int sp_vcount = (op >> 8) & 0xFF;
|
|
|
|
int sp_utype = (op >> 16) & 0x3;
|
|
|
|
int sp_vtype = (op >> 18) & 0x3;
|
|
|
|
GEPatchPrimType patchPrim = gstate.getPatchPrimitiveType();
|
|
|
|
bool computeNormals = gstate.isLightingEnabled();
|
|
|
|
bool patchFacing = gstate.patchfacing & 1;
|
|
|
|
u32 vertType = gstate.vertType;
|
|
|
|
int bytesRead = 0;
|
|
|
|
drawEngine_.SubmitSpline(control_points, indices, gstate.getPatchDivisionU(), gstate.getPatchDivisionV(), sp_ucount, sp_vcount, sp_utype, sp_vtype, patchPrim, computeNormals, patchFacing, vertType, &bytesRead);
|
|
|
|
|
|
|
|
// After drawing, we advance pointers - see SubmitPrim which does the same.
|
|
|
|
int count = sp_ucount * sp_vcount;
|
|
|
|
AdvanceVerts(gstate.vertType, count, bytesRead);
|
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::Execute_TexScaleU(u32 op, u32 diff) {
|
2014-09-13 15:20:55 +00:00
|
|
|
gstate_c.uv.uScale = getFloat24(op);
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_UVSCALEOFFSET);
|
2014-09-13 15:20:55 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::Execute_TexScaleV(u32 op, u32 diff) {
|
2014-09-13 15:20:55 +00:00
|
|
|
gstate_c.uv.vScale = getFloat24(op);
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_UVSCALEOFFSET);
|
2014-09-13 15:20:55 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::Execute_TexOffsetU(u32 op, u32 diff) {
|
2014-09-13 15:20:55 +00:00
|
|
|
gstate_c.uv.uOff = getFloat24(op);
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_UVSCALEOFFSET);
|
2014-09-13 15:20:55 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::Execute_TexOffsetV(u32 op, u32 diff) {
|
2014-09-13 15:20:55 +00:00
|
|
|
gstate_c.uv.vOff = getFloat24(op);
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_UVSCALEOFFSET);
|
2014-09-13 15:20:55 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::Execute_TexSize0(u32 op, u32 diff) {
|
2014-09-13 15:20:55 +00:00
|
|
|
// Render to texture may have overridden the width/height.
|
|
|
|
// Don't reset it unless the size is different / the texture has changed.
|
2017-01-24 08:41:38 +00:00
|
|
|
if (diff || gstate_c.IsDirty(DIRTY_TEXTURE_IMAGE | DIRTY_TEXTURE_PARAMS)) {
|
2014-09-13 15:20:55 +00:00
|
|
|
gstate_c.curTextureWidth = gstate.getTextureWidth(0);
|
|
|
|
gstate_c.curTextureHeight = gstate.getTextureHeight(0);
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_UVSCALEOFFSET);
|
2014-09-13 15:20:55 +00:00
|
|
|
// We will need to reset the texture now.
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_TEXTURE_PARAMS);
|
2014-09-13 15:20:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::Execute_LoadClut(u32 op, u32 diff) {
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_TEXTURE_PARAMS);
|
2016-12-21 17:51:19 +00:00
|
|
|
textureCacheDX9_->LoadClut(gstate.getClutAddress(), gstate.getClutLoadBytes());
|
2014-09-13 15:20:55 +00:00
|
|
|
// This could be used to "dirty" textures with clut.
|
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::GetStats(char *buffer, size_t bufsize) {
|
2016-03-31 08:17:02 +00:00
|
|
|
float vertexAverageCycles = gpuStats.numVertsSubmitted > 0 ? (float)gpuStats.vertexGPUCycles / (float)gpuStats.numVertsSubmitted : 0.0f;
|
|
|
|
snprintf(buffer, bufsize - 1,
|
|
|
|
"DL processing time: %0.2f ms\n"
|
|
|
|
"Draw calls: %i, flushes %i\n"
|
|
|
|
"Cached Draw calls: %i\n"
|
|
|
|
"Num Tracked Vertex Arrays: %i\n"
|
|
|
|
"GPU cycles executed: %d (%f per vertex)\n"
|
|
|
|
"Commands per call level: %i %i %i %i\n"
|
|
|
|
"Vertices submitted: %i\n"
|
|
|
|
"Cached, Uncached Vertices Drawn: %i, %i\n"
|
|
|
|
"FBOs active: %i\n"
|
|
|
|
"Textures active: %i, decoded: %i invalidated: %i\n"
|
2016-03-31 08:23:40 +00:00
|
|
|
"Vertex, Fragment shaders loaded: %i, %i\n",
|
2016-03-31 08:17:02 +00:00
|
|
|
gpuStats.msProcessingDisplayLists * 1000.0f,
|
|
|
|
gpuStats.numDrawCalls,
|
|
|
|
gpuStats.numFlushes,
|
|
|
|
gpuStats.numCachedDrawCalls,
|
|
|
|
gpuStats.numTrackedVertexArrays,
|
|
|
|
gpuStats.vertexGPUCycles + gpuStats.otherGPUCycles,
|
|
|
|
vertexAverageCycles,
|
|
|
|
gpuStats.gpuCommandsAtCallLevel[0], gpuStats.gpuCommandsAtCallLevel[1], gpuStats.gpuCommandsAtCallLevel[2], gpuStats.gpuCommandsAtCallLevel[3],
|
|
|
|
gpuStats.numVertsSubmitted,
|
|
|
|
gpuStats.numCachedVertsDrawn,
|
|
|
|
gpuStats.numUncachedVertsDrawn,
|
2016-12-21 17:07:17 +00:00
|
|
|
(int)framebufferManagerDX9_->NumVFBs(),
|
2016-12-21 17:51:19 +00:00
|
|
|
(int)textureCacheDX9_->NumLoadedTextures(),
|
2016-03-31 08:17:02 +00:00
|
|
|
gpuStats.numTexturesDecoded,
|
|
|
|
gpuStats.numTextureInvalidations,
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerDX9_->NumVertexShaders(),
|
|
|
|
shaderManagerDX9_->NumFragmentShaders()
|
2016-03-31 08:17:02 +00:00
|
|
|
);
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::ClearCacheNextFrame() {
|
2016-12-21 17:51:19 +00:00
|
|
|
textureCacheDX9_->ClearNextFrame();
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::ClearShaderCache() {
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerDX9_->ClearCache(true);
|
2013-12-05 15:37:52 +00:00
|
|
|
}
|
2014-09-11 23:48:43 +00:00
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
std::vector<FramebufferInfo> GPU_DX9::GetFramebufferList() {
|
2016-12-21 17:07:17 +00:00
|
|
|
return framebufferManagerDX9_->GetFramebufferList();
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_DX9::DoState(PointerWrap &p) {
|
2013-08-17 09:23:51 +00:00
|
|
|
GPUCommon::DoState(p);
|
|
|
|
|
2013-12-05 15:37:52 +00:00
|
|
|
// TODO: Some of these things may not be necessary.
|
|
|
|
// None of these are necessary when saving.
|
|
|
|
if (p.mode == p.MODE_READ) {
|
2016-12-21 17:51:19 +00:00
|
|
|
textureCacheDX9_->Clear(true);
|
2016-04-10 08:21:48 +00:00
|
|
|
drawEngine_.ClearTrackedVertexArrays();
|
2013-08-17 09:23:51 +00:00
|
|
|
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_TEXTURE_IMAGE);
|
2016-12-21 17:07:17 +00:00
|
|
|
framebufferManagerDX9_->DestroyAllFBOs(true);
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerDX9_->ClearCache(true);
|
2013-12-05 15:37:52 +00:00
|
|
|
}
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
2013-09-15 15:53:21 +00:00
|
|
|
|
2016-09-25 23:31:38 +00:00
|
|
|
bool GPU_DX9::GetCurrentFramebuffer(GPUDebugBuffer &buffer, GPUDebugFramebufferType type, int maxRes) {
|
2016-12-21 17:07:17 +00:00
|
|
|
return framebufferManagerDX9_->GetCurrentFramebuffer(buffer, type, maxRes);
|
2013-12-05 15:37:52 +00:00
|
|
|
}
|
2013-11-15 13:24:25 +00:00
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
bool GPU_DX9::GetCurrentDepthbuffer(GPUDebugBuffer &buffer) {
|
2016-12-21 17:07:17 +00:00
|
|
|
return framebufferManagerDX9_->GetCurrentDepthbuffer(buffer);
|
2013-12-05 15:37:52 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
bool GPU_DX9::GetCurrentStencilbuffer(GPUDebugBuffer &buffer) {
|
2016-12-21 17:07:17 +00:00
|
|
|
return framebufferManagerDX9_->GetCurrentStencilbuffer(buffer);
|
2013-12-05 15:37:52 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
bool GPU_DX9::GetCurrentTexture(GPUDebugBuffer &buffer, int level) {
|
2013-12-05 15:37:52 +00:00
|
|
|
if (!gstate.isTextureMapEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-21 17:51:19 +00:00
|
|
|
textureCacheDX9_->SetTexture(true);
|
|
|
|
textureCacheDX9_->ApplyTexture();
|
2014-08-25 04:23:23 +00:00
|
|
|
int w = gstate.getTextureWidth(level);
|
|
|
|
int h = gstate.getTextureHeight(level);
|
|
|
|
|
|
|
|
LPDIRECT3DBASETEXTURE9 baseTex;
|
|
|
|
LPDIRECT3DTEXTURE9 tex;
|
2014-09-09 08:42:21 +00:00
|
|
|
LPDIRECT3DSURFACE9 offscreen = nullptr;
|
2014-08-25 04:23:23 +00:00
|
|
|
HRESULT hr;
|
|
|
|
|
2014-09-13 21:50:42 +00:00
|
|
|
bool success = false;
|
2014-08-25 04:23:23 +00:00
|
|
|
hr = pD3Ddevice->GetTexture(0, &baseTex);
|
2014-09-13 21:50:42 +00:00
|
|
|
if (SUCCEEDED(hr) && baseTex != NULL) {
|
2014-08-25 04:23:23 +00:00
|
|
|
hr = baseTex->QueryInterface(IID_IDirect3DTexture9, (void **)&tex);
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
D3DSURFACE_DESC desc;
|
|
|
|
D3DLOCKED_RECT locked;
|
|
|
|
tex->GetLevelDesc(level, &desc);
|
2015-09-17 20:02:15 +00:00
|
|
|
RECT rect = {0, 0, (LONG)desc.Width, (LONG)desc.Height};
|
2014-08-25 04:23:23 +00:00
|
|
|
hr = tex->LockRect(level, &locked, &rect, D3DLOCK_READONLY);
|
2014-09-09 08:42:21 +00:00
|
|
|
|
|
|
|
// If it fails, this means it's a render-to-texture, so we have to get creative.
|
|
|
|
if (FAILED(hr)) {
|
2014-09-12 06:52:06 +00:00
|
|
|
LPDIRECT3DSURFACE9 renderTarget = nullptr;
|
2014-09-09 08:42:21 +00:00
|
|
|
hr = tex->GetSurfaceLevel(level, &renderTarget);
|
2014-09-12 06:52:06 +00:00
|
|
|
if (renderTarget && SUCCEEDED(hr)) {
|
2014-09-09 08:42:21 +00:00
|
|
|
hr = pD3Ddevice->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &offscreen, NULL);
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
hr = pD3Ddevice->GetRenderTargetData(renderTarget, offscreen);
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
hr = offscreen->LockRect(&locked, &rect, D3DLOCK_READONLY);
|
|
|
|
}
|
|
|
|
}
|
2014-09-12 06:52:06 +00:00
|
|
|
renderTarget->Release();
|
2014-09-09 08:42:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-25 04:23:23 +00:00
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
GPUDebugBufferFormat fmt;
|
|
|
|
int pixelSize;
|
|
|
|
switch (desc.Format) {
|
|
|
|
case D3DFMT_A1R5G5B5:
|
2014-09-09 04:25:37 +00:00
|
|
|
fmt = gstate_c.bgraTexture ? GPU_DBG_FORMAT_5551 : GPU_DBG_FORMAT_5551_BGRA;
|
2014-08-25 04:23:23 +00:00
|
|
|
pixelSize = 2;
|
|
|
|
break;
|
|
|
|
case D3DFMT_A4R4G4B4:
|
2014-09-09 04:25:37 +00:00
|
|
|
fmt = gstate_c.bgraTexture ? GPU_DBG_FORMAT_4444 : GPU_DBG_FORMAT_4444_BGRA;
|
2014-08-25 04:23:23 +00:00
|
|
|
pixelSize = 2;
|
|
|
|
break;
|
|
|
|
case D3DFMT_R5G6B5:
|
2014-09-09 04:25:37 +00:00
|
|
|
fmt = gstate_c.bgraTexture ? GPU_DBG_FORMAT_565 : GPU_DBG_FORMAT_565_BGRA;
|
2014-08-25 04:23:23 +00:00
|
|
|
pixelSize = 2;
|
|
|
|
break;
|
|
|
|
case D3DFMT_A8R8G8B8:
|
2014-09-09 04:25:37 +00:00
|
|
|
fmt = gstate_c.bgraTexture ? GPU_DBG_FORMAT_8888 : GPU_DBG_FORMAT_8888_BGRA;
|
2014-08-25 04:23:23 +00:00
|
|
|
pixelSize = 4;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fmt = GPU_DBG_FORMAT_INVALID;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fmt != GPU_DBG_FORMAT_INVALID) {
|
2015-10-31 22:59:23 +00:00
|
|
|
buffer.Allocate(locked.Pitch / pixelSize, desc.Height, fmt, false);
|
2014-08-25 04:23:23 +00:00
|
|
|
memcpy(buffer.GetData(), locked.pBits, locked.Pitch * desc.Height);
|
|
|
|
success = true;
|
|
|
|
} else {
|
|
|
|
success = false;
|
|
|
|
}
|
2014-09-09 08:42:21 +00:00
|
|
|
if (offscreen) {
|
|
|
|
offscreen->UnlockRect();
|
|
|
|
offscreen->Release();
|
|
|
|
} else {
|
|
|
|
tex->UnlockRect(level);
|
|
|
|
}
|
2014-08-25 04:23:23 +00:00
|
|
|
}
|
|
|
|
tex->Release();
|
|
|
|
}
|
|
|
|
baseTex->Release();
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
2013-11-15 13:24:25 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
bool GPU_DX9::GetCurrentClut(GPUDebugBuffer &buffer) {
|
2016-12-21 17:51:19 +00:00
|
|
|
return textureCacheDX9_->GetCurrentClutBuffer(buffer);
|
2016-01-10 17:25:19 +00:00
|
|
|
}
|
|
|
|
|
2016-09-25 23:35:43 +00:00
|
|
|
bool GPU_DX9::GetOutputFramebuffer(GPUDebugBuffer &buffer) {
|
|
|
|
return FramebufferManagerDX9::GetOutputFramebuffer(buffer);
|
2014-12-20 16:31:56 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
bool GPU_DX9::GetCurrentSimpleVertices(int count, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices) {
|
|
|
|
return drawEngine_.GetCurrentSimpleVertices(count, vertices, indices);
|
2014-08-25 05:16:32 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
std::vector<std::string> GPU_DX9::DebugGetShaderIDs(DebugShaderType type) {
|
2015-10-24 22:34:23 +00:00
|
|
|
if (type == SHADER_TYPE_VERTEXLOADER) {
|
2016-04-10 08:21:48 +00:00
|
|
|
return drawEngine_.DebugGetVertexLoaderIDs();
|
2015-10-24 22:34:23 +00:00
|
|
|
} else {
|
2017-01-23 19:48:23 +00:00
|
|
|
return shaderManagerDX9_->DebugGetShaderIDs(type);
|
2015-10-24 22:34:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
std::string GPU_DX9::DebugGetShaderString(std::string id, DebugShaderType type, DebugShaderStringType stringType) {
|
2015-10-24 22:34:23 +00:00
|
|
|
if (type == SHADER_TYPE_VERTEXLOADER) {
|
2016-04-10 08:21:48 +00:00
|
|
|
return drawEngine_.DebugGetVertexLoaderString(id, stringType);
|
2015-10-24 22:34:23 +00:00
|
|
|
} else {
|
2017-01-23 19:48:23 +00:00
|
|
|
return shaderManagerDX9_->DebugGetShaderString(id, type, stringType);
|
2015-10-24 22:34:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-13 10:11:34 +00:00
|
|
|
} // namespace DX9
|