mirror of https://github.com/PCSX2/pcsx2.git
Implemented virtual alloc functions and changed the event class to use semaphores.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@4318 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
parent
2ac76bbdad
commit
5860de1cce
|
@ -26,7 +26,11 @@
|
|||
const GSVector4i GPULocalMemory::m_xxxa(0x00008000);
|
||||
const GSVector4i GPULocalMemory::m_xxbx(0x00007c00);
|
||||
const GSVector4i GPULocalMemory::m_xgxx(0x000003e0);
|
||||
const GSVector4i GPULocalMemory::m_rxxx(0x0000001f);
|
||||
const GSVector4i GPULocalMemory::m_rxxx(0x0000001f);
|
||||
|
||||
#define VM_SIZE ((1 << (12 + 11)) * sizeof(uint16))
|
||||
#define VM_ALLOC_SIZE (VM_SIZE * 2)
|
||||
#define TEX_ALLOC_SIZE (256 * 256 * (1 + 1 + 4) * 32)
|
||||
|
||||
GPULocalMemory::GPULocalMemory()
|
||||
{
|
||||
|
@ -35,9 +39,9 @@ GPULocalMemory::GPULocalMemory()
|
|||
|
||||
//
|
||||
|
||||
int size = (1 << (12 + 11)) * sizeof(uint16);
|
||||
int size = VM_SIZE;
|
||||
|
||||
m_vm = (uint16*)vmalloc(size * 2, false);
|
||||
m_vm = (uint16*)vmalloc(VM_ALLOC_SIZE, false);
|
||||
|
||||
memset(m_vm, 0, size);
|
||||
|
||||
|
@ -48,7 +52,7 @@ GPULocalMemory::GPULocalMemory()
|
|||
|
||||
//
|
||||
|
||||
size = 256 * 256 * (1 + 1 + 4) * 32;
|
||||
size = TEX_ALLOC_SIZE;
|
||||
|
||||
m_texture.buff[0] = (uint8*)vmalloc(size, false);
|
||||
m_texture.buff[1] = m_texture.buff[0] + 256 * 256 * 32;
|
||||
|
@ -78,9 +82,9 @@ GPULocalMemory::GPULocalMemory()
|
|||
|
||||
GPULocalMemory::~GPULocalMemory()
|
||||
{
|
||||
vmfree(m_vm);
|
||||
vmfree(m_vm, VM_ALLOC_SIZE);
|
||||
|
||||
vmfree(m_texture.buff[0]);
|
||||
vmfree(m_texture.buff[0], TEX_ALLOC_SIZE);
|
||||
}
|
||||
|
||||
const uint16* GPULocalMemory::GetCLUT(int tp, int cx, int cy)
|
||||
|
|
|
@ -23,10 +23,12 @@
|
|||
#include "GSClut.h"
|
||||
#include "GSLocalMemory.h"
|
||||
|
||||
#define CLUT_ALLOC_SIZE (2 * 4096)
|
||||
|
||||
GSClut::GSClut(GSLocalMemory* mem)
|
||||
: m_mem(mem)
|
||||
{
|
||||
uint8* p = (uint8*)vmalloc(2 * 4096, false);
|
||||
uint8* p = (uint8*)vmalloc(CLUT_ALLOC_SIZE, false);
|
||||
|
||||
m_clut = (uint16*)&p[0]; // 1k + 1k for buffer overruns (sfex: PSM == PSM_PSMT8, CPSM == PSM_PSMCT32, CSA != 0)
|
||||
m_buff32 = (uint32*)&p[2048]; // 1k
|
||||
|
@ -88,7 +90,7 @@ GSClut::GSClut(GSLocalMemory* mem)
|
|||
|
||||
GSClut::~GSClut()
|
||||
{
|
||||
vmfree(m_clut);
|
||||
vmfree(m_clut, CLUT_ALLOC_SIZE);
|
||||
}
|
||||
|
||||
void GSClut::Invalidate()
|
||||
|
|
|
@ -34,7 +34,7 @@ GSCodeBuffer::~GSCodeBuffer()
|
|||
{
|
||||
for(list<void*>::iterator i = m_buffers.begin(); i != m_buffers.end(); i++)
|
||||
{
|
||||
vmfree(*i);
|
||||
vmfree(*i, m_blocksize);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -442,7 +442,7 @@ GSLocalMemory::GSLocalMemory()
|
|||
|
||||
GSLocalMemory::~GSLocalMemory()
|
||||
{
|
||||
vmfree(m_vm8);
|
||||
vmfree(m_vm8, m_vmsize * 2);
|
||||
|
||||
for_each(m_omap.begin(), m_omap.end(), aligned_free_second());
|
||||
for_each(m_po4map.begin(), m_po4map.end(), aligned_free_second());
|
||||
|
|
|
@ -70,6 +70,7 @@ public:
|
|||
#else
|
||||
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
class GSThread
|
||||
{
|
||||
|
@ -116,47 +117,14 @@ public:
|
|||
class GSAutoResetEvent
|
||||
{
|
||||
protected:
|
||||
pthread_mutexattr_t m_mutex_attr;
|
||||
pthread_mutex_t m_mutex;
|
||||
pthread_cond_t m_cond;
|
||||
pthread_condattr_t m_cond_attr;
|
||||
sem_t m_sem;
|
||||
|
||||
public:
|
||||
GSAutoResetEvent()
|
||||
{
|
||||
pthread_mutexattr_settype(&m_mutex_attr, PTHREAD_MUTEX_FAST_NP);
|
||||
pthread_mutex_init(&m_mutex, &m_mutex_attr);
|
||||
pthread_condattr_init(&m_cond_attr);
|
||||
pthread_cond_init(&m_cond, &m_cond_attr);
|
||||
}
|
||||
GSAutoResetEvent() {sem_init(&m_sem, 0, 0);}
|
||||
~GSAutoResetEvent() {sem_destroy(&m_sem);}
|
||||
|
||||
~GSAutoResetEvent()
|
||||
{
|
||||
pthread_mutex_destroy(&m_mutex);
|
||||
pthread_mutexattr_destroy(&m_mutex_attr);
|
||||
pthread_cond_destroy(&m_cond);
|
||||
pthread_condattr_destroy(&m_cond_attr);
|
||||
}
|
||||
|
||||
void Set()
|
||||
{
|
||||
int ret;
|
||||
|
||||
pthread_mutex_lock(&m_mutex);
|
||||
pthread_cond_signal(&m_cond);
|
||||
pthread_mutex_unlock(&m_mutex);
|
||||
}
|
||||
|
||||
bool Wait()
|
||||
{
|
||||
int ret;
|
||||
|
||||
pthread_mutex_lock(&m_mutex);
|
||||
ret = pthread_cond_wait(&m_cond, &m_mutex);
|
||||
pthread_mutex_unlock(&m_mutex);
|
||||
|
||||
return ret == 0;
|
||||
}
|
||||
void Set() {sem_post(&m_sem);}
|
||||
bool Wait() {return sem_wait(&m_sem) == 0;}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -194,6 +194,8 @@ GSVector4i GSWnd::GetClientRect()
|
|||
|
||||
r = GSVector4i::zero();
|
||||
|
||||
// TODO: linux
|
||||
|
||||
#endif
|
||||
|
||||
return r;
|
||||
|
@ -225,13 +227,13 @@ void GSWnd::Show()
|
|||
|
||||
#ifdef _WINDOWS
|
||||
|
||||
//SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
|
||||
HWND hWnd = (HWND)m_hWnd;
|
||||
|
||||
SetForegroundWindow((HWND)m_hWnd);
|
||||
SetForegroundWindow(hWnd);
|
||||
|
||||
ShowWindow((HWND)m_hWnd, SW_SHOWNORMAL);
|
||||
ShowWindow(hWnd, SW_SHOWNORMAL);
|
||||
|
||||
UpdateWindow((HWND)m_hWnd);
|
||||
UpdateWindow(hWnd);
|
||||
|
||||
#else
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
<Option createStaticLib="1" />
|
||||
<Compiler>
|
||||
<Add option="-g" />
|
||||
<Add option="-fno-operator-names" />
|
||||
</Compiler>
|
||||
</Target>
|
||||
<Target title="Release">
|
||||
|
@ -32,6 +31,7 @@
|
|||
</Build>
|
||||
<Compiler>
|
||||
<Add option="-march=pentium4" />
|
||||
<Add option="-fno-operator-names" />
|
||||
<Add option="-D_LINUX" />
|
||||
</Compiler>
|
||||
<Unit filename="GPU.cpp" />
|
||||
|
|
|
@ -38,26 +38,49 @@ string format(const char* fmt, ...)
|
|||
return s;
|
||||
}
|
||||
|
||||
#ifdef _WINDOWS
|
||||
|
||||
void* vmalloc(size_t size, bool code)
|
||||
{
|
||||
#ifdef _WINDOWS
|
||||
return VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, code ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE);
|
||||
#else
|
||||
// TODO: linux
|
||||
return malloc(size);
|
||||
#endif
|
||||
}
|
||||
|
||||
void vmfree(void* ptr)
|
||||
void vmfree(void* ptr, size_t size)
|
||||
{
|
||||
#ifdef _WINDOWS
|
||||
VirtualFree(ptr, 0, MEM_RELEASE);
|
||||
#else
|
||||
// TODO: linux
|
||||
free(ptr);
|
||||
#endif
|
||||
VirtualFree(ptr, size, MEM_RELEASE);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <sys/mman.h>
|
||||
|
||||
void* vmalloc(size_t size, bool code)
|
||||
{
|
||||
size_t mask = getpagesize() - 1;
|
||||
|
||||
size = (size + mask) & ~mask;
|
||||
|
||||
int flags = PROT_READ | PROT_WRITE;
|
||||
|
||||
if(code)
|
||||
{
|
||||
flags |= PROT_EXEC;
|
||||
}
|
||||
|
||||
return mmap(NULL, size, flags, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
}
|
||||
|
||||
void vmfree(void* ptr, size_t size)
|
||||
{
|
||||
size_t mask = getpagesize() - 1;
|
||||
|
||||
size = (size + mask) & ~mask;
|
||||
|
||||
munmap(ptr, size);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined(_MSC_VER) && !defined(HAVE_ALIGNED_MALLOC)
|
||||
|
||||
// declare linux equivalents (alignment must be power of 2 (1,2,4...2^15)
|
||||
|
|
|
@ -307,4 +307,4 @@ __forceinline unsigned long long __rdtsc()
|
|||
#endif
|
||||
|
||||
extern void* vmalloc(size_t size, bool code);
|
||||
extern void vmfree(void* ptr);
|
||||
extern void vmfree(void* ptr, size_t size);
|
||||
|
|
Loading…
Reference in New Issue