/ src / Ryujinx.Graphics.Shader / Decoders / DecodedProgram.cs
DecodedProgram.cs
 1  using Ryujinx.Graphics.Shader.Translation;
 2  using System;
 3  using System.Collections;
 4  using System.Collections.Generic;
 5  
 6  namespace Ryujinx.Graphics.Shader.Decoders
 7  {
 8      readonly struct DecodedProgram : IEnumerable<DecodedFunction>
 9      {
10          public DecodedFunction MainFunction { get; }
11          private readonly IReadOnlyDictionary<ulong, DecodedFunction> _functions;
12          private readonly List<DecodedFunction> _functionsWithId;
13          public int FunctionsWithIdCount => _functionsWithId.Count;
14  
15          public AttributeUsage AttributeUsage { get; }
16          public FeatureFlags UsedFeatures { get; }
17          public byte ClipDistancesWritten { get; }
18          public int Cb1DataSize { get; }
19  
20          public DecodedProgram(
21              DecodedFunction mainFunction,
22              IReadOnlyDictionary<ulong, DecodedFunction> functions,
23              AttributeUsage attributeUsage,
24              FeatureFlags usedFeatures,
25              byte clipDistancesWritten,
26              int cb1DataSize)
27          {
28              MainFunction = mainFunction;
29              _functions = functions;
30              _functionsWithId = new();
31              AttributeUsage = attributeUsage;
32              UsedFeatures = usedFeatures;
33              ClipDistancesWritten = clipDistancesWritten;
34              Cb1DataSize = cb1DataSize;
35          }
36  
37          public DecodedFunction GetFunctionByAddress(ulong address)
38          {
39              if (_functions.TryGetValue(address, out DecodedFunction function))
40              {
41                  return function;
42              }
43  
44              return null;
45          }
46  
47          public DecodedFunction GetFunctionById(int id)
48          {
49              if ((uint)id >= (uint)_functionsWithId.Count)
50              {
51                  throw new ArgumentOutOfRangeException(nameof(id));
52              }
53  
54              return _functionsWithId[id];
55          }
56  
57          public void AddFunctionAndSetId(DecodedFunction function)
58          {
59              function.Id = _functionsWithId.Count;
60              _functionsWithId.Add(function);
61          }
62  
63          public IoUsage GetIoUsage()
64          {
65              return new IoUsage(UsedFeatures, ClipDistancesWritten, AttributeUsage.UsedOutputAttributes);
66          }
67  
68          public IEnumerator<DecodedFunction> GetEnumerator()
69          {
70              return _functions.Values.GetEnumerator();
71          }
72  
73          IEnumerator IEnumerable.GetEnumerator()
74          {
75              return GetEnumerator();
76          }
77      }
78  }