From ab25edfaccb5574f0c9b87870a723d7e3e22ecdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandro=20S=C3=A1nchez=20Bach?= Date: Sun, 16 Feb 2014 22:17:56 +0100 Subject: [PATCH] Few source-code improvements * Fixed identation inconsistency after last merge. * Replaced uint32_t with u32 in LinearToSwizzleAddress. * Replaced hardcoded values with defined GCM constants (in Emu/GS/GCM.h) in some switch statements. This commit won't produce any changes in the RPCS3 executable. It's just to make the code easier to read. --- rpcs3/Emu/GS/GCM.h | 51 ++++++++++++++++++++++++++++++++++ rpcs3/Emu/GS/GL/GLGSRender.cpp | 32 ++++++++++----------- rpcs3/Emu/GS/GL/GLGSRender.h | 36 ++++++++++++------------ rpcs3/Emu/GS/RSXTexture.cpp | 18 ++++++------ rpcs3/Emu/GS/RSXThread.cpp | 14 +++++----- rpcs3/Emu/GS/RSXThread.h | 19 +++++++------ 6 files changed, 109 insertions(+), 61 deletions(-) diff --git a/rpcs3/Emu/GS/GCM.h b/rpcs3/Emu/GS/GCM.h index 7c23596207..da9c068027 100644 --- a/rpcs3/Emu/GS/GCM.h +++ b/rpcs3/Emu/GS/GCM.h @@ -22,6 +22,57 @@ enum CELL_GCM_DISPLAY_FREQUENCY_DISABLE = 3, }; +// GCM Texture +enum +{ + // Format + CELL_GCM_TEXTURE_B8 = 0x81, + CELL_GCM_TEXTURE_A1R5G5B5 = 0x82, + CELL_GCM_TEXTURE_A4R4G4B4 = 0x83, + CELL_GCM_TEXTURE_R5G6B5 = 0x84, + CELL_GCM_TEXTURE_A8R8G8B8 = 0x85, + CELL_GCM_TEXTURE_COMPRESSED_DXT1 = 0x86, + CELL_GCM_TEXTURE_COMPRESSED_DXT23 = 0x87, + CELL_GCM_TEXTURE_COMPRESSED_DXT45 = 0x88, + CELL_GCM_TEXTURE_G8B8 = 0x8B, + CELL_GCM_TEXTURE_R6G5B5 = 0x8F, + CELL_GCM_TEXTURE_DEPTH24_D8 = 0x90, + CELL_GCM_TEXTURE_DEPTH24_D8_FLOAT = 0x91, + CELL_GCM_TEXTURE_DEPTH16 = 0x92, + CELL_GCM_TEXTURE_DEPTH16_FLOAT = 0x93, + CELL_GCM_TEXTURE_X16 = 0x94, + CELL_GCM_TEXTURE_Y16_X16 = 0x95, + CELL_GCM_TEXTURE_R5G5B5A1 = 0x97, + CELL_GCM_TEXTURE_COMPRESSED_HILO8 = 0x98, + CELL_GCM_TEXTURE_COMPRESSED_HILO_S8 = 0x99, + CELL_GCM_TEXTURE_W16_Z16_Y16_X16_FLOAT = 0x9A, + CELL_GCM_TEXTURE_W32_Z32_Y32_X32_FLOAT = 0x9B, + CELL_GCM_TEXTURE_X32_FLOAT = 0x9C, + CELL_GCM_TEXTURE_D1R5G5B5 = 0x9D, + CELL_GCM_TEXTURE_D8R8G8B8 = 0x9E, + CELL_GCM_TEXTURE_Y16_X16_FLOAT = 0x9F, + CELL_GCM_TEXTURE_COMPRESSED_B8R8_G8R8 = 0xAD, + CELL_GCM_TEXTURE_COMPRESSED_R8B8_R8G8 = 0xAE, + + // Format flags + CELL_GCM_TEXTURE_SZ = 0x00, + CELL_GCM_TEXTURE_LN = 0x20, + CELL_GCM_TEXTURE_NR = 0x00, + CELL_GCM_TEXTURE_UN = 0x40, +}; + +// GCM Surface +enum +{ + // Target + CELL_GCM_SURFACE_TARGET_NONE = 0, + CELL_GCM_SURFACE_TARGET_0 = 1, + CELL_GCM_SURFACE_TARGET_1 = 2, + CELL_GCM_SURFACE_TARGET_MRT1 = 0x13, + CELL_GCM_SURFACE_TARGET_MRT2 = 0x17, + CELL_GCM_SURFACE_TARGET_MRT3 = 0x1f, +}; + struct CellGcmControl { u32 put; diff --git a/rpcs3/Emu/GS/GL/GLGSRender.cpp b/rpcs3/Emu/GS/GL/GLGSRender.cpp index 068a0f6a2e..9bfaccc8dc 100644 --- a/rpcs3/Emu/GS/GL/GLGSRender.cpp +++ b/rpcs3/Emu/GS/GL/GLGSRender.cpp @@ -556,29 +556,29 @@ void GLGSRender::WriteBuffers() switch(m_surface_colour_target) { - case 0x0: + case CELL_GCM_SURFACE_TARGET_NONE: return; - case 0x1: + case CELL_GCM_SURFACE_TARGET_0: WriteColourBufferA(); break; - case 0x2: + case CELL_GCM_SURFACE_TARGET_1: WriteColourBufferB(); break; - case 0x13: + case CELL_GCM_SURFACE_TARGET_MRT1: WriteColourBufferA(); WriteColourBufferB(); break; - case 0x17: + case CELL_GCM_SURFACE_TARGET_MRT2: WriteColourBufferA(); WriteColourBufferB(); WriteColourBufferC(); break; - case 0x1f: + case CELL_GCM_SURFACE_TARGET_MRT3: WriteColourBufferA(); WriteColourBufferB(); WriteColourBufferC(); @@ -726,26 +726,26 @@ void GLGSRender::ExecCMD() switch(m_surface_colour_target) { - case 0x0: + case CELL_GCM_SURFACE_TARGET_NONE: break; - case 0x1: + case CELL_GCM_SURFACE_TARGET_0: glDrawBuffer(draw_buffers[0]); break; - case 0x2: + case CELL_GCM_SURFACE_TARGET_1: glDrawBuffer(draw_buffers[1]); break; - case 0x13: + case CELL_GCM_SURFACE_TARGET_MRT1: glDrawBuffers(2, draw_buffers); break; - case 0x17: + case CELL_GCM_SURFACE_TARGET_MRT2: glDrawBuffers(3, draw_buffers); break; - case 0x1f: + case CELL_GCM_SURFACE_TARGET_MRT3: glDrawBuffers(4, draw_buffers); break; @@ -1147,12 +1147,10 @@ void GLGSRender::Flip() } } -uint32_t LinearToSwizzleAddress( - uint32_t x, uint32_t y, uint32_t z, - uint32_t log2_width, uint32_t log2_height, uint32_t log2_depth) +u32 LinearToSwizzleAddress(u32 x, u32 y, u32 z, u32 log2_width, u32 log2_height, u32 log2_depth) { - uint32_t offset = 0; - uint32_t shift_count = 0; + u32 offset = 0; + u32 shift_count = 0; while(log2_width | log2_height | log2_depth){ if(log2_width){ offset |= (x & 0x01) << shift_count; diff --git a/rpcs3/Emu/GS/GL/GLGSRender.h b/rpcs3/Emu/GS/GL/GLGSRender.h index d685271871..b0ea63df71 100644 --- a/rpcs3/Emu/GS/GL/GLGSRender.h +++ b/rpcs3/Emu/GS/GL/GLGSRender.h @@ -13,9 +13,7 @@ extern GLenum g_last_gl_error; void printGlError(GLenum err, const char* situation); -uint32_t LinearToSwizzleAddress( - uint32_t x, uint32_t y, uint32_t z, - uint32_t log2_width, uint32_t log2_height, uint32_t log2_depth); +u32 LinearToSwizzleAddress(u32 x, u32 y, u32 z, u32 log2_width, u32 log2_height, u32 log2_depth); #if RSX_DEBUG #define checkForGlError(sit) if((g_last_gl_error = glGetError()) != GL_NO_ERROR) printGlError(g_last_gl_error, sit) @@ -79,7 +77,7 @@ public: checkForGlError("GLTexture::Init() -> glBindTexture"); int format = tex.GetFormat() & ~(0x20 | 0x40); - bool is_swizzled = (tex.GetFormat() & 0x20) == 0; + bool is_swizzled = !(tex.GetFormat() & CELL_GCM_TEXTURE_LN); glPixelStorei(GL_PACK_ALIGNMENT, tex.m_pitch); char* pixels = (char*)Memory.GetMemFromAddr(GetAddress(tex.GetOffset(), tex.GetLocation())); @@ -87,7 +85,7 @@ public: switch(format) { - case 0x81: + case CELL_GCM_TEXTURE_B8: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_BLUE, GL_UNSIGNED_BYTE, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D"); @@ -99,15 +97,15 @@ public: checkForGlError("GLTexture::Init() -> glTexParameteri"); break; - case 0x85: + case CELL_GCM_TEXTURE_A8R8G8B8: if(is_swizzled) { - uint32_t *src, *dst; - uint32_t log2width, log2height; + u32 *src, *dst; + u32 log2width, log2height; unswizzledPixels = (char*)malloc(tex.GetWidth() * tex.GetHeight() * 4); - src = (uint32_t*)pixels; - dst = (uint32_t*)unswizzledPixels; + src = (u32*)pixels; + dst = (u32*)unswizzledPixels; log2width = log(tex.GetWidth())/log(2); log2height = log(tex.GetHeight())/log(2); @@ -125,7 +123,7 @@ public: checkForGlError("GLTexture::Init() -> glTexImage2D"); break; - case 0x86: + case CELL_GCM_TEXTURE_COMPRESSED_DXT1: { u32 size = ((tex.GetWidth() + 3) / 4) * ((tex.GetHeight() + 3) / 4) * 8; @@ -134,7 +132,7 @@ public: } break; - case 0x87: + case CELL_GCM_TEXTURE_COMPRESSED_DXT23: { u32 size = ((tex.GetWidth() + 3) / 4) * ((tex.GetHeight() + 3) / 4) * 16; @@ -143,7 +141,7 @@ public: } break; - case 0x88: + case CELL_GCM_TEXTURE_COMPRESSED_DXT45: { u32 size = ((tex.GetWidth() + 3) / 4) * ((tex.GetHeight() + 3) / 4) * 16; @@ -152,7 +150,7 @@ public: } break; - case 0x94: + case CELL_GCM_TEXTURE_X16: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_RED, GL_SHORT, pixels); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_ONE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_ONE); @@ -161,12 +159,12 @@ public: checkForGlError("GLTexture::Init() -> glTexImage2D"); break; - case 0x9a: + case CELL_GCM_TEXTURE_W16_Z16_Y16_X16_FLOAT: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_BGRA, GL_HALF_FLOAT, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D"); break; - case 0x9e: + case CELL_GCM_TEXTURE_D8R8G8B8: { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D"); @@ -255,7 +253,7 @@ public: void Save(RSXTexture& tex, const wxString& name) { - if(!m_id || !tex.GetOffset() || !tex.GetWidth() || !tex.GetHeight()) return; + if(!m_id || !tex.GetOffset() || !tex.GetWidth() || !tex.GetHeight()) return; u32* alldata = new u32[tex.GetWidth() * tex.GetHeight()]; @@ -263,11 +261,11 @@ public: switch(tex.GetFormat() & ~(0x20 | 0x40)) { - case 0x81: + case CELL_GCM_TEXTURE_B8: glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, alldata); break; - case 0x85: + case CELL_GCM_TEXTURE_A8R8G8B8: glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, alldata); break; diff --git a/rpcs3/Emu/GS/RSXTexture.cpp b/rpcs3/Emu/GS/RSXTexture.cpp index 8db5499a02..9ac888c8e9 100644 --- a/rpcs3/Emu/GS/RSXTexture.cpp +++ b/rpcs3/Emu/GS/RSXTexture.cpp @@ -42,37 +42,37 @@ void RSXTexture::Init() u32 RSXTexture::GetOffset() const { - return methodRegisters[NV4097_SET_TEXTURE_OFFSET + (m_index*32)]; + return methodRegisters[NV4097_SET_TEXTURE_OFFSET + (m_index*32)]; } u8 RSXTexture::GetLocation() const { - return (methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*32)] & 0x3) - 1; + return (methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*32)] & 0x3) - 1; } bool RSXTexture::isCubemap() const { - return ((methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*32)] >> 2) & 0x1); + return ((methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*32)] >> 2) & 0x1); } u8 RSXTexture::GetBorderType() const { - return ((methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*32)] >> 3) & 0x1); + return ((methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*32)] >> 3) & 0x1); } u8 RSXTexture::GetDimension() const { - return ((methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*32)] >> 4) & 0xf); + return ((methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*32)] >> 4) & 0xf); } u8 RSXTexture::GetFormat() const { - return ((methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*32)] >> 8) & 0xff); + return ((methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*32)] >> 8) & 0xff); } u16 RSXTexture::Getmipmap() const { - return ((methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*32)] >> 16) & 0xffff); + return ((methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*32)] >> 16) & 0xffff); } u8 RSXTexture::GetWrapS() const @@ -197,6 +197,6 @@ u16 RSXTexture::GetHeight() const void RSXTexture::SetControl3(u16 depth, u32 pitch) { - m_depth = depth; - m_pitch = pitch; + m_depth = depth; + m_pitch = pitch; } \ No newline at end of file diff --git a/rpcs3/Emu/GS/RSXThread.cpp b/rpcs3/Emu/GS/RSXThread.cpp index 9556370bf9..d88e4d3fb8 100644 --- a/rpcs3/Emu/GS/RSXThread.cpp +++ b/rpcs3/Emu/GS/RSXThread.cpp @@ -1378,7 +1378,7 @@ void RSXThread::End() void RSXThread::Task() { - u8 inc; + u8 inc; ConLog.Write("RSX thread entry"); OnInitThread(); @@ -1387,7 +1387,7 @@ void RSXThread::Task() { wxCriticalSectionLocker lock(m_cs_main); - inc=1; + inc=1; u32 put, get; se_t::func(put, std::atomic_load((volatile std::atomic*)((u8*)m_ctrl + offsetof(CellGcmControl, put)))); @@ -1439,7 +1439,7 @@ void RSXThread::Task() if(cmd & CELL_GCM_METHOD_FLAG_NON_INCREMENT) { //ConLog.Warning("non increment cmd! 0x%x", cmd); - inc=0; + inc=0; } if(cmd == 0) @@ -1449,10 +1449,10 @@ void RSXThread::Task() continue; } - for(int i=0; i