I have two draw calls that are rendering the same mesh, with the same buffers, same shaders, etc. The first draw call renders on the scene as expected, the second draw call renders nothing because the model matrix is 0 for some reason. The only difference between the draw calls is the firstInstance parameter, which I use to index into a SSBO to get the model matrix and texture.
#How do I debug this?
11 messages · Page 1 of 1 (latest)
The shader is pretty simple
#version 450
#extension GL_EXT_nonuniform_qualifier : enable
struct Frame_Data {
mat4 view;
mat4 projection;
mat4 view_projection;
vec2 viewport_size;
};
struct Draw_Cmd {
mat4 transform;
uint texture_index;
uint p0; // padding for alignment
uint p1;
uint p2;
};
layout(location=0) in vec4 v_pos;
layout(location=1) in vec4 v_normal;
layout(location=2) in vec2 v_uv;
layout(set=0, binding=0) uniform Per_Frame_Data { Frame_Data frame_data; };
layout(set=1, binding=0) readonly buffer Draw_Commands { Draw_Cmd draw_cmds[]; };
layout(location=1) out vec2 out_uv;
layout(location=2) flat out uint out_tex_index;
void main() {
Draw_Cmd cmd = draw_cmds[gl_InstanceIndex];
gl_Position = v_pos * cmd.transform * frame_data.view_projection;
out_tex_index = cmd.texture_index;
out_uv = v_uv;
}```
so I use gl_InstanceIndex to get the model matrix for this draw call
I've confirmed that the firstInstance is 0 for the first call and 1 for the second call
I've also confirmed that the data in the buffer is correct, here are screen shots of the first entry and second entry
does the problem go away if you use scalar block layout and remove any padding for alignment
The layout of the struct works when I use it with the same shader but through instanced indirect code path, rather than individual draw calls
hm
solved: I was passing the wrong buffer size when writing the descriptor set. Thanks for being a rubber ducky 
surprised it didn't throw an error for out-of-bounds access
you only get that with GPU assisted validation