/ src / Ryujinx.Graphics.Gpu / Shader / TransformFeedbackDescriptor.cs
TransformFeedbackDescriptor.cs
 1  using Ryujinx.Common.Memory;
 2  using System;
 3  using System.Runtime.InteropServices;
 4  
 5  namespace Ryujinx.Graphics.Gpu.Shader
 6  {
 7      /// <summary>
 8      /// Transform feedback descriptor.
 9      /// </summary>
10      struct TransformFeedbackDescriptor
11      {
12          // New fields should be added to the end of the struct to keep disk shader cache compatibility.
13  
14          /// <summary>
15          /// Index of the transform feedback.
16          /// </summary>
17          public readonly int BufferIndex;
18  
19          /// <summary>
20          /// Amount of bytes consumed per vertex.
21          /// </summary>
22          public readonly int Stride;
23  
24          /// <summary>
25          /// Number of varyings written into the buffer.
26          /// </summary>
27          public readonly int VaryingCount;
28  
29          /// <summary>
30          /// Location of varyings to be written into the buffer. Each byte is one location.
31          /// </summary>
32          public Array32<uint> VaryingLocations; // Making this readonly breaks AsSpan
33  
34          /// <summary>
35          /// Creates a new transform feedback descriptor.
36          /// </summary>
37          /// <param name="bufferIndex">Index of the transform feedback</param>
38          /// <param name="stride">Amount of bytes consumed per vertex</param>
39          /// <param name="varyingCount">Number of varyings written into the buffer. Indicates size in bytes of <paramref name="varyingLocations"/></param>
40          /// <param name="varyingLocations">Location of varyings to be written into the buffer. Each byte is one location</param>
41          public TransformFeedbackDescriptor(int bufferIndex, int stride, int varyingCount, ref Array32<uint> varyingLocations)
42          {
43              BufferIndex = bufferIndex;
44              Stride = stride;
45              VaryingCount = varyingCount;
46              VaryingLocations = varyingLocations;
47          }
48  
49          /// <summary>
50          /// Gets a span of the <see cref="VaryingLocations"/>.
51          /// </summary>
52          /// <returns>Span of varying locations</returns>
53          public ReadOnlySpan<byte> AsSpan()
54          {
55              return MemoryMarshal.Cast<uint, byte>(VaryingLocations.AsSpan())[..Math.Min(128, VaryingCount)];
56          }
57      }
58  }