aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs
blob: 78dcde490c9596ee9e92dcfb054ca36c74726d74 (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
using System;

namespace Ryujinx.Graphics.Shader.Translation
{
    struct ShaderConfig
    {
        public ShaderStage Stage { get; }

        public OutputTopology OutputTopology { get; }

        public int MaxOutputVertices { get; }

        public OutputMapTarget[] OmapTargets    { get; }
        public bool              OmapSampleMask { get; }
        public bool              OmapDepth      { get; }

        public TranslationFlags Flags { get; }

        private QueryInfoCallback _queryInfoCallback;

        public ShaderConfig(TranslationFlags flags, QueryInfoCallback queryInfoCallback)
        {
            Stage              = ShaderStage.Compute;
            OutputTopology     = OutputTopology.PointList;
            MaxOutputVertices  = 0;
            OmapTargets        = null;
            OmapSampleMask     = false;
            OmapDepth          = false;
            Flags              = flags;
            _queryInfoCallback = queryInfoCallback;
        }

        public ShaderConfig(ShaderHeader header, TranslationFlags flags, QueryInfoCallback queryInfoCallback)
        {
            Stage              = header.Stage;
            OutputTopology     = header.OutputTopology;
            MaxOutputVertices  = header.MaxOutputVertexCount;
            OmapTargets        = header.OmapTargets;
            OmapSampleMask     = header.OmapSampleMask;
            OmapDepth          = header.OmapDepth;
            Flags              = flags;
            _queryInfoCallback = queryInfoCallback;
        }

        public int GetDepthRegister()
        {
            int count = 0;

            for (int index = 0; index < OmapTargets.Length; index++)
            {
                for (int component = 0; component < 4; component++)
                {
                    if (OmapTargets[index].ComponentEnabled(component))
                    {
                        count++;
                    }
                }
            }

            // The depth register is always two registers after the last color output.
            return count + 1;
        }

        public bool QueryInfoBool(QueryInfoName info, int index = 0)
        {
            return Convert.ToBoolean(QueryInfo(info, index));
        }

        public int QueryInfo(QueryInfoName info, int index = 0)
        {
            if (_queryInfoCallback != null)
            {
                return _queryInfoCallback(info, index);
            }
            else
            {
                switch (info)
                {
                    case QueryInfoName.ComputeLocalSizeX:
                    case QueryInfoName.ComputeLocalSizeY:
                    case QueryInfoName.ComputeLocalSizeZ:
                        return 1;
                    case QueryInfoName.ComputeSharedMemorySize:
                        return 0xc000;
                    case QueryInfoName.IsTextureBuffer:
                        return Convert.ToInt32(false);
                    case QueryInfoName.IsTextureRectangle:
                        return Convert.ToInt32(false);
                    case QueryInfoName.MaximumViewportDimensions:
                        return 0x8000;
                    case QueryInfoName.PrimitiveTopology:
                        return (int)InputTopology.Points;
                    case QueryInfoName.StorageBufferOffsetAlignment:
                        return 16;
                    case QueryInfoName.SupportsNonConstantTextureOffset:
                        return Convert.ToInt32(true);
                    case QueryInfoName.ViewportTransformEnable:
                        return Convert.ToInt32(true);
                }
            }

            return 0;
        }
    }
}