set svn:eol-style=native for **.cpp

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1442 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
bushing
2008-12-08 05:30:24 +00:00
parent 901fe7c00f
commit 49cfded60b
177 changed files with 53968 additions and 53968 deletions

View File

@ -1,24 +1,24 @@
// 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/
#include "Common.h"
#include "BPMemory.h"
//BP state
// STATE_TO_SAVE
// 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/
#include "Common.h"
#include "BPMemory.h"
//BP state
// STATE_TO_SAVE
BPMemory bpmem;

View File

@ -1,29 +1,29 @@
// 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/
#include "Common.h"
#include "CPMemory.h"
// CP state
// STATE_TO_SAVE
u32 arraybases[16];
u32 arraystrides[16];
TMatrixIndexA MatrixIndexA;
TMatrixIndexB MatrixIndexB;
TVtxDesc g_VtxDesc;
// Most games only use the first VtxAttr and simply reconfigure it all the time as needed.
VAT g_VtxAttr[8];
// 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/
#include "Common.h"
#include "CPMemory.h"
// CP state
// STATE_TO_SAVE
u32 arraybases[16];
u32 arraystrides[16];
TMatrixIndexA MatrixIndexA;
TMatrixIndexB MatrixIndexB;
TVtxDesc g_VtxDesc;
// Most games only use the first VtxAttr and simply reconfigure it all the time as needed.
VAT g_VtxAttr[8];

View File

@ -1,167 +1,167 @@
// 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/
#include <string.h>
#include "MemoryUtil.h"
#include "Thread.h"
#include "OpcodeDecoding.h"
#include "Fifo.h"
extern u8* g_pVideoData;
bool fifoStateRun = true;
// STATE_TO_SAVE
static u8 *videoBuffer;
static int size = 0;
void Fifo_DoState(PointerWrap &p)
{
p.DoArray(videoBuffer, FIFO_SIZE);
p.Do(size);
int pos = (int)(g_pVideoData-videoBuffer); // get offset
p.Do(pos); // read or write offset (depends on the mode afaik)
g_pVideoData = &videoBuffer[pos]; // overwrite g_pVideoData -> expected no change when load ss and change when save ss
}
void Fifo_Init()
{
videoBuffer = (u8*)AllocateMemoryPages(FIFO_SIZE);
fifoStateRun = true;
}
void Fifo_Shutdown()
{
FreeMemoryPages(videoBuffer, FIFO_SIZE);
fifoStateRun = false;
}
void Fifo_Stop()
{
fifoStateRun = false;
}
u8* FAKE_GetFifoStartPtr()
{
return videoBuffer;
}
u8* FAKE_GetFifoEndPtr()
{
return &videoBuffer[size];
}
void Video_SendFifoData(u8* _uData, u32 len)
{
if (size + len >= FIFO_SIZE)
{
int pos = (int)(g_pVideoData-videoBuffer);
if (size-pos > pos)
{
PanicAlert("FIFO out of bounds (sz = %i, at %08x)", size, pos);
}
memmove(&videoBuffer[0], &videoBuffer[pos], size - pos );
size -= pos;
g_pVideoData = FAKE_GetFifoStartPtr();
}
memcpy(videoBuffer + size, _uData, len);
size += len;
OpcodeDecoder_Run();
}
void Fifo_EnterLoop(const SVideoInitialize &video_initialize)
{
SCPFifoStruct &_fifo = *video_initialize.pCPFifo;
u32 distToSend;
#ifdef _WIN32
// TODO(ector): Don't peek so often!
while (video_initialize.pPeekMessages())
#else
while (fifoStateRun)
#endif
{
if (_fifo.CPReadWriteDistance < _fifo.CPLoWatermark)
Common::SleepCurrentThread(1);
//etc...
// check if we are able to run this buffer
if ((_fifo.bFF_GPReadEnable) && _fifo.CPReadWriteDistance && !(_fifo.bFF_BPEnable && _fifo.bFF_Breakpoint))
{
Common::SyncInterlockedExchange((LONG*)&_fifo.CPReadIdle, 0);
//video_initialize.pLog("RUN...........................",FALSE);
int peek_counter = 0;
while (_fifo.bFF_GPReadEnable && (_fifo.CPReadWriteDistance > 0))
{
peek_counter++;
if (peek_counter == 50) {
video_initialize.pPeekMessages();
peek_counter = 0;
}
// read the data and send it to the VideoPlugin
u32 readPtr = _fifo.CPReadPointer;
u8 *uData = video_initialize.pGetMemoryPointer(readPtr);
// if we are on BP mode we must send 32B chunks to Video plugin for BP checking
// TODO (mb2): test & check if MP1/MP2 realy need this now.
if (_fifo.bFF_BPEnable)
{
if (readPtr == _fifo.CPBreakpoint)
{
video_initialize.pLog("!!! BP irq raised",FALSE);
Common::SyncInterlockedExchange((LONG*)&_fifo.bFF_Breakpoint, 1);
video_initialize.pUpdateInterrupts();
break;
}
distToSend = 32;
readPtr += 32;
if ( readPtr >= _fifo.CPEnd)
readPtr = _fifo.CPBase;
}
else
{
#if 0 // ugly random GP slowdown for testing DC robustness... TODO: remove when completly sure DC is ok
int r=rand();if ((r&0xF)==r) Common::SleepCurrentThread(r);
distToSend = 32;
readPtr += 32;
if ( readPtr >= _fifo.CPEnd)
readPtr = _fifo.CPBase;
#else
// sending the whole CPReadWriteDistance
distToSend = _fifo.CPReadWriteDistance;
if ( (distToSend+readPtr) >= _fifo.CPEnd) // TODO: better?
{
distToSend =_fifo.CPEnd - readPtr;
readPtr = _fifo.CPBase;
}
else
readPtr += distToSend;
#endif
}
Video_SendFifoData(uData, distToSend);
Common::SyncInterlockedExchange((LONG*)&_fifo.CPReadPointer, readPtr);
Common::SyncInterlockedExchangeAdd((LONG*)&_fifo.CPReadWriteDistance, -distToSend);
}
//video_initialize.pLog("..........................IDLE",FALSE);
Common::SyncInterlockedExchange((LONG*)&_fifo.CPReadIdle, 1);
}
}
}
// 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/
#include <string.h>
#include "MemoryUtil.h"
#include "Thread.h"
#include "OpcodeDecoding.h"
#include "Fifo.h"
extern u8* g_pVideoData;
bool fifoStateRun = true;
// STATE_TO_SAVE
static u8 *videoBuffer;
static int size = 0;
void Fifo_DoState(PointerWrap &p)
{
p.DoArray(videoBuffer, FIFO_SIZE);
p.Do(size);
int pos = (int)(g_pVideoData-videoBuffer); // get offset
p.Do(pos); // read or write offset (depends on the mode afaik)
g_pVideoData = &videoBuffer[pos]; // overwrite g_pVideoData -> expected no change when load ss and change when save ss
}
void Fifo_Init()
{
videoBuffer = (u8*)AllocateMemoryPages(FIFO_SIZE);
fifoStateRun = true;
}
void Fifo_Shutdown()
{
FreeMemoryPages(videoBuffer, FIFO_SIZE);
fifoStateRun = false;
}
void Fifo_Stop()
{
fifoStateRun = false;
}
u8* FAKE_GetFifoStartPtr()
{
return videoBuffer;
}
u8* FAKE_GetFifoEndPtr()
{
return &videoBuffer[size];
}
void Video_SendFifoData(u8* _uData, u32 len)
{
if (size + len >= FIFO_SIZE)
{
int pos = (int)(g_pVideoData-videoBuffer);
if (size-pos > pos)
{
PanicAlert("FIFO out of bounds (sz = %i, at %08x)", size, pos);
}
memmove(&videoBuffer[0], &videoBuffer[pos], size - pos );
size -= pos;
g_pVideoData = FAKE_GetFifoStartPtr();
}
memcpy(videoBuffer + size, _uData, len);
size += len;
OpcodeDecoder_Run();
}
void Fifo_EnterLoop(const SVideoInitialize &video_initialize)
{
SCPFifoStruct &_fifo = *video_initialize.pCPFifo;
u32 distToSend;
#ifdef _WIN32
// TODO(ector): Don't peek so often!
while (video_initialize.pPeekMessages())
#else
while (fifoStateRun)
#endif
{
if (_fifo.CPReadWriteDistance < _fifo.CPLoWatermark)
Common::SleepCurrentThread(1);
//etc...
// check if we are able to run this buffer
if ((_fifo.bFF_GPReadEnable) && _fifo.CPReadWriteDistance && !(_fifo.bFF_BPEnable && _fifo.bFF_Breakpoint))
{
Common::SyncInterlockedExchange((LONG*)&_fifo.CPReadIdle, 0);
//video_initialize.pLog("RUN...........................",FALSE);
int peek_counter = 0;
while (_fifo.bFF_GPReadEnable && (_fifo.CPReadWriteDistance > 0))
{
peek_counter++;
if (peek_counter == 50) {
video_initialize.pPeekMessages();
peek_counter = 0;
}
// read the data and send it to the VideoPlugin
u32 readPtr = _fifo.CPReadPointer;
u8 *uData = video_initialize.pGetMemoryPointer(readPtr);
// if we are on BP mode we must send 32B chunks to Video plugin for BP checking
// TODO (mb2): test & check if MP1/MP2 realy need this now.
if (_fifo.bFF_BPEnable)
{
if (readPtr == _fifo.CPBreakpoint)
{
video_initialize.pLog("!!! BP irq raised",FALSE);
Common::SyncInterlockedExchange((LONG*)&_fifo.bFF_Breakpoint, 1);
video_initialize.pUpdateInterrupts();
break;
}
distToSend = 32;
readPtr += 32;
if ( readPtr >= _fifo.CPEnd)
readPtr = _fifo.CPBase;
}
else
{
#if 0 // ugly random GP slowdown for testing DC robustness... TODO: remove when completly sure DC is ok
int r=rand();if ((r&0xF)==r) Common::SleepCurrentThread(r);
distToSend = 32;
readPtr += 32;
if ( readPtr >= _fifo.CPEnd)
readPtr = _fifo.CPBase;
#else
// sending the whole CPReadWriteDistance
distToSend = _fifo.CPReadWriteDistance;
if ( (distToSend+readPtr) >= _fifo.CPEnd) // TODO: better?
{
distToSend =_fifo.CPEnd - readPtr;
readPtr = _fifo.CPBase;
}
else
readPtr += distToSend;
#endif
}
Video_SendFifoData(uData, distToSend);
Common::SyncInterlockedExchange((LONG*)&_fifo.CPReadPointer, readPtr);
Common::SyncInterlockedExchangeAdd((LONG*)&_fifo.CPReadWriteDistance, -distToSend);
}
//video_initialize.pLog("..........................IDLE",FALSE);
Common::SyncInterlockedExchange((LONG*)&_fifo.CPReadIdle, 1);
}
}
}

View File

