mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 13:49:53 -06:00
Hey, long time no commits :).
So to compensate lets bring back some speed to the emulation. change a little the way the vertex are send to the gpu, This first implementation changes dx9 a lot and dx11 a little to increase the parallelism between the cpu and gpu. ogl: is my next step in ogl is a little more trickier so i have to take a little more time. the original concept is Marcos idea, with my little touch to make it even more faster. what to look for: SPEEEEEDDD :). please test it a lot and let me know if you see any problem. in dx9 the code is prepared to fall back to the previous implementation if your card does not support the amount of buffers needed. So if you did not experience any speed gains you know where is the problem :). for the ones with more experience and compression of the code please test changing the amount and size of the buffers to tune this for your specific machine. The current values are the sweet spot for my machine. All must Thanks Marcos, I hate him for giving good ideas when I'm full of work.
This commit is contained in:
@ -39,32 +39,47 @@ namespace DX11
|
||||
{
|
||||
|
||||
// TODO: Find sensible values for these two
|
||||
const UINT IBUFFER_SIZE = VertexManager::MAXIBUFFERSIZE*2 * 16;
|
||||
const UINT VBUFFER_SIZE = VertexManager::MAXVBUFFERSIZE * 16;
|
||||
const UINT IBUFFER_SIZE = VertexManager::MAXIBUFFERSIZE * 12;
|
||||
const UINT VBUFFER_SIZE = VertexManager::MAXVBUFFERSIZE * 8;
|
||||
const UINT MAXVBUFFER_COUNT = 4;
|
||||
|
||||
void VertexManager::CreateDeviceObjects()
|
||||
{
|
||||
D3D11_BUFFER_DESC bufdesc = CD3D11_BUFFER_DESC(IBUFFER_SIZE,
|
||||
D3D11_BIND_INDEX_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
|
||||
|
||||
CHECK(SUCCEEDED(D3D::device->CreateBuffer(&bufdesc, NULL, &m_indexBuffer)),
|
||||
"Failed to create index buffer.");
|
||||
D3D::SetDebugObjectName((ID3D11DeviceChild*)m_indexBuffer, "index buffer of VertexManager");
|
||||
|
||||
bufdesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||
bufdesc.ByteWidth = VBUFFER_SIZE;
|
||||
|
||||
CHECK(SUCCEEDED(D3D::device->CreateBuffer(&bufdesc, NULL, &m_vertexBuffer)),
|
||||
"Failed to create vertex buffer.");
|
||||
D3D::SetDebugObjectName((ID3D11DeviceChild*)m_vertexBuffer, "vertex buffer of VertexManager");
|
||||
|
||||
m_indexBufferCursor = 0;
|
||||
m_vertexBufferCursor = 0;
|
||||
m_vertexDrawOffset = 0;
|
||||
|
||||
m_triangleDrawIndex = 0;
|
||||
m_lineDrawIndex = 0;
|
||||
m_pointDrawIndex = 0;
|
||||
m_indexBuffers = new PID3D11Buffer[MAXVBUFFER_COUNT];
|
||||
m_vertexBuffers = new PID3D11Buffer[MAXVBUFFER_COUNT];
|
||||
bool Fail = false;
|
||||
for (m_activeVertexBuffer = 0; m_activeVertexBuffer < MAXVBUFFER_COUNT; m_activeVertexBuffer++)
|
||||
{
|
||||
m_indexBuffers[m_activeVertexBuffer] = NULL;
|
||||
m_vertexBuffers[m_activeVertexBuffer] = NULL;
|
||||
}
|
||||
for (m_activeIndexBuffer = 0; m_activeIndexBuffer < MAXVBUFFER_COUNT; m_activeIndexBuffer++)
|
||||
{
|
||||
CHECK(SUCCEEDED(D3D::device->CreateBuffer(&bufdesc, NULL, &m_indexBuffers[m_activeIndexBuffer])),
|
||||
"Failed to create index buffer.");
|
||||
D3D::SetDebugObjectName((ID3D11DeviceChild*)m_indexBuffers[m_activeIndexBuffer], "index buffer of VertexManager");
|
||||
}
|
||||
bufdesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||
bufdesc.ByteWidth = VBUFFER_SIZE;
|
||||
for (m_activeVertexBuffer = 0; m_activeVertexBuffer < MAXVBUFFER_COUNT; m_activeVertexBuffer++)
|
||||
{
|
||||
CHECK(SUCCEEDED(D3D::device->CreateBuffer(&bufdesc, NULL, &m_vertexBuffers[m_activeVertexBuffer])),
|
||||
"Failed to create vertex buffer.");
|
||||
D3D::SetDebugObjectName((ID3D11DeviceChild*)m_vertexBuffers[m_activeVertexBuffer], "Vertex buffer of VertexManager");
|
||||
}
|
||||
m_activeVertexBuffer = 0;
|
||||
m_activeIndexBuffer = 0;
|
||||
m_LastVertexBuffer = MAXVBUFFER_COUNT;
|
||||
m_LastIndexBuffer = MAXVBUFFER_COUNT;
|
||||
|
||||
m_lineShader.Init();
|
||||
m_pointShader.Init();
|
||||
@ -74,9 +89,12 @@ void VertexManager::DestroyDeviceObjects()
|
||||
{
|
||||
m_pointShader.Shutdown();
|
||||
m_lineShader.Shutdown();
|
||||
|
||||
SAFE_RELEASE(m_vertexBuffer);
|
||||
SAFE_RELEASE(m_indexBuffer);
|
||||
for (m_activeVertexBuffer = 0; m_activeVertexBuffer < MAXVBUFFER_COUNT; m_activeVertexBuffer++)
|
||||
{
|
||||
SAFE_RELEASE(m_vertexBuffers[m_activeVertexBuffer]);
|
||||
SAFE_RELEASE(m_indexBuffers[m_activeVertexBuffer]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
VertexManager::VertexManager()
|
||||
@ -94,42 +112,41 @@ void VertexManager::LoadBuffers()
|
||||
D3D11_MAPPED_SUBRESOURCE map;
|
||||
|
||||
UINT vSize = UINT(s_pCurBufferPointer - LocalVBuffer);
|
||||
if (m_vertexBufferCursor + vSize >= VBUFFER_SIZE)
|
||||
D3D11_MAP MapType = D3D11_MAP_WRITE_NO_OVERWRITE;
|
||||
if (m_vertexBufferCursor + vSize >= VBUFFER_SIZE || m_activeVertexBuffer != m_LastVertexBuffer)
|
||||
{
|
||||
// Wrap around
|
||||
D3D::context->Map(m_vertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
|
||||
m_activeVertexBuffer = (m_activeVertexBuffer + 1) % MAXVBUFFER_COUNT;
|
||||
m_vertexBufferCursor = 0;
|
||||
MapType = D3D11_MAP_WRITE_DISCARD;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Append data
|
||||
D3D::context->Map(m_vertexBuffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map);
|
||||
}
|
||||
|
||||
D3D::context->Map(m_vertexBuffers[m_activeVertexBuffer], 0, MapType, 0, &map);
|
||||
|
||||
memcpy((u8*)map.pData + m_vertexBufferCursor, LocalVBuffer, vSize);
|
||||
D3D::context->Unmap(m_vertexBuffer, 0);
|
||||
D3D::context->Unmap(m_vertexBuffers[m_activeVertexBuffer], 0);
|
||||
m_vertexDrawOffset = m_vertexBufferCursor;
|
||||
m_vertexBufferCursor += vSize;
|
||||
|
||||
UINT iCount = IndexGenerator::GetTriangleindexLen() +
|
||||
IndexGenerator::GetLineindexLen() + IndexGenerator::GetPointindexLen();
|
||||
if (m_indexBufferCursor + iCount >= IBUFFER_SIZE/2)
|
||||
MapType = D3D11_MAP_WRITE_NO_OVERWRITE;
|
||||
if (m_indexBufferCursor + iCount >= IBUFFER_SIZE/2 || m_activeIndexBuffer != m_LastIndexBuffer)
|
||||
{
|
||||
// Wrap around
|
||||
D3D::context->Map(m_indexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
|
||||
m_activeIndexBuffer = (m_activeIndexBuffer + 1) % MAXVBUFFER_COUNT;
|
||||
m_indexBufferCursor = 0;
|
||||
MapType = D3D11_MAP_WRITE_DISCARD;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Append data
|
||||
D3D::context->Map(m_indexBuffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map);
|
||||
}
|
||||
D3D::context->Map(m_indexBuffers[m_activeIndexBuffer], 0, MapType, 0, &map);
|
||||
|
||||
m_triangleDrawIndex = m_indexBufferCursor;
|
||||
m_lineDrawIndex = m_triangleDrawIndex + IndexGenerator::GetTriangleindexLen();
|
||||
m_pointDrawIndex = m_lineDrawIndex + IndexGenerator::GetLineindexLen();
|
||||
memcpy((u16*)map.pData + m_triangleDrawIndex, TIBuffer, 2*IndexGenerator::GetTriangleindexLen());
|
||||
memcpy((u16*)map.pData + m_lineDrawIndex, LIBuffer, 2*IndexGenerator::GetLineindexLen());
|
||||
memcpy((u16*)map.pData + m_pointDrawIndex, PIBuffer, 2*IndexGenerator::GetPointindexLen());
|
||||
D3D::context->Unmap(m_indexBuffer, 0);
|
||||
D3D::context->Unmap(m_indexBuffers[m_activeIndexBuffer], 0);
|
||||
m_indexBufferCursor += iCount;
|
||||
}
|
||||
|
||||
@ -139,9 +156,11 @@ static const float LINE_PT_TEX_OFFSETS[8] = {
|
||||
|
||||
void VertexManager::Draw(UINT stride)
|
||||
{
|
||||
D3D::context->IASetVertexBuffers(0, 1, &m_vertexBuffer, &stride, &m_vertexDrawOffset);
|
||||
D3D::context->IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R16_UINT, 0);
|
||||
|
||||
D3D::context->IASetVertexBuffers(0, 1, &m_vertexBuffers[m_activeVertexBuffer], &stride, &m_vertexDrawOffset);
|
||||
D3D::context->IASetIndexBuffer(m_indexBuffers[m_activeIndexBuffer], DXGI_FORMAT_R16_UINT, 0);
|
||||
m_LastIndexBuffer = m_activeIndexBuffer;
|
||||
m_LastVertexBuffer = m_activeVertexBuffer;
|
||||
|
||||
if (IndexGenerator::GetNumTriangles() > 0)
|
||||
{
|
||||
D3D::context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
@ -260,12 +279,11 @@ void VertexManager::vFlush()
|
||||
GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");});
|
||||
goto shader_fail;
|
||||
}
|
||||
|
||||
LoadBuffers();
|
||||
unsigned int stride = g_nativeVertexFmt->GetVertexStride();
|
||||
g_nativeVertexFmt->SetupVertexPointers();
|
||||
|
||||
g_renderer->ApplyState(useDstAlpha);
|
||||
LoadBuffers();
|
||||
|
||||
Draw(stride);
|
||||
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true);
|
||||
|
Reference in New Issue
Block a user