diff options
| author | TSR Berry <20988865+TSRBerry@users.noreply.github.com> | 2023-04-08 01:22:00 +0200 |
|---|---|---|
| committer | Mary <thog@protonmail.com> | 2023-04-27 23:51:14 +0200 |
| commit | cee712105850ac3385cd0091a923438167433f9f (patch) | |
| tree | 4a5274b21d8b7f938c0d0ce18736d3f2993b11b1 /src/Ryujinx.Graphics.Vulkan/FormatConverter.cs | |
| parent | cd124bda587ef09668a971fa1cac1c3f0cfc9f21 (diff) | |
Move solution and projects to src
Diffstat (limited to 'src/Ryujinx.Graphics.Vulkan/FormatConverter.cs')
| -rw-r--r-- | src/Ryujinx.Graphics.Vulkan/FormatConverter.cs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/Ryujinx.Graphics.Vulkan/FormatConverter.cs b/src/Ryujinx.Graphics.Vulkan/FormatConverter.cs new file mode 100644 index 00000000..33472ae4 --- /dev/null +++ b/src/Ryujinx.Graphics.Vulkan/FormatConverter.cs @@ -0,0 +1,49 @@ +using System; +using System.Runtime.InteropServices; + +namespace Ryujinx.Graphics.Vulkan +{ + class FormatConverter + { + public static void ConvertD24S8ToD32FS8(Span<byte> output, ReadOnlySpan<byte> input) + { + const float UnormToFloat = 1f / 0xffffff; + + Span<uint> outputUint = MemoryMarshal.Cast<byte, uint>(output); + ReadOnlySpan<uint> inputUint = MemoryMarshal.Cast<byte, uint>(input); + + int i = 0; + + for (; i < inputUint.Length; i++) + { + uint depthStencil = inputUint[i]; + uint depth = depthStencil >> 8; + uint stencil = depthStencil & 0xff; + + int j = i * 2; + + outputUint[j] = (uint)BitConverter.SingleToInt32Bits(depth * UnormToFloat); + outputUint[j + 1] = stencil; + } + } + + public static void ConvertD32FS8ToD24S8(Span<byte> output, ReadOnlySpan<byte> input) + { + Span<uint> outputUint = MemoryMarshal.Cast<byte, uint>(output); + ReadOnlySpan<uint> inputUint = MemoryMarshal.Cast<byte, uint>(input); + + int i = 0; + + for (; i < inputUint.Length; i += 2) + { + float depth = BitConverter.Int32BitsToSingle((int)inputUint[i]); + uint stencil = inputUint[i + 1]; + uint depthStencil = (Math.Clamp((uint)(depth * 0xffffff), 0, 0xffffff) << 8) | (stencil & 0xff); + + int j = i >> 1; + + outputUint[j] = depthStencil; + } + } + } +} |
