Merge pull request #4141 from lioncash/vtx
VertexManagerBase: Get rid of static state
This commit is contained in:
commit
52af0770c3
|
@ -61,8 +61,8 @@ VertexManager::VertexManager()
|
||||||
{
|
{
|
||||||
LocalVBuffer.resize(MAXVBUFFERSIZE);
|
LocalVBuffer.resize(MAXVBUFFERSIZE);
|
||||||
|
|
||||||
s_pCurBufferPointer = s_pBaseBufferPointer = &LocalVBuffer[0];
|
m_cur_buffer_pointer = m_base_buffer_pointer = &LocalVBuffer[0];
|
||||||
s_pEndBufferPointer = s_pBaseBufferPointer + LocalVBuffer.size();
|
m_end_buffer_pointer = m_base_buffer_pointer + LocalVBuffer.size();
|
||||||
|
|
||||||
LocalIBuffer.resize(MAXIBUFFERSIZE);
|
LocalIBuffer.resize(MAXIBUFFERSIZE);
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ void VertexManager::PrepareDrawBuffers(u32 stride)
|
||||||
{
|
{
|
||||||
D3D11_MAPPED_SUBRESOURCE map;
|
D3D11_MAPPED_SUBRESOURCE map;
|
||||||
|
|
||||||
u32 vertexBufferSize = u32(s_pCurBufferPointer - s_pBaseBufferPointer);
|
u32 vertexBufferSize = u32(m_cur_buffer_pointer - m_base_buffer_pointer);
|
||||||
u32 indexBufferSize = IndexGenerator::GetIndexLen() * sizeof(u16);
|
u32 indexBufferSize = IndexGenerator::GetIndexLen() * sizeof(u16);
|
||||||
u32 totalBufferSize = vertexBufferSize + indexBufferSize;
|
u32 totalBufferSize = vertexBufferSize + indexBufferSize;
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ void VertexManager::PrepareDrawBuffers(u32 stride)
|
||||||
|
|
||||||
D3D::context->Map(m_buffers[m_currentBuffer], 0, MapType, 0, &map);
|
D3D::context->Map(m_buffers[m_currentBuffer], 0, MapType, 0, &map);
|
||||||
u8* mappedData = reinterpret_cast<u8*>(map.pData);
|
u8* mappedData = reinterpret_cast<u8*>(map.pData);
|
||||||
memcpy(mappedData + m_vertexDrawOffset, s_pBaseBufferPointer, vertexBufferSize);
|
memcpy(mappedData + m_vertexDrawOffset, m_base_buffer_pointer, vertexBufferSize);
|
||||||
memcpy(mappedData + m_indexDrawOffset, GetIndexBuffer(), indexBufferSize);
|
memcpy(mappedData + m_indexDrawOffset, GetIndexBuffer(), indexBufferSize);
|
||||||
D3D::context->Unmap(m_buffers[m_currentBuffer], 0);
|
D3D::context->Unmap(m_buffers[m_currentBuffer], 0);
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ void VertexManager::Draw(u32 stride)
|
||||||
u32 baseVertex = m_vertexDrawOffset / stride;
|
u32 baseVertex = m_vertexDrawOffset / stride;
|
||||||
u32 startIndex = m_indexDrawOffset / sizeof(u16);
|
u32 startIndex = m_indexDrawOffset / sizeof(u16);
|
||||||
|
|
||||||
switch (current_primitive_type)
|
switch (m_current_primitive_type)
|
||||||
{
|
{
|
||||||
case PRIMITIVE_POINTS:
|
case PRIMITIVE_POINTS:
|
||||||
D3D::stateman->SetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
|
D3D::stateman->SetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
|
||||||
|
@ -143,7 +143,7 @@ void VertexManager::Draw(u32 stride)
|
||||||
|
|
||||||
INCSTAT(stats.thisFrame.numDrawCalls);
|
INCSTAT(stats.thisFrame.numDrawCalls);
|
||||||
|
|
||||||
if (current_primitive_type != PRIMITIVE_TRIANGLES)
|
if (m_current_primitive_type != PRIMITIVE_TRIANGLES)
|
||||||
static_cast<Renderer*>(g_renderer.get())->RestoreCull();
|
static_cast<Renderer*>(g_renderer.get())->RestoreCull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ void VertexManager::vFlush(bool useDstAlpha)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GeometryShaderCache::SetShader(current_primitive_type))
|
if (!GeometryShaderCache::SetShader(m_current_primitive_type))
|
||||||
{
|
{
|
||||||
GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR, true, { printf("Fail to set pixel shader\n"); });
|
GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR, true, { printf("Fail to set pixel shader\n"); });
|
||||||
return;
|
return;
|
||||||
|
@ -188,7 +188,7 @@ void VertexManager::vFlush(bool useDstAlpha)
|
||||||
|
|
||||||
void VertexManager::ResetBuffer(u32 stride)
|
void VertexManager::ResetBuffer(u32 stride)
|
||||||
{
|
{
|
||||||
s_pCurBufferPointer = s_pBaseBufferPointer;
|
m_cur_buffer_pointer = m_base_buffer_pointer;
|
||||||
IndexGenerator::Start(GetIndexBuffer());
|
IndexGenerator::Start(GetIndexBuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ void VertexManager::Draw(u32 stride)
|
||||||
|
|
||||||
D3D_PRIMITIVE_TOPOLOGY d3d_primitive_topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP;
|
D3D_PRIMITIVE_TOPOLOGY d3d_primitive_topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP;
|
||||||
|
|
||||||
switch (current_primitive_type)
|
switch (m_current_primitive_type)
|
||||||
{
|
{
|
||||||
case PRIMITIVE_POINTS:
|
case PRIMITIVE_POINTS:
|
||||||
d3d_primitive_topology = D3D_PRIMITIVE_TOPOLOGY_POINTLIST;
|
d3d_primitive_topology = D3D_PRIMITIVE_TOPOLOGY_POINTLIST;
|
||||||
|
@ -138,7 +138,7 @@ void VertexManager::Draw(u32 stride)
|
||||||
void VertexManager::vFlush(bool use_dst_alpha)
|
void VertexManager::vFlush(bool use_dst_alpha)
|
||||||
{
|
{
|
||||||
ShaderCache::LoadAndSetActiveShaders(use_dst_alpha ? DSTALPHA_DUAL_SOURCE_BLEND : DSTALPHA_NONE,
|
ShaderCache::LoadAndSetActiveShaders(use_dst_alpha ? DSTALPHA_DUAL_SOURCE_BLEND : DSTALPHA_NONE,
|
||||||
current_primitive_type);
|
m_current_primitive_type);
|
||||||
|
|
||||||
if (g_ActiveConfig.backend_info.bSupportsBBox && BoundingBox::active)
|
if (g_ActiveConfig.backend_info.bSupportsBBox && BoundingBox::active)
|
||||||
BBox::Invalidate();
|
BBox::Invalidate();
|
||||||
|
@ -180,11 +180,11 @@ void VertexManager::vFlush(bool use_dst_alpha)
|
||||||
|
|
||||||
void VertexManager::ResetBuffer(u32 stride)
|
void VertexManager::ResetBuffer(u32 stride)
|
||||||
{
|
{
|
||||||
if (s_cull_all)
|
if (m_cull_all)
|
||||||
{
|
{
|
||||||
s_pCurBufferPointer = m_vertex_cpu_buffer.data();
|
m_cur_buffer_pointer = m_vertex_cpu_buffer.data();
|
||||||
s_pBaseBufferPointer = m_vertex_cpu_buffer.data();
|
m_base_buffer_pointer = m_vertex_cpu_buffer.data();
|
||||||
s_pEndBufferPointer = m_vertex_cpu_buffer.data() + MAXVBUFFERSIZE;
|
m_end_buffer_pointer = m_vertex_cpu_buffer.data() + MAXVBUFFERSIZE;
|
||||||
|
|
||||||
IndexGenerator::Start(reinterpret_cast<u16*>(m_index_cpu_buffer.data()));
|
IndexGenerator::Start(reinterpret_cast<u16*>(m_index_cpu_buffer.data()));
|
||||||
return;
|
return;
|
||||||
|
@ -198,9 +198,9 @@ void VertexManager::ResetBuffer(u32 stride)
|
||||||
m_vertex_stream_buffer_reallocated = false;
|
m_vertex_stream_buffer_reallocated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
s_pBaseBufferPointer = static_cast<u8*>(m_vertex_stream_buffer->GetBaseCPUAddress());
|
m_base_buffer_pointer = static_cast<u8*>(m_vertex_stream_buffer->GetBaseCPUAddress());
|
||||||
s_pEndBufferPointer = s_pBaseBufferPointer + m_vertex_stream_buffer->GetSize();
|
m_end_buffer_pointer = m_base_buffer_pointer + m_vertex_stream_buffer->GetSize();
|
||||||
s_pCurBufferPointer =
|
m_cur_buffer_pointer =
|
||||||
static_cast<u8*>(m_vertex_stream_buffer->GetCPUAddressOfCurrentAllocation());
|
static_cast<u8*>(m_vertex_stream_buffer->GetCPUAddressOfCurrentAllocation());
|
||||||
m_vertex_draw_offset = static_cast<u32>(m_vertex_stream_buffer->GetOffsetOfCurrentAllocation());
|
m_vertex_draw_offset = static_cast<u32>(m_vertex_stream_buffer->GetOffsetOfCurrentAllocation());
|
||||||
|
|
||||||
|
|
|
@ -35,19 +35,19 @@ VertexManager::~VertexManager()
|
||||||
|
|
||||||
void VertexManager::ResetBuffer(u32 stride)
|
void VertexManager::ResetBuffer(u32 stride)
|
||||||
{
|
{
|
||||||
s_pCurBufferPointer = s_pBaseBufferPointer = m_local_v_buffer.data();
|
m_cur_buffer_pointer = m_base_buffer_pointer = m_local_v_buffer.data();
|
||||||
s_pEndBufferPointer = s_pCurBufferPointer + m_local_v_buffer.size();
|
m_end_buffer_pointer = m_cur_buffer_pointer + m_local_v_buffer.size();
|
||||||
IndexGenerator::Start(&m_local_i_buffer[0]);
|
IndexGenerator::Start(&m_local_i_buffer[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexManager::vFlush(bool use_dst_alpha)
|
void VertexManager::vFlush(bool use_dst_alpha)
|
||||||
{
|
{
|
||||||
VertexShaderCache::s_instance->SetShader(
|
VertexShaderCache::s_instance->SetShader(
|
||||||
use_dst_alpha ? DSTALPHA_DUAL_SOURCE_BLEND : DSTALPHA_NONE, current_primitive_type);
|
use_dst_alpha ? DSTALPHA_DUAL_SOURCE_BLEND : DSTALPHA_NONE, m_current_primitive_type);
|
||||||
GeometryShaderCache::s_instance->SetShader(
|
GeometryShaderCache::s_instance->SetShader(
|
||||||
use_dst_alpha ? DSTALPHA_DUAL_SOURCE_BLEND : DSTALPHA_NONE, current_primitive_type);
|
use_dst_alpha ? DSTALPHA_DUAL_SOURCE_BLEND : DSTALPHA_NONE, m_current_primitive_type);
|
||||||
PixelShaderCache::s_instance->SetShader(
|
PixelShaderCache::s_instance->SetShader(
|
||||||
use_dst_alpha ? DSTALPHA_DUAL_SOURCE_BLEND : DSTALPHA_NONE, current_primitive_type);
|
use_dst_alpha ? DSTALPHA_DUAL_SOURCE_BLEND : DSTALPHA_NONE, m_current_primitive_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -75,19 +75,19 @@ void VertexManager::PrepareDrawBuffers(u32 stride)
|
||||||
|
|
||||||
void VertexManager::ResetBuffer(u32 stride)
|
void VertexManager::ResetBuffer(u32 stride)
|
||||||
{
|
{
|
||||||
if (s_cull_all)
|
if (m_cull_all)
|
||||||
{
|
{
|
||||||
// This buffer isn't getting sent to the GPU. Just allocate it on the cpu.
|
// This buffer isn't getting sent to the GPU. Just allocate it on the cpu.
|
||||||
s_pCurBufferPointer = s_pBaseBufferPointer = m_cpu_v_buffer.data();
|
m_cur_buffer_pointer = m_base_buffer_pointer = m_cpu_v_buffer.data();
|
||||||
s_pEndBufferPointer = s_pBaseBufferPointer + m_cpu_v_buffer.size();
|
m_end_buffer_pointer = m_base_buffer_pointer + m_cpu_v_buffer.size();
|
||||||
|
|
||||||
IndexGenerator::Start((u16*)m_cpu_i_buffer.data());
|
IndexGenerator::Start((u16*)m_cpu_i_buffer.data());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto buffer = s_vertexBuffer->Map(MAXVBUFFERSIZE, stride);
|
auto buffer = s_vertexBuffer->Map(MAXVBUFFERSIZE, stride);
|
||||||
s_pCurBufferPointer = s_pBaseBufferPointer = buffer.first;
|
m_cur_buffer_pointer = m_base_buffer_pointer = buffer.first;
|
||||||
s_pEndBufferPointer = buffer.first + MAXVBUFFERSIZE;
|
m_end_buffer_pointer = buffer.first + MAXVBUFFERSIZE;
|
||||||
s_baseVertex = buffer.second / stride;
|
s_baseVertex = buffer.second / stride;
|
||||||
|
|
||||||
buffer = s_indexBuffer->Map(MAXIBUFFERSIZE * sizeof(u16));
|
buffer = s_indexBuffer->Map(MAXIBUFFERSIZE * sizeof(u16));
|
||||||
|
@ -102,7 +102,7 @@ void VertexManager::Draw(u32 stride)
|
||||||
u32 max_index = IndexGenerator::GetNumVerts();
|
u32 max_index = IndexGenerator::GetNumVerts();
|
||||||
GLenum primitive_mode = 0;
|
GLenum primitive_mode = 0;
|
||||||
|
|
||||||
switch (current_primitive_type)
|
switch (m_current_primitive_type)
|
||||||
{
|
{
|
||||||
case PRIMITIVE_POINTS:
|
case PRIMITIVE_POINTS:
|
||||||
primitive_mode = GL_POINTS;
|
primitive_mode = GL_POINTS;
|
||||||
|
@ -131,7 +131,7 @@ void VertexManager::Draw(u32 stride)
|
||||||
|
|
||||||
INCSTAT(stats.thisFrame.numDrawCalls);
|
INCSTAT(stats.thisFrame.numDrawCalls);
|
||||||
|
|
||||||
if (current_primitive_type != PRIMITIVE_TRIANGLES)
|
if (m_current_primitive_type != PRIMITIVE_TRIANGLES)
|
||||||
static_cast<Renderer*>(g_renderer.get())->SetGenerationMode();
|
static_cast<Renderer*>(g_renderer.get())->SetGenerationMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,11 +155,11 @@ void VertexManager::vFlush(bool useDstAlpha)
|
||||||
// the same pass as regular rendering.
|
// the same pass as regular rendering.
|
||||||
if (useDstAlpha && dualSourcePossible)
|
if (useDstAlpha && dualSourcePossible)
|
||||||
{
|
{
|
||||||
ProgramShaderCache::SetShader(DSTALPHA_DUAL_SOURCE_BLEND, current_primitive_type);
|
ProgramShaderCache::SetShader(DSTALPHA_DUAL_SOURCE_BLEND, m_current_primitive_type);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ProgramShaderCache::SetShader(DSTALPHA_NONE, current_primitive_type);
|
ProgramShaderCache::SetShader(DSTALPHA_NONE, m_current_primitive_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// upload global constants
|
// upload global constants
|
||||||
|
@ -173,7 +173,7 @@ void VertexManager::vFlush(bool useDstAlpha)
|
||||||
// run through vertex groups again to set alpha
|
// run through vertex groups again to set alpha
|
||||||
if (useDstAlpha && !dualSourcePossible)
|
if (useDstAlpha && !dualSourcePossible)
|
||||||
{
|
{
|
||||||
ProgramShaderCache::SetShader(DSTALPHA_ALPHA_PASS, current_primitive_type);
|
ProgramShaderCache::SetShader(DSTALPHA_ALPHA_PASS, m_current_primitive_type);
|
||||||
|
|
||||||
// only update alpha
|
// only update alpha
|
||||||
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
|
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
|
||||||
|
|
|
@ -54,8 +54,8 @@ SWVertexLoader::~SWVertexLoader()
|
||||||
|
|
||||||
void SWVertexLoader::ResetBuffer(u32 stride)
|
void SWVertexLoader::ResetBuffer(u32 stride)
|
||||||
{
|
{
|
||||||
s_pCurBufferPointer = s_pBaseBufferPointer = LocalVBuffer.data();
|
m_cur_buffer_pointer = m_base_buffer_pointer = LocalVBuffer.data();
|
||||||
s_pEndBufferPointer = s_pCurBufferPointer + LocalVBuffer.size();
|
m_end_buffer_pointer = m_cur_buffer_pointer + LocalVBuffer.size();
|
||||||
IndexGenerator::Start(GetIndexBuffer());
|
IndexGenerator::Start(GetIndexBuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ void SWVertexLoader::vFlush(bool useDstAlpha)
|
||||||
DebugUtil::OnObjectBegin();
|
DebugUtil::OnObjectBegin();
|
||||||
|
|
||||||
u8 primitiveType = 0;
|
u8 primitiveType = 0;
|
||||||
switch (current_primitive_type)
|
switch (m_current_primitive_type)
|
||||||
{
|
{
|
||||||
case PRIMITIVE_POINTS:
|
case PRIMITIVE_POINTS:
|
||||||
primitiveType = GX_DRAW_POINTS;
|
primitiveType = GX_DRAW_POINTS;
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace BPFunctions
|
||||||
|
|
||||||
void FlushPipeline()
|
void FlushPipeline()
|
||||||
{
|
{
|
||||||
VertexManagerBase::Flush();
|
g_vertex_manager->Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetGenerationMode()
|
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.
|
// 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.
|
// Make sure VertexManager finishes drawing any primitives it has stored in it's buffer.
|
||||||
VertexManagerBase::Flush();
|
g_vertex_manager->Flush();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
100);
|
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 ||
|
if (loader->m_native_vertex_format != s_current_vtx_fmt ||
|
||||||
loader->m_native_components != g_current_components)
|
loader->m_native_components != g_current_components)
|
||||||
{
|
{
|
||||||
VertexManagerBase::Flush();
|
g_vertex_manager->Flush();
|
||||||
}
|
}
|
||||||
s_current_vtx_fmt = loader->m_native_vertex_format;
|
s_current_vtx_fmt = loader->m_native_vertex_format;
|
||||||
g_current_components = loader->m_native_components;
|
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.
|
// slope.
|
||||||
bool cullall = (bpmem.genMode.cullmode == GenMode::CULL_ALL && primitive < 5);
|
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);
|
primitive, count, loader->m_native_vtx_decl.stride, cullall);
|
||||||
|
|
||||||
count = loader->RunVertices(src, dst, count);
|
count = loader->RunVertices(src, dst, count);
|
||||||
|
|
||||||
IndexGenerator::AddIndices(primitive, 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);
|
ADDSTAT(stats.thisFrame.numPrims, count);
|
||||||
INCSTAT(stats.thisFrame.numPrimitiveJoins);
|
INCSTAT(stats.thisFrame.numPrimitiveJoins);
|
||||||
|
|
|
@ -28,17 +28,6 @@
|
||||||
|
|
||||||
std::unique_ptr<VertexManagerBase> g_vertex_manager;
|
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] = {
|
static const PrimitiveType primitive_from_gx[8] = {
|
||||||
PRIMITIVE_TRIANGLES, // GX_DRAW_QUADS
|
PRIMITIVE_TRIANGLES, // GX_DRAW_QUADS
|
||||||
PRIMITIVE_TRIANGLES, // GX_DRAW_QUADS_2
|
PRIMITIVE_TRIANGLES, // GX_DRAW_QUADS_2
|
||||||
|
@ -52,17 +41,15 @@ static const PrimitiveType primitive_from_gx[8] = {
|
||||||
|
|
||||||
VertexManagerBase::VertexManagerBase()
|
VertexManagerBase::VertexManagerBase()
|
||||||
{
|
{
|
||||||
s_is_flushed = true;
|
|
||||||
s_cull_all = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexManagerBase::~VertexManagerBase()
|
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,
|
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;
|
u32 const needed_vertex_bytes = count * stride + 4;
|
||||||
|
|
||||||
// We can't merge different kinds of primitives, so we have to flush here
|
// 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();
|
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()
|
// 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) ||
|
(count > IndexGenerator::GetRemainingIndices() || count > GetRemainingIndices(primitive) ||
|
||||||
needed_vertex_bytes > GetRemainingSize()))
|
needed_vertex_bytes > GetRemainingSize()))
|
||||||
{
|
{
|
||||||
|
@ -93,21 +80,21 @@ DataReader VertexManagerBase::PrepareForAdditionalData(int primitive, u32 count,
|
||||||
"Increase MAXVBUFFERSIZE or we need primitive breaking after all.");
|
"Increase MAXVBUFFERSIZE or we need primitive breaking after all.");
|
||||||
}
|
}
|
||||||
|
|
||||||
s_cull_all = cullall;
|
m_cull_all = cullall;
|
||||||
|
|
||||||
// need to alloc new buffer
|
// need to alloc new buffer
|
||||||
if (s_is_flushed)
|
if (m_is_flushed)
|
||||||
{
|
{
|
||||||
g_vertex_manager->ResetBuffer(stride);
|
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)
|
void VertexManagerBase::FlushData(u32 count, u32 stride)
|
||||||
{
|
{
|
||||||
s_pCurBufferPointer += count * stride;
|
m_cur_buffer_pointer += count * stride;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 VertexManagerBase::GetRemainingIndices(int primitive)
|
u32 VertexManagerBase::GetRemainingIndices(int primitive)
|
||||||
|
@ -170,7 +157,7 @@ u32 VertexManagerBase::GetRemainingIndices(int primitive)
|
||||||
|
|
||||||
void VertexManagerBase::Flush()
|
void VertexManagerBase::Flush()
|
||||||
{
|
{
|
||||||
if (s_is_flushed)
|
if (m_is_flushed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// loading a state will invalidate BP, so check for it
|
// 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
|
// If the primitave is marked CullAll. All we need to do is update the vertex constants and
|
||||||
// calculate the zfreeze refrence slope
|
// calculate the zfreeze refrence slope
|
||||||
if (!s_cull_all)
|
if (!m_cull_all)
|
||||||
{
|
{
|
||||||
BitSet32 usedtextures;
|
BitSet32 usedtextures;
|
||||||
for (u32 i = 0; i < bpmem.genMode.numtevstages + 1u; ++i)
|
for (u32 i = 0; i < bpmem.genMode.numtevstages + 1u; ++i)
|
||||||
|
@ -254,13 +241,13 @@ void VertexManagerBase::Flush()
|
||||||
// Must be done after VertexShaderManager::SetConstants()
|
// Must be done after VertexShaderManager::SetConstants()
|
||||||
CalculateZSlope(VertexLoaderManager::GetCurrentVertexFormat());
|
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);
|
PixelShaderManager::SetZSlope(m_zslope.dfdx, m_zslope.dfdy, m_zslope.f0);
|
||||||
s_zslope.dirty = false;
|
m_zslope.dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!s_cull_all)
|
if (!m_cull_all)
|
||||||
{
|
{
|
||||||
// set the rest of the global constants
|
// set the rest of the global constants
|
||||||
GeometryShaderManager::SetConstants();
|
GeometryShaderManager::SetConstants();
|
||||||
|
@ -283,13 +270,13 @@ void VertexManagerBase::Flush()
|
||||||
"xf.numtexgens (%d) does not match bp.numtexgens (%d). Error in command stream.",
|
"xf.numtexgens (%d) does not match bp.numtexgens (%d). Error in command stream.",
|
||||||
xfmem.numTexGen.numTexGens, bpmem.genMode.numtexgens.Value());
|
xfmem.numTexGen.numTexGens, bpmem.genMode.numtexgens.Value());
|
||||||
|
|
||||||
s_is_flushed = true;
|
m_is_flushed = true;
|
||||||
s_cull_all = false;
|
m_cull_all = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexManagerBase::DoState(PointerWrap& p)
|
void VertexManagerBase::DoState(PointerWrap& p)
|
||||||
{
|
{
|
||||||
p.Do(s_zslope);
|
p.Do(m_zslope);
|
||||||
g_vertex_manager->vDoState(p);
|
g_vertex_manager->vDoState(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,7 +286,7 @@ void VertexManagerBase::CalculateZSlope(NativeVertexFormat* format)
|
||||||
float viewOffset[2] = {xfmem.viewport.xOrig - bpmem.scissorOffset.x * 2,
|
float viewOffset[2] = {xfmem.viewport.xOrig - bpmem.scissorOffset.x * 2,
|
||||||
xfmem.viewport.yOrig - bpmem.scissorOffset.y * 2};
|
xfmem.viewport.yOrig - bpmem.scissorOffset.y * 2};
|
||||||
|
|
||||||
if (current_primitive_type != PRIMITIVE_TRIANGLES)
|
if (m_current_primitive_type != PRIMITIVE_TRIANGLES)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Global matrix ID.
|
// Global matrix ID.
|
||||||
|
@ -307,7 +294,7 @@ void VertexManagerBase::CalculateZSlope(NativeVertexFormat* format)
|
||||||
const PortableVertexDeclaration vert_decl = format->GetVertexDeclaration();
|
const PortableVertexDeclaration vert_decl = format->GetVertexDeclaration();
|
||||||
|
|
||||||
// Make sure the buffer contains at least 3 vertices.
|
// 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;
|
return;
|
||||||
|
|
||||||
// Lookup vertices of the last rendered triangle and software-transform them
|
// Lookup vertices of the last rendered triangle and software-transform them
|
||||||
|
@ -348,8 +335,8 @@ void VertexManagerBase::CalculateZSlope(NativeVertexFormat* format)
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
s_zslope.dfdx = -a / c;
|
m_zslope.dfdx = -a / c;
|
||||||
s_zslope.dfdy = -b / c;
|
m_zslope.dfdy = -b / c;
|
||||||
s_zslope.f0 = out[2] - (out[0] * s_zslope.dfdx + out[1] * s_zslope.dfdy);
|
m_zslope.f0 = out[2] - (out[0] * m_zslope.dfdx + out[1] * m_zslope.dfdy);
|
||||||
s_zslope.dirty = true;
|
m_zslope.dirty = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,36 +50,36 @@ public:
|
||||||
// needs to be virtual for DX11's dtor
|
// needs to be virtual for DX11's dtor
|
||||||
virtual ~VertexManagerBase();
|
virtual ~VertexManagerBase();
|
||||||
|
|
||||||
static DataReader PrepareForAdditionalData(int primitive, u32 count, u32 stride, bool cullall);
|
DataReader PrepareForAdditionalData(int primitive, u32 count, u32 stride, bool cullall);
|
||||||
static void FlushData(u32 count, u32 stride);
|
void FlushData(u32 count, u32 stride);
|
||||||
|
|
||||||
static void Flush();
|
void Flush();
|
||||||
|
|
||||||
virtual NativeVertexFormat*
|
virtual NativeVertexFormat*
|
||||||
CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) = 0;
|
CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) = 0;
|
||||||
|
|
||||||
static void DoState(PointerWrap& p);
|
void DoState(PointerWrap& p);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void vDoState(PointerWrap& p) {}
|
virtual void vDoState(PointerWrap& p) {}
|
||||||
static PrimitiveType current_primitive_type;
|
PrimitiveType m_current_primitive_type = PrimitiveType::PRIMITIVE_POINTS;
|
||||||
|
|
||||||
virtual void ResetBuffer(u32 stride) = 0;
|
virtual void ResetBuffer(u32 stride) = 0;
|
||||||
|
|
||||||
static u8* s_pCurBufferPointer;
|
u8* m_cur_buffer_pointer = nullptr;
|
||||||
static u8* s_pBaseBufferPointer;
|
u8* m_base_buffer_pointer = nullptr;
|
||||||
static u8* s_pEndBufferPointer;
|
u8* m_end_buffer_pointer = nullptr;
|
||||||
|
|
||||||
static u32 GetRemainingSize();
|
u32 GetRemainingSize() const;
|
||||||
static u32 GetRemainingIndices(int primitive);
|
static u32 GetRemainingIndices(int primitive);
|
||||||
|
|
||||||
static Slope s_zslope;
|
Slope m_zslope = {};
|
||||||
static void CalculateZSlope(NativeVertexFormat* format);
|
void CalculateZSlope(NativeVertexFormat* format);
|
||||||
|
|
||||||
static bool s_cull_all;
|
bool m_cull_all = false;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool s_is_flushed;
|
bool m_is_flushed = true;
|
||||||
|
|
||||||
virtual void vFlush(bool useDstAlpha) = 0;
|
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)
|
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))
|
if (g_main_cp_state.matrix_index_a.PosNormalMtxIdx != (Value & 0x3f))
|
||||||
bPosNormalMatrixChanged = true;
|
bPosNormalMatrixChanged = true;
|
||||||
bTexMatricesChanged[0] = true;
|
bTexMatricesChanged[0] = true;
|
||||||
|
@ -688,7 +688,7 @@ void VertexShaderManager::SetTexMatrixChangedB(u32 Value)
|
||||||
{
|
{
|
||||||
if (g_main_cp_state.matrix_index_b.Hex != Value)
|
if (g_main_cp_state.matrix_index_b.Hex != Value)
|
||||||
{
|
{
|
||||||
VertexManagerBase::Flush();
|
g_vertex_manager->Flush();
|
||||||
bTexMatricesChanged[1] = true;
|
bTexMatricesChanged[1] = true;
|
||||||
g_main_cp_state.matrix_index_b.Hex = Value;
|
g_main_cp_state.matrix_index_b.Hex = Value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ void VideoCommon_DoState(PointerWrap& p)
|
||||||
GeometryShaderManager::DoState(p);
|
GeometryShaderManager::DoState(p);
|
||||||
p.DoMarker("GeometryShaderManager");
|
p.DoMarker("GeometryShaderManager");
|
||||||
|
|
||||||
VertexManagerBase::DoState(p);
|
g_vertex_manager->DoState(p);
|
||||||
p.DoMarker("VertexManager");
|
p.DoMarker("VertexManager");
|
||||||
|
|
||||||
BoundingBox::DoState(p);
|
BoundingBox::DoState(p);
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
static void XFMemWritten(u32 transferSize, u32 baseAddress)
|
static void XFMemWritten(u32 transferSize, u32 baseAddress)
|
||||||
{
|
{
|
||||||
VertexManagerBase::Flush();
|
g_vertex_manager->Flush();
|
||||||
VertexShaderManager::InvalidateXFRange(baseAddress, baseAddress + transferSize);
|
VertexShaderManager::InvalidateXFRange(baseAddress, baseAddress + transferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ static void XFRegWritten(int transferSize, u32 baseAddress, DataReader src)
|
||||||
|
|
||||||
case XFMEM_SETNUMCHAN:
|
case XFMEM_SETNUMCHAN:
|
||||||
if (xfmem.numChan.numColorChans != (newValue & 3))
|
if (xfmem.numChan.numColorChans != (newValue & 3))
|
||||||
VertexManagerBase::Flush();
|
g_vertex_manager->Flush();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XFMEM_SETCHAN0_AMBCOLOR: // Channel Ambient Color
|
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;
|
u8 chan = address - XFMEM_SETCHAN0_AMBCOLOR;
|
||||||
if (xfmem.ambColor[chan] != newValue)
|
if (xfmem.ambColor[chan] != newValue)
|
||||||
{
|
{
|
||||||
VertexManagerBase::Flush();
|
g_vertex_manager->Flush();
|
||||||
VertexShaderManager::SetMaterialColorChanged(chan);
|
VertexShaderManager::SetMaterialColorChanged(chan);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -74,7 +74,7 @@ static void XFRegWritten(int transferSize, u32 baseAddress, DataReader src)
|
||||||
u8 chan = address - XFMEM_SETCHAN0_MATCOLOR;
|
u8 chan = address - XFMEM_SETCHAN0_MATCOLOR;
|
||||||
if (xfmem.matColor[chan] != newValue)
|
if (xfmem.matColor[chan] != newValue)
|
||||||
{
|
{
|
||||||
VertexManagerBase::Flush();
|
g_vertex_manager->Flush();
|
||||||
VertexShaderManager::SetMaterialColorChanged(chan + 2);
|
VertexShaderManager::SetMaterialColorChanged(chan + 2);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -85,12 +85,12 @@ static void XFRegWritten(int transferSize, u32 baseAddress, DataReader src)
|
||||||
case XFMEM_SETCHAN0_ALPHA: // Channel Alpha
|
case XFMEM_SETCHAN0_ALPHA: // Channel Alpha
|
||||||
case XFMEM_SETCHAN1_ALPHA:
|
case XFMEM_SETCHAN1_ALPHA:
|
||||||
if (((u32*)&xfmem)[address] != (newValue & 0x7fff))
|
if (((u32*)&xfmem)[address] != (newValue & 0x7fff))
|
||||||
VertexManagerBase::Flush();
|
g_vertex_manager->Flush();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XFMEM_DUALTEX:
|
case XFMEM_DUALTEX:
|
||||||
if (xfmem.dualTexTrans.enabled != (newValue & 1))
|
if (xfmem.dualTexTrans.enabled != (newValue & 1))
|
||||||
VertexManagerBase::Flush();
|
g_vertex_manager->Flush();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XFMEM_SETMATRIXINDA:
|
case XFMEM_SETMATRIXINDA:
|
||||||
|
@ -108,7 +108,7 @@ static void XFRegWritten(int transferSize, u32 baseAddress, DataReader src)
|
||||||
case XFMEM_SETVIEWPORT + 3:
|
case XFMEM_SETVIEWPORT + 3:
|
||||||
case XFMEM_SETVIEWPORT + 4:
|
case XFMEM_SETVIEWPORT + 4:
|
||||||
case XFMEM_SETVIEWPORT + 5:
|
case XFMEM_SETVIEWPORT + 5:
|
||||||
VertexManagerBase::Flush();
|
g_vertex_manager->Flush();
|
||||||
VertexShaderManager::SetViewportChanged();
|
VertexShaderManager::SetViewportChanged();
|
||||||
PixelShaderManager::SetViewportChanged();
|
PixelShaderManager::SetViewportChanged();
|
||||||
GeometryShaderManager::SetViewportChanged();
|
GeometryShaderManager::SetViewportChanged();
|
||||||
|
@ -123,7 +123,7 @@ static void XFRegWritten(int transferSize, u32 baseAddress, DataReader src)
|
||||||
case XFMEM_SETPROJECTION + 4:
|
case XFMEM_SETPROJECTION + 4:
|
||||||
case XFMEM_SETPROJECTION + 5:
|
case XFMEM_SETPROJECTION + 5:
|
||||||
case XFMEM_SETPROJECTION + 6:
|
case XFMEM_SETPROJECTION + 6:
|
||||||
VertexManagerBase::Flush();
|
g_vertex_manager->Flush();
|
||||||
VertexShaderManager::SetProjectionChanged();
|
VertexShaderManager::SetProjectionChanged();
|
||||||
GeometryShaderManager::SetProjectionChanged();
|
GeometryShaderManager::SetProjectionChanged();
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ static void XFRegWritten(int transferSize, u32 baseAddress, DataReader src)
|
||||||
|
|
||||||
case XFMEM_SETNUMTEXGENS: // GXSetNumTexGens
|
case XFMEM_SETNUMTEXGENS: // GXSetNumTexGens
|
||||||
if (xfmem.numTexGen.numTexGens != (newValue & 15))
|
if (xfmem.numTexGen.numTexGens != (newValue & 15))
|
||||||
VertexManagerBase::Flush();
|
g_vertex_manager->Flush();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XFMEM_SETTEXMTXINFO:
|
case XFMEM_SETTEXMTXINFO:
|
||||||
|
@ -143,7 +143,7 @@ static void XFRegWritten(int transferSize, u32 baseAddress, DataReader src)
|
||||||
case XFMEM_SETTEXMTXINFO + 5:
|
case XFMEM_SETTEXMTXINFO + 5:
|
||||||
case XFMEM_SETTEXMTXINFO + 6:
|
case XFMEM_SETTEXMTXINFO + 6:
|
||||||
case XFMEM_SETTEXMTXINFO + 7:
|
case XFMEM_SETTEXMTXINFO + 7:
|
||||||
VertexManagerBase::Flush();
|
g_vertex_manager->Flush();
|
||||||
|
|
||||||
nextAddress = XFMEM_SETTEXMTXINFO + 8;
|
nextAddress = XFMEM_SETTEXMTXINFO + 8;
|
||||||
break;
|
break;
|
||||||
|
@ -156,7 +156,7 @@ static void XFRegWritten(int transferSize, u32 baseAddress, DataReader src)
|
||||||
case XFMEM_SETPOSMTXINFO + 5:
|
case XFMEM_SETPOSMTXINFO + 5:
|
||||||
case XFMEM_SETPOSMTXINFO + 6:
|
case XFMEM_SETPOSMTXINFO + 6:
|
||||||
case XFMEM_SETPOSMTXINFO + 7:
|
case XFMEM_SETPOSMTXINFO + 7:
|
||||||
VertexManagerBase::Flush();
|
g_vertex_manager->Flush();
|
||||||
|
|
||||||
nextAddress = XFMEM_SETPOSMTXINFO + 8;
|
nextAddress = XFMEM_SETPOSMTXINFO + 8;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue