Skip to content

Commit

Permalink
Allow block transfers from RAM to depth buffers.
Browse files Browse the repository at this point in the history
Reuses the existing compat flag BlockTransferDepth.

I do aim to remove that compat flag in the future, it's probably not
even necessary here, it's just that general depth block transfers were
already gated on it.

Fixes #17878
  • Loading branch information
hrydgard committed Dec 5, 2023
1 parent 81d741a commit 88f2657
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
38 changes: 34 additions & 4 deletions GPU/Common/FramebufferManagerCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1904,6 +1904,7 @@ bool FramebufferManagerCommon::NotifyFramebufferCopy(u32 src, u32 dst, int size,

dst &= 0x3FFFFFFF;
src &= 0x3FFFFFFF;

if (Memory::IsVRAMAddress(dst))
dst &= 0x041FFFFF;
if (Memory::IsVRAMAddress(src))
Expand All @@ -1917,7 +1918,7 @@ bool FramebufferManagerCommon::NotifyFramebufferCopy(u32 src, u32 dst, int size,
bool ignoreSrcBuffer = flags & (GPUCopyFlag::FORCE_SRC_MATCH_MEM | GPUCopyFlag::MEMSET);

// TODO: In the future we should probably check both channels. Currently depth is only on request.
RasterChannel channel = flags & GPUCopyFlag::DEPTH_REQUESTED ? RASTER_DEPTH : RASTER_COLOR;
RasterChannel channel = (flags & GPUCopyFlag::DEPTH_REQUESTED) ? RASTER_DEPTH : RASTER_COLOR;

TinySet<CopyCandidate, 4> srcCandidates;
TinySet<CopyCandidate, 4> dstCandidates;
Expand Down Expand Up @@ -2510,8 +2511,21 @@ bool FramebufferManagerCommon::NotifyBlockTransferBefore(u32 dstBasePtr, int dst
return false;
}

// Skip checking if there's no framebuffers in that area.
if (!MayIntersectFramebuffer(srcBasePtr) && !MayIntersectFramebuffer(dstBasePtr)) {
// Skip checking if there's no framebuffers in that area. Make a special exception for obvious transfers to depth buffer, see issue #17878
bool dstDepthSwizzle = Memory::IsVRAMAddress(dstBasePtr) && ((dstBasePtr & 0x600000) == 0x600000);

if (dstDepthSwizzle) {
// Convert the 32-bit copy to a 16-bit copy so stride matches in FindTransferFramebuffer.
// Though, FindTransferFramebuffer should really go by byte stride...
if (bpp == 4) {
bpp = 2;
srcX *= 2;
srcStride *= 2;
dstX *= 2;
dstStride *= 2;
width *= 2;
}
} else if (!MayIntersectFramebuffer(srcBasePtr) && !MayIntersectFramebuffer(dstBasePtr)) {
return false;
}

Expand All @@ -2529,6 +2543,10 @@ bool FramebufferManagerCommon::NotifyBlockTransferBefore(u32 dstBasePtr, int dst
}
}

if (!srcBuffer && dstBuffer && dstRect.channel == RASTER_DEPTH) {
dstBuffer = true;
}

if (srcBuffer && !dstBuffer) {
// In here, we can't read from dstRect.
if (PSP_CoreParameter().compat.flags().BlockTransferAllowCreateFB ||
Expand Down Expand Up @@ -2635,7 +2653,19 @@ bool FramebufferManagerCommon::NotifyBlockTransferBefore(u32 dstBasePtr, int dst
return true;

} else if (dstBuffer) {
// Here we should just draw the pixels into the buffer. Copy first.
// Handle depth uploads directly here, and let's not bother copying the data. This is compat-flag-gated for now,
// may generalize it when I remove the compat flag.
if (dstRect.channel == RASTER_DEPTH) {
WARN_LOG_ONCE(btud, G3D, "Block transfer upload %08x -> %08x (%dx%d %d,%d bpp=%d %s)", srcBasePtr, dstBasePtr, width, height, dstX, dstY, bpp, RasterChannelToString(dstRect.channel));
FlushBeforeCopy();
const u8 *srcBase = Memory::GetPointerUnchecked(srcBasePtr) + (srcX + srcY * srcStride) * bpp;
DrawPixels(dstRect.vfb, dstX, dstY, srcBase, dstRect.vfb->Format(dstRect.channel), srcStride, (int)(dstRect.w_bytes / bpp), dstRect.h, dstRect.channel, "BlockTransferCopy_DrawPixelsDepth");
RebindFramebuffer("RebindFramebuffer - UploadDepth");
return true;
}

// Here we should just draw the pixels into the buffer. Return false to copy the memory first.
// NotifyBlockTransferAfter will take care of the rest.
return false;
} else if (srcBuffer) {
WARN_LOG_N_TIMES(btd, 10, G3D, "Block transfer readback %dx%d %dbpp from %08x (x:%d y:%d stride:%d) -> %08x (x:%d y:%d stride:%d)",
Expand Down
3 changes: 3 additions & 0 deletions assets/compat.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,9 @@ ULES01070 = true
ULES01071 = true
ULUS10347 = true

# Hayate no Gotoku!! Nightmare Paradise - see issue #17878
ULJM05416 = true

[DaxterRotatedAnalogStick]
# Daxter (see issue #17015)
UCUS98618 = true
Expand Down

0 comments on commit 88f2657

Please sign in to comment.