From 8987350b5b4f96b12856fe53f26f59bd5cf0cc1c Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sun, 29 Jun 2014 07:21:57 +0400 Subject: [PATCH] Small changes 2 --- Utilities/SQueue.h | 47 ++++++++++++----------- rpcs3/Emu/GS/GL/GLGSRender.cpp | 10 +++-- rpcs3/Emu/GS/RSXThread.cpp | 2 + rpcs3/Emu/SysCalls/Modules/cellAdec.cpp | 27 ++++++++----- rpcs3/Emu/SysCalls/Modules/cellAdec.h | 2 + rpcs3/Emu/SysCalls/Modules/cellDmux.cpp | 2 +- rpcs3/Emu/SysCalls/Modules/cellGame.cpp | 19 +++++++-- rpcs3/Emu/SysCalls/Modules/cellGcmSys.cpp | 7 ++-- rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp | 13 +++++-- rpcs3/Emu/SysCalls/Modules/cellPngDec.h | 13 ++++++- rpcs3/Emu/SysCalls/Modules/cellResc.cpp | 7 ++-- rpcs3/Emu/SysCalls/Modules/cellVdec.cpp | 32 ++++++++------- rpcs3/Emu/SysCalls/Modules/cellVdec.h | 2 + 13 files changed, 118 insertions(+), 65 deletions(-) diff --git a/Utilities/SQueue.h b/Utilities/SQueue.h index 4e3b317a9d..52b68979f0 100644 --- a/Utilities/SQueue.h +++ b/Utilities/SQueue.h @@ -4,8 +4,6 @@ template 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 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 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 lock(m_mutex); + return m_count; + } + + u32 GetCountUnsafe() { return m_count; } - volatile bool IsEmpty() // may be thread unsafe + bool IsEmpty() { + std::lock_guard lock(m_mutex); return !m_count; } void Clear() { std::lock_guard 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 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 lock(m_mutex); + if (m_count <= pos) + { + return def; + } + else + { + return m_data[(m_pos + pos) % SQSize]; + } + } }; diff --git a/rpcs3/Emu/GS/GL/GLGSRender.cpp b/rpcs3/Emu/GS/GL/GLGSRender.cpp index 9309eae93c..c7f6f80404 100644 --- a/rpcs3/Emu/GS/GL/GLGSRender.cpp +++ b/rpcs3/Emu/GS/GL/GLGSRender.cpp @@ -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"); diff --git a/rpcs3/Emu/GS/RSXThread.cpp b/rpcs3/Emu/GS/RSXThread.cpp index a7f2d30286..614bdafe85 100644 --- a/rpcs3/Emu/GS/RSXThread.cpp +++ b/rpcs3/Emu/GS/RSXThread.cpp @@ -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", [&]() diff --git a/rpcs3/Emu/SysCalls/Modules/cellAdec.cpp b/rpcs3/Emu/SysCalls/Modules/cellAdec.cpp index aa72d95f64..fec90b45d1 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellAdec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellAdec.cpp @@ -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 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 pcm(adec->memAddr + adec->memBias); diff --git a/rpcs3/Emu/SysCalls/Modules/cellAdec.h b/rpcs3/Emu/SysCalls/Modules/cellAdec.h index 88a6e6bf47..65ce820f13 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellAdec.h +++ b/rpcs3/Emu/SysCalls/Modules/cellAdec.h @@ -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) { diff --git a/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp b/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp index ee799261b7..377ebf22dc 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp @@ -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 code; diff --git a/rpcs3/Emu/SysCalls/Modules/cellGame.cpp b/rpcs3/Emu/SysCalls/Modules/cellGame.cpp index 7a1a42d02a..9a7471f63d 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellGame.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellGame.cpp @@ -119,6 +119,15 @@ struct CellGameContentSize be_t 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 contentInfoPath, mem_list_ptr_t 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 init, mem_list_ptr_t tmp_contentInfoPath, mem_list_ptr_t 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; } diff --git a/rpcs3/Emu/SysCalls/Modules/cellGcmSys.cpp b/rpcs3/Emu/SysCalls/Modules/cellGcmSys.cpp index 6d22b47da8..f91232d0c4 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellGcmSys.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellGcmSys.cpp @@ -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() diff --git a/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp b/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp index ebdce664a4..5f61fb8aa1 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp @@ -98,9 +98,16 @@ int cellPngDecExtOpen(u32 mainHandle, mem32_t subHandle, mem_ptr_tWarning("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 streamInfo; + MemoryAllocator 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); } diff --git a/rpcs3/Emu/SysCalls/Modules/cellPngDec.h b/rpcs3/Emu/SysCalls/Modules/cellPngDec.h index 9db3ac8bcb..b93f82ba8e 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellPngDec.h +++ b/rpcs3/Emu/SysCalls/Modules/cellPngDec.h @@ -125,9 +125,20 @@ struct CellPngDecMainHandle be_t threadOutParam; }; +struct CellPngDecStrmInfo +{ + be_t decodedStrmSize; +}; + +struct CellPngDecStrmParam +{ + be_t strmPtr; + be_t strmSize; +}; + struct CellPngDecCbCtrlStrm { - be_t cbCtrlStrmFunc_addr; + mem_func_beptr_t strmInfo, mem_ptr_t strmParam, u32 cbCtrlStrmArg)> cbCtrlStrmFunc; be_t cbCtrlStrmArg; }; diff --git a/rpcs3/Emu/SysCalls/Modules/cellResc.cpp b/rpcs3/Emu/SysCalls/Modules/cellResc.cpp index 05381883e0..c8a84b13ad 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellResc.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellResc.cpp @@ -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() diff --git a/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp b/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp index 29b12f10f7..c1551e842e 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp @@ -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 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 info(vdec->memAddr + vdec->memBias); diff --git a/rpcs3/Emu/SysCalls/Modules/cellVdec.h b/rpcs3/Emu/SysCalls/Modules/cellVdec.h index 7c9508d049..4731d50e3d 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellVdec.h +++ b/rpcs3/Emu/SysCalls/Modules/cellVdec.h @@ -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) {