RSX: Create a rsx namespace.

Put get_address inside.
This commit is contained in:
Vincent Lejeune 2015-10-08 15:53:21 +02:00
parent e3e5b46cbf
commit 3de47c201c
13 changed files with 781 additions and 745 deletions

View file

@ -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; 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) switch (format)
{ {
@ -390,11 +390,11 @@ size_t getPlacedTextureStorageSpace(const RSXTexture &texture, size_t rowPitchAl
return rowPitch * heightInBlocks * 2; // * 2 for mipmap levels return rowPitch * heightInBlocks * 2; // * 2 for mipmap levels
} }
std::vector<MipmapLevelInfo> uploadPlacedTexture(const RSXTexture &texture, size_t rowPitchAlignement, void* textureData) std::vector<MipmapLevelInfo> 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; size_t blockSizeInByte, blockWidthInPixel, blockHeightInPixel;
switch (format) switch (format)
@ -514,31 +514,31 @@ std::vector<MipmapLevelInfo> uploadPlacedTexture(const RSXTexture &texture, size
std::vector<MipmapLevelInfo> mipInfos; std::vector<MipmapLevelInfo> mipInfos;
const u32 texaddr = GetAddress(texture.GetOffset(), texture.GetLocation()); const u32 texaddr = rsx::get_address(texture.offset(), texture.location());
auto pixels = vm::get_ptr<const u8>(texaddr); auto pixels = vm::get_ptr<const u8>(texaddr);
bool is_swizzled = !(texture.GetFormat() & CELL_GCM_TEXTURE_LN); bool is_swizzled = !(texture.format() & CELL_GCM_TEXTURE_LN);
switch (format) switch (format)
{ {
case CELL_GCM_TEXTURE_A8R8G8B8: case CELL_GCM_TEXTURE_A8R8G8B8:
if (is_swizzled) 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 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_A1R5G5B5:
case CELL_GCM_TEXTURE_A4R4G4B4: case CELL_GCM_TEXTURE_A4R4G4B4:
case CELL_GCM_TEXTURE_R5G6B5: case CELL_GCM_TEXTURE_R5G6B5:
if (is_swizzled) 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 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: 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_DXT1:
case CELL_GCM_TEXTURE_COMPRESSED_DXT23: case CELL_GCM_TEXTURE_COMPRESSED_DXT23:
case CELL_GCM_TEXTURE_COMPRESSED_DXT45: 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: default:
return writeTexelsGeneric((char*)pixels, (char*)textureData, w, h, blockSizeInByte, texture.GetMipmap()); return writeTexelsGeneric((char*)pixels, (char*)textureData, w, h, blockSizeInByte, texture.mipmap());
} }
} }

View file

@ -16,11 +16,11 @@ unsigned LinearToSwizzleAddress(unsigned x, unsigned y, unsigned z, unsigned log
* Get size to store texture in a linear fashion. * Get size to store texture in a linear fashion.
* Storage is assumed to use a rowPitchAlignement boundary for every row of texture. * 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. * Write texture data to textureData.
* Data are not packed, they are stored per rows using rowPitchAlignement. * Data are not packed, they are stored per rows using rowPitchAlignement.
* Similarly, offset for every mipmaplevel is aligned to rowPitchAlignement boundary. * Similarly, offset for every mipmaplevel is aligned to rowPitchAlignement boundary.
*/ */
std::vector<MipmapLevelInfo> uploadPlacedTexture(const RSXTexture &texture, size_t rowPitchAlignement, void* textureData); std::vector<MipmapLevelInfo> uploadPlacedTexture(const rsx::texture &texture, size_t rowPitchAlignement, void* textureData);

View file

@ -243,14 +243,14 @@ void D3D12GSRender::setScaleOffset()
}; };
// Scale // Scale
scaleOffsetMat[0] *= (float&)methodRegisters[NV4097_SET_VIEWPORT_SCALE + (0x4 * 0)] / (m_surface_clip_w / 2.f); scaleOffsetMat[0] *= (float&)rsx::method_registers[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[5] *= (float&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + (0x4 * 1)] / (m_surface_clip_h / 2.f);
scaleOffsetMat[10] = (float&)methodRegisters[NV4097_SET_VIEWPORT_SCALE + (0x4 * 2)]; scaleOffsetMat[10] = (float&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + (0x4 * 2)];
// Offset // Offset
scaleOffsetMat[3] = (float&)methodRegisters[NV4097_SET_VIEWPORT_OFFSET + (0x4 * 0)] - (m_surface_clip_w / 2.f); scaleOffsetMat[3] = (float&)rsx::method_registers[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[7] = -((float&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET + (0x4 * 1)] - (m_surface_clip_h / 2.f));
scaleOffsetMat[11] = (float&)methodRegisters[NV4097_SET_VIEWPORT_OFFSET + (0x4 * 2)]; scaleOffsetMat[11] = (float&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET + (0x4 * 2)];
scaleOffsetMat[3] /= m_surface_clip_w / 2.f; scaleOffsetMat[3] /= m_surface_clip_w / 2.f;
scaleOffsetMat[7] /= m_surface_clip_h / 2.f; scaleOffsetMat[7] /= m_surface_clip_h / 2.f;

View file

@ -647,7 +647,7 @@ void D3D12GSRender::Flip()
if (m_read_buffer) if (m_read_buffer)
{ {
CellGcmDisplayInfo* buffers = vm::get_ptr<CellGcmDisplayInfo>(m_gcm_buffers_addr); CellGcmDisplayInfo* buffers = vm::get_ptr<CellGcmDisplayInfo>(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; w = buffers[gcm_current_buffer].width;
h = buffers[gcm_current_buffer].height; h = buffers[gcm_current_buffer].height;
u8 *src_buffer = vm::get_ptr<u8>(addr); u8 *src_buffer = vm::get_ptr<u8>(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, 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); &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; ID3D12Resource *rtt0, *rtt1, *rtt2, *rtt3;
@ -1038,10 +1038,10 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
break; break;
} }
if (m_context_dma_color_a) invalidateAddress(GetAddress(m_surface_offset_a, m_context_dma_color_a - 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(GetAddress(m_surface_offset_b, m_context_dma_color_b - 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(GetAddress(m_surface_offset_c, m_context_dma_color_c - 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(GetAddress(m_surface_offset_d, m_context_dma_color_d - 0xfeed0000)); if (m_context_dma_color_d) invalidateAddress(rsx::get_address(m_surface_offset_d, m_context_dma_color_d - 0xfeed0000));
} }
if (needTransfer) if (needTransfer)
{ {
@ -1057,7 +1057,7 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
if (m_set_context_dma_z && Ini.GSDumpDepthBuffer.GetValue()) 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<void>(address); auto ptr = vm::get_ptr<void>(address);
char *ptrAsChar = (char*)ptr; char *ptrAsChar = (char*)ptr;
unsigned char *writeDestPtr; unsigned char *writeDestPtr;
@ -1097,53 +1097,53 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
break; break;
case CELL_GCM_SURFACE_TARGET_0: 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<void>(address); void *dstAddress = vm::get_ptr<void>(address);
copyToCellRamAndRelease(dstAddress, rtt0, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); copyToCellRamAndRelease(dstAddress, rtt0, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h);
} }
break; break;
case CELL_GCM_SURFACE_TARGET_1: 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<void>(address); void *dstAddress = vm::get_ptr<void>(address);
copyToCellRamAndRelease(dstAddress, rtt1, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); copyToCellRamAndRelease(dstAddress, rtt1, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h);
} }
break; break;
case CELL_GCM_SURFACE_TARGET_MRT1: 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<void>(address); void *dstAddress = vm::get_ptr<void>(address);
copyToCellRamAndRelease(dstAddress, rtt0, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); 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<void>(address); dstAddress = vm::get_ptr<void>(address);
copyToCellRamAndRelease(dstAddress, rtt1, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); copyToCellRamAndRelease(dstAddress, rtt1, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h);
} }
break; break;
case CELL_GCM_SURFACE_TARGET_MRT2: 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<void>(address); void *dstAddress = vm::get_ptr<void>(address);
copyToCellRamAndRelease(dstAddress, rtt0, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); 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<void>(address); dstAddress = vm::get_ptr<void>(address);
copyToCellRamAndRelease(dstAddress, rtt1, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); 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<void>(address); dstAddress = vm::get_ptr<void>(address);
copyToCellRamAndRelease(dstAddress, rtt2, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); copyToCellRamAndRelease(dstAddress, rtt2, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h);
} }
break; break;
case CELL_GCM_SURFACE_TARGET_MRT3: 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<void>(address); void *dstAddress = vm::get_ptr<void>(address);
copyToCellRamAndRelease(dstAddress, rtt0, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); 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<void>(address); dstAddress = vm::get_ptr<void>(address);
copyToCellRamAndRelease(dstAddress, rtt1, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); 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<void>(address); dstAddress = vm::get_ptr<void>(address);
copyToCellRamAndRelease(dstAddress, rtt2, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); 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<void>(address); dstAddress = vm::get_ptr<void>(address);
copyToCellRamAndRelease(dstAddress, rtt3, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); copyToCellRamAndRelease(dstAddress, rtt3, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h);
} }

View file

@ -29,11 +29,11 @@ void D3D12GSRender::PrepareRenderTargets(ID3D12GraphicsCommandList *copycmdlist)
m_previous_address_z = m_surface_offset_z; m_previous_address_z = m_surface_offset_z;
// FBO location has changed, previous data might be copied // 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_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 ? GetAddress(m_surface_offset_b, m_context_dma_color_b - 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 ? GetAddress(m_surface_offset_c, m_context_dma_color_c - 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 ? GetAddress(m_surface_offset_d, m_context_dma_color_d - 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 ? GetAddress(m_surface_offset_z, m_context_dma_z - 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 // Make previous RTTs sampleable
for (unsigned i = 0; i < 4; i++) for (unsigned i = 0; i < 4; i++)

View file

@ -104,19 +104,19 @@ D3D12_FILTER getSamplerFilter(u32 minFilter, u32 magFilter)
} }
static static
D3D12_SAMPLER_DESC getSamplerDesc(const RSXTexture &texture) D3D12_SAMPLER_DESC getSamplerDesc(const rsx::texture &texture)
{ {
D3D12_SAMPLER_DESC samplerDesc = {}; D3D12_SAMPLER_DESC samplerDesc = {};
samplerDesc.Filter = getSamplerFilter(texture.GetMinFilter(), texture.GetMagFilter()); samplerDesc.Filter = getSamplerFilter(texture.min_filter(), texture.mag_filter());
samplerDesc.AddressU = getSamplerWrap(texture.GetWrapS()); samplerDesc.AddressU = getSamplerWrap(texture.wrap_s());
samplerDesc.AddressV = getSamplerWrap(texture.GetWrapT()); samplerDesc.AddressV = getSamplerWrap(texture.wrap_t());
samplerDesc.AddressW = getSamplerWrap(texture.GetWrapR()); samplerDesc.AddressW = getSamplerWrap(texture.wrap_r());
samplerDesc.ComparisonFunc = getSamplerCompFunc[texture.GetZfunc()]; samplerDesc.ComparisonFunc = getSamplerCompFunc[texture.zfunc()];
samplerDesc.MaxAnisotropy = (UINT)getSamplerMaxAniso(texture.GetMaxAniso()); samplerDesc.MaxAnisotropy = (UINT)getSamplerMaxAniso(texture.max_aniso());
samplerDesc.MipLODBias = texture.GetBias(); samplerDesc.MipLODBias = texture.bias();
samplerDesc.BorderColor[4] = (FLOAT)texture.GetBorderColor(); samplerDesc.BorderColor[4] = (FLOAT)texture.border_color();
samplerDesc.MinLOD = (FLOAT)(texture.GetMinLOD() >> 8); samplerDesc.MinLOD = (FLOAT)(texture.min_lod() >> 8);
samplerDesc.MaxLOD = (FLOAT)(texture.GetMaxLOD() >> 8); samplerDesc.MaxLOD = (FLOAT)(texture.max_lod() >> 8);
return samplerDesc; return samplerDesc;
} }
@ -127,15 +127,15 @@ D3D12_SAMPLER_DESC getSamplerDesc(const RSXTexture &texture)
*/ */
static static
ComPtr<ID3D12Resource> uploadSingleTexture( ComPtr<ID3D12Resource> uploadSingleTexture(
const RSXTexture &texture, const rsx::texture &texture,
ID3D12Device *device, ID3D12Device *device,
ID3D12GraphicsCommandList *commandList, ID3D12GraphicsCommandList *commandList,
DataHeap<ID3D12Resource, 65536> &textureBuffersHeap) DataHeap<ID3D12Resource, 65536> &textureBuffersHeap)
{ {
ComPtr<ID3D12Resource> vramTexture; ComPtr<ID3D12Resource> 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); DXGI_FORMAT dxgiFormat = getTextureDXGIFormat(format);
size_t textureSize = getPlacedTextureStorageSpace(texture, 256); size_t textureSize = getPlacedTextureStorageSpace(texture, 256);
@ -148,7 +148,7 @@ ComPtr<ID3D12Resource> uploadSingleTexture(
std::vector<MipmapLevelInfo> mipInfos = uploadPlacedTexture(texture, 256, textureData); std::vector<MipmapLevelInfo> mipInfos = uploadPlacedTexture(texture, 256, textureData);
textureBuffersHeap.m_heap->Unmap(0, &CD3DX12_RANGE(heapOffset, heapOffset + textureSize)); 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; textureSize = device->GetResourceAllocationInfo(0, 1, &texturedesc).SizeInBytes;
ThrowIfFailed(device->CreateCommittedResource( ThrowIfFailed(device->CreateCommittedResource(
@ -179,14 +179,14 @@ ComPtr<ID3D12Resource> uploadSingleTexture(
*/ */
static static
void updateExistingTexture( void updateExistingTexture(
const RSXTexture &texture, const rsx::texture &texture,
ID3D12GraphicsCommandList *commandList, ID3D12GraphicsCommandList *commandList,
DataHeap<ID3D12Resource, 65536> &textureBuffersHeap, DataHeap<ID3D12Resource, 65536> &textureBuffersHeap,
ID3D12Resource *existingTexture) 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); DXGI_FORMAT dxgiFormat = getTextureDXGIFormat(format);
size_t textureSize = getPlacedTextureStorageSpace(texture, 256); size_t textureSize = getPlacedTextureStorageSpace(texture, 256);
@ -216,11 +216,11 @@ void updateExistingTexture(
* Get number of bytes occupied by texture in RSX mem * Get number of bytes occupied by texture in RSX mem
*/ */
static 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 // TODO: Take mipmaps into account
switch (format) switch (format)
{ {
@ -290,15 +290,15 @@ size_t D3D12GSRender::UploadTextures(ID3D12GraphicsCommandList *cmdlist)
for (u32 i = 0; i < m_textures_count; ++i) for (u32 i = 0; i < m_textures_count; ++i)
{ {
if (!m_textures[i].IsEnabled()) continue; if (!m_textures[i].enabled()) continue;
size_t w = m_textures[i].GetWidth(), h = m_textures[i].GetHeight(); size_t w = m_textures[i].width(), h = m_textures[i].height();
if (!w || !h) continue; 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); 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; ID3D12Resource *vramTexture;
std::unordered_map<u32, ID3D12Resource* >::const_iterator ItRTT = m_rtts.m_renderTargets.find(texaddr); std::unordered_map<u32, ID3D12Resource* >::const_iterator ItRTT = m_rtts.m_renderTargets.find(texaddr);
@ -309,7 +309,7 @@ size_t D3D12GSRender::UploadTextures(ID3D12GraphicsCommandList *cmdlist)
vramTexture = ItRTT->second; vramTexture = ItRTT->second;
isRenderTarget = true; 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) if (cachedTex->first.m_isDirty)
{ {
@ -324,13 +324,13 @@ size_t D3D12GSRender::UploadTextures(ID3D12GraphicsCommandList *cmdlist)
getCurrentResourceStorage().m_dirtyTextures.push_back(m_textureCache.removeFromCache(texaddr)); getCurrentResourceStorage().m_dirtyTextures.push_back(m_textureCache.removeFromCache(texaddr));
ComPtr<ID3D12Resource> tex = uploadSingleTexture(m_textures[i], m_device.Get(), cmdlist, m_textureUploadData); ComPtr<ID3D12Resource> tex = uploadSingleTexture(m_textures[i], m_device.Get(), cmdlist, m_textureUploadData);
vramTexture = tex.Get(); 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 = {}; D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
srvDesc.Format = dxgiFormat; srvDesc.Format = dxgiFormat;
srvDesc.Texture2D.MipLevels = m_textures[i].GetMipmap(); srvDesc.Texture2D.MipLevels = m_textures[i].mipmap();
switch (format) switch (format)
{ {
@ -357,10 +357,10 @@ size_t D3D12GSRender::UploadTextures(ID3D12GraphicsCommandList *cmdlist)
{ {
u8 remap_a = m_textures[i].GetRemap() & 0x3; u8 remap_a = m_textures[i].remap() & 0x3;
u8 remap_r = (m_textures[i].GetRemap() >> 2) & 0x3; u8 remap_r = (m_textures[i].remap() >> 2) & 0x3;
u8 remap_g = (m_textures[i].GetRemap() >> 4) & 0x3; u8 remap_g = (m_textures[i].remap() >> 4) & 0x3;
u8 remap_b = (m_textures[i].GetRemap() >> 6) & 0x3; u8 remap_b = (m_textures[i].remap() >> 6) & 0x3;
if (isRenderTarget) if (isRenderTarget)
{ {
// ARGB format // ARGB format
@ -428,10 +428,10 @@ size_t D3D12GSRender::UploadTextures(ID3D12GraphicsCommandList *cmdlist)
D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_1 D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_1
}; };
u8 remap_a = m_textures[i].GetRemap() & 0x3; u8 remap_a = m_textures[i].remap() & 0x3;
u8 remap_r = (m_textures[i].GetRemap() >> 2) & 0x3; u8 remap_r = (m_textures[i].remap() >> 2) & 0x3;
u8 remap_g = (m_textures[i].GetRemap() >> 4) & 0x3; u8 remap_g = (m_textures[i].remap() >> 4) & 0x3;
u8 remap_b = (m_textures[i].GetRemap() >> 6) & 0x3; u8 remap_b = (m_textures[i].remap() >> 6) & 0x3;
srvDesc.Shader4ComponentMapping = D3D12_ENCODE_SHADER_4_COMPONENT_MAPPING( srvDesc.Shader4ComponentMapping = D3D12_ENCODE_SHADER_4_COMPONENT_MAPPING(
RemapValue[remap_a], RemapValue[remap_a],

View file

@ -89,24 +89,24 @@ float GLTexture::GetMaxAniso(int aniso)
return 1.0f; return 1.0f;
} }
void GLTexture::Init(RSXTexture& tex) void GLTexture::Init(rsx::texture& tex)
{ {
if (tex.GetLocation() > 1) if (tex.location() > 1)
{ {
return; return;
} }
Bind(); 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", //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); // 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 //TODO: safe init
checkForGlError("GLTexture::Init() -> glBindTexture"); checkForGlError("GLTexture::Init() -> glBindTexture");
int format = tex.GetFormat() & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN); int format = tex.format() & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN);
bool is_swizzled = !(tex.GetFormat() & CELL_GCM_TEXTURE_LN); bool is_swizzled = !(tex.format() & CELL_GCM_TEXTURE_LN);
auto pixels = vm::get_ptr<const u8>(texaddr); auto pixels = vm::get_ptr<const u8>(texaddr);
u8 *unswizzledPixels; u8 *unswizzledPixels;
@ -118,7 +118,7 @@ void GLTexture::Init(RSXTexture& tex)
{ {
case CELL_GCM_TEXTURE_B8: // One 8-bit fixed-point number 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)"); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_B8)");
static const GLint swizzleMaskB8[] = { GL_BLUE, GL_BLUE, GL_BLUE, GL_BLUE }; 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"); checkForGlError("GLTexture::Init() -> glPixelStorei");
// TODO: texture swizzling // 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)"); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_A1R5G5B5)");
glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE);
@ -142,7 +142,7 @@ void GLTexture::Init(RSXTexture& tex)
case CELL_GCM_TEXTURE_A4R4G4B4: 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)"); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_A4R4G4B4)");
// We read it in as R4G4B4A4, so we need to remap each component. // 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); glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE);
checkForGlError("GLTexture::Init() -> glPixelStorei(CELL_GCM_TEXTURE_R5G6B5)"); 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)"); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_R5G6B5)");
glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE);
@ -171,57 +171,57 @@ void GLTexture::Init(RSXTexture& tex)
u32 *src, *dst; u32 *src, *dst;
u32 log2width, log2height; u32 log2width, log2height;
unswizzledPixels = (u8*)malloc(tex.GetWidth() * tex.GetHeight() * 4); unswizzledPixels = (u8*)malloc(tex.width() * tex.height() * 4);
src = (u32*)pixels; src = (u32*)pixels;
dst = (u32*)unswizzledPixels; dst = (u32*)unswizzledPixels;
log2width = log(tex.GetWidth()) / log(2); log2width = log(tex.width()) / log(2);
log2height = log(tex.GetHeight()) / 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)"); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_A8R8G8B8)");
break; break;
} }
case CELL_GCM_TEXTURE_COMPRESSED_DXT1: // Compressed 4x4 pixels into 8 bytes 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)"); checkForGlError("GLTexture::Init() -> glCompressedTexImage2D(CELL_GCM_TEXTURE_COMPRESSED_DXT1)");
break; break;
} }
case CELL_GCM_TEXTURE_COMPRESSED_DXT23: // Compressed 4x4 pixels into 16 bytes 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)"); checkForGlError("GLTexture::Init() -> glCompressedTexImage2D(CELL_GCM_TEXTURE_COMPRESSED_DXT23)");
} }
break; break;
case CELL_GCM_TEXTURE_COMPRESSED_DXT45: // Compressed 4x4 pixels into 16 bytes 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)"); checkForGlError("GLTexture::Init() -> glCompressedTexImage2D(CELL_GCM_TEXTURE_COMPRESSED_DXT45)");
break; break;
} }
case CELL_GCM_TEXTURE_G8B8: 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)"); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_G8B8)");
static const GLint swizzleMaskG8B8[] = { GL_RED, GL_GREEN, GL_RED, GL_GREEN }; 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: case CELL_GCM_TEXTURE_R6G5B5:
{ {
// TODO: Probably need to actually unswizzle if is_swizzled. // 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); unswizzledPixels = (u8 *)malloc(numPixels * 4);
// TODO: Speed. // TODO: Speed.
for (u32 i = 0; i < numPixels; ++i) { for (u32 i = 0; i < numPixels; ++i) {
@ -243,7 +243,7 @@ void GLTexture::Init(RSXTexture& tex)
unswizzledPixels[i * 4 + 3] = 255; 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)"); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_R6G5B5)");
free(unswizzledPixels); 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 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)"); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_DEPTH24_D8)");
break; break;
} }
case CELL_GCM_TEXTURE_DEPTH24_D8_FLOAT: // 24-bit unsigned float and 8 bits of garbage 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)"); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_DEPTH24_D8_FLOAT)");
break; break;
} }
case CELL_GCM_TEXTURE_DEPTH16: // 16-bit unsigned fixed-point number 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)"); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_DEPTH16)");
break; break;
} }
case CELL_GCM_TEXTURE_DEPTH16_FLOAT: // 16-bit unsigned float 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)"); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_DEPTH16_FLOAT)");
break; break;
} }
@ -283,7 +283,7 @@ void GLTexture::Init(RSXTexture& tex)
glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE); glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE);
checkForGlError("GLTexture::Init() -> glPixelStorei(CELL_GCM_TEXTURE_X16)"); 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)"); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_X16)");
glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE);
@ -299,7 +299,7 @@ void GLTexture::Init(RSXTexture& tex)
glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE); glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE);
checkForGlError("GLTexture::Init() -> glPixelStorei(CELL_GCM_TEXTURE_Y16_X16)"); 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)"); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_Y16_X16)");
glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE);
@ -315,7 +315,7 @@ void GLTexture::Init(RSXTexture& tex)
glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE); glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE);
checkForGlError("GLTexture::Init() -> glPixelStorei(CELL_GCM_TEXTURE_R5G5B5A1)"); 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)"); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_R5G5B5A1)");
glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE);
@ -328,7 +328,7 @@ void GLTexture::Init(RSXTexture& tex)
glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE); glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE);
checkForGlError("GLTexture::Init() -> glPixelStorei(CELL_GCM_TEXTURE_W16_Z16_Y16_X16_FLOAT)"); 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)"); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_W16_Z16_Y16_X16_FLOAT)");
glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); 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 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)"); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_W32_Z32_Y32_X32_FLOAT)");
break; break;
} }
case CELL_GCM_TEXTURE_X32_FLOAT: // One 32-bit floating-point number 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)"); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_X32_FLOAT)");
static const GLint swizzleMaskX32_FLOAT[] = { GL_RED, GL_ONE, GL_ONE, GL_ONE }; 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)"); checkForGlError("GLTexture::Init() -> glPixelStorei(CELL_GCM_TEXTURE_D1R5G5B5)");
// TODO: Texture swizzling // 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)"); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_D1R5G5B5)");
static const GLint swizzleMaskX32_D1R5G5B5[] = { GL_ONE, GL_RED, GL_GREEN, GL_BLUE }; 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 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)"); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_D8R8G8B8)");
static const GLint swizzleMaskX32_D8R8G8B8[] = { GL_ONE, GL_RED, GL_GREEN, GL_BLUE }; 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); glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE);
checkForGlError("GLTexture::Init() -> glPixelStorei(CELL_GCM_TEXTURE_Y16_X16_FLOAT)"); 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)"); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_Y16_X16_FLOAT)");
glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); 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: 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); unswizzledPixels = (u8 *)malloc(numPixels * 4);
// TODO: Speed. // TODO: Speed.
for (u32 i = 0; i < numPixels; i += 2) for (u32 i = 0; i < numPixels; i += 2)
@ -416,7 +416,7 @@ void GLTexture::Init(RSXTexture& tex)
unswizzledPixels[i * 4 + 4 + 3] = 255; 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)"); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_COMPRESSED_B8R8_G8R8 & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN)");
free(unswizzledPixels); 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: 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); unswizzledPixels = (u8 *)malloc(numPixels * 4);
// TODO: Speed. // TODO: Speed.
for (u32 i = 0; i < numPixels; i += 2) for (u32 i = 0; i < numPixels; i += 2)
@ -442,7 +442,7 @@ void GLTexture::Init(RSXTexture& tex)
unswizzledPixels[i * 4 + 4 + 3] = 255; 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)"); checkForGlError("GLTexture::Init() -> glTexImage2D(CELL_GCM_TEXTURE_COMPRESSED_R8B8_R8G8 & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN)");
free(unswizzledPixels); free(unswizzledPixels);
@ -451,20 +451,20 @@ void GLTexture::Init(RSXTexture& tex)
default: 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; break;
} }
} }
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, tex.GetMipmap() - 1); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, tex.mipmap() - 1);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, tex.GetMipmap() > 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) 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_a = tex.remap() & 0x3;
u8 remap_r = (tex.GetRemap() >> 2) & 0x3; u8 remap_r = (tex.remap() >> 2) & 0x3;
u8 remap_g = (tex.GetRemap() >> 4) & 0x3; u8 remap_g = (tex.remap() >> 4) & 0x3;
u8 remap_b = (tex.GetRemap() >> 6) & 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_A, glRemap[remap_a]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, glRemap[remap_r]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, glRemap[remap_r]);
@ -494,19 +494,19 @@ void GLTexture::Init(RSXTexture& tex)
GL_ALWAYS, GL_ALWAYS,
}; };
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GetGlWrap(tex.GetWrapS())); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GetGlWrap(tex.wrap_s()));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GetGlWrap(tex.GetWrapT())); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GetGlWrap(tex.wrap_t()));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GetGlWrap(tex.GetWrapR())); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GetGlWrap(tex.wrap_r()));
checkForGlError("GLTexture::Init() -> wrap"); 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"); checkForGlError("GLTexture::Init() -> compare");
glTexEnvi(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, tex.GetBias()); glTexEnvi(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, tex.bias());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, (tex.GetMinLOD() >> 8)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, (tex.min_lod() >> 8));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, (tex.GetMaxLOD() >> 8)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, (tex.max_lod() >> 8));
checkForGlError("GLTexture::Init() -> lod"); checkForGlError("GLTexture::Init() -> lod");
@ -530,14 +530,14 @@ void GLTexture::Init(RSXTexture& tex)
GL_LINEAR // CELL_GCM_TEXTURE_CONVOLUTION_MAG 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"); 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"); 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"); 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]; u32* alldata = new u32[texPixelCount];
Bind(); Bind();
switch (tex.GetFormat() & ~(0x20 | 0x40)) switch (tex.format() & ~(0x20 | 0x40))
{ {
case CELL_GCM_TEXTURE_B8: case CELL_GCM_TEXTURE_B8:
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, alldata); 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; rImage out;
out.Create(tex.GetWidth(), tex.GetHeight(), data, alpha); out.Create(tex.width(), tex.height(), data, alpha);
out.SaveFile(name, rBITMAP_TYPE_PNG); out.SaveFile(name, rBITMAP_TYPE_PNG);
delete[] alldata; delete[] alldata;
@ -599,7 +599,7 @@ void GLTexture::Save(RSXTexture& tex, const std::string& name)
//free(alpha); //free(alpha);
} }
void GLTexture::Save(RSXTexture& tex) void GLTexture::Save(rsx::texture& tex)
{ {
static const std::string& dir_path = "textures"; static const std::string& dir_path = "textures";
static const std::string& file_fmt = dir_path + "/" + "tex[%d].png"; static const std::string& file_fmt = dir_path + "/" + "tex[%d].png";
@ -813,7 +813,7 @@ void GLGSRender::EnableVertexData(bool indexed_draw)
{ {
if (0) 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; u16 frequency = data_format >> 16;
u8 stride = (data_format >> 8) & 0xff; u8 stride = (data_format >> 8) & 0xff;
u8 size = (data_format >> 4) & 0xf; u8 size = (data_format >> 4) & 0xf;
@ -1043,14 +1043,14 @@ void GLGSRender::InitVertexData()
} }
// Scale // Scale
scaleOffsetMat[0] = (GLfloat&)methodRegisters[NV4097_SET_VIEWPORT_SCALE + (0x4 * 0)] / (RSXThread::m_width / RSXThread::m_width_scale); scaleOffsetMat[0] = (GLfloat&)rsx::method_registers[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[5] = (GLfloat&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + (0x4 * 1)] / (RSXThread::m_height / RSXThread::m_height_scale);
scaleOffsetMat[10] = (GLfloat&)methodRegisters[NV4097_SET_VIEWPORT_SCALE + (0x4 * 2)]; scaleOffsetMat[10] = (GLfloat&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + (0x4 * 2)];
// Offset // Offset
scaleOffsetMat[3] = (GLfloat&)methodRegisters[NV4097_SET_VIEWPORT_OFFSET + (0x4 * 0)] - (RSXThread::m_width / RSXThread::m_width_scale); scaleOffsetMat[3] = (GLfloat&)rsx::method_registers[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[7] = (GLfloat&)rsx::method_registers[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[11] = (GLfloat&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET + (0x4 * 2)] - 1 / 2.0f;
scaleOffsetMat[3] /= RSXThread::m_width / RSXThread::m_width_scale; scaleOffsetMat[3] /= RSXThread::m_width / RSXThread::m_width_scale;
scaleOffsetMat[7] /= RSXThread::m_height / RSXThread::m_height_scale; scaleOffsetMat[7] /= RSXThread::m_height / RSXThread::m_height_scale;
@ -1155,7 +1155,7 @@ void GLGSRender::WriteDepthBuffer()
return; 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<void>(address); auto ptr = vm::get_ptr<void>(address);
glBindBuffer(GL_PIXEL_PACK_BUFFER, g_pbo[4]); glBindBuffer(GL_PIXEL_PACK_BUFFER, g_pbo[4]);
@ -1187,7 +1187,7 @@ void GLGSRender::WriteColorBufferA()
return; 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); glReadBuffer(GL_COLOR_ATTACHMENT0);
checkForGlError("WriteColorBufferA(): glReadBuffer"); checkForGlError("WriteColorBufferA(): glReadBuffer");
@ -1213,7 +1213,7 @@ void GLGSRender::WriteColorBufferB()
return; 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); glReadBuffer(GL_COLOR_ATTACHMENT1);
checkForGlError("WriteColorBufferB(): glReadBuffer"); checkForGlError("WriteColorBufferB(): glReadBuffer");
@ -1239,7 +1239,7 @@ void GLGSRender::WriteColorBufferC()
return; 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); glReadBuffer(GL_COLOR_ATTACHMENT2);
checkForGlError("WriteColorBufferC(): glReadBuffer"); checkForGlError("WriteColorBufferC(): glReadBuffer");
@ -1265,7 +1265,7 @@ void GLGSRender::WriteColorBufferD()
return; 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); glReadBuffer(GL_COLOR_ATTACHMENT3);
checkForGlError("WriteColorBufferD(): glReadBuffer"); checkForGlError("WriteColorBufferD(): glReadBuffer");
@ -1567,7 +1567,7 @@ void GLGSRender::InitDrawBuffers()
{ {
u32 format = GL_BGRA; u32 format = GL_BGRA;
CellGcmDisplayInfo* buffers = vm::get_ptr<CellGcmDisplayInfo>(m_gcm_buffers_addr); CellGcmDisplayInfo* buffers = vm::get_ptr<CellGcmDisplayInfo>(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 width = buffers[gcm_current_buffer].width;
u32 height = buffers[gcm_current_buffer].height; u32 height = buffers[gcm_current_buffer].height;
glDrawPixels(width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, vm::get_ptr(addr)); 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) 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); glActiveTexture(GL_TEXTURE0 + i);
checkForGlError("glActiveTexture"); checkForGlError("glActiveTexture");
@ -1926,7 +1926,7 @@ void GLGSRender::Draw()
for (u32 i = 0; i < m_textures_count; ++i) 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); glActiveTexture(GL_TEXTURE0 + m_textures_count + i);
checkForGlError("glActiveTexture"); checkForGlError("glActiveTexture");
@ -1934,7 +1934,7 @@ void GLGSRender::Draw()
m_gl_vertex_textures[i].Bind(); m_gl_vertex_textures[i].Bind();
checkForGlError(fmt::format("m_gl_vertex_textures[%d].Bind", i)); checkForGlError(fmt::format("m_gl_vertex_textures[%d].Bind", i));
m_program.SetVTex(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)); checkForGlError(fmt::format("m_gl_vertex_textures[%d].Init", i));
} }
@ -2023,7 +2023,7 @@ void GLGSRender::Flip()
{ {
format = GL_BGRA; format = GL_BGRA;
CellGcmDisplayInfo* buffers = vm::get_ptr<CellGcmDisplayInfo>(m_gcm_buffers_addr); CellGcmDisplayInfo* buffers = vm::get_ptr<CellGcmDisplayInfo>(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; width = buffers[gcm_current_buffer].width;
height = buffers[gcm_current_buffer].height; height = buffers[gcm_current_buffer].height;
src_buffer = vm::get_ptr<u8>(addr); src_buffer = vm::get_ptr<u8>(addr);

View file

@ -53,11 +53,11 @@ public:
return (v << 2) | (v >> 4); 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(); void Bind();

View file

@ -3,413 +3,416 @@
#include "RSXThread.h" #include "RSXThread.h"
#include "RSXTexture.h" #include "RSXTexture.h"
RSXTexture::RSXTexture() namespace rsx
{ {
m_index = 0; void texture::init(u8 index)
}
RSXTexture::RSXTexture(u8 index)
{ {
m_index = index; m_index = index;
}
void RSXTexture::Init()
{
// Offset // Offset
methodRegisters[NV4097_SET_TEXTURE_OFFSET + (m_index*32)] = 0; method_registers[NV4097_SET_TEXTURE_OFFSET + (m_index * 8)] = 0;
// Format // Format
methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*32)] = 0; method_registers[NV4097_SET_TEXTURE_FORMAT + (m_index * 8)] = 0;
// Address // Address
methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*32)] = method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)] =
((/*wraps*/1) | ((/*anisoBias*/0) << 4) | ((/*wrapt*/1) << 8) | ((/*unsignedRemap*/0) << 12) | ((/*wraps*/1) | ((/*anisoBias*/0) << 4) | ((/*wrapt*/1) << 8) | ((/*unsignedRemap*/0) << 12) |
((/*wrapr*/3) << 16) | ((/*gamma*/0) << 20) | ((/*signedRemap*/0) << 24) | ((/*zfunc*/0) << 28)); ((/*wrapr*/3) << 16) | ((/*gamma*/0) << 20) | ((/*signedRemap*/0) << 24) | ((/*zfunc*/0) << 28));
// Control0 // Control0
methodRegisters[NV4097_SET_TEXTURE_CONTROL0 + (m_index*32)] = method_registers[NV4097_SET_TEXTURE_CONTROL0 + (m_index * 8)] =
(((/*alphakill*/0) << 2) | (/*maxaniso*/0) << 4) | ((/*maxlod*/0xc00) << 7) | ((/*minlod*/0) << 19) | ((/*enable*/0) << 31); (((/*alphakill*/0) << 2) | (/*maxaniso*/0) << 4) | ((/*maxlod*/0xc00) << 7) | ((/*minlod*/0) << 19) | ((/*enable*/0) << 31);
// Control1 // Control1
methodRegisters[NV4097_SET_TEXTURE_CONTROL1 + (m_index*32)] = 0xE4; method_registers[NV4097_SET_TEXTURE_CONTROL1 + (m_index * 8)] = 0xE4;
// Filter // Filter
methodRegisters[NV4097_SET_TEXTURE_FILTER + (m_index*32)] = method_registers[NV4097_SET_TEXTURE_FILTER + (m_index * 8)] =
((/*bias*/0) | ((/*conv*/1) << 13) | ((/*min*/5) << 16) | ((/*mag*/2) << 24) ((/*bias*/0) | ((/*conv*/1) << 13) | ((/*min*/5) << 16) | ((/*mag*/2) << 24)
| ((/*as*/0) << 28) | ((/*rs*/0) << 29) | ((/*gs*/0) << 30) | ((/*bs*/0) << 31)); | ((/*as*/0) << 28) | ((/*rs*/0) << 29) | ((/*gs*/0) << 30) | ((/*bs*/0) << 31));
// Image Rect // Image Rect
methodRegisters[NV4097_SET_TEXTURE_IMAGE_RECT + (m_index*32)] = (/*height*/1) | ((/*width*/1) << 16); method_registers[NV4097_SET_TEXTURE_IMAGE_RECT + (m_index * 8)] = (/*height*/1) | ((/*width*/1) << 16);
// Border Color // Border Color
methodRegisters[NV4097_SET_TEXTURE_BORDER_COLOR + (m_index*32)] = 0; method_registers[NV4097_SET_TEXTURE_BORDER_COLOR + (m_index * 8)] = 0;
} }
u32 RSXTexture::GetOffset() const u32 texture::offset() const
{ {
return methodRegisters[NV4097_SET_TEXTURE_OFFSET + (m_index*32)]; return method_registers[NV4097_SET_TEXTURE_OFFSET + (m_index * 8)];
} }
u8 RSXTexture::GetLocation() const u8 texture::location() const
{ {
return (methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*32)] & 0x3) - 1; return (method_registers[NV4097_SET_TEXTURE_FORMAT + (m_index * 8)] & 0x3) - 1;
} }
bool RSXTexture::isCubemap() const bool texture::cubemap() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*32)] >> 2) & 0x1); return ((method_registers[NV4097_SET_TEXTURE_FORMAT + (m_index * 8)] >> 2) & 0x1);
} }
u8 RSXTexture::GetBorderType() const u8 texture::border_type() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*32)] >> 3) & 0x1); return ((method_registers[NV4097_SET_TEXTURE_FORMAT + (m_index * 8)] >> 3) & 0x1);
} }
u8 RSXTexture::GetDimension() const u8 texture::dimension() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*32)] >> 4) & 0xf); return ((method_registers[NV4097_SET_TEXTURE_FORMAT + (m_index * 8)] >> 4) & 0xf);
} }
u8 RSXTexture::GetFormat() const u8 texture::format() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*32)] >> 8) & 0xff); return ((method_registers[NV4097_SET_TEXTURE_FORMAT + (m_index * 8)] >> 8) & 0xff);
} }
u16 RSXTexture::GetMipmap() const u16 texture::mipmap() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*32)] >> 16) & 0xffff); return ((method_registers[NV4097_SET_TEXTURE_FORMAT + (m_index * 8)] >> 16) & 0xffff);
} }
u8 RSXTexture::GetWrapS() const u8 texture::wrap_s() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*32)]) & 0xf); return ((method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)]) & 0xf);
} }
u8 RSXTexture::GetWrapT() const u8 texture::wrap_t() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*32)] >> 8) & 0xf); return ((method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)] >> 8) & 0xf);
} }
u8 RSXTexture::GetWrapR() const u8 texture::wrap_r() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*32)] >> 16) & 0xf); return ((method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)] >> 16) & 0xf);
} }
u8 RSXTexture::GetUnsignedRemap() const u8 texture::unsigned_remap() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*32)] >> 12) & 0xf); return ((method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)] >> 12) & 0xf);
} }
u8 RSXTexture::GetZfunc() const u8 texture::zfunc() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*32)] >> 28) & 0xf); return ((method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)] >> 28) & 0xf);
} }
u8 RSXTexture::GetGamma() const u8 texture::gamma() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*32)] >> 20) & 0xf); return ((method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)] >> 20) & 0xf);
} }
u8 RSXTexture::GetAnisoBias() const u8 texture::aniso_bias() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*32)] >> 4) & 0xf); return ((method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)] >> 4) & 0xf);
} }
u8 RSXTexture::GetSignedRemap() const u8 texture::signed_remap() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*32)] >> 24) & 0xf); return ((method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)] >> 24) & 0xf);
} }
bool RSXTexture::IsEnabled() const bool texture::enabled() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_CONTROL0 + (m_index*32)] >> 31) & 0x1); return location() <= 1 && ((method_registers[NV4097_SET_TEXTURE_CONTROL0 + (m_index * 8)] >> 31) & 0x1);
} }
u16 RSXTexture::GetMinLOD() const u16 texture::min_lod() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_CONTROL0 + (m_index*32)] >> 19) & 0xfff); return ((method_registers[NV4097_SET_TEXTURE_CONTROL0 + (m_index * 8)] >> 19) & 0xfff);
} }
u16 RSXTexture::GetMaxLOD() const u16 texture::max_lod() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_CONTROL0 + (m_index*32)] >> 7) & 0xfff); return ((method_registers[NV4097_SET_TEXTURE_CONTROL0 + (m_index * 8)] >> 7) & 0xfff);
} }
u8 RSXTexture::GetMaxAniso() const u8 texture::max_aniso() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_CONTROL0 + (m_index*32)] >> 4) & 0x7); return ((method_registers[NV4097_SET_TEXTURE_CONTROL0 + (m_index * 8)] >> 4) & 0x7);
} }
bool RSXTexture::IsAlphaKillEnabled() const bool texture::alpha_kill_enabled() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_CONTROL0 + (m_index*32)] >> 2) & 0x1); return ((method_registers[NV4097_SET_TEXTURE_CONTROL0 + (m_index * 8)] >> 2) & 0x1);
} }
u32 RSXTexture::GetRemap() const u32 texture::remap() const
{ {
return (methodRegisters[NV4097_SET_TEXTURE_CONTROL1 + (m_index*32)]); return (method_registers[NV4097_SET_TEXTURE_CONTROL1 + (m_index * 8)]);
} }
u16 RSXTexture::GetBias() const u16 texture::bias() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_FILTER + (m_index*32)]) & 0x1fff); return ((method_registers[NV4097_SET_TEXTURE_FILTER + (m_index * 8)]) & 0x1fff);
} }
u8 RSXTexture::GetMinFilter() const u8 texture::min_filter() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_FILTER + (m_index*32)] >> 16) & 0x7); return ((method_registers[NV4097_SET_TEXTURE_FILTER + (m_index * 8)] >> 16) & 0x7);
} }
u8 RSXTexture::GetMagFilter() const u8 texture::mag_filter() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_FILTER + (m_index*32)] >> 24) & 0x7); return ((method_registers[NV4097_SET_TEXTURE_FILTER + (m_index * 8)] >> 24) & 0x7);
} }
u8 RSXTexture::GetConvolutionFilter() const u8 texture::convolution_filter() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_FILTER + (m_index*32)] >> 13) & 0xf); return ((method_registers[NV4097_SET_TEXTURE_FILTER + (m_index * 8)] >> 13) & 0xf);
} }
bool RSXTexture::isASigned() const bool texture::a_signed() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_FILTER + (m_index*32)] >> 28) & 0x1); return ((method_registers[NV4097_SET_TEXTURE_FILTER + (m_index * 8)] >> 28) & 0x1);
} }
bool RSXTexture::isRSigned() const bool texture::r_signed() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_FILTER + (m_index*32)] >> 29) & 0x1); return ((method_registers[NV4097_SET_TEXTURE_FILTER + (m_index * 8)] >> 29) & 0x1);
} }
bool RSXTexture::isGSigned() const bool texture::g_signed() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_FILTER + (m_index*32)] >> 30) & 0x1); return ((method_registers[NV4097_SET_TEXTURE_FILTER + (m_index * 8)] >> 30) & 0x1);
} }
bool RSXTexture::isBSigned() const bool texture::b_signed() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_FILTER + (m_index*32)] >> 31) & 0x1); return ((method_registers[NV4097_SET_TEXTURE_FILTER + (m_index * 8)] >> 31) & 0x1);
} }
u16 RSXTexture::GetWidth() const u16 texture::width() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_IMAGE_RECT + (m_index*32)] >> 16) & 0xffff); return ((method_registers[NV4097_SET_TEXTURE_IMAGE_RECT + (m_index * 8)] >> 16) & 0xffff);
} }
u16 RSXTexture::GetHeight() const u16 texture::height() const
{ {
return ((methodRegisters[NV4097_SET_TEXTURE_IMAGE_RECT + (m_index*32)]) & 0xffff); return ((method_registers[NV4097_SET_TEXTURE_IMAGE_RECT + (m_index * 8)]) & 0xffff);
} }
u32 RSXTexture::GetBorderColor() const u32 texture::border_color() const
{ {
return methodRegisters[NV4097_SET_TEXTURE_BORDER_COLOR + (m_index*32)]; return method_registers[NV4097_SET_TEXTURE_BORDER_COLOR + (m_index * 8)];
} }
void RSXTexture::SetControl3(u16 depth, u32 pitch) u16 texture::depth() const
{ {
m_depth = depth; return method_registers[NV4097_SET_TEXTURE_CONTROL3] >> 20;
m_pitch = pitch;
} }
RSXVertexTexture::RSXVertexTexture() : RSXTexture() u32 texture::pitch() const
{ {
return method_registers[NV4097_SET_TEXTURE_CONTROL3] & 0xfffff;
} }
RSXVertexTexture::RSXVertexTexture(u8 index) : RSXTexture(index) void vertex_texture::init(u8 index)
{ {
} m_index = index;
void RSXVertexTexture::Init()
{
// Offset // Offset
methodRegisters[NV4097_SET_VERTEX_TEXTURE_OFFSET + (m_index * 32)] = 0; method_registers[NV4097_SET_VERTEX_TEXTURE_OFFSET + (m_index * 8)] = 0;
// Format // Format
methodRegisters[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 32)] = 0; method_registers[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 8)] = 0;
// Address // Address
methodRegisters[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 32)] = method_registers[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 8)] =
((/*wraps*/1) | ((/*anisoBias*/0) << 4) | ((/*wrapt*/1) << 8) | ((/*unsignedRemap*/0) << 12) | ((/*wraps*/1) | ((/*anisoBias*/0) << 4) | ((/*wrapt*/1) << 8) | ((/*unsignedRemap*/0) << 12) |
((/*wrapr*/3) << 16) | ((/*gamma*/0) << 20) | ((/*signedRemap*/0) << 24) | ((/*zfunc*/0) << 28)); ((/*wrapr*/3) << 16) | ((/*gamma*/0) << 20) | ((/*signedRemap*/0) << 24) | ((/*zfunc*/0) << 28));
// Control0 // Control0
methodRegisters[NV4097_SET_VERTEX_TEXTURE_CONTROL0 + (m_index * 32)] = 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); (((/*alphakill*/0) << 2) | (/*maxaniso*/0) << 4) | ((/*maxlod*/0xc00) << 7) | ((/*minlod*/0) << 19) | ((/*enable*/0) << 31);
// Control1 // Control1
//methodRegisters[NV4097_SET_VERTEX_TEXTURE_CONTROL1 + (m_index * 32)] = 0xE4; //method_registers[NV4097_SET_VERTEX_TEXTURE_CONTROL1 + (m_index * 8)] = 0xE4;
// Filter // Filter
methodRegisters[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 32)] = method_registers[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 8)] =
((/*bias*/0) | ((/*conv*/1) << 13) | ((/*min*/5) << 16) | ((/*mag*/2) << 24) ((/*bias*/0) | ((/*conv*/1) << 13) | ((/*min*/5) << 16) | ((/*mag*/2) << 24)
| ((/*as*/0) << 28) | ((/*rs*/0) << 29) | ((/*gs*/0) << 30) | ((/*bs*/0) << 31)); | ((/*as*/0) << 28) | ((/*rs*/0) << 29) | ((/*gs*/0) << 30) | ((/*bs*/0) << 31));
// Image Rect // Image Rect
methodRegisters[NV4097_SET_VERTEX_TEXTURE_IMAGE_RECT + (m_index * 32)] = (/*height*/1) | ((/*width*/1) << 16); method_registers[NV4097_SET_VERTEX_TEXTURE_IMAGE_RECT + (m_index * 8)] = (/*height*/1) | ((/*width*/1) << 16);
// Border Color // Border Color
methodRegisters[NV4097_SET_VERTEX_TEXTURE_BORDER_COLOR + (m_index * 32)] = 0; method_registers[NV4097_SET_VERTEX_TEXTURE_BORDER_COLOR + (m_index * 8)] = 0;
} }
u32 RSXVertexTexture::GetOffset() const u32 vertex_texture::offset() const
{ {
return methodRegisters[NV4097_SET_VERTEX_TEXTURE_OFFSET + (m_index * 32)]; return method_registers[NV4097_SET_VERTEX_TEXTURE_OFFSET + (m_index * 8)];
} }
u8 RSXVertexTexture::GetLocation() const u8 vertex_texture::location() const
{ {
return (methodRegisters[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 32)] & 0x3) - 1; return (method_registers[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 8)] & 0x3) - 1;
} }
bool RSXVertexTexture::isCubemap() const bool vertex_texture::cubemap() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 32)] >> 2) & 0x1); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 8)] >> 2) & 0x1);
} }
u8 RSXVertexTexture::GetBorderType() const u8 vertex_texture::border_type() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 32)] >> 3) & 0x1); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 8)] >> 3) & 0x1);
} }
u8 RSXVertexTexture::GetDimension() const u8 vertex_texture::dimension() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 32)] >> 4) & 0xf); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 8)] >> 4) & 0xf);
} }
u8 RSXVertexTexture::GetFormat() const u8 vertex_texture::format() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 32)] >> 8) & 0xff); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 8)] >> 8) & 0xff);
} }
u16 RSXVertexTexture::GetMipmap() const u16 vertex_texture::mipmap() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 32)] >> 16) & 0xffff); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FORMAT + (m_index * 8)] >> 16) & 0xffff);
} }
u8 RSXVertexTexture::GetWrapS() const u8 vertex_texture::wrap_s() const
{ {
return 1; return 1;
//return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 32)]) & 0xf); //return ((method_registers[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 8)]) & 0xf);
} }
u8 RSXVertexTexture::GetWrapT() const u8 vertex_texture::wrap_t() const
{ {
return 1; return 1;
//return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 32)] >> 8) & 0xf); //return ((method_registers[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 8)] >> 8) & 0xf);
} }
u8 RSXVertexTexture::GetWrapR() const u8 vertex_texture::wrap_r() const
{ {
return 1; return 1;
//return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 32)] >> 16) & 0xf); //return ((method_registers[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 8)] >> 16) & 0xf);
} }
u8 RSXVertexTexture::GetUnsignedRemap() const u8 vertex_texture::unsigned_remap() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 32)] >> 12) & 0xf); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 8)] >> 12) & 0xf);
} }
u8 RSXVertexTexture::GetZfunc() const u8 vertex_texture::zfunc() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 32)] >> 28) & 0xf); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 8)] >> 28) & 0xf);
} }
u8 RSXVertexTexture::GetGamma() const u8 vertex_texture::gamma() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 32)] >> 20) & 0xf); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 8)] >> 20) & 0xf);
} }
u8 RSXVertexTexture::GetAnisoBias() const u8 vertex_texture::aniso_bias() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 32)] >> 4) & 0xf); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 8)] >> 4) & 0xf);
} }
u8 RSXVertexTexture::GetSignedRemap() const u8 vertex_texture::signed_remap() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 32)] >> 24) & 0xf); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_ADDRESS + (m_index * 8)] >> 24) & 0xf);
} }
bool RSXVertexTexture::IsEnabled() const bool vertex_texture::enabled() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_CONTROL0 + (m_index * 32)] >> 31) & 0x1); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_CONTROL0 + (m_index * 8)] >> 31) & 0x1);
} }
u16 RSXVertexTexture::GetMinLOD() const u16 vertex_texture::min_lod() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_CONTROL0 + (m_index * 32)] >> 19) & 0xfff); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_CONTROL0 + (m_index * 8)] >> 19) & 0xfff);
} }
u16 RSXVertexTexture::GetMaxLOD() const u16 vertex_texture::max_lod() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_CONTROL0 + (m_index * 32)] >> 7) & 0xfff); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_CONTROL0 + (m_index * 8)] >> 7) & 0xfff);
} }
u8 RSXVertexTexture::GetMaxAniso() const u8 vertex_texture::max_aniso() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_CONTROL0 + (m_index * 32)] >> 4) & 0x7); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_CONTROL0 + (m_index * 8)] >> 4) & 0x7);
} }
bool RSXVertexTexture::IsAlphaKillEnabled() const bool vertex_texture::alpha_kill_enabled() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_CONTROL0 + (m_index * 32)] >> 2) & 0x1); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_CONTROL0 + (m_index * 8)] >> 2) & 0x1);
} }
u32 RSXVertexTexture::GetRemap() const u32 vertex_texture::remap() const
{ {
return 0 | (1 << 2) | (2 << 4) | (3 << 6);//(methodRegisters[NV4097_SET_VERTEX_TEXTURE_CONTROL1 + (m_index * 32)]); return 0 | (1 << 2) | (2 << 4) | (3 << 6);//(method_registers[NV4097_SET_VERTEX_TEXTURE_CONTROL1 + (m_index * 8)]);
} }
u16 RSXVertexTexture::GetBias() const u16 vertex_texture::bias() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 32)]) & 0x1fff); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 8)]) & 0x1fff);
} }
u8 RSXVertexTexture::GetMinFilter() const u8 vertex_texture::min_filter() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 32)] >> 16) & 0x7); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 8)] >> 16) & 0x7);
} }
u8 RSXVertexTexture::GetMagFilter() const u8 vertex_texture::mag_filter() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 32)] >> 24) & 0x7); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 8)] >> 24) & 0x7);
} }
u8 RSXVertexTexture::GetConvolutionFilter() const u8 vertex_texture::convolution_filter() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 32)] >> 13) & 0xf); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 8)] >> 13) & 0xf);
} }
bool RSXVertexTexture::isASigned() const bool vertex_texture::a_signed() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 32)] >> 28) & 0x1); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 8)] >> 28) & 0x1);
} }
bool RSXVertexTexture::isRSigned() const bool vertex_texture::r_signed() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 32)] >> 29) & 0x1); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 8)] >> 29) & 0x1);
} }
bool RSXVertexTexture::isGSigned() const bool vertex_texture::g_signed() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 32)] >> 30) & 0x1); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 8)] >> 30) & 0x1);
} }
bool RSXVertexTexture::isBSigned() const bool vertex_texture::b_signed() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 32)] >> 31) & 0x1); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_FILTER + (m_index * 8)] >> 31) & 0x1);
} }
u16 RSXVertexTexture::GetWidth() const u16 vertex_texture::width() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_IMAGE_RECT + (m_index * 32)] >> 16) & 0xffff); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_IMAGE_RECT + (m_index * 8)] >> 16) & 0xffff);
} }
u16 RSXVertexTexture::GetHeight() const u16 vertex_texture::height() const
{ {
return ((methodRegisters[NV4097_SET_VERTEX_TEXTURE_IMAGE_RECT + (m_index * 32)]) & 0xffff); return ((method_registers[NV4097_SET_VERTEX_TEXTURE_IMAGE_RECT + (m_index * 8)]) & 0xffff);
} }
u32 RSXVertexTexture::GetBorderColor() const u32 vertex_texture::border_color() const
{ {
return methodRegisters[NV4097_SET_VERTEX_TEXTURE_BORDER_COLOR + (m_index * 32)]; 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;
}
} }

