Video backends: mass-replace "xfregs" with "xfmem".

This commit is contained in:
magumagu
2014-04-27 11:59:04 -07:00
parent 8f5342c442
commit 1357277f40
24 changed files with 179 additions and 178 deletions

View File

@ -41,7 +41,7 @@ struct LightingUidData
template<class T>
static void GenerateLightShader(T& object, LightingUidData& uid_data, int index, int litchan_index, const char* lightsColName, const char* lightsName, int coloralpha)
{
const LitChannel& chan = (litchan_index > 1) ? xfregs.alpha[litchan_index-2] : xfregs.color[litchan_index];
const LitChannel& chan = (litchan_index > 1) ? xfmem.alpha[litchan_index-2] : xfmem.color[litchan_index];
const char* swizzle = (coloralpha == 1) ? "xyz" : (coloralpha == 2) ? "w" : "xyzw";
const char* swizzle_components = (coloralpha == 1) ? "3" : (coloralpha == 2) ? "" : "4";
@ -117,14 +117,14 @@ static void GenerateLightShader(T& object, LightingUidData& uid_data, int index,
template<class T>
static void GenerateLightingShader(T& object, LightingUidData& uid_data, int components, const char* materialsName, const char* lightsColName, const char* lightsName, const char* inColorName, const char* dest)
{
for (unsigned int j = 0; j < xfregs.numChan.numColorChans; j++)
for (unsigned int j = 0; j < xfmem.numChan.numColorChans; j++)
{
const LitChannel& color = xfregs.color[j];
const LitChannel& alpha = xfregs.alpha[j];
const LitChannel& color = xfmem.color[j];
const LitChannel& alpha = xfmem.alpha[j];
object.Write("{\n");
uid_data.matsource |= xfregs.color[j].matsource << j;
uid_data.matsource |= xfmem.color[j].matsource << j;
if (color.matsource) // from vertex
{
if (components & (VB_HAS_COL0 << j))
@ -139,10 +139,10 @@ static void GenerateLightingShader(T& object, LightingUidData& uid_data, int com
object.Write("int4 mat = %s[%d];\n", materialsName, j+2);
}
uid_data.enablelighting |= xfregs.color[j].enablelighting << j;
uid_data.enablelighting |= xfmem.color[j].enablelighting << j;
if (color.enablelighting)
{
uid_data.ambsource |= xfregs.color[j].ambsource << j;
uid_data.ambsource |= xfmem.color[j].ambsource << j;
if (color.ambsource) // from vertex
{
if (components & (VB_HAS_COL0<<j) )
@ -166,7 +166,7 @@ static void GenerateLightingShader(T& object, LightingUidData& uid_data, int com
}
// check if alpha is different
uid_data.matsource |= xfregs.alpha[j].matsource << (j+2);
uid_data.matsource |= xfmem.alpha[j].matsource << (j+2);
if (alpha.matsource != color.matsource)
{
if (alpha.matsource) // from vertex
@ -183,10 +183,10 @@ static void GenerateLightingShader(T& object, LightingUidData& uid_data, int com
}
}
uid_data.enablelighting |= xfregs.alpha[j].enablelighting << (j+2);
uid_data.enablelighting |= xfmem.alpha[j].enablelighting << (j+2);
if (alpha.enablelighting)
{
uid_data.ambsource |= xfregs.alpha[j].ambsource << (j+2);
uid_data.ambsource |= xfmem.alpha[j].ambsource << (j+2);
if (alpha.ambsource) // from vertex
{
if (components & (VB_HAS_COL0<<j) )

View File

@ -294,7 +294,7 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
// compute window position if needed because binding semantic WPOS is not widely supported
// Let's set up attributes
for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i)
for (unsigned int i = 0; i < xfmem.numTexGen.numTexGens; ++i)
{
out.Write("centroid in float3 uv%d;\n", i);
}
@ -370,8 +370,8 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
{
out.Write("\tint2 fixpoint_uv%d = iround(", i);
// optional perspective divides
uid_data.texMtxInfo_n_projection |= xfregs.texMtxInfo[i].projection << i;
if (xfregs.texMtxInfo[i].projection == XF_TEXPROJ_STQ)
uid_data.texMtxInfo_n_projection |= xfmem.texMtxInfo[i].projection << i;
if (xfmem.texMtxInfo[i].projection == XF_TEXPROJ_STQ)
{
out.Write("(uv%d.z == 0.0 ? uv%d.xy : uv%d.xy / uv%d.z)", i, i, i, i);
}

View File

@ -77,7 +77,7 @@ void PixelShaderManager::SetConstants()
//bpmem.fogRange.Base.Center : center of the viewport in x axis. observation: bpmem.fogRange.Base.Center = realcenter + 342;
int center = ((u32)bpmem.fogRange.Base.Center) - 342;
// normalize center to make calculations easy
float ScreenSpaceCenter = center / (2.0f * xfregs.viewport.wd);
float ScreenSpaceCenter = center / (2.0f * xfmem.viewport.wd);
ScreenSpaceCenter = (ScreenSpaceCenter * 2.0f) - 1.0f;
//bpmem.fogRange.K seems to be a table of precalculated coefficients for the adjust factor
//observations: bpmem.fogRange.K[0].LO appears to be the lowest value and bpmem.fogRange.K[4].HI the largest
@ -86,7 +86,7 @@ void PixelShaderManager::SetConstants()
// so to simplify I use the hi coefficient as K in the shader taking 256 as the scale
// TODO: Shouldn't this be EFBToScaledXf?
constants.fogf[0][0] = ScreenSpaceCenter;
constants.fogf[0][1] = (float)Renderer::EFBToScaledX((int)(2.0f * xfregs.viewport.wd));
constants.fogf[0][1] = (float)Renderer::EFBToScaledX((int)(2.0f * xfmem.viewport.wd));
constants.fogf[0][2] = bpmem.fogRange.K[4].HI / 256.0f;
}
else
@ -108,7 +108,7 @@ void PixelShaderManager::SetConstants()
// lights don't have a 1 to 1 mapping, the color component needs to be converted to 4 floats
int istart = nLightsChanged[0] / 0x10;
int iend = (nLightsChanged[1] + 15) / 0x10;
const float* xfmemptr = (const float*)&xfregs.lights[0x10 * istart];
const float* xfmemptr = (const float*)&xfmem.lights[0x10 * istart];
for (int i = istart; i < iend; ++i)
{
@ -141,8 +141,8 @@ void PixelShaderManager::SetConstants()
if (s_bViewPortChanged)
{
constants.zbias[1][0] = xfregs.viewport.farZ;
constants.zbias[1][1] = xfregs.viewport.zRange;
constants.zbias[1][0] = xfmem.viewport.farZ;
constants.zbias[1][1] = xfmem.viewport.zRange;
dirty = true;
s_bViewPortChanged = false;
}

View File

@ -504,13 +504,13 @@ void Renderer::RecordVideoMemory()
{
u32 *bpMem = (u32*)&bpmem;
u32 cpMem[256];
u32 *xfMem = (u32*)&xfregs;
u32 *xfRegs = (u32*)&xfregs + 0x1000;
u32 *xfMem = (u32*)&xfmem;
u32 *xfRegs = (u32*)&xfmem + 0x1000;
memset(cpMem, 0, 256 * 4);
FillCPMemoryArray(cpMem);
FifoRecorder::GetInstance().SetVideoMemory(bpMem, cpMem, xfMem, xfRegs, sizeof(XFRegisters) / 4);
FifoRecorder::GetInstance().SetVideoMemory(bpMem, cpMem, xfMem, xfRegs, sizeof(XFMemory) / 4);
}
void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& rc, float Gamma)

View File

@ -217,8 +217,8 @@ void LOADERDECL UpdateBoundingBox()
// We need to get the raw projection values for the bounding box calculation
// to work properly. That means, no projection hacks!
const float * const orig_point = s_bbox_vertex_buffer;
const float * const world_matrix = (float*)xfregs.posMatrices + s_curposmtx * 4;
const float * const proj_matrix = xfregs.projection.rawProjection;
const float * const world_matrix = (float*)xfmem.posMatrices + s_curposmtx * 4;
const float * const proj_matrix = xfmem.projection.rawProjection;
// Transform by world matrix
// Only calculate what we need, discard the rest
@ -226,7 +226,7 @@ void LOADERDECL UpdateBoundingBox()
transformed[1] = orig_point[0] * world_matrix[4] + orig_point[1] * world_matrix[5] + orig_point[2] * world_matrix[6] + world_matrix[7];
// Transform by projection matrix
switch (xfregs.projection.type)
switch (xfmem.projection.type)
{
// Perspective projection, we must divide by w
case GX_PERSPECTIVE:
@ -246,13 +246,13 @@ void LOADERDECL UpdateBoundingBox()
break;
default:
ERROR_LOG(VIDEO, "Unknown projection type: %d", xfregs.projection.type);
ERROR_LOG(VIDEO, "Unknown projection type: %d", xfmem.projection.type);
screenPoint[0] = screenPoint[1] = screenPoint[2] = 1;
}
// Convert to screen space and add the point to the list - round like the real hardware
s_bbox_points[s_bbox_currPoint].x = (((s32) (0.5f + (16.0f * (screenPoint[0] * xfregs.viewport.wd + (xfregs.viewport.xOrig - 342.0f))))) + 3) >> 4;
s_bbox_points[s_bbox_currPoint].y = (((s32) (0.5f + (16.0f * (screenPoint[1] * xfregs.viewport.ht + (xfregs.viewport.yOrig - 342.0f))))) + 3) >> 4;
s_bbox_points[s_bbox_currPoint].x = (((s32) (0.5f + (16.0f * (screenPoint[0] * xfmem.viewport.wd + (xfmem.viewport.xOrig - 342.0f))))) + 3) >> 4;
s_bbox_points[s_bbox_currPoint].y = (((s32) (0.5f + (16.0f * (screenPoint[1] * xfmem.viewport.ht + (xfmem.viewport.yOrig - 342.0f))))) + 3) >> 4;
s_bbox_points[s_bbox_currPoint].z = screenPoint[2];
// Update point list for primitive

View File

@ -150,27 +150,27 @@ void VertexManager::Flush()
VideoFifo_CheckEFBAccess();
#if defined(_DEBUG) || defined(DEBUGFAST)
PRIM_LOG("frame%d:\n texgen=%d, numchan=%d, dualtex=%d, ztex=%d, cole=%d, alpe=%d, ze=%d", g_ActiveConfig.iSaveTargetId, xfregs.numTexGen.numTexGens,
xfregs.numChan.numColorChans, xfregs.dualTexTrans.enabled, bpmem.ztex2.op,
PRIM_LOG("frame%d:\n texgen=%d, numchan=%d, dualtex=%d, ztex=%d, cole=%d, alpe=%d, ze=%d", g_ActiveConfig.iSaveTargetId, xfmem.numTexGen.numTexGens,
xfmem.numChan.numColorChans, xfmem.dualTexTrans.enabled, bpmem.ztex2.op,
bpmem.blendmode.colorupdate, bpmem.blendmode.alphaupdate, bpmem.zmode.updateenable);
for (unsigned int i = 0; i < xfregs.numChan.numColorChans; ++i)
for (unsigned int i = 0; i < xfmem.numChan.numColorChans; ++i)
{
LitChannel* ch = &xfregs.color[i];
LitChannel* ch = &xfmem.color[i];
PRIM_LOG("colchan%d: matsrc=%d, light=0x%x, ambsrc=%d, diffunc=%d, attfunc=%d", i, ch->matsource, ch->GetFullLightMask(), ch->ambsource, ch->diffusefunc, ch->attnfunc);
ch = &xfregs.alpha[i];
ch = &xfmem.alpha[i];
PRIM_LOG("alpchan%d: matsrc=%d, light=0x%x, ambsrc=%d, diffunc=%d, attfunc=%d", i, ch->matsource, ch->GetFullLightMask(), ch->ambsource, ch->diffusefunc, ch->attnfunc);
}
for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i)
for (unsigned int i = 0; i < xfmem.numTexGen.numTexGens; ++i)
{
TexMtxInfo tinfo = xfregs.texMtxInfo[i];
TexMtxInfo tinfo = xfmem.texMtxInfo[i];
if (tinfo.texgentype != XF_TEXGEN_EMBOSS_MAP) tinfo.hex &= 0x7ff;
if (tinfo.texgentype != XF_TEXGEN_REGULAR) tinfo.projection = 0;
PRIM_LOG("txgen%d: proj=%d, input=%d, gentype=%d, srcrow=%d, embsrc=%d, emblght=%d, postmtx=%d, postnorm=%d",
i, tinfo.projection, tinfo.inputform, tinfo.texgentype, tinfo.sourcerow, tinfo.embosssourceshift, tinfo.embosslightshift,
xfregs.postMtxInfo[i].index, xfregs.postMtxInfo[i].normalize);
xfmem.postMtxInfo[i].index, xfmem.postMtxInfo[i].normalize);
}
PRIM_LOG("pixel: tev=%d, ind=%d, texgen=%d, dstalpha=%d, alphatest=0x%x", bpmem.genMode.numtevstages+1, bpmem.genMode.numindstages,

View File

@ -44,13 +44,13 @@ static inline void GenerateVSOutputStruct(T& object, API_TYPE api_type)
DefineVSOutputStructMember(object, api_type, "float4", "colors_", 0, "COLOR", 0);
DefineVSOutputStructMember(object, api_type, "float4", "colors_", 1, "COLOR", 1);
for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i)
for (unsigned int i = 0; i < xfmem.numTexGen.numTexGens; ++i)
DefineVSOutputStructMember(object, api_type, "float3", "tex", i, "TEXCOORD", i);
DefineVSOutputStructMember(object, api_type, "float4", "clipPos", -1, "TEXCOORD", xfregs.numTexGen.numTexGens);
DefineVSOutputStructMember(object, api_type, "float4", "clipPos", -1, "TEXCOORD", xfmem.numTexGen.numTexGens);
if (g_ActiveConfig.bEnablePixelLighting)
DefineVSOutputStructMember(object, api_type, "float4", "Normal", -1, "TEXCOORD", xfregs.numTexGen.numTexGens + 1);
DefineVSOutputStructMember(object, api_type, "float4", "Normal", -1, "TEXCOORD", xfmem.numTexGen.numTexGens + 1);
object.Write("};\n");
}
@ -78,8 +78,8 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
if (is_writing_shadercode)
text[sizeof(text) - 1] = 0x7C; // canary
_assert_(bpmem.genMode.numtexgens == xfregs.numTexGen.numTexGens);
_assert_(bpmem.genMode.numcolchans == xfregs.numChan.numColorChans);
_assert_(bpmem.genMode.numtexgens == xfmem.numTexGen.numTexGens);
_assert_(bpmem.genMode.numcolchans == xfmem.numChan.numColorChans);
// uniforms
if (api_type == API_OPENGL)
@ -101,7 +101,7 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
GenerateVSOutputStruct(out, api_type);
uid_data.numTexGens = xfregs.numTexGen.numTexGens;
uid_data.numTexGens = xfmem.numTexGen.numTexGens;
uid_data.components = components;
uid_data.pixel_lighting = g_ActiveConfig.bEnablePixelLighting;
@ -132,7 +132,7 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
// Let's set up attributes
for (size_t i = 0; i < 8; ++i)
{
if (i < xfregs.numTexGen.numTexGens)
if (i < xfmem.numTexGen.numTexGens)
{
out.Write("centroid out float3 uv%d;\n", i);
}
@ -220,8 +220,8 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
"float3 ldir, h;\n"
"float dist, dist2, attn;\n");
uid_data.numColorChans = xfregs.numChan.numColorChans;
if (xfregs.numChan.numColorChans == 0)
uid_data.numColorChans = xfmem.numChan.numColorChans;
if (xfmem.numChan.numColorChans == 0)
{
if (components & VB_HAS_COL0)
out.Write("o.colors_0 = color0;\n");
@ -231,7 +231,7 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
GenerateLightingShader<T>(out, uid_data.lighting, components, I_MATERIALS, I_LIGHT_COLORS, I_LIGHTS, "color", "o.colors_");
if (xfregs.numChan.numColorChans < 2)
if (xfmem.numChan.numColorChans < 2)
{
if (components & VB_HAS_COL1)
out.Write("o.colors_1 = color1;\n");
@ -244,18 +244,18 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
/*bool texGenSpecialCase =
((g_VtxDesc.Hex & 0x60600L) == g_VtxDesc.Hex) && // only pos and tex coord 0
(g_VtxDesc.Tex0Coord != NOT_PRESENT) &&
(xfregs.texcoords[0].texmtxinfo.inputform == XF_TEXINPUT_AB11);
(xfmem.texcoords[0].texmtxinfo.inputform == XF_TEXINPUT_AB11);
*/
// transform texcoords
out.Write("float4 coord = float4(0.0, 0.0, 1.0, 1.0);\n");
for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i)
for (unsigned int i = 0; i < xfmem.numTexGen.numTexGens; ++i)
{
TexMtxInfo& texinfo = xfregs.texMtxInfo[i];
TexMtxInfo& texinfo = xfmem.texMtxInfo[i];
out.Write("{\n");
out.Write("coord = float4(0.0, 0.0, 1.0, 1.0);\n");
uid_data.texMtxInfo[i].sourcerow = xfregs.texMtxInfo[i].sourcerow;
uid_data.texMtxInfo[i].sourcerow = xfmem.texMtxInfo[i].sourcerow;
switch (texinfo.sourcerow)
{
case XF_SRCGEOM_INROW:
@ -294,7 +294,7 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
}
// first transformation
uid_data.texMtxInfo[i].texgentype = xfregs.texMtxInfo[i].texgentype;
uid_data.texMtxInfo[i].texgentype = xfmem.texMtxInfo[i].texgentype;
switch (texinfo.texgentype)
{
case XF_TEXGEN_EMBOSS_MAP: // calculate tex coords into bump map
@ -302,15 +302,15 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
if (components & (VB_HAS_NRM1|VB_HAS_NRM2))
{
// transform the light dir into tangent space
uid_data.texMtxInfo[i].embosslightshift = xfregs.texMtxInfo[i].embosslightshift;
uid_data.texMtxInfo[i].embosssourceshift = xfregs.texMtxInfo[i].embosssourceshift;
uid_data.texMtxInfo[i].embosslightshift = xfmem.texMtxInfo[i].embosslightshift;
uid_data.texMtxInfo[i].embosssourceshift = xfmem.texMtxInfo[i].embosssourceshift;
out.Write("ldir = normalize(" LIGHT_POS".xyz - pos.xyz);\n", LIGHT_POS_PARAMS(I_LIGHTS, texinfo.embosslightshift));
out.Write("o.tex%d.xyz = o.tex%d.xyz + float3(dot(ldir, _norm1), dot(ldir, _norm2), 0.0);\n", i, texinfo.embosssourceshift);
}
else
{
_assert_(0); // should have normals
uid_data.texMtxInfo[i].embosssourceshift = xfregs.texMtxInfo[i].embosssourceshift;
uid_data.texMtxInfo[i].embosssourceshift = xfmem.texMtxInfo[i].embosssourceshift;
out.Write("o.tex%d.xyz = o.tex%d.xyz;\n", i, texinfo.embosssourceshift);
}
@ -325,7 +325,7 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
break;
case XF_TEXGEN_REGULAR:
default:
uid_data.texMtxInfo_n_projection |= xfregs.texMtxInfo[i].projection << i;
uid_data.texMtxInfo_n_projection |= xfmem.texMtxInfo[i].projection << i;
if (components & (VB_HAS_TEXMTXIDX0<<i))
{
out.Write("int tmp = int(tex%d.z);\n", i);
@ -344,13 +344,13 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
break;
}
uid_data.dualTexTrans_enabled = xfregs.dualTexTrans.enabled;
uid_data.dualTexTrans_enabled = xfmem.dualTexTrans.enabled;
// CHECKME: does this only work for regular tex gen types?
if (xfregs.dualTexTrans.enabled && texinfo.texgentype == XF_TEXGEN_REGULAR)
if (xfmem.dualTexTrans.enabled && texinfo.texgentype == XF_TEXGEN_REGULAR)
{
const PostMtxInfo& postInfo = xfregs.postMtxInfo[i];
const PostMtxInfo& postInfo = xfmem.postMtxInfo[i];
uid_data.postMtxInfo[i].index = xfregs.postMtxInfo[i].index;
uid_data.postMtxInfo[i].index = xfmem.postMtxInfo[i].index;
int postidx = postInfo.index;
out.Write("float4 P0 = " I_POSTTRANSFORMMATRICES"[%d];\n"
"float4 P1 = " I_POSTTRANSFORMMATRICES"[%d];\n"
@ -368,7 +368,7 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
}
else
{
uid_data.postMtxInfo[i].normalize = xfregs.postMtxInfo[i].normalize;
uid_data.postMtxInfo[i].normalize = xfmem.postMtxInfo[i].normalize;
if (postInfo.normalize)
out.Write("o.tex%d.xyz = normalize(o.tex%d.xyz);\n", i, i);
@ -432,9 +432,10 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
// Will look better when we bind uniforms in GLSL 1.3
// clipPos/w needs to be done in pixel shader, not here
for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i)
for (unsigned int i = 0; i < xfmem.numTexGen.numTexGens; ++i)
out.Write(" uv%d.xyz = o.tex%d;\n", i, i);
out.Write(" clipPos = o.clipPos;\n");
if (g_ActiveConfig.bEnablePixelLighting)
out.Write(" Normal = o.Normal;\n");

View File

@ -131,10 +131,10 @@ static void ViewportCorrectionMatrix(Matrix44& result)
// TODO: ceil, floor or just cast to int?
// TODO: Directly use the floats instead of rounding them?
float intendedX = xfregs.viewport.xOrig - xfregs.viewport.wd - scissorXOff;
float intendedY = xfregs.viewport.yOrig + xfregs.viewport.ht - scissorYOff;
float intendedWd = 2.0f * xfregs.viewport.wd;
float intendedHt = -2.0f * xfregs.viewport.ht;
float intendedX = xfmem.viewport.xOrig - xfmem.viewport.wd - scissorXOff;
float intendedY = xfmem.viewport.yOrig + xfmem.viewport.ht - scissorYOff;
float intendedWd = 2.0f * xfmem.viewport.wd;
float intendedHt = -2.0f * xfmem.viewport.ht;
if (intendedWd < 0.f)
{
@ -167,7 +167,7 @@ void VertexShaderManager::Init()
{
Dirty();
memset(&xfregs, 0, sizeof(xfregs));
memset(&xfmem, 0, sizeof(xfmem));
memset(&constants, 0 , sizeof(constants));
ResetView();
@ -215,7 +215,7 @@ void VertexShaderManager::SetConstants()
{
int startn = nTransformMatricesChanged[0] / 4;
int endn = (nTransformMatricesChanged[1] + 3) / 4;
memcpy(constants.transformmatrices[startn], &xfregs.posMatrices[startn * 4], (endn - startn) * 16);
memcpy(constants.transformmatrices[startn], &xfmem.posMatrices[startn * 4], (endn - startn) * 16);
dirty = true;
nTransformMatricesChanged[0] = nTransformMatricesChanged[1] = -1;
}
@ -226,7 +226,7 @@ void VertexShaderManager::SetConstants()
int endn = (nNormalMatricesChanged[1] + 2) / 3;
for (int i=startn; i<endn; i++)
{
memcpy(constants.normalmatrices[i], &xfregs.normalMatrices[3*i], 12);
memcpy(constants.normalmatrices[i], &xfmem.normalMatrices[3*i], 12);
}
dirty = true;
nNormalMatricesChanged[0] = nNormalMatricesChanged[1] = -1;
@ -236,7 +236,7 @@ void VertexShaderManager::SetConstants()
{
int startn = nPostTransformMatricesChanged[0] / 4;
int endn = (nPostTransformMatricesChanged[1] + 3 ) / 4;
memcpy(constants.posttransformmatrices[startn], &xfregs.postMatrices[startn * 4], (endn - startn) * 16);
memcpy(constants.posttransformmatrices[startn], &xfmem.postMatrices[startn * 4], (endn - startn) * 16);
dirty = true;
nPostTransformMatricesChanged[0] = nPostTransformMatricesChanged[1] = -1;
}
@ -247,7 +247,7 @@ void VertexShaderManager::SetConstants()
// lights don't have a 1 to 1 mapping, the color component needs to be converted to 4 floats
int istart = nLightsChanged[0] / 0x10;
int iend = (nLightsChanged[1] + 15) / 0x10;
const float* xfmemptr = (const float*)&xfregs.lights[0x10 * istart];
const float* xfmemptr = (const float*)&xfmem.lights[0x10 * istart];
for (int i = istart; i < iend; ++i)
{
@ -285,7 +285,7 @@ void VertexShaderManager::SetConstants()
{
if (nMaterialsChanged & (1 << i))
{
u32 data = xfregs.ambColor[i];
u32 data = xfmem.ambColor[i];
constants.materials[i][0] = (data >> 24) & 0xFF;
constants.materials[i][1] = (data >> 16) & 0xFF;
constants.materials[i][2] = (data >> 8) & 0xFF;
@ -297,7 +297,7 @@ void VertexShaderManager::SetConstants()
{
if (nMaterialsChanged & (1 << (i + 2)))
{
u32 data = xfregs.matColor[i];
u32 data = xfmem.matColor[i];
constants.materials[i+2][0] = (data >> 24) & 0xFF;
constants.materials[i+2][1] = (data >> 16) & 0xFF;
constants.materials[i+2][2] = (data >> 8) & 0xFF;
@ -313,8 +313,8 @@ void VertexShaderManager::SetConstants()
{
bPosNormalMatrixChanged = false;
const float *pos = (const float *)xfregs.posMatrices + MatrixIndexA.PosNormalMtxIdx * 4;
const float *norm = (const float *)xfregs.normalMatrices + 3 * (MatrixIndexA.PosNormalMtxIdx & 31);
const float *pos = (const float *)xfmem.posMatrices + MatrixIndexA.PosNormalMtxIdx * 4;
const float *norm = (const float *)xfmem.normalMatrices + 3 * (MatrixIndexA.PosNormalMtxIdx & 31);
memcpy(constants.posnormalmatrix, pos, 3*16);
memcpy(constants.posnormalmatrix[3], norm, 12);
@ -328,10 +328,10 @@ void VertexShaderManager::SetConstants()
bTexMatricesChanged[0] = false;
const float *fptrs[] =
{
(const float *)&xfregs.posMatrices[MatrixIndexA.Tex0MtxIdx * 4],
(const float *)&xfregs.posMatrices[MatrixIndexA.Tex1MtxIdx * 4],
(const float *)&xfregs.posMatrices[MatrixIndexA.Tex2MtxIdx * 4],
(const float *)&xfregs.posMatrices[MatrixIndexA.Tex3MtxIdx * 4]
(const float *)&xfmem.posMatrices[MatrixIndexA.Tex0MtxIdx * 4],
(const float *)&xfmem.posMatrices[MatrixIndexA.Tex1MtxIdx * 4],
(const float *)&xfmem.posMatrices[MatrixIndexA.Tex2MtxIdx * 4],
(const float *)&xfmem.posMatrices[MatrixIndexA.Tex3MtxIdx * 4]
};
for (int i = 0; i < 4; ++i)
@ -345,10 +345,10 @@ void VertexShaderManager::SetConstants()
{
bTexMatricesChanged[1] = false;
const float *fptrs[] = {
(const float *)&xfregs.posMatrices[MatrixIndexB.Tex4MtxIdx * 4],
(const float *)&xfregs.posMatrices[MatrixIndexB.Tex5MtxIdx * 4],
(const float *)&xfregs.posMatrices[MatrixIndexB.Tex6MtxIdx * 4],
(const float *)&xfregs.posMatrices[MatrixIndexB.Tex7MtxIdx * 4]
(const float *)&xfmem.posMatrices[MatrixIndexB.Tex4MtxIdx * 4],
(const float *)&xfmem.posMatrices[MatrixIndexB.Tex5MtxIdx * 4],
(const float *)&xfmem.posMatrices[MatrixIndexB.Tex6MtxIdx * 4],
(const float *)&xfmem.posMatrices[MatrixIndexB.Tex7MtxIdx * 4]
};
for (int i = 0; i < 4; ++i)
@ -361,8 +361,8 @@ void VertexShaderManager::SetConstants()
if (bViewportChanged)
{
bViewportChanged = false;
constants.depthparams[0] = xfregs.viewport.farZ / 16777216.0f;
constants.depthparams[1] = xfregs.viewport.zRange / 16777216.0f;
constants.depthparams[0] = xfmem.viewport.farZ / 16777216.0f;
constants.depthparams[1] = xfmem.viewport.zRange / 16777216.0f;
// The console GPU places the pixel center at 7/12 unless antialiasing
// is enabled, while D3D and OpenGL place it at 0.5. See the comment
@ -370,8 +370,8 @@ void VertexShaderManager::SetConstants()
// NOTE: If we ever emulate antialiasing, the sample locations set by
// BP registers 0x01-0x04 need to be considered here.
const float pixel_center_correction = 7.0f / 12.0f - 0.5f;
const float pixel_size_x = 2.f / Renderer::EFBToScaledXf(2.f * xfregs.viewport.wd);
const float pixel_size_y = 2.f / Renderer::EFBToScaledXf(2.f * xfregs.viewport.ht);
const float pixel_size_x = 2.f / Renderer::EFBToScaledXf(2.f * xfmem.viewport.wd);
const float pixel_size_y = 2.f / Renderer::EFBToScaledXf(2.f * xfmem.viewport.ht);
constants.depthparams[2] = pixel_center_correction * pixel_size_x;
constants.depthparams[3] = pixel_center_correction * pixel_size_y;
dirty = true;
@ -390,9 +390,9 @@ void VertexShaderManager::SetConstants()
{
bProjectionChanged = false;
float *rawProjection = xfregs.projection.rawProjection;
float *rawProjection = xfmem.projection.rawProjection;
switch (xfregs.projection.type)
switch (xfmem.projection.type)
{
case GX_PERSPECTIVE:
@ -486,12 +486,12 @@ void VertexShaderManager::SetConstants()
break;
default:
ERROR_LOG(VIDEO, "Unknown projection type: %d", xfregs.projection.type);
ERROR_LOG(VIDEO, "Unknown projection type: %d", xfmem.projection.type);
}
PRIM_LOG("Projection: %f %f %f %f %f %f\n", rawProjection[0], rawProjection[1], rawProjection[2], rawProjection[3], rawProjection[4], rawProjection[5]);
if ((g_ActiveConfig.bFreeLook || g_ActiveConfig.bAnaglyphStereo ) && xfregs.projection.type == GX_PERSPECTIVE)
if ((g_ActiveConfig.bFreeLook || g_ActiveConfig.bAnaglyphStereo ) && xfmem.projection.type == GX_PERSPECTIVE)
{
Matrix44 mtxA;
Matrix44 mtxB;

View File

@ -30,7 +30,7 @@ static void DoState(PointerWrap &p)
p.DoMarker("CP Memory");
// XF Memory
p.Do(xfregs);
p.Do(xfmem);
p.DoMarker("XF Memory");
// Texture decoder

View File

@ -5,4 +5,4 @@
#include "VideoCommon/XFMemory.h"
// STATE_TO_SAVE
XFRegisters xfregs;
XFMemory xfmem;

View File

@ -234,7 +234,7 @@ struct Projection
u32 type; // only GX_PERSPECTIVE or GX_ORTHOGRAPHIC are allowed
};
struct XFRegisters
struct XFMemory
{
u32 posMatrices[256]; // 0x0000 - 0x00ff
u32 unk0[768]; // 0x0100 - 0x03ff
@ -275,7 +275,7 @@ struct XFRegisters
};
extern XFRegisters xfregs;
extern XFMemory xfmem;
void LoadXFReg(u32 transferSize, u32 address, u32 *pData);
void LoadIndexedXF(u32 val, int array);

View File

@ -49,7 +49,7 @@ void XFRegWritten(int transferSize, u32 baseAddress, u32 *pData)
break;
case XFMEM_SETNUMCHAN:
if (xfregs.numChan.numColorChans != (newValue & 3))
if (xfmem.numChan.numColorChans != (newValue & 3))
VertexManager::Flush();
break;
@ -57,7 +57,7 @@ void XFRegWritten(int transferSize, u32 baseAddress, u32 *pData)
case XFMEM_SETCHAN1_AMBCOLOR:
{
u8 chan = address - XFMEM_SETCHAN0_AMBCOLOR;
if (xfregs.ambColor[chan] != newValue)
if (xfmem.ambColor[chan] != newValue)
{
VertexManager::Flush();
VertexShaderManager::SetMaterialColorChanged(chan, newValue);
@ -70,7 +70,7 @@ void XFRegWritten(int transferSize, u32 baseAddress, u32 *pData)
case XFMEM_SETCHAN1_MATCOLOR:
{
u8 chan = address - XFMEM_SETCHAN0_MATCOLOR;
if (xfregs.matColor[chan] != newValue)
if (xfmem.matColor[chan] != newValue)
{
VertexManager::Flush();
VertexShaderManager::SetMaterialColorChanged(chan + 2, newValue);
@ -83,12 +83,12 @@ void XFRegWritten(int transferSize, u32 baseAddress, u32 *pData)
case XFMEM_SETCHAN1_COLOR:
case XFMEM_SETCHAN0_ALPHA: // Channel Alpha
case XFMEM_SETCHAN1_ALPHA:
if (((u32*)&xfregs)[address] != (newValue & 0x7fff))
if (((u32*)&xfmem)[address] != (newValue & 0x7fff))
VertexManager::Flush();
break;
case XFMEM_DUALTEX:
if (xfregs.dualTexTrans.enabled != (newValue & 1))
if (xfmem.dualTexTrans.enabled != (newValue & 1))
VertexManager::Flush();
break;
@ -129,7 +129,7 @@ void XFRegWritten(int transferSize, u32 baseAddress, u32 *pData)
break;
case XFMEM_SETNUMTEXGENS: // GXSetNumTexGens
if (xfregs.numTexGen.numTexGens != (newValue & 15))
if (xfmem.numTexGen.numTexGens != (newValue & 15))
VertexManager::Flush();
break;
@ -164,7 +164,7 @@ void XFRegWritten(int transferSize, u32 baseAddress, u32 *pData)
// --------------
// Maybe these are for Normals?
case 0x1048: //xfregs.texcoords[0].nrmmtxinfo.hex = data; break; ??
case 0x1048: //xfmem.texcoords[0].nrmmtxinfo.hex = data; break; ??
case 0x1049:
case 0x104a:
case 0x104b:
@ -228,7 +228,7 @@ void LoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData)
}
XFMemWritten(xfMemTransferSize, xfMemBase);
memcpy_gc((u32*)(&xfregs) + xfMemBase, pData, xfMemTransferSize * 4);
memcpy_gc((u32*)(&xfmem) + xfMemBase, pData, xfMemTransferSize * 4);
pData += xfMemTransferSize;
}
@ -237,7 +237,7 @@ void LoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData)
if (transferSize > 0)
{
XFRegWritten(transferSize, baseAddress, pData);
memcpy_gc((u32*)(&xfregs) + baseAddress, pData, transferSize * 4);
memcpy_gc((u32*)(&xfmem) + baseAddress, pData, transferSize * 4);
}
}
@ -249,7 +249,7 @@ void LoadIndexedXF(u32 val, int refarray)
int size = ((val >> 12) & 0xF) + 1;
//load stuff from array to address in xf mem
u32* currData = (u32*)(&xfregs) + address;
u32* currData = (u32*)(&xfmem) + address;
u32* newData = (u32*)Memory::GetPointer(arraybases[refarray] + arraystrides[refarray] * index);
bool changed = false;
for (int i = 0; i < size; ++i)