@ -1,45 +1,45 @@
// 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/
#include "LookUpTables.h"
const int lut3to8[] = { 0x00,0x24,0x48,0x6D,0x91,0xB6,0xDA,0xFF};
const int lut4to8[] = { 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,
0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF};
const int lut5to8[] = { 0x00,0x08,0x10,0x18,0x20,0x29,0x31,0x39,
0x41,0x4A,0x52,0x5A,0x62,0x6A,0x73,0x7B,
0x83,0x8B,0x94,0x9C,0xA4,0xAC,0xB4,0xBD,
0xC5,0xCD,0xD5,0xDE,0xE6,0xEE,0xF6,0xFF};
int lut6to8[64];
float lutu8tosfloat[256];
float lutu8toufloat[256];
float luts8tosfloat[256];
float shiftLookup[32];
void InitLUTs()
{
for (int i = 0; i < 32; i++)
shiftLookup[i] = 1.0f / float(1 << i);
for (int i = 0; i < 64; i++)
lut6to8[i] = (i*255) / 63;
for (int i = 0; i < 256; i++)
{
lutu8tosfloat[i] = (float)(i - 128) / 127.0f;
lutu8toufloat[i] = (float)(i) / 255.0f;
luts8tosfloat[i] = ((float)(signed char)(char)i) / 127.0f;
}
}
// 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/
#include "LookUpTables.h"
const int lut3to8[] = { 0x00,0x24,0x48,0x6D,0x91,0xB6,0xDA,0xFF};
const int lut4to8[] = { 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,
0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF};
const int lut5to8[] = { 0x00,0x08,0x10,0x18,0x20,0x29,0x31,0x39,
0x41,0x4A,0x52,0x5A,0x62,0x6A,0x73,0x7B,
0x83,0x8B,0x94,0x9C,0xA4,0xAC,0xB4,0xBD,
0xC5,0xCD,0xD5,0xDE,0xE6,0xEE,0xF6,0xFF};
int lut6to8[64];
float lutu8tosfloat[256];
float lutu8toufloat[256];
float luts8tosfloat[256];
float shiftLookup[32];
void InitLUTs()
{
for (int i = 0; i < 32; i++)
shiftLookup[i] = 1.0f / float(1 << i);
for (int i = 0; i < 64; i++)
lut6to8[i] = (i*255) / 63;
for (int i = 0; i < 256; i++)
{
lutu8tosfloat[i] = (float)(i - 128) / 127.0f;
lutu8toufloat[i] = (float)(i) / 255.0f;
luts8tosfloat[i] = ((float)(signed char)(char)i) / 127.0f;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,291 +1,291 @@
// 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/
// Simple profiler
#include "Common.h"
#include "Profiler.h"
#include <list>
#include <string>
#include <map>
#ifdef _WIN32
#if defined (_MSC_VER) && _MSC_VER >= 1400
#define _interlockedbittestandset workaround_ms_header_bug_platform_sdk6_set
#define _interlockedbittestandreset workaround_ms_header_bug_platform_sdk6_reset
#define _interlockedbittestandset64 workaround_ms_header_bug_platform_sdk6_set64
#define _interlockedbittestandreset64 workaround_ms_header_bug_platform_sdk6_reset64
#include <intrin.h>
#undef _interlockedbittestandset
#undef _interlockedbittestandreset
#undef _interlockedbittestandset64
#undef _interlockedbittestandreset64
#pragma intrinsic(__rdtsc)
#endif
// Globals
static u64 luPerfFreq = 0;
#ifdef DVPROFILE
int g_bWriteProfile = 1;
#else
int g_bWriteProfile = 1;
#endif
inline u64 GET_PROFILE_TIME()
{
#if defined (_MSC_VER) && _MSC_VER >= 1400
return __rdtsc();
#else
LARGE_INTEGER lu;
QueryPerformanceCounter(&lu);
return lu.QuadPart;
#endif
}
#else
static u64 luPerfFreq = 1000000;
#define GET_PROFILE_TIME() //GetCpuTick()
#endif
struct DVPROFSTRUCT;
struct DVPROFSTRUCT
{
struct DATA
{
DATA(u64 time, u32 user = 0) : dwTime(time), dwUserData(user) {}
DATA() : dwTime(0), dwUserData(0) {}
u64 dwTime;
u32 dwUserData;
};
~DVPROFSTRUCT() {
std::list<DVPROFSTRUCT *>::iterator it = listpChild.begin();
while (it != listpChild.end()) {
delete *it;
*it = NULL;
++it;
}
}
// before DVProfEnd is called, contains the global time it started
// after DVProfEnd is called, contains the time it lasted
// the list contains all the tracked times
std::list<DATA> listTimes;
char pname[256];
std::list<DVPROFSTRUCT*> listpChild; // other profilers called during this profiler period
};
struct DVPROFTRACK
{
u32 dwUserData;
DVPROFSTRUCT::DATA* pdwTime;
DVPROFSTRUCT* pprof;
};
// the current profiling functions, the back element is the
// one that will first get popped off the list when DVProfEnd is called
// the pointer is an element in DVPROFSTRUCT::listTimes
static std::list<DVPROFTRACK> g_listCurTracking;
// the current profilers, note that these are the parents
// any profiler started during the time of another is held in
// DVPROFSTRUCT::listpChild
static std::list<DVPROFSTRUCT> g_listProfilers;
// ignores the hierarchy, pointer to elements in g_listProfilers
static std::list<DVPROFSTRUCT*> g_listAllProfilers;
void DVProfRegister(const char *pname)
{
if (!g_bWriteProfile)
return;
#ifdef _WIN32
if (luPerfFreq <= 1) {
#if defined (_MSC_VER) && _MSC_VER >= 1400
luPerfFreq = 1000000;
#else
LARGE_INTEGER temp;
QueryPerformanceFrequency(&temp);
luPerfFreq = temp.QuadPart;
#endif
}
#endif
std::list<DVPROFSTRUCT*>::iterator it = g_listAllProfilers.begin();
// while(it != g_listAllProfilers.end() ) {
//
// if( _tcscmp(pname, (*it)->pname) == 0 ) {
// (*it)->listTimes.push_back(timeGetTime());
// DVPROFTRACK dvtrack;
// dvtrack.pdwTime = &(*it)->listTimes.back();
// dvtrack.pprof = *it;
// g_listCurTracking.push_back(dvtrack);
// return;
// }
//
// ++it;
// }
// else add in a new profiler to the appropriate parent profiler
DVPROFSTRUCT* pprof = NULL;
if (g_listCurTracking.size() > 0) {
_assert_( g_listCurTracking.back().pprof != NULL );
g_listCurTracking.back().pprof->listpChild.push_back(new DVPROFSTRUCT());
pprof = g_listCurTracking.back().pprof->listpChild.back();
}
else {
g_listProfilers.push_back(DVPROFSTRUCT());
pprof = &g_listProfilers.back();
}
strncpy(pprof->pname, pname, 256);
// setup the profiler for tracking
pprof->listTimes.push_back(DVPROFSTRUCT::DATA(GET_PROFILE_TIME()));
DVPROFTRACK dvtrack;
dvtrack.pdwTime = &pprof->listTimes.back();
dvtrack.pprof = pprof;
dvtrack.dwUserData = 0;
g_listCurTracking.push_back(dvtrack);
// add to all profiler list
g_listAllProfilers.push_back(pprof);
}
void DVProfEnd(u32 dwUserData)
{
if (!g_bWriteProfile)
return;
if (g_listCurTracking.size() == 0)
return;
DVPROFTRACK dvtrack = g_listCurTracking.back();
_assert_( dvtrack.pdwTime != NULL && dvtrack.pprof != NULL );
dvtrack.pdwTime->dwTime = GET_PROFILE_TIME()- dvtrack.pdwTime->dwTime;
dvtrack.pdwTime->dwUserData= dwUserData;
g_listCurTracking.pop_back();
}
struct DVTIMEINFO
{
DVTIMEINFO() : uInclusive(0), uExclusive(0) {}
u64 uInclusive, uExclusive;
};
std::map<std::string, DVTIMEINFO> mapAggregateTimes;
u64 DVProfWriteStruct(FILE* f, const DVPROFSTRUCT* p, int ident)
{
fprintf(f, "%*s%s - ", ident, "", p->pname);
std::list<DVPROFSTRUCT::DATA>::const_iterator ittime = p->listTimes.begin();
u64 utime = 0;
while (ittime != p->listTimes.end()) {
utime += ittime->dwTime;
if (ittime->dwUserData)
fprintf(f, "time: %d, user: 0x%8.8x", (u32)ittime->dwTime, ittime->dwUserData);
else
fprintf(f, "time: %d", (u32)ittime->dwTime);
++ittime;
}
// yes this is necessary, maps have problems with constructors on their type
std::map<std::string, DVTIMEINFO>::iterator ittimes = mapAggregateTimes.find(p->pname);
if (ittimes == mapAggregateTimes.end()) {
ittimes = mapAggregateTimes.insert(std::map<std::string, DVTIMEINFO>::value_type(p->pname, DVTIMEINFO())).first;
ittimes->second.uExclusive = 0;
ittimes->second.uInclusive = 0;
}
ittimes->second.uInclusive += utime;
fprintf(f, "\n");
std::list<DVPROFSTRUCT*>::const_iterator itprof = p->listpChild.begin();
u64 uex = utime;
while (itprof != p->listpChild.end()) {
uex -= DVProfWriteStruct(f, *itprof, ident+4);
++itprof;
}
if (uex > utime) {
uex = 0;
}
ittimes->second.uExclusive += uex;
return utime;
}
void DVProfWrite(const char* pfilename, u32 frames)
{
_assert_( pfilename != NULL );
FILE* f = fopen(pfilename, "w");
// pop back any unused
mapAggregateTimes.clear();
std::list<DVPROFSTRUCT>::iterator it = g_listProfilers.begin();
while (it != g_listProfilers.end() ) {
DVProfWriteStruct(f, &(*it), 0);
++it;
}
std::map<std::string, DVTIMEINFO>::const_iterator iter;
fprintf(f, "\n\n-------------------------------------------------------------------\n\n");
u64 uTotal[2] = {0};
double fiTotalTime[2];
for (iter = mapAggregateTimes.begin(); iter != mapAggregateTimes.end(); ++iter) {
uTotal[0] += iter->second.uExclusive;
uTotal[1] += iter->second.uInclusive;
}
fprintf(f, "total times (%d): ex: %Lu ", frames, 1000000 * uTotal[0] / (luPerfFreq*(u64)frames));
fprintf(f, "inc: %Lu\n", 1000000 * uTotal[1]/(luPerfFreq*(u64)frames));
fiTotalTime[0] = 1.0 / (double)uTotal[0];
fiTotalTime[1] = 1.0 / (double)uTotal[1];
// output the combined times
for (iter = mapAggregateTimes.begin(); iter != mapAggregateTimes.end(); ++iter) {
fprintf(f, "%s - ex: %f inc: %f\n", iter->first.c_str(), (float)((double)iter->second.uExclusive * fiTotalTime[0]),
(float)((double)iter->second.uInclusive * fiTotalTime[1]));
}
fclose(f);
}
void DVProfClear()
{
g_listCurTracking.clear();
g_listProfilers.clear();
g_listAllProfilers.clear();
}
// 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/
// Simple profiler
#include "Common.h"
#include "Profiler.h"
#include <list>
#include <string>
#include <map>
#ifdef _WIN32
#if defined (_MSC_VER) && _MSC_VER >= 1400
#define _interlockedbittestandset workaround_ms_header_bug_platform_sdk6_set
#define _interlockedbittestandreset workaround_ms_header_bug_platform_sdk6_reset
#define _interlockedbittestandset64 workaround_ms_header_bug_platform_sdk6_set64
#define _interlockedbittestandreset64 workaround_ms_header_bug_platform_sdk6_reset64
#include <intrin.h>
#undef _interlockedbittestandset
#undef _interlockedbittestandreset
#undef _interlockedbittestandset64
#undef _interlockedbittestandreset64
#pragma intrinsic(__rdtsc)
#endif
// Globals
static u64 luPerfFreq = 0;
#ifdef DVPROFILE
int g_bWriteProfile = 1;
#else
int g_bWriteProfile = 1;
#endif
inline u64 GET_PROFILE_TIME()
{
#if defined (_MSC_VER) && _MSC_VER >= 1400
return __rdtsc();
#else
LARGE_INTEGER lu;
QueryPerformanceCounter(&lu);
return lu.QuadPart;
#endif
}
#else
static u64 luPerfFreq = 1000000;
#define GET_PROFILE_TIME() //GetCpuTick()
#endif
struct DVPROFSTRUCT;
struct DVPROFSTRUCT
{
struct DATA
{
DATA(u64 time, u32 user = 0) : dwTime(time), dwUserData(user) {}
DATA() : dwTime(0), dwUserData(0) {}
u64 dwTime;
u32 dwUserData;
};
~DVPROFSTRUCT() {
std::list<DVPROFSTRUCT *>::iterator it = listpChild.begin();
while (it != listpChild.end()) {
delete *it;
*it = NULL;
++it;
}
}
// before DVProfEnd is called, contains the global time it started
// after DVProfEnd is called, contains the time it lasted
// the list contains all the tracked times
std::list<DATA> listTimes;
char pname[256];
std::list<DVPROFSTRUCT*> listpChild; // other profilers called during this profiler period
};
struct DVPROFTRACK
{
u32 dwUserData;
DVPROFSTRUCT::DATA* pdwTime;
DVPROFSTRUCT* pprof;
};
// the current profiling functions, the back element is the
// one that will first get popped off the list when DVProfEnd is called
// the pointer is an element in DVPROFSTRUCT::listTimes
static std::list<DVPROFTRACK> g_listCurTracking;
// the current profilers, note that these are the parents
// any profiler started during the time of another is held in
// DVPROFSTRUCT::listpChild
static std::list<DVPROFSTRUCT> g_listProfilers;
// ignores the hierarchy, pointer to elements in g_listProfilers
static std::list<DVPROFSTRUCT*> g_listAllProfilers;
void DVProfRegister(const char *pname)
{
if (!g_bWriteProfile)
return;
#ifdef _WIN32
if (luPerfFreq <= 1) {
#if defined (_MSC_VER) && _MSC_VER >= 1400
luPerfFreq = 1000000;
#else
LARGE_INTEGER temp;
QueryPerformanceFrequency(&temp);
luPerfFreq = temp.QuadPart;
#endif
}
#endif
std::list<DVPROFSTRUCT*>::iterator it = g_listAllProfilers.begin();
// while(it != g_listAllProfilers.end() ) {
//
// if( _tcscmp(pname, (*it)->pname) == 0 ) {
// (*it)->listTimes.push_back(timeGetTime());
// DVPROFTRACK dvtrack;
// dvtrack.pdwTime = &(*it)->listTimes.back();
// dvtrack.pprof = *it;
// g_listCurTracking.push_back(dvtrack);
// return;
// }
//
// ++it;
// }
// else add in a new profiler to the appropriate parent profiler
DVPROFSTRUCT* pprof = NULL;
if (g_listCurTracking.size() > 0) {
_assert_( g_listCurTracking.back().pprof != NULL );
g_listCurTracking.back().pprof->listpChild.push_back(new DVPROFSTRUCT());
pprof = g_listCurTracking.back().pprof->listpChild.back();
}
else {
g_listProfilers.push_back(DVPROFSTRUCT());
pprof = &g_listProfilers.back();
}
strncpy(pprof->pname, pname, 256);
// setup the profiler for tracking
pprof->listTimes.push_back(DVPROFSTRUCT::DATA(GET_PROFILE_TIME()));
DVPROFTRACK dvtrack;
dvtrack.pdwTime = &pprof->listTimes.back();
dvtrack.pprof = pprof;
dvtrack.dwUserData = 0;
g_listCurTracking.push_back(dvtrack);
// add to all profiler list
g_listAllProfilers.push_back(pprof);
}
void DVProfEnd(u32 dwUserData)
{
if (!g_bWriteProfile)
return;
if (g_listCurTracking.size() == 0)
return;
DVPROFTRACK dvtrack = g_listCurTracking.back();
_assert_( dvtrack.pdwTime != NULL && dvtrack.pprof != NULL );
dvtrack.pdwTime->dwTime = GET_PROFILE_TIME()- dvtrack.pdwTime->dwTime;
dvtrack.pdwTime->dwUserData= dwUserData;
g_listCurTracking.pop_back();
}
struct DVTIMEINFO
{
DVTIMEINFO() : uInclusive(0), uExclusive(0) {}
u64 uInclusive, uExclusive;
};
std::map<std::string, DVTIMEINFO> mapAggregateTimes;
u64 DVProfWriteStruct(FILE* f, const DVPROFSTRUCT* p, int ident)
{
fprintf(f, "%*s%s - ", ident, "", p->pname);
std::list<DVPROFSTRUCT::DATA>::const_iterator ittime = p->listTimes.begin();
u64 utime = 0;
while (ittime != p->listTimes.end()) {
utime += ittime->dwTime;
if (ittime->dwUserData)
fprintf(f, "time: %d, user: 0x%8.8x", (u32)ittime->dwTime, ittime->dwUserData);
else
fprintf(f, "time: %d", (u32)ittime->dwTime);
++ittime;
}
// yes this is necessary, maps have problems with constructors on their type
std::map<std::string, DVTIMEINFO>::iterator ittimes = mapAggregateTimes.find(p->pname);
if (ittimes == mapAggregateTimes.end()) {
ittimes = mapAggregateTimes.insert(std::map<std::string, DVTIMEINFO>::value_type(p->pname, DVTIMEINFO())).first;
ittimes->second.uExclusive = 0;
ittimes->second.uInclusive = 0;
}
ittimes->second.uInclusive += utime;
fprintf(f, "\n");
std::list<DVPROFSTRUCT*>::const_iterator itprof = p->listpChild.begin();
u64 uex = utime;
while (itprof != p->listpChild.end()) {
uex -= DVProfWriteStruct(f, *itprof, ident+4);
++itprof;
}
if (uex > utime) {
uex = 0;
}
ittimes->second.uExclusive += uex;
return utime;
}
void DVProfWrite(const char* pfilename, u32 frames)
{
_assert_( pfilename != NULL );
FILE* f = fopen(pfilename, "w");
// pop back any unused
mapAggregateTimes.clear();
std::list<DVPROFSTRUCT>::iterator it = g_listProfilers.begin();
while (it != g_listProfilers.end() ) {
DVProfWriteStruct(f, &(*it), 0);
++it;
}
std::map<std::string, DVTIMEINFO>::const_iterator iter;
fprintf(f, "\n\n-------------------------------------------------------------------\n\n");
u64 uTotal[2] = {0};
double fiTotalTime[2];
for (iter = mapAggregateTimes.begin(); iter != mapAggregateTimes.end(); ++iter) {
uTotal[0] += iter->second.uExclusive;
uTotal[1] += iter->second.uInclusive;
}
fprintf(f, "total times (%d): ex: %Lu ", frames, 1000000 * uTotal[0] / (luPerfFreq*(u64)frames));
fprintf(f, "inc: %Lu\n", 1000000 * uTotal[1]/(luPerfFreq*(u64)frames));
fiTotalTime[0] = 1.0 / (double)uTotal[0];
fiTotalTime[1] = 1.0 / (double)uTotal[1];
// output the combined times
for (iter = mapAggregateTimes.begin(); iter != mapAggregateTimes.end(); ++iter) {
fprintf(f, "%s - ex: %f inc: %f\n", iter->first.c_str(), (float)((double)iter->second.uExclusive * fiTotalTime[0]),
(float)((double)iter->second.uInclusive * fiTotalTime[1]));
}
fclose(f);
}
void DVProfClear()
{
g_listCurTracking.clear();
g_listProfilers.clear();
g_listAllProfilers.clear();
}

View File

@ -1,43 +1,43 @@
// 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/
#include <string.h>
#include "Statistics.h"
Statistics stats;
template <class T>
void Xchg(T& a, T&b)
{
T c = a;
a = b;
b = c;
}
void Statistics::ResetFrame()
{
memset(&thisFrame, 0, sizeof(ThisFrame));
}
void Statistics::SwapDL()
{
Xchg(stats.thisFrame.numDLPrims, stats.thisFrame.numPrims);
Xchg(stats.thisFrame.numXFLoadsInDL, stats.thisFrame.numXFLoads);
Xchg(stats.thisFrame.numCPLoadsInDL, stats.thisFrame.numCPLoads);
Xchg(stats.thisFrame.numBPLoadsInDL, stats.thisFrame.numBPLoads);
}
// 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/
#include <string.h>
#include "Statistics.h"
Statistics stats;
template <class T>
void Xchg(T& a, T&b)
{
T c = a;
a = b;
b = c;
}
void Statistics::ResetFrame()
{
memset(&thisFrame, 0, sizeof(ThisFrame));
}
void Statistics::SwapDL()
{
Xchg(stats.thisFrame.numDLPrims, stats.thisFrame.numPrims);
Xchg(stats.thisFrame.numXFLoadsInDL, stats.thisFrame.numXFLoads);
Xchg(stats.thisFrame.numCPLoadsInDL, stats.thisFrame.numCPLoads);
Xchg(stats.thisFrame.numBPLoadsInDL, stats.thisFrame.numBPLoads);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,466 +1,466 @@
// 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/
#include <math.h>
#include "Profiler.h"
#include "NativeVertexFormat.h"
#include "BPMemory.h"
#include "VertexShader.h"
static char text[16384];
#define WRITE p+=sprintf
#define LIGHTS_POS ""
char *GenerateLightShader(char* p, int index, const LitChannel& chan, const char* dest, int coloralpha);
char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
{
text[sizeof(text) - 1] = 0x7C; // canary
DVSTARTPROFILE();
_assert_( bpmem.genMode.numtexgens == xfregs.numTexGens);
_assert_( bpmem.genMode.numcolchans == xfregs.nNumChans);
u32 lightMask = 0;
if (xfregs.nNumChans > 0)
lightMask |= xfregs.colChans[0].color.GetFullLightMask() | xfregs.colChans[0].alpha.GetFullLightMask();
if (xfregs.nNumChans > 1)
lightMask |= xfregs.colChans[1].color.GetFullLightMask() | xfregs.colChans[1].alpha.GetFullLightMask();
bool bOutputZ = bpmem.ztex2.op==ZTEXTURE_ADD || has_zbuffer_target;
int ztexcoord = -1;
char *p = text;
WRITE(p, "//Vertex Shader: comp:%x, \n", components);
WRITE(p, "typedef struct {\n"
" float4 T0, T1, T2;\n"
" float4 N0, N1, N2;\n"
"} s_"I_POSNORMALMATRIX";\n\n"
"typedef struct {\n"
" float4 t;\n"
"} FLT4;\n"
"typedef struct {\n"
" FLT4 T[24];\n"
"} s_"I_TEXMATRICES";\n\n"
"typedef struct {\n"
" FLT4 T[64];\n"
"} s_"I_TRANSFORMMATRICES";\n\n"
"typedef struct {\n"
" FLT4 T[32];\n"
"} s_"I_NORMALMATRICES";\n\n"
"typedef struct {\n"
" FLT4 T[64];\n"
"} s_"I_POSTTRANSFORMMATRICES";\n\n"
"typedef struct {\n"
" float4 col;\n"
" float4 cosatt;\n"
" float4 distatt;\n"
" float4 pos;\n"
" float4 dir;\n"
"} Light;\n\n"
"typedef struct {\n"
" Light lights[8];\n"
"} s_"I_LIGHTS";\n\n"
"typedef struct {\n"
" float4 C0, C1, C2, C3;\n"
"} s_"I_MATERIALS";\n\n"
"typedef struct {\n"
" float4 T0,T1,T2,T3;\n"
"} s_"I_PROJECTION";\n"
"typedef struct {\n"
" float4 params;\n" // a, b, c, b_shift
"} s_"I_FOGPARAMS";\n\n");
WRITE(p, "struct VS_OUTPUT {\n");
WRITE(p, " float4 pos : POSITION;\n");
WRITE(p, " float4 colors[2] : COLOR0;\n");
// if outputting Z, embed the Z coordinate in the w component of a texture coordinate
// if number of tex gens occupies all the texture coordinates, use the last tex coord
// otherwise use the next available tex coord
for (int i = 0; i < xfregs.numTexGens; ++i) {
WRITE(p, " float%d tex%d : TEXCOORD%d;\n", (i==(xfregs.numTexGens-1)&&bOutputZ)?4:3, i, i);
}
if (bOutputZ && xfregs.numTexGens == 0) {
ztexcoord = 0;
WRITE(p, " float4 tex%d : TEXCOORD%d;\n", ztexcoord, ztexcoord);
}
else if (bOutputZ)
ztexcoord = xfregs.numTexGens - 1;
WRITE(p, "};\n");
WRITE(p, "\n");
// uniforms
// bool bTexMtx = ((components & VB_HAS_TEXMTXIDXALL)<<VB_HAS_UVTEXMTXSHIFT)!=0; unused TODO: keep?
WRITE(p, "uniform s_"I_TRANSFORMMATRICES" "I_TRANSFORMMATRICES" : register(c%d);\n", C_TRANSFORMMATRICES);
WRITE(p, "uniform s_"I_TEXMATRICES" "I_TEXMATRICES" : register(c%d);\n", C_TEXMATRICES); // also using tex matrices
WRITE(p, "uniform s_"I_NORMALMATRICES" "I_NORMALMATRICES" : register(c%d);\n", C_NORMALMATRICES);
WRITE(p, "uniform s_"I_POSNORMALMATRIX" "I_POSNORMALMATRIX" : register(c%d);\n", C_POSNORMALMATRIX);
WRITE(p, "uniform s_"I_POSTTRANSFORMMATRICES" "I_POSTTRANSFORMMATRICES" : register(c%d);\n", C_POSTTRANSFORMMATRICES);
WRITE(p, "uniform s_"I_LIGHTS" "I_LIGHTS" : register(c%d);\n", C_LIGHTS);
WRITE(p, "uniform s_"I_MATERIALS" "I_MATERIALS" : register(c%d);\n", C_MATERIALS);
WRITE(p, "uniform s_"I_PROJECTION" "I_PROJECTION" : register(c%d);\n", C_PROJECTION);
WRITE(p, "uniform s_"I_FOGPARAMS" "I_FOGPARAMS" : register(c%d);\n", C_FOGPARAMS);
WRITE(p, "VS_OUTPUT main(\n");
// inputs
if (components & VB_HAS_NRM0)
WRITE(p, " float3 rawnorm0 : NORMAL,\n");
if (components & VB_HAS_NRM1)
WRITE(p, " float3 rawnorm1 : ATTR%d,\n", SHADER_NORM1_ATTRIB);
if (components & VB_HAS_NRM2)
WRITE(p, " float3 rawnorm2 : ATTR%d,\n", SHADER_NORM2_ATTRIB);
if (components & VB_HAS_COL0)
WRITE(p, " float4 color0 : COLOR0,\n");
if (components & VB_HAS_COL1)
WRITE(p, " float4 color1 : COLOR1,\n");
for (int i = 0; i < 8; ++i) {
u32 hastexmtx = (components & (VB_HAS_TEXMTXIDX0<<i));
if ((components & (VB_HAS_UV0<<i)) || hastexmtx )
WRITE(p, " float%d tex%d : TEXCOORD%d,\n", hastexmtx ? 3 : 2, i,i);
}
if (components & VB_HAS_POSMTXIDX)
WRITE(p, " half posmtx : ATTR%d,\n", SHADER_POSMTX_ATTRIB);
WRITE(p, " float4 rawpos : POSITION) {\n");
WRITE(p, "VS_OUTPUT o;\n");
// transforms
if (components & VB_HAS_POSMTXIDX) {
WRITE(p, "float4 pos = float4(dot("I_TRANSFORMMATRICES".T[posmtx].t, rawpos), dot("I_TRANSFORMMATRICES".T[posmtx+1].t, rawpos), dot("I_TRANSFORMMATRICES".T[posmtx+2].t, rawpos),1);\n");
if (components & VB_HAS_NRMALL) {
WRITE(p, "int normidx = posmtx >= 32 ? (posmtx-32) : posmtx;\n");
WRITE(p, "float3 N0 = "I_NORMALMATRICES".T[normidx].t.xyz, N1 = "I_NORMALMATRICES".T[normidx+1].t.xyz, N2 = "I_NORMALMATRICES".T[normidx+2].t.xyz;\n");
}
if (components & VB_HAS_NRM0)
WRITE(p, "half3 _norm0 = half3(dot(N0, rawnorm0), dot(N1, rawnorm0), dot(N2, rawnorm0));\n"
"half3 norm0 = normalize(_norm0);\n");
if (components & VB_HAS_NRM1)
WRITE(p, "half3 _norm1 = half3(dot(N0, rawnorm1), dot(N1, rawnorm1), dot(N2, rawnorm1));\n");
//"half3 norm1 = normalize(_norm1);\n");
if (components & VB_HAS_NRM2)
WRITE(p, "half3 _norm2 = half3(dot(N0, rawnorm2), dot(N1, rawnorm2), dot(N2, rawnorm2));\n");
//"half3 norm2 = normalize(_norm2);\n");
}
else {
WRITE(p, "float4 pos = float4(dot("I_POSNORMALMATRIX".T0, rawpos), dot("I_POSNORMALMATRIX".T1, rawpos), dot("I_POSNORMALMATRIX".T2, rawpos), 1);\n");
if (components & VB_HAS_NRM0)
WRITE(p, "half3 _norm0 = half3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm0), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm0), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm0));\n"
"half3 norm0 = normalize(_norm0);\n");
if (components & VB_HAS_NRM1)
WRITE(p, "half3 _norm1 = half3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm1), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm1), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm1));\n");
//"half3 norm1 = normalize(_norm1);\n");
if (components & VB_HAS_NRM2)
WRITE(p, "half3 _norm2 = half3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm2), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm2), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm2));\n");
//"half3 norm2 = normalize(_norm2);\n");
}
if (!(components & VB_HAS_NRM0))
WRITE(p, "half3 _norm0 = half3(0,0,0), norm0= half3(0,0,0);\n");
WRITE(p, "o.pos = float4(dot("I_PROJECTION".T0, pos), dot("I_PROJECTION".T1, pos), dot("I_PROJECTION".T2, pos), dot("I_PROJECTION".T3, pos));\n");
WRITE(p, "half4 mat, lacc;\n"
"half3 ldir, h;\n"
"half dist, dist2, attn;\n");
// lights/colors
for (int j = 0; j < xfregs.nNumChans; j++) {
// bool bColorAlphaSame = xfregs.colChans[j].color.hex == xfregs.colChans[j].alpha.hex; unused
const LitChannel& color = xfregs.colChans[j].color;
const LitChannel& alpha = xfregs.colChans[j].alpha;
WRITE(p, "{\n");
if (color.matsource) {// from vertex
if (components & (VB_HAS_COL0<<j) )
WRITE(p, "mat = color%d;\n", j);
else WRITE(p, "mat = half4(1,1,1,1);\n");
}
else // from color
WRITE(p, "mat = "I_MATERIALS".C%d;\n", j+2);
if (color.enablelighting) {
if (color.ambsource) {// from vertex
if (components & (VB_HAS_COL0<<j) )
WRITE(p, "lacc = color%d;\n", j);
else WRITE(p, "lacc = half4(0.0f,0.0f,0.0f,0.0f);\n");
}
else // from color
WRITE(p, "lacc = "I_MATERIALS".C%d;\n", j);
}
// check if alpha is different
if (alpha.matsource != color.matsource) {
if (alpha.matsource) {// from vertex
if (components & (VB_HAS_COL0<<j) )
WRITE(p, "mat.w = color%d.w;\n", j);
else WRITE(p, "mat.w = 1;\n");
}
else // from color
WRITE(p, "mat.w = "I_MATERIALS".C%d.w;\n", j+2);
}
if (alpha.enablelighting && alpha.ambsource != color.ambsource) {
if (alpha.ambsource) {// from vertex
if (components & (VB_HAS_COL0<<j) )
WRITE(p, "lacc.w = color%d.w;\n", j);
else WRITE(p, "lacc.w = 0;\n");
}
else // from color
WRITE(p, "lacc.w = "I_MATERIALS".C%d.w;\n", j);
}
if (color.enablelighting && alpha.enablelighting && (color.GetFullLightMask() != alpha.GetFullLightMask() || color.lightparams != alpha.lightparams)) {
// both have lighting, except not using the same lights
int mask = 0; // holds already computed lights
if (color.lightparams == alpha.lightparams && (color.GetFullLightMask() & alpha.GetFullLightMask())) {
// if lights are shared, compute those first
mask = color.GetFullLightMask() & alpha.GetFullLightMask();
for (int i = 0; i < 8; ++i) {
if (mask&(1<<i))
p = GenerateLightShader(p, i, color, "lacc", 3);
}
}
// no shared lights
for (int i = 0; i < 8; ++i) {
if (!(mask&(1<<i)) && (color.GetFullLightMask() & (1<<i)) )
p = GenerateLightShader(p, i, color, "lacc", 1);
if (!(mask&(1<<i)) && (alpha.GetFullLightMask() & (1<<i)) )
p = GenerateLightShader(p, i, alpha, "lacc", 2);
}
}
else if (color.enablelighting || alpha.enablelighting) {
// either one is enabled
int coloralpha = (int)color.enablelighting|((int)alpha.enablelighting<<1);
for (int i = 0; i < 8; ++i) {
if (color.GetFullLightMask() & (1<<i) )
p = GenerateLightShader(p, i, color.enablelighting?color:alpha, "lacc", coloralpha);
}
}
if (color.enablelighting != alpha.enablelighting) {
if (color.enablelighting )
WRITE(p, "o.colors[%d].xyz = mat.xyz * clamp(lacc.xyz,float3(0.0f,0.0f,0.0f),float3(1.0f,1.0f,1.0f));\n"
"o.colors[%d].w = mat.w;\n", j, j);
else
WRITE(p, "o.colors[%d].xyz = mat.xyz;\n"
"o.colors[%d].w = mat.w * clamp(lacc.w,0.0f,1.0f);\n", j, j);
}
else {
if (alpha.enablelighting )
WRITE(p, "o.colors[%d] = mat * clamp(lacc,float4(0.0f,0.0f,0.0f,0.0f), float4(1.0f,1.0f,1.0f,1.0f));\n", j);
else WRITE(p, "o.colors[%d] = mat;\n", j);
}
WRITE(p, "}\n");
}
// zero left over channels
for (int i = xfregs.nNumChans; i < 2; ++i)
WRITE(p, "o.colors[%d] = 0;\n", i);
// transform texcoords
for (int i = 0; i < xfregs.numTexGens; ++i) {
TexMtxInfo& texinfo = xfregs.texcoords[i].texmtxinfo;
WRITE(p, "{\n");
switch (texinfo.sourcerow) {
case XF_SRCGEOM_INROW:
_assert_( texinfo.inputform == XF_TEXINPUT_ABC1 );
WRITE(p, "float4 coord = rawpos;\n"); // pos.w is 1
break;
case XF_SRCNORMAL_INROW:
if (components & VB_HAS_NRM0) {
_assert_( texinfo.inputform == XF_TEXINPUT_ABC1 );
WRITE(p, "float4 coord = float4(rawnorm0.xyz, 1.0);\n");
}
else WRITE(p, "float4 coord = 0;\n");
break;
case XF_SRCCOLORS_INROW:
_assert_( texinfo.texgentype == XF_TEXGEN_COLOR_STRGBC0 || texinfo.texgentype == XF_TEXGEN_COLOR_STRGBC1 );
break;
case XF_SRCBINORMAL_T_INROW:
if (components & VB_HAS_NRM1) {
_assert_( texinfo.inputform == XF_TEXINPUT_ABC1 );
WRITE(p, "float4 coord = float4(rawnorm1.xyz, 1.0);\n");
}
else WRITE(p, "float4 coord = 0;\n");
break;
case XF_SRCBINORMAL_B_INROW:
if (components & VB_HAS_NRM2) {
_assert_( texinfo.inputform == XF_TEXINPUT_ABC1 );
WRITE(p, "float4 coord = float4(rawnorm2.xyz, 1.0);\n");
}
else WRITE(p, "float4 coord = 0;\n");
break;
default:
_assert_(texinfo.sourcerow <= XF_SRCTEX7_INROW);
if (components & (VB_HAS_UV0<<(texinfo.sourcerow - XF_SRCTEX0_INROW)) )
WRITE(p, "float4 coord = float4(tex%d.x, tex%d.y, 1.0f, 1.0f);\n", texinfo.sourcerow - XF_SRCTEX0_INROW, texinfo.sourcerow - XF_SRCTEX0_INROW);
else
WRITE(p, "float4 coord = float4(0.0f, 0.0f, 1.0f, 1.0f);\n");
break;
}
// firs transformation
switch (texinfo.texgentype) {
case XF_TEXGEN_REGULAR:
if (components & (VB_HAS_TEXMTXIDX0<<i)) {
if (texinfo.projection == XF_TEXPROJ_STQ )
WRITE(p, "o.tex%d.xyz = float3(dot(coord, "I_TRANSFORMMATRICES".T[tex%d.z].t), dot(coord, "I_TRANSFORMMATRICES".T[tex%d.z+1].t), dot(coord, "I_TRANSFORMMATRICES".T[tex%d.z+2].t));\n", i, i, i, i);
else {
WRITE(p, "o.tex%d.xyz = float3(dot(coord, "I_TRANSFORMMATRICES".T[tex%d.z].t), dot(coord, "I_TRANSFORMMATRICES".T[tex%d.z+1].t), 1);\n", i, i, i);
}
}
else {
if (texinfo.projection == XF_TEXPROJ_STQ )
WRITE(p, "o.tex%d.xyz = float3(dot(coord, "I_TEXMATRICES".T[%d].t), dot(coord, "I_TEXMATRICES".T[%d].t), dot(coord, "I_TEXMATRICES".T[%d].t));\n", i, 3*i, 3*i+1, 3*i+2);
else
WRITE(p, "o.tex%d.xyz = float3(dot(coord, "I_TEXMATRICES".T[%d].t), dot(coord, "I_TEXMATRICES".T[%d].t), 1);\n", i, 3*i, 3*i+1);
}
break;
case XF_TEXGEN_EMBOSS_MAP: // calculate tex coords into bump map
if (components & (VB_HAS_NRM1|VB_HAS_NRM2)) {
// transform the light dir into tangent space
WRITE(p, "ldir = normalize("I_LIGHTS".lights[%d].pos.xyz - pos.xyz);\n", texinfo.embosslightshift);
WRITE(p, "o.tex%d.xyz = o.tex%d.xyz + float3(dot(ldir, _norm1), dot(ldir, _norm2), 0.0f);\n", i, texinfo.embosssourceshift);
}
else _assert_(0); // should have normals
break;
case XF_TEXGEN_COLOR_STRGBC0:
_assert_(texinfo.sourcerow == XF_SRCCOLORS_INROW);
WRITE(p, "o.tex%d.xyz = float3(o.colors[0].x, o.colors[0].y, 1);\n", i);
break;
case XF_TEXGEN_COLOR_STRGBC1:
_assert_(texinfo.sourcerow == XF_SRCCOLORS_INROW);
WRITE(p, "o.tex%d.xyz = float3(o.colors[1].x, o.colors[1].y, 1);\n", i);
break;
}
if(xfregs.bEnableDualTexTransform && texinfo.texgentype == XF_TEXGEN_REGULAR) { // only works for regular tex gen types?
if (xfregs.texcoords[i].postmtxinfo.normalize)
WRITE(p, "o.tex%d.xyz = normalize(o.tex%d.xyz);\n", i, i);
//multiply by postmatrix
int postidx = xfregs.texcoords[i].postmtxinfo.index;
WRITE(p, "float4 P0 = "I_POSTTRANSFORMMATRICES".T[%d].t;\n"
"float4 P1 = "I_POSTTRANSFORMMATRICES".T[%d].t;\n"
"float4 P2 = "I_POSTTRANSFORMMATRICES".T[%d].t;\n",
postidx&0x3f, (postidx+1)&0x3f, (postidx+2)&0x3f);
WRITE(p, "o.tex%d.xyz = float3(dot(P0.xyz, o.tex%d.xyz) + P0.w, dot(P1.xyz, o.tex%d.xyz) + P1.w, dot(P2.xyz, o.tex%d.xyz) + P2.w);\n", i, i, i, i);
}
WRITE(p, "}\n");
}
if (ztexcoord >= 0 )
WRITE(p, "o.tex%d.w = o.pos.z/o.pos.w;\n", ztexcoord);
// if (bpmem.fog.c_proj_fsel.fsel != 0) {
// switch (bpmem.fog.c_proj_fsel.fsel) {
// case 1: // linear
// break;
// case 4: // exp
// break;
// case 5: // exp2
// break;
// case 6: // backward exp
// break;
// case 7: // backward exp2
// break;
// }
//
// WRITE(p, "o.fog = o.pos.z/o.pos.w;\n");
// }
WRITE(p, "return o;\n}\n");
if (text[sizeof(text) - 1] != 0x7C)
PanicAlert("VertexShader generator - buffer too small, canary has been eaten!");
return text;
}
// coloralpha - 1 if color, 2 if alpha
char* GenerateLightShader(char* p, int index, const LitChannel& chan, const char* dest, int coloralpha)
{
const char* swizzle = "xyzw";
if (coloralpha == 1 ) swizzle = "xyz";
else if (coloralpha == 2 ) swizzle = "w";
if (!(chan.attnfunc & 1)) {
// atten disabled
switch (chan.diffusefunc) {
case LIGHTDIF_NONE:
WRITE(p, "%s.%s += "I_LIGHTS".lights[%d].col.%s;\n", dest, swizzle, index, swizzle);
break;
case LIGHTDIF_SIGN:
case LIGHTDIF_CLAMP:
WRITE(p, "ldir = normalize("I_LIGHTS".lights[%d].pos.xyz - pos.xyz);\n", index);
WRITE(p, "%s.%s += %sdot(ldir, norm0)) * "I_LIGHTS".lights[%d].col.%s;\n",
dest, swizzle, chan.diffusefunc != LIGHTDIF_SIGN ? "max(0.0f," :"(", index, swizzle);
break;
default: _assert_(0);
}
}
else { // spec and spot
WRITE(p, "ldir = "I_LIGHTS".lights[%d].pos.xyz - pos.xyz;\n", index);
if (chan.attnfunc == 3) { // spot
WRITE(p, "dist2 = dot(ldir, ldir);\n"
"dist = sqrt(dist2);\n"
"ldir = ldir / dist;\n"
"attn = max(0.0f, dot(ldir, "I_LIGHTS".lights[%d].dir.xyz));\n",index);
WRITE(p, "attn = max(0.0f, dot("I_LIGHTS".lights[%d].cosatt.xyz, half3(1, attn, attn*attn))) / dot("I_LIGHTS".lights[%d].distatt.xyz, half3(1,dist,dist2));\n", index, index);
}
else if (chan.attnfunc == 1) { // specular
WRITE(p, "attn = dot(norm0, "I_LIGHTS".lights[%d].pos.xyz) > 0 ? max(0.0f, dot(norm0, "I_LIGHTS".lights[%d].dir.xyz)) : 0;\n", index, index);
WRITE(p, "ldir = half3(1,attn,attn*attn);\n");
WRITE(p, "attn = max(0.0f, dot("I_LIGHTS".lights[%d].cosatt.xyz, ldir)) / dot("I_LIGHTS".lights[%d].distatt.xyz, ldir);\n", index, index);
}
switch (chan.diffusefunc) {
case LIGHTDIF_NONE:
WRITE(p, "%s.%s += attn * "I_LIGHTS".lights[%d].col.%s;\n", dest, swizzle, index, swizzle);
break;
case LIGHTDIF_SIGN:
case LIGHTDIF_CLAMP:
WRITE(p, "%s.%s += attn * %sdot(ldir, norm0)) * "I_LIGHTS".lights[%d].col.%s;\n",
dest, swizzle, chan.diffusefunc != LIGHTDIF_SIGN ? "max(0.0f," :"(", index, swizzle);
break;
default: _assert_(0);
}
}
WRITE(p, "\n");
return p;
}
// 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/
#include <math.h>
#include "Profiler.h"
#include "NativeVertexFormat.h"
#include "BPMemory.h"
#include "VertexShader.h"
static char text[16384];
#define WRITE p+=sprintf
#define LIGHTS_POS ""
char *GenerateLightShader(char* p, int index, const LitChannel& chan, const char* dest, int coloralpha);
char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
{
text[sizeof(text) - 1] = 0x7C; // canary
DVSTARTPROFILE();
_assert_( bpmem.genMode.numtexgens == xfregs.numTexGens);
_assert_( bpmem.genMode.numcolchans == xfregs.nNumChans);
u32 lightMask = 0;
if (xfregs.nNumChans > 0)
lightMask |= xfregs.colChans[0].color.GetFullLightMask() | xfregs.colChans[0].alpha.GetFullLightMask();
if (xfregs.nNumChans > 1)
lightMask |= xfregs.colChans[1].color.GetFullLightMask() | xfregs.colChans[1].alpha.GetFullLightMask();
bool bOutputZ = bpmem.ztex2.op==ZTEXTURE_ADD || has_zbuffer_target;
int ztexcoord = -1;
char *p = text;
WRITE(p, "//Vertex Shader: comp:%x, \n", components);
WRITE(p, "typedef struct {\n"
" float4 T0, T1, T2;\n"
" float4 N0, N1, N2;\n"
"} s_"I_POSNORMALMATRIX";\n\n"
"typedef struct {\n"
" float4 t;\n"
"} FLT4;\n"
"typedef struct {\n"
" FLT4 T[24];\n"
"} s_"I_TEXMATRICES";\n\n"
"typedef struct {\n"
" FLT4 T[64];\n"
"} s_"I_TRANSFORMMATRICES";\n\n"
"typedef struct {\n"
" FLT4 T[32];\n"
"} s_"I_NORMALMATRICES";\n\n"
"typedef struct {\n"
" FLT4 T[64];\n"
"} s_"I_POSTTRANSFORMMATRICES";\n\n"
"typedef struct {\n"
" float4 col;\n"
" float4 cosatt;\n"
" float4 distatt;\n"
" float4 pos;\n"
" float4 dir;\n"
"} Light;\n\n"
"typedef struct {\n"
" Light lights[8];\n"
"} s_"I_LIGHTS";\n\n"
"typedef struct {\n"
" float4 C0, C1, C2, C3;\n"
"} s_"I_MATERIALS";\n\n"
"typedef struct {\n"
" float4 T0,T1,T2,T3;\n"
"} s_"I_PROJECTION";\n"
"typedef struct {\n"
" float4 params;\n" // a, b, c, b_shift
"} s_"I_FOGPARAMS";\n\n");
WRITE(p, "struct VS_OUTPUT {\n");
WRITE(p, " float4 pos : POSITION;\n");
WRITE(p, " float4 colors[2] : COLOR0;\n");
// if outputting Z, embed the Z coordinate in the w component of a texture coordinate
// if number of tex gens occupies all the texture coordinates, use the last tex coord
// otherwise use the next available tex coord
for (int i = 0; i < xfregs.numTexGens; ++i) {
WRITE(p, " float%d tex%d : TEXCOORD%d;\n", (i==(xfregs.numTexGens-1)&&bOutputZ)?4:3, i, i);
}
if (bOutputZ && xfregs.numTexGens == 0) {
ztexcoord = 0;
WRITE(p, " float4 tex%d : TEXCOORD%d;\n", ztexcoord, ztexcoord);
}
else if (bOutputZ)
ztexcoord = xfregs.numTexGens - 1;
WRITE(p, "};\n");
WRITE(p, "\n");
// uniforms
// bool bTexMtx = ((components & VB_HAS_TEXMTXIDXALL)<<VB_HAS_UVTEXMTXSHIFT)!=0; unused TODO: keep?
WRITE(p, "uniform s_"I_TRANSFORMMATRICES" "I_TRANSFORMMATRICES" : register(c%d);\n", C_TRANSFORMMATRICES);
WRITE(p, "uniform s_"I_TEXMATRICES" "I_TEXMATRICES" : register(c%d);\n", C_TEXMATRICES); // also using tex matrices
WRITE(p, "uniform s_"I_NORMALMATRICES" "I_NORMALMATRICES" : register(c%d);\n", C_NORMALMATRICES);
WRITE(p, "uniform s_"I_POSNORMALMATRIX" "I_POSNORMALMATRIX" : register(c%d);\n", C_POSNORMALMATRIX);
WRITE(p, "uniform s_"I_POSTTRANSFORMMATRICES" "I_POSTTRANSFORMMATRICES" : register(c%d);\n", C_POSTTRANSFORMMATRICES);
WRITE(p, "uniform s_"I_LIGHTS" "I_LIGHTS" : register(c%d);\n", C_LIGHTS);
WRITE(p, "uniform s_"I_MATERIALS" "I_MATERIALS" : register(c%d);\n", C_MATERIALS);
WRITE(p, "uniform s_"I_PROJECTION" "I_PROJECTION" : register(c%d);\n", C_PROJECTION);
WRITE(p, "uniform s_"I_FOGPARAMS" "I_FOGPARAMS" : register(c%d);\n", C_FOGPARAMS);
WRITE(p, "VS_OUTPUT main(\n");
// inputs
if (components & VB_HAS_NRM0)
WRITE(p, " float3 rawnorm0 : NORMAL,\n");
if (components & VB_HAS_NRM1)
WRITE(p, " float3 rawnorm1 : ATTR%d,\n", SHADER_NORM1_ATTRIB);
if (components & VB_HAS_NRM2)
WRITE(p, " float3 rawnorm2 : ATTR%d,\n", SHADER_NORM2_ATTRIB);
if (components & VB_HAS_COL0)
WRITE(p, " float4 color0 : COLOR0,\n");
if (components & VB_HAS_COL1)
WRITE(p, " float4 color1 : COLOR1,\n");
for (int i = 0; i < 8; ++i) {
u32 hastexmtx = (components & (VB_HAS_TEXMTXIDX0<<i));
if ((components & (VB_HAS_UV0<<i)) || hastexmtx )
WRITE(p, " float%d tex%d : TEXCOORD%d,\n", hastexmtx ? 3 : 2, i,i);
}
if (components & VB_HAS_POSMTXIDX)
WRITE(p, " half posmtx : ATTR%d,\n", SHADER_POSMTX_ATTRIB);
WRITE(p, " float4 rawpos : POSITION) {\n");
WRITE(p, "VS_OUTPUT o;\n");
// transforms
if (components & VB_HAS_POSMTXIDX) {
WRITE(p, "float4 pos = float4(dot("I_TRANSFORMMATRICES".T[posmtx].t, rawpos), dot("I_TRANSFORMMATRICES".T[posmtx+1].t, rawpos), dot("I_TRANSFORMMATRICES".T[posmtx+2].t, rawpos),1);\n");
if (components & VB_HAS_NRMALL) {
WRITE(p, "int normidx = posmtx >= 32 ? (posmtx-32) : posmtx;\n");
WRITE(p, "float3 N0 = "I_NORMALMATRICES".T[normidx].t.xyz, N1 = "I_NORMALMATRICES".T[normidx+1].t.xyz, N2 = "I_NORMALMATRICES".T[normidx+2].t.xyz;\n");
}
if (components & VB_HAS_NRM0)
WRITE(p, "half3 _norm0 = half3(dot(N0, rawnorm0), dot(N1, rawnorm0), dot(N2, rawnorm0));\n"
"half3 norm0 = normalize(_norm0);\n");
if (components & VB_HAS_NRM1)
WRITE(p, "half3 _norm1 = half3(dot(N0, rawnorm1), dot(N1, rawnorm1), dot(N2, rawnorm1));\n");
//"half3 norm1 = normalize(_norm1);\n");
if (components & VB_HAS_NRM2)
WRITE(p, "half3 _norm2 = half3(dot(N0, rawnorm2), dot(N1, rawnorm2), dot(N2, rawnorm2));\n");
//"half3 norm2 = normalize(_norm2);\n");
}
else {
WRITE(p, "float4 pos = float4(dot("I_POSNORMALMATRIX".T0, rawpos), dot("I_POSNORMALMATRIX".T1, rawpos), dot("I_POSNORMALMATRIX".T2, rawpos), 1);\n");
if (components & VB_HAS_NRM0)
WRITE(p, "half3 _norm0 = half3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm0), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm0), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm0));\n"
"half3 norm0 = normalize(_norm0);\n");
if (components & VB_HAS_NRM1)
WRITE(p, "half3 _norm1 = half3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm1), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm1), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm1));\n");
//"half3 norm1 = normalize(_norm1);\n");
if (components & VB_HAS_NRM2)
WRITE(p, "half3 _norm2 = half3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm2), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm2), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm2));\n");
//"half3 norm2 = normalize(_norm2);\n");
}
if (!(components & VB_HAS_NRM0))
WRITE(p, "half3 _norm0 = half3(0,0,0), norm0= half3(0,0,0);\n");
WRITE(p, "o.pos = float4(dot("I_PROJECTION".T0, pos), dot("I_PROJECTION".T1, pos), dot("I_PROJECTION".T2, pos), dot("I_PROJECTION".T3, pos));\n");
WRITE(p, "half4 mat, lacc;\n"
"half3 ldir, h;\n"
"half dist, dist2, attn;\n");
// lights/colors
for (int j = 0; j < xfregs.nNumChans; j++) {
// bool bColorAlphaSame = xfregs.colChans[j].color.hex == xfregs.colChans[j].alpha.hex; unused
const LitChannel& color = xfregs.colChans[j].color;
const LitChannel& alpha = xfregs.colChans[j].alpha;
WRITE(p, "{\n");
if (color.matsource) {// from vertex
if (components & (VB_HAS_COL0<<j) )
WRITE(p, "mat = color%d;\n", j);
else WRITE(p, "mat = half4(1,1,1,1);\n");
}
else // from color
WRITE(p, "mat = "I_MATERIALS".C%d;\n", j+2);
if (color.enablelighting) {
if (color.ambsource) {// from vertex
if (components & (VB_HAS_COL0<<j) )
WRITE(p, "lacc = color%d;\n", j);
else WRITE(p, "lacc = half4(0.0f,0.0f,0.0f,0.0f);\n");
}
else // from color
WRITE(p, "lacc = "I_MATERIALS".C%d;\n", j);
}
// check if alpha is different
if (alpha.matsource != color.matsource) {
if (alpha.matsource) {// from vertex
if (components & (VB_HAS_COL0<<j) )
WRITE(p, "mat.w = color%d.w;\n", j);
else WRITE(p, "mat.w = 1;\n");
}
else // from color
WRITE(p, "mat.w = "I_MATERIALS".C%d.w;\n", j+2);
}
if (alpha.enablelighting && alpha.ambsource != color.ambsource) {
if (alpha.ambsource) {// from vertex
if (components & (VB_HAS_COL0<<j) )
WRITE(p, "lacc.w = color%d.w;\n", j);
else WRITE(p, "lacc.w = 0;\n");
}
else // from color
WRITE(p, "lacc.w = "I_MATERIALS".C%d.w;\n", j);
}
if (color.enablelighting && alpha.enablelighting && (color.GetFullLightMask() != alpha.GetFullLightMask() || color.lightparams != alpha.lightparams)) {
// both have lighting, except not using the same lights
int mask = 0; // holds already computed lights
if (color.lightparams == alpha.lightparams && (color.GetFullLightMask() & alpha.GetFullLightMask())) {
// if lights are shared, compute those first
mask = color.GetFullLightMask() & alpha.GetFullLightMask();
for (int i = 0; i < 8; ++i) {
if (mask&(1<<i))
p = GenerateLightShader(p, i, color, "lacc", 3);
}
}
// no shared lights
for (int i = 0; i < 8; ++i) {
if (!(mask&(1<<i)) && (color.GetFullLightMask() & (1<<i)) )
p = GenerateLightShader(p, i, color, "lacc", 1);
if (!(mask&(1<<i)) && (alpha.GetFullLightMask() & (1<<i)) )
p = GenerateLightShader(p, i, alpha, "lacc", 2);
}
}
else if (color.enablelighting || alpha.enablelighting) {
// either one is enabled
int coloralpha = (int)color.enablelighting|((int)alpha.enablelighting<<1);
for (int i = 0; i < 8; ++i) {
if (color.GetFullLightMask() & (1<<i) )
p = GenerateLightShader(p, i, color.enablelighting?color:alpha, "lacc", coloralpha);
}
}
if (color.enablelighting != alpha.enablelighting) {
if (color.enablelighting )
WRITE(p, "o.colors[%d].xyz = mat.xyz * clamp(lacc.xyz,float3(0.0f,0.0f,0.0f),float3(1.0f,1.0f,1.0f));\n"
"o.colors[%d].w = mat.w;\n", j, j);
else
WRITE(p, "o.colors[%d].xyz = mat.xyz;\n"
"o.colors[%d].w = mat.w * clamp(lacc.w,0.0f,1.0f);\n", j, j);
}
else {
if (alpha.enablelighting )
WRITE(p, "o.colors[%d] = mat * clamp(lacc,float4(0.0f,0.0f,0.0f,0.0f), float4(1.0f,1.0f,1.0f,1.0f));\n", j);
else WRITE(p, "o.colors[%d] = mat;\n", j);
}
WRITE(p, "}\n");
}
// zero left over channels
for (int i = xfregs.nNumChans; i < 2; ++i)
WRITE(p, "o.colors[%d] = 0;\n", i);
// transform texcoords
for (int i = 0; i < xfregs.numTexGens; ++i) {
TexMtxInfo& texinfo = xfregs.texcoords[i].texmtxinfo;
WRITE(p, "{\n");
switch (texinfo.sourcerow) {
case XF_SRCGEOM_INROW:
_assert_( texinfo.inputform == XF_TEXINPUT_ABC1 );
WRITE(p, "float4 coord = rawpos;\n"); // pos.w is 1
break;
case XF_SRCNORMAL_INROW:
if (components & VB_HAS_NRM0) {
_assert_( texinfo.inputform == XF_TEXINPUT_ABC1 );
WRITE(p, "float4 coord = float4(rawnorm0.xyz, 1.0);\n");
}
else WRITE(p, "float4 coord = 0;\n");
break;
case XF_SRCCOLORS_INROW:
_assert_( texinfo.texgentype == XF_TEXGEN_COLOR_STRGBC0 || texinfo.texgentype == XF_TEXGEN_COLOR_STRGBC1 );
break;
case XF_SRCBINORMAL_T_INROW:
if (components & VB_HAS_NRM1) {
_assert_( texinfo.inputform == XF_TEXINPUT_ABC1 );
WRITE(p, "float4 coord = float4(rawnorm1.xyz, 1.0);\n");
}
else WRITE(p, "float4 coord = 0;\n");
break;
case XF_SRCBINORMAL_B_INROW:
if (components & VB_HAS_NRM2) {
_assert_( texinfo.inputform == XF_TEXINPUT_ABC1 );
WRITE(p, "float4 coord = float4(rawnorm2.xyz, 1.0);\n");
}
else WRITE(p, "float4 coord = 0;\n");
break;
default:
_assert_(texinfo.sourcerow <= XF_SRCTEX7_INROW);
if (components & (VB_HAS_UV0<<(texinfo.sourcerow - XF_SRCTEX0_INROW)) )
WRITE(p, "float4 coord = float4(tex%d.x, tex%d.y, 1.0f, 1.0f);\n", texinfo.sourcerow - XF_SRCTEX0_INROW, texinfo.sourcerow - XF_SRCTEX0_INROW);
else
WRITE(p, "float4 coord = float4(0.0f, 0.0f, 1.0f, 1.0f);\n");
break;
}
// firs transformation
switch (texinfo.texgentype) {
case XF_TEXGEN_REGULAR:
if (components & (VB_HAS_TEXMTXIDX0<<i)) {
if (texinfo.projection == XF_TEXPROJ_STQ )
WRITE(p, "o.tex%d.xyz = float3(dot(coord, "I_TRANSFORMMATRICES".T[tex%d.z].t), dot(coord, "I_TRANSFORMMATRICES".T[tex%d.z+1].t), dot(coord, "I_TRANSFORMMATRICES".T[tex%d.z+2].t));\n", i, i, i, i);
else {
WRITE(p, "o.tex%d.xyz = float3(dot(coord, "I_TRANSFORMMATRICES".T[tex%d.z].t), dot(coord, "I_TRANSFORMMATRICES".T[tex%d.z+1].t), 1);\n", i, i, i);
}
}
else {
if (texinfo.projection == XF_TEXPROJ_STQ )
WRITE(p, "o.tex%d.xyz = float3(dot(coord, "I_TEXMATRICES".T[%d].t), dot(coord, "I_TEXMATRICES".T[%d].t), dot(coord, "I_TEXMATRICES".T[%d].t));\n", i, 3*i, 3*i+1, 3*i+2);
else
WRITE(p, "o.tex%d.xyz = float3(dot(coord, "I_TEXMATRICES".T[%d].t), dot(coord, "I_TEXMATRICES".T[%d].t), 1);\n", i, 3*i, 3*i+1);
}
break;
case XF_TEXGEN_EMBOSS_MAP: // calculate tex coords into bump map
if (components & (VB_HAS_NRM1|VB_HAS_NRM2)) {
// transform the light dir into tangent space
WRITE(p, "ldir = normalize("I_LIGHTS".lights[%d].pos.xyz - pos.xyz);\n", texinfo.embosslightshift);
WRITE(p, "o.tex%d.xyz = o.tex%d.xyz + float3(dot(ldir, _norm1), dot(ldir, _norm2), 0.0f);\n", i, texinfo.embosssourceshift);
}
else _assert_(0); // should have normals
break;
case XF_TEXGEN_COLOR_STRGBC0:
_assert_(texinfo.sourcerow == XF_SRCCOLORS_INROW);
WRITE(p, "o.tex%d.xyz = float3(o.colors[0].x, o.colors[0].y, 1);\n", i);
break;
case XF_TEXGEN_COLOR_STRGBC1:
_assert_(texinfo.sourcerow == XF_SRCCOLORS_INROW);
WRITE(p, "o.tex%d.xyz = float3(o.colors[1].x, o.colors[1].y, 1);\n", i);
break;
}
if(xfregs.bEnableDualTexTransform && texinfo.texgentype == XF_TEXGEN_REGULAR) { // only works for regular tex gen types?
if (xfregs.texcoords[i].postmtxinfo.normalize)
WRITE(p, "o.tex%d.xyz = normalize(o.tex%d.xyz);\n", i, i);
//multiply by postmatrix
int postidx = xfregs.texcoords[i].postmtxinfo.index;
WRITE(p, "float4 P0 = "I_POSTTRANSFORMMATRICES".T[%d].t;\n"
"float4 P1 = "I_POSTTRANSFORMMATRICES".T[%d].t;\n"
"float4 P2 = "I_POSTTRANSFORMMATRICES".T[%d].t;\n",
postidx&0x3f, (postidx+1)&0x3f, (postidx+2)&0x3f);
WRITE(p, "o.tex%d.xyz = float3(dot(P0.xyz, o.tex%d.xyz) + P0.w, dot(P1.xyz, o.tex%d.xyz) + P1.w, dot(P2.xyz, o.tex%d.xyz) + P2.w);\n", i, i, i, i);
}
WRITE(p, "}\n");
}
if (ztexcoord >= 0 )
WRITE(p, "o.tex%d.w = o.pos.z/o.pos.w;\n", ztexcoord);
// if (bpmem.fog.c_proj_fsel.fsel != 0) {
// switch (bpmem.fog.c_proj_fsel.fsel) {
// case 1: // linear
// break;
// case 4: // exp
// break;
// case 5: // exp2
// break;
// case 6: // backward exp
// break;
// case 7: // backward exp2
// break;
// }
//
// WRITE(p, "o.fog = o.pos.z/o.pos.w;\n");
// }
WRITE(p, "return o;\n}\n");
if (text[sizeof(text) - 1] != 0x7C)
PanicAlert("VertexShader generator - buffer too small, canary has been eaten!");
return text;
}
// coloralpha - 1 if color, 2 if alpha
char* GenerateLightShader(char* p, int index, const LitChannel& chan, const char* dest, int coloralpha)
{
const char* swizzle = "xyzw";
if (coloralpha == 1 ) swizzle = "xyz";
else if (coloralpha == 2 ) swizzle = "w";
if (!(chan.attnfunc & 1)) {
// atten disabled
switch (chan.diffusefunc) {
case LIGHTDIF_NONE:
WRITE(p, "%s.%s += "I_LIGHTS".lights[%d].col.%s;\n", dest, swizzle, index, swizzle);
break;
case LIGHTDIF_SIGN:
case LIGHTDIF_CLAMP:
WRITE(p, "ldir = normalize("I_LIGHTS".lights[%d].pos.xyz - pos.xyz);\n", index);
WRITE(p, "%s.%s += %sdot(ldir, norm0)) * "I_LIGHTS".lights[%d].col.%s;\n",
dest, swizzle, chan.diffusefunc != LIGHTDIF_SIGN ? "max(0.0f," :"(", index, swizzle);
break;
default: _assert_(0);
}
}
else { // spec and spot
WRITE(p, "ldir = "I_LIGHTS".lights[%d].pos.xyz - pos.xyz;\n", index);
if (chan.attnfunc == 3) { // spot
WRITE(p, "dist2 = dot(ldir, ldir);\n"
"dist = sqrt(dist2);\n"
"ldir = ldir / dist;\n"
"attn = max(0.0f, dot(ldir, "I_LIGHTS".lights[%d].dir.xyz));\n",index);
WRITE(p, "attn = max(0.0f, dot("I_LIGHTS".lights[%d].cosatt.xyz, half3(1, attn, attn*attn))) / dot("I_LIGHTS".lights[%d].distatt.xyz, half3(1,dist,dist2));\n", index, index);
}
else if (chan.attnfunc == 1) { // specular
WRITE(p, "attn = dot(norm0, "I_LIGHTS".lights[%d].pos.xyz) > 0 ? max(0.0f, dot(norm0, "I_LIGHTS".lights[%d].dir.xyz)) : 0;\n", index, index);
WRITE(p, "ldir = half3(1,attn,attn*attn);\n");
WRITE(p, "attn = max(0.0f, dot("I_LIGHTS".lights[%d].cosatt.xyz, ldir)) / dot("I_LIGHTS".lights[%d].distatt.xyz, ldir);\n", index, index);
}
switch (chan.diffusefunc) {
case LIGHTDIF_NONE:
WRITE(p, "%s.%s += attn * "I_LIGHTS".lights[%d].col.%s;\n", dest, swizzle, index, swizzle);
break;
case LIGHTDIF_SIGN:
case LIGHTDIF_CLAMP:
WRITE(p, "%s.%s += attn * %sdot(ldir, norm0)) * "I_LIGHTS".lights[%d].col.%s;\n",
dest, swizzle, chan.diffusefunc != LIGHTDIF_SIGN ? "max(0.0f," :"(", index, swizzle);
break;
default: _assert_(0);
}
}
WRITE(p, "\n");
return p;
}

View File

@ -1,51 +1,51 @@
// 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/
#include "VideoState.h"
#include "BPMemory.h"
#include "CPMemory.h"
#include "XFMemory.h"
#include "TextureDecoder.h"
#include "Fifo.h"
static void DoState(PointerWrap &p)
{
// BP Memory
p.Do(bpmem);
// CP Memory
p.DoArray(arraybases, 16);
p.DoArray(arraystrides, 16);
p.Do(MatrixIndexA);
p.Do(MatrixIndexB);
p.Do(g_VtxDesc.Hex);
p.DoArray(g_VtxAttr, 8);
// XF Memory
p.Do(xfregs);
p.DoArray(xfmem, XFMEM_SIZE);
// Texture decoder
p.DoArray(texMem, TMEM_SIZE);
// FIFO
Fifo_DoState(p);
}
void VideoCommon_DoState(PointerWrap &p) {
DoState(p);
//TODO: search for more data that should be saved and add it here
}
// 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/
#include "VideoState.h"
#include "BPMemory.h"
#include "CPMemory.h"
#include "XFMemory.h"
#include "TextureDecoder.h"
#include "Fifo.h"
static void DoState(PointerWrap &p)
{
// BP Memory
p.Do(bpmem);
// CP Memory
p.DoArray(arraybases, 16);
p.DoArray(arraystrides, 16);
p.Do(MatrixIndexA);
p.Do(MatrixIndexB);
p.Do(g_VtxDesc.Hex);
p.DoArray(g_VtxAttr, 8);
// XF Memory
p.Do(xfregs);
p.DoArray(xfmem, XFMEM_SIZE);
// Texture decoder
p.DoArray(texMem, TMEM_SIZE);
// FIFO
Fifo_DoState(p);
}
void VideoCommon_DoState(PointerWrap &p) {
DoState(p);
//TODO: search for more data that should be saved and add it here
}

View File

@ -1,131 +1,131 @@
// 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/
#if _WIN32
#include <intrin.h>
#endif
#include <xmmintrin.h>
#include "XFBConvert.h"
#include "Common.h"
namespace {
const __m128i _bias1 = _mm_set_epi32(128/2 << 16, 0, 128/2 << 16, 16 << 16);
const __m128i _bias2 = _mm_set_epi32(128/2 << 16, 16 << 16, 128/2 << 16, 0);
__m128i _y[256];
__m128i _u[256];
__m128i _v[256];
__m128i _r1[256];
__m128i _r2[256];
__m128i _g1[256];
__m128i _g2[256];
__m128i _b1[256];
__m128i _b2[256];
} // namespace
void InitXFBConvTables()
{
for (int i = 0; i < 256; i++)
{
_y[i] = _mm_set_epi32(0xFFFFFFF, 76283*(i - 16), 76283*(i - 16), 76283*(i - 16));
_u[i] = _mm_set_epi32( 0, 0, -25624 * (i - 128), 132252 * (i - 128));
_v[i] = _mm_set_epi32( 0, 104595 * (i - 128), -53281 * (i - 128), 0);
_r1[i] = _mm_add_epi32(_mm_set_epi32( 28770 * i / 2, 0, -9699 * i / 2, 16843 * i),
_bias1);
_g1[i] = _mm_set_epi32(-24117 * i / 2, 0, -19071 * i / 2, 33030 * i);
_b1[i] = _mm_set_epi32( -4653 * i / 2, 0, 28770 * i / 2, 6423 * i);
_r2[i] = _mm_add_epi32(_mm_set_epi32( 28770 * i / 2, 16843 * i, -9699 * i / 2, 0),
_bias2);
_g2[i] = _mm_set_epi32(-24117 * i / 2, 33030 * i, -19071 * i / 2, 0);
_b2[i] = _mm_set_epi32( -4653 * i / 2, 6423 * i, 28770 * i / 2, 0);
}
}
void ConvertFromXFB(u32 *dst, const u8* _pXFB, int width, int height)
{
if (((size_t)dst & 0xF) != 0) {
PanicAlert("ConvertFromXFB - unaligned destination");
}
const unsigned char *src = _pXFB;
u32 numBlocks = ((width * height) / 2) / 2;
for (u32 i = 0; i < numBlocks; i++)
{
__m128i y1 = _y[src[0]];
__m128i u = _u[src[1]];
__m128i y2 = _y[src[2]];
__m128i v = _v[src[3]];
__m128i y1_2 = _y[src[4+0]];
__m128i u_2 = _u[src[4+1]];
__m128i y2_2 = _y[src[4+2]];
__m128i v_2 = _v[src[4+3]];
__m128i c1 = _mm_srai_epi32(_mm_add_epi32(y1, _mm_add_epi32(u, v)), 16);
__m128i c2 = _mm_srai_epi32(_mm_add_epi32(y2, _mm_add_epi32(u, v)), 16);
__m128i c3 = _mm_srai_epi32(_mm_add_epi32(y1_2, _mm_add_epi32(u_2, v_2)), 16);
__m128i c4 = _mm_srai_epi32(_mm_add_epi32(y2_2, _mm_add_epi32(u_2, v_2)), 16);
__m128i four_dest = _mm_packus_epi16(_mm_packs_epi32(c1, c2), _mm_packs_epi32(c3, c4));
_mm_store_si128((__m128i *)dst, four_dest);
dst += 4;
src += 8;
}
}
void ConvertToXFB(u32 *dst, const u8* _pEFB, int width, int height)
{
const unsigned char *src = _pEFB;
u32 numBlocks = ((width * height) / 2) / 4;
if (((size_t)dst & 0xF) != 0) {
PanicAlert("ConvertToXFB - unaligned XFB");
}
for (u32 i = 0; i < numBlocks; i++)
{
__m128i yuyv0 = _mm_srai_epi32(
_mm_add_epi32(
_mm_add_epi32(_r1[src[0]], _mm_add_epi32(_g1[src[1]], _b1[src[2]])),
_mm_add_epi32(_r2[src[4]], _mm_add_epi32(_g2[src[5]], _b2[src[6]]))), 16);
src += 8;
__m128i yuyv1 = _mm_srai_epi32(
_mm_add_epi32(
_mm_add_epi32(_r1[src[0]], _mm_add_epi32(_g1[src[1]], _b1[src[2]])),
_mm_add_epi32(_r2[src[4]], _mm_add_epi32(_g2[src[5]], _b2[src[6]]))), 16);
src += 8;
__m128i yuyv2 = _mm_srai_epi32(
_mm_add_epi32(
_mm_add_epi32(_r1[src[0]], _mm_add_epi32(_g1[src[1]], _b1[src[2]])),
_mm_add_epi32(_r2[src[4]], _mm_add_epi32(_g2[src[5]], _b2[src[6]]))), 16);
src += 8;
__m128i yuyv3 = _mm_srai_epi32(
_mm_add_epi32(
_mm_add_epi32(_r1[src[0]], _mm_add_epi32(_g1[src[1]], _b1[src[2]])),
_mm_add_epi32(_r2[src[4]], _mm_add_epi32(_g2[src[5]], _b2[src[6]]))), 16);
src += 8;
__m128i four_dest = _mm_packus_epi16(_mm_packs_epi32(yuyv0, yuyv1), _mm_packs_epi32(yuyv2, yuyv3));
_mm_store_si128((__m128i *)dst, four_dest);
dst += 4;
}
}
// 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/
#if _WIN32
#include <intrin.h>
#endif
#include <xmmintrin.h>
#include "XFBConvert.h"
#include "Common.h"
namespace {
const __m128i _bias1 = _mm_set_epi32(128/2 << 16, 0, 128/2 << 16, 16 << 16);
const __m128i _bias2 = _mm_set_epi32(128/2 << 16, 16 << 16, 128/2 << 16, 0);
__m128i _y[256];
__m128i _u[256];
__m128i _v[256];
__m128i _r1[256];
__m128i _r2[256];
__m128i _g1[256];
__m128i _g2[256];
__m128i _b1[256];
__m128i _b2[256];
} // namespace
void InitXFBConvTables()
{
for (int i = 0; i < 256; i++)
{
_y[i] = _mm_set_epi32(0xFFFFFFF, 76283*(i - 16), 76283*(i - 16), 76283*(i - 16));
_u[i] = _mm_set_epi32( 0, 0, -25624 * (i - 128), 132252 * (i - 128));
_v[i] = _mm_set_epi32( 0, 104595 * (i - 128), -53281 * (i - 128), 0);
_r1[i] = _mm_add_epi32(_mm_set_epi32( 28770 * i / 2, 0, -9699 * i / 2, 16843 * i),
_bias1);
_g1[i] = _mm_set_epi32(-24117 * i / 2, 0, -19071 * i / 2, 33030 * i);
_b1[i] = _mm_set_epi32( -4653 * i / 2, 0, 28770 * i / 2, 6423 * i);
_r2[i] = _mm_add_epi32(_mm_set_epi32( 28770 * i / 2, 16843 * i, -9699 * i / 2, 0),
_bias2);
_g2[i] = _mm_set_epi32(-24117 * i / 2, 33030 * i, -19071 * i / 2, 0);
_b2[i] = _mm_set_epi32( -4653 * i / 2, 6423 * i, 28770 * i / 2, 0);
}
}
void ConvertFromXFB(u32 *dst, const u8* _pXFB, int width, int height)
{
if (((size_t)dst & 0xF) != 0) {
PanicAlert("ConvertFromXFB - unaligned destination");
}
const unsigned char *src = _pXFB;
u32 numBlocks = ((width * height) / 2) / 2;
for (u32 i = 0; i < numBlocks; i++)
{
__m128i y1 = _y[src[0]];
__m128i u = _u[src[1]];
__m128i y2 = _y[src[2]];
__m128i v = _v[src[3]];
__m128i y1_2 = _y[src[4+0]];
__m128i u_2 = _u[src[4+1]];
__m128i y2_2 = _y[src[4+2]];
__m128i v_2 = _v[src[4+3]];
__m128i c1 = _mm_srai_epi32(_mm_add_epi32(y1, _mm_add_epi32(u, v)), 16);
__m128i c2 = _mm_srai_epi32(_mm_add_epi32(y2, _mm_add_epi32(u, v)), 16);
__m128i c3 = _mm_srai_epi32(_mm_add_epi32(y1_2, _mm_add_epi32(u_2, v_2)), 16);
__m128i c4 = _mm_srai_epi32(_mm_add_epi32(y2_2, _mm_add_epi32(u_2, v_2)), 16);
__m128i four_dest = _mm_packus_epi16(_mm_packs_epi32(c1, c2), _mm_packs_epi32(c3, c4));
_mm_store_si128((__m128i *)dst, four_dest);
dst += 4;
src += 8;
}
}
void ConvertToXFB(u32 *dst, const u8* _pEFB, int width, int height)
{
const unsigned char *src = _pEFB;
u32 numBlocks = ((width * height) / 2) / 4;
if (((size_t)dst & 0xF) != 0) {
PanicAlert("ConvertToXFB - unaligned XFB");
}
for (u32 i = 0; i < numBlocks; i++)
{
__m128i yuyv0 = _mm_srai_epi32(
_mm_add_epi32(
_mm_add_epi32(_r1[src[0]], _mm_add_epi32(_g1[src[1]], _b1[src[2]])),
_mm_add_epi32(_r2[src[4]], _mm_add_epi32(_g2[src[5]], _b2[src[6]]))), 16);
src += 8;
__m128i yuyv1 = _mm_srai_epi32(
_mm_add_epi32(
_mm_add_epi32(_r1[src[0]], _mm_add_epi32(_g1[src[1]], _b1[src[2]])),
_mm_add_epi32(_r2[src[4]], _mm_add_epi32(_g2[src[5]], _b2[src[6]]))), 16);
src += 8;
__m128i yuyv2 = _mm_srai_epi32(
_mm_add_epi32(
_mm_add_epi32(_r1[src[0]], _mm_add_epi32(_g1[src[1]], _b1[src[2]])),
_mm_add_epi32(_r2[src[4]], _mm_add_epi32(_g2[src[5]], _b2[src[6]]))), 16);
src += 8;
__m128i yuyv3 = _mm_srai_epi32(
_mm_add_epi32(
_mm_add_epi32(_r1[src[0]], _mm_add_epi32(_g1[src[1]], _b1[src[2]])),
_mm_add_epi32(_r2[src[4]], _mm_add_epi32(_g2[src[5]], _b2[src[6]]))), 16);
src += 8;
__m128i four_dest = _mm_packus_epi16(_mm_packs_epi32(yuyv0, yuyv1), _mm_packs_epi32(yuyv2, yuyv3));
_mm_store_si128((__m128i *)dst, four_dest);
dst += 4;
}
}

View File

@ -1,22 +1,22 @@
// 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/
#include "XFMemory.h"
// STATE_TO_SAVE
XFRegisters xfregs;
u32 xfmem[XFMEM_SIZE];
// 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/
#include "XFMemory.h"
// STATE_TO_SAVE
XFRegisters xfregs;
u32 xfmem[XFMEM_SIZE];