Array of Vertex Input Attribute?

Unless I’ve missed something I don’t see a way to have a vertex input attribute be an array. What I was thinking is that if I have multiple textcoords in the input and they are contiguous why not represent them as an array. If that was allowed I could use a specialization constant for the size like I do for the array of samplers. Then I could use the same GLSL for 1-n textures in the format and with the specialization constants unused paths should be optimized away. In addition to location, binding, format, and offset it could have a count or something. Is there a technical reason it doesn’t work like this?

Vertex shader inputs can be arrays in GLSL.

However, to the API (OpenGL or Vulkan), each array element (or vector in a matrix) is a separate location. The first element of the array has the specified location (with the location value), and each subsequent element increases that location by 1. So if you have a 3-element input of type vec4, and the location is set to 2, then it will consume attribute locations 2, 3, and 4.

But you still have to set the vertex format data for each location individually. It doesn’t care if an attribute location is going to an element in an array or a vector in a matrix. And yes, this means that different elements of an arrayed attributes can come from different buffers.

And as far as I can tell, there is no restriction in the VKSL document on using specialization constants in vertex shader input arrays.

As Alfonse said there is nothing that permits you from doing that in the specs.

I did some testing with a similar approach some time ago and it works just fine. Haven’t tested on all platforms (though there’s nothing that shouldn’t work everywhere), but something like this doesn’t throw any errors and works:

#version 450

constant_id = 0) const int arraySize = 3;

layout (location = 0) in vec3 inputs[arraySize];
layout (location = 0) out vec3 outputs[arraySize];

out gl_PerVertex {
	vec4 gl_Position;
};

void main() 
{
	gl_Position = vec4(inputs[0], 1.0);	
	for (int i = 0; i < arraySize; i++) {
		outputs[i] = inputs[i];
	}
}