| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | // Copyright (C) 2003 Dolphin Project.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // This program is free software: you can redistribute it and/or modify
 | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by
 | 
					
						
							|  |  |  | // the Free Software Foundation, version 2.0.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful,
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					
						
							|  |  |  | // GNU General Public License 2.0 for more details.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // A copy of the GPL 2.0 should have been included with the program.
 | 
					
						
							|  |  |  | // If not, see http://www.gnu.org/licenses/
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Official SVN repository and contact information can be found at
 | 
					
						
							|  |  |  | // http://code.google.com/p/dolphin-emu/
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "D3DBase.h"
 | 
					
						
							| 
									
										
										
										
											2011-01-25 16:43:08 +00:00
										 |  |  | #include "PixelShaderCache.h"
 | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | #include "VertexManager.h"
 | 
					
						
							|  |  |  | #include "VertexShaderCache.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-25 16:43:08 +00:00
										 |  |  | #include "BPMemory.h"
 | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | #include "Debugger.h"
 | 
					
						
							| 
									
										
										
										
											2011-01-25 16:43:08 +00:00
										 |  |  | #include "IndexGenerator.h"
 | 
					
						
							|  |  |  | #include "MainBase.h"
 | 
					
						
							|  |  |  | #include "PixelShaderManager.h"
 | 
					
						
							|  |  |  | #include "RenderBase.h"
 | 
					
						
							| 
									
										
										
										
											2011-03-15 03:51:31 +00:00
										 |  |  | #include "Render.h"
 | 
					
						
							| 
									
										
										
										
											2011-01-25 16:43:08 +00:00
										 |  |  | #include "Statistics.h"
 | 
					
						
							|  |  |  | #include "TextureCacheBase.h"
 | 
					
						
							|  |  |  | #include "VertexShaderManager.h"
 | 
					
						
							|  |  |  | #include "VideoConfig.h"
 | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-28 02:15:02 +00:00
										 |  |  | // internal state for loading vertices
 | 
					
						
							|  |  |  | extern NativeVertexFormat *g_nativeVertexFmt; | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-03 00:41:06 +00:00
										 |  |  | namespace DX11 | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 02:17:16 +00:00
										 |  |  | // TODO: Find sensible values for these two
 | 
					
						
							| 
									
										
										
										
											2012-10-22 19:37:26 -03:00
										 |  |  | const UINT IBUFFER_SIZE = VertexManager::MAXIBUFFERSIZE * 16 * sizeof(u16); | 
					
						
							|  |  |  | const UINT VBUFFER_SIZE = VertexManager::MAXVBUFFERSIZE * 16; | 
					
						
							|  |  |  | const UINT MAXVBUFFER_COUNT = 2; | 
					
						
							| 
									
										
										
										
											2010-10-20 02:17:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-11 19:37:21 +00:00
										 |  |  | void VertexManager::CreateDeviceObjects() | 
					
						
							| 
									
										
										
										
											2010-10-03 00:41:06 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-10-20 02:17:16 +00:00
										 |  |  | 	D3D11_BUFFER_DESC bufdesc = CD3D11_BUFFER_DESC(IBUFFER_SIZE, | 
					
						
							|  |  |  | 		D3D11_BIND_INDEX_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE); | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 02:17:16 +00:00
										 |  |  | 	m_vertexDrawOffset = 0; | 
					
						
							|  |  |  | 	m_triangleDrawIndex = 0; | 
					
						
							|  |  |  | 	m_lineDrawIndex = 0; | 
					
						
							|  |  |  | 	m_pointDrawIndex = 0; | 
					
						
							| 
									
										
										
										
											2012-10-20 10:22:15 -03:00
										 |  |  | 	m_indexBuffers = new PID3D11Buffer[MAXVBUFFER_COUNT]; | 
					
						
							| 
									
										
										
										
											2012-10-22 19:37:26 -03:00
										 |  |  | 	m_vertexBuffers = new PID3D11Buffer[MAXVBUFFER_COUNT];	 | 
					
						
							| 
									
										
										
										
											2012-10-20 10:22:15 -03:00
										 |  |  | 	for (m_activeIndexBuffer = 0; m_activeIndexBuffer < MAXVBUFFER_COUNT; m_activeIndexBuffer++) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2012-10-22 19:37:26 -03:00
										 |  |  | 		m_indexBuffers[m_activeIndexBuffer] = NULL; | 
					
						
							| 
									
										
										
										
											2012-10-20 10:22:15 -03:00
										 |  |  | 		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++) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2012-10-22 19:37:26 -03:00
										 |  |  | 		m_vertexBuffers[m_activeVertexBuffer] = NULL; | 
					
						
							| 
									
										
										
										
											2012-10-20 10:22:15 -03:00
										 |  |  | 		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; | 
					
						
							| 
									
										
										
										
											2012-10-22 19:37:26 -03:00
										 |  |  | 	m_indexBufferCursor = IBUFFER_SIZE; | 
					
						
							|  |  |  | 	m_vertexBufferCursor = VBUFFER_SIZE; | 
					
						
							| 
									
										
										
										
											2011-06-11 19:37:21 +00:00
										 |  |  | 	m_lineShader.Init(); | 
					
						
							|  |  |  | 	m_pointShader.Init(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void VertexManager::DestroyDeviceObjects() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_pointShader.Shutdown(); | 
					
						
							|  |  |  | 	m_lineShader.Shutdown(); | 
					
						
							| 
									
										
										
										
											2012-10-20 10:22:15 -03:00
										 |  |  | 	for (m_activeVertexBuffer = 0; m_activeVertexBuffer < MAXVBUFFER_COUNT; m_activeVertexBuffer++) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		SAFE_RELEASE(m_vertexBuffers[m_activeVertexBuffer]); | 
					
						
							|  |  |  | 		SAFE_RELEASE(m_indexBuffers[m_activeVertexBuffer]); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2011-06-11 19:37:21 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | VertexManager::VertexManager() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	CreateDeviceObjects(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | VertexManager::~VertexManager() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	DestroyDeviceObjects(); | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 02:17:16 +00:00
										 |  |  | void VertexManager::LoadBuffers() | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	D3D11_MAPPED_SUBRESOURCE map; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 02:17:16 +00:00
										 |  |  | 	UINT vSize = UINT(s_pCurBufferPointer - LocalVBuffer); | 
					
						
							| 
									
										
										
										
											2012-10-20 10:22:15 -03:00
										 |  |  | 	D3D11_MAP MapType = D3D11_MAP_WRITE_NO_OVERWRITE; | 
					
						
							| 
									
										
										
										
											2012-10-22 19:37:26 -03:00
										 |  |  | 	if (m_vertexBufferCursor + vSize >= VBUFFER_SIZE) | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2010-10-20 02:17:16 +00:00
										 |  |  | 		// Wrap around
 | 
					
						
							| 
									
										
										
										
											2012-10-20 10:22:15 -03:00
										 |  |  | 		m_activeVertexBuffer = (m_activeVertexBuffer + 1) % MAXVBUFFER_COUNT;		 | 
					
						
							| 
									
										
										
										
											2010-10-20 02:17:16 +00:00
										 |  |  | 		m_vertexBufferCursor = 0; | 
					
						
							| 
									
										
										
										
											2012-10-20 10:22:15 -03:00
										 |  |  | 		MapType = D3D11_MAP_WRITE_DISCARD; | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-10-20 10:22:15 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	D3D::context->Map(m_vertexBuffers[m_activeVertexBuffer], 0, MapType, 0, &map); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 02:17:16 +00:00
										 |  |  | 	memcpy((u8*)map.pData + m_vertexBufferCursor, LocalVBuffer, vSize); | 
					
						
							| 
									
										
										
										
											2012-10-20 10:22:15 -03:00
										 |  |  | 	D3D::context->Unmap(m_vertexBuffers[m_activeVertexBuffer], 0); | 
					
						
							| 
									
										
										
										
											2010-10-20 02:17:16 +00:00
										 |  |  | 	m_vertexDrawOffset = m_vertexBufferCursor; | 
					
						
							|  |  |  | 	m_vertexBufferCursor += vSize; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	UINT iCount = IndexGenerator::GetTriangleindexLen() + | 
					
						
							|  |  |  | 		IndexGenerator::GetLineindexLen() + IndexGenerator::GetPointindexLen(); | 
					
						
							| 
									
										
										
										
											2012-10-20 10:22:15 -03:00
										 |  |  | 	MapType = D3D11_MAP_WRITE_NO_OVERWRITE; | 
					
						
							| 
									
										
										
										
											2012-10-22 19:37:26 -03:00
										 |  |  | 	if (m_indexBufferCursor + iCount >= (IBUFFER_SIZE / sizeof(u16))) | 
					
						
							| 
									
										
										
										
											2010-10-20 02:17:16 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		// Wrap around
 | 
					
						
							| 
									
										
										
										
											2012-10-20 10:22:15 -03:00
										 |  |  | 		m_activeIndexBuffer = (m_activeIndexBuffer + 1) % MAXVBUFFER_COUNT;		 | 
					
						
							| 
									
										
										
										
											2010-10-20 02:17:16 +00:00
										 |  |  | 		m_indexBufferCursor = 0; | 
					
						
							| 
									
										
										
										
											2012-10-20 10:22:15 -03:00
										 |  |  | 		MapType = D3D11_MAP_WRITE_DISCARD; | 
					
						
							| 
									
										
										
										
											2010-10-20 02:17:16 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-10-20 10:22:15 -03:00
										 |  |  | 	D3D::context->Map(m_indexBuffers[m_activeIndexBuffer], 0, MapType, 0, &map); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 02:17:16 +00:00
										 |  |  | 	m_triangleDrawIndex = m_indexBufferCursor; | 
					
						
							|  |  |  | 	m_lineDrawIndex = m_triangleDrawIndex + IndexGenerator::GetTriangleindexLen(); | 
					
						
							|  |  |  | 	m_pointDrawIndex = m_lineDrawIndex + IndexGenerator::GetLineindexLen(); | 
					
						
							| 
									
										
										
										
											2012-10-22 19:37:26 -03:00
										 |  |  | 	memcpy((u16*)map.pData + m_triangleDrawIndex, TIBuffer, sizeof(u16) * IndexGenerator::GetTriangleindexLen()); | 
					
						
							|  |  |  | 	memcpy((u16*)map.pData + m_lineDrawIndex, LIBuffer, sizeof(u16) * IndexGenerator::GetLineindexLen()); | 
					
						
							|  |  |  | 	memcpy((u16*)map.pData + m_pointDrawIndex, PIBuffer, sizeof(u16) * IndexGenerator::GetPointindexLen()); | 
					
						
							| 
									
										
										
										
											2012-10-20 10:22:15 -03:00
										 |  |  | 	D3D::context->Unmap(m_indexBuffers[m_activeIndexBuffer], 0); | 
					
						
							| 
									
										
										
										
											2010-10-20 02:17:16 +00:00
										 |  |  | 	m_indexBufferCursor += iCount; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-14 09:38:29 +00:00
										 |  |  | static const float LINE_PT_TEX_OFFSETS[8] = { | 
					
						
							|  |  |  | 	0.f, 0.0625f, 0.125f, 0.25f, 0.5f, 1.f, 1.f, 1.f | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 03:11:22 +00:00
										 |  |  | void VertexManager::Draw(UINT stride) | 
					
						
							| 
									
										
										
										
											2010-10-20 02:17:16 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-10-20 10:22:15 -03:00
										 |  |  | 	D3D::context->IASetVertexBuffers(0, 1, &m_vertexBuffers[m_activeVertexBuffer], &stride, &m_vertexDrawOffset); | 
					
						
							|  |  |  | 	D3D::context->IASetIndexBuffer(m_indexBuffers[m_activeIndexBuffer], DXGI_FORMAT_R16_UINT, 0); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | 	if (IndexGenerator::GetNumTriangles() > 0) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2011-06-11 19:37:21 +00:00
										 |  |  | 		D3D::context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); | 
					
						
							|  |  |  | 		D3D::context->DrawIndexed(IndexGenerator::GetTriangleindexLen(), m_triangleDrawIndex, 0); | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | 		INCSTAT(stats.thisFrame.numIndexedDrawCalls); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-03-15 03:51:31 +00:00
										 |  |  | 	// Disable culling for lines and points
 | 
					
						
							|  |  |  | 	if (IndexGenerator::GetNumLines() > 0 || IndexGenerator::GetNumPoints() > 0) | 
					
						
							|  |  |  | 		((DX11::Renderer*)g_renderer)->ApplyCullDisable(); | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | 	if (IndexGenerator::GetNumLines() > 0) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2011-03-14 09:38:29 +00:00
										 |  |  | 		float lineWidth = float(bpmem.lineptwidth.linesize) / 6.f; | 
					
						
							|  |  |  | 		float texOffset = LINE_PT_TEX_OFFSETS[bpmem.lineptwidth.lineoff]; | 
					
						
							| 
									
										
										
										
											2011-04-11 01:49:32 +00:00
										 |  |  | 		float vpWidth = 2.0f * xfregs.viewport.wd; | 
					
						
							|  |  |  | 		float vpHeight = -2.0f * xfregs.viewport.ht; | 
					
						
							| 
									
										
										
										
											2011-03-14 09:38:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-15 22:34:54 +00:00
										 |  |  | 		bool texOffsetEnable[8]; | 
					
						
							| 
									
										
										
										
											2011-06-11 19:37:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-15 22:34:54 +00:00
										 |  |  | 		for (int i = 0; i < 8; ++i) | 
					
						
							|  |  |  | 			texOffsetEnable[i] = bpmem.texcoords[i].s.line_offset; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (m_lineShader.SetShader(g_nativeVertexFmt->m_components, lineWidth, | 
					
						
							|  |  |  | 			texOffset, vpWidth, vpHeight, texOffsetEnable)) | 
					
						
							| 
									
										
										
										
											2011-03-14 09:38:29 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2011-06-11 19:37:21 +00:00
										 |  |  | 			D3D::context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST); | 
					
						
							|  |  |  | 			D3D::context->DrawIndexed(IndexGenerator::GetLineindexLen(), m_lineDrawIndex, 0); | 
					
						
							| 
									
										
										
										
											2011-03-14 09:38:29 +00:00
										 |  |  | 			INCSTAT(stats.thisFrame.numIndexedDrawCalls); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-11 19:37:21 +00:00
										 |  |  | 			D3D::context->GSSetShader(NULL, NULL, 0); | 
					
						
							| 
									
										
										
										
											2011-03-14 09:38:29 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (IndexGenerator::GetNumPoints() > 0) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2011-03-14 09:38:29 +00:00
										 |  |  | 		float pointSize = float(bpmem.lineptwidth.pointsize) / 6.f; | 
					
						
							|  |  |  | 		float texOffset = LINE_PT_TEX_OFFSETS[bpmem.lineptwidth.pointoff]; | 
					
						
							| 
									
										
										
										
											2011-04-11 01:49:32 +00:00
										 |  |  | 		float vpWidth = 2.0f * xfregs.viewport.wd; | 
					
						
							|  |  |  | 		float vpHeight = -2.0f * xfregs.viewport.ht; | 
					
						
							| 
									
										
										
										
											2011-03-14 09:38:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-15 22:34:54 +00:00
										 |  |  | 		bool texOffsetEnable[8]; | 
					
						
							| 
									
										
										
										
											2011-06-11 19:37:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-15 22:34:54 +00:00
										 |  |  | 		for (int i = 0; i < 8; ++i) | 
					
						
							|  |  |  | 			texOffsetEnable[i] = bpmem.texcoords[i].s.point_offset; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (m_pointShader.SetShader(g_nativeVertexFmt->m_components, pointSize, | 
					
						
							|  |  |  | 			texOffset, vpWidth, vpHeight, texOffsetEnable)) | 
					
						
							| 
									
										
										
										
											2011-03-14 09:38:29 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2011-06-11 19:37:21 +00:00
										 |  |  | 			D3D::context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST); | 
					
						
							|  |  |  | 			D3D::context->DrawIndexed(IndexGenerator::GetPointindexLen(), m_pointDrawIndex, 0); | 
					
						
							| 
									
										
										
										
											2011-03-14 09:38:29 +00:00
										 |  |  | 			INCSTAT(stats.thisFrame.numIndexedDrawCalls); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-11 19:37:21 +00:00
										 |  |  | 			D3D::context->GSSetShader(NULL, NULL, 0); | 
					
						
							| 
									
										
										
										
											2011-03-14 09:38:29 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-03-15 03:51:31 +00:00
										 |  |  | 	if (IndexGenerator::GetNumLines() > 0 || IndexGenerator::GetNumPoints() > 0) | 
					
						
							|  |  |  | 		((DX11::Renderer*)g_renderer)->RestoreCull(); | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-03 00:41:06 +00:00
										 |  |  | void VertexManager::vFlush() | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (LocalVBuffer == s_pCurBufferPointer) return; | 
					
						
							|  |  |  | 	if (Flushed) return; | 
					
						
							|  |  |  | 	Flushed=true; | 
					
						
							| 
									
										
										
										
											2010-06-29 14:40:37 +00:00
										 |  |  | 	VideoFifo_CheckEFBAccess(); | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	u32 usedtextures = 0; | 
					
						
							|  |  |  | 	for (u32 i = 0; i < (u32)bpmem.genMode.numtevstages + 1; ++i) | 
					
						
							| 
									
										
										
										
											2010-09-28 02:15:02 +00:00
										 |  |  | 		if (bpmem.tevorders[i / 2].getEnable(i & 1)) | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | 			usedtextures |= 1 << bpmem.tevorders[i/2].getTexMap(i & 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	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) | 
					
						
							|  |  |  | 				usedtextures |= 1 << bpmem.tevindref.getTexMap(bpmem.tevind[i].bt); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (unsigned int i = 0; i < 8; i++) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (usedtextures & (1 << i)) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2010-11-18 02:21:26 +00:00
										 |  |  | 			g_renderer->SetSamplerState(i & 3, i >> 2); | 
					
						
							| 
									
										
										
										
											2010-10-20 02:17:16 +00:00
										 |  |  | 			const FourTexUnits &tex = bpmem.tex[i >> 2]; | 
					
						
							|  |  |  | 			const 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, | 
					
						
							|  |  |  | 				tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9,  | 
					
						
							|  |  |  | 				tex.texTlut[i&3].tlut_format, | 
					
						
							| 
									
										
										
										
											2012-08-10 13:29:19 +02:00
										 |  |  | 				(tex.texMode0[i&3].min_filter & 3), | 
					
						
							|  |  |  | 				ceil(tex.texMode1[i&3].max_lod / 16.f), | 
					
						
							| 
									
										
										
										
											2012-01-29 21:49:50 +01:00
										 |  |  | 				tex.texImage1[i&3].image_type); | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (tentry) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2010-09-28 02:15:02 +00:00
										 |  |  | 				// 0s are probably for no manual wrapping needed.
 | 
					
						
							| 
									
										
										
										
											2012-03-24 04:47:28 +01:00
										 |  |  | 				PixelShaderManager::SetTexDims(i, tentry->native_width, tentry->native_height, 0, 0); | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				ERROR_LOG(VIDEO, "error loading texture"); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-28 02:15:02 +00:00
										 |  |  | 	// set global constants
 | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | 	VertexShaderManager::SetConstants(); | 
					
						
							| 
									
										
										
										
											2012-03-24 04:47:28 +01:00
										 |  |  | 	PixelShaderManager::SetConstants(); | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 18:22:04 +00:00
										 |  |  | 	bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate && | 
					
						
							| 
									
										
										
										
											2010-10-20 03:11:22 +00:00
										 |  |  | 		bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-11 19:37:21 +00:00
										 |  |  | 	if (!PixelShaderCache::SetShader( | 
					
						
							| 
									
										
										
										
											2012-08-10 18:57:37 +02:00
										 |  |  | 		useDstAlpha ? DSTALPHA_DUAL_SOURCE_BLEND : DSTALPHA_NONE, | 
					
						
							| 
									
										
										
										
											2010-10-21 05:22:18 +00:00
										 |  |  | 		g_nativeVertexFmt->m_components)) | 
					
						
							| 
									
										
										
										
											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-13 19:50:06 +00:00
										 |  |  | 		goto shader_fail; | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-06-11 19:37:21 +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 pixel shader\n");}); | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | 		goto shader_fail; | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-10-20 10:22:15 -03:00
										 |  |  | 	LoadBuffers(); | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | 	unsigned int stride = g_nativeVertexFmt->GetVertexStride(); | 
					
						
							|  |  |  | 	g_nativeVertexFmt->SetupVertexPointers(); | 
					
						
							| 
									
										
										
										
											2012-08-10 18:57:37 +02:00
										 |  |  | 	g_renderer->ApplyState(useDstAlpha); | 
					
						
							| 
									
										
										
										
											2012-10-20 10:22:15 -03:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2010-10-20 03:11:22 +00:00
										 |  |  | 	Draw(stride); | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | 	GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-30 01:56:24 +02:00
										 |  |  | 	g_renderer->RestoreState(); | 
					
						
							| 
									
										
										
										
											2011-01-24 10:42:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | shader_fail: | 
					
						
							|  |  |  | 	ResetBuffer(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-10-03 00:41:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-13 19:50:06 +00:00
										 |  |  | }  // namespace
 |