ShaderAddresses.cs 2.2 KB

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