From 36c98ab367b4a1c0bbb874dc6fd4fdc876a599d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 15 Sep 2022 09:15:02 +0200 Subject: [PATCH] Address feedback, change roles of the two dynamic clut fbos to eliminate the need for state (see next commit) --- GPU/Common/FramebufferManagerCommon.cpp | 7 +++++-- GPU/Common/TextureCacheCommon.cpp | 27 +++++++++++++------------ GPU/Common/TextureCacheCommon.h | 2 +- assets/compat.ini | 9 +++------ 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/GPU/Common/FramebufferManagerCommon.cpp b/GPU/Common/FramebufferManagerCommon.cpp index c735bad062..006452ac9c 100644 --- a/GPU/Common/FramebufferManagerCommon.cpp +++ b/GPU/Common/FramebufferManagerCommon.cpp @@ -557,11 +557,14 @@ void FramebufferManagerCommon::SetDepthFrameBuffer(bool isClearingDepth) { // Set the flag, then upload memory contents to depth channel. // Sanity check the depth buffer pointer. if (currentRenderVfb_->z_address != 0 && currentRenderVfb_->z_address != currentRenderVfb_->fb_address) { - const u16 *src = (const u16 *)Memory::GetPointerUnchecked(currentRenderVfb_->z_address); - DrawPixels(currentRenderVfb_, 0, 0, (const u8 *)src, GE_FORMAT_DEPTH16, currentRenderVfb_->z_stride, currentRenderVfb_->width, currentRenderVfb_->height, RASTER_DEPTH, "Depth Upload"); + if (Memory::IsValidRange(currentRenderVfb_->z_address, currentRenderVfb_->width * 2)) { + const u16 *src = (const u16 *)Memory::GetPointerUnchecked(currentRenderVfb_->z_address); + DrawPixels(currentRenderVfb_, 0, 0, (const u8 *)src, GE_FORMAT_DEPTH16, currentRenderVfb_->z_stride, currentRenderVfb_->width, currentRenderVfb_->height, RASTER_DEPTH, "Depth Upload"); + } } } } + // First time use of this framebuffer's depth buffer. currentRenderVfb_->usageFlags |= FB_USAGE_RENDER_DEPTH; diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 70be614c85..ec730a5a59 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -2176,7 +2176,8 @@ void TextureCacheCommon::ApplyTextureDepal(TexCacheEntry *entry) { desc.numColorAttachments = 1; desc.tag = "dynamic_clut"; dynamicClutFbo_ = draw_->CreateFramebuffer(desc); - dynamicClutReinterpreted_ = draw_->CreateFramebuffer(desc); + desc.tag = "dynamic_clut_temp"; + dynamicClutTemp_ = draw_->CreateFramebuffer(desc); } const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat(); @@ -2192,21 +2193,21 @@ void TextureCacheCommon::ApplyTextureDepal(TexCacheEntry *entry) { return; } - Draw::Framebuffer *clutFbo = dynamicClutFbo_; - // First we use a blit (with nearest interpolation, so we don't mash pixels together) // to shrink to the correct size, if we are running with scaling. // We can always blit 512 pixels even if we only need less, the cost will be negligible. - framebufferManager_->BlitUsingRaster( - src->fbo, 0.0f, 0.0f, 512.0f * src->renderScaleFactor, 1.0f, dynamicClutFbo_, 0.0f, 0.0f, 512.0f, 1.0f, false, 1.0f, framebufferManager_->Get2DPipeline(DRAW2D_COPY_COLOR), "copy_clut"); - // OK, figure out what format we want our framebuffer in, so it can be reinterpreted if needed. - if (expectedCLUTBufferFormat != src->fb_format) { + if (expectedCLUTBufferFormat == src->fb_format) { + framebufferManager_->BlitUsingRaster( + src->fbo, 0.0f, 0.0f, 512.0f * src->renderScaleFactor, 1.0f, dynamicClutFbo_, 0.0f, 0.0f, 512.0f, 1.0f, false, 1.0f, framebufferManager_->Get2DPipeline(DRAW2D_COPY_COLOR), "copy_clut"); + } else { + framebufferManager_->BlitUsingRaster( + src->fbo, 0.0f, 0.0f, 512.0f * src->renderScaleFactor, 1.0f, dynamicClutTemp_, 0.0f, 0.0f, 512.0f, 1.0f, false, 1.0f, framebufferManager_->Get2DPipeline(DRAW2D_COPY_COLOR), "copy_clut_to_temp"); + // OK, figure out what format we want our framebuffer in, so it can be reinterpreted if needed. float scaleFactorX = 1.0f; Draw2DPipeline *reinterpret = framebufferManager_->GetReinterpretPipeline(src->fb_format, expectedCLUTBufferFormat, &scaleFactorX); framebufferManager_->BlitUsingRaster( - dynamicClutFbo_, 0.0f, 0.0f, 512.0f, 1.0f, dynamicClutReinterpreted_, 0.0f, 0.0f, scaleFactorX * 512.0f, 1.0f, false, 1.0f, reinterpret, "reinterpret_clut"); - clutFbo = dynamicClutReinterpreted_; + dynamicClutTemp_, 0.0f, 0.0f, 512.0f, 1.0f, dynamicClutFbo_, 0.0f, 0.0f, scaleFactorX * 512.0f, 1.0f, false, 1.0f, reinterpret, "reinterpret_clut"); } textureShader = textureShaderCache_->GetDepalettizeShader(clutMode, GE_TFMT_CLUT8, GE_FORMAT_CLUT8, false, 0); @@ -2240,7 +2241,7 @@ void TextureCacheCommon::ApplyTextureDepal(TexCacheEntry *entry) { draw_->SetViewports(1, &vp); draw_->BindNativeTexture(0, GetNativeTextureView(entry)); - draw_->BindFramebufferAsTexture(clutFbo, 1, Draw::FB_COLOR_BIT, 0); + draw_->BindFramebufferAsTexture(dynamicClutFbo_, 1, Draw::FB_COLOR_BIT, 0); Draw::SamplerState *nearest = textureShaderCache_->GetSampler(false); Draw::SamplerState *clutSampler = textureShaderCache_->GetSampler(false); draw_->BindSamplerStates(0, 1, &nearest); @@ -2298,9 +2299,9 @@ void TextureCacheCommon::Clear(bool delete_them) { dynamicClutFbo_->Release(); dynamicClutFbo_ = nullptr; } - if (dynamicClutReinterpreted_) { - dynamicClutReinterpreted_->Release(); - dynamicClutReinterpreted_ = nullptr; + if (dynamicClutTemp_) { + dynamicClutTemp_->Release(); + dynamicClutTemp_ = nullptr; } } diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index b24c50b95c..126a497bb6 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -491,8 +491,8 @@ protected: u16 clutAlphaLinearColor_; // Facilities for GPU depal of static textures. + Draw::Framebuffer *dynamicClutTemp_ = nullptr; Draw::Framebuffer *dynamicClutFbo_ = nullptr; - Draw::Framebuffer *dynamicClutReinterpreted_ = nullptr; int standardScaleFactor_; int shaderScaleFactor_ = 0; diff --git a/assets/compat.ini b/assets/compat.ini index 7bc570faaf..f79978e9fd 100644 --- a/assets/compat.ini +++ b/assets/compat.ini @@ -1152,7 +1152,7 @@ ULES00262 = true ULUS10064 = true ULKS46087 = true -# Burnout Dominator - lens flare effect (issue )#11100) +# Burnout Dominator - lens flare effect (issue #11100) ULUS10236 = true ULES00703 = true @@ -1324,11 +1324,8 @@ NPJH50143 = true ULJM05738 = true [AllowDownloadCLUT] -# Temporary compatibility option, while developing a GPU CLUT-from-framebuffer path. - -# Burnout Dominator - lens flare effect (issue #11100) -# ULUS10236 = true -# ULES00703 = true +# Temporary compatibility option, while working on the GPU CLUT-from-framebuffer path. +# Not required for any games now that it works, but might be useful for development. [UploadDepthForCLUTTextures] # Burnout Dominator - lens flare effect (issue #11100)