mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
Video Backends: Implement vertical scaling for xfb copies. This fixes the
display of PAL games that run in 50hz mode.
This commit is contained in:
@ -232,7 +232,7 @@ static void BPWritten(const BPCmd& bp)
|
||||
bool is_depth_copy = bpmem.zcontrol.pixel_format == PEControl::Z24;
|
||||
g_texture_cache->CopyRenderTargetToTexture(destAddr, PE_copy.tp_realFormat(), destStride,
|
||||
is_depth_copy, srcRect, !!PE_copy.intensity_fmt,
|
||||
!!PE_copy.half_scale);
|
||||
!!PE_copy.half_scale, 1.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -261,7 +261,7 @@ static void BPWritten(const BPCmd& bp)
|
||||
bool is_depth_copy = bpmem.zcontrol.pixel_format == PEControl::Z24;
|
||||
g_texture_cache->CopyRenderTargetToTexture(destAddr, EFBCopyFormat::XFB, destStride,
|
||||
is_depth_copy, srcRect, false,
|
||||
false);
|
||||
false, yScale);
|
||||
|
||||
// This stays in to signal end of a "frame"
|
||||
g_renderer->RenderToXFB(destAddr, srcRect, destStride, height, s_gammaLUT[PE_copy.gamma]);
|
||||
|
@ -668,15 +668,16 @@ void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, const
|
||||
// Get the current XFB from texture cache
|
||||
auto* xfb_entry = g_texture_cache->GetTexture(xfbAddr, fbWidth, fbHeight, TextureFormat::XFB,
|
||||
force_safe_texture_cache_hash);
|
||||
|
||||
// TODO, check if xfb_entry is a duplicate of the previous frame and skip SwapImpl
|
||||
|
||||
m_previous_xfb_texture = xfb_entry->texture.get();
|
||||
if (xfb_entry)
|
||||
{
|
||||
// TODO, check if xfb_entry is a duplicate of the previous frame and skip SwapImpl
|
||||
|
||||
m_last_xfb_texture = xfb_entry->texture.get();
|
||||
|
||||
// TODO: merge more generic parts into VideoCommon
|
||||
g_renderer->SwapImpl(xfb_entry->texture.get(), rc, ticks, Gamma);
|
||||
// TODO: merge more generic parts into VideoCommon
|
||||
g_renderer->SwapImpl(xfb_entry->texture.get(), rc, ticks, Gamma);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_xfb_written)
|
||||
|
@ -376,7 +376,7 @@ TextureCacheBase::DoPartialTextureUpdates(TCacheEntry* entry_to_update, u8* pale
|
||||
u32 copy_width =
|
||||
std::min(entry->native_width - src_x, entry_to_update->native_width - dst_x);
|
||||
u32 copy_height =
|
||||
std::min(entry->native_height - src_y, entry_to_update->native_height - dst_y);
|
||||
std::min((entry->native_height * entry->y_scale) - src_y, (entry_to_update->native_height * entry_to_update->y_scale) - dst_y);
|
||||
|
||||
// If one of the textures is scaled, scale both with the current efb scaling factor
|
||||
if (entry_to_update->native_width != entry_to_update->GetWidth() ||
|
||||
@ -385,9 +385,9 @@ TextureCacheBase::DoPartialTextureUpdates(TCacheEntry* entry_to_update, u8* pale
|
||||
{
|
||||
ScaleTextureCacheEntryTo(entry_to_update,
|
||||
g_renderer->EFBToScaledX(entry_to_update->native_width),
|
||||
g_renderer->EFBToScaledY(entry_to_update->native_height));
|
||||
g_renderer->EFBToScaledY(entry_to_update->native_height * entry_to_update->y_scale));
|
||||
ScaleTextureCacheEntryTo(entry, g_renderer->EFBToScaledX(entry->native_width),
|
||||
g_renderer->EFBToScaledY(entry->native_height));
|
||||
g_renderer->EFBToScaledY(entry->native_height * entry->y_scale));
|
||||
|
||||
src_x = g_renderer->EFBToScaledX(src_x);
|
||||
src_y = g_renderer->EFBToScaledY(src_y);
|
||||
@ -794,7 +794,7 @@ TextureCacheBase::TCacheEntry* TextureCacheBase::GetTexture(u32 address, u32 wid
|
||||
|
||||
// Do not load strided EFB copies, they are not meant to be used directly.
|
||||
// Also do not directly load EFB copies, which were partly overwritten.
|
||||
if (entry->IsCopy() && entry->native_width == nativeW && entry->native_height == nativeH &&
|
||||
if (entry->IsCopy() && entry->native_width == nativeW && static_cast<unsigned int>(entry->native_height * entry->y_scale) == nativeH &&
|
||||
entry->memory_stride == entry->BytesPerRow() && !entry->may_have_overlapping_textures)
|
||||
{
|
||||
// EFB copies have slightly different rules as EFB copy formats have different
|
||||
@ -881,7 +881,8 @@ TextureCacheBase::TCacheEntry* TextureCacheBase::GetTexture(u32 address, u32 wid
|
||||
TCacheEntry* entry = hash_iter->second;
|
||||
// All parameters, except the address, need to match here
|
||||
if (entry->format == full_format && entry->native_levels >= tex_levels &&
|
||||
entry->native_width == nativeW && entry->native_height == nativeH)
|
||||
entry->native_width == nativeW &&
|
||||
static_cast<unsigned int>(entry->native_height * entry->y_scale) == nativeH)
|
||||
{
|
||||
entry = DoPartialTextureUpdates(hash_iter->second, &texMem[tlutaddr], tlutfmt);
|
||||
|
||||
@ -1107,7 +1108,7 @@ TextureCacheBase::TCacheEntry* TextureCacheBase::GetTexture(u32 address, u32 wid
|
||||
void TextureCacheBase::CopyRenderTargetToTexture(u32 dstAddr, EFBCopyFormat dstFormat,
|
||||
u32 dstStride, bool is_depth_copy,
|
||||
const EFBRectangle& srcRect, bool isIntensity,
|
||||
bool scaleByHalf)
|
||||
bool scaleByHalf, float y_scale)
|
||||
{
|
||||
// Emulation methods:
|
||||
//
|
||||
@ -1451,7 +1452,7 @@ void TextureCacheBase::CopyRenderTargetToTexture(u32 dstAddr, EFBCopyFormat dstF
|
||||
const u32 blockW = TexDecoder_GetBlockWidthInTexels(baseFormat);
|
||||
|
||||
// Round up source height to multiple of block size
|
||||
u32 actualHeight = Common::AlignUp(tex_h, blockH);
|
||||
u32 actualHeight = Common::AlignUp(static_cast<unsigned int>(tex_h * y_scale), blockH);
|
||||
const u32 actualWidth = Common::AlignUp(tex_w, blockW);
|
||||
|
||||
u32 num_blocks_y = actualHeight / blockH;
|
||||
@ -1465,7 +1466,7 @@ void TextureCacheBase::CopyRenderTargetToTexture(u32 dstAddr, EFBCopyFormat dstF
|
||||
|
||||
if (copy_to_ram)
|
||||
{
|
||||
EFBCopyParams format(srcFormat, dstFormat, is_depth_copy, isIntensity);
|
||||
EFBCopyParams format(srcFormat, dstFormat, is_depth_copy, isIntensity, y_scale);
|
||||
CopyEFB(dst, format, tex_w, bytes_per_row, num_blocks_y, dstStride, srcRect, scaleByHalf);
|
||||
}
|
||||
else
|
||||
@ -1556,6 +1557,7 @@ void TextureCacheBase::CopyRenderTargetToTexture(u32 dstAddr, EFBCopyFormat dstF
|
||||
{
|
||||
entry->SetGeneralParameters(dstAddr, 0, baseFormat, is_xfb_copy);
|
||||
entry->SetDimensions(tex_w, tex_h, 1);
|
||||
entry->y_scale = y_scale;
|
||||
|
||||
entry->frameCount = FRAMECOUNT_INVALID;
|
||||
if (is_xfb_copy)
|
||||
@ -1731,7 +1733,7 @@ u32 TextureCacheBase::TCacheEntry::NumBlocksY() const
|
||||
{
|
||||
u32 blockH = TexDecoder_GetBlockHeightInTexels(format.texfmt);
|
||||
// Round up source height to multiple of block size
|
||||
u32 actualHeight = Common::AlignUp(native_height, blockH);
|
||||
u32 actualHeight = Common::AlignUp(static_cast<unsigned int>(native_height * y_scale), blockH);
|
||||
|
||||
return actualHeight / blockH;
|
||||
}
|
||||
|
@ -45,21 +45,22 @@ struct TextureAndTLUTFormat
|
||||
struct EFBCopyParams
|
||||
{
|
||||
EFBCopyParams(PEControl::PixelFormat efb_format_, EFBCopyFormat copy_format_, bool depth_,
|
||||
bool yuv_)
|
||||
: efb_format(efb_format_), copy_format(copy_format_), depth(depth_), yuv(yuv_)
|
||||
bool yuv_, float y_scale_)
|
||||
: efb_format(efb_format_), copy_format(copy_format_), depth(depth_), yuv(yuv_), y_scale(y_scale_)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator<(const EFBCopyParams& rhs) const
|
||||
{
|
||||
return std::tie(efb_format, copy_format, depth, yuv) <
|
||||
std::tie(rhs.efb_format, rhs.copy_format, rhs.depth, rhs.yuv);
|
||||
return std::tie(efb_format, copy_format, depth, yuv, y_scale) <
|
||||
std::tie(rhs.efb_format, rhs.copy_format, rhs.depth, rhs.yuv, rhs.y_scale);
|
||||
}
|
||||
|
||||
PEControl::PixelFormat efb_format;
|
||||
EFBCopyFormat copy_format;
|
||||
bool depth;
|
||||
bool yuv;
|
||||
float y_scale;
|
||||
};
|
||||
|
||||
class TextureCacheBase
|
||||
@ -86,6 +87,7 @@ public:
|
||||
// content, aren't just downscaled
|
||||
bool should_force_safe_hashing = false; // for XFB
|
||||
bool is_xfb_copy = false;
|
||||
float y_scale = 1.0f;
|
||||
|
||||
unsigned int native_width,
|
||||
native_height; // Texture dimensions from the GameCube's point of view
|
||||
@ -188,7 +190,7 @@ public:
|
||||
virtual void BindTextures();
|
||||
void CopyRenderTargetToTexture(u32 dstAddr, EFBCopyFormat dstFormat, u32 dstStride,
|
||||
bool is_depth_copy, const EFBRectangle& srcRect, bool isIntensity,
|
||||
bool scaleByHalf);
|
||||
bool scaleByHalf, float y_scale);
|
||||
|
||||
virtual void ConvertTexture(TCacheEntry* entry, TCacheEntry* unconverted, const void* palette,
|
||||
TLUTFormat format) = 0;
|
||||
@ -210,6 +212,8 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void ScaleTextureCacheEntryTo(TCacheEntry* entry, u32 new_width, u32 new_height);
|
||||
|
||||
protected:
|
||||
TextureCacheBase();
|
||||
|
||||
@ -235,7 +239,6 @@ private:
|
||||
|
||||
TCacheEntry* ApplyPaletteToEntry(TCacheEntry* entry, u8* palette, TLUTFormat tlutfmt);
|
||||
|
||||
void ScaleTextureCacheEntryTo(TCacheEntry* entry, u32 new_width, u32 new_height);
|
||||
TCacheEntry* DoPartialTextureUpdates(TCacheEntry* entry_to_update, u8* palette,
|
||||
TLUTFormat tlutfmt);
|
||||
|
||||
|
@ -64,9 +64,12 @@ static void WriteSwizzler(char*& p, EFBCopyFormat format, APIType ApiType)
|
||||
// left, top, of source rectangle within source texture
|
||||
// width of the destination rectangle, scale_factor (1 or 2)
|
||||
if (ApiType == APIType::Vulkan)
|
||||
WRITE(p, "layout(std140, push_constant) uniform PCBlock { int4 position; } PC;\n");
|
||||
WRITE(p, "layout(std140, push_constant) uniform PCBlock { int4 position; float y_scale; } PC;\n");
|
||||
else
|
||||
{
|
||||
WRITE(p, "uniform int4 position;\n");
|
||||
WRITE(p, "uniform float y_scale;\n");
|
||||
}
|
||||
|
||||
// Alpha channel in the copy is set to 1 the EFB format does not have an alpha channel.
|
||||
WRITE(p, "float4 RGBA8ToRGB8(float4 src)\n");
|
||||
@ -111,7 +114,8 @@ static void WriteSwizzler(char*& p, EFBCopyFormat format, APIType ApiType)
|
||||
WRITE(p, "{\n"
|
||||
" int2 sampleUv;\n"
|
||||
" int2 uv1 = int2(gl_FragCoord.xy);\n"
|
||||
" int4 position = PC.position;\n");
|
||||
" int4 position = PC.position;\n"
|
||||
" float y_scale = PC.y_scale;\n");
|
||||
}
|
||||
else // D3D
|
||||
{
|
||||
@ -150,6 +154,7 @@ static void WriteSwizzler(char*& p, EFBCopyFormat format, APIType ApiType)
|
||||
// pixel)
|
||||
WRITE(p, " uv0 += float2(position.xy);\n"); // move to copied rect
|
||||
WRITE(p, " uv0 /= float2(%d, %d);\n", EFB_WIDTH, EFB_HEIGHT); // normalize to [0:1]
|
||||
WRITE(p, " uv0 /= float2(1, y_scale);\n"); // apply the y scaling
|
||||
if (ApiType == APIType::OpenGL) // ogl has to flip up and down
|
||||
{
|
||||
WRITE(p, " uv0.y = 1.0-uv0.y;\n");
|
||||
|
Reference in New Issue
Block a user