mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
Merge pull request #1503 from kayru/d3d_optimization_cache
D3D: Filter redundant API calls by caching state in StateManager
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
|
||||
#include "VideoBackends/D3D/BoundingBox.h"
|
||||
#include "VideoBackends/D3D/D3DBase.h"
|
||||
#include "VideoBackends/D3D/D3DState.h"
|
||||
#include "VideoBackends/D3D/PixelShaderCache.h"
|
||||
#include "VideoBackends/D3D/Render.h"
|
||||
#include "VideoBackends/D3D/VertexManager.h"
|
||||
@ -129,17 +130,19 @@ void VertexManager::Draw(u32 stride)
|
||||
u32 components = VertexLoaderManager::GetCurrentVertexFormat()->m_components;
|
||||
u32 indices = IndexGenerator::GetIndexLen();
|
||||
|
||||
u32 zero = 0;
|
||||
D3D::context->IASetVertexBuffers(0, 1, &m_buffers[m_currentBuffer], &stride, &zero);
|
||||
D3D::context->IASetIndexBuffer(m_buffers[m_currentBuffer], DXGI_FORMAT_R16_UINT, 0);
|
||||
D3D::stateman->SetVertexBuffer(m_buffers[m_currentBuffer], stride, 0);
|
||||
D3D::stateman->SetIndexBuffer(m_buffers[m_currentBuffer]);
|
||||
|
||||
u32 baseVertex = m_vertexDrawOffset / stride;
|
||||
u32 startIndex = m_indexDrawOffset / sizeof(u16);
|
||||
|
||||
if (current_primitive_type == PRIMITIVE_TRIANGLES)
|
||||
{
|
||||
D3D::context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
|
||||
D3D::stateman->SetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
|
||||
|
||||
D3D::stateman->Apply();
|
||||
D3D::context->DrawIndexed(indices, startIndex, baseVertex);
|
||||
|
||||
INCSTAT(stats.thisFrame.numDrawCalls);
|
||||
}
|
||||
else if (current_primitive_type == PRIMITIVE_LINES)
|
||||
@ -157,13 +160,14 @@ void VertexManager::Draw(u32 stride)
|
||||
if (m_lineShader.SetShader(components, lineWidth,
|
||||
texOffset, vpWidth, vpHeight, texOffsetEnable))
|
||||
{
|
||||
((DX11::Renderer*)g_renderer)->ApplyCullDisable(); // Disable culling for lines and points
|
||||
D3D::context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST);
|
||||
D3D::stateman->SetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST);
|
||||
|
||||
D3D::stateman->Apply();
|
||||
D3D::context->DrawIndexed(indices, startIndex, baseVertex);
|
||||
|
||||
INCSTAT(stats.thisFrame.numDrawCalls);
|
||||
|
||||
D3D::context->GSSetShader(nullptr, nullptr, 0);
|
||||
((DX11::Renderer*)g_renderer)->RestoreCull();
|
||||
D3D::stateman->SetGeometryShader(nullptr);
|
||||
}
|
||||
}
|
||||
else //if (current_primitive_type == PRIMITIVE_POINTS)
|
||||
@ -181,13 +185,14 @@ void VertexManager::Draw(u32 stride)
|
||||
if (m_pointShader.SetShader(components, pointSize,
|
||||
texOffset, vpWidth, vpHeight, texOffsetEnable))
|
||||
{
|
||||
((DX11::Renderer*)g_renderer)->ApplyCullDisable(); // Disable culling for lines and points
|
||||
D3D::context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
|
||||
D3D::stateman->SetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
|
||||
|
||||
D3D::stateman->Apply();
|
||||
D3D::context->DrawIndexed(indices, startIndex, baseVertex);
|
||||
|
||||
INCSTAT(stats.thisFrame.numDrawCalls);
|
||||
|
||||
D3D::context->GSSetShader(nullptr, nullptr, 0);
|
||||
((DX11::Renderer*)g_renderer)->RestoreCull();
|
||||
D3D::stateman->SetGeometryShader(nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user