mirror of https://github.com/PCSX2/pcsx2.git
Add disabled code to use a cache for cso reading.
It doesn't seem like the cache is worth it, unfortunately.
This commit is contained in:
parent
427fa039ba
commit
7b1214849a
|
@ -154,6 +154,9 @@ bool CsoFileReader::InitializeBuffers() {
|
|||
|
||||
void CsoFileReader::Close() {
|
||||
m_filename.Empty();
|
||||
#if CSO_USE_CHUNKSCACHE
|
||||
m_cache.Clear();
|
||||
#endif
|
||||
|
||||
if (m_src) {
|
||||
fclose(m_src);
|
||||
|
@ -193,18 +196,37 @@ int CsoFileReader::ReadSync(void* pBuffer, uint sector, uint count) {
|
|||
int bytes = 0;
|
||||
|
||||
while (remaining > 0) {
|
||||
int readBytes = ReadFromFrame(dest + bytes, pos + bytes, remaining);
|
||||
if (readBytes == 0) {
|
||||
// We hit EOF.
|
||||
break;
|
||||
int readBytes;
|
||||
|
||||
#if CSO_USE_CHUNKSCACHE
|
||||
// Try first to read from the cache.
|
||||
readBytes = m_cache.Read(dest + bytes, pos + bytes, remaining);
|
||||
#else
|
||||
readBytes = -1;
|
||||
#endif
|
||||
if (readBytes < 0) {
|
||||
readBytes = ReadFromFrame(dest + bytes, pos + bytes, remaining);
|
||||
if (readBytes == 0) {
|
||||
// We hit EOF.
|
||||
break;
|
||||
}
|
||||
|
||||
#if CSO_USE_CHUNKSCACHE
|
||||
// Add the bytes into the cache. We need to allocate a buffer for it.
|
||||
void *cached = malloc(readBytes);
|
||||
memcpy(cached, dest + bytes, readBytes);
|
||||
m_cache.Take(cached, pos + bytes, readBytes, readBytes);
|
||||
#endif
|
||||
}
|
||||
|
||||
bytes += readBytes;
|
||||
remaining -= readBytes;
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
int CsoFileReader::ReadFromFrame(u8 *dest, u64 pos, u64 maxBytes) {
|
||||
int CsoFileReader::ReadFromFrame(u8 *dest, u64 pos, int maxBytes) {
|
||||
if (pos >= m_totalSize) {
|
||||
// Can't read anything passed the end.
|
||||
return 0;
|
||||
|
|
|
@ -15,11 +15,23 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
// Based on testing, the overhead of using this cache is high.
|
||||
//
|
||||
// The test was done with CSO files using a block size of 16KB.
|
||||
// Cache hit rates were observed in the range of 25%.
|
||||
// Cache overhead added 35% to the overall read time.
|
||||
//
|
||||
// For this reason, it's currently disabled.
|
||||
#define CSO_USE_CHUNKSCACHE 0
|
||||
|
||||
#include "AsyncFileReader.h"
|
||||
#include "ChunksCache.h"
|
||||
|
||||
struct CsoHeader;
|
||||
typedef struct z_stream_s z_stream;
|
||||
|
||||
static const uint CSO_CHUNKCACHE_SIZE_MB = 200;
|
||||
|
||||
class CsoFileReader : public AsyncFileReader
|
||||
{
|
||||
DeclareNoncopyableObject(CsoFileReader);
|
||||
|
@ -31,6 +43,9 @@ public:
|
|||
m_totalSize(0),
|
||||
m_src(0),
|
||||
m_z_stream(0),
|
||||
#if CSO_USE_CHUNKSCACHE
|
||||
m_cache(CSO_CHUNKCACHE_SIZE_MB),
|
||||
#endif
|
||||
m_bytesRead(0) {
|
||||
m_blocksize = 2048;
|
||||
};
|
||||
|
@ -59,7 +74,7 @@ private:
|
|||
static bool ValidateHeader(const CsoHeader& hdr);
|
||||
bool ReadFileHeader();
|
||||
bool InitializeBuffers();
|
||||
int ReadFromFrame(u8 *dest, u64 pos, u64 maxBytes);
|
||||
int ReadFromFrame(u8 *dest, u64 pos, int maxBytes);
|
||||
bool DecompressFrame(u32 frame, u32 readBufferSize);
|
||||
|
||||
u32 m_frameSize;
|
||||
|
@ -73,6 +88,11 @@ private:
|
|||
// The actual source cso file handle.
|
||||
FILE* m_src;
|
||||
z_stream* m_z_stream;
|
||||
|
||||
#if CSO_USE_CHUNKSCACHE
|
||||
ChunksCache m_cache;
|
||||
#endif
|
||||
|
||||
// The result of a read is stored here between BeginRead() and FinishRead().
|
||||
int m_bytesRead;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue