Fix threading issue with vertex loader JIT.

VertexLoader::VertexLoader was setting loop_counter, a *static*
variable, to 0.  This was nonsensical, but harmless until I started to
run it on a separate thread, where it had a chance of interfering with a
running vertex translator.

Switch to just using a register for the loop counter.
This commit is contained in:
comex 2014-08-26 23:17:51 -04:00
parent 63c62b277d
commit f8452ff501
1 changed files with 8 additions and 11 deletions

View File

@ -38,9 +38,6 @@ static u8 s_curtexmtx[8];
static int s_texmtxwrite = 0; static int s_texmtxwrite = 0;
static int s_texmtxread = 0; static int s_texmtxread = 0;
static int loop_counter;
// Vertex loaders read these. Although the scale ones should be baked into the shader. // Vertex loaders read these. Although the scale ones should be baked into the shader.
int tcIndex; int tcIndex;
int colIndex; int colIndex;
@ -549,7 +546,6 @@ VertexLoader::VertexLoader(const TVtxDesc &vtx_desc, const VAT &vtx_attr)
m_numLoadedVertices = 0; m_numLoadedVertices = 0;
m_VertexSize = 0; m_VertexSize = 0;
m_native_vertex_format = nullptr; m_native_vertex_format = nullptr;
loop_counter = 0;
VertexLoader_Normal::Init(); VertexLoader_Normal::Init();
VertexLoader_Position::Init(); VertexLoader_Position::Init();
VertexLoader_TextCoord::Init(); VertexLoader_TextCoord::Init();
@ -585,8 +581,11 @@ void VertexLoader::CompileVertexTranslator()
PanicAlert("Trying to recompile a vertex translator"); PanicAlert("Trying to recompile a vertex translator");
m_compiledCode = GetCodePtr(); m_compiledCode = GetCodePtr();
// We don't use any callee saved registers or anything but RAX. // We only use RAX (caller saved) and RBX (callee saved).
ABI_PushRegistersAndAdjustStack(0, 8); ABI_PushRegistersAndAdjustStack(1 << RBX, 8);
// save count
MOV(64, R(RBX), R(ABI_PARAM1));
// Start loop here // Start loop here
const u8 *loop_start = GetCodePtr(); const u8 *loop_start = GetCodePtr();
@ -843,11 +842,10 @@ void VertexLoader::CompileVertexTranslator()
#ifdef USE_VERTEX_LOADER_JIT #ifdef USE_VERTEX_LOADER_JIT
// End loop here // End loop here
MOV(64, R(RAX), Imm64((u64)&loop_counter)); SUB(64, R(RBX), Imm8(1));
SUB(32, MatR(RAX), Imm8(1));
J_CC(CC_NZ, loop_start); J_CC(CC_NZ, loop_start);
ABI_PopRegistersAndAdjustStack(0, 8); ABI_PopRegistersAndAdjustStack(1 << RBX, 8);
RET(); RET();
#endif #endif
} }
@ -913,8 +911,7 @@ void VertexLoader::ConvertVertices ( int count )
#ifdef USE_VERTEX_LOADER_JIT #ifdef USE_VERTEX_LOADER_JIT
if (count > 0) if (count > 0)
{ {
loop_counter = count; ((void (*)(int))(void*)m_compiledCode)(count);
((void (*)())(void*)m_compiledCode)();
} }
#else #else
for (int s = 0; s < count; s++) for (int s = 0; s < count; s++)