From 6cbb385b89334059c16d37647f49beb75778feb3 Mon Sep 17 00:00:00 2001 From: Anthony Date: Wed, 22 Jun 2022 23:57:22 +1200 Subject: [PATCH] Fix mipmapped cubemaps which had broken faces (other than the first face) because the slice pitch calculation did not account for mipmaps. We are iterating the mipmaps already, so just calculate the slice pitch directly rather than trying to generalize CxbxGetPixelContainerMeasures --- src/core/hle/D3D8/Direct3D9/Direct3D9.cpp | 8 +++++++- src/core/hle/D3D8/XbConvert.cpp | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp index 0315f3579..38ce76540 100644 --- a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp +++ b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp @@ -5848,6 +5848,7 @@ void CreateHostResource(xbox::X_D3DResource *pResource, DWORD D3DUsage, int iTex blockSize = X_Format == xbox::X_D3DFMT_DXT1 ? 8 : 16; } + DWORD actualSlicePitch = dwSlicePitch; for (int face = D3DCUBEMAP_FACE_POSITIVE_X; face <= last_face; face++) { // As we iterate through mipmap levels, we'll adjust the source resource offset DWORD dwMipOffset = 0; @@ -5924,6 +5925,11 @@ void CreateHostResource(xbox::X_D3DResource *pResource, DWORD D3DUsage, int iTex uint8_t *pSrc = (uint8_t *)VirtualAddr + dwCubeFaceOffset + dwMipOffset; + // If this is the final mip of the first cube face, set the cube face size + if (face == D3DCUBEMAP_FACE_POSITIVE_X && mipmap_level >= dwMipMapLevels - 1) { + actualSlicePitch = ROUND_UP(((UINT)pSrc + mipSlicePitch) - (UINT)VirtualAddr, X_D3DTEXTURE_CUBEFACE_ALIGNMENT); + } + // Copy texture data to the host resource if (bConvertToARGB) { EmuLog(LOG_LEVEL::DEBUG, "Unsupported texture format, expanding to D3DFMT_A8R8G8B8"); @@ -6023,7 +6029,7 @@ void CreateHostResource(xbox::X_D3DResource *pResource, DWORD D3DUsage, int iTex } } // for mipmap levels - dwCubeFaceOffset += dwSlicePitch; + dwCubeFaceOffset += actualSlicePitch; } // for cube faces diff --git a/src/core/hle/D3D8/XbConvert.cpp b/src/core/hle/D3D8/XbConvert.cpp index ac6db58c3..6b79914a7 100644 --- a/src/core/hle/D3D8/XbConvert.cpp +++ b/src/core/hle/D3D8/XbConvert.cpp @@ -1614,6 +1614,7 @@ void CxbxGetPixelContainerMeasures UINT* pHeight, UINT* pDepth, UINT* pRowPitch, + // Slice pitch (does not include mipmaps!) UINT* pSlicePitch ) {