They should be called SU Registers (Setup Unit/Rasterization). BP (Bypass) is really the name of the commands that are passed in.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3531 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
omegadox
2009-06-22 07:40:28 +00:00
parent cfe3f77ccf
commit 6de0cd1e4b
36 changed files with 257 additions and 2479 deletions

View File

@ -1,60 +0,0 @@
// Copyright (C) 2003-2009 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// 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 SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
// ------------------------------------------
// The plugins has to define these functions
// ------------------------------------------
#ifndef _BPFUNCTIONS_H_
#define _BPFUNCTIONS_H_
#include "BPMemory.h"
#include "VideoCommon.h"
namespace BPFunctions
{
enum
{
CONFIG_ISWII = 0,
CONFIG_DISABLEFOG,
CONFIG_SHOWEFBREGIONS
};
void FlushPipeline();
void SetGenerationMode(const Bypass &bp);
void SetScissor(const Bypass &bp);
void SetLineWidth(const Bypass &bp);
void SetDepthMode(const Bypass &bp);
void SetBlendMode(const Bypass &bp);
void SetDitherMode(const Bypass &bp);
void SetLogicOpMode(const Bypass &bp);
void SetColorMask(const Bypass &bp);
float GetRendererTargetScaleX();
float GetRendererTargetScaleY();
void CopyEFB(const Bypass &bp, const TRectangle &rc, const u32 &address, const bool &fromZBuffer, const bool &isIntensityFmt, const u32 &copyfmt, const bool &scaleByHalf);
void RenderToXFB(const Bypass &bp, const TRectangle &multirc, const float &yScale, const float &xfbLines, u8* pXFB, const u32 &dstWidth, const u32 &dstHeight);
void ClearScreen(const Bypass &bp, const TRectangle &multirc);
void RestoreRenderState(const Bypass &bp);
u8 *GetPointer(const u32 &address);
bool GetConfig(const int &type);
void SetSamplerState(const Bypass &bp);
void SetInterlacingMode(const Bypass &bp);
};
#endif // _BPFUNCTIONS_H_

View File

@ -1,68 +0,0 @@
// Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// 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 SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "Common.h"
#include "BPMemory.h"
//BP state
// STATE_TO_SAVE
BPMemory bpmem;
// The plugin must implement this.
void BPWritten(const Bypass& bp);
// Call browser: OpcodeDecoding.cpp ExecuteDisplayList > Decode() > LoadBPReg()
void LoadBPReg(u32 value0)
{
//handle the mask register
int opcode = value0 >> 24;
int oldval = ((u32*)&bpmem)[opcode];
int newval = (oldval & ~bpmem.bpMask) | (value0 & bpmem.bpMask);
int changes = (oldval ^ newval) & 0xFFFFFF;
Bypass bp = {opcode, changes, newval};
//reset the mask register
if (opcode != 0xFE)
bpmem.bpMask = 0xFFFFFF;
BPWritten(bp);
}
// Called when loading a saved state.
// Needs more testing though.
void BPReload()
{
for (int i = 0; i < 254; i++)
{
switch (i) {
case 0x41:
case 0x45: //GXSetDrawDone
case 0x52:
case 0x65:
case 0x67: // set gp metric?
case BPMEM_PE_TOKEN_ID:
case BPMEM_PE_TOKEN_INT_ID:
// Cases in which we DON'T want to reload the BP
continue;
default:
Bypass bp = {i, 0xFFFFFF, ((u32*)&bpmem)[i]};
BPWritten(bp);
}
}
}

View File

@ -1,913 +0,0 @@
// Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// 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 SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef _BPMEMORY_H
#define _BPMEMORY_H
#include "Common.h"
#pragma pack(4)
#define BPMEM_GENMODE 0x00
#define BPMEM_DISPLAYCOPYFILER 0x01 // 0x01 + 4
#define BPMEM_IND_MTXA 0x06 // 0x06 + (3 * 3)
#define BPMEM_IND_MTXB 0x07 // 0x07 + (3 * 3)
#define BPMEM_IND_MTXC 0x08 // 0x08 + (3 * 3)
#define BPMEM_IND_IMASK 0x0F
#define BPMEM_IND_CMD 0x10 // 0x10 + 16
#define BPMEM_SCISSORTL 0x20
#define BPMEM_SCISSORBR 0x21
#define BPMEM_LINEPTWIDTH 0x22
#define BPMEM_SU_COUNTER 0x23
#define BPMEM_RAS_COUNTER 0x24
#define BPMEM_RAS1_SS0 0x25
#define BPMEM_RAS1_SS1 0x26
#define BPMEM_IREF 0x27
#define BPMEM_TREF 0x28 // 0x28 + 8
#define BPMEM_SU_SSIZE 0x30 // 0x30 + (2 * 8)
#define BPMEM_SU_TSIZE 0x31 // 0x31 + (2 * 8)
#define BPMEM_ZMODE 0x40
#define BPMEM_BLENDMODE 0x41
#define BPMEM_CONSTANTALPHA 0x42
#define BPMEM_ZCOMPARE 0x43
#define BPMEM_FIELDMASK 0x44
#define BPMEM_SETDRAWDONE 0x45
#define BPMEM_CLOCK0 0x46
#define BPMEM_PE_TOKEN_ID 0x47
#define BPMEM_PE_TOKEN_INT_ID 0x48
#define BPMEM_EFB_TL 0x49
#define BPMEM_EFB_BR 0x4A
#define BPMEM_EFB_ADDR 0x4B
#define BPMEM_MIPMAP_STRIDE 0x4D
#define BPMEM_COPYYSCALE 0x4E
#define BPMEM_CLEAR_AR 0x4F
#define BPMEM_CLEAR_GB 0x50
#define BPMEM_CLEAR_Z 0x51
#define BPMEM_TRIGGER_EFB_COPY 0x52
#define BPMEM_COPYFILTER0 0x53
#define BPMEM_COPYFILTER1 0x54
#define BPMEM_CLEARBBOX1 0x55
#define BPMEM_CLEARBBOX2 0x56
#define BPMEM_UNKNOWN 0x58
#define BPMEM_SCISSOROFFSET 0x59
#define BPMEM_UNKNOWN1 0x60
#define BPMEM_UNKNOWN2 0x61
#define BPMEM_UNKNOWN3 0x62
#define BPMEM_UNKNOWN4 0x63
#define BPMEM_LOADTLUT0 0x64
#define BPMEM_LOADTLUT1 0x65
#define BPMEM_TEXINVALIDATE 0x66
#define BPMEM_SETGPMETRIC 0x67
#define BPMEM_FIELDMODE 0x68
#define BPMEM_CLOCK1 0x69
#define BPMEM_TX_SETMODE0 0x80 // 0x80 + 4
#define BPMEM_TX_SETMODE1 0x84 // 0x84 + 4
#define BPMEM_TX_SETIMAGE0 0x88 // 0x88 + 4
#define BPMEM_TX_SETIMAGE1 0x8C // 0x8C + 4
#define BPMEM_TX_SETIMAGE2 0x90 // 0x90 + 4
#define BPMEM_TX_SETIMAGE3 0x94 // 0x94 + 4
#define BPMEM_TX_SETTLUT 0x98 // 0x98 + 4
#define BPMEM_TX_SETMODE0_4 0xA0 // 0xA0 + 4
#define BPMEM_TX_SETMODE1_4 0xA4 // 0xA4 + 4
#define BPMEM_TX_SETIMAGE0_4 0xA8 // 0xA8 + 4
#define BPMEM_TX_SETIMAGE1_4 0xAC // 0xA4 + 4
#define BPMEM_TX_SETIMAGE2_4 0xB0 // 0xB0 + 4
#define BPMEM_TX_SETIMAGE3_4 0xB4 // 0xB4 + 4
#define BPMEM_TX_SETLUT_4 0xB8 // 0xB8 + 4
#define BPMEM_TEV_COLOR_ENV 0xC0 // 0xC0 + (2 * 16)
#define BPMEM_TEV_ALPHA_ENV 0xC1 // 0xC1 + (2 * 16)
#define BPMEM_TEV_REGISTER_L 0xE0 // 0xE0 + (2 * 4)
#define BPMEM_TEV_REGISTER_H 0xE1 // 0xE1 + (2 * 4)
#define BPMEM_FOGRANGE 0xE8
#define BPMEM_FOGPARAM0 0xEE
#define BPMEM_FOGBMAGNITUDE 0xEF
#define BPMEM_FOGBEXPONENT 0xF0
#define BPMEM_FOGPARAM3 0xF1
#define BPMEM_FOGCOLOR 0xF2
#define BPMEM_ALPHACOMPARE 0xF3
#define BPMEM_BIAS 0xF4
#define BPMEM_ZTEX2 0xF5
#define BPMEM_TEV_KSEL 0xF6 // 0xF6 + 8
#define BPMEM_BP_MASK 0xFE
//////////////////////////////////////////////////////////////////////////
// Tev/combiner things
//////////////////////////////////////////////////////////////////////////
#define TEVOP_ADD 0
#define TEVOP_SUB 1
#define TEVCMP_R8_GT 8
#define TEVCMP_R8_EQ 9
#define TEVCMP_GR16_GT 10
#define TEVCMP_GR16_EQ 11
#define TEVCMP_BGR24_GT 12
#define TEVCMP_BGR24_EQ 13
#define TEVCMP_RGB8_GT 14
#define TEVCMP_RGB8_EQ 15
#define TEVCMP_A8_GT 14
#define TEVCMP_A8_EQ 15
#define TEVCOLORARG_CPREV 0
#define TEVCOLORARG_APREV 1
#define TEVCOLORARG_C0 2
#define TEVCOLORARG_A0 3
#define TEVCOLORARG_C1 4
#define TEVCOLORARG_A1 5
#define TEVCOLORARG_C2 6
#define TEVCOLORARG_A2 7
#define TEVCOLORARG_TEXC 8
#define TEVCOLORARG_TEXA 9
#define TEVCOLORARG_RASC 10
#define TEVCOLORARG_RASA 11
#define TEVCOLORARG_ONE 12
#define TEVCOLORARG_HALF 13
#define TEVCOLORARG_KONST 14
#define TEVCOLORARG_ZERO 15
#define TEVALPHAARG_APREV 0
#define TEVALPHAARG_A0 1
#define TEVALPHAARG_A1 2
#define TEVALPHAARG_A2 3
#define TEVALPHAARG_TEXA 4
#define TEVALPHAARG_RASA 5
#define TEVALPHAARG_KONST 6
#define TEVALPHAARG_ZERO 7
#define ALPHACMP_NEVER 0
#define ALPHACMP_LESS 1
#define ALPHACMP_EQUAL 2
#define ALPHACMP_LEQUAL 3
#define ALPHACMP_GREATER 4
#define ALPHACMP_NEQUAL 5
#define ALPHACMP_GEQUAL 6
#define ALPHACMP_ALWAYS 7
enum Compare
{
COMPARE_NEVER = 0,
COMPARE_LESS,
COMPARE_EQUAL,
COMPARE_LEQUAL,
COMPARE_GREATER,
COMPARE_NEQUAL,
COMPARE_GEQUAL,
COMPARE_ALWAYS
};
#define ZTEXTURE_DISABLE 0
#define ZTEXTURE_ADD 1
#define ZTEXTURE_REPLACE 2
enum TevBias
{
TB_ZERO = 0,
TB_ADDHALF = 1,
TB_SUBHALF = 2,
TB_COMPARE = 3,
};
enum AlphaOp
{
ALPHAOP_AND = 0,
ALPHAOP_OR,
ALPHAOP_XOR,
ALPHAOP_XNOR,
};
union IND_MTXA
{
struct
{
signed ma : 11;
signed mb : 11;
unsigned s0 : 2; // bits 0-1 of scale factor
unsigned rid : 8;
};
u32 hex;
};
union IND_MTXB
{
struct
{
signed mc : 11;
signed md : 11;
unsigned s1 : 2; // bits 2-3 of scale factor
unsigned rid : 8;
};
u32 hex;
};
union IND_MTXC
{
struct
{
signed me : 11;
signed mf : 11;
unsigned s2 : 2; // bits 4-5 of scale factor
unsigned rid : 8;
};
u32 hex;
};
struct IND_MTX
{
IND_MTXA col0;
IND_MTXB col1;
IND_MTXC col2;
};
union IND_IMASK
{
struct
{
unsigned mask : 24;
unsigned rid : 8;
};
u32 hex;
};
#define TEVSELCC_CPREV 0
#define TEVSELCC_APREV 1
#define TEVSELCC_C0 2
#define TEVSELCC_A0 3
#define TEVSELCC_C1 4
#define TEVSELCC_A1 5
#define TEVSELCC_C2 6
#define TEVSELCC_A2 7
#define TEVSELCC_TEXC 8
#define TEVSELCC_TEXA 9
#define TEVSELCC_RASC 10
#define TEVSELCC_RASA 11
#define TEVSELCC_ONE 12
#define TEVSELCC_HALF 13
#define TEVSELCC_KONST 14
#define TEVSELCC_ZERO 15
#define TEVSELCA_APREV 0
#define TEVSELCA_A0 1
#define TEVSELCA_A1 2
#define TEVSELCA_A2 3
#define TEVSELCA_TEXA 4
#define TEVSELCA_RASA 5
#define TEVSELCA_KONST 6
#define TEVSELCA_ZERO 7
struct TevStageCombiner
{
union ColorCombiner
{
struct //abc=8bit,d=10bit
{
unsigned d : 4; // TEVSELCC_X
unsigned c : 4; // TEVSELCC_X
unsigned b : 4; // TEVSELCC_X
unsigned a : 4; // TEVSELCC_X
unsigned bias : 2;
unsigned op : 1;
unsigned clamp : 1;
unsigned shift : 2;
unsigned dest : 2; //1,2,3
};
u32 hex;
};
union AlphaCombiner
{
struct
{
unsigned rswap : 2;
unsigned tswap : 2;
unsigned d : 3; // TEVSELCA_
unsigned c : 3; // TEVSELCA_
unsigned b : 3; // TEVSELCA_
unsigned a : 3; // TEVSELCA_
unsigned bias : 2; //GXTevBias
unsigned op : 1;
unsigned clamp : 1;
unsigned shift : 2;
unsigned dest : 2; //1,2,3
};
u32 hex;
};
ColorCombiner colorC;
AlphaCombiner alphaC;
};
#define ITF_8 0
#define ITF_5 1
#define ITF_4 2
#define ITF_3 3
#define ITB_NONE 0
#define ITB_S 1
#define ITB_T 2
#define ITB_ST 3
#define ITB_U 4
#define ITB_SU 5
#define ITB_TU 6
#define ITB_STU 7
#define ITBA_OFF 0
#define ITBA_S 1
#define ITBA_T 2
#define ITBA_U 3
#define ITW_OFF 0
#define ITW_256 1
#define ITW_128 2
#define ITW_64 3
#define ITW_32 4
#define ITW_16 5
#define ITW_0 6
// several discoveries:
// GXSetTevIndBumpST(tevstage, indstage, matrixind)
// if( matrix == 2 ) realmat = 6; // 10
// else if( matrix == 3 ) realmat = 7; // 11
// else if( matrix == 1 ) realmat = 5; // 9
// GXSetTevIndirect(tevstage, indstage, 0, 3, realmat, 6, 6, 0, 0, 0)
// GXSetTevIndirect(tevstage+1, indstage, 0, 3, realmat+4, 6, 6, 1, 0, 0)
// GXSetTevIndirect(tevstage+2, indstage, 0, 0, 0, 0, 0, 1, 0, 0)
union TevStageIndirect
{
// if mid, sw, tw, and addprev are 0, then no indirect stage is used, mask = 0x17fe00
struct
{
unsigned bt : 2; // indirect tex stage ID
unsigned fmt : 2; // format: ITF_X
unsigned bias : 3; // ITB_X
unsigned bs : 2; // ITBA_X, indicates which coordinate will become the 'bump alpha'
unsigned mid : 4; // matrix id to multiply offsets with
unsigned sw : 3; // ITW_X, wrapping factor for S of regular coord
unsigned tw : 3; // ITW_X, wrapping factor for T of regular coord
unsigned lb_utclod : 1; // use modified or unmodified texture coordinates for LOD computation
unsigned fb_addprev : 1; // 1 if the texture coordinate results from the previous TEV stage should be added
unsigned pad0 : 3;
unsigned rid : 8;
};
struct
{
u32 hex : 21;
u32 unused : 11;
};
bool IsActive() { return (hex&0x17fe00)!=0; }
};
union TwoTevStageOrders
{
struct
{
unsigned texmap0 : 3; // indirect tex stage texmap
unsigned texcoord0 : 3;
unsigned enable0 : 1; // 1 if should read from texture
unsigned colorchan0 : 3; // RAS1_CC_X
unsigned pad0 : 2;
unsigned texmap1 : 3;
unsigned texcoord1 : 3;
unsigned enable1 : 1; // 1 if should read from texture
unsigned colorchan1 : 3; // RAS1_CC_X
unsigned pad1 : 2;
unsigned rid : 8;
};
u32 hex;
int getTexMap(int i){return i?texmap1:texmap0;}
int getTexCoord(int i){return i?texcoord1:texcoord0;}
int getEnable(int i){return i?enable1:enable0;}
int getColorChan(int i){return i?colorchan1:colorchan0;}
};
union TEXSCALE
{
struct
{
unsigned ss0 : 4; // indirect tex stage 0, 2^(-ss0)
unsigned ts0 : 4; // indirect tex stage 0
unsigned ss1 : 4; // indirect tex stage 1
unsigned ts1 : 4; // indirect tex stage 1
unsigned pad : 8;
unsigned rid : 8;
};
u32 hex;
float getScaleS(int i){return 1.0f/(float)(1<<(i?ss1:ss0));}
float getScaleT(int i){return 1.0f/(float)(1<<(i?ts1:ts0));}
};
union RAS1_IREF
{
struct
{
unsigned bi0 : 3; // indirect tex stage 0 ntexmap
unsigned bc0 : 3; // indirect tex stage 0 ntexcoord
unsigned bi1 : 3;
unsigned bc1 : 3;
unsigned bi2 : 3;
unsigned bc3 : 3;
unsigned bi4 : 3;
unsigned bc4 : 3;
unsigned rid : 8;
};
u32 hex;
u32 getTexCoord(int i) { return (hex>>(6*i+3))&3; }
u32 getTexMap(int i) { return (hex>>(6*i))&3; }
};
//////////////////////////////////////////////////////////////////////////
// Texture structs
//////////////////////////////////////////////////////////////////////////
union TexMode0
{
struct
{
unsigned wrap_s : 2;
unsigned wrap_t : 2;
unsigned mag_filter : 1;
unsigned min_filter : 3;
unsigned diag_lod : 1;
signed lod_bias : 10;
unsigned max_aniso : 2;
unsigned lod_clamp : 1;
};
u32 hex;
};
union TexMode1
{
struct
{
unsigned min_lod : 8;
unsigned max_lod : 8;
};
u32 hex;
};
union TexImage0
{
struct
{
unsigned width : 10; //actually w-1
unsigned height : 10; //actually h-1
unsigned format : 4;
};
u32 hex;
};
union TexImage1
{
struct
{
unsigned tmem_offset : 15; // we ignore texture caching for now, we do it ourselves
unsigned cache_width : 3;
unsigned cache_height : 3;
unsigned image_type : 1;
};
u32 hex;
};
union TexImage2
{
struct
{
unsigned tmem_offset : 15; // we ignore texture caching for now, we do it ourselves
unsigned cache_width : 3;
unsigned cache_height : 3;
};
u32 hex;
};
union TexImage3
{
struct
{
unsigned image_base: 24; //address in memory >> 5 (was 20 for GC)
};
u32 hex;
};
union TexTLUT
{
struct
{
unsigned tmem_offset : 10;
unsigned tlut_format : 2;
};
u32 hex;
};
union ZTex1
{
struct
{
unsigned bias : 24;
};
u32 hex;
};
union ZTex2
{
struct
{
unsigned type : 2; // TEV_Z_TYPE_X
unsigned op : 2; // GXZTexOp
};
u32 hex;
};
// Z-texture types (formats)
#define TEV_ZTEX_TYPE_U8 0
#define TEV_ZTEX_TYPE_U16 1
#define TEV_ZTEX_TYPE_U24 2
#define TEV_ZTEX_DISABLE 0
#define TEV_ZTEX_ADD 1
#define TEV_ZTEX_REPLACE 2
struct FourTexUnits
{
TexMode0 texMode0[4];
TexMode1 texMode1[4];
TexImage0 texImage0[4];
TexImage1 texImage1[4];
TexImage2 texImage2[4];
TexImage3 texImage3[4];
TexTLUT texTlut[4];
u32 unknown[4];
};
//////////////////////////////////////////////////////////////////////////
// Geometry/other structs
//////////////////////////////////////////////////////////////////////////
union GenMode
{
struct
{
unsigned numtexgens : 4; // 0xF
unsigned numcolchans : 5; // 0x1E0
unsigned ms_en : 1; // 0x200
unsigned numtevstages : 4; // 0x3C00
unsigned cullmode : 2; // 0xC000
unsigned numindstages : 3; // 0x30000
unsigned zfreeze : 5; //0x3C0000
};
u32 hex;
};
union LPSize
{
struct
{
unsigned linesize : 8; // in 1/6th pixels
unsigned pointsize : 8; // in 1/6th pixels
unsigned lineoff : 3;
unsigned pointoff : 3;
unsigned lineaspect : 1;
unsigned padding : 1;
};
u32 hex;
};
union X12Y12
{
struct
{
unsigned y : 12;
unsigned x : 12;
};
u32 hex;
};
union X10Y10
{
struct
{
unsigned x : 10;
unsigned y : 10;
};
u32 hex;
};
//////////////////////////////////////////////////////////////////////////
// Framebuffer/pixel stuff (incl fog)
//////////////////////////////////////////////////////////////////////////
union BlendMode
{
struct
{
unsigned blendenable : 1;
unsigned logicopenable : 1;
unsigned dither : 1;
unsigned colorupdate : 1;
unsigned alphaupdate : 1;
unsigned dstfactor : 3; //BLEND_ONE, BLEND_INV_SRc etc
unsigned srcfactor : 3;
unsigned subtract : 1;
unsigned logicmode : 4;
};
u32 hex;
};
union FogParam0
{
struct
{
unsigned mantissa : 11;
unsigned exponent : 8;
unsigned sign : 1;
};
float GetA() {
union { u32 i; float f; } dummy;
dummy.i = ((u32)sign<<31)|((u32)exponent<<23)|((u32)mantissa<<12);
return dummy.f;
}
u32 hex;
};
union FogParam3
{
struct
{
unsigned c_mant : 11;
unsigned c_exp : 8;
unsigned c_sign : 1;
unsigned proj : 1; // 0 - perspective, 1 - orthographic
unsigned fsel : 3; // 0 - off, 2 - linear, 4 - exp, 5 - exp2, 6 - backward exp, 7 - backward exp2
};
// amount to subtract from eyespacez after range adjustment
float GetC() {
union { u32 i; float f; } dummy;
dummy.i = ((u32)c_sign << 31) | ((u32)c_exp << 23) | ((u32)c_mant << 12);
return dummy.f;
}
u32 hex;
};
// final eq: ze = A/(B_MAG - (Zs>>B_SHF));
struct FogParams
{
FogParam0 a;
u32 b_magnitude;
u32 b_shift; // b's exp + 1?
FogParam3 c_proj_fsel;
union FogColor
{
struct
{
unsigned b : 8;
unsigned g : 8;
unsigned r : 8;
};
u32 hex;
};
FogColor color; //0:b 8:g 16:r - nice!
};
union ZMode
{
struct
{
unsigned testenable : 1;
unsigned func : 3;
unsigned updateenable : 1; //size?
};
u32 hex;
};
union ConstantAlpha
{
struct
{
unsigned alpha : 8;
unsigned enable : 1;
};
u32 hex;
};
#define PIXELFMT_RGB8_Z24 0
#define PIXELFMT_RGBA6_Z24 1
#define PIXELFMT_RGB565_Z16 2
#define PIXELFMT_Z24 3
#define PIXELFMT_Y8 4
#define PIXELFMT_U8 5
#define PIXELFMT_V8 6
#define PIXELFMT_YUV420 7
union PE_CONTROL
{
struct
{
unsigned pixel_format : 3; // PIXELFMT_X
unsigned zformat : 3; // 0 - linear, 1 - near, 2 - mid, 3 - far
unsigned zcomploc : 1; // 1: before tex stage
unsigned unused : 17;
unsigned rid : 8;
};
u32 hex;
};
//////////////////////////////////////////////////////////////////////////
// Texture coordinate stuff
//////////////////////////////////////////////////////////////////////////
union TCInfo
{
struct
{
unsigned scale_minus_1 : 16;
unsigned range_bias : 1;
unsigned cylindric_wrap : 1;
};
u32 hex;
};
struct TCoordInfo
{
TCInfo s;
TCInfo t;
};
union ColReg
{
u32 hex;
struct
{
signed a : 11;
unsigned : 1;
signed b : 11;
unsigned type : 1;
};
};
struct TevReg
{
ColReg low;
ColReg high;
};
union TevKSel
{
struct {
unsigned swap1 : 2;
unsigned swap2 : 2;
unsigned kcsel0 : 5;
unsigned kasel0 : 5;
unsigned kcsel1 : 5;
unsigned kasel1 : 5;
};
u32 hex;
int getKC(int i) {return i?kcsel1:kcsel0;}
int getKA(int i) {return i?kasel1:kasel0;}
};
union AlphaFunc
{
struct
{
unsigned ref0 : 8;
unsigned ref1 : 8;
unsigned comp0 : 3;
unsigned comp1 : 3;
unsigned logic : 2;
};
u32 hex;
};
union UPE_Copy
{
u32 Hex;
struct
{
unsigned clamp0 : 1;
unsigned clamp1 : 1;
unsigned : 1;
unsigned target_pixel_format : 4; // realformat is (fmt/2)+((fmt&1)*8).... for some reason the msb is the lsb
unsigned gamma : 2;
unsigned half_scale : 1; // real size should be 2x smaller (run a gauss filter?)
unsigned scale_something : 1;
unsigned clear : 1;
unsigned frame_to_field : 2;
unsigned copy_to_xfb : 1;
unsigned intensity_fmt : 1; // if set, is an intensity format (I4,I8,IA4,IA8)
unsigned : 16; // seems to set everything to 1s when target pixel format is invalid
};
};
//////////////////////////////////////////////////////////////////////////
// All of BP memory
//////////////////////////////////////////////////////////////////////////
struct Bypass
{
int address;
int changes;
int newvalue;
};
struct BPMemory
{
GenMode genMode;
u32 display_copy_filter[4]; // 01-04
u32 unknown; // 05
// indirect matrices (set by GXSetIndTexMtx, selected by TevStageIndirect::mid)
// abc form a 2x3 offset matrix, there's 3 such matrices
// the 3 offset matrices can either be indirect type, S-type, or T-type
// 6bit scale factor s is distributed across IND_MTXA/B/C.
// before using matrices scale by 2^-(s-17)
IND_MTX indmtx[3];//06-0e GXSetIndTexMtx, 2x3 matrices
IND_IMASK imask;//0f
TevStageIndirect tevind[16];//10 GXSetTevIndirect
X12Y12 scissorTL; //20
X12Y12 scissorBR; //21
LPSize lineptwidth; //22 line and point width
u32 sucounter; //23
u32 rascounter; //24
TEXSCALE texscale[2]; //25-26 GXSetIndTexCoordScale
RAS1_IREF tevindref; //27 GXSetIndTexOrder
TwoTevStageOrders tevorders[8]; //28-2F
TCoordInfo texcoords[8]; //0x30 s,t,s,t,s,t,s,t...
ZMode zmode; //40
BlendMode blendmode; //41
ConstantAlpha dstalpha; //42
PE_CONTROL zcontrol; //43 GXSetZCompLoc, GXPixModeSync
u32 fieldmask; //44
u32 drawdone; //45, bit1=1 if end of list
u32 unknown5; //46 clock?
u32 petoken; //47
u32 petokenint; // 48
X10Y10 copyTexSrcXY; // 49
X10Y10 copyTexSrcWH; // 4a
u32 copyTexDest; //4b// 4b == CopyAddress (GXDispCopy and GXTexCopy use it)
u32 unknown6; //4c
u32 copyMipMapStrideChannels; // 4d usually set to 4 when dest is single channel, 8 when dest is 2 channel, 16 when dest is RGBA
// also, doubles whenever mipmap box filter option is set (excent on RGBA). Probably to do with number of bytes to look at when smoothing
u32 dispcopyyscale; //4e
u32 clearcolorAR; //4f
u32 clearcolorGB; //50
u32 clearZValue; //51
u32 triggerEFBCopy; //52
u32 copyfilter[2]; //53,54
u32 boundbox0;//55
u32 boundbox1;//56
u32 unknown7[2];//57,58
X10Y10 scissorOffset; //59
u32 unknown8[10]; //5a,5b,5c,5d, 5e,5f,60,61, 62, 63 (GXTexModeSync), 0x60-0x63 have to do with preloaded textures?
u32 tlutXferSrc; //64
u32 tlutXferDest; //65
u32 texinvalidate;//66
u32 metric; //67
u32 fieldmode;//68
u32 unknown10[7];//69-6F
u32 unknown11[16];//70-7F
FourTexUnits tex[2]; //80-bf
TevStageCombiner combiners[16]; //0xC0-0xDF
TevReg tevregs[4]; //0xE0
u32 fogRangeAdj; //0xE8
u32 unknown15[3]; //0xe9,0xea,0xeb - fog related
u32 tev_range_adj_c; //0xec - screenx center for range adjustment, range adjustment enable
u32 tev_range_adj_k; //0xed - specifies range adjustment function = sqrt(x*x+k*k)/k
FogParams fog; //0xEE,0xEF,0xF0,0xF1,0xF2
AlphaFunc alphaFunc; //0xF3
ZTex1 ztex1; //0xf4,0xf5
ZTex2 ztex2;
TevKSel tevksel[8];//0xf6,0xf7,f8,f9,fa,fb,fc,fd
u32 bpMask; //0xFE
u32 unknown18; //ff
};
#pragma pack()
extern BPMemory bpmem;
void LoadBPReg(u32 value0);
#endif

