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
if (texDim == Latte::E_DIM::DIM_2D_ARRAY)
{
// 3 coords + compare value (as float4)
// 3 coords + compare value
src->add("float3(");
_emitTEXSampleCoordInputComponent(shaderContext, texInstruction, 0, LATTE_DECOMPILER_DTYPE_FLOAT);
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 )
{
src->add(",0.0");
// TODO: correct?
src->add(", level(0.0)");
}
}
// gradient parameters

View File

@ -27,43 +27,42 @@ MTL::Texture* LatteTextureViewMtl::GetSwizzledView(uint32 gpuSamplerSwizzle)
// Mask out
gpuSamplerSwizzle &= 0x0FFF0000;
// RGBA swizzle == no swizzle
if (gpuSamplerSwizzle == RGBA_SWIZZLE)
{
return m_baseTexture->GetTexture();
}
else
// First, try to find a view in the cache
// Fast cache
sint32 freeIndex = -1;
for (sint32 i = 0; i < std::size(m_viewCache); i++)
{
// First, try to find a view in the cache
// Fast cache
sint32 freeIndex = -1;
for (sint32 i = 0; i < std::size(m_viewCache); i++)
if (m_viewCache[i].key == gpuSamplerSwizzle)
{
if (m_viewCache[i].key == gpuSamplerSwizzle)
{
return m_viewCache[i].texture;
}
else if (m_viewCache[i].key == INVALID_SWIZZLE && freeIndex == -1)
{
freeIndex = i;
}
return m_viewCache[i].texture;
}
// Fallback cache
auto it = m_fallbackViewCache.find(gpuSamplerSwizzle);
if (it != m_fallbackViewCache.end())
else if (m_viewCache[i].key == INVALID_SWIZZLE && freeIndex == -1)
{
return it->second;
freeIndex = i;
}
MTL::Texture* texture = CreateSwizzledView(gpuSamplerSwizzle);
if (freeIndex != -1)
m_viewCache[freeIndex] = {gpuSamplerSwizzle, texture};
else
it->second = texture;
return texture;
}
// Fallback cache
auto it = m_fallbackViewCache.find(gpuSamplerSwizzle);
if (it != m_fallbackViewCache.end())
{
return it->second;
}
MTL::Texture* texture = CreateSwizzledView(gpuSamplerSwizzle);
if (freeIndex != -1)
m_viewCache[freeIndex] = {gpuSamplerSwizzle, texture};
else
it->second = texture;
return texture;
}
MTL::Texture* LatteTextureViewMtl::CreateSwizzledView(uint32 gpuSamplerSwizzle)
@ -117,10 +116,14 @@ MTL::Texture* LatteTextureViewMtl::CreateSwizzledView(uint32 gpuSamplerSwizzle)
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());
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;
}

View File

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