ResourceLayout.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. using System;
  2. using System.Collections.ObjectModel;
  3. namespace Ryujinx.Graphics.GAL
  4. {
  5. public enum ResourceType : byte
  6. {
  7. UniformBuffer,
  8. StorageBuffer,
  9. Texture,
  10. Sampler,
  11. TextureAndSampler,
  12. Image,
  13. BufferTexture,
  14. BufferImage,
  15. }
  16. public enum ResourceAccess : byte
  17. {
  18. None = 0,
  19. Read = 1,
  20. Write = 2,
  21. ReadWrite = Read | Write,
  22. }
  23. [Flags]
  24. public enum ResourceStages : byte
  25. {
  26. None = 0,
  27. Compute = 1 << 0,
  28. Vertex = 1 << 1,
  29. TessellationControl = 1 << 2,
  30. TessellationEvaluation = 1 << 3,
  31. Geometry = 1 << 4,
  32. Fragment = 1 << 5,
  33. }
  34. public readonly struct ResourceDescriptor : IEquatable<ResourceDescriptor>
  35. {
  36. public int Binding { get; }
  37. public int Count { get; }
  38. public ResourceType Type { get; }
  39. public ResourceStages Stages { get; }
  40. public ResourceDescriptor(int binding, int count, ResourceType type, ResourceStages stages)
  41. {
  42. Binding = binding;
  43. Count = count;
  44. Type = type;
  45. Stages = stages;
  46. }
  47. public override int GetHashCode()
  48. {
  49. return HashCode.Combine(Binding, Count, Type, Stages);
  50. }
  51. public override bool Equals(object obj)
  52. {
  53. return obj is ResourceDescriptor other && Equals(other);
  54. }
  55. public bool Equals(ResourceDescriptor other)
  56. {
  57. return Binding == other.Binding && Count == other.Count && Type == other.Type && Stages == other.Stages;
  58. }
  59. public static bool operator ==(ResourceDescriptor left, ResourceDescriptor right)
  60. {
  61. return left.Equals(right);
  62. }
  63. public static bool operator !=(ResourceDescriptor left, ResourceDescriptor right)
  64. {
  65. return !(left == right);
  66. }
  67. }
  68. public readonly struct ResourceUsage : IEquatable<ResourceUsage>
  69. {
  70. public int Binding { get; }
  71. public ResourceType Type { get; }
  72. public ResourceStages Stages { get; }
  73. public ResourceAccess Access { get; }
  74. public ResourceUsage(int binding, ResourceType type, ResourceStages stages, ResourceAccess access)
  75. {
  76. Binding = binding;
  77. Type = type;
  78. Stages = stages;
  79. Access = access;
  80. }
  81. public override int GetHashCode()
  82. {
  83. return HashCode.Combine(Binding, Type, Stages, Access);
  84. }
  85. public override bool Equals(object obj)
  86. {
  87. return obj is ResourceUsage other && Equals(other);
  88. }
  89. public bool Equals(ResourceUsage other)
  90. {
  91. return Binding == other.Binding && Type == other.Type && Stages == other.Stages && Access == other.Access;
  92. }
  93. public static bool operator ==(ResourceUsage left, ResourceUsage right)
  94. {
  95. return left.Equals(right);
  96. }
  97. public static bool operator !=(ResourceUsage left, ResourceUsage right)
  98. {
  99. return !(left == right);
  100. }
  101. }
  102. public readonly struct ResourceDescriptorCollection
  103. {
  104. public ReadOnlyCollection<ResourceDescriptor> Descriptors { get; }
  105. public ResourceDescriptorCollection(ReadOnlyCollection<ResourceDescriptor> descriptors)
  106. {
  107. Descriptors = descriptors;
  108. }
  109. public override int GetHashCode()
  110. {
  111. HashCode hasher = new();
  112. if (Descriptors != null)
  113. {
  114. foreach (var descriptor in Descriptors)
  115. {
  116. hasher.Add(descriptor);
  117. }
  118. }
  119. return hasher.ToHashCode();
  120. }
  121. public override bool Equals(object obj)
  122. {
  123. return obj is ResourceDescriptorCollection other && Equals(other);
  124. }
  125. public bool Equals(ResourceDescriptorCollection other)
  126. {
  127. if ((Descriptors == null) != (other.Descriptors == null))
  128. {
  129. return false;
  130. }
  131. if (Descriptors != null)
  132. {
  133. if (Descriptors.Count != other.Descriptors.Count)
  134. {
  135. return false;
  136. }
  137. for (int index = 0; index < Descriptors.Count; index++)
  138. {
  139. if (!Descriptors[index].Equals(other.Descriptors[index]))
  140. {
  141. return false;
  142. }
  143. }
  144. }
  145. return true;
  146. }
  147. public static bool operator ==(ResourceDescriptorCollection left, ResourceDescriptorCollection right)
  148. {
  149. return left.Equals(right);
  150. }
  151. public static bool operator !=(ResourceDescriptorCollection left, ResourceDescriptorCollection right)
  152. {
  153. return !(left == right);
  154. }
  155. }
  156. public readonly struct ResourceUsageCollection
  157. {
  158. public ReadOnlyCollection<ResourceUsage> Usages { get; }
  159. public ResourceUsageCollection(ReadOnlyCollection<ResourceUsage> usages)
  160. {
  161. Usages = usages;
  162. }
  163. }
  164. public readonly struct ResourceLayout
  165. {
  166. public ReadOnlyCollection<ResourceDescriptorCollection> Sets { get; }
  167. public ReadOnlyCollection<ResourceUsageCollection> SetUsages { get; }
  168. public ResourceLayout(
  169. ReadOnlyCollection<ResourceDescriptorCollection> sets,
  170. ReadOnlyCollection<ResourceUsageCollection> setUsages)
  171. {
  172. Sets = sets;
  173. SetUsages = setUsages;
  174. }
  175. }
  176. }