Skip to content

Commit 27fe5c6

Browse files
committed
rsx: Fix input-side vs output-side remapping flags
- Sign bit and biased renorm apply on input, Gamma on output
1 parent ed3d2a0 commit 27fe5c6

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

rpcs3/Emu/RSX/RSXThread.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,19 +2332,47 @@ namespace rsx
23322332
u32 unsigned_remap = 0;
23332333
u32 gamma = 0;
23342334

2335+
auto remap_channel_bits = [](const rsx::texture_channel_remap_t& remap, u32 bits) -> u32
2336+
{
2337+
if (!bits || remap.encoded == RSX_TEXTURE_REMAP_IDENTITY) [[ likely ]]
2338+
{
2339+
return bits;
2340+
}
2341+
2342+
u32 result = 0;
2343+
for (u8 channel = 0; channel < 4; ++channel)
2344+
{
2345+
switch (remap.control_map[channel])
2346+
{
2347+
case CELL_GCM_TEXTURE_REMAP_REMAP:
2348+
if (bits & (1u << remap.channel_map[channel]))
2349+
{
2350+
result |= (1u << channel);
2351+
}
2352+
break;
2353+
default:
2354+
break;
2355+
}
2356+
}
2357+
return result;
2358+
};
2359+
2360+
const auto texture_remap = tex.decoded_remap();
23352361
if (format_features & RSX_FORMAT_FEATURE_SIGNED_COMPONENTS)
23362362
{
2337-
argb8_signed = tex.argb_signed();
2363+
// Tests show this is applied pre-readout. It's just a property of the incoming bytes and is therefore subject to remap.
2364+
argb8_signed = remap_channel_bits(texture_remap, tex.argb_signed());
23382365
}
23392366

23402367
if (format_features & RSX_FORMAT_FEATURE_GAMMA_CORRECTION)
23412368
{
2369+
// Tests show this is applied post-readout. It's a property of the final value stored in the register and is not remapped. It overwrites even constant channels (REMAP_ZERO | REMAP_ONE)
23422370
gamma = tex.gamma() & ~(argb8_signed);
23432371
}
23442372

23452373
if (format_features & RSX_FORMAT_FEATURE_BIASED_NORMALIZATION)
23462374
{
2347-
// The renormalization flag applies to all channels
2375+
// The renormalization flag applies to all channels. It is weaker than the other flags.
23482376
unsigned_remap = (tex.unsigned_remap() == CELL_GCM_TEXTURE_UNSIGNED_REMAP_NORMAL) ? 0u : 0xF;
23492377
unsigned_remap &= ~(argb8_signed | gamma);
23502378
}

0 commit comments

Comments
 (0)