Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rsx: Texturing improvements #11163

Merged
merged 9 commits into from
Nov 24, 2021
46 changes: 34 additions & 12 deletions rpcs3/Emu/RSX/Common/texture_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -2173,6 +2173,7 @@ namespace rsx
// NOTE: Do not disable 'cyclic ref' since the texture_barrier may have already been issued!
result.image_handle = 0;
result.external_subresource_desc = { 0, deferred_request_command::mipmap_gather, attributes, {}, tex.decoded_remap() };
result.format_class = rsx::classify_format(attributes.gcm_format);

if (use_upscaling)
{
Expand Down Expand Up @@ -2622,7 +2623,6 @@ namespace rsx
case CELL_GCM_TEXTURE_A8R8G8B8:
if (!dst_is_argb8) continue;
break;
case CELL_GCM_TEXTURE_X16:
case CELL_GCM_TEXTURE_R5G6B5:
if (dst_is_argb8) continue;
break;
Expand Down Expand Up @@ -2703,29 +2703,51 @@ namespace rsx
// Force format matching; only accept 16-bit data for 16-bit transfers, 32-bit for 32-bit transfers
switch (surface->get_gcm_format())
{
case CELL_GCM_TEXTURE_A8R8G8B8:
case CELL_GCM_TEXTURE_D8R8G8B8:
case CELL_GCM_TEXTURE_DEPTH24_D8:
case CELL_GCM_TEXTURE_DEPTH24_D8_FLOAT:
case CELL_GCM_TEXTURE_X32_FLOAT:
case CELL_GCM_TEXTURE_Y16_X16:
case CELL_GCM_TEXTURE_Y16_X16_FLOAT:
{
if (!src_is_argb8) continue;
break;
// Should be copy compatible but not scaling compatible
if (src_is_argb8 && (is_copy_op || dst_is_render_target)) break;
continue;
}
case CELL_GCM_TEXTURE_DEPTH24_D8:
case CELL_GCM_TEXTURE_DEPTH24_D8_FLOAT:
{
// Should be copy compatible but not scaling compatible
if (src_is_argb8 && (is_copy_op || !dst_is_render_target)) break;
continue;
}
case CELL_GCM_TEXTURE_A8R8G8B8:
case CELL_GCM_TEXTURE_D8R8G8B8:
{
// Perfect match
if (src_is_argb8) break;
continue;
}
case CELL_GCM_TEXTURE_R5G6B5:
case CELL_GCM_TEXTURE_DEPTH16:
case CELL_GCM_TEXTURE_DEPTH16_FLOAT:
case CELL_GCM_TEXTURE_X16:
case CELL_GCM_TEXTURE_G8B8:
case CELL_GCM_TEXTURE_A1R5G5B5:
case CELL_GCM_TEXTURE_A4R4G4B4:
case CELL_GCM_TEXTURE_D1R5G5B5:
case CELL_GCM_TEXTURE_R5G5B5A1:
{
if (src_is_argb8) continue;
break;
// Copy compatible
if (!src_is_argb8 && (is_copy_op || dst_is_render_target)) break;
continue;
}
case CELL_GCM_TEXTURE_DEPTH16:
case CELL_GCM_TEXTURE_DEPTH16_FLOAT:
{
// Copy compatible
if (!src_is_argb8 && (is_copy_op || !dst_is_render_target)) break;
continue;
}
case CELL_GCM_TEXTURE_R5G6B5:
{
// Perfect match
if (!src_is_argb8) break;
continue;
}
default:
{
Expand Down
10 changes: 3 additions & 7 deletions rpcs3/Emu/RSX/Common/texture_cache_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,15 @@ namespace rsx
return gcm_format;
}

static inline u32 get_sized_blit_format(bool is_32_bit, bool depth_format, bool format_conversion)
static inline u32 get_sized_blit_format(bool is_32_bit, bool depth_format, bool is_format_convert)
kd-11 marked this conversation as resolved.
Show resolved Hide resolved
{
if (format_conversion)
{
return (is_32_bit) ? CELL_GCM_TEXTURE_A8R8G8B8 : CELL_GCM_TEXTURE_R5G6B5;
}
else if (is_32_bit)
if (is_32_bit)
{
return (!depth_format) ? CELL_GCM_TEXTURE_A8R8G8B8 : CELL_GCM_TEXTURE_DEPTH24_D8;
}
else
{
return (!depth_format) ? CELL_GCM_TEXTURE_X16 : CELL_GCM_TEXTURE_DEPTH16;
return (!depth_format) ? CELL_GCM_TEXTURE_R5G6B5 : CELL_GCM_TEXTURE_DEPTH16;
}
}

Expand Down
86 changes: 48 additions & 38 deletions rpcs3/Emu/RSX/GL/GLHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,63 +554,73 @@ namespace gl

ensure(real_src->aspect() == real_dst->aspect());

const bool is_depth_copy = (real_src->aspect() != image_aspect::color);
const filter interp = (linear_interpolation && !is_depth_copy) ? filter::linear : filter::nearest;
GLenum attachment;
gl::buffers target;

if (is_depth_copy)
if (src_rect.width() == dst_rect.width() && src_rect.height() == dst_rect.height() &&
!src_rect.is_flipped() && !dst_rect.is_flipped())
{
if (real_dst->aspect() & gl::image_aspect::stencil)
glCopyImageSubData(real_src->id(), static_cast<GLenum>(real_src->get_target()), 0, src_rect.x1, src_rect.y1, 0,
real_dst->id(), static_cast<GLenum>(real_dst->get_target()), 0, dst_rect.x1, dst_rect.y1, 0,
src_rect.width(), src_rect.height(), 1);
}
else
{
const bool is_depth_copy = (real_src->aspect() != image_aspect::color);
const filter interp = (linear_interpolation && !is_depth_copy) ? filter::linear : filter::nearest;
GLenum attachment;
gl::buffers target;

if (is_depth_copy)
{
attachment = GL_DEPTH_STENCIL_ATTACHMENT;
target = gl::buffers::depth_stencil;
if (real_dst->aspect() & gl::image_aspect::stencil)
{
attachment = GL_DEPTH_STENCIL_ATTACHMENT;
target = gl::buffers::depth_stencil;
}
else
{
attachment = GL_DEPTH_ATTACHMENT;
target = gl::buffers::depth;
}
}
else
{
attachment = GL_DEPTH_ATTACHMENT;
target = gl::buffers::depth;
attachment = GL_COLOR_ATTACHMENT0;
target = gl::buffers::color;
}
}
else
{
attachment = GL_COLOR_ATTACHMENT0;
target = gl::buffers::color;
}

cmd.drv->enable(GL_FALSE, GL_SCISSOR_TEST);
cmd.drv->enable(GL_FALSE, GL_SCISSOR_TEST);

save_binding_state saved;
save_binding_state saved;

glBindFramebuffer(GL_READ_FRAMEBUFFER, blit_src.id());
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, attachment, GL_TEXTURE_2D, real_src->id(), 0);
glBindFramebuffer(GL_READ_FRAMEBUFFER, blit_src.id());
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, attachment, GL_TEXTURE_2D, real_src->id(), 0);

