VideoCommon: remove SetVSConstant4f

This commit is contained in:
degasus 2013-10-08 23:58:51 +02:00
parent 5de7ac4791
commit 0b2fb548c3
2 changed files with 45 additions and 91 deletions

View File

@ -42,6 +42,7 @@
#define I_POSTTRANSFORMMATRICES "cpostmtx"
#define I_DEPTHPARAMS "cDepth" // farZ, zRange, scaled viewport width, scaled viewport height
//TODO: get rid of them, they aren't used at all
#define C_POSNORMALMATRIX 0
#define C_PROJECTION (C_POSNORMALMATRIX + 6)
#define C_MATERIALS (C_PROJECTION + 4)

View File

@ -46,52 +46,6 @@ void UpdateViewportWithCorrection()
UpdateViewport(s_viewportCorrection);
}
inline void SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{
float4* c = (float4*) &VertexShaderManager::constants;
c[const_number][0] = f1;
c[const_number][1] = f2;
c[const_number][2] = f3;
c[const_number][3] = f4;
VertexShaderManager::dirty = true;
}
inline void SetVSConstant4fv(unsigned int const_number, const float *f)
{
float4* c = (float4*) &VertexShaderManager::constants;
c[const_number][0] = f[0];
c[const_number][1] = f[1];
c[const_number][2] = f[2];
c[const_number][3] = f[3];
VertexShaderManager::dirty = true;
}
inline void SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const float *f)
{
float4* c = (float4*) &VertexShaderManager::constants;
for(u32 i=0; i<count; i++)
{
c[const_number+i][0] = f[0 + 3*i];
c[const_number+i][1] = f[1 + 3*i];
c[const_number+i][2] = f[2 + 3*i];
c[const_number+i][3] = 0.0f;
}
VertexShaderManager::dirty = true;
}
inline void SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
{
float4* c = (float4*) &VertexShaderManager::constants;
for(u32 i=0; i<count; i++)
{
c[const_number+i][0] = f[0 + 4*i];
c[const_number+i][1] = f[1 + 4*i];
c[const_number+i][2] = f[2 + 4*i];
c[const_number+i][3] = f[3 + 4*i];
}
VertexShaderManager::dirty = true;
}
struct ProjectionHack
{
float sign;
@ -229,8 +183,8 @@ void VertexShaderManager::SetConstants()
{
int startn = nTransformMatricesChanged[0] / 4;
int endn = (nTransformMatricesChanged[1] + 3) / 4;
const float* pstart = (const float*)&xfmem[startn * 4];
SetMultiVSConstant4fv(C_TRANSFORMMATRICES + startn, endn - startn, pstart);
memcpy(constants.transformmatrices[startn], &xfmem[startn * 4], (endn - startn) * 16);
dirty = true;
nTransformMatricesChanged[0] = nTransformMatricesChanged[1] = -1;
}
@ -238,8 +192,11 @@ void VertexShaderManager::SetConstants()
{
int startn = nNormalMatricesChanged[0] / 3;
int endn = (nNormalMatricesChanged[1] + 2) / 3;
const float *pnstart = (const float*)&xfmem[XFMEM_NORMALMATRICES+3*startn];
SetMultiVSConstant3fv(C_NORMALMATRICES + startn, endn - startn, pnstart);
for(int i=startn; i<endn; i++)
{
memcpy(constants.normalmatrices[i], &xfmem[XFMEM_NORMALMATRICES + 3*i], 12);
}
dirty = true;
nNormalMatricesChanged[0] = nNormalMatricesChanged[1] = -1;
}
@ -247,8 +204,8 @@ void VertexShaderManager::SetConstants()
{
int startn = nPostTransformMatricesChanged[0] / 4;
int endn = (nPostTransformMatricesChanged[1] + 3 ) / 4;
const float* pstart = (const float*)&xfmem[XFMEM_POSTMATRICES + startn * 4];
SetMultiVSConstant4fv(C_POSTTRANSFORMMATRICES + startn, endn - startn, pstart);
memcpy(constants.posttransformmatrices[startn], &xfmem[XFMEM_POSTMATRICES + startn * 4], (endn - startn) * 16);
dirty = true;
nPostTransformMatricesChanged[0] = nPostTransformMatricesChanged[1] = -1;
}
@ -262,12 +219,10 @@ void VertexShaderManager::SetConstants()
for (int i = istart; i < iend; ++i)
{
u32 color = *(const u32*)(xfmemptr + 3);
float NormalizationCoef = 1 / 255.0f;
SetVSConstant4f(C_LIGHTS + 5 * i,
((color >> 24) & 0xFF) * NormalizationCoef,
((color >> 16) & 0xFF) * NormalizationCoef,
((color >> 8) & 0xFF) * NormalizationCoef,
((color) & 0xFF) * NormalizationCoef);
constants.lights[5*i][0] = ((color >> 24) & 0xFF) / 255.0f;
constants.lights[5*i][1] = ((color >> 16) & 0xFF) / 255.0f;
constants.lights[5*i][2] = ((color >> 8) & 0xFF) / 255.0f;
constants.lights[5*i][3] = ((color) & 0xFF) / 255.0f;
xfmemptr += 4;
for (int j = 0; j < 4; ++j, xfmemptr += 3)
@ -278,35 +233,30 @@ void VertexShaderManager::SetConstants()
fabs(xfmemptr[2]) < 0.00001f)
{
// dist attenuation, make sure not equal to 0!!!
SetVSConstant4f(C_LIGHTS+5*i+j+1, 0.00001f, xfmemptr[1], xfmemptr[2], 0);
constants.lights[5*i+j+1][0] = 0.00001f;
}
else
{
SetVSConstant4fv(C_LIGHTS+5*i+j+1, xfmemptr);
}
constants.lights[5*i+j+1][0] = xfmemptr[0];
constants.lights[5*i+j+1][1] = xfmemptr[1];
constants.lights[5*i+j+1][2] = xfmemptr[2];
}
}
dirty = true;
nLightsChanged[0] = nLightsChanged[1] = -1;
}
if (nMaterialsChanged)
{
float GC_ALIGNED16(material[4]);
float NormalizationCoef = 1 / 255.0f;
for (int i = 0; i < 2; ++i)
{
if (nMaterialsChanged & (1 << i))
{
u32 data = *(xfregs.ambColor + i);
material[0] = ((data >> 24) & 0xFF) * NormalizationCoef;
material[1] = ((data >> 16) & 0xFF) * NormalizationCoef;
material[2] = ((data >> 8) & 0xFF) * NormalizationCoef;
material[3] = ( data & 0xFF) * NormalizationCoef;
SetVSConstant4fv(C_MATERIALS + i, material);
constants.materials[i][0] = ((data >> 24) & 0xFF) / 255.0f;
constants.materials[i][1] = ((data >> 16) & 0xFF) / 255.0f;
constants.materials[i][2] = ((data >> 8) & 0xFF) / 255.0f;
constants.materials[i][3] = ( data & 0xFF) / 255.0f;
}
}
@ -315,15 +265,13 @@ void VertexShaderManager::SetConstants()
if (nMaterialsChanged & (1 << (i + 2)))
{
u32 data = *(xfregs.matColor + i);
material[0] = ((data >> 24) & 0xFF) * NormalizationCoef;
material[1] = ((data >> 16) & 0xFF) * NormalizationCoef;
material[2] = ((data >> 8) & 0xFF) * NormalizationCoef;
material[3] = ( data & 0xFF) * NormalizationCoef;
SetVSConstant4fv(C_MATERIALS + i + 2, material);
constants.materials[i+2][0] = ((data >> 24) & 0xFF) / 255.0f;
constants.materials[i+2][1] = ((data >> 16) & 0xFF) / 255.0f;
constants.materials[i+2][2] = ((data >> 8) & 0xFF) / 255.0f;
constants.materials[i+2][3] = ( data & 0xFF) / 255.0f;
}
}
dirty = true;
nMaterialsChanged = 0;
}
@ -335,8 +283,11 @@ void VertexShaderManager::SetConstants()
const float *pos = (const float *)xfmem + MatrixIndexA.PosNormalMtxIdx * 4;
const float *norm = (const float *)xfmem + XFMEM_NORMALMATRICES + 3 * (MatrixIndexA.PosNormalMtxIdx & 31);
SetMultiVSConstant4fv(C_POSNORMALMATRIX, 3, pos);
SetMultiVSConstant3fv(C_POSNORMALMATRIX + 3, 3, norm);
memcpy(constants.posnormalmatrix, pos, 3*16);
memcpy(constants.posnormalmatrix[3], norm, 12);
memcpy(constants.posnormalmatrix[4], norm+3, 12);
memcpy(constants.posnormalmatrix[5], norm+6, 12);
dirty = true;
}
if (bTexMatricesChanged[0])
@ -350,8 +301,9 @@ void VertexShaderManager::SetConstants()
for (int i = 0; i < 4; ++i)
{
SetMultiVSConstant4fv(C_TEXMATRICES + 3 * i, 3, fptrs[i]);
memcpy(constants.texmatrices[3*i], fptrs[i], 3*16);
}
dirty = true;
}
if (bTexMatricesChanged[1])
@ -364,18 +316,19 @@ void VertexShaderManager::SetConstants()
for (int i = 0; i < 4; ++i)
{
SetMultiVSConstant4fv(C_TEXMATRICES+3 * i + 12, 3, fptrs[i]);
memcpy(constants.texmatrices[3*i+12], fptrs[i], 3*16);
}
dirty = true;
}
if (bViewportChanged)
{
bViewportChanged = false;
SetVSConstant4f(C_DEPTHPARAMS,
xfregs.viewport.farZ / 16777216.0f,
xfregs.viewport.zRange / 16777216.0f,
-1.f / (float)g_renderer->EFBToScaledX((int)ceil(2.0f * xfregs.viewport.wd)),
1.f / (float)g_renderer->EFBToScaledY((int)ceil(-2.0f * xfregs.viewport.ht)));
constants.depthparams[0] = xfregs.viewport.farZ / 16777216.0f;
constants.depthparams[1] = xfregs.viewport.zRange / 16777216.0f;
constants.depthparams[2] = -1.f / g_renderer->EFBToScaledX(ceilf(2.0f * xfregs.viewport.wd));
constants.depthparams[3] = 1.f / g_renderer->EFBToScaledY(ceilf(-2.0f * xfregs.viewport.ht));
dirty = true;
// This is so implementation-dependent that we can't have it here.
UpdateViewport(s_viewportCorrection);
bProjectionChanged = true;
@ -504,8 +457,7 @@ void VertexShaderManager::SetConstants()
Matrix44::Set(mtxB, g_fProjectionMatrix);
Matrix44::Multiply(mtxB, viewMtx, mtxA); // mtxA = projection x view
Matrix44::Multiply(s_viewportCorrection, mtxA, mtxB); // mtxB = viewportCorrection x mtxA
SetMultiVSConstant4fv(C_PROJECTION, 4, mtxB.data);
memcpy(constants.projection, mtxB.data, 4*16);
}
else
{
@ -514,8 +466,9 @@ void VertexShaderManager::SetConstants()
Matrix44 correctedMtx;
Matrix44::Multiply(s_viewportCorrection, projMtx, correctedMtx);
SetMultiVSConstant4fv(C_PROJECTION, 4, correctedMtx.data);
memcpy(constants.projection, correctedMtx.data, 4*16);
}
dirty = true;
}
}