mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-06 06:51:18 +12:00
support max anisotropy overwrite
This commit is contained in:
parent
2f9ef596d2
commit
05518c01fb
3 changed files with 23 additions and 24 deletions
|
@ -2068,7 +2068,22 @@ void MetalRenderer::BindStageResources(MTL::RenderCommandEncoder* renderCommandE
|
||||||
MTL::SamplerState* sampler;
|
MTL::SamplerState* sampler;
|
||||||
if (stageSamplerIndex != LATTE_DECOMPILER_SAMPLER_NONE)
|
if (stageSamplerIndex != LATTE_DECOMPILER_SAMPLER_NONE)
|
||||||
{
|
{
|
||||||
sampler = m_samplerCache->GetSamplerState(LatteGPUState.contextNew, shader->shaderType, stageSamplerIndex);
|
uint32 samplerIndex = stageSamplerIndex + LatteDecompiler_getTextureSamplerBaseIndex(shader->shaderType);
|
||||||
|
_LatteRegisterSetSampler* samplerWords = LatteGPUState.contextNew.SQ_TEX_SAMPLER + samplerIndex;
|
||||||
|
|
||||||
|
// Overwriting
|
||||||
|
|
||||||
|
// Lod bias
|
||||||
|
//if (baseTexture->overwriteInfo.hasLodBias)
|
||||||
|
// samplerWords->WORD1.set_LOD_BIAS(baseTexture->overwriteInfo.lodBias);
|
||||||
|
//else if (baseTexture->overwriteInfo.hasRelativeLodBias)
|
||||||
|
// samplerWords->WORD1.set_LOD_BIAS(samplerWords->WORD1.get_LOD_BIAS() + baseTexture->overwriteInfo.relativeLodBias);
|
||||||
|
|
||||||
|
// Max anisotropy
|
||||||
|
if (baseTexture->overwriteInfo.anisotropicLevel >= 0)
|
||||||
|
samplerWords->WORD0.set_MAX_ANISO_RATIO(baseTexture->overwriteInfo.anisotropicLevel);
|
||||||
|
|
||||||
|
sampler = m_samplerCache->GetSamplerState(LatteGPUState.contextNew, shader->shaderType, stageSamplerIndex, samplerWords);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -86,32 +86,22 @@ MetalSamplerCache::~MetalSamplerCache()
|
||||||
m_samplerCache.clear();
|
m_samplerCache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
MTL::SamplerState* MetalSamplerCache::GetSamplerState(const LatteContextRegister& lcr, LatteConst::ShaderType shaderType, uint32 stageSamplerIndex)
|
MTL::SamplerState* MetalSamplerCache::GetSamplerState(const LatteContextRegister& lcr, LatteConst::ShaderType shaderType, uint32 stageSamplerIndex, const _LatteRegisterSetSampler* samplerWords)
|
||||||
{
|
{
|
||||||
uint32 samplerIndex = stageSamplerIndex + LatteDecompiler_getTextureSamplerBaseIndex(shaderType);
|
uint64 stateHash = CalculateSamplerHash(lcr, shaderType, stageSamplerIndex, samplerWords);
|
||||||
|
|
||||||
uint64 stateHash = CalculateSamplerHash(lcr, shaderType, stageSamplerIndex, samplerIndex);
|
|
||||||
auto& samplerState = m_samplerCache[stateHash];
|
auto& samplerState = m_samplerCache[stateHash];
|
||||||
if (samplerState)
|
if (samplerState)
|
||||||
return samplerState;
|
return samplerState;
|
||||||
|
|
||||||
// Sampler state
|
// Sampler state
|
||||||
const _LatteRegisterSetSampler* samplerWords = lcr.SQ_TEX_SAMPLER + samplerIndex;
|
|
||||||
|
|
||||||
NS_STACK_SCOPED MTL::SamplerDescriptor* samplerDescriptor = MTL::SamplerDescriptor::alloc()->init();
|
NS_STACK_SCOPED MTL::SamplerDescriptor* samplerDescriptor = MTL::SamplerDescriptor::alloc()->init();
|
||||||
|
|
||||||
// lod
|
// lod
|
||||||
uint32 iMinLOD = samplerWords->WORD1.get_MIN_LOD();
|
uint32 iMinLOD = samplerWords->WORD1.get_MIN_LOD();
|
||||||
uint32 iMaxLOD = samplerWords->WORD1.get_MAX_LOD();
|
uint32 iMaxLOD = samplerWords->WORD1.get_MAX_LOD();
|
||||||
sint32 iLodBias = samplerWords->WORD1.get_LOD_BIAS();
|
//sint32 iLodBias = samplerWords->WORD1.get_LOD_BIAS();
|
||||||
|
|
||||||
// TODO: uncomment
|
|
||||||
// apply relative lod bias from graphic pack
|
|
||||||
//if (baseTexture->overwriteInfo.hasRelativeLodBias)
|
|
||||||
// iLodBias += baseTexture->overwriteInfo.relativeLodBias;
|
|
||||||
// apply absolute lod bias from graphic pack
|
|
||||||
//if (baseTexture->overwriteInfo.hasLodBias)
|
|
||||||
// iLodBias = baseTexture->overwriteInfo.lodBias;
|
|
||||||
|
|
||||||
auto filterMip = samplerWords->WORD0.get_MIP_FILTER();
|
auto filterMip = samplerWords->WORD0.get_MIP_FILTER();
|
||||||
if (filterMip == Latte::LATTE_SQ_TEX_SAMPLER_WORD0_0::E_Z_FILTER::NONE)
|
if (filterMip == Latte::LATTE_SQ_TEX_SAMPLER_WORD0_0::E_Z_FILTER::NONE)
|
||||||
|
@ -160,10 +150,6 @@ MTL::SamplerState* MetalSamplerCache::GetSamplerState(const LatteContextRegister
|
||||||
|
|
||||||
auto maxAniso = samplerWords->WORD0.get_MAX_ANISO_RATIO();
|
auto maxAniso = samplerWords->WORD0.get_MAX_ANISO_RATIO();
|
||||||
|
|
||||||
// TODO: uncomment
|
|
||||||
//if (baseTexture->overwriteInfo.anisotropicLevel >= 0)
|
|
||||||
// maxAniso = baseTexture->overwriteInfo.anisotropicLevel;
|
|
||||||
|
|
||||||
if (maxAniso > 0)
|
if (maxAniso > 0)
|
||||||
samplerDescriptor->setMaxAnisotropy(1 << maxAniso);
|
samplerDescriptor->setMaxAnisotropy(1 << maxAniso);
|
||||||
|
|
||||||
|
@ -184,10 +170,8 @@ MTL::SamplerState* MetalSamplerCache::GetSamplerState(const LatteContextRegister
|
||||||
return samplerState;
|
return samplerState;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 MetalSamplerCache::CalculateSamplerHash(const LatteContextRegister& lcr, LatteConst::ShaderType shaderType, uint32 stageSamplerIndex, uint32 samplerIndex)
|
uint64 MetalSamplerCache::CalculateSamplerHash(const LatteContextRegister& lcr, LatteConst::ShaderType shaderType, uint32 stageSamplerIndex, const _LatteRegisterSetSampler* samplerWords)
|
||||||
{
|
{
|
||||||
const _LatteRegisterSetSampler* samplerWords = lcr.SQ_TEX_SAMPLER + samplerIndex;
|
|
||||||
|
|
||||||
uint64 hash = 0;
|
uint64 hash = 0;
|
||||||
hash = std::rotl<uint64>(hash, 17);
|
hash = std::rotl<uint64>(hash, 17);
|
||||||
hash += (uint64)samplerWords->WORD0.getRawValue();
|
hash += (uint64)samplerWords->WORD0.getRawValue();
|
||||||
|
|
|
@ -11,12 +11,12 @@ public:
|
||||||
MetalSamplerCache(class MetalRenderer* metalRenderer) : m_mtlr{metalRenderer} {}
|
MetalSamplerCache(class MetalRenderer* metalRenderer) : m_mtlr{metalRenderer} {}
|
||||||
~MetalSamplerCache();
|
~MetalSamplerCache();
|
||||||
|
|
||||||
MTL::SamplerState* GetSamplerState(const LatteContextRegister& lcr, LatteConst::ShaderType shaderType, uint32 stageSamplerIndex);
|
MTL::SamplerState* GetSamplerState(const LatteContextRegister& lcr, LatteConst::ShaderType shaderType, uint32 stageSamplerIndex, const _LatteRegisterSetSampler* samplerWords);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class MetalRenderer* m_mtlr;
|
class MetalRenderer* m_mtlr;
|
||||||
|
|
||||||
std::map<uint64, MTL::SamplerState*> m_samplerCache;
|
std::map<uint64, MTL::SamplerState*> m_samplerCache;
|
||||||
|
|
||||||
uint64 CalculateSamplerHash(const LatteContextRegister& lcr, LatteConst::ShaderType shaderType, uint32 stageSamplerIndex, uint32 samplerIndex);
|
uint64 CalculateSamplerHash(const LatteContextRegister& lcr, LatteConst::ShaderType shaderType, uint32 stageSamplerIndex, const _LatteRegisterSetSampler* samplerWords);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue