Convert some VideoCommon stuff to BitSet.
Now with a minor performance improvement removed for no reason.
This commit is contained in:
parent
f51c233a08
commit
b29e5146ec
|
@ -4,6 +4,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "Common/BitSet.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
// Vertex array numbers
|
||||
|
@ -252,7 +253,7 @@ struct CPState final
|
|||
VAT vtx_attr[8];
|
||||
|
||||
// Attributes that actually belong to VertexLoaderManager:
|
||||
int attr_dirty; // bitfield
|
||||
BitSet32 attr_dirty;
|
||||
VertexLoader* vertex_loaders[8];
|
||||
};
|
||||
|
||||
|
|
|
@ -100,14 +100,14 @@ void AppendListToString(std::string *dest)
|
|||
|
||||
void MarkAllDirty()
|
||||
{
|
||||
g_main_cp_state.attr_dirty = 0xff;
|
||||
g_preprocess_cp_state.attr_dirty = 0xff;
|
||||
g_main_cp_state.attr_dirty = BitSet32::AllTrue(8);
|
||||
g_preprocess_cp_state.attr_dirty = BitSet32::AllTrue(8);
|
||||
}
|
||||
|
||||
static VertexLoader* RefreshLoader(int vtx_attr_group, CPState* state)
|
||||
{
|
||||
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]);
|
||||
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);
|
||||
}
|
||||
state->vertex_loaders[vtx_attr_group] = loader;
|
||||
state->attr_dirty &= ~(1 << vtx_attr_group);
|
||||
state->attr_dirty[vtx_attr_group] = false;
|
||||
} else {
|
||||
loader = state->vertex_loaders[vtx_attr_group];
|
||||
}
|
||||
|
@ -200,31 +200,31 @@ void LoadCPReg(u32 sub_cmd, u32 value, bool is_preprocess)
|
|||
case 0x50:
|
||||
state->vtx_desc.Hex &= ~0x1FFFF; // keep the Upper bits
|
||||
state->vtx_desc.Hex |= value;
|
||||
state->attr_dirty = 0xFF;
|
||||
state->attr_dirty = BitSet32::AllTrue(8);
|
||||
break;
|
||||
|
||||
case 0x60:
|
||||
state->vtx_desc.Hex &= 0x1FFFF; // keep the lower 17Bits
|
||||
state->vtx_desc.Hex |= (u64)value << 17;
|
||||
state->attr_dirty = 0xFF;
|
||||
state->attr_dirty = BitSet32::AllTrue(8);
|
||||
break;
|
||||
|
||||
case 0x70:
|
||||
_assert_((sub_cmd & 0x0F) < 8);
|
||||
state->vtx_attr[sub_cmd & 7].g0.Hex = value;
|
||||
state->attr_dirty |= 1 << (sub_cmd & 7);
|
||||
state->attr_dirty[sub_cmd & 7] = true;
|
||||
break;
|
||||
|
||||
case 0x80:
|
||||
_assert_((sub_cmd & 0x0F) < 8);
|
||||
state->vtx_attr[sub_cmd & 7].g1.Hex = value;
|
||||
state->attr_dirty |= 1 << (sub_cmd & 7);
|
||||
state->attr_dirty[sub_cmd & 7] = true;
|
||||
break;
|
||||
|
||||
case 0x90:
|
||||
_assert_((sub_cmd & 0x0F) < 8);
|
||||
state->vtx_attr[sub_cmd & 7].g2.Hex = value;
|
||||
state->attr_dirty |= 1 << (sub_cmd & 7);
|
||||
state->attr_dirty[sub_cmd & 7] = true;
|
||||
break;
|
||||
|
||||
// Pointers to vertex arrays in GC RAM
|
||||
|
|
|
@ -180,39 +180,36 @@ void VertexManager::Flush()
|
|||
(int)bpmem.genMode.numtexgens, (u32)bpmem.dstalpha.enable, (bpmem.alpha_test.hex>>16)&0xff);
|
||||
#endif
|
||||
|
||||
u32 usedtextures = 0;
|
||||
BitSet32 usedtextures;
|
||||
for (u32 i = 0; i < bpmem.genMode.numtevstages + 1u; ++i)
|
||||
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)
|
||||
for (unsigned int i = 0; i < bpmem.genMode.numtevstages + 1u; ++i)
|
||||
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);
|
||||
const FourTexUnits &tex = bpmem.tex[i >> 2];
|
||||
const TextureCache::TCacheEntryBase* tentry = TextureCache::Load(i,
|
||||
(tex.texImage3[i&3].image_base/* & 0x1FFFFF*/) << 5,
|
||||
tex.texImage0[i&3].width + 1, tex.texImage0[i&3].height + 1,
|
||||
tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9,
|
||||
tex.texTlut[i&3].tlut_format,
|
||||
((tex.texMode0[i&3].min_filter & 3) != 0),
|
||||
(tex.texMode1[i&3].max_lod + 0xf) / 0x10,
|
||||
(tex.texImage1[i&3].image_type != 0));
|
||||
g_renderer->SetSamplerState(i & 3, i >> 2);
|
||||
const FourTexUnits &tex = bpmem.tex[i >> 2];
|
||||
const TextureCache::TCacheEntryBase* tentry = TextureCache::Load(i,
|
||||
(tex.texImage3[i&3].image_base/* & 0x1FFFFF*/) << 5,
|
||||
tex.texImage0[i&3].width + 1, tex.texImage0[i&3].height + 1,
|
||||
tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9,
|
||||
tex.texTlut[i&3].tlut_format,
|
||||
((tex.texMode0[i&3].min_filter & 3) != 0),
|
||||
(tex.texMode1[i&3].max_lod + 0xf) / 0x10,
|
||||
(tex.texImage1[i&3].image_type != 0));
|
||||
|
||||
if (tentry)
|
||||
{
|
||||
// 0s are probably for no manual wrapping needed.
|
||||
PixelShaderManager::SetTexDims(i, tentry->native_width, tentry->native_height, 0, 0);
|
||||
}
|
||||
else
|
||||
ERROR_LOG(VIDEO, "error loading texture");
|
||||
if (tentry)
|
||||
{
|
||||
// 0s are probably for no manual wrapping needed.
|
||||
PixelShaderManager::SetTexDims(i, tentry->native_width, tentry->native_height, 0, 0);
|
||||
}
|
||||
else
|
||||
ERROR_LOG(VIDEO, "error loading texture");
|
||||
}
|
||||
|
||||
// set global constants
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <cmath>
|
||||
#include <sstream>
|
||||
|
||||
#include "Common/BitSet.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/MathUtil.h"
|
||||
#include "VideoCommon/BPMemory.h"
|
||||
|
@ -22,7 +23,7 @@ static float GC_ALIGNED16(g_fProjectionMatrix[16]);
|
|||
|
||||
// track changes
|
||||
static bool bTexMatricesChanged[2], bPosNormalMatrixChanged, bProjectionChanged, bViewportChanged;
|
||||
static int nMaterialsChanged;
|
||||
static BitSet32 nMaterialsChanged;
|
||||
static int nTransformMatricesChanged[2]; // min,max
|
||||
static int nNormalMatricesChanged[2]; // min,max
|
||||
static int nPostTransformMatricesChanged[2]; // min,max
|
||||
|
@ -202,7 +203,7 @@ void VertexShaderManager::Dirty()
|
|||
|
||||
bProjectionChanged = true;
|
||||
|
||||
nMaterialsChanged = 15;
|
||||
nMaterialsChanged = BitSet32::AllTrue(4);
|
||||
|
||||
dirty = true;
|
||||
}
|
||||
|
@ -295,35 +296,16 @@ void VertexShaderManager::SetConstants()
|
|||
nLightsChanged[0] = nLightsChanged[1] = -1;
|
||||
}
|
||||
|
||||
if (nMaterialsChanged)
|
||||
for (int i : nMaterialsChanged)
|
||||
{
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
if (nMaterialsChanged & (1 << i))
|
||||
{
|
||||
u32 data = xfmem.ambColor[i];
|
||||
constants.materials[i][0] = (data >> 24) & 0xFF;
|
||||
constants.materials[i][1] = (data >> 16) & 0xFF;
|
||||
constants.materials[i][2] = (data >> 8) & 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;
|
||||
}
|
||||
}
|
||||
u32 data = i >= 2 ? xfmem.matColor[i - 2] : xfmem.ambColor[i];
|
||||
constants.materials[i][0] = (data >> 24) & 0xFF;
|
||||
constants.materials[i][1] = (data >> 16) & 0xFF;
|
||||
constants.materials[i][2] = (data >> 8) & 0xFF;
|
||||
constants.materials[i][3] = data & 0xFF;
|
||||
dirty = true;
|
||||
|
||||
nMaterialsChanged = 0;
|
||||
}
|
||||
nMaterialsChanged = BitSet32(0);
|
||||
|
||||
if (bPosNormalMatrixChanged)
|
||||
{
|
||||
|
@ -660,7 +642,7 @@ void VertexShaderManager::SetProjectionChanged()
|
|||
|
||||
void VertexShaderManager::SetMaterialColorChanged(int index, u32 color)
|
||||
{
|
||||
nMaterialsChanged |= (1 << index);
|
||||
nMaterialsChanged[index] = true;
|
||||
}
|
||||
|
||||
void VertexShaderManager::TranslateView(float x, float y, float z)
|
||||
|
|
Loading…
Reference in New Issue