/ src / Ryujinx.Graphics.Gpu / Memory / BufferStage.cs
BufferStage.cs
 1  using Ryujinx.Graphics.Shader;
 2  using System.Runtime.CompilerServices;
 3  
 4  namespace Ryujinx.Graphics.Gpu.Memory
 5  {
 6      /// <summary>
 7      /// Pipeline stages that can modify buffer data, as well as flags indicating storage usage.
 8      /// Must match ShaderStage for the shader stages, though anything after that can be in any order.
 9      /// </summary>
10      internal enum BufferStage : byte
11      {
12          Compute,
13          Vertex,
14          TessellationControl,
15          TessellationEvaluation,
16          Geometry,
17          Fragment,
18  
19          Indirect,
20          VertexBuffer,
21          IndexBuffer,
22          Copy,
23          TransformFeedback,
24          Internal,
25          None,
26  
27          StageMask = 0x3f,
28          StorageMask = 0xc0,
29  
30          StorageRead = 0x40,
31          StorageWrite = 0x80,
32  
33  #pragma warning disable CA1069 // Enums values should not be duplicated
34          StorageAtomic = 0xc0
35  #pragma warning restore CA1069 // Enums values should not be duplicated
36      }
37  
38      /// <summary>
39      /// Utility methods to convert shader stages and binding flags into buffer stages.
40      /// </summary>
41      internal static class BufferStageUtils
42      {
43          [MethodImpl(MethodImplOptions.AggressiveInlining)]
44          public static BufferStage FromShaderStage(ShaderStage stage)
45          {
46              return (BufferStage)stage;
47          }
48  
49          [MethodImpl(MethodImplOptions.AggressiveInlining)]
50          public static BufferStage FromShaderStage(int stageIndex)
51          {
52              return (BufferStage)(stageIndex + 1);
53          }
54  
55          [MethodImpl(MethodImplOptions.AggressiveInlining)]
56          public static BufferStage FromUsage(BufferUsageFlags flags)
57          {
58              if (flags.HasFlag(BufferUsageFlags.Write))
59              {
60                  return BufferStage.StorageWrite;
61              }
62              else
63              {
64                  return BufferStage.StorageRead;
65              }
66          }
67  
68          [MethodImpl(MethodImplOptions.AggressiveInlining)]
69          public static BufferStage FromUsage(TextureUsageFlags flags)
70          {
71              if (flags.HasFlag(TextureUsageFlags.ImageStore))
72              {
73                  return BufferStage.StorageWrite;
74              }
75              else
76              {
77                  return BufferStage.StorageRead;
78              }
79          }
80  
81          [MethodImpl(MethodImplOptions.AggressiveInlining)]
82          public static BufferStage TextureBuffer(ShaderStage shaderStage, TextureUsageFlags flags)
83          {
84              return FromShaderStage(shaderStage) | FromUsage(flags);
85          }
86  
87          [MethodImpl(MethodImplOptions.AggressiveInlining)]
88          public static BufferStage GraphicsStorage(int stageIndex, BufferUsageFlags flags)
89          {
90              return FromShaderStage(stageIndex) | FromUsage(flags);
91          }
92  
93          [MethodImpl(MethodImplOptions.AggressiveInlining)]
94          public static BufferStage ComputeStorage(BufferUsageFlags flags)
95          {
96              return BufferStage.Compute | FromUsage(flags);
97          }
98      }
99  }