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