aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Shader/StructuredIr/StructuredProgramInfo.cs
blob: 57253148f17a4e55cd1337c67ee7d9cad77a91ff (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
using System.Collections.Generic;

namespace Ryujinx.Graphics.Shader.StructuredIr
{
    struct TransformFeedbackOutput
    {
        public readonly bool Valid;
        public readonly int Buffer;
        public readonly int Offset;
        public readonly int Stride;

        public TransformFeedbackOutput(int buffer, int offset, int stride)
        {
            Valid = true;
            Buffer = buffer;
            Offset = offset;
            Stride = stride;
        }
    }

    class StructuredProgramInfo
    {
        public List<StructuredFunction> Functions { get; }

        public HashSet<int> Inputs { get; }
        public HashSet<int> Outputs { get; }
        public HashSet<int> InputsPerPatch { get; }
        public HashSet<int> OutputsPerPatch { get; }

        public HelperFunctionsMask HelperFunctionsMask { get; set; }

        public TransformFeedbackOutput[] TransformFeedbackOutputs { get; }

        public StructuredProgramInfo()
        {
            Functions = new List<StructuredFunction>();

            Inputs = new HashSet<int>();
            Outputs = new HashSet<int>();
            InputsPerPatch = new HashSet<int>();
            OutputsPerPatch = new HashSet<int>();

            TransformFeedbackOutputs = new TransformFeedbackOutput[0xc0];
        }

        public TransformFeedbackOutput GetTransformFeedbackOutput(int attr)
        {
            int index = attr / 4;
            return TransformFeedbackOutputs[index];
        }

        public int GetTransformFeedbackOutputComponents(int attr)
        {
            int index = attr / 4;
            int baseIndex = index & ~3;

            int count = 1;

            for (; count < 4; count++)
            {
                ref var prev = ref TransformFeedbackOutputs[baseIndex + count - 1];
                ref var curr = ref TransformFeedbackOutputs[baseIndex + count];

                int prevOffset = prev.Offset;
                int currOffset = curr.Offset;

                if (!prev.Valid || !curr.Valid || prevOffset + 4 != currOffset)
                {
                    break;
                }
            }

            if (baseIndex + count <= index)
            {
                return 1;
            }

            return count;
        }
    }
}