From c515cb8fb6d8722faad980a82dfe278da6471687 Mon Sep 17 00:00:00 2001 From: elisha464 Date: Wed, 5 Feb 2014 22:48:30 +0200 Subject: [PATCH] more rsx texture (address, control0, image rect) --- rpcs3/Emu/GS/GL/GLGSRender.h | 54 ++++++------- rpcs3/Emu/GS/RSXTexture.cpp | 142 +++++++++++++++++++++++------------ rpcs3/Emu/GS/RSXThread.cpp | 65 ++-------------- rpcs3/Emu/GS/RSXThread.h | 64 ++++++++-------- 4 files changed, 159 insertions(+), 166 deletions(-) diff --git a/rpcs3/Emu/GS/GL/GLGSRender.h b/rpcs3/Emu/GS/GL/GLGSRender.h index df3745444d..7a174ec7d6 100644 --- a/rpcs3/Emu/GS/GL/GLGSRender.h +++ b/rpcs3/Emu/GS/GL/GLGSRender.h @@ -53,8 +53,10 @@ public: case 2: return GL_MIRRORED_REPEAT; case 3: return GL_CLAMP_TO_EDGE; case 4: return GL_CLAMP_TO_BORDER; - case 5: return GL_CLAMP_TO_EDGE;//GL_CLAMP; - //case 6: return GL_MIRROR_CLAMP_TO_EDGE_EXT; + case 5: return GL_CLAMP_TO_EDGE; + case 6: return GL_MIRROR_CLAMP_TO_EDGE_EXT; + case 7: return GL_MIRROR_CLAMP_TO_BORDER_EXT; + case 8: return GL_MIRROR_CLAMP_EXT; } ConLog.Error("Texture wrap error: bad wrap (%d).", wrap); @@ -83,7 +85,7 @@ public: switch(format) { case 0x81: - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.m_width, tex.m_height, 0, GL_BLUE, GL_UNSIGNED_BYTE, pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_BLUE, GL_UNSIGNED_BYTE, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D"); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_BLUE); @@ -95,39 +97,39 @@ public: break; case 0x85: - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.m_width, tex.m_height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, pixels); + 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"); break; case 0x86: { - u32 size = ((tex.m_width + 3) / 4) * ((tex.m_height + 3) / 4) * 8; + u32 size = ((tex.GetWidth() + 3) / 4) * ((tex.GetHeight() + 3) / 4) * 8; - glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, tex.m_width, tex.m_height, 0, size, pixels); + glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, tex.GetWidth(), tex.GetHeight(), 0, size, pixels); checkForGlError("GLTexture::Init() -> glCompressedTexImage2D"); } break; case 0x87: { - u32 size = ((tex.m_width + 3) / 4) * ((tex.m_height + 3) / 4) * 16; + u32 size = ((tex.GetWidth() + 3) / 4) * ((tex.GetHeight() + 3) / 4) * 16; - glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, tex.m_width, tex.m_height, 0, size, pixels); + glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, tex.GetWidth(), tex.GetHeight(), 0, size, pixels); checkForGlError("GLTexture::Init() -> glCompressedTexImage2D"); } break; case 0x88: { - u32 size = ((tex.m_width + 3) / 4) * ((tex.m_height + 3) / 4) * 16; + u32 size = ((tex.GetWidth() + 3) / 4) * ((tex.GetHeight() + 3) / 4) * 16; - glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, tex.m_width, tex.m_height, 0, size, pixels); + glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, tex.GetWidth(), tex.GetHeight(), 0, size, pixels); checkForGlError("GLTexture::Init() -> glCompressedTexImage2D"); } break; case 0x94: - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.m_width, tex.m_height, 0, GL_RED, GL_SHORT, pixels); + 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); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_ONE); @@ -136,13 +138,13 @@ public: break; case 0x9a: - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.m_width, tex.m_height, 0, GL_BGRA, GL_HALF_FLOAT, pixels); + 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: { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.m_width, tex.m_height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, pixels); + 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"); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ONE); } @@ -189,16 +191,16 @@ public: GL_ALWAYS, }; - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GetGlWrap(tex.m_wraps)); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GetGlWrap(tex.m_wrapt)); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GetGlWrap(tex.m_wrapr)); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, gl_tex_zfunc[tex.m_zfunc]); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GetGlWrap(tex.GetWrapS())); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GetGlWrap(tex.GetWrapT())); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GetGlWrap(tex.GetWrapR())); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, gl_tex_zfunc[tex.GetZfunc()]); checkForGlError("GLTexture::Init() -> parameters1"); glTexEnvi(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, tex.m_bias); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, tex.m_minlod); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, tex.m_maxlod); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, (tex.GetMinLOD() >> 8)); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, (tex.GetMaxLOD() >> 8)); checkForGlError("GLTexture::Init() -> parameters2"); @@ -224,9 +226,9 @@ public: void Save(RSXTexture& tex, const wxString& name) { - if(!m_id || !tex.GetOffset() || !tex.m_width || !tex.m_height) return; + if(!m_id || !tex.GetOffset() || !tex.GetWidth() || !tex.GetHeight()) return; - u32* alldata = new u32[tex.m_width * tex.m_height]; + u32* alldata = new u32[tex.GetWidth() * tex.GetHeight()]; Bind(); @@ -247,15 +249,15 @@ public: { wxFile f(name + ".raw", wxFile::write); - f.Write(alldata, tex.m_width * tex.m_height * 4); + f.Write(alldata, tex.GetWidth() * tex.GetHeight() * 4); } - u8* data = new u8[tex.m_width * tex.m_height * 3]; - u8* alpha = new u8[tex.m_width * tex.m_height]; + u8* data = new u8[tex.GetWidth() * tex.GetHeight() * 3]; + u8* alpha = new u8[tex.GetWidth() * tex.GetHeight()]; u8* src = (u8*)alldata; u8* dst_d = data; u8* dst_a = alpha; - for(u32 i=0; i> 16) & 0xffff); } -void RSXTexture::SetRect(const u32 width, const u32 height) +u8 RSXTexture::GetWrapS() const { - m_width = width; - m_height = height; + return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*4)]) & 0xf); } -void RSXTexture::SetAddress(u8 wraps, u8 wrapt, u8 wrapr, u8 unsigned_remap, u8 zfunc, u8 gamma, u8 aniso_bias, u8 signed_remap) +u8 RSXTexture::GetWrapT() const { - m_wraps = wraps; - m_wrapt = wrapt; - m_wrapr = wrapr; - m_unsigned_remap = unsigned_remap; - m_zfunc = zfunc; - m_gamma = gamma; - m_aniso_bias = aniso_bias; - m_signed_remap = signed_remap; + return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*4)] >> 8) & 0xf); +} + +u8 RSXTexture::GetWrapR() const +{ + return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*4)] >> 16) & 0xf); +} + +u8 RSXTexture::GetUnsignedRemap() const +{ + return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*4)] >> 12) & 0xf); +} + +u8 RSXTexture::GetZfunc() const +{ + return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*4)] >> 28) & 0xf); +} + +u8 RSXTexture::GetGamma() const +{ + return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*4)] >> 20) & 0xf); +} + +u8 RSXTexture::GetAnisoBias() const +{ + return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*4)] >> 4) & 0xf); +} + +u8 RSXTexture::GetSignedRemap() const +{ + return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*4)] >> 24) & 0xf); +} + +bool RSXTexture::IsEnabled() const +{ + return ((methodRegisters[NV4097_SET_TEXTURE_CONTROL0 + (m_index*4)] >> 31) & 0x1); +} + +u16 RSXTexture::GetMinLOD() const +{ + return ((methodRegisters[NV4097_SET_TEXTURE_CONTROL0 + (m_index*4)] >> 19) & 0xfff); +} + +u16 RSXTexture::GetMaxLOD() const +{ + return ((methodRegisters[NV4097_SET_TEXTURE_CONTROL0 + (m_index*4)] >> 7) & 0xfff); +} + +u8 RSXTexture::GetMaxAniso() const +{ + return ((methodRegisters[NV4097_SET_TEXTURE_CONTROL0 + (m_index*4)] >> 4) & 0x7); +} + +bool RSXTexture::IsAlphaKillEnabled() const +{ + return ((methodRegisters[NV4097_SET_TEXTURE_CONTROL0 + (m_index*4)] >> 2) & 0x1); +} + +u16 RSXTexture::GetWidth() const +{ + return ((methodRegisters[NV4097_SET_TEXTURE_IMAGE_RECT + (m_index*4)] >> 16) & 0xffff); +} + +u16 RSXTexture::GetHeight() const +{ + return ((methodRegisters[NV4097_SET_TEXTURE_IMAGE_RECT + (m_index*4)]) & 0xffff); } void RSXTexture::SetControl0(const bool enable, const u16 minlod, const u16 maxlod, const u8 maxaniso) { - m_enabled = enable; - m_minlod = minlod; - m_maxlod = maxlod; - m_maxaniso = maxaniso; } void RSXTexture::SetControl1(u32 remap) @@ -123,14 +175,4 @@ void RSXTexture::SetFilter(u16 bias, u8 min, u8 mag, u8 conv, u8 a_signed, u8 r_ m_r_signed = r_signed; m_g_signed = g_signed; m_b_signed = b_signed; -} - -wxSize RSXTexture::GetRect() const -{ - return wxSize(m_width, m_height); -} - -bool RSXTexture::IsEnabled() const -{ - return m_enabled; } \ No newline at end of file diff --git a/rpcs3/Emu/GS/RSXThread.cpp b/rpcs3/Emu/GS/RSXThread.cpp index 0d82d494f6..346a1d5728 100644 --- a/rpcs3/Emu/GS/RSXThread.cpp +++ b/rpcs3/Emu/GS/RSXThread.cpp @@ -200,33 +200,6 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, mem32_ptr_t& args, const u3 case_16(NV4097_SET_TEXTURE_OFFSET, 0x20): { - RSXTexture& tex = m_textures[index]; - const u32 offset = ARGS(0); - u32 a1 = ARGS(1); - u8 location = (a1 & 0x3) - 1; - const bool cubemap = (a1 >> 2) & 0x1; - const u8 dimension = (a1 >> 4) & 0xf; - const u8 format = (a1 >> 8) & 0xff; - const u16 mipmap = (a1 >> 16) & 0xffff; - CMD_LOG("index = %d, offset=0x%x, location=0x%x, cubemap=0x%x, dimension=0x%x, format=0x%x, mipmap=0x%x", - index, offset, location, cubemap, dimension, format, mipmap); - - if(location == 2) - { - ConLog.Error("Bad texture location."); - location = 1; - } - u32 tex_addr = GetAddress(offset, location); - if(!Memory.IsGoodAddr(tex_addr)) - ConLog.Error("Bad texture[%d] addr = 0x%x #offset = 0x%x, location=%d", index, tex_addr, offset, location); - //ConLog.Warning("texture addr = 0x%x #offset = 0x%x, location=%d", tex_addr, offset, location); - - if(!tex.m_width || !tex.m_height) - { - gcmBuffer* buffers = (gcmBuffer*)Memory.GetMemFromAddr(m_gcm_buffers_addr); - if(!tex.m_width) tex.m_width = re(buffers[m_gcm_current_buffer].width); - if(!tex.m_height) tex.m_height = re(buffers[m_gcm_current_buffer].height); - } } break; @@ -341,19 +314,6 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, mem32_ptr_t& args, const u3 case_16(NV4097_SET_TEXTURE_ADDRESS, 0x20): { - RSXTexture& tex = m_textures[index]; - - u32 a0 = ARGS(0); - u8 wraps = a0 & 0xf; - u8 aniso_bias = (a0 >> 4) & 0xf; - u8 wrapt = (a0 >> 8) & 0xf; - u8 unsigned_remap = (a0 >> 12) & 0xf; - u8 wrapr = (a0 >> 16) & 0xf; - u8 gamma = (a0 >> 20) & 0xf; - u8 signed_remap = (a0 >> 24) & 0xf; - u8 zfunc = a0 >> 28; - - tex.SetAddress(wraps, wrapt, wrapr, unsigned_remap, zfunc, gamma, aniso_bias, signed_remap); } break; @@ -363,26 +323,6 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, mem32_ptr_t& args, const u3 case_16(NV4097_SET_TEXTURE_IMAGE_RECT, 32): { - RSXTexture& tex = m_textures[index]; - - u16 height = ARGS(0) & 0xffff; - u16 width = ARGS(0) >> 16; - CMD_LOG("width=%d, height=%d", width, height); - - if(!width || !height) - { - ConLog.Warning("Bad texture rect: %dx%d (%dx%d)", width, height, tex.m_width, tex.m_height); - for(int i=0; i