mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-03 03:03:50 +01:00
Carry "this is video" across block copies
videos_ only learns about the CSC output, so the texture we actually draw is just an ordinary 512x512 8888 texture whose contents happen to be different every frame: hash, miss, throw it in the secondary cache, rebuild, forever. So track the copy. NotifyVideoCopy marks the destination as video when the source is, and the copy funnels call it: sceDmacMemcpy, sceKernelMemcpy, and the four replaced memcpy/memmove variants. It sits outside their "is either side VRAM" gate, since a RAM-to-RAM copy of a frame is still a frame. Being a video texture also gets it forced linear filtering and keeps it out of texture upscaling, which is what you want for a video either way. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
aa7b1de28c
commit
4aef060293
7 files changed
+39
-5
No files matched your search
@@ -132,6 +132,7 @@ static int Replace_memcpy() {
|
||||
skip = gpu->PerformMemoryCopy(destPtr, srcPtr, bytes);
|
||||
}
|
||||
}
|
||||
gpu->NotifyVideoCopy(destPtr, srcPtr, bytes);
|
||||
if (!skip && bytes != 0) {
|
||||
u8 *dst = Memory::GetPointerWriteRangeOrException(destPtr, bytes);
|
||||
const u8 *src = Memory::GetPointerRangeOrException(srcPtr, bytes);
|
||||
@@ -193,6 +194,7 @@ static int Replace_memcpy_jak() {
|
||||
skip = gpu->PerformMemoryCopy(destPtr, srcPtr, bytes);
|
||||
}
|
||||
}
|
||||
gpu->NotifyVideoCopy(destPtr, srcPtr, bytes);
|
||||
if (!skip && bytes > SLICE_SIZE && bytes != 512 * 272 * 4 && !PSP_CoreParameter().compat.flags().DisableMemcpySlicing) {
|
||||
// This is a very slow func. To avoid thread blocking, do a slice at a time.
|
||||
// Avoiding exactly 512 * 272 * 4 to detect videos, though.
|
||||
@@ -264,6 +266,7 @@ static int Replace_memcpy16() {
|
||||
skip = gpu->PerformMemoryCopy(destPtr, srcPtr, bytes);
|
||||
}
|
||||
}
|
||||
gpu->NotifyVideoCopy(destPtr, srcPtr, bytes);
|
||||
if (!skip && bytes != 0) {
|
||||
u8 *dst = Memory::GetPointerWriteRangeOrException(destPtr, bytes);
|
||||
const u8 *src = Memory::GetPointerRangeOrException(srcPtr, bytes);
|
||||
@@ -332,6 +335,7 @@ static int Replace_memmove() {
|
||||
skip = gpu->PerformMemoryCopy(destPtr, srcPtr, bytes);
|
||||
}
|
||||
}
|
||||
gpu->NotifyVideoCopy(destPtr, srcPtr, bytes);
|
||||
if (!skip && bytes != 0) {
|
||||
u8 *dst = Memory::GetPointerWriteRangeOrException(destPtr, bytes);
|
||||
const u8 *src = Memory::GetPointerRangeOrException(srcPtr, bytes);
|
||||
|
||||
@@ -51,6 +51,7 @@ static int __DmacMemcpy(MIPSState *mips, u32 dst, u32 src, u32 size) {
|
||||
// We let the GPU deal with invalid range.
|
||||
skip = gpu->PerformMemoryCopy(dst, src, size);
|
||||
}
|
||||
gpu->NotifyVideoCopy(dst, src, size);
|
||||
if (!skip && size != 0) {
|
||||
mips->InvalidateICacheRangeDeferred(src, size);
|
||||
if (Memory::IsValidRange(dst, size) && Memory::IsValidRange(src, size)) {
|
||||
|
||||
@@ -632,6 +632,7 @@ static u32 sceKernelMemcpy(u32 dst, u32 src, u32 size) {
|
||||
if (Memory::IsVRAMAddress(src) || Memory::IsVRAMAddress(dst)) {
|
||||
skip = gpu->PerformMemoryCopy(dst, src, size);
|
||||
}
|
||||
gpu->NotifyVideoCopy(dst, src, size);
|
||||
|
||||
// Technically should crash if these are invalid and size > 0...
|
||||
if (!skip && Memory::IsValidAddress(dst) && Memory::IsValidAddress(src) && Memory::IsValidAddress(dst + size - 1) && Memory::IsValidAddress(src + size - 1)) {
|
||||
|
||||
@@ -1506,19 +1506,35 @@ void TextureCacheCommon::NotifyConfigChanged() {
|
||||
replacer_.NotifyConfigChanged();
|
||||
}
|
||||
|
||||
void TextureCacheCommon::NotifyWriteFormattedFromMemory(u32 addr, int size, int width, GEBufferFormat fmt) {
|
||||
void TextureCacheCommon::NoteVideoRange(u32 addr, u32 size) {
|
||||
addr &= 0x3FFFFFFF;
|
||||
// A game blits its video frame every displayed frame while waiting for the next one, so the
|
||||
// same few display buffers arrive over and over. Refresh the one we already have rather than
|
||||
// stacking a duplicate per frame - IsVideo() scans this linearly.
|
||||
// same few buffers arrive over and over. Refresh the one we already have rather than stacking
|
||||
// a duplicate per frame - IsVideo() scans this linearly.
|
||||
for (VideoInfo &info : videos_) {
|
||||
if (info.addr == addr) {
|
||||
info.size = (u32)size;
|
||||
info.size = size;
|
||||
info.flips = gpuStats.totals.numFlips;
|
||||
return;
|
||||
}
|
||||
}
|
||||
videos_.push_back({ addr, (u32)size, gpuStats.totals.numFlips });
|
||||
videos_.push_back({ addr, size, gpuStats.totals.numFlips });
|
||||
}
|
||||
|
||||
void TextureCacheCommon::NotifyWriteFormattedFromMemory(u32 addr, int size, int width, GEBufferFormat fmt) {
|
||||
NoteVideoRange(addr, (u32)size);
|
||||
}
|
||||
|
||||
// A block copy of a video frame is still a video frame, and games do move them around: Dragon Ball
|
||||
// Z - Shin Budokai: Another Road colour-converts into RAM, sceDmacMemcpy's the result into VRAM and
|
||||
// textures from there, never sampling the converted buffer itself. Without carrying the status
|
||||
// across the copy, what we actually sample looks like an ordinary texture that happens to have new
|
||||
// contents every frame, so we hash it, miss, and rebuild it - forever.
|
||||
void TextureCacheCommon::NotifyVideoCopy(u32 dst, u32 src, int size) {
|
||||
if (size <= 0 || !IsVideo(src)) {
|
||||
return;
|
||||
}
|
||||
NoteVideoRange(dst, (u32)size);
|
||||
}
|
||||
|
||||
void TextureCacheCommon::LoadClut(u32 clutAddr, u32 loadBytes, GPURecord::Recorder *recorder) {
|
||||
|
||||
@@ -363,6 +363,7 @@ public:
|
||||
// so that it can invalidate TexCacheEntries pointed at those addresses.
|
||||
void NotifyFramebuffer(VirtualFramebuffer *framebuffer, FramebufferNotification msg);
|
||||
void NotifyWriteFormattedFromMemory(u32 addr, int size, int width, GEBufferFormat fmt);
|
||||
void NotifyVideoCopy(u32 dst, u32 src, int size);
|
||||
|
||||
int NumLoadedTextures() const {
|
||||
return (int)cache_.size();
|
||||
@@ -445,6 +446,7 @@ protected:
|
||||
virtual void BoundFramebufferTexture() {}
|
||||
|
||||
bool IsVideo(u32 texaddr) const;
|
||||
void NoteVideoRange(u32 addr, u32 size);
|
||||
|
||||
static TextureAlpha CheckCLUTAlpha(const uint8_t *pixelData, GEPaletteFormat clutFmt, int w);
|
||||
|
||||
|
||||
@@ -2004,6 +2004,12 @@ void GPUCommon::DoBlockTransfer(u32 skipDrawReason) {
|
||||
cyclesExecuted += ((height * width * bpp) * 16) / 10;
|
||||
}
|
||||
|
||||
void GPUCommon::NotifyVideoCopy(u32 dest, u32 src, int size) {
|
||||
if (textureCache_) {
|
||||
textureCache_->NotifyVideoCopy(dest, src, size);
|
||||
}
|
||||
}
|
||||
|
||||
bool GPUCommon::PerformMemoryCopy(u32 dest, u32 src, int size, GPUCopyFlag flags) {
|
||||
if (size == 0) {
|
||||
_dbg_assert_msg_(false, "Zero-sized PerformMemoryCopy: %08x -> %08x, size %d (flag: %d)", src, dest, size, (int)flags);
|
||||
|
||||
@@ -162,6 +162,10 @@ public:
|
||||
virtual void PerformWriteFormattedFromMemory(u32 addr, int size, int width, GEBufferFormat format);
|
||||
virtual bool PerformWriteStencilFromMemory(u32 dest, int size, WriteStencil flags);
|
||||
|
||||
// Tells the texture cache that a block copy moved pixels, so it can carry "this is video" from
|
||||
// the source to the destination. Cheap and safe to call for any copy.
|
||||
void NotifyVideoCopy(u32 dest, u32 src, int size);
|
||||
|
||||
virtual void ExecuteOp(u32 op, u32 diff) = 0;
|
||||
|
||||
void Execute_OffsetAddr(u32 op, u32 diff);
|
||||
|
||||
Reference in new issue
Block a user