fix: texture swizzle

This commit is contained in:
Samuliak 2024-08-06 13:42:06 +02:00
parent 0a7f30c6a4
commit 5fc45407db
3 changed files with 35 additions and 32 deletions

View File

@ -2334,7 +2334,7 @@ static void _emitTEXSampleTextureCode(LatteDecompilerShaderContext* shaderContex
// shadow sampler // shadow sampler
if (texDim == Latte::E_DIM::DIM_2D_ARRAY) if (texDim == Latte::E_DIM::DIM_2D_ARRAY)
{ {
// 3 coords + compare value (as float4) // 3 coords + compare value
src->add("float3("); src->add("float3(");
_emitTEXSampleCoordInputComponent(shaderContext, texInstruction, 0, LATTE_DECOMPILER_DTYPE_FLOAT); _emitTEXSampleCoordInputComponent(shaderContext, texInstruction, 0, LATTE_DECOMPILER_DTYPE_FLOAT);
src->add(", "); src->add(", ");
@ -2442,7 +2442,8 @@ static void _emitTEXSampleTextureCode(LatteDecompilerShaderContext* shaderContex
} }
else if( texOpcode == GPU7_TEX_INST_SAMPLE_LZ || texOpcode == GPU7_TEX_INST_SAMPLE_C_LZ ) else if( texOpcode == GPU7_TEX_INST_SAMPLE_LZ || texOpcode == GPU7_TEX_INST_SAMPLE_C_LZ )
{ {
src->add(",0.0"); // TODO: correct?
src->add(", level(0.0)");
} }
} }
// gradient parameters // gradient parameters

View File

@ -27,12 +27,12 @@ MTL::Texture* LatteTextureViewMtl::GetSwizzledView(uint32 gpuSamplerSwizzle)
// Mask out // Mask out
gpuSamplerSwizzle &= 0x0FFF0000; gpuSamplerSwizzle &= 0x0FFF0000;
// RGBA swizzle == no swizzle
if (gpuSamplerSwizzle == RGBA_SWIZZLE) if (gpuSamplerSwizzle == RGBA_SWIZZLE)
{ {
return m_baseTexture->GetTexture(); return m_baseTexture->GetTexture();
} }
else
{
// First, try to find a view in the cache // First, try to find a view in the cache
// Fast cache // Fast cache
@ -63,7 +63,6 @@ MTL::Texture* LatteTextureViewMtl::GetSwizzledView(uint32 gpuSamplerSwizzle)
it->second = texture; it->second = texture;
return texture; return texture;
}
} }
MTL::Texture* LatteTextureViewMtl::CreateSwizzledView(uint32 gpuSamplerSwizzle) MTL::Texture* LatteTextureViewMtl::CreateSwizzledView(uint32 gpuSamplerSwizzle)
@ -117,10 +116,14 @@ MTL::Texture* LatteTextureViewMtl::CreateSwizzledView(uint32 gpuSamplerSwizzle)
layerCount = this->numSlice; layerCount = this->numSlice;
} }
// TODO: swizzle MTL::TextureSwizzleChannels swizzle;
swizzle.red = GetMtlTextureSwizzle(compSelR);
swizzle.green = GetMtlTextureSwizzle(compSelG);
swizzle.blue = GetMtlTextureSwizzle(compSelB);
swizzle.alpha = GetMtlTextureSwizzle(compSelA);
auto formatInfo = GetMtlPixelFormatInfo(format, m_baseTexture->IsDepth()); auto formatInfo = GetMtlPixelFormatInfo(format, m_baseTexture->IsDepth());
MTL::Texture* texture = m_baseTexture->GetTexture()->newTextureView(formatInfo.pixelFormat, textureType, NS::Range::Make(baseLevel, levelCount), NS::Range::Make(baseLayer, layerCount)); MTL::Texture* texture = m_baseTexture->GetTexture()->newTextureView(formatInfo.pixelFormat, textureType, NS::Range::Make(baseLevel, levelCount), NS::Range::Make(baseLayer, layerCount), swizzle);
return texture; return texture;
} }

View File

@ -8,7 +8,6 @@
#define RGBA_SWIZZLE 0x06880000 #define RGBA_SWIZZLE 0x06880000
#define INVALID_SWIZZLE 0xFFFFFFFF #define INVALID_SWIZZLE 0xFFFFFFFF
// TODO: test the swizzle
class LatteTextureViewMtl : public LatteTextureView class LatteTextureViewMtl : public LatteTextureView
{ {
public: public: