Transfer data CPU -> GPU

Hi,

I’m still working on instancing and now I’m trying to give to each particle its own color, but got some weird results…
I’ve created a struct:

struct ParticleShaderData {
	glm::mat4 modelMatrix;
	glm::vec3 color;
};

This structure contains the informations of each particle. I stored each of those struct in a std::vector then send them to cpu


		ssbo.datas.push_back({ model, color });//datas is a std::vector<ParticleShaderData>
		void *data;
		vkMapMemory(device, modelBuffer->memory(), 0, instanceCount * sizeof(ParticleShaderData), 0, &data);
		memcpy(data, ssbo.datas.data(), instanceCount * sizeof(ParticleShaderData));
		vkUnmapMemory(device, modelBuffer->memory());

My descriptor sets and layouts are fine.

The vertex shader looks like:

struct ParticleData{
	mat4 model;
        vec3 color;
};

layout(binding = 2) buffer SSBOject { 
    ParticleData datas[];
} ssbo;

Thanks for your help.:smiley:

You’re using a vec3 in a UBO/SSBO. Please stop doing that.

Now in the case of your struct, that probably isn’t your issue.

The other problems I see in your code is:

  1. Treating vkMapMemory like glMapBufferRange. Mapping should be something you should do to memory precisely once; Vulkan operations can access mapped memory just fine (and in OpenGL via persistent buffers).

  2. A completely lack of synchronization. I don’t see anything which ensures the visibility of this mapped memory to the consuming operation.

Thanks for your answer

[QUOTE=Alfonse Reinheart;43056]You’re using a vec3 in a UBO/SSBO. Please stop doing that.
[/QUOTE]
As mentionned in the link, I’ve changed my vec3 to vec4 and it SEEMS to be working now.

[QUOTE=Alfonse Reinheart;43056]1) Treating vkMapMemory like glMapBufferRange. Mapping should be something you should do to memory precisely once; Vulkan operations can access mapped memory just fine (and in OpenGL via persistent buffers).
[/QUOTE]
Actually, I have a for loop which set each particleShaderData and then store it. So I only use vkMapMemory once, out of that loop. (I don’t know if it answer to your question)

For this one, I must admit that I’ve absolutely no idea of what you are talking about.