2010-05-28 23:14:16 +00:00
|
|
|
// Copyright (C) 2003-2009 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/
|
|
|
|
|
|
|
|
// TODO: Handle cache-is-full condition :p
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include "Common.h"
|
|
|
|
#include "VideoCommon.h"
|
|
|
|
#include "Hash.h"
|
|
|
|
#include "MemoryUtil.h"
|
|
|
|
#include "DataReader.h"
|
|
|
|
#include "Statistics.h"
|
|
|
|
#include "OpcodeDecoding.h" // For the GX_ constants.
|
|
|
|
|
|
|
|
#include "XFMemory.h"
|
|
|
|
#include "CPMemory.h"
|
|
|
|
#include "BPMemory.h"
|
|
|
|
|
|
|
|
#include "VertexLoaderManager.h"
|
2010-08-29 23:08:56 +00:00
|
|
|
#include "NativeVertexWriter.h"
|
2010-05-28 23:14:16 +00:00
|
|
|
#include "x64Emitter.h"
|
|
|
|
#include "ABI.h"
|
|
|
|
|
|
|
|
#include "DLCache.h"
|
|
|
|
|
|
|
|
#define DL_CODE_CACHE_SIZE (1024*1024*16)
|
|
|
|
extern int frameCount;
|
|
|
|
|
|
|
|
using namespace Gen;
|
|
|
|
|
|
|
|
namespace DLCache
|
|
|
|
{
|
|
|
|
|
|
|
|
// Currently just recompiles the DLs themselves, doesn't bother with the vertex data.
|
|
|
|
// The speed boost is pretty small. The real big boost will come when we also store
|
|
|
|
// vertex arrays in the cached DLs.
|
|
|
|
|
|
|
|
enum DisplayListPass {
|
|
|
|
DLPASS_ANALYZE,
|
|
|
|
DLPASS_COMPILE,
|
|
|
|
DLPASS_RUN,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VDataHashRegion
|
|
|
|
{
|
|
|
|
u32 hash;
|
|
|
|
u32 start_address;
|
|
|
|
int size;
|
|
|
|
};
|
2010-08-29 23:08:56 +00:00
|
|
|
typedef u8* DataPointer;
|
|
|
|
typedef std::map<u8, DataPointer> VdataMap;
|
2010-05-28 23:14:16 +00:00
|
|
|
|
|
|
|
struct CachedDisplayList
|
|
|
|
{
|
|
|
|
CachedDisplayList()
|
2010-08-29 23:08:56 +00:00
|
|
|
: uncachable(false),
|
|
|
|
pass(DLPASS_ANALYZE),
|
|
|
|
next_check(1),
|
|
|
|
BufferCount(0),
|
|
|
|
num_xf_reg(0),
|
|
|
|
num_cp_reg(0),
|
|
|
|
num_bp_reg(0),
|
|
|
|
num_index_xf(0),
|
|
|
|
num_draw_call(0)
|
2010-05-28 23:14:16 +00:00
|
|
|
{
|
|
|
|
frame_count = frameCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool uncachable; // if set, this DL will always be interpreted. This gets set if hash ever changes.
|
|
|
|
|
|
|
|
int pass;
|
2010-08-28 15:09:42 +00:00
|
|
|
u64 dl_hash;
|
2010-05-28 23:14:16 +00:00
|
|
|
|
|
|
|
int check;
|
|
|
|
int next_check;
|
|
|
|
|
|
|
|
int frame_count;
|
|
|
|
|
|
|
|
// ... Something containing cached vertex buffers here ...
|
2010-08-29 23:08:56 +00:00
|
|
|
u8 BufferCount;
|
|
|
|
VdataMap Vdata;
|
|
|
|
|
|
|
|
int num_xf_reg;
|
|
|
|
int num_cp_reg;
|
|
|
|
int num_bp_reg;
|
|
|
|
int num_index_xf;
|
|
|
|
int num_draw_call;
|
2010-05-28 23:14:16 +00:00
|
|
|
|
|
|
|
// Compile the commands themselves down to native code.
|
2010-08-29 23:08:56 +00:00
|
|
|
const u8* compiled_code;
|
2010-05-28 23:14:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// We want to allow caching DLs that start at the same address but have different lengths,
|
|
|
|
// so the size has to be in the ID.
|
|
|
|
inline u64 CreateMapId(u32 address, u32 size)
|
|
|
|
{
|
|
|
|
return ((u64)address << 32) | size;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef std::map<u64, CachedDisplayList> DLMap;
|
|
|
|
|
|
|
|
static DLMap dl_map;
|
2010-08-29 23:08:56 +00:00
|
|
|
static DataPointer dlcode_cache;
|
2010-05-28 23:14:16 +00:00
|
|
|
|
|
|
|
static Gen::XEmitter emitter;
|
|
|
|
|
|
|
|
// First pass - analyze
|
|
|
|
bool AnalyzeAndRunDisplayList(u32 address, int size, CachedDisplayList *dl)
|
|
|
|
{
|
|
|
|
int num_xf_reg = 0;
|
|
|
|
int num_cp_reg = 0;
|
2010-08-29 23:08:56 +00:00
|
|
|
int num_bp_reg = 0;
|
2010-05-28 23:14:16 +00:00
|
|
|
int num_index_xf = 0;
|
2010-08-29 23:08:56 +00:00
|
|
|
int num_draw_call = 0;
|
2010-05-28 23:14:16 +00:00
|
|
|
|
2010-08-28 15:09:42 +00:00
|
|
|
u8* old_pVideoData = g_pVideoData;
|
|
|
|
u8* startAddress = Memory_GetPtr(address);
|
2010-05-28 23:14:16 +00:00
|
|
|
|
2010-08-28 15:09:42 +00:00
|
|
|
// Avoid the crash if Memory_GetPtr failed ..
|
|
|
|
if (startAddress != 0)
|
2010-05-28 23:14:16 +00:00
|
|
|
{
|
2010-08-28 15:09:42 +00:00
|
|
|
g_pVideoData = startAddress;
|
2010-05-28 23:14:16 +00:00
|
|
|
|
2010-08-28 15:09:42 +00:00
|
|
|
// temporarily swap dl and non-dl (small "hack" for the stats)
|
|
|
|
Statistics::SwapDL();
|
2010-05-28 23:14:16 +00:00
|
|
|
|
2010-08-28 15:09:42 +00:00
|
|
|
u8 *end = g_pVideoData + size;
|
|
|
|
while (g_pVideoData < end)
|
|
|
|
{
|
|
|
|
// Yet another reimplementation of the DL reading...
|
|
|
|
int cmd_byte = DataReadU8();
|
|
|
|
switch (cmd_byte)
|
2010-05-28 23:14:16 +00:00
|
|
|
{
|
2010-08-28 15:09:42 +00:00
|
|
|
case GX_NOP:
|
|
|
|
break;
|
2010-05-28 23:14:16 +00:00
|
|
|
|
2010-08-28 15:09:42 +00:00
|
|
|
case GX_LOAD_CP_REG: //0x08
|
|
|
|
{
|
|
|
|
u8 sub_cmd = DataReadU8();
|
|
|
|
u32 value = DataReadU32();
|
|
|
|
LoadCPReg(sub_cmd, value);
|
|
|
|
INCSTAT(stats.thisFrame.numCPLoads);
|
|
|
|
num_cp_reg++;
|
|
|
|
}
|
|
|
|
break;
|
2010-05-28 23:14:16 +00:00
|
|
|
|
2010-08-28 15:09:42 +00:00
|
|
|
case GX_LOAD_XF_REG:
|
|
|
|
{
|
|
|
|
u32 Cmd2 = DataReadU32();
|
|
|
|
int transfer_size = ((Cmd2 >> 16) & 15) + 1;
|
|
|
|
u32 xf_address = Cmd2 & 0xFFFF;
|
|
|
|
// TODO - speed this up. pshufb?
|
|
|
|
u32 data_buffer[16];
|
|
|
|
for (int i = 0; i < transfer_size; i++)
|
|
|
|
data_buffer[i] = DataReadU32();
|
|
|
|
LoadXFReg(transfer_size, xf_address, data_buffer);
|
|
|
|
INCSTAT(stats.thisFrame.numXFLoads);
|
|
|
|
num_xf_reg++;
|
|
|
|
}
|
|
|
|
break;
|
2010-05-28 23:14:16 +00:00
|
|
|
|
2010-08-28 15:09:42 +00:00
|
|
|
case GX_LOAD_INDX_A: //used for position matrices
|
|
|
|
{
|
|
|
|
LoadIndexedXF(DataReadU32(), 0xC);
|
|
|
|
num_index_xf++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GX_LOAD_INDX_B: //used for normal matrices
|
|
|
|
{
|
|
|
|
LoadIndexedXF(DataReadU32(), 0xD);
|
|
|
|
num_index_xf++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GX_LOAD_INDX_C: //used for postmatrices
|
|
|
|
{
|
|
|
|
LoadIndexedXF(DataReadU32(), 0xE);
|
|
|
|
num_index_xf++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GX_LOAD_INDX_D: //used for lights
|
|
|
|
{
|
|
|
|
LoadIndexedXF(DataReadU32(), 0xF);
|
|
|
|
num_index_xf++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GX_CMD_CALL_DL:
|
|
|
|
{
|
2010-08-28 15:53:01 +00:00
|
|
|
u32 addr = DataReadU32();
|
2010-08-28 15:09:42 +00:00
|
|
|
u32 count = DataReadU32();
|
2010-08-28 15:53:01 +00:00
|
|
|
ExecuteDisplayList(addr, count);
|
2010-08-28 15:09:42 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GX_CMD_UNKNOWN_METRICS: // zelda 4 swords calls it and checks the metrics registers after that
|
|
|
|
DEBUG_LOG(VIDEO, "GX 0x44: %08x", cmd_byte);
|
|
|
|
break;
|
|
|
|
case GX_CMD_INVL_VC: // Invalidate Vertex Cache
|
|
|
|
DEBUG_LOG(VIDEO, "Invalidate (vertex cache?)");
|
|
|
|
break;
|
|
|
|
case GX_LOAD_BP_REG: //0x61
|
|
|
|
{
|
|
|
|
u32 bp_cmd = DataReadU32();
|
|
|
|
LoadBPReg(bp_cmd);
|
|
|
|
INCSTAT(stats.thisFrame.numBPLoads);
|
2010-08-29 23:08:56 +00:00
|
|
|
num_bp_reg++;
|
2010-08-28 15:09:42 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-05-28 23:14:16 +00:00
|
|
|
|
|
|
|
// draw primitives
|
2010-08-28 15:09:42 +00:00
|
|
|
default:
|
|
|
|
if (cmd_byte & 0x80)
|
|
|
|
{
|
|
|
|
// load vertices (use computed vertex size from FifoCommandRunnable above)
|
|
|
|
u16 numVertices = DataReadU16();
|
2010-05-28 23:14:16 +00:00
|
|
|
|
2010-08-28 15:09:42 +00:00
|
|
|
VertexLoaderManager::RunVertices(
|
|
|
|
cmd_byte & GX_VAT_MASK, // Vertex loader index (0 - 7)
|
|
|
|
(cmd_byte & GX_PRIMITIVE_MASK) >> GX_PRIMITIVE_SHIFT,
|
|
|
|
numVertices);
|
2010-08-29 23:08:56 +00:00
|
|
|
num_draw_call++;
|
2010-08-28 15:09:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERROR_LOG(VIDEO, "OpcodeDecoding::Decode: Illegal command %02x", cmd_byte);
|
|
|
|
break;
|
|
|
|
}
|
2010-05-28 23:14:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-08-28 15:09:42 +00:00
|
|
|
INCSTAT(stats.numDListsCalled);
|
|
|
|
INCSTAT(stats.thisFrame.numDListsCalled);
|
|
|
|
// un-swap
|
|
|
|
Statistics::SwapDL();
|
2010-05-28 23:14:16 +00:00
|
|
|
}
|
2010-08-29 23:08:56 +00:00
|
|
|
dl->num_bp_reg = num_bp_reg;
|
|
|
|
dl->num_cp_reg = num_cp_reg;
|
|
|
|
dl->num_draw_call = num_draw_call;
|
|
|
|
dl->num_index_xf = num_index_xf;
|
|
|
|
dl->num_xf_reg = num_xf_reg;
|
2010-08-28 15:09:42 +00:00
|
|
|
// reset to the old pointer
|
|
|
|
g_pVideoData = old_pVideoData;
|
2010-05-28 23:14:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The only sensible way to detect changes to vertex data is to convert several times
|
|
|
|
// and hash the output.
|
|
|
|
|
|
|
|
// Second pass - compile
|
|
|
|
// Since some commands can affect the size of other commands, we really have no choice
|
|
|
|
// but to compile as we go, interpreting the list. We can't compile and then execute, we must
|
|
|
|
// compile AND execute at the same time. The second time the display list gets called, we already
|
|
|
|
// have the compiled code so we don't have to interpret anymore, we just run it.
|
|
|
|
bool CompileAndRunDisplayList(u32 address, int size, CachedDisplayList *dl)
|
|
|
|
{
|
2010-08-28 15:09:42 +00:00
|
|
|
u8* old_pVideoData = g_pVideoData;
|
|
|
|
u8* startAddress = Memory_GetPtr(address);
|
2010-05-28 23:14:16 +00:00
|
|
|
|
2010-08-28 15:09:42 +00:00
|
|
|
// Avoid the crash if Memory_GetPtr failed ..
|
|
|
|
if (startAddress != 0)
|
2010-05-28 23:14:16 +00:00
|
|
|
{
|
2010-08-28 15:09:42 +00:00
|
|
|
g_pVideoData = startAddress;
|
2010-05-28 23:14:16 +00:00
|
|
|
|
2010-08-28 15:09:42 +00:00
|
|
|
// temporarily swap dl and non-dl (small "hack" for the stats)
|
|
|
|
Statistics::SwapDL();
|
2010-05-28 23:14:16 +00:00
|
|
|
|
2010-08-28 15:09:42 +00:00
|
|
|
u8 *end = g_pVideoData + size;
|
2010-05-28 23:14:16 +00:00
|
|
|
|
2010-08-28 15:09:42 +00:00
|
|
|
emitter.AlignCode4();
|
|
|
|
dl->compiled_code = emitter.GetCodePtr();
|
|
|
|
emitter.ABI_EmitPrologue(4);
|
2010-05-28 23:14:16 +00:00
|
|
|
|
2010-08-28 15:09:42 +00:00
|
|
|
while (g_pVideoData < end)
|
|
|
|
{
|
|
|
|
// Yet another reimplementation of the DL reading...
|
|
|
|
int cmd_byte = DataReadU8();
|
|
|
|
switch (cmd_byte)
|
2010-05-28 23:14:16 +00:00
|
|
|
{
|
2010-08-28 15:09:42 +00:00
|
|
|
case GX_NOP:
|
2010-05-28 23:14:16 +00:00
|
|
|
// Execute
|
|
|
|
// Compile
|
2010-08-28 15:09:42 +00:00
|
|
|
break;
|
2010-05-28 23:14:16 +00:00
|
|
|
|
2010-08-28 15:09:42 +00:00
|
|
|
case GX_LOAD_CP_REG: //0x08
|
|
|
|
{
|
|
|
|
// Execute
|
|
|
|
u8 sub_cmd = DataReadU8();
|
|
|
|
u32 value = DataReadU32();
|
|
|
|
LoadCPReg(sub_cmd, value);
|
|
|
|
INCSTAT(stats.thisFrame.numCPLoads);
|
|
|
|
|
|
|
|
// Compile
|
|
|
|
emitter.ABI_CallFunctionCC((void *)&LoadCPReg, sub_cmd, value);
|
|
|
|
}
|
|
|
|
break;
|
2010-05-28 23:14:16 +00:00
|
|
|
|
2010-08-28 15:09:42 +00:00
|
|
|
case GX_LOAD_XF_REG:
|
|
|
|
{
|
|
|
|
// Execute
|
|
|
|
u32 Cmd2 = DataReadU32();
|
|
|
|
int transfer_size = ((Cmd2 >> 16) & 15) + 1;
|
|
|
|
u32 xf_address = Cmd2 & 0xFFFF;
|
|
|
|
// TODO - speed this up. pshufb?
|
2010-08-29 23:08:56 +00:00
|
|
|
DataPointer real_data_buffer = (DataPointer) new u8[transfer_size * 4];
|
|
|
|
u32 *data_buffer = (u32*)real_data_buffer;
|
2010-08-28 15:09:42 +00:00
|
|
|
for (int i = 0; i < transfer_size; i++)
|
|
|
|
data_buffer[i] = DataReadU32();
|
|
|
|
LoadXFReg(transfer_size, xf_address, data_buffer);
|
|
|
|
INCSTAT(stats.thisFrame.numXFLoads);
|
2010-08-29 23:08:56 +00:00
|
|
|
dl->Vdata[dl->BufferCount] = real_data_buffer;
|
|
|
|
dl->BufferCount++;
|
2010-08-28 15:09:42 +00:00
|
|
|
// Compile
|
|
|
|
emitter.ABI_CallFunctionCCP((void *)&LoadXFReg, transfer_size, xf_address, data_buffer);
|
|
|
|
}
|
|
|
|
break;
|
2010-05-28 23:14:16 +00:00
|
|
|
|
2010-08-28 15:09:42 +00:00
|
|
|
case GX_LOAD_INDX_A: //used for position matrices
|
|
|
|
{
|
|
|
|
u32 value = DataReadU32();
|
|
|
|
// Execute
|
|
|
|
LoadIndexedXF(value, 0xC);
|
|
|
|
// Compile
|
|
|
|
emitter.ABI_CallFunctionCC((void *)&LoadIndexedXF, value, 0xC);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GX_LOAD_INDX_B: //used for normal matrices
|
|
|
|
{
|
|
|
|
u32 value = DataReadU32();
|
|
|
|
// Execute
|
|
|
|
LoadIndexedXF(value, 0xD);
|
|
|
|
// Compile
|
|
|
|
emitter.ABI_CallFunctionCC((void *)&LoadIndexedXF, value, 0xD);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GX_LOAD_INDX_C: //used for postmatrices
|
|
|
|
{
|
|
|
|
u32 value = DataReadU32();
|
|
|
|
// Execute
|
|
|
|
LoadIndexedXF(value, 0xE);
|
|
|
|
// Compile
|
|
|
|
emitter.ABI_CallFunctionCC((void *)&LoadIndexedXF, value, 0xE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GX_LOAD_INDX_D: //used for lights
|
|
|
|
{
|
|
|
|
u32 value = DataReadU32();
|
|
|
|
// Execute
|
|
|
|
LoadIndexedXF(value, 0xF);
|
|
|
|
// Compile
|
|
|
|
emitter.ABI_CallFunctionCC((void *)&LoadIndexedXF, value, 0xF);
|
|
|
|
}
|
|
|
|
break;
|
2010-05-28 23:14:16 +00:00
|
|
|
|
2010-08-28 15:09:42 +00:00
|
|
|
case GX_CMD_CALL_DL:
|
|
|
|
{
|
2010-08-28 15:53:01 +00:00
|
|
|
u32 addr= DataReadU32();
|
2010-08-28 15:09:42 +00:00
|
|
|
u32 count = DataReadU32();
|
2010-08-28 15:53:01 +00:00
|
|
|
ExecuteDisplayList(addr, count);
|
2010-08-28 15:09:42 +00:00
|
|
|
emitter.ABI_CallFunctionCC((void *)&ExecuteDisplayList, address, count);
|
|
|
|
}
|
|
|
|
break;
|
2010-05-28 23:14:16 +00:00
|
|
|
|
2010-08-28 15:09:42 +00:00
|
|
|
case GX_CMD_UNKNOWN_METRICS:
|
|
|
|
// zelda 4 swords calls it and checks the metrics registers after that
|
|
|
|
break;
|
2010-05-28 23:14:16 +00:00
|
|
|
|
2010-08-28 15:09:42 +00:00
|
|
|
case GX_CMD_INVL_VC:// Invalidate (vertex cache?)
|
|
|
|
DEBUG_LOG(VIDEO, "Invalidate (vertex cache?)");
|
|
|
|
break;
|
2010-05-28 23:14:16 +00:00
|
|
|
|
2010-08-28 15:09:42 +00:00
|
|
|
case GX_LOAD_BP_REG: //0x61
|
|
|
|
{
|
|
|
|
u32 bp_cmd = DataReadU32();
|
|
|
|
// Execute
|
|
|
|
LoadBPReg(bp_cmd);
|
|
|
|
INCSTAT(stats.thisFrame.numBPLoads);
|
|
|
|
// Compile
|
|
|
|
emitter.ABI_CallFunctionC((void *)&LoadBPReg, bp_cmd);
|
|
|
|
}
|
|
|
|
break;
|
2010-05-28 23:14:16 +00:00
|
|
|
|
2010-08-28 15:09:42 +00:00
|
|
|
// draw primitives
|
|
|
|
default:
|
|
|
|
if (cmd_byte & 0x80)
|
|
|
|
{
|
|
|
|
// load vertices (use computed vertex size from FifoCommandRunnable above)
|
|
|
|
|
|
|
|
// Execute
|
|
|
|
u16 numVertices = DataReadU16();
|
|
|
|
|
|
|
|
u64 pre_draw_video_data = (u64)g_pVideoData;
|
|
|
|
|
2010-08-29 23:08:56 +00:00
|
|
|
u8* StartAddress = VertexManager::s_pBaseBufferPointer;
|
|
|
|
VertexManager::Flush();
|
2010-08-28 15:09:42 +00:00
|
|
|
VertexLoaderManager::RunVertices(
|
|
|
|
cmd_byte & GX_VAT_MASK, // Vertex loader index (0 - 7)
|
|
|
|
(cmd_byte & GX_PRIMITIVE_MASK) >> GX_PRIMITIVE_SHIFT,
|
|
|
|
numVertices);
|
2010-08-29 23:08:56 +00:00
|
|
|
u8* EndAddress = VertexManager::s_pCurBufferPointer;
|
|
|
|
u32 Vdatasize = (u32)(EndAddress - StartAddress);
|
|
|
|
if (size > 0)
|
|
|
|
{
|
2010-08-28 15:09:42 +00:00
|
|
|
// Compile
|
2010-08-29 23:08:56 +00:00
|
|
|
DataPointer NewData = (DataPointer)new u8[Vdatasize];
|
|
|
|
memcpy(NewData,StartAddress,Vdatasize);
|
|
|
|
dl->Vdata[dl->BufferCount] = NewData;
|
|
|
|
dl->BufferCount++;
|
|
|
|
emitter.ABI_CallFunctionCCCP((void *)&VertexLoaderManager::RunCompiledVertices,cmd_byte & GX_VAT_MASK, (cmd_byte & GX_PRIMITIVE_MASK) >> GX_PRIMITIVE_SHIFT, numVertices, NewData);
|
|
|
|
}
|
2010-08-28 15:09:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERROR_LOG(VIDEO, "DLCache::CompileAndRun: Illegal command %02x", cmd_byte);
|
|
|
|
break;
|
|
|
|
}
|
2010-05-28 23:14:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-08-28 15:09:42 +00:00
|
|
|
emitter.ABI_EmitEpilogue(4);
|
2010-08-29 23:08:56 +00:00
|
|
|
INCSTAT(stats.numDListsCalled);
|
|
|
|
INCSTAT(stats.thisFrame.numDListsCalled);
|
|
|
|
Statistics::SwapDL();
|
2010-05-28 23:14:16 +00:00
|
|
|
}
|
2010-08-28 15:09:42 +00:00
|
|
|
g_pVideoData = old_pVideoData;
|
2010-05-28 23:14:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Init()
|
|
|
|
{
|
2010-08-29 23:08:56 +00:00
|
|
|
dlcode_cache = (DataPointer)AllocateExecutableMemory(DL_CODE_CACHE_SIZE, false); // Don't need low memory.
|
2010-05-28 23:14:16 +00:00
|
|
|
emitter.SetCodePtr(dlcode_cache);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shutdown()
|
|
|
|
{
|
|
|
|
Clear();
|
2010-08-29 23:08:56 +00:00
|
|
|
FreeMemoryPages(dlcode_cache, DL_CODE_CACHE_SIZE);
|
2010-05-28 23:14:16 +00:00
|
|
|
dlcode_cache = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clear()
|
|
|
|
{
|
2010-08-29 23:08:56 +00:00
|
|
|
DLMap::iterator iter = dl_map.begin();
|
|
|
|
while (iter != dl_map.end()) {
|
|
|
|
CachedDisplayList &entry = iter->second;
|
|
|
|
VdataMap::iterator viter = entry.Vdata.begin();
|
|
|
|
while (viter != entry.Vdata.end())
|
|
|
|
{
|
|
|
|
DataPointer &ventry = viter->second;
|
|
|
|
delete [] ventry;
|
|
|
|
entry.Vdata.erase(viter++);
|
|
|
|
}
|
|
|
|
iter++;
|
|
|
|
}
|
2010-05-28 23:14:16 +00:00
|
|
|
dl_map.clear();
|
|
|
|
// Reset the cache pointers.
|
2010-08-29 23:08:56 +00:00
|
|
|
emitter.SetCodePtr(dlcode_cache);
|
2010-05-28 23:14:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProgressiveCleanup()
|
|
|
|
{
|
|
|
|
DLMap::iterator iter = dl_map.begin();
|
|
|
|
while (iter != dl_map.end()) {
|
|
|
|
CachedDisplayList &entry = iter->second;
|
|
|
|
int limit = iter->second.uncachable ? 1200 : 400;
|
|
|
|
if (entry.frame_count < frameCount - limit) {
|
|
|
|
// entry.Destroy();
|
2010-08-29 23:08:56 +00:00
|
|
|
VdataMap::iterator viter = entry.Vdata.begin();
|
|
|
|
while (viter != entry.Vdata.end())
|
|
|
|
{
|
|
|
|
DataPointer &ventry = viter->second;
|
|
|
|
delete [] ventry;
|
|
|
|
entry.Vdata.erase(viter++);
|
|
|
|
}
|
2010-05-28 23:14:16 +00:00
|
|
|
dl_map.erase(iter++); // (this is gcc standard!)
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// NOTE - outside the namespace on purpose.
|
|
|
|
bool HandleDisplayList(u32 address, u32 size)
|
|
|
|
{
|
|
|
|
// Disable display list caching since the benefit isn't much to write home about
|
|
|
|
// right now...
|
2010-08-28 15:09:42 +00:00
|
|
|
//Fixed DlistCaching now is fully functional benefits still marginal but when vertex data is stored here the story will be diferent :)
|
|
|
|
//to test remove the next line;
|
|
|
|
|
|
|
|
if(size == 0) return false;
|
2010-05-28 23:14:16 +00:00
|
|
|
u64 dl_id = DLCache::CreateMapId(address, size);
|
|
|
|
DLCache::DLMap::iterator iter = DLCache::dl_map.find(dl_id);
|
|
|
|
|
|
|
|
stats.numDListsAlive = (int)DLCache::dl_map.size();
|
|
|
|
if (iter != DLCache::dl_map.end())
|
|
|
|
{
|
|
|
|
DLCache::CachedDisplayList &dl = iter->second;
|
|
|
|
if (dl.uncachable)
|
|
|
|
{
|
|
|
|
// We haven't compiled it - let's return false so it gets
|
2010-08-29 23:08:56 +00:00
|
|
|
// interpreted.
|
2010-05-28 23:14:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Got one! And it's been compiled too, so let's run the compiled code!
|
|
|
|
switch (dl.pass)
|
|
|
|
{
|
|
|
|
case DLCache::DLPASS_ANALYZE:
|
|
|
|
PanicAlert("DLPASS_ANALYZE - should have been done the first pass");
|
|
|
|
break;
|
|
|
|
case DLCache::DLPASS_COMPILE:
|
|
|
|
// First, check that the hash is the same as the last time.
|
2010-08-28 15:09:42 +00:00
|
|
|
if (dl.dl_hash != GetHash64(Memory_GetPtr(address), size,0))
|
2010-05-28 23:14:16 +00:00
|
|
|
{
|
|
|
|
// PanicAlert("uncachable %08x", address);
|
2010-08-29 23:08:56 +00:00
|
|
|
dl.uncachable = true;
|
2010-05-28 23:14:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
DLCache::CompileAndRunDisplayList(address, size, &dl);
|
|
|
|
dl.pass = DLCache::DLPASS_RUN;
|
|
|
|
break;
|
|
|
|
case DLCache::DLPASS_RUN:
|
|
|
|
{
|
|
|
|
// Every N draws, check hash
|
|
|
|
dl.check--;
|
|
|
|
if (dl.check <= 0)
|
|
|
|
{
|
2010-08-28 15:09:42 +00:00
|
|
|
if (dl.dl_hash != GetHash64(Memory_GetPtr(address), size,0))
|
2010-05-28 23:14:16 +00:00
|
|
|
{
|
|
|
|
dl.uncachable = true;
|
2010-08-29 23:08:56 +00:00
|
|
|
DLCache::VdataMap::iterator viter = dl.Vdata.begin();
|
|
|
|
while (viter != dl.Vdata.end())
|
|
|
|
{
|
|
|
|
DLCache::DataPointer &ventry = viter->second;
|
|
|
|
delete [] ventry;
|
|
|
|
dl.Vdata.erase(viter++);
|
|
|
|
}
|
|
|
|
dl.BufferCount = 0;
|
2010-05-28 23:14:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
dl.check = dl.next_check;
|
2010-08-29 23:08:56 +00:00
|
|
|
dl.next_check *= 2;
|
2010-05-28 23:14:16 +00:00
|
|
|
if (dl.next_check > 1024)
|
|
|
|
dl.next_check = 1024;
|
|
|
|
}
|
2010-08-29 23:08:56 +00:00
|
|
|
dl.frame_count= frameCount;
|
2010-05-28 23:14:16 +00:00
|
|
|
u8 *old_datareader = g_pVideoData;
|
|
|
|
((void (*)())(void*)(dl.compiled_code))();
|
2010-08-29 23:08:56 +00:00
|
|
|
Statistics::SwapDL();
|
|
|
|
ADDSTAT(stats.thisFrame.numCPLoadsInDL,dl.num_cp_reg);
|
|
|
|
ADDSTAT(stats.thisFrame.numXFLoadsInDL,dl.num_xf_reg);
|
|
|
|
ADDSTAT(stats.thisFrame.numBPLoadsInDL,dl.num_bp_reg);
|
|
|
|
|
|
|
|
ADDSTAT(stats.thisFrame.numCPLoads,dl.num_cp_reg);
|
|
|
|
ADDSTAT(stats.thisFrame.numXFLoads,dl.num_xf_reg);
|
|
|
|
ADDSTAT(stats.thisFrame.numBPLoads,dl.num_bp_reg);
|
|
|
|
|
|
|
|
INCSTAT(stats.numDListsCalled);
|
|
|
|
INCSTAT(stats.thisFrame.numDListsCalled);
|
|
|
|
|
|
|
|
Statistics::SwapDL();
|
2010-05-28 23:14:16 +00:00
|
|
|
g_pVideoData = old_datareader;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
DLCache::CachedDisplayList dl;
|
|
|
|
|
|
|
|
if (DLCache::AnalyzeAndRunDisplayList(address, size, &dl)) {
|
2010-08-28 15:09:42 +00:00
|
|
|
dl.dl_hash = GetHash64(Memory_GetPtr(address), size,0);
|
2010-05-28 23:14:16 +00:00
|
|
|
dl.pass = DLCache::DLPASS_COMPILE;
|
|
|
|
dl.check = 1;
|
|
|
|
dl.next_check = 1;
|
|
|
|
DLCache::dl_map[dl_id] = dl;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
dl.uncachable = true;
|
|
|
|
DLCache::dl_map[dl_id] = dl;
|
|
|
|
return true; // don't also interpret the list.
|
|
|
|
}
|
|
|
|
}
|