From 768a605ccd2a162c8d2c0e9113ed2615dd335adb Mon Sep 17 00:00:00 2001 From: Eric Mellino Date: Wed, 9 May 2018 16:42:44 -0700 Subject: [PATCH] Add matching validation for compute ResourceSets. --- src/Veldrid/CommandList.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Veldrid/CommandList.cs b/src/Veldrid/CommandList.cs index 760dfc5b6..5e3aed182 100644 --- a/src/Veldrid/CommandList.cs +++ b/src/Veldrid/CommandList.cs @@ -213,7 +213,26 @@ public void SetComputeResourceSet(uint slot, ResourceSet rs) if (layoutsCount <= slot) { throw new VeldridException( - $"The currently-bound compute Pipeline only contains {layoutsCount} ResourceLayouts, so a ResourceSet cannot be bound to slot {slot}."); + $"Failed to bind ResourceSet to slot {slot}. The active compute Pipeline only contains {layoutsCount} ResourceLayouts."); + } + + ResourceLayout layout = _computePipeline.ResourceLayouts[slot]; + int pipelineLength = layout.ResourceKinds.Length; + int setLength = rs.Layout.ResourceKinds.Length; + if (pipelineLength != setLength) + { + throw new VeldridException($"Failed to bind ResourceSet to slot {slot}. The number of resources in the ResourceSet ({setLength}) does not match the number expected by the active Pipeline ({pipelineLength})."); + } + + for (int i = 0; i < pipelineLength; i++) + { + ResourceKind pipelineKind = layout.ResourceKinds[i]; + ResourceKind setKind = rs.Layout.ResourceKinds[i]; + if (pipelineKind != setKind) + { + throw new VeldridException( + $"Failed to bind ResourceSet to slot {slot}. Resource element {i} was of the incorrect type. The bound Pipeline expects {pipelineKind}, but the ResourceSet contained {setKind}."); + } } #endif SetComputeResourceSetCore(slot, rs);