From 5860de1ccedaeea62ce4e74972976fed26a1e0a5 Mon Sep 17 00:00:00 2001 From: gabest11 Date: Sat, 19 Feb 2011 10:27:10 +0000 Subject: [PATCH] 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 --- plugins/GSdx/GPULocalMemory.cpp | 16 ++++++----- plugins/GSdx/GSClut.cpp | 6 +++-- plugins/GSdx/GSCodeBuffer.cpp | 2 +- plugins/GSdx/GSLocalMemory.cpp | 2 +- plugins/GSdx/GSThread.h | 44 +++++------------------------- plugins/GSdx/GSWnd.cpp | 10 ++++--- plugins/GSdx/GSdx.gcc.cbp | 2 +- plugins/GSdx/stdafx.cpp | 47 ++++++++++++++++++++++++--------- plugins/GSdx/stdafx.h | 2 +- 9 files changed, 65 insertions(+), 66 deletions(-) diff --git a/plugins/GSdx/GPULocalMemory.cpp b/plugins/GSdx/GPULocalMemory.cpp index 589319a3e7..7f330ccd4c 100644 --- a/plugins/GSdx/GPULocalMemory.cpp +++ b/plugins/GSdx/GPULocalMemory.cpp @@ -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) diff --git a/plugins/GSdx/GSClut.cpp b/plugins/GSdx/GSClut.cpp index a9d93d23a7..e223b72cb6 100644 --- a/plugins/GSdx/GSClut.cpp +++ b/plugins/GSdx/GSClut.cpp @@ -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() diff --git a/plugins/GSdx/GSCodeBuffer.cpp b/plugins/GSdx/GSCodeBuffer.cpp index 66fcedc291..3cd27ce7b7 100644 --- a/plugins/GSdx/GSCodeBuffer.cpp +++ b/plugins/GSdx/GSCodeBuffer.cpp @@ -34,7 +34,7 @@ GSCodeBuffer::~GSCodeBuffer() { for(list::iterator i = m_buffers.begin(); i != m_buffers.end(); i++) { - vmfree(*i); + vmfree(*i, m_blocksize); } } diff --git a/plugins/GSdx/GSLocalMemory.cpp b/plugins/GSdx/GSLocalMemory.cpp index b0421ed93a..8525350843 100644 --- a/plugins/GSdx/GSLocalMemory.cpp +++ b/plugins/GSdx/GSLocalMemory.cpp @@ -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()); diff --git a/plugins/GSdx/GSThread.h b/plugins/GSdx/GSThread.h index dd37a3857b..b14fc6708f 100644 --- a/plugins/GSdx/GSThread.h +++ b/plugins/GSdx/GSThread.h @@ -70,6 +70,7 @@ public: #else #include +#include 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 diff --git a/plugins/GSdx/GSWnd.cpp b/plugins/GSdx/GSWnd.cpp index 1dececffa1..313d1b1068 100644 --- a/plugins/GSdx/GSWnd.cpp +++ b/plugins/GSdx/GSWnd.cpp @@ -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 diff --git a/plugins/GSdx/GSdx.gcc.cbp b/plugins/GSdx/GSdx.gcc.cbp index e07132f0c5..72eca79dad 100644 --- a/plugins/GSdx/GSdx.gcc.cbp +++ b/plugins/GSdx/GSdx.gcc.cbp @@ -15,7 +15,6 @@