Merge pull request #2274 from degasus/disable_bbox

Disable bbox
This commit is contained in:
Ryan Houdek
2015-05-25 08:46:12 -04:00
28 changed files with 47 additions and 175 deletions

View File

@ -379,16 +379,11 @@ 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);
}
else
{
BoundingBox::coords[offset] = bp.newvalue & 0x3ff;
BoundingBox::coords[offset + 1] = bp.newvalue >> 10;
}
}
return;
case BPMEM_TEXINVALIDATE:

View File

@ -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)

View File

@ -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);

View File

@ -157,7 +157,16 @@ u32 VideoBackendHardware::Video_GetQueryResult(PerfQueryType type)
u16 VideoBackendHardware::Video_GetBoundingBox(int index)
{
if (!g_ActiveConfig.backend_info.bSupportsBBox)
return BoundingBox::coords[index];
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);

View File

@ -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";

View File

@ -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)
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)
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)
BoundingBox::Prepare(m_vat, primitive, m_VtxDesc, m_native_vtx_decl);
for (int s = 0; s < count; s++)
{
m_tcIndex = 0;

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -512,7 +512,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);

View File

@ -13,7 +13,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;

View File

@ -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);

View File

@ -112,6 +112,7 @@ struct VideoConfig final
// Hacks
bool bEFBAccessEnable;
bool bPerfQueriesEnable;
bool bBBoxEnable;
bool bEFBEmulateFormatChanges;
bool bSkipEFBCopyToRam;