glBindFramebuffer(GL_DRAW_FRAMEBUFFER, blit_dst.id());
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, GL_TEXTURE_2D, real_dst->id(), 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, blit_dst.id());
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, GL_TEXTURE_2D, real_dst->id(), 0);

if (xfer_info.flip_horizontal)
{
src_rect.flip_horizontal();
}
if (xfer_info.flip_horizontal)
{
src_rect.flip_horizontal();
}

if (xfer_info.flip_vertical)
{
src_rect.flip_vertical();
}
if (xfer_info.flip_vertical)
{
src_rect.flip_vertical();
}

glBlitFramebuffer(src_rect.x1, src_rect.y1, src_rect.x2, src_rect.y2,
dst_rect.x1, dst_rect.y1, dst_rect.x2, dst_rect.y2,
static_cast<GLbitfield>(target), static_cast<GLenum>(interp));
glBlitFramebuffer(src_rect.x1, src_rect.y1, src_rect.x2, src_rect.y2,
dst_rect.x1, dst_rect.y1, dst_rect.x2, dst_rect.y2,
static_cast<GLbitfield>(target), static_cast<GLenum>(interp));

// Release the attachments explicitly (not doing so causes glitches, e.g Journey Menu)
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, attachment, GL_TEXTURE_2D, GL_NONE, 0);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, GL_TEXTURE_2D, GL_NONE, 0);
}

if (xfer_info.dst_is_typeless)
{
// Transfer contents from typeless dst back to original dst
copy_typeless(dst, typeless_dst.get());
}

// Release the attachments explicitly (not doing so causes glitches, e.g Journey Menu)
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, attachment, GL_TEXTURE_2D, GL_NONE, 0);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, GL_TEXTURE_2D, GL_NONE, 0);
}

void blitter::fast_clear_image(gl::command_context& cmd, const texture* dst, const color4f& color)
Expand Down