aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Gpu/Shader/TransformFeedbackDescriptor.cs
blob: 5baf2a1a6b76eee3b6c5aef9a23463933d3ee2b3 (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
using Ryujinx.Common.Memory;
using System;
using System.Runtime.InteropServices;

namespace Ryujinx.Graphics.Gpu.Shader
{
    /// <summary>
    /// Transform feedback descriptor.
    /// </summary>
    struct TransformFeedbackDescriptor
    {
        // New fields should be added to the end of the struct to keep disk shader cache compatibility.

        /// <summary>
        /// Index of the transform feedback.
        /// </summary>
        public readonly int BufferIndex;

        /// <summary>
        /// Amount of bytes consumed per vertex.
        /// </summary>
        public readonly int Stride;

        /// <summary>
        /// Number of varyings written into the buffer.
        /// </summary>
        public readonly int VaryingCount;

        /// <summary>
        /// Location of varyings to be written into the buffer. Each byte is one location.
        /// </summary>
        public Array32<uint> VaryingLocations; // Making this readonly breaks AsSpan

        /// <summary>
        /// Creates a new transform feedback descriptor.
        /// </summary>
        /// <param name="bufferIndex">Index of the transform feedback</param>
        /// <param name="stride">Amount of bytes consumed per vertex</param>
        /// <param name="varyingCount">Number of varyings written into the buffer. Indicates size in bytes of <paramref name="varyingLocations"/></param>
        /// <param name="varyingLocations">Location of varyings to be written into the buffer. Each byte is one location</param>
        public TransformFeedbackDescriptor(int bufferIndex, int stride, int varyingCount, ref Array32<uint> varyingLocations)
        {
            BufferIndex = bufferIndex;
            Stride = stride;
            VaryingCount = varyingCount;
            VaryingLocations = varyingLocations;
        }

        /// <summary>
        /// Gets a span of the <see cref="VaryingLocations"/>.
        /// </summary>
        /// <returns>Span of varying locations</returns>
        public ReadOnlySpan<byte> AsSpan()
        {
            return MemoryMarshal.Cast<uint, byte>(VaryingLocations.AsSpan()).Slice(0, Math.Min(128, VaryingCount));
        }
    }
}