PSP: moved VramAllocator to display_manager.cpp.
It didn't really belong in memory.cpp and we're going to want to include memory.h everywhere. * * * PSP: more Vram Allocator cleanup svn-id: r52815
This commit is contained in:
parent
971d5ca4b8
commit
b006082cf1
4 changed files with 109 additions and 120 deletions
|
@ -59,6 +59,71 @@ const OSystem::GraphicsMode DisplayManager::_supportedModes[] = {
|
||||||
{0, 0, 0}
|
{0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Class VramAllocator -----------------------------------
|
||||||
|
|
||||||
|
DECLARE_SINGLETON(VramAllocator)
|
||||||
|
|
||||||
|
//#define __PSP_DEBUG_FUNCS__ /* For debugging the stack */
|
||||||
|
//#define __PSP_DEBUG_PRINT__
|
||||||
|
|
||||||
|
#include "backends/platform/psp/trace.h"
|
||||||
|
|
||||||
|
|
||||||
|
void *VramAllocator::allocate(int32 size, bool smallAllocation /* = false */) {
|
||||||
|
DEBUG_ENTER_FUNC();
|
||||||
|
assert(size > 0);
|
||||||
|
|
||||||
|
byte *lastAddress = smallAllocation ? (byte *)VRAM_SMALL_ADDRESS : (byte *)VRAM_START_ADDRESS;
|
||||||
|
Common::List<Allocation>::iterator i;
|
||||||
|
|
||||||
|
// Find a block that fits, starting from the beginning
|
||||||
|
for (i = _allocList.begin(); i != _allocList.end(); ++i) {
|
||||||
|
byte *currAddress = (*i).address;
|
||||||
|
|
||||||
|
if (currAddress - lastAddress >= size) // We found a match
|
||||||
|
break;
|
||||||
|
|
||||||
|
if ((*i).getEnd() > lastAddress)
|
||||||
|
lastAddress = (byte *)(*i).getEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastAddress + size > (byte *)VRAM_END_ADDRESS) {
|
||||||
|
PSP_DEBUG_PRINT("No space for allocation of %d bytes. %d bytes already allocated.\n",
|
||||||
|
size, _bytesAllocated);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
_allocList.insert(i, Allocation(lastAddress, size));
|
||||||
|
_bytesAllocated += size;
|
||||||
|
|
||||||
|
PSP_DEBUG_PRINT("Allocated in VRAM, size %u at %p.\n", size, lastAddress);
|
||||||
|
PSP_DEBUG_PRINT("Total allocated %u, remaining %u.\n", _bytesAllocated, (2 * 1024 * 1024) - _bytesAllocated);
|
||||||
|
|
||||||
|
return lastAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deallocate a block from VRAM
|
||||||
|
void VramAllocator::deallocate(void *address) {
|
||||||
|
DEBUG_ENTER_FUNC();
|
||||||
|
address = (byte *)CACHED(address); // Make sure all addresses are the same
|
||||||
|
|
||||||
|
Common::List<Allocation>::iterator i;
|
||||||
|
|
||||||
|
// Find the Allocator to deallocate
|
||||||
|
for (i = _allocList.begin(); i != _allocList.end(); ++i) {
|
||||||
|
if ((*i).address == address) {
|
||||||
|
_bytesAllocated -= (*i).size;
|
||||||
|
_allocList.erase(i);
|
||||||
|
PSP_DEBUG_PRINT("Deallocated address[%p], size[%u]\n", (*i).address, (*i).size);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PSP_DEBUG_PRINT("Address[%p] not allocated.\n", address);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Class MasterGuRenderer ----------------------------------------------
|
// Class MasterGuRenderer ----------------------------------------------
|
||||||
|
|
||||||
void MasterGuRenderer::setupCallbackThread() {
|
void MasterGuRenderer::setupCallbackThread() {
|
||||||
|
|
|
@ -27,6 +27,48 @@
|
||||||
#define PSP_DISPLAY_MAN_H
|
#define PSP_DISPLAY_MAN_H
|
||||||
|
|
||||||
#include "backends/platform/psp/thread.h"
|
#include "backends/platform/psp/thread.h"
|
||||||
|
#include "common/list.h"
|
||||||
|
|
||||||
|
#define UNCACHED(x) ((byte *)(((uint32)(x)) | 0x40000000)) /* make an uncached access */
|
||||||
|
#define CACHED(x) ((byte *)(((uint32)(x)) & 0xBFFFFFFF)) /* make an uncached access into a cached one */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class that allocates memory in the VRAM
|
||||||
|
*/
|
||||||
|
class VramAllocator : public Common::Singleton<VramAllocator> {
|
||||||
|
public:
|
||||||
|
VramAllocator() : _bytesAllocated(0) {}
|
||||||
|
void *allocate(int32 size, bool smallAllocation = false); // smallAllocation e.g. palettes
|
||||||
|
void deallocate(void *pointer);
|
||||||
|
|
||||||
|
static inline bool isAddressInVram(void *address) {
|
||||||
|
if ((uint32)(CACHED(address)) >= VRAM_START_ADDRESS && (uint32)(CACHED(address)) < VRAM_END_ADDRESS)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* Used to allocate in VRAM
|
||||||
|
*/
|
||||||
|
struct Allocation {
|
||||||
|
byte *address;
|
||||||
|
uint32 size;
|
||||||
|
void *getEnd() { return address + size; }
|
||||||
|
Allocation(void *Address, uint32 Size) : address((byte *)Address), size(Size) {}
|
||||||
|
Allocation() : address(0), size(0) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
VRAM_START_ADDRESS = 0x04000000,
|
||||||
|
VRAM_END_ADDRESS = 0x04200000,
|
||||||
|
VRAM_SMALL_ADDRESS = VRAM_END_ADDRESS - (4 * 1024) // 4K in the end for small allocations
|
||||||
|
};
|
||||||
|
Common::List <Allocation> _allocList; // List of allocations
|
||||||
|
uint32 _bytesAllocated;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class used only by DisplayManager to start/stop GU rendering
|
* Class used only by DisplayManager to start/stop GU rendering
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
|
|
||||||
#include "common/scummsys.h"
|
#include "common/scummsys.h"
|
||||||
#include "common/singleton.h"
|
#include "common/singleton.h"
|
||||||
#include "common/list.h"
|
|
||||||
#include "backends/platform/psp/psppixelformat.h"
|
#include "backends/platform/psp/psppixelformat.h"
|
||||||
#include "backends/platform/psp/memory.h"
|
#include "backends/platform/psp/memory.h"
|
||||||
|
|
||||||
|
@ -424,79 +423,3 @@ void PspMemory::swap32Misaligned(uint32 *dst32, const uint16 *src16, uint32 byte
|
||||||
*((uint16 *)dst32) = format.swapRedBlue16((uint16)(srcWord >> shiftValue));
|
*((uint16 *)dst32) = format.swapRedBlue16((uint16)(srcWord >> shiftValue));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void PspMemory::copy16(uint16 *dst16, const uint16 *src16, uint32 bytes) {
|
|
||||||
PSP_DEBUG_PRINT("copy16(): dst16[%p], src16[%p], bytes[%d]\n", dst16, src16, bytes);
|
|
||||||
|
|
||||||
uint32 shorts = bytes >> 1;
|
|
||||||
uint32 remainingBytes = bytes & 1;
|
|
||||||
|
|
||||||
for (; shorts > 0 ; shorts--) {
|
|
||||||
*dst16++ = *src16++;
|
|
||||||
}
|
|
||||||
if (remainingBytes)
|
|
||||||
*(byte *)dst16 = *(byte *)src16;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Class VramAllocator -----------------------------------
|
|
||||||
|
|
||||||
DECLARE_SINGLETON(VramAllocator)
|
|
||||||
|
|
||||||
//#define __PSP_DEBUG_FUNCS__ /* For debugging the stack */
|
|
||||||
//#define __PSP_DEBUG_PRINT__
|
|
||||||
|
|
||||||
#include "backends/platform/psp/trace.h"
|
|
||||||
|
|
||||||
|
|
||||||
void *VramAllocator::allocate(int32 size, bool smallAllocation /* = false */) {
|
|
||||||
DEBUG_ENTER_FUNC();
|
|
||||||
assert(size > 0);
|
|
||||||
|
|
||||||
byte *lastAddress = smallAllocation ? (byte *)VRAM_SMALL_ADDRESS : (byte *)VRAM_START_ADDRESS;
|
|
||||||
Common::List<Allocation>::iterator i;
|
|
||||||
|
|
||||||
// Find a block that fits, starting from the beginning
|
|
||||||
for (i = _allocList.begin(); i != _allocList.end(); ++i) {
|
|
||||||
byte *currAddress = (*i).address;
|
|
||||||
|
|
||||||
if (currAddress - lastAddress >= size) // We found a match
|
|
||||||
break;
|
|
||||||
|
|
||||||
if ((*i).getEnd() > lastAddress)
|
|
||||||
lastAddress = (byte *)(*i).getEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastAddress + size > (byte *)VRAM_END_ADDRESS) {
|
|
||||||
PSP_DEBUG_PRINT("No space for allocation of %d bytes. %d bytes already allocated.\n",
|
|
||||||
size, _bytesAllocated);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
_allocList.insert(i, Allocation(lastAddress, size));
|
|
||||||
_bytesAllocated += size;
|
|
||||||
|
|
||||||
PSP_DEBUG_PRINT("Allocated in VRAM, size %u at %p.\n", size, lastAddress);
|
|
||||||
PSP_DEBUG_PRINT("Total allocated %u, remaining %u.\n", _bytesAllocated, (2 * 1024 * 1024) - _bytesAllocated);
|
|
||||||
|
|
||||||
return lastAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deallocate a block from VRAM
|
|
||||||
void VramAllocator::deallocate(void *address) {
|
|
||||||
DEBUG_ENTER_FUNC();
|
|
||||||
address = (byte *)CACHED(address); // Make sure all addresses are the same
|
|
||||||
|
|
||||||
Common::List<Allocation>::iterator i;
|
|
||||||
|
|
||||||
// Find the Allocator to deallocate
|
|
||||||
for (i = _allocList.begin(); i != _allocList.end(); ++i) {
|
|
||||||
if ((*i).address == address) {
|
|
||||||
_bytesAllocated -= (*i).size;
|
|
||||||
_allocList.erase(i);
|
|
||||||
PSP_DEBUG_PRINT("Deallocated address[%p], size[%u]\n", (*i).address, (*i).size);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PSP_DEBUG_PRINT("Address[%p] not allocated.\n", address);
|
|
||||||
}
|
|
||||||
|
|
|
@ -27,12 +27,6 @@
|
||||||
#ifndef PSP_MEMORY_H
|
#ifndef PSP_MEMORY_H
|
||||||
#define PSP_MEMORY_H
|
#define PSP_MEMORY_H
|
||||||
|
|
||||||
#include "backends/platform/psp/psppixelformat.h"
|
|
||||||
#include "common/list.h"
|
|
||||||
|
|
||||||
#define UNCACHED(x) ((byte *)(((uint32)(x)) | 0x40000000)) /* make an uncached access */
|
|
||||||
#define CACHED(x) ((byte *)(((uint32)(x)) & 0xBFFFFFFF)) /* make an uncached access into a cached one */
|
|
||||||
|
|
||||||
#define MIN_AMOUNT_FOR_COMPLEX_COPY 8
|
#define MIN_AMOUNT_FOR_COMPLEX_COPY 8
|
||||||
#define MIN_AMOUNT_FOR_MISALIGNED_COPY 8
|
#define MIN_AMOUNT_FOR_MISALIGNED_COPY 8
|
||||||
|
|
||||||
|
@ -91,41 +85,6 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Class that allocates memory in the VRAM
|
|
||||||
*/
|
|
||||||
class VramAllocator : public Common::Singleton<VramAllocator> {
|
|
||||||
public:
|
|
||||||
VramAllocator() : _bytesAllocated(0) {}
|
|
||||||
void *allocate(int32 size, bool smallAllocation = false); // smallAllocation e.g. palettes
|
|
||||||
void deallocate(void *pointer);
|
|
||||||
|
|
||||||
static inline bool isAddressInVram(void *address) {
|
|
||||||
if ((uint32)(CACHED(address)) >= VRAM_START_ADDRESS && (uint32)(CACHED(address)) < VRAM_END_ADDRESS)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
/**
|
|
||||||
* Used to allocate in VRAM
|
|
||||||
*/
|
|
||||||
struct Allocation {
|
|
||||||
byte *address;
|
|
||||||
uint32 size;
|
|
||||||
void *getEnd() { return address + size; }
|
|
||||||
Allocation(void *Address, uint32 Size) : address((byte *)Address), size(Size) {}
|
|
||||||
Allocation() : address(0), size(0) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
|
||||||
VRAM_START_ADDRESS = 0x04000000,
|
|
||||||
VRAM_END_ADDRESS = 0x04200000,
|
|
||||||
VRAM_SMALL_ADDRESS = VRAM_END_ADDRESS - (4 * 1024) // 4K in the end for small allocations
|
|
||||||
};
|
|
||||||
Common::List <Allocation> _allocList; // List of allocations
|
|
||||||
uint32 _bytesAllocated;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* PSP_MEMORY_H */
|
#endif /* PSP_MEMORY_H */
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue