2012-11-01 15:19:01 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
2012-11-04 22:58:25 +00:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
#include "../../Core/MemMap.h"
|
|
|
|
#include "../../Core/Host.h"
|
2012-11-19 20:23:29 +00:00
|
|
|
#include "../../Core/Config.h"
|
2012-11-19 22:29:14 +00:00
|
|
|
#include "../../Core/System.h"
|
2012-11-24 14:19:29 +00:00
|
|
|
#include "../../native/gfx_es2/gl_state.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
#include "../GPUState.h"
|
|
|
|
#include "../ge_constants.h"
|
2012-12-26 23:18:45 +00:00
|
|
|
#include "../GeDisasm.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
#include "ShaderManager.h"
|
|
|
|
#include "DisplayListInterpreter.h"
|
2012-11-19 20:23:29 +00:00
|
|
|
#include "Framebuffer.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
#include "TransformPipeline.h"
|
2012-11-22 22:07:15 +00:00
|
|
|
#include "TextureCache.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
#include "../../Core/HLE/sceKernelThread.h"
|
|
|
|
#include "../../Core/HLE/sceKernelInterrupt.h"
|
|
|
|
|
|
|
|
extern u32 curTextureWidth;
|
|
|
|
extern u32 curTextureHeight;
|
|
|
|
|
2013-01-11 01:00:51 +00:00
|
|
|
// Aggressively delete unused FBO:s to save gpu memory.
|
|
|
|
enum {
|
|
|
|
FBO_OLD_AGE = 4
|
|
|
|
};
|
|
|
|
|
2012-12-26 23:18:45 +00:00
|
|
|
const int flushOnChangedBeforeCommandList[] = {
|
|
|
|
GE_CMD_VERTEXTYPE,
|
|
|
|
GE_CMD_BLENDMODE,
|
|
|
|
GE_CMD_BLENDFIXEDA,
|
|
|
|
GE_CMD_BLENDFIXEDB,
|
2013-01-20 12:15:46 +00:00
|
|
|
GE_CMD_TEXOFFSETU,
|
|
|
|
GE_CMD_TEXOFFSETV,
|
|
|
|
GE_CMD_TEXSCALEU,
|
|
|
|
GE_CMD_TEXSCALEV,
|
2012-12-25 12:47:59 +00:00
|
|
|
GE_CMD_CULLFACEENABLE,
|
|
|
|
GE_CMD_TEXTUREMAPENABLE,
|
2012-12-21 20:49:09 +00:00
|
|
|
GE_CMD_LIGHTINGENABLE,
|
2012-12-25 12:47:59 +00:00
|
|
|
GE_CMD_FOGENABLE,
|
2013-01-14 19:43:18 +00:00
|
|
|
GE_CMD_ALPHABLENDENABLE,
|
|
|
|
GE_CMD_ALPHATESTENABLE,
|
|
|
|
GE_CMD_ALPHATEST,
|
|
|
|
GE_CMD_COLORTESTENABLE,
|
|
|
|
GE_CMD_COLORTESTMASK,
|
|
|
|
GE_CMD_COLORREF,
|
2013-01-05 17:15:07 +00:00
|
|
|
GE_CMD_MINZ,GE_CMD_MAXZ,
|
2013-01-20 12:15:46 +00:00
|
|
|
GE_CMD_FOG1,
|
|
|
|
GE_CMD_FOG2,
|
|
|
|
GE_CMD_FOGCOLOR,
|
2013-01-14 19:43:18 +00:00
|
|
|
GE_CMD_LMODE,
|
|
|
|
GE_CMD_REVERSENORMAL,
|
|
|
|
GE_CMD_MATERIALUPDATE,
|
|
|
|
GE_CMD_MATERIALEMISSIVE,
|
2012-12-21 20:49:09 +00:00
|
|
|
GE_CMD_MATERIALAMBIENT,
|
|
|
|
GE_CMD_MATERIALDIFFUSE,
|
|
|
|
GE_CMD_MATERIALSPECULAR,
|
|
|
|
GE_CMD_MATERIALALPHA,
|
|
|
|
GE_CMD_MATERIALSPECULARCOEF,
|
2013-01-14 19:43:18 +00:00
|
|
|
GE_CMD_AMBIENTCOLOR,
|
|
|
|
GE_CMD_AMBIENTALPHA,
|
2013-01-05 17:15:07 +00:00
|
|
|
GE_CMD_COLORMODEL,
|
|
|
|
GE_CMD_LIGHTTYPE0, GE_CMD_LIGHTTYPE1, GE_CMD_LIGHTTYPE2, GE_CMD_LIGHTTYPE3,
|
|
|
|
GE_CMD_LX0,GE_CMD_LY0,GE_CMD_LZ0,
|
|
|
|
GE_CMD_LX1,GE_CMD_LY1,GE_CMD_LZ1,
|
|
|
|
GE_CMD_LX2,GE_CMD_LY2,GE_CMD_LZ2,
|
|
|
|
GE_CMD_LX3,GE_CMD_LY3,GE_CMD_LZ3,
|
|
|
|
GE_CMD_LDX0,GE_CMD_LDY0,GE_CMD_LDZ0,
|
|
|
|
GE_CMD_LDX1,GE_CMD_LDY1,GE_CMD_LDZ1,
|
|
|
|
GE_CMD_LDX2,GE_CMD_LDY2,GE_CMD_LDZ2,
|
|
|
|
GE_CMD_LDX3,GE_CMD_LDY3,GE_CMD_LDZ3,
|
|
|
|
GE_CMD_LKA0,GE_CMD_LKB0,GE_CMD_LKC0,
|
|
|
|
GE_CMD_LKA1,GE_CMD_LKB1,GE_CMD_LKC1,
|
|
|
|
GE_CMD_LKA2,GE_CMD_LKB2,GE_CMD_LKC2,
|
|
|
|
GE_CMD_LKA3,GE_CMD_LKB3,GE_CMD_LKC3,
|
|
|
|
GE_CMD_LKS0,GE_CMD_LKS1,GE_CMD_LKS2,GE_CMD_LKS3,
|
|
|
|
GE_CMD_LKO0,GE_CMD_LKO1,GE_CMD_LKO2,GE_CMD_LKO3,
|
|
|
|
GE_CMD_LAC0,GE_CMD_LDC0,GE_CMD_LSC0,
|
|
|
|
GE_CMD_LAC1,GE_CMD_LDC1,GE_CMD_LSC1,
|
|
|
|
GE_CMD_LAC2,GE_CMD_LDC2,GE_CMD_LSC2,
|
|
|
|
GE_CMD_LAC3,GE_CMD_LDC3,GE_CMD_LSC3,
|
|
|
|
GE_CMD_VIEWPORTX1,GE_CMD_VIEWPORTY1,
|
|
|
|
GE_CMD_VIEWPORTX2,GE_CMD_VIEWPORTY2,
|
|
|
|
GE_CMD_VIEWPORTZ1,GE_CMD_VIEWPORTZ2,
|
|
|
|
GE_CMD_LIGHTENABLE0,GE_CMD_LIGHTENABLE1,GE_CMD_LIGHTENABLE2,GE_CMD_LIGHTENABLE3,
|
2012-12-21 20:49:09 +00:00
|
|
|
GE_CMD_CULL,
|
|
|
|
GE_CMD_PATCHDIVISION,
|
|
|
|
GE_CMD_MATERIALUPDATE,
|
|
|
|
GE_CMD_CLEARMODE,
|
2013-01-20 12:15:46 +00:00
|
|
|
GE_CMD_TEXMAPMODE,
|
|
|
|
GE_CMD_TEXSHADELS,
|
2012-12-21 20:49:09 +00:00
|
|
|
GE_CMD_TEXFUNC,
|
|
|
|
GE_CMD_TEXFILTER,
|
|
|
|
GE_CMD_TEXENVCOLOR,
|
|
|
|
GE_CMD_TEXMODE,
|
|
|
|
GE_CMD_TEXFORMAT,
|
|
|
|
GE_CMD_TEXWRAP,
|
|
|
|
GE_CMD_ZTESTENABLE,
|
|
|
|
GE_CMD_STENCILTESTENABLE,
|
2012-12-21 23:24:04 +00:00
|
|
|
GE_CMD_STENCILOP,
|
2013-01-14 19:43:18 +00:00
|
|
|
GE_CMD_STENCILTEST,
|
2012-12-21 20:49:09 +00:00
|
|
|
GE_CMD_ZTEST,
|
2013-01-20 12:15:46 +00:00
|
|
|
GE_CMD_MASKRGB,
|
|
|
|
GE_CMD_MASKALPHA,
|
|
|
|
};
|
|
|
|
|
|
|
|
const int flushBeforeCommandList[] = {
|
|
|
|
GE_CMD_BEZIER,
|
|
|
|
GE_CMD_SPLINE,
|
|
|
|
GE_CMD_SIGNAL,
|
|
|
|
GE_CMD_FINISH,
|
|
|
|
GE_CMD_BJUMP,
|
|
|
|
GE_CMD_OFFSETADDR,
|
|
|
|
GE_CMD_REGION1,GE_CMD_REGION2,
|
|
|
|
GE_CMD_FRAMEBUFPTR,
|
|
|
|
GE_CMD_FRAMEBUFWIDTH,
|
|
|
|
GE_CMD_FRAMEBUFPIXFORMAT,
|
|
|
|
GE_CMD_TEXADDR0,
|
|
|
|
GE_CMD_CLUTADDR,
|
|
|
|
GE_CMD_LOADCLUT,
|
|
|
|
GE_CMD_CLUTFORMAT,
|
|
|
|
GE_CMD_TRANSFERSTART,
|
|
|
|
GE_CMD_TEXBUFWIDTH0,
|
|
|
|
GE_CMD_TEXSIZE0,GE_CMD_TEXSIZE1,GE_CMD_TEXSIZE2,GE_CMD_TEXSIZE3,
|
|
|
|
GE_CMD_TEXSIZE4,GE_CMD_TEXSIZE5,GE_CMD_TEXSIZE6,GE_CMD_TEXSIZE7,
|
|
|
|
GE_CMD_ZBUFPTR,
|
|
|
|
GE_CMD_ZBUFWIDTH,
|
|
|
|
GE_CMD_OFFSETY,
|
|
|
|
GE_CMD_OFFSETX,
|
|
|
|
GE_CMD_OFFSETY,
|
|
|
|
GE_CMD_TEXFLUSH,
|
2013-01-05 17:15:07 +00:00
|
|
|
GE_CMD_MORPHWEIGHT0,GE_CMD_MORPHWEIGHT1,GE_CMD_MORPHWEIGHT2,GE_CMD_MORPHWEIGHT3,
|
|
|
|
GE_CMD_MORPHWEIGHT4,GE_CMD_MORPHWEIGHT5,GE_CMD_MORPHWEIGHT6,GE_CMD_MORPHWEIGHT7,
|
2013-01-20 12:15:46 +00:00
|
|
|
// These handle their own flushing.
|
|
|
|
/*
|
2012-12-21 20:49:09 +00:00
|
|
|
GE_CMD_WORLDMATRIXNUMBER,
|
2013-01-20 12:15:46 +00:00
|
|
|
GE_CMD_WORLDMATRIXDATA,
|
2012-12-21 20:49:09 +00:00
|
|
|
GE_CMD_VIEWMATRIXNUMBER,
|
2013-01-20 12:15:46 +00:00
|
|
|
GE_CMD_VIEWMATRIXDATA,
|
2012-12-21 20:49:09 +00:00
|
|
|
GE_CMD_PROJMATRIXNUMBER,
|
|
|
|
GE_CMD_PROJMATRIXDATA,
|
|
|
|
GE_CMD_TGENMATRIXNUMBER,
|
2013-01-20 12:15:46 +00:00
|
|
|
GE_CMD_TGENMATRIXDATA,
|
2012-12-21 20:49:09 +00:00
|
|
|
GE_CMD_BONEMATRIXNUMBER,
|
2013-01-20 12:15:46 +00:00
|
|
|
GE_CMD_BONEMATRIXDATA,
|
|
|
|
*/
|
2012-12-21 20:49:09 +00:00
|
|
|
};
|
|
|
|
|
2013-01-28 23:48:13 +00:00
|
|
|
GLES_GPU::GLES_GPU()
|
2012-12-21 22:02:35 +00:00
|
|
|
: interruptsEnabled_(true),
|
|
|
|
displayFramebufPtr_(0),
|
2013-01-24 23:36:59 +00:00
|
|
|
prevDisplayFramebuf_(0),
|
|
|
|
prevPrevDisplayFramebuf_(0),
|
2013-01-26 23:15:39 +00:00
|
|
|
resized_(false)
|
2012-12-28 20:58:00 +00:00
|
|
|
{
|
2012-12-25 14:28:34 +00:00
|
|
|
shaderManager_ = new ShaderManager();
|
|
|
|
transformDraw_.SetShaderManager(shaderManager_);
|
2013-01-30 19:40:26 +00:00
|
|
|
transformDraw_.SetTextureCache(&textureCache_);
|
|
|
|
|
2012-11-22 19:57:41 +00:00
|
|
|
// Sanity check gstate
|
|
|
|
if ((int *)&gstate.transferstart - (int *)&gstate != 0xEA) {
|
|
|
|
ERROR_LOG(G3D, "gstate has drifted out of sync!");
|
|
|
|
}
|
2012-12-21 20:49:09 +00:00
|
|
|
|
2012-12-26 23:18:45 +00:00
|
|
|
flushBeforeCommand_ = new u8[256];
|
2012-12-25 12:47:59 +00:00
|
|
|
memset(flushBeforeCommand_, 0, 256 * sizeof(bool));
|
2013-01-02 20:11:24 +00:00
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(flushOnChangedBeforeCommandList); i++) {
|
2012-12-26 23:18:45 +00:00
|
|
|
flushBeforeCommand_[flushOnChangedBeforeCommandList[i]] = 2;
|
|
|
|
}
|
2013-01-02 20:11:24 +00:00
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(flushBeforeCommandList); i++) {
|
2012-12-26 23:18:45 +00:00
|
|
|
flushBeforeCommand_[flushBeforeCommandList[i]] = 1;
|
2012-12-21 20:49:09 +00:00
|
|
|
}
|
2012-12-26 23:18:45 +00:00
|
|
|
flushBeforeCommand_[1] = 0;
|
2012-11-20 09:59:23 +00:00
|
|
|
}
|
|
|
|
|
2012-12-25 12:47:59 +00:00
|
|
|
GLES_GPU::~GLES_GPU() {
|
|
|
|
for (auto iter = vfbs_.begin(); iter != vfbs_.end(); ++iter) {
|
2012-11-19 22:29:14 +00:00
|
|
|
fbo_destroy((*iter)->fbo);
|
|
|
|
delete (*iter);
|
|
|
|
}
|
|
|
|
vfbs_.clear();
|
2012-12-25 14:28:34 +00:00
|
|
|
shaderManager_->ClearCache(true);
|
|
|
|
delete shaderManager_;
|
2012-12-25 12:47:59 +00:00
|
|
|
delete [] flushBeforeCommand_;
|
2012-11-19 22:29:14 +00:00
|
|
|
}
|
|
|
|
|
2012-12-25 14:28:34 +00:00
|
|
|
void GLES_GPU::DeviceLost() {
|
|
|
|
// Simply drop all caches and textures.
|
|
|
|
// FBO:s appear to survive? Or no?
|
|
|
|
shaderManager_->ClearCache(false);
|
2013-01-30 19:40:26 +00:00
|
|
|
textureCache_.Clear(false);
|
2012-12-25 14:28:34 +00:00
|
|
|
}
|
|
|
|
|
2012-12-25 12:47:59 +00:00
|
|
|
void GLES_GPU::InitClear() {
|
|
|
|
if (!g_Config.bBufferedRendering) {
|
2012-11-20 09:59:23 +00:00
|
|
|
glClearColor(0,0,0,1);
|
|
|
|
// glClearColor(1,0,1,1);
|
2013-01-14 18:26:10 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
2012-11-20 09:59:23 +00:00
|
|
|
}
|
2013-01-06 22:23:36 +00:00
|
|
|
glstate.viewport.set(0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight);
|
2012-11-19 20:23:29 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-12-26 23:18:45 +00:00
|
|
|
void GLES_GPU::DumpNextFrame() {
|
|
|
|
dumpNextFrame_ = true;
|
|
|
|
}
|
|
|
|
|
2012-12-25 12:47:59 +00:00
|
|
|
void GLES_GPU::BeginFrame() {
|
2013-01-30 19:40:26 +00:00
|
|
|
textureCache_.StartFrame();
|
2013-01-11 01:00:51 +00:00
|
|
|
DecimateFBOs();
|
2013-01-19 16:05:08 +00:00
|
|
|
transformDraw_.DecimateTrackedVertexArrays();
|
2012-11-22 22:07:15 +00:00
|
|
|
|
2012-12-26 23:18:45 +00:00
|
|
|
if (dumpNextFrame_) {
|
|
|
|
NOTICE_LOG(G3D, "DUMPING THIS FRAME");
|
|
|
|
dumpThisFrame_ = true;
|
|
|
|
dumpNextFrame_ = false;
|
|
|
|
} else if (dumpThisFrame_) {
|
|
|
|
dumpThisFrame_ = false;
|
|
|
|
}
|
2012-12-25 14:28:34 +00:00
|
|
|
shaderManager_->DirtyShader();
|
|
|
|
|
|
|
|
// Not sure if this is really needed.
|
|
|
|
shaderManager_->DirtyUniform(DIRTY_ALL);
|
|
|
|
|
2012-12-01 01:15:46 +00:00
|
|
|
// NOTE - this is all wrong. At the beginning of the frame is a TERRIBLE time to draw the fb.
|
2012-12-25 12:47:59 +00:00
|
|
|
if (g_Config.bDisplayFramebuffer && displayFramebufPtr_) {
|
2012-11-19 20:23:29 +00:00
|
|
|
INFO_LOG(HLE, "Drawing the framebuffer");
|
2012-12-01 01:15:46 +00:00
|
|
|
const u8 *pspframebuf = Memory::GetPointer((0x44000000) | (displayFramebufPtr_ & 0x1FFFFF)); // TODO - check
|
|
|
|
glstate.cullFace.disable();
|
|
|
|
glstate.depthTest.disable();
|
|
|
|
glstate.blend.disable();
|
|
|
|
framebufferManager.DrawPixels(pspframebuf, displayFormat_, displayStride_);
|
|
|
|
// TODO: restore state?
|
2012-11-19 20:23:29 +00:00
|
|
|
}
|
2012-11-20 10:35:48 +00:00
|
|
|
currentRenderVfb_ = 0;
|
2012-11-19 20:23:29 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-12-25 12:47:59 +00:00
|
|
|
void GLES_GPU::SetDisplayFramebuffer(u32 framebuf, u32 stride, int format) {
|
2012-11-19 22:53:38 +00:00
|
|
|
if (framebuf & 0x04000000) {
|
2012-12-26 23:18:45 +00:00
|
|
|
//DEBUG_LOG(G3D, "Switch display framebuffer %08x", framebuf);
|
2012-11-19 22:53:38 +00:00
|
|
|
displayFramebufPtr_ = framebuf;
|
|
|
|
displayStride_ = stride;
|
|
|
|
displayFormat_ = format;
|
|
|
|
} else {
|
2012-12-17 20:59:43 +00:00
|
|
|
ERROR_LOG(HLE, "Bogus framebuffer address: %08x", framebuf);
|
2012-11-19 22:53:38 +00:00
|
|
|
}
|
2012-11-19 20:23:29 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-12-25 12:47:59 +00:00
|
|
|
void GLES_GPU::CopyDisplayToOutput() {
|
|
|
|
transformDraw_.Flush();
|
2012-11-20 09:59:23 +00:00
|
|
|
if (!g_Config.bBufferedRendering)
|
|
|
|
return;
|
|
|
|
|
2012-12-19 14:14:41 +00:00
|
|
|
EndDebugDraw();
|
|
|
|
|
2012-11-19 22:29:14 +00:00
|
|
|
fbo_unbind();
|
|
|
|
|
2013-01-26 20:38:27 +00:00
|
|
|
VirtualFramebuffer *vfb = GetDisplayFBO();
|
2012-11-19 22:29:14 +00:00
|
|
|
if (!vfb) {
|
2012-11-19 23:31:19 +00:00
|
|
|
DEBUG_LOG(HLE, "Found no FBO! displayFBPtr = %08x", displayFramebufPtr_);
|
2012-11-19 22:29:14 +00:00
|
|
|
// No framebuffer to display! Clear to black.
|
|
|
|
glClearColor(0,0,0,1);
|
2013-01-14 18:26:10 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
2012-11-19 22:29:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-26 20:38:27 +00:00
|
|
|
prevPrevDisplayFramebuf_ = prevDisplayFramebuf_;
|
|
|
|
prevDisplayFramebuf_ = displayFramebuf_;
|
|
|
|
displayFramebuf_ = vfb;
|
|
|
|
|
|
|
|
glstate.viewport.set(0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight);
|
|
|
|
|
|
|
|
currentRenderVfb_ = 0;
|
|
|
|
|
2012-11-19 23:31:19 +00:00
|
|
|
DEBUG_LOG(HLE, "Displaying FBO %08x", vfb->fb_address);
|
2012-11-24 14:19:29 +00:00
|
|
|
glstate.blend.disable();
|
|
|
|
glstate.cullFace.disable();
|
|
|
|
glstate.depthTest.disable();
|
2012-11-26 16:35:08 +00:00
|
|
|
glstate.scissorTest.disable();
|
2012-11-19 22:29:14 +00:00
|
|
|
|
|
|
|
fbo_bind_color_as_texture(vfb->fbo, 0);
|
|
|
|
|
2012-12-01 01:15:46 +00:00
|
|
|
// These are in the output display coordinates
|
|
|
|
framebufferManager.DrawActiveTexture(480, 272, true);
|
2012-11-19 22:29:14 +00:00
|
|
|
|
2012-12-25 12:47:59 +00:00
|
|
|
shaderManager_->DirtyShader();
|
|
|
|
shaderManager_->DirtyUniform(DIRTY_ALL);
|
2012-11-19 23:31:19 +00:00
|
|
|
gstate_c.textureChanged = true;
|
2012-12-19 14:14:41 +00:00
|
|
|
|
2013-01-26 23:15:39 +00:00
|
|
|
if (resized_) {
|
|
|
|
DestroyAllFBOs();
|
|
|
|
glstate.viewport.set(0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight);
|
|
|
|
resized_ = false;
|
|
|
|
}
|
|
|
|
|
2012-12-19 14:14:41 +00:00
|
|
|
BeginDebugDraw();
|
2012-11-19 22:29:14 +00:00
|
|
|
}
|
|
|
|
|
2013-01-11 01:00:51 +00:00
|
|
|
void GLES_GPU::DecimateFBOs() {
|
|
|
|
for (auto iter = vfbs_.begin(); iter != vfbs_.end();) {
|
2013-01-11 16:54:30 +00:00
|
|
|
VirtualFramebuffer *v = *iter;
|
2013-01-24 23:36:59 +00:00
|
|
|
if (v == displayFramebuf_ ||
|
|
|
|
v == prevDisplayFramebuf_ ||
|
|
|
|
v == prevPrevDisplayFramebuf_) {
|
2013-01-11 16:54:30 +00:00
|
|
|
++iter;
|
|
|
|
continue;
|
|
|
|
}
|
2013-01-11 01:00:51 +00:00
|
|
|
if ((*iter)->last_frame_used + FBO_OLD_AGE < gpuStats.numFrames) {
|
2013-01-26 20:38:27 +00:00
|
|
|
INFO_LOG(HLE, "Destroying FBO %i (%i x %i x %i)", v->fb_address, v->width, v->height, v->format);
|
|
|
|
fbo_destroy(v->fbo);
|
|
|
|
delete v;
|
2013-01-11 01:00:51 +00:00
|
|
|
vfbs_.erase(iter++);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-24 23:36:59 +00:00
|
|
|
static bool MaskedEqual(u32 addr1, u32 addr2) {
|
|
|
|
return (addr1 & 0x3FFFFFF) == (addr2 & 0x3FFFFFF);
|
|
|
|
}
|
|
|
|
|
2012-12-25 12:47:59 +00:00
|
|
|
GLES_GPU::VirtualFramebuffer *GLES_GPU::GetDisplayFBO() {
|
|
|
|
for (auto iter = vfbs_.begin(); iter != vfbs_.end(); ++iter) {
|
2013-01-26 20:38:27 +00:00
|
|
|
VirtualFramebuffer *v = *iter;
|
|
|
|
if (MaskedEqual(v->fb_address, displayFramebufPtr_) && v->format == displayFormat_) {
|
2013-01-25 05:32:36 +00:00
|
|
|
// Could check w too but whatever
|
2012-11-19 22:29:14 +00:00
|
|
|
return *iter;
|
|
|
|
}
|
|
|
|
}
|
2013-01-03 09:19:18 +00:00
|
|
|
DEBUG_LOG(HLE, "Finding no FBO matching address %08x", displayFramebufPtr_);
|
2013-01-24 23:36:59 +00:00
|
|
|
#if 0 // defined(_DEBUG)
|
2013-01-03 09:19:18 +00:00
|
|
|
std::string debug = "FBOs: ";
|
|
|
|
for (auto iter = vfbs_.begin(); iter != vfbs_.end(); ++iter) {
|
|
|
|
char temp[256];
|
|
|
|
sprintf(temp, "%08x %i %i", (*iter)->fb_address, (*iter)->width, (*iter)->height);
|
|
|
|
debug += std::string(temp);
|
|
|
|
}
|
|
|
|
ERROR_LOG(HLE, "FBOs: %s", debug.c_str());
|
|
|
|
#endif
|
2012-11-19 22:29:14 +00:00
|
|
|
return 0;
|
2012-11-18 12:14:22 +00:00
|
|
|
}
|
|
|
|
|
2012-12-25 12:47:59 +00:00
|
|
|
void GLES_GPU::SetRenderFrameBuffer() {
|
2012-11-20 09:59:23 +00:00
|
|
|
if (!g_Config.bBufferedRendering)
|
|
|
|
return;
|
2012-11-19 22:29:14 +00:00
|
|
|
// Get parameters
|
|
|
|
u32 fb_address = (gstate.fbptr & 0xFFE000) | ((gstate.fbwidth & 0xFF0000) << 8);
|
|
|
|
int fb_stride = gstate.fbwidth & 0x3C0;
|
|
|
|
|
|
|
|
u32 z_address = (gstate.zbptr & 0xFFE000) | ((gstate.zbwidth & 0xFF0000) << 8);
|
|
|
|
int z_stride = gstate.zbwidth & 0x3C0;
|
2012-12-25 12:47:59 +00:00
|
|
|
|
2012-11-19 22:29:14 +00:00
|
|
|
// Yeah this is not completely right. but it'll do for now.
|
|
|
|
int drawing_width = ((gstate.region2) & 0x3FF) + 1;
|
|
|
|
int drawing_height = ((gstate.region2 >> 10) & 0x3FF) + 1;
|
|
|
|
|
2013-01-03 09:19:18 +00:00
|
|
|
// HACK for first frame where some games don't init things right
|
|
|
|
if (drawing_width == 1 && drawing_height == 1) {
|
|
|
|
drawing_width = 480;
|
|
|
|
drawing_height = 272;
|
|
|
|
}
|
|
|
|
|
2012-11-19 22:29:14 +00:00
|
|
|
int fmt = gstate.framebufpixformat & 3;
|
2012-12-01 22:38:18 +00:00
|
|
|
|
2012-11-19 22:29:14 +00:00
|
|
|
// Find a matching framebuffer
|
|
|
|
VirtualFramebuffer *vfb = 0;
|
2012-12-25 12:47:59 +00:00
|
|
|
for (auto iter = vfbs_.begin(); iter != vfbs_.end(); ++iter) {
|
2012-11-19 22:29:14 +00:00
|
|
|
VirtualFramebuffer *v = *iter;
|
2013-01-26 20:38:27 +00:00
|
|
|
if (MaskedEqual(v->fb_address, fb_address) && v->width == drawing_width && v->height == drawing_height && v->format == fmt) {
|
2012-11-19 22:29:14 +00:00
|
|
|
// Let's not be so picky for now. Let's say this is the one.
|
|
|
|
vfb = v;
|
|
|
|
// Update fb stride in case it changed
|
|
|
|
vfb->fb_stride = fb_stride;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-12-01 22:38:18 +00:00
|
|
|
|
2012-11-19 22:29:14 +00:00
|
|
|
// None found? Create one.
|
|
|
|
if (!vfb) {
|
2012-12-25 12:47:59 +00:00
|
|
|
transformDraw_.Flush();
|
2012-12-21 22:40:11 +00:00
|
|
|
gstate_c.textureChanged = true;
|
2013-01-26 20:38:27 +00:00
|
|
|
vfb = new VirtualFramebuffer();
|
2012-11-19 22:29:14 +00:00
|
|
|
vfb->fb_address = fb_address;
|
|
|
|
vfb->fb_stride = fb_stride;
|
|
|
|
vfb->z_address = z_address;
|
|
|
|
vfb->z_stride = z_stride;
|
|
|
|
vfb->width = drawing_width;
|
|
|
|
vfb->height = drawing_height;
|
2012-11-19 23:31:19 +00:00
|
|
|
vfb->format = fmt;
|
2013-01-23 22:02:49 +00:00
|
|
|
|
2013-01-26 20:38:27 +00:00
|
|
|
vfb->colorDepth = FBO_8888;
|
|
|
|
switch (fmt) {
|
2013-01-23 22:02:49 +00:00
|
|
|
case GE_FORMAT_4444: vfb->colorDepth = FBO_4444;
|
|
|
|
case GE_FORMAT_5551: vfb->colorDepth = FBO_5551;
|
|
|
|
case GE_FORMAT_565: vfb->colorDepth = FBO_565;
|
|
|
|
case GE_FORMAT_8888: vfb->colorDepth = FBO_8888;
|
|
|
|
}
|
|
|
|
//#ifdef ANDROID
|
2013-01-24 23:36:59 +00:00
|
|
|
// vfb->colorDepth = FBO_8888;
|
2013-01-23 22:02:49 +00:00
|
|
|
//#endif
|
2013-01-26 23:15:39 +00:00
|
|
|
float renderWidthFactor = (float)PSP_CoreParameter().renderWidth / 480.0f;
|
|
|
|
float renderHeightFactor = (float)PSP_CoreParameter().renderHeight / 272.0f;
|
|
|
|
vfb->fbo = fbo_create(vfb->width * renderWidthFactor, vfb->height * renderHeightFactor, 1, true, vfb->colorDepth);
|
2013-01-23 22:02:49 +00:00
|
|
|
|
2013-01-11 01:00:51 +00:00
|
|
|
vfb->last_frame_used = gpuStats.numFrames;
|
2012-11-19 22:29:14 +00:00
|
|
|
vfbs_.push_back(vfb);
|
|
|
|
fbo_bind_as_render_target(vfb->fbo);
|
2013-01-23 22:02:49 +00:00
|
|
|
glEnable(GL_DITHER);
|
2013-01-26 23:15:39 +00:00
|
|
|
glstate.viewport.set(0, 0, PSP_CoreParameter().renderWidth, PSP_CoreParameter().renderHeight);
|
2012-11-19 22:29:14 +00:00
|
|
|
currentRenderVfb_ = vfb;
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
2013-01-26 20:38:27 +00:00
|
|
|
INFO_LOG(HLE, "Creating FBO for %08x : %i x %i x %i", vfb->fb_address, vfb->width, vfb->height, vfb->format);
|
2012-11-19 22:29:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-25 12:47:59 +00:00
|
|
|
if (vfb != currentRenderVfb_) {
|
|
|
|
transformDraw_.Flush();
|
2012-11-19 22:29:14 +00:00
|
|
|
// Use it as a render target.
|
2012-11-27 10:40:30 +00:00
|
|
|
DEBUG_LOG(HLE, "Switching render target to FBO for %08x", vfb->fb_address);
|
2012-12-21 22:40:11 +00:00
|
|
|
gstate_c.textureChanged = true;
|
2012-11-19 22:29:14 +00:00
|
|
|
fbo_bind_as_render_target(vfb->fbo);
|
2013-01-20 21:05:11 +00:00
|
|
|
|
|
|
|
#ifdef USING_GLES2
|
2013-01-23 07:31:29 +00:00
|
|
|
// Tiled renderers benefit IMMENSELY from clearing an FBO before rendering
|
|
|
|
// to it. Let's hope this doesn't break too many things...
|
|
|
|
// It did, will have to find a better solution like clearing only if this is
|
|
|
|
// the first time the buffer is bound on this frame.
|
|
|
|
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
2013-01-20 21:05:11 +00:00
|
|
|
#endif
|
2013-01-26 23:15:39 +00:00
|
|
|
glstate.viewport.set(0, 0, PSP_CoreParameter().renderWidth, PSP_CoreParameter().renderHeight);
|
2012-11-19 22:29:14 +00:00
|
|
|
currentRenderVfb_ = vfb;
|
2013-01-11 01:00:51 +00:00
|
|
|
vfb->last_frame_used = gpuStats.numFrames;
|
2012-11-19 22:29:14 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-19 20:23:29 +00:00
|
|
|
|
2012-12-25 12:47:59 +00:00
|
|
|
void GLES_GPU::BeginDebugDraw() {
|
2012-12-19 14:14:41 +00:00
|
|
|
if (g_Config.bDrawWireframe) {
|
|
|
|
#ifndef USING_GLES2
|
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void GLES_GPU::EndDebugDraw() {
|
|
|
|
#ifndef USING_GLES2
|
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
|
|
|
#endif
|
|
|
|
}
|
2012-11-19 23:31:19 +00:00
|
|
|
|
|
|
|
// Render queue
|
|
|
|
|
2012-12-28 20:58:00 +00:00
|
|
|
void GLES_GPU::DrawSync(int mode)
|
|
|
|
{
|
2012-12-25 12:47:59 +00:00
|
|
|
transformDraw_.Flush();
|
2012-11-06 17:14:09 +00:00
|
|
|
}
|
|
|
|
|
2012-12-25 12:47:59 +00:00
|
|
|
void GLES_GPU::Continue() {
|
2012-11-28 12:45:22 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-12-25 12:47:59 +00:00
|
|
|
void GLES_GPU::Break() {
|
2012-11-28 12:45:22 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-12-25 12:47:59 +00:00
|
|
|
static void EnterClearMode(u32 data) {
|
2012-11-01 15:19:01 +00:00
|
|
|
bool colMask = (data >> 8) & 1;
|
|
|
|
bool alphaMask = (data >> 9) & 1;
|
|
|
|
bool updateZ = (data >> 10) & 1;
|
2012-12-01 01:15:46 +00:00
|
|
|
glstate.colorMask.set(colMask, colMask, colMask, alphaMask);
|
2012-11-28 12:45:22 +00:00
|
|
|
glstate.depthWrite.set(updateZ ? GL_TRUE : GL_FALSE);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-25 12:47:59 +00:00
|
|
|
static void LeaveClearMode() {
|
2012-11-01 15:19:01 +00:00
|
|
|
// We have to reset the following state as per the state of the command registers:
|
|
|
|
// Back face culling
|
|
|
|
// Texture map enable (meh)
|
|
|
|
// Fogging
|
|
|
|
// Antialiasing
|
|
|
|
// Alpha test
|
2012-12-01 01:15:46 +00:00
|
|
|
glstate.colorMask.set(1,1,1,1);
|
2012-11-28 12:45:22 +00:00
|
|
|
glstate.depthWrite.set(!(gstate.zmsk & 1) ? GL_TRUE : GL_FALSE);
|
2012-11-01 15:19:01 +00:00
|
|
|
// dirtyshader?
|
|
|
|
}
|
|
|
|
|
2012-12-29 01:10:29 +00:00
|
|
|
void GLES_GPU::PreExecuteOp(u32 op, u32 diff) {
|
|
|
|
u32 cmd = op >> 24;
|
|
|
|
if (flushBeforeCommand_[cmd] == 1 || (diff && flushBeforeCommand_[cmd] == 2))
|
2013-01-20 12:15:46 +00:00
|
|
|
{
|
|
|
|
if (dumpThisFrame_) {
|
|
|
|
NOTICE_LOG(G3D, "================ FLUSH ================");
|
|
|
|
}
|
2012-12-29 01:10:29 +00:00
|
|
|
transformDraw_.Flush();
|
2013-01-20 12:15:46 +00:00
|
|
|
}
|
2012-12-29 01:10:29 +00:00
|
|
|
}
|
|
|
|
|
2012-12-25 12:47:59 +00:00
|
|
|
void GLES_GPU::ExecuteOp(u32 op, u32 diff) {
|
2012-11-01 15:19:01 +00:00
|
|
|
u32 cmd = op >> 24;
|
|
|
|
u32 data = op & 0xFFFFFF;
|
|
|
|
|
|
|
|
// Handle control and drawing commands here directly. The others we delegate.
|
2012-12-28 18:33:26 +00:00
|
|
|
switch (cmd) {
|
2012-11-01 15:19:01 +00:00
|
|
|
case GE_CMD_BASE:
|
2012-12-26 23:18:45 +00:00
|
|
|
//DEBUG_LOG(G3D,"DL BASE: %06x", data & 0xFFFFFF);
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_VADDR: /// <<8????
|
2012-11-18 12:04:49 +00:00
|
|
|
gstate_c.vertexAddr = ((gstate.base & 0x00FF0000) << 8)|data;
|
2012-12-26 23:18:45 +00:00
|
|
|
//DEBUG_LOG(G3D,"DL VADDR: %06x", gstate_c.vertexAddr);
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_IADDR:
|
2012-11-18 12:04:49 +00:00
|
|
|
gstate_c.indexAddr = ((gstate.base & 0x00FF0000) << 8)|data;
|
2012-12-26 23:18:45 +00:00
|
|
|
//DEBUG_LOG(G3D,"DL IADDR: %06x", gstate_c.indexAddr);
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_PRIM:
|
|
|
|
{
|
2012-11-19 22:29:14 +00:00
|
|
|
SetRenderFrameBuffer();
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
u32 count = data & 0xFFFF;
|
|
|
|
u32 type = data >> 16;
|
2012-12-28 18:33:26 +00:00
|
|
|
|
|
|
|
if (!Memory::IsValidAddress(gstate_c.vertexAddr)) {
|
2012-12-20 13:35:47 +00:00
|
|
|
ERROR_LOG(G3D, "Bad vertex address %08x!", gstate_c.vertexAddr);
|
|
|
|
break;
|
|
|
|
}
|
2012-12-28 19:53:26 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
// TODO: Split this so that we can collect sequences of primitives, can greatly speed things up
|
|
|
|
// on platforms where draw calls are expensive like mobile and D3D
|
2012-11-18 12:04:49 +00:00
|
|
|
void *verts = Memory::GetPointer(gstate_c.vertexAddr);
|
2012-11-01 15:19:01 +00:00
|
|
|
void *inds = 0;
|
2012-12-28 18:33:26 +00:00
|
|
|
if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) {
|
|
|
|
if (!Memory::IsValidAddress(gstate_c.indexAddr)) {
|
2012-12-20 13:35:47 +00:00
|
|
|
ERROR_LOG(G3D, "Bad index address %08x!", gstate_c.indexAddr);
|
|
|
|
break;
|
|
|
|
}
|
2012-11-18 12:04:49 +00:00
|
|
|
inds = Memory::GetPointer(gstate_c.indexAddr);
|
2012-12-20 13:35:47 +00:00
|
|
|
}
|
2012-11-28 12:45:22 +00:00
|
|
|
|
|
|
|
int bytesRead;
|
2013-01-04 08:54:19 +00:00
|
|
|
transformDraw_.SubmitPrim(verts, inds, type, count, gstate.vertType, -1, &bytesRead);
|
2012-12-28 19:53:26 +00:00
|
|
|
// After drawing, we advance the vertexAddr (when non indexed) or indexAddr (when indexed).
|
|
|
|
// Some games rely on this, they don't bother reloading VADDR and IADDR.
|
|
|
|
// Q: Are these changed reflected in the real registers? Needs testing.
|
|
|
|
if (inds) {
|
|
|
|
int indexSize = 1;
|
|
|
|
if ((gstate.vertType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_16BIT)
|
|
|
|
indexSize = 2;
|
|
|
|
gstate_c.indexAddr += count * indexSize;
|
|
|
|
} else {
|
|
|
|
gstate_c.vertexAddr += bytesRead;
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// The arrow and other rotary items in Puzbob are bezier patches, strangely enough.
|
|
|
|
case GE_CMD_BEZIER:
|
|
|
|
{
|
2012-11-02 11:33:16 +00:00
|
|
|
int bz_ucount = data & 0xFF;
|
|
|
|
int bz_vcount = (data >> 8) & 0xFF;
|
2012-12-25 12:47:59 +00:00
|
|
|
transformDraw_.DrawBezier(bz_ucount, bz_vcount);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_SPLINE:
|
|
|
|
{
|
2012-11-02 11:33:16 +00:00
|
|
|
int sp_ucount = data & 0xFF;
|
|
|
|
int sp_vcount = (data >> 8) & 0xFF;
|
|
|
|
int sp_utype = (data >> 16) & 0x3;
|
|
|
|
int sp_vtype = (data >> 18) & 0x3;
|
2012-12-28 18:33:26 +00:00
|
|
|
transformDraw_.DrawSpline(sp_ucount, sp_vcount, sp_utype, sp_vtype);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-12-28 18:33:26 +00:00
|
|
|
case GE_CMD_JUMP:
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2012-11-09 16:51:45 +00:00
|
|
|
u32 target = (((gstate.base & 0x00FF0000) << 8) | (op & 0xFFFFFC)) & 0x0FFFFFFF;
|
2012-12-28 18:33:26 +00:00
|
|
|
if (Memory::IsValidAddress(target)) {
|
2012-12-28 20:58:00 +00:00
|
|
|
currentList->pc = target - 4; // pc will be increased after we return, counteract that
|
2012-12-28 18:33:26 +00:00
|
|
|
} else {
|
|
|
|
ERROR_LOG(G3D, "JUMP to illegal address %08x - ignoring??", target);
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-12-28 18:33:26 +00:00
|
|
|
case GE_CMD_CALL:
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2012-12-28 20:58:00 +00:00
|
|
|
u32 retval = currentList->pc + 4;
|
2013-01-29 16:07:36 +00:00
|
|
|
u32 target = (((gstate.base & 0x00FF0000) << 8) | (op & 0xFFFFFC)) & 0xFFFFFFF;
|
2012-12-22 15:24:01 +00:00
|
|
|
if (stackptr == ARRAY_SIZE(stack)) {
|
2012-11-28 12:45:22 +00:00
|
|
|
ERROR_LOG(G3D, "CALL: Stack full!");
|
2013-01-29 16:07:36 +00:00
|
|
|
} else if (!Memory::IsValidAddress(target)) {
|
|
|
|
ERROR_LOG(G3D, "CALL to illegal address %08x - ignoring??", target);
|
2012-11-28 12:45:22 +00:00
|
|
|
} else {
|
|
|
|
stack[stackptr++] = retval;
|
2012-12-28 20:58:00 +00:00
|
|
|
currentList->pc = target - 4; // pc will be increased after we return, counteract that
|
2012-11-28 12:45:22 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-12-28 18:33:26 +00:00
|
|
|
case GE_CMD_RET:
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2012-12-28 20:58:00 +00:00
|
|
|
u32 target = (currentList->pc & 0xF0000000) | (stack[--stackptr] & 0x0FFFFFFF);
|
|
|
|
currentList->pc = target - 4;
|
2013-01-29 16:07:36 +00:00
|
|
|
if (!Memory::IsValidAddress(currentList->pc))
|
|
|
|
{
|
|
|
|
ERROR_LOG(G3D, "Invalid DL PC %08x on return", currentList->pc);
|
|
|
|
finished = true;
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_SIGNAL:
|
|
|
|
{
|
2012-12-28 18:33:26 +00:00
|
|
|
// Processed in GE_END. Has data.
|
2012-11-28 12:45:22 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-28 12:45:22 +00:00
|
|
|
case GE_CMD_FINISH:
|
2012-12-21 05:54:40 +00:00
|
|
|
// TODO: Should this run while interrupts are suspended?
|
2012-11-28 12:45:22 +00:00
|
|
|
if (interruptsEnabled_)
|
2012-12-22 06:50:35 +00:00
|
|
|
__TriggerInterruptWithArg(PSP_INTR_HLE, PSP_GE_INTR, currentList->subIntrBase | PSP_GE_SUBINTR_FINISH, 0);
|
2012-11-28 12:45:22 +00:00
|
|
|
break;
|
|
|
|
|
2012-12-28 18:33:26 +00:00
|
|
|
case GE_CMD_END:
|
|
|
|
switch (prev >> 24) {
|
2012-11-28 12:45:22 +00:00
|
|
|
case GE_CMD_SIGNAL:
|
|
|
|
{
|
2012-12-28 20:58:00 +00:00
|
|
|
currentList->status = PSP_GE_LIST_END_REACHED;
|
2012-12-21 09:18:52 +00:00
|
|
|
// TODO: see http://code.google.com/p/jpcsp/source/detail?r=2935#
|
2012-11-28 13:01:28 +00:00
|
|
|
int behaviour = (prev >> 16) & 0xFF;
|
|
|
|
int signal = prev & 0xFFFF;
|
|
|
|
int enddata = data & 0xFFFF;
|
2012-11-28 12:45:22 +00:00
|
|
|
// We should probably defer to sceGe here, no sense in implementing this stuff in every GPU
|
|
|
|
switch (behaviour) {
|
|
|
|
case 1: // Signal with Wait
|
2012-12-28 18:33:26 +00:00
|
|
|
ERROR_LOG(G3D, "Signal with Wait UNIMPLEMENTED! signal/end: %04x %04x", signal, enddata);
|
2012-11-28 12:45:22 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2012-12-28 18:33:26 +00:00
|
|
|
ERROR_LOG(G3D, "Signal without wait. signal/end: %04x %04x", signal, enddata);
|
2012-11-28 12:45:22 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2012-11-28 13:01:28 +00:00
|
|
|
ERROR_LOG(G3D, "Signal with Pause UNIMPLEMENTED! signal/end: %04x %04x", signal, enddata);
|
2012-11-28 12:45:22 +00:00
|
|
|
break;
|
|
|
|
case 0x10:
|
2012-11-28 13:01:28 +00:00
|
|
|
ERROR_LOG(G3D, "Signal with Jump UNIMPLEMENTED! signal/end: %04x %04x", signal, enddata);
|
2012-11-28 12:45:22 +00:00
|
|
|
break;
|
|
|
|
case 0x11:
|
2012-11-28 15:12:29 +00:00
|
|
|
ERROR_LOG(G3D, "Signal with Call UNIMPLEMENTED! signal/end: %04x %04x", signal, enddata);
|
2012-11-28 12:45:22 +00:00
|
|
|
break;
|
|
|
|
case 0x12:
|
2012-11-28 13:01:28 +00:00
|
|
|
ERROR_LOG(G3D, "Signal with Return UNIMPLEMENTED! signal/end: %04x %04x", signal, enddata);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERROR_LOG(G3D, "UNKNOWN Signal UNIMPLEMENTED %i ! signal/end: %04x %04x", behaviour, signal, enddata);
|
2012-11-28 12:45:22 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-12-21 05:54:40 +00:00
|
|
|
// TODO: Should this run while interrupts are suspended?
|
2012-11-28 12:45:22 +00:00
|
|
|
if (interruptsEnabled_)
|
2012-12-22 06:50:35 +00:00
|
|
|
__TriggerInterruptWithArg(PSP_INTR_HLE, PSP_GE_INTR, currentList->subIntrBase | PSP_GE_SUBINTR_SIGNAL, signal);
|
2012-11-28 12:45:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GE_CMD_FINISH:
|
2012-12-28 20:58:00 +00:00
|
|
|
currentList->status = PSP_GE_LIST_DONE;
|
2012-11-28 12:45:22 +00:00
|
|
|
finished = true;
|
|
|
|
break;
|
|
|
|
default:
|
2012-12-28 18:33:26 +00:00
|
|
|
DEBUG_LOG(G3D,"Ah, not finished: %06x", prev & 0xFFFFFF);
|
2012-11-28 12:45:22 +00:00
|
|
|
break;
|
2012-11-06 17:14:09 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_BJUMP:
|
|
|
|
// bounding box jump. Let's just not jump, for now.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_BOUNDINGBOX:
|
|
|
|
// bounding box test. Let's do nothing.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_ORIGIN:
|
2012-12-28 20:58:00 +00:00
|
|
|
gstate.offsetAddr = currentList->pc & 0xFFFFFF;
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_VERTEXTYPE:
|
|
|
|
if (diff & GE_VTYPE_THROUGH) {
|
|
|
|
// Throughmode changed, let's make the proj matrix dirty.
|
2012-12-25 12:47:59 +00:00
|
|
|
shaderManager_->DirtyUniform(DIRTY_PROJMATRIX);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
// This sets through-mode or not, as well.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_OFFSETADDR:
|
|
|
|
// offsetAddr = data<<8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_REGION1:
|
|
|
|
{
|
|
|
|
int x1 = data & 0x3ff;
|
|
|
|
int y1 = data >> 10;
|
|
|
|
//topleft
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_REGION2:
|
|
|
|
{
|
|
|
|
int x2 = data & 0x3ff;
|
|
|
|
int y2 = data >> 10;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_CLIPENABLE:
|
|
|
|
//we always clip, this is opengl
|
|
|
|
break;
|
|
|
|
|
2012-12-28 18:33:26 +00:00
|
|
|
case GE_CMD_CULLFACEENABLE:
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
2012-12-28 18:33:26 +00:00
|
|
|
case GE_CMD_TEXTUREMAPENABLE:
|
2012-12-14 00:04:45 +00:00
|
|
|
gstate_c.textureChanged = true;
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_LIGHTINGENABLE:
|
|
|
|
break;
|
|
|
|
|
2013-01-14 19:43:18 +00:00
|
|
|
case GE_CMD_FOGCOLOR:
|
|
|
|
shaderManager_->DirtyUniform(DIRTY_FOGCOLOR);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_FOG1:
|
|
|
|
shaderManager_->DirtyUniform(DIRTY_FOGCOEF);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_FOG2:
|
|
|
|
shaderManager_->DirtyUniform(DIRTY_FOGCOEF);
|
|
|
|
break;
|
|
|
|
|
2012-12-28 18:33:26 +00:00
|
|
|
case GE_CMD_FOGENABLE:
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_DITHERENABLE:
|
|
|
|
break;
|
|
|
|
|
2012-12-28 18:33:26 +00:00
|
|
|
case GE_CMD_OFFSETX:
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
2012-12-28 18:33:26 +00:00
|
|
|
case GE_CMD_OFFSETY:
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
2012-12-01 22:38:18 +00:00
|
|
|
case GE_CMD_TEXSCALEU:
|
|
|
|
gstate_c.uScale = getFloat24(data);
|
2012-12-25 12:47:59 +00:00
|
|
|
shaderManager_->DirtyUniform(DIRTY_UVSCALEOFFSET);
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
2012-12-01 22:38:18 +00:00
|
|
|
case GE_CMD_TEXSCALEV:
|
|
|
|
gstate_c.vScale = getFloat24(data);
|
2012-12-25 12:47:59 +00:00
|
|
|
shaderManager_->DirtyUniform(DIRTY_UVSCALEOFFSET);
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
2012-12-01 22:38:18 +00:00
|
|
|
case GE_CMD_TEXOFFSETU:
|
|
|
|
gstate_c.uOff = getFloat24(data);
|
2012-12-25 12:47:59 +00:00
|
|
|
shaderManager_->DirtyUniform(DIRTY_UVSCALEOFFSET);
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
2012-12-01 22:38:18 +00:00
|
|
|
case GE_CMD_TEXOFFSETV:
|
|
|
|
gstate_c.vOff = getFloat24(data);
|
2012-12-25 12:47:59 +00:00
|
|
|
shaderManager_->DirtyUniform(DIRTY_UVSCALEOFFSET);
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_SCISSOR1:
|
|
|
|
case GE_CMD_SCISSOR2:
|
|
|
|
break;
|
|
|
|
|
2012-11-24 23:15:21 +00:00
|
|
|
case GE_CMD_MINZ:
|
|
|
|
gstate_c.zMin = getFloat24(data) / 65535.f;
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
2012-11-24 23:15:21 +00:00
|
|
|
case GE_CMD_MAXZ:
|
|
|
|
gstate_c.zMax = getFloat24(data) / 65535.f;
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_FRAMEBUFPTR:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_FRAMEBUFWIDTH:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_FRAMEBUFPIXFORMAT:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_TEXADDR0:
|
|
|
|
case GE_CMD_TEXADDR1:
|
|
|
|
case GE_CMD_TEXADDR2:
|
|
|
|
case GE_CMD_TEXADDR3:
|
|
|
|
case GE_CMD_TEXADDR4:
|
|
|
|
case GE_CMD_TEXADDR5:
|
|
|
|
case GE_CMD_TEXADDR6:
|
|
|
|
case GE_CMD_TEXADDR7:
|
2012-12-21 22:40:11 +00:00
|
|
|
gstate_c.textureChanged = true;
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_TEXBUFWIDTH0:
|
|
|
|
case GE_CMD_TEXBUFWIDTH1:
|
|
|
|
case GE_CMD_TEXBUFWIDTH2:
|
|
|
|
case GE_CMD_TEXBUFWIDTH3:
|
|
|
|
case GE_CMD_TEXBUFWIDTH4:
|
|
|
|
case GE_CMD_TEXBUFWIDTH5:
|
|
|
|
case GE_CMD_TEXBUFWIDTH6:
|
|
|
|
case GE_CMD_TEXBUFWIDTH7:
|
2012-12-21 22:40:11 +00:00
|
|
|
gstate_c.textureChanged = true;
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_CLUTADDR:
|
2012-12-21 22:43:48 +00:00
|
|
|
gstate_c.textureChanged = true;
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_CLUTADDRUPPER:
|
2012-12-21 22:40:11 +00:00
|
|
|
gstate_c.textureChanged = true;
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_LOADCLUT:
|
2012-12-21 22:40:11 +00:00
|
|
|
gstate_c.textureChanged = true;
|
2012-11-18 12:04:49 +00:00
|
|
|
// This could be used to "dirty" textures with clut.
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
2012-12-19 14:14:41 +00:00
|
|
|
case GE_CMD_TEXMAPMODE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_TEXSHADELS:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_CLUTFORMAT:
|
2012-12-28 18:33:26 +00:00
|
|
|
gstate_c.textureChanged = true;
|
2012-12-19 14:14:41 +00:00
|
|
|
break;
|
|
|
|
|
2012-11-19 22:29:14 +00:00
|
|
|
case GE_CMD_TRANSFERSRC:
|
2012-11-01 15:19:01 +00:00
|
|
|
case GE_CMD_TRANSFERSRCW:
|
2012-11-19 22:29:14 +00:00
|
|
|
case GE_CMD_TRANSFERDST:
|
2012-11-01 15:19:01 +00:00
|
|
|
case GE_CMD_TRANSFERDSTW:
|
|
|
|
case GE_CMD_TRANSFERSRCPOS:
|
|
|
|
case GE_CMD_TRANSFERDSTPOS:
|
2012-12-28 18:33:26 +00:00
|
|
|
break;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
case GE_CMD_TRANSFERSIZE:
|
2012-12-28 18:33:26 +00:00
|
|
|
break;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-22 19:14:24 +00:00
|
|
|
case GE_CMD_TRANSFERSTART: // Orphis calls this TRXKICK
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2012-11-02 11:33:16 +00:00
|
|
|
// TODO: Here we should check if the transfer overlaps a framebuffer or any textures,
|
2012-11-22 19:57:41 +00:00
|
|
|
// and take appropriate action. This is a block transfer between RAM and VRAM, or vice versa.
|
|
|
|
DoBlockTransfer();
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GE_CMD_TEXSIZE0:
|
2012-11-18 12:04:49 +00:00
|
|
|
gstate_c.curTextureWidth = 1 << (gstate.texsize[0] & 0xf);
|
|
|
|
gstate_c.curTextureHeight = 1 << ((gstate.texsize[0]>>8) & 0xf);
|
2012-11-01 15:19:01 +00:00
|
|
|
//fall thru - ignoring the mipmap sizes for now
|
|
|
|
case GE_CMD_TEXSIZE1:
|
|
|
|
case GE_CMD_TEXSIZE2:
|
|
|
|
case GE_CMD_TEXSIZE3:
|
|
|
|
case GE_CMD_TEXSIZE4:
|
|
|
|
case GE_CMD_TEXSIZE5:
|
|
|
|
case GE_CMD_TEXSIZE6:
|
|
|
|
case GE_CMD_TEXSIZE7:
|
2012-12-21 22:40:11 +00:00
|
|
|
gstate_c.textureChanged = true;
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_ZBUFPTR:
|
|
|
|
case GE_CMD_ZBUFWIDTH:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_AMBIENTCOLOR:
|
|
|
|
case GE_CMD_AMBIENTALPHA:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_MATERIALAMBIENT:
|
2012-12-20 13:10:42 +00:00
|
|
|
if (diff)
|
2012-12-25 12:47:59 +00:00
|
|
|
shaderManager_->DirtyUniform(DIRTY_MATAMBIENTALPHA);
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_MATERIALDIFFUSE:
|
2012-12-20 17:31:21 +00:00
|
|
|
if (diff)
|
2012-12-25 12:47:59 +00:00
|
|
|
shaderManager_->DirtyUniform(DIRTY_MATDIFFUSE);
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_MATERIALEMISSIVE:
|
2012-12-20 17:31:21 +00:00
|
|
|
if (diff)
|
2012-12-25 12:47:59 +00:00
|
|
|
shaderManager_->DirtyUniform(DIRTY_MATEMISSIVE);
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_MATERIALSPECULAR:
|
2012-12-20 17:31:21 +00:00
|
|
|
if (diff)
|
2012-12-25 12:47:59 +00:00
|
|
|
shaderManager_->DirtyUniform(DIRTY_MATSPECULAR);
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_MATERIALALPHA:
|
2012-12-20 13:10:42 +00:00
|
|
|
if (diff)
|
2012-12-25 12:47:59 +00:00
|
|
|
shaderManager_->DirtyUniform(DIRTY_MATAMBIENTALPHA);
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_MATERIALSPECULARCOEF:
|
2012-12-20 17:31:21 +00:00
|
|
|
if (diff)
|
2012-12-25 12:47:59 +00:00
|
|
|
shaderManager_->DirtyUniform(DIRTY_MATSPECULAR);
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_LIGHTTYPE0:
|
|
|
|
case GE_CMD_LIGHTTYPE1:
|
|
|
|
case GE_CMD_LIGHTTYPE2:
|
|
|
|
case GE_CMD_LIGHTTYPE3:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_LX0:case GE_CMD_LY0:case GE_CMD_LZ0:
|
|
|
|
case GE_CMD_LX1:case GE_CMD_LY1:case GE_CMD_LZ1:
|
|
|
|
case GE_CMD_LX2:case GE_CMD_LY2:case GE_CMD_LZ2:
|
|
|
|
case GE_CMD_LX3:case GE_CMD_LY3:case GE_CMD_LZ3:
|
|
|
|
{
|
|
|
|
int n = cmd - GE_CMD_LX0;
|
|
|
|
int l = n / 3;
|
|
|
|
int c = n % 3;
|
2012-12-28 18:33:26 +00:00
|
|
|
gstate_c.lightpos[l][c] = getFloat24(data);
|
2012-12-20 17:31:21 +00:00
|
|
|
if (diff)
|
2012-12-25 12:47:59 +00:00
|
|
|
shaderManager_->DirtyUniform(DIRTY_LIGHT0 << l);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_LDX0:case GE_CMD_LDY0:case GE_CMD_LDZ0:
|
|
|
|
case GE_CMD_LDX1:case GE_CMD_LDY1:case GE_CMD_LDZ1:
|
|
|
|
case GE_CMD_LDX2:case GE_CMD_LDY2:case GE_CMD_LDZ2:
|
|
|
|
case GE_CMD_LDX3:case GE_CMD_LDY3:case GE_CMD_LDZ3:
|
|
|
|
{
|
|
|
|
int n = cmd - GE_CMD_LDX0;
|
|
|
|
int l = n / 3;
|
|
|
|
int c = n % 3;
|
2012-12-28 18:33:26 +00:00
|
|
|
gstate_c.lightdir[l][c] = getFloat24(data);
|
2012-12-20 17:31:21 +00:00
|
|
|
if (diff)
|
2012-12-25 12:47:59 +00:00
|
|
|
shaderManager_->DirtyUniform(DIRTY_LIGHT0 << l);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_LKA0:case GE_CMD_LKB0:case GE_CMD_LKC0:
|
|
|
|
case GE_CMD_LKA1:case GE_CMD_LKB1:case GE_CMD_LKC1:
|
|
|
|
case GE_CMD_LKA2:case GE_CMD_LKB2:case GE_CMD_LKC2:
|
|
|
|
case GE_CMD_LKA3:case GE_CMD_LKB3:case GE_CMD_LKC3:
|
|
|
|
{
|
|
|
|
int n = cmd - GE_CMD_LKA0;
|
|
|
|
int l = n / 3;
|
|
|
|
int c = n % 3;
|
2012-12-28 18:33:26 +00:00
|
|
|
gstate_c.lightatt[l][c] = getFloat24(data);
|
2012-12-20 17:31:21 +00:00
|
|
|
if (diff)
|
2012-12-25 12:47:59 +00:00
|
|
|
shaderManager_->DirtyUniform(DIRTY_LIGHT0 << l);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case GE_CMD_LAC0:case GE_CMD_LAC1:case GE_CMD_LAC2:case GE_CMD_LAC3:
|
|
|
|
case GE_CMD_LDC0:case GE_CMD_LDC1:case GE_CMD_LDC2:case GE_CMD_LDC3:
|
|
|
|
case GE_CMD_LSC0:case GE_CMD_LSC1:case GE_CMD_LSC2:case GE_CMD_LSC3:
|
|
|
|
{
|
2012-11-11 16:27:39 +00:00
|
|
|
float r = (float)(data & 0xff)/255.0f;
|
2012-11-01 15:19:01 +00:00
|
|
|
float g = (float)((data>>8) & 0xff)/255.0f;
|
2012-11-11 16:27:39 +00:00
|
|
|
float b = (float)(data>>16)/255.0f;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
int l = (cmd - GE_CMD_LAC0) / 3;
|
|
|
|
int t = (cmd - GE_CMD_LAC0) % 3;
|
2012-12-21 15:49:42 +00:00
|
|
|
gstate_c.lightColor[t][l][0] = r;
|
|
|
|
gstate_c.lightColor[t][l][1] = g;
|
|
|
|
gstate_c.lightColor[t][l][2] = b;
|
2012-12-20 17:31:21 +00:00
|
|
|
if (diff)
|
2012-12-25 12:47:59 +00:00
|
|
|
shaderManager_->DirtyUniform(DIRTY_LIGHT0 << l);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_VIEWPORTX1:
|
|
|
|
case GE_CMD_VIEWPORTY1:
|
|
|
|
case GE_CMD_VIEWPORTX2:
|
|
|
|
case GE_CMD_VIEWPORTY2:
|
|
|
|
break;
|
2012-12-28 18:33:26 +00:00
|
|
|
|
2012-11-24 23:15:21 +00:00
|
|
|
case GE_CMD_VIEWPORTZ1:
|
|
|
|
gstate_c.zScale = getFloat24(data) / 65535.f;
|
|
|
|
break;
|
2012-12-28 18:33:26 +00:00
|
|
|
|
2012-11-24 23:15:21 +00:00
|
|
|
case GE_CMD_VIEWPORTZ2:
|
|
|
|
gstate_c.zOff = getFloat24(data) / 65535.f;
|
|
|
|
break;
|
2012-12-28 18:33:26 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
case GE_CMD_LIGHTENABLE0:
|
|
|
|
case GE_CMD_LIGHTENABLE1:
|
|
|
|
case GE_CMD_LIGHTENABLE2:
|
|
|
|
case GE_CMD_LIGHTENABLE3:
|
|
|
|
break;
|
2012-12-28 18:33:26 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
case GE_CMD_CULL:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_LMODE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_PATCHDIVISION:
|
2012-12-28 18:33:26 +00:00
|
|
|
case GE_CMD_PATCHPRIMITIVE:
|
|
|
|
case GE_CMD_PATCHFACING:
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
2012-12-28 18:33:26 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
case GE_CMD_MATERIALUPDATE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// CLEARING
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
case GE_CMD_CLEARMODE:
|
|
|
|
// If it becomes a performance problem, check diff&1
|
|
|
|
if (data & 1)
|
|
|
|
EnterClearMode(data);
|
|
|
|
else
|
|
|
|
LeaveClearMode();
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// ALPHA BLENDING
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
case GE_CMD_ALPHABLENDENABLE:
|
|
|
|
case GE_CMD_BLENDMODE:
|
|
|
|
case GE_CMD_BLENDFIXEDA:
|
|
|
|
case GE_CMD_BLENDFIXEDB:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_ALPHATESTENABLE:
|
2013-01-14 19:43:18 +00:00
|
|
|
case GE_CMD_COLORTESTENABLE:
|
2012-11-01 15:19:01 +00:00
|
|
|
// This is done in the shader.
|
|
|
|
break;
|
|
|
|
|
2013-01-14 19:43:18 +00:00
|
|
|
case GE_CMD_COLORREF:
|
2012-11-01 15:19:01 +00:00
|
|
|
case GE_CMD_ALPHATEST:
|
2012-12-25 12:47:59 +00:00
|
|
|
shaderManager_->DirtyUniform(DIRTY_ALPHACOLORREF);
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
2012-12-01 22:38:18 +00:00
|
|
|
case GE_CMD_TEXENVCOLOR:
|
2012-12-20 13:10:42 +00:00
|
|
|
if (diff)
|
2012-12-25 12:47:59 +00:00
|
|
|
shaderManager_->DirtyUniform(DIRTY_TEXENV);
|
2012-12-01 22:38:18 +00:00
|
|
|
break;
|
2012-12-28 18:33:26 +00:00
|
|
|
|
|
|
|
case GE_CMD_TEXFUNC:
|
|
|
|
case GE_CMD_TEXFILTER:
|
2012-11-28 12:45:22 +00:00
|
|
|
case GE_CMD_TEXMODE:
|
|
|
|
case GE_CMD_TEXFORMAT:
|
|
|
|
case GE_CMD_TEXFLUSH:
|
|
|
|
case GE_CMD_TEXWRAP:
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
2012-12-28 18:33:26 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Z/STENCIL TESTING
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
case GE_CMD_STENCILTESTENABLE:
|
2012-12-28 18:33:26 +00:00
|
|
|
case GE_CMD_ZTESTENABLE:
|
2012-11-01 15:19:01 +00:00
|
|
|
case GE_CMD_ZTEST:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_MORPHWEIGHT0:
|
|
|
|
case GE_CMD_MORPHWEIGHT1:
|
|
|
|
case GE_CMD_MORPHWEIGHT2:
|
|
|
|
case GE_CMD_MORPHWEIGHT3:
|
|
|
|
case GE_CMD_MORPHWEIGHT4:
|
|
|
|
case GE_CMD_MORPHWEIGHT5:
|
|
|
|
case GE_CMD_MORPHWEIGHT6:
|
|
|
|
case GE_CMD_MORPHWEIGHT7:
|
2012-12-28 18:33:26 +00:00
|
|
|
gstate_c.morphWeights[cmd - GE_CMD_MORPHWEIGHT0] = getFloat24(data);
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
2012-12-01 22:38:18 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
case GE_CMD_DITH0:
|
|
|
|
case GE_CMD_DITH1:
|
|
|
|
case GE_CMD_DITH2:
|
|
|
|
case GE_CMD_DITH3:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_WORLDMATRIXNUMBER:
|
2012-11-26 17:04:34 +00:00
|
|
|
gstate.worldmtxnum &= 0xFF00000F;
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_WORLDMATRIXDATA:
|
2012-11-26 17:04:34 +00:00
|
|
|
{
|
|
|
|
int num = gstate.worldmtxnum & 0xF;
|
2013-01-20 12:15:46 +00:00
|
|
|
float newVal = getFloat24(data);
|
|
|
|
if (num < 12 && newVal != gstate.worldMatrix[num]) {
|
|
|
|
Flush();
|
|
|
|
gstate.worldMatrix[num] = getFloat24(data);
|
|
|
|
shaderManager_->DirtyUniform(DIRTY_WORLDMATRIX);
|
|
|
|
}
|
|
|
|
num++;
|
2012-11-26 17:04:34 +00:00
|
|
|
gstate.worldmtxnum = (gstate.worldmtxnum & 0xFF000000) | (num & 0xF);
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_VIEWMATRIXNUMBER:
|
2012-11-26 17:04:34 +00:00
|
|
|
gstate.viewmtxnum &= 0xFF00000F;
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_VIEWMATRIXDATA:
|
2012-11-26 17:04:34 +00:00
|
|
|
{
|
|
|
|
int num = gstate.viewmtxnum & 0xF;
|
2013-01-20 12:15:46 +00:00
|
|
|
float newVal = getFloat24(data);
|
|
|
|
if (num < 12 && newVal != gstate.viewMatrix[num]) {
|
|
|
|
Flush();
|
|
|
|
gstate.viewMatrix[num] = newVal;
|
|
|
|
shaderManager_->DirtyUniform(DIRTY_VIEWMATRIX);
|
|
|
|
}
|
|
|
|
num++;
|
2012-11-26 17:04:34 +00:00
|
|
|
gstate.viewmtxnum = (gstate.viewmtxnum & 0xFF000000) | (num & 0xF);
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_PROJMATRIXNUMBER:
|
2012-11-26 17:04:34 +00:00
|
|
|
gstate.projmtxnum &= 0xFF00000F;
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_PROJMATRIXDATA:
|
2012-11-26 17:04:34 +00:00
|
|
|
{
|
2012-12-01 22:38:18 +00:00
|
|
|
int num = gstate.projmtxnum & 0xF;
|
2013-01-20 12:15:46 +00:00
|
|
|
float newVal = getFloat24(data);
|
|
|
|
if (newVal != gstate.projMatrix[num]) {
|
|
|
|
Flush();
|
|
|
|
gstate.projMatrix[num] = newVal;
|
|
|
|
shaderManager_->DirtyUniform(DIRTY_PROJMATRIX);
|
|
|
|
}
|
|
|
|
num++;
|
2012-11-26 17:04:34 +00:00
|
|
|
gstate.projmtxnum = (gstate.projmtxnum & 0xFF000000) | (num & 0xF);
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_TGENMATRIXNUMBER:
|
2012-11-26 17:04:34 +00:00
|
|
|
gstate.texmtxnum &= 0xFF00000F;
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_TGENMATRIXDATA:
|
2012-11-26 17:04:34 +00:00
|
|
|
{
|
|
|
|
int num = gstate.texmtxnum & 0xF;
|
2013-01-20 12:15:46 +00:00
|
|
|
float newVal = getFloat24(data);
|
|
|
|
if (newVal != gstate.tgenMatrix[num] && num < 12) {
|
|
|
|
Flush();
|
|
|
|
gstate.tgenMatrix[num] = newVal;
|
|
|
|
shaderManager_->DirtyUniform(DIRTY_TEXMATRIX);
|
|
|
|
}
|
|
|
|
num++;
|
2012-11-26 17:04:34 +00:00
|
|
|
gstate.texmtxnum = (gstate.texmtxnum & 0xFF000000) | (num & 0xF);
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_BONEMATRIXNUMBER:
|
2012-11-26 19:38:26 +00:00
|
|
|
gstate.boneMatrixNumber &= 0xFF00007F;
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_BONEMATRIXDATA:
|
2012-11-26 17:04:34 +00:00
|
|
|
{
|
|
|
|
int num = gstate.boneMatrixNumber & 0x7F;
|
2013-01-20 12:15:46 +00:00
|
|
|
float newVal = getFloat24(data);
|
|
|
|
if (newVal != gstate.boneMatrix[num] && num < 96) {
|
|
|
|
Flush();
|
|
|
|
gstate.boneMatrix[num] = newVal;
|
|
|
|
shaderManager_->DirtyUniform(DIRTY_BONEMATRIX0 << (num / 12));
|
2012-11-26 19:38:26 +00:00
|
|
|
}
|
2013-01-20 12:15:46 +00:00
|
|
|
num++;
|
2012-11-26 17:04:34 +00:00
|
|
|
gstate.boneMatrixNumber = (gstate.boneMatrixNumber & 0xFF000000) | (num & 0x7F);
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-12-29 19:41:33 +00:00
|
|
|
DEBUG_LOG(G3D,"DL Unknown: %08x @ %08x", op, currentList == NULL ? 0 : currentList->pc);
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-28 18:33:26 +00:00
|
|
|
void GLES_GPU::UpdateStats() {
|
2012-12-25 12:47:59 +00:00
|
|
|
gpuStats.numVertexShaders = shaderManager_->NumVertexShaders();
|
|
|
|
gpuStats.numFragmentShaders = shaderManager_->NumFragmentShaders();
|
|
|
|
gpuStats.numShaders = shaderManager_->NumPrograms();
|
2013-01-30 19:40:26 +00:00
|
|
|
gpuStats.numTextures = textureCache_.NumLoadedTextures();
|
2013-01-19 21:48:20 +00:00
|
|
|
gpuStats.numFBOs = (int)vfbs_.size();
|
2012-11-26 16:35:08 +00:00
|
|
|
}
|
|
|
|
|
2012-12-28 18:33:26 +00:00
|
|
|
void GLES_GPU::DoBlockTransfer() {
|
2012-12-21 15:49:42 +00:00
|
|
|
// 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:
|
2012-12-21 22:10:57 +00:00
|
|
|
// * Does dstBasePtr point to an existing texture? If so maybe reload it immediately.
|
2012-12-21 15:49:42 +00:00
|
|
|
//
|
|
|
|
// * 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....
|
|
|
|
|
2012-11-22 19:57:41 +00:00
|
|
|
u32 srcBasePtr = (gstate.transfersrc & 0xFFFFFF) | ((gstate.transfersrcw & 0xFF0000) << 8);
|
|
|
|
u32 srcStride = gstate.transfersrcw & 0x3FF;
|
|
|
|
|
2012-12-17 18:04:19 +00:00
|
|
|
u32 dstBasePtr = (gstate.transferdst & 0xFFFFFF) | ((gstate.transferdstw & 0xFF0000) << 8);
|
|
|
|
u32 dstStride = gstate.transferdstw & 0x3FF;
|
2012-11-22 19:57:41 +00:00
|
|
|
|
|
|
|
int srcX = gstate.transfersrcpos & 0x3FF;
|
|
|
|
int srcY = (gstate.transfersrcpos >> 10) & 0x3FF;
|
|
|
|
|
|
|
|
int dstX = gstate.transferdstpos & 0x3FF;
|
|
|
|
int dstY = (gstate.transferdstpos >> 10) & 0x3FF;
|
|
|
|
|
|
|
|
int width = (gstate.transfersize & 0x3FF) + 1;
|
|
|
|
int height = ((gstate.transfersize >> 10) & 0x3FF) + 1;
|
2012-12-26 23:18:45 +00:00
|
|
|
|
2012-11-22 19:57:41 +00:00
|
|
|
int bpp = (gstate.transferstart & 1) ? 4 : 2;
|
|
|
|
|
2012-12-26 23:18:45 +00:00
|
|
|
DEBUG_LOG(G3D, "Block transfer: %08x to %08x, %i x %i , ...", srcBasePtr, dstBasePtr, width, height);
|
2012-11-22 19:57:41 +00:00
|
|
|
|
|
|
|
// Do the copy!
|
|
|
|
for (int y = 0; y < height; y++) {
|
|
|
|
const u8 *src = Memory::GetPointer(srcBasePtr + ((y + srcY) * srcStride + srcX) * bpp);
|
|
|
|
u8 *dst = Memory::GetPointer(dstBasePtr + ((y + dstY) * srcStride + dstX) * bpp);
|
|
|
|
memcpy(dst, src, width * bpp);
|
|
|
|
}
|
|
|
|
|
2012-12-28 18:33:26 +00:00
|
|
|
// TODO: Notify all overlapping FBOs that they need to reload.
|
2012-12-21 22:10:57 +00:00
|
|
|
|
2013-01-30 19:40:26 +00:00
|
|
|
textureCache_.Invalidate(dstBasePtr + dstY * dstStride + dstX, height * dstStride + width * bpp, true);
|
2012-12-21 22:10:57 +00:00
|
|
|
}
|
|
|
|
|
2012-12-28 18:33:26 +00:00
|
|
|
void GLES_GPU::InvalidateCache(u32 addr, int size) {
|
2012-12-21 22:10:57 +00:00
|
|
|
if (size > 0)
|
2013-01-30 19:40:26 +00:00
|
|
|
textureCache_.Invalidate(addr, size, true);
|
2012-12-21 22:10:57 +00:00
|
|
|
else
|
2013-01-30 19:40:26 +00:00
|
|
|
textureCache_.InvalidateAll(true);
|
2013-01-03 07:21:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLES_GPU::InvalidateCacheHint(u32 addr, int size) {
|
|
|
|
if (size > 0)
|
2013-01-30 19:40:26 +00:00
|
|
|
textureCache_.Invalidate(addr, size, false);
|
2013-01-03 07:21:02 +00:00
|
|
|
else
|
2013-01-30 19:40:26 +00:00
|
|
|
textureCache_.InvalidateAll(false);
|
2012-11-22 19:57:41 +00:00
|
|
|
}
|
2012-12-25 12:47:59 +00:00
|
|
|
|
|
|
|
void GLES_GPU::Flush() {
|
|
|
|
transformDraw_.Flush();
|
|
|
|
}
|
2012-12-29 20:21:56 +00:00
|
|
|
|
2013-01-26 23:15:39 +00:00
|
|
|
void GLES_GPU::DestroyAllFBOs() {
|
2012-12-29 20:21:56 +00:00
|
|
|
for (auto iter = vfbs_.begin(); iter != vfbs_.end(); ++iter) {
|
2013-01-26 20:38:27 +00:00
|
|
|
VirtualFramebuffer *v = *iter;
|
|
|
|
fbo_destroy(v->fbo);
|
|
|
|
delete v;
|
2012-12-29 20:21:56 +00:00
|
|
|
}
|
|
|
|
vfbs_.clear();
|
2013-01-26 23:15:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLES_GPU::Resized() {
|
|
|
|
resized_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLES_GPU::DoState(PointerWrap &p) {
|
|
|
|
GPUCommon::DoState(p);
|
|
|
|
|
2013-01-30 19:40:26 +00:00
|
|
|
textureCache_.Clear(true);
|
2013-01-26 23:15:39 +00:00
|
|
|
|
|
|
|
gstate_c.textureChanged = true;
|
|
|
|
DestroyAllFBOs();
|
2012-12-29 20:21:56 +00:00
|
|
|
shaderManager_->ClearCache(true);
|
|
|
|
}
|