Convert some VideoCommon stuff to BitSet.

Now with a minor performance improvement removed for no reason.
This commit is contained in:
comex 2014-10-21 20:42:55 -04:00
parent f51c233a08
commit b29e5146ec
4 changed files with 42 additions and 62 deletions

View File

@ -4,6 +4,7 @@
#pragma once #pragma once
#include "Common/BitSet.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
// Vertex array numbers // Vertex array numbers
@ -252,7 +253,7 @@ struct CPState final
VAT vtx_attr[8]; VAT vtx_attr[8];
// Attributes that actually belong to VertexLoaderManager: // Attributes that actually belong to VertexLoaderManager:
int attr_dirty; // bitfield BitSet32 attr_dirty;
VertexLoader* vertex_loaders[8]; VertexLoader* vertex_loaders[8];
}; };

View File

@ -100,14 +100,14 @@ void AppendListToString(std::string *dest)
void MarkAllDirty() void MarkAllDirty()
{ {
g_main_cp_state.attr_dirty = 0xff; g_main_cp_state.attr_dirty = BitSet32::AllTrue(8);
g_preprocess_cp_state.attr_dirty = 0xff; g_preprocess_cp_state.attr_dirty = BitSet32::AllTrue(8);
} }
static VertexLoader* RefreshLoader(int vtx_attr_group, CPState* state) static VertexLoader* RefreshLoader(int vtx_attr_group, CPState* state)
{ {
VertexLoader* loader; VertexLoader* loader;
if ((state->attr_dirty >> vtx_attr_group) & 1) if (state->attr_dirty[vtx_attr_group])
{ {
VertexLoaderUID uid(state->vtx_desc, state->vtx_attr[vtx_attr_group]); VertexLoaderUID uid(state->vtx_desc, state->vtx_attr[vtx_attr_group]);
std::lock_guard<std::mutex> lk(s_vertex_loader_map_lock); std::lock_guard<std::mutex> lk(s_vertex_loader_map_lock);
@ -123,7 +123,7 @@ static VertexLoader* RefreshLoader(int vtx_attr_group, CPState* state)
INCSTAT(stats.numVertexLoaders); INCSTAT(stats.numVertexLoaders);
} }
state->vertex_loaders[vtx_attr_group] = loader; state->vertex_loaders[vtx_attr_group] = loader;
state->attr_dirty &= ~(1 << vtx_attr_group); state->attr_dirty[vtx_attr_group] = false;
} else { } else {
loader = state->vertex_loaders[vtx_attr_group]; loader = state->vertex_loaders[vtx_attr_group];
} }
@ -200,31 +200,31 @@ void LoadCPReg(u32 sub_cmd, u32 value, bool is_preprocess)
case 0x50: case 0x50:
state->vtx_desc.Hex &= ~0x1FFFF; // keep the Upper bits state->vtx_desc.Hex &= ~0x1FFFF; // keep the Upper bits
state->vtx_desc.Hex |= value; state->vtx_desc.Hex |= value;
state->attr_dirty = 0xFF; state->attr_dirty = BitSet32::AllTrue(8);
break; break;
case 0x60: case 0x60:
state->vtx_desc.Hex &= 0x1FFFF; // keep the lower 17Bits state->vtx_desc.Hex &= 0x1FFFF; // keep the lower 17Bits
state->vtx_desc.Hex |= (u64)value << 17; state->vtx_desc.Hex |= (u64)value << 17;
state->attr_dirty = 0xFF; state->attr_dirty = BitSet32::AllTrue(8);
break; break;
case 0x70: case 0x70:
_assert_((sub_cmd & 0x0F) < 8); _assert_((sub_cmd & 0x0F) < 8);
state->vtx_attr[sub_cmd & 7].g0.Hex = value; state->vtx_attr[sub_cmd & 7].g0.Hex = value;
state->attr_dirty |= 1 << (sub_cmd & 7); state->attr_dirty[sub_cmd & 7] = true;
break; break;
case 0x80: case 0x80:
_assert_((sub_cmd & 0x0F) < 8); _assert_((sub_cmd & 0x0F) < 8);
state->vtx_attr[sub_cmd & 7].g1.Hex = value; state->vtx_attr[sub_cmd & 7].g1.Hex = value;
state->attr_dirty |= 1 << (sub_cmd & 7); state->attr_dirty[sub_cmd & 7] = true;
break; break;
case 0x90: case 0x90:
_assert_((sub_cmd & 0x0F) < 8); _assert_((sub_cmd & 0x0F) < 8);
state->vtx_attr[sub_cmd & 7].g2.Hex = value; state->vtx_attr[sub_cmd & 7].g2.Hex = value;
state->attr_dirty |= 1 << (sub_cmd & 7); state->attr_dirty[sub_cmd & 7] = true;
break; break;
// Pointers to vertex arrays in GC RAM // Pointers to vertex arrays in GC RAM

View File

@ -180,19 +180,17 @@ void VertexManager::Flush()
(int)bpmem.genMode.numtexgens, (u32)bpmem.dstalpha.enable, (bpmem.alpha_test.hex>>16)&0xff); (int)bpmem.genMode.numtexgens, (u32)bpmem.dstalpha.enable, (bpmem.alpha_test.hex>>16)&0xff);
#endif #endif
u32 usedtextures = 0; BitSet32 usedtextures;
for (u32 i = 0; i < bpmem.genMode.numtevstages + 1u; ++i) for (u32 i = 0; i < bpmem.genMode.numtevstages + 1u; ++i)
if (bpmem.tevorders[i / 2].getEnable(i & 1)) if (bpmem.tevorders[i / 2].getEnable(i & 1))
usedtextures |= 1 << bpmem.tevorders[i/2].getTexMap(i & 1); usedtextures[bpmem.tevorders[i/2].getTexMap(i & 1)] = true;
if (bpmem.genMode.numindstages > 0) if (bpmem.genMode.numindstages > 0)
for (unsigned int i = 0; i < bpmem.genMode.numtevstages + 1u; ++i) for (unsigned int i = 0; i < bpmem.genMode.numtevstages + 1u; ++i)
if (bpmem.tevind[i].IsActive() && bpmem.tevind[i].bt < bpmem.genMode.numindstages) if (bpmem.tevind[i].IsActive() && bpmem.tevind[i].bt < bpmem.genMode.numindstages)
usedtextures |= 1 << bpmem.tevindref.getTexMap(bpmem.tevind[i].bt); usedtextures[bpmem.tevindref.getTexMap(bpmem.tevind[i].bt)] = true;
for (unsigned int i = 0; i < 8; i++) for (unsigned int i : usedtextures)
{
if (usedtextures & (1 << i))
{ {
g_renderer->SetSamplerState(i & 3, i >> 2); g_renderer->SetSamplerState(i & 3, i >> 2);
const FourTexUnits &tex = bpmem.tex[i >> 2]; const FourTexUnits &tex = bpmem.tex[i >> 2];
@ -213,7 +211,6 @@ void VertexManager::Flush()
else else
ERROR_LOG(VIDEO, "error loading texture"); ERROR_LOG(VIDEO, "error loading texture");
} }
}
// set global constants // set global constants
VertexShaderManager::SetConstants(); VertexShaderManager::SetConstants();

View File

@ -5,6 +5,7 @@
#include <cmath> #include <cmath>
#include <sstream> #include <sstream>
#include "Common/BitSet.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/MathUtil.h" #include "Common/MathUtil.h"
#include "VideoCommon/BPMemory.h" #include "VideoCommon/BPMemory.h"
@ -22,7 +23,7 @@ static float GC_ALIGNED16(g_fProjectionMatrix[16]);
// track changes // track changes
static bool bTexMatricesChanged[2], bPosNormalMatrixChanged, bProjectionChanged, bViewportChanged; static bool bTexMatricesChanged[2], bPosNormalMatrixChanged, bProjectionChanged, bViewportChanged;
static int nMaterialsChanged; static BitSet32 nMaterialsChanged;
static int nTransformMatricesChanged[2]; // min,max static int nTransformMatricesChanged[2]; // min,max
static int nNormalMatricesChanged[2]; // min,max static int nNormalMatricesChanged[2]; // min,max
static int nPostTransformMatricesChanged[2]; // min,max static int nPostTransformMatricesChanged[2]; // min,max
@ -202,7 +203,7 @@ void VertexShaderManager::Dirty()
bProjectionChanged = true; bProjectionChanged = true;
nMaterialsChanged = 15; nMaterialsChanged = BitSet32::AllTrue(4);
dirty = true; dirty = true;
} }
@ -295,35 +296,16 @@ void VertexShaderManager::SetConstants()
nLightsChanged[0] = nLightsChanged[1] = -1; nLightsChanged[0] = nLightsChanged[1] = -1;
} }
if (nMaterialsChanged) for (int i : nMaterialsChanged)
{ {
for (int i = 0; i < 2; ++i) u32 data = i >= 2 ? xfmem.matColor[i - 2] : xfmem.ambColor[i];
{
if (nMaterialsChanged & (1 << i))
{
u32 data = xfmem.ambColor[i];
constants.materials[i][0] = (data >> 24) & 0xFF; constants.materials[i][0] = (data >> 24) & 0xFF;
constants.materials[i][1] = (data >> 16) & 0xFF; constants.materials[i][1] = (data >> 16) & 0xFF;
constants.materials[i][2] = (data >> 8) & 0xFF; constants.materials[i][2] = (data >> 8) & 0xFF;
constants.materials[i][3] = data & 0xFF; constants.materials[i][3] = data & 0xFF;
}
}
for (int i = 0; i < 2; ++i)
{
if (nMaterialsChanged & (1 << (i + 2)))
{
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;
constants.materials[i+2][3] = data & 0xFF;
}
}
dirty = true; dirty = true;
nMaterialsChanged = 0;
} }
nMaterialsChanged = BitSet32(0);
if (bPosNormalMatrixChanged) if (bPosNormalMatrixChanged)
{ {
@ -660,7 +642,7 @@ void VertexShaderManager::SetProjectionChanged()
void VertexShaderManager::SetMaterialColorChanged(int index, u32 color) void VertexShaderManager::SetMaterialColorChanged(int index, u32 color)
{ {
nMaterialsChanged |= (1 << index); nMaterialsChanged[index] = true;
} }
void VertexShaderManager::TranslateView(float x, float y, float z) void VertexShaderManager::TranslateView(float x, float y, float z)