Relax descriptor set index assert at descriptor point of definition

The module may legitimately contain descriptor set references (intended
for another entrypoint) which are not compatible with our limits.

There is a matching assert to verify the set index at the point the
descriptor is actually referenced.

Bug: b/140648941
Change-Id: Ie3b8c6a2e53e553d1dccb2995e6719539eab89de
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/36114
Tested-by: Chris Forbes <chrisforbes@google.com>
Presubmit-Ready: Chris Forbes <chrisforbes@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/src/Pipeline/SpirvShader.cpp b/src/Pipeline/SpirvShader.cpp
index b4b1f73..db1dcdf 100644
--- a/src/Pipeline/SpirvShader.cpp
+++ b/src/Pipeline/SpirvShader.cpp
@@ -2879,9 +2879,19 @@
 		case spv::StorageClassStorageBuffer:
 		{
 			const auto &d = descriptorDecorations.at(resultId);
-			ASSERT(d.DescriptorSet >= 0 && d.DescriptorSet < vk::MAX_BOUND_DESCRIPTOR_SETS);
+			ASSERT(d.DescriptorSet >= 0);
 			auto size = 0; // Not required as this pointer is not directly used by SIMD::Read or SIMD::Write.
-			state->createPointer(resultId, SIMD::Pointer(routine->descriptorSets[d.DescriptorSet], size));
+			// Note: the module may contain descriptor set references that are not suitable for this implementation -- using a set index higher than the number
+			// of descriptor set binding points we support. As long as the selected entrypoint doesn't actually touch the out of range binding points, this
+			// is valid. In this case make the value nullptr to make it easier to diagnose an attempt to dereference it.
+			if (d.DescriptorSet < vk::MAX_BOUND_DESCRIPTOR_SETS)
+			{
+				state->createPointer(resultId, SIMD::Pointer(routine->descriptorSets[d.DescriptorSet], size));
+			}
+			else
+			{
+				state->createPointer(resultId, SIMD::Pointer(nullptr, 0));
+			}
 			break;
 		}
 		case spv::StorageClassPushConstant: