Spent way too long debugging a missing struct member in VkWriteDescriptorSet

main
noah metz 2024-01-10 19:32:01 -07:00
parent 2e0de3cc93
commit 26b5af16b3
2 changed files with 36 additions and 21 deletions

@ -1,9 +1,13 @@
#version 450 #version 450
layout(binding = 0) uniform UniformBufferObject { layout(set = 0, binding = 0) uniform SceneUniform {
mat4 view; mat4 view;
mat4 proj; mat4 proj;
} ubo; } scene;
layout(set = 2, binding = 0) uniform ModelUniform {
mat4 model;
} model_ubo;
layout(location = 0) in vec3 inPosition; layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inColor; layout(location = 1) in vec3 inColor;
@ -11,6 +15,6 @@ layout(location = 1) in vec3 inColor;
layout(location = 0) out vec3 fragColor; layout(location = 0) out vec3 fragColor;
void main() { void main() {
gl_Position = ubo.proj * ubo.view * vec4(inPosition, 1.0); gl_Position = scene.proj * scene.view * model_ubo.model * vec4(inPosition, 1.0);
fragColor = inColor; fragColor = inColor;
} }

@ -1829,6 +1829,8 @@ void command_draw_object(Material material, Object object, uint32_t frame_num, V
VkDescriptorSet* descriptor_sets = maybe_descriptors.value; VkDescriptorSet* descriptor_sets = maybe_descriptors.value;
vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, material.layout, 2, 1, &descriptor_sets[frame_num], 0, 0); vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, material.layout, 2, 1, &descriptor_sets[frame_num], 0, 0);
} else {
fprintf(stderr, "test\n");
} }
vkCmdDrawIndexed(command_buffer, mesh->index_count, 1, 0, 0, 0); vkCmdDrawIndexed(command_buffer, mesh->index_count, 1, 0, 0, 0);
@ -2289,7 +2291,7 @@ Material create_simple_mesh_material(VkDevice device, VkExtent2D extent, VkRende
PipelineLayout simple_layout = { PipelineLayout simple_layout = {
.object_bindings = object_set_bindings, .object_bindings = object_set_bindings,
.object_bindings_count = sizeof(object_set_bindings)/sizeof(*object_set_bindings), .object_bindings_count = sizeof(object_set_bindings)/sizeof(VkDescriptorSetLayoutBinding),
}; };
Map object_descriptor_mappings = map_create(8, 2); Map object_descriptor_mappings = map_create(8, 2);
@ -2329,16 +2331,21 @@ Material create_texture_mesh_material(VkDevice device, VkExtent2D extent, VkRend
Material tmp = {}; Material tmp = {};
return tmp; return tmp;
} }
VkPipelineShaderStageCreateInfo shader_stages[2] = {}; VkPipelineShaderStageCreateInfo shader_stages[2] = {
shader_stages[0].sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO_EXT; {
shader_stages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; .sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO_EXT,
shader_stages[0].module = vert_shader; .stage = VK_SHADER_STAGE_VERTEX_BIT,
shader_stages[0].pName = "main"; .module = vert_shader,
.pName = "main",
},
{
.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO_EXT,
.stage = VK_SHADER_STAGE_FRAGMENT_BIT,
.module = frag_shader,
.pName = "main",
},
};
shader_stages[1].sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO_EXT;
shader_stages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
shader_stages[1].module = frag_shader;
shader_stages[1].pName = "main";
VkVertexInputBindingDescription bindings[] = { VkVertexInputBindingDescription bindings[] = {
{ {
@ -3119,10 +3126,12 @@ Object create_simple_mesh_object(Material* simple_mesh_material, VkPhysicalDevic
return zero; return zero;
} }
glm_quat_identity(position->rotation); glm_quat_identity(position->rotation);
glm_vec3_adds(position->scale, 1.0f, position->scale); position->scale[0] = 1.f;
position->scale[1] = 1.f;
position->scale[2] = 1.f;
position->position[0] = 0.0f; position->position[0] = 0.0f;
position->position[1] = 0.0f; position->position[1] = 0.0f;
position->position[2] = 2.0f; position->position[2] = 0.0f;
bool map_result = map_add(&object.attributes, ATTRIBUTE_ID_POSITION, position); bool map_result = map_add(&object.attributes, ATTRIBUTE_ID_POSITION, position);
if(map_result == 0) { if(map_result == 0) {
return zero; return zero;
@ -3137,6 +3146,7 @@ Object create_simple_mesh_object(Material* simple_mesh_material, VkPhysicalDevic
if(maybe_ptrs.has_value == false) { if(maybe_ptrs.has_value == false) {
return zero; return zero;
} }
void*** ptrs = maybe_ptrs.value; void*** ptrs = maybe_ptrs.value;
for(uint32_t i = 0; i < max_frames_in_flight; i++) { for(uint32_t i = 0; i < max_frames_in_flight; i++) {
VkResult result = vkMapMemory(device, position_buffers[i].memory, 0, sizeof(struct ModelUBO), 0, &ptrs[i][0]); VkResult result = vkMapMemory(device, position_buffers[i].memory, 0, sizeof(struct ModelUBO), 0, &ptrs[i][0]);
@ -3156,6 +3166,7 @@ Object create_simple_mesh_object(Material* simple_mesh_material, VkPhysicalDevic
.dstBinding = 0, .dstBinding = 0,
.dstArrayElement = 0, .dstArrayElement = 0,
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.descriptorCount = 1,
.pBufferInfo = &buffer_info, .pBufferInfo = &buffer_info,
}; };
@ -3209,9 +3220,9 @@ Object create_texture_mesh_object(Material* texture_mesh_material, VkPhysicalDev
return zero; return zero;
} }
glm_quat_identity(position->rotation); glm_quat_identity(position->rotation);
position->scale[0] = 1.f; position->scale[0] = 0.5f;
position->scale[1] = 1.f; position->scale[1] = 0.5f;
position->scale[2] = 1.f; position->scale[2] = 0.5f;
position->position[0] = 0.0f; position->position[0] = 0.0f;
position->position[1] = 0.0f; position->position[1] = 0.0f;
position->position[2] = 1.0f; position->position[2] = 1.0f;
@ -3389,15 +3400,15 @@ void main_loop(GLFWwindow* window, VulkanContext* context) {
return; return;
} }
Object* objects[] = {&triangle_object_textured, &triangle_object}; Object* objects[] = {&triangle_object, &triangle_object_textured};
Material materials[] = {texture_mesh_material, simple_mesh_material}; Material materials[] = {simple_mesh_material, texture_mesh_material};
uint32_t objects_counts[] = {1, 1}; uint32_t objects_counts[] = {1, 1};
context->current_frame = 0; context->current_frame = 0;
while(!glfwWindowShouldClose(window)) { while(!glfwWindowShouldClose(window)) {
glfwPollEvents(); glfwPollEvents();
VkResult result = draw_frame(context, &scene, 2, materials, objects_counts, objects); VkResult result = draw_frame(context, &scene, sizeof(materials)/sizeof(Material), materials, objects_counts, objects);
if(result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR) { if(result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR) {
recreate_swap_chain(context); recreate_swap_chain(context);
} else if(result != VK_SUCCESS) { } else if(result != VK_SUCCESS) {