From c36ed08cfcfdb94708d1b32081808f58eb87f1b1 Mon Sep 17 00:00:00 2001 From: donkopunchstania Date: Sat, 5 Feb 2011 18:25:34 +0000 Subject: [PATCH] Rework XF register loading a bit and change how registers are arranged in memory. This removes the assumption that all data for a viewport or projection matrix will be available when index 0 is loaded. Fixes issue 3688 and probably breaks old save states (sorry). git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7083 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Core/VideoCommon/Src/PixelShaderGen.cpp | 26 +- .../VideoCommon/Src/PixelShaderManager.cpp | 140 +++---- .../Core/VideoCommon/Src/PixelShaderManager.h | 4 +- .../Core/VideoCommon/Src/VertexShaderGen.cpp | 76 ++-- .../VideoCommon/Src/VertexShaderManager.cpp | 50 +-- .../VideoCommon/Src/VertexShaderManager.h | 11 +- Source/Core/VideoCommon/Src/XFMemory.h | 82 ++-- Source/Core/VideoCommon/Src/XFStructs.cpp | 382 ++++++++++-------- .../Src/NativeVertexFormat.cpp | 6 +- .../Plugin_VideoOGL/Src/VertexManager.cpp | 16 +- 10 files changed, 414 insertions(+), 379 deletions(-) diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index 425666e4ce..95dfd630d1 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -41,7 +41,7 @@ void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode) if (bpmem.tevorders[i/2].getEnable(i & 1)) { int texcoord = bpmem.tevorders[i / 2].getTexCoord(i & 1); - if (xfregs.texcoords[texcoord].texmtxinfo.projection) + if (xfregs.texMtxInfo[i].projection) projtexcoords |= 1 << texcoord; } } @@ -66,12 +66,12 @@ void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode) if(g_ActiveConfig.bEnablePixelLigting && g_ActiveConfig.backend_info.bSupportsPixelLighting) { for (int i = 0; i < 2; ++i) { - uid->values[3 + i] = xfregs.colChans[i].color.enablelighting ? - (u32)xfregs.colChans[i].color.hex : - (u32)xfregs.colChans[i].color.matsource; - uid->values[3 + i] |= (xfregs.colChans[i].alpha.enablelighting ? - (u32)xfregs.colChans[i].alpha.hex : - (u32)xfregs.colChans[i].alpha.matsource) << 15; + uid->values[3 + i] = xfregs.color[i].enablelighting ? + (u32)xfregs.color[i].hex : + (u32)xfregs.color[i].matsource; + uid->values[3 + i] |= (xfregs.alpha[i].enablelighting ? + (u32)xfregs.alpha[i].hex : + (u32)xfregs.alpha[i].matsource) << 15; } } uid->values[4] |= (g_ActiveConfig.bEnablePixelLigting && g_ActiveConfig.backend_info.bSupportsPixelLighting) << 31; @@ -552,7 +552,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType } else { - for (int i = 0; i < xfregs.numTexGens; ++i) + for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i) WRITE(p, ",\n in float%d uv%d : TEXCOORD%d", i < 4 ? 4 : 3 , i, i); } } @@ -591,7 +591,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType if(g_ActiveConfig.bEnablePixelLigting && g_ActiveConfig.backend_info.bSupportsPixelLighting) { - if (xfregs.numTexGens < 7) + if (xfregs.numTexGen.numTexGens < 7) { WRITE(p,"float3 _norm0 = normalize(Normal.xyz);\n\n"); WRITE(p,"float3 pos = float3(clipPos.x,clipPos.y,Normal.w);\n"); @@ -607,10 +607,10 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType "float3 ldir, h;\n" "float dist, dist2, attn;\n"); // lights/colors - for (int j = 0; j < xfregs.nNumChans; j++) + for (unsigned int j = 0; j < xfregs.numChan.numColorChans; j++) { - const LitChannel& color = xfregs.colChans[j].color; - const LitChannel& alpha = xfregs.colChans[j].alpha; + const LitChannel& color = xfregs.color[j]; + const LitChannel& alpha = xfregs.alpha[j]; WRITE(p, "{\n"); @@ -730,7 +730,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType for (int i = 0; i < numTexgen; ++i) { // optional perspective divides - if (xfregs.texcoords[i].texmtxinfo.projection == XF_TEXPROJ_STQ) + if (xfregs.texMtxInfo[i].projection == XF_TEXPROJ_STQ) { WRITE(p, "if (uv%d.z)", i); WRITE(p, " uv%d.xy = uv%d.xy / uv%d.z;\n", i, i, i); diff --git a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp index 1618a3bdab..e81db49f43 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp @@ -24,8 +24,6 @@ #include "VideoConfig.h" #include "RenderBase.h" - -static float GC_ALIGNED16(s_fMaterials[16]); static int s_nColorsChanged[2]; // 0 - regular colors, 1 - k colors static int s_nIndTexMtxChanged; static bool s_bAlphaChanged; @@ -36,7 +34,6 @@ static bool s_bFogColorChanged; static bool s_bFogParamChanged; static bool s_bFogRangeAdjustChanged; static int nLightsChanged[2]; // min,max -static float lastDepthRange[2]; // 0 = far z, 1 = far - near static float lastRGBAfull[2][4][4]; static u8 s_nTexDimsChanged; static u8 s_nIndTexScaleChanged; @@ -142,8 +139,16 @@ void PixelShaderManager::SetConstants() if (s_bZBiasChanged || s_bDepthRangeChanged) { - //ERROR_LOG("pixel=%x,%x, bias=%x\n", bpmem.zcontrol.pixel_format, bpmem.ztex2.type, lastZBias); - SetPSConstant4f(C_ZBIAS+1, lastDepthRange[0] / 16777216.0f, lastDepthRange[1] / 16777216.0f, 0, (float)(lastZBias)/16777215.0f); + // reversed gxsetviewport(xorig, yorig, width, height, nearz, farz) + // [0] = width/2 + // [1] = height/2 + // [2] = 16777215 * (farz - nearz) + // [3] = xorig + width/2 + 342 + // [4] = yorig + height/2 + 342 + // [5] = 16777215 * farz + + //ERROR_LOG("pixel=%x,%x, bias=%x\n", bpmem.zcontrol.pixel_format, bpmem.ztex2.type, lastZBias); + SetPSConstant4f(C_ZBIAS+1, xfregs.rawViewport[2] / 16777216.0f, xfregs.rawViewport[5] / 16777216.0f, 0, (float)(lastZBias)/16777215.0f); s_bZBiasChanged = s_bDepthRangeChanged = false; } @@ -252,48 +257,66 @@ void PixelShaderManager::SetConstants() s_bFogRangeAdjustChanged = false; } - if (g_ActiveConfig.bEnablePixelLigting && g_ActiveConfig.backend_info.bSupportsPixelLighting && nLightsChanged[0] >= 0) // config check added because the code in here was crashing for me inside SetPSConstant4f + if (g_ActiveConfig.bEnablePixelLigting && g_ActiveConfig.backend_info.bSupportsPixelLighting) // config check added because the code in here was crashing for me inside SetPSConstant4f { - // 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]; - - for (int i = istart; i < iend; ++i) + if (nLightsChanged[0] >= 0) { - u32 color = *(const u32*)(xfmemptr + 3); - float NormalizationCoef = 1 / 255.0f; - SetPSConstant4f(C_PLIGHTS + 5 * i, - ((color >> 24) & 0xFF) * NormalizationCoef, - ((color >> 16) & 0xFF) * NormalizationCoef, - ((color >> 8) & 0xFF) * NormalizationCoef, - ((color) & 0xFF) * NormalizationCoef); - xfmemptr += 4; + // 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]; - for (int j = 0; j < 4; ++j, xfmemptr += 3) + for (int i = istart; i < iend; ++i) { - if (j == 1 && - fabs(xfmemptr[0]) < 0.00001f && - fabs(xfmemptr[1]) < 0.00001f && - fabs(xfmemptr[2]) < 0.00001f) + u32 color = *(const u32*)(xfmemptr + 3); + float NormalizationCoef = 1 / 255.0f; + SetPSConstant4f(C_PLIGHTS + 5 * i, + ((color >> 24) & 0xFF) * NormalizationCoef, + ((color >> 16) & 0xFF) * NormalizationCoef, + ((color >> 8) & 0xFF) * NormalizationCoef, + ((color) & 0xFF) * NormalizationCoef); + xfmemptr += 4; + + for (int j = 0; j < 4; ++j, xfmemptr += 3) { - // dist attenuation, make sure not equal to 0!!! - SetPSConstant4f(C_PLIGHTS+5*i+j+1, 0.00001f, xfmemptr[1], xfmemptr[2], 0); + if (j == 1 && + fabs(xfmemptr[0]) < 0.00001f && + fabs(xfmemptr[1]) < 0.00001f && + fabs(xfmemptr[2]) < 0.00001f) + { + // dist attenuation, make sure not equal to 0!!! + SetPSConstant4f(C_PLIGHTS+5*i+j+1, 0.00001f, xfmemptr[1], xfmemptr[2], 0); + } + else + SetPSConstant4fv(C_PLIGHTS+5*i+j+1, xfmemptr); } - else - SetPSConstant4fv(C_PLIGHTS+5*i+j+1, xfmemptr); } + + nLightsChanged[0] = nLightsChanged[1] = -1; } - nLightsChanged[0] = nLightsChanged[1] = -1; - } - if (nMaterialsChanged) - { - for (int i = 0; i < 4; ++i) - if (nMaterialsChanged & (1 << i)) - SetPSConstant4fv(C_PMATERIALS + i, &s_fMaterials[4 * i]); + if (nMaterialsChanged) + { + float GC_ALIGNED16(material[4]); + float NormalizationCoef = 1 / 255.0f; - nMaterialsChanged = 0; + for (int i = 0; i < 4; ++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; + + SetPSConstant4fv(C_PMATERIALS + i, material); + } + } + + nMaterialsChanged = 0; + } } } @@ -367,39 +390,9 @@ void PixelShaderManager::SetZTextureBias(u32 bias) } } -void PixelShaderManager::SetViewport(float* viewport,int VIndex) +void PixelShaderManager::SetViewportChanged() { - // reversed gxsetviewport(xorig, yorig, width, height, nearz, farz) - // [0] = width/2 - // [1] = height/2 - // [2] = 16777215 * (farz - nearz) - // [3] = xorig + width/2 + 342 - // [4] = yorig + height/2 + 342 - // [5] = 16777215 * farz - - if(VIndex <= 0) - { - if (lastDepthRange[0] != viewport[5] || lastDepthRange[1] != viewport[2]) - { - lastDepthRange[0] = viewport[5]; - lastDepthRange[1] = viewport[2]; - - s_bDepthRangeChanged = true; - } - } - else - { - if (VIndex == 2 && lastDepthRange[1] != viewport[0]) - { - lastDepthRange[1] = viewport[0]; - s_bDepthRangeChanged = true; - } - else if(VIndex == 5 && lastDepthRange[0] != viewport[0]) - { - lastDepthRange[0] = viewport[0]; - s_bDepthRangeChanged = true; - } - } + s_bDepthRangeChanged = true; } void PixelShaderManager::SetIndTexScaleChanged(u8 stagemask) @@ -463,14 +456,7 @@ void PixelShaderManager::InvalidateXFRange(int start, int end) } } -void PixelShaderManager::SetMaterialColor(int index, u32 data) +void PixelShaderManager::SetMaterialColorChanged(int index) { - int ind = index * 4; - nMaterialsChanged |= (1 << index); - float NormalizationCoef = 1 / 255.0f; - s_fMaterials[ind++] = ((data >> 24) & 0xFF) * NormalizationCoef; - s_fMaterials[ind++] = ((data >> 16) & 0xFF) * NormalizationCoef; - s_fMaterials[ind++] = ((data >> 8) & 0xFF) * NormalizationCoef; - s_fMaterials[ind] = ( data & 0xFF) * NormalizationCoef; } diff --git a/Source/Core/VideoCommon/Src/PixelShaderManager.h b/Source/Core/VideoCommon/Src/PixelShaderManager.h index 51e4705925..adbc8bf037 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderManager.h +++ b/Source/Core/VideoCommon/Src/PixelShaderManager.h @@ -39,7 +39,7 @@ public: static void SetDestAlpha(const ConstantAlpha& alpha); static void SetTexDims(int texmapid, u32 width, u32 height, u32 wraps, u32 wrapt); static void SetZTextureBias(u32 bias); - static void SetViewport(float* viewport,int VIndex = -1); + static void SetViewportChanged(); static void SetIndMatrixChanged(int matrixidx); static void SetTevKSelChanged(int id); static void SetZTextureTypeChanged(); @@ -50,7 +50,7 @@ public: static void SetFogRangeAdjustChanged(); static void SetColorMatrix(const float* pmatrix); static void InvalidateXFRange(int start, int end); - static void SetMaterialColor(int index, u32 data); + static void SetMaterialColorChanged(int index); }; diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp index 3b5762271f..61f73c1e42 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp @@ -32,31 +32,31 @@ VERTEXSHADERUID last_vertex_shader_uid; void GetVertexShaderId(VERTEXSHADERUID *uid, u32 components) { uid->values[0] = components | - (xfregs.numTexGens << 23) | - (xfregs.nNumChans << 27) | - ((u32)xfregs.bEnableDualTexTransform << 29); + (xfregs.numTexGen.numTexGens << 23) | + (xfregs.numChan.numColorChans << 27) | + (xfregs.dualTexTrans.enabled << 29); for (int i = 0; i < 2; ++i) { - uid->values[1+i] = xfregs.colChans[i].color.enablelighting ? - (u32)xfregs.colChans[i].color.hex : - (u32)xfregs.colChans[i].color.matsource; - uid->values[1+i] |= (xfregs.colChans[i].alpha.enablelighting ? - (u32)xfregs.colChans[i].alpha.hex : - (u32)xfregs.colChans[i].alpha.matsource) << 15; + uid->values[1+i] = xfregs.color[i].enablelighting ? + (u32)xfregs.color[i].hex : + (u32)xfregs.color[i].matsource; + uid->values[1+i] |= (xfregs.alpha[i].enablelighting ? + (u32)xfregs.alpha[i].hex : + (u32)xfregs.alpha[i].matsource) << 15; } uid->values[2] |= (g_ActiveConfig.bEnablePixelLigting && g_ActiveConfig.backend_info.bSupportsPixelLighting) << 31; u32 *pcurvalue = &uid->values[3]; - for (int i = 0; i < xfregs.numTexGens; ++i) { - TexMtxInfo tinfo = xfregs.texcoords[i].texmtxinfo; + for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i) { + TexMtxInfo tinfo = xfregs.texMtxInfo[i]; if (tinfo.texgentype != XF_TEXGEN_EMBOSS_MAP) tinfo.hex &= 0x7ff; if (tinfo.texgentype != XF_TEXGEN_REGULAR) tinfo.projection = 0; u32 val = ((tinfo.hex >> 1) & 0x1ffff); - if (xfregs.bEnableDualTexTransform && tinfo.texgentype == XF_TEXGEN_REGULAR) { + if (xfregs.dualTexTrans.enabled && tinfo.texgentype == XF_TEXGEN_REGULAR) { // rewrite normalization and post index - val |= ((u32)xfregs.texcoords[i].postmtxinfo.index << 17) | ((u32)xfregs.texcoords[i].postmtxinfo.normalize << 23); + val |= ((u32)xfregs.postMtxInfo[i].index << 17) | ((u32)xfregs.postMtxInfo[i].normalize << 23); } switch (i & 3) { @@ -81,15 +81,15 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type) setlocale(LC_NUMERIC, "C"); // Reset locale for compilation text[sizeof(text) - 1] = 0x7C; // canary - _assert_(bpmem.genMode.numtexgens == xfregs.numTexGens); - _assert_(bpmem.genMode.numcolchans == xfregs.nNumChans); + _assert_(bpmem.genMode.numtexgens == xfregs.numTexGen.numTexGens); + _assert_(bpmem.genMode.numcolchans == xfregs.numChan.numColorChans); bool is_d3d = (api_type == API_D3D9 || api_type == API_D3D11); u32 lightMask = 0; - if (xfregs.nNumChans > 0) - lightMask |= xfregs.colChans[0].color.GetFullLightMask() | xfregs.colChans[0].alpha.GetFullLightMask(); - if (xfregs.nNumChans > 1) - lightMask |= xfregs.colChans[1].color.GetFullLightMask() | xfregs.colChans[1].alpha.GetFullLightMask(); + if (xfregs.numChan.numColorChans > 0) + lightMask |= xfregs.color[0].GetFullLightMask() | xfregs.alpha[0].GetFullLightMask(); + if (xfregs.numChan.numColorChans > 1) + lightMask |= xfregs.color[1].GetFullLightMask() | xfregs.alpha[1].GetFullLightMask(); char *p = text; WRITE(p, "//Vertex Shader: comp:%x, \n", components); @@ -110,12 +110,12 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type) WRITE(p, " float4 colors_0 : COLOR0;\n"); WRITE(p, " float4 colors_1 : COLOR1;\n"); - if (xfregs.numTexGens < 7) { - for (int i = 0; i < xfregs.numTexGens; ++i) + if (xfregs.numTexGen.numTexGens < 7) { + for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i) WRITE(p, " float3 tex%d : TEXCOORD%d;\n", i, i); - WRITE(p, " float4 clipPos : TEXCOORD%d;\n", xfregs.numTexGens); + WRITE(p, " float4 clipPos : TEXCOORD%d;\n", xfregs.numTexGen.numTexGens); if(g_ActiveConfig.bEnablePixelLigting && g_ActiveConfig.backend_info.bSupportsPixelLighting) - WRITE(p, " float4 Normal : TEXCOORD%d;\n", xfregs.numTexGens + 1); + WRITE(p, " float4 Normal : TEXCOORD%d;\n", xfregs.numTexGen.numTexGens + 1); } else { // clip position is in w of first 4 texcoords if(g_ActiveConfig.bEnablePixelLigting && g_ActiveConfig.backend_info.bSupportsPixelLighting) @@ -125,7 +125,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type) } else { - for (int i = 0; i < xfregs.numTexGens; ++i) + for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i) WRITE(p, " float%d tex%d : TEXCOORD%d;\n", i < 4 ? 4 : 3 , i, i); } } @@ -231,7 +231,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type) "float3 ldir, h;\n" "float dist, dist2, attn;\n"); - if(xfregs.nNumChans == 0) + if(xfregs.numChan.numColorChans == 0) { if (components & VB_HAS_COL0) WRITE(p, "o.colors_0 = color0;\n"); @@ -239,10 +239,10 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type) WRITE(p, "o.colors_0 = float4(1.0f, 1.0f, 1.0f, 1.0f);\n"); } // lights/colors - for (int j = 0; j < xfregs.nNumChans; j++) + for (unsigned int j = 0; j < xfregs.numChan.numColorChans; j++) { - const LitChannel& color = xfregs.colChans[j].color; - const LitChannel& alpha = xfregs.colChans[j].alpha; + const LitChannel& color = xfregs.color[j]; + const LitChannel& alpha = xfregs.alpha[j]; WRITE(p, "{\n"); @@ -345,7 +345,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type) WRITE(p, "o.colors_%d = mat * saturate(lacc);\n", j); WRITE(p, "}\n"); } - if(xfregs.nNumChans < 2) + if(xfregs.numChan.numColorChans < 2) { if (components & VB_HAS_COL1) WRITE(p, "o.colors_1 = color1;\n"); @@ -363,8 +363,8 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type) // transform texcoords WRITE(p, "float4 coord = float4(0.0f, 0.0f, 1.0f, 1.0f);\n"); - for (int i = 0; i < xfregs.numTexGens; ++i) { - TexMtxInfo& texinfo = xfregs.texcoords[i].texmtxinfo; + for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i) { + TexMtxInfo& texinfo = xfregs.texMtxInfo[i]; WRITE(p, "{\n"); WRITE(p, "coord = float4(0.0f, 0.0f, 1.0f, 1.0f);\n"); @@ -443,8 +443,10 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type) break; } - if (xfregs.bEnableDualTexTransform && texinfo.texgentype == XF_TEXGEN_REGULAR) { // only works for regular tex gen types? - int postidx = xfregs.texcoords[i].postmtxinfo.index; + if (xfregs.dualTexTrans.enabled && texinfo.texgentype == XF_TEXGEN_REGULAR) { // only works for regular tex gen types? + const PostMtxInfo& postInfo = xfregs.postMtxInfo[i]; + + int postidx = postInfo.index; WRITE(p, "float4 P0 = "I_POSTTRANSFORMMATRICES".T[%d].t;\n" "float4 P1 = "I_POSTTRANSFORMMATRICES".T[%d].t;\n" "float4 P2 = "I_POSTTRANSFORMMATRICES".T[%d].t;\n", @@ -460,7 +462,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type) } else { - if (xfregs.texcoords[i].postmtxinfo.normalize) + if (postInfo.normalize) WRITE(p, "o.tex%d.xyz = normalize(o.tex%d.xyz);\n", i, i); // multiply by postmatrix @@ -472,7 +474,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type) } // clipPos/w needs to be done in pixel shader, not here - if (xfregs.numTexGens < 7) { + if (xfregs.numTexGen.numTexGens < 7) { WRITE(p, "o.clipPos = float4(pos.x,pos.y,o.pos.z,o.pos.w);\n"); } else { WRITE(p, "o.tex0.w = pos.x;\n"); @@ -483,13 +485,13 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type) if(g_ActiveConfig.bEnablePixelLigting && g_ActiveConfig.backend_info.bSupportsPixelLighting) { - if (xfregs.numTexGens < 7) { + if (xfregs.numTexGen.numTexGens < 7) { WRITE(p, "o.Normal = float4(_norm0.x,_norm0.y,_norm0.z,pos.z);\n"); } else { WRITE(p, "o.tex4.w = _norm0.x;\n"); WRITE(p, "o.tex5.w = _norm0.y;\n"); WRITE(p, "o.tex6.w = _norm0.z;\n"); - if (xfregs.numTexGens < 8) + if (xfregs.numTexGen.numTexGens < 8) WRITE(p, "o.tex7 = pos.xyzz;\n"); else WRITE(p, "o.tex7.w = pos.z;\n"); diff --git a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp index 78d6819244..ebb449540a 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp @@ -33,8 +33,6 @@ #include "VertexManagerBase.h" #include "RenderBase.h" - -static float GC_ALIGNED16(s_fMaterials[16]); float GC_ALIGNED16(g_fProjectionMatrix[16]); // track changes @@ -237,9 +235,23 @@ void VertexShaderManager::SetConstants() if (nMaterialsChanged) { + float GC_ALIGNED16(material[4]); + float NormalizationCoef = 1 / 255.0f; + for (int i = 0; i < 4; ++i) + { if (nMaterialsChanged & (1 << i)) - SetVSConstant4fv(C_MATERIALS + i, &s_fMaterials[4 * 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); + } + } nMaterialsChanged = 0; } @@ -530,47 +542,19 @@ void VertexShaderManager::SetTexMatrixChangedB(u32 Value) } } -void VertexShaderManager::SetViewport(float* _Viewport, int constantIndex) -{ - if(constantIndex <= 0) - { - memcpy(xfregs.rawViewport, _Viewport, sizeof(xfregs.rawViewport)); - } - else - { - xfregs.rawViewport[constantIndex] = _Viewport[0]; - } - bViewportChanged = true; -} - void VertexShaderManager::SetViewportChanged() { bViewportChanged = true; } -void VertexShaderManager::SetProjection(float* _pProjection, int constantIndex) +void VertexShaderManager::SetProjectionChanged() { - if(constantIndex <= 0) - { - memcpy(xfregs.rawProjection, _pProjection, sizeof(xfregs.rawProjection)); - } - else - { - xfregs.rawProjection[constantIndex] = _pProjection[0]; - } bProjectionChanged = true; } -void VertexShaderManager::SetMaterialColor(int index, u32 data) +void VertexShaderManager::SetMaterialColorChanged(int index) { - int ind = index * 4; - nMaterialsChanged |= (1 << index); - float NormalizationCoef = 1 / 255.0f; - s_fMaterials[ind++] = ((data >> 24) & 0xFF) * NormalizationCoef; - s_fMaterials[ind++] = ((data >> 16) & 0xFF) * NormalizationCoef; - s_fMaterials[ind++] = ((data >> 8) & 0xFF) * NormalizationCoef; - s_fMaterials[ind] = ( data & 0xFF) * NormalizationCoef; } void VertexShaderManager::TranslateView(float x, float y) diff --git a/Source/Core/VideoCommon/Src/VertexShaderManager.h b/Source/Core/VideoCommon/Src/VertexShaderManager.h index 32fa555cdb..ddbde1c0dd 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderManager.h +++ b/Source/Core/VideoCommon/Src/VertexShaderManager.h @@ -42,13 +42,12 @@ public: // constant management static void SetConstants(); - static void SetViewport(float* _Viewport, int constantIndex = -1); - static void SetViewportChanged(); - static void SetProjection(float* _pProjection, int constantIndex = -1); static void InvalidateXFRange(int start, int end); - static void SetTexMatrixChangedA(u32 Value); - static void SetTexMatrixChangedB(u32 Value); - static void SetMaterialColor(int index, u32 data); + static void SetTexMatrixChangedA(u32 value); + static void SetTexMatrixChangedB(u32 value); + static void SetViewportChanged(); + static void SetProjectionChanged(); + static void SetMaterialColorChanged(int index); static void TranslateView(float x, float y); static void RotateView(float x, float y); diff --git a/Source/Core/VideoCommon/Src/XFMemory.h b/Source/Core/VideoCommon/Src/XFMemory.h index 2ffe01305b..a45cc6af24 100644 --- a/Source/Core/VideoCommon/Src/XFMemory.h +++ b/Source/Core/VideoCommon/Src/XFMemory.h @@ -173,6 +173,32 @@ union PostMtxInfo u32 hex; }; +union NumColorChannel +{ + struct + { + u32 numColorChans : 2; + }; + u32 hex; +}; + +union NumTexGen +{ + struct + { + u32 numTexGens : 4; + }; + u32 hex; +}; + +union DualTexInfo +{ + struct + { + u32 enabled : 1; + }; + u32 hex; +}; @@ -199,16 +225,6 @@ struct Light }; }; - - -struct ColorChannel -{ - u32 ambColor; - u32 matColor; - LitChannel color; - LitChannel alpha; -}; - struct Viewport { float wd; @@ -219,28 +235,40 @@ struct Viewport float farZ; }; -struct TexCoordInfo -{ - TexMtxInfo texmtxinfo; - PostMtxInfo postmtxinfo; -}; - struct XFRegisters { - int numTexGens; - int nNumChans; - INVTXSPEC hostinfo; // number of textures,colors,normals from vertex input - ColorChannel colChans[2]; //C0A0 C1A1 - TexCoordInfo texcoords[8]; - bool bEnableDualTexTransform; - float rawViewport[6]; - float rawProjection[7]; + u32 error; // 0x1000 + u32 diag; // 0x1001 + u32 state0; // 0x1002 + u32 state1; // 0x1003 + u32 xfClock; // 0x1004 + u32 clipDisable; // 0x1005 + u32 perf0; // 0x1006 + u32 perf1; // 0x1007 + INVTXSPEC hostinfo; // 0x1008 number of textures,colors,normals from vertex input + NumColorChannel numChan; // 0x1009 + u32 ambColor[2]; // 0x100a, 0x100b + u32 matColor[2]; // 0x100c, 0x100d + LitChannel color[2]; // 0x100e, 0x100f + LitChannel alpha[2]; // 0x1010, 0x1011 + DualTexInfo dualTexTrans; // 0x1012 + u32 unk3; // 0x1013 + u32 unk4; // 0x1014 + u32 unk5; // 0x1015 + u32 unk6; // 0x1016 + u32 unk7; // 0x1017 + u32 MatrixIndexA; // 0x1018 + u32 MatrixIndexB; // 0x1019 + float rawViewport[6]; // 0x101a - 0x101f + float rawProjection[7]; // 0x1020 - 0x1026 + u32 unk8[24]; // 0x1027 - 0x103e + NumTexGen numTexGen; // 0x103f + TexMtxInfo texMtxInfo[8]; // 0x1040 - 0x1047 + u32 unk9[8]; // 0x1048 - 0x104f + PostMtxInfo postMtxInfo[8]; // 0x1050 - 0x1057 }; - - - extern XFRegisters xfregs; extern u32 xfmem[XFMEM_SIZE]; diff --git a/Source/Core/VideoCommon/Src/XFStructs.cpp b/Source/Core/VideoCommon/Src/XFStructs.cpp index 21f8ba0bda..4f91c94151 100644 --- a/Source/Core/VideoCommon/Src/XFStructs.cpp +++ b/Source/Core/VideoCommon/Src/XFStructs.cpp @@ -24,193 +24,232 @@ #include "PixelShaderManager.h" #include "HW/Memmap.h" -// LoadXFReg 0x10 -void LoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData) +void XFMemWritten(u32 transferSize, u32 baseAddress) { - u32 address = baseAddress; - for (int i = 0; i < (int)transferSize; i++) + VertexManager::Flush(); + VertexShaderManager::InvalidateXFRange(baseAddress, baseAddress + transferSize); + PixelShaderManager::InvalidateXFRange(baseAddress, baseAddress + transferSize); +} + +void XFRegWritten(int transferSize, u32 baseAddress, u32 *pData) +{ + u32 address = baseAddress; + u32 dataIndex = 0; + + while (transferSize > 0 && address < 0x1058) { - address = baseAddress + i; + u32 newValue = pData[dataIndex]; + u32 nextAddress = address + 1; - // Setup a Matrix - if (address < XFMEM_ERROR) + switch (address) { - VertexManager::Flush(); - VertexShaderManager::InvalidateXFRange(address, address + transferSize); - PixelShaderManager::InvalidateXFRange(address, address + transferSize); - //PRIM_LOG("xfmem write: 0x%x-0x%x\n", address, address+transferSize); + case XFMEM_ERROR: + case XFMEM_DIAG: + case XFMEM_STATE0: // internal state 0 + case XFMEM_STATE1: // internal state 1 + case XFMEM_CLOCK: + case XFMEM_SETGPMETRIC: + nextAddress = 0x1007; + break; - memcpy_gc((u32*)&xfmem[address], &pData[i], transferSize*4); - i += transferSize; - } - else if (address >= XFMEM_SETTEXMTXINFO && address <= XFMEM_SETTEXMTXINFO+7) - { - xfregs.texcoords[address - XFMEM_SETTEXMTXINFO].texmtxinfo.hex = pData[i]; - } - else if (address >= XFMEM_SETPOSMTXINFO && address <= XFMEM_SETPOSMTXINFO+7) - { - xfregs.texcoords[address - XFMEM_SETPOSMTXINFO].postmtxinfo.hex = pData[i]; - } - else if (address >= XFMEM_SETVIEWPORT && address <= XFMEM_SETVIEWPORT+5) - { - VertexManager::Flush(); - u32 Index = address - XFMEM_SETVIEWPORT; - VertexShaderManager::SetViewport((float*)&pData[i],Index); - PixelShaderManager::SetViewport((float*)&pData[i],Index); - if(Index == 0) + case XFMEM_CLIPDISABLE: + //if (data & 1) {} // disable clipping detection + //if (data & 2) {} // disable trivial rejection + //if (data & 4) {} // disable cpoly clipping acceleration + break; + + case XFMEM_VTXSPECS: //__GXXfVtxSpecs, wrote 0004 + break; + + case XFMEM_SETNUMCHAN: + if (xfregs.numChan.numColorChans != (newValue & 3)) + VertexManager::Flush(); + break; + + case XFMEM_SETCHAN0_AMBCOLOR: // Channel Ambient Color + case XFMEM_SETCHAN1_AMBCOLOR: { - i += 5; + u8 chan = address - XFMEM_SETCHAN0_AMBCOLOR; + if (xfregs.ambColor[chan] != newValue) + { + VertexManager::Flush(); + VertexShaderManager::SetMaterialColorChanged(chan); + PixelShaderManager::SetMaterialColorChanged(chan); + } + break; } - } - else if (address >= XFMEM_SETPROJECTION && address <= XFMEM_SETPROJECTION+7) - { - VertexManager::Flush(); - u32 Index = address - XFMEM_SETPROJECTION; - VertexShaderManager::SetProjection((float*)&pData[i],Index); - if(Index == 0) + case XFMEM_SETCHAN0_MATCOLOR: // Channel Material Color + case XFMEM_SETCHAN1_MATCOLOR: { - i += 7; - } - } - else if (address < 0x2000) - { - u32 data = pData[i]; - switch (address) - { - case XFMEM_ERROR: - case XFMEM_DIAG: - case XFMEM_STATE0: // internal state 0 - case XFMEM_STATE1: // internal state 1 - case XFMEM_CLOCK: - case XFMEM_SETGPMETRIC: - break; - - case XFMEM_CLIPDISABLE: - //if (data & 1) {} // disable clipping detection - //if (data & 2) {} // disable trivial rejection - //if (data & 4) {} // disable cpoly clipping acceleration - break; - - case XFMEM_VTXSPECS: //__GXXfVtxSpecs, wrote 0004 - xfregs.hostinfo = *(INVTXSPEC*)&data; - break; - - case XFMEM_SETNUMCHAN: - if ((u32)xfregs.nNumChans != (data & 3)) + u8 chan = address - XFMEM_SETCHAN0_MATCOLOR; + if (xfregs.matColor[chan] != newValue) { - VertexManager::Flush(); - xfregs.nNumChans = data & 3; - } - break; - - case XFMEM_SETCHAN0_AMBCOLOR: // Channel Ambient Color - case XFMEM_SETCHAN1_AMBCOLOR: - { - u8 chan = address - XFMEM_SETCHAN0_AMBCOLOR; - if (xfregs.colChans[chan].ambColor != data) - { - VertexManager::Flush(); - xfregs.colChans[chan].ambColor = data; - VertexShaderManager::SetMaterialColor(chan, data); - PixelShaderManager::SetMaterialColor(chan, data); - } - break; + VertexManager::Flush(); + VertexShaderManager::SetMaterialColorChanged(chan + 2); + PixelShaderManager::SetMaterialColorChanged(chan + 2); } - - case XFMEM_SETCHAN0_MATCOLOR: // Channel Material Color - case XFMEM_SETCHAN1_MATCOLOR: - { - u8 chan = address - XFMEM_SETCHAN0_MATCOLOR; - if (xfregs.colChans[chan].matColor != data) - { - VertexManager::Flush(); - xfregs.colChans[chan].matColor = data; - VertexShaderManager::SetMaterialColor(address - XFMEM_SETCHAN0_AMBCOLOR, data); - PixelShaderManager::SetMaterialColor(address - XFMEM_SETCHAN0_AMBCOLOR, data); - } - break; - } - - case XFMEM_SETCHAN0_COLOR: // Channel Color - case XFMEM_SETCHAN1_COLOR: - { - u8 chan = address - XFMEM_SETCHAN0_COLOR; - if (xfregs.colChans[chan].color.hex != (data & 0x7fff)) - { - VertexManager::Flush(); - xfregs.colChans[chan].color.hex = data; - } - break; - } - - case XFMEM_SETCHAN0_ALPHA: // Channel Alpha - case XFMEM_SETCHAN1_ALPHA: - { - u8 chan = address - XFMEM_SETCHAN0_ALPHA; - if (xfregs.colChans[chan].alpha.hex != (data & 0x7fff)) - { - VertexManager::Flush(); - xfregs.colChans[chan].alpha.hex = data; - } - break; - } - - case XFMEM_DUALTEX: - if (xfregs.bEnableDualTexTransform != (data & 1)) - { - VertexManager::Flush(); - xfregs.bEnableDualTexTransform = data & 1; - } - break; - - - case XFMEM_SETMATRIXINDA: - //_assert_msg_(GX_XF, 0, "XF matrixindex0"); - VertexShaderManager::SetTexMatrixChangedA(data); // ? - break; - case XFMEM_SETMATRIXINDB: - //_assert_msg_(GX_XF, 0, "XF matrixindex1"); - VertexShaderManager::SetTexMatrixChangedB(data); // ? - break; - case XFMEM_SETNUMTEXGENS: // GXSetNumTexGens - if ((u32)xfregs.numTexGens != data) - { - VertexManager::Flush(); - xfregs.numTexGens = data; - } - break; - - // -------------- - // Unknown Regs - // -------------- - - // Maybe these are for Normals? - case 0x1048: //xfregs.texcoords[0].nrmmtxinfo.hex = data; break; ?? - case 0x1049: - case 0x104a: - case 0x104b: - case 0x104c: - case 0x104d: - case 0x104e: - case 0x104f: - DEBUG_LOG(VIDEO, "Possible Normal Mtx XF reg?: %x=%x\n", address, data); break; + } - case 0x1013: - case 0x1014: - case 0x1015: - case 0x1016: - case 0x1017: + case XFMEM_SETCHAN0_COLOR: // Channel Color + case XFMEM_SETCHAN1_COLOR: + case XFMEM_SETCHAN0_ALPHA: // Channel Alpha + case XFMEM_SETCHAN1_ALPHA: + if (((u32*)&xfregs)[address - 0x1000] != (newValue & 0x7fff)) + VertexManager::Flush(); + break; - default: - WARN_LOG(VIDEO, "Unknown XF Reg: %x=%x\n", address, data); - break; - } + case XFMEM_DUALTEX: + if (xfregs.dualTexTrans.enabled != (newValue & 1)) + VertexManager::Flush(); + break; + + + case XFMEM_SETMATRIXINDA: + //_assert_msg_(GX_XF, 0, "XF matrixindex0"); + VertexShaderManager::SetTexMatrixChangedA(newValue); + break; + case XFMEM_SETMATRIXINDB: + //_assert_msg_(GX_XF, 0, "XF matrixindex1"); + VertexShaderManager::SetTexMatrixChangedB(newValue); + break; + + case XFMEM_SETVIEWPORT: + case XFMEM_SETVIEWPORT+1: + case XFMEM_SETVIEWPORT+2: + case XFMEM_SETVIEWPORT+3: + case XFMEM_SETVIEWPORT+4: + case XFMEM_SETVIEWPORT+5: + VertexManager::Flush(); + VertexShaderManager::SetViewportChanged(); + PixelShaderManager::SetViewportChanged(); + + nextAddress = XFMEM_SETVIEWPORT + 6; + break; + + case XFMEM_SETPROJECTION: + case XFMEM_SETPROJECTION+1: + case XFMEM_SETPROJECTION+2: + case XFMEM_SETPROJECTION+3: + case XFMEM_SETPROJECTION+4: + case XFMEM_SETPROJECTION+5: + case XFMEM_SETPROJECTION+6: + VertexManager::Flush(); + VertexShaderManager::SetProjectionChanged(); + + nextAddress = XFMEM_SETPROJECTION + 7; + break; + + case XFMEM_SETNUMTEXGENS: // GXSetNumTexGens + if (xfregs.numTexGen.numTexGens != (newValue & 15)) + VertexManager::Flush(); + break; + + case XFMEM_SETTEXMTXINFO: + case XFMEM_SETTEXMTXINFO+1: + case XFMEM_SETTEXMTXINFO+2: + case XFMEM_SETTEXMTXINFO+3: + case XFMEM_SETTEXMTXINFO+4: + case XFMEM_SETTEXMTXINFO+5: + case XFMEM_SETTEXMTXINFO+6: + case XFMEM_SETTEXMTXINFO+7: + nextAddress = XFMEM_SETTEXMTXINFO + 8; + break; + + case XFMEM_SETPOSMTXINFO: + case XFMEM_SETPOSMTXINFO+1: + case XFMEM_SETPOSMTXINFO+2: + case XFMEM_SETPOSMTXINFO+3: + case XFMEM_SETPOSMTXINFO+4: + case XFMEM_SETPOSMTXINFO+5: + case XFMEM_SETPOSMTXINFO+6: + case XFMEM_SETPOSMTXINFO+7: + nextAddress = XFMEM_SETPOSMTXINFO + 8; + break; + + // -------------- + // Unknown Regs + // -------------- + + // Maybe these are for Normals? + case 0x1048: //xfregs.texcoords[0].nrmmtxinfo.hex = data; break; ?? + case 0x1049: + case 0x104a: + case 0x104b: + case 0x104c: + case 0x104d: + case 0x104e: + case 0x104f: + DEBUG_LOG(VIDEO, "Possible Normal Mtx XF reg?: %x=%x\n", address, newValue); + break; + + case 0x1013: + case 0x1014: + case 0x1015: + case 0x1016: + case 0x1017: + + default: + WARN_LOG(VIDEO, "Unknown XF Reg: %x=%x\n", address, newValue); + break; } + + int transferred = nextAddress - address; + address = nextAddress; + + transferSize -= transferred; + dataIndex += transferred; } } +void LoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData) +{ + // do not allow writes past registers + if (baseAddress + transferSize > 0x1058) + { + INFO_LOG(VIDEO, "xf load exceeds address space: %x %d bytes\n", baseAddress, transferSize); + + if (baseAddress >= 0x1058) + transferSize = 0; + else + 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; + } + + XFMemWritten(xfMemTransferSize, xfMemBase); + memcpy_gc(&xfmem[xfMemBase], pData, xfMemTransferSize * 4); + + pData += xfMemTransferSize; + } + + // write to XF regs + if (transferSize > 0) + { + XFRegWritten(transferSize, baseAddress, pData); + memcpy_gc((u32*)(&xfregs) + (baseAddress - 0x1000), pData, transferSize * 4); + } +} + // TODO - verify that it is correct. Seems to work, though. void LoadIndexedXF(u32 val, int array) { @@ -219,10 +258,7 @@ void LoadIndexedXF(u32 val, int array) int size = ((val >> 12) & 0xF) + 1; //load stuff from array to address in xf mem - VertexManager::Flush(); - VertexShaderManager::InvalidateXFRange(address, address+size); - PixelShaderManager::InvalidateXFRange(address, address+size); - //PRIM_LOG("xfmem iwrite: 0x%x-0x%x\n", address, address+size); + XFMemWritten(size, address); for (int i = 0; i < size; i++) xfmem[address + i] = Memory::Read_U32(arraybases[array] + arraystrides[array] * index + i * 4); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp b/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp index f3e625fc2f..d81f406e73 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp @@ -291,10 +291,10 @@ void GLVertexFormat::EnableComponents(u32 components) // TODO - Is this a good spot for this code? if (g_ActiveConfig.bDisableLighting) { - for (int i = 0; i < xfregs.nNumChans; i++) + for (int i = 0; i < xfregs.numChan.numColorChans; i++) { - xfregs.colChans[i].alpha.enablelighting = false; - xfregs.colChans[i].color.enablelighting = false; + xfregs.alpha[i].enablelighting = false; + xfregs.color[i].enablelighting = false; } } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp index c117004ec1..67cda00473 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp @@ -95,27 +95,27 @@ void VertexManager::vFlush() Flushed=true; 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.numTexGens, - xfregs.nNumChans, (int)xfregs.bEnableDualTexTransform, 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, xfregs.numTexGen.numTexGens, + xfregs.numChan.numColorChans, xfregs.dualTexTrans.enabled, bpmem.ztex2.op, bpmem.blendmode.colorupdate, bpmem.blendmode.alphaupdate, bpmem.zmode.updateenable); - for (int i = 0; i < xfregs.nNumChans; ++i) + for (unsigned int i = 0; i < xfregs.numChan.numColorChans; ++i) { - LitChannel* ch = &xfregs.colChans[i].color; + LitChannel* ch = &xfregs.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.colChans[i].alpha; + ch = &xfregs.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 (int i = 0; i < xfregs.numTexGens; ++i) + for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i) { - TexMtxInfo tinfo = xfregs.texcoords[i].texmtxinfo; + TexMtxInfo tinfo = xfregs.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.texcoords[i].postmtxinfo.index, xfregs.texcoords[i].postmtxinfo.normalize); + xfregs.postMtxInfo[i].index, xfregs.postMtxInfo[i].normalize); } PRIM_LOG("pixel: tev=%d, ind=%d, texgen=%d, dstalpha=%d, alphafunc=0x%x", bpmem.genMode.numtevstages+1, bpmem.genMode.numindstages,