Skip to content

Commit

Permalink
Fix the equality and hash code implementations of several Description…
Browse files Browse the repository at this point in the history
… structs.
  • Loading branch information
mellinoe committed Mar 30, 2018
1 parent 0d67eb0 commit fe20ccf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/Veldrid/OutputsDescription.cs
Expand Up @@ -76,7 +76,8 @@ internal static OutputDescription CreateFromFramebuffer(Framebuffer fb)
public bool Equals(OutputDescription other)
{
return DepthAttachment.GetValueOrDefault().Equals(other.DepthAttachment.GetValueOrDefault())
&& Util.ArrayEqualsEquatable(ColorAttachments, other.ColorAttachments);
&& Util.ArrayEqualsEquatable(ColorAttachments, other.ColorAttachments)
&& SampleCount == other.SampleCount;
}

/// <summary>
Expand All @@ -85,7 +86,10 @@ public bool Equals(OutputDescription other)
/// <returns>A 32-bit signed integer that is the hash code for this instance.</returns>
public override int GetHashCode()
{
return HashHelper.Combine(DepthAttachment.GetHashCode(), HashHelper.Array(ColorAttachments));
return HashHelper.Combine(
DepthAttachment.GetHashCode(),
HashHelper.Array(ColorAttachments),
SampleCount.GetHashCode());
}
}
}
4 changes: 2 additions & 2 deletions src/Veldrid/ShaderDescription.cs
Expand Up @@ -46,7 +46,7 @@ public ShaderDescription(ShaderStages stage, byte[] shaderBytes, string entryPoi
/// <returns>True if all elements and if array instances are equal; false otherswise.</returns>
public bool Equals(ShaderDescription other)
{
return Stage == other.Stage && ShaderBytes == other.ShaderBytes;
return Stage == other.Stage && ShaderBytes == other.ShaderBytes && EntryPoint.Equals(other.EntryPoint);
}

/// <summary>
Expand All @@ -55,7 +55,7 @@ public bool Equals(ShaderDescription other)
/// <returns>A 32-bit signed integer that is the hash code for this instance.</returns>
public override int GetHashCode()
{
return HashHelper.Combine(Stage.GetHashCode(), ShaderBytes.GetHashCode());
return HashHelper.Combine(Stage.GetHashCode(), ShaderBytes.GetHashCode(), EntryPoint.GetHashCode());
}
}
}
2 changes: 2 additions & 0 deletions src/Veldrid/SwapchainDescription.cs
Expand Up @@ -60,6 +60,8 @@ public SwapchainDescription(SwapchainSource source, uint width, uint height, Pix
public bool Equals(SwapchainDescription other)
{
return Source.Equals(other.Source)
&& Width.Equals(other.Width)
&& Height.Equals(other.Height)
&& DepthFormat == other.DepthFormat
&& SyncToVerticalBlank.Equals(other.SyncToVerticalBlank);
}
Expand Down
13 changes: 11 additions & 2 deletions src/Veldrid/TextureViewDescription.cs
Expand Up @@ -66,7 +66,11 @@ public TextureViewDescription(Texture target, uint baseMipLevel, uint mipLevels,
/// <returns>True if all elements are equal; false otherswise.</returns>
public bool Equals(TextureViewDescription other)
{
return Target.Equals(other.Target);
return Target.Equals(other.Target)
&& BaseMipLevel.Equals(other.BaseMipLevel)
&& MipLevels.Equals(other.MipLevels)
&& BaseArrayLayer.Equals(other.BaseArrayLayer)
&& ArrayLayers.Equals(other.ArrayLayers);
}

/// <summary>
Expand All @@ -75,7 +79,12 @@ public bool Equals(TextureViewDescription other)
/// <returns>A 32-bit signed integer that is the hash code for this instance.</returns>
public override int GetHashCode()
{
return Target.GetHashCode();
return HashHelper.Combine(
Target.GetHashCode(),
BaseMipLevel.GetHashCode(),
MipLevels.GetHashCode(),
BaseArrayLayer.GetHashCode(),
ArrayLayers.GetHashCode());
}
}
}

0 comments on commit fe20ccf

Please sign in to comment.