diff options
Diffstat (limited to 'src/Ryujinx.Graphics.Gpu/Image/FormatTable.cs')
-rw-r--r-- | src/Ryujinx.Graphics.Gpu/Image/FormatTable.cs | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/Ryujinx.Graphics.Gpu/Image/FormatTable.cs b/src/Ryujinx.Graphics.Gpu/Image/FormatTable.cs index 1b517e63f..0af0725a2 100644 --- a/src/Ryujinx.Graphics.Gpu/Image/FormatTable.cs +++ b/src/Ryujinx.Graphics.Gpu/Image/FormatTable.cs | |||
@@ -651,9 +651,35 @@ namespace Ryujinx.Graphics.Gpu.Image | |||
651 | /// <returns>True if the format is valid, false otherwise</returns> | 651 | /// <returns>True if the format is valid, false otherwise</returns> |
652 | public static bool TryGetTextureFormat(uint encoded, bool isSrgb, out FormatInfo format) | 652 | public static bool TryGetTextureFormat(uint encoded, bool isSrgb, out FormatInfo format) |
653 | { | 653 | { |
654 | encoded |= (isSrgb ? 1u << 19 : 0u); | 654 | bool isPacked = (encoded & 0x80000000u) != 0; |
655 | if (isPacked) | ||
656 | { | ||
657 | encoded &= ~0x80000000u; | ||
658 | } | ||
655 | 659 | ||
656 | return _textureFormats.TryGetValue((TextureFormat)encoded, out format); | 660 | encoded |= isSrgb ? 1u << 19 : 0u; |
661 | |||
662 | bool found = _textureFormats.TryGetValue((TextureFormat)encoded, out format); | ||
663 | |||
664 | if (found && isPacked && !format.Format.IsDepthOrStencil()) | ||
665 | { | ||
666 | // If the packed flag is set, then the components of the pixel are tightly packed into the | ||
667 | // GPU registers on the shader. | ||
668 | // We can get the same behaviour by aliasing the texture as a format with the same amount of | ||
669 | // bytes per pixel, but only a single or the lowest possible number of components. | ||
670 | |||
671 | format = format.BytesPerPixel switch | ||
672 | { | ||
673 | 1 => new FormatInfo(Format.R8Unorm, 1, 1, 1, 1), | ||
674 | 2 => new FormatInfo(Format.R16Unorm, 1, 1, 2, 1), | ||
675 | 4 => new FormatInfo(Format.R32Float, 1, 1, 4, 1), | ||
676 | 8 => new FormatInfo(Format.R32G32Float, 1, 1, 8, 2), | ||
677 | 16 => new FormatInfo(Format.R32G32B32A32Float, 1, 1, 16, 4), | ||
678 | _ => format, | ||
679 | }; | ||
680 | } | ||
681 | |||
682 | return found; | ||
657 | } | 683 | } |
658 | 684 | ||
659 | /// <summary> | 685 | /// <summary> |