View File

@ -1,596 +0,0 @@
// Copyright (C) 2003-2009 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// 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 SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include <cmath>
#include "Profiler.h"
#include "Statistics.h"
#include "VideoCommon.h"
#include "PixelShaderManager.h"
#include "BPFunctions.h"
#include "BPStructs.h"
#include "TextureDecoder.h"
#include "OpcodeDecoding.h"
#include "VertexLoader.h"
#include "VertexShaderManager.h"
using namespace BPFunctions;
void BPInit()
{
memset(&bpmem, 0, sizeof(bpmem));
bpmem.bpMask = 0xFFFFFF;
}
// ----------------------------------------------------------------------------------------------------------
// Write to the Bypass Memory (Bypass Raster State Registers)
/* ------------------
Called:
At the end of every: OpcodeDecoding.cpp ExecuteDisplayList > Decode() > LoadBPReg
TODO:
Turn into function table. The (future) DisplayList (DL) jit can then call the functions directly,
getting rid of dynamic dispatch. Unfortunately, few games use DLs properly - most\
just stuff geometry in them and don't put state changes there. */
// ----------------------------------------------------------------------------------------------------------
void BPWritten(const Bypass& bp)
{
// --------------------------------------------------------------------------------------------------------
// First the pipeline is flushed then update the bpmem with the new value.
// Some of the BP cases have to call certain functions while others just update the bpmem.
// some bp cases check the changes variable, because they might not have to be updated all the time
// NOTE: it seems not all bp cases like checking changes, so calling if (bp.changes == 0 ? false : true)
// had to be ditched and the games seem to work fine with out it.
// NOTE2: Yet Another Gamecube Documentation calls them Bypass Registers
// --------------------------------------------------------------------------------------------------------
// Debugging only, this lets you skip a bp update
//static int times = 0;
//static bool enable = false;
//switch (bp.address)
//{
//case BPMEM_CONSTANTALPHA:
// {
// if (times-- == 0 && enable)
// return;
// else
// break;
// }
//default: break;
//}
FlushPipeline();
((u32*)&bpmem)[bp.address] = bp.newvalue;
switch (bp.address)
{
case BPMEM_GENMODE: // Set the Generation Mode
{
PRIM_LOG("genmode: texgen=%d, col=%d, ms_en=%d, tev=%d, culmode=%d, ind=%d, zfeeze=%d",
bpmem.genMode.numtexgens, bpmem.genMode.numcolchans,
bpmem.genMode.ms_en, bpmem.genMode.numtevstages+1, bpmem.genMode.cullmode,
bpmem.genMode.numindstages, bpmem.genMode.zfreeze);
SetGenerationMode(bp);
break;
}
case BPMEM_IND_MTXA: // Index Matrix Changed
case BPMEM_IND_MTXB:
case BPMEM_IND_MTXC:
case BPMEM_IND_MTXA+3:
case BPMEM_IND_MTXB+3:
case BPMEM_IND_MTXC+3:
case BPMEM_IND_MTXA+6:
case BPMEM_IND_MTXB+6:
case BPMEM_IND_MTXC+6:
PixelShaderManager::SetIndMatrixChanged((bp.address - BPMEM_IND_MTXA) / 3);
break;
case BPMEM_RAS1_SS0: // Index Texture Coordinate Scale 0
PixelShaderManager::SetIndTexScaleChanged(0x03);
case BPMEM_RAS1_SS1: // Index Texture Coordinate Scale 1
PixelShaderManager::SetIndTexScaleChanged(0x0c);
break;
case BPMEM_SCISSORTL: // Scissor Rectable Top, Left
case BPMEM_SCISSORBR: // Scissor Rectable Bottom, Right
case BPMEM_SCISSOROFFSET: // Scissor Offset
SetScissor(bp);
break;
case BPMEM_LINEPTWIDTH: // Line Width
SetLineWidth(bp);
break;
case BPMEM_ZMODE: // Depth Control
PRIM_LOG("zmode: test=%d, func=%d, upd=%d", bpmem.zmode.testenable, bpmem.zmode.func,
bpmem.zmode.updateenable);
SetDepthMode(bp);
break;
case BPMEM_BLENDMODE: // Blending Control
{
if (bp.changes & 0xFFFF)
{
PRIM_LOG("blendmode: en=%d, open=%d, colupd=%d, alphaupd=%d, dst=%d, src=%d, sub=%d, mode=%d",
bpmem.blendmode.blendenable, bpmem.blendmode.logicopenable, bpmem.blendmode.colorupdate, bpmem.blendmode.alphaupdate,
bpmem.blendmode.dstfactor, bpmem.blendmode.srcfactor, bpmem.blendmode.subtract, bpmem.blendmode.logicmode);
// Set LogicOp Blending Mode
if (bp.changes & 2)
{
SETSTAT(stats.logicOpMode, bpmem.blendmode.logicopenable != 0 ? bpmem.blendmode.logicmode : stats.logicOpMode);
SetLogicOpMode(bp);
}
// Set Dithering Mode
if (bp.changes & 4)
{
SETSTAT(stats.dither, bpmem.blendmode.dither);
SetDitherMode(bp);
}
// Set Blending Mode
if (bp.changes & 0xFE1)
{
SETSTAT(stats.srcFactor, bpmem.blendmode.srcfactor);
SETSTAT(stats.dstFactor, bpmem.blendmode.dstfactor);
SetBlendMode(bp);
}
// Set Color Mask
if (bp.changes & 0x18)
{
SETSTAT(stats.alphaUpdate, bpmem.blendmode.alphaupdate);
SETSTAT(stats.colorUpdate, bpmem.blendmode.colorupdate);
SetColorMask(bp);
}
}
break;
}
case BPMEM_CONSTANTALPHA: // Set Destination Alpha
{
PRIM_LOG("constalpha: alp=%d, en=%d", bpmem.dstalpha.alpha, bpmem.dstalpha.enable);
SETSTAT(stats.dstAlphaEnable, bpmem.dstalpha.enable);
SETSTAT_UINT(stats.dstAlpha, bpmem.dstalpha.alpha);
PixelShaderManager::SetDestAlpha(bpmem.dstalpha);
break;
}
// This is called when the game is done drawing the new frame (eg: like in DX: Begin(); Draw(); End();)
case BPMEM_SETDRAWDONE:
switch (bp.newvalue & 0xFF)
{
case 0x02:
g_VideoInitialize.pSetPEFinish(); // may generate interrupt
DEBUG_LOG(VIDEO, "GXSetDrawDone SetPEFinish (value: 0x%02X)", (bp.newvalue & 0xFFFF));
break;
default:
WARN_LOG(VIDEO, "GXSetDrawDone ??? (value 0x%02X)", (bp.newvalue & 0xFFFF));
break;
}
break;
case BPMEM_PE_TOKEN_ID: // Pixel Engine Token ID
g_VideoInitialize.pSetPEToken(static_cast<u16>(bp.newvalue & 0xFFFF), FALSE);
DEBUG_LOG(VIDEO, "SetPEToken 0x%04x", (bp.newvalue & 0xFFFF));
break;
case BPMEM_PE_TOKEN_INT_ID: // Pixel Engine Interrupt Token ID
g_VideoInitialize.pSetPEToken(static_cast<u16>(bp.newvalue & 0xFFFF), TRUE);
DEBUG_LOG(VIDEO, "SetPEToken + INT 0x%04x", (bp.newvalue & 0xFFFF));
break;
// ------------------------
// EFB copy command. This copies a rectangle from the EFB to either RAM in a texture format or to XFB as YUYV.
// It can also optionally clear the EFB while copying from it. To emulate this, we of course copy first and clear afterwards.
case BPMEM_TRIGGER_EFB_COPY: // Copy EFB Region or Render to the XFB or Clear the screen.
{
DVSTARTSUBPROFILE("LoadBPReg:swap");
// The bottom right is within the rectangle
// The values in bpmem.copyTexSrcXY and bpmem.copyTexSrcWH are updated in case 0x49 and 0x4a in this function
TRectangle rc = {
(int)(bpmem.copyTexSrcXY.x),
(int)(bpmem.copyTexSrcXY.y),
(int)((bpmem.copyTexSrcXY.x + bpmem.copyTexSrcWH.x + 1)),
(int)((bpmem.copyTexSrcXY.y + bpmem.copyTexSrcWH.y + 1))
};
float MValueX = GetRendererTargetScaleX();
float MValueY = GetRendererTargetScaleY();
// Need another rc here to get it to scale.
// Here the bottom right is the out of the rectangle.
TRectangle multirc = {
(int)(bpmem.copyTexSrcXY.x * MValueX),
(int)(bpmem.copyTexSrcXY.y * MValueY),
(int)((bpmem.copyTexSrcXY.x * MValueX + (bpmem.copyTexSrcWH.x + 1) * MValueX)),
(int)((bpmem.copyTexSrcXY.y * MValueY + (bpmem.copyTexSrcWH.y + 1) * MValueY))
};
UPE_Copy PE_copy;
PE_copy.Hex = bpmem.triggerEFBCopy;
// Check if we are to copy from the EFB or draw to the XFB
if (PE_copy.copy_to_xfb == 0)
{
if (GetConfig(CONFIG_SHOWEFBREGIONS))
stats.efb_regions.push_back(rc);
CopyEFB(bp, rc, bpmem.copyTexDest << 5,
bpmem.zcontrol.pixel_format == PIXELFMT_Z24,
PE_copy.intensity_fmt > 0,
((PE_copy.target_pixel_format / 2) + ((PE_copy.target_pixel_format & 1) * 8)),
PE_copy.half_scale > 0);
}
else
{
// the number of lines copied is determined by the y scale * source efb height
const float yScale = bpmem.dispcopyyscale / 256.0f;
const float xfbLines = ((bpmem.copyTexSrcWH.y + 1.0f) * yScale);
RenderToXFB(bp, multirc, yScale, xfbLines,
Memory_GetPtr(bpmem.copyTexDest << 5),
bpmem.copyMipMapStrideChannels << 4,
(u32)ceil(xfbLines));
}
// Clear the picture after it's done and submitted, to prepare for the next picture
if (PE_copy.clear)
ClearScreen(bp, multirc);
RestoreRenderState(bp);
break;
}
case BPMEM_LOADTLUT0: // Load a Texture Look Up Table
case BPMEM_LOADTLUT1:
{
DVSTARTSUBPROFILE("LoadBPReg:GXLoadTlut");
u32 tlutTMemAddr = (bp.newvalue & 0x3FF) << 9;
u32 tlutXferCount = (bp.newvalue & 0x1FFC00) >> 5;
u8 *ptr = 0;
// TODO - figure out a cleaner way.
if (GetConfig(CONFIG_ISWII))
ptr = GetPointer(bpmem.tlutXferSrc << 5);
else
ptr = GetPointer((bpmem.tlutXferSrc & 0xFFFFF) << 5);
if (ptr)
memcpy_gc(texMem + tlutTMemAddr, ptr, tlutXferCount);
else
PanicAlert("Invalid palette pointer %08x %08x %08x", bpmem.tlutXferSrc, bpmem.tlutXferSrc << 5, (bpmem.tlutXferSrc & 0xFFFFF)<< 5);
// TODO(ector) : kill all textures that use this palette
// Not sure if it's a good idea, though. For now, we hash texture palettes
break;
}
case BPMEM_FOGRANGE: // Fog Settings Control
case BPMEM_FOGPARAM0:
case BPMEM_FOGBMAGNITUDE:
case BPMEM_FOGBEXPONENT:
case BPMEM_FOGPARAM3:
if(!GetConfig(CONFIG_DISABLEFOG))
PixelShaderManager::SetFogParamChanged();
break;
case BPMEM_FOGCOLOR: // Fog Color
PixelShaderManager::SetFogColorChanged();
break;
case BPMEM_ALPHACOMPARE: // Compare Alpha Values
PRIM_LOG("alphacmp: ref0=%d, ref1=%d, comp0=%d, comp1=%d, logic=%d", bpmem.alphaFunc.ref0,
bpmem.alphaFunc.ref1, bpmem.alphaFunc.comp0, bpmem.alphaFunc.comp1, bpmem.alphaFunc.logic);
PixelShaderManager::SetAlpha(bpmem.alphaFunc);
break;
case BPMEM_BIAS: // BIAS
PRIM_LOG("ztex bias=0x%x", bpmem.ztex1.bias);
PixelShaderManager::SetZTextureBias(bpmem.ztex1.bias);
break;
case BPMEM_ZTEX2: // Z Texture type
{
if (bp.changes & 3)
PixelShaderManager::SetZTextureTypeChanged();
#if defined(_DEBUG) || defined(DEBUGFAST)
const char* pzop[] = {"DISABLE", "ADD", "REPLACE", "?"};
const char* pztype[] = {"Z8", "Z16", "Z24", "?"};
PRIM_LOG("ztex op=%s, type=%s", pzop[bpmem.ztex2.op], pztype[bpmem.ztex2.type]);
#endif
break;
}
// ----------------------------------
// Display Copy Filtering Control
// Fields: Destination, Frame2Field, Gamma, Source
// TODO: We might have to implement the gamma one, some games might need this, if they are too dark to see.
// ----------------------------------
case BPMEM_DISPLAYCOPYFILER:
case BPMEM_DISPLAYCOPYFILER+1:
case BPMEM_DISPLAYCOPYFILER+2:
case BPMEM_DISPLAYCOPYFILER+3:
case BPMEM_COPYFILTER0: //GXSetCopyFilter
case BPMEM_COPYFILTER1:
break;
case BPMEM_FIELDMASK: // Interlacing Control
case BPMEM_FIELDMODE:
SetInterlacingMode(bp);
break;
// ---------------------------------------------------
// Debugging/Profiling info, we don't care about them
// ---------------------------------------------------
case BPMEM_CLOCK0: // Some Clock
case BPMEM_CLOCK1: // Some Clock
case BPMEM_SU_COUNTER: // Pixel or Poly Count
case BPMEM_RAS_COUNTER: // Sound Count of something in the Texture Units
case BPMEM_SETGPMETRIC: // Set the Graphic Processor Metric
break;
// ----------------
// EFB Copy config
// ----------------
case BPMEM_EFB_TL: // EFB Source Rect. Top, Left
case BPMEM_EFB_BR: // EFB Source Rect. Bottom, Right (w, h - 1)
case BPMEM_EFB_ADDR: // EFB Target Address
break;
// --------------
// Clear Config
// --------------
case BPMEM_CLEAR_AR: // Alpha and Red Components
case BPMEM_CLEAR_GB: // Green and Blue Components
case BPMEM_CLEAR_Z: // Z Components (24-bit Zbuffer)
break;
// -------------------------
// Culling Occulsion, we don't support this
// let's hope not many games use bboxes..
// TODO(ector): add something that watches bboxes
// -------------------------
case BPMEM_CLEARBBOX1:
case BPMEM_CLEARBBOX2:
break;
case BPMEM_ZCOMPARE: // Set the Z-Compare
case BPMEM_TEXINVALIDATE: // Used, if game has manual control the Texture Cache, which we don't allow
case BPMEM_MIPMAP_STRIDE: // MipMap Stride Channel
case BPMEM_COPYYSCALE: // Display Copy Y Scale
case BPMEM_IREF: /* 24 RID
21 BC3 - Ind. Tex Stage 3 NTexCoord
18 BI3 - Ind. Tex Stage 3 NTexMap
15 BC2 - Ind. Tex Stage 2 NTexCoord
12 BI2 - Ind. Tex Stage 2 NTexMap
9 BC1 - Ind. Tex Stage 1 NTexCoord
6 BI1 - Ind. Tex Stage 1 NTexMap
3 BC0 - Ind. Tex Stage 0 NTexCoord
0 BI0 - Ind. Tex Stage 0 NTexMap */
break;
case BPMEM_TEV_KSEL: // Texture Environment Swap Mode Table 0
case BPMEM_TEV_KSEL+1:// Texture Environment Swap Mode Table 1
case BPMEM_TEV_KSEL+2:// Texture Environment Swap Mode Table 2
case BPMEM_TEV_KSEL+3:// Texture Environment Swap Mode Table 3
case BPMEM_TEV_KSEL+4:// Texture Environment Swap Mode Table 4
case BPMEM_TEV_KSEL+5:// Texture Environment Swap Mode Table 5
case BPMEM_TEV_KSEL+6:// Texture Environment Swap Mode Table 6
case BPMEM_TEV_KSEL+7:// Texture Environment Swap Mode Table 7
break;
case BPMEM_BP_MASK: // This Register can be used to limit to which bits of BP registers is actually written to. the mask is
// only valid for the next BP command, and will reset itself.
case BPMEM_IND_IMASK: // Index Mask ?
break;
case BPMEM_UNKNOWN: // This is always set to 0xF at boot of any game, so this sounds like a useless reg
if (bp.newvalue != 0x0F)
PanicAlert("Unknown is not 0xF! val = 0x%08x", bp.newvalue);
break;
// Cases added due to: http://code.google.com/p/dolphin-emu/issues/detail?id=360#c90
// Are these related to BBox?
case BPMEM_UNKNOWN1:
case BPMEM_UNKNOWN2:
case BPMEM_UNKNOWN3:
case BPMEM_UNKNOWN4:
break;
// ------------------------------------------------
// On Default, we try to look for other things
// before we give up and say its an unknown opcode
// ------------------------------------------------
default:
switch (bp.address & 0xFC) // Texture sampler filter
{
// -------------------------
// Texture Environment Order
// -------------------------
case BPMEM_TREF:
case BPMEM_TREF+1:
case BPMEM_TREF+2:
case BPMEM_TREF+3:
case BPMEM_TREF+4:
case BPMEM_TREF+5:
case BPMEM_TREF+6:
case BPMEM_TREF+7:
break;
// ----------------------
// Set wrap size
// ----------------------
case BPMEM_SU_SSIZE:
case BPMEM_SU_TSIZE:
case BPMEM_SU_SSIZE+2:
case BPMEM_SU_TSIZE+2:
case BPMEM_SU_SSIZE+4:
case BPMEM_SU_TSIZE+4:
case BPMEM_SU_SSIZE+6:
case BPMEM_SU_TSIZE+6:
case BPMEM_SU_SSIZE+8:
case BPMEM_SU_TSIZE+8:
case BPMEM_SU_SSIZE+10:
case BPMEM_SU_TSIZE+10:
case BPMEM_SU_SSIZE+12:
case BPMEM_SU_TSIZE+12:
case BPMEM_SU_SSIZE+14:
case BPMEM_SU_TSIZE+14:
PixelShaderManager::SetTexCoordChanged((bp.address - BPMEM_SU_SSIZE) >> 1);
break;
// ------------------------
// BPMEM_TX_SETMODE0 - (Texture lookup and filtering mode) LOD/BIAS Clamp, MaxAnsio, LODBIAS, DiagLoad, Min Filter, Mag Filter, Wrap T, S
// BPMEM_TX_SETMODE1 - (LOD Stuff) - Max LOD, Min LOD
// ------------------------
case BPMEM_TX_SETMODE0: // (0x90 for linear)
case BPMEM_TX_SETMODE0+1:
case BPMEM_TX_SETMODE0+2:
case BPMEM_TX_SETMODE0+3:
case BPMEM_TX_SETMODE1:
case BPMEM_TX_SETMODE1+1:
case BPMEM_TX_SETMODE1+2:
case BPMEM_TX_SETMODE1+3:
case BPMEM_TX_SETMODE0_4:
case BPMEM_TX_SETMODE0_4+1:
case BPMEM_TX_SETMODE0_4+2:
case BPMEM_TX_SETMODE0_4+3:
case BPMEM_TX_SETMODE1_4:
case BPMEM_TX_SETMODE1_4+1:
case BPMEM_TX_SETMODE1_4+2:
case BPMEM_TX_SETMODE1_4+3:
SetSamplerState(bp);
break;
// --------------------------------------------
// BPMEM_TX_SETIMAGE0 - Texture width, height, format
// BPMEM_TX_SETIMAGE1 - even LOD address in TMEM - Image Type, Cache Height, Cache Width, TMEM Offset
// BPMEM_TX_SETIMAGE2 - odd LOD address in TMEM - Cache Height, Cache Width, TMEM Offset
// BPMEM_TX_SETIMAGE3 - Address of Texture in main memory
// --------------------------------------------
case BPMEM_TX_SETIMAGE0:
case BPMEM_TX_SETIMAGE0+1:
case BPMEM_TX_SETIMAGE0+2:
case BPMEM_TX_SETIMAGE0+3:
case BPMEM_TX_SETIMAGE0_4:
case BPMEM_TX_SETIMAGE0_4+1:
case BPMEM_TX_SETIMAGE0_4+2:
case BPMEM_TX_SETIMAGE0_4+3:
case BPMEM_TX_SETIMAGE1:
case BPMEM_TX_SETIMAGE1+1:
case BPMEM_TX_SETIMAGE1+2:
case BPMEM_TX_SETIMAGE1+3:
case BPMEM_TX_SETIMAGE1_4:
case BPMEM_TX_SETIMAGE1_4+1:
case BPMEM_TX_SETIMAGE1_4+2:
case BPMEM_TX_SETIMAGE1_4+3:
case BPMEM_TX_SETIMAGE2:
case BPMEM_TX_SETIMAGE2+1:
case BPMEM_TX_SETIMAGE2+2:
case BPMEM_TX_SETIMAGE2+3:
case BPMEM_TX_SETIMAGE2_4:
case BPMEM_TX_SETIMAGE2_4+1:
case BPMEM_TX_SETIMAGE2_4+2:
case BPMEM_TX_SETIMAGE2_4+3:
case BPMEM_TX_SETIMAGE3:
case BPMEM_TX_SETIMAGE3+1:
case BPMEM_TX_SETIMAGE3+2:
case BPMEM_TX_SETIMAGE3+3:
case BPMEM_TX_SETIMAGE3_4:
case BPMEM_TX_SETIMAGE3_4+1:
case BPMEM_TX_SETIMAGE3_4+2:
case BPMEM_TX_SETIMAGE3_4+3:
break;
// -------------------------------
// Set a TLUT
// BPMEM_TX_SETTLUT - Format, TMEM Offset (offset of TLUT from start of TMEM high bank > > 5)
// -------------------------------
case BPMEM_TX_SETTLUT:
case BPMEM_TX_SETTLUT+1:
case BPMEM_TX_SETTLUT+2:
case BPMEM_TX_SETTLUT+3:
case BPMEM_TX_SETLUT_4:
case BPMEM_TX_SETLUT_4+1:
case BPMEM_TX_SETLUT_4+2:
case BPMEM_TX_SETLUT_4+3:
break;
// ---------------------------------------------------
// Set the TEV Color
// ---------------------------------------------------
case BPMEM_TEV_REGISTER_L: // Reg 1
case BPMEM_TEV_REGISTER_H:
case BPMEM_TEV_REGISTER_L+2: // Reg 2
case BPMEM_TEV_REGISTER_H+2:
case BPMEM_TEV_REGISTER_L+4: // Reg 3
case BPMEM_TEV_REGISTER_H+4:
case BPMEM_TEV_REGISTER_L+6: // Reg 4
case BPMEM_TEV_REGISTER_H+6:
{
if (bp.address & 1)
{
// don't compare with changes!
int num = (bp.address >> 1 ) & 0x3;
PixelShaderManager::SetColorChanged(bpmem.tevregs[num].high.type, num);
}
break;
}
// ------------------------------------------------
// On Default, we try to look for other things
// before we give up and say its an unknown opcode
// again ...
// ------------------------------------------------
default:
switch (bp.address & 0xF0)
{
// --------------
// Indirect Tev
// --------------
case BPMEM_IND_CMD:
case BPMEM_IND_CMD+1:
case BPMEM_IND_CMD+2:
case BPMEM_IND_CMD+3:
case BPMEM_IND_CMD+4:
case BPMEM_IND_CMD+5:
case BPMEM_IND_CMD+6:
case BPMEM_IND_CMD+7:
case BPMEM_IND_CMD+8:
case BPMEM_IND_CMD+9:
case BPMEM_IND_CMD+10:
case BPMEM_IND_CMD+11:
case BPMEM_IND_CMD+12:
case BPMEM_IND_CMD+13:
case BPMEM_IND_CMD+14:
case BPMEM_IND_CMD+15:
break;
// --------------------------------------------------
// Set Color/Alpha of a Tev
// BPMEM_TEV_COLOR_ENV - Dest, Shift, Clamp, Sub, Bias, Sel A, Sel B, Sel C, Sel D
// BPMEM_TEV_ALPHA_ENV - Dest, Shift, Clamp, Sub, Bias, Sel A, Sel B, Sel C, Sel D, T Swap, R Swap
// --------------------------------------------------
case BPMEM_TEV_COLOR_ENV: // Texture Environment 1
case BPMEM_TEV_ALPHA_ENV:
case BPMEM_TEV_COLOR_ENV+2: // Texture Environment 2
case BPMEM_TEV_ALPHA_ENV+2:
case BPMEM_TEV_COLOR_ENV+4: // Texture Environment 3
case BPMEM_TEV_ALPHA_ENV+4:
case BPMEM_TEV_COLOR_ENV+8: // Texture Environment 4
case BPMEM_TEV_ALPHA_ENV+8:
case BPMEM_TEV_COLOR_ENV+10: // Texture Environment 5
case BPMEM_TEV_ALPHA_ENV+10:
case BPMEM_TEV_COLOR_ENV+12: // Texture Environment 6
case BPMEM_TEV_ALPHA_ENV+12:
case BPMEM_TEV_COLOR_ENV+14: // Texture Environment 7
case BPMEM_TEV_ALPHA_ENV+14:
case BPMEM_TEV_COLOR_ENV+16: // Texture Environment 8
case BPMEM_TEV_ALPHA_ENV+16:
case BPMEM_TEV_COLOR_ENV+18: // Texture Environment 9
case BPMEM_TEV_ALPHA_ENV+18:
case BPMEM_TEV_COLOR_ENV+20: // Texture Environment 10
case BPMEM_TEV_ALPHA_ENV+20:
case BPMEM_TEV_COLOR_ENV+22: // Texture Environment 11
case BPMEM_TEV_ALPHA_ENV+22:
case BPMEM_TEV_COLOR_ENV+24: // Texture Environment 12
case BPMEM_TEV_ALPHA_ENV+24:
case BPMEM_TEV_COLOR_ENV+26: // Texture Environment 13
case BPMEM_TEV_ALPHA_ENV+26:
case BPMEM_TEV_COLOR_ENV+28: // Texture Environment 14
case BPMEM_TEV_ALPHA_ENV+28:
case BPMEM_TEV_COLOR_ENV+30: // Texture Environment 15
case BPMEM_TEV_ALPHA_ENV+30:
case BPMEM_TEV_COLOR_ENV+32: // Texture Environment 16
case BPMEM_TEV_ALPHA_ENV+32:
break;
default:
WARN_LOG(VIDEO, "Unknown Bypass opcode: address = 0x%08x value = 0x%08x", bp.address, bp.newvalue);
break;
}
}
}
}

