So I have a debug callback that says
Wrong component type or count. repeatedly with
Buffer object 4 (bound to GL_SHADER_STORAGE_BUFFER, and GL_SHADER_STORAGE_BUFFER (1), usage hint is GL_STREAM_COPY) is being copied/moved from VIDEO memory to DMA CACHED memory.
it jumps to 7 and repeates every value +2
this is the shader
#version 430
layout(local_size_x = 32, local_size_y = 1, local_size_z = 1) in;
struct nessVertex {
vec3 position;
ivec4 m_BoneIDs;
vec4 m_Weights;
};
// For SSBO
layout(std140, binding = 0) buffer VertexBuffer {
nessVertex vertices[];
};
layout(std140, binding = 1) buffer PositionBuffer {
vec3 positions[];
};
uniform uint arraySize;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
uniform mat4 transforms[100];
void main() {
uint index = gl_GlobalInvocationID.x; // For compute shader example
if (index < arraySize) {
vec3 position = vertices[index].position;
ivec4 boneIDs = vertices[index].m_BoneIDs;
vec4 weights = vertices[index].m_Weights;
vec4 totalPosition = vec4(1.0f);
for(int i = 0 ; i < 4 ; i++)
{
if(boneIDs[i] == -1)
continue;
if (boneIDs[i] >= 100){
totalPosition = vec4(position, 1);
}
vec4 localPosition = transforms[boneIDs[i]] * vec4(position,1.0f);
totalPosition += localPosition * weights[i];
}
positions[index] = totalPosition.xyz;
}
}
I have a class to bind the buffers:
#include "ModelBind.h"
ModelBind::~ModelBind()
{
glDeleteBuffers(1, &buffer);
}
void ModelBind::load(vector<nessVertex> vertices)
{
this->vertices = vertices;
}
void ModelBind::bind()
{
if (first) {
glGenBuffers(1, &buffer);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer); // For SSBO, or GL_ARRAY_BUFFER for VBO
glBufferData(GL_SHADER_STORAGE_BUFFER, vertices.size() * sizeof(nessVertex), vertices.data(), GL_STATIC_DRAW);
// Bind to binding point 0 for SSBO
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, buffer);
glGenBuffers(1, &outputBuffer);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, outputBuffer);
glBufferData(GL_SHADER_STORAGE_BUFFER, vertices.size() * sizeof(glm::vec3), nullptr, GL_STREAM_COPY);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, outputBuffer);
first = false;
}
else {
//Dynamic write
//glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer);
//glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, vertices.size() * sizeof(nessVertex), vertices.data());
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, buffer);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, outputBuffer);
glBufferData(GL_SHADER_STORAGE_BUFFER, vertices.size() * sizeof(glm::vec3), nullptr, GL_STREAM_COPY);
}
}
void ModelBind::retreive()
{
glBindBuffer(GL_SHADER_STORAGE_BUFFER, outputBuffer);
glm::vec3* outputData = (glm::vec3*)glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_READ_ONLY);
outData = vector<glm::vec3>(outputData, outputData + vertices.size());
glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
}
the main code is
vector<nessVertex> pasver = mymod.nesverts;
GLuint nessize = (int)ceil(pasver.size() / 32);
GLuint totsize = pasver.size();
ModelBind mbind;
mbind.load(pasver);
acompute.use();
for (int j = 0; j < transforms.size(); ++j) acompute.setUniform("transforms[" + std::to_string(j) + "]", transforms[j]);
mbind.bind();
acompute.setUniform("arraySize", totsize);
acompute.RunComputeShader(nessize, 1, 1);
mbind.retreive();
this is my vertex
struct nessVertex {
glm::vec3 position;
int m_BoneIDs[4];
float m_Weights[4];
};
this what I have in my shader compiler
void ComputeShader::RunComputeShader(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
{
glUseProgram(program);
// Dispatch the compute shader
glDispatchCompute(numGroupsX, numGroupsY, numGroupsZ);
// Make sure writing to image or buffer is done
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
}