fix: cubemap sampling

This commit is contained in:
Samuliak 2024-08-13 07:30:33 +02:00
parent 0c73ff8452
commit 3f52f3acfe
3 changed files with 8 additions and 10 deletions

View File

@ -2357,11 +2357,10 @@ static void _emitTEXSampleTextureCode(LatteDecompilerShaderContext* shaderContex
{ {
debugBreakpoint(); debugBreakpoint();
} }
src->add("float4(");
src->addFmt("redcCUBEReverse({},", _getTexGPRAccess(shaderContext, texInstruction->srcGpr, LATTE_DECOMPILER_DTYPE_FLOAT, texInstruction->textureFetch.srcSel[0], texInstruction->textureFetch.srcSel[1], -1, -1, tempBuffer0)); src->addFmt("redcCUBEReverse({},", _getTexGPRAccess(shaderContext, texInstruction->srcGpr, LATTE_DECOMPILER_DTYPE_FLOAT, texInstruction->textureFetch.srcSel[0], texInstruction->textureFetch.srcSel[1], -1, -1, tempBuffer0));
_emitTEXSampleCoordInputComponent(shaderContext, texInstruction, 2, LATTE_DECOMPILER_DTYPE_SIGNED_INT); _emitTEXSampleCoordInputComponent(shaderContext, texInstruction, 2, LATTE_DECOMPILER_DTYPE_SIGNED_INT);
src->addFmt(")"); src->addFmt(")");
src->addFmt(",cubeMapArrayIndex{})", texInstruction->textureFetch.textureIndex); // cubemap index src->addFmt(", uint(cubeMapArrayIndex{})", texInstruction->textureFetch.textureIndex); // cubemap index
} }
else if (texDim == Latte::E_DIM::DIM_1D) else if (texDim == Latte::E_DIM::DIM_1D)
{ {
@ -2411,7 +2410,7 @@ static void _emitTEXSampleTextureCode(LatteDecompilerShaderContext* shaderContex
src->addFmt("redcCUBEReverse({},", _getTexGPRAccess(shaderContext, texInstruction->srcGpr, LATTE_DECOMPILER_DTYPE_FLOAT, texInstruction->textureFetch.srcSel[0], texInstruction->textureFetch.srcSel[1], -1, -1, tempBuffer0)); src->addFmt("redcCUBEReverse({},", _getTexGPRAccess(shaderContext, texInstruction->srcGpr, LATTE_DECOMPILER_DTYPE_FLOAT, texInstruction->textureFetch.srcSel[0], texInstruction->textureFetch.srcSel[1], -1, -1, tempBuffer0));
_emitTEXSampleCoordInputComponent(shaderContext, texInstruction, 2, LATTE_DECOMPILER_DTYPE_SIGNED_INT); _emitTEXSampleCoordInputComponent(shaderContext, texInstruction, 2, LATTE_DECOMPILER_DTYPE_SIGNED_INT);
src->add(")"); src->add(")");
src->addFmt(", cubeMapArrayIndex{}", texInstruction->textureFetch.textureIndex); // cubemap index src->addFmt(", uint(cubeMapArrayIndex{})", texInstruction->textureFetch.textureIndex); // cubemap index
} }
else if( texDim == Latte::E_DIM::DIM_1D ) else if( texDim == Latte::E_DIM::DIM_1D )
{ {

View File

@ -2,6 +2,7 @@
#include "Cafe/HW/Latte/Renderer/Metal/LatteTextureViewMtl.h" #include "Cafe/HW/Latte/Renderer/Metal/LatteTextureViewMtl.h"
#include "Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h" #include "Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h"
#include "Cafe/HW/Latte/Renderer/Metal/LatteToMtl.h" #include "Cafe/HW/Latte/Renderer/Metal/LatteToMtl.h"
#include "Common/precompiled.h"
LatteTextureMtl::LatteTextureMtl(class MetalRenderer* mtlRenderer, Latte::E_DIM dim, MPTR physAddress, MPTR physMipAddress, Latte::E_GX2SURFFMT format, uint32 width, uint32 height, uint32 depth, uint32 pitch, uint32 mipLevels, uint32 swizzle, LatteTextureMtl::LatteTextureMtl(class MetalRenderer* mtlRenderer, Latte::E_DIM dim, MPTR physAddress, MPTR physMipAddress, Latte::E_GX2SURFFMT format, uint32 width, uint32 height, uint32 depth, uint32 pitch, uint32 mipLevels, uint32 swizzle,
Latte::E_HWTILEMODE tileMode, bool isDepth) Latte::E_HWTILEMODE tileMode, bool isDepth)
@ -42,12 +43,8 @@ LatteTextureMtl::LatteTextureMtl(class MetalRenderer* mtlRenderer, Latte::E_DIM
textureType = MTL::TextureType3D; textureType = MTL::TextureType3D;
break; break;
case Latte::E_DIM::DIM_CUBEMAP: case Latte::E_DIM::DIM_CUBEMAP:
if (effectiveBaseDepth % 6 != 0) cemu_assert_debug(effectiveBaseDepth % 6 == 0 && "cubemaps must have an array length multiple of 6");
debug_printf("cubemaps must have an array length multiple of 6, length: %u\n", effectiveBaseDepth);
if (effectiveBaseDepth <= 6)
textureType = MTL::TextureTypeCube;
else
textureType = MTL::TextureTypeCubeArray; textureType = MTL::TextureTypeCubeArray;
break; break;
default: default:

View File

@ -91,7 +91,9 @@ MTL::Texture* LatteTextureViewMtl::CreateSwizzledView(uint32 gpuSamplerSwizzle)
textureType = MTL::TextureType3D; textureType = MTL::TextureType3D;
break; break;
case Latte::E_DIM::DIM_CUBEMAP: case Latte::E_DIM::DIM_CUBEMAP:
textureType = MTL::TextureTypeCube; // TODO: check this cemu_assert_debug(this->numSlice % 6 == 0 && "cubemaps must have an array length multiple of 6");
textureType = MTL::TextureTypeCubeArray;
break; break;
default: default:
cemu_assert_unimplemented(); cemu_assert_unimplemented();