View File

@ -1,27 +0,0 @@
// Copyright (C) 2003-2009 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// 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 SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef _BPSTRUCTS_H_
#define _BPSTRUCTS_H_
#include "BPMemory.h"
void BPInit();
void LoadBPReg(u32 value0);
void BPReload();
#endif // _BPSTRUCTS_H_

View File

@ -35,7 +35,7 @@
#include "XFMemory.h"
#include "CPMemory.h"
#include "BPMemory.h"
#include "SUMemory.h"
#include "Fifo.h"
#include "DataReader.h"
@ -267,7 +267,7 @@ static void Decode()
case GX_LOAD_BP_REG: //0x61
{
u32 cmd = DataReadU32();
LoadBPReg(cmd);
LoadSUReg(cmd);
INCSTAT(stats.thisFrame.numBPLoads);
}
break;

View File

@ -22,63 +22,63 @@
#include "Profiler.h"
#include "PixelShaderGen.h"
#include "XFMemory.h" // for texture projection mode
#include "BPMemory.h"
#include "SUMemory.h"
// Mash together all the inputs that contribute to the code of a generated pixel shader into
// a unique identifier, basically containing all the bits. Yup, it's a lot ....
void GetPixelShaderId(PIXELSHADERUID &uid, u32 s_texturemask, u32 dstAlphaEnable)
{
u32 projtexcoords = 0;
for (u32 i = 0; i < (u32)bpmem.genMode.numtevstages + 1; i++) {
if (bpmem.tevorders[i/2].getEnable(i&1)) {
int texcoord = bpmem.tevorders[i/2].getTexCoord(i&1);
for (u32 i = 0; i < (u32)sumem.genMode.numtevstages + 1; i++) {
if (sumem.tevorders[i/2].getEnable(i&1)) {
int texcoord = sumem.tevorders[i/2].getTexCoord(i&1);
if (xfregs.texcoords[texcoord].texmtxinfo.projection )
projtexcoords |= 1 << texcoord;
}
}
uid.values[0] = (u32)bpmem.genMode.numtevstages |
((u32)bpmem.genMode.numindstages << 4) |
((u32)bpmem.genMode.numtexgens << 7) |
uid.values[0] = (u32)sumem.genMode.numtevstages |
((u32)sumem.genMode.numindstages << 4) |
((u32)sumem.genMode.numtexgens << 7) |
((u32)dstAlphaEnable << 11) |
((u32)((bpmem.alphaFunc.hex >> 16) & 0xff) << 12) |
((u32)((sumem.alphaFunc.hex >> 16) & 0xff) << 12) |
(projtexcoords << 20) |
((u32)bpmem.ztex2.op << 28);
((u32)sumem.ztex2.op << 28);
uid.values[0] = (uid.values[0] & ~0x0ff00000) | (projtexcoords << 20);
// swap table
for (int i = 0; i < 8; i += 2)
((u8*)&uid.values[1])[i/2] = (bpmem.tevksel[i].hex & 0xf) | ((bpmem.tevksel[i + 1].hex & 0xf) << 4);
((u8*)&uid.values[1])[i/2] = (sumem.tevksel[i].hex & 0xf) | ((sumem.tevksel[i + 1].hex & 0xf) << 4);
uid.values[2] = s_texturemask;
uid.values[3] = (u32)bpmem.fog.c_proj_fsel.fsel |
((u32)bpmem.fog.c_proj_fsel.proj << 3);
uid.values[3] = (u32)sumem.fog.c_proj_fsel.fsel |
((u32)sumem.fog.c_proj_fsel.proj << 3);
int hdr = 4;
u32* pcurvalue = &uid.values[hdr];
for (u32 i = 0; i < (u32)bpmem.genMode.numtevstages+1; ++i) {
TevStageCombiner::ColorCombiner &cc = bpmem.combiners[i].colorC;
TevStageCombiner::AlphaCombiner &ac = bpmem.combiners[i].alphaC;
for (u32 i = 0; i < (u32)sumem.genMode.numtevstages+1; ++i) {
TevStageCombiner::ColorCombiner &cc = sumem.combiners[i].colorC;
TevStageCombiner::AlphaCombiner &ac = sumem.combiners[i].alphaC;
u32 val0 = cc.hex&0xffffff;
u32 val1 = ac.hex&0xffffff;
val0 |= bpmem.tevksel[i/2].getKC(i&1)<<24;
val1 |= bpmem.tevksel[i/2].getKA(i&1)<<24;
val0 |= sumem.tevksel[i/2].getKC(i&1)<<24;
val1 |= sumem.tevksel[i/2].getKA(i&1)<<24;
pcurvalue[0] = val0;
pcurvalue[1] = val1;
pcurvalue += 2;
}
for (u32 i = 0; i < ((u32)bpmem.genMode.numtevstages+1)/2; ++i) {
for (u32 i = 0; i < ((u32)sumem.genMode.numtevstages+1)/2; ++i) {
u32 val0, val1;
if (bpmem.tevorders[i].hex & 0x40)
val0 = bpmem.tevorders[i].hex & 0x3ff;
if (sumem.tevorders[i].hex & 0x40)
val0 = sumem.tevorders[i].hex & 0x3ff;
else
val0 = bpmem.tevorders[i].hex & 0x380;
if (bpmem.tevorders[i].hex & 0x40000)
val1 = (bpmem.tevorders[i].hex & 0x3ff000) >> 12;
val0 = sumem.tevorders[i].hex & 0x380;
if (sumem.tevorders[i].hex & 0x40000)
val1 = (sumem.tevorders[i].hex & 0x3ff000) >> 12;
else
val1 = (bpmem.tevorders[i].hex & 0x380000) >> 12;
val1 = (sumem.tevorders[i].hex & 0x380000) >> 12;
switch (i % 3) {
case 0: pcurvalue[0] = val0|(val1<<10); break;
@ -87,27 +87,27 @@ void GetPixelShaderId(PIXELSHADERUID &uid, u32 s_texturemask, u32 dstAlphaEnable
}
}
if ((bpmem.genMode.numtevstages + 1) & 1) { // odd
if ((sumem.genMode.numtevstages + 1) & 1) { // odd
u32 val0;
if (bpmem.tevorders[bpmem.genMode.numtevstages/2].hex & 0x40)
val0 = bpmem.tevorders[bpmem.genMode.numtevstages/2].hex&0x3ff;
if (sumem.tevorders[sumem.genMode.numtevstages/2].hex & 0x40)
val0 = sumem.tevorders[sumem.genMode.numtevstages/2].hex&0x3ff;
else
val0 = bpmem.tevorders[bpmem.genMode.numtevstages/2].hex & 0x380;
val0 = sumem.tevorders[sumem.genMode.numtevstages/2].hex & 0x380;
switch (bpmem.genMode.numtevstages % 3) {
switch (sumem.genMode.numtevstages % 3) {
case 0: pcurvalue[0] = val0; break;
case 1: pcurvalue[0] |= val0 << 20; break;
case 2: pcurvalue[1] |= val0 << 10; pcurvalue++; break;
}
}
if ((bpmem.genMode.numtevstages % 3) != 2)
if ((sumem.genMode.numtevstages % 3) != 2)
++pcurvalue;
uid.tevstages = (u32)(pcurvalue-&uid.values[0]-hdr);
for (u32 i = 0; i < bpmem.genMode.numindstages; ++i) {
u32 val = bpmem.tevind[i].hex & 0x1fffff; // 21 bits
for (u32 i = 0; i < sumem.genMode.numindstages; ++i) {
u32 val = sumem.tevind[i].hex & 0x1fffff; // 21 bits
switch (i%3) {
case 0: pcurvalue[0] = val; break;
case 1: pcurvalue[0] |= val << 21; pcurvalue[1] = val >> 11; ++pcurvalue; break;
@ -121,9 +121,9 @@ void GetPixelShaderId(PIXELSHADERUID &uid, u32 s_texturemask, u32 dstAlphaEnable
// old tev->pixelshader notes
//
// color for this stage (alpha, color) is given by bpmem.tevorders[0].colorchan0
// konstant for this stage (alpha, color) is given by bpmem.tevksel
// inputs are given by bpmem.combiners[0].colorC.a/b/c/d << could be current chan color
// color for this stage (alpha, color) is given by sumem.tevorders[0].colorchan0
// konstant for this stage (alpha, color) is given by sumem.tevksel
// inputs are given by sumem.combiners[0].colorC.a/b/c/d << could be current chan color
// according to GXTevColorArg table above
// output is given by .outreg
// tevtemp is set according to swapmodetables and
@ -356,13 +356,13 @@ static char text[16384];
static void BuildSwapModeTable()
{
//bpmem.tevregs[0].
//sumem.tevregs[0].
for (int i = 0; i < 4; i++)
{
swapModeTable[i][0] = swapColors[bpmem.tevksel[i*2].swap1];
swapModeTable[i][1] = swapColors[bpmem.tevksel[i*2].swap2];
swapModeTable[i][2] = swapColors[bpmem.tevksel[i*2+1].swap1];
swapModeTable[i][3] = swapColors[bpmem.tevksel[i*2+1].swap2];
swapModeTable[i][0] = swapColors[sumem.tevksel[i*2].swap1];
swapModeTable[i][1] = swapColors[sumem.tevksel[i*2].swap2];
swapModeTable[i][2] = swapColors[sumem.tevksel[i*2+1].swap1];
swapModeTable[i][3] = swapColors[sumem.tevksel[i*2+1].swap2];
swapModeTable[i][4] = 0;
}
}
@ -373,19 +373,19 @@ const char *GeneratePixelShader(u32 texture_mask, bool dstAlphaEnable, bool HLSL
DVSTARTPROFILE();
BuildSwapModeTable();
int numStages = bpmem.genMode.numtevstages + 1;
int numTexgen = bpmem.genMode.numtexgens;
int numStages = sumem.genMode.numtevstages + 1;
int numTexgen = sumem.genMode.numtexgens;
char *p = text;
WRITE(p, "//Pixel Shader for TEV stages\n");
WRITE(p, "//%i TEV stages, %i texgens, %i IND stages\n",
numStages, numTexgen, bpmem.genMode.numindstages);
numStages, numTexgen, sumem.genMode.numindstages);
int nIndirectStagesUsed = 0;
if (bpmem.genMode.numindstages > 0) {
if (sumem.genMode.numindstages > 0) {
for (int i = 0; i < numStages; ++i) {
if (bpmem.tevind[i].IsActive() && bpmem.tevind[i].bt < bpmem.genMode.numindstages) {
nIndirectStagesUsed |= 1<<bpmem.tevind[i].bt;
if (sumem.tevind[i].IsActive() && sumem.tevind[i].bt < sumem.genMode.numindstages) {
nIndirectStagesUsed |= 1<<sumem.tevind[i].bt;
}
}
}
@ -462,9 +462,9 @@ const char *GeneratePixelShader(u32 texture_mask, bool dstAlphaEnable, bool HLSL
}
// indirect texture map lookup
for(u32 i = 0; i < bpmem.genMode.numindstages; ++i) {
for(u32 i = 0; i < sumem.genMode.numindstages; ++i) {
if (nIndirectStagesUsed & (1<<i)) {
int texcoord = bpmem.tevindref.getTexCoord(i);
int texcoord = sumem.tevindref.getTexCoord(i);
if (texcoord < numTexgen) {
WRITE(p, "tempcoord=uv%d.xy * "I_INDTEXSCALE"[%d].%s;\n", texcoord, i/2, (i&1)?"zw":"xy");
@ -475,7 +475,7 @@ const char *GeneratePixelShader(u32 texture_mask, bool dstAlphaEnable, bool HLSL
char buffer[32];
sprintf(buffer, "float3 indtex%d", i);
SampleTexture(p, buffer, "tempcoord", "abg", bpmem.tevindref.getTexMap(i), texture_mask);
SampleTexture(p, buffer, "tempcoord", "abg", sumem.tevindref.getTexMap(i), texture_mask);
}
}
@ -495,17 +495,17 @@ const char *GeneratePixelShader(u32 texture_mask, bool dstAlphaEnable, bool HLSL
WRITE(p, "float zCoord = "I_ZBIAS"[1].x + (clipPos.z / clipPos.w) * "I_ZBIAS"[1].y;\n");
// use the texture input of the last texture stage (textemp), hopefully this has been read and is in correct format...
if (bpmem.ztex2.op == ZTEXTURE_ADD) {
if (sumem.ztex2.op == ZTEXTURE_ADD) {
WRITE(p, "depth = frac(dot("I_ZBIAS"[0].xyzw, textemp.xyzw) + "I_ZBIAS"[1].w + zCoord);\n");
}
else if (bpmem.ztex2.op == ZTEXTURE_REPLACE) {
else if (sumem.ztex2.op == ZTEXTURE_REPLACE) {
WRITE(p, "depth = frac(dot("I_ZBIAS"[0].xyzw, textemp.xyzw) + "I_ZBIAS"[1].w);\n");
}
else {
WRITE(p, "depth = zCoord;\n");
}
//if (bpmem.genMode.numindstages ) WRITE(p, "prev.rg = indtex0.xy;\nprev.b = 0;\n");
//if (sumem.genMode.numindstages ) WRITE(p, "prev.rg = indtex0.xy;\nprev.b = 0;\n");
if (!WriteAlphaTest(p, HLSL)) {
// alpha test will always fail, so restart the shader and just make it an empty function
@ -530,13 +530,13 @@ const char *GeneratePixelShader(u32 texture_mask, bool dstAlphaEnable, bool HLSL
static void WriteStage(char *&p, int n, u32 texture_mask)
{
char *rasswap = swapModeTable[bpmem.combiners[n].alphaC.rswap];
char *texswap = swapModeTable[bpmem.combiners[n].alphaC.tswap];
char *rasswap = swapModeTable[sumem.combiners[n].alphaC.rswap];
char *texswap = swapModeTable[sumem.combiners[n].alphaC.tswap];
int texcoord = bpmem.tevorders[n/2].getTexCoord(n&1);
bool bHasTexCoord = (u32)texcoord < bpmem.genMode.numtexgens;
bool bHasIndStage = bpmem.tevind[n].IsActive() && bpmem.tevind[n].bt < bpmem.genMode.numindstages;
int texcoord = sumem.tevorders[n/2].getTexCoord(n&1);
bool bHasTexCoord = (u32)texcoord < sumem.genMode.numtexgens;
bool bHasIndStage = sumem.tevind[n].IsActive() && sumem.tevind[n].bt < sumem.genMode.numindstages;
// HACK to handle cases where the tex gen is not enabled
if (!bHasTexCoord) {
@ -545,46 +545,46 @@ static void WriteStage(char *&p, int n, u32 texture_mask)
if (bHasIndStage) {
// perform the indirect op on the incoming regular coordinates using indtex%d as the offset coords
if (bpmem.tevind[n].bs != ITBA_OFF) {
if (sumem.tevind[n].bs != ITBA_OFF) {
// write the bump alpha
if (bpmem.tevind[n].fmt == ITF_8) {
WRITE(p, "alphabump = indtex%d.%s %s;\n", bpmem.tevind[n].bt,
tevIndAlphaSel[bpmem.tevind[n].bs], tevIndAlphaScale[bpmem.tevind[n].fmt]);
if (sumem.tevind[n].fmt == ITF_8) {
WRITE(p, "alphabump = indtex%d.%s %s;\n", sumem.tevind[n].bt,
tevIndAlphaSel[sumem.tevind[n].bs], tevIndAlphaScale[sumem.tevind[n].fmt]);
}
else {
// donkopunchstania: really bad way to do this
// cannot always use fract because fract(1.0) is 0.0 when it needs to be 1.0
// omitting fract seems to work as well
WRITE(p, "if (indtex%d.%s >= 1.0f )\n", bpmem.tevind[n].bt,
tevIndAlphaSel[bpmem.tevind[n].bs]);
WRITE(p, "if (indtex%d.%s >= 1.0f )\n", sumem.tevind[n].bt,
tevIndAlphaSel[sumem.tevind[n].bs]);
WRITE(p, " alphabump = 1.0f;\n");
WRITE(p, "else\n");
WRITE(p, " alphabump = fract ( indtex%d.%s %s );\n", bpmem.tevind[n].bt,
tevIndAlphaSel[bpmem.tevind[n].bs], tevIndAlphaScale[bpmem.tevind[n].fmt]);
WRITE(p, " alphabump = fract ( indtex%d.%s %s );\n", sumem.tevind[n].bt,
tevIndAlphaSel[sumem.tevind[n].bs], tevIndAlphaScale[sumem.tevind[n].fmt]);
}
}
// format
WRITE(p, "float3 indtevcrd%d = indtex%d * %s;\n", n, bpmem.tevind[n].bt, tevIndFmtScale[bpmem.tevind[n].fmt]);
WRITE(p, "float3 indtevcrd%d = indtex%d * %s;\n", n, sumem.tevind[n].bt, tevIndFmtScale[sumem.tevind[n].fmt]);
// bias
if (bpmem.tevind[n].bias != ITB_NONE )
WRITE(p, "indtevcrd%d.%s += %s;\n", n, tevIndBiasField[bpmem.tevind[n].bias], tevIndBiasAdd[bpmem.tevind[n].fmt]);
if (sumem.tevind[n].bias != ITB_NONE )
WRITE(p, "indtevcrd%d.%s += %s;\n", n, tevIndBiasField[sumem.tevind[n].bias], tevIndBiasAdd[sumem.tevind[n].fmt]);
// multiply by offset matrix and scale
if (bpmem.tevind[n].mid != 0) {
if (bpmem.tevind[n].mid <= 3) {
int mtxidx = 2*(bpmem.tevind[n].mid-1);
if (sumem.tevind[n].mid != 0) {
if (sumem.tevind[n].mid <= 3) {
int mtxidx = 2*(sumem.tevind[n].mid-1);
WRITE(p, "float2 indtevtrans%d = float2(dot("I_INDTEXMTX"[%d].xyz, indtevcrd%d), dot("I_INDTEXMTX"[%d].xyz, indtevcrd%d));\n",
n, mtxidx, n, mtxidx+1, n);
}
else if (bpmem.tevind[n].mid <= 7 && bHasTexCoord) { // s matrix
int mtxidx = 2*(bpmem.tevind[n].mid-5);
else if (sumem.tevind[n].mid <= 7 && bHasTexCoord) { // s matrix
int mtxidx = 2*(sumem.tevind[n].mid-5);
WRITE(p, "float2 indtevtrans%d = "I_INDTEXMTX"[%d].ww * uv%d.xy * indtevcrd%d.xx;\n", n, mtxidx, texcoord, n);
}
else if (bpmem.tevind[n].mid <= 11 && bHasTexCoord) { // t matrix
int mtxidx = 2*(bpmem.tevind[n].mid-9);
else if (sumem.tevind[n].mid <= 11 && bHasTexCoord) { // t matrix
int mtxidx = 2*(sumem.tevind[n].mid-9);
WRITE(p, "float2 indtevtrans%d = "I_INDTEXMTX"[%d].ww * uv%d.xy * indtevcrd%d.yy;\n", n, mtxidx, texcoord, n);
}
else {
@ -598,28 +598,28 @@ static void WriteStage(char *&p, int n, u32 texture_mask)
// wrapping
// wrap S
if (bpmem.tevind[n].sw == ITW_OFF) {
if (sumem.tevind[n].sw == ITW_OFF) {
WRITE(p, "wrappedcoord.x = uv%d.x;\n", texcoord);
}
else if (bpmem.tevind[n].sw == ITW_0) {
else if (sumem.tevind[n].sw == ITW_0) {
WRITE(p, "wrappedcoord.x = 0.0f;\n");
}
else {
WRITE(p, "wrappedcoord.x = fmod( uv%d.x, %s );\n", texcoord, tevIndWrapStart[bpmem.tevind[n].sw]);
WRITE(p, "wrappedcoord.x = fmod( uv%d.x, %s );\n", texcoord, tevIndWrapStart[sumem.tevind[n].sw]);
}
// wrap T
if (bpmem.tevind[n].tw == ITW_OFF) {
if (sumem.tevind[n].tw == ITW_OFF) {
WRITE(p, "wrappedcoord.y = uv%d.y;\n", texcoord);
}
else if (bpmem.tevind[n].tw == ITW_0) {
else if (sumem.tevind[n].tw == ITW_0) {
WRITE(p, "wrappedcoord.y = 0.0f;\n");
}
else {
WRITE(p, "wrappedcoord.y = fmod( uv%d.y, %s );\n", texcoord, tevIndWrapStart[bpmem.tevind[n].tw]);
WRITE(p, "wrappedcoord.y = fmod( uv%d.y, %s );\n", texcoord, tevIndWrapStart[sumem.tevind[n].tw]);
}
if (bpmem.tevind[n].fb_addprev) {
if (sumem.tevind[n].fb_addprev) {
// add previous tevcoord
WRITE(p, "tevcoord.xy += wrappedcoord + indtevtrans%d;\n", n);
}
@ -628,10 +628,10 @@ static void WriteStage(char *&p, int n, u32 texture_mask)
}
}
WRITE(p, "rastemp=%s.%s;\n",tevRasTable[bpmem.tevorders[n/2].getColorChan(n&1)],rasswap);
WRITE(p, "rastemp=%s.%s;\n",tevRasTable[sumem.tevorders[n/2].getColorChan(n&1)],rasswap);
if (bpmem.tevorders[n/2].getEnable(n&1)) {
int texmap = bpmem.tevorders[n/2].getTexMap(n&1);
if (sumem.tevorders[n/2].getEnable(n&1)) {
int texmap = sumem.tevorders[n/2].getTexMap(n&1);
if(!bHasIndStage) {
// calc tevcord
if(bHasTexCoord) {
@ -646,11 +646,11 @@ static void WriteStage(char *&p, int n, u32 texture_mask)
else
WRITE(p, "textemp=float4(1,1,1,1);\n");
int kc = bpmem.tevksel[n/2].getKC(n&1);
int ka = bpmem.tevksel[n/2].getKA(n&1);
int kc = sumem.tevksel[n/2].getKC(n&1);
int ka = sumem.tevksel[n/2].getKA(n&1);
TevStageCombiner::ColorCombiner &cc = bpmem.combiners[n].colorC;
TevStageCombiner::AlphaCombiner &ac = bpmem.combiners[n].alphaC;
TevStageCombiner::ColorCombiner &cc = sumem.combiners[n].colorC;
TevStageCombiner::AlphaCombiner &ac = sumem.combiners[n].alphaC;
bool bCKonst = cc.a == TEVCOLORARG_KONST || cc.b == TEVCOLORARG_KONST || cc.c == TEVCOLORARG_KONST || cc.d == TEVCOLORARG_KONST;
bool bAKonst = ac.a == TEVALPHAARG_KONST || ac.b == TEVALPHAARG_KONST || ac.c == TEVALPHAARG_KONST || ac.d == TEVALPHAARG_KONST;
@ -797,8 +797,8 @@ static void WriteAlphaCompare(char *&p, int num, int comp)
static bool WriteAlphaTest(char *&p, bool HLSL)
{
u32 op = bpmem.alphaFunc.logic;
u32 comp[2] = {bpmem.alphaFunc.comp0,bpmem.alphaFunc.comp1};
u32 op = sumem.alphaFunc.logic;
u32 comp[2] = {sumem.alphaFunc.comp0,sumem.alphaFunc.comp1};
//first kill all the simple cases
switch(op) {
@ -839,26 +839,26 @@ static bool WriteAlphaTest(char *&p, bool HLSL)
else {
WRITE(p, "discard( ");
}
WriteAlphaCompare(p, 0, bpmem.alphaFunc.comp0);
WriteAlphaCompare(p, 0, sumem.alphaFunc.comp0);
// negated because testing the inverse condition
switch (bpmem.alphaFunc.logic) {
switch (sumem.alphaFunc.logic) {
case 0: WRITE(p, " || "); break; // and
case 1: WRITE(p, " && "); break; // or
case 2: WRITE(p, " == "); break; // xor
case 3: WRITE(p, " != "); break; // xnor
}
WriteAlphaCompare(p, 1, bpmem.alphaFunc.comp1);
WriteAlphaCompare(p, 1, sumem.alphaFunc.comp1);
WRITE(p, ");\n");
return true;
}
static void WriteFog(char *&p)
{
bool enabled = bpmem.fog.c_proj_fsel.fsel == 0 ? false : true;
bool enabled = sumem.fog.c_proj_fsel.fsel == 0 ? false : true;
if (enabled) {
if (bpmem.fog.c_proj_fsel.proj == 0) {
if (sumem.fog.c_proj_fsel.proj == 0) {
// perspective
// ze = A/(B - Zs)
WRITE (p, " float ze = "I_FOG"[1].x / ("I_FOG"[1].y - depth);\n");
@ -871,7 +871,7 @@ static void WriteFog(char *&p)
WRITE (p, " float fog = clamp(ze - "I_FOG"[1].z, 0.0f, 1.0f);\n");
}
switch (bpmem.fog.c_proj_fsel.fsel) {
switch (sumem.fog.c_proj_fsel.fsel) {
case 2: // linear
// empty
break;

View File

@ -99,7 +99,7 @@ void PixelShaderManager::SetConstants()
{
static float ffrac = 255.0f/256.0f;
float ftemp[4];
switch (bpmem.ztex2.type)
switch (sumem.ztex2.type)
{
case 0:
// 8 bits
@ -122,7 +122,7 @@ void PixelShaderManager::SetConstants()
if (s_bZBiasChanged || s_bDepthRangeChanged)
{
//ERROR_LOG("pixel=%x,%x, bias=%x\n", bpmem.zcontrol.pixel_format, bpmem.ztex2.type, lastZBias);
//ERROR_LOG("pixel=%x,%x, bias=%x\n", sumem.zcontrol.pixel_format, sumem.ztex2.type, lastZBias);
SetPSConstant4f(C_ZBIAS+1, lastDepthRange[0] / 16777216.0f, lastDepthRange[1] / 16777216.0f, 0, (float)( (((int)lastZBias<<8)>>8))/16777216.0f);
s_bZBiasChanged = s_bDepthRangeChanged = false;
}
@ -137,8 +137,8 @@ void PixelShaderManager::SetConstants()
{
for (u32 i = 0; i < 2; ++i)
{
f[2 * i] = bpmem.texscale[0].getScaleS(i & 1);
f[2 * i + 1] = bpmem.texscale[0].getScaleT(i & 1);
f[2 * i] = sumem.texscale[0].getScaleS(i & 1);
f[2 * i + 1] = sumem.texscale[0].getScaleT(i & 1);
PRIM_LOG("tex indscale%d: %f %f\n", i, f[2 * i], f[2 * i + 1]);
}
SetPSConstant4fv(C_INDTEXSCALE, f);
@ -146,8 +146,8 @@ void PixelShaderManager::SetConstants()
if (s_nIndTexScaleChanged & 0x0c) {
for (u32 i = 2; i < 4; ++i) {
f[2 * i] = bpmem.texscale[1].getScaleS(i & 1);
f[2 * i + 1] = bpmem.texscale[1].getScaleT(i & 1);
f[2 * i] = sumem.texscale[1].getScaleS(i & 1);
f[2 * i + 1] = sumem.texscale[1].getScaleT(i & 1);
PRIM_LOG("tex indscale%d: %f %f\n", i, f[2 * i], f[2 * i + 1]);
}
SetPSConstant4fv(C_INDTEXSCALE+1, &f[4]);
@ -162,28 +162,28 @@ void PixelShaderManager::SetConstants()
{
if (s_nIndTexMtxChanged & (1 << i))
{
int scale = ((u32)bpmem.indmtx[i].col0.s0 << 0) |
((u32)bpmem.indmtx[i].col1.s1 << 2) |
((u32)bpmem.indmtx[i].col2.s2 << 4);
int scale = ((u32)sumem.indmtx[i].col0.s0 << 0) |
((u32)sumem.indmtx[i].col1.s1 << 2) |
((u32)sumem.indmtx[i].col2.s2 << 4);
float fscale = powf(2.0f, (float)(scale - 17)) / 1024.0f;
// xyz - static matrix
// TODO w - dynamic matrix scale / 256...... somehow / 4 works better
// rev 2972 - now using / 256.... verify that this works
SetPSConstant4f(C_INDTEXMTX + 2 * i,
bpmem.indmtx[i].col0.ma * fscale,
bpmem.indmtx[i].col1.mc * fscale,
bpmem.indmtx[i].col2.me * fscale,
sumem.indmtx[i].col0.ma * fscale,
sumem.indmtx[i].col1.mc * fscale,
sumem.indmtx[i].col2.me * fscale,
fscale * 4.0f);
SetPSConstant4f(C_INDTEXMTX + 2 * i + 1,
bpmem.indmtx[i].col0.mb * fscale,
bpmem.indmtx[i].col1.md * fscale,
bpmem.indmtx[i].col2.mf * fscale,
sumem.indmtx[i].col0.mb * fscale,
sumem.indmtx[i].col1.md * fscale,
sumem.indmtx[i].col2.mf * fscale,
fscale * 4.0f);
PRIM_LOG("indmtx%d: scale=%f, mat=(%f %f %f; %f %f %f)\n", i,
1024.0f*fscale, bpmem.indmtx[i].col0.ma * fscale, bpmem.indmtx[i].col1.mc * fscale, bpmem.indmtx[i].col2.me * fscale,
bpmem.indmtx[i].col0.mb * fscale, bpmem.indmtx[i].col1.md * fscale, bpmem.indmtx[i].col2.mf * fscale, fscale);
1024.0f*fscale, sumem.indmtx[i].col0.ma * fscale, sumem.indmtx[i].col1.mc * fscale, sumem.indmtx[i].col2.me * fscale,
sumem.indmtx[i].col0.mb * fscale, sumem.indmtx[i].col1.md * fscale, sumem.indmtx[i].col2.mf * fscale, fscale);
}
}
s_nIndTexMtxChanged = 0;
@ -191,15 +191,15 @@ void PixelShaderManager::SetConstants()
if (s_bFogColorChanged)
{
SetPSConstant4f(C_FOG, bpmem.fog.color.r / 255.0f, bpmem.fog.color.g / 255.0f, bpmem.fog.color.b / 255.0f, 0);
SetPSConstant4f(C_FOG, sumem.fog.color.r / 255.0f, sumem.fog.color.g / 255.0f, sumem.fog.color.b / 255.0f, 0);
s_bFogColorChanged = false;
}
if (s_bFogParamChanged)
{
float a = bpmem.fog.a.GetA() * ((float)(1 << bpmem.fog.b_shift));
float b = ((float)bpmem.fog.b_magnitude / 8388638) * ((float)(1 << (bpmem.fog.b_shift - 1)));
SetPSConstant4f(C_FOG + 1, a, b, bpmem.fog.c_proj_fsel.GetC(), 0);
float a = sumem.fog.a.GetA() * ((float)(1 << sumem.fog.b_shift));
float b = ((float)sumem.fog.b_magnitude / 8388638) * ((float)(1 << (sumem.fog.b_shift - 1)));
SetPSConstant4f(C_FOG + 1, a, b, sumem.fog.c_proj_fsel.GetC(), 0);
s_bFogParamChanged = false;
}
for (int i = 0; i < 8; i++)
@ -214,7 +214,7 @@ void PixelShaderManager::SetPSTextureDims(int texid)
float fdims[4];
if (s_texturemask & (1 << texid))
{
TCoordInfo& tc = bpmem.texcoords[texid];
TCoordInfo& tc = sumem.texcoords[texid];
fdims[0] = (float)(lastTexDims[texid] & 0xffff);
fdims[1] = (float)((lastTexDims[texid] >> 16) & 0xfff);
fdims[2] = (float)(tc.s.scale_minus_1 + 1)*lastCustomTexScale[texid][0];
@ -222,7 +222,7 @@ void PixelShaderManager::SetPSTextureDims(int texid)
}
else
{
TCoordInfo& tc = bpmem.texcoords[texid];
TCoordInfo& tc = sumem.texcoords[texid];
fdims[0] = 1.0f / (float)(lastTexDims[texid] & 0xffff);
fdims[1] = 1.0f / (float)((lastTexDims[texid] >> 16) & 0xfff);
fdims[2] = (float)(tc.s.scale_minus_1 + 1) * lastCustomTexScale[texid][0];
@ -235,10 +235,10 @@ void PixelShaderManager::SetPSTextureDims(int texid)
void PixelShaderManager::SetColorChanged(int type, int num)
{
int r = bpmem.tevregs[num].low.a;
int a = bpmem.tevregs[num].low.b;
int b = bpmem.tevregs[num].high.a;
int g = bpmem.tevregs[num].high.b;
int r = sumem.tevregs[num].low.a;
int a = sumem.tevregs[num].low.b;
int b = sumem.tevregs[num].high.a;
int g = sumem.tevregs[num].high.b;
float *pf = &lastRGBAfull[type][num][0];
pf[0] = (float)r / 255.0f;
pf[1] = (float)g / 255.0f;

View File

@ -18,7 +18,7 @@
#ifndef _PIXELSHADERMANAGER_H
#define _PIXELSHADERMANAGER_H
#include "BPMemory.h"
#include "SUMemory.h"
#include "PixelShaderGen.h"
void SetPSConstant4f(int const_number, float f1, float f2, float f3, float f4);

View File

@ -3,11 +3,11 @@
Import('env')
files = [
'BPMemory.cpp',
'SUMemory.cpp',
'CPMemory.cpp',
'XFMemory.cpp',
'XFStructs.cpp',
'BPStructs.cpp',
'SUStructs.cpp',
'memcpy_amd.cpp',
'LookUpTables.cpp',
'OpcodeDecoding.cpp',

View File

@ -29,7 +29,7 @@
#include "Statistics.h"
#include "VertexLoaderManager.h"
#include "VertexLoader.h"
#include "BPMemory.h"
#include "SUMemory.h"
#include "DataReader.h"
#include "NativeVertexWriter.h"
@ -539,7 +539,7 @@ void VertexLoader::RunVertices(int vtx_attr_group, int primitive, int count)
}
g_nativeVertexFmt = m_NativeFmt;
if (bpmem.genMode.cullmode == 3 && primitive < 5)
if (sumem.genMode.cullmode == 3 && primitive < 5)
{
// if cull mode is none, ignore triangles and quads
DataSkip(count * m_VertexSize);

View File

@ -20,7 +20,7 @@
#include "Profiler.h"
#include "NativeVertexFormat.h"
#include "BPMemory.h"
#include "SUMemory.h"
#include "VertexShaderGen.h"
// Mash together all the inputs that contribute to the code of a generated vertex shader into
@ -42,8 +42,8 @@ void GetVertexShaderId(VERTEXSHADERUID& vid, u32 components)
}
// fog
vid.values[1] |= (((u32)bpmem.fog.c_proj_fsel.fsel & 3) << 30);
vid.values[2] |= (((u32)bpmem.fog.c_proj_fsel.fsel >> 2) << 30);
vid.values[1] |= (((u32)sumem.fog.c_proj_fsel.fsel & 3) << 30);
vid.values[2] |= (((u32)sumem.fog.c_proj_fsel.fsel >> 2) << 30);
u32* pcurvalue = &vid.values[3];
for (int i = 0; i < xfregs.numTexGens; ++i) {
@ -81,8 +81,8 @@ const char *GenerateVertexShader(u32 components)
text[sizeof(text) - 1] = 0x7C; // canary
DVSTARTPROFILE();
_assert_( bpmem.genMode.numtexgens == xfregs.numTexGens);
_assert_( bpmem.genMode.numcolchans == xfregs.nNumChans);
_assert_( sumem.genMode.numtexgens == xfregs.numTexGens);
_assert_( sumem.genMode.numcolchans == xfregs.nNumChans);
u32 lightMask = 0;
if (xfregs.nNumChans > 0)
@ -432,8 +432,8 @@ const char *GenerateVertexShader(u32 components)
WRITE(p, "o.tex3.w = o.pos.w;\n");
}
// if (bpmem.fog.c_proj_fsel.fsel != 0) {
// switch (bpmem.fog.c_proj_fsel.fsel) {
// if (sumem.fog.c_proj_fsel.fsel != 0) {
// switch (sumem.fog.c_proj_fsel.fsel) {
// case 1: // linear
// break;
// case 4: // exp

View File

@ -25,7 +25,7 @@
#include "VertexShaderGen.h"
#include "VertexShaderManager.h"
#include "BPMemory.h"
#include "SUMemory.h"
#include "CPMemory.h"
#include "XFMemory.h"
#include "VideoCommon.h"

View File

@ -17,7 +17,7 @@
#include "VideoState.h"
#include "BPMemory.h"
#include "SUMemory.h"
#include "CPMemory.h"
#include "XFMemory.h"
#include "TextureDecoder.h"
@ -26,7 +26,7 @@
static void DoState(PointerWrap &p)
{
// BP Memory
p.Do(bpmem);
p.Do(sumem);
// CP Memory
p.DoArray(arraybases, 16);
p.DoArray(arraystrides, 16);

View File

@ -428,14 +428,6 @@
<Filter
Name="Sections"
>
<File
RelativePath=".\Src\BPMemory.cpp"
>
</File>
<File
RelativePath=".\Src\BPMemory.h"
>
</File>
<File
RelativePath=".\Src\CPMemory.cpp"
>
@ -444,6 +436,26 @@
RelativePath=".\Src\CPMemory.h"
>
</File>
<File
RelativePath=".\Src\SUFunctions.h"
>
</File>
<File
RelativePath=".\Src\SUMemory.cpp"
>
</File>
<File
RelativePath=".\Src\SUMemory.h"
>
</File>
<File
RelativePath=".\Src\SUStructs.cpp"
>
</File>
<File
RelativePath=".\Src\SUStructs.h"
>
</File>
<File
RelativePath=".\Src\XFMemory.cpp"
>
@ -609,18 +621,26 @@
>
</File>
</Filter>
<File
RelativePath=".\Src\BPFunctions.h"
<Filter
Name="Decoding"
>
</File>
<File
RelativePath=".\Src\BPStructs.cpp"
>
</File>
<File
RelativePath=".\Src\BPStructs.h"
>
</File>
<File
RelativePath=".\Src\OpcodeDecoding.cpp"
>
</File>
<File
RelativePath=".\Src\OpcodeDecoding.h"
>
</File>
<File
RelativePath=".\Src\TextureDecoder.cpp"
>
</File>
<File
RelativePath=".\Src\TextureDecoder.h"
>
</File>
</Filter>
<File
RelativePath=".\Src\DataReader.h"
>
@ -657,26 +677,10 @@
RelativePath=".\Src\NativeVertexWriter.h"
>
</File>
<File
RelativePath=".\Src\OpcodeDecoding.cpp"
>
</File>
<File
RelativePath=".\Src\OpcodeDecoding.h"
>
</File>
<File
RelativePath=".\Src\SConscript"
>
</File>
<File
RelativePath=".\Src\TextureDecoder.cpp"
>
</File>
<File
RelativePath=".\Src\TextureDecoder.h"
>
</File>
<File
RelativePath=".\Src\VertexLoaderManager.cpp"
>