DataReader inline for OGL/DX9 and moved to VideoCommon. Large clean up.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@760 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
memberTwo.mb2
2008-10-03 22:05:28 +00:00
parent 8997f9cb3e
commit 8d0f6d40f4
20 changed files with 284 additions and 931 deletions

View File

@ -0,0 +1,80 @@
// Copyright (C) 2003-2008 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/
#ifndef _DATAREADER_H
#define _DATAREADER_H
extern u8* g_pVideoData;
inline u8 DataPeek8(u32 _uOffset)
{
return g_pVideoData[_uOffset];
}
inline u16 DataPeek16(u32 _uOffset)
{
return Common::swap16(*(u16*)&g_pVideoData[_uOffset]);
}
inline u32 DataPeek32(u32 _uOffset)
{
return Common::swap32(*(u32*)&g_pVideoData[_uOffset]);
}
inline u8 DataReadU8()
{
return *g_pVideoData++;
}
inline u16 DataReadU16()
{
u16 tmp = Common::swap16(*(u16*)g_pVideoData);
g_pVideoData+=2;
return tmp;
}
inline u32 DataReadU32()
{
u32 tmp = Common::swap32(*(u32*)g_pVideoData);
g_pVideoData+=4;
return tmp;
}
inline float DataReadF32()
{
union {u32 i; float f;} temp;
temp.i = Common::swap32(*(u32*)g_pVideoData);
g_pVideoData+=4;
float tmp = temp.f;
return tmp;
}
inline u8* DataGetPosition()
{
return g_pVideoData;
}
inline void DataSkip(u32 skip)
{
g_pVideoData += skip;
}
#endif

View File

@ -23,31 +23,23 @@
#include "Fifo.h"
#if defined(DATAREADER_INLINE)
extern u8* g_pVideoData;
#else
FifoReader fifo;
#endif
bool fifoStateRun = true;
// STATE_TO_SAVE
static u8 *videoBuffer;
static int size = 0;
static int readptr = 0;
void Fifo_DoState(PointerWrap &p) {
void Fifo_DoState(PointerWrap &p)
{
p.DoArray(videoBuffer, FIFO_SIZE);
p.Do(size);
p.Do(readptr);
}
void Fifo_Init()
{
videoBuffer = (u8*)AllocateMemoryPages(FIFO_SIZE);
#ifndef DATAREADER_INLINE
fifo.Init(videoBuffer, videoBuffer); //zero length. there is no data yet.
#endif
fifoStateRun = true;
}
@ -57,7 +49,8 @@ void Fifo_Shutdown()
fifoStateRun = false;
}
void Fifo_Stop() {
void Fifo_Stop()
{
fifoStateRun = false;
}
@ -66,68 +59,11 @@ u8* FAKE_GetFifoStartPtr()
return videoBuffer;
}
int FAKE_GetFifoSize()
{
if (size < readptr)
{
PanicAlert("GFX Fifo underrun encountered (size = %i, readptr = %i)", size, readptr);
}
return (size - readptr);
}
u8* FAKE_GetFifoEndPtr()
{
return &videoBuffer[size];
}
u8 FAKE_PeekFifo8(u32 _uOffset)
{
return videoBuffer[readptr + _uOffset];
}
u16 FAKE_PeekFifo16(u32 _uOffset)
{
return Common::swap16(*(u16*)&videoBuffer[readptr + _uOffset]);
}
u32 FAKE_PeekFifo32(u32 _uOffset)
{
return Common::swap32(*(u32*)&videoBuffer[readptr + _uOffset]);
}
u8 FAKE_ReadFifo8()
{
return videoBuffer[readptr++];
}
int FAKE_GetPosition()
{
return readptr;
}
u8* FAKE_GetFifoCurrentPtr()
{
return &videoBuffer[readptr];
}
u16 FAKE_ReadFifo16()
{
u16 val = Common::swap16(*(u16*)(videoBuffer+readptr));
readptr += 2;
return val;
}
u32 FAKE_ReadFifo32()
{
u32 val = Common::swap32(*(u32*)(videoBuffer+readptr));
readptr += 4;
return val;
}
void FAKE_SkipFifo(u32 skip)
{
readptr += skip;
}
void Video_SendFifoData(u8* _uData)
{
// TODO (mb2): unrolled loop faster than memcpy here?
@ -135,24 +71,14 @@ void Video_SendFifoData(u8* _uData)
size += 32;
if (size + 32 >= FIFO_SIZE)
{
// TODO (mb2): Better and DataReader inline for DX9
#ifdef DATAREADER_INLINE
if (g_pVideoData) // for DX9 plugin "compatibility"
readptr = (int)(g_pVideoData-videoBuffer);
#endif
if (FAKE_GetFifoSize() > readptr)
{
PanicAlert("FIFO out of bounds (sz = %i, at %08x)", FAKE_GetFifoSize(), readptr);
}
// DebugLog("FAKE BUFFER LOOPS");
memmove(&videoBuffer[0], &videoBuffer[readptr], FAKE_GetFifoSize());
// memset(&videoBuffer[FAKE_GetFifoSize()], 0, FIFO_SIZE - FAKE_GetFifoSize());
size = FAKE_GetFifoSize();
readptr = 0;
#ifdef DATAREADER_INLINE
if (g_pVideoData) // for DX9 plugin "compatibility"
g_pVideoData = FAKE_GetFifoStartPtr();
#endif
int pos = (int)(g_pVideoData-videoBuffer);
//if (size-pos > pos)
//{
// PanicAlert("FIFO out of bounds (sz = %i, at %08x)", FAKE_GetFifoSize(), readptr);
//}
memmove(&videoBuffer[0], &videoBuffer[pos], size - pos );
size -= pos;
g_pVideoData = FAKE_GetFifoStartPtr();
}
OpcodeDecoder_Run();
}

