Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/resources/shaders/dx11/convert.fx
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ OUTPUT_TYPE ps_convert_depth32_depth24(PS_INPUT input) : OUTPUT_SV
float depthTR = CONVERT_FN(Texture.Load(int3(coords.zy, 0))); \
float depthBL = CONVERT_FN(Texture.Load(int3(coords.xw, 0))); \
float depthBR = CONVERT_FN(Texture.Load(int3(coords.zw, 0))); \
return lerp(lerp(depthTL, depthTR, mix_vals.x), lerp(depthBL, depthBR, mix_vals.x), mix_vals.y);
return floor(lerp(lerp(depthTL, depthTR, mix_vals.x), lerp(depthBL, depthBR, mix_vals.x), mix_vals.y) * exp2(32.0f)) * exp2(-32.0f);

#if defined(__ps_convert_rgba8_depth32__)
OUTPUT_TYPE ps_convert_rgba8_depth32(PS_INPUT input) : OUTPUT_SV
Expand Down
2 changes: 1 addition & 1 deletion bin/resources/shaders/opengl/convert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void ps_convert_depth32_depth24()
float depthTR = CONVERT_FN(texelFetch(TextureSampler, coords.zy, 0)); \
float depthBL = CONVERT_FN(texelFetch(TextureSampler, coords.xw, 0)); \
float depthBR = CONVERT_FN(texelFetch(TextureSampler, coords.zw, 0)); \
OUTPUT = mix(mix(depthTL, depthTR, mix_vals.x), mix(depthBL, depthBR, mix_vals.x), mix_vals.y);
OUTPUT = floor(mix(mix(depthTL, depthTR, mix_vals.x), mix(depthBL, depthBR, mix_vals.x), mix_vals.y) * exp2(32.0f)) * exp2(-32.0f);

#ifdef ps_convert_rgba8_depth32
void ps_convert_rgba8_depth32()
Expand Down
2 changes: 1 addition & 1 deletion bin/resources/shaders/vulkan/convert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ void ps_convert_depth32_depth24()
float depthTR = CONVERT_FN(texelFetch(samp0, coords.zy, 0)); \
float depthBL = CONVERT_FN(texelFetch(samp0, coords.xw, 0)); \
float depthBR = CONVERT_FN(texelFetch(samp0, coords.zw, 0)); \
OUTPUT = mix(mix(depthTL, depthTR, mix_vals.x), mix(depthBL, depthBR, mix_vals.x), mix_vals.y);
OUTPUT = floor(mix(mix(depthTL, depthTR, mix_vals.x), mix(depthBL, depthBR, mix_vals.x), mix_vals.y) * exp2(32.0f)) * exp2(-32.0f);

#ifdef ps_convert_rgba8_depth32
void ps_convert_rgba8_depth32()
Expand Down
11 changes: 9 additions & 2 deletions pcsx2/GS/Renderers/Common/GSDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,13 @@ class ShaderConvertSelector
return ShaderEntryPoint(Shader());
}

constexpr ShaderConvertSelector SetShader(ShaderConvert shader = ShaderConvert::COPY)
{
ShaderConvertSelector tmp = *this;
tmp.fields.shader = static_cast<u32>(shader);
return tmp;
}

constexpr ShaderConvertSelector SetMask(u8 mask = 0xf) const
{
ShaderConvertSelector tmp = *this;
Expand Down Expand Up @@ -446,7 +453,7 @@ class ShaderConvertSelector
};

static inline ShaderConvertSelector GetConvertShader(GSTexture::Format src, GSTexture::Format dst,
u32 src_bpp = 32, u32 dst_bpp = 32, u8 mask = 0xf)
u32 src_bpp = 32, u32 dst_bpp = 32, u8 mask = 0xf, Filter linear = Nearest)
{
ShaderConvert shader = static_cast<ShaderConvert>(-1);
switch (src)
Expand Down Expand Up @@ -531,7 +538,7 @@ static inline ShaderConvertSelector GetConvertShader(GSTexture::Format src, GSTe
break;
}

return ShaderConvertSelector(shader, mask, dst == GSTexture::Format::DepthStencil);
return ShaderConvertSelector(shader, mask, dst == GSTexture::Format::DepthStencil, linear);
}

