2013-04-02 06:54:19 +00:00
|
|
|
#include <algorithm>
|
2015-10-11 12:38:26 +00:00
|
|
|
#include <type_traits>
|
2017-02-27 20:57:46 +00:00
|
|
|
#include <mutex>
|
2015-10-11 12:38:26 +00:00
|
|
|
|
2015-09-06 19:19:33 +00:00
|
|
|
#include "base/timeutil.h"
|
2017-08-18 11:39:42 +00:00
|
|
|
#include "profiler/profiler.h"
|
|
|
|
|
2015-05-23 17:33:24 +00:00
|
|
|
#include "Common/ColorConv.h"
|
2017-01-24 09:44:02 +00:00
|
|
|
#include "Core/Reporting.h"
|
2015-05-23 17:33:24 +00:00
|
|
|
#include "GPU/GeDisasm.h"
|
2015-07-26 20:38:40 +00:00
|
|
|
#include "GPU/GPU.h"
|
2015-05-23 17:33:24 +00:00
|
|
|
#include "GPU/GPUCommon.h"
|
|
|
|
#include "GPU/GPUState.h"
|
2013-02-04 04:31:46 +00:00
|
|
|
#include "ChunkFile.h"
|
2013-04-21 22:16:45 +00:00
|
|
|
#include "Core/Config.h"
|
2013-04-03 15:10:35 +00:00
|
|
|
#include "Core/CoreTiming.h"
|
2013-04-01 06:02:46 +00:00
|
|
|
#include "Core/MemMap.h"
|
2013-02-10 15:36:06 +00:00
|
|
|
#include "Core/Host.h"
|
2013-04-05 08:13:54 +00:00
|
|
|
#include "Core/Reporting.h"
|
2014-06-14 15:42:18 +00:00
|
|
|
#include "Core/HLE/HLE.h"
|
2013-04-04 07:35:38 +00:00
|
|
|
#include "Core/HLE/sceKernelMemory.h"
|
2013-08-29 06:15:13 +00:00
|
|
|
#include "Core/HLE/sceKernelInterrupt.h"
|
2014-03-30 00:02:41 +00:00
|
|
|
#include "Core/HLE/sceKernelThread.h"
|
2013-04-01 06:02:46 +00:00
|
|
|
#include "Core/HLE/sceGe.h"
|
2016-12-21 17:07:17 +00:00
|
|
|
#include "Core/Debugger/Breakpoints.h"
|
2016-12-21 17:26:06 +00:00
|
|
|
#include "Core/MemMapHelpers.h"
|
2016-12-21 17:07:17 +00:00
|
|
|
#include "GPU/Common/FramebufferCommon.h"
|
|
|
|
#include "GPU/Common/TextureCacheCommon.h"
|
2017-01-21 19:42:40 +00:00
|
|
|
#include "GPU/Common/DrawEngineCommon.h"
|
2017-06-03 04:53:20 +00:00
|
|
|
#include "GPU/Debugger/Record.h"
|
2012-12-28 20:58:00 +00:00
|
|
|
|
2017-03-14 12:21:24 +00:00
|
|
|
const CommonCommandTableEntry commonCommandTable[] = {
|
2017-03-14 12:35:09 +00:00
|
|
|
// From Common. No flushing but definitely need execute.
|
|
|
|
{ GE_CMD_OFFSETADDR, FLAG_EXECUTE, 0, &GPUCommon::Execute_OffsetAddr },
|
|
|
|
{ GE_CMD_ORIGIN, FLAG_EXECUTE | FLAG_READS_PC, 0, &GPUCommon::Execute_Origin },
|
|
|
|
{ GE_CMD_JUMP, FLAG_EXECUTE | FLAG_READS_PC | FLAG_WRITES_PC, 0, &GPUCommon::Execute_Jump },
|
|
|
|
{ GE_CMD_CALL, FLAG_EXECUTE | FLAG_READS_PC | FLAG_WRITES_PC, 0, &GPUCommon::Execute_Call },
|
|
|
|
{ GE_CMD_RET, FLAG_EXECUTE | FLAG_READS_PC | FLAG_WRITES_PC, 0, &GPUCommon::Execute_Ret },
|
|
|
|
{ GE_CMD_END, FLAG_FLUSHBEFORE | FLAG_EXECUTE | FLAG_READS_PC | FLAG_WRITES_PC, 0, &GPUCommon::Execute_End },
|
|
|
|
{ GE_CMD_VADDR, FLAG_EXECUTE, 0, &GPUCommon::Execute_Vaddr },
|
|
|
|
{ GE_CMD_IADDR, FLAG_EXECUTE, 0, &GPUCommon::Execute_Iaddr },
|
|
|
|
{ GE_CMD_BJUMP, FLAG_EXECUTE | FLAG_READS_PC | FLAG_WRITES_PC, 0, &GPUCommon::Execute_BJump }, // EXECUTE
|
|
|
|
{ GE_CMD_BOUNDINGBOX, FLAG_EXECUTE, 0, &GPUCommon::Execute_BoundingBox }, // + FLUSHBEFORE when we implement... or not, do we need to?
|
|
|
|
|
2017-03-14 14:44:39 +00:00
|
|
|
// These two are actually processed in CMD_END. Not sure if FLAG_FLUSHBEFORE matters.
|
|
|
|
{ GE_CMD_SIGNAL, FLAG_FLUSHBEFORE },
|
|
|
|
{ GE_CMD_FINISH, FLAG_FLUSHBEFORE },
|
|
|
|
|
2017-03-14 12:21:24 +00:00
|
|
|
// Changes that dirty the framebuffer
|
|
|
|
{ GE_CMD_FRAMEBUFPTR, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS },
|
2017-01-30 11:22:35 +00:00
|
|
|
{ GE_CMD_FRAMEBUFWIDTH, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS | DIRTY_VIEWPORTSCISSOR_STATE },
|
2017-03-19 10:32:29 +00:00
|
|
|
{ GE_CMD_FRAMEBUFPIXFORMAT, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS | DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_FRAGMENTSHADER_STATE},
|
2017-03-14 12:21:24 +00:00
|
|
|
{ GE_CMD_ZBUFPTR, FLAG_FLUSHBEFOREONCHANGE },
|
|
|
|
{ GE_CMD_ZBUFWIDTH, FLAG_FLUSHBEFOREONCHANGE },
|
|
|
|
|
|
|
|
{ GE_CMD_FOGCOLOR, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FOGCOLOR },
|
|
|
|
{ GE_CMD_FOG1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FOGCOEF },
|
|
|
|
{ GE_CMD_FOG2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FOGCOEF },
|
|
|
|
|
2017-03-14 12:47:34 +00:00
|
|
|
// These affect the fragment shader so need flushing.
|
2017-03-19 10:32:29 +00:00
|
|
|
{ GE_CMD_CLEARMODE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_VERTEXSHADER_STATE | DIRTY_FRAGMENTSHADER_STATE },
|
|
|
|
{ GE_CMD_TEXTUREMAPENABLE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VERTEXSHADER_STATE | DIRTY_FRAGMENTSHADER_STATE },
|
|
|
|
{ GE_CMD_FOGENABLE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VERTEXSHADER_STATE | DIRTY_FRAGMENTSHADER_STATE},
|
|
|
|
{ GE_CMD_TEXMODE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS | DIRTY_FRAGMENTSHADER_STATE },
|
2017-01-30 13:04:20 +00:00
|
|
|
{ GE_CMD_TEXSHADELS, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VERTEXSHADER_STATE },
|
2017-08-17 19:01:44 +00:00
|
|
|
{ GE_CMD_SHADEMODE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VERTEXSHADER_STATE | DIRTY_FRAGMENTSHADER_STATE },
|
2017-03-19 10:32:29 +00:00
|
|
|
{ GE_CMD_TEXFUNC, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAGMENTSHADER_STATE },
|
|
|
|
{ GE_CMD_COLORTEST, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAGMENTSHADER_STATE },
|
|
|
|
{ GE_CMD_ALPHATESTENABLE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAGMENTSHADER_STATE },
|
|
|
|
{ GE_CMD_COLORTESTENABLE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAGMENTSHADER_STATE },
|
|
|
|
{ GE_CMD_COLORTESTMASK, FLAG_FLUSHBEFOREONCHANGE, DIRTY_ALPHACOLORMASK | DIRTY_FRAGMENTSHADER_STATE },
|
2017-03-14 12:47:34 +00:00
|
|
|
|
2017-03-14 12:44:18 +00:00
|
|
|
// These change the vertex shader so need flushing.
|
2017-01-30 13:04:20 +00:00
|
|
|
{ GE_CMD_REVERSENORMAL, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VERTEXSHADER_STATE },
|
2017-08-20 18:14:41 +00:00
|
|
|
{ GE_CMD_LIGHTINGENABLE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VERTEXSHADER_STATE | DIRTY_FRAGMENTSHADER_STATE },
|
2017-01-30 13:04:20 +00:00
|
|
|
{ GE_CMD_LIGHTENABLE0, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VERTEXSHADER_STATE },
|
|
|
|
{ GE_CMD_LIGHTENABLE1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VERTEXSHADER_STATE },
|
|
|
|
{ GE_CMD_LIGHTENABLE2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VERTEXSHADER_STATE },
|
|
|
|
{ GE_CMD_LIGHTENABLE3, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VERTEXSHADER_STATE },
|
|
|
|
{ GE_CMD_LIGHTTYPE0, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VERTEXSHADER_STATE },
|
|
|
|
{ GE_CMD_LIGHTTYPE1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VERTEXSHADER_STATE },
|
|
|
|
{ GE_CMD_LIGHTTYPE2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VERTEXSHADER_STATE },
|
|
|
|
{ GE_CMD_LIGHTTYPE3, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VERTEXSHADER_STATE },
|
2017-08-20 18:14:41 +00:00
|
|
|
{ GE_CMD_MATERIALUPDATE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VERTEXSHADER_STATE | DIRTY_FRAGMENTSHADER_STATE },
|
2017-03-14 12:44:18 +00:00
|
|
|
|
|
|
|
// These change both shaders so need flushing.
|
2017-03-19 10:32:29 +00:00
|
|
|
{ GE_CMD_LIGHTMODE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VERTEXSHADER_STATE | DIRTY_FRAGMENTSHADER_STATE },
|
|
|
|
|
2017-03-14 12:44:18 +00:00
|
|
|
{ GE_CMD_TEXFILTER, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
2017-03-19 10:32:29 +00:00
|
|
|
{ GE_CMD_TEXWRAP, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS | DIRTY_FRAGMENTSHADER_STATE },
|
2017-03-14 12:44:18 +00:00
|
|
|
|
2017-03-19 10:32:29 +00:00
|
|
|
// Uniform changes. though the fragmentshader optimizes based on these sometimes.
|
|
|
|
{ GE_CMD_ALPHATEST, FLAG_FLUSHBEFOREONCHANGE, DIRTY_ALPHACOLORREF | DIRTY_ALPHACOLORMASK | DIRTY_FRAGMENTSHADER_STATE },
|
|
|
|
{ GE_CMD_COLORREF, FLAG_FLUSHBEFOREONCHANGE, DIRTY_ALPHACOLORREF | DIRTY_FRAGMENTSHADER_STATE },
|
2017-03-14 12:47:34 +00:00
|
|
|
{ GE_CMD_TEXENVCOLOR, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXENV },
|
|
|
|
|
|
|
|
// Simple render state changes. Handled in StateMapping.cpp.
|
2017-01-30 11:07:26 +00:00
|
|
|
{ GE_CMD_CULL, FLAG_FLUSHBEFOREONCHANGE, DIRTY_RASTER_STATE },
|
|
|
|
{ GE_CMD_CULLFACEENABLE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_RASTER_STATE },
|
|
|
|
{ GE_CMD_DITHERENABLE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_RASTER_STATE },
|
2017-03-19 10:32:29 +00:00
|
|
|
{ GE_CMD_STENCILOP, FLAG_FLUSHBEFOREONCHANGE, DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_FRAGMENTSHADER_STATE },
|
|
|
|
{ GE_CMD_STENCILTESTENABLE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_FRAGMENTSHADER_STATE },
|
|
|
|
{ GE_CMD_ALPHABLENDENABLE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_BLEND_STATE | DIRTY_FRAGMENTSHADER_STATE },
|
|
|
|
{ GE_CMD_BLENDMODE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_BLEND_STATE | DIRTY_FRAGMENTSHADER_STATE },
|
|
|
|
{ GE_CMD_BLENDFIXEDA, FLAG_FLUSHBEFOREONCHANGE, DIRTY_BLEND_STATE | DIRTY_FRAGMENTSHADER_STATE },
|
|
|
|
{ GE_CMD_BLENDFIXEDB, FLAG_FLUSHBEFOREONCHANGE, DIRTY_BLEND_STATE | DIRTY_FRAGMENTSHADER_STATE },
|
|
|
|
{ GE_CMD_MASKRGB, FLAG_FLUSHBEFOREONCHANGE, DIRTY_BLEND_STATE | DIRTY_FRAGMENTSHADER_STATE },
|
|
|
|
{ GE_CMD_MASKALPHA, FLAG_FLUSHBEFOREONCHANGE, DIRTY_BLEND_STATE | DIRTY_FRAGMENTSHADER_STATE },
|
2017-01-30 11:02:14 +00:00
|
|
|
{ GE_CMD_ZTEST, FLAG_FLUSHBEFOREONCHANGE, DIRTY_DEPTHSTENCIL_STATE },
|
|
|
|
{ GE_CMD_ZTESTENABLE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_DEPTHSTENCIL_STATE },
|
|
|
|
{ GE_CMD_ZWRITEDISABLE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_DEPTHSTENCIL_STATE },
|
2017-03-19 10:32:29 +00:00
|
|
|
{ GE_CMD_LOGICOP, FLAG_FLUSHBEFOREONCHANGE, DIRTY_BLEND_STATE | DIRTY_FRAGMENTSHADER_STATE },
|
|
|
|
{ GE_CMD_LOGICOPENABLE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_BLEND_STATE | DIRTY_FRAGMENTSHADER_STATE },
|
2017-03-14 12:42:48 +00:00
|
|
|
|
2017-03-19 10:32:29 +00:00
|
|
|
{ GE_CMD_TEXMAPMODE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VERTEXSHADER_STATE | DIRTY_FRAGMENTSHADER_STATE },
|
2017-08-17 11:53:13 +00:00
|
|
|
|
|
|
|
// These are read on every SubmitPrim, no need for dirtying or flushing.
|
|
|
|
{ GE_CMD_TEXSCALEU },
|
|
|
|
{ GE_CMD_TEXSCALEV },
|
|
|
|
{ GE_CMD_TEXOFFSETU },
|
|
|
|
{ GE_CMD_TEXOFFSETV },
|
2017-03-14 12:39:32 +00:00
|
|
|
|
|
|
|
// TEXSIZE0 is handled by each backend.
|
|
|
|
{ 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, FLAG_EXECUTEONCHANGE, DIRTY_TEXTURE_PARAMS, &GPUCommon::Execute_TexLevel },
|
2017-05-13 03:05:35 +00:00
|
|
|
{ GE_CMD_TEXLODSLOPE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_TEXTURE_PARAMS },
|
2017-03-14 12:39:32 +00:00
|
|
|
{ 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 },
|
2017-03-14 12:21:24 +00:00
|
|
|
|
2017-03-14 12:30:03 +00:00
|
|
|
// Morph weights. TODO: Remove precomputation?
|
|
|
|
{ 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 },
|
|
|
|
|
|
|
|
// Control spline/bezier patches. Don't really require flushing as such, but meh.
|
|
|
|
{ GE_CMD_PATCHDIVISION, FLAG_FLUSHBEFOREONCHANGE },
|
|
|
|
{ GE_CMD_PATCHPRIMITIVE, FLAG_FLUSHBEFOREONCHANGE },
|
2017-01-30 13:04:20 +00:00
|
|
|
{ GE_CMD_PATCHFACING, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VERTEXSHADER_STATE },
|
2017-03-14 12:30:03 +00:00
|
|
|
{ GE_CMD_PATCHCULLENABLE, FLAG_FLUSHBEFOREONCHANGE },
|
|
|
|
|
2017-03-14 12:37:12 +00:00
|
|
|
// Can probably ignore this one as we don't support AA lines.
|
|
|
|
{ GE_CMD_ANTIALIASENABLE, FLAG_FLUSHBEFOREONCHANGE },
|
|
|
|
|
2017-03-14 12:28:28 +00:00
|
|
|
// Viewport.
|
2017-01-30 11:22:35 +00:00
|
|
|
{ GE_CMD_OFFSETX, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VIEWPORTSCISSOR_STATE },
|
|
|
|
{ GE_CMD_OFFSETY, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VIEWPORTSCISSOR_STATE },
|
|
|
|
{ GE_CMD_VIEWPORTXSCALE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS | DIRTY_VIEWPORTSCISSOR_STATE },
|
|
|
|
{ GE_CMD_VIEWPORTYSCALE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS | DIRTY_VIEWPORTSCISSOR_STATE },
|
|
|
|
{ GE_CMD_VIEWPORTXCENTER, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS | DIRTY_VIEWPORTSCISSOR_STATE },
|
|
|
|
{ GE_CMD_VIEWPORTYCENTER, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS | DIRTY_VIEWPORTSCISSOR_STATE },
|
|
|
|
{ GE_CMD_VIEWPORTZSCALE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS | DIRTY_DEPTHRANGE | DIRTY_PROJMATRIX | DIRTY_VIEWPORTSCISSOR_STATE },
|
|
|
|
{ GE_CMD_VIEWPORTZCENTER, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS | DIRTY_DEPTHRANGE | DIRTY_PROJMATRIX | DIRTY_VIEWPORTSCISSOR_STATE },
|
2017-04-03 21:51:54 +00:00
|
|
|
{ GE_CMD_CLIPENABLE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VIEWPORTSCISSOR_STATE },
|
2017-03-14 12:28:28 +00:00
|
|
|
|
2017-03-14 12:41:13 +00:00
|
|
|
// Z clip
|
2017-03-19 17:56:34 +00:00
|
|
|
{ GE_CMD_MINZ, FLAG_FLUSHBEFOREONCHANGE, DIRTY_DEPTHRANGE | DIRTY_VIEWPORTSCISSOR_STATE },
|
|
|
|
{ GE_CMD_MAXZ, FLAG_FLUSHBEFOREONCHANGE, DIRTY_DEPTHRANGE | DIRTY_VIEWPORTSCISSOR_STATE },
|
2017-03-14 12:41:13 +00:00
|
|
|
|
2017-03-14 12:28:28 +00:00
|
|
|
// Region
|
2017-04-03 21:51:54 +00:00
|
|
|
{ GE_CMD_REGION1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS | DIRTY_VIEWPORTSCISSOR_STATE },
|
|
|
|
{ GE_CMD_REGION2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS | DIRTY_VIEWPORTSCISSOR_STATE },
|
2017-03-14 12:28:28 +00:00
|
|
|
|
|
|
|
// Scissor
|
2017-01-30 11:22:35 +00:00
|
|
|
{ GE_CMD_SCISSOR1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS | DIRTY_VIEWPORTSCISSOR_STATE },
|
|
|
|
{ GE_CMD_SCISSOR2, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS | DIRTY_VIEWPORTSCISSOR_STATE },
|
2017-03-14 12:28:28 +00:00
|
|
|
|
2017-03-14 12:26:53 +00:00
|
|
|
// Lighting base colors
|
|
|
|
{ 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 },
|
|
|
|
|
|
|
|
// Light parameters
|
|
|
|
{ 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 },
|
|
|
|
|
2017-03-14 12:25:52 +00:00
|
|
|
// Ignored commands
|
|
|
|
{ GE_CMD_TEXFLUSH, 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 },
|
2017-08-17 12:26:52 +00:00
|
|
|
{ GE_CMD_TRANSFERSTART, FLAG_FLUSHBEFORE | FLAG_EXECUTE | FLAG_READS_PC, 0, &GPUCommon::Execute_BlockTransferStart },
|
2017-03-14 12:25:52 +00:00
|
|
|
|
2017-03-14 12:24:35 +00:00
|
|
|
// We don't use the dither table.
|
|
|
|
{ GE_CMD_DITH0 },
|
|
|
|
{ GE_CMD_DITH1 },
|
|
|
|
{ GE_CMD_DITH2 },
|
|
|
|
{ GE_CMD_DITH3 },
|
|
|
|
|
|
|
|
// These handle their own flushing.
|
|
|
|
{ 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 },
|
|
|
|
|
2017-03-14 12:21:24 +00:00
|
|
|
// Vertex Screen/Texture/Color
|
|
|
|
{ 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 },
|
|
|
|
|
|
|
|
// "Missing" commands (gaps in the sequence)
|
|
|
|
{ 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 },
|
|
|
|
// Appears to be debugging related or something? Hit a lot in GoW.
|
2017-08-05 16:15:01 +00:00
|
|
|
{ GE_CMD_NOP_FF, 0 },
|
2017-03-14 12:21:24 +00:00
|
|
|
};
|
|
|
|
size_t commonCommandTableSize = ARRAY_SIZE(commonCommandTable);
|
|
|
|
|
2017-01-23 19:56:25 +00:00
|
|
|
void GPUCommon::Flush() {
|
|
|
|
drawEngineCommon_->DispatchFlush();
|
|
|
|
}
|
|
|
|
|
2017-01-30 15:50:35 +00:00
|
|
|
GPUCommon::GPUCommon(GraphicsContext *gfxCtx, Draw::DrawContext *draw) :
|
2013-04-05 06:19:28 +00:00
|
|
|
dumpNextFrame_(false),
|
2016-12-21 17:07:17 +00:00
|
|
|
dumpThisFrame_(false),
|
2016-12-21 17:13:58 +00:00
|
|
|
framebufferManager_(nullptr),
|
2017-01-30 15:50:35 +00:00
|
|
|
resized_(false),
|
|
|
|
gfxCtx_(gfxCtx),
|
|
|
|
draw_(draw)
|
2013-04-05 06:19:28 +00:00
|
|
|
{
|
2015-10-11 16:42:32 +00:00
|
|
|
// This assert failed on GCC x86 32-bit (but not MSVC 32-bit!) before adding the
|
2015-10-11 12:38:26 +00:00
|
|
|
// "padding" field at the end. This is important for save state compatibility.
|
2015-10-11 16:42:32 +00:00
|
|
|
// The compiler was not rounding the struct size up to an 8 byte boundary, which
|
|
|
|
// you'd expect due to the int64 field, but the Linux ABI apparently does not require that.
|
2015-10-11 12:38:26 +00:00
|
|
|
static_assert(sizeof(DisplayList) == 456, "Bad DisplayList size");
|
2017-01-27 09:17:44 +00:00
|
|
|
listLock.set_enabled(g_Config.bSeparateCPUThread);
|
2015-10-11 12:38:26 +00:00
|
|
|
|
2013-11-28 23:34:41 +00:00
|
|
|
Reinitialize();
|
2015-05-23 17:33:24 +00:00
|
|
|
SetupColorConv();
|
2013-11-28 23:34:41 +00:00
|
|
|
SetThreadEnabled(g_Config.bSeparateCPUThread);
|
2016-01-06 22:49:02 +00:00
|
|
|
gstate.Reset();
|
|
|
|
gstate_c.Reset();
|
2016-04-02 08:28:38 +00:00
|
|
|
gpuStats.Reset();
|
2015-07-26 20:38:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GPUCommon::~GPUCommon() {
|
2013-11-28 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
2016-01-06 22:53:21 +00:00
|
|
|
void GPUCommon::BeginHostFrame() {
|
|
|
|
ReapplyGfxState();
|
2017-03-19 17:40:23 +00:00
|
|
|
|
|
|
|
// TODO: Assume config may have changed - maybe move to resize.
|
|
|
|
gstate_c.Dirty(DIRTY_ALL);
|
2016-01-06 22:53:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::EndHostFrame() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-12-21 17:51:19 +00:00
|
|
|
void GPUCommon::InitClear() {
|
|
|
|
ScheduleEvent(GPU_EVENT_INIT_CLEAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::CopyDisplayToOutput() {
|
|
|
|
ScheduleEvent(GPU_EVENT_COPY_DISPLAY_TO_OUTPUT);
|
|
|
|
}
|
|
|
|
|
2013-11-28 23:34:41 +00:00
|
|
|
void GPUCommon::Reinitialize() {
|
|
|
|
easy_guard guard(listLock);
|
2013-04-15 20:57:54 +00:00
|
|
|
memset(dls, 0, sizeof(dls));
|
2013-04-06 09:28:49 +00:00
|
|
|
for (int i = 0; i < DisplayListMaxCount; ++i) {
|
2013-04-05 06:19:28 +00:00
|
|
|
dls[i].state = PSP_GE_DL_STATE_NONE;
|
2013-04-07 19:45:42 +00:00
|
|
|
dls[i].waitTicks = 0;
|
2013-04-06 09:28:49 +00:00
|
|
|
}
|
2013-11-28 23:34:41 +00:00
|
|
|
|
|
|
|
nextListID = 0;
|
|
|
|
currentList = NULL;
|
|
|
|
isbreak = false;
|
|
|
|
drawCompleteTicks = 0;
|
|
|
|
busyTicks = 0;
|
2014-06-14 15:42:18 +00:00
|
|
|
timeSpentStepping_ = 0.0;
|
2013-11-28 23:34:41 +00:00
|
|
|
interruptsEnabled_ = true;
|
|
|
|
UpdateTickEstimate(0);
|
2016-12-21 17:51:19 +00:00
|
|
|
ScheduleEvent(GPU_EVENT_REINITIALIZE);
|
2013-04-05 06:19:28 +00:00
|
|
|
}
|
2012-12-28 20:58:00 +00:00
|
|
|
|
2017-01-23 20:00:44 +00:00
|
|
|
int GPUCommon::EstimatePerVertexCost() {
|
|
|
|
// TODO: This is transform cost, also account for rasterization cost somehow... although it probably
|
|
|
|
// runs in parallel with transform.
|
|
|
|
|
|
|
|
// Also, this is all pure guesswork. If we can find a way to do measurements, that would be great.
|
|
|
|
|
|
|
|
// GTA wants a low value to run smooth, GoW wants a high value (otherwise it thinks things
|
|
|
|
// went too fast and starts doing all the work over again).
|
|
|
|
|
|
|
|
int cost = 20;
|
|
|
|
if (gstate.isLightingEnabled()) {
|
|
|
|
cost += 10;
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
if (gstate.isLightChanEnabled(i))
|
|
|
|
cost += 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gstate.getUVGenMode() != GE_TEXMAP_TEXTURE_COORDS) {
|
|
|
|
cost += 20;
|
|
|
|
}
|
|
|
|
int morphCount = gstate.getNumMorphWeights();
|
|
|
|
if (morphCount > 1) {
|
|
|
|
cost += 5 * morphCount;
|
|
|
|
}
|
|
|
|
return cost;
|
|
|
|
}
|
|
|
|
|
2013-04-05 06:19:28 +00:00
|
|
|
void GPUCommon::PopDLQueue() {
|
2013-08-09 07:32:40 +00:00
|
|
|
easy_guard guard(listLock);
|
2013-04-05 06:19:28 +00:00
|
|
|
if(!dlQueue.empty()) {
|
|
|
|
dlQueue.pop_front();
|
|
|
|
if(!dlQueue.empty()) {
|
|
|
|
bool running = currentList->state == PSP_GE_DL_STATE_RUNNING;
|
|
|
|
currentList = &dls[dlQueue.front()];
|
|
|
|
if (running)
|
|
|
|
currentList->state = PSP_GE_DL_STATE_RUNNING;
|
|
|
|
} else {
|
|
|
|
currentList = NULL;
|
|
|
|
}
|
|
|
|
}
|
2012-12-28 20:58:00 +00:00
|
|
|
}
|
|
|
|
|
2013-09-22 02:31:54 +00:00
|
|
|
bool GPUCommon::BusyDrawing() {
|
|
|
|
u32 state = DrawSync(1);
|
|
|
|
if (state == PSP_GE_LIST_DRAWING || state == PSP_GE_LIST_STALLING) {
|
2017-01-27 09:17:44 +00:00
|
|
|
easy_guard guard(listLock);
|
2013-09-22 02:31:54 +00:00
|
|
|
if (currentList && currentList->state != PSP_GE_DL_STATE_PAUSED) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-21 17:13:58 +00:00
|
|
|
void GPUCommon::Resized() {
|
|
|
|
resized_ = true;
|
|
|
|
}
|
|
|
|
|
2017-06-03 02:39:11 +00:00
|
|
|
void GPUCommon::DumpNextFrame() {
|
|
|
|
dumpNextFrame_ = true;
|
|
|
|
}
|
|
|
|
|
2013-04-01 06:23:03 +00:00
|
|
|
u32 GPUCommon::DrawSync(int mode) {
|
2014-12-21 00:11:19 +00:00
|
|
|
if (ThreadEnabled()) {
|
2013-08-14 19:44:20 +00:00
|
|
|
// Sync first, because the CPU is usually faster than the emulated GPU.
|
|
|
|
SyncThread();
|
|
|
|
}
|
2013-08-10 22:16:49 +00:00
|
|
|
|
2013-08-09 07:32:40 +00:00
|
|
|
easy_guard guard(listLock);
|
2013-04-01 06:42:56 +00:00
|
|
|
if (mode < 0 || mode > 1)
|
|
|
|
return SCE_KERNEL_ERROR_INVALID_MODE;
|
|
|
|
|
2013-04-04 06:31:01 +00:00
|
|
|
if (mode == 0) {
|
2013-08-28 15:13:44 +00:00
|
|
|
if (!__KernelIsDispatchEnabled()) {
|
|
|
|
return SCE_KERNEL_ERROR_CAN_NOT_WAIT;
|
|
|
|
}
|
2013-08-29 06:15:13 +00:00
|
|
|
if (__IsInInterrupt()) {
|
|
|
|
return SCE_KERNEL_ERROR_ILLEGAL_CONTEXT;
|
|
|
|
}
|
2013-08-28 15:13:44 +00:00
|
|
|
|
2013-04-07 19:45:42 +00:00
|
|
|
if (drawCompleteTicks > CoreTiming::GetTicks()) {
|
2014-03-30 00:02:41 +00:00
|
|
|
__GeWaitCurrentThread(GPU_SYNC_DRAW, 1, "GeDrawSync");
|
2013-04-06 05:38:19 +00:00
|
|
|
} else {
|
|
|
|
for (int i = 0; i < DisplayListMaxCount; ++i) {
|
|
|
|
if (dls[i].state == PSP_GE_DL_STATE_COMPLETED) {
|
|
|
|
dls[i].state = PSP_GE_DL_STATE_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-04 06:31:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-06 05:38:19 +00:00
|
|
|
// If there's no current list, it must be complete.
|
|
|
|
DisplayList *top = NULL;
|
|
|
|
for (auto it = dlQueue.begin(), end = dlQueue.end(); it != end; ++it) {
|
|
|
|
if (dls[*it].state != PSP_GE_DL_STATE_COMPLETED) {
|
|
|
|
top = &dls[*it];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!top || top->state == PSP_GE_DL_STATE_COMPLETED)
|
2013-04-04 06:31:01 +00:00
|
|
|
return PSP_GE_LIST_COMPLETED;
|
|
|
|
|
|
|
|
if (currentList->pc == currentList->stall)
|
|
|
|
return PSP_GE_LIST_STALLING;
|
|
|
|
|
|
|
|
return PSP_GE_LIST_DRAWING;
|
2013-04-01 06:23:03 +00:00
|
|
|
}
|
|
|
|
|
2013-08-09 07:32:40 +00:00
|
|
|
void GPUCommon::CheckDrawSync() {
|
|
|
|
easy_guard guard(listLock);
|
2013-04-05 06:19:28 +00:00
|
|
|
if (dlQueue.empty()) {
|
|
|
|
for (int i = 0; i < DisplayListMaxCount; ++i)
|
|
|
|
dls[i].state = PSP_GE_DL_STATE_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-09 07:32:40 +00:00
|
|
|
int GPUCommon::ListSync(int listid, int mode) {
|
2014-12-21 00:11:19 +00:00
|
|
|
if (ThreadEnabled()) {
|
2013-08-14 19:44:20 +00:00
|
|
|
// Sync first, because the CPU is usually faster than the emulated GPU.
|
|
|
|
SyncThread();
|
|
|
|
}
|
2013-08-10 22:16:49 +00:00
|
|
|
|
2013-08-09 07:32:40 +00:00
|
|
|
easy_guard guard(listLock);
|
2013-04-05 06:19:28 +00:00
|
|
|
if (listid < 0 || listid >= DisplayListMaxCount)
|
|
|
|
return SCE_KERNEL_ERROR_INVALID_ID;
|
|
|
|
|
2013-04-01 06:42:56 +00:00
|
|
|
if (mode < 0 || mode > 1)
|
|
|
|
return SCE_KERNEL_ERROR_INVALID_MODE;
|
|
|
|
|
2013-04-06 09:28:49 +00:00
|
|
|
DisplayList& dl = dls[listid];
|
2013-04-04 06:05:54 +00:00
|
|
|
if (mode == 1) {
|
2013-04-05 06:19:28 +00:00
|
|
|
switch (dl.state) {
|
2013-04-04 06:05:54 +00:00
|
|
|
case PSP_GE_DL_STATE_QUEUED:
|
2013-04-05 06:19:28 +00:00
|
|
|
if (dl.interrupted)
|
2013-04-04 07:35:38 +00:00
|
|
|
return PSP_GE_LIST_PAUSED;
|
2013-04-04 06:05:54 +00:00
|
|
|
return PSP_GE_LIST_QUEUED;
|
|
|
|
|
|
|
|
case PSP_GE_DL_STATE_RUNNING:
|
2013-04-05 06:19:28 +00:00
|
|
|
if (dl.pc == dl.stall)
|
2013-04-04 06:05:54 +00:00
|
|
|
return PSP_GE_LIST_STALLING;
|
|
|
|
return PSP_GE_LIST_DRAWING;
|
|
|
|
|
|
|
|
case PSP_GE_DL_STATE_COMPLETED:
|
|
|
|
return PSP_GE_LIST_COMPLETED;
|
|
|
|
|
|
|
|
case PSP_GE_DL_STATE_PAUSED:
|
|
|
|
return PSP_GE_LIST_PAUSED;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return SCE_KERNEL_ERROR_INVALID_ID;
|
2012-12-28 20:58:00 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-04 06:05:54 +00:00
|
|
|
|
2013-08-28 15:13:44 +00:00
|
|
|
if (!__KernelIsDispatchEnabled()) {
|
|
|
|
return SCE_KERNEL_ERROR_CAN_NOT_WAIT;
|
2013-08-29 06:15:13 +00:00
|
|
|
}
|
|
|
|
if (__IsInInterrupt()) {
|
|
|
|
return SCE_KERNEL_ERROR_ILLEGAL_CONTEXT;
|
2013-08-28 15:13:44 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 19:45:42 +00:00
|
|
|
if (dl.waitTicks > CoreTiming::GetTicks()) {
|
2014-03-30 00:02:41 +00:00
|
|
|
__GeWaitCurrentThread(GPU_SYNC_LIST, listid, "GeListSync");
|
2013-04-06 09:28:49 +00:00
|
|
|
}
|
2013-04-04 06:05:54 +00:00
|
|
|
return PSP_GE_LIST_COMPLETED;
|
2012-12-28 20:58:00 +00:00
|
|
|
}
|
|
|
|
|
2013-09-21 17:03:49 +00:00
|
|
|
int GPUCommon::GetStack(int index, u32 stackPtr) {
|
|
|
|
easy_guard guard(listLock);
|
|
|
|
if (currentList == NULL) {
|
|
|
|
// Seems like it doesn't return an error code?
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentList->stackptr <= index) {
|
|
|
|
return SCE_KERNEL_ERROR_INVALID_INDEX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index >= 0) {
|
2013-12-17 07:47:34 +00:00
|
|
|
auto stack = PSPPointer<u32>::Create(stackPtr);
|
2013-09-21 17:03:49 +00:00
|
|
|
if (stack.IsValid()) {
|
|
|
|
auto entry = currentList->stack[index];
|
|
|
|
// Not really sure what most of these values are.
|
|
|
|
stack[0] = 0;
|
|
|
|
stack[1] = entry.pc + 4;
|
|
|
|
stack[2] = entry.offsetAddr;
|
|
|
|
stack[7] = entry.baseAddr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return currentList->stackptr;
|
|
|
|
}
|
|
|
|
|
2013-09-20 16:42:09 +00:00
|
|
|
u32 GPUCommon::EnqueueList(u32 listpc, u32 stall, int subIntrBase, PSPPointer<PspGeListArgs> args, bool head) {
|
2013-08-09 07:32:40 +00:00
|
|
|
easy_guard guard(listLock);
|
2013-04-04 07:04:24 +00:00
|
|
|
// TODO Check the stack values in missing arg and ajust the stack depth
|
|
|
|
|
|
|
|
// Check alignment
|
|
|
|
// TODO Check the context and stack alignement too
|
|
|
|
if (((listpc | stall) & 3) != 0)
|
2013-09-29 23:51:49 +00:00
|
|
|
return SCE_KERNEL_ERROR_INVALID_POINTER;
|
2013-04-04 07:04:24 +00:00
|
|
|
|
2013-04-05 06:19:28 +00:00
|
|
|
int id = -1;
|
2013-10-26 17:38:59 +00:00
|
|
|
u64 currentTicks = CoreTiming::GetTicks();
|
2014-08-13 13:15:30 +00:00
|
|
|
u32_le stackAddr = args.IsValid() ? args->stackAddr : 0;
|
2013-10-26 17:38:59 +00:00
|
|
|
// Check compatibility
|
2013-04-05 06:19:28 +00:00
|
|
|
if (sceKernelGetCompiledSdkVersion() > 0x01FFFFFF) {
|
|
|
|
//numStacks = 0;
|
|
|
|
//stack = NULL;
|
2013-10-26 17:38:59 +00:00
|
|
|
for (int i = 0; i < DisplayListMaxCount; ++i) {
|
|
|
|
if (dls[i].state != PSP_GE_DL_STATE_NONE && dls[i].state != PSP_GE_DL_STATE_COMPLETED) {
|
2014-05-26 01:52:31 +00:00
|
|
|
// Logically, if the CPU has not interrupted yet, it hasn't seen the latest pc either.
|
|
|
|
// Exit enqueues right after an END, which fails without ignoring pendingInterrupt lists.
|
|
|
|
if (dls[i].pc == listpc && !dls[i].pendingInterrupt) {
|
2013-10-26 17:38:59 +00:00
|
|
|
ERROR_LOG(G3D, "sceGeListEnqueue: can't enqueue, list address %08X already used", listpc);
|
|
|
|
return 0x80000021;
|
2014-08-18 23:04:36 +00:00
|
|
|
} else if (stackAddr != 0 && dls[i].stackAddr == stackAddr && !dls[i].pendingInterrupt) {
|
2014-08-13 13:15:30 +00:00
|
|
|
ERROR_LOG(G3D, "sceGeListEnqueue: can't enqueue, stack address %08X already used", stackAddr);
|
|
|
|
return 0x80000021;
|
|
|
|
}
|
2013-04-05 06:19:28 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-21 20:18:20 +00:00
|
|
|
}
|
2013-10-27 13:09:46 +00:00
|
|
|
// TODO Check if list stack dls[i].stack already used then return 0x80000021 as above
|
2013-10-26 17:38:59 +00:00
|
|
|
|
2013-09-21 20:18:20 +00:00
|
|
|
for (int i = 0; i < DisplayListMaxCount; ++i) {
|
|
|
|
int possibleID = (i + nextListID) % DisplayListMaxCount;
|
|
|
|
auto possibleList = dls[possibleID];
|
|
|
|
if (possibleList.pendingInterrupt) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (possibleList.state == PSP_GE_DL_STATE_NONE) {
|
|
|
|
id = possibleID;
|
2013-04-05 06:19:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-09-21 20:18:20 +00:00
|
|
|
if (possibleList.state == PSP_GE_DL_STATE_COMPLETED && possibleList.waitTicks < currentTicks) {
|
|
|
|
id = possibleID;
|
2013-04-05 06:19:28 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-21 20:18:20 +00:00
|
|
|
if (id < 0) {
|
2013-04-05 08:13:54 +00:00
|
|
|
ERROR_LOG_REPORT(G3D, "No DL ID available to enqueue");
|
2013-09-21 20:18:20 +00:00
|
|
|
for (auto it = dlQueue.begin(); it != dlQueue.end(); ++it) {
|
2013-04-05 06:19:28 +00:00
|
|
|
DisplayList &dl = dls[*it];
|
|
|
|
DEBUG_LOG(G3D, "DisplayList %d status %d pc %08x stall %08x", *it, dl.state, dl.pc, dl.stall);
|
|
|
|
}
|
|
|
|
return SCE_KERNEL_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2013-09-21 20:18:20 +00:00
|
|
|
nextListID = id + 1;
|
2013-04-05 06:19:28 +00:00
|
|
|
|
|
|
|
DisplayList &dl = dls[id];
|
|
|
|
dl.id = id;
|
2013-08-23 06:23:48 +00:00
|
|
|
dl.startpc = listpc & 0x0FFFFFFF;
|
|
|
|
dl.pc = listpc & 0x0FFFFFFF;
|
|
|
|
dl.stall = stall & 0x0FFFFFFF;
|
2013-04-02 06:54:19 +00:00
|
|
|
dl.subIntrBase = std::max(subIntrBase, -1);
|
2013-04-01 06:28:35 +00:00
|
|
|
dl.stackptr = 0;
|
2013-04-02 06:54:19 +00:00
|
|
|
dl.signal = PSP_GE_SIGNAL_NONE;
|
2013-04-04 07:35:38 +00:00
|
|
|
dl.interrupted = false;
|
2013-04-07 19:45:42 +00:00
|
|
|
dl.waitTicks = (u64)-1;
|
2013-08-07 06:59:28 +00:00
|
|
|
dl.interruptsEnabled = interruptsEnabled_;
|
2013-09-20 16:42:09 +00:00
|
|
|
dl.started = false;
|
2013-09-22 03:47:35 +00:00
|
|
|
dl.offsetAddr = 0;
|
2013-09-24 10:59:34 +00:00
|
|
|
dl.bboxResult = false;
|
2014-08-13 13:15:30 +00:00
|
|
|
dl.stackAddr = stackAddr;
|
2013-09-24 10:59:34 +00:00
|
|
|
|
2013-09-20 16:42:09 +00:00
|
|
|
if (args.IsValid() && args->context.IsValid())
|
|
|
|
dl.context = args->context;
|
|
|
|
else
|
2013-10-07 05:07:57 +00:00
|
|
|
dl.context = 0;
|
2013-04-05 06:19:28 +00:00
|
|
|
|
2013-04-04 07:04:24 +00:00
|
|
|
if (head) {
|
|
|
|
if (currentList) {
|
|
|
|
if (currentList->state != PSP_GE_DL_STATE_PAUSED)
|
|
|
|
return SCE_KERNEL_ERROR_INVALID_VALUE;
|
|
|
|
currentList->state = PSP_GE_DL_STATE_QUEUED;
|
|
|
|
}
|
|
|
|
|
|
|
|
dl.state = PSP_GE_DL_STATE_PAUSED;
|
2013-04-05 06:19:28 +00:00
|
|
|
|
|
|
|
currentList = &dl;
|
|
|
|
dlQueue.push_front(id);
|
2013-04-04 07:04:24 +00:00
|
|
|
} else if (currentList) {
|
|
|
|
dl.state = PSP_GE_DL_STATE_QUEUED;
|
2013-04-05 06:19:28 +00:00
|
|
|
dlQueue.push_back(id);
|
2013-04-04 07:04:24 +00:00
|
|
|
} else {
|
|
|
|
dl.state = PSP_GE_DL_STATE_RUNNING;
|
2013-04-05 06:19:28 +00:00
|
|
|
currentList = &dl;
|
|
|
|
dlQueue.push_front(id);
|
2013-04-04 07:04:24 +00:00
|
|
|
|
2013-04-07 19:45:42 +00:00
|
|
|
drawCompleteTicks = (u64)-1;
|
2013-04-06 05:38:19 +00:00
|
|
|
|
2013-04-04 07:04:24 +00:00
|
|
|
// TODO save context when starting the list if param is set
|
2013-08-09 07:32:40 +00:00
|
|
|
guard.unlock();
|
2013-04-04 07:04:24 +00:00
|
|
|
ProcessDLQueue();
|
|
|
|
}
|
|
|
|
|
2013-04-05 06:19:28 +00:00
|
|
|
return id;
|
2012-12-28 20:58:00 +00:00
|
|
|
}
|
|
|
|
|
2013-08-09 07:32:40 +00:00
|
|
|
u32 GPUCommon::DequeueList(int listid) {
|
|
|
|
easy_guard guard(listLock);
|
2013-04-05 06:25:13 +00:00
|
|
|
if (listid < 0 || listid >= DisplayListMaxCount || dls[listid].state == PSP_GE_DL_STATE_NONE)
|
|
|
|
return SCE_KERNEL_ERROR_INVALID_ID;
|
|
|
|
|
2013-09-21 21:58:39 +00:00
|
|
|
auto &dl = dls[listid];
|
|
|
|
if (dl.started)
|
|
|
|
return SCE_KERNEL_ERROR_BUSY;
|
2013-04-05 06:25:13 +00:00
|
|
|
|
2013-09-21 21:58:39 +00:00
|
|
|
dl.state = PSP_GE_DL_STATE_NONE;
|
2013-04-05 06:25:13 +00:00
|
|
|
|
|
|
|
if (listid == dlQueue.front())
|
|
|
|
PopDLQueue();
|
|
|
|
else
|
|
|
|
dlQueue.remove(listid);
|
|
|
|
|
2013-09-21 21:58:39 +00:00
|
|
|
dl.waitTicks = 0;
|
2014-03-30 00:02:41 +00:00
|
|
|
__GeTriggerWait(GPU_SYNC_LIST, listid);
|
2013-04-05 06:25:13 +00:00
|
|
|
|
|
|
|
CheckDrawSync();
|
|
|
|
|
2013-04-01 06:23:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-09 07:32:40 +00:00
|
|
|
u32 GPUCommon::UpdateStall(int listid, u32 newstall) {
|
|
|
|
easy_guard guard(listLock);
|
2013-04-05 06:19:28 +00:00
|
|
|
if (listid < 0 || listid >= DisplayListMaxCount || dls[listid].state == PSP_GE_DL_STATE_NONE)
|
2013-04-05 06:25:13 +00:00
|
|
|
return SCE_KERNEL_ERROR_INVALID_ID;
|
2013-09-21 21:54:07 +00:00
|
|
|
auto &dl = dls[listid];
|
|
|
|
if (dl.state == PSP_GE_DL_STATE_COMPLETED)
|
|
|
|
return SCE_KERNEL_ERROR_ALREADY;
|
2013-04-05 06:19:28 +00:00
|
|
|
|
2013-09-21 21:54:07 +00:00
|
|
|
dl.stall = newstall & 0x0FFFFFFF;
|
2012-12-28 20:58:00 +00:00
|
|
|
|
2013-08-09 07:32:40 +00:00
|
|
|
guard.unlock();
|
2012-12-28 20:58:00 +00:00
|
|
|
ProcessDLQueue();
|
2013-04-01 06:23:03 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-09 07:32:40 +00:00
|
|
|
u32 GPUCommon::Continue() {
|
|
|
|
easy_guard guard(listLock);
|
2013-04-04 07:35:38 +00:00
|
|
|
if (!currentList)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (currentList->state == PSP_GE_DL_STATE_PAUSED)
|
|
|
|
{
|
|
|
|
if (!isbreak)
|
|
|
|
{
|
2014-04-12 06:32:34 +00:00
|
|
|
// TODO: Supposedly this returns SCE_KERNEL_ERROR_BUSY in some case, previously it had
|
|
|
|
// currentList->signal == PSP_GE_SIGNAL_HANDLER_PAUSE, but it doesn't reproduce.
|
2013-04-04 07:35:38 +00:00
|
|
|
|
|
|
|
currentList->state = PSP_GE_DL_STATE_RUNNING;
|
|
|
|
currentList->signal = PSP_GE_SIGNAL_NONE;
|
|
|
|
|
|
|
|
// TODO Restore context of DL is necessary
|
|
|
|
// TODO Restore BASE
|
2013-04-06 05:38:19 +00:00
|
|
|
|
|
|
|
// We have a list now, so it's not complete.
|
2013-04-07 19:45:42 +00:00
|
|
|
drawCompleteTicks = (u64)-1;
|
2013-04-04 07:35:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
currentList->state = PSP_GE_DL_STATE_QUEUED;
|
|
|
|
}
|
|
|
|
else if (currentList->state == PSP_GE_DL_STATE_RUNNING)
|
|
|
|
{
|
|
|
|
if (sceKernelGetCompiledSdkVersion() >= 0x02000000)
|
|
|
|
return 0x80000020;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (sceKernelGetCompiledSdkVersion() >= 0x02000000)
|
|
|
|
return 0x80000004;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-08-09 07:32:40 +00:00
|
|
|
guard.unlock();
|
2013-04-04 07:35:38 +00:00
|
|
|
ProcessDLQueue();
|
2013-04-01 06:23:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-09 07:32:40 +00:00
|
|
|
u32 GPUCommon::Break(int mode) {
|
|
|
|
easy_guard guard(listLock);
|
2013-04-01 06:42:56 +00:00
|
|
|
if (mode < 0 || mode > 1)
|
|
|
|
return SCE_KERNEL_ERROR_INVALID_MODE;
|
|
|
|
|
2013-04-04 07:35:38 +00:00
|
|
|
if (!currentList)
|
2013-09-22 02:07:02 +00:00
|
|
|
return SCE_KERNEL_ERROR_ALREADY;
|
2013-04-04 07:35:38 +00:00
|
|
|
|
2013-04-05 06:19:28 +00:00
|
|
|
if (mode == 1)
|
2013-04-04 07:35:38 +00:00
|
|
|
{
|
2013-04-05 06:19:28 +00:00
|
|
|
// Clear the queue
|
2013-04-04 07:35:38 +00:00
|
|
|
dlQueue.clear();
|
2013-04-05 06:19:28 +00:00
|
|
|
for (int i = 0; i < DisplayListMaxCount; ++i)
|
|
|
|
{
|
|
|
|
dls[i].state = PSP_GE_DL_STATE_NONE;
|
|
|
|
dls[i].signal = PSP_GE_SIGNAL_NONE;
|
|
|
|
}
|
|
|
|
|
2013-09-21 20:18:20 +00:00
|
|
|
nextListID = 0;
|
2013-04-05 06:19:28 +00:00
|
|
|
currentList = NULL;
|
2013-04-04 07:35:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentList->state == PSP_GE_DL_STATE_NONE || currentList->state == PSP_GE_DL_STATE_COMPLETED)
|
|
|
|
{
|
|
|
|
if (sceKernelGetCompiledSdkVersion() >= 0x02000000)
|
|
|
|
return 0x80000004;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentList->state == PSP_GE_DL_STATE_PAUSED)
|
|
|
|
{
|
|
|
|
if (sceKernelGetCompiledSdkVersion() > 0x02000010)
|
|
|
|
{
|
|
|
|
if (currentList->signal == PSP_GE_SIGNAL_HANDLER_PAUSE)
|
|
|
|
{
|
2013-04-05 08:13:54 +00:00
|
|
|
ERROR_LOG_REPORT(G3D, "sceGeBreak: can't break signal-pausing list");
|
2013-04-04 07:35:38 +00:00
|
|
|
}
|
|
|
|
else
|
2013-09-22 02:07:02 +00:00
|
|
|
return SCE_KERNEL_ERROR_ALREADY;
|
2013-04-04 07:35:38 +00:00
|
|
|
}
|
2013-09-22 02:07:02 +00:00
|
|
|
return SCE_KERNEL_ERROR_BUSY;
|
2013-04-04 07:35:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (currentList->state == PSP_GE_DL_STATE_QUEUED)
|
|
|
|
{
|
|
|
|
currentList->state = PSP_GE_DL_STATE_PAUSED;
|
|
|
|
return currentList->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO Save BASE
|
|
|
|
// TODO Adjust pc to be just before SIGNAL/END
|
|
|
|
|
|
|
|
// TODO: Is this right?
|
|
|
|
if (currentList->signal == PSP_GE_SIGNAL_SYNC)
|
|
|
|
currentList->pc += 8;
|
|
|
|
|
|
|
|
currentList->interrupted = true;
|
|
|
|
currentList->state = PSP_GE_DL_STATE_PAUSED;
|
|
|
|
currentList->signal = PSP_GE_SIGNAL_HANDLER_SUSPEND;
|
|
|
|
isbreak = true;
|
|
|
|
|
|
|
|
return currentList->id;
|
2012-12-29 01:10:29 +00:00
|
|
|
}
|
|
|
|
|
2014-06-14 15:42:18 +00:00
|
|
|
void GPUCommon::NotifySteppingEnter() {
|
2017-03-24 01:57:18 +00:00
|
|
|
if (coreCollectDebugStats) {
|
2014-06-14 15:42:18 +00:00
|
|
|
time_update();
|
|
|
|
timeSteppingStarted_ = time_now_d();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void GPUCommon::NotifySteppingExit() {
|
2017-03-24 01:57:18 +00:00
|
|
|
if (coreCollectDebugStats) {
|
2014-06-14 15:42:18 +00:00
|
|
|
if (timeSteppingStarted_ <= 0.0) {
|
|
|
|
ERROR_LOG(G3D, "Mismatched stepping enter/exit.");
|
|
|
|
}
|
|
|
|
time_update();
|
|
|
|
timeSpentStepping_ += time_now_d() - timeSteppingStarted_;
|
|
|
|
timeSteppingStarted_ = 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-09 06:46:10 +00:00
|
|
|
bool GPUCommon::InterpretList(DisplayList &list) {
|
2013-04-21 22:16:45 +00:00
|
|
|
// Initialized to avoid a race condition with bShowDebugStats changing.
|
|
|
|
double start = 0.0;
|
2017-03-24 01:57:18 +00:00
|
|
|
if (coreCollectDebugStats) {
|
2013-04-21 22:16:45 +00:00
|
|
|
time_update();
|
|
|
|
start = time_now_d();
|
|
|
|
}
|
|
|
|
|
2013-08-09 07:32:40 +00:00
|
|
|
easy_guard guard(listLock);
|
2013-08-09 06:46:10 +00:00
|
|
|
|
2014-04-12 06:32:34 +00:00
|
|
|
if (list.state == PSP_GE_DL_STATE_PAUSED)
|
|
|
|
return false;
|
2013-08-09 07:32:40 +00:00
|
|
|
currentList = &list;
|
2013-04-06 16:59:24 +00:00
|
|
|
|
2013-10-07 05:07:57 +00:00
|
|
|
if (!list.started && list.context.IsValid()) {
|
2013-09-20 16:42:09 +00:00
|
|
|
gstate.Save(list.context);
|
|
|
|
}
|
|
|
|
list.started = true;
|
|
|
|
|
2013-09-22 03:47:35 +00:00
|
|
|
gstate_c.offsetAddr = list.offsetAddr;
|
2013-01-29 16:07:36 +00:00
|
|
|
|
2013-08-09 07:32:40 +00:00
|
|
|
if (!Memory::IsValidAddress(list.pc)) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "DL PC = %08x WTF!!!!", list.pc);
|
|
|
|
return true;
|
|
|
|
}
|
2013-02-02 22:47:35 +00:00
|
|
|
|
2013-08-09 07:32:40 +00:00
|
|
|
cycleLastPC = list.pc;
|
2013-10-12 08:20:27 +00:00
|
|
|
cyclesExecuted += 60;
|
2013-08-23 06:23:48 +00:00
|
|
|
downcount = list.stall == 0 ? 0x0FFFFFFF : (list.stall - list.pc) / 4;
|
2013-08-09 07:32:40 +00:00
|
|
|
list.state = PSP_GE_DL_STATE_RUNNING;
|
|
|
|
list.interrupted = false;
|
2013-04-03 15:10:35 +00:00
|
|
|
|
2013-08-09 07:32:40 +00:00
|
|
|
gpuState = list.pc == list.stall ? GPUSTATE_STALL : GPUSTATE_RUNNING;
|
|
|
|
guard.unlock();
|
2013-04-28 21:56:38 +00:00
|
|
|
|
2017-06-03 22:03:59 +00:00
|
|
|
debugRecording_ = GPURecord::IsActive();
|
|
|
|
const bool useDebugger = host->GPUDebuggingActive() || debugRecording_;
|
2013-09-22 07:18:46 +00:00
|
|
|
const bool useFastRunLoop = !dumpThisFrame_ && !useDebugger;
|
2013-08-09 06:46:10 +00:00
|
|
|
while (gpuState == GPUSTATE_RUNNING) {
|
2013-08-09 08:03:54 +00:00
|
|
|
{
|
|
|
|
easy_guard innerGuard(listLock);
|
|
|
|
if (list.pc == list.stall) {
|
|
|
|
gpuState = GPUSTATE_STALL;
|
|
|
|
downcount = 0;
|
|
|
|
}
|
2013-04-04 08:07:30 +00:00
|
|
|
}
|
2013-02-17 00:06:06 +00:00
|
|
|
|
2013-08-09 06:46:10 +00:00
|
|
|
if (useFastRunLoop) {
|
2013-04-28 21:23:30 +00:00
|
|
|
FastRunLoop(list);
|
2013-08-09 06:46:10 +00:00
|
|
|
} else {
|
2013-04-28 21:23:30 +00:00
|
|
|
SlowRunLoop(list);
|
2013-08-09 06:46:10 +00:00
|
|
|
}
|
2013-04-28 21:23:30 +00:00
|
|
|
|
2013-08-09 08:03:54 +00:00
|
|
|
{
|
|
|
|
easy_guard innerGuard(listLock);
|
2013-08-23 06:23:48 +00:00
|
|
|
downcount = list.stall == 0 ? 0x0FFFFFFF : (list.stall - list.pc) / 4;
|
2013-08-09 06:46:10 +00:00
|
|
|
|
2013-08-09 08:03:54 +00:00
|
|
|
if (gpuState == GPUSTATE_STALL && list.stall != list.pc) {
|
|
|
|
// Unstalled.
|
|
|
|
gpuState = GPUSTATE_RUNNING;
|
|
|
|
}
|
2013-08-09 06:46:10 +00:00
|
|
|
}
|
2013-04-28 21:23:30 +00:00
|
|
|
}
|
|
|
|
|
2015-03-15 01:11:00 +00:00
|
|
|
FinishDeferred();
|
|
|
|
|
2013-04-28 21:23:30 +00:00
|
|
|
// We haven't run the op at list.pc, so it shouldn't count.
|
2013-08-09 06:46:10 +00:00
|
|
|
if (cycleLastPC != list.pc) {
|
2013-04-28 21:23:30 +00:00
|
|
|
UpdatePC(list.pc - 4, list.pc);
|
2013-08-09 06:46:10 +00:00
|
|
|
}
|
2013-04-28 21:23:30 +00:00
|
|
|
|
2013-09-22 03:47:35 +00:00
|
|
|
list.offsetAddr = gstate_c.offsetAddr;
|
|
|
|
|
2017-03-24 01:57:18 +00:00
|
|
|
if (coreCollectDebugStats) {
|
2013-04-28 21:23:30 +00:00
|
|
|
time_update();
|
2014-06-14 15:42:18 +00:00
|
|
|
double total = time_now_d() - start - timeSpentStepping_;
|
|
|
|
hleSetSteppingTime(timeSpentStepping_);
|
|
|
|
timeSpentStepping_ = 0.0;
|
|
|
|
gpuStats.msProcessingDisplayLists += total;
|
2013-04-28 21:23:30 +00:00
|
|
|
}
|
|
|
|
return gpuState == GPUSTATE_DONE || gpuState == GPUSTATE_ERROR;
|
|
|
|
}
|
|
|
|
|
2017-06-04 05:28:29 +00:00
|
|
|
void GPUCommon::BeginFrame() {
|
|
|
|
ScheduleEvent(GPU_EVENT_BEGIN_FRAME);
|
|
|
|
}
|
|
|
|
|
2017-06-03 02:39:11 +00:00
|
|
|
void GPUCommon::BeginFrameInternal() {
|
|
|
|
if (dumpNextFrame_) {
|
|
|
|
NOTICE_LOG(G3D, "DUMPING THIS FRAME");
|
|
|
|
dumpThisFrame_ = true;
|
|
|
|
dumpNextFrame_ = false;
|
|
|
|
} else if (dumpThisFrame_) {
|
|
|
|
dumpThisFrame_ = false;
|
|
|
|
}
|
2017-06-03 04:53:20 +00:00
|
|
|
GPURecord::NotifyFrame();
|
2017-06-03 02:39:11 +00:00
|
|
|
}
|
|
|
|
|
2013-04-28 21:23:30 +00:00
|
|
|
void GPUCommon::SlowRunLoop(DisplayList &list)
|
|
|
|
{
|
|
|
|
const bool dumpThisFrame = dumpThisFrame_;
|
|
|
|
while (downcount > 0)
|
|
|
|
{
|
2013-09-22 07:18:46 +00:00
|
|
|
host->GPUNotifyCommand(list.pc);
|
2017-06-03 04:53:20 +00:00
|
|
|
GPURecord::NotifyCommand(list.pc);
|
2013-04-28 21:23:30 +00:00
|
|
|
u32 op = Memory::ReadUnchecked_U32(list.pc);
|
2013-02-17 00:06:06 +00:00
|
|
|
u32 cmd = op >> 24;
|
|
|
|
|
2012-12-29 01:10:29 +00:00
|
|
|
u32 diff = op ^ gstate.cmdmem[cmd];
|
|
|
|
PreExecuteOp(op, diff);
|
2013-04-20 22:23:35 +00:00
|
|
|
if (dumpThisFrame) {
|
2012-12-29 01:10:29 +00:00
|
|
|
char temp[256];
|
2013-10-07 20:57:44 +00:00
|
|
|
u32 prev;
|
|
|
|
if (Memory::IsValidAddress(list.pc - 4)) {
|
|
|
|
prev = Memory::ReadUnchecked_U32(list.pc - 4);
|
|
|
|
} else {
|
|
|
|
prev = 0;
|
|
|
|
}
|
2014-09-13 21:50:42 +00:00
|
|
|
GeDisassembleOp(list.pc, op, prev, temp, 256);
|
2015-02-01 09:21:04 +00:00
|
|
|
NOTICE_LOG(G3D, "%08x: %s", op, temp);
|
2012-12-29 01:10:29 +00:00
|
|
|
}
|
2013-04-04 08:07:30 +00:00
|
|
|
gstate.cmdmem[cmd] = op;
|
2013-04-03 15:10:35 +00:00
|
|
|
|
2013-04-28 21:23:30 +00:00
|
|
|
ExecuteOp(op, diff);
|
2013-04-03 15:10:35 +00:00
|
|
|
|
2013-04-28 21:23:30 +00:00
|
|
|
list.pc += 4;
|
|
|
|
--downcount;
|
2013-04-21 22:16:45 +00:00
|
|
|
}
|
2012-12-29 01:10:29 +00:00
|
|
|
}
|
|
|
|
|
2013-04-28 20:34:29 +00:00
|
|
|
// The newPC parameter is used for jumps, we don't count cycles between.
|
2014-03-04 10:38:25 +00:00
|
|
|
void GPUCommon::UpdatePC(u32 currentPC, u32 newPC) {
|
2013-04-07 23:55:48 +00:00
|
|
|
// Rough estimate, 2 CPU ticks (it's double the clock rate) per GPU instruction.
|
2014-04-05 08:41:54 +00:00
|
|
|
u32 executed = (currentPC - cycleLastPC) / 4;
|
2013-08-23 09:42:15 +00:00
|
|
|
cyclesExecuted += 2 * executed;
|
2014-04-05 21:08:44 +00:00
|
|
|
cycleLastPC = newPC;
|
2013-04-28 21:23:30 +00:00
|
|
|
|
2017-03-24 01:57:18 +00:00
|
|
|
if (coreCollectDebugStats) {
|
2014-04-05 08:41:54 +00:00
|
|
|
gpuStats.otherGPUCycles += 2 * executed;
|
|
|
|
gpuStats.gpuCommandsAtCallLevel[std::min(currentList->stackptr, 3)] += executed;
|
|
|
|
}
|
2013-08-23 09:26:13 +00:00
|
|
|
|
2014-03-06 07:24:18 +00:00
|
|
|
// Exit the runloop and recalculate things. This happens a lot in some games.
|
2017-02-27 20:57:46 +00:00
|
|
|
// No need to lock, this function is always called under listLock.
|
2014-03-06 07:24:18 +00:00
|
|
|
if (currentList)
|
2014-04-05 21:08:44 +00:00
|
|
|
downcount = currentList->stall == 0 ? 0x0FFFFFFF : (currentList->stall - newPC) / 4;
|
2014-03-06 07:24:18 +00:00
|
|
|
else
|
|
|
|
downcount = 0;
|
2013-04-28 20:34:29 +00:00
|
|
|
}
|
|
|
|
|
2013-08-08 06:59:32 +00:00
|
|
|
void GPUCommon::ReapplyGfxState() {
|
2013-08-09 07:32:40 +00:00
|
|
|
if (IsOnSeparateCPUThread()) {
|
|
|
|
ScheduleEvent(GPU_EVENT_REAPPLY_GFX_STATE);
|
|
|
|
} else {
|
|
|
|
ReapplyGfxStateInternal();
|
|
|
|
}
|
2013-08-08 06:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::ReapplyGfxStateInternal() {
|
2013-08-04 22:15:50 +00:00
|
|
|
// The commands are embedded in the command memory so we can just reexecute the words. Convenient.
|
2013-08-23 06:23:48 +00:00
|
|
|
// To be safe we pass 0xFFFFFFFF as the diff.
|
2013-08-04 22:15:50 +00:00
|
|
|
|
2013-08-08 06:59:32 +00:00
|
|
|
for (int i = GE_CMD_VERTEXTYPE; i < GE_CMD_BONEMATRIXNUMBER; i++) {
|
2014-04-16 14:53:07 +00:00
|
|
|
if (i != GE_CMD_ORIGIN && i != GE_CMD_OFFSETADDR) {
|
2013-08-04 22:15:50 +00:00
|
|
|
ExecuteOp(gstate.cmdmem[i], 0xFFFFFFFF);
|
2013-08-08 06:59:32 +00:00
|
|
|
}
|
2013-08-04 22:15:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Can't write to bonematrixnumber here
|
|
|
|
|
2013-09-20 07:43:45 +00:00
|
|
|
for (int i = GE_CMD_MORPHWEIGHT0; i <= GE_CMD_PATCHFACING; i++) {
|
2013-08-04 22:15:50 +00:00
|
|
|
ExecuteOp(gstate.cmdmem[i], 0xFFFFFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
// There are a few here in the middle that we shouldn't execute...
|
|
|
|
|
2015-11-04 21:03:29 +00:00
|
|
|
for (int i = GE_CMD_VIEWPORTXSCALE; i < GE_CMD_TRANSFERSTART; i++) {
|
2013-08-04 22:15:50 +00:00
|
|
|
ExecuteOp(gstate.cmdmem[i], 0xFFFFFFFF);
|
|
|
|
}
|
|
|
|
|
2013-09-20 07:43:45 +00:00
|
|
|
// Let's just skip the transfer size stuff, it's just values.
|
2013-08-04 22:15:50 +00:00
|
|
|
}
|
|
|
|
|
2015-07-26 20:38:40 +00:00
|
|
|
inline void GPUCommon::UpdateState(GPURunState state) {
|
2013-04-28 20:34:29 +00:00
|
|
|
gpuState = state;
|
2013-04-28 21:23:30 +00:00
|
|
|
if (state != GPUSTATE_RUNNING)
|
|
|
|
downcount = 0;
|
2013-04-03 15:10:35 +00:00
|
|
|
}
|
|
|
|
|
2013-08-10 10:33:09 +00:00
|
|
|
void GPUCommon::ProcessEvent(GPUEvent ev) {
|
|
|
|
switch (ev.type) {
|
|
|
|
case GPU_EVENT_PROCESS_QUEUE:
|
|
|
|
ProcessDLQueueInternal();
|
|
|
|
break;
|
2013-08-09 07:45:27 +00:00
|
|
|
|
2013-08-10 10:33:09 +00:00
|
|
|
case GPU_EVENT_REAPPLY_GFX_STATE:
|
|
|
|
ReapplyGfxStateInternal();
|
|
|
|
break;
|
2013-08-09 07:45:27 +00:00
|
|
|
|
2016-12-21 18:58:10 +00:00
|
|
|
case GPU_EVENT_INIT_CLEAR:
|
|
|
|
InitClearInternal();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GPU_EVENT_BEGIN_FRAME:
|
|
|
|
BeginFrameInternal();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GPU_EVENT_COPY_DISPLAY_TO_OUTPUT:
|
|
|
|
CopyDisplayToOutputInternal();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GPU_EVENT_INVALIDATE_CACHE:
|
|
|
|
InvalidateCacheInternal(ev.invalidate_cache.addr, ev.invalidate_cache.size, ev.invalidate_cache.type);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GPU_EVENT_FB_MEMCPY:
|
|
|
|
PerformMemoryCopyInternal(ev.fb_memcpy.dst, ev.fb_memcpy.src, ev.fb_memcpy.size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GPU_EVENT_FB_MEMSET:
|
|
|
|
PerformMemorySetInternal(ev.fb_memset.dst, ev.fb_memset.v, ev.fb_memset.size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GPU_EVENT_FB_STENCIL_UPLOAD:
|
|
|
|
PerformStencilUploadInternal(ev.fb_stencil_upload.dst, ev.fb_stencil_upload.size);
|
|
|
|
break;
|
|
|
|
|
2017-01-26 07:43:26 +00:00
|
|
|
case GPU_EVENT_REINITIALIZE:
|
|
|
|
break;
|
|
|
|
|
2013-08-10 10:33:09 +00:00
|
|
|
default:
|
2013-08-24 18:19:35 +00:00
|
|
|
ERROR_LOG_REPORT(G3D, "Unexpected GPU event type: %d", (int)ev);
|
2016-12-21 18:58:10 +00:00
|
|
|
break;
|
2013-08-08 07:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-04 23:31:11 +00:00
|
|
|
int GPUCommon::GetNextListIndex() {
|
2013-08-09 07:32:40 +00:00
|
|
|
easy_guard guard(listLock);
|
2013-08-04 23:31:11 +00:00
|
|
|
auto iter = dlQueue.begin();
|
|
|
|
if (iter != dlQueue.end()) {
|
|
|
|
return *iter;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GPUCommon::ProcessDLQueue() {
|
2013-08-08 06:59:32 +00:00
|
|
|
ScheduleEvent(GPU_EVENT_PROCESS_QUEUE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::ProcessDLQueueInternal() {
|
2013-04-03 15:10:35 +00:00
|
|
|
startingTicks = CoreTiming::GetTicks();
|
|
|
|
cyclesExecuted = 0;
|
2013-08-11 20:41:42 +00:00
|
|
|
UpdateTickEstimate(std::max(busyTicks, startingTicks + cyclesExecuted));
|
2013-04-03 15:10:35 +00:00
|
|
|
|
2013-08-25 01:13:34 +00:00
|
|
|
// Seems to be correct behaviour to process the list anyway?
|
2013-08-04 23:31:11 +00:00
|
|
|
if (startingTicks < busyTicks) {
|
2013-09-07 20:31:14 +00:00
|
|
|
DEBUG_LOG(G3D, "Can't execute a list yet, still busy for %lld ticks", busyTicks - startingTicks);
|
2013-08-25 01:13:34 +00:00
|
|
|
//return;
|
2013-04-09 07:56:04 +00:00
|
|
|
}
|
|
|
|
|
2013-08-04 23:31:11 +00:00
|
|
|
for (int listIndex = GetNextListIndex(); listIndex != -1; listIndex = GetNextListIndex()) {
|
|
|
|
DisplayList &l = dls[listIndex];
|
2015-05-25 22:39:27 +00:00
|
|
|
DEBUG_LOG(G3D, "Starting DL execution at %08x - stall = %08x", l.pc, l.stall);
|
2013-08-04 23:31:11 +00:00
|
|
|
if (!InterpretList(l)) {
|
2013-08-08 06:59:32 +00:00
|
|
|
return;
|
2013-08-04 23:31:11 +00:00
|
|
|
} else {
|
2013-08-09 07:32:40 +00:00
|
|
|
easy_guard guard(listLock);
|
2014-05-04 01:40:27 +00:00
|
|
|
|
|
|
|
// Some other list could've taken the spot while we dilly-dallied around.
|
|
|
|
if (l.state != PSP_GE_DL_STATE_QUEUED) {
|
|
|
|
// At the end, we can remove it from the queue and continue.
|
|
|
|
dlQueue.erase(std::remove(dlQueue.begin(), dlQueue.end(), listIndex), dlQueue.end());
|
|
|
|
}
|
2013-08-11 20:41:42 +00:00
|
|
|
UpdateTickEstimate(std::max(busyTicks, startingTicks + cyclesExecuted));
|
2012-12-29 01:10:29 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-04 23:31:11 +00:00
|
|
|
|
2013-08-09 07:32:40 +00:00
|
|
|
easy_guard guard(listLock);
|
2013-04-04 06:31:01 +00:00
|
|
|
currentList = NULL;
|
2013-04-06 05:38:19 +00:00
|
|
|
|
2013-04-07 19:45:42 +00:00
|
|
|
drawCompleteTicks = startingTicks + cyclesExecuted;
|
2013-04-09 07:56:04 +00:00
|
|
|
busyTicks = std::max(busyTicks, drawCompleteTicks);
|
2014-03-30 00:02:41 +00:00
|
|
|
__GeTriggerSync(GPU_SYNC_DRAW, 1, drawCompleteTicks);
|
2013-08-11 20:41:42 +00:00
|
|
|
// Since the event is in CoreTiming, we're in sync. Just set 0 now.
|
|
|
|
UpdateTickEstimate(0);
|
2012-12-29 01:10:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::PreExecuteOp(u32 op, u32 diff) {
|
|
|
|
// Nothing to do
|
2012-12-29 19:41:33 +00:00
|
|
|
}
|
|
|
|
|
2014-04-16 15:12:21 +00:00
|
|
|
void GPUCommon::Execute_OffsetAddr(u32 op, u32 diff) {
|
|
|
|
gstate_c.offsetAddr = op << 8;
|
|
|
|
}
|
2013-04-01 06:02:46 +00:00
|
|
|
|
2017-01-28 10:53:28 +00:00
|
|
|
void GPUCommon::Execute_Vaddr(u32 op, u32 diff) {
|
|
|
|
gstate_c.vertexAddr = gstate_c.getRelativeAddress(op & 0x00FFFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::Execute_Iaddr(u32 op, u32 diff) {
|
|
|
|
gstate_c.indexAddr = gstate_c.getRelativeAddress(op & 0x00FFFFFF);
|
|
|
|
}
|
|
|
|
|
2014-04-16 15:12:21 +00:00
|
|
|
void GPUCommon::Execute_Origin(u32 op, u32 diff) {
|
|
|
|
easy_guard guard(listLock);
|
|
|
|
gstate_c.offsetAddr = currentList->pc;
|
|
|
|
}
|
2013-04-01 06:02:46 +00:00
|
|
|
|
2014-04-16 15:12:21 +00:00
|
|
|
void GPUCommon::Execute_Jump(u32 op, u32 diff) {
|
|
|
|
easy_guard guard(listLock);
|
2014-05-05 00:58:44 +00:00
|
|
|
const u32 target = gstate_c.getRelativeAddress(op & 0x00FFFFFC);
|
2017-01-28 10:39:34 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
if (!Memory::IsValidAddress(target)) {
|
2014-05-05 00:58:44 +00:00
|
|
|
ERROR_LOG_REPORT(G3D, "JUMP to illegal address %08x - ignoring! data=%06x", target, op & 0x00FFFFFF);
|
2017-01-28 10:39:34 +00:00
|
|
|
return;
|
2014-04-16 15:12:21 +00:00
|
|
|
}
|
2017-01-28 10:39:34 +00:00
|
|
|
#endif
|
|
|
|
UpdatePC(currentList->pc, target - 4);
|
|
|
|
currentList->pc = target - 4; // pc will be increased after we return, counteract that
|
2014-04-16 15:12:21 +00:00
|
|
|
}
|
2013-04-01 06:02:46 +00:00
|
|
|
|
2014-04-16 15:12:21 +00:00
|
|
|
void GPUCommon::Execute_BJump(u32 op, u32 diff) {
|
|
|
|
if (!currentList->bboxResult) {
|
|
|
|
// bounding box jump.
|
|
|
|
easy_guard guard(listLock);
|
2014-05-05 00:58:44 +00:00
|
|
|
const u32 target = gstate_c.getRelativeAddress(op & 0x00FFFFFC);
|
2014-04-16 15:12:21 +00:00
|
|
|
if (Memory::IsValidAddress(target)) {
|
|
|
|
UpdatePC(currentList->pc, target - 4);
|
|
|
|
currentList->pc = target - 4; // pc will be increased after we return, counteract that
|
|
|
|
} else {
|
2014-05-05 00:58:44 +00:00
|
|
|
ERROR_LOG_REPORT(G3D, "BJUMP to illegal address %08x - ignoring! data=%06x", target, op & 0x00FFFFFF);
|
2013-08-08 06:27:29 +00:00
|
|
|
}
|
2014-04-16 15:12:21 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-01 06:02:46 +00:00
|
|
|
|
2014-04-16 15:12:21 +00:00
|
|
|
void GPUCommon::Execute_Call(u32 op, u32 diff) {
|
2017-08-18 11:39:42 +00:00
|
|
|
PROFILE_THIS_SCOPE("gpu_call");
|
2014-04-16 15:12:21 +00:00
|
|
|
easy_guard guard(listLock);
|
2013-04-01 06:02:46 +00:00
|
|
|
|
2014-04-16 15:12:21 +00:00
|
|
|
// Saint Seiya needs correct support for relative calls.
|
|
|
|
const u32 retval = currentList->pc + 4;
|
2014-05-05 00:58:44 +00:00
|
|
|
const u32 target = gstate_c.getRelativeAddress(op & 0x00FFFFFC);
|
2017-01-28 10:39:34 +00:00
|
|
|
#ifdef _DEBUG
|
2014-09-23 15:31:29 +00:00
|
|
|
if (!Memory::IsValidAddress(target)) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "CALL to illegal address %08x - ignoring! data=%06x", target, op & 0x00FFFFFF);
|
|
|
|
return;
|
|
|
|
}
|
2017-01-28 10:39:34 +00:00
|
|
|
#endif
|
2014-04-16 15:12:21 +00:00
|
|
|
|
|
|
|
// Bone matrix optimization - many games will CALL a bone matrix (!).
|
2017-06-04 19:50:12 +00:00
|
|
|
// We don't optimize during recording - so the matrix data gets recorded.
|
|
|
|
if (!debugRecording_ && (Memory::ReadUnchecked_U32(target) >> 24) == GE_CMD_BONEMATRIXDATA) {
|
2014-04-16 15:12:21 +00:00
|
|
|
// Check for the end
|
|
|
|
if ((Memory::ReadUnchecked_U32(target + 11 * 4) >> 24) == GE_CMD_BONEMATRIXDATA &&
|
|
|
|
(Memory::ReadUnchecked_U32(target + 12 * 4) >> 24) == GE_CMD_RET) {
|
2017-06-04 19:50:12 +00:00
|
|
|
// Yep, pretty sure this is a bone matrix call. Double check stall first.
|
|
|
|
if (target > currentList->stall || target + 12 * 4 < currentList->stall) {
|
|
|
|
FastLoadBoneMatrix(target);
|
|
|
|
return;
|
|
|
|
}
|
2013-09-24 10:59:34 +00:00
|
|
|
}
|
2014-04-16 15:12:21 +00:00
|
|
|
}
|
2013-11-14 13:02:31 +00:00
|
|
|
|
2014-04-16 15:12:21 +00:00
|
|
|
if (currentList->stackptr == ARRAY_SIZE(currentList->stack)) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "CALL: Stack full!");
|
|
|
|
} else {
|
|
|
|
auto &stackEntry = currentList->stack[currentList->stackptr++];
|
|
|
|
stackEntry.pc = retval;
|
|
|
|
stackEntry.offsetAddr = gstate_c.offsetAddr;
|
|
|
|
// The base address is NOT saved/restored for a regular call.
|
|
|
|
UpdatePC(currentList->pc, target - 4);
|
|
|
|
currentList->pc = target - 4; // pc will be increased after we return, counteract that
|
|
|
|
}
|
|
|
|
}
|
2013-04-01 06:02:46 +00:00
|
|
|
|
2014-04-16 15:12:21 +00:00
|
|
|
void GPUCommon::Execute_Ret(u32 op, u32 diff) {
|
|
|
|
easy_guard guard(listLock);
|
|
|
|
if (currentList->stackptr == 0) {
|
|
|
|
DEBUG_LOG_REPORT(G3D, "RET: Stack empty!");
|
|
|
|
} else {
|
|
|
|
auto &stackEntry = currentList->stack[--currentList->stackptr];
|
|
|
|
gstate_c.offsetAddr = stackEntry.offsetAddr;
|
2014-05-05 00:58:44 +00:00
|
|
|
// We always clear the top (uncached/etc.) bits
|
|
|
|
const u32 target = stackEntry.pc & 0x0FFFFFFF;
|
2014-04-16 15:12:21 +00:00
|
|
|
UpdatePC(currentList->pc, target - 4);
|
|
|
|
currentList->pc = target - 4;
|
2017-01-28 10:39:34 +00:00
|
|
|
#ifdef _DEBUG
|
2014-04-16 15:12:21 +00:00
|
|
|
if (!Memory::IsValidAddress(currentList->pc)) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "Invalid DL PC %08x on return", currentList->pc);
|
|
|
|
UpdateState(GPUSTATE_ERROR);
|
2013-04-01 06:02:46 +00:00
|
|
|
}
|
2017-01-28 10:39:34 +00:00
|
|
|
#endif
|
2014-04-16 15:12:21 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-01 06:02:46 +00:00
|
|
|
|
2014-04-16 15:12:21 +00:00
|
|
|
void GPUCommon::Execute_End(u32 op, u32 diff) {
|
2017-08-17 11:05:13 +00:00
|
|
|
Flush();
|
|
|
|
|
2014-04-16 15:12:21 +00:00
|
|
|
easy_guard guard(listLock);
|
|
|
|
const u32 prev = Memory::ReadUnchecked_U32(currentList->pc - 4);
|
2017-02-27 20:57:46 +00:00
|
|
|
UpdatePC(currentList->pc, currentList->pc);
|
2014-04-29 07:08:43 +00:00
|
|
|
// Count in a few extra cycles on END.
|
|
|
|
cyclesExecuted += 60;
|
|
|
|
|
2014-04-16 15:12:21 +00:00
|
|
|
switch (prev >> 24) {
|
2013-04-01 06:02:46 +00:00
|
|
|
case GE_CMD_SIGNAL:
|
2014-04-16 15:12:21 +00:00
|
|
|
{
|
|
|
|
// TODO: see http://code.google.com/p/jpcsp/source/detail?r=2935#
|
|
|
|
SignalBehavior behaviour = static_cast<SignalBehavior>((prev >> 16) & 0xFF);
|
2014-04-22 15:07:10 +00:00
|
|
|
const int signal = prev & 0xFFFF;
|
|
|
|
const int enddata = op & 0xFFFF;
|
2014-04-16 15:12:21 +00:00
|
|
|
bool trigger = true;
|
|
|
|
currentList->subIntrToken = signal;
|
|
|
|
|
|
|
|
switch (behaviour) {
|
|
|
|
case PSP_GE_SIGNAL_HANDLER_SUSPEND:
|
|
|
|
// Suspend the list, and call the signal handler. When it's done, resume.
|
|
|
|
// Before sdkver 0x02000010, listsync should return paused.
|
|
|
|
if (sceKernelGetCompiledSdkVersion() <= 0x02000010)
|
|
|
|
currentList->state = PSP_GE_DL_STATE_PAUSED;
|
|
|
|
currentList->signal = behaviour;
|
|
|
|
DEBUG_LOG(G3D, "Signal with wait. signal/end: %04x %04x", signal, enddata);
|
|
|
|
break;
|
|
|
|
case PSP_GE_SIGNAL_HANDLER_CONTINUE:
|
|
|
|
// Resume the list right away, then call the handler.
|
|
|
|
currentList->signal = behaviour;
|
|
|
|
DEBUG_LOG(G3D, "Signal without wait. signal/end: %04x %04x", signal, enddata);
|
|
|
|
break;
|
|
|
|
case PSP_GE_SIGNAL_HANDLER_PAUSE:
|
|
|
|
// Pause the list instead of ending at the next FINISH.
|
|
|
|
// Call the handler with the PAUSE signal value at that FINISH.
|
|
|
|
// Technically, this ought to trigger an interrupt, but it won't do anything.
|
|
|
|
// But right now, signal is always reset by interrupts, so that causes pause to not work.
|
|
|
|
trigger = false;
|
|
|
|
currentList->signal = behaviour;
|
|
|
|
DEBUG_LOG(G3D, "Signal with Pause. signal/end: %04x %04x", signal, enddata);
|
|
|
|
break;
|
|
|
|
case PSP_GE_SIGNAL_SYNC:
|
|
|
|
// Acts as a memory barrier, never calls any user code.
|
|
|
|
// Technically, this ought to trigger an interrupt, but it won't do anything.
|
|
|
|
// Triggering here can cause incorrect rescheduling, which breaks 3rd Birthday.
|
|
|
|
// However, this is likely a bug in how GE signal interrupts are handled.
|
|
|
|
trigger = false;
|
|
|
|
currentList->signal = behaviour;
|
|
|
|
DEBUG_LOG(G3D, "Signal with Sync. signal/end: %04x %04x", signal, enddata);
|
|
|
|
break;
|
|
|
|
case PSP_GE_SIGNAL_JUMP:
|
|
|
|
{
|
2014-04-09 05:20:33 +00:00
|
|
|
trigger = false;
|
2013-04-06 17:05:09 +00:00
|
|
|
currentList->signal = behaviour;
|
2014-04-16 15:12:21 +00:00
|
|
|
// pc will be increased after we return, counteract that.
|
2017-08-20 20:30:39 +00:00
|
|
|
u32 target = (((signal << 16) | enddata) & 0xFFFFFFFC) - 4;
|
2014-04-16 15:12:21 +00:00
|
|
|
if (!Memory::IsValidAddress(target)) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "Signal with Jump: bad address. signal/end: %04x %04x", signal, enddata);
|
|
|
|
} else {
|
|
|
|
UpdatePC(currentList->pc, target);
|
|
|
|
currentList->pc = target;
|
|
|
|
DEBUG_LOG(G3D, "Signal with Jump. signal/end: %04x %04x", signal, enddata);
|
2013-04-06 17:30:12 +00:00
|
|
|
}
|
2013-04-01 06:02:46 +00:00
|
|
|
}
|
2014-04-16 15:12:21 +00:00
|
|
|
break;
|
|
|
|
case PSP_GE_SIGNAL_CALL:
|
|
|
|
{
|
|
|
|
trigger = false;
|
|
|
|
currentList->signal = behaviour;
|
|
|
|
// pc will be increased after we return, counteract that.
|
2017-08-20 20:30:39 +00:00
|
|
|
u32 target = (((signal << 16) | enddata) & 0xFFFFFFFC) - 4;
|
2014-04-16 15:12:21 +00:00
|
|
|
if (currentList->stackptr == ARRAY_SIZE(currentList->stack)) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "Signal with Call: stack full. signal/end: %04x %04x", signal, enddata);
|
|
|
|
} else if (!Memory::IsValidAddress(target)) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "Signal with Call: bad address. signal/end: %04x %04x", signal, enddata);
|
|
|
|
} else {
|
|
|
|
// TODO: This might save/restore other state...
|
|
|
|
auto &stackEntry = currentList->stack[currentList->stackptr++];
|
|
|
|
stackEntry.pc = currentList->pc;
|
|
|
|
stackEntry.offsetAddr = gstate_c.offsetAddr;
|
|
|
|
stackEntry.baseAddr = gstate.base;
|
|
|
|
UpdatePC(currentList->pc, target);
|
|
|
|
currentList->pc = target;
|
|
|
|
DEBUG_LOG(G3D, "Signal with Call. signal/end: %04x %04x", signal, enddata);
|
2013-09-01 17:16:29 +00:00
|
|
|
}
|
2013-04-05 07:21:47 +00:00
|
|
|
}
|
2014-04-16 15:12:21 +00:00
|
|
|
break;
|
|
|
|
case PSP_GE_SIGNAL_RET:
|
|
|
|
{
|
|
|
|
trigger = false;
|
|
|
|
currentList->signal = behaviour;
|
|
|
|
if (currentList->stackptr == 0) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "Signal with Return: stack empty. signal/end: %04x %04x", signal, enddata);
|
|
|
|
} else {
|
|
|
|
// TODO: This might save/restore other state...
|
|
|
|
auto &stackEntry = currentList->stack[--currentList->stackptr];
|
|
|
|
gstate_c.offsetAddr = stackEntry.offsetAddr;
|
|
|
|
gstate.base = stackEntry.baseAddr;
|
|
|
|
UpdatePC(currentList->pc, stackEntry.pc);
|
|
|
|
currentList->pc = stackEntry.pc;
|
|
|
|
DEBUG_LOG(G3D, "Signal with Return. signal/end: %04x %04x", signal, enddata);
|
2013-09-01 17:16:29 +00:00
|
|
|
}
|
2013-04-06 16:59:24 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2014-04-16 15:12:21 +00:00
|
|
|
ERROR_LOG_REPORT(G3D, "UNKNOWN Signal UNIMPLEMENTED %i ! signal/end: %04x %04x", behaviour, signal, enddata);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// TODO: Technically, jump/call/ret should generate an interrupt, but before the pc change maybe?
|
|
|
|
if (currentList->interruptsEnabled && trigger) {
|
|
|
|
if (__GeTriggerInterrupt(currentList->id, currentList->pc, startingTicks + cyclesExecuted)) {
|
2013-09-01 17:16:29 +00:00
|
|
|
currentList->pendingInterrupt = true;
|
2014-04-16 15:12:21 +00:00
|
|
|
UpdateState(GPUSTATE_INTERRUPT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GE_CMD_FINISH:
|
|
|
|
switch (currentList->signal) {
|
|
|
|
case PSP_GE_SIGNAL_HANDLER_PAUSE:
|
|
|
|
currentList->state = PSP_GE_DL_STATE_PAUSED;
|
|
|
|
if (currentList->interruptsEnabled) {
|
|
|
|
if (__GeTriggerInterrupt(currentList->id, currentList->pc, startingTicks + cyclesExecuted)) {
|
|
|
|
currentList->pendingInterrupt = true;
|
|
|
|
UpdateState(GPUSTATE_INTERRUPT);
|
2013-04-06 16:59:24 +00:00
|
|
|
}
|
2013-04-06 15:19:54 +00:00
|
|
|
}
|
2013-04-01 06:02:46 +00:00
|
|
|
break;
|
2014-04-16 15:12:21 +00:00
|
|
|
|
|
|
|
case PSP_GE_SIGNAL_SYNC:
|
|
|
|
currentList->signal = PSP_GE_SIGNAL_NONE;
|
|
|
|
// TODO: Technically this should still cause an interrupt. Probably for memory sync.
|
|
|
|
break;
|
|
|
|
|
2013-04-01 06:02:46 +00:00
|
|
|
default:
|
2014-04-16 15:12:21 +00:00
|
|
|
currentList->subIntrToken = prev & 0xFFFF;
|
|
|
|
UpdateState(GPUSTATE_DONE);
|
|
|
|
if (currentList->interruptsEnabled && __GeTriggerInterrupt(currentList->id, currentList->pc, startingTicks + cyclesExecuted)) {
|
|
|
|
currentList->pendingInterrupt = true;
|
|
|
|
} else {
|
|
|
|
currentList->state = PSP_GE_DL_STATE_COMPLETED;
|
|
|
|
currentList->waitTicks = startingTicks + cyclesExecuted;
|
|
|
|
busyTicks = std::max(busyTicks, currentList->waitTicks);
|
|
|
|
__GeTriggerSync(GPU_SYNC_LIST, currentList->id, currentList->waitTicks);
|
|
|
|
if (currentList->started && currentList->context.IsValid()) {
|
|
|
|
gstate.Restore(currentList->context);
|
|
|
|
ReapplyGfxStateInternal();
|
|
|
|
}
|
|
|
|
}
|
2013-04-01 06:02:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2014-04-16 15:12:21 +00:00
|
|
|
default:
|
|
|
|
DEBUG_LOG(G3D,"Ah, not finished: %06x", prev & 0xFFFFFF);
|
|
|
|
break;
|
2013-04-20 22:23:35 +00:00
|
|
|
}
|
2014-04-16 15:12:21 +00:00
|
|
|
}
|
|
|
|
|
2017-02-13 21:02:26 +00:00
|
|
|
void GPUCommon::Execute_TexLevel(u32 op, u32 diff) {
|
2017-02-14 15:51:56 +00:00
|
|
|
if (diff == 0xFFFFFFFF) return;
|
|
|
|
|
|
|
|
gstate.texlevel ^= diff;
|
2017-05-13 03:05:35 +00:00
|
|
|
if (gstate.getTexLevelMode() != GE_TEXLEVEL_MODE_AUTO && (0x00FF0000 & gstate.texlevel) != 0) {
|
2017-02-13 21:02:26 +00:00
|
|
|
Flush();
|
|
|
|
}
|
2017-02-14 15:51:56 +00:00
|
|
|
gstate.texlevel ^= diff;
|
2017-03-19 10:32:29 +00:00
|
|
|
gstate_c.Dirty(DIRTY_TEXTURE_PARAMS | DIRTY_FRAGMENTSHADER_STATE);
|
2017-02-13 21:02:26 +00:00
|
|
|
}
|
|
|
|
|
2017-01-21 19:42:40 +00:00
|
|
|
void GPUCommon::Execute_Bezier(u32 op, u32 diff) {
|
2017-08-17 11:05:13 +00:00
|
|
|
Flush();
|
2017-01-21 19:42:40 +00:00
|
|
|
// This also make skipping drawing very effective.
|
2017-01-23 22:25:09 +00:00
|
|
|
framebufferManager_->SetRenderFrameBuffer(gstate_c.IsDirty(DIRTY_FRAMEBUF), gstate_c.skipDrawReason);
|
2017-01-21 19:42:40 +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;
|
|
|
|
drawEngineCommon_->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 GPUCommon::Execute_Spline(u32 op, u32 diff) {
|
2017-08-17 11:05:13 +00:00
|
|
|
Flush();
|
2017-01-21 19:42:40 +00:00
|
|
|
// This also make skipping drawing very effective.
|
2017-01-23 22:25:09 +00:00
|
|
|
framebufferManager_->SetRenderFrameBuffer(gstate_c.IsDirty(DIRTY_FRAMEBUF), gstate_c.skipDrawReason);
|
2017-01-21 19:42:40 +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;
|
|
|
|
drawEngineCommon_->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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::Execute_BoundingBox(u32 op, u32 diff) {
|
|
|
|
// Just resetting, nothing to check bounds for.
|
|
|
|
const u32 data = op & 0x00FFFFFF;
|
|
|
|
if (data == 0) {
|
2017-08-20 20:30:10 +00:00
|
|
|
currentList->bboxResult = false;
|
2017-01-21 19:42:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (((data & 7) == 0) && data <= 64) { // Sanity check
|
|
|
|
void *control_points = Memory::GetPointer(gstate_c.vertexAddr);
|
|
|
|
if (gstate.vertType & GE_VTYPE_IDX_MASK) {
|
|
|
|
ERROR_LOG_REPORT_ONCE(boundingbox, G3D, "Indexed bounding box data not supported.");
|
|
|
|
// Data seems invalid. Let's assume the box test passed.
|
|
|
|
currentList->bboxResult = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test if the bounding box is within the drawing region.
|
|
|
|
if (control_points) {
|
|
|
|
currentList->bboxResult = drawEngineCommon_->TestBoundingBox(control_points, data, gstate.vertType);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ERROR_LOG_REPORT_ONCE(boundingbox, G3D, "Bad bounding box data: %06x", data);
|
|
|
|
// Data seems invalid. Let's assume the box test passed.
|
|
|
|
currentList->bboxResult = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-23 15:57:16 +00:00
|
|
|
void GPUCommon::Execute_BlockTransferStart(u32 op, u32 diff) {
|
2017-08-18 11:39:42 +00:00
|
|
|
PROFILE_THIS_SCOPE("block");
|
2017-08-17 11:05:13 +00:00
|
|
|
Flush();
|
2017-01-23 15:57:16 +00:00
|
|
|
// and take appropriate action. This is a block transfer between RAM and VRAM, or vice versa.
|
|
|
|
// Can we skip this on SkipDraw?
|
|
|
|
DoBlockTransfer(gstate_c.skipDrawReason);
|
|
|
|
}
|
|
|
|
|
2017-01-23 19:56:25 +00:00
|
|
|
void GPUCommon::Execute_WorldMtxNum(u32 op, u32 diff) {
|
|
|
|
// This is almost always followed by GE_CMD_WORLDMATRIXDATA.
|
|
|
|
const u32_le *src = (const u32_le *)Memory::GetPointerUnchecked(currentList->pc + 4);
|
|
|
|
u32 *dst = (u32 *)(gstate.worldMatrix + (op & 0xF));
|
|
|
|
const int end = 12 - (op & 0xF);
|
|
|
|
int i = 0;
|
|
|
|
|
2017-06-04 19:50:12 +00:00
|
|
|
// We must record the individual data commands while debugRecording_.
|
|
|
|
bool fastLoad = !debugRecording_;
|
2017-08-18 11:39:42 +00:00
|
|
|
// Stalling in the middle of a matrix would be stupid, I doubt this check is necessary.
|
2017-06-04 19:50:12 +00:00
|
|
|
if (currentList->pc < currentList->stall && currentList->pc + end * 4 >= currentList->stall) {
|
|
|
|
fastLoad = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fastLoad) {
|
|
|
|
while ((src[i] >> 24) == GE_CMD_WORLDMATRIXDATA) {
|
|
|
|
const u32 newVal = src[i] << 8;
|
|
|
|
if (dst[i] != newVal) {
|
|
|
|
Flush();
|
|
|
|
dst[i] = newVal;
|
|
|
|
gstate_c.Dirty(DIRTY_WORLDMATRIX);
|
|
|
|
}
|
|
|
|
if (++i >= end) {
|
|
|
|
break;
|
|
|
|
}
|
2017-01-23 19:56:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-04 19:50:12 +00:00
|
|
|
const int count = i;
|
2017-01-23 19:56:25 +00:00
|
|
|
gstate.worldmtxnum = (GE_CMD_WORLDMATRIXNUMBER << 24) | ((op + count) & 0xF);
|
|
|
|
|
|
|
|
// Skip over the loaded data, it's done now.
|
2017-02-27 20:57:46 +00:00
|
|
|
easy_guard innerGuard(listLock);
|
2017-01-23 19:56:25 +00:00
|
|
|
UpdatePC(currentList->pc, currentList->pc + count * 4);
|
|
|
|
currentList->pc += count * 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::Execute_WorldMtxData(u32 op, u32 diff) {
|
|
|
|
// Note: it's uncommon to get here now, see above.
|
|
|
|
int num = gstate.worldmtxnum & 0xF;
|
|
|
|
u32 newVal = op << 8;
|
|
|
|
if (num < 12 && newVal != ((const u32 *)gstate.worldMatrix)[num]) {
|
|
|
|
Flush();
|
|
|
|
((u32 *)gstate.worldMatrix)[num] = newVal;
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_WORLDMATRIX);
|
2017-01-23 19:56:25 +00:00
|
|
|
}
|
|
|
|
num++;
|
|
|
|
gstate.worldmtxnum = (GE_CMD_WORLDMATRIXNUMBER << 24) | (num & 0xF);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::Execute_ViewMtxNum(u32 op, u32 diff) {
|
|
|
|
// This is almost always followed by GE_CMD_VIEWMATRIXDATA.
|
|
|
|
const u32_le *src = (const u32_le *)Memory::GetPointerUnchecked(currentList->pc + 4);
|
|
|
|
u32 *dst = (u32 *)(gstate.viewMatrix + (op & 0xF));
|
|
|
|
const int end = 12 - (op & 0xF);
|
|
|
|
int i = 0;
|
|
|
|
|
2017-06-04 19:50:12 +00:00
|
|
|
bool fastLoad = !debugRecording_;
|
|
|
|
if (currentList->pc < currentList->stall && currentList->pc + end * 4 >= currentList->stall) {
|
|
|
|
fastLoad = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fastLoad) {
|
|
|
|
while ((src[i] >> 24) == GE_CMD_VIEWMATRIXDATA) {
|
|
|
|
const u32 newVal = src[i] << 8;
|
|
|
|
if (dst[i] != newVal) {
|
|
|
|
Flush();
|
|
|
|
dst[i] = newVal;
|
|
|
|
gstate_c.Dirty(DIRTY_VIEWMATRIX);
|
|
|
|
}
|
|
|
|
if (++i >= end) {
|
|
|
|
break;
|
|
|
|
}
|
2017-01-23 19:56:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-04 19:50:12 +00:00
|
|
|
const int count = i;
|
2017-01-23 19:56:25 +00:00
|
|
|
gstate.viewmtxnum = (GE_CMD_VIEWMATRIXNUMBER << 24) | ((op + count) & 0xF);
|
|
|
|
|
|
|
|
// Skip over the loaded data, it's done now.
|
2017-02-27 20:57:46 +00:00
|
|
|
easy_guard innerGuard(listLock);
|
2017-01-23 19:56:25 +00:00
|
|
|
UpdatePC(currentList->pc, currentList->pc + count * 4);
|
|
|
|
currentList->pc += count * 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::Execute_ViewMtxData(u32 op, u32 diff) {
|
|
|
|
// Note: it's uncommon to get here now, see above.
|
|
|
|
int num = gstate.viewmtxnum & 0xF;
|
|
|
|
u32 newVal = op << 8;
|
|
|
|
if (num < 12 && newVal != ((const u32 *)gstate.viewMatrix)[num]) {
|
|
|
|
Flush();
|
|
|
|
((u32 *)gstate.viewMatrix)[num] = newVal;
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_VIEWMATRIX);
|
2017-01-23 19:56:25 +00:00
|
|
|
}
|
|
|
|
num++;
|
|
|
|
gstate.viewmtxnum = (GE_CMD_VIEWMATRIXNUMBER << 24) | (num & 0xF);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::Execute_ProjMtxNum(u32 op, u32 diff) {
|
|
|
|
// This is almost always followed by GE_CMD_PROJMATRIXDATA.
|
|
|
|
const u32_le *src = (const u32_le *)Memory::GetPointerUnchecked(currentList->pc + 4);
|
|
|
|
u32 *dst = (u32 *)(gstate.projMatrix + (op & 0xF));
|
|
|
|
const int end = 16 - (op & 0xF);
|
|
|
|
int i = 0;
|
|
|
|
|
2017-06-04 19:50:12 +00:00
|
|
|
bool fastLoad = !debugRecording_;
|
|
|
|
if (currentList->pc < currentList->stall && currentList->pc + end * 4 >= currentList->stall) {
|
|
|
|
fastLoad = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fastLoad) {
|
|
|
|
while ((src[i] >> 24) == GE_CMD_PROJMATRIXDATA) {
|
|
|
|
const u32 newVal = src[i] << 8;
|
|
|
|
if (dst[i] != newVal) {
|
|
|
|
Flush();
|
|
|
|
dst[i] = newVal;
|
|
|
|
gstate_c.Dirty(DIRTY_PROJMATRIX);
|
|
|
|
}
|
|
|
|
if (++i >= end) {
|
|
|
|
break;
|
|
|
|
}
|
2017-01-23 19:56:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-04 19:50:12 +00:00
|
|
|
const int count = i;
|
2017-01-24 01:33:16 +00:00
|
|
|
gstate.projmtxnum = (GE_CMD_PROJMATRIXNUMBER << 24) | ((op + count) & 0x1F);
|
2017-01-23 19:56:25 +00:00
|
|
|
|
|
|
|
// Skip over the loaded data, it's done now.
|
2017-02-27 20:57:46 +00:00
|
|
|
easy_guard innerGuard(listLock);
|
2017-01-23 19:56:25 +00:00
|
|
|
UpdatePC(currentList->pc, currentList->pc + count * 4);
|
|
|
|
currentList->pc += count * 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::Execute_ProjMtxData(u32 op, u32 diff) {
|
|
|
|
// Note: it's uncommon to get here now, see above.
|
2017-01-24 01:33:16 +00:00
|
|
|
int num = gstate.projmtxnum & 0x1F; // NOTE: Changed from 0xF to catch overflows
|
2017-01-23 19:56:25 +00:00
|
|
|
u32 newVal = op << 8;
|
2017-01-24 01:33:16 +00:00
|
|
|
if (num < 0x10 && newVal != ((const u32 *)gstate.projMatrix)[num]) {
|
2017-01-23 19:56:25 +00:00
|
|
|
Flush();
|
|
|
|
((u32 *)gstate.projMatrix)[num] = newVal;
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_PROJMATRIX);
|
2017-01-23 19:56:25 +00:00
|
|
|
}
|
|
|
|
num++;
|
2017-01-24 01:33:16 +00:00
|
|
|
if (num <= 16)
|
|
|
|
gstate.projmtxnum = (GE_CMD_PROJMATRIXNUMBER << 24) | (num & 0xF);
|
2017-01-23 19:56:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::Execute_TgenMtxNum(u32 op, u32 diff) {
|
|
|
|
// This is almost always followed by GE_CMD_TGENMATRIXDATA.
|
|
|
|
const u32_le *src = (const u32_le *)Memory::GetPointerUnchecked(currentList->pc + 4);
|
|
|
|
u32 *dst = (u32 *)(gstate.tgenMatrix + (op & 0xF));
|
|
|
|
const int end = 12 - (op & 0xF);
|
|
|
|
int i = 0;
|
|
|
|
|
2017-06-04 19:50:12 +00:00
|
|
|
bool fastLoad = !debugRecording_;
|
|
|
|
if (currentList->pc < currentList->stall && currentList->pc + end * 4 >= currentList->stall) {
|
|
|
|
fastLoad = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fastLoad) {
|
|
|
|
while ((src[i] >> 24) == GE_CMD_TGENMATRIXDATA) {
|
|
|
|
const u32 newVal = src[i] << 8;
|
|
|
|
if (dst[i] != newVal) {
|
|
|
|
Flush();
|
|
|
|
dst[i] = newVal;
|
|
|
|
gstate_c.Dirty(DIRTY_TEXMATRIX);
|
|
|
|
}
|
|
|
|
if (++i >= end) {
|
|
|
|
break;
|
|
|
|
}
|
2017-01-23 19:56:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-04 19:50:12 +00:00
|
|
|
const int count = i;
|
2017-01-23 19:56:25 +00:00
|
|
|
gstate.texmtxnum = (GE_CMD_TGENMATRIXNUMBER << 24) | ((op + count) & 0xF);
|
|
|
|
|
|
|
|
// Skip over the loaded data, it's done now.
|
2017-02-27 20:57:46 +00:00
|
|
|
easy_guard innerGuard(listLock);
|
2017-01-23 19:56:25 +00:00
|
|
|
UpdatePC(currentList->pc, currentList->pc + count * 4);
|
|
|
|
currentList->pc += count * 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::Execute_TgenMtxData(u32 op, u32 diff) {
|
|
|
|
// Note: it's uncommon to get here now, see above.
|
|
|
|
int num = gstate.texmtxnum & 0xF;
|
|
|
|
u32 newVal = op << 8;
|
|
|
|
if (num < 12 && newVal != ((const u32 *)gstate.tgenMatrix)[num]) {
|
|
|
|
Flush();
|
|
|
|
((u32 *)gstate.tgenMatrix)[num] = newVal;
|
2017-03-19 10:32:29 +00:00
|
|
|
gstate_c.Dirty(DIRTY_TEXMATRIX | DIRTY_FRAGMENTSHADER_STATE); // We check the matrix to see if we need projection
|
2017-01-23 19:56:25 +00:00
|
|
|
}
|
|
|
|
num++;
|
|
|
|
gstate.texmtxnum = (GE_CMD_TGENMATRIXNUMBER << 24) | (num & 0xF);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::Execute_BoneMtxNum(u32 op, u32 diff) {
|
|
|
|
// This is almost always followed by GE_CMD_BONEMATRIXDATA.
|
|
|
|
const u32_le *src = (const u32_le *)Memory::GetPointerUnchecked(currentList->pc + 4);
|
|
|
|
u32 *dst = (u32 *)(gstate.boneMatrix + (op & 0x7F));
|
|
|
|
const int end = 12 * 8 - (op & 0x7F);
|
|
|
|
int i = 0;
|
|
|
|
|
2017-06-04 19:50:12 +00:00
|
|
|
bool fastLoad = !debugRecording_;
|
|
|
|
if (currentList->pc < currentList->stall && currentList->pc + end * 4 >= currentList->stall) {
|
|
|
|
fastLoad = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fastLoad) {
|
|
|
|
// If we can't use software skinning, we have to flush and dirty.
|
|
|
|
if (!g_Config.bSoftwareSkinning || (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) != 0) {
|
|
|
|
while ((src[i] >> 24) == GE_CMD_BONEMATRIXDATA) {
|
|
|
|
const u32 newVal = src[i] << 8;
|
|
|
|
if (dst[i] != newVal) {
|
|
|
|
Flush();
|
|
|
|
dst[i] = newVal;
|
|
|
|
}
|
|
|
|
if (++i >= end) {
|
|
|
|
break;
|
|
|
|
}
|
2017-01-23 19:56:25 +00:00
|
|
|
}
|
|
|
|
|
2017-06-04 19:50:12 +00:00
|
|
|
const int numPlusCount = (op & 0x7F) + i;
|
2017-08-18 11:39:42 +00:00
|
|
|
for (unsigned int num = op & 0x7F; num < numPlusCount; num += 12) {
|
2017-06-04 19:50:12 +00:00
|
|
|
gstate_c.Dirty(DIRTY_BONEMATRIX0 << (num / 12));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while ((src[i] >> 24) == GE_CMD_BONEMATRIXDATA) {
|
|
|
|
dst[i] = src[i] << 8;
|
|
|
|
if (++i >= end) {
|
|
|
|
break;
|
|
|
|
}
|
2017-01-23 19:56:25 +00:00
|
|
|
}
|
|
|
|
|
2017-06-04 19:50:12 +00:00
|
|
|
const int numPlusCount = (op & 0x7F) + i;
|
2017-08-18 11:39:42 +00:00
|
|
|
for (unsigned int num = op & 0x7F; num < numPlusCount; num += 12) {
|
2017-06-04 19:50:12 +00:00
|
|
|
gstate_c.deferredVertTypeDirty |= DIRTY_BONEMATRIX0 << (num / 12);
|
|
|
|
}
|
2017-01-23 19:56:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-04 19:50:12 +00:00
|
|
|
const int count = i;
|
2017-01-23 19:56:25 +00:00
|
|
|
gstate.boneMatrixNumber = (GE_CMD_BONEMATRIXNUMBER << 24) | ((op + count) & 0x7F);
|
|
|
|
|
|
|
|
// Skip over the loaded data, it's done now.
|
2017-02-27 20:57:46 +00:00
|
|
|
easy_guard innerGuard(listLock);
|
2017-01-23 19:56:25 +00:00
|
|
|
UpdatePC(currentList->pc, currentList->pc + count * 4);
|
|
|
|
currentList->pc += count * 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::Execute_BoneMtxData(u32 op, u32 diff) {
|
|
|
|
// Note: it's uncommon to get here now, see above.
|
|
|
|
int num = gstate.boneMatrixNumber & 0x7F;
|
|
|
|
u32 newVal = op << 8;
|
|
|
|
if (num < 96 && newVal != ((const u32 *)gstate.boneMatrix)[num]) {
|
|
|
|
// Bone matrices should NOT flush when software skinning is enabled!
|
|
|
|
if (!g_Config.bSoftwareSkinning || (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) != 0) {
|
|
|
|
Flush();
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_BONEMATRIX0 << (num / 12));
|
2017-01-23 19:56:25 +00:00
|
|
|
} else {
|
|
|
|
gstate_c.deferredVertTypeDirty |= DIRTY_BONEMATRIX0 << (num / 12);
|
|
|
|
}
|
|
|
|
((u32 *)gstate.boneMatrix)[num] = newVal;
|
|
|
|
}
|
|
|
|
num++;
|
|
|
|
gstate.boneMatrixNumber = (GE_CMD_BONEMATRIXNUMBER << 24) | (num & 0x7F);
|
|
|
|
}
|
|
|
|
|
2017-01-24 09:44:02 +00:00
|
|
|
void GPUCommon::Execute_MorphWeight(u32 op, u32 diff) {
|
|
|
|
gstate_c.morphWeights[(op >> 24) - GE_CMD_MORPHWEIGHT0] = getFloat24(op);
|
|
|
|
}
|
|
|
|
|
2014-04-16 15:12:21 +00:00
|
|
|
void GPUCommon::ExecuteOp(u32 op, u32 diff) {
|
|
|
|
const u32 cmd = op >> 24;
|
|
|
|
|
|
|
|
// Handle control and drawing commands here directly. The others we delegate.
|
|
|
|
switch (cmd) {
|
|
|
|
case GE_CMD_NOP:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_OFFSETADDR:
|
|
|
|
Execute_OffsetAddr(op, diff);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_ORIGIN:
|
|
|
|
Execute_Origin(op, diff);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_JUMP:
|
|
|
|
Execute_Jump(op, diff);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_BJUMP:
|
|
|
|
Execute_BJump(op, diff);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_CALL:
|
|
|
|
Execute_Call(op, diff);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_RET:
|
|
|
|
Execute_Ret(op, diff);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_SIGNAL:
|
|
|
|
case GE_CMD_FINISH:
|
|
|
|
// Processed in GE_END.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_END:
|
|
|
|
Execute_End(op, diff);
|
|
|
|
break;
|
2013-04-01 06:02:46 +00:00
|
|
|
|
|
|
|
default:
|
2017-01-24 09:44:02 +00:00
|
|
|
DEBUG_LOG(G3D, "DL Unknown: %08x @ %08x", op, currentList == NULL ? 0 : currentList->pc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::Execute_Unknown(u32 op, u32 diff) {
|
|
|
|
switch (op >> 24) {
|
|
|
|
case GE_CMD_VSCX:
|
|
|
|
if ((op & 0xFFFFFF) != 0)
|
|
|
|
WARN_LOG_REPORT_ONCE(vscx, G3D, "Unsupported Vertex Screen Coordinate X : %06x", op);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_VSCY:
|
|
|
|
if ((op & 0xFFFFFF) != 0)
|
|
|
|
WARN_LOG_REPORT_ONCE(vscy, G3D, "Unsupported Vertex Screen Coordinate Y : %06x", op);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_VSCZ:
|
|
|
|
if ((op & 0xFFFFFF) != 0)
|
|
|
|
WARN_LOG_REPORT_ONCE(vscz, G3D, "Unsupported Vertex Screen Coordinate Z : %06x", op);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_VTCS:
|
|
|
|
if ((op & 0xFFFFFF) != 0)
|
|
|
|
WARN_LOG_REPORT_ONCE(vtcs, G3D, "Unsupported Vertex Texture Coordinate S : %06x", op);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_VTCT:
|
|
|
|
if ((op & 0xFFFFFF) != 0)
|
|
|
|
WARN_LOG_REPORT_ONCE(vtct, G3D, "Unsupported Vertex Texture Coordinate T : %06x", op);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_VTCQ:
|
|
|
|
if ((op & 0xFFFFFF) != 0)
|
|
|
|
WARN_LOG_REPORT_ONCE(vtcq, G3D, "Unsupported Vertex Texture Coordinate Q : %06x", op);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_VCV:
|
|
|
|
if ((op & 0xFFFFFF) != 0)
|
|
|
|
WARN_LOG_REPORT_ONCE(vcv, G3D, "Unsupported Vertex Color Value : %06x", op);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_VAP:
|
|
|
|
if ((op & 0xFFFFFF) != 0)
|
|
|
|
WARN_LOG_REPORT_ONCE(vap, G3D, "Unsupported Vertex Alpha and Primitive : %06x", op);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_VFC:
|
|
|
|
if ((op & 0xFFFFFF) != 0)
|
|
|
|
WARN_LOG_REPORT_ONCE(vfc, G3D, "Unsupported Vertex Fog Coefficient : %06x", op);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_VSCV:
|
|
|
|
if ((op & 0xFFFFFF) != 0)
|
|
|
|
WARN_LOG_REPORT_ONCE(vscv, G3D, "Unsupported Vertex Secondary Color Value : %06x", op);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_UNKNOWN_03:
|
|
|
|
case GE_CMD_UNKNOWN_0D:
|
|
|
|
case GE_CMD_UNKNOWN_11:
|
|
|
|
case GE_CMD_UNKNOWN_29:
|
|
|
|
case GE_CMD_UNKNOWN_34:
|
|
|
|
case GE_CMD_UNKNOWN_35:
|
|
|
|
case GE_CMD_UNKNOWN_39:
|
|
|
|
case GE_CMD_UNKNOWN_4E:
|
|
|
|
case GE_CMD_UNKNOWN_4F:
|
|
|
|
case GE_CMD_UNKNOWN_52:
|
|
|
|
case GE_CMD_UNKNOWN_59:
|
|
|
|
case GE_CMD_UNKNOWN_5A:
|
|
|
|
case GE_CMD_UNKNOWN_B6:
|
|
|
|
case GE_CMD_UNKNOWN_B7:
|
|
|
|
case GE_CMD_UNKNOWN_D1:
|
|
|
|
case GE_CMD_UNKNOWN_ED:
|
|
|
|
case GE_CMD_UNKNOWN_EF:
|
|
|
|
case GE_CMD_UNKNOWN_FA:
|
|
|
|
case GE_CMD_UNKNOWN_FB:
|
|
|
|
case GE_CMD_UNKNOWN_FC:
|
|
|
|
case GE_CMD_UNKNOWN_FD:
|
|
|
|
case GE_CMD_UNKNOWN_FE:
|
|
|
|
if ((op & 0xFFFFFF) != 0)
|
|
|
|
WARN_LOG_REPORT_ONCE(unknowncmd, G3D, "Unknown GE command : %08x ", op);
|
|
|
|
break;
|
|
|
|
default:
|
2013-04-01 06:02:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-03 02:12:40 +00:00
|
|
|
void GPUCommon::FastLoadBoneMatrix(u32 target) {
|
2017-01-23 21:06:30 +00:00
|
|
|
const int num = gstate.boneMatrixNumber & 0x7F;
|
|
|
|
const int mtxNum = num / 12;
|
|
|
|
uint32_t uniformsToDirty = DIRTY_BONEMATRIX0 << mtxNum;
|
|
|
|
if ((num - 12 * mtxNum) != 0) {
|
|
|
|
uniformsToDirty |= DIRTY_BONEMATRIX0 << ((mtxNum + 1) & 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_Config.bSoftwareSkinning || (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) != 0) {
|
|
|
|
Flush();
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(uniformsToDirty);
|
2017-01-23 21:06:30 +00:00
|
|
|
} else {
|
|
|
|
gstate_c.deferredVertTypeDirty |= uniformsToDirty;
|
|
|
|
}
|
2014-03-03 02:12:40 +00:00
|
|
|
gstate.FastLoadBoneMatrix(target);
|
|
|
|
}
|
|
|
|
|
2014-08-17 08:52:06 +00:00
|
|
|
struct DisplayList_v1 {
|
2013-10-07 05:07:57 +00:00
|
|
|
int id;
|
|
|
|
u32 startpc;
|
|
|
|
u32 pc;
|
|
|
|
u32 stall;
|
|
|
|
DisplayListState state;
|
|
|
|
SignalBehavior signal;
|
|
|
|
int subIntrBase;
|
|
|
|
u16 subIntrToken;
|
|
|
|
DisplayListStackEntry stack[32];
|
|
|
|
int stackptr;
|
|
|
|
bool interrupted;
|
|
|
|
u64 waitTicks;
|
|
|
|
bool interruptsEnabled;
|
|
|
|
bool pendingInterrupt;
|
|
|
|
bool started;
|
|
|
|
size_t contextPtr;
|
|
|
|
u32 offsetAddr;
|
|
|
|
bool bboxResult;
|
|
|
|
};
|
|
|
|
|
2014-08-17 08:52:06 +00:00
|
|
|
struct DisplayList_v2 {
|
|
|
|
int id;
|
|
|
|
u32 startpc;
|
|
|
|
u32 pc;
|
|
|
|
u32 stall;
|
|
|
|
DisplayListState state;
|
|
|
|
SignalBehavior signal;
|
|
|
|
int subIntrBase;
|
|
|
|
u16 subIntrToken;
|
|
|
|
DisplayListStackEntry stack[32];
|
|
|
|
int stackptr;
|
|
|
|
bool interrupted;
|
|
|
|
u64 waitTicks;
|
|
|
|
bool interruptsEnabled;
|
|
|
|
bool pendingInterrupt;
|
|
|
|
bool started;
|
|
|
|
PSPPointer<u32_le> context;
|
|
|
|
u32 offsetAddr;
|
|
|
|
bool bboxResult;
|
|
|
|
};
|
|
|
|
|
2012-12-29 19:41:33 +00:00
|
|
|
void GPUCommon::DoState(PointerWrap &p) {
|
2013-08-09 07:32:40 +00:00
|
|
|
easy_guard guard(listLock);
|
2013-08-08 06:27:29 +00:00
|
|
|
|
2015-10-11 12:38:26 +00:00
|
|
|
auto s = p.Section("GPUCommon", 1, 4);
|
2013-09-15 03:23:03 +00:00
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
|
2013-04-05 06:19:28 +00:00
|
|
|
p.Do<int>(dlQueue);
|
2015-10-11 12:38:26 +00:00
|
|
|
if (s >= 4) {
|
|
|
|
p.DoArray(dls, ARRAY_SIZE(dls));
|
|
|
|
} else if (s >= 3) {
|
2015-12-24 22:31:43 +00:00
|
|
|
// This may have been saved with or without padding, depending on platform.
|
|
|
|
// We need to upconvert it to our consistently-padded struct.
|
|
|
|
static const size_t DisplayList_v3_size = 452;
|
|
|
|
static const size_t DisplayList_v4_size = 456;
|
|
|
|
static_assert(DisplayList_v4_size == sizeof(DisplayList), "Make sure to change here when updating DisplayList");
|
|
|
|
|
|
|
|
p.DoVoid(&dls[0], DisplayList_v3_size);
|
|
|
|
dls[0].padding = 0;
|
|
|
|
|
|
|
|
const u8 *savedPtr = *p.GetPPtr();
|
|
|
|
const u32 *savedPtr32 = (const u32 *)savedPtr;
|
|
|
|
// Here's the trick: the first member (id) is always the same as the index.
|
|
|
|
// The second member (startpc) is always an address, or 0, never 1. So we can see the padding.
|
|
|
|
const bool hasPadding = savedPtr32[1] == 1;
|
|
|
|
if (hasPadding) {
|
|
|
|
u32 padding;
|
|
|
|
p.Do(padding);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 1; i < ARRAY_SIZE(dls); ++i) {
|
|
|
|
p.DoVoid(&dls[i], DisplayList_v3_size);
|
2015-10-11 12:38:26 +00:00
|
|
|
dls[i].padding = 0;
|
2015-12-24 22:31:43 +00:00
|
|
|
if (hasPadding) {
|
|
|
|
u32 padding;
|
|
|
|
p.Do(padding);
|
|
|
|
}
|
2015-10-11 12:38:26 +00:00
|
|
|
}
|
2014-08-17 08:52:06 +00:00
|
|
|
} else if (s >= 2) {
|
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(dls); ++i) {
|
|
|
|
DisplayList_v2 oldDL;
|
|
|
|
p.Do(oldDL);
|
|
|
|
// Copy over everything except the last, new member (stackAddr.)
|
|
|
|
memcpy(&dls[i], &oldDL, sizeof(DisplayList_v2));
|
|
|
|
dls[i].stackAddr = 0;
|
|
|
|
}
|
2013-10-07 05:07:57 +00:00
|
|
|
} else {
|
|
|
|
// Can only be in read mode here.
|
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(dls); ++i) {
|
2014-08-17 08:52:06 +00:00
|
|
|
DisplayList_v1 oldDL;
|
2013-10-07 05:07:57 +00:00
|
|
|
p.Do(oldDL);
|
|
|
|
// On 32-bit, they're the same, on 64-bit oldDL is bigger.
|
|
|
|
memcpy(&dls[i], &oldDL, sizeof(DisplayList));
|
|
|
|
// Fix the other fields. Let's hope context wasn't important, it was a pointer.
|
|
|
|
dls[i].context = 0;
|
|
|
|
dls[i].offsetAddr = oldDL.offsetAddr;
|
|
|
|
dls[i].bboxResult = oldDL.bboxResult;
|
2014-08-17 08:52:06 +00:00
|
|
|
dls[i].stackAddr = 0;
|
2013-10-07 05:07:57 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-05 06:19:28 +00:00
|
|
|
int currentID = 0;
|
2016-01-22 06:14:47 +00:00
|
|
|
if (currentList != nullptr) {
|
|
|
|
currentID = (int)(currentList - &dls[0]);
|
2013-04-05 06:19:28 +00:00
|
|
|
}
|
2013-02-12 09:06:11 +00:00
|
|
|
p.Do(currentID);
|
|
|
|
if (currentID == 0) {
|
2016-01-22 06:14:47 +00:00
|
|
|
currentList = nullptr;
|
2013-02-12 09:06:11 +00:00
|
|
|
} else {
|
2013-04-05 06:19:28 +00:00
|
|
|
currentList = &dls[currentID];
|
2013-02-12 09:06:11 +00:00
|
|
|
}
|
|
|
|
p.Do(interruptRunning);
|
2013-04-04 08:07:30 +00:00
|
|
|
p.Do(gpuState);
|
2013-04-04 07:35:38 +00:00
|
|
|
p.Do(isbreak);
|
2013-04-07 19:45:42 +00:00
|
|
|
p.Do(drawCompleteTicks);
|
2013-04-09 09:18:09 +00:00
|
|
|
p.Do(busyTicks);
|
2012-12-29 19:41:33 +00:00
|
|
|
}
|
2013-02-03 23:41:16 +00:00
|
|
|
|
2013-08-09 07:32:40 +00:00
|
|
|
void GPUCommon::InterruptStart(int listid) {
|
2013-02-03 23:41:16 +00:00
|
|
|
interruptRunning = true;
|
|
|
|
}
|
2013-08-09 07:32:40 +00:00
|
|
|
void GPUCommon::InterruptEnd(int listid) {
|
|
|
|
easy_guard guard(listLock);
|
2013-02-03 23:41:16 +00:00
|
|
|
interruptRunning = false;
|
2013-04-04 07:35:38 +00:00
|
|
|
isbreak = false;
|
2013-04-06 15:19:54 +00:00
|
|
|
|
|
|
|
DisplayList &dl = dls[listid];
|
2013-09-01 17:16:29 +00:00
|
|
|
dl.pendingInterrupt = false;
|
2013-04-06 15:19:54 +00:00
|
|
|
// TODO: Unless the signal handler could change it?
|
2013-04-07 23:47:29 +00:00
|
|
|
if (dl.state == PSP_GE_DL_STATE_COMPLETED || dl.state == PSP_GE_DL_STATE_NONE) {
|
2013-10-07 05:07:57 +00:00
|
|
|
if (dl.started && dl.context.IsValid()) {
|
2013-09-20 16:42:09 +00:00
|
|
|
gstate.Restore(dl.context);
|
2013-09-24 06:17:36 +00:00
|
|
|
ReapplyGfxState();
|
2013-09-20 16:42:09 +00:00
|
|
|
}
|
2013-04-07 19:45:42 +00:00
|
|
|
dl.waitTicks = 0;
|
2014-03-30 00:02:41 +00:00
|
|
|
__GeTriggerWait(GPU_SYNC_LIST, listid);
|
2013-04-06 15:19:54 +00:00
|
|
|
}
|
|
|
|
|
2013-08-09 07:32:40 +00:00
|
|
|
guard.unlock();
|
2013-02-03 23:41:16 +00:00
|
|
|
ProcessDLQueue();
|
|
|
|
}
|
2013-04-07 19:45:42 +00:00
|
|
|
|
|
|
|
// TODO: Maybe cleaner to keep this in GE and trigger the clear directly?
|
2014-03-29 23:51:38 +00:00
|
|
|
void GPUCommon::SyncEnd(GPUSyncType waitType, int listid, bool wokeThreads) {
|
2013-08-09 07:32:40 +00:00
|
|
|
easy_guard guard(listLock);
|
2014-03-29 23:51:38 +00:00
|
|
|
if (waitType == GPU_SYNC_DRAW && wokeThreads)
|
2013-04-07 19:45:42 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < DisplayListMaxCount; ++i) {
|
|
|
|
if (dls[i].state == PSP_GE_DL_STATE_COMPLETED) {
|
|
|
|
dls[i].state = PSP_GE_DL_STATE_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-22 17:22:33 +00:00
|
|
|
|
|
|
|
bool GPUCommon::GetCurrentDisplayList(DisplayList &list) {
|
|
|
|
easy_guard guard(listLock);
|
|
|
|
if (!currentList) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
list = *currentList;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<DisplayList> GPUCommon::ActiveDisplayLists() {
|
|
|
|
std::vector<DisplayList> result;
|
|
|
|
|
|
|
|
easy_guard guard(listLock);
|
|
|
|
for (auto it = dlQueue.begin(), end = dlQueue.end(); it != end; ++it) {
|
|
|
|
result.push_back(dls[*it]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::ResetListPC(int listID, u32 pc) {
|
|
|
|
if (listID < 0 || listID >= DisplayListMaxCount) {
|
|
|
|
_dbg_assert_msg_(G3D, false, "listID out of range: %d", listID);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
easy_guard guard(listLock);
|
|
|
|
dls[listID].pc = pc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::ResetListStall(int listID, u32 stall) {
|
|
|
|
if (listID < 0 || listID >= DisplayListMaxCount) {
|
|
|
|
_dbg_assert_msg_(G3D, false, "listID out of range: %d", listID);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
easy_guard guard(listLock);
|
|
|
|
dls[listID].stall = stall;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::ResetListState(int listID, DisplayListState state) {
|
|
|
|
if (listID < 0 || listID >= DisplayListMaxCount) {
|
|
|
|
_dbg_assert_msg_(G3D, false, "listID out of range: %d", listID);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
easy_guard guard(listLock);
|
|
|
|
dls[listID].state = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
GPUDebugOp GPUCommon::DissassembleOp(u32 pc, u32 op) {
|
|
|
|
char buffer[1024];
|
2014-09-13 21:50:42 +00:00
|
|
|
GeDisassembleOp(pc, op, Memory::Read_U32(pc - 4), buffer, sizeof(buffer));
|
2013-09-22 17:22:33 +00:00
|
|
|
|
|
|
|
GPUDebugOp info;
|
|
|
|
info.pc = pc;
|
|
|
|
info.cmd = op >> 24;
|
|
|
|
info.op = op;
|
|
|
|
info.desc = buffer;
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<GPUDebugOp> GPUCommon::DissassembleOpRange(u32 startpc, u32 endpc) {
|
|
|
|
char buffer[1024];
|
|
|
|
std::vector<GPUDebugOp> result;
|
|
|
|
GPUDebugOp info;
|
|
|
|
|
2013-10-06 22:07:54 +00:00
|
|
|
// Don't trigger a pause.
|
|
|
|
u32 prev = Memory::IsValidAddress(startpc - 4) ? Memory::Read_U32(startpc - 4) : 0;
|
2013-09-22 17:22:33 +00:00
|
|
|
for (u32 pc = startpc; pc < endpc; pc += 4) {
|
2013-10-06 22:07:54 +00:00
|
|
|
u32 op = Memory::IsValidAddress(pc) ? Memory::Read_U32(pc) : 0;
|
2014-09-13 21:50:42 +00:00
|
|
|
GeDisassembleOp(pc, op, prev, buffer, sizeof(buffer));
|
2013-09-22 17:22:33 +00:00
|
|
|
prev = op;
|
|
|
|
|
|
|
|
info.pc = pc;
|
|
|
|
info.cmd = op >> 24;
|
|
|
|
info.op = op;
|
|
|
|
info.desc = buffer;
|
|
|
|
result.push_back(info);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 GPUCommon::GetRelativeAddress(u32 data) {
|
|
|
|
return gstate_c.getRelativeAddress(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 GPUCommon::GetVertexAddress() {
|
|
|
|
return gstate_c.vertexAddr;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 GPUCommon::GetIndexAddress() {
|
|
|
|
return gstate_c.indexAddr;
|
|
|
|
}
|
|
|
|
|
|
|
|
GPUgstate GPUCommon::GetGState() {
|
|
|
|
return gstate;
|
|
|
|
}
|
2013-10-07 02:17:06 +00:00
|
|
|
|
|
|
|
void GPUCommon::SetCmdValue(u32 op) {
|
|
|
|
u32 cmd = op >> 24;
|
|
|
|
u32 diff = op ^ gstate.cmdmem[cmd];
|
|
|
|
|
|
|
|
PreExecuteOp(op, diff);
|
|
|
|
gstate.cmdmem[cmd] = op;
|
|
|
|
ExecuteOp(op, diff);
|
|
|
|
}
|
2016-04-10 20:07:08 +00:00
|
|
|
|
2016-12-21 17:07:17 +00:00
|
|
|
void GPUCommon::DoBlockTransfer(u32 skipDrawReason) {
|
|
|
|
// TODO: This is used a lot to copy data around between render targets and textures,
|
|
|
|
// and also to quickly load textures from RAM to VRAM. So we should do checks like the following:
|
|
|
|
// * Does dstBasePtr point to an existing texture? If so maybe reload it immediately.
|
|
|
|
//
|
|
|
|
// * Does srcBasePtr point to a render target, and dstBasePtr to a texture? If so
|
|
|
|
// either copy between rt and texture or reassign the texture to point to the render target
|
|
|
|
//
|
|
|
|
// etc....
|
|
|
|
|
|
|
|
u32 srcBasePtr = gstate.getTransferSrcAddress();
|
|
|
|
u32 srcStride = gstate.getTransferSrcStride();
|
|
|
|
|
|
|
|
u32 dstBasePtr = gstate.getTransferDstAddress();
|
|
|
|
u32 dstStride = gstate.getTransferDstStride();
|
|
|
|
|
|
|
|
int srcX = gstate.getTransferSrcX();
|
|
|
|
int srcY = gstate.getTransferSrcY();
|
|
|
|
|
|
|
|
int dstX = gstate.getTransferDstX();
|
|
|
|
int dstY = gstate.getTransferDstY();
|
|
|
|
|
|
|
|
int width = gstate.getTransferWidth();
|
|
|
|
int height = gstate.getTransferHeight();
|
|
|
|
|
|
|
|
int bpp = gstate.getTransferBpp();
|
|
|
|
|
|
|
|
DEBUG_LOG(G3D, "Block transfer: %08x/%x -> %08x/%x, %ix%ix%i (%i,%i)->(%i,%i)", srcBasePtr, srcStride, dstBasePtr, dstStride, width, height, bpp, srcX, srcY, dstX, dstY);
|
|
|
|
|
|
|
|
if (!Memory::IsValidAddress(srcBasePtr)) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "BlockTransfer: Bad source transfer address %08x!", srcBasePtr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Memory::IsValidAddress(dstBasePtr)) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "BlockTransfer: Bad destination transfer address %08x!", dstBasePtr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the last address of both source and dest are valid addresses
|
|
|
|
|
|
|
|
u32 srcLastAddr = srcBasePtr + ((srcY + height - 1) * srcStride + (srcX + width - 1)) * bpp;
|
|
|
|
u32 dstLastAddr = dstBasePtr + ((dstY + height - 1) * dstStride + (dstX + width - 1)) * bpp;
|
|
|
|
|
|
|
|
if (!Memory::IsValidAddress(srcLastAddr)) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "Bottom-right corner of source of block transfer is at an invalid address: %08x", srcLastAddr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!Memory::IsValidAddress(dstLastAddr)) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "Bottom-right corner of destination of block transfer is at an invalid address: %08x", srcLastAddr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tell the framebuffer manager to take action if possible. If it does the entire thing, let's just return.
|
|
|
|
if (!framebufferManager_->NotifyBlockTransferBefore(dstBasePtr, dstStride, dstX, dstY, srcBasePtr, srcStride, srcX, srcY, width, height, bpp, skipDrawReason)) {
|
|
|
|
// Do the copy! (Hm, if we detect a drawn video frame (see below) then we could maybe skip this?)
|
|
|
|
// Can use GetPointerUnchecked because we checked the addresses above. We could also avoid them
|
|
|
|
// entirely by walking a couple of pointers...
|
|
|
|
if (srcStride == dstStride && (u32)width == srcStride) {
|
|
|
|
// Common case in God of War, let's do it all in one chunk.
|
|
|
|
u32 srcLineStartAddr = srcBasePtr + (srcY * srcStride + srcX) * bpp;
|
|
|
|
u32 dstLineStartAddr = dstBasePtr + (dstY * dstStride + dstX) * bpp;
|
|
|
|
const u8 *src = Memory::GetPointerUnchecked(srcLineStartAddr);
|
|
|
|
u8 *dst = Memory::GetPointerUnchecked(dstLineStartAddr);
|
|
|
|
memcpy(dst, src, width * height * bpp);
|
|
|
|
} else {
|
|
|
|
for (int y = 0; y < height; y++) {
|
|
|
|
u32 srcLineStartAddr = srcBasePtr + ((y + srcY) * srcStride + srcX) * bpp;
|
|
|
|
u32 dstLineStartAddr = dstBasePtr + ((y + dstY) * dstStride + dstX) * bpp;
|
|
|
|
|
|
|
|
const u8 *src = Memory::GetPointerUnchecked(srcLineStartAddr);
|
|
|
|
u8 *dst = Memory::GetPointerUnchecked(dstLineStartAddr);
|
|
|
|
memcpy(dst, src, width * bpp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-25 18:43:19 +00:00
|
|
|
// Fixes Gran Turismo's funky text issue, since it overwrites the current texture.
|
2016-12-21 17:07:17 +00:00
|
|
|
textureCache_->Invalidate(dstBasePtr + (dstY * dstStride + dstX) * bpp, height * dstStride * bpp, GPU_INVALIDATE_HINT);
|
|
|
|
framebufferManager_->NotifyBlockTransferAfter(dstBasePtr, dstStride, dstX, dstY, srcBasePtr, srcStride, srcX, srcY, width, height, bpp, skipDrawReason);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef MOBILE_DEVICE
|
|
|
|
CBreakPoints::ExecMemCheck(srcBasePtr + (srcY * srcStride + srcX) * bpp, false, height * srcStride * bpp, currentMIPS->pc);
|
|
|
|
CBreakPoints::ExecMemCheck(dstBasePtr + (srcY * dstStride + srcX) * bpp, true, height * dstStride * bpp, currentMIPS->pc);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// TODO: Correct timing appears to be 1.9, but erring a bit low since some of our other timing is inaccurate.
|
|
|
|
cyclesExecuted += ((height * width * bpp) * 16) / 10;
|
2016-12-21 17:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::PerformMemoryCopyInternal(u32 dest, u32 src, int size) {
|
|
|
|
if (!framebufferManager_->NotifyFramebufferCopy(src, dest, size, false, gstate_c.skipDrawReason)) {
|
|
|
|
// We use a little hack for Download/Upload using a VRAM mirror.
|
|
|
|
// Since they're identical we don't need to copy.
|
|
|
|
if (!Memory::IsVRAMAddress(dest) || (dest ^ 0x00400000) != src) {
|
|
|
|
Memory::Memcpy(dest, src, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
InvalidateCache(dest, size, GPU_INVALIDATE_HINT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::PerformMemorySetInternal(u32 dest, u8 v, int size) {
|
|
|
|
if (!framebufferManager_->NotifyFramebufferCopy(dest, dest, size, true, gstate_c.skipDrawReason)) {
|
|
|
|
InvalidateCache(dest, size, GPU_INVALIDATE_HINT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GPUCommon::PerformMemoryCopy(u32 dest, u32 src, int size) {
|
|
|
|
// Track stray copies of a framebuffer in RAM. MotoGP does this.
|
|
|
|
if (framebufferManager_->MayIntersectFramebuffer(src) || framebufferManager_->MayIntersectFramebuffer(dest)) {
|
|
|
|
if (IsOnSeparateCPUThread()) {
|
|
|
|
GPUEvent ev(GPU_EVENT_FB_MEMCPY);
|
|
|
|
ev.fb_memcpy.dst = dest;
|
|
|
|
ev.fb_memcpy.src = src;
|
|
|
|
ev.fb_memcpy.size = size;
|
|
|
|
ScheduleEvent(ev);
|
|
|
|
|
|
|
|
// This is a memcpy, so we need to wait for it to complete.
|
|
|
|
SyncThread();
|
|
|
|
} else {
|
|
|
|
PerformMemoryCopyInternal(dest, src, size);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
InvalidateCache(dest, size, GPU_INVALIDATE_HINT);
|
2017-06-03 07:09:58 +00:00
|
|
|
GPURecord::NotifyMemcpy(dest, src, size);
|
2016-12-21 17:26:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GPUCommon::PerformMemorySet(u32 dest, u8 v, int size) {
|
|
|
|
// This may indicate a memset, usually to 0, of a framebuffer.
|
|
|
|
if (framebufferManager_->MayIntersectFramebuffer(dest)) {
|
|
|
|
Memory::Memset(dest, v, size);
|
|
|
|
|
|
|
|
if (IsOnSeparateCPUThread()) {
|
|
|
|
GPUEvent ev(GPU_EVENT_FB_MEMSET);
|
|
|
|
ev.fb_memset.dst = dest;
|
|
|
|
ev.fb_memset.v = v;
|
|
|
|
ev.fb_memset.size = size;
|
|
|
|
ScheduleEvent(ev);
|
|
|
|
|
|
|
|
// We don't need to wait for the framebuffer to be updated.
|
|
|
|
} else {
|
|
|
|
PerformMemorySetInternal(dest, v, size);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Or perhaps a texture, let's invalidate.
|
|
|
|
InvalidateCache(dest, size, GPU_INVALIDATE_HINT);
|
2017-06-03 07:09:58 +00:00
|
|
|
GPURecord::NotifyMemset(dest, v, size);
|
2016-12-21 17:26:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GPUCommon::PerformMemoryDownload(u32 dest, int size) {
|
|
|
|
// Cheat a bit to force a download of the framebuffer.
|
|
|
|
// VRAM + 0x00400000 is simply a VRAM mirror.
|
|
|
|
if (Memory::IsVRAMAddress(dest)) {
|
|
|
|
return PerformMemoryCopy(dest ^ 0x00400000, dest, size);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GPUCommon::PerformMemoryUpload(u32 dest, int size) {
|
|
|
|
// Cheat a bit to force an upload of the framebuffer.
|
|
|
|
// VRAM + 0x00400000 is simply a VRAM mirror.
|
|
|
|
if (Memory::IsVRAMAddress(dest)) {
|
2017-06-03 07:09:58 +00:00
|
|
|
GPURecord::NotifyUpload(dest, size);
|
2016-12-21 17:26:06 +00:00
|
|
|
return PerformMemoryCopy(dest, dest ^ 0x00400000, size);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-12-21 17:33:08 +00:00
|
|
|
|
|
|
|
void GPUCommon::InvalidateCache(u32 addr, int size, GPUInvalidationType type) {
|
|
|
|
GPUEvent ev(GPU_EVENT_INVALIDATE_CACHE);
|
|
|
|
ev.invalidate_cache.addr = addr;
|
|
|
|
ev.invalidate_cache.size = size;
|
|
|
|
ev.invalidate_cache.type = type;
|
|
|
|
ScheduleEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::InvalidateCacheInternal(u32 addr, int size, GPUInvalidationType type) {
|
|
|
|
if (size > 0)
|
|
|
|
textureCache_->Invalidate(addr, size, type);
|
|
|
|
else
|
|
|
|
textureCache_->InvalidateAll(type);
|
|
|
|
|
|
|
|
if (type != GPU_INVALIDATE_ALL && framebufferManager_->MayIntersectFramebuffer(addr)) {
|
|
|
|
// If we're doing block transfers, we shouldn't need this, and it'll only confuse us.
|
|
|
|
// Vempire invalidates (with writeback) after drawing, but before blitting.
|
|
|
|
if (!g_Config.bBlockTransferGPU || type == GPU_INVALIDATE_SAFE) {
|
|
|
|
framebufferManager_->UpdateFromMemory(addr, size, type == GPU_INVALIDATE_SAFE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::NotifyVideoUpload(u32 addr, int size, int width, int format) {
|
|
|
|
if (Memory::IsVRAMAddress(addr)) {
|
|
|
|
framebufferManager_->NotifyVideoUpload(addr, size, width, (GEBufferFormat)format);
|
|
|
|
}
|
|
|
|
textureCache_->NotifyVideoUpload(addr, size, width, (GEBufferFormat)format);
|
|
|
|
InvalidateCache(addr, size, GPU_INVALIDATE_SAFE);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GPUCommon::PerformStencilUpload(u32 dest, int size) {
|
|
|
|
if (framebufferManager_->MayIntersectFramebuffer(dest)) {
|
|
|
|
if (IsOnSeparateCPUThread()) {
|
|
|
|
GPUEvent ev(GPU_EVENT_FB_STENCIL_UPLOAD);
|
|
|
|
ev.fb_stencil_upload.dst = dest;
|
|
|
|
ev.fb_stencil_upload.size = size;
|
|
|
|
ScheduleEvent(ev);
|
|
|
|
} else {
|
|
|
|
PerformStencilUploadInternal(dest, size);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::PerformStencilUploadInternal(u32 dest, int size) {
|
|
|
|
framebufferManager_->NotifyStencilUpload(dest, size);
|
|
|
|
}
|
2017-02-14 11:42:35 +00:00
|
|
|
|
|
|
|
bool GPUCommon::GetCurrentFramebuffer(GPUDebugBuffer &buffer, GPUDebugFramebufferType type, int maxRes) {
|
|
|
|
u32 fb_address = type == GPU_DBG_FRAMEBUF_RENDER ? gstate.getFrameBufRawAddress() : framebufferManager_->DisplayFramebufAddr();
|
|
|
|
int fb_stride = type == GPU_DBG_FRAMEBUF_RENDER ? gstate.FrameBufStride() : framebufferManager_->DisplayFramebufStride();
|
|
|
|
GEBufferFormat format = type == GPU_DBG_FRAMEBUF_RENDER ? gstate.FrameBufFormat() : framebufferManager_->DisplayFramebufFormat();
|
|
|
|
return framebufferManager_->GetFramebuffer(fb_address, fb_stride, format, buffer, maxRes);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GPUCommon::GetCurrentDepthbuffer(GPUDebugBuffer &buffer) {
|
|
|
|
u32 fb_address = gstate.getFrameBufRawAddress();
|
|
|
|
int fb_stride = gstate.FrameBufStride();
|
|
|
|
|
|
|
|
u32 z_address = gstate.getDepthBufRawAddress();
|
|
|
|
int z_stride = gstate.DepthBufStride();
|
|
|
|
|
|
|
|
return framebufferManager_->GetDepthbuffer(fb_address, fb_stride, z_address, z_stride, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GPUCommon::GetCurrentStencilbuffer(GPUDebugBuffer &buffer) {
|
|
|
|
u32 fb_address = gstate.getFrameBufRawAddress();
|
|
|
|
int fb_stride = gstate.FrameBufStride();
|
|
|
|
|
|
|
|
return framebufferManager_->GetStencilbuffer(fb_address, fb_stride, buffer);
|
|
|
|
}
|
2017-02-17 23:43:02 +00:00
|
|
|
|
|
|
|
bool GPUCommon::GetOutputFramebuffer(GPUDebugBuffer &buffer) {
|
2017-05-24 09:09:08 +00:00
|
|
|
// framebufferManager_ can be null here when taking screens in software rendering mode.
|
|
|
|
// TODO: Actually grab the framebuffer anyway.
|
|
|
|
return framebufferManager_ ? framebufferManager_->GetOutputFramebuffer(buffer) : false;
|
2017-02-17 23:43:02 +00:00
|
|
|
}
|
2017-03-06 15:46:15 +00:00
|
|
|
|
|
|
|
bool GPUCommon::GetCurrentTexture(GPUDebugBuffer &buffer, int level) {
|
|
|
|
return textureCache_->GetCurrentTextureDebug(buffer, level);
|
2017-03-24 01:57:18 +00:00
|
|
|
}
|