Vulkan: Remove parameters/members of single-instance classes

There's not a lot of point in passing these around or storing them
(texture cache/state tracker mainly) as there will only ever be a single
instance of the class.

Also adds downcast helpers such as Vulkan::Renderer::GetInstance().
This commit is contained in:
Stenzek
2016-10-22 20:50:36 +10:00
parent ab9f539233
commit b066d51dfa
21 changed files with 336 additions and 303 deletions

View File

@ -36,10 +36,13 @@ VertexManager::~VertexManager()
{
}
bool VertexManager::Initialize(StateTracker* state_tracker)
VertexManager* VertexManager::GetInstance()
{
m_state_tracker = state_tracker;
return static_cast<VertexManager*>(g_vertex_manager.get());
}
bool VertexManager::Initialize()
{
m_vertex_stream_buffer = StreamBuffer::Create(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
INITIAL_VERTEX_BUFFER_SIZE, MAX_VERTEX_BUFFER_SIZE);
@ -72,8 +75,9 @@ void VertexManager::PrepareDrawBuffers(u32 stride)
ADDSTAT(stats.thisFrame.bytesVertexStreamed, static_cast<int>(vertex_data_size));
ADDSTAT(stats.thisFrame.bytesIndexStreamed, static_cast<int>(index_data_size));
m_state_tracker->SetVertexBuffer(m_vertex_stream_buffer->GetBuffer(), 0);
m_state_tracker->SetIndexBuffer(m_index_stream_buffer->GetBuffer(), 0, VK_INDEX_TYPE_UINT16);
StateTracker::GetInstance()->SetVertexBuffer(m_vertex_stream_buffer->GetBuffer(), 0);
StateTracker::GetInstance()->SetIndexBuffer(m_index_stream_buffer->GetBuffer(), 0,
VK_INDEX_TYPE_UINT16);
}
void VertexManager::ResetBuffer(u32 stride)
@ -94,7 +98,7 @@ void VertexManager::ResetBuffer(u32 stride)
{
// Flush any pending commands first, so that we can wait on the fences
WARN_LOG(VIDEO, "Executing command list while waiting for space in vertex/index buffer");
Util::ExecuteCurrentCommandsAndRestoreState(m_state_tracker, false);
Util::ExecuteCurrentCommandsAndRestoreState(false);
// Attempt to allocate again, this may cause a fence wait
if (!has_vbuffer_allocation)
@ -133,21 +137,21 @@ void VertexManager::vFlush(bool use_dst_alpha)
u32 index_count = IndexGenerator::GetIndexLen();
// Update assembly state
m_state_tracker->SetVertexFormat(vertex_format);
StateTracker::GetInstance()->SetVertexFormat(vertex_format);
switch (m_current_primitive_type)
{
case PRIMITIVE_POINTS:
m_state_tracker->SetPrimitiveTopology(VK_PRIMITIVE_TOPOLOGY_POINT_LIST);
m_state_tracker->DisableBackFaceCulling();
StateTracker::GetInstance()->SetPrimitiveTopology(VK_PRIMITIVE_TOPOLOGY_POINT_LIST);
StateTracker::GetInstance()->DisableBackFaceCulling();
break;
case PRIMITIVE_LINES:
m_state_tracker->SetPrimitiveTopology(VK_PRIMITIVE_TOPOLOGY_LINE_LIST);
m_state_tracker->DisableBackFaceCulling();
StateTracker::GetInstance()->SetPrimitiveTopology(VK_PRIMITIVE_TOPOLOGY_LINE_LIST);
StateTracker::GetInstance()->DisableBackFaceCulling();
break;
case PRIMITIVE_TRIANGLES:
m_state_tracker->SetPrimitiveTopology(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP);
StateTracker::GetInstance()->SetPrimitiveTopology(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP);
g_renderer->SetGenerationMode();
break;
}
@ -158,37 +162,34 @@ void VertexManager::vFlush(bool use_dst_alpha)
dstalpha_mode = DSTALPHA_DUAL_SOURCE_BLEND;
// Check for any shader stage changes
m_state_tracker->CheckForShaderChanges(m_current_primitive_type, dstalpha_mode);
StateTracker::GetInstance()->CheckForShaderChanges(m_current_primitive_type, dstalpha_mode);
// Update any changed constants
m_state_tracker->UpdateVertexShaderConstants();
m_state_tracker->UpdateGeometryShaderConstants();
m_state_tracker->UpdatePixelShaderConstants();
StateTracker::GetInstance()->UpdateVertexShaderConstants();
StateTracker::GetInstance()->UpdateGeometryShaderConstants();
StateTracker::GetInstance()->UpdatePixelShaderConstants();
// Flush all EFB pokes and invalidate the peek cache.
// TODO: Cleaner way without the cast.
FramebufferManager* framebuffer_mgr =
static_cast<FramebufferManager*>(g_framebuffer_manager.get());
framebuffer_mgr->InvalidatePeekCache();
framebuffer_mgr->FlushEFBPokes(m_state_tracker);
FramebufferManager::GetInstance()->InvalidatePeekCache();
FramebufferManager::GetInstance()->FlushEFBPokes();
// If bounding box is enabled, we need to flush any changes first, then invalidate what we have.
if (g_vulkan_context->SupportsBoundingBox())
{
BoundingBox* bounding_box = static_cast<Renderer*>(g_renderer.get())->GetBoundingBox();
BoundingBox* bounding_box = Renderer::GetInstance()->GetBoundingBox();
bool bounding_box_enabled = (::BoundingBox::active && g_ActiveConfig.bBBoxEnable);
if (bounding_box_enabled)
{
bounding_box->Flush(m_state_tracker);
bounding_box->Invalidate(m_state_tracker);
bounding_box->Flush();
bounding_box->Invalidate();
}
// Update which descriptor set/pipeline layout to use.
m_state_tracker->SetBBoxEnable(bounding_box_enabled);
StateTracker::GetInstance()->SetBBoxEnable(bounding_box_enabled);
}
// Bind all pending state to the command buffer
if (!m_state_tracker->Bind())
if (!StateTracker::GetInstance()->Bind())
{
WARN_LOG(VIDEO, "Skipped draw of %u indices", index_count);
return;
@ -207,8 +208,9 @@ void VertexManager::vFlush(bool use_dst_alpha)
bool logic_op_enabled = bpmem.blendmode.logicopenable && !bpmem.blendmode.blendenable;
if (use_dst_alpha && (!g_vulkan_context->SupportsDualSourceBlend() || logic_op_enabled))
{
m_state_tracker->CheckForShaderChanges(m_current_primitive_type, DSTALPHA_ALPHA_PASS);
if (!m_state_tracker->Bind())
StateTracker::GetInstance()->CheckForShaderChanges(m_current_primitive_type,
DSTALPHA_ALPHA_PASS);
if (!StateTracker::GetInstance()->Bind())
{
WARN_LOG(VIDEO, "Skipped draw of %u indices (alpha pass)", index_count);
return;
@ -218,7 +220,7 @@ void VertexManager::vFlush(bool use_dst_alpha)
m_current_draw_base_index, m_current_draw_base_vertex, 0);
}
m_state_tracker->OnDraw();
StateTracker::GetInstance()->OnDraw();
}
} // namespace Vulkan