static inline ShaderConvertSelector GetConvertShader(const GSTexture* src, const GSTexture* dst, u32 src_bpp, u32 dst_bpp, u8 mask = 0xf)
Expand Down
16 changes: 9 additions & 7 deletions pcsx2/GS/Renderers/HW/GSTextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7955,8 +7955,9 @@ void GSTextureCache::Target::Update(bool cannot_scale)
// Bilinear filtering this is probably not a good thing, at least in native, but upscaling Nearest can be gross and messy.
// It's needed for depth, though.. filtering depth doesn't make much sense, but SMT3 needs it..
const bool upscaled = (m_scale != 1.0f);
const bool is_depth = m_type == DepthStencil;
const bool override_linear = (upscaled && GSConfig.UserHacks_BilinearHack == GSBilinearDirtyMode::ForceBilinear);
const bool linear = (m_type == RenderTarget && upscaled && GSConfig.UserHacks_BilinearHack != GSBilinearDirtyMode::ForceNearest);
const bool linear = (upscaled && ((!is_depth && GSConfig.UserHacks_BilinearHack != GSBilinearDirtyMode::ForceNearest) || is_depth));

GSDevice::MultiStretchRect* drects = static_cast<GSDevice::MultiStretchRect*>(
alloca(sizeof(GSDevice::MultiStretchRect) * static_cast<u32>(m_dirty.size())));
Expand Down Expand Up @@ -8018,7 +8019,7 @@ void GSTextureCache::Target::Update(bool cannot_scale)
drect.src = t;
drect.src_rect = GSVector4(update_r - t_offset) / t_sizef;
drect.dst_rect = GSVector4(update_r) * GSVector4(m_scale);
drect.filter = BilnIf(linear && (m_dirty[i].req_linear || override_linear));
drect.filter = BilnIf(linear && (is_depth || m_dirty[i].req_linear || override_linear));

// Copy the new GS memory content into the destination texture.
if (m_type == RenderTarget)
Expand Down Expand Up @@ -8047,12 +8048,13 @@ void GSTextureCache::Target::Update(bool cannot_scale)
m_rt_alpha_scale = true;
}

const bool linear = upscaled && GSConfig.UserHacks_BilinearHack != GSBilinearDirtyMode::ForceNearest;

// No need to sort here, it's all the one texture.
const ShaderConvertSelector shader = (m_type == RenderTarget) ?
(m_rt_alpha_scale ? ShaderConvert::RTA_CORRECTION : ShaderConvert::COPY) :
GetConvertShader(GSTexture::Format::Color, m_texture->GetFormat(), bpp, bpp, linear);
ShaderConvertSelector shader = GetConvertShader(GSTexture::Format::Color, m_texture->GetFormat(), bpp, bpp, 0xF, drects[0].filter);

if (m_type == RenderTarget && m_rt_alpha_scale && shader.Shader() == ShaderConvert::COPY)
{
shader = shader.SetShader(ShaderConvert::RTA_CORRECTION);
}

g_gs_device->DrawMultiStretchRects(drects, ndrects, m_texture, shader);
}
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/GS/Renderers/Metal/convert.metal
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ struct ConvertToDepthRes
float depthTR = convert(texture.read(coords.zy));
float depthBL = convert(texture.read(coords.xw));
float depthBR = convert(texture.read(coords.zw));
return mix(mix(depthTL, depthTR, mix_vals.x), mix(depthBL, depthBR, mix_vals.x), mix_vals.y);
return floor(mix(mix(depthTL, depthTR, mix_vals.x), mix(depthBL, depthBR, mix_vals.x), mix_vals.y) * 0x1p32) * 0x1p-32;
}

template <float (&convert)(half4)>
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/ShaderCacheVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

/// Version number for GS and other shaders. Increment whenever any of the contents of the
/// shaders change, to invalidate the cache.
static constexpr u32 SHADER_CACHE_VERSION = 109; // Last changed in PR 14795
static constexpr u32 SHADER_CACHE_VERSION = 110; // Last changed in PR 14897
Loading