RenderPassCacheKey.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Linq;
  3. namespace Ryujinx.Graphics.Vulkan
  4. {
  5. internal readonly struct RenderPassCacheKey : IRefEquatable<RenderPassCacheKey>
  6. {
  7. private readonly TextureView _depthStencil;
  8. private readonly TextureView[] _colors;
  9. public RenderPassCacheKey(TextureView depthStencil, TextureView[] colors)
  10. {
  11. _depthStencil = depthStencil;
  12. _colors = colors;
  13. }
  14. public override int GetHashCode()
  15. {
  16. HashCode hc = new();
  17. hc.Add(_depthStencil);
  18. if (_colors != null)
  19. {
  20. foreach (TextureView color in _colors)
  21. {
  22. hc.Add(color);
  23. }
  24. }
  25. return hc.ToHashCode();
  26. }
  27. public bool Equals(ref RenderPassCacheKey other)
  28. {
  29. bool colorsNull = _colors == null;
  30. bool otherNull = other._colors == null;
  31. return other._depthStencil == _depthStencil &&
  32. colorsNull == otherNull &&
  33. (colorsNull || other._colors.SequenceEqual(_colors));
  34. }
  35. }
  36. }