Reduce descriptor binding info exposure

Only the descriptor binding type is needed. It's an implementation
detail that we currently store the entire original
VkDescriptorSetLayoutBinding structures, which might change in the
future.

This also avoids specializing generated code for things which should
not be treated as pipeline immutable state.

Bug: b/152227757
Change-Id: I20ca7de53e972e77649dec20fcf623f818d4f53c
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/43972
Presubmit-Ready: Nicolas Capens <nicolascapens@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
diff --git a/src/Pipeline/SpirvShaderImage.cpp b/src/Pipeline/SpirvShaderImage.cpp
index 8197df0..b803b40 100644
--- a/src/Pipeline/SpirvShaderImage.cpp
+++ b/src/Pipeline/SpirvShaderImage.cpp
@@ -346,14 +346,14 @@
 
 	const DescriptorDecorations &d = descriptorDecorations.at(imageId);
 	auto setLayout = routine->pipelineLayout->getDescriptorSetLayout(d.DescriptorSet);
-	auto &bindingLayout = setLayout->getBindingLayout(d.Binding);
+	auto descriptorType = setLayout->getDescriptorType(d.Binding);
 
 	Pointer<Byte> descriptor = state->getPointer(imageId).base;
 
 	Pointer<Int> extent;
 	Int arrayLayers;
 
-	switch(bindingLayout.descriptorType)
+	switch(descriptorType)
 	{
 		case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
 		case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
@@ -371,7 +371,7 @@
 			break;
 		}
 		default:
-			UNREACHABLE("Image descriptorType: %d", int(bindingLayout.descriptorType));
+			UNREACHABLE("Image descriptorType: %d", int(descriptorType));
 	}
 
 	auto dimensions = resultTy.componentCount - (isArrayed ? 1 : 0);
@@ -410,11 +410,11 @@
 
 	const DescriptorDecorations &d = descriptorDecorations.at(imageId);
 	auto setLayout = state->routine->pipelineLayout->getDescriptorSetLayout(d.DescriptorSet);
-	auto &bindingLayout = setLayout->getBindingLayout(d.Binding);
+	auto descriptorType = setLayout->getDescriptorType(d.Binding);
 
 	Pointer<Byte> descriptor = state->getPointer(imageId).base;
 	Int mipLevels = 0;
-	switch(bindingLayout.descriptorType)
+	switch(descriptorType)
 	{
 		case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
 		case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
@@ -422,7 +422,7 @@
 			mipLevels = *Pointer<Int>(descriptor + OFFSET(vk::SampledImageDescriptor, mipLevels));  // uint32_t
 			break;
 		default:
-			UNREACHABLE("Image descriptorType: %d", int(bindingLayout.descriptorType));
+			UNREACHABLE("Image descriptorType: %d", int(descriptorType));
 	}
 
 	auto &dst = state->createIntermediate(insn.resultId(), 1);
@@ -443,11 +443,11 @@
 
 	const DescriptorDecorations &d = descriptorDecorations.at(imageId);
 	auto setLayout = state->routine->pipelineLayout->getDescriptorSetLayout(d.DescriptorSet);
-	auto &bindingLayout = setLayout->getBindingLayout(d.Binding);
+	auto descriptorType = setLayout->getDescriptorType(d.Binding);
 
 	Pointer<Byte> descriptor = state->getPointer(imageId).base;
 	Int sampleCount = 0;
-	switch(bindingLayout.descriptorType)
+	switch(descriptorType)
 	{
 		case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
 			sampleCount = *Pointer<Int>(descriptor + OFFSET(vk::StorageImageDescriptor, sampleCount));  // uint32_t
@@ -458,7 +458,7 @@
 			sampleCount = *Pointer<Int>(descriptor + OFFSET(vk::SampledImageDescriptor, sampleCount));  // uint32_t
 			break;
 		default:
-			UNREACHABLE("Image descriptorType: %d", int(bindingLayout.descriptorType));
+			UNREACHABLE("Image descriptorType: %d", int(descriptorType));
 	}
 
 	auto &dst = state->createIntermediate(insn.resultId(), 1);
diff --git a/src/Vulkan/VkDescriptorSetLayout.cpp b/src/Vulkan/VkDescriptorSetLayout.cpp
index 64de3bf..27d9969 100644
--- a/src/Vulkan/VkDescriptorSetLayout.cpp
+++ b/src/Vulkan/VkDescriptorSetLayout.cpp
@@ -240,10 +240,10 @@
 	return index;
 }
 
-VkDescriptorSetLayoutBinding const &DescriptorSetLayout::getBindingLayout(uint32_t binding) const
+VkDescriptorType DescriptorSetLayout::getDescriptorType(uint32_t binding) const
 {
 	uint32_t index = getBindingIndex(binding);
-	return bindings[index];
+	return bindings[index].descriptorType;
 }
 
 uint8_t *DescriptorSetLayout::getOffsetPointer(DescriptorSet *descriptorSet, uint32_t binding, uint32_t arrayElement, uint32_t count, size_t *typeSize) const
diff --git a/src/Vulkan/VkDescriptorSetLayout.hpp b/src/Vulkan/VkDescriptorSetLayout.hpp
index b75f79b..cc12976 100644
--- a/src/Vulkan/VkDescriptorSetLayout.hpp
+++ b/src/Vulkan/VkDescriptorSetLayout.hpp
@@ -124,8 +124,8 @@
 	//  VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
 	bool isBindingDynamic(uint32_t binding) const;
 
-	// Returns the VkDescriptorSetLayoutBinding for the given binding.
-	VkDescriptorSetLayoutBinding const &getBindingLayout(uint32_t binding) const;
+	// Returns the descriptor type for the given binding.
+	VkDescriptorType getDescriptorType(uint32_t binding) const;
 
 	uint8_t *getOffsetPointer(DescriptorSet *descriptorSet, uint32_t binding, uint32_t arrayElement, uint32_t count, size_t *typeSize) const;