ShaderAddresses.cs
1 using System; 2 using System.Runtime.CompilerServices; 3 using System.Runtime.InteropServices; 4 5 namespace Ryujinx.Graphics.Gpu.Shader 6 { 7 /// <summary> 8 /// Shader code addresses in memory for each shader stage. 9 /// </summary> 10 struct ShaderAddresses : IEquatable<ShaderAddresses> 11 { 12 #pragma warning disable CS0649 // Field is never assigned to 13 public ulong VertexA; 14 public ulong VertexB; 15 public ulong TessControl; 16 public ulong TessEvaluation; 17 public ulong Geometry; 18 public ulong Fragment; 19 #pragma warning restore CS0649 20 21 /// <summary> 22 /// Check if the addresses are equal. 23 /// </summary> 24 /// <param name="other">Shader addresses structure to compare with</param> 25 /// <returns>True if they are equal, false otherwise</returns> 26 public readonly override bool Equals(object other) 27 { 28 return other is ShaderAddresses addresses && Equals(addresses); 29 } 30 31 /// <summary> 32 /// Check if the addresses are equal. 33 /// </summary> 34 /// <param name="other">Shader addresses structure to compare with</param> 35 /// <returns>True if they are equal, false otherwise</returns> 36 public readonly bool Equals(ShaderAddresses other) 37 { 38 return VertexA == other.VertexA && 39 VertexB == other.VertexB && 40 TessControl == other.TessControl && 41 TessEvaluation == other.TessEvaluation && 42 Geometry == other.Geometry && 43 Fragment == other.Fragment; 44 } 45 46 /// <summary> 47 /// Computes hash code from the addresses. 48 /// </summary> 49 /// <returns>Hash code</returns> 50 public readonly override int GetHashCode() 51 { 52 return HashCode.Combine(VertexA, VertexB, TessControl, TessEvaluation, Geometry, Fragment); 53 } 54 55 /// <summary> 56 /// Gets a view of the structure as a span of addresses. 57 /// </summary> 58 /// <returns>Span of addresses</returns> 59 public Span<ulong> AsSpan() 60 { 61 return MemoryMarshal.CreateSpan(ref VertexA, Unsafe.SizeOf<ShaderAddresses>() / sizeof(ulong)); 62 } 63 } 64 }