2013-04-18 03:29:41 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
#include "Common.h"
|
2009-09-02 07:25:22 +00:00
|
|
|
#include "FileUtil.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
#include "D3DBase.h"
|
2010-06-29 14:40:37 +00:00
|
|
|
#include "Fifo.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "Statistics.h"
|
|
|
|
#include "VertexManager.h"
|
|
|
|
#include "OpcodeDecoding.h"
|
|
|
|
#include "IndexGenerator.h"
|
2008-12-25 15:56:36 +00:00
|
|
|
#include "VertexShaderManager.h"
|
2008-12-26 19:39:12 +00:00
|
|
|
#include "VertexShaderCache.h"
|
2008-12-25 15:56:36 +00:00
|
|
|
#include "PixelShaderManager.h"
|
2008-12-26 19:39:12 +00:00
|
|
|
#include "PixelShaderCache.h"
|
2009-02-28 22:10:38 +00:00
|
|
|
#include "NativeVertexFormat.h"
|
2009-03-07 18:05:29 +00:00
|
|
|
#include "TextureCache.h"
|
2010-08-04 21:02:32 +00:00
|
|
|
#include "main.h"
|
2009-02-28 22:10:38 +00:00
|
|
|
|
2009-06-22 09:31:30 +00:00
|
|
|
#include "BPStructs.h"
|
2009-02-28 22:10:38 +00:00
|
|
|
#include "XFStructs.h"
|
2010-12-05 14:15:36 +00:00
|
|
|
#include "Debugger.h"
|
|
|
|
#include "VideoConfig.h"
|
2009-09-02 06:33:41 +00:00
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
// internal state for loading vertices
|
|
|
|
extern NativeVertexFormat *g_nativeVertexFmt;
|
2010-10-03 00:41:06 +00:00
|
|
|
namespace DX9
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2012-10-22 22:37:26 +00:00
|
|
|
//This are the initially requeted size for the buffers expresed in elements
|
2013-03-12 16:48:20 +00:00
|
|
|
const u32 IBUFFER_SIZE = VertexManager::MAXIBUFFERSIZE * sizeof(u16) * 8;
|
|
|
|
const u32 VBUFFER_SIZE = VertexManager::MAXVBUFFERSIZE;
|
2013-03-15 16:29:12 +00:00
|
|
|
const u32 MAX_VBUFFER_COUNT = 2;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-11-01 02:03:26 +00:00
|
|
|
inline void DumpBadShaders()
|
|
|
|
{
|
|
|
|
#if defined(_DEBUG) || defined(DEBUGFAST)
|
2010-12-05 14:15:36 +00:00
|
|
|
// TODO: Reimplement!
|
|
|
|
/* std::string error_shaders;
|
2009-11-01 02:03:26 +00:00
|
|
|
error_shaders.append(VertexShaderCache::GetCurrentShaderCode());
|
|
|
|
error_shaders.append(PixelShaderCache::GetCurrentShaderCode());
|
|
|
|
char filename[512] = "bad_shader_combo_0.txt";
|
|
|
|
int which = 0;
|
|
|
|
while (File::Exists(filename))
|
|
|
|
{
|
|
|
|
which++;
|
|
|
|
sprintf(filename, "bad_shader_combo_%i.txt", which);
|
|
|
|
}
|
|
|
|
File::WriteStringToFile(true, error_shaders, filename);
|
2010-12-05 14:15:36 +00:00
|
|
|
PanicAlert("DrawIndexedPrimitiveUP failed. Shaders written to %s", filename);*/
|
2009-11-01 02:03:26 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-10-20 13:22:15 +00:00
|
|
|
void VertexManager::CreateDeviceObjects()
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2012-10-26 14:34:02 +00:00
|
|
|
m_buffers_count = 0;
|
|
|
|
m_vertex_buffers = NULL;
|
|
|
|
m_index_buffers = NULL;
|
2012-10-20 13:22:15 +00:00
|
|
|
D3DCAPS9 DeviceCaps = D3D::GetCaps();
|
2012-10-22 22:37:26 +00:00
|
|
|
u32 devicevMaxBufferSize = DeviceCaps.MaxPrimitiveCount * 3 * DeviceCaps.MaxStreamStride;
|
|
|
|
//Calculate Device Dependant size
|
2012-10-26 14:34:02 +00:00
|
|
|
m_vertex_buffer_size = (VBUFFER_SIZE > devicevMaxBufferSize) ? devicevMaxBufferSize : VBUFFER_SIZE;
|
|
|
|
m_index_buffer_size = (IBUFFER_SIZE > DeviceCaps.MaxVertexIndex) ? DeviceCaps.MaxVertexIndex : IBUFFER_SIZE;
|
2012-10-22 22:37:26 +00:00
|
|
|
//if device caps are not enough for Vbuffer fall back to vertex arrays
|
2012-10-26 14:34:02 +00:00
|
|
|
if (m_index_buffer_size < MAXIBUFFERSIZE || m_vertex_buffer_size < MAXVBUFFERSIZE) return;
|
2012-10-22 22:37:26 +00:00
|
|
|
|
2012-10-26 14:34:02 +00:00
|
|
|
m_vertex_buffers = new LPDIRECT3DVERTEXBUFFER9[MAX_VBUFFER_COUNT];
|
|
|
|
m_index_buffers = new LPDIRECT3DINDEXBUFFER9[MAX_VBUFFER_COUNT];
|
2012-10-22 22:37:26 +00:00
|
|
|
|
2012-10-20 13:22:15 +00:00
|
|
|
bool Fail = false;
|
2012-10-26 14:34:02 +00:00
|
|
|
for (m_current_vertex_buffer = 0; m_current_vertex_buffer < MAX_VBUFFER_COUNT; m_current_vertex_buffer++)
|
2012-10-20 13:22:15 +00:00
|
|
|
{
|
2012-10-26 14:34:02 +00:00
|
|
|
m_vertex_buffers[m_current_vertex_buffer] = NULL;
|
|
|
|
m_index_buffers[m_current_vertex_buffer] = NULL;
|
2012-10-20 13:22:15 +00:00
|
|
|
}
|
2012-10-26 14:34:02 +00:00
|
|
|
for (m_current_vertex_buffer = 0; m_current_vertex_buffer < MAX_VBUFFER_COUNT; m_current_vertex_buffer++)
|
2012-10-20 13:22:15 +00:00
|
|
|
{
|
2012-10-26 14:34:02 +00:00
|
|
|
if(FAILED( D3D::dev->CreateVertexBuffer( m_vertex_buffer_size, D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &m_vertex_buffers[m_current_vertex_buffer], NULL ) ) )
|
2009-11-01 02:03:26 +00:00
|
|
|
{
|
2012-10-20 13:22:15 +00:00
|
|
|
Fail = true;
|
|
|
|
break;
|
|
|
|
}
|
2012-10-26 14:34:02 +00:00
|
|
|
if( FAILED( D3D::dev->CreateIndexBuffer( m_index_buffer_size * sizeof(u16), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &m_index_buffers[m_current_vertex_buffer], NULL ) ) )
|
2012-10-20 13:22:15 +00:00
|
|
|
{
|
|
|
|
Fail = true;
|
|
|
|
return;
|
2009-11-01 02:03:26 +00:00
|
|
|
}
|
2009-10-02 14:03:07 +00:00
|
|
|
}
|
2012-10-26 14:34:02 +00:00
|
|
|
m_buffers_count = m_current_vertex_buffer;
|
|
|
|
m_current_vertex_buffer = 0;
|
|
|
|
m_current_index_buffer = 0;
|
|
|
|
m_index_buffer_cursor = m_index_buffer_size;
|
|
|
|
m_vertex_buffer_cursor = m_vertex_buffer_size;
|
2012-10-27 02:18:09 +00:00
|
|
|
m_current_stride = 0;
|
2012-10-20 13:22:15 +00:00
|
|
|
if (Fail)
|
2009-10-02 14:03:07 +00:00
|
|
|
{
|
2012-10-26 14:34:02 +00:00
|
|
|
m_buffers_count--;
|
|
|
|
if (m_buffers_count < 2)
|
2009-11-01 02:03:26 +00:00
|
|
|
{
|
2012-10-22 22:37:26 +00:00
|
|
|
//Error creating Vertex buffers. clean and fall to Vertex arrays
|
2012-10-26 14:34:02 +00:00
|
|
|
m_buffers_count = MAX_VBUFFER_COUNT;
|
2012-10-20 13:22:15 +00:00
|
|
|
DestroyDeviceObjects();
|
|
|
|
}
|
2012-10-22 22:37:26 +00:00
|
|
|
}
|
2012-10-20 13:22:15 +00:00
|
|
|
}
|
|
|
|
void VertexManager::DestroyDeviceObjects()
|
|
|
|
{
|
2012-10-27 02:18:09 +00:00
|
|
|
D3D::SetStreamSource( 0, NULL, 0, 0);
|
|
|
|
D3D::SetIndices(NULL);
|
2012-10-26 14:34:02 +00:00
|
|
|
for (int i = 0; i < MAX_VBUFFER_COUNT; i++)
|
2012-10-20 13:22:15 +00:00
|
|
|
{
|
2012-10-26 14:34:02 +00:00
|
|
|
if(m_vertex_buffers)
|
2012-10-20 13:22:15 +00:00
|
|
|
{
|
2012-10-26 14:34:02 +00:00
|
|
|
if (m_vertex_buffers[i])
|
2012-10-20 13:22:15 +00:00
|
|
|
{
|
2012-10-26 14:34:02 +00:00
|
|
|
m_vertex_buffers[i]->Release();
|
|
|
|
m_vertex_buffers[i] = NULL;
|
2012-10-20 13:22:15 +00:00
|
|
|
}
|
2009-11-01 02:03:26 +00:00
|
|
|
}
|
2012-10-20 13:22:15 +00:00
|
|
|
|
2012-10-26 14:34:02 +00:00
|
|
|
if (m_index_buffers[i])
|
2012-10-20 13:22:15 +00:00
|
|
|
{
|
2012-10-26 14:34:02 +00:00
|
|
|
m_index_buffers[i]->Release();
|
|
|
|
m_index_buffers[i] = NULL;
|
2012-10-20 13:22:15 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-26 14:34:02 +00:00
|
|
|
if(m_vertex_buffers)
|
|
|
|
delete [] m_vertex_buffers;
|
|
|
|
if(m_index_buffers)
|
|
|
|
delete [] m_index_buffers;
|
|
|
|
m_vertex_buffers = NULL;
|
|
|
|
m_index_buffers = NULL;
|
2012-10-20 13:22:15 +00:00
|
|
|
}
|
|
|
|
|
2012-10-26 14:34:02 +00:00
|
|
|
void VertexManager::PrepareDrawBuffers(u32 stride)
|
2012-10-20 13:22:15 +00:00
|
|
|
{
|
2012-10-26 14:34:02 +00:00
|
|
|
if (!m_buffers_count)
|
2012-10-20 13:22:15 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
u8* pVertices;
|
|
|
|
u16* pIndices;
|
|
|
|
int datasize = IndexGenerator::GetNumVerts() * stride;
|
|
|
|
int TdataSize = IndexGenerator::GetTriangleindexLen();
|
|
|
|
int LDataSize = IndexGenerator::GetLineindexLen();
|
|
|
|
int PDataSize = IndexGenerator::GetPointindexLen();
|
2012-11-12 22:37:08 +00:00
|
|
|
int IndexDataSize = TdataSize + LDataSize;
|
2012-10-20 13:22:15 +00:00
|
|
|
DWORD LockMode = D3DLOCK_NOOVERWRITE;
|
2012-10-27 02:18:09 +00:00
|
|
|
m_vertex_buffer_cursor--;
|
|
|
|
m_vertex_buffer_cursor = m_vertex_buffer_cursor - (m_vertex_buffer_cursor % stride) + stride;
|
2012-10-26 14:34:02 +00:00
|
|
|
if (m_vertex_buffer_cursor > m_vertex_buffer_size - datasize)
|
2012-10-20 13:22:15 +00:00
|
|
|
{
|
|
|
|
LockMode = D3DLOCK_DISCARD;
|
2012-10-26 14:34:02 +00:00
|
|
|
m_vertex_buffer_cursor = 0;
|
2012-10-27 02:18:09 +00:00
|
|
|
m_current_vertex_buffer = (m_current_vertex_buffer + 1) % m_buffers_count;
|
|
|
|
}
|
2012-10-26 14:34:02 +00:00
|
|
|
if(FAILED(m_vertex_buffers[m_current_vertex_buffer]->Lock(m_vertex_buffer_cursor, datasize,(VOID**)(&pVertices), LockMode)))
|
2012-10-20 13:22:15 +00:00
|
|
|
{
|
|
|
|
DestroyDeviceObjects();
|
|
|
|
return;
|
|
|
|
}
|
2013-03-06 15:17:07 +00:00
|
|
|
memcpy(pVertices, s_pBaseBufferPointer, datasize);
|
2012-10-26 14:34:02 +00:00
|
|
|
m_vertex_buffers[m_current_vertex_buffer]->Unlock();
|
2012-10-20 13:22:15 +00:00
|
|
|
|
|
|
|
LockMode = D3DLOCK_NOOVERWRITE;
|
2012-10-26 14:34:02 +00:00
|
|
|
if (m_index_buffer_cursor > m_index_buffer_size - IndexDataSize)
|
2012-10-20 13:22:15 +00:00
|
|
|
{
|
|
|
|
LockMode = D3DLOCK_DISCARD;
|
2012-10-26 14:34:02 +00:00
|
|
|
m_index_buffer_cursor = 0;
|
2012-10-27 02:18:09 +00:00
|
|
|
m_current_index_buffer = (m_current_index_buffer + 1) % m_buffers_count;
|
|
|
|
}
|
2012-10-20 13:22:15 +00:00
|
|
|
|
2012-10-26 14:34:02 +00:00
|
|
|
if(FAILED(m_index_buffers[m_current_index_buffer]->Lock(m_index_buffer_cursor * sizeof(u16), IndexDataSize * sizeof(u16), (VOID**)(&pIndices), LockMode )))
|
2009-09-19 13:14:55 +00:00
|
|
|
{
|
2012-10-20 13:22:15 +00:00
|
|
|
DestroyDeviceObjects();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(TdataSize)
|
|
|
|
{
|
2013-02-27 04:47:50 +00:00
|
|
|
memcpy(pIndices, GetTriangleIndexBuffer(), TdataSize * sizeof(u16));
|
2012-10-20 13:22:15 +00:00
|
|
|
pIndices += TdataSize;
|
|
|
|
}
|
|
|
|
if(LDataSize)
|
|
|
|
{
|
2013-02-27 04:47:50 +00:00
|
|
|
memcpy(pIndices, GetLineIndexBuffer(), LDataSize * sizeof(u16));
|
2012-10-20 13:22:15 +00:00
|
|
|
pIndices += LDataSize;
|
|
|
|
}
|
2012-11-10 14:37:08 +00:00
|
|
|
m_index_buffers[m_current_index_buffer]->Unlock();
|
2012-10-27 02:18:09 +00:00
|
|
|
if(m_current_stride != stride || m_vertex_buffer_cursor == 0)
|
|
|
|
{
|
|
|
|
m_current_stride = stride;
|
|
|
|
D3D::SetStreamSource( 0, m_vertex_buffers[m_current_vertex_buffer], 0, stride);
|
|
|
|
}
|
|
|
|
if (m_index_buffer_cursor == 0)
|
2012-10-22 22:37:26 +00:00
|
|
|
{
|
2012-10-27 02:18:09 +00:00
|
|
|
D3D::SetIndices(m_index_buffers[m_current_index_buffer]);
|
2012-10-22 22:37:26 +00:00
|
|
|
}
|
2012-11-10 14:37:08 +00:00
|
|
|
|
2013-05-23 19:07:01 +00:00
|
|
|
ADDSTAT(stats.thisFrame.bytesVertexStreamed, datasize);
|
|
|
|
ADDSTAT(stats.thisFrame.bytesIndexStreamed, IndexDataSize);
|
2012-10-20 13:22:15 +00:00
|
|
|
}
|
|
|
|
|
2012-10-26 14:34:02 +00:00
|
|
|
void VertexManager::DrawVertexBuffer(int stride)
|
2012-10-20 13:22:15 +00:00
|
|
|
{
|
2012-11-12 01:39:27 +00:00
|
|
|
int triangles = IndexGenerator::GetNumTriangles();
|
|
|
|
int lines = IndexGenerator::GetNumLines();
|
|
|
|
int points = IndexGenerator::GetNumPoints();
|
|
|
|
int numverts = IndexGenerator::GetNumVerts();
|
|
|
|
int StartIndex = m_index_buffer_cursor;
|
|
|
|
int basevertex = m_vertex_buffer_cursor / stride;
|
|
|
|
if (triangles > 0)
|
2012-10-20 13:22:15 +00:00
|
|
|
{
|
2012-10-22 22:37:26 +00:00
|
|
|
if (FAILED(D3D::dev->DrawIndexedPrimitive(
|
2012-10-27 02:18:09 +00:00
|
|
|
D3DPT_TRIANGLELIST,
|
2012-11-12 01:39:27 +00:00
|
|
|
basevertex,
|
2012-10-22 22:37:26 +00:00
|
|
|
0,
|
2012-11-12 01:39:27 +00:00
|
|
|
numverts,
|
|
|
|
StartIndex,
|
|
|
|
triangles)))
|
2012-10-20 13:22:15 +00:00
|
|
|
{
|
2012-10-22 22:37:26 +00:00
|
|
|
DumpBadShaders();
|
2012-10-20 13:22:15 +00:00
|
|
|
}
|
2012-11-12 01:39:27 +00:00
|
|
|
StartIndex += IndexGenerator::GetTriangleindexLen();
|
2012-10-22 22:37:26 +00:00
|
|
|
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
|
|
|
}
|
2012-11-12 01:39:27 +00:00
|
|
|
if (lines > 0)
|
2012-10-22 22:37:26 +00:00
|
|
|
{
|
|
|
|
if (FAILED(D3D::dev->DrawIndexedPrimitive(
|
|
|
|
D3DPT_LINELIST,
|
2012-11-12 01:39:27 +00:00
|
|
|
basevertex,
|
2012-10-22 22:37:26 +00:00
|
|
|
0,
|
2012-11-12 01:39:27 +00:00
|
|
|
numverts,
|
|
|
|
StartIndex,
|
2012-10-22 22:37:26 +00:00
|
|
|
IndexGenerator::GetNumLines())))
|
2012-10-20 13:22:15 +00:00
|
|
|
{
|
2012-10-22 22:37:26 +00:00
|
|
|
DumpBadShaders();
|
2012-10-20 13:22:15 +00:00
|
|
|
}
|
2012-11-12 01:39:27 +00:00
|
|
|
StartIndex += IndexGenerator::GetLineindexLen();
|
2012-10-22 22:37:26 +00:00
|
|
|
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
|
|
|
}
|
2012-11-12 01:39:27 +00:00
|
|
|
if (points > 0)
|
2012-10-22 22:37:26 +00:00
|
|
|
{
|
2012-11-12 22:37:08 +00:00
|
|
|
//DrawIndexedPrimitive does not support point list so we have to draw the points one by one
|
|
|
|
for (int i = 0; i < points; i++)
|
2012-10-20 13:22:15 +00:00
|
|
|
{
|
2012-11-12 22:37:08 +00:00
|
|
|
if (FAILED(D3D::dev->DrawPrimitive(
|
|
|
|
D3DPT_POINTLIST,
|
2013-03-06 15:17:07 +00:00
|
|
|
basevertex + GetPointIndexBuffer()[i],
|
2012-11-12 22:37:08 +00:00
|
|
|
1)))
|
|
|
|
{
|
|
|
|
DumpBadShaders();
|
|
|
|
}
|
|
|
|
INCSTAT(stats.thisFrame.numDrawCalls);
|
2012-10-20 13:22:15 +00:00
|
|
|
}
|
2012-11-12 22:37:08 +00:00
|
|
|
|
|
|
|
|
2012-10-20 13:22:15 +00:00
|
|
|
}
|
2012-10-22 22:37:26 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-10-26 14:34:02 +00:00
|
|
|
void VertexManager::DrawVertexArray(int stride)
|
2012-11-12 01:39:27 +00:00
|
|
|
{
|
|
|
|
int triangles = IndexGenerator::GetNumTriangles();
|
|
|
|
int lines = IndexGenerator::GetNumLines();
|
|
|
|
int points = IndexGenerator::GetNumPoints();
|
|
|
|
int numverts = IndexGenerator::GetNumVerts();
|
|
|
|
if (triangles > 0)
|
2012-10-20 13:22:15 +00:00
|
|
|
{
|
2012-10-22 22:37:26 +00:00
|
|
|
if (FAILED(D3D::dev->DrawIndexedPrimitiveUP(
|
|
|
|
D3DPT_TRIANGLELIST,
|
2012-11-12 01:39:27 +00:00
|
|
|
0, numverts, triangles,
|
2013-02-27 04:47:50 +00:00
|
|
|
GetTriangleIndexBuffer(),
|
2012-10-22 22:37:26 +00:00
|
|
|
D3DFMT_INDEX16,
|
2013-02-21 11:36:29 +00:00
|
|
|
s_pBaseBufferPointer,
|
2012-10-22 22:37:26 +00:00
|
|
|
stride)))
|
2012-10-20 13:22:15 +00:00
|
|
|
{
|
2012-10-22 22:37:26 +00:00
|
|
|
DumpBadShaders();
|
2012-10-20 13:22:15 +00:00
|
|
|
}
|
2012-10-22 22:37:26 +00:00
|
|
|
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
|
|
|
}
|
2012-11-12 01:39:27 +00:00
|
|
|
if (lines > 0)
|
2012-10-22 22:37:26 +00:00
|
|
|
{
|
|
|
|
if (FAILED(D3D::dev->DrawIndexedPrimitiveUP(
|
|
|
|
D3DPT_LINELIST,
|
2012-11-12 01:39:27 +00:00
|
|
|
0, numverts, lines,
|
2013-02-27 04:47:50 +00:00
|
|
|
GetLineIndexBuffer(),
|
2012-10-22 22:37:26 +00:00
|
|
|
D3DFMT_INDEX16,
|
2013-02-21 11:36:29 +00:00
|
|
|
s_pBaseBufferPointer,
|
2012-10-22 22:37:26 +00:00
|
|
|
stride)))
|
2009-11-01 02:03:26 +00:00
|
|
|
{
|
2012-10-22 22:37:26 +00:00
|
|
|
DumpBadShaders();
|
2012-10-20 13:22:15 +00:00
|
|
|
}
|
2012-10-22 22:37:26 +00:00
|
|
|
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
|
|
|
}
|
2012-11-12 01:39:27 +00:00
|
|
|
if (points > 0)
|
2012-10-22 22:37:26 +00:00
|
|
|
{
|
|
|
|
if (FAILED(D3D::dev->DrawIndexedPrimitiveUP(
|
|
|
|
D3DPT_POINTLIST,
|
2012-11-12 01:39:27 +00:00
|
|
|
0, numverts, points,
|
2013-02-27 04:47:50 +00:00
|
|
|
GetPointIndexBuffer(),
|
2012-10-22 22:37:26 +00:00
|
|
|
D3DFMT_INDEX16,
|
2013-02-21 11:36:29 +00:00
|
|
|
s_pBaseBufferPointer,
|
2012-10-22 22:37:26 +00:00
|
|
|
stride)))
|
2012-10-20 13:22:15 +00:00
|
|
|
{
|
2012-10-22 22:37:26 +00:00
|
|
|
DumpBadShaders();
|
2009-11-01 02:03:26 +00:00
|
|
|
}
|
2012-10-22 22:37:26 +00:00
|
|
|
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
|
|
|
}
|
2009-09-19 13:14:55 +00:00
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2010-10-03 00:41:06 +00:00
|
|
|
void VertexManager::vFlush()
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-10-06 14:24:10 +00:00
|
|
|
u32 usedtextures = 0;
|
2010-09-28 02:15:02 +00:00
|
|
|
for (u32 i = 0; i < (u32)bpmem.genMode.numtevstages + 1; ++i)
|
|
|
|
if (bpmem.tevorders[i / 2].getEnable(i & 1))
|
2009-10-06 14:24:10 +00:00
|
|
|
usedtextures |= 1 << bpmem.tevorders[i/2].getTexMap(i & 1);
|
2009-03-07 18:05:29 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
if (bpmem.genMode.numindstages > 0)
|
|
|
|
for (unsigned int i = 0; i < bpmem.genMode.numtevstages + 1; ++i)
|
|
|
|
if (bpmem.tevind[i].IsActive() && bpmem.tevind[i].bt < bpmem.genMode.numindstages)
|
2009-10-06 14:24:10 +00:00
|
|
|
usedtextures |= 1 << bpmem.tevindref.getTexMap(bpmem.tevind[i].bt);
|
2009-03-07 18:05:29 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
for (unsigned int i = 0; i < 8; i++)
|
2009-10-06 14:24:10 +00:00
|
|
|
{
|
2010-09-28 02:15:02 +00:00
|
|
|
if (usedtextures & (1 << i))
|
|
|
|
{
|
2010-11-18 02:21:26 +00:00
|
|
|
g_renderer->SetSamplerState(i & 3, i >> 2);
|
2009-10-06 14:24:10 +00:00
|
|
|
FourTexUnits &tex = bpmem.tex[i >> 2];
|
2010-10-19 22:24:27 +00:00
|
|
|
TextureCache::TCacheEntryBase* tentry = TextureCache::Load(i,
|
2010-09-28 02:15:02 +00:00
|
|
|
(tex.texImage3[i&3].image_base/* & 0x1FFFFF*/) << 5,
|
|
|
|
tex.texImage0[i&3].width + 1, tex.texImage0[i&3].height + 1,
|
2009-10-06 14:24:10 +00:00
|
|
|
tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9,
|
2010-04-14 13:57:16 +00:00
|
|
|
tex.texTlut[i&3].tlut_format,
|
2012-08-10 11:29:19 +00:00
|
|
|
(tex.texMode0[i&3].min_filter & 3),
|
2013-02-16 02:46:03 +00:00
|
|
|
(tex.texMode1[i&3].max_lod + 0xf) / 0x10,
|
2012-01-29 20:49:50 +00:00
|
|
|
tex.texImage1[i&3].image_type);
|
2009-10-06 14:24:10 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
if (tentry)
|
|
|
|
{
|
|
|
|
// 0s are probably for no manual wrapping needed.
|
2012-03-24 03:47:28 +00:00
|
|
|
PixelShaderManager::SetTexDims(i, tentry->native_width, tentry->native_height, 0, 0);
|
2009-10-06 14:24:10 +00:00
|
|
|
}
|
|
|
|
else
|
2013-03-31 23:10:21 +00:00
|
|
|
ERROR_LOG(VIDEO, "Error loading texture");
|
2009-03-07 18:05:29 +00:00
|
|
|
}
|
2009-10-06 14:24:10 +00:00
|
|
|
}
|
2009-07-19 08:17:41 +00:00
|
|
|
|
2009-10-06 14:24:10 +00:00
|
|
|
// set global constants
|
|
|
|
VertexShaderManager::SetConstants();
|
2013-03-26 22:44:41 +00:00
|
|
|
PixelShaderManager::SetConstants(g_nativeVertexFmt->m_components);
|
2012-10-26 14:34:02 +00:00
|
|
|
u32 stride = g_nativeVertexFmt->GetVertexStride();
|
2013-03-28 23:08:51 +00:00
|
|
|
bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate &&
|
|
|
|
bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24;
|
|
|
|
bool useDualSource = useDstAlpha && g_ActiveConfig.backend_info.bSupportsDualSourceBlend;
|
|
|
|
DSTALPHA_MODE AlphaMode = useDualSource ? DSTALPHA_DUAL_SOURCE_BLEND : DSTALPHA_NONE;
|
|
|
|
|
|
|
|
if (!PixelShaderCache::SetShader(AlphaMode ,g_nativeVertexFmt->m_components))
|
2012-03-29 23:56:24 +00:00
|
|
|
{
|
|
|
|
GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");});
|
|
|
|
goto shader_fail;
|
|
|
|
}
|
2009-10-06 14:24:10 +00:00
|
|
|
if (!VertexShaderCache::SetShader(g_nativeVertexFmt->m_components))
|
|
|
|
{
|
2010-12-05 14:15:36 +00:00
|
|
|
GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set vertex shader\n");});
|
2009-10-06 14:24:10 +00:00
|
|
|
goto shader_fail;
|
2009-03-10 14:15:46 +00:00
|
|
|
|
2009-10-06 14:24:10 +00:00
|
|
|
}
|
2012-10-26 14:34:02 +00:00
|
|
|
PrepareDrawBuffers(stride);
|
2013-04-03 22:53:48 +00:00
|
|
|
g_nativeVertexFmt->SetupVertexPointers();
|
|
|
|
g_perf_query->EnableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP);
|
2012-11-10 14:37:08 +00:00
|
|
|
if(m_buffers_count)
|
|
|
|
{
|
|
|
|
DrawVertexBuffer(stride);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DrawVertexArray(stride);
|
|
|
|
}
|
2013-04-03 22:53:48 +00:00
|
|
|
g_perf_query->DisableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP);
|
2013-03-28 23:08:51 +00:00
|
|
|
if (useDstAlpha && !useDualSource)
|
2009-10-06 14:24:10 +00:00
|
|
|
{
|
2012-08-10 16:57:37 +00:00
|
|
|
if (!PixelShaderCache::SetShader(DSTALPHA_ALPHA_PASS, g_nativeVertexFmt->m_components))
|
2010-06-12 15:38:42 +00:00
|
|
|
{
|
2010-12-05 14:15:36 +00:00
|
|
|
GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");});
|
2010-06-12 15:38:42 +00:00
|
|
|
goto shader_fail;
|
|
|
|
}
|
|
|
|
// update alpha only
|
2012-08-10 16:57:37 +00:00
|
|
|
g_renderer->ApplyState(true);
|
2012-11-10 14:37:08 +00:00
|
|
|
if(m_buffers_count)
|
|
|
|
{
|
|
|
|
DrawVertexBuffer(stride);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DrawVertexArray(stride);
|
|
|
|
}
|
2012-04-03 03:08:36 +00:00
|
|
|
g_renderer->RestoreState();
|
|
|
|
}
|
2010-12-05 14:15:36 +00:00
|
|
|
GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true);
|
2009-10-06 14:24:10 +00:00
|
|
|
|
|
|
|
shader_fail:
|
2012-10-26 14:34:02 +00:00
|
|
|
if(m_buffers_count)
|
2012-10-20 13:22:15 +00:00
|
|
|
{
|
2012-10-26 14:34:02 +00:00
|
|
|
m_index_buffer_cursor += IndexGenerator::GetTriangleindexLen() + IndexGenerator::GetLineindexLen() + IndexGenerator::GetPointindexLen();
|
|
|
|
m_vertex_buffer_cursor += IndexGenerator::GetNumVerts() * stride;
|
2012-10-20 13:22:15 +00:00
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2010-10-03 00:41:06 +00:00
|
|
|
|
|
|
|
}
|