@@ -27,43 +27,42 @@ MTL::Texture* LatteTextureViewMtl::GetSwizzledView(uint32 gpuSamplerSwizzle)
27
27
// Mask out
28
28
gpuSamplerSwizzle &= 0x0FFF0000 ;
29
29
30
+ // RGBA swizzle == no swizzle
30
31
if (gpuSamplerSwizzle == RGBA_SWIZZLE)
31
32
{
32
33
return m_baseTexture->GetTexture ();
33
34
}
34
- else
35
- {
36
- // First, try to find a view in the cache
37
35
38
- // Fast cache
39
- sint32 freeIndex = -1 ;
40
- for (sint32 i = 0 ; i < std::size (m_viewCache); i++)
36
+ // First, try to find a view in the cache
37
+
38
+ // Fast cache
39
+ sint32 freeIndex = -1 ;
40
+ for (sint32 i = 0 ; i < std::size (m_viewCache); i++)
41
+ {
42
+ if (m_viewCache[i].key == gpuSamplerSwizzle)
41
43
{
42
- if (m_viewCache[i].key == gpuSamplerSwizzle)
43
- {
44
- return m_viewCache[i].texture ;
45
- }
46
- else if (m_viewCache[i].key == INVALID_SWIZZLE && freeIndex == -1 )
47
- {
48
- freeIndex = i;
49
- }
44
+ return m_viewCache[i].texture ;
50
45
}
51
-
52
- // Fallback cache
53
- auto it = m_fallbackViewCache.find (gpuSamplerSwizzle);
54
- if (it != m_fallbackViewCache.end ())
46
+ else if (m_viewCache[i].key == INVALID_SWIZZLE && freeIndex == -1 )
55
47
{
56
- return it-> second ;
48
+ freeIndex = i ;
57
49
}
50
+ }
58
51
59
- MTL::Texture* texture = CreateSwizzledView (gpuSamplerSwizzle);
60
- if (freeIndex != -1 )
61
- m_viewCache[freeIndex] = {gpuSamplerSwizzle, texture};
62
- else
63
- it->second = texture;
64
-
65
- return texture;
52
+ // Fallback cache
53
+ auto it = m_fallbackViewCache.find (gpuSamplerSwizzle);
54
+ if (it != m_fallbackViewCache.end ())
55
+ {
56
+ return it->second ;
66
57
}
58
+
59
+ MTL::Texture* texture = CreateSwizzledView (gpuSamplerSwizzle);
60
+ if (freeIndex != -1 )
61
+ m_viewCache[freeIndex] = {gpuSamplerSwizzle, texture};
62
+ else
63
+ it->second = texture;
64
+
65
+ return texture;
67
66
}
68
67
69
68
MTL::Texture* LatteTextureViewMtl::CreateSwizzledView (uint32 gpuSamplerSwizzle)
@@ -117,10 +116,14 @@ MTL::Texture* LatteTextureViewMtl::CreateSwizzledView(uint32 gpuSamplerSwizzle)
117
116
layerCount = this ->numSlice ;
118
117
}
119
118
120
- // TODO: swizzle
119
+ MTL::TextureSwizzleChannels swizzle;
120
+ swizzle.red = GetMtlTextureSwizzle (compSelR);
121
+ swizzle.green = GetMtlTextureSwizzle (compSelG);
122
+ swizzle.blue = GetMtlTextureSwizzle (compSelB);
123
+ swizzle.alpha = GetMtlTextureSwizzle (compSelA);
121
124
122
125
auto formatInfo = GetMtlPixelFormatInfo (format, m_baseTexture->IsDepth ());
123
- MTL::Texture* texture = m_baseTexture->GetTexture ()->newTextureView (formatInfo.pixelFormat , textureType, NS::Range::Make (baseLevel, levelCount), NS::Range::Make (baseLayer, layerCount));
126
+ MTL::Texture* texture = m_baseTexture->GetTexture ()->newTextureView (formatInfo.pixelFormat , textureType, NS::Range::Make (baseLevel, levelCount), NS::Range::Make (baseLayer, layerCount), swizzle );
124
127
125
128
return texture;
126
129
}
0 commit comments