From 096c9316b80e45a1baa9eb47d9d50f0625fa48ea Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Mon, 23 Jan 2017 19:14:43 +0100 Subject: [PATCH] gsdx cl: fix various compilation issues and a couple of warnings I didn't fix all the warnings (purpose was to realign code with "recent" update) Linux note: only miss 2 major items * res/tfx.cl loading * device descriptor * And various bug fixes ;) --- plugins/GSdx/GSRendererCL.cpp | 48 ++++++++++++++++++++++++----------- plugins/GSdx/GSRendererCL.h | 2 +- plugins/GSdx/GSUtil.cpp | 7 +++-- 3 files changed, 39 insertions(+), 18 deletions(-) diff --git a/plugins/GSdx/GSRendererCL.cpp b/plugins/GSdx/GSRendererCL.cpp index f6615ec0f0..d5896fd7c7 100644 --- a/plugins/GSdx/GSRendererCL.cpp +++ b/plugins/GSdx/GSRendererCL.cpp @@ -74,7 +74,7 @@ typedef struct #pragma pack(pop) -static GSVector4 GSRendererCL::m_pos_scale; +GSVector4 GSRendererCL::m_pos_scale; void GSRendererCL::InitVectors() { @@ -98,7 +98,8 @@ GSRendererCL::GSRendererCL() m_tc_pages[i] = GSVector4i::xffffffff(); } - memset(m_rw_pages_rendering, 0, sizeof(m_rw_pages_rendering)); + for (auto& page_ref : m_rw_pages_rendering) + page_ref = 0; #define InitCVB(P) \ m_cvb[P][0][0] = &GSRendererCL::ConvertVertexBuffer; \ @@ -573,7 +574,10 @@ void GSRendererCL::Sync(int reason) m_rw_pages[1][i] = GSVector4i::zero(); } - for(int i = 0; i < MAX_PAGES; i++) ASSERT(m_rw_pages_rendering[i] == 0); +#ifndef NDEBUG + for(auto page_ref : m_rw_pages_rendering) + ASSERT(page_ref == 0); +#endif m_synced = true; } @@ -793,7 +797,7 @@ void GSRendererCL::Enqueue() auto job = next++; uint32 cur_prim_count = (*job)->prim_count; - uint32 next_prim_count = next != m_jobs.end() ? (*next)->prim_count : 0; + //uint32 next_prim_count = next != m_jobs.end() ? (*next)->prim_count : 0; total_prim_count += cur_prim_count; @@ -1234,7 +1238,11 @@ void GSRendererCL::UsePages(uint32* p) { for(int index = 0; index < 32; index++) { - _InterlockedIncrement16((short*)&m_rw_pages_rendering[index | o] + l); + //_InterlockedIncrement16((short*)&m_rw_pages_rendering[index | o] + l); + if (l == 0) + m_rw_pages_rendering[index | o] += 1; + else + m_rw_pages_rendering[index | o] += 0x10000; *p++ = index | o; } @@ -1245,7 +1253,11 @@ void GSRendererCL::UsePages(uint32* p) { mask &= ~(1 << index); - _InterlockedIncrement16((short*)&m_rw_pages_rendering[index | o] + l); + //_InterlockedIncrement16((short*)&m_rw_pages_rendering[index | o] + l); + if (l == 0) + m_rw_pages_rendering[index | o] += 1; + else + m_rw_pages_rendering[index | o] += 0x10000; *p++ = index | o; } @@ -1265,14 +1277,16 @@ void GSRendererCL::ReleasePages(uint32* pages) for(; *p != GSOffset::EOP; p++) { - _InterlockedDecrement16((short*)&m_rw_pages_rendering[*p] + 0); + m_rw_pages_rendering[*p] -= 1; + //_InterlockedDecrement16((short*)&m_rw_pages_rendering[*p] + 0); } p++; for(; *p != GSOffset::EOP; p++) { - _InterlockedDecrement16((short*)&m_rw_pages_rendering[*p] + 1); + m_rw_pages_rendering[*p] -= 0x10000; + //_InterlockedDecrement16((short*)&m_rw_pages_rendering[*p] + 1); } } @@ -1439,7 +1453,7 @@ bool GSRendererCL::SetupParameter(TFXJob* job, TFXParameter* pb, GSVertexCL* ver bool mipmap = IsMipMapActive(); - GIFRegTEX0 TEX0 = m_context->GetSizeFixedTEX0(m_vt.m_min.t.xyxy(m_vt.m_max.t), m_vt.IsLinear(), mipmap); + GIFRegTEX0 TEX0 = m_context->GetSizeFixedTEX0(s_n, m_vt.m_min.t.xyxy(m_vt.m_max.t), m_vt.IsLinear(), mipmap); GSVector4i r; @@ -1902,7 +1916,7 @@ GSRendererCL::CL::CL() if(devs.empty()) { - throw new std::exception("OpenCL device not found"); + throw new std::runtime_error("OpenCL device not found"); } vector tmp; @@ -1917,10 +1931,14 @@ GSRendererCL::CL::CL() vector buff; +#ifdef _WIN32 if(theApp.LoadResource(IDR_TFX_CL, buff)) { kernel_str = std::string((const char*)buff.data(), buff.size()); } +#else + ASSERT(0); +#endif vb.head = vb.tail = vb.size = 0; ib.head = ib.tail = ib.size = 0; @@ -2001,7 +2019,7 @@ cl::Kernel GSRendererCL::CL::Build(const char* entry, ostringstream& opt) if(f != NULL) { - fseek(f, 0, SEEK_END); + fseek(f, 0, SEEK_END); long size = ftell(f); pair b(new char[size], size); fseek(f, 0, SEEK_SET); @@ -2076,7 +2094,7 @@ cl::Kernel GSRendererCL::CL::Build(const char* entry, ostringstream& opt) vector sizes = program.getInfo(); vector binaries = program.getInfo(); - for(int i = 0; i < binaries.size(); i++) + for(size_t i = 0; i < binaries.size(); i++) { string path = devs[i].tmppath + "/" + entry; @@ -2130,7 +2148,7 @@ cl::Kernel& GSRendererCL::CL::GetPrimKernel(const PrimSelector& sel) char entry[256]; - sprintf(entry, "prim_%02x", sel); + sprintf(entry, "prim_%02x", sel.key); ostringstream opt; @@ -2157,7 +2175,7 @@ cl::Kernel& GSRendererCL::CL::GetTileKernel(const TileSelector& sel) char entry[256]; - sprintf(entry, "tile_%02x", sel); + sprintf(entry, "tile_%02x", sel.key); ostringstream opt; @@ -2186,7 +2204,7 @@ cl::Kernel& GSRendererCL::CL::GetTFXKernel(const TFXSelector& sel) char entry[256]; - sprintf(entry, "tfx_%016llx", sel); + sprintf(entry, "tfx_%016llx", sel.key); ostringstream opt; diff --git a/plugins/GSdx/GSRendererCL.h b/plugins/GSdx/GSRendererCL.h index 6f656e75a6..e85d598869 100644 --- a/plugins/GSdx/GSRendererCL.h +++ b/plugins/GSdx/GSRendererCL.h @@ -248,7 +248,7 @@ protected: GSVector4i m_tc_pages[4]; // invalidated texture cache pages (split this into 8:24?) // TODO: this should be block level, too many overlaps inside pages with render targets GSVector4i m_tmp_pages[4]; uint32 m_tmp_pages2[MAX_PAGES + 1]; - uint32 m_rw_pages_rendering[512]; // pages that are currently in-use + std::array, 512> m_rw_pages_rendering; // pages that are currently in-use void Reset(); void VSync(int field); diff --git a/plugins/GSdx/GSUtil.cpp b/plugins/GSdx/GSUtil.cpp index d7d257553f..07f7c4075f 100644 --- a/plugins/GSdx/GSUtil.cpp +++ b/plugins/GSdx/GSUtil.cpp @@ -285,8 +285,7 @@ void GSUtil::GetDeviceDescs(list& dl) desc.name = GetDeviceUniqueName(device); desc.version = major * 100 + minor * 10; - // TODO: linux - +#ifdef _WIN32 char* buff = new char[MAX_PATH + 1]; GetTempPath(MAX_PATH, buff); desc.tmppath = string(buff) + "/" + desc.name; @@ -303,6 +302,10 @@ void GSUtil::GetDeviceDescs(list& dl) hFind = FindFirstFile(desc.tmppath.c_str(), &FindFileData); if(hFind != INVALID_HANDLE_VALUE) FindClose(hFind); else CreateDirectory(desc.tmppath.c_str(), NULL); +#else + // TODO: linux + ASSERT(0); +#endif dl.push_back(desc); }