aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Graphics.Gpu/Engine/ShaderTexture.cs
blob: bdb34180e6fbd6db5e9534521e04239f4fdcdb07 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.Gpu.Image;
using Ryujinx.Graphics.Shader;

namespace Ryujinx.Graphics.Gpu.Engine
{
    /// <summary>
    /// Shader texture properties conversion methods.
    /// </summary>
    static class ShaderTexture
    {
        /// <summary>
        /// Gets a texture target from a sampler type.
        /// </summary>
        /// <param name="type">Sampler type</param>
        /// <returns>Texture target value</returns>
        public static Target GetTarget(SamplerType type)
        {
            type &= ~SamplerType.Shadow;

            switch (type)
            {
                case SamplerType.Texture1D:
                    return Target.Texture1D;

                case SamplerType.TextureBuffer:
                    return Target.TextureBuffer;

                case SamplerType.Texture1D | SamplerType.Array:
                    return Target.Texture1DArray;

                case SamplerType.Texture2D:
                    return Target.Texture2D;

                case SamplerType.Texture2D | SamplerType.Array:
                    return Target.Texture2DArray;

                case SamplerType.Texture2D | SamplerType.Multisample:
                    return Target.Texture2DMultisample;

                case SamplerType.Texture2D | SamplerType.Multisample | SamplerType.Array:
                    return Target.Texture2DMultisampleArray;

                case SamplerType.Texture3D:
                    return Target.Texture3D;

                case SamplerType.TextureCube:
                    return Target.Cubemap;

                case SamplerType.TextureCube | SamplerType.Array:
                    return Target.CubemapArray;
            }

            Logger.Warning?.Print(LogClass.Gpu, $"Invalid sampler type \"{type}\".");

            return Target.Texture2D;
        }

        /// <summary>
        /// Gets a texture format from a shader image format.
        /// </summary>
        /// <param name="format">Shader image format</param>
        /// <returns>Texture format</returns>
        public static FormatInfo GetFormatInfo(TextureFormat format)
        {
            return format switch
            {
#pragma warning disable IDE0055 // Disable formatting
                TextureFormat.R8Unorm           => new(Format.R8Unorm, 1, 1, 1, 1),
                TextureFormat.R8Snorm           => new(Format.R8Snorm, 1, 1, 1, 1),
                TextureFormat.R8Uint            => new(Format.R8Uint, 1, 1, 1, 1),
                TextureFormat.R8Sint            => new(Format.R8Sint, 1, 1, 1, 1),
                TextureFormat.R16Float          => new(Format.R16Float, 1, 1, 2, 1),
                TextureFormat.R16Unorm          => new(Format.R16Unorm, 1, 1, 2, 1),
                TextureFormat.R16Snorm          => new(Format.R16Snorm, 1, 1, 2, 1),
                TextureFormat.R16Uint           => new(Format.R16Uint, 1, 1, 2, 1),
                TextureFormat.R16Sint           => new(Format.R16Sint, 1, 1, 2, 1),
                TextureFormat.R32Float          => new(Format.R32Float, 1, 1, 4, 1),
                TextureFormat.R32Uint           => new(Format.R32Uint, 1, 1, 4, 1),
                TextureFormat.R32Sint           => new(Format.R32Sint, 1, 1, 4, 1),
                TextureFormat.R8G8Unorm         => new(Format.R8G8Unorm, 1, 1, 2, 2),
                TextureFormat.R8G8Snorm         => new(Format.R8G8Snorm, 1, 1, 2, 2),
                TextureFormat.R8G8Uint          => new(Format.R8G8Uint, 1, 1, 2, 2),
                TextureFormat.R8G8Sint          => new(Format.R8G8Sint, 1, 1, 2, 2),
                TextureFormat.R16G16Float       => new(Format.R16G16Float, 1, 1, 4, 2),
                TextureFormat.R16G16Unorm       => new(Format.R16G16Unorm, 1, 1, 4, 2),
                TextureFormat.R16G16Snorm       => new(Format.R16G16Snorm, 1, 1, 4, 2),
                TextureFormat.R16G16Uint        => new(Format.R16G16Uint, 1, 1, 4, 2),
                TextureFormat.R16G16Sint        => new(Format.R16G16Sint, 1, 1, 4, 2),
                TextureFormat.R32G32Float       => new(Format.R32G32Float, 1, 1, 8, 2),
                TextureFormat.R32G32Uint        => new(Format.R32G32Uint, 1, 1, 8, 2),
                TextureFormat.R32G32Sint        => new(Format.R32G32Sint, 1, 1, 8, 2),
                TextureFormat.R8G8B8A8Unorm     => new(Format.R8G8B8A8Unorm, 1, 1, 4, 4),
                TextureFormat.R8G8B8A8Snorm     => new(Format.R8G8B8A8Snorm, 1, 1, 4, 4),
                TextureFormat.R8G8B8A8Uint      => new(Format.R8G8B8A8Uint, 1, 1, 4, 4),
                TextureFormat.R8G8B8A8Sint      => new(Format.R8G8B8A8Sint, 1, 1, 4, 4),
                TextureFormat.R16G16B16A16Float => new(Format.R16G16B16A16Float, 1, 1, 8, 4),
                TextureFormat.R16G16B16A16Unorm => new(Format.R16G16B16A16Unorm, 1, 1, 8, 4),
                TextureFormat.R16G16B16A16Snorm => new(Format.R16G16B16A16Snorm, 1, 1, 8, 4),
                TextureFormat.R16G16B16A16Uint  => new(Format.R16G16B16A16Uint, 1, 1, 8, 4),
                TextureFormat.R16G16B16A16Sint  => new(Format.R16G16B16A16Sint, 1, 1, 8, 4),
                TextureFormat.R32G32B32A32Float => new(Format.R32G32B32A32Float, 1, 1, 16, 4),
                TextureFormat.R32G32B32A32Uint  => new(Format.R32G32B32A32Uint, 1, 1, 16, 4),
                TextureFormat.R32G32B32A32Sint  => new(Format.R32G32B32A32Sint, 1, 1, 16, 4),
                TextureFormat.R10G10B10A2Unorm  => new(Format.R10G10B10A2Unorm, 1, 1, 4, 4),
                TextureFormat.R10G10B10A2Uint   => new(Format.R10G10B10A2Uint, 1, 1, 4, 4),
                TextureFormat.R11G11B10Float    => new(Format.R11G11B10Float, 1, 1, 4, 3),
                _                               => FormatInfo.Invalid,
#pragma warning restore IDE0055
            };
        }
    }
}