1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-25 04:02:42 +01:00

Small changes 2

This commit is contained in:
Nekotekina 2014-06-29 07:21:57 +04:00
parent b11e086589
commit 8987350b5b
13 changed files with 118 additions and 65 deletions

View File

@ -4,8 +4,6 @@ template<typename T, u32 SQSize = 666>
class SQueue
{
std::mutex m_mutex;
NamedThreadBase* push_waiter;
NamedThreadBase* pop_waiter;
u32 m_pos;
u32 m_count;
T m_data[SQSize];
@ -14,8 +12,6 @@ public:
SQueue()
: m_pos(0)
, m_count(0)
, push_waiter(nullptr)
, pop_waiter(nullptr)
{
}
@ -26,9 +22,6 @@ public:
bool Push(const T& data)
{
NamedThreadBase* t = GetCurrentNamedThread();
push_waiter = t;
while (true)
{
if (m_count >= SQSize)
@ -46,11 +39,9 @@ public:
std::lock_guard<std::mutex> lock(m_mutex);
if (m_count >= SQSize) continue;
if (pop_waiter && !m_count) pop_waiter->Notify();
m_data[(m_pos + m_count++) % SQSize] = data;
push_waiter = nullptr;
return true;
}
}
@ -58,9 +49,6 @@ public:
bool Pop(T& data)
{
NamedThreadBase* t = GetCurrentNamedThread();
pop_waiter = t;
while (true)
{
if (!m_count)
@ -78,43 +66,44 @@ public:
std::lock_guard<std::mutex> lock(m_mutex);
if (!m_count) continue;
if (push_waiter && m_count >= SQSize) push_waiter->Notify();
data = m_data[m_pos];
m_pos = (m_pos + 1) % SQSize;
m_count--;
pop_waiter = nullptr;
return true;
}
}
}
volatile u32 GetCount() // may be thread unsafe
u32 GetCount()
{
std::lock_guard<std::mutex> lock(m_mutex);
return m_count;
}
u32 GetCountUnsafe()
{
return m_count;
}
volatile bool IsEmpty() // may be thread unsafe
bool IsEmpty()
{
std::lock_guard<std::mutex> lock(m_mutex);
return !m_count;
}
void Clear()
{
std::lock_guard<std::mutex> lock(m_mutex);
if (push_waiter && m_count >= SQSize) push_waiter->Notify();
m_count = 0;
}
T& Peek(u32 pos = 0)
{
NamedThreadBase* t = GetCurrentNamedThread();
pop_waiter = t;
while (true)
{
if (!m_count)
if (m_count <= pos)
{
if (Emu.IsStopped())
{
@ -127,13 +116,25 @@ public:
{
std::lock_guard<std::mutex> lock(m_mutex);
if (m_count)
if (m_count > pos)
{
pop_waiter = nullptr;
break;
}
}
}
return m_data[(m_pos + pos) % SQSize];
}
T& PeekIfExist(T& def, u32 pos = 0)
{
std::lock_guard<std::mutex> lock(m_mutex);
if (m_count <= pos)
{
return def;
}
else
{
return m_data[(m_pos + pos) % SQSize];
}
}
};

View File

@ -355,8 +355,9 @@ bool GLGSRender::LoadProgram()
if(m_fp_buf_num == -1)
{
LOG_WARNING(RSX, "FP not found in buffer!");
m_shader_prog.DecompileAsync(*m_cur_shader_prog);
m_shader_prog.Wait();
//m_shader_prog.DecompileAsync(*m_cur_shader_prog);
//m_shader_prog.Wait();
m_shader_prog.Decompile(*m_cur_shader_prog);
m_shader_prog.Compile();
checkForGlError("m_shader_prog.Compile");
@ -367,8 +368,9 @@ bool GLGSRender::LoadProgram()
if(m_vp_buf_num == -1)
{
LOG_WARNING(RSX, "VP not found in buffer!");
m_vertex_prog.DecompileAsync(*m_cur_vertex_prog);
m_vertex_prog.Wait();
//m_vertex_prog.DecompileAsync(*m_cur_vertex_prog);
//m_vertex_prog.Wait();
m_vertex_prog.Decompile(*m_cur_vertex_prog);
m_vertex_prog.Compile();
checkForGlError("m_vertex_prog.Compile");

View File

@ -197,6 +197,7 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, mem32_ptr_t& args, const u3
//if(cmd == 0xfeadffff)
{
Flip();
m_last_flip_time = get_system_time();
m_gcm_current_buffer = ARGS(0);
m_read_buffer = true;
@ -1878,6 +1879,7 @@ void RSXThread::Task()
OnInitThread();
m_last_flip_time = get_system_time();
volatile bool is_vblank_stopped = false;
thread vblank("VBlank thread", [&]()

View File

@ -32,7 +32,7 @@ int adecRawRead(void* opaque, u8* buf, int buf_size)
next:
if (adec.reader.size < (u32)buf_size /*&& !adec.just_started*/)
{
while (adec.job.IsEmpty())
while (!adec.job.GetCountUnsafe())
{
if (Emu.IsStopped())
{
@ -45,6 +45,7 @@ next:
switch (adec.job.Peek().type)
{
case adecEndSeq:
case adecClose:
{
buf_size = adec.reader.size;
}
@ -209,7 +210,7 @@ u32 adecOpen(AudioDecoder* data)
break;
}
if (adec.job.IsEmpty() && adec.is_running)
if (!adec.job.GetCountUnsafe() && adec.is_running)
{
Sleep(1);
continue;
@ -255,10 +256,8 @@ u32 adecOpen(AudioDecoder* data)
cb.Branch(true); // ???*/
adec.adecCb->ExecAsCallback(adec.cbFunc, true, adec.id, CELL_ADEC_MSG_TYPE_SEQDONE, CELL_OK, adec.cbArg);
avcodec_close(adec.ctx);
avformat_close_input(&adec.fmt);
adec.is_running = false;
adec.just_finished = true;
}
break;
@ -312,7 +311,14 @@ u32 adecOpen(AudioDecoder* data)
dump.Close();
}*/
if (adec.just_started) // deferred initialization
if (adec.just_started && adec.just_finished)
{
avcodec_flush_buffers(adec.ctx);
adec.reader.init = true;
adec.just_finished = false;
adec.just_started = false;
}
else if (adec.just_started) // deferred initialization
{
err = avformat_open_input(&adec.fmt, NULL, av_find_input_format("oma"), NULL);
if (err)
@ -353,7 +359,7 @@ u32 adecOpen(AudioDecoder* data)
av_dict_set(&opts, "refcounted_frames", "1", 0);
{
std::lock_guard<std::mutex> lock(g_mutex_avcodec_open2);
// not multithread-safe
// not multithread-safe (???)
err = avcodec_open2(adec.ctx, codec, &opts);
}
if (err)
@ -605,7 +611,7 @@ int cellAdecClose(u32 handle)
adec->job.Push(AdecTask(adecClose));
while (!adec->is_finished || !adec->frames.IsEmpty())
while (!adec->is_finished)
{
if (Emu.IsStopped())
{
@ -789,13 +795,14 @@ int cellAdecGetPcmItem(u32 handle, mem32_t pcmItem_ptr)
return CELL_ADEC_ERROR_FATAL;
}
AdecFrame& af = adec->frames.Peek();
if (adec->frames.IsEmpty())
{
Sleep(1); // hack
return CELL_ADEC_ERROR_EMPTY;
}
AdecFrame& af = adec->frames.Peek();
AVFrame* frame = af.data;
mem_ptr_t<CellAdecPcmItem> pcm(adec->memAddr + adec->memBias);

View File

@ -1076,6 +1076,7 @@ public:
volatile bool is_running;
volatile bool is_finished;
bool just_started;
bool just_finished;
AVCodecContext* ctx;
AVFormatContext* fmt;
@ -1127,6 +1128,7 @@ public:
, is_running(false)
, is_finished(false)
, just_started(false)
, just_finished(false)
, ctx(nullptr)
, fmt(nullptr)
{

View File

@ -71,7 +71,7 @@ u32 dmuxOpen(Demuxer* data)
break;
}
if (dmux.job.IsEmpty() && dmux.is_running)
if (!dmux.job.GetCountUnsafe() && dmux.is_running)
{
// default task (demuxing) (if there is no other work)
be_t<u32> code;

View File

@ -119,6 +119,15 @@ struct CellGameContentSize
be_t<s32> sysSizeKB;
};
struct CellGameSetInitParams
{
char title[CELL_GAME_SYSP_TITLE_SIZE];
char titleId[CELL_GAME_SYSP_TITLEID_SIZE];
char reserved0[2];
char version[CELL_GAME_SYSP_VERSION_SIZE];
char reserved1[66];
};
std::string contentInfo = "";
std::string usrdir = "";
@ -293,7 +302,7 @@ int cellGameContentPermit(mem_list_ptr_t<u8> contentInfoPath, mem_list_ptr_t<u8>
if (contentInfo == "" && usrdir == "")
{
cellGame->Error("cellGameContentPermit(): CELL_GAME_ERROR_FAILURE (calling order is invalid)");
cellGame->Warning("cellGameContentPermit(): CELL_GAME_ERROR_FAILURE (no permission given)");
return CELL_GAME_ERROR_FAILURE;
}
@ -320,9 +329,13 @@ int cellGameDataCheckCreate(u32 version, u32 dirName_addr, u32 errDialog, u32 fu
return cellGameDataCheckCreate2(version, dirName_addr, errDialog, funcStat_addr, container);
}
int cellGameCreateGameData()
int cellGameCreateGameData(mem_ptr_t<CellGameSetInitParams> init, mem_list_ptr_t<u8> tmp_contentInfoPath, mem_list_ptr_t<u8> tmp_usrdirPath)
{
UNIMPLEMENTED_FUNC(cellGame);
cellGame->Error("cellGameCreateGameData(init_addr=0x%x, tmp_contentInfoPath_addr=0x%x, tmp_usrdirPath_addr=0x%x)",
init.GetAddr(), tmp_contentInfoPath.GetAddr(), tmp_usrdirPath.GetAddr());
// TODO: create temporary game directory, set initial PARAM.SFO parameters
// cellGameContentPermit should then move files in non-temporary location and return their non-temporary displacement
return CELL_OK;
}

View File

@ -709,10 +709,11 @@ int cellGcmGetDisplayBufferByFlipIndex()
return CELL_OK;
}
int cellGcmGetLastFlipTime()
u64 cellGcmGetLastFlipTime()
{
UNIMPLEMENTED_FUNC(cellGcmSys);
return CELL_OK;
cellGcmSys->Log("cellGcmGetLastFlipTime()");
return Emu.GetGSManager().GetRender().m_last_flip_time;
}
int cellGcmGetLastSecondVTime()

View File

@ -98,9 +98,16 @@ int cellPngDecExtOpen(u32 mainHandle, mem32_t subHandle, mem_ptr_t<CellPngDecSrc
cellPngDec->Warning("cellPngDecExtOpen(mainHandle=0x%x, subHandle=0x%x, src_addr=0x%x, openInfo=0x%x, cbCtrlStrm_addr=0x%x, opnParam=0x%x)",
mainHandle, subHandle.GetAddr(), src.GetAddr(), openInfo, cbCtrlStrm.GetAddr(), opnParam.GetAddr());
cellPngDec->Warning("*** cbCtrlStrm->cbCtrlStrmFunc_addr=0x%x", (u32)cbCtrlStrm->cbCtrlStrmFunc_addr);
cellPngDec->Warning("*** cbCtrlStrm->cbCtrlStrmFunc_addr=0x%x", cbCtrlStrm->cbCtrlStrmFunc.GetAddr());
return cellPngDecOpen(mainHandle, subHandle, src, openInfo);
MemoryAllocator<CellPngDecStrmInfo> streamInfo;
MemoryAllocator<CellPngDecStrmParam> streamParam;
int res = cellPngDecOpen(mainHandle, subHandle, src, openInfo);
if (!res) cbCtrlStrm->cbCtrlStrmFunc(streamInfo.GetAddr(), streamParam.GetAddr(), cbCtrlStrm->cbCtrlStrmArg);
return res;
}
int cellPngDecClose(u32 mainHandle, u32 subHandle)
@ -316,7 +323,7 @@ int cellPngDecExtDecodeData(u32 mainHandle, u32 subHandle, mem8_ptr_t data, cons
cellPngDec->Warning("cellPngDecExtDecodeData(mainHandle=0x%x, subHandle=0x%x, data_addr=0x%x, dataCtrlParam_addr=0x%x, dataOutInfo_addr=0x%x, cbCtrlDisp_addr=0x%x, dispParam=0x%x",
mainHandle, subHandle, data.GetAddr(), dataCtrlParam.GetAddr(), dataOutInfo.GetAddr(), cbCtrlDisp.GetAddr(), dispParam.GetAddr());
cellPngDec->Warning("*** cbCtrlDisp->cbCtrlDispFunc_addr=0x%x", (u32)scbCtrlDisp->cbCtrlDispFunc_addr);
if (cbCtrlDisp.GetAddr()) cellPngDec->Warning("*** cbCtrlDisp->cbCtrlDispFunc_addr=0x%x", (u32)cbCtrlDisp->cbCtrlDispFunc_addr);
return cellPngDecDecodeData(mainHandle, subHandle, data, dataCtrlParam, dataOutInfo);
}

View File

@ -125,9 +125,20 @@ struct CellPngDecMainHandle
be_t<u32> threadOutParam;
};
struct CellPngDecStrmInfo
{
be_t<u32> decodedStrmSize;
};
struct CellPngDecStrmParam
{
be_t<u32> strmPtr;
be_t<u32> strmSize;
};
struct CellPngDecCbCtrlStrm
{
be_t<u32> cbCtrlStrmFunc_addr;
mem_func_beptr_t<void(*)(mem_ptr_t<CellPngDecStrmInfo> strmInfo, mem_ptr_t<CellPngDecStrmParam> strmParam, u32 cbCtrlStrmArg)> cbCtrlStrmFunc;
be_t<u32> cbCtrlStrmArg;
};

View File

@ -889,10 +889,11 @@ int cellRescGetRegisterCount()
return CELL_OK;
}
int cellRescGetLastFlipTime()
u64 cellRescGetLastFlipTime()
{
UNIMPLEMENTED_FUNC(cellResc);
return CELL_OK;
cellResc->Log("cellRescGetLastFlipTime()");
return Emu.GetGSManager().GetRender().m_last_flip_time;
}
int cellRescSetRegisterCount()

View File

@ -31,7 +31,7 @@ int vdecRead(void* opaque, u8* buf, int buf_size)
next:
if (vdec.reader.size < (u32)buf_size /*&& !vdec.just_started*/)
{
while (vdec.job.IsEmpty())
while (!vdec.job.GetCountUnsafe())
{
if (Emu.IsStopped())
{
@ -44,6 +44,7 @@ next:
switch (vdec.job.Peek().type)
{
case vdecEndSeq:
case vdecClose:
{
buf_size = vdec.reader.size;
}
@ -147,7 +148,7 @@ u32 vdecOpen(VideoDecoder* data)
break;
}
if (vdec.job.IsEmpty() && vdec.is_running)
if (!vdec.job.GetCountUnsafe() && vdec.is_running)
{
Sleep(1);
continue;
@ -189,10 +190,8 @@ u32 vdecOpen(VideoDecoder* data)
cb.Handle(vdec.id, CELL_VDEC_MSG_TYPE_SEQDONE, CELL_OK, vdec.cbArg);
cb.Branch(true); // ???*/
avcodec_close(vdec.ctx);
avformat_close_input(&vdec.fmt);
vdec.is_running = false;
vdec.just_finished = true;
}
break;
@ -244,7 +243,13 @@ u32 vdecOpen(VideoDecoder* data)
} au(0);
if (vdec.just_started) // deferred initialization
if (vdec.just_started && vdec.just_finished)
{
avcodec_flush_buffers(vdec.ctx);
vdec.just_started = false;
vdec.just_finished = false;
}
else if (vdec.just_started) // deferred initialization
{
err = avformat_open_input(&vdec.fmt, NULL, av_find_input_format("mpeg"), NULL);
if (err)
@ -285,7 +290,7 @@ u32 vdecOpen(VideoDecoder* data)
av_dict_set(&opts, "refcounted_frames", "1", 0);
{
std::lock_guard<std::mutex> lock(g_mutex_avcodec_open2);
// not multithread-safe
// not multithread-safe (???)
err = avcodec_open2(vdec.ctx, codec, &opts);
}
if (err)
@ -294,8 +299,6 @@ u32 vdecOpen(VideoDecoder* data)
Emu.Pause();
break;
}
//vdec.ctx->flags |= CODEC_FLAG_TRUNCATED;
//vdec.ctx->flags2 |= CODEC_FLAG2_CHUNKS;
vdec.just_started = false;
}
@ -303,8 +306,9 @@ u32 vdecOpen(VideoDecoder* data)
while (true)
{
if (Emu.IsStopped())
if (Emu.IsStopped() || vdec.job.PeekIfExist(VdecTask()).type == vdecClose)
{
vdec.is_finished = true;
LOG_WARNING(HLE, "vdecDecodeAu: aborted");
return;
}
@ -498,7 +502,7 @@ int cellVdecClose(u32 handle)
vdec->job.Push(VdecTask(vdecClose));
while (!vdec->is_finished || !vdec->frames.IsEmpty())
while (!vdec->is_finished)
{
if (Emu.IsStopped())
{
@ -674,14 +678,14 @@ int cellVdecGetPicItem(u32 handle, mem32_t picItem_ptr)
return CELL_VDEC_ERROR_FATAL;
}
VdecFrame& vf = vdec->frames.Peek();
if (vdec->frames.IsEmpty())
{
Sleep(1);
Sleep(1); // hack
return CELL_VDEC_ERROR_EMPTY;
}
VdecFrame& vf = vdec->frames.Peek();
AVFrame& frame = *vf.data;
mem_ptr_t<CellVdecPicItem> info(vdec->memAddr + vdec->memBias);

View File

@ -697,6 +697,7 @@ public:
volatile bool is_running;
volatile bool is_finished;
bool just_started;
bool just_finished;
AVCodecContext* ctx;
AVFormatContext* fmt;
@ -735,6 +736,7 @@ public:
, is_finished(false)
, is_running(false)
, just_started(false)
, just_finished(false)
, ctx(nullptr)
, vdecCb(nullptr)
{