Video backends: unify xfregs/xfmem structures.

Removes the duplicate swxfregs global variable/struct from the software
backend in favor of the ones from VideoCommon.
This commit is contained in:
magumagu
2014-04-16 14:51:18 -07:00
parent fee6efc4dc
commit 818c89313e
16 changed files with 123 additions and 158 deletions

View File

@ -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[0x10 * istart + XFMEM_LIGHTS];
const float* xfmemptr = (const float*)&xfmem.lights[0x10 * istart];
for (int i = istart; i < iend; ++i)
{

View File

@ -504,7 +504,7 @@ void Renderer::RecordVideoMemory()
{
u32 *bpMem = (u32*)&bpmem;
u32 cpMem[256];
u32 *xfMem = (u32*)xfmem;
u32 *xfMem = (u32*)&xfmem;
u32 *xfRegs = (u32*)&xfregs;
memset(cpMem, 0, 256 * 4);

View File

@ -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 + s_curposmtx * 4;
const float * const world_matrix = (float*)xfmem.posMatrices + s_curposmtx * 4;
const float * const proj_matrix = xfregs.projection.rawProjection;
// Transform by world matrix

View File

@ -168,7 +168,7 @@ void VertexShaderManager::Init()
Dirty();
memset(&xfregs, 0, sizeof(xfregs));
memset(xfmem, 0, sizeof(xfmem));
memset(&xfmem, 0, sizeof(xfmem));
memset(&constants, 0 , sizeof(constants));
ResetView();
@ -216,7 +216,7 @@ void VertexShaderManager::SetConstants()
{
int startn = nTransformMatricesChanged[0] / 4;
int endn = (nTransformMatricesChanged[1] + 3) / 4;
memcpy(constants.transformmatrices[startn], &xfmem[startn * 4], (endn - startn) * 16);
memcpy(constants.transformmatrices[startn], &xfmem.posMatrices[startn * 4], (endn - startn) * 16);
dirty = true;
nTransformMatricesChanged[0] = nTransformMatricesChanged[1] = -1;
}
@ -227,7 +227,7 @@ void VertexShaderManager::SetConstants()
int endn = (nNormalMatricesChanged[1] + 2) / 3;
for (int i=startn; i<endn; i++)
{
memcpy(constants.normalmatrices[i], &xfmem[XFMEM_NORMALMATRICES + 3*i], 12);
memcpy(constants.normalmatrices[i], &xfmem.normalMatrices[3*i], 12);
}
dirty = true;
nNormalMatricesChanged[0] = nNormalMatricesChanged[1] = -1;
@ -237,7 +237,7 @@ void VertexShaderManager::SetConstants()
{
int startn = nPostTransformMatricesChanged[0] / 4;
int endn = (nPostTransformMatricesChanged[1] + 3 ) / 4;
memcpy(constants.posttransformmatrices[startn], &xfmem[XFMEM_POSTMATRICES + startn * 4], (endn - startn) * 16);
memcpy(constants.posttransformmatrices[startn], &xfmem.postMatrices[startn * 4], (endn - startn) * 16);
dirty = true;
nPostTransformMatricesChanged[0] = nPostTransformMatricesChanged[1] = -1;
}
@ -248,7 +248,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*)&xfmem[0x10 * istart + XFMEM_LIGHTS];
const float* xfmemptr = (const float*)&xfmem.lights[0x10 * istart];
for (int i = istart; i < iend; ++i)
{
@ -314,8 +314,8 @@ void VertexShaderManager::SetConstants()
{
bPosNormalMatrixChanged = false;
const float *pos = (const float *)xfmem + MatrixIndexA.PosNormalMtxIdx * 4;
const float *norm = (const float *)xfmem + XFMEM_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);
@ -329,8 +329,10 @@ void VertexShaderManager::SetConstants()
bTexMatricesChanged[0] = false;
const float *fptrs[] =
{
(const float *)xfmem + MatrixIndexA.Tex0MtxIdx * 4, (const float *)xfmem + MatrixIndexA.Tex1MtxIdx * 4,
(const float *)xfmem + MatrixIndexA.Tex2MtxIdx * 4, (const float *)xfmem + 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)
@ -344,8 +346,10 @@ void VertexShaderManager::SetConstants()
{
bTexMatricesChanged[1] = false;
const float *fptrs[] = {
(const float *)xfmem + MatrixIndexB.Tex4MtxIdx * 4, (const float *)xfmem + MatrixIndexB.Tex5MtxIdx * 4,
(const float *)xfmem + MatrixIndexB.Tex6MtxIdx * 4, (const float *)xfmem + 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)

View File

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

View File

@ -6,4 +6,4 @@
// STATE_TO_SAVE
XFRegisters xfregs;
u32 xfmem[XFMEM_SIZE];
XFMemory xfmem;

View File

@ -5,6 +5,7 @@
#pragma once
#include "Common/Common.h"
#include "VideoCommon/CPMemory.h"
// Lighting
@ -50,7 +51,6 @@
#define GX_PERSPECTIVE 0
#define GX_ORTHOGRAPHIC 1
#define XFMEM_SIZE 0x8000
#define XFMEM_POSMATRICES 0x000
#define XFMEM_POSMATRICES_END 0x100
#define XFMEM_NORMALMATRICES 0x400
@ -234,6 +234,17 @@ struct Projection
u32 type; // only GX_PERSPECTIVE or GX_ORTHOGRAPHIC are allowed
};
struct XFMemory
{
u32 posMatrices[256]; // 0x0000 - 0x00ff
u32 unk0[768]; // 0x0100 - 0x03ff
u32 normalMatrices[96]; // 0x0400 - 0x045f
u32 unk1[160]; // 0x0460 - 0x04ff
u32 postMatrices[256]; // 0x0500 - 0x05ff
u32 lights[128]; // 0x0600 - 0x067f
u32 unk2[2432]; // 0x0680 - 0x0fff
};
struct XFRegisters
{
u32 error; // 0x1000
@ -256,8 +267,8 @@ struct XFRegisters
u32 unk5; // 0x1015
u32 unk6; // 0x1016
u32 unk7; // 0x1017
u32 MatrixIndexA; // 0x1018
u32 MatrixIndexB; // 0x1019
TMatrixIndexA MatrixIndexA; // 0x1018
TMatrixIndexB MatrixIndexB; // 0x1019
Viewport viewport; // 0x101a - 0x101f
Projection projection; // 0x1020 - 0x1026
u32 unk8[24]; // 0x1027 - 0x103e
@ -268,8 +279,8 @@ struct XFRegisters
};
extern XFMemory xfmem;
extern XFRegisters xfregs;
extern u32 xfmem[XFMEM_SIZE];
void LoadXFReg(u32 transferSize, u32 address, u32 *pData);
void LoadIndexedXF(u32 val, int array);

View File

@ -228,7 +228,7 @@ void LoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData)
}
XFMemWritten(xfMemTransferSize, xfMemBase);
memcpy_gc(&xfmem[xfMemBase], pData, xfMemTransferSize * 4);
memcpy_gc((u32*)(&xfmem) + xfMemBase, pData, xfMemTransferSize * 4);
pData += xfMemTransferSize;
}
@ -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*)(&xfmem) + address;
u32* newData = (u32*)Memory::GetPointer(arraybases[refarray] + arraystrides[refarray] * index);
bool changed = false;
for (int i = 0; i < size; ++i)