View file

@ -1,122 +1,130 @@
#pragma once #pragma once
class RSXTexture namespace rsx
{
class texture
{ {
protected: protected:
u8 m_index; u8 m_index;
public: public:
u32 m_pitch; //initialize texture registers with default values
u16 m_depth; void init(u8 index);
public:
RSXTexture();
RSXTexture(u8 index);
virtual void Init();
// Offset // Offset
virtual u32 GetOffset() const; u32 offset() const;
// Format // Format
virtual u8 GetLocation() const; u8 location() const;
virtual bool isCubemap() const; bool cubemap() const;
virtual u8 GetBorderType() const; u8 border_type() const;
virtual u8 GetDimension() const; u8 dimension() const;
virtual u8 GetFormat() const; u8 format() const;
virtual u16 GetMipmap() const; u16 mipmap() const;
// Address // Address
virtual u8 GetWrapS() const; u8 wrap_s() const;
virtual u8 GetWrapT() const; u8 wrap_t() const;
virtual u8 GetWrapR() const; u8 wrap_r() const;
virtual u8 GetUnsignedRemap() const; u8 unsigned_remap() const;
virtual u8 GetZfunc() const; u8 zfunc() const;
virtual u8 GetGamma() const; u8 gamma() const;
virtual u8 GetAnisoBias() const; u8 aniso_bias() const;
virtual u8 GetSignedRemap() const; u8 signed_remap() const;
// Control0 // Control0
virtual bool IsEnabled() const; bool enabled() const;
virtual u16 GetMinLOD() const; u16 min_lod() const;
virtual u16 GetMaxLOD() const; u16 max_lod() const;
virtual u8 GetMaxAniso() const; u8 max_aniso() const;
virtual bool IsAlphaKillEnabled() const; bool alpha_kill_enabled() const;
// Control1 // Control1
virtual u32 GetRemap() const; u32 remap() const;
// Filter // Filter
virtual u16 GetBias() const; u16 bias() const;
virtual u8 GetMinFilter() const; u8 min_filter() const;
virtual u8 GetMagFilter() const; u8 mag_filter() const;
virtual u8 GetConvolutionFilter() const; u8 convolution_filter() const;
virtual bool isASigned() const; bool a_signed() const;
virtual bool isRSigned() const; bool r_signed() const;
virtual bool isGSigned() const; bool g_signed() const;
virtual bool isBSigned() const; bool b_signed() const;
// Image Rect // Image Rect
virtual u16 GetWidth() const; u16 width() const;
virtual u16 GetHeight() const; u16 height() const;
// Border Color // Border Color
virtual u32 GetBorderColor() const; u32 border_color() const;
u16 depth() const;
u32 pitch() const;
void SetControl3(u16 depth, u32 pitch); //custom info
u8 index() const;
}; };
class RSXVertexTexture : public RSXTexture class vertex_texture
{ {
protected:
u8 m_index;
public: public:
RSXVertexTexture(); //initialize texture registers with default values
RSXVertexTexture(u8 index); void init(u8 index);
void Init();
// Offset // Offset
u32 GetOffset() const; u32 offset() const;
// Format // Format
u8 GetLocation() const; u8 location() const;
bool isCubemap() const; bool cubemap() const;
u8 GetBorderType() const; u8 border_type() const;
u8 GetDimension() const; u8 dimension() const;
u8 GetFormat() const; u8 format() const;
u16 GetMipmap() const; u16 mipmap() const;
// Address // Address
u8 GetWrapS() const; u8 wrap_s() const;
u8 GetWrapT() const; u8 wrap_t() const;
u8 GetWrapR() const; u8 wrap_r() const;
u8 GetUnsignedRemap() const; u8 unsigned_remap() const;
u8 GetZfunc() const; u8 zfunc() const;
u8 GetGamma() const; u8 gamma() const;
u8 GetAnisoBias() const; u8 aniso_bias() const;
u8 GetSignedRemap() const; u8 signed_remap() const;
// Control0 // Control0
bool IsEnabled() const; bool enabled() const;
u16 GetMinLOD() const; u16 min_lod() const;
u16 GetMaxLOD() const; u16 max_lod() const;
u8 GetMaxAniso() const; u8 max_aniso() const;
bool IsAlphaKillEnabled() const; bool alpha_kill_enabled() const;
// Control1 // Control1
u32 GetRemap() const; u32 remap() const;
// Filter // Filter
u16 GetBias() const; u16 bias() const;
u8 GetMinFilter() const; u8 min_filter() const;
u8 GetMagFilter() const; u8 mag_filter() const;
u8 GetConvolutionFilter() const; u8 convolution_filter() const;
bool isASigned() const; bool a_signed() const;
bool isRSigned() const; bool r_signed() const;
bool isGSigned() const; bool g_signed() const;
bool isBSigned() const; bool b_signed() const;
// Image Rect // Image Rect
u16 GetWidth() const; u16 width() const;
u16 GetHeight() const; u16 height() const;
// Border Color // Border Color
u32 GetBorderColor() const; u32 border_color() const;
u16 depth() const;
u32 pitch() const;
//custom info
u8 index() const;
}; };
}

