mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 22:00:39 -06:00
Fix/workaround at least one class of buffer underruns in the GL plugin. Fix some bad deletes (instead of delete []). etc.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@404 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@ -26,6 +26,7 @@ IDataReader* g_pDataReader = NULL;
|
||||
extern u8 FAKE_ReadFifo8();
|
||||
extern u16 FAKE_ReadFifo16();
|
||||
extern u32 FAKE_ReadFifo32();
|
||||
extern int FAKE_GetPosition();
|
||||
extern void FAKE_SkipFifo(u32 skip);
|
||||
|
||||
CDataReader_Fifo::CDataReader_Fifo(void)
|
||||
@ -53,6 +54,12 @@ void CDataReader_Fifo::Skip(u32 skip)
|
||||
return FAKE_SkipFifo(skip);
|
||||
}
|
||||
|
||||
int CDataReader_Fifo::GetPosition()
|
||||
{
|
||||
return FAKE_GetPosition();
|
||||
}
|
||||
|
||||
|
||||
// =================================================================================================
|
||||
// CDataReader_Memory
|
||||
// =================================================================================================
|
||||
@ -64,26 +71,31 @@ CDataReader_Memory::CDataReader_Memory(u32 _uAddress) :
|
||||
m_szName = "CDataReader_Memory";
|
||||
}
|
||||
|
||||
u32 CDataReader_Memory::GetReadAddress(void)
|
||||
u32 CDataReader_Memory::GetReadAddress()
|
||||
{
|
||||
return m_uReadAddress;
|
||||
}
|
||||
|
||||
u8 CDataReader_Memory::Read8(void)
|
||||
int CDataReader_Memory::GetPosition()
|
||||
{
|
||||
return m_uReadAddress;
|
||||
}
|
||||
|
||||
u8 CDataReader_Memory::Read8()
|
||||
{
|
||||
u8 tmp = Memory_Read_U8(m_uReadAddress);//m_pMemory[m_uReadAddress];
|
||||
m_uReadAddress++;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
u16 CDataReader_Memory::Read16(void)
|
||||
u16 CDataReader_Memory::Read16()
|
||||
{
|
||||
u16 tmp = Memory_Read_U16(m_uReadAddress);//_byteswap_ushort(*(u16*)&m_pMemory[m_uReadAddress]);
|
||||
m_uReadAddress += 2;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
u32 CDataReader_Memory::Read32(void)
|
||||
u32 CDataReader_Memory::Read32()
|
||||
{
|
||||
u32 tmp = Memory_Read_U32(m_uReadAddress);//_byteswap_ulong(*(u32*)&m_pMemory[m_uReadAddress]);
|
||||
m_uReadAddress += 4;
|
||||
|
@ -29,9 +29,11 @@ protected:
|
||||
|
||||
public:
|
||||
virtual void Skip(u32) = 0;
|
||||
virtual u8 Read8 (void) = 0;
|
||||
virtual u16 Read16(void) = 0;
|
||||
virtual u32 Read32(void) = 0;
|
||||
virtual u8 Read8 () = 0;
|
||||
virtual u16 Read16() = 0;
|
||||
virtual u32 Read32() = 0;
|
||||
|
||||
virtual int GetPosition() = 0; // return values can be anything, as long as relative distances are correct
|
||||
};
|
||||
|
||||
// =================================================================================================
|
||||
@ -43,12 +45,13 @@ class CDataReader_Fifo : public IDataReader
|
||||
private:
|
||||
|
||||
public:
|
||||
CDataReader_Fifo(void);
|
||||
CDataReader_Fifo();
|
||||
|
||||
virtual void Skip(u32);
|
||||
virtual u8 Read8(void);
|
||||
virtual u16 Read16(void);
|
||||
virtual u32 Read32(void);
|
||||
virtual u8 Read8();
|
||||
virtual u16 Read16();
|
||||
virtual u32 Read32();
|
||||
virtual int GetPosition();
|
||||
};
|
||||
|
||||
// =================================================================================================
|
||||
@ -66,12 +69,13 @@ public:
|
||||
|
||||
CDataReader_Memory(u32 _uAddress);
|
||||
|
||||
u32 GetReadAddress(void);
|
||||
u32 GetReadAddress();
|
||||
|
||||
virtual void Skip(u32);
|
||||
virtual u8 Read8(void);
|
||||
virtual u16 Read16(void);
|
||||
virtual u32 Read32(void);
|
||||
virtual u8 Read8();
|
||||
virtual u16 Read16();
|
||||
virtual u32 Read32();
|
||||
virtual int GetPosition();
|
||||
};
|
||||
|
||||
extern IDataReader* g_pDataReader;
|
||||
|
@ -269,8 +269,8 @@ void Decode(void)
|
||||
// draw primitives
|
||||
default:
|
||||
if (Cmd&0x80)
|
||||
{
|
||||
// load vertices
|
||||
{
|
||||
// load vertices (use computed vertex size from FifoCommandRunnable above)
|
||||
u16 numVertices = g_pDataReader->Read16();
|
||||
if (numVertices > 0) {
|
||||
g_VertexLoaders[Cmd & GX_VAT_MASK].RunVertices((Cmd & GX_PRIMITIVE_MASK) >> GX_PRIMITIVE_SHIFT, numVertices);
|
||||
@ -301,11 +301,6 @@ void OpcodeDecoder_Shutdown()
|
||||
|
||||
void OpcodeDecoder_Run()
|
||||
{
|
||||
// just a small check
|
||||
if (g_pDataReader != &g_fifoReader) {
|
||||
SysMessage("very strange");
|
||||
}
|
||||
|
||||
DVSTARTPROFILE();
|
||||
|
||||
while (FifoCommandRunnable())
|
||||
|
@ -43,7 +43,7 @@ class PixelShaderMngr
|
||||
memset(values, 0, (4+32+6+11) * 4);
|
||||
tevstages = indstages = 0;
|
||||
}
|
||||
~PIXELSHADERUID() { delete[] values; }
|
||||
~PIXELSHADERUID() { delete[] values; values = NULL;}
|
||||
PIXELSHADERUID(const PIXELSHADERUID& r)
|
||||
{
|
||||
values = new u32[4+32+6+11];
|
||||
|
@ -19,8 +19,10 @@
|
||||
#include <fstream>
|
||||
#include <assert.h>
|
||||
|
||||
#include "Common.h"
|
||||
#include "x64Emitter.h"
|
||||
#include "Profiler.h"
|
||||
#include "StringUtil.h"
|
||||
|
||||
#include "Render.h"
|
||||
#include "VertexLoader.h"
|
||||
@ -82,6 +84,12 @@ inline float ReadBuffer32F()
|
||||
return *(float*)(&temp);
|
||||
}
|
||||
|
||||
|
||||
inline int GetBufferPosition()
|
||||
{
|
||||
return g_pDataReader->GetPosition();
|
||||
}
|
||||
|
||||
// ==============================================================================
|
||||
// Direct
|
||||
// ==============================================================================
|
||||
@ -143,7 +151,7 @@ VertexLoader::VertexLoader()
|
||||
{
|
||||
m_numPipelineStates = 0;
|
||||
m_VertexSize = 0;
|
||||
m_AttrDirty = 2;
|
||||
m_AttrDirty = 1;
|
||||
VertexLoader_Normal::Init();
|
||||
|
||||
m_compiledCode = (u8 *)AllocateExecutableMemory(COMPILED_CODE_SIZE, false);
|
||||
@ -159,8 +167,7 @@ VertexLoader::~VertexLoader()
|
||||
|
||||
int VertexLoader::ComputeVertexSize()
|
||||
{
|
||||
if (m_AttrDirty < 2) {
|
||||
|
||||
if (!m_AttrDirty) {
|
||||
if (m_VtxDesc.Hex0 == VertexManager::GetVtxDesc().Hex0 && (m_VtxDesc.Hex1&1)==(VertexManager::GetVtxDesc().Hex1&1))
|
||||
return m_VertexSize;
|
||||
|
||||
@ -212,6 +219,7 @@ int VertexLoader::ComputeVertexSize()
|
||||
break;
|
||||
}
|
||||
|
||||
VertexLoader_Normal::index3 = m_VtxAttr.NormalIndex3;
|
||||
if (m_VtxDesc.Normal != NOT_PRESENT)
|
||||
m_VertexSize += VertexLoader_Normal::GetSize(m_VtxDesc.Normal, m_VtxAttr.NormalFormat, m_VtxAttr.NormalElements);
|
||||
|
||||
@ -297,7 +305,7 @@ void VertexLoader::ProcessFormat()
|
||||
|
||||
//_assert_( VertexManager::s_pCurBufferPointer == s_pBaseBufferPointer );
|
||||
|
||||
if (!m_AttrDirty ) {
|
||||
if (!m_AttrDirty) {
|
||||
|
||||
if (m_VtxDesc.Hex0 == VertexManager::GetVtxDesc().Hex0 && (m_VtxDesc.Hex1&1)==(VertexManager::GetVtxDesc().Hex1&1))
|
||||
// same
|
||||
@ -410,7 +418,7 @@ void VertexLoader::ProcessFormat()
|
||||
// Colors
|
||||
int col[2] = {m_VtxDesc.Color0, m_VtxDesc.Color1};
|
||||
for (int i = 0; i < 2; i++) {
|
||||
SetupColor(i,col[i], m_VtxAttr.color[i].Comp, m_VtxAttr.color[i].Elements);
|
||||
SetupColor(i, col[i], m_VtxAttr.color[i].Comp, m_VtxAttr.color[i].Elements);
|
||||
|
||||
if (col[i] != NOT_PRESENT )
|
||||
m_VBVertexStride+=4;
|
||||
@ -504,8 +512,8 @@ void VertexLoader::ProcessFormat()
|
||||
case FORMAT_FLOAT:
|
||||
CallCdeclFunction3_I(glNormalPointer, GL_FLOAT, m_VBVertexStride, offset); offset += 12;
|
||||
if (m_VtxAttr.NormalElements) {
|
||||
CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM1_ATTRIB,3,GL_FLOAT, GL_TRUE, m_VBVertexStride, offset); offset += 12;
|
||||
CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM2_ATTRIB,3,GL_FLOAT, GL_TRUE, m_VBVertexStride, offset); offset += 12;
|
||||
CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM1_ATTRIB, 3, GL_FLOAT, GL_TRUE, m_VBVertexStride, offset); offset += 12;
|
||||
CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM2_ATTRIB, 3, GL_FLOAT, GL_TRUE, m_VBVertexStride, offset); offset += 12;
|
||||
}
|
||||
break;
|
||||
default: _assert_(0); break;
|
||||
@ -513,7 +521,7 @@ void VertexLoader::ProcessFormat()
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (col[i] != NOT_PRESENT ) {
|
||||
if (col[i] != NOT_PRESENT) {
|
||||
if (i)
|
||||
CallCdeclFunction4((void *)glSecondaryColorPointer, 4, GL_UNSIGNED_BYTE, m_VBVertexStride, offset);
|
||||
else
|
||||
@ -570,7 +578,7 @@ void VertexLoader::ProcessFormat()
|
||||
_assert_(offset+m_VBStridePad == m_VBVertexStride);
|
||||
|
||||
Util::EmitEpilogue(6);
|
||||
if (Gen::GetCodePtr()-(u8*)m_compiledCode > COMPILED_CODE_SIZE)
|
||||
if (Gen::GetCodePtr() - (u8*)m_compiledCode > COMPILED_CODE_SIZE)
|
||||
{
|
||||
assert(0);
|
||||
Crash();
|
||||
@ -689,12 +697,14 @@ void VertexLoader::SetupTexCoord(int num, int mode, int format, int elements, in
|
||||
|
||||
void VertexLoader::WriteCall(void (LOADERDECL *func)(void *))
|
||||
{
|
||||
m_PipelineStates[m_numPipelineStates++] = func;;
|
||||
m_PipelineStates[m_numPipelineStates++] = func;
|
||||
}
|
||||
|
||||
void VertexLoader::RunVertices(int primitive, int count)
|
||||
{
|
||||
if( count <= 0 )
|
||||
ComputeVertexSize();
|
||||
|
||||
if( count <= 0 )
|
||||
return;
|
||||
|
||||
if( fnSetupVertexPointers != NULL && fnSetupVertexPointers != (void (*)())(void*)m_compiledCode )
|
||||
@ -833,6 +843,7 @@ void VertexLoader::RunVertices(int primitive, int count)
|
||||
break;
|
||||
default:
|
||||
extraverts = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
startv = v;
|
||||
@ -842,8 +853,22 @@ void VertexLoader::RunVertices(int primitive, int count)
|
||||
tcIndex = 0;
|
||||
colIndex = 0;
|
||||
s_texmtxwrite = s_texmtxread = 0;
|
||||
|
||||
int pred_size = m_VertexSize;
|
||||
|
||||
//int start = GetBufferPosition();
|
||||
//if (!m_numPipelineStates)
|
||||
// PanicAlert("trying to draw with no pipeline");
|
||||
for (int i = 0; i < m_numPipelineStates; i++)
|
||||
m_PipelineStates[i](&m_VtxAttr);
|
||||
//int end = GetBufferPosition();
|
||||
|
||||
//if (end - start != pred_size) {
|
||||
// std::string vtx_summary;
|
||||
// vtx_summary += StringFromFormat("Nrm d:%i f:%i e:%i 3:%i", m_VtxDesc.Normal, m_VtxAttr.NormalFormat, m_VtxAttr.NormalElements, m_VtxAttr.NormalIndex3);
|
||||
// PanicAlert((vtx_summary + "\nWTF %i %i").c_str(), end - start, pred_size);
|
||||
//}
|
||||
|
||||
VertexManager::s_pCurBufferPointer += m_VBStridePad;
|
||||
PRIM_LOG("\n");
|
||||
}
|
||||
|
@ -224,5 +224,6 @@ u8 ReadBuffer8();
|
||||
u16 ReadBuffer16();
|
||||
u32 ReadBuffer32();
|
||||
float ReadBuffer32F();
|
||||
int GetBufferPosition();
|
||||
|
||||
#endif
|
||||
|
@ -106,7 +106,10 @@ void VertexLoader_Normal::Init(void)
|
||||
|
||||
unsigned int VertexLoader_Normal::GetSize(unsigned int _type, unsigned int _format, unsigned int _elements)
|
||||
{
|
||||
return m_sizeTable[_type][_format][_elements];
|
||||
if (!index3 && _elements == NRM_NBT3)
|
||||
return m_sizeTable[_type][_format][_elements] / 3;
|
||||
else
|
||||
return m_sizeTable[_type][_format][_elements];
|
||||
}
|
||||
|
||||
TPipelineFunction VertexLoader_Normal::GetFunction(unsigned int _type, unsigned int _format, unsigned int _elements)
|
||||
|
Reference in New Issue
Block a user