diff --git a/Common/Math/math_util.h b/Common/Math/math_util.h index 0807d47003..fd47662b54 100644 --- a/Common/Math/math_util.h +++ b/Common/Math/math_util.h @@ -28,6 +28,7 @@ inline bool isPowerOf2(int n) { return n == 1 || (n & (n - 1)) == 0; } +// Next power of 2. inline uint32_t RoundUpToPowerOf2(uint32_t v) { v--; v |= v >> 1; diff --git a/GPU/Common/DepalettizeShaderCommon.cpp b/GPU/Common/DepalettizeShaderCommon.cpp index a79744d866..1746215ada 100644 --- a/GPU/Common/DepalettizeShaderCommon.cpp +++ b/GPU/Common/DepalettizeShaderCommon.cpp @@ -112,16 +112,12 @@ void GenerateDepalShader300(ShaderWriter &writer, const DepalConfig &config) { writer.C(" int index = (a << 15) | (b << 10) | (g << 5) | (r);\n"); break; case GE_FORMAT_DEPTH16: - // Byteswap experiment, seems to be wrong. - // writer.C(" int d = int(color.x * 65535.0);\n"); - // writer.C(" d = ((d >> 8) & 0xFF) | ((d << 8) & 0xFF00);\n"); - // float(d) / 65535.0 - // Remap depth buffer. writer.C(" float depth = (color.x - z_offset) * z_scale;\n"); if (config.bufferFormat == GE_FORMAT_DEPTH16 && config.textureFormat == GE_TFMT_5650) { // Convert depth to 565, without going through a CLUT. + // TODO: Make "depal without a CLUT" a separate concept, to avoid redundantly creating a CLUT texture. writer.C(" int idepth = int(clamp(depth, 0.0, 65535.0));\n"); writer.C(" float r = float(idepth & 31) / 31.0f;\n"); writer.C(" float g = float((idepth >> 5) & 63) / 63.0f;\n"); diff --git a/GPU/Common/FramebufferManagerCommon.cpp b/GPU/Common/FramebufferManagerCommon.cpp index b48c445885..05734ef53c 100644 --- a/GPU/Common/FramebufferManagerCommon.cpp +++ b/GPU/Common/FramebufferManagerCommon.cpp @@ -579,21 +579,30 @@ void FramebufferManagerCommon::CopyToDepthFromOverlappingFramebuffers(VirtualFra } // Can't easily dynamically create these strings, we just pass along the pointer. -static const char *reinterpretStrings[3][3] = { +static const char *reinterpretStrings[4][4] = { { "self_reinterpret_565", "reinterpret_565_to_5551", "reinterpret_565_to_4444", + "reinterpret_565_to_8888", }, { "reinterpret_5551_to_565", "self_reinterpret_5551", "reinterpret_5551_to_4444", + "reinterpret_5551_to_8888", }, { "reinterpret_4444_to_565", "reinterpret_4444_to_5551", "self_reinterpret_4444", + "reinterpret_4444_to_8888", + }, + { + "reinterpret_8888_to_565", + "reinterpret_8888_to_5551", + "reinterpret_8888_to_4444", + "self_reinterpret_8888", }, }; @@ -677,6 +686,9 @@ void FramebufferManagerCommon::CopyToColorFromOverlappingFramebuffers(VirtualFra // Copy a rectangle from the original to the new buffer. // Yes, we mean to look at src->width/height for the dest rectangle. + + // TODO: Try to bound the blit using gstate_c.vertBounds like depal does. + int srcWidth = src->width * src->renderScaleFactor; int srcHeight = src->height * src->renderScaleFactor; int dstWidth = src->width * dst->renderScaleFactor; diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 3abdf512f5..e6ce09ae62 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -103,17 +103,6 @@ inline int dimHeight(u16 dim) { return 1 << ((dim >> 8) & 0xFF); } -int nextPow2(unsigned int v) { - v--; - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - v++; - return v; -} - // Vulkan color formats: // TODO TextureCacheCommon::TextureCacheCommon(Draw::DrawContext *draw, Draw2D *draw2D) @@ -1018,14 +1007,14 @@ void TextureCacheCommon::SetTextureFramebuffer(const AttachCandidate &candidate) if (framebufferManager_->UseBufferedRendering()) { // Detect when we need to apply the horizontal texture swizzle. u64 depthUpperBits = (channel == RASTER_DEPTH && framebuffer->fb_format == GE_FORMAT_8888) ? ((gstate.getTextureAddress(0) & 0x600000) >> 20) : 0; - bool needsSpecialSwizzle = depthUpperBits == 2; + bool needsDepthXSwizzle = depthUpperBits == 2; // We need to force it, since we may have set it on a texture before attaching. gstate_c.curTextureWidth = framebuffer->bufferWidth; gstate_c.curTextureHeight = framebuffer->bufferHeight; - if (needsSpecialSwizzle) { - gstate_c.curTextureWidth = nextPow2(gstate_c.curTextureWidth); + if (needsDepthXSwizzle) { + gstate_c.curTextureWidth = RoundUpToPowerOf2(gstate_c.curTextureWidth); } if (gstate_c.bgraTexture) { @@ -1957,12 +1946,12 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat(); ClutTexture clutTexture = textureShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBufRaw_); - bool needsSpecialSwizzle = depthUpperBits == 2; + bool needsDepthXSwizzle = depthUpperBits == 2; int depalWidth = framebuffer->renderWidth; int texWidth = framebuffer->width; - if (needsSpecialSwizzle) { - texWidth = nextPow2(framebuffer->width); + if (needsDepthXSwizzle) { + texWidth = RoundUpToPowerOf2(framebuffer->width); depalWidth = texWidth * framebuffer->renderScaleFactor; gstate_c.Dirty(DIRTY_UVSCALEOFFSET); }