Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #10396 from Pokechu22/efb-copy-clamp
Fix copy filter clamping (again)
  • Loading branch information
JMC47 committed Jan 28, 2022
2 parents 80771ec + 25c547e commit f0136e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions Source/Core/VideoCommon/TextureCacheBase.cpp
Expand Up @@ -2676,7 +2676,8 @@ void TextureCacheBase::CopyEFBToCacheEntry(TCacheEntry* entry, bool is_depth_cop
};
Uniforms uniforms;
const float rcp_efb_width = 1.0f / static_cast<float>(g_framebuffer_manager->GetEFBWidth());
const float rcp_efb_height = 1.0f / static_cast<float>(g_framebuffer_manager->GetEFBHeight());
const u32 efb_height = g_framebuffer_manager->GetEFBHeight();
const float rcp_efb_height = 1.0f / static_cast<float>(efb_height);
uniforms.src_left = framebuffer_rect.left * rcp_efb_width;
uniforms.src_top = framebuffer_rect.top * rcp_efb_height;
uniforms.src_width = framebuffer_rect.GetWidth() * rcp_efb_width;
Expand All @@ -2685,9 +2686,15 @@ void TextureCacheBase::CopyEFBToCacheEntry(TCacheEntry* entry, bool is_depth_cop
uniforms.filter_coefficients[1] = filter_coefficients.middle;
uniforms.filter_coefficients[2] = filter_coefficients.lower;
uniforms.gamma_rcp = 1.0f / gamma;
uniforms.clamp_top = clamp_top ? framebuffer_rect.top * rcp_efb_height : 0.0f;
int bottom_coord = framebuffer_rect.bottom - 1;
uniforms.clamp_bottom = clamp_bottom ? bottom_coord * rcp_efb_height : 1.0f;
// NOTE: when the clamp bits aren't set, the hardware will happily read beyond the EFB,
// which returns random garbage from the empty bus (confirmed by hardware tests).
//
// In our implementation, the garbage just so happens to be the top or bottom row.
// Statistically, that could happen.
const u32 top_coord = clamp_top ? framebuffer_rect.top : 0;
uniforms.clamp_top = (static_cast<float>(top_coord) + .5f) * rcp_efb_height;
const u32 bottom_coord = (clamp_bottom ? framebuffer_rect.bottom : efb_height) - 1;
uniforms.clamp_bottom = (static_cast<float>(bottom_coord) + .5f) * rcp_efb_height;
uniforms.pixel_height = g_ActiveConfig.bCopyEFBScaled ? rcp_efb_height : 1.0f / EFB_HEIGHT;
uniforms.padding = 0;
g_vertex_manager->UploadUtilityUniforms(&uniforms, sizeof(uniforms));
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoCommon/TextureConverterShaderGen.cpp
Expand Up @@ -127,7 +127,7 @@ ShaderCode GeneratePixelShader(APIType api_type, const UidData* uid_data)
{
out.Write("VARYING_LOCATION(0) in vec3 v_tex0;\n");
}
out.Write("FRAGMENT_OUTPUT_LOCATION(0) out vec4 ocol0;"
out.Write("FRAGMENT_OUTPUT_LOCATION(0) out vec4 ocol0;\n"
"void main()\n{{\n");
}

Expand Down

1 comment on commit f0136e0

@philou-felin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yippee! 😃

Please sign in to comment.