View file

@ -22,9 +22,13 @@ extern u64 get_system_time();
#define ARGS(x) (x >= count ? OutOfArgsCount(x, cmd, count, args.addr()) : args[x].value()) #define ARGS(x) (x >= count ? OutOfArgsCount(x, cmd, count, args.addr()) : args[x].value())
#define CMD_DEBUG 0 #define CMD_DEBUG 0
u32 methodRegisters[0xffff];
u32 GetAddress(u32 offset, u32 location)
namespace rsx
{
u32 method_registers[0x10000 >> 2];
u32 get_address(u32 offset, u32 location)
{ {
u32 res = 0; u32 res = 0;
@ -58,6 +62,7 @@ u32 GetAddress(u32 offset, u32 location)
return res; return res;
} }
}
RSXVertexData::RSXVertexData() RSXVertexData::RSXVertexData()
: frequency(0) : frequency(0)
@ -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); case_range(16, NV4097_SET_TEXTURE_CONTROL3, 4);
{ {
RSXTexture& tex = m_textures[index]; rsx::texture& tex = m_textures[index];
const u32 a0 = ARGS(0); const u32 a0 = ARGS(0);
u32 pitch = a0 & 0xFFFFF; u32 pitch = a0 & 0xFFFFF;
u16 depth = a0 >> 20; u16 depth = a0 >> 20;
tex.SetControl3(depth, pitch); //tex.SetControl3(depth, pitch);
break; 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); 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); const u32 a0 = ARGS(0);
u32 pitch = a0 & 0xFFFFF; u32 pitch = a0 & 0xFFFFF;
u16 depth = a0 >> 20; u16 depth = a0 >> 20;
tex.SetControl3(depth, pitch); //tex.SetControl3(depth, pitch);
break; 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); 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].addr = addr;
m_vertex_data[index].data.clear(); 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: 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; m_indexed_array.m_type = ARGS(1) >> 4;
break; break;
} }
@ -1063,7 +1068,7 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const
const u32 a0 = ARGS(0); const u32 a0 = ARGS(0);
m_cur_fragment_prog->offset = a0 & ~0x3; 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; m_cur_fragment_prog->ctrl = 0x40;
notifyProgramChange(); notifyProgramChange();
break; 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) if (lineCount == 1 && !inPitch && !outPitch && !notify)
{ {
memcpy(vm::get_ptr<void>(GetAddress(outOffset, 0)), vm::get_ptr<void>(GetAddress(inOffset, 0)), lineLength); memcpy(vm::get_ptr<void>(rsx::get_address(outOffset, 0)), vm::get_ptr<void>(rsx::get_address(inOffset, 0)), lineLength);
} }
else 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 u = ARGS(3); // inX (currently ignored)
const u16 v = ARGS(3) >> 16; // inY (currently ignored) const u16 v = ARGS(3) >> 16; // inY (currently ignored)
u8* pixels_src = vm::get_ptr<u8>(GetAddress(offset, m_context_dma_img_src - 0xfeed0000)); u8* pixels_src = vm::get_ptr<u8>(rsx::get_address(offset, m_context_dma_img_src - 0xfeed0000));
u8* pixels_dst = vm::get_ptr<u8>(GetAddress(m_dst_offset, m_context_dma_img_dst - 0xfeed0000)); u8* pixels_dst = vm::get_ptr<u8>(rsx::get_address(m_dst_offset, m_context_dma_img_dst - 0xfeed0000));
if (m_context_surface == CELL_GCM_CONTEXT_SWIZZLE2D) if (m_context_surface == CELL_GCM_CONTEXT_SWIZZLE2D)
{ {
@ -2588,7 +2593,7 @@ void RSXThread::Task()
for (u32 i = 0; i < count; i++) 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); DoCmd(cmd, cmd & 0x3ffff, args.addr(), count);

View file

@ -9,6 +9,29 @@
#include "Utilities/Thread.h" #include "Utilities/Thread.h"
#include "Utilities/Timer.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 enum Method
{ {
CELL_GCM_METHOD_FLAG_NON_INCREMENT = 0x40000000, CELL_GCM_METHOD_FLAG_NON_INCREMENT = 0x40000000,
@ -17,9 +40,6 @@ enum Method
CELL_GCM_METHOD_FLAG_RETURN = 0x00020000, CELL_GCM_METHOD_FLAG_RETURN = 0x00020000,
}; };
extern u32 methodRegisters[0xffff];
u32 GetAddress(u32 offset, u32 location);
struct RSXVertexData struct RSXVertexData
{ {
u32 frequency; u32 frequency;
@ -107,8 +127,8 @@ protected:
public: public:
GcmTileInfo tiles[m_tiles_count]; GcmTileInfo tiles[m_tiles_count];
GcmZcullInfo zculls[m_zculls_count]; GcmZcullInfo zculls[m_zculls_count];
RSXTexture m_textures[m_textures_count]; rsx::texture m_textures[m_textures_count];
RSXVertexTexture m_vertex_textures[m_textures_count]; rsx::vertex_texture m_vertex_textures[m_textures_count];
RSXVertexData m_vertex_data[m_vertex_count]; RSXVertexData m_vertex_data[m_vertex_count];
RSXIndexArrayData m_indexed_array; RSXIndexArrayData m_indexed_array;
std::vector<RSXTransformConstant> m_fragment_constants; std::vector<RSXTransformConstant> m_fragment_constants;
@ -543,7 +563,7 @@ protected:
// Construct Textures // Construct Textures
for (int i = 0; i < 16; i++) for (int i = 0; i < 16; i++)
{ {
m_textures[i] = RSXTexture(i); m_textures[i] = rsx::texture();
} }
Reset(); Reset();
@ -632,7 +652,7 @@ protected:
for (uint i = 0; i < m_textures_count; ++i) for (uint i = 0; i < m_textures_count; ++i)
{ {
m_textures[i].Init(); m_textures[i].init(i);
} }
} }

View file

@ -316,13 +316,13 @@ void RSXDebugger::OnClickBuffer(wxMouseEvent& event)
if (event.GetId() == p_buffer_colorD->GetId()) SHOW_BUFFER(3); if (event.GetId() == p_buffer_colorD->GetId()) SHOW_BUFFER(3);
if (event.GetId() == p_buffer_tex->GetId()) if (event.GetId() == p_buffer_tex->GetId())
{ {
u8 location = render.m_textures[m_cur_texture].GetLocation(); u8 location = render.m_textures[m_cur_texture].location();
if(location <= 1 && vm::check_addr(GetAddress(render.m_textures[m_cur_texture].GetOffset(), location)) if(location <= 1 && vm::check_addr(rsx::get_address(render.m_textures[m_cur_texture].offset(), location))
&& render.m_textures[m_cur_texture].GetWidth() && render.m_textures[m_cur_texture].GetHeight()) && render.m_textures[m_cur_texture].width() && render.m_textures[m_cur_texture].height())
MemoryViewerPanel::ShowImage(this, MemoryViewerPanel::ShowImage(this,
GetAddress(render.m_textures[m_cur_texture].GetOffset(), location), 1, rsx::get_address(render.m_textures[m_cur_texture].offset(), location), 1,
render.m_textures[m_cur_texture].GetWidth(), render.m_textures[m_cur_texture].width(),
render.m_textures[m_cur_texture].GetHeight(), false); render.m_textures[m_cur_texture].height(), false);
} }
#undef SHOW_BUFFER #undef SHOW_BUFFER
@ -453,28 +453,28 @@ void RSXDebugger::GetBuffers()
} }
// Draw Texture // Draw Texture
if(!render.m_textures[m_cur_texture].IsEnabled()) if(!render.m_textures[m_cur_texture].enabled())
return; return;
u32 offset = render.m_textures[m_cur_texture].GetOffset(); u32 offset = render.m_textures[m_cur_texture].offset();
if(!offset) if(!offset)
return; return;
u8 location = render.m_textures[m_cur_texture].GetLocation(); u8 location = render.m_textures[m_cur_texture].location();
if(location > 1) if(location > 1)
return; return;
u32 TexBuffer_addr = GetAddress(offset, location); u32 TexBuffer_addr = rsx::get_address(offset, location);
if(!vm::check_addr(TexBuffer_addr)) if(!vm::check_addr(TexBuffer_addr))
return; return;
unsigned char* TexBuffer = vm::get_ptr<unsigned char>(TexBuffer_addr); unsigned char* TexBuffer = vm::get_ptr<unsigned char>(TexBuffer_addr);
u32 width = render.m_textures[m_cur_texture].GetWidth(); u32 width = render.m_textures[m_cur_texture].width();
u32 height = render.m_textures[m_cur_texture].GetHeight(); u32 height = render.m_textures[m_cur_texture].height();
unsigned char* buffer = (unsigned char*)malloc(width * height * 3); unsigned char* buffer = (unsigned char*)malloc(width * height * 3);
memcpy(buffer, TexBuffer, width * height * 3); memcpy(buffer, TexBuffer, width * height * 3);
@ -553,29 +553,29 @@ void RSXDebugger::GetTexture()
for(uint i=0; i<RSXThread::m_textures_count; ++i) for(uint i=0; i<RSXThread::m_textures_count; ++i)
{ {
if(render.m_textures[i].IsEnabled()) if(render.m_textures[i].enabled())
{ {
m_list_texture->InsertItem(i, wxString::Format("%d", i)); m_list_texture->InsertItem(i, wxString::Format("%d", i));
u8 location = render.m_textures[i].GetLocation(); u8 location = render.m_textures[i].location();
if(location > 1) if(location > 1)
{ {
m_list_texture->SetItem(i, 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 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, 2, render.m_textures[i].cubemap() ? "True" : "False");
m_list_texture->SetItem(i, 3, wxString::Format("%dD", render.m_textures[i].GetDimension())); m_list_texture->SetItem(i, 3, wxString::Format("%dD", render.m_textures[i].dimension()));
m_list_texture->SetItem(i, 4, render.m_textures[i].IsEnabled() ? "True" : "False"); 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].GetFormat())); 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].GetMipmap())); 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].m_pitch)); 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", m_list_texture->SetItem(i, 8, wxString::Format("%dx%d",
render.m_textures[i].GetWidth(), render.m_textures[i].width(),
render.m_textures[i].GetHeight())); render.m_textures[i].height()));
m_list_texture->SetItemBackgroundColour(i, wxColour(m_cur_texture == i ? "Wheat" : "White")); m_list_texture->SetItemBackgroundColour(i, wxColour(m_cur_texture == i ? "Wheat" : "White"));
} }