diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2022-01-22 15:23:00 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-22 19:23:00 +0100 |
| commit | 42c75dbb8f9472f434d0324a37a87e91ee7b50f3 (patch) | |
| tree | bae433fed0b2807893d520c1b1b49e33588ea303 /Ryujinx.Graphics.Gpu | |
| parent | 8117f6a9790e129ffd4513f23f6f5be6c6864269 (diff) | |
Add support for BC1/2/3 decompression (for 3D textures) (#2987)
* Add support for BC1/2/3 decompression (for 3D textures)
* Optimize and clean up
* Unsafe not needed here
* Fix alpha value interpolation when a0 <= a1
Diffstat (limited to 'Ryujinx.Graphics.Gpu')
| -rw-r--r-- | Ryujinx.Graphics.Gpu/GpuContext.cs | 19 | ||||
| -rw-r--r-- | Ryujinx.Graphics.Gpu/Image/Texture.cs | 30 | ||||
| -rw-r--r-- | Ryujinx.Graphics.Gpu/Image/TextureCompatibility.cs | 18 |
3 files changed, 49 insertions, 18 deletions
diff --git a/Ryujinx.Graphics.Gpu/GpuContext.cs b/Ryujinx.Graphics.Gpu/GpuContext.cs index 5c9af383..ddc95b2c 100644 --- a/Ryujinx.Graphics.Gpu/GpuContext.cs +++ b/Ryujinx.Graphics.Gpu/GpuContext.cs @@ -78,14 +78,27 @@ namespace Ryujinx.Graphics.Gpu /// <summary> /// Host hardware capabilities. /// </summary> - internal Capabilities Capabilities => _caps.Value; + internal ref Capabilities Capabilities + { + get + { + if (!_capsLoaded) + { + _caps = Renderer.GetCapabilities(); + _capsLoaded = true; + } + + return ref _caps; + } + } /// <summary> /// Event for signalling shader cache loading progress. /// </summary> public event Action<ShaderCacheState, int, int> ShaderCacheStateChanged; - private readonly Lazy<Capabilities> _caps; + private bool _capsLoaded; + private Capabilities _caps; private Thread _gpuThread; /// <summary> @@ -110,8 +123,6 @@ namespace Ryujinx.Graphics.Gpu DeferredActions = new Queue<Action>(); PhysicalMemoryRegistry = new ConcurrentDictionary<long, PhysicalMemory>(); - - _caps = new Lazy<Capabilities>(Renderer.GetCapabilities); } /// <summary> diff --git a/Ryujinx.Graphics.Gpu/Image/Texture.cs b/Ryujinx.Graphics.Gpu/Image/Texture.cs index b2fa15a2..e1f00606 100644 --- a/Ryujinx.Graphics.Gpu/Image/Texture.cs +++ b/Ryujinx.Graphics.Gpu/Image/Texture.cs @@ -834,13 +834,31 @@ namespace Ryujinx.Graphics.Gpu.Image { data = PixelConverter.ConvertR4G4ToR4G4B4A4(data); } - else if (Target == Target.Texture3D && Format.IsBc4()) + else if (!_context.Capabilities.Supports3DTextureCompression && Target == Target.Texture3D) { - data = BCnDecoder.DecodeBC4(data, width, height, depth, levels, layers, Info.FormatInfo.Format == Format.Bc4Snorm); - } - else if (Target == Target.Texture3D && Format.IsBc5()) - { - data = BCnDecoder.DecodeBC5(data, width, height, depth, levels, layers, Info.FormatInfo.Format == Format.Bc5Snorm); + switch (Format) + { + case Format.Bc1RgbaSrgb: + case Format.Bc1RgbaUnorm: + data = BCnDecoder.DecodeBC1(data, width, height, depth, levels, layers); + break; + case Format.Bc2Srgb: + case Format.Bc2Unorm: + data = BCnDecoder.DecodeBC2(data, width, height, depth, levels, layers); + break; + case Format.Bc3Srgb: + case Format.Bc3Unorm: + data = BCnDecoder.DecodeBC3(data, width, height, depth, levels, layers); + break; + case Format.Bc4Snorm: + case Format.Bc4Unorm: + data = BCnDecoder.DecodeBC4(data, width, height, depth, levels, layers, Format == Format.Bc4Snorm); + break; + case Format.Bc5Snorm: + case Format.Bc5Unorm: + data = BCnDecoder.DecodeBC5(data, width, height, depth, levels, layers, Format == Format.Bc5Snorm); + break; + } } return data; diff --git a/Ryujinx.Graphics.Gpu/Image/TextureCompatibility.cs b/Ryujinx.Graphics.Gpu/Image/TextureCompatibility.cs index 0461a81f..188e1e09 100644 --- a/Ryujinx.Graphics.Gpu/Image/TextureCompatibility.cs +++ b/Ryujinx.Graphics.Gpu/Image/TextureCompatibility.cs @@ -14,9 +14,6 @@ namespace Ryujinx.Graphics.Gpu.Image private enum FormatClass { Unclassified, - BCn64, - BCn128, - Bc1Rgb, Bc1Rgba, Bc2, Bc3, @@ -88,13 +85,21 @@ namespace Ryujinx.Graphics.Gpu.Image return new FormatInfo(Format.R4G4B4A4Unorm, 1, 1, 2, 4); } - if (info.Target == Target.Texture3D) + if (!caps.Supports3DTextureCompression && info.Target == Target.Texture3D) { - // The host API does not support 3D BC4/BC5 compressed formats. + // The host API does not support 3D compressed formats. // We assume software decompression will be done for those textures, // and so we adjust the format here to match the decompressor output. switch (info.FormatInfo.Format) { + case Format.Bc1RgbaSrgb: + case Format.Bc2Srgb: + case Format.Bc3Srgb: + return new FormatInfo(Format.R8G8B8A8Srgb, 1, 1, 4, 4); + case Format.Bc1RgbaUnorm: + case Format.Bc2Unorm: + case Format.Bc3Unorm: + return new FormatInfo(Format.R8G8B8A8Unorm, 1, 1, 4, 4); case Format.Bc4Unorm: return new FormatInfo(Format.R8Unorm, 1, 1, 1, 1); case Format.Bc4Snorm: @@ -749,9 +754,6 @@ namespace Ryujinx.Graphics.Gpu.Image { switch (format) { - case Format.Bc1RgbSrgb: - case Format.Bc1RgbUnorm: - return FormatClass.Bc1Rgb; case Format.Bc1RgbaSrgb: case Format.Bc1RgbaUnorm: return FormatClass.Bc1Rgba; |
