From ac0e3041599429f271d6fddc284ec3e4753c0cd3 Mon Sep 17 00:00:00 2001
From: degasus <wickmarkus@web.de>
Date: Sat, 2 May 2015 22:30:56 +0200
Subject: [PATCH 1/6] Jitregister: fix common-core dependency

---
 Source/Core/Common/JitRegister.cpp              | 4 +---
 Source/Core/Common/JitRegister.h                | 2 +-
 Source/Core/Core/PowerPC/JitCommon/JitCache.cpp | 2 +-
 3 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/Source/Core/Common/JitRegister.cpp b/Source/Core/Common/JitRegister.cpp
index 7b0d24454a..47ddf19c79 100644
--- a/Source/Core/Common/JitRegister.cpp
+++ b/Source/Core/Common/JitRegister.cpp
@@ -12,7 +12,6 @@
 #include "Common/FileUtil.h"
 #include "Common/JitRegister.h"
 #include "Common/StringUtil.h"
-#include "Core/ConfigManager.h"
 
 #ifdef _WIN32
 #include <process.h>
@@ -38,13 +37,12 @@ static File::IOFile s_perf_map_file;
 namespace JitRegister
 {
 
-void Init()
+void Init(const std::string& perf_dir)
 {
 #if defined USE_OPROFILE && USE_OPROFILE
 	s_agent = op_open_agent();
 #endif
 
-	const std::string& perf_dir = SConfig::GetInstance().m_LocalCoreStartupParameter.m_perfDir;
 	if (!perf_dir.empty())
 	{
 		std::string filename = StringFromFormat("%s/perf-%d.map", perf_dir.data(), getpid());
diff --git a/Source/Core/Common/JitRegister.h b/Source/Core/Common/JitRegister.h
index ce63aeace0..a1f19d9fef 100644
--- a/Source/Core/Common/JitRegister.h
+++ b/Source/Core/Common/JitRegister.h
@@ -9,7 +9,7 @@
 namespace JitRegister
 {
 
-void Init();
+void Init(const std::string& perf_dir);
 void Shutdown();
 void RegisterV(const void* base_address, u32 code_size,
 	const char* format, va_list args);
diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp
index 6a7b6102d4..003cea9e90 100644
--- a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp
+++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp
@@ -36,7 +36,7 @@ using namespace Gen;
 			return;
 		}
 
-		JitRegister::Init();
+		JitRegister::Init(SConfig::GetInstance().m_LocalCoreStartupParameter.m_perfDir);
 
 		iCache.fill(JIT_ICACHE_INVALID_BYTE);
 		iCacheEx.fill(JIT_ICACHE_INVALID_BYTE);

From acd074e291d287080031d7295baa6e2f7862440f Mon Sep 17 00:00:00 2001
From: degasus <wickmarkus@web.de>
Date: Mon, 6 Apr 2015 02:17:57 +0200
Subject: [PATCH 2/6] VideoCommon: Make BBox emulation optional

---
 Source/Core/DolphinWX/VideoConfigDiag.cpp  | 2 ++
 Source/Core/VideoCommon/BPStructs.cpp      | 2 +-
 Source/Core/VideoCommon/MainBase.cpp       | 2 +-
 Source/Core/VideoCommon/PixelShaderGen.cpp | 4 ++--
 Source/Core/VideoCommon/VertexLoader.cpp   | 6 +++---
 Source/Core/VideoCommon/VideoConfig.cpp    | 3 +++
 Source/Core/VideoCommon/VideoConfig.h      | 1 +
 7 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/Source/Core/DolphinWX/VideoConfigDiag.cpp b/Source/Core/DolphinWX/VideoConfigDiag.cpp
index 8af3dff615..9fb9086238 100644
--- a/Source/Core/DolphinWX/VideoConfigDiag.cpp
+++ b/Source/Core/DolphinWX/VideoConfigDiag.cpp
@@ -110,6 +110,7 @@ static wxString aa_desc = _("Reduces the amount of aliasing caused by rasterizin
 static wxString scaled_efb_copy_desc = _("Greatly increases quality of textures generated using render-to-texture effects.\nRaising the internal resolution will improve the effect of this setting.\nSlightly increases GPU load and causes relatively few graphical issues.\n\nIf unsure, leave this checked.");
 static wxString pixel_lighting_desc = _("Calculates lighting of 3D objects per-pixel rather than per-vertex, smoothing out the appearance of lit polygons and making individual triangles less noticeable.\nRarely causes slowdowns or graphical issues.\n\nIf unsure, leave this unchecked.");
 static wxString fast_depth_calc_desc = _("Use a less accurate algorithm to calculate depth values.\nCauses issues in a few games, but can give a decent speedup depending on the game and/or your GPU.\n\nIf unsure, leave this checked.");
+static wxString disable_bbox_desc = _("Disable the bounding box emulation.\nThis may improve the GPU performance a lot, but some games will break.\n\nIf unsure, leave this checked.");
 static wxString force_filtering_desc = _("Filter all textures, including any that the game explicitly set as unfiltered.\nMay improve quality of certain textures in some games, but will cause issues in others.\nOn Direct3D, setting Anisotropic Filtering above 1x will also have the same effect as enabling this option.\n\nIf unsure, leave this unchecked.");
 static wxString borderless_fullscreen_desc = _("Implement fullscreen mode with a borderless window spanning the whole screen instead of using exclusive mode.\nAllows for faster transitions between fullscreen and windowed mode, but slightly increases input latency, makes movement less smooth and slightly decreases performance.\nExclusive mode is required for Nvidia 3D Vision to work in the Direct3D backend.\n\nIf unsure, leave this unchecked.");
 static wxString internal_res_desc = _("Specifies the resolution used to render at. A high resolution greatly improves visual quality, but also greatly increases GPU load and can cause issues in certain games.\n\"Multiple of 640x528\" will result in a size slightly larger than \"Window Size\" but yield fewer issues. Generally speaking, the lower the internal resolution is, the better your performance will be.\n\nIf unsure, select 640x528.");
@@ -517,6 +518,7 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title, con
 	wxGridSizer* const szr_other = new wxGridSizer(2, 5, 5);
 	szr_other->Add(CreateCheckBox(page_hacks, _("Disable Destination Alpha"), disable_dstalpha_desc, vconfig.bDstAlphaPass));
 	szr_other->Add(CreateCheckBox(page_hacks, _("Fast Depth Calculation"), fast_depth_calc_desc, vconfig.bFastDepthCalc));
+	szr_other->Add(CreateCheckBox(page_hacks, _("Disable Bounding Box"), disable_bbox_desc, vconfig.bBBoxEnable, true));
 
 	wxStaticBoxSizer* const group_other = new wxStaticBoxSizer(wxVERTICAL, page_hacks, _("Other"));
 	group_other->Add(szr_other, 1, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5);
diff --git a/Source/Core/VideoCommon/BPStructs.cpp b/Source/Core/VideoCommon/BPStructs.cpp
index 44f6964cfb..29913559c6 100644
--- a/Source/Core/VideoCommon/BPStructs.cpp
+++ b/Source/Core/VideoCommon/BPStructs.cpp
@@ -379,7 +379,7 @@ static void BPWritten(const BPCmd& bp)
 			u8 offset = bp.address & 2;
 			BoundingBox::active = true;
 
-			if (g_ActiveConfig.backend_info.bSupportsBBox)
+			if (g_ActiveConfig.backend_info.bSupportsBBox && g_ActiveConfig.bBBoxEnable)
 			{
 				g_renderer->BBoxWrite(offset, bp.newvalue & 0x3ff);
 				g_renderer->BBoxWrite(offset + 1, bp.newvalue >> 10);
diff --git a/Source/Core/VideoCommon/MainBase.cpp b/Source/Core/VideoCommon/MainBase.cpp
index 102e17db34..1454d88ca0 100644
--- a/Source/Core/VideoCommon/MainBase.cpp
+++ b/Source/Core/VideoCommon/MainBase.cpp
@@ -152,7 +152,7 @@ u32 VideoBackendHardware::Video_GetQueryResult(PerfQueryType type)
 
 u16 VideoBackendHardware::Video_GetBoundingBox(int index)
 {
-	if (!g_ActiveConfig.backend_info.bSupportsBBox)
+	if (!g_ActiveConfig.backend_info.bSupportsBBox || !g_ActiveConfig.bBBoxEnable)
 		return BoundingBox::coords[index];
 
 	SyncGPU(SYNC_GPU_BBOX);
diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp
index f3db81fbf4..90c80136c2 100644
--- a/Source/Core/VideoCommon/PixelShaderGen.cpp
+++ b/Source/Core/VideoCommon/PixelShaderGen.cpp
@@ -277,7 +277,7 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
 		out.Write("};\n");
 	}
 
-	if (g_ActiveConfig.backend_info.bSupportsBBox)
+	if (g_ActiveConfig.backend_info.bSupportsBBox && g_ActiveConfig.bBBoxEnable)
 	{
 		if (ApiType == API_OPENGL)
 		{
@@ -641,7 +641,7 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
 		out.Write("\tocol0.a = float(" I_ALPHA".a) / 255.0;\n");
 	}
 
-	if (g_ActiveConfig.backend_info.bSupportsBBox && BoundingBox::active)
+	if (g_ActiveConfig.backend_info.bSupportsBBox && g_ActiveConfig.bBBoxEnable && BoundingBox::active)
 	{
 		uid_data->bounding_box = true;
 		const char* atomic_op = ApiType == API_OPENGL ? "atomic" : "Interlocked";
diff --git a/Source/Core/VideoCommon/VertexLoader.cpp b/Source/Core/VideoCommon/VertexLoader.cpp
index 49b6d23e1a..8e5c73b6a0 100644
--- a/Source/Core/VideoCommon/VertexLoader.cpp
+++ b/Source/Core/VideoCommon/VertexLoader.cpp
@@ -88,7 +88,7 @@ void VertexLoader::CompileVertexTranslator()
 	m_numPipelineStages = 0;
 
 	// Get the pointer to this vertex's buffer data for the bounding box
-	if (!g_ActiveConfig.backend_info.bSupportsBBox)
+	if (!g_ActiveConfig.backend_info.bSupportsBBox && g_ActiveConfig.bBBoxEnable)
 		WriteCall(BoundingBox::SetVertexBufferPosition);
 
 	// Colors
@@ -299,7 +299,7 @@ void VertexLoader::CompileVertexTranslator()
 	}
 
 	// Update the bounding box
-	if (!g_ActiveConfig.backend_info.bSupportsBBox)
+	if (!g_ActiveConfig.backend_info.bSupportsBBox && g_ActiveConfig.bBBoxEnable)
 		WriteCall(BoundingBox::Update);
 
 	// indexed position formats may skip a the vertex
@@ -326,7 +326,7 @@ int VertexLoader::RunVertices(DataReader src, DataReader dst, int count, int pri
 	m_skippedVertices = 0;
 
 	// Prepare bounding box
-	if (!g_ActiveConfig.backend_info.bSupportsBBox)
+	if (!g_ActiveConfig.backend_info.bSupportsBBox && g_ActiveConfig.bBBoxEnable)
 		BoundingBox::Prepare(m_vat, primitive, m_VtxDesc, m_native_vtx_decl);
 
 	for (int s = 0; s < count; s++)
diff --git a/Source/Core/VideoCommon/VideoConfig.cpp b/Source/Core/VideoCommon/VideoConfig.cpp
index 5201f13ba7..b8044bd880 100644
--- a/Source/Core/VideoCommon/VideoConfig.cpp
+++ b/Source/Core/VideoCommon/VideoConfig.cpp
@@ -97,6 +97,7 @@ void VideoConfig::Load(const std::string& ini_file)
 
 	IniFile::Section* hacks = iniFile.GetOrCreateSection("Hacks");
 	hacks->Get("EFBAccessEnable", &bEFBAccessEnable, true);
+	hacks->Get("BBoxEnable", &bBBoxEnable, false);
 	hacks->Get("EFBToTextureEnable", &bSkipEFBCopyToRam, true);
 	hacks->Get("EFBScaledCopy", &bCopyEFBScaled, true);
 	hacks->Get("EFBEmulateFormatChanges", &bEFBEmulateFormatChanges, false);
@@ -196,6 +197,7 @@ void VideoConfig::GameIniLoad()
 	CHECK_SETTING("Video_Stereoscopy", "StereoConvergenceMinimum", iStereoConvergenceMinimum);
 
 	CHECK_SETTING("Video_Hacks", "EFBAccessEnable", bEFBAccessEnable);
+	CHECK_SETTING("Video_Hacks", "BBoxEnable", bBBoxEnable);
 	CHECK_SETTING("Video_Hacks", "EFBToTextureEnable", bSkipEFBCopyToRam);
 	CHECK_SETTING("Video_Hacks", "EFBScaledCopy", bCopyEFBScaled);
 	CHECK_SETTING("Video_Hacks", "EFBEmulateFormatChanges", bEFBEmulateFormatChanges);
@@ -283,6 +285,7 @@ void VideoConfig::Save(const std::string& ini_file)
 
 	IniFile::Section* hacks = iniFile.GetOrCreateSection("Hacks");
 	hacks->Set("EFBAccessEnable", bEFBAccessEnable);
+	hacks->Set("BBoxEnable", bBBoxEnable);
 	hacks->Set("EFBToTextureEnable", bSkipEFBCopyToRam);
 	hacks->Set("EFBScaledCopy", bCopyEFBScaled);
 	hacks->Set("EFBEmulateFormatChanges", bEFBEmulateFormatChanges);
diff --git a/Source/Core/VideoCommon/VideoConfig.h b/Source/Core/VideoCommon/VideoConfig.h
index b0f133e759..37eeb50101 100644
--- a/Source/Core/VideoCommon/VideoConfig.h
+++ b/Source/Core/VideoCommon/VideoConfig.h
@@ -112,6 +112,7 @@ struct VideoConfig final
 	// Hacks
 	bool bEFBAccessEnable;
 	bool bPerfQueriesEnable;
+	bool bBBoxEnable;
 
 	bool bEFBEmulateFormatChanges;
 	bool bSkipEFBCopyToRam;

From 6b2a1e57e2482efb46a91401fa22aaf5ef779974 Mon Sep 17 00:00:00 2001
From: degasus <wickmarkus@web.de>
Date: Mon, 6 Apr 2015 11:44:13 +0200
Subject: [PATCH 3/6] BBox: remove now unreachable SW bbox implementation

---
 .../VideoBackends/Software/SWVertexLoader.cpp |   3 +-
 .../VideoBackends/Software/SWVertexLoader.h   |   1 -
 Source/Core/VideoCommon/BoundingBox.cpp       | 121 ------------------
 Source/Core/VideoCommon/BoundingBox.h         |  10 --
 Source/Core/VideoCommon/VertexLoader.cpp      |  19 +--
 Source/Core/VideoCommon/VertexLoader.h        |   2 +-
 Source/Core/VideoCommon/VertexLoaderARM64.cpp |   2 +-
 Source/Core/VideoCommon/VertexLoaderARM64.h   |   2 +-
 Source/Core/VideoCommon/VertexLoaderBase.cpp  |   6 +-
 Source/Core/VideoCommon/VertexLoaderBase.h    |   2 +-
 .../Core/VideoCommon/VertexLoaderManager.cpp  |   2 +-
 Source/Core/VideoCommon/VertexLoaderX64.cpp   |   2 +-
 Source/Core/VideoCommon/VertexLoaderX64.h     |   2 +-
 .../VideoCommon/VertexLoaderTest.cpp          |   2 +-
 14 files changed, 15 insertions(+), 161 deletions(-)

diff --git a/Source/Core/VideoBackends/Software/SWVertexLoader.cpp b/Source/Core/VideoBackends/Software/SWVertexLoader.cpp
index 859cf593b4..31c6eebb17 100644
--- a/Source/Core/VideoBackends/Software/SWVertexLoader.cpp
+++ b/Source/Core/VideoBackends/Software/SWVertexLoader.cpp
@@ -33,7 +33,6 @@ SWVertexLoader::~SWVertexLoader()
 void SWVertexLoader::SetFormat(u8 attributeIndex, u8 primitiveType)
 {
 	m_attributeIndex = attributeIndex;
-	m_primitiveType = primitiveType;
 
 	VertexLoaderUID uid(g_main_cp_state.vtx_desc, g_main_cp_state.vtx_attr[m_attributeIndex]);
 	m_CurrentLoader = m_VertexLoaderMap[uid].get();
@@ -182,7 +181,7 @@ void SWVertexLoader::LoadVertex()
 	int converted_vertices = m_CurrentLoader->RunVertices(
 		DataReader(g_video_buffer_read_ptr, nullptr), // src
 		DataReader(m_LoadedVertices.data(), m_LoadedVertices.data() + m_LoadedVertices.size()), // dst
-		1, m_primitiveType
+		1 // vertices
 	);
 	g_video_buffer_read_ptr = old + m_CurrentLoader->m_VertexSize;
 
diff --git a/Source/Core/VideoBackends/Software/SWVertexLoader.h b/Source/Core/VideoBackends/Software/SWVertexLoader.h
index cfdbd9efd5..ff6c4cc18c 100644
--- a/Source/Core/VideoBackends/Software/SWVertexLoader.h
+++ b/Source/Core/VideoBackends/Software/SWVertexLoader.h
@@ -36,7 +36,6 @@ class SWVertexLoader
 	VertexLoaderBase* m_CurrentLoader;
 
 	u8 m_attributeIndex;
-	u8 m_primitiveType;
 
 public:
 	SWVertexLoader();
diff --git a/Source/Core/VideoCommon/BoundingBox.cpp b/Source/Core/VideoCommon/BoundingBox.cpp
index 9ea0fa5689..795302978b 100644
--- a/Source/Core/VideoCommon/BoundingBox.cpp
+++ b/Source/Core/VideoCommon/BoundingBox.cpp
@@ -18,127 +18,6 @@ namespace BoundingBox
 // External vars
 bool active = false;
 u16 coords[4] = { 0x80, 0xA0, 0x80, 0xA0 };
-u8 posMtxIdx;
-u8 texMtxIdx[8];
-
-
-// Internal vars
-static SetupUnit vtxUnit;
-static VAT myVat;
-static u8 * bufferPos;
-static TVtxDesc vertexDesc;
-static PortableVertexDeclaration vertexDecl;
-
-// Gets the pointer to the current buffer position
-void LOADERDECL SetVertexBufferPosition(VertexLoader* loader)
-{
-	bufferPos = g_vertex_manager_write_ptr;
-}
-
-// Prepares the bounding box for new primitive data
-void Prepare(const VAT & vat, int primitive, const TVtxDesc & vtxDesc, const PortableVertexDeclaration & vtxDecl)
-{
-	if (!active)
-		return;
-
-	myVat = vat;
-	vertexDesc = vtxDesc;
-	vertexDecl = vtxDecl;
-
-	vtxUnit.Init(primitive);
-
-	// Initialize the SW renderer
-	static bool SWinit = false;
-
-	if (!SWinit)
-	{
-		Clipper::Init();
-		Rasterizer::Init();
-		SWinit = true;
-	}
-
-	// Update SW renderer values
-	Clipper::SetViewOffset();
-	Rasterizer::SetScissor();
-
-	for (u8 i = 0; i < 4; ++i)
-	{
-		Rasterizer::SetTevReg(i, 0, true, (s16)PixelShaderManager::constants.kcolors[i][0]);
-		Rasterizer::SetTevReg(i, 1, true, (s16)PixelShaderManager::constants.kcolors[i][1]);
-		Rasterizer::SetTevReg(i, 2, true, (s16)PixelShaderManager::constants.kcolors[i][2]);
-		Rasterizer::SetTevReg(i, 3, true, (s16)PixelShaderManager::constants.kcolors[i][3]);
-
-		Rasterizer::SetTevReg(i, 0, false, (s16)PixelShaderManager::constants.colors[i][0]);
-		Rasterizer::SetTevReg(i, 1, false, (s16)PixelShaderManager::constants.colors[i][1]);
-		Rasterizer::SetTevReg(i, 2, false, (s16)PixelShaderManager::constants.colors[i][2]);
-		Rasterizer::SetTevReg(i, 3, false, (s16)PixelShaderManager::constants.colors[i][3]);
-	}
-}
-
-// Updates the bounding box
-void LOADERDECL Update(VertexLoader* loader)
-{
-	if (!active)
-		return;
-
-	// Grab vertex input data and transform to output vertex
-	InputVertexData myVertex;
-	OutputVertexData * outVertex = vtxUnit.GetVertex();
-
-	// Feed vertex position and matrix
-	myVertex.position = Vec3((const float *)bufferPos);
-	myVertex.posMtx = vertexDesc.PosMatIdx ? posMtxIdx : g_main_cp_state.matrix_index_a.PosNormalMtxIdx;
-
-	// Transform position
-	TransformUnit::TransformPosition(&myVertex, outVertex);
-
-	if (g_main_cp_state.vtx_desc.Normal != NOT_PRESENT)
-	{
-		// Feed normal input data and transform
-		memcpy((u8 *)myVertex.normal, bufferPos + vertexDecl.normals[0].offset, sizeof(float) * 3 * ((myVat.g0.NormalElements) ? 3 : 1));
-
-		TransformUnit::TransformNormal(&myVertex, myVat.g0.NormalElements, outVertex);
-	}
-
-	// Feed color input data
-	for (int i = 0; i < 2; ++i)
-	{
-		if (vertexDecl.colors[i].enable)
-		{
-			u32 color;
-			memcpy((u8 *)&color, bufferPos + vertexDecl.colors[i].offset, sizeof(u32));
-			*(u32*)myVertex.color[i] = Common::swap32(color);
-		}
-	}
-
-	// Transform color
-	TransformUnit::TransformColor(&myVertex, outVertex);
-
-	// Feed texture matrices
-	int idx = 0;
-
-	myVertex.texMtx[0] = (vertexDesc.Tex0MatIdx) ? texMtxIdx[idx++] : g_main_cp_state.matrix_index_a.Tex0MtxIdx;
-	myVertex.texMtx[1] = (vertexDesc.Tex1MatIdx) ? texMtxIdx[idx++] : g_main_cp_state.matrix_index_a.Tex1MtxIdx;
-	myVertex.texMtx[2] = (vertexDesc.Tex2MatIdx) ? texMtxIdx[idx++] : g_main_cp_state.matrix_index_a.Tex2MtxIdx;
-	myVertex.texMtx[3] = (vertexDesc.Tex3MatIdx) ? texMtxIdx[idx++] : g_main_cp_state.matrix_index_a.Tex3MtxIdx;
-	myVertex.texMtx[4] = (vertexDesc.Tex4MatIdx) ? texMtxIdx[idx++] : g_main_cp_state.matrix_index_b.Tex4MtxIdx;
-	myVertex.texMtx[5] = (vertexDesc.Tex5MatIdx) ? texMtxIdx[idx++] : g_main_cp_state.matrix_index_b.Tex5MtxIdx;
-	myVertex.texMtx[6] = (vertexDesc.Tex6MatIdx) ? texMtxIdx[idx++] : g_main_cp_state.matrix_index_b.Tex6MtxIdx;
-	myVertex.texMtx[7] = (vertexDesc.Tex7MatIdx) ? texMtxIdx[idx++] : g_main_cp_state.matrix_index_b.Tex7MtxIdx;
-
-	// Feed texture coordinate data
-	for (int i = 0; i < 8; ++i)
-	{
-		if (vertexDecl.texcoords[i].enable)
-			memcpy((u8 *)&myVertex.texCoords[i], bufferPos + vertexDecl.texcoords[i].offset, sizeof(float) * 2);
-	}
-
-	// Transform texture coordinate
-	TransformUnit::TransformTexCoord(&myVertex, outVertex, false);
-
-	// Render the vertex in SW to calculate bbox
-	vtxUnit.SetupVertex();
-}
 
 // Save state
 void DoState(PointerWrap &p)
diff --git a/Source/Core/VideoCommon/BoundingBox.h b/Source/Core/VideoCommon/BoundingBox.h
index afff0e3e72..fd1faee30c 100644
--- a/Source/Core/VideoCommon/BoundingBox.h
+++ b/Source/Core/VideoCommon/BoundingBox.h
@@ -25,16 +25,6 @@ enum
 	BOTTOM = 3
 };
 
-// Current position matrix index
-extern u8 posMtxIdx;
-
-// Texture matrix indexes
-extern u8 texMtxIdx[8];
-
-void LOADERDECL SetVertexBufferPosition(VertexLoader* loader);
-void LOADERDECL Update(VertexLoader* loader);
-void Prepare(const VAT & vat, int primitive, const TVtxDesc & vtxDesc, const PortableVertexDeclaration & vtxDecl);
-
 // Save state
 void DoState(PointerWrap &p);
 
diff --git a/Source/Core/VideoCommon/VertexLoader.cpp b/Source/Core/VideoCommon/VertexLoader.cpp
index 8e5c73b6a0..d7dad1c95a 100644
--- a/Source/Core/VideoCommon/VertexLoader.cpp
+++ b/Source/Core/VideoCommon/VertexLoader.cpp
@@ -7,7 +7,6 @@
 
 #include "Core/Host.h"
 
-#include "VideoCommon/BoundingBox.h"
 #include "VideoCommon/DataReader.h"
 #include "VideoCommon/PixelEngine.h"
 #include "VideoCommon/VertexLoader.h"
@@ -24,14 +23,14 @@ u8* g_vertex_manager_write_ptr;
 
 static void LOADERDECL PosMtx_ReadDirect_UByte(VertexLoader* loader)
 {
-	u8 posmtx = BoundingBox::posMtxIdx = DataReadU8() & 0x3f;
+	u32 posmtx = DataReadU8() & 0x3f;
 	DataWrite<u32>(posmtx);
 	PRIM_LOG("posmtx: %d, ", posmtx);
 }
 
 static void LOADERDECL TexMtx_ReadDirect_UByte(VertexLoader* loader)
 {
-	BoundingBox::texMtxIdx[loader->m_texmtxread] = loader->m_curtexmtx[loader->m_texmtxread] = DataReadU8() & 0x3f;
+	loader->m_curtexmtx[loader->m_texmtxread] = DataReadU8() & 0x3f;
 
 	PRIM_LOG("texmtx%d: %d, ", loader->m_texmtxread, loader->m_curtexmtx[loader->m_texmtxread]);
 	loader->m_texmtxread++;
@@ -87,10 +86,6 @@ void VertexLoader::CompileVertexTranslator()
 	// Reset pipeline
 	m_numPipelineStages = 0;
 
-	// Get the pointer to this vertex's buffer data for the bounding box
-	if (!g_ActiveConfig.backend_info.bSupportsBBox && g_ActiveConfig.bBBoxEnable)
-		WriteCall(BoundingBox::SetVertexBufferPosition);
-
 	// Colors
 	const u64 col[2] = { m_VtxDesc.Color0, m_VtxDesc.Color1 };
 	// TextureCoord
@@ -298,10 +293,6 @@ void VertexLoader::CompileVertexTranslator()
 		}
 	}
 
-	// Update the bounding box
-	if (!g_ActiveConfig.backend_info.bSupportsBBox && g_ActiveConfig.bBBoxEnable)
-		WriteCall(BoundingBox::Update);
-
 	// indexed position formats may skip a the vertex
 	if (m_VtxDesc.Position & 2)
 	{
@@ -317,7 +308,7 @@ void VertexLoader::WriteCall(TPipelineFunction func)
 	m_PipelineStages[m_numPipelineStages++] = func;
 }
 
-int VertexLoader::RunVertices(DataReader src, DataReader dst, int count, int primitive)
+int VertexLoader::RunVertices(DataReader src, DataReader dst, int count)
 {
 	g_vertex_manager_write_ptr = dst.GetPointer();
 	g_video_buffer_read_ptr = src.GetPointer();
@@ -325,10 +316,6 @@ int VertexLoader::RunVertices(DataReader src, DataReader dst, int count, int pri
 	m_numLoadedVertices += count;
 	m_skippedVertices = 0;
 
-	// Prepare bounding box
-	if (!g_ActiveConfig.backend_info.bSupportsBBox && g_ActiveConfig.bBBoxEnable)
-		BoundingBox::Prepare(m_vat, primitive, m_VtxDesc, m_native_vtx_decl);
-
 	for (int s = 0; s < count; s++)
 	{
 		m_tcIndex = 0;
diff --git a/Source/Core/VideoCommon/VertexLoader.h b/Source/Core/VideoCommon/VertexLoader.h
index 3bae14a2d0..4e6e19f727 100644
--- a/Source/Core/VideoCommon/VertexLoader.h
+++ b/Source/Core/VideoCommon/VertexLoader.h
@@ -32,7 +32,7 @@ class VertexLoader : public VertexLoaderBase
 public:
 	VertexLoader(const TVtxDesc &vtx_desc, const VAT &vtx_attr);
 
-	int RunVertices(DataReader src, DataReader dst, int count, int primitive) override;
+	int RunVertices(DataReader src, DataReader dst, int count) override;
 	std::string GetName() const override { return "OldLoader"; }
 	bool IsInitialized() override { return true; } // This vertex loader supports all formats
 
diff --git a/Source/Core/VideoCommon/VertexLoaderARM64.cpp b/Source/Core/VideoCommon/VertexLoaderARM64.cpp
index 397a179e9e..11bfd4b495 100644
--- a/Source/Core/VideoCommon/VertexLoaderARM64.cpp
+++ b/Source/Core/VideoCommon/VertexLoaderARM64.cpp
@@ -535,7 +535,7 @@ void VertexLoaderARM64::GenerateVertexLoader()
 	m_native_vtx_decl.stride = m_dst_ofs;
 }
 
-int VertexLoaderARM64::RunVertices(DataReader src, DataReader dst, int count, int primitive)
+int VertexLoaderARM64::RunVertices(DataReader src, DataReader dst, int count)
 {
 	m_numLoadedVertices += count;
 	return ((int (*)(u8* src, u8* dst, int count))region)(src.GetPointer(), dst.GetPointer(), count);
diff --git a/Source/Core/VideoCommon/VertexLoaderARM64.h b/Source/Core/VideoCommon/VertexLoaderARM64.h
index 4a6a389201..b67ac78cf2 100644
--- a/Source/Core/VideoCommon/VertexLoaderARM64.h
+++ b/Source/Core/VideoCommon/VertexLoaderARM64.h
@@ -14,7 +14,7 @@ public:
 protected:
 	std::string GetName() const override { return "VertexLoaderARM64"; }
 	bool IsInitialized() override { return true; }
-	int RunVertices(DataReader src, DataReader dst, int count, int primitive) override;
+	int RunVertices(DataReader src, DataReader dst, int count) override;
 
 private:
 	u32 m_src_ofs = 0;
diff --git a/Source/Core/VideoCommon/VertexLoaderBase.cpp b/Source/Core/VideoCommon/VertexLoaderBase.cpp
index 9089ee67af..94ba4f2728 100644
--- a/Source/Core/VideoCommon/VertexLoaderBase.cpp
+++ b/Source/Core/VideoCommon/VertexLoaderBase.cpp
@@ -161,13 +161,13 @@ public:
 		delete b;
 	}
 
-	int RunVertices(DataReader src, DataReader dst, int count, int primitive) override
+	int RunVertices(DataReader src, DataReader dst, int count) override
 	{
 		buffer_a.resize(count * a->m_native_vtx_decl.stride + 4);
 		buffer_b.resize(count * b->m_native_vtx_decl.stride + 4);
 
-		int count_a = a->RunVertices(src, DataReader(buffer_a.data(), buffer_a.data()+buffer_a.size()), count, primitive);
-		int count_b = b->RunVertices(src, DataReader(buffer_b.data(), buffer_b.data()+buffer_b.size()), count, primitive);
+		int count_a = a->RunVertices(src, DataReader(buffer_a.data(), buffer_a.data()+buffer_a.size()), count);
+		int count_b = b->RunVertices(src, DataReader(buffer_b.data(), buffer_b.data()+buffer_b.size()), count);
 
 		if (count_a != count_b)
 			ERROR_LOG(VIDEO, "The two vertex loaders have loaded a different amount of vertices (a: %d, b: %d).", count_a, count_b);
diff --git a/Source/Core/VideoCommon/VertexLoaderBase.h b/Source/Core/VideoCommon/VertexLoaderBase.h
index fc3737ae69..9b8391a52f 100644
--- a/Source/Core/VideoCommon/VertexLoaderBase.h
+++ b/Source/Core/VideoCommon/VertexLoaderBase.h
@@ -74,7 +74,7 @@ public:
 	static VertexLoaderBase* CreateVertexLoader(const TVtxDesc &vtx_desc, const VAT &vtx_attr);
 	virtual ~VertexLoaderBase() {}
 
-	virtual int RunVertices(DataReader src, DataReader dst, int count, int primitive) = 0;
+	virtual int RunVertices(DataReader src, DataReader dst, int count) = 0;
 
 	virtual bool IsInitialized() = 0;
 
diff --git a/Source/Core/VideoCommon/VertexLoaderManager.cpp b/Source/Core/VideoCommon/VertexLoaderManager.cpp
index 74dad016cb..199197646a 100644
--- a/Source/Core/VideoCommon/VertexLoaderManager.cpp
+++ b/Source/Core/VideoCommon/VertexLoaderManager.cpp
@@ -165,7 +165,7 @@ int RunVertices(int vtx_attr_group, int primitive, int count, DataReader src, bo
 	DataReader dst = VertexManager::PrepareForAdditionalData(primitive, count,
 			loader->m_native_vtx_decl.stride, cullall);
 
-	count = loader->RunVertices(src, dst, count, primitive);
+	count = loader->RunVertices(src, dst, count);
 
 	IndexGenerator::AddIndices(primitive, count);
 
diff --git a/Source/Core/VideoCommon/VertexLoaderX64.cpp b/Source/Core/VideoCommon/VertexLoaderX64.cpp
index 1754a32fb4..6aa85be2fa 100644
--- a/Source/Core/VideoCommon/VertexLoaderX64.cpp
+++ b/Source/Core/VideoCommon/VertexLoaderX64.cpp
@@ -508,7 +508,7 @@ void VertexLoaderX64::GenerateVertexLoader()
 	m_native_vtx_decl.stride = m_dst_ofs;
 }
 
-int VertexLoaderX64::RunVertices(DataReader src, DataReader dst, int count, int primitive)
+int VertexLoaderX64::RunVertices(DataReader src, DataReader dst, int count)
 {
 	m_numLoadedVertices += count;
 	return ((int (*)(u8* src, u8* dst, int count))region)(src.GetPointer(), dst.GetPointer(), count);
diff --git a/Source/Core/VideoCommon/VertexLoaderX64.h b/Source/Core/VideoCommon/VertexLoaderX64.h
index 53b7b58d9e..9f04f7e094 100644
--- a/Source/Core/VideoCommon/VertexLoaderX64.h
+++ b/Source/Core/VideoCommon/VertexLoaderX64.h
@@ -9,7 +9,7 @@ public:
 protected:
 	std::string GetName() const override { return "VertexLoaderX64"; }
 	bool IsInitialized() override { return true; }
-	int RunVertices(DataReader src, DataReader dst, int count, int primitive) override;
+	int RunVertices(DataReader src, DataReader dst, int count) override;
 
 private:
 	u32 m_src_ofs = 0;
diff --git a/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp b/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp
index 1c6579b795..0fe5db1b55 100644
--- a/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp
+++ b/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp
@@ -83,7 +83,7 @@ protected:
 		if (expected_count == -1)
 			expected_count = count;
 		ResetPointers();
-		int actual_count = m_loader->RunVertices(m_src, m_dst, count, GX_DRAW_POINTS);
+		int actual_count = m_loader->RunVertices(m_src, m_dst, count);
 		EXPECT_EQ(actual_count, expected_count);
 	}
 

From 029912681e1f6a17ad68f8593c78d514b863724c Mon Sep 17 00:00:00 2001
From: degasus <wickmarkus@web.de>
Date: Sat, 23 May 2015 16:05:21 +0200
Subject: [PATCH 4/6] VideoCommon: return 0 if bbox is disabled

Through just returning the last written value sounds better, this crashes Paper Mario.
In my opinion, gfx issues are fine on older GPUs, but crashes should not happen.
---
 Source/Core/VideoCommon/BPStructs.cpp | 5 -----
 Source/Core/VideoCommon/MainBase.cpp  | 2 +-
 2 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/Source/Core/VideoCommon/BPStructs.cpp b/Source/Core/VideoCommon/BPStructs.cpp
index 29913559c6..7148b2a0cc 100644
--- a/Source/Core/VideoCommon/BPStructs.cpp
+++ b/Source/Core/VideoCommon/BPStructs.cpp
@@ -384,11 +384,6 @@ static void BPWritten(const BPCmd& bp)
 				g_renderer->BBoxWrite(offset, bp.newvalue & 0x3ff);
 				g_renderer->BBoxWrite(offset + 1, bp.newvalue >> 10);
 			}
-			else
-			{
-				BoundingBox::coords[offset]     = bp.newvalue & 0x3ff;
-				BoundingBox::coords[offset + 1] = bp.newvalue >> 10;
-			}
 		}
 		return;
 	case BPMEM_TEXINVALIDATE:
diff --git a/Source/Core/VideoCommon/MainBase.cpp b/Source/Core/VideoCommon/MainBase.cpp
index 1454d88ca0..e06ce3c84e 100644
--- a/Source/Core/VideoCommon/MainBase.cpp
+++ b/Source/Core/VideoCommon/MainBase.cpp
@@ -153,7 +153,7 @@ u32 VideoBackendHardware::Video_GetQueryResult(PerfQueryType type)
 u16 VideoBackendHardware::Video_GetBoundingBox(int index)
 {
 	if (!g_ActiveConfig.backend_info.bSupportsBBox || !g_ActiveConfig.bBBoxEnable)
-		return BoundingBox::coords[index];
+		return 0;
 
 	SyncGPU(SYNC_GPU_BBOX);
 

From 7e127da791cd8b81626fa2d196f874365cf4fab2 Mon Sep 17 00:00:00 2001
From: degasus <wickmarkus@web.de>
Date: Sat, 23 May 2015 16:08:49 +0200
Subject: [PATCH 5/6] VideoCommon: Warn if bbox is disabled but used

---
 Source/Core/VideoCommon/MainBase.cpp | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/Source/Core/VideoCommon/MainBase.cpp b/Source/Core/VideoCommon/MainBase.cpp
index e06ce3c84e..17ead5265e 100644
--- a/Source/Core/VideoCommon/MainBase.cpp
+++ b/Source/Core/VideoCommon/MainBase.cpp
@@ -152,9 +152,18 @@ u32 VideoBackendHardware::Video_GetQueryResult(PerfQueryType type)
 
 u16 VideoBackendHardware::Video_GetBoundingBox(int index)
 {
-	if (!g_ActiveConfig.backend_info.bSupportsBBox || !g_ActiveConfig.bBBoxEnable)
+	if (!g_ActiveConfig.backend_info.bSupportsBBox)
 		return 0;
 
+	if (!g_ActiveConfig.bBBoxEnable)
+	{
+		static bool warn_once = true;
+		if (warn_once)
+			ERROR_LOG(VIDEO, "BBox shall be used but it is disabled. Please use a gameini to enable it for this game.");
+		warn_once = false;
+		return 0;
+	}
+
 	SyncGPU(SYNC_GPU_BBOX);
 
 	AsyncRequests::Event e;

From fc76d0df38b8324c876f9fd8a1594f1df5b60ba7 Mon Sep 17 00:00:00 2001
From: degasus <wickmarkus@web.de>
Date: Mon, 25 May 2015 09:48:50 +0200
Subject: [PATCH 6/6] BBox: Touch old gameinis again

---
 Data/Sys/GameSettings/G8M.ini | 1 +
 Data/Sys/GameSettings/GDM.ini | 2 ++
 Data/Sys/GameSettings/GHV.ini | 2 ++
 Data/Sys/GameSettings/GSZ.ini | 3 +++
 Data/Sys/GameSettings/R8P.ini | 2 ++
 5 files changed, 10 insertions(+)

diff --git a/Data/Sys/GameSettings/G8M.ini b/Data/Sys/GameSettings/G8M.ini
index 1516199687..1c07b83be4 100644
--- a/Data/Sys/GameSettings/G8M.ini
+++ b/Data/Sys/GameSettings/G8M.ini
@@ -19,4 +19,5 @@ EmulationIssues = Needs Efb to Ram for BBox (proper graphics).
 
 [Video_Hacks]
 EFBToTextureEnable = False
+BBoxEnable = True
 
diff --git a/Data/Sys/GameSettings/GDM.ini b/Data/Sys/GameSettings/GDM.ini
index 783be19817..5445559bd5 100644
--- a/Data/Sys/GameSettings/GDM.ini
+++ b/Data/Sys/GameSettings/GDM.ini
@@ -17,3 +17,5 @@ EmulationIssues =
 [ActionReplay]
 # Add action replay cheats here.
 
+[Video_Hacks]
+BBoxEnable = True
diff --git a/Data/Sys/GameSettings/GHV.ini b/Data/Sys/GameSettings/GHV.ini
index ef688ce114..4acedba8a0 100644
--- a/Data/Sys/GameSettings/GHV.ini
+++ b/Data/Sys/GameSettings/GHV.ini
@@ -17,3 +17,5 @@ EmulationIssues =
 [ActionReplay]
 # Add action replay cheats here.
 
+[Video_Hacks]
+BBoxEnable = True
diff --git a/Data/Sys/GameSettings/GSZ.ini b/Data/Sys/GameSettings/GSZ.ini
index a305be0faa..d87d2d594c 100644
--- a/Data/Sys/GameSettings/GSZ.ini
+++ b/Data/Sys/GameSettings/GSZ.ini
@@ -25,3 +25,6 @@ PH_SZFar = 0
 PH_ExtraParam = 0
 PH_ZNear =
 PH_ZFar =
+
+[Video_Hacks]
+BBoxEnable = True
diff --git a/Data/Sys/GameSettings/R8P.ini b/Data/Sys/GameSettings/R8P.ini
index 22ee7db50f..8cc62012b6 100644
--- a/Data/Sys/GameSettings/R8P.ini
+++ b/Data/Sys/GameSettings/R8P.ini
@@ -23,3 +23,5 @@ ProjectionHack = 0
 [Video_Hacks]
 EFBToTextureEnable = False
 
+[Video_Hacks]
+BBoxEnable = True