Skip to content

Commit

Permalink
[hgiMetal] Change Metal's swizzle so single channel texture
Browse files Browse the repository at this point in the history
reads follow the UsdPreviewSurface spec of repeating the single channel
on the r, g and b channels with 1.0 in the alpha channel.

Fixes #2731

(Internal change: 2308645)
  • Loading branch information
klucknav authored and pixar-oss committed Dec 15, 2023
1 parent 5207223 commit bb81827
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions pxr/imaging/hgiMetal/texture.mm
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,15 @@
#if (defined(__MAC_10_15) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_15) \
|| __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
if (@available(macOS 10.15, ios 13.0, *)) {
size_t numChannels = HgiGetComponentCount(desc.format);

if (usage == MTLTextureUsageShaderRead && numChannels == 1) {
MTLTextureSwizzle s = HgiMetalConversions::GetComponentSwizzle(
desc.componentMapping.r);
texDesc.swizzle = MTLTextureSwizzleChannelsMake(s, s, s, s);
}
else {
texDesc.swizzle = MTLTextureSwizzleChannelsMake(
HgiMetalConversions::GetComponentSwizzle(
desc.componentMapping.r),
HgiMetalConversions::GetComponentSwizzle(
desc.componentMapping.g),
HgiMetalConversions::GetComponentSwizzle(
desc.componentMapping.b),
HgiMetalConversions::GetComponentSwizzle(
desc.componentMapping.a));
}
texDesc.swizzle = MTLTextureSwizzleChannelsMake(
HgiMetalConversions::GetComponentSwizzle(
desc.componentMapping.r),
HgiMetalConversions::GetComponentSwizzle(
desc.componentMapping.g),
HgiMetalConversions::GetComponentSwizzle(
desc.componentMapping.b),
HgiMetalConversions::GetComponentSwizzle(
desc.componentMapping.a));
}
#endif

Expand Down

0 comments on commit bb81827

Please sign in to comment.