View File

@ -23,50 +23,8 @@
#include "Common.h"
#include "ChunkFile.h"
// TODO (mb2) clean this if ok
#define DATAREADER_INLINE // comment to use the previous IDataReader way
//#define DATAREADER_DEBUG // simple compare with the previous IDataReader way
#if defined(DATAREADER_DEBUG) && !defined(DATAREADER_INLINE)
#define DATAREADER_INLINE
#endif
#define FIFO_SIZE (1024*1024)
#ifndef DATAREADER_INLINE
// inline for speed!
class FifoReader
{
u8 *ptr;
u8 *end;
u8 *tempPtr; //single element stack :P
u8 *tempEnd;
bool pushed;
public:
void Init(u8 *_ptr, u8 *_end)
{
ptr = _ptr; end = _end; pushed = false;
}
bool IsPushed() {return pushed;}
void Push(u8 *_ptr, u8 *_end) {pushed = true; tempPtr = ptr; tempEnd = end; ptr = _ptr; end = _end;}
void Pop() {pushed = false; ptr = tempPtr; end = tempEnd;}
u8 Peek8 (int offset) const { return ptr[offset]; }
u16 Peek16(int offset) const { return Common::swap16(*(u16*)(ptr+offset)); }
u32 Peek32(int offset) const { return Common::swap32(*(u32*)(ptr+offset)); }
u8 Read8 () {return *ptr++;}
u16 Read16() {const u16 value = Common::swap16(*((u16*)ptr)); ptr+=2; return value;}
u32 Read32() {const u32 value = Common::swap32(*((u32*)ptr)); ptr+=4; return value;}
float Read32F() {const u32 value = Common::swap32(*((u32*)ptr)); ptr+=4; return *(float*)&value;}
int GetRemainSize() const { return (int)(end - ptr); }
u8 *GetPtr() const { return ptr; }
void MoveEndForward() { end += 32; }
u8 *GetEnd() const { return end; }
};
extern FifoReader fifo;
#endif
void Fifo_Init();
void Fifo_Shutdown();
void Fifo_EnterLoop(const SVideoInitialize &video_initialize);

View File

@ -418,6 +418,10 @@
RelativePath=".\Src\CPMemory.h"
>
</File>
<File
RelativePath=".\Src\DataReader.h"
>
</File>
<File
RelativePath=".\Src\Fifo.cpp"
>