Problem with SSBO binding

I want to transfer an array variable size to the fragment shader. For this purpose I’m using a SSBO. The execution crashes by vkQueueSubmit with the following message from the validation Layers:

validateFunctionArguments:3476: failed assertion `Fragment Function(main0): missing buffer binding at index 14 for spvBufferSizeConstants[0].’

This is the fragment shader:

#version 450
layout(location = 0) in vec2 vPos;

layout(location = 0) out vec4 fragColor;


layout(push_constant) uniform PushConsts {
	vec4 innerColor;
	vec4 borderColor; //not used yet
} pushConsts;
	
layout(std430, set = 0, binding = 0) readonly buffer Vertex {
	vec2[] polygonVertex;
} vertex;

float dot2(vec2 v) { return dot(v,v); }
float cross2d(vec2 v0, in vec2 v1) { return v0.x*v1.y - v0.y*v1.x; }

float polygon(vec2 p ) {
	int arraySize = vertex.polygonVertex.length();
	float d = dot(p-vertex.polygonVertex[0],p-vertex.polygonVertex[0]);
	float s = 1.0;
	for(int i=0, j=arraySize-1; i<arraySize; j=i, i++) {
			// distance
		vec2 e = vertex.polygonVertex[j] - vertex.polygonVertex[i];
		vec2 w =  p - vertex.polygonVertex[i];
		vec2 b = w - e*clamp(dot(w,e)/dot(e,e), 0.0, 1.0);
		d = min(d, dot(b,b));
			// winding number
		bvec3 c = bvec3(p.y>=vertex.polygonVertex[i].y,p.y<vertex.polygonVertex[j].y,e.x*w.y>e.y*w.x);
		if(all(c) || all(not(c))) s*=-1.0;
	}
	return s*sqrt(d);
}

void main() {
	float d = polygon(vPos);
	fragColor = pushConsts.innerColor;
	fragColor.a = 1.0 - smoothstep(-0.003, 0.003, d);
}

The SSBO is declared in the following way:
in polygon.hpp

struct BufferData {
    VkBuffer buffer;
    VkDeviceMemory memory;
    VkDeviceSize size = 0; 
};

BufferData ssboBuffer;

Polygon Coordinates:

std::vector<glm::vec2> polygonCoords = {
	{220.F, 130.F}, {310.F, 110.F}, {380.F, 175.F}, {275.F, 240.F}, {260.F, 280.F}
};

In polygon.cpp:
Buffer Creation (I tried different flags here or staging without success) :

ssboBuffer.size = polygonCoords.size()*sizeof(glm::vec2);
ssboBuffer.buffer = getDevice().createBuffer(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, ssboBuffer.size, &ssboBuffer.memory, polygonCoords.data());

DescriptorPoolSize is initialized as VK_DESCRIPTOR_TYPE_STORAGE_BUFFER .
LayoutBinding:

VkDescriptorSetLayoutBinding ssboBinding {};
setLayoutBinding.descriptorType  = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
setLayoutBinding.stageFlags      = VK_SHADER_STAGE_FRAGMENT_BIT;
setLayoutBinding.binding         = 0;
setLayoutBinding.descriptorCount = 1;

vkCreateDescriptorSetLayout(getDevice().getHandle(), &ssboLayout, nullptr, &ssboDescriptorSetLayout);

DescriptorSet:

VkDescriptorSetAllocateInfo descriptorSetAllocateInfo {};
descriptorSetAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
descriptorSetAllocateInfo.descriptorPool     = descriptorPool;
descriptorSetAllocateInfo.pSetLayouts        = &ssboDescriptorSetLayout;
descriptorSetAllocateInfo.descriptorSetCount = 1;
vkAllocateDescriptorSets(getDevice().getHandle(), &ssboAllocInfo, &ssboDescriptor);

Write DescriptorSet:

VkDescriptorBufferInfo polyCoords{};
polyCoords.buffer = ssboBuffer.buffer;
polyCoords.range = VK_WHOLE_SIZE;
polyCoords.offset = 0;


VkWriteDescriptorSet writeDescriptorSet {};
writeDescriptorSet.sType           =     VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
writeDescriptorSet.dstSet          = ssboDescriptor;
writeDescriptorSet.descriptorType  = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
writeDescriptorSet.dstBinding      = 0;
writeDescriptorSet.pBufferInfo     = &polyCoords;
writeDescriptorSet.descriptorCount = 1;


vkUpdateDescriptorSets(getDevice().getHandle(), 1, &writeDescriptorSet, 0, NULL);

Inside VkPipelineLayoutCreateInfo:

pipelineLayoutCreateInfo.pSetLayouts = &ssboDescriptorSetLayout;
pipelineLayoutCreateInfo.setLayoutCount = 1;

CommandBuffer:
vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &ssboDescriptor, 0, NULL);

What I’m missing? I Cann’t see the error. I found other similar posts in this forum, however I couldn’t find a solution yet.
I’m currently working on MacOs 10.15 with the last Vulkan SDK. I’ll appreciate any help.

It is some kind of Metal error. You might have better luck asking at the MoltenVK repo.

I assume you otherwisely use Validation Layers?

@krOoze
Thanks for your answer. Yes, I use validation Layers, the error message is at the beginning of the post:

validateFunctionArguments:3476: failed assertion `Fragment Function(main0): missing buffer binding at index 14 for spvBufferSizeConstants[0].’

I posted here first because I wasn’t sure I made a mistake. I’ll ask at the MoltenVK repo.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.