Skip to content

Commit 05518c0

Browse files
committed
support max anisotropy overwrite
1 parent 2f9ef59 commit 05518c0

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -2068,7 +2068,22 @@ void MetalRenderer::BindStageResources(MTL::RenderCommandEncoder* renderCommandE
20682068
MTL::SamplerState* sampler;
20692069
if (stageSamplerIndex != LATTE_DECOMPILER_SAMPLER_NONE)
20702070
{
2071-
sampler = m_samplerCache->GetSamplerState(LatteGPUState.contextNew, shader->shaderType, stageSamplerIndex);
2071+
uint32 samplerIndex = stageSamplerIndex + LatteDecompiler_getTextureSamplerBaseIndex(shader->shaderType);
2072+
_LatteRegisterSetSampler* samplerWords = LatteGPUState.contextNew.SQ_TEX_SAMPLER + samplerIndex;
2073+
2074+
// Overwriting
2075+
2076+
// Lod bias
2077+
//if (baseTexture->overwriteInfo.hasLodBias)
2078+
// samplerWords->WORD1.set_LOD_BIAS(baseTexture->overwriteInfo.lodBias);
2079+
//else if (baseTexture->overwriteInfo.hasRelativeLodBias)
2080+
// samplerWords->WORD1.set_LOD_BIAS(samplerWords->WORD1.get_LOD_BIAS() + baseTexture->overwriteInfo.relativeLodBias);
2081+
2082+
// Max anisotropy
2083+
if (baseTexture->overwriteInfo.anisotropicLevel >= 0)
2084+
samplerWords->WORD0.set_MAX_ANISO_RATIO(baseTexture->overwriteInfo.anisotropicLevel);
2085+
2086+
sampler = m_samplerCache->GetSamplerState(LatteGPUState.contextNew, shader->shaderType, stageSamplerIndex, samplerWords);
20722087
}
20732088
else
20742089
{

src/Cafe/HW/Latte/Renderer/Metal/MetalSamplerCache.cpp

+5-21
Original file line numberDiff line numberDiff line change
@@ -86,32 +86,22 @@ MetalSamplerCache::~MetalSamplerCache()
8686
m_samplerCache.clear();
8787
}
8888

89-
MTL::SamplerState* MetalSamplerCache::GetSamplerState(const LatteContextRegister& lcr, LatteConst::ShaderType shaderType, uint32 stageSamplerIndex)
89+
MTL::SamplerState* MetalSamplerCache::GetSamplerState(const LatteContextRegister& lcr, LatteConst::ShaderType shaderType, uint32 stageSamplerIndex, const _LatteRegisterSetSampler* samplerWords)
9090
{
91-
uint32 samplerIndex = stageSamplerIndex + LatteDecompiler_getTextureSamplerBaseIndex(shaderType);
92-
93-
uint64 stateHash = CalculateSamplerHash(lcr, shaderType, stageSamplerIndex, samplerIndex);
91+
uint64 stateHash = CalculateSamplerHash(lcr, shaderType, stageSamplerIndex, samplerWords);
9492
auto& samplerState = m_samplerCache[stateHash];
9593
if (samplerState)
9694
return samplerState;
9795

9896
// Sampler state
99-
const _LatteRegisterSetSampler* samplerWords = lcr.SQ_TEX_SAMPLER + samplerIndex;
97+
10098

10199
NS_STACK_SCOPED MTL::SamplerDescriptor* samplerDescriptor = MTL::SamplerDescriptor::alloc()->init();
102100

103101
// lod
104102
uint32 iMinLOD = samplerWords->WORD1.get_MIN_LOD();
105103
uint32 iMaxLOD = samplerWords->WORD1.get_MAX_LOD();
106-
sint32 iLodBias = samplerWords->WORD1.get_LOD_BIAS();
107-
108-
// TODO: uncomment
109-
// apply relative lod bias from graphic pack
110-
//if (baseTexture->overwriteInfo.hasRelativeLodBias)
111-
// iLodBias += baseTexture->overwriteInfo.relativeLodBias;
112-
// apply absolute lod bias from graphic pack
113-
//if (baseTexture->overwriteInfo.hasLodBias)
114-
// iLodBias = baseTexture->overwriteInfo.lodBias;
104+
//sint32 iLodBias = samplerWords->WORD1.get_LOD_BIAS();
115105

116106
auto filterMip = samplerWords->WORD0.get_MIP_FILTER();
117107
if (filterMip == Latte::LATTE_SQ_TEX_SAMPLER_WORD0_0::E_Z_FILTER::NONE)
@@ -160,10 +150,6 @@ MTL::SamplerState* MetalSamplerCache::GetSamplerState(const LatteContextRegister
160150

161151
auto maxAniso = samplerWords->WORD0.get_MAX_ANISO_RATIO();
162152

163-
// TODO: uncomment
164-
//if (baseTexture->overwriteInfo.anisotropicLevel >= 0)
165-
// maxAniso = baseTexture->overwriteInfo.anisotropicLevel;
166-
167153
if (maxAniso > 0)
168154
samplerDescriptor->setMaxAnisotropy(1 << maxAniso);
169155

@@ -184,10 +170,8 @@ MTL::SamplerState* MetalSamplerCache::GetSamplerState(const LatteContextRegister
184170
return samplerState;
185171
}
186172

187-
uint64 MetalSamplerCache::CalculateSamplerHash(const LatteContextRegister& lcr, LatteConst::ShaderType shaderType, uint32 stageSamplerIndex, uint32 samplerIndex)
173+
uint64 MetalSamplerCache::CalculateSamplerHash(const LatteContextRegister& lcr, LatteConst::ShaderType shaderType, uint32 stageSamplerIndex, const _LatteRegisterSetSampler* samplerWords)
188174
{
189-
const _LatteRegisterSetSampler* samplerWords = lcr.SQ_TEX_SAMPLER + samplerIndex;
190-
191175
uint64 hash = 0;
192176
hash = std::rotl<uint64>(hash, 17);
193177
hash += (uint64)samplerWords->WORD0.getRawValue();

src/Cafe/HW/Latte/Renderer/Metal/MetalSamplerCache.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ class MetalSamplerCache
1111
MetalSamplerCache(class MetalRenderer* metalRenderer) : m_mtlr{metalRenderer} {}
1212
~MetalSamplerCache();
1313

14-
MTL::SamplerState* GetSamplerState(const LatteContextRegister& lcr, LatteConst::ShaderType shaderType, uint32 stageSamplerIndex);
14+
MTL::SamplerState* GetSamplerState(const LatteContextRegister& lcr, LatteConst::ShaderType shaderType, uint32 stageSamplerIndex, const _LatteRegisterSetSampler* samplerWords);
1515

1616
private:
1717
class MetalRenderer* m_mtlr;
1818

1919
std::map<uint64, MTL::SamplerState*> m_samplerCache;
2020

21-
uint64 CalculateSamplerHash(const LatteContextRegister& lcr, LatteConst::ShaderType shaderType, uint32 stageSamplerIndex, uint32 samplerIndex);
21+
uint64 CalculateSamplerHash(const LatteContextRegister& lcr, LatteConst::ShaderType shaderType, uint32 stageSamplerIndex, const _LatteRegisterSetSampler* samplerWords);
2222
};

0 commit comments

Comments
 (0)