VertexManagerBase: Get rid of static behavior
This commit is contained in:
parent
f1964f90d6
commit
1392efa91d
|
@ -23,7 +23,7 @@ namespace BPFunctions
|
|||
|
||||
void FlushPipeline()
|
||||
{
|
||||
VertexManagerBase::Flush();
|
||||
g_vertex_manager->Flush();
|
||||
}
|
||||
|
||||
void SetGenerationMode()
|
||||
|
|
|
@ -390,7 +390,7 @@ void RunGpuLoop()
|
|||
|
||||
// The fifo is empty and it's unlikely we will get any more work in the near future.
|
||||
// Make sure VertexManager finishes drawing any primitives it has stored in it's buffer.
|
||||
VertexManagerBase::Flush();
|
||||
g_vertex_manager->Flush();
|
||||
}
|
||||
},
|
||||
100);
|
||||
|
|
|
@ -196,7 +196,7 @@ int RunVertices(int vtx_attr_group, int primitive, int count, DataReader src, bo
|
|||
if (loader->m_native_vertex_format != s_current_vtx_fmt ||
|
||||
loader->m_native_components != g_current_components)
|
||||
{
|
||||
VertexManagerBase::Flush();
|
||||
g_vertex_manager->Flush();
|
||||
}
|
||||
s_current_vtx_fmt = loader->m_native_vertex_format;
|
||||
g_current_components = loader->m_native_components;
|
||||
|
@ -206,14 +206,14 @@ int RunVertices(int vtx_attr_group, int primitive, int count, DataReader src, bo
|
|||
// slope.
|
||||
bool cullall = (bpmem.genMode.cullmode == GenMode::CULL_ALL && primitive < 5);
|
||||
|
||||
DataReader dst = VertexManagerBase::PrepareForAdditionalData(
|
||||
DataReader dst = g_vertex_manager->PrepareForAdditionalData(
|
||||
primitive, count, loader->m_native_vtx_decl.stride, cullall);
|
||||
|
||||
count = loader->RunVertices(src, dst, count);
|
||||
|
||||
IndexGenerator::AddIndices(primitive, count);
|
||||
|
||||
VertexManagerBase::FlushData(count, loader->m_native_vtx_decl.stride);
|
||||
g_vertex_manager->FlushData(count, loader->m_native_vtx_decl.stride);
|
||||
|
||||
ADDSTAT(stats.thisFrame.numPrims, count);
|
||||
INCSTAT(stats.thisFrame.numPrimitiveJoins);
|
||||
|
|
|
@ -28,17 +28,6 @@
|
|||
|
||||
std::unique_ptr<VertexManagerBase> g_vertex_manager;
|
||||
|
||||
u8* VertexManagerBase::s_pCurBufferPointer;
|
||||
u8* VertexManagerBase::s_pBaseBufferPointer;
|
||||
u8* VertexManagerBase::s_pEndBufferPointer;
|
||||
|
||||
PrimitiveType VertexManagerBase::current_primitive_type;
|
||||
|
||||
Slope VertexManagerBase::s_zslope;
|
||||
|
||||
bool VertexManagerBase::s_is_flushed;
|
||||
bool VertexManagerBase::s_cull_all;
|
||||
|
||||
static const PrimitiveType primitive_from_gx[8] = {
|
||||
PRIMITIVE_TRIANGLES, // GX_DRAW_QUADS
|
||||
PRIMITIVE_TRIANGLES, // GX_DRAW_QUADS_2
|
||||
|
@ -52,17 +41,15 @@ static const PrimitiveType primitive_from_gx[8] = {
|
|||
|
||||
VertexManagerBase::VertexManagerBase()
|
||||
{
|
||||
s_is_flushed = true;
|
||||
s_cull_all = false;
|
||||
}
|
||||
|
||||
VertexManagerBase::~VertexManagerBase()
|
||||
{
|
||||
}
|
||||
|
||||
u32 VertexManagerBase::GetRemainingSize()
|
||||
u32 VertexManagerBase::GetRemainingSize() const
|
||||
{
|
||||
return (u32)(s_pEndBufferPointer - s_pCurBufferPointer);
|
||||
return static_cast<u32>(m_end_buffer_pointer - m_cur_buffer_pointer);
|
||||
}
|
||||
|
||||
DataReader VertexManagerBase::PrepareForAdditionalData(int primitive, u32 count, u32 stride,
|
||||
|
@ -72,12 +59,12 @@ DataReader VertexManagerBase::PrepareForAdditionalData(int primitive, u32 count,
|
|||
u32 const needed_vertex_bytes = count * stride + 4;
|
||||
|
||||
// We can't merge different kinds of primitives, so we have to flush here
|
||||
if (current_primitive_type != primitive_from_gx[primitive])
|
||||
if (m_current_primitive_type != primitive_from_gx[primitive])
|
||||
Flush();
|
||||
current_primitive_type = primitive_from_gx[primitive];
|
||||
m_current_primitive_type = primitive_from_gx[primitive];
|
||||
|
||||
// Check for size in buffer, if the buffer gets full, call Flush()
|
||||
if (!s_is_flushed &&
|
||||
if (!m_is_flushed &&
|
||||
(count > IndexGenerator::GetRemainingIndices() || count > GetRemainingIndices(primitive) ||
|
||||
needed_vertex_bytes > GetRemainingSize()))
|
||||
{
|
||||
|
@ -93,21 +80,21 @@ DataReader VertexManagerBase::PrepareForAdditionalData(int primitive, u32 count,
|
|||
"Increase MAXVBUFFERSIZE or we need primitive breaking after all.");
|
||||
}
|
||||
|
||||
s_cull_all = cullall;
|
||||
|
||||
m_cull_all = cullall;
|
||||
|
||||
// need to alloc new buffer
|
||||
if (s_is_flushed)
|
||||
if (m_is_flushed)
|
||||
{
|
||||
g_vertex_manager->ResetBuffer(stride);
|
||||
s_is_flushed = false;
|
||||
m_is_flushed = false;
|
||||
}
|
||||
|
||||
return DataReader(s_pCurBufferPointer, s_pEndBufferPointer);
|
||||
return DataReader(m_cur_buffer_pointer, m_end_buffer_pointer);
|
||||
}
|
||||
|
||||
void VertexManagerBase::FlushData(u32 count, u32 stride)
|
||||
{
|
||||
s_pCurBufferPointer += count * stride;
|
||||
m_cur_buffer_pointer += count * stride;
|
||||
}
|
||||
|
||||
u32 VertexManagerBase::GetRemainingIndices(int primitive)
|
||||
|
@ -170,7 +157,7 @@ u32 VertexManagerBase::GetRemainingIndices(int primitive)
|
|||
|
||||
void VertexManagerBase::Flush()
|
||||
{
|
||||
if (s_is_flushed)
|
||||
if (m_is_flushed)
|
||||
return;
|
||||
|
||||
// loading a state will invalidate BP, so check for it
|
||||
|
@ -215,7 +202,7 @@ void VertexManagerBase::Flush()
|
|||
|
||||
// If the primitave is marked CullAll. All we need to do is update the vertex constants and
|
||||
// calculate the zfreeze refrence slope
|
||||
if (!s_cull_all)
|
||||
if (!m_cull_all)
|
||||
{
|
||||
BitSet32 usedtextures;
|
||||
for (u32 i = 0; i < bpmem.genMode.numtevstages + 1u; ++i)
|
||||
|
@ -254,13 +241,13 @@ void VertexManagerBase::Flush()
|
|||
// Must be done after VertexShaderManager::SetConstants()
|
||||
CalculateZSlope(VertexLoaderManager::GetCurrentVertexFormat());
|
||||
}
|
||||
else if (s_zslope.dirty && !s_cull_all) // or apply any dirty ZSlopes
|
||||
else if (m_zslope.dirty && !m_cull_all) // or apply any dirty ZSlopes
|
||||
{
|
||||
PixelShaderManager::SetZSlope(s_zslope.dfdx, s_zslope.dfdy, s_zslope.f0);
|
||||
s_zslope.dirty = false;
|
||||
PixelShaderManager::SetZSlope(m_zslope.dfdx, m_zslope.dfdy, m_zslope.f0);
|
||||
m_zslope.dirty = false;
|
||||
}
|
||||
|
||||
if (!s_cull_all)
|
||||
if (!m_cull_all)
|
||||
{
|
||||
// set the rest of the global constants
|
||||
GeometryShaderManager::SetConstants();
|
||||
|
@ -283,13 +270,13 @@ void VertexManagerBase::Flush()
|
|||
"xf.numtexgens (%d) does not match bp.numtexgens (%d). Error in command stream.",
|
||||
xfmem.numTexGen.numTexGens, bpmem.genMode.numtexgens.Value());
|
||||
|
||||
s_is_flushed = true;
|
||||
s_cull_all = false;
|
||||
m_is_flushed = true;
|
||||
m_cull_all = false;
|
||||
}
|
||||
|
||||
void VertexManagerBase::DoState(PointerWrap& p)
|
||||
{
|
||||
p.Do(s_zslope);
|
||||
p.Do(m_zslope);
|
||||
g_vertex_manager->vDoState(p);
|
||||
}
|
||||
|
||||
|
@ -299,7 +286,7 @@ void VertexManagerBase::CalculateZSlope(NativeVertexFormat* format)
|
|||
float viewOffset[2] = {xfmem.viewport.xOrig - bpmem.scissorOffset.x * 2,
|
||||
xfmem.viewport.yOrig - bpmem.scissorOffset.y * 2};
|
||||
|
||||
if (current_primitive_type != PRIMITIVE_TRIANGLES)
|
||||
if (m_current_primitive_type != PRIMITIVE_TRIANGLES)
|
||||
return;
|
||||
|
||||
// Global matrix ID.
|
||||
|
@ -307,7 +294,7 @@ void VertexManagerBase::CalculateZSlope(NativeVertexFormat* format)
|
|||
const PortableVertexDeclaration vert_decl = format->GetVertexDeclaration();
|
||||
|
||||
// Make sure the buffer contains at least 3 vertices.
|
||||
if ((s_pCurBufferPointer - s_pBaseBufferPointer) < (vert_decl.stride * 3))
|
||||
if ((m_cur_buffer_pointer - m_base_buffer_pointer) < (vert_decl.stride * 3))
|
||||
return;
|
||||
|
||||
// Lookup vertices of the last rendered triangle and software-transform them
|
||||
|
@ -348,8 +335,8 @@ void VertexManagerBase::CalculateZSlope(NativeVertexFormat* format)
|
|||
if (c == 0)
|
||||
return;
|
||||
|
||||
s_zslope.dfdx = -a / c;
|
||||
s_zslope.dfdy = -b / c;
|
||||
s_zslope.f0 = out[2] - (out[0] * s_zslope.dfdx + out[1] * s_zslope.dfdy);
|
||||
s_zslope.dirty = true;
|
||||
m_zslope.dfdx = -a / c;
|
||||
m_zslope.dfdy = -b / c;
|
||||
m_zslope.f0 = out[2] - (out[0] * m_zslope.dfdx + out[1] * m_zslope.dfdy);
|
||||
m_zslope.dirty = true;
|
||||
}
|
||||
|
|
|
@ -50,36 +50,36 @@ public:
|
|||
// needs to be virtual for DX11's dtor
|
||||
virtual ~VertexManagerBase();
|
||||
|
||||
static DataReader PrepareForAdditionalData(int primitive, u32 count, u32 stride, bool cullall);
|
||||
static void FlushData(u32 count, u32 stride);
|
||||
DataReader PrepareForAdditionalData(int primitive, u32 count, u32 stride, bool cullall);
|
||||
void FlushData(u32 count, u32 stride);
|
||||
|
||||
static void Flush();
|
||||
void Flush();
|
||||
|
||||
virtual NativeVertexFormat*
|
||||
CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) = 0;
|
||||
|
||||
static void DoState(PointerWrap& p);
|
||||
void DoState(PointerWrap& p);
|
||||
|
||||
protected:
|
||||
virtual void vDoState(PointerWrap& p) {}
|
||||
static PrimitiveType current_primitive_type;
|
||||
PrimitiveType m_current_primitive_type = PrimitiveType::PRIMITIVE_POINTS;
|
||||
|
||||
virtual void ResetBuffer(u32 stride) = 0;
|
||||
|
||||
static u8* s_pCurBufferPointer;
|
||||
static u8* s_pBaseBufferPointer;
|
||||
static u8* s_pEndBufferPointer;
|
||||
u8* m_cur_buffer_pointer = nullptr;
|
||||
u8* m_base_buffer_pointer = nullptr;
|
||||
u8* m_end_buffer_pointer = nullptr;
|
||||
|
||||
static u32 GetRemainingSize();
|
||||
u32 GetRemainingSize() const;
|
||||
static u32 GetRemainingIndices(int primitive);
|
||||
|
||||
static Slope s_zslope;
|
||||
static void CalculateZSlope(NativeVertexFormat* format);
|
||||
Slope m_zslope = {};
|
||||
void CalculateZSlope(NativeVertexFormat* format);
|
||||
|
||||
static bool s_cull_all;
|
||||
bool m_cull_all = false;
|
||||
|
||||
private:
|
||||
static bool s_is_flushed;
|
||||
bool m_is_flushed = true;
|
||||
|
||||
virtual void vFlush(bool useDstAlpha) = 0;
|
||||
|
||||
|
|
|
@ -676,7 +676,7 @@ void VertexShaderManager::SetTexMatrixChangedA(u32 Value)
|
|||
{
|
||||
if (g_main_cp_state.matrix_index_a.Hex != Value)
|
||||
{
|
||||
VertexManagerBase::Flush();
|
||||
g_vertex_manager->Flush();
|
||||
if (g_main_cp_state.matrix_index_a.PosNormalMtxIdx != (Value & 0x3f))
|
||||
bPosNormalMatrixChanged = true;
|
||||
bTexMatricesChanged[0] = true;
|
||||
|
@ -688,7 +688,7 @@ void VertexShaderManager::SetTexMatrixChangedB(u32 Value)
|
|||
{
|
||||
if (g_main_cp_state.matrix_index_b.Hex != Value)
|
||||
{
|
||||
VertexManagerBase::Flush();
|
||||
g_vertex_manager->Flush();
|
||||
bTexMatricesChanged[1] = true;
|
||||
g_main_cp_state.matrix_index_b.Hex = Value;
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ void VideoCommon_DoState(PointerWrap& p)
|
|||
GeometryShaderManager::DoState(p);
|
||||
p.DoMarker("GeometryShaderManager");
|
||||
|
||||
VertexManagerBase::DoState(p);
|
||||
g_vertex_manager->DoState(p);
|
||||
p.DoMarker("VertexManager");
|
||||
|
||||
BoundingBox::DoState(p);
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
static void XFMemWritten(u32 transferSize, u32 baseAddress)
|
||||
{
|
||||
VertexManagerBase::Flush();
|
||||
g_vertex_manager->Flush();
|
||||
VertexShaderManager::InvalidateXFRange(baseAddress, baseAddress + transferSize);
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ static void XFRegWritten(int transferSize, u32 baseAddress, DataReader src)
|
|||
|
||||
case XFMEM_SETNUMCHAN:
|
||||
if (xfmem.numChan.numColorChans != (newValue & 3))
|
||||
VertexManagerBase::Flush();
|
||||
g_vertex_manager->Flush();
|
||||
break;
|
||||
|
||||
case XFMEM_SETCHAN0_AMBCOLOR: // Channel Ambient Color
|
||||
|
@ -62,7 +62,7 @@ static void XFRegWritten(int transferSize, u32 baseAddress, DataReader src)
|
|||
u8 chan = address - XFMEM_SETCHAN0_AMBCOLOR;
|
||||
if (xfmem.ambColor[chan] != newValue)
|
||||
{
|
||||
VertexManagerBase::Flush();
|
||||
g_vertex_manager->Flush();
|
||||
VertexShaderManager::SetMaterialColorChanged(chan);
|
||||
}
|
||||
break;
|
||||
|
@ -74,7 +74,7 @@ static void XFRegWritten(int transferSize, u32 baseAddress, DataReader src)
|
|||
u8 chan = address - XFMEM_SETCHAN0_MATCOLOR;
|
||||
if (xfmem.matColor[chan] != newValue)
|
||||
{
|
||||
VertexManagerBase::Flush();
|
||||
g_vertex_manager->Flush();
|
||||
VertexShaderManager::SetMaterialColorChanged(chan + 2);
|
||||
}
|
||||
break;
|
||||
|
@ -85,12 +85,12 @@ static void XFRegWritten(int transferSize, u32 baseAddress, DataReader src)
|
|||
case XFMEM_SETCHAN0_ALPHA: // Channel Alpha
|
||||
case XFMEM_SETCHAN1_ALPHA:
|
||||
if (((u32*)&xfmem)[address] != (newValue & 0x7fff))
|
||||
VertexManagerBase::Flush();
|
||||
g_vertex_manager->Flush();
|
||||
break;
|
||||
|
||||
case XFMEM_DUALTEX:
|
||||
if (xfmem.dualTexTrans.enabled != (newValue & 1))
|
||||
VertexManagerBase::Flush();
|
||||
g_vertex_manager->Flush();
|
||||
break;
|
||||
|
||||
case XFMEM_SETMATRIXINDA:
|
||||
|
@ -108,7 +108,7 @@ static void XFRegWritten(int transferSize, u32 baseAddress, DataReader src)
|
|||
case XFMEM_SETVIEWPORT + 3:
|
||||
case XFMEM_SETVIEWPORT + 4:
|
||||
case XFMEM_SETVIEWPORT + 5:
|
||||
VertexManagerBase::Flush();
|
||||
g_vertex_manager->Flush();
|
||||
VertexShaderManager::SetViewportChanged();
|
||||
PixelShaderManager::SetViewportChanged();
|
||||
GeometryShaderManager::SetViewportChanged();
|
||||
|
@ -123,7 +123,7 @@ static void XFRegWritten(int transferSize, u32 baseAddress, DataReader src)
|
|||
case XFMEM_SETPROJECTION + 4:
|
||||
case XFMEM_SETPROJECTION + 5:
|
||||
case XFMEM_SETPROJECTION + 6:
|
||||
VertexManagerBase::Flush();
|
||||
g_vertex_manager->Flush();
|
||||
VertexShaderManager::SetProjectionChanged();
|
||||
GeometryShaderManager::SetProjectionChanged();
|
||||
|
||||
|
@ -132,7 +132,7 @@ static void XFRegWritten(int transferSize, u32 baseAddress, DataReader src)
|
|||
|
||||
case XFMEM_SETNUMTEXGENS: // GXSetNumTexGens
|
||||
if (xfmem.numTexGen.numTexGens != (newValue & 15))
|
||||
VertexManagerBase::Flush();
|
||||
g_vertex_manager->Flush();
|
||||
break;
|
||||
|
||||
case XFMEM_SETTEXMTXINFO:
|
||||
|
@ -143,7 +143,7 @@ static void XFRegWritten(int transferSize, u32 baseAddress, DataReader src)
|
|||
case XFMEM_SETTEXMTXINFO + 5:
|
||||
case XFMEM_SETTEXMTXINFO + 6:
|
||||
case XFMEM_SETTEXMTXINFO + 7:
|
||||
VertexManagerBase::Flush();
|
||||
g_vertex_manager->Flush();
|
||||
|
||||
nextAddress = XFMEM_SETTEXMTXINFO + 8;
|
||||
break;
|
||||
|
@ -156,7 +156,7 @@ static void XFRegWritten(int transferSize, u32 baseAddress, DataReader src)
|
|||
case XFMEM_SETPOSMTXINFO + 5:
|
||||
case XFMEM_SETPOSMTXINFO + 6:
|
||||
case XFMEM_SETPOSMTXINFO + 7:
|
||||
VertexManagerBase::Flush();
|
||||
g_vertex_manager->Flush();
|
||||
|
||||
nextAddress = XFMEM_SETPOSMTXINFO + 8;
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue