From 8f5342c442c8e78784b4ea7002250781ba768767 Mon Sep 17 00:00:00 2001 From: magumagu Date: Wed, 16 Apr 2014 18:10:33 -0700 Subject: [PATCH] Video backend: merge global var xfmem into xfregs. There isn't really any reason to keep them separate. --- Source/Core/VideoBackends/Software/SWmain.cpp | 1 - .../VideoBackends/Software/TransformUnit.cpp | 14 ++++---- .../VideoBackends/Software/XFMemLoader.cpp | 31 ++--------------- .../Core/VideoCommon/PixelShaderManager.cpp | 2 +- Source/Core/VideoCommon/RenderBase.cpp | 4 +-- Source/Core/VideoCommon/VertexLoader.cpp | 2 +- .../Core/VideoCommon/VertexShaderManager.cpp | 33 +++++++++---------- Source/Core/VideoCommon/VideoState.cpp | 1 - Source/Core/VideoCommon/XFMemory.cpp | 1 - Source/Core/VideoCommon/XFMemory.h | 7 +--- Source/Core/VideoCommon/XFStructs.cpp | 8 ++--- 11 files changed, 34 insertions(+), 70 deletions(-) diff --git a/Source/Core/VideoBackends/Software/SWmain.cpp b/Source/Core/VideoBackends/Software/SWmain.cpp index 16ce1d059c..fbbef11704 100644 --- a/Source/Core/VideoBackends/Software/SWmain.cpp +++ b/Source/Core/VideoBackends/Software/SWmain.cpp @@ -115,7 +115,6 @@ void VideoSoftware::DoState(PointerWrap& p) EfbInterface::DoState(p); OpcodeDecoder::DoState(p); Clipper::DoState(p); - p.Do(xfmem); p.Do(xfregs); p.Do(bpmem); p.DoPOD(swstats); diff --git a/Source/Core/VideoBackends/Software/TransformUnit.cpp b/Source/Core/VideoBackends/Software/TransformUnit.cpp index a25ef9e460..7090245a06 100644 --- a/Source/Core/VideoBackends/Software/TransformUnit.cpp +++ b/Source/Core/VideoBackends/Software/TransformUnit.cpp @@ -70,7 +70,7 @@ void MultipleVec3Ortho(const Vec3 &vec, const float *proj, Vec4 &result) void TransformPosition(const InputVertexData *src, OutputVertexData *dst) { - const float* mat = (const float*)&xfmem.posMatrices[src->posMtx * 4]; + const float* mat = (const float*)&xfregs.posMatrices[src->posMtx * 4]; MultiplyVec3Mat34(src->position, mat, dst->mvPosition); if (xfregs.projection.type == GX_PERSPECTIVE) @@ -85,7 +85,7 @@ void TransformPosition(const InputVertexData *src, OutputVertexData *dst) void TransformNormal(const InputVertexData *src, bool nbt, OutputVertexData *dst) { - const float* mat = (const float*)&xfmem.normalMatrices[(src->posMtx & 31) * 3]; + const float* mat = (const float*)&xfregs.normalMatrices[(src->posMtx & 31) * 3]; if (nbt) { @@ -124,7 +124,7 @@ void TransformTexCoordRegular(const TexMtxInfo &texinfo, int coordNum, bool spec break; } - const float *mat = (const float*)&xfmem.posMatrices[srcVertex->texMtx[coordNum] * 4]; + const float *mat = (const float*)&xfregs.posMatrices[srcVertex->texMtx[coordNum] * 4]; Vec3 *dst = &dstVertex->texCoords[coordNum]; if (texinfo.projection == XF_TEXPROJ_ST) @@ -150,7 +150,7 @@ void TransformTexCoordRegular(const TexMtxInfo &texinfo, int coordNum, bool spec // normalize const PostMtxInfo &postInfo = xfregs.postMtxInfo[coordNum]; - const float *postMat = (const float*)&xfmem.postMatrices[postInfo.index * 4]; + const float *postMat = (const float*)&xfregs.postMatrices[postInfo.index * 4]; if (specialCase) { @@ -212,7 +212,7 @@ inline float SafeDivide(float n, float d) void LightColor(const Vec3 &pos, const Vec3 &normal, u8 lightNum, const LitChannel &chan, Vec3 &lightCol) { - const LightPointer *light = (const LightPointer*)&xfmem.lights[0x10*lightNum]; + const LightPointer *light = (const LightPointer*)&xfregs.lights[0x10*lightNum]; if (!(chan.attnfunc & 1)) { @@ -297,7 +297,7 @@ void LightColor(const Vec3 &pos, const Vec3 &normal, u8 lightNum, const LitChann void LightAlpha(const Vec3 &pos, const Vec3 &normal, u8 lightNum, const LitChannel &chan, float &lightCol) { - const LightPointer *light = (const LightPointer*)&xfmem.lights[0x10*lightNum]; + const LightPointer *light = (const LightPointer*)&xfregs.lights[0x10*lightNum]; if (!(chan.attnfunc & 1)) { @@ -471,7 +471,7 @@ void TransformTexCoord(const InputVertexData *src, OutputVertexData *dst, bool s break; case XF_TEXGEN_EMBOSS_MAP: { - const LightPointer *light = (const LightPointer*)&xfmem.lights[0x10*texinfo.embosslightshift]; + const LightPointer *light = (const LightPointer*)&xfregs.lights[0x10*texinfo.embosslightshift]; Vec3 ldir = (light->pos - dst->mvPosition).normalized(); float d1 = ldir * dst->normal[1]; diff --git a/Source/Core/VideoBackends/Software/XFMemLoader.cpp b/Source/Core/VideoBackends/Software/XFMemLoader.cpp index 4304500056..37211e0384 100644 --- a/Source/Core/VideoBackends/Software/XFMemLoader.cpp +++ b/Source/Core/VideoBackends/Software/XFMemLoader.cpp @@ -11,7 +11,6 @@ void InitXFMemory() { memset(&xfregs, 0, sizeof(xfregs)); - memset(&xfmem, 0, sizeof(xfmem)); } void XFWritten(u32 transferSize, u32 baseAddress) @@ -24,7 +23,7 @@ void XFWritten(u32 transferSize, u32 baseAddress) // fix lights so invalid values don't trash the lighting computations if (baseAddress <= 0x067f && topAddress >= 0x0604) { - u32* x = xfmem.lights; + u32* x = xfregs.lights; // go through all lights for (int light = 0; light < 8; light++) @@ -59,36 +58,10 @@ void SWLoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData) transferSize = 0x1058 - baseAddress; } - // write to XF mem - if (baseAddress < 0x1000 && transferSize > 0) - { - u32 end = baseAddress + transferSize; - - u32 xfMemBase = baseAddress; - u32 xfMemTransferSize = transferSize; - - if (end >= 0x1000) - { - xfMemTransferSize = 0x1000 - baseAddress; - - baseAddress = 0x1000; - transferSize = end - 0x1000; - } - else - { - transferSize = 0; - } - - memcpy_gc((u32*)(&xfmem) + xfMemBase, pData, xfMemTransferSize * 4); - XFWritten(xfMemTransferSize, xfMemBase); - - pData += xfMemTransferSize; - } - // write to XF regs if (transferSize > 0) { - memcpy_gc((u32*)(&xfregs) + (baseAddress - 0x1000), pData, transferSize * 4); + memcpy_gc((u32*)(&xfregs) + baseAddress, pData, transferSize * 4); XFWritten(transferSize, baseAddress); } } diff --git a/Source/Core/VideoCommon/PixelShaderManager.cpp b/Source/Core/VideoCommon/PixelShaderManager.cpp index f03b6332ac..3b67b7a936 100644 --- a/Source/Core/VideoCommon/PixelShaderManager.cpp +++ b/Source/Core/VideoCommon/PixelShaderManager.cpp @@ -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*)&xfmem.lights[0x10 * istart]; + const float* xfmemptr = (const float*)&xfregs.lights[0x10 * istart]; for (int i = istart; i < iend; ++i) { diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index 8702648b9a..9e7719a1c9 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -504,8 +504,8 @@ void Renderer::RecordVideoMemory() { u32 *bpMem = (u32*)&bpmem; u32 cpMem[256]; - u32 *xfMem = (u32*)&xfmem; - u32 *xfRegs = (u32*)&xfregs; + u32 *xfMem = (u32*)&xfregs; + u32 *xfRegs = (u32*)&xfregs + 0x1000; memset(cpMem, 0, 256 * 4); FillCPMemoryArray(cpMem); diff --git a/Source/Core/VideoCommon/VertexLoader.cpp b/Source/Core/VideoCommon/VertexLoader.cpp index 5b99174822..fc8b2771a1 100644 --- a/Source/Core/VideoCommon/VertexLoader.cpp +++ b/Source/Core/VideoCommon/VertexLoader.cpp @@ -217,7 +217,7 @@ 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*)xfmem.posMatrices + s_curposmtx * 4; + const float * const world_matrix = (float*)xfregs.posMatrices + s_curposmtx * 4; const float * const proj_matrix = xfregs.projection.rawProjection; // Transform by world matrix diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index 627d432fb0..d73b1e2588 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -168,7 +168,6 @@ void VertexShaderManager::Init() Dirty(); memset(&xfregs, 0, sizeof(xfregs)); - memset(&xfmem, 0, sizeof(xfmem)); memset(&constants, 0 , sizeof(constants)); ResetView(); @@ -216,7 +215,7 @@ void VertexShaderManager::SetConstants() { int startn = nTransformMatricesChanged[0] / 4; int endn = (nTransformMatricesChanged[1] + 3) / 4; - memcpy(constants.transformmatrices[startn], &xfmem.posMatrices[startn * 4], (endn - startn) * 16); + memcpy(constants.transformmatrices[startn], &xfregs.posMatrices[startn * 4], (endn - startn) * 16); dirty = true; nTransformMatricesChanged[0] = nTransformMatricesChanged[1] = -1; } @@ -227,7 +226,7 @@ void VertexShaderManager::SetConstants() int endn = (nNormalMatricesChanged[1] + 2) / 3; for (int i=startn; i> 24) & 0xFF; constants.materials[i][1] = (data >> 16) & 0xFF; constants.materials[i][2] = (data >> 8) & 0xFF; @@ -298,7 +297,7 @@ void VertexShaderManager::SetConstants() { if (nMaterialsChanged & (1 << (i + 2))) { - u32 data = *(xfregs.matColor + i); + u32 data = xfregs.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; @@ -314,8 +313,8 @@ void VertexShaderManager::SetConstants() { bPosNormalMatrixChanged = false; - const float *pos = (const float *)xfmem.posMatrices + MatrixIndexA.PosNormalMtxIdx * 4; - const float *norm = (const float *)xfmem.normalMatrices + 3 * (MatrixIndexA.PosNormalMtxIdx & 31); + const float *pos = (const float *)xfregs.posMatrices + MatrixIndexA.PosNormalMtxIdx * 4; + const float *norm = (const float *)xfregs.normalMatrices + 3 * (MatrixIndexA.PosNormalMtxIdx & 31); memcpy(constants.posnormalmatrix, pos, 3*16); memcpy(constants.posnormalmatrix[3], norm, 12); @@ -329,10 +328,10 @@ void VertexShaderManager::SetConstants() bTexMatricesChanged[0] = false; const float *fptrs[] = { - (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] + (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] }; for (int i = 0; i < 4; ++i) @@ -346,10 +345,10 @@ void VertexShaderManager::SetConstants() { bTexMatricesChanged[1] = false; const float *fptrs[] = { - (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] + (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] }; for (int i = 0; i < 4; ++i) diff --git a/Source/Core/VideoCommon/VideoState.cpp b/Source/Core/VideoCommon/VideoState.cpp index 0c55af3a0c..33ce1f208c 100644 --- a/Source/Core/VideoCommon/VideoState.cpp +++ b/Source/Core/VideoCommon/VideoState.cpp @@ -31,7 +31,6 @@ static void DoState(PointerWrap &p) // XF Memory p.Do(xfregs); - p.Do(xfmem); p.DoMarker("XF Memory"); // Texture decoder diff --git a/Source/Core/VideoCommon/XFMemory.cpp b/Source/Core/VideoCommon/XFMemory.cpp index d523d3e215..3a9fc87e0c 100644 --- a/Source/Core/VideoCommon/XFMemory.cpp +++ b/Source/Core/VideoCommon/XFMemory.cpp @@ -6,4 +6,3 @@ // STATE_TO_SAVE XFRegisters xfregs; -XFMemory xfmem; diff --git a/Source/Core/VideoCommon/XFMemory.h b/Source/Core/VideoCommon/XFMemory.h index 9789e5f70c..1297ad6ee9 100644 --- a/Source/Core/VideoCommon/XFMemory.h +++ b/Source/Core/VideoCommon/XFMemory.h @@ -234,7 +234,7 @@ struct Projection u32 type; // only GX_PERSPECTIVE or GX_ORTHOGRAPHIC are allowed }; -struct XFMemory +struct XFRegisters { u32 posMatrices[256]; // 0x0000 - 0x00ff u32 unk0[768]; // 0x0100 - 0x03ff @@ -243,10 +243,6 @@ struct XFMemory u32 postMatrices[256]; // 0x0500 - 0x05ff u32 lights[128]; // 0x0600 - 0x067f u32 unk2[2432]; // 0x0680 - 0x0fff -}; - -struct XFRegisters -{ u32 error; // 0x1000 u32 diag; // 0x1001 u32 state0; // 0x1002 @@ -279,7 +275,6 @@ struct XFRegisters }; -extern XFMemory xfmem; extern XFRegisters xfregs; void LoadXFReg(u32 transferSize, u32 address, u32 *pData); diff --git a/Source/Core/VideoCommon/XFStructs.cpp b/Source/Core/VideoCommon/XFStructs.cpp index 2232f04f8f..f87c573e51 100644 --- a/Source/Core/VideoCommon/XFStructs.cpp +++ b/Source/Core/VideoCommon/XFStructs.cpp @@ -83,7 +83,7 @@ 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 - 0x1000] != (newValue & 0x7fff)) + if (((u32*)&xfregs)[address] != (newValue & 0x7fff)) VertexManager::Flush(); break; @@ -228,7 +228,7 @@ void LoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData) } XFMemWritten(xfMemTransferSize, xfMemBase); - memcpy_gc((u32*)(&xfmem) + xfMemBase, pData, xfMemTransferSize * 4); + memcpy_gc((u32*)(&xfregs) + 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 - 0x1000), pData, transferSize * 4); + memcpy_gc((u32*)(&xfregs) + 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*)(&xfmem) + address; + u32* currData = (u32*)(&xfregs) + address; u32* newData = (u32*)Memory::GetPointer(arraybases[refarray] + arraystrides[refarray] * index); bool changed = false; for (int i = 0; i < size; ++i)