From 3de47c201c7c82b54c259cff61b2f0f8e92b3d76 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Thu, 8 Oct 2015 15:53:21 +0200 Subject: [PATCH] RSX: Create a rsx namespace. Put get_address inside. --- rpcs3/Emu/RSX/Common/TextureUtils.cpp | 30 +- rpcs3/Emu/RSX/Common/TextureUtils.h | 4 +- rpcs3/Emu/RSX/D3D12/D3D12Buffer.cpp | 12 +- rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp | 36 +- rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp | 10 +- rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp | 74 +- rpcs3/Emu/RSX/GL/GLGSRender.cpp | 164 ++-- rpcs3/Emu/RSX/GL/GLGSRender.h | 6 +- rpcs3/Emu/RSX/RSXTexture.cpp | 821 +++++++++--------- rpcs3/Emu/RSX/RSXTexture.h | 206 ++--- rpcs3/Emu/RSX/RSXThread.cpp | 81 +- rpcs3/Emu/RSX/RSXThread.h | 34 +- rpcs3/Gui/RSXDebugger.cpp | 48 +- 13 files changed, 781 insertions(+), 745 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/TextureUtils.cpp b/rpcs3/Emu/RSX/Common/TextureUtils.cpp index 6d6cf383f8..e763ae0a25 100644 --- a/rpcs3/Emu/RSX/Common/TextureUtils.cpp +++ b/rpcs3/Emu/RSX/Common/TextureUtils.cpp @@ -263,12 +263,12 @@ write16bX4TexelsGeneric(const char *src, char *dst, size_t widthInBlock, size_t } -size_t getPlacedTextureStorageSpace(const RSXTexture &texture, size_t rowPitchAlignement) +size_t getPlacedTextureStorageSpace(const rsx::texture &texture, size_t rowPitchAlignement) { - size_t w = texture.GetWidth(), h = texture.GetHeight(); + size_t w = texture.width(), h = texture.height(); size_t blockSizeInByte, blockWidthInPixel, blockHeightInPixel; - int format = texture.GetFormat() & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN); + int format = texture.format() & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN); switch (format) { @@ -390,11 +390,11 @@ size_t getPlacedTextureStorageSpace(const RSXTexture &texture, size_t rowPitchAl return rowPitch * heightInBlocks * 2; // * 2 for mipmap levels } -std::vector uploadPlacedTexture(const RSXTexture &texture, size_t rowPitchAlignement, void* textureData) +std::vector uploadPlacedTexture(const rsx::texture &texture, size_t rowPitchAlignement, void* textureData) { - size_t w = texture.GetWidth(), h = texture.GetHeight(); + size_t w = texture.width(), h = texture.height(); - int format = texture.GetFormat() & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN); + int format = texture.format() & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN); size_t blockSizeInByte, blockWidthInPixel, blockHeightInPixel; switch (format) @@ -514,31 +514,31 @@ std::vector uploadPlacedTexture(const RSXTexture &texture, size std::vector mipInfos; - const u32 texaddr = GetAddress(texture.GetOffset(), texture.GetLocation()); + const u32 texaddr = rsx::get_address(texture.offset(), texture.location()); auto pixels = vm::get_ptr(texaddr); - bool is_swizzled = !(texture.GetFormat() & CELL_GCM_TEXTURE_LN); + bool is_swizzled = !(texture.format() & CELL_GCM_TEXTURE_LN); switch (format) { case CELL_GCM_TEXTURE_A8R8G8B8: if (is_swizzled) - return writeTexelsSwizzled((char*)pixels, (char*)textureData, w, h, 4, texture.GetMipmap()); + return writeTexelsSwizzled((char*)pixels, (char*)textureData, w, h, 4, texture.mipmap()); else - return writeTexelsGeneric((char*)pixels, (char*)textureData, w, h, 4, texture.GetMipmap()); + return writeTexelsGeneric((char*)pixels, (char*)textureData, w, h, 4, texture.mipmap()); case CELL_GCM_TEXTURE_A1R5G5B5: case CELL_GCM_TEXTURE_A4R4G4B4: case CELL_GCM_TEXTURE_R5G6B5: if (is_swizzled) - return write16bTexelsSwizzled((char*)pixels, (char*)textureData, w, h, 2, texture.GetMipmap()); + return write16bTexelsSwizzled((char*)pixels, (char*)textureData, w, h, 2, texture.mipmap()); else - return write16bTexelsGeneric((char*)pixels, (char*)textureData, w, h, 2, texture.GetMipmap()); + return write16bTexelsGeneric((char*)pixels, (char*)textureData, w, h, 2, texture.mipmap()); case CELL_GCM_TEXTURE_W16_Z16_Y16_X16_FLOAT: - return write16bX4TexelsGeneric((char*)pixels, (char*)textureData, w, h, 8, texture.GetMipmap()); + return write16bX4TexelsGeneric((char*)pixels, (char*)textureData, w, h, 8, texture.mipmap()); case CELL_GCM_TEXTURE_COMPRESSED_DXT1: case CELL_GCM_TEXTURE_COMPRESSED_DXT23: case CELL_GCM_TEXTURE_COMPRESSED_DXT45: - return writeCompressedTexel((char*)pixels, (char*)textureData, widthInBlocks, blockWidthInPixel, heightInBlocks, blockHeightInPixel, blockSizeInByte, texture.GetMipmap()); + return writeCompressedTexel((char*)pixels, (char*)textureData, widthInBlocks, blockWidthInPixel, heightInBlocks, blockHeightInPixel, blockSizeInByte, texture.mipmap()); default: - return writeTexelsGeneric((char*)pixels, (char*)textureData, w, h, blockSizeInByte, texture.GetMipmap()); + return writeTexelsGeneric((char*)pixels, (char*)textureData, w, h, blockSizeInByte, texture.mipmap()); } } \ No newline at end of file diff --git a/rpcs3/Emu/RSX/Common/TextureUtils.h b/rpcs3/Emu/RSX/Common/TextureUtils.h index 6a5e5ae295..cdb4df89cc 100644 --- a/rpcs3/Emu/RSX/Common/TextureUtils.h +++ b/rpcs3/Emu/RSX/Common/TextureUtils.h @@ -16,11 +16,11 @@ unsigned LinearToSwizzleAddress(unsigned x, unsigned y, unsigned z, unsigned log * Get size to store texture in a linear fashion. * Storage is assumed to use a rowPitchAlignement boundary for every row of texture. */ -size_t getPlacedTextureStorageSpace(const RSXTexture &texture, size_t rowPitchAlignement); +size_t getPlacedTextureStorageSpace(const rsx::texture &texture, size_t rowPitchAlignement); /** * Write texture data to textureData. * Data are not packed, they are stored per rows using rowPitchAlignement. * Similarly, offset for every mipmaplevel is aligned to rowPitchAlignement boundary. */ -std::vector uploadPlacedTexture(const RSXTexture &texture, size_t rowPitchAlignement, void* textureData); \ No newline at end of file +std::vector uploadPlacedTexture(const rsx::texture &texture, size_t rowPitchAlignement, void* textureData); \ No newline at end of file diff --git a/rpcs3/Emu/RSX/D3D12/D3D12Buffer.cpp b/rpcs3/Emu/RSX/D3D12/D3D12Buffer.cpp index ce5d580690..c7fe4cfb02 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12Buffer.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12Buffer.cpp @@ -243,14 +243,14 @@ void D3D12GSRender::setScaleOffset() }; // Scale - scaleOffsetMat[0] *= (float&)methodRegisters[NV4097_SET_VIEWPORT_SCALE + (0x4 * 0)] / (m_surface_clip_w / 2.f); - scaleOffsetMat[5] *= (float&)methodRegisters[NV4097_SET_VIEWPORT_SCALE + (0x4 * 1)] / (m_surface_clip_h / 2.f); - scaleOffsetMat[10] = (float&)methodRegisters[NV4097_SET_VIEWPORT_SCALE + (0x4 * 2)]; + scaleOffsetMat[0] *= (float&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + (0x4 * 0)] / (m_surface_clip_w / 2.f); + scaleOffsetMat[5] *= (float&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + (0x4 * 1)] / (m_surface_clip_h / 2.f); + scaleOffsetMat[10] = (float&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + (0x4 * 2)]; // Offset - scaleOffsetMat[3] = (float&)methodRegisters[NV4097_SET_VIEWPORT_OFFSET + (0x4 * 0)] - (m_surface_clip_w / 2.f); - scaleOffsetMat[7] = -((float&)methodRegisters[NV4097_SET_VIEWPORT_OFFSET + (0x4 * 1)] - (m_surface_clip_h / 2.f)); - scaleOffsetMat[11] = (float&)methodRegisters[NV4097_SET_VIEWPORT_OFFSET + (0x4 * 2)]; + scaleOffsetMat[3] = (float&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET + (0x4 * 0)] - (m_surface_clip_w / 2.f); + scaleOffsetMat[7] = -((float&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET + (0x4 * 1)] - (m_surface_clip_h / 2.f)); + scaleOffsetMat[11] = (float&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET + (0x4 * 2)]; scaleOffsetMat[3] /= m_surface_clip_w / 2.f; scaleOffsetMat[7] /= m_surface_clip_h / 2.f; diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp index 51a7bfe4d1..58a0c09375 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp @@ -647,7 +647,7 @@ void D3D12GSRender::Flip() if (m_read_buffer) { CellGcmDisplayInfo* buffers = vm::get_ptr(m_gcm_buffers_addr); - u32 addr = GetAddress(buffers[gcm_current_buffer].offset, CELL_GCM_LOCATION_LOCAL); + u32 addr = rsx::get_address(buffers[gcm_current_buffer].offset, CELL_GCM_LOCATION_LOCAL); w = buffers[gcm_current_buffer].width; h = buffers[gcm_current_buffer].height; u8 *src_buffer = vm::get_ptr(addr); @@ -1000,7 +1000,7 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value) getCurrentResourceStorage().m_commandList->CopyTextureRegion(&CD3DX12_TEXTURE_COPY_LOCATION(writeDest.Get(), { 0, { DXGI_FORMAT_R8_UNORM, m_surface_clip_w, m_surface_clip_h, 1, (UINT)depthRowPitch } }), 0, 0, 0, &CD3DX12_TEXTURE_COPY_LOCATION(depthConverted.Get(), 0), nullptr); - invalidateAddress(GetAddress(m_surface_offset_z, m_context_dma_z - 0xfeed0000)); + invalidateAddress(rsx::get_address(m_surface_offset_z, m_context_dma_z - 0xfeed0000)); } ID3D12Resource *rtt0, *rtt1, *rtt2, *rtt3; @@ -1038,10 +1038,10 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value) break; } - if (m_context_dma_color_a) invalidateAddress(GetAddress(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000)); - if (m_context_dma_color_b) invalidateAddress(GetAddress(m_surface_offset_b, m_context_dma_color_b - 0xfeed0000)); - if (m_context_dma_color_c) invalidateAddress(GetAddress(m_surface_offset_c, m_context_dma_color_c - 0xfeed0000)); - if (m_context_dma_color_d) invalidateAddress(GetAddress(m_surface_offset_d, m_context_dma_color_d - 0xfeed0000)); + if (m_context_dma_color_a) invalidateAddress(rsx::get_address(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000)); + if (m_context_dma_color_b) invalidateAddress(rsx::get_address(m_surface_offset_b, m_context_dma_color_b - 0xfeed0000)); + if (m_context_dma_color_c) invalidateAddress(rsx::get_address(m_surface_offset_c, m_context_dma_color_c - 0xfeed0000)); + if (m_context_dma_color_d) invalidateAddress(rsx::get_address(m_surface_offset_d, m_context_dma_color_d - 0xfeed0000)); } if (needTransfer) { @@ -1057,7 +1057,7 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value) if (m_set_context_dma_z && Ini.GSDumpDepthBuffer.GetValue()) { - u32 address = GetAddress(m_surface_offset_z, m_context_dma_z - 0xfeed0000); + u32 address = rsx::get_address(m_surface_offset_z, m_context_dma_z - 0xfeed0000); auto ptr = vm::get_ptr(address); char *ptrAsChar = (char*)ptr; unsigned char *writeDestPtr; @@ -1097,53 +1097,53 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value) break; case CELL_GCM_SURFACE_TARGET_0: { - u32 address = GetAddress(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000); + u32 address = rsx::get_address(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000); void *dstAddress = vm::get_ptr(address); copyToCellRamAndRelease(dstAddress, rtt0, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); } break; case CELL_GCM_SURFACE_TARGET_1: { - u32 address = GetAddress(m_surface_offset_b, m_context_dma_color_b - 0xfeed0000); + u32 address = rsx::get_address(m_surface_offset_b, m_context_dma_color_b - 0xfeed0000); void *dstAddress = vm::get_ptr(address); copyToCellRamAndRelease(dstAddress, rtt1, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); } break; case CELL_GCM_SURFACE_TARGET_MRT1: { - u32 address = GetAddress(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000); + u32 address = rsx::get_address(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000); void *dstAddress = vm::get_ptr(address); copyToCellRamAndRelease(dstAddress, rtt0, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); - address = GetAddress(m_surface_offset_b, m_context_dma_color_b - 0xfeed0000); + address = rsx::get_address(m_surface_offset_b, m_context_dma_color_b - 0xfeed0000); dstAddress = vm::get_ptr(address); copyToCellRamAndRelease(dstAddress, rtt1, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); } break; case CELL_GCM_SURFACE_TARGET_MRT2: { - u32 address = GetAddress(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000); + u32 address = rsx::get_address(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000); void *dstAddress = vm::get_ptr(address); copyToCellRamAndRelease(dstAddress, rtt0, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); - address = GetAddress(m_surface_offset_b, m_context_dma_color_b - 0xfeed0000); + address = rsx::get_address(m_surface_offset_b, m_context_dma_color_b - 0xfeed0000); dstAddress = vm::get_ptr(address); copyToCellRamAndRelease(dstAddress, rtt1, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); - address = GetAddress(m_surface_offset_c, m_context_dma_color_c - 0xfeed0000); + address = rsx::get_address(m_surface_offset_c, m_context_dma_color_c - 0xfeed0000); dstAddress = vm::get_ptr(address); copyToCellRamAndRelease(dstAddress, rtt2, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); } break; case CELL_GCM_SURFACE_TARGET_MRT3: { - u32 address = GetAddress(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000); + u32 address = rsx::get_address(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000); void *dstAddress = vm::get_ptr(address); copyToCellRamAndRelease(dstAddress, rtt0, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); - address = GetAddress(m_surface_offset_b, m_context_dma_color_b - 0xfeed0000); + address = rsx::get_address(m_surface_offset_b, m_context_dma_color_b - 0xfeed0000); dstAddress = vm::get_ptr(address); copyToCellRamAndRelease(dstAddress, rtt1, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); - address = GetAddress(m_surface_offset_c, m_context_dma_color_c - 0xfeed0000); + address = rsx::get_address(m_surface_offset_c, m_context_dma_color_c - 0xfeed0000); dstAddress = vm::get_ptr(address); copyToCellRamAndRelease(dstAddress, rtt2, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); - address = GetAddress(m_surface_offset_d, m_context_dma_color_d - 0xfeed0000); + address = rsx::get_address(m_surface_offset_d, m_context_dma_color_d - 0xfeed0000); dstAddress = vm::get_ptr(address); copyToCellRamAndRelease(dstAddress, rtt3, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); } diff --git a/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp b/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp index f9f8dc3f6c..5fc125835e 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp @@ -29,11 +29,11 @@ void D3D12GSRender::PrepareRenderTargets(ID3D12GraphicsCommandList *copycmdlist) m_previous_address_z = m_surface_offset_z; // FBO location has changed, previous data might be copied - u32 address_a = m_set_context_dma_color_a ? GetAddress(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000) : 0; - u32 address_b = m_set_context_dma_color_b ? GetAddress(m_surface_offset_b, m_context_dma_color_b - 0xfeed0000) : 0; - u32 address_c = m_set_context_dma_color_c ? GetAddress(m_surface_offset_c, m_context_dma_color_c - 0xfeed0000) : 0; - u32 address_d = m_set_context_dma_color_d ? GetAddress(m_surface_offset_d, m_context_dma_color_d - 0xfeed0000) : 0; - u32 address_z = m_set_context_dma_z ? GetAddress(m_surface_offset_z, m_context_dma_z - 0xfeed0000) : 0; + u32 address_a = m_set_context_dma_color_a ? rsx::get_address(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000) : 0; + u32 address_b = m_set_context_dma_color_b ? rsx::get_address(m_surface_offset_b, m_context_dma_color_b - 0xfeed0000) : 0; + u32 address_c = m_set_context_dma_color_c ? rsx::get_address(m_surface_offset_c, m_context_dma_color_c - 0xfeed0000) : 0; + u32 address_d = m_set_context_dma_color_d ? rsx::get_address(m_surface_offset_d, m_context_dma_color_d - 0xfeed0000) : 0; + u32 address_z = m_set_context_dma_z ? rsx::get_address(m_surface_offset_z, m_context_dma_z - 0xfeed0000) : 0; // Make previous RTTs sampleable for (unsigned i = 0; i < 4; i++) diff --git a/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp b/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp index 6f71a2a41f..e86bb5219a 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp @@ -104,19 +104,19 @@ D3D12_FILTER getSamplerFilter(u32 minFilter, u32 magFilter) } static -D3D12_SAMPLER_DESC getSamplerDesc(const RSXTexture &texture) +D3D12_SAMPLER_DESC getSamplerDesc(const rsx::texture &texture) { D3D12_SAMPLER_DESC samplerDesc = {}; - samplerDesc.Filter = getSamplerFilter(texture.GetMinFilter(), texture.GetMagFilter()); - samplerDesc.AddressU = getSamplerWrap(texture.GetWrapS()); - samplerDesc.AddressV = getSamplerWrap(texture.GetWrapT()); - samplerDesc.AddressW = getSamplerWrap(texture.GetWrapR()); - samplerDesc.ComparisonFunc = getSamplerCompFunc[texture.GetZfunc()]; - samplerDesc.MaxAnisotropy = (UINT)getSamplerMaxAniso(texture.GetMaxAniso()); - samplerDesc.MipLODBias = texture.GetBias(); - samplerDesc.BorderColor[4] = (FLOAT)texture.GetBorderColor(); - samplerDesc.MinLOD = (FLOAT)(texture.GetMinLOD() >> 8); - samplerDesc.MaxLOD = (FLOAT)(texture.GetMaxLOD() >> 8); + samplerDesc.Filter = getSamplerFilter(texture.min_filter(), texture.mag_filter()); + samplerDesc.AddressU = getSamplerWrap(texture.wrap_s()); + samplerDesc.AddressV = getSamplerWrap(texture.wrap_t()); + samplerDesc.AddressW = getSamplerWrap(texture.wrap_r()); + samplerDesc.ComparisonFunc = getSamplerCompFunc[texture.zfunc()]; + samplerDesc.MaxAnisotropy = (UINT)getSamplerMaxAniso(texture.max_aniso()); + samplerDesc.MipLODBias = texture.bias(); + samplerDesc.BorderColor[4] = (FLOAT)texture.border_color(); + samplerDesc.MinLOD = (FLOAT)(texture.min_lod() >> 8); + samplerDesc.MaxLOD = (FLOAT)(texture.max_lod() >> 8); return samplerDesc; } @@ -127,15 +127,15 @@ D3D12_SAMPLER_DESC getSamplerDesc(const RSXTexture &texture) */ static ComPtr uploadSingleTexture( - const RSXTexture &texture, + const rsx::texture &texture, ID3D12Device *device, ID3D12GraphicsCommandList *commandList, DataHeap &textureBuffersHeap) { ComPtr vramTexture; - size_t w = texture.GetWidth(), h = texture.GetHeight(); + size_t w = texture.width(), h = texture.height(); - int format = texture.GetFormat() & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN); + int format = texture.format() & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN); DXGI_FORMAT dxgiFormat = getTextureDXGIFormat(format); size_t textureSize = getPlacedTextureStorageSpace(texture, 256); @@ -148,7 +148,7 @@ ComPtr uploadSingleTexture( std::vector mipInfos = uploadPlacedTexture(texture, 256, textureData); textureBuffersHeap.m_heap->Unmap(0, &CD3DX12_RANGE(heapOffset, heapOffset + textureSize)); - D3D12_RESOURCE_DESC texturedesc = CD3DX12_RESOURCE_DESC::Tex2D(dxgiFormat, (UINT)w, (UINT)h, 1, texture.GetMipmap()); + D3D12_RESOURCE_DESC texturedesc = CD3DX12_RESOURCE_DESC::Tex2D(dxgiFormat, (UINT)w, (UINT)h, 1, texture.mipmap()); textureSize = device->GetResourceAllocationInfo(0, 1, &texturedesc).SizeInBytes; ThrowIfFailed(device->CreateCommittedResource( @@ -179,14 +179,14 @@ ComPtr uploadSingleTexture( */ static void updateExistingTexture( - const RSXTexture &texture, + const rsx::texture &texture, ID3D12GraphicsCommandList *commandList, DataHeap &textureBuffersHeap, ID3D12Resource *existingTexture) { - size_t w = texture.GetWidth(), h = texture.GetHeight(); + size_t w = texture.width(), h = texture.height(); - int format = texture.GetFormat() & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN); + int format = texture.format() & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN); DXGI_FORMAT dxgiFormat = getTextureDXGIFormat(format); size_t textureSize = getPlacedTextureStorageSpace(texture, 256); @@ -216,11 +216,11 @@ void updateExistingTexture( * Get number of bytes occupied by texture in RSX mem */ static -size_t getTextureSize(const RSXTexture &texture) +size_t getTextureSize(const rsx::texture &texture) { - size_t w = texture.GetWidth(), h = texture.GetHeight(); + size_t w = texture.width(), h = texture.height(); - int format = texture.GetFormat() & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN); + int format = texture.format() & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN); // TODO: Take mipmaps into account switch (format) { @@ -290,15 +290,15 @@ size_t D3D12GSRender::UploadTextures(ID3D12GraphicsCommandList *cmdlist) for (u32 i = 0; i < m_textures_count; ++i) { - if (!m_textures[i].IsEnabled()) continue; - size_t w = m_textures[i].GetWidth(), h = m_textures[i].GetHeight(); + if (!m_textures[i].enabled()) continue; + size_t w = m_textures[i].width(), h = m_textures[i].height(); if (!w || !h) continue; - const u32 texaddr = GetAddress(m_textures[i].GetOffset(), m_textures[i].GetLocation()); + const u32 texaddr = rsx::get_address(m_textures[i].offset(), m_textures[i].location()); - int format = m_textures[i].GetFormat() & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN); + int format = m_textures[i].format() & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN); DXGI_FORMAT dxgiFormat = getTextureDXGIFormat(format); - bool is_swizzled = !(m_textures[i].GetFormat() & CELL_GCM_TEXTURE_LN); + bool is_swizzled = !(m_textures[i].format() & CELL_GCM_TEXTURE_LN); ID3D12Resource *vramTexture; std::unordered_map::const_iterator ItRTT = m_rtts.m_renderTargets.find(texaddr); @@ -309,7 +309,7 @@ size_t D3D12GSRender::UploadTextures(ID3D12GraphicsCommandList *cmdlist) vramTexture = ItRTT->second; isRenderTarget = true; } - else if (cachedTex != nullptr && (cachedTex->first == TextureEntry(format, w, h, m_textures[i].GetMipmap()))) + else if (cachedTex != nullptr && (cachedTex->first == TextureEntry(format, w, h, m_textures[i].mipmap()))) { if (cachedTex->first.m_isDirty) { @@ -324,13 +324,13 @@ size_t D3D12GSRender::UploadTextures(ID3D12GraphicsCommandList *cmdlist) getCurrentResourceStorage().m_dirtyTextures.push_back(m_textureCache.removeFromCache(texaddr)); ComPtr tex = uploadSingleTexture(m_textures[i], m_device.Get(), cmdlist, m_textureUploadData); vramTexture = tex.Get(); - m_textureCache.storeAndProtectData(texaddr, texaddr, getTextureSize(m_textures[i]), format, w, h, m_textures[i].GetMipmap(), tex); + m_textureCache.storeAndProtectData(texaddr, texaddr, getTextureSize(m_textures[i]), format, w, h, m_textures[i].mipmap(), tex); } D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; srvDesc.Format = dxgiFormat; - srvDesc.Texture2D.MipLevels = m_textures[i].GetMipmap(); + srvDesc.Texture2D.MipLevels = m_textures[i].mipmap(); switch (format) { @@ -357,10 +357,10 @@ size_t D3D12GSRender::UploadTextures(ID3D12GraphicsCommandList *cmdlist) { - u8 remap_a = m_textures[i].GetRemap() & 0x3; - u8 remap_r = (m_textures[i].GetRemap() >> 2) & 0x3; - u8 remap_g = (m_textures[i].GetRemap() >> 4) & 0x3; - u8 remap_b = (m_textures[i].GetRemap() >> 6) & 0x3; + u8 remap_a = m_textures[i].remap() & 0x3; + u8 remap_r = (m_textures[i].remap() >> 2) & 0x3; + u8 remap_g = (m_textures[i].remap() >> 4) & 0x3; + u8 remap_b = (m_textures[i].remap() >> 6) & 0x3; if (isRenderTarget) { // ARGB format @@ -428,10 +428,10 @@ size_t D3D12GSRender::UploadTextures(ID3D12GraphicsCommandList *cmdlist) D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_1 }; - u8 remap_a = m_textures[i].GetRemap() & 0x3; - u8 remap_r = (m_textures[i].GetRemap() >> 2) & 0x3; - u8 remap_g = (m_textures[i].GetRemap() >> 4) & 0x3; - u8 remap_b = (m_textures[i].GetRemap() >> 6) & 0x3; + u8 remap_a = m_textures[i].remap() & 0x3; + u8 remap_r = (m_textures[i].remap() >> 2) & 0x3; + u8 remap_g = (m_textures[i].remap() >> 4) & 0x3; + u8 remap_b = (m_textures[i].remap() >> 6) & 0x3; srvDesc.Shader4ComponentMapping = D3D12_ENCODE_SHADER_4_COMPONENT_MAPPING( RemapValue[remap_a], diff --git a/rpcs3/Emu/RSX/GL/GLGSRender.cpp b/rpcs3/Emu/RSX/GL/GLGSRender.cpp index 29ec99127a..becf0cf0f7 100644 --- a/rpcs3/Emu/RSX/GL/GLGSRender.cpp +++ b/rpcs3/Emu/RSX/GL/GLGSRender.cpp @@ -89,24 +89,24 @@ float GLTexture::GetMaxAniso(int aniso) return 1.0f; } -void GLTexture::Init(RSXTexture& tex) +void GLTexture::Init(rsx::texture& tex) { - if (tex.GetLocation() > 1) + if (tex.location() > 1) { return; } Bind(); - const u32 texaddr = GetAddress(tex.GetOffset(), tex.GetLocation()); + const u32 texaddr = rsx::get_address(tex.offset(), tex.location()); //LOG_WARNING(RSX, "texture addr = 0x%x, width = %d, height = %d, max_aniso=%d, mipmap=%d, remap=0x%x, zfunc=0x%x, wraps=0x%x, wrapt=0x%x, wrapr=0x%x, minlod=0x%x, maxlod=0x%x", // m_offset, m_width, m_height, m_maxaniso, m_mipmap, m_remap, m_zfunc, m_wraps, m_wrapt, m_wrapr, m_minlod, m_maxlod); //TODO: safe init checkForGlError("GLTexture::Init() -> glBindTexture"); - int format = tex.GetFormat() & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN); - bool is_swizzled = !(tex.GetFormat() & CELL_GCM_TEXTURE_LN); + int format = tex.format() & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN); + bool is_swizzled = !(tex.format() & CELL_GCM_TEXTURE_LN); auto pixels = vm::get_ptr(texaddr); u8 *unswizzledPixels; @@ -118,7 +118,7 @@ void GLTexture::Init(RSXTexture& tex) { case CELL_GCM_TEXTURE_B8: // One 8-bit fixed-point number { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_BLUE, GL_UNSIGNED_BYTE, pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width(), tex.height(), 0, GL_BLUE, GL_UNSIGNED_BYTE, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_B8)"); static const GLint swizzleMaskB8[] = { GL_BLUE, GL_BLUE, GL_BLUE, GL_BLUE }; @@ -132,7 +132,7 @@ void GLTexture::Init(RSXTexture& tex) checkForGlError("GLTexture::Init() -> glPixelStorei"); // TODO: texture swizzling - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width(), tex.height(), 0, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_A1R5G5B5)"); glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); @@ -142,7 +142,7 @@ void GLTexture::Init(RSXTexture& tex) case CELL_GCM_TEXTURE_A4R4G4B4: { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width(), tex.height(), 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_A4R4G4B4)"); // We read it in as R4G4B4A4, so we need to remap each component. @@ -156,7 +156,7 @@ void GLTexture::Init(RSXTexture& tex) glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE); checkForGlError("GLTexture::Init() -> glPixelStorei(CELL_GCM_TEXTURE_R5G6B5)"); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex.GetWidth(), tex.GetHeight(), 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex.width(), tex.height(), 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_R5G6B5)"); glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); @@ -171,57 +171,57 @@ void GLTexture::Init(RSXTexture& tex) u32 *src, *dst; u32 log2width, log2height; - unswizzledPixels = (u8*)malloc(tex.GetWidth() * tex.GetHeight() * 4); + unswizzledPixels = (u8*)malloc(tex.width() * tex.height() * 4); src = (u32*)pixels; dst = (u32*)unswizzledPixels; - log2width = log(tex.GetWidth()) / log(2); - log2height = log(tex.GetHeight()) / log(2); + log2width = log(tex.width()) / log(2); + log2height = log(tex.height()) / log(2); - for (int i = 0; i < tex.GetHeight(); i++) + for (int i = 0; i < tex.height(); i++) { - for (int j = 0; j < tex.GetWidth(); j++) + for (int j = 0; j < tex.width(); j++) { - dst[(i * tex.GetWidth()) + j] = src[LinearToSwizzleAddress(j, i, 0, log2width, log2height, 0)]; + dst[(i * tex.width()) + j] = src[LinearToSwizzleAddress(j, i, 0, log2width, log2height, 0)]; } } } - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, is_swizzled ? unswizzledPixels : pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width(), tex.height(), 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, is_swizzled ? unswizzledPixels : pixels); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_A8R8G8B8)"); break; } case CELL_GCM_TEXTURE_COMPRESSED_DXT1: // Compressed 4x4 pixels into 8 bytes { - u32 size = ((tex.GetWidth() + 3) / 4) * ((tex.GetHeight() + 3) / 4) * 8; + u32 size = ((tex.width() + 3) / 4) * ((tex.height() + 3) / 4) * 8; - glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, tex.GetWidth(), tex.GetHeight(), 0, size, pixels); + glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, tex.width(), tex.height(), 0, size, pixels); checkForGlError("GLTexture::Init() -> glCompressedTexImage2D(CELL_GCM_TEXTURE_COMPRESSED_DXT1)"); break; } case CELL_GCM_TEXTURE_COMPRESSED_DXT23: // Compressed 4x4 pixels into 16 bytes { - u32 size = ((tex.GetWidth() + 3) / 4) * ((tex.GetHeight() + 3) / 4) * 16; + u32 size = ((tex.width() + 3) / 4) * ((tex.height() + 3) / 4) * 16; - glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, tex.GetWidth(), tex.GetHeight(), 0, size, pixels); + glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, tex.width(), tex.height(), 0, size, pixels); checkForGlError("GLTexture::Init() -> glCompressedTexImage2D(CELL_GCM_TEXTURE_COMPRESSED_DXT23)"); } break; case CELL_GCM_TEXTURE_COMPRESSED_DXT45: // Compressed 4x4 pixels into 16 bytes { - u32 size = ((tex.GetWidth() + 3) / 4) * ((tex.GetHeight() + 3) / 4) * 16; + u32 size = ((tex.width() + 3) / 4) * ((tex.height() + 3) / 4) * 16; - glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, tex.GetWidth(), tex.GetHeight(), 0, size, pixels); + glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, tex.width(), tex.height(), 0, size, pixels); checkForGlError("GLTexture::Init() -> glCompressedTexImage2D(CELL_GCM_TEXTURE_COMPRESSED_DXT45)"); break; } case CELL_GCM_TEXTURE_G8B8: { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_RG, GL_UNSIGNED_BYTE, pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width(), tex.height(), 0, GL_RG, GL_UNSIGNED_BYTE, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_G8B8)"); static const GLint swizzleMaskG8B8[] = { GL_RED, GL_GREEN, GL_RED, GL_GREEN }; @@ -232,7 +232,7 @@ void GLTexture::Init(RSXTexture& tex) case CELL_GCM_TEXTURE_R6G5B5: { // TODO: Probably need to actually unswizzle if is_swizzled. - const u32 numPixels = tex.GetWidth() * tex.GetHeight(); + const u32 numPixels = tex.width() * tex.height(); unswizzledPixels = (u8 *)malloc(numPixels * 4); // TODO: Speed. for (u32 i = 0; i < numPixels; ++i) { @@ -243,7 +243,7 @@ void GLTexture::Init(RSXTexture& tex) unswizzledPixels[i * 4 + 3] = 255; } - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, unswizzledPixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width(), tex.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, unswizzledPixels); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_R6G5B5)"); free(unswizzledPixels); @@ -252,28 +252,28 @@ void GLTexture::Init(RSXTexture& tex) case CELL_GCM_TEXTURE_DEPTH24_D8: // 24-bit unsigned fixed-point number and 8 bits of garbage { - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, tex.GetWidth(), tex.GetHeight(), 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, tex.width(), tex.height(), 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_DEPTH24_D8)"); break; } case CELL_GCM_TEXTURE_DEPTH24_D8_FLOAT: // 24-bit unsigned float and 8 bits of garbage { - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, tex.GetWidth(), tex.GetHeight(), 0, GL_DEPTH_COMPONENT, GL_FLOAT, pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, tex.width(), tex.height(), 0, GL_DEPTH_COMPONENT, GL_FLOAT, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_DEPTH24_D8_FLOAT)"); break; } case CELL_GCM_TEXTURE_DEPTH16: // 16-bit unsigned fixed-point number { - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, tex.GetWidth(), tex.GetHeight(), 0, GL_DEPTH_COMPONENT, GL_SHORT, pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, tex.width(), tex.height(), 0, GL_DEPTH_COMPONENT, GL_SHORT, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_DEPTH16)"); break; } case CELL_GCM_TEXTURE_DEPTH16_FLOAT: // 16-bit unsigned float { - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, tex.GetWidth(), tex.GetHeight(), 0, GL_DEPTH_COMPONENT, GL_FLOAT, pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, tex.width(), tex.height(), 0, GL_DEPTH_COMPONENT, GL_FLOAT, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_DEPTH16_FLOAT)"); break; } @@ -283,7 +283,7 @@ void GLTexture::Init(RSXTexture& tex) glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE); checkForGlError("GLTexture::Init() -> glPixelStorei(CELL_GCM_TEXTURE_X16)"); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_RED, GL_UNSIGNED_SHORT, pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width(), tex.height(), 0, GL_RED, GL_UNSIGNED_SHORT, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_X16)"); glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); @@ -299,7 +299,7 @@ void GLTexture::Init(RSXTexture& tex) glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE); checkForGlError("GLTexture::Init() -> glPixelStorei(CELL_GCM_TEXTURE_Y16_X16)"); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_RG, GL_UNSIGNED_SHORT, pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width(), tex.height(), 0, GL_RG, GL_UNSIGNED_SHORT, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_Y16_X16)"); glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); @@ -315,7 +315,7 @@ void GLTexture::Init(RSXTexture& tex) glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE); checkForGlError("GLTexture::Init() -> glPixelStorei(CELL_GCM_TEXTURE_R5G5B5A1)"); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width(), tex.height(), 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_R5G5B5A1)"); glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); @@ -328,7 +328,7 @@ void GLTexture::Init(RSXTexture& tex) glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE); checkForGlError("GLTexture::Init() -> glPixelStorei(CELL_GCM_TEXTURE_W16_Z16_Y16_X16_FLOAT)"); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_RGBA, GL_HALF_FLOAT, pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width(), tex.height(), 0, GL_RGBA, GL_HALF_FLOAT, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_W16_Z16_Y16_X16_FLOAT)"); glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); @@ -338,14 +338,14 @@ void GLTexture::Init(RSXTexture& tex) case CELL_GCM_TEXTURE_W32_Z32_Y32_X32_FLOAT: // Four fp32 values { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_BGRA, GL_FLOAT, pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width(), tex.height(), 0, GL_BGRA, GL_FLOAT, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_W32_Z32_Y32_X32_FLOAT)"); break; } case CELL_GCM_TEXTURE_X32_FLOAT: // One 32-bit floating-point number { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_RED, GL_FLOAT, pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width(), tex.height(), 0, GL_RED, GL_FLOAT, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_X32_FLOAT)"); static const GLint swizzleMaskX32_FLOAT[] = { GL_RED, GL_ONE, GL_ONE, GL_ONE }; @@ -359,7 +359,7 @@ void GLTexture::Init(RSXTexture& tex) checkForGlError("GLTexture::Init() -> glPixelStorei(CELL_GCM_TEXTURE_D1R5G5B5)"); // TODO: Texture swizzling - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width(), tex.height(), 0, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_D1R5G5B5)"); static const GLint swizzleMaskX32_D1R5G5B5[] = { GL_ONE, GL_RED, GL_GREEN, GL_BLUE }; @@ -372,7 +372,7 @@ void GLTexture::Init(RSXTexture& tex) case CELL_GCM_TEXTURE_D8R8G8B8: // 8 bits of garbage and three unsigned 8-bit fixed-point numbers { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width(), tex.height(), 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_D8R8G8B8)"); static const GLint swizzleMaskX32_D8R8G8B8[] = { GL_ONE, GL_RED, GL_GREEN, GL_BLUE }; @@ -386,7 +386,7 @@ void GLTexture::Init(RSXTexture& tex) glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE); checkForGlError("GLTexture::Init() -> glPixelStorei(CELL_GCM_TEXTURE_Y16_X16_FLOAT)"); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_RG, GL_HALF_FLOAT, pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width(), tex.height(), 0, GL_RG, GL_HALF_FLOAT, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_Y16_X16_FLOAT)"); glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); @@ -399,7 +399,7 @@ void GLTexture::Init(RSXTexture& tex) case ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN) & CELL_GCM_TEXTURE_COMPRESSED_B8R8_G8R8: { - const u32 numPixels = tex.GetWidth() * tex.GetHeight(); + const u32 numPixels = tex.width() * tex.height(); unswizzledPixels = (u8 *)malloc(numPixels * 4); // TODO: Speed. for (u32 i = 0; i < numPixels; i += 2) @@ -416,7 +416,7 @@ void GLTexture::Init(RSXTexture& tex) unswizzledPixels[i * 4 + 4 + 3] = 255; } - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, unswizzledPixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width(), tex.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, unswizzledPixels); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_COMPRESSED_B8R8_G8R8 & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN)"); free(unswizzledPixels); @@ -425,7 +425,7 @@ void GLTexture::Init(RSXTexture& tex) case ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN) & CELL_GCM_TEXTURE_COMPRESSED_R8B8_R8G8: { - const u32 numPixels = tex.GetWidth() * tex.GetHeight(); + const u32 numPixels = tex.width() * tex.height(); unswizzledPixels = (u8 *)malloc(numPixels * 4); // TODO: Speed. for (u32 i = 0; i < numPixels; i += 2) @@ -442,7 +442,7 @@ void GLTexture::Init(RSXTexture& tex) unswizzledPixels[i * 4 + 4 + 3] = 255; } - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, unswizzledPixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width(), tex.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, unswizzledPixels); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_COMPRESSED_R8B8_R8G8 & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN)"); free(unswizzledPixels); @@ -451,20 +451,20 @@ void GLTexture::Init(RSXTexture& tex) default: { - LOG_ERROR(RSX, "Init tex error: Bad tex format (0x%x | %s | 0x%x)", format, (is_swizzled ? "swizzled" : "linear"), tex.GetFormat() & 0x40); + LOG_ERROR(RSX, "Init tex error: Bad tex format (0x%x | %s | 0x%x)", format, (is_swizzled ? "swizzled" : "linear"), tex.format() & 0x40); break; } } - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, tex.GetMipmap() - 1); - glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, tex.GetMipmap() > 1); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, tex.mipmap() - 1); + glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, tex.mipmap() > 1); if (format != CELL_GCM_TEXTURE_B8 && format != CELL_GCM_TEXTURE_X16 && format != CELL_GCM_TEXTURE_X32_FLOAT) { - u8 remap_a = tex.GetRemap() & 0x3; - u8 remap_r = (tex.GetRemap() >> 2) & 0x3; - u8 remap_g = (tex.GetRemap() >> 4) & 0x3; - u8 remap_b = (tex.GetRemap() >> 6) & 0x3; + u8 remap_a = tex.remap() & 0x3; + u8 remap_r = (tex.remap() >> 2) & 0x3; + u8 remap_g = (tex.remap() >> 4) & 0x3; + u8 remap_b = (tex.remap() >> 6) & 0x3; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, glRemap[remap_a]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, glRemap[remap_r]); @@ -494,19 +494,19 @@ void GLTexture::Init(RSXTexture& tex) GL_ALWAYS, }; - 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_WRAP_S, GetGlWrap(tex.wrap_s())); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GetGlWrap(tex.wrap_t())); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GetGlWrap(tex.wrap_r())); checkForGlError("GLTexture::Init() -> wrap"); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, gl_tex_zfunc[tex.GetZfunc()]); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, gl_tex_zfunc[tex.zfunc()]); checkForGlError("GLTexture::Init() -> compare"); - glTexEnvi(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, tex.GetBias()); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, (tex.GetMinLOD() >> 8)); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, (tex.GetMaxLOD() >> 8)); + glTexEnvi(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, tex.bias()); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, (tex.min_lod() >> 8)); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, (tex.max_lod() >> 8)); checkForGlError("GLTexture::Init() -> lod"); @@ -530,14 +530,14 @@ void GLTexture::Init(RSXTexture& tex) GL_LINEAR // CELL_GCM_TEXTURE_CONVOLUTION_MAG }; - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_tex_min_filter[tex.GetMinFilter()]); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_tex_min_filter[tex.min_filter()]); checkForGlError("GLTexture::Init() -> min filters"); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_tex_mag_filter[tex.GetMagFilter()]); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_tex_mag_filter[tex.mag_filter()]); checkForGlError("GLTexture::Init() -> mag filters"); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, GetMaxAniso(tex.GetMaxAniso())); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, GetMaxAniso(tex.max_aniso())); checkForGlError("GLTexture::Init() -> max anisotropy"); @@ -549,17 +549,17 @@ void GLTexture::Init(RSXTexture& tex) } } -void GLTexture::Save(RSXTexture& tex, const std::string& name) +void GLTexture::Save(rsx::texture& tex, const std::string& name) { - if (!m_id || !tex.GetOffset() || !tex.GetWidth() || !tex.GetHeight()) return; + if (!m_id || !tex.offset() || !tex.width() || !tex.height()) return; - const u32 texPixelCount = tex.GetWidth() * tex.GetHeight(); + const u32 texPixelCount = tex.width() * tex.height(); u32* alldata = new u32[texPixelCount]; Bind(); - switch (tex.GetFormat() & ~(0x20 | 0x40)) + switch (tex.format() & ~(0x20 | 0x40)) { case CELL_GCM_TEXTURE_B8: glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, alldata); @@ -591,7 +591,7 @@ void GLTexture::Save(RSXTexture& tex, const std::string& name) } rImage out; - out.Create(tex.GetWidth(), tex.GetHeight(), data, alpha); + out.Create(tex.width(), tex.height(), data, alpha); out.SaveFile(name, rBITMAP_TYPE_PNG); delete[] alldata; @@ -599,7 +599,7 @@ void GLTexture::Save(RSXTexture& tex, const std::string& name) //free(alpha); } -void GLTexture::Save(RSXTexture& tex) +void GLTexture::Save(rsx::texture& tex) { static const std::string& dir_path = "textures"; static const std::string& file_fmt = dir_path + "/" + "tex[%d].png"; @@ -813,7 +813,7 @@ void GLGSRender::EnableVertexData(bool indexed_draw) { if (0) { - u32 data_format = methodRegisters[NV4097_SET_VERTEX_DATA_ARRAY_FORMAT + i * 4]; + u32 data_format = rsx::method_registers[NV4097_SET_VERTEX_DATA_ARRAY_FORMAT + i * 4]; u16 frequency = data_format >> 16; u8 stride = (data_format >> 8) & 0xff; u8 size = (data_format >> 4) & 0xf; @@ -1043,14 +1043,14 @@ void GLGSRender::InitVertexData() } // Scale - scaleOffsetMat[0] = (GLfloat&)methodRegisters[NV4097_SET_VIEWPORT_SCALE + (0x4 * 0)] / (RSXThread::m_width / RSXThread::m_width_scale); - scaleOffsetMat[5] = (GLfloat&)methodRegisters[NV4097_SET_VIEWPORT_SCALE + (0x4 * 1)] / (RSXThread::m_height / RSXThread::m_height_scale); - scaleOffsetMat[10] = (GLfloat&)methodRegisters[NV4097_SET_VIEWPORT_SCALE + (0x4 * 2)]; + scaleOffsetMat[0] = (GLfloat&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + (0x4 * 0)] / (RSXThread::m_width / RSXThread::m_width_scale); + scaleOffsetMat[5] = (GLfloat&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + (0x4 * 1)] / (RSXThread::m_height / RSXThread::m_height_scale); + scaleOffsetMat[10] = (GLfloat&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + (0x4 * 2)]; // Offset - scaleOffsetMat[3] = (GLfloat&)methodRegisters[NV4097_SET_VIEWPORT_OFFSET + (0x4 * 0)] - (RSXThread::m_width / RSXThread::m_width_scale); - scaleOffsetMat[7] = (GLfloat&)methodRegisters[NV4097_SET_VIEWPORT_OFFSET + (0x4 * 1)] - (RSXThread::m_height / RSXThread::m_height_scale); - scaleOffsetMat[11] = (GLfloat&)methodRegisters[NV4097_SET_VIEWPORT_OFFSET + (0x4 * 2)] - 1 / 2.0f; + scaleOffsetMat[3] = (GLfloat&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET + (0x4 * 0)] - (RSXThread::m_width / RSXThread::m_width_scale); + scaleOffsetMat[7] = (GLfloat&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET + (0x4 * 1)] - (RSXThread::m_height / RSXThread::m_height_scale); + scaleOffsetMat[11] = (GLfloat&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET + (0x4 * 2)] - 1 / 2.0f; scaleOffsetMat[3] /= RSXThread::m_width / RSXThread::m_width_scale; scaleOffsetMat[7] /= RSXThread::m_height / RSXThread::m_height_scale; @@ -1155,7 +1155,7 @@ void GLGSRender::WriteDepthBuffer() return; } - u32 address = GetAddress(m_surface_offset_z, m_context_dma_z - 0xfeed0000); + u32 address = rsx::get_address(m_surface_offset_z, m_context_dma_z - 0xfeed0000); auto ptr = vm::get_ptr(address); glBindBuffer(GL_PIXEL_PACK_BUFFER, g_pbo[4]); @@ -1187,7 +1187,7 @@ void GLGSRender::WriteColorBufferA() return; } - u32 address = GetAddress(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000); + u32 address = rsx::get_address(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000); glReadBuffer(GL_COLOR_ATTACHMENT0); checkForGlError("WriteColorBufferA(): glReadBuffer"); @@ -1213,7 +1213,7 @@ void GLGSRender::WriteColorBufferB() return; } - u32 address = GetAddress(m_surface_offset_b, m_context_dma_color_b - 0xfeed0000); + u32 address = rsx::get_address(m_surface_offset_b, m_context_dma_color_b - 0xfeed0000); glReadBuffer(GL_COLOR_ATTACHMENT1); checkForGlError("WriteColorBufferB(): glReadBuffer"); @@ -1239,7 +1239,7 @@ void GLGSRender::WriteColorBufferC() return; } - u32 address = GetAddress(m_surface_offset_c, m_context_dma_color_c - 0xfeed0000); + u32 address = rsx::get_address(m_surface_offset_c, m_context_dma_color_c - 0xfeed0000); glReadBuffer(GL_COLOR_ATTACHMENT2); checkForGlError("WriteColorBufferC(): glReadBuffer"); @@ -1265,7 +1265,7 @@ void GLGSRender::WriteColorBufferD() return; } - u32 address = GetAddress(m_surface_offset_d, m_context_dma_color_d - 0xfeed0000); + u32 address = rsx::get_address(m_surface_offset_d, m_context_dma_color_d - 0xfeed0000); glReadBuffer(GL_COLOR_ATTACHMENT3); checkForGlError("WriteColorBufferD(): glReadBuffer"); @@ -1567,7 +1567,7 @@ void GLGSRender::InitDrawBuffers() { u32 format = GL_BGRA; CellGcmDisplayInfo* buffers = vm::get_ptr(m_gcm_buffers_addr); - u32 addr = GetAddress(buffers[gcm_current_buffer].offset, CELL_GCM_LOCATION_LOCAL); + u32 addr = rsx::get_address(buffers[gcm_current_buffer].offset, CELL_GCM_LOCATION_LOCAL); u32 width = buffers[gcm_current_buffer].width; u32 height = buffers[gcm_current_buffer].height; glDrawPixels(width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, vm::get_ptr(addr)); @@ -1912,7 +1912,7 @@ void GLGSRender::Draw() for (u32 i = 0; i < m_textures_count; ++i) { - if (!m_textures[i].IsEnabled()) continue; + if (!m_textures[i].enabled()) continue; glActiveTexture(GL_TEXTURE0 + i); checkForGlError("glActiveTexture"); @@ -1926,7 +1926,7 @@ void GLGSRender::Draw() for (u32 i = 0; i < m_textures_count; ++i) { - if (!m_vertex_textures[i].IsEnabled()) continue; + if (!m_vertex_textures[i].enabled()) continue; glActiveTexture(GL_TEXTURE0 + m_textures_count + i); checkForGlError("glActiveTexture"); @@ -1934,7 +1934,7 @@ void GLGSRender::Draw() m_gl_vertex_textures[i].Bind(); checkForGlError(fmt::format("m_gl_vertex_textures[%d].Bind", i)); m_program.SetVTex(i); - m_gl_vertex_textures[i].Init(m_vertex_textures[i]); +// m_gl_vertex_textures[i].Init(m_vertex_textures[i]); checkForGlError(fmt::format("m_gl_vertex_textures[%d].Init", i)); } @@ -2023,7 +2023,7 @@ void GLGSRender::Flip() { format = GL_BGRA; CellGcmDisplayInfo* buffers = vm::get_ptr(m_gcm_buffers_addr); - u32 addr = GetAddress(buffers[gcm_current_buffer].offset, CELL_GCM_LOCATION_LOCAL); + u32 addr = rsx::get_address(buffers[gcm_current_buffer].offset, CELL_GCM_LOCATION_LOCAL); width = buffers[gcm_current_buffer].width; height = buffers[gcm_current_buffer].height; src_buffer = vm::get_ptr(addr); diff --git a/rpcs3/Emu/RSX/GL/GLGSRender.h b/rpcs3/Emu/RSX/GL/GLGSRender.h index e98e3021ab..4b669d533d 100644 --- a/rpcs3/Emu/RSX/GL/GLGSRender.h +++ b/rpcs3/Emu/RSX/GL/GLGSRender.h @@ -53,11 +53,11 @@ public: return (v << 2) | (v >> 4); } - void Init(RSXTexture& tex); + void Init(rsx::texture& tex); - void Save(RSXTexture& tex, const std::string& name); + void Save(rsx::texture& tex, const std::string& name); - void Save(RSXTexture& tex); + void Save(rsx::texture& tex); void Bind(); diff --git a/rpcs3/Emu/RSX/RSXTexture.cpp b/rpcs3/Emu/RSX/RSXTexture.cpp index ba07dfd5a3..c31a2d44f4 100644 --- a/rpcs3/Emu/RSX/RSXTexture.cpp +++ b/rpcs3/Emu/RSX/RSXTexture.cpp @@ -3,413 +3,416 @@ #include "RSXThread.h" #include "RSXTexture.h" -RSXTexture::RSXTexture() -{ - m_index = 0; -} - -RSXTexture::RSXTexture(u8 index) -{ - m_index = index; -} - -void RSXTexture::Init() -{ - // Offset - methodRegisters[NV4097_SET_TEXTURE_OFFSET + (m_index*32)] = 0; - - // Format - methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*32)] = 0; - - // Address - methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*32)] = - ((/*wraps*/1) | ((/*anisoBias*/0) << 4) | ((/*wrapt*/1) << 8) | ((/*unsignedRemap*/0) << 12) | - ((/*wrapr*/3) << 16) | ((/*gamma*/0) << 20) |((/*signedRemap*/0) << 24) | ((/*zfunc*/0) << 28)); - - // Control0 - methodRegisters[NV4097_SET_TEXTURE_CONTROL0 + (m_index*32)] = - (((/*alphakill*/0) << 2) | (/*maxaniso*/0) << 4) | ((/*maxlod*/0xc00) << 7) | ((/*minlod*/0) << 19) | ((/*enable*/0) << 31); - - // Control1 - methodRegisters[NV4097_SET_TEXTURE_CONTROL1 + (m_index*32)] = 0xE4; - - // Filter - methodRegisters[NV4097_SET_TEXTURE_FILTER + (m_index*32)] = - ((/*bias*/0) | ((/*conv*/1) << 13) | ((/*min*/5) << 16) | ((/*mag*/2) << 24) - | ((/*as*/0) << 28) | ((/*rs*/0) << 29) | ((/*gs*/0) << 30) | ((/*bs*/0) << 31) ); - - // Image Rect - methodRegisters[NV4097_SET_TEXTURE_IMAGE_RECT + (m_index*32)] = (/*height*/1) | ((/*width*/1) << 16); - - // Border Color - methodRegisters[NV4097_SET_TEXTURE_BORDER_COLOR + (m_index*32)] = 0; -} - -u32 RSXTexture::GetOffset() const -{ - return methodRegisters[NV4097_SET_TEXTURE_OFFSET + (m_index*32)]; -} - -u8 RSXTexture::GetLocation() const -{ - 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); -} - -u8 RSXTexture::GetBorderType() const -{ - 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); -} - -u8 RSXTexture::GetFormat() const -{ - 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); -} - -u8 RSXTexture::GetWrapS() const -{ - return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*32)]) & 0xf); -} - -u8 RSXTexture::GetWrapT() const -{ - return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*32)] >> 8) & 0xf); -} - -u8 RSXTexture::GetWrapR() const -{ - return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*32)] >> 16) & 0xf); -} - -u8 RSXTexture::GetUnsignedRemap() const -{ - return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*32)] >> 12) & 0xf); -} - -u8 RSXTexture::GetZfunc() const -{ - return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*32)] >> 28) & 0xf); -} - -u8 RSXTexture::GetGamma() const -{ - return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*32)] >> 20) & 0xf); -} - -u8 RSXTexture::GetAnisoBias() const -{ - return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*32)] >> 4) & 0xf); -} - -u8 RSXTexture::GetSignedRemap() const -{ - return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*32)] >> 24) & 0xf); -} - -bool RSXTexture::IsEnabled() const -{ - return ((methodRegisters[NV4097_SET_TEXTURE_CONTROL0 + (m_index*32)] >> 31) & 0x1); -} - -u16 RSXTexture::GetMinLOD() const -{ - return ((methodRegisters[NV4097_SET_TEXTURE_CONTROL0 + (m_index*32)] >> 19) & 0xfff); -} - -u16 RSXTexture::GetMaxLOD() const -{ - return ((methodRegisters[NV4097_SET_TEXTURE_CONTROL0 + (m_index*32)] >> 7) & 0xfff); -} - -u8 RSXTexture::GetMaxAniso() const -{ - return ((methodRegisters[NV4097_SET_TEXTURE_CONTROL0 + (m_index*32)] >> 4) & 0x7); -} - -bool RSXTexture::IsAlphaKillEnabled() const -{ - return ((methodRegisters[NV4097_SET_TEXTURE_CONTROL0 + (m_index*32)] >> 2) & 0x1); -} - -u32 RSXTexture::GetRemap() const -{ - return (methodRegisters[NV4097_SET_TEXTURE_CONTROL1 + (m_index*32)]); -} - -u16 RSXTexture::GetBias() const -{ - return ((methodRegisters[NV4097_SET_TEXTURE_FILTER + (m_index*32)]) & 0x1fff); -} - -u8 RSXTexture::GetMinFilter() const -{ - return ((methodRegisters[NV4097_SET_TEXTURE_FILTER + (m_index*32)] >> 16) & 0x7); -} - -u8 RSXTexture::GetMagFilter() const -{ - return ((methodRegisters[NV4097_SET_TEXTURE_FILTER + (m_index*32)] >> 24) & 0x7); -} - -u8 RSXTexture::GetConvolutionFilter() const -{ - return ((methodRegisters[NV4097_SET_TEXTURE_FILTER + (m_index*32)] >> 13) & 0xf); -} - -bool RSXTexture::isASigned() const -{ - return ((methodRegisters[NV4097_SET_TEXTURE_FILTER + (m_index*32)] >> 28) & 0x1); -} - -bool RSXTexture::isRSigned() const -{ - return ((methodRegisters[NV4097_SET_TEXTURE_FILTER + (m_index*32)] >> 29) & 0x1); -} - -bool RSXTexture::isGSigned() const -{ - return ((methodRegisters[NV4097_SET_TEXTURE_FILTER + (m_index*32)] >> 30) & 0x1); -} - -bool RSXTexture::isBSigned() const -{ - return ((methodRegisters[NV4097_SET_TEXTURE_FILTER + (m_index*32)] >> 31) & 0x1); -} - -u16 RSXTexture::GetWidth() const -{ - return ((methodRegisters[NV4097_SET_TEXTURE_IMAGE_RECT + (m_index*32)] >> 16) & 0xffff); -} - -u16 RSXTexture::GetHeight() const -{ - return ((methodRegisters[NV4097_SET_TEXTURE_IMAGE_RECT + (m_index*32)]) & 0xffff); -} - -u32 RSXTexture::GetBorderColor() const -{ - return methodRegisters[NV4097_SET_TEXTURE_BORDER_COLOR + (m_index*32)]; -} - -void RSXTexture::SetControl3(u16 depth, u32 pitch) -{ - m_depth = depth; - m_pitch = pitch; -} - -RSXVertexTexture::RSXVertexTexture() : RSXTexture() -{ -} - -RSXVertexTexture::RSXVertexTexture(u8 index) : RSXTexture(index) -{ -} - -void RSXVertexTexture::Init() -{ - // Offset - methodRegisters[NV4097_SET_VERTEX_TEXTURE_OFFSET + (m_index * 32)] = 0; - - // Format - methodRegisters[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 32)] = 0; - - // Address - methodRegisters[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 32)] = - ((/*wraps*/1) | ((/*anisoBias*/0) << 4) | ((/*wrapt*/1) << 8) | ((/*unsignedRemap*/0) << 12) | - ((/*wrapr*/3) << 16) | ((/*gamma*/0) << 20) | ((/*signedRemap*/0) << 24) | ((/*zfunc*/0) << 28)); - - // Control0 - methodRegisters[NV4097_SET_VERTEX_TEXTURE_CONTROL0 + (m_index * 32)] = - (((/*alphakill*/0) << 2) | (/*maxaniso*/0) << 4) | ((/*maxlod*/0xc00) << 7) | ((/*minlod*/0) << 19) | ((/*enable*/0) << 31); - - // Control1 - //methodRegisters[NV4097_SET_VERTEX_TEXTURE_CONTROL1 + (m_index * 32)] = 0xE4; - - // Filter - methodRegisters[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 32)] = - ((/*bias*/0) | ((/*conv*/1) << 13) | ((/*min*/5) << 16) | ((/*mag*/2) << 24) - | ((/*as*/0) << 28) | ((/*rs*/0) << 29) | ((/*gs*/0) << 30) | ((/*bs*/0) << 31)); - - // Image Rect - methodRegisters[NV4097_SET_VERTEX_TEXTURE_IMAGE_RECT + (m_index * 32)] = (/*height*/1) | ((/*width*/1) << 16); - - // Border Color - methodRegisters[NV4097_SET_VERTEX_TEXTURE_BORDER_COLOR + (m_index * 32)] = 0; -} - -u32 RSXVertexTexture::GetOffset() const -{ - return methodRegisters[NV4097_SET_VERTEX_TEXTURE_OFFSET + (m_index * 32)]; -} - -u8 RSXVertexTexture::GetLocation() const -{ - return (methodRegisters[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 32)] & 0x3) - 1; -} - -bool RSXVertexTexture::isCubemap() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 32)] >> 2) & 0x1); -} - -u8 RSXVertexTexture::GetBorderType() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 32)] >> 3) & 0x1); -} - -u8 RSXVertexTexture::GetDimension() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 32)] >> 4) & 0xf); -} - -u8 RSXVertexTexture::GetFormat() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 32)] >> 8) & 0xff); -} - -u16 RSXVertexTexture::GetMipmap() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 32)] >> 16) & 0xffff); -} - -u8 RSXVertexTexture::GetWrapS() const -{ - return 1; - //return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 32)]) & 0xf); -} - -u8 RSXVertexTexture::GetWrapT() const -{ - return 1; - //return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 32)] >> 8) & 0xf); -} - -u8 RSXVertexTexture::GetWrapR() const -{ - return 1; - //return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 32)] >> 16) & 0xf); -} - -u8 RSXVertexTexture::GetUnsignedRemap() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 32)] >> 12) & 0xf); -} - -u8 RSXVertexTexture::GetZfunc() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 32)] >> 28) & 0xf); -} - -u8 RSXVertexTexture::GetGamma() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 32)] >> 20) & 0xf); -} - -u8 RSXVertexTexture::GetAnisoBias() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 32)] >> 4) & 0xf); -} - -u8 RSXVertexTexture::GetSignedRemap() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 32)] >> 24) & 0xf); -} - -bool RSXVertexTexture::IsEnabled() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_CONTROL0 + (m_index * 32)] >> 31) & 0x1); -} - -u16 RSXVertexTexture::GetMinLOD() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_CONTROL0 + (m_index * 32)] >> 19) & 0xfff); -} - -u16 RSXVertexTexture::GetMaxLOD() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_CONTROL0 + (m_index * 32)] >> 7) & 0xfff); -} - -u8 RSXVertexTexture::GetMaxAniso() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_CONTROL0 + (m_index * 32)] >> 4) & 0x7); -} - -bool RSXVertexTexture::IsAlphaKillEnabled() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_CONTROL0 + (m_index * 32)] >> 2) & 0x1); -} - -u32 RSXVertexTexture::GetRemap() const -{ - return 0 | (1 << 2) | (2 << 4) | (3 << 6);//(methodRegisters[NV4097_SET_VERTEX_TEXTURE_CONTROL1 + (m_index * 32)]); -} - -u16 RSXVertexTexture::GetBias() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 32)]) & 0x1fff); -} - -u8 RSXVertexTexture::GetMinFilter() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 32)] >> 16) & 0x7); -} - -u8 RSXVertexTexture::GetMagFilter() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 32)] >> 24) & 0x7); -} - -u8 RSXVertexTexture::GetConvolutionFilter() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 32)] >> 13) & 0xf); -} - -bool RSXVertexTexture::isASigned() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 32)] >> 28) & 0x1); -} - -bool RSXVertexTexture::isRSigned() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 32)] >> 29) & 0x1); -} - -bool RSXVertexTexture::isGSigned() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 32)] >> 30) & 0x1); -} - -bool RSXVertexTexture::isBSigned() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 32)] >> 31) & 0x1); -} - -u16 RSXVertexTexture::GetWidth() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_IMAGE_RECT + (m_index * 32)] >> 16) & 0xffff); -} - -u16 RSXVertexTexture::GetHeight() const -{ - return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_IMAGE_RECT + (m_index * 32)]) & 0xffff); -} - -u32 RSXVertexTexture::GetBorderColor() const -{ - return methodRegisters[NV4097_SET_VERTEX_TEXTURE_BORDER_COLOR + (m_index * 32)]; +namespace rsx +{ + void texture::init(u8 index) + { + m_index = index; + + // Offset + method_registers[NV4097_SET_TEXTURE_OFFSET + (m_index * 8)] = 0; + + // Format + method_registers[NV4097_SET_TEXTURE_FORMAT + (m_index * 8)] = 0; + + // Address + method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)] = + ((/*wraps*/1) | ((/*anisoBias*/0) << 4) | ((/*wrapt*/1) << 8) | ((/*unsignedRemap*/0) << 12) | + ((/*wrapr*/3) << 16) | ((/*gamma*/0) << 20) | ((/*signedRemap*/0) << 24) | ((/*zfunc*/0) << 28)); + + // Control0 + method_registers[NV4097_SET_TEXTURE_CONTROL0 + (m_index * 8)] = + (((/*alphakill*/0) << 2) | (/*maxaniso*/0) << 4) | ((/*maxlod*/0xc00) << 7) | ((/*minlod*/0) << 19) | ((/*enable*/0) << 31); + + // Control1 + method_registers[NV4097_SET_TEXTURE_CONTROL1 + (m_index * 8)] = 0xE4; + + // Filter + method_registers[NV4097_SET_TEXTURE_FILTER + (m_index * 8)] = + ((/*bias*/0) | ((/*conv*/1) << 13) | ((/*min*/5) << 16) | ((/*mag*/2) << 24) + | ((/*as*/0) << 28) | ((/*rs*/0) << 29) | ((/*gs*/0) << 30) | ((/*bs*/0) << 31)); + + // Image Rect + method_registers[NV4097_SET_TEXTURE_IMAGE_RECT + (m_index * 8)] = (/*height*/1) | ((/*width*/1) << 16); + + // Border Color + method_registers[NV4097_SET_TEXTURE_BORDER_COLOR + (m_index * 8)] = 0; + } + + u32 texture::offset() const + { + return method_registers[NV4097_SET_TEXTURE_OFFSET + (m_index * 8)]; + } + + u8 texture::location() const + { + return (method_registers[NV4097_SET_TEXTURE_FORMAT + (m_index * 8)] & 0x3) - 1; + } + + bool texture::cubemap() const + { + return ((method_registers[NV4097_SET_TEXTURE_FORMAT + (m_index * 8)] >> 2) & 0x1); + } + + u8 texture::border_type() const + { + return ((method_registers[NV4097_SET_TEXTURE_FORMAT + (m_index * 8)] >> 3) & 0x1); + } + + u8 texture::dimension() const + { + return ((method_registers[NV4097_SET_TEXTURE_FORMAT + (m_index * 8)] >> 4) & 0xf); + } + + u8 texture::format() const + { + return ((method_registers[NV4097_SET_TEXTURE_FORMAT + (m_index * 8)] >> 8) & 0xff); + } + + u16 texture::mipmap() const + { + return ((method_registers[NV4097_SET_TEXTURE_FORMAT + (m_index * 8)] >> 16) & 0xffff); + } + + u8 texture::wrap_s() const + { + return ((method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)]) & 0xf); + } + + u8 texture::wrap_t() const + { + return ((method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)] >> 8) & 0xf); + } + + u8 texture::wrap_r() const + { + return ((method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)] >> 16) & 0xf); + } + + u8 texture::unsigned_remap() const + { + return ((method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)] >> 12) & 0xf); + } + + u8 texture::zfunc() const + { + return ((method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)] >> 28) & 0xf); + } + + u8 texture::gamma() const + { + return ((method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)] >> 20) & 0xf); + } + + u8 texture::aniso_bias() const + { + return ((method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)] >> 4) & 0xf); + } + + u8 texture::signed_remap() const + { + return ((method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)] >> 24) & 0xf); + } + + bool texture::enabled() const + { + return location() <= 1 && ((method_registers[NV4097_SET_TEXTURE_CONTROL0 + (m_index * 8)] >> 31) & 0x1); + } + + u16 texture::min_lod() const + { + return ((method_registers[NV4097_SET_TEXTURE_CONTROL0 + (m_index * 8)] >> 19) & 0xfff); + } + + u16 texture::max_lod() const + { + return ((method_registers[NV4097_SET_TEXTURE_CONTROL0 + (m_index * 8)] >> 7) & 0xfff); + } + + u8 texture::max_aniso() const + { + return ((method_registers[NV4097_SET_TEXTURE_CONTROL0 + (m_index * 8)] >> 4) & 0x7); + } + + bool texture::alpha_kill_enabled() const + { + return ((method_registers[NV4097_SET_TEXTURE_CONTROL0 + (m_index * 8)] >> 2) & 0x1); + } + + u32 texture::remap() const + { + return (method_registers[NV4097_SET_TEXTURE_CONTROL1 + (m_index * 8)]); + } + + u16 texture::bias() const + { + return ((method_registers[NV4097_SET_TEXTURE_FILTER + (m_index * 8)]) & 0x1fff); + } + + u8 texture::min_filter() const + { + return ((method_registers[NV4097_SET_TEXTURE_FILTER + (m_index * 8)] >> 16) & 0x7); + } + + u8 texture::mag_filter() const + { + return ((method_registers[NV4097_SET_TEXTURE_FILTER + (m_index * 8)] >> 24) & 0x7); + } + + u8 texture::convolution_filter() const + { + return ((method_registers[NV4097_SET_TEXTURE_FILTER + (m_index * 8)] >> 13) & 0xf); + } + + bool texture::a_signed() const + { + return ((method_registers[NV4097_SET_TEXTURE_FILTER + (m_index * 8)] >> 28) & 0x1); + } + + bool texture::r_signed() const + { + return ((method_registers[NV4097_SET_TEXTURE_FILTER + (m_index * 8)] >> 29) & 0x1); + } + + bool texture::g_signed() const + { + return ((method_registers[NV4097_SET_TEXTURE_FILTER + (m_index * 8)] >> 30) & 0x1); + } + + bool texture::b_signed() const + { + return ((method_registers[NV4097_SET_TEXTURE_FILTER + (m_index * 8)] >> 31) & 0x1); + } + + u16 texture::width() const + { + return ((method_registers[NV4097_SET_TEXTURE_IMAGE_RECT + (m_index * 8)] >> 16) & 0xffff); + } + + u16 texture::height() const + { + return ((method_registers[NV4097_SET_TEXTURE_IMAGE_RECT + (m_index * 8)]) & 0xffff); + } + + u32 texture::border_color() const + { + return method_registers[NV4097_SET_TEXTURE_BORDER_COLOR + (m_index * 8)]; + } + + u16 texture::depth() const + { + return method_registers[NV4097_SET_TEXTURE_CONTROL3] >> 20; + } + + u32 texture::pitch() const + { + return method_registers[NV4097_SET_TEXTURE_CONTROL3] & 0xfffff; + } + + void vertex_texture::init(u8 index) + { + m_index = index; + + // Offset + method_registers[NV4097_SET_VERTEX_TEXTURE_OFFSET + (m_index * 8)] = 0; + + // Format + method_registers[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 8)] = 0; + + // Address + method_registers[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 8)] = + ((/*wraps*/1) | ((/*anisoBias*/0) << 4) | ((/*wrapt*/1) << 8) | ((/*unsignedRemap*/0) << 12) | + ((/*wrapr*/3) << 16) | ((/*gamma*/0) << 20) | ((/*signedRemap*/0) << 24) | ((/*zfunc*/0) << 28)); + + // Control0 + method_registers[NV4097_SET_VERTEX_TEXTURE_CONTROL0 + (m_index * 8)] = + (((/*alphakill*/0) << 2) | (/*maxaniso*/0) << 4) | ((/*maxlod*/0xc00) << 7) | ((/*minlod*/0) << 19) | ((/*enable*/0) << 31); + + // Control1 + //method_registers[NV4097_SET_VERTEX_TEXTURE_CONTROL1 + (m_index * 8)] = 0xE4; + + // Filter + method_registers[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 8)] = + ((/*bias*/0) | ((/*conv*/1) << 13) | ((/*min*/5) << 16) | ((/*mag*/2) << 24) + | ((/*as*/0) << 28) | ((/*rs*/0) << 29) | ((/*gs*/0) << 30) | ((/*bs*/0) << 31)); + + // Image Rect + method_registers[NV4097_SET_VERTEX_TEXTURE_IMAGE_RECT + (m_index * 8)] = (/*height*/1) | ((/*width*/1) << 16); + + // Border Color + method_registers[NV4097_SET_VERTEX_TEXTURE_BORDER_COLOR + (m_index * 8)] = 0; + } + + u32 vertex_texture::offset() const + { + return method_registers[NV4097_SET_VERTEX_TEXTURE_OFFSET + (m_index * 8)]; + } + + u8 vertex_texture::location() const + { + return (method_registers[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 8)] & 0x3) - 1; + } + + bool vertex_texture::cubemap() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 8)] >> 2) & 0x1); + } + + u8 vertex_texture::border_type() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 8)] >> 3) & 0x1); + } + + u8 vertex_texture::dimension() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 8)] >> 4) & 0xf); + } + + u8 vertex_texture::format() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 8)] >> 8) & 0xff); + } + + u16 vertex_texture::mipmap() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 8)] >> 16) & 0xffff); + } + + u8 vertex_texture::wrap_s() const + { + return 1; + //return ((method_registers[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 8)]) & 0xf); + } + + u8 vertex_texture::wrap_t() const + { + return 1; + //return ((method_registers[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 8)] >> 8) & 0xf); + } + + u8 vertex_texture::wrap_r() const + { + return 1; + //return ((method_registers[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 8)] >> 16) & 0xf); + } + + u8 vertex_texture::unsigned_remap() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 8)] >> 12) & 0xf); + } + + u8 vertex_texture::zfunc() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 8)] >> 28) & 0xf); + } + + u8 vertex_texture::gamma() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 8)] >> 20) & 0xf); + } + + u8 vertex_texture::aniso_bias() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 8)] >> 4) & 0xf); + } + + u8 vertex_texture::signed_remap() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 8)] >> 24) & 0xf); + } + + bool vertex_texture::enabled() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_CONTROL0 + (m_index * 8)] >> 31) & 0x1); + } + + u16 vertex_texture::min_lod() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_CONTROL0 + (m_index * 8)] >> 19) & 0xfff); + } + + u16 vertex_texture::max_lod() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_CONTROL0 + (m_index * 8)] >> 7) & 0xfff); + } + + u8 vertex_texture::max_aniso() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_CONTROL0 + (m_index * 8)] >> 4) & 0x7); + } + + bool vertex_texture::alpha_kill_enabled() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_CONTROL0 + (m_index * 8)] >> 2) & 0x1); + } + + u32 vertex_texture::remap() const + { + return 0 | (1 << 2) | (2 << 4) | (3 << 6);//(method_registers[NV4097_SET_VERTEX_TEXTURE_CONTROL1 + (m_index * 8)]); + } + + u16 vertex_texture::bias() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 8)]) & 0x1fff); + } + + u8 vertex_texture::min_filter() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 8)] >> 16) & 0x7); + } + + u8 vertex_texture::mag_filter() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 8)] >> 24) & 0x7); + } + + u8 vertex_texture::convolution_filter() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 8)] >> 13) & 0xf); + } + + bool vertex_texture::a_signed() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 8)] >> 28) & 0x1); + } + + bool vertex_texture::r_signed() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 8)] >> 29) & 0x1); + } + + bool vertex_texture::g_signed() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 8)] >> 30) & 0x1); + } + + bool vertex_texture::b_signed() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 8)] >> 31) & 0x1); + } + + u16 vertex_texture::width() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_IMAGE_RECT + (m_index * 8)] >> 16) & 0xffff); + } + + u16 vertex_texture::height() const + { + return ((method_registers[NV4097_SET_VERTEX_TEXTURE_IMAGE_RECT + (m_index * 8)]) & 0xffff); + } + + u32 vertex_texture::border_color() const + { + return method_registers[NV4097_SET_VERTEX_TEXTURE_BORDER_COLOR + (m_index * 8)]; + } + + u16 vertex_texture::depth() const + { + return method_registers[NV4097_SET_VERTEX_TEXTURE_CONTROL3] >> 20; + } + + u32 vertex_texture::pitch() const + { + return method_registers[NV4097_SET_VERTEX_TEXTURE_CONTROL3] & 0xfffff; + } } \ No newline at end of file diff --git a/rpcs3/Emu/RSX/RSXTexture.h b/rpcs3/Emu/RSX/RSXTexture.h index c595dba082..f2a8342e98 100644 --- a/rpcs3/Emu/RSX/RSXTexture.h +++ b/rpcs3/Emu/RSX/RSXTexture.h @@ -1,122 +1,130 @@ #pragma once -class RSXTexture +namespace rsx { -protected: - u8 m_index; + class texture + { + protected: + u8 m_index; -public: - u32 m_pitch; - u16 m_depth; + public: + //initialize texture registers with default values + void init(u8 index); -public: - RSXTexture(); - RSXTexture(u8 index); - virtual void Init(); + // Offset + u32 offset() const; - // Offset - virtual u32 GetOffset() const; + // Format + u8 location() const; + bool cubemap() const; + u8 border_type() const; + u8 dimension() const; + u8 format() const; + u16 mipmap() const; - // Format - virtual u8 GetLocation() const; - virtual bool isCubemap() const; - virtual u8 GetBorderType() const; - virtual u8 GetDimension() const; - virtual u8 GetFormat() const; - virtual u16 GetMipmap() const; + // Address + u8 wrap_s() const; + u8 wrap_t() const; + u8 wrap_r() const; + u8 unsigned_remap() const; + u8 zfunc() const; + u8 gamma() const; + u8 aniso_bias() const; + u8 signed_remap() const; - // Address - virtual u8 GetWrapS() const; - virtual u8 GetWrapT() const; - virtual u8 GetWrapR() const; - virtual u8 GetUnsignedRemap() const; - virtual u8 GetZfunc() const; - virtual u8 GetGamma() const; - virtual u8 GetAnisoBias() const; - virtual u8 GetSignedRemap() const; + // Control0 + bool enabled() const; + u16 min_lod() const; + u16 max_lod() const; + u8 max_aniso() const; + bool alpha_kill_enabled() const; - // Control0 - virtual bool IsEnabled() const; - virtual u16 GetMinLOD() const; - virtual u16 GetMaxLOD() const; - virtual u8 GetMaxAniso() const; - virtual bool IsAlphaKillEnabled() const; + // Control1 + u32 remap() const; - // Control1 - virtual u32 GetRemap() const; + // Filter + u16 bias() const; + u8 min_filter() const; + u8 mag_filter() const; + u8 convolution_filter() const; + bool a_signed() const; + bool r_signed() const; + bool g_signed() const; + bool b_signed() const; - // Filter - virtual u16 GetBias() const; - virtual u8 GetMinFilter() const; - virtual u8 GetMagFilter() const; - virtual u8 GetConvolutionFilter() const; - virtual bool isASigned() const; - virtual bool isRSigned() const; - virtual bool isGSigned() const; - virtual bool isBSigned() const; + // Image Rect + u16 width() const; + u16 height() const; - // Image Rect - virtual u16 GetWidth() const; - virtual u16 GetHeight() const; + // Border Color + u32 border_color() const; + u16 depth() const; + u32 pitch() const; - // Border Color - virtual u32 GetBorderColor() const; + //custom info + u8 index() const; + }; - void SetControl3(u16 depth, u32 pitch); -}; + class vertex_texture + { + protected: + u8 m_index; -class RSXVertexTexture : public RSXTexture -{ -public: - RSXVertexTexture(); - RSXVertexTexture(u8 index); - void Init(); + public: + //initialize texture registers with default values + void init(u8 index); - // Offset - u32 GetOffset() const; + // Offset + u32 offset() const; - // Format - u8 GetLocation() const; - bool isCubemap() const; - u8 GetBorderType() const; - u8 GetDimension() const; - u8 GetFormat() const; - u16 GetMipmap() const; + // Format + u8 location() const; + bool cubemap() const; + u8 border_type() const; + u8 dimension() const; + u8 format() const; + u16 mipmap() const; - // Address - u8 GetWrapS() const; - u8 GetWrapT() const; - u8 GetWrapR() const; - u8 GetUnsignedRemap() const; - u8 GetZfunc() const; - u8 GetGamma() const; - u8 GetAnisoBias() const; - u8 GetSignedRemap() const; + // Address + u8 wrap_s() const; + u8 wrap_t() const; + u8 wrap_r() const; + u8 unsigned_remap() const; + u8 zfunc() const; + u8 gamma() const; + u8 aniso_bias() const; + u8 signed_remap() const; - // Control0 - bool IsEnabled() const; - u16 GetMinLOD() const; - u16 GetMaxLOD() const; - u8 GetMaxAniso() const; - bool IsAlphaKillEnabled() const; + // Control0 + bool enabled() const; + u16 min_lod() const; + u16 max_lod() const; + u8 max_aniso() const; + bool alpha_kill_enabled() const; - // Control1 - u32 GetRemap() const; + // Control1 + u32 remap() const; - // Filter - u16 GetBias() const; - u8 GetMinFilter() const; - u8 GetMagFilter() const; - u8 GetConvolutionFilter() const; - bool isASigned() const; - bool isRSigned() const; - bool isGSigned() const; - bool isBSigned() const; + // Filter + u16 bias() const; + u8 min_filter() const; + u8 mag_filter() const; + u8 convolution_filter() const; + bool a_signed() const; + bool r_signed() const; + bool g_signed() const; + bool b_signed() const; - // Image Rect - u16 GetWidth() const; - u16 GetHeight() const; + // Image Rect + u16 width() const; + u16 height() const; - // Border Color - u32 GetBorderColor() const; -}; \ No newline at end of file + // Border Color + u32 border_color() const; + u16 depth() const; + u32 pitch() const; + + //custom info + u8 index() const; + }; +} \ No newline at end of file diff --git a/rpcs3/Emu/RSX/RSXThread.cpp b/rpcs3/Emu/RSX/RSXThread.cpp index 07648dbd57..05cf2ec305 100644 --- a/rpcs3/Emu/RSX/RSXThread.cpp +++ b/rpcs3/Emu/RSX/RSXThread.cpp @@ -22,41 +22,46 @@ extern u64 get_system_time(); #define ARGS(x) (x >= count ? OutOfArgsCount(x, cmd, count, args.addr()) : args[x].value()) #define CMD_DEBUG 0 -u32 methodRegisters[0xffff]; -u32 GetAddress(u32 offset, u32 location) + +namespace rsx { - u32 res = 0; + u32 method_registers[0x10000 >> 2]; - switch (location) + u32 get_address(u32 offset, u32 location) { - case CELL_GCM_LOCATION_LOCAL: - { - res = 0xC0000000 + offset; - break; - } - case CELL_GCM_LOCATION_MAIN: - { - res = RSXIOMem.RealAddr(offset); // TODO: Error Check? - if (res == 0) + u32 res = 0; + + switch (location) { - throw EXCEPTION("RSXIO memory not mapped (offset=0x%x)", offset); + case CELL_GCM_LOCATION_LOCAL: + { + res = 0xC0000000 + offset; + break; + } + case CELL_GCM_LOCATION_MAIN: + { + res = RSXIOMem.RealAddr(offset); // TODO: Error Check? + if (res == 0) + { + throw EXCEPTION("RSXIO memory not mapped (offset=0x%x)", offset); + } + + if (Emu.GetGSManager().GetRender().strict_ordering[offset >> 20]) + { + _mm_mfence(); // probably doesn't have any effect on current implementation + } + + break; + } + default: + { + throw EXCEPTION("Invalid location (offset=0x%x, location=0x%x)", offset, location); + } } - if (Emu.GetGSManager().GetRender().strict_ordering[offset >> 20]) - { - _mm_mfence(); // probably doesn't have any effect on current implementation - } - - break; + return res; } - default: - { - throw EXCEPTION("Invalid location (offset=0x%x, location=0x%x)", offset, location); - } - } - - return res; } RSXVertexData::RSXVertexData() @@ -366,11 +371,11 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const case_range(16, NV4097_SET_TEXTURE_CONTROL3, 4); { - RSXTexture& tex = m_textures[index]; + rsx::texture& tex = m_textures[index]; const u32 a0 = ARGS(0); u32 pitch = a0 & 0xFFFFF; u16 depth = a0 >> 20; - tex.SetControl3(depth, pitch); + //tex.SetControl3(depth, pitch); break; } @@ -389,11 +394,11 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const case_range(4, NV4097_SET_VERTEX_TEXTURE_CONTROL3, 0x20); { - RSXVertexTexture& tex = m_vertex_textures[index]; + rsx::vertex_texture& tex = m_vertex_textures[index]; const u32 a0 = ARGS(0); u32 pitch = a0 & 0xFFFFF; u16 depth = a0 >> 20; - tex.SetControl3(depth, pitch); + //tex.SetControl3(depth, pitch); break; } @@ -466,7 +471,7 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const case_range(16, NV4097_SET_VERTEX_DATA_ARRAY_OFFSET, 4); { - const u32 addr = GetAddress(ARGS(0) & 0x7fffffff, ARGS(0) >> 31); + const u32 addr = rsx::get_address(ARGS(0) & 0x7fffffff, ARGS(0) >> 31); m_vertex_data[index].addr = addr; m_vertex_data[index].data.clear(); @@ -949,7 +954,7 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const case NV4097_SET_INDEX_ARRAY_ADDRESS: { - m_indexed_array.m_addr = GetAddress(ARGS(0), ARGS(1) & 0xf); + m_indexed_array.m_addr = rsx::get_address(ARGS(0), ARGS(1) & 0xf); m_indexed_array.m_type = ARGS(1) >> 4; break; } @@ -1063,7 +1068,7 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const const u32 a0 = ARGS(0); m_cur_fragment_prog->offset = a0 & ~0x3; - m_cur_fragment_prog->addr = GetAddress(m_cur_fragment_prog->offset, (a0 & 0x3) - 1); + m_cur_fragment_prog->addr = rsx::get_address(m_cur_fragment_prog->offset, (a0 & 0x3) - 1); m_cur_fragment_prog->ctrl = 0x40; notifyProgramChange(); break; @@ -1979,7 +1984,7 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const if (lineCount == 1 && !inPitch && !outPitch && !notify) { - memcpy(vm::get_ptr(GetAddress(outOffset, 0)), vm::get_ptr(GetAddress(inOffset, 0)), lineLength); + memcpy(vm::get_ptr(rsx::get_address(outOffset, 0)), vm::get_ptr(rsx::get_address(inOffset, 0)), lineLength); } else { @@ -2211,8 +2216,8 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const const u16 u = ARGS(3); // inX (currently ignored) const u16 v = ARGS(3) >> 16; // inY (currently ignored) - u8* pixels_src = vm::get_ptr(GetAddress(offset, m_context_dma_img_src - 0xfeed0000)); - u8* pixels_dst = vm::get_ptr(GetAddress(m_dst_offset, m_context_dma_img_dst - 0xfeed0000)); + u8* pixels_src = vm::get_ptr(rsx::get_address(offset, m_context_dma_img_src - 0xfeed0000)); + u8* pixels_dst = vm::get_ptr(rsx::get_address(m_dst_offset, m_context_dma_img_dst - 0xfeed0000)); if (m_context_surface == CELL_GCM_CONTEXT_SWIZZLE2D) { @@ -2588,7 +2593,7 @@ void RSXThread::Task() for (u32 i = 0; i < count; i++) { - methodRegisters[(cmd & 0xffff) + (i * 4 * inc)] = ARGS(i); + rsx::method_registers[(cmd & 0xffff) + (i * 4 * inc)] = ARGS(i); } DoCmd(cmd, cmd & 0x3ffff, args.addr(), count); diff --git a/rpcs3/Emu/RSX/RSXThread.h b/rpcs3/Emu/RSX/RSXThread.h index ccbb28708b..42b2e4fef3 100644 --- a/rpcs3/Emu/RSX/RSXThread.h +++ b/rpcs3/Emu/RSX/RSXThread.h @@ -9,6 +9,29 @@ #include "Utilities/Thread.h" #include "Utilities/Timer.h" + +namespace rsx +{ + namespace limits + { + enum + { + textures_count = 16, + vertex_textures_count = 4, + vertex_count = 16, + fragment_count = 32, + tiles_count = 15, + zculls_count = 8, + color_buffers_count = 4 + }; + } + + extern u32 method_registers[0x10000 >> 2]; + + u32 get_address(u32 offset, u32 location); + +} + enum Method { CELL_GCM_METHOD_FLAG_NON_INCREMENT = 0x40000000, @@ -17,9 +40,6 @@ enum Method CELL_GCM_METHOD_FLAG_RETURN = 0x00020000, }; -extern u32 methodRegisters[0xffff]; -u32 GetAddress(u32 offset, u32 location); - struct RSXVertexData { u32 frequency; @@ -107,8 +127,8 @@ protected: public: GcmTileInfo tiles[m_tiles_count]; GcmZcullInfo zculls[m_zculls_count]; - RSXTexture m_textures[m_textures_count]; - RSXVertexTexture m_vertex_textures[m_textures_count]; + rsx::texture m_textures[m_textures_count]; + rsx::vertex_texture m_vertex_textures[m_textures_count]; RSXVertexData m_vertex_data[m_vertex_count]; RSXIndexArrayData m_indexed_array; std::vector m_fragment_constants; @@ -543,7 +563,7 @@ protected: // Construct Textures for (int i = 0; i < 16; i++) { - m_textures[i] = RSXTexture(i); + m_textures[i] = rsx::texture(); } Reset(); @@ -632,7 +652,7 @@ protected: for (uint i = 0; i < m_textures_count; ++i) { - m_textures[i].Init(); + m_textures[i].init(i); } } diff --git a/rpcs3/Gui/RSXDebugger.cpp b/rpcs3/Gui/RSXDebugger.cpp index d836b6fbd6..c7a4995dc4 100644 --- a/rpcs3/Gui/RSXDebugger.cpp +++ b/rpcs3/Gui/RSXDebugger.cpp @@ -316,13 +316,13 @@ void RSXDebugger::OnClickBuffer(wxMouseEvent& event) if (event.GetId() == p_buffer_colorD->GetId()) SHOW_BUFFER(3); if (event.GetId() == p_buffer_tex->GetId()) { - u8 location = render.m_textures[m_cur_texture].GetLocation(); - if(location <= 1 && vm::check_addr(GetAddress(render.m_textures[m_cur_texture].GetOffset(), location)) - && render.m_textures[m_cur_texture].GetWidth() && render.m_textures[m_cur_texture].GetHeight()) + u8 location = render.m_textures[m_cur_texture].location(); + if(location <= 1 && vm::check_addr(rsx::get_address(render.m_textures[m_cur_texture].offset(), location)) + && render.m_textures[m_cur_texture].width() && render.m_textures[m_cur_texture].height()) MemoryViewerPanel::ShowImage(this, - GetAddress(render.m_textures[m_cur_texture].GetOffset(), location), 1, - render.m_textures[m_cur_texture].GetWidth(), - render.m_textures[m_cur_texture].GetHeight(), false); + rsx::get_address(render.m_textures[m_cur_texture].offset(), location), 1, + render.m_textures[m_cur_texture].width(), + render.m_textures[m_cur_texture].height(), false); } #undef SHOW_BUFFER @@ -453,28 +453,28 @@ void RSXDebugger::GetBuffers() } // Draw Texture - if(!render.m_textures[m_cur_texture].IsEnabled()) + if(!render.m_textures[m_cur_texture].enabled()) return; - u32 offset = render.m_textures[m_cur_texture].GetOffset(); + u32 offset = render.m_textures[m_cur_texture].offset(); if(!offset) return; - u8 location = render.m_textures[m_cur_texture].GetLocation(); + u8 location = render.m_textures[m_cur_texture].location(); if(location > 1) return; - u32 TexBuffer_addr = GetAddress(offset, location); + u32 TexBuffer_addr = rsx::get_address(offset, location); if(!vm::check_addr(TexBuffer_addr)) return; unsigned char* TexBuffer = vm::get_ptr(TexBuffer_addr); - u32 width = render.m_textures[m_cur_texture].GetWidth(); - u32 height = render.m_textures[m_cur_texture].GetHeight(); + u32 width = render.m_textures[m_cur_texture].width(); + u32 height = render.m_textures[m_cur_texture].height(); unsigned char* buffer = (unsigned char*)malloc(width * height * 3); memcpy(buffer, TexBuffer, width * height * 3); @@ -553,29 +553,29 @@ void RSXDebugger::GetTexture() for(uint i=0; iInsertItem(i, wxString::Format("%d", i)); - u8 location = render.m_textures[i].GetLocation(); + u8 location = render.m_textures[i].location(); if(location > 1) { m_list_texture->SetItem(i, 1, - wxString::Format("Bad address (offset=0x%x, location=%d)", render.m_textures[i].GetOffset(), location)); + wxString::Format("Bad address (offset=0x%x, location=%d)", render.m_textures[i].offset(), location)); } else { - m_list_texture->SetItem(i, 1, wxString::Format("0x%x", GetAddress(render.m_textures[i].GetOffset(), location))); + m_list_texture->SetItem(i, 1, wxString::Format("0x%x", rsx::get_address(render.m_textures[i].offset(), location))); } - m_list_texture->SetItem(i, 2, render.m_textures[i].isCubemap() ? "True" : "False"); - m_list_texture->SetItem(i, 3, wxString::Format("%dD", render.m_textures[i].GetDimension())); - m_list_texture->SetItem(i, 4, render.m_textures[i].IsEnabled() ? "True" : "False"); - m_list_texture->SetItem(i, 5, wxString::Format("0x%x", render.m_textures[i].GetFormat())); - m_list_texture->SetItem(i, 6, wxString::Format("0x%x", render.m_textures[i].GetMipmap())); - m_list_texture->SetItem(i, 7, wxString::Format("0x%x", render.m_textures[i].m_pitch)); + m_list_texture->SetItem(i, 2, render.m_textures[i].cubemap() ? "True" : "False"); + m_list_texture->SetItem(i, 3, wxString::Format("%dD", render.m_textures[i].dimension())); + m_list_texture->SetItem(i, 4, render.m_textures[i].enabled() ? "True" : "False"); + m_list_texture->SetItem(i, 5, wxString::Format("0x%x", render.m_textures[i].format())); + m_list_texture->SetItem(i, 6, wxString::Format("0x%x", render.m_textures[i].mipmap())); + m_list_texture->SetItem(i, 7, wxString::Format("0x%x", render.m_textures[i].pitch())); m_list_texture->SetItem(i, 8, wxString::Format("%dx%d", - render.m_textures[i].GetWidth(), - render.m_textures[i].GetHeight())); + render.m_textures[i].width(), + render.m_textures[i].height())); m_list_texture->SetItemBackgroundColour(i, wxColour(m_cur_texture == i ? "Wheat" : "White")); }