aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Gpu/Image/TextureDescriptor.cs
blob: 79e4f55eafad5f96bb59d5f8947ff0fa5c4abeda (plain)
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
115
116
117
118
119
namespace Ryujinx.Graphics.Gpu.Image
{
    struct TextureDescriptor
    {
        public uint Word0;
        public uint Word1;
        public uint Word2;
        public uint Word3;
        public uint Word4;
        public uint Word5;
        public uint Word6;
        public uint Word7;

        public uint UnpackFormat()
        {
            return Word0 & 0x8007ffff;
        }

        public TextureComponent UnpackSwizzleR()
        {
            return(TextureComponent)((Word0 >> 19) & 7);
        }

        public TextureComponent UnpackSwizzleG()
        {
            return(TextureComponent)((Word0 >> 22) & 7);
        }

        public TextureComponent UnpackSwizzleB()
        {
            return(TextureComponent)((Word0 >> 25) & 7);
        }

        public TextureComponent UnpackSwizzleA()
        {
            return(TextureComponent)((Word0 >> 28) & 7);
        }

        public ulong UnpackAddress()
        {
            return Word1 | ((ulong)(Word2 & 0xffff) << 32);
        }

        public TextureDescriptorType UnpackTextureDescriptorType()
        {
            return (TextureDescriptorType)((Word2 >> 21) & 7);
        }

        public int UnpackStride()
        {
            return (int)(Word3 & 0xffff) << 5;
        }

        public int UnpackGobBlocksInX()
        {
            return 1 << (int)(Word3 & 7);
        }

        public int UnpackGobBlocksInY()
        {
            return 1 << (int)((Word3 >> 3) & 7);
        }

        public int UnpackGobBlocksInZ()
        {
            return 1 << (int)((Word3 >> 6) & 7);
        }

        public int UnpackGobBlocksInTileX()
        {
            return 1 << (int)((Word3 >> 10) & 7);
        }

        public int UnpackLevels()
        {
            return (int)(Word3 >> 28) + 1;
        }

        public int UnpackWidth()
        {
            return (int)(Word4 & 0xffff) + 1;
        }

        public bool UnpackSrgb()
        {
            return (Word4 & (1 << 22)) != 0;
        }

        public TextureTarget UnpackTextureTarget()
        {
            return (TextureTarget)((Word4 >> 23) & 0xf);
        }

        public int UnpackHeight()
        {
            return (int)(Word5 & 0xffff) + 1;
        }

        public int UnpackDepth()
        {
            return (int)((Word5 >> 16) & 0x3fff) + 1;
        }

        public int UnpackBaseLevel()
        {
            return (int)(Word7 & 0xf);
        }

        public int UnpackMaxLevelInclusive()
        {
            return (int)((Word7 >> 4) & 0xf);
        }

        public TextureMsaaMode UnpackTextureMsaaMode()
        {
            return (TextureMsaaMode)((Word7 >> 8) & 0xf);
        }
    }
}