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:01:49 +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/.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../Globals.h"
|
2013-07-10 17:28:15 +00:00
|
|
|
#include "gfx/gl_common.h"
|
2012-11-24 14:19:29 +00:00
|
|
|
#include "ge_constants.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
struct GPUgstate
|
|
|
|
{
|
2012-12-21 15:49:42 +00:00
|
|
|
// Getting rid of this ugly union in favor of the accessor functions
|
|
|
|
// might be a good idea....
|
2012-11-01 15:19:01 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
u32 cmdmem[256];
|
|
|
|
struct
|
|
|
|
{
|
2012-12-05 03:45:28 +00:00
|
|
|
u32 nop,
|
|
|
|
vaddr,
|
2012-11-01 15:19:01 +00:00
|
|
|
iaddr,
|
|
|
|
pad00,
|
|
|
|
prim,
|
|
|
|
bezier,
|
|
|
|
spline,
|
|
|
|
boundBox,
|
|
|
|
jump,
|
|
|
|
bjump,
|
|
|
|
call,
|
|
|
|
ret,
|
|
|
|
end,
|
|
|
|
pad01,
|
|
|
|
signal,
|
|
|
|
finish,
|
|
|
|
base,
|
|
|
|
pad02,
|
|
|
|
vertType,
|
|
|
|
offsetAddr,
|
|
|
|
origin,
|
|
|
|
region1,
|
|
|
|
region2,
|
|
|
|
lightingEnable,
|
|
|
|
lightEnable[4],
|
|
|
|
clipEnable,
|
|
|
|
cullfaceEnable,
|
|
|
|
textureMapEnable,
|
|
|
|
fogEnable,
|
|
|
|
ditherEnable,
|
|
|
|
alphaBlendEnable,
|
|
|
|
alphaTestEnable,
|
|
|
|
zTestEnable,
|
|
|
|
stencilTestEnable,
|
|
|
|
antiAliasEnable,
|
|
|
|
patchCullEnable,
|
|
|
|
colorTestEnable,
|
|
|
|
logicOpEnable,
|
|
|
|
pad03,
|
|
|
|
boneMatrixNumber,
|
|
|
|
boneMatrixData,
|
|
|
|
morphwgt[8], //dont use
|
2012-12-28 18:33:26 +00:00
|
|
|
pad04[2],
|
|
|
|
patchdivision,
|
|
|
|
patchprimitive,
|
|
|
|
patchfacing,
|
|
|
|
pad04_a,
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-07-22 00:43:08 +00:00
|
|
|
worldmtxnum, // 0x3A
|
|
|
|
worldmtxdata, // 0x3B
|
|
|
|
viewmtxnum, // 0x3C
|
|
|
|
viewmtxdata, // 0x3D
|
|
|
|
projmtxnum, // 0x3E
|
|
|
|
projmtxdata, // 0x3F
|
|
|
|
texmtxnum, // 0x40
|
|
|
|
texmtxdata, // 0x41
|
|
|
|
|
|
|
|
viewportx1, // 0x42
|
|
|
|
viewporty1, // 0x43
|
|
|
|
viewportz1, // 0x44
|
|
|
|
viewportx2, // 0x45
|
|
|
|
viewporty2, // 0x46
|
|
|
|
viewportz2, // 0x47
|
|
|
|
texscaleu, // 0x48
|
|
|
|
texscalev, // 0x49
|
|
|
|
texoffsetu, // 0x4A
|
|
|
|
texoffsetv, // 0x4B
|
|
|
|
offsetx, // 0x4C
|
|
|
|
offsety, // 0x4D
|
2012-11-01 15:19:01 +00:00
|
|
|
pad111[2],
|
2013-07-22 00:43:08 +00:00
|
|
|
shademodel, // 0x50
|
|
|
|
reversenormals, // 0x51
|
2012-11-01 15:19:01 +00:00
|
|
|
pad222,
|
2013-07-22 00:43:08 +00:00
|
|
|
materialupdate, // 0x53
|
|
|
|
materialemissive, // 0x54
|
|
|
|
materialambient, // 0x55
|
|
|
|
materialdiffuse, // 0x56
|
|
|
|
materialspecular, // 0x57
|
|
|
|
materialalpha, // 0x58
|
2012-11-25 17:12:20 +00:00
|
|
|
pad333[2],
|
2013-07-22 00:43:08 +00:00
|
|
|
materialspecularcoef, // 0x5B
|
|
|
|
ambientcolor, // 0x5C
|
|
|
|
ambientalpha, // 0x5D
|
2013-04-16 17:22:18 +00:00
|
|
|
lmode,
|
2012-11-01 15:19:01 +00:00
|
|
|
ltype[4],
|
|
|
|
lpos[12],
|
|
|
|
ldir[12],
|
|
|
|
latt[12],
|
|
|
|
lconv[4],
|
|
|
|
lcutoff[4],
|
|
|
|
lcolor[12],
|
|
|
|
cullmode,
|
|
|
|
fbptr,
|
|
|
|
fbwidth,
|
|
|
|
zbptr,
|
|
|
|
zbwidth,
|
|
|
|
texaddr[8],
|
|
|
|
texbufwidth[8],
|
|
|
|
clutaddr,
|
|
|
|
clutaddrupper,
|
|
|
|
transfersrc,
|
|
|
|
transfersrcw,
|
|
|
|
transferdst,
|
|
|
|
transferdstw,
|
|
|
|
padxxx[2],
|
|
|
|
texsize[8],
|
|
|
|
texmapmode,
|
|
|
|
texshade,
|
|
|
|
texmode,
|
|
|
|
texformat,
|
|
|
|
loadclut,
|
|
|
|
clutformat,
|
|
|
|
texfilter,
|
|
|
|
texwrap,
|
2013-02-07 23:04:34 +00:00
|
|
|
texlevel,
|
2012-11-01 15:19:01 +00:00
|
|
|
texfunc,
|
|
|
|
texenvcolor,
|
|
|
|
texflush,
|
|
|
|
texsync,
|
|
|
|
fog1,
|
|
|
|
fog2,
|
|
|
|
fogcolor,
|
|
|
|
texlodslope,
|
|
|
|
padxxxxxx,
|
|
|
|
framebufpixformat,
|
|
|
|
clearmode,
|
|
|
|
scissor1,
|
|
|
|
scissor2,
|
|
|
|
minz,
|
|
|
|
maxz,
|
|
|
|
colortest,
|
|
|
|
colorref,
|
|
|
|
colormask,
|
|
|
|
alphatest,
|
|
|
|
stenciltest,
|
|
|
|
stencilop,
|
|
|
|
ztestfunc,
|
|
|
|
blend,
|
|
|
|
blendfixa,
|
|
|
|
blendfixb,
|
|
|
|
dith1,
|
|
|
|
dith2,
|
|
|
|
dith3,
|
|
|
|
dith4,
|
|
|
|
lop,
|
|
|
|
zmsk,
|
2013-01-12 11:51:09 +00:00
|
|
|
pmskc,
|
|
|
|
pmska,
|
2012-11-22 19:57:41 +00:00
|
|
|
transferstart,
|
|
|
|
transfersrcpos,
|
|
|
|
transferdstpos,
|
2012-12-17 18:04:19 +00:00
|
|
|
pad99,
|
|
|
|
transfersize; // 0xEE
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-12-17 18:04:19 +00:00
|
|
|
u32 pad05[0xFF- 0xEE];
|
2012-11-01 15:19:01 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2012-11-18 12:04:49 +00:00
|
|
|
float worldMatrix[12];
|
|
|
|
float viewMatrix[12];
|
|
|
|
float projMatrix[16];
|
|
|
|
float tgenMatrix[12];
|
2012-11-25 11:25:07 +00:00
|
|
|
float boneMatrix[12 * 8]; // Eight bone matrices.
|
2012-11-24 14:19:29 +00:00
|
|
|
|
2012-12-21 15:49:42 +00:00
|
|
|
// Pixel Pipeline
|
2012-11-28 12:45:22 +00:00
|
|
|
bool isModeClear() const { return clearmode & 1; }
|
|
|
|
bool isCullEnabled() const { return cullfaceEnable & 1; }
|
2012-12-21 15:49:42 +00:00
|
|
|
int getCullMode() const { return cullmode & 1; }
|
|
|
|
int getBlendFuncA() const { return blend & 0xF; }
|
2012-11-28 12:45:22 +00:00
|
|
|
u32 getFixA() const { return blendfixa & 0xFFFFFF; }
|
|
|
|
u32 getFixB() const { return blendfixb & 0xFFFFFF; }
|
2012-12-21 15:49:42 +00:00
|
|
|
int getBlendFuncB() const { return (blend >> 4) & 0xF; }
|
|
|
|
int getBlendEq() const { return (blend >> 8) & 0x7; }
|
2012-11-28 12:45:22 +00:00
|
|
|
bool isDepthTestEnabled() const { return zTestEnable & 1; }
|
|
|
|
bool isDepthWriteEnabled() const { return !(zmsk & 1); }
|
2012-12-21 15:49:42 +00:00
|
|
|
int getDepthTestFunc() const { return ztestfunc & 0x7; }
|
2012-11-28 12:45:22 +00:00
|
|
|
bool isFogEnabled() const { return fogEnable & 1; }
|
2013-01-12 16:20:00 +00:00
|
|
|
bool isStencilTestEnabled() const { return stencilTestEnable & 1; }
|
2013-02-27 14:37:17 +00:00
|
|
|
bool isAlphaBlendEnabled() const { return alphaBlendEnable & 1; }
|
|
|
|
bool isDitherEnabled() const { return ditherEnable & 1; }
|
2013-03-27 10:21:02 +00:00
|
|
|
bool isAlphaTestEnabled() const { return alphaTestEnable & 1; }
|
|
|
|
bool isColorTestEnabled() const { return colorTestEnable & 1; }
|
|
|
|
bool isLightingEnabled() const { return lightingEnable & 1; }
|
2013-07-22 00:43:08 +00:00
|
|
|
bool isUsingSecondaryColor() const { return lmode & 1; }
|
2013-03-27 10:21:02 +00:00
|
|
|
bool isTextureMapEnabled() const { return textureMapEnable & 1; }
|
2012-11-18 12:04:49 +00:00
|
|
|
|
2013-07-22 00:43:08 +00:00
|
|
|
unsigned int getAmbientR() const { return ambientcolor&0xFF; }
|
|
|
|
unsigned int getAmbientG() const { return (ambientcolor>>8)&0xFF; }
|
|
|
|
unsigned int getAmbientB() const { return (ambientcolor>>16)&0xFF; }
|
|
|
|
unsigned int getAmbientA() const { return ambientalpha&0xFF; }
|
|
|
|
|
|
|
|
unsigned int getMaterialAmbientR() const { return materialambient&0xFF; }
|
|
|
|
unsigned int getMaterialAmbientG() const { return (materialambient>>8)&0xFF; }
|
|
|
|
unsigned int getMaterialAmbientB() const { return (materialambient>>16)&0xFF; }
|
|
|
|
unsigned int getMaterialAmbientA() const { return materialalpha&0xFF; }
|
|
|
|
|
|
|
|
unsigned int getMaterialEmissiveR() const { return materialemissive&0xFF; }
|
|
|
|
unsigned int getMaterialEmissiveG() const { return (materialemissive>>8)&0xFF; }
|
|
|
|
unsigned int getMaterialEmissiveB() const { return (materialemissive>>16)&0xFF; }
|
|
|
|
|
2012-12-21 15:49:42 +00:00
|
|
|
// UV gen
|
2012-12-20 13:10:42 +00:00
|
|
|
int getUVGenMode() const { return texmapmode & 3;} // 2 bits
|
|
|
|
int getUVProjMode() const { return (texmapmode >> 8) & 3;} // 2 bits
|
|
|
|
int getUVLS0() const { return texshade & 0x3; } // 2 bits
|
|
|
|
int getUVLS1() const { return (texshade >> 8) & 0x3; } // 2 bits
|
|
|
|
|
2013-03-15 23:40:37 +00:00
|
|
|
int getScissorX1() const { return scissor1 & 0x3FF; }
|
|
|
|
int getScissorY1() const { return (scissor1 >> 10) & 0x3FF; }
|
|
|
|
int getScissorX2() const { return scissor2 & 0x3FF; }
|
|
|
|
int getScissorY2() const { return (scissor2 >> 10) & 0x3FF; }
|
|
|
|
|
2013-07-10 19:57:25 +00:00
|
|
|
int getRegionX1() const { return region1 & 0x3FF; }
|
|
|
|
int getRegionY1() const { return (region1 >> 10) & 0x3FF; }
|
|
|
|
int getRegionX2() const { return (region2 & 0x3FF); }
|
|
|
|
int getRegionY2() const { return ((region2 >> 10) & 0x3FF); }
|
|
|
|
|
2012-12-21 15:49:42 +00:00
|
|
|
// Vertex type
|
|
|
|
bool isModeThrough() const { return (vertType & GE_VTYPE_THROUGH) != 0; }
|
2012-12-20 13:10:42 +00:00
|
|
|
int getNumBoneWeights() const {
|
|
|
|
return 1 + ((vertType & GE_VTYPE_WEIGHTCOUNT_MASK) >> GE_VTYPE_WEIGHTCOUNT_SHIFT);
|
|
|
|
}
|
2013-02-02 12:40:26 +00:00
|
|
|
|
2012-12-20 13:10:42 +00:00
|
|
|
// Real data in the context ends here
|
|
|
|
};
|
2013-02-18 22:44:32 +00:00
|
|
|
|
|
|
|
enum SkipDrawReasonFlags {
|
|
|
|
SKIPDRAW_SKIPFRAME = 1,
|
2013-03-03 12:00:21 +00:00
|
|
|
SKIPDRAW_NON_DISPLAYED_FB = 2, // Skip drawing to FBO:s that have not been displayed.
|
|
|
|
SKIPDRAW_BAD_FB_TEXTURE = 4,
|
2013-02-18 22:44:32 +00:00
|
|
|
};
|
|
|
|
|
2012-11-18 22:14:50 +00:00
|
|
|
// The rest is cached simplified/converted data for fast access.
|
|
|
|
// Does not need to be saved when saving/restoring context.
|
2012-11-18 12:04:49 +00:00
|
|
|
struct GPUStateCache
|
|
|
|
{
|
2012-11-01 15:19:01 +00:00
|
|
|
u32 vertexAddr;
|
|
|
|
u32 indexAddr;
|
|
|
|
|
2013-02-02 12:38:34 +00:00
|
|
|
u32 offsetAddr;
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
bool textureChanged;
|
2013-05-08 14:52:54 +00:00
|
|
|
bool textureFullAlpha;
|
2013-04-21 22:08:47 +00:00
|
|
|
bool framebufChanged;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-02-18 22:44:32 +00:00
|
|
|
int skipDrawReason;
|
|
|
|
|
2013-02-09 19:53:32 +00:00
|
|
|
float uScale,vScale;
|
|
|
|
float uOff,vOff;
|
2013-02-14 23:30:02 +00:00
|
|
|
bool flipTexture;
|
|
|
|
|
2012-11-24 23:15:21 +00:00
|
|
|
float zMin, zMax;
|
2012-11-01 15:19:01 +00:00
|
|
|
float lightpos[4][3];
|
|
|
|
float lightdir[4][3];
|
|
|
|
float lightatt[4][3];
|
2013-02-12 20:00:51 +00:00
|
|
|
float lightColor[3][4][3]; // Ambient Diffuse Specular
|
2013-04-09 16:25:22 +00:00
|
|
|
float lightangle[4]; // spotlight cone angle (cosine)
|
|
|
|
float lightspotCoef[4]; // spotlight dropoff
|
2012-11-01 15:19:01 +00:00
|
|
|
float morphWeights[8];
|
|
|
|
|
|
|
|
u32 curTextureWidth;
|
|
|
|
u32 curTextureHeight;
|
2013-02-21 20:37:19 +00:00
|
|
|
u32 actualTextureHeight;
|
2012-11-26 19:38:26 +00:00
|
|
|
|
|
|
|
float vpWidth;
|
|
|
|
float vpHeight;
|
2013-02-02 12:38:34 +00:00
|
|
|
|
2013-03-15 23:40:37 +00:00
|
|
|
u32 curRTWidth;
|
|
|
|
u32 curRTHeight;
|
|
|
|
|
2013-02-02 22:47:35 +00:00
|
|
|
u32 getRelativeAddress(u32 data) const;
|
2013-07-20 17:14:36 +00:00
|
|
|
int gpuVendor;
|
2012-11-18 12:04:49 +00:00
|
|
|
};
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-18 12:04:49 +00:00
|
|
|
// TODO: Implement support for these.
|
|
|
|
struct GPUStatistics
|
|
|
|
{
|
2012-11-22 22:07:15 +00:00
|
|
|
void reset() {
|
2012-11-25 11:25:07 +00:00
|
|
|
memset(this, 0, sizeof(*this));
|
2012-11-22 22:07:15 +00:00
|
|
|
}
|
|
|
|
void resetFrame() {
|
|
|
|
numDrawCalls = 0;
|
2013-01-19 16:05:08 +00:00
|
|
|
numCachedDrawCalls = 0;
|
2013-01-24 23:36:59 +00:00
|
|
|
numVertsSubmitted = 0;
|
2013-01-19 16:05:08 +00:00
|
|
|
numCachedVertsDrawn = 0;
|
2013-01-24 23:36:59 +00:00
|
|
|
numUncachedVertsDrawn = 0;
|
2013-01-19 16:05:08 +00:00
|
|
|
numTrackedVertexArrays = 0;
|
2013-01-06 11:27:01 +00:00
|
|
|
numTextureInvalidations = 0;
|
2012-11-22 22:07:15 +00:00
|
|
|
numTextureSwitches = 0;
|
|
|
|
numShaderSwitches = 0;
|
2012-12-21 20:49:09 +00:00
|
|
|
numFlushes = 0;
|
|
|
|
numTexturesDecoded = 0;
|
2013-01-10 22:49:33 +00:00
|
|
|
msProcessingDisplayLists = 0;
|
2013-05-31 17:40:16 +00:00
|
|
|
vertexGPUCycles = 0;
|
|
|
|
otherGPUCycles = 0;
|
2012-11-22 22:07:15 +00:00
|
|
|
}
|
|
|
|
|
2012-11-18 12:04:49 +00:00
|
|
|
// Per frame statistics
|
|
|
|
int numDrawCalls;
|
2013-01-19 16:05:08 +00:00
|
|
|
int numCachedDrawCalls;
|
2012-12-21 18:16:17 +00:00
|
|
|
int numFlushes;
|
2013-01-24 23:36:59 +00:00
|
|
|
int numVertsSubmitted;
|
2013-01-19 16:05:08 +00:00
|
|
|
int numCachedVertsDrawn;
|
2013-01-24 23:36:59 +00:00
|
|
|
int numUncachedVertsDrawn;
|
2013-01-19 16:05:08 +00:00
|
|
|
int numTrackedVertexArrays;
|
2013-01-06 11:27:01 +00:00
|
|
|
int numTextureInvalidations;
|
2012-11-18 12:04:49 +00:00
|
|
|
int numTextureSwitches;
|
|
|
|
int numShaderSwitches;
|
2012-12-21 20:49:09 +00:00
|
|
|
int numTexturesDecoded;
|
2013-01-10 22:49:33 +00:00
|
|
|
double msProcessingDisplayLists;
|
2013-05-31 17:40:16 +00:00
|
|
|
int vertexGPUCycles;
|
|
|
|
int otherGPUCycles;
|
2012-11-18 12:04:49 +00:00
|
|
|
|
2012-11-26 16:35:08 +00:00
|
|
|
// Total statistics, updated by the GPU core in UpdateStats
|
2012-11-18 12:04:49 +00:00
|
|
|
int numFrames;
|
2012-11-26 16:35:08 +00:00
|
|
|
int numTextures;
|
|
|
|
int numVertexShaders;
|
|
|
|
int numFragmentShaders;
|
|
|
|
int numShaders;
|
2013-01-11 01:00:51 +00:00
|
|
|
int numFBOs;
|
2012-11-01 15:19:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void InitGfxState();
|
2012-11-06 16:05:27 +00:00
|
|
|
void ShutdownGfxState();
|
2012-11-01 15:19:01 +00:00
|
|
|
void ReapplyGfxState();
|
|
|
|
|
|
|
|
// PSP uses a curious 24-bit float - it's basically the top 24 bits of a regular IEEE754 32-bit float.
|
2012-11-25 11:25:07 +00:00
|
|
|
// This is used for light positions, transform matrices, you name it.
|
2012-11-01 15:19:01 +00:00
|
|
|
inline float getFloat24(unsigned int data)
|
|
|
|
{
|
2012-11-25 11:25:07 +00:00
|
|
|
data <<= 8;
|
2012-11-01 15:19:01 +00:00
|
|
|
float f;
|
|
|
|
memcpy(&f, &data, 4);
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
// in case we ever want to generate PSP display lists...
|
|
|
|
inline unsigned int toFloat24(float f) {
|
|
|
|
unsigned int i;
|
|
|
|
memcpy(&i, &f, 4);
|
2012-11-25 11:25:07 +00:00
|
|
|
return i >> 8;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-11-06 16:05:27 +00:00
|
|
|
class GPUInterface;
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
extern GPUgstate gstate;
|
2012-11-18 12:04:49 +00:00
|
|
|
extern GPUStateCache gstate_c;
|
|
|
|
extern GPUInterface *gpu;
|
2012-11-24 14:19:29 +00:00
|
|
|
extern GPUStatistics gpuStats;
|
2013-02-02 12:38:34 +00:00
|
|
|
|
2013-02-02 22:47:35 +00:00
|
|
|
inline u32 GPUStateCache::getRelativeAddress(u32 data) const {
|
2013-04-15 20:57:54 +00:00
|
|
|
u32 baseExtended = ((gstate.base & 0x0F0000) << 8) | data;
|
2013-02-02 12:38:34 +00:00
|
|
|
return (gstate_c.offsetAddr + baseExtended) & 0x0FFFFFFF;
|
|
|
|
}
|