|  |  |  | @ -978,30 +978,37 @@ VkRenderPass create_render_pass(VkDevice device, VkSurfaceFormatKHR format, VkFo | 
		
	
		
			
				|  |  |  |  |     .layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, | 
		
	
		
			
				|  |  |  |  |   }; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   VkSubpassDescription subpass = { | 
		
	
		
			
				|  |  |  |  |     .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS, | 
		
	
		
			
				|  |  |  |  |     .colorAttachmentCount = sizeof(color_attachment_refs)/sizeof(VkAttachmentReference), | 
		
	
		
			
				|  |  |  |  |     .pColorAttachments = color_attachment_refs, | 
		
	
		
			
				|  |  |  |  |     .pDepthStencilAttachment = &depth_attachment_ref, | 
		
	
		
			
				|  |  |  |  |   // Create a subpass with the color and depth attachments
 | 
		
	
		
			
				|  |  |  |  |   VkSubpassDescription subpasses[] = { | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |       .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS, | 
		
	
		
			
				|  |  |  |  |       .colorAttachmentCount = sizeof(color_attachment_refs)/sizeof(VkAttachmentReference), | 
		
	
		
			
				|  |  |  |  |       .pColorAttachments = color_attachment_refs, | 
		
	
		
			
				|  |  |  |  |       .pDepthStencilAttachment = &depth_attachment_ref, | 
		
	
		
			
				|  |  |  |  |     }, | 
		
	
		
			
				|  |  |  |  |   }; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   VkSubpassDependency dependency = { | 
		
	
		
			
				|  |  |  |  |     .srcSubpass = VK_SUBPASS_EXTERNAL, | 
		
	
		
			
				|  |  |  |  |     .dstSubpass = 0, | 
		
	
		
			
				|  |  |  |  |     .srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT, | 
		
	
		
			
				|  |  |  |  |     .srcAccessMask = 0, | 
		
	
		
			
				|  |  |  |  |     .dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT, | 
		
	
		
			
				|  |  |  |  |     .dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, | 
		
	
		
			
				|  |  |  |  |   // This basically says "make sure nothing else is writing to the depth_stencil or the color attachment during the pipeline
 | 
		
	
		
			
				|  |  |  |  |   VkSubpassDependency dependencies[] = { | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |       .srcSubpass = VK_SUBPASS_EXTERNAL, | 
		
	
		
			
				|  |  |  |  |       .dstSubpass = 0, | 
		
	
		
			
				|  |  |  |  |       .srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT, | 
		
	
		
			
				|  |  |  |  |       .srcAccessMask = 0, | 
		
	
		
			
				|  |  |  |  |       .dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT, | 
		
	
		
			
				|  |  |  |  |       .dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, | 
		
	
		
			
				|  |  |  |  |       .dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT, | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   }; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   VkRenderPassCreateInfo render_info = { | 
		
	
		
			
				|  |  |  |  |     .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, | 
		
	
		
			
				|  |  |  |  |     .attachmentCount = sizeof(attachments)/sizeof(VkAttachmentDescription), | 
		
	
		
			
				|  |  |  |  |     .pAttachments = attachments, | 
		
	
		
			
				|  |  |  |  |     .subpassCount = 1, | 
		
	
		
			
				|  |  |  |  |     .pSubpasses = &subpass, | 
		
	
		
			
				|  |  |  |  |     .dependencyCount = 1, | 
		
	
		
			
				|  |  |  |  |     .pDependencies = &dependency, | 
		
	
		
			
				|  |  |  |  |     .subpassCount = sizeof(subpasses)/sizeof(VkSubpassDescription), | 
		
	
		
			
				|  |  |  |  |     .pSubpasses = subpasses, | 
		
	
		
			
				|  |  |  |  |     .dependencyCount = sizeof(dependencies)/sizeof(VkSubpassDependency), | 
		
	
		
			
				|  |  |  |  |     .pDependencies = dependencies, | 
		
	
		
			
				|  |  |  |  |   }; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   VkRenderPass render_pass; | 
		
	
	
		
			
				
					|  |  |  | @ -2800,28 +2807,38 @@ VkResult draw_frame(VulkanContext* context, SceneContext* scene, uint32_t materi | 
		
	
		
			
				|  |  |  |  |   return vkQueuePresentKHR(context->queues.present, &present_info); | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | Object create_simple_mesh_object(Material* simple_mesh_material, VkPhysicalDeviceMemoryProperties memories, VkDevice device, VkCommandPool transfer_pool, VkQueue transfer_queue, uint32_t max_frames_in_flight, VkDescriptorPool pool) { | 
		
	
		
			
				|  |  |  |  | Object create_simple_mesh_object(PlyMesh ply_mesh, Material* simple_mesh_material, VkPhysicalDeviceMemoryProperties memories, VkDevice device, VkCommandPool transfer_pool, VkQueue transfer_queue, uint32_t max_frames_in_flight, VkDescriptorPool pool) { | 
		
	
		
			
				|  |  |  |  |   Object zero = {}; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   GPUPage* mesh_memory = NULL; | 
		
	
		
			
				|  |  |  |  |   VkResult result = gpu_page_allocate(device, memories, 10000, 0xFFFFFFFF, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT, &mesh_memory); | 
		
	
		
			
				|  |  |  |  |   VkResult result = gpu_page_allocate(device, memories, 100000, 0xFFFFFFFF, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT, &mesh_memory); | 
		
	
		
			
				|  |  |  |  |   if(result != VK_SUCCESS) { | 
		
	
		
			
				|  |  |  |  |     return zero; | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   GPUPage* transfer_memory = NULL; | 
		
	
		
			
				|  |  |  |  |   result = gpu_page_allocate(device, memories, 100000, 0xFFFFFFFF, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, &transfer_memory); | 
		
	
		
			
				|  |  |  |  |   result = gpu_page_allocate(device, memories, 200000, 0xFFFFFFFF, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, &transfer_memory); | 
		
	
		
			
				|  |  |  |  |   if(result != VK_SUCCESS) { | 
		
	
		
			
				|  |  |  |  |     return zero; | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   GPUBuffer transfer_buffer = {0}; | 
		
	
		
			
				|  |  |  |  |   result = gpu_buffer_malloc(device, transfer_memory, 10000, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, &transfer_buffer); | 
		
	
		
			
				|  |  |  |  |   result = gpu_buffer_malloc(device, transfer_memory, 100000, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, &transfer_buffer); | 
		
	
		
			
				|  |  |  |  |   if(result != VK_SUCCESS) { | 
		
	
		
			
				|  |  |  |  |     return zero; | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Mesh* mesh = load_mesh_to_buffer(device, mesh_memory, transfer_buffer, 4, sizeof(struct Vertex), (void*)vertices, 6, sizeof(uint16_t), (void*)indices, transfer_pool, transfer_queue); | 
		
	
		
			
				|  |  |  |  |   struct Vertex* tmp = malloc(sizeof(struct Vertex)*ply_mesh.vertex_count); | 
		
	
		
			
				|  |  |  |  |   for(uint32_t i = 0; i < ply_mesh.vertex_count; i++) { | 
		
	
		
			
				|  |  |  |  |     tmp[i].pos[0] = ply_mesh.position[i][0]; | 
		
	
		
			
				|  |  |  |  |     tmp[i].pos[1] = ply_mesh.position[i][1]; | 
		
	
		
			
				|  |  |  |  |     tmp[i].pos[2] = ply_mesh.position[i][2]; | 
		
	
		
			
				|  |  |  |  |     tmp[i].color[0] = ply_mesh.colour[i][0]; | 
		
	
		
			
				|  |  |  |  |     tmp[i].color[1] = ply_mesh.colour[i][1]; | 
		
	
		
			
				|  |  |  |  |     tmp[i].color[2] = ply_mesh.colour[i][2]; | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Mesh* mesh = load_mesh_to_buffer(device, mesh_memory, transfer_buffer, ply_mesh.vertex_count, sizeof(struct Vertex), (void*)tmp, ply_mesh.index_count, sizeof(uint16_t), (void*)ply_mesh.index, transfer_pool, transfer_queue); | 
		
	
		
			
				|  |  |  |  |   if(mesh == 0) { | 
		
	
		
			
				|  |  |  |  |     return zero; | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
	
		
			
				
					|  |  |  | @ -2862,9 +2879,9 @@ Object create_simple_mesh_object(Material* simple_mesh_material, VkPhysicalDevic | 
		
	
		
			
				|  |  |  |  |     return zero; | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  |   glm_quat_identity(position->rotation); | 
		
	
		
			
				|  |  |  |  |   position->scale[0] = 10.f; | 
		
	
		
			
				|  |  |  |  |   position->scale[1] = 10.f; | 
		
	
		
			
				|  |  |  |  |   position->scale[2] = 10.f; | 
		
	
		
			
				|  |  |  |  |   position->scale[0] = 1.f; | 
		
	
		
			
				|  |  |  |  |   position->scale[1] = 1.f; | 
		
	
		
			
				|  |  |  |  |   position->scale[2] = 1.f; | 
		
	
		
			
				|  |  |  |  |   position->position[0] = 0.0f; | 
		
	
		
			
				|  |  |  |  |   position->position[1] = 0.0f; | 
		
	
		
			
				|  |  |  |  |   position->position[2] = 1.1f; | 
		
	
	
		
			
				
					|  |  |  | @ -3006,7 +3023,7 @@ Object create_texture_mesh_object(Material* texture_mesh_material, VkPhysicalDev | 
		
	
		
			
				|  |  |  |  |   return object; | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | void main_loop(GLFWwindow* window, VulkanContext* context) { | 
		
	
		
			
				|  |  |  |  | void main_loop(PlyMesh ply_mesh, GLFWwindow* window, VulkanContext* context) { | 
		
	
		
			
				|  |  |  |  |   SceneContext scene = create_scene_context(context->device, context->memories, context->max_frames_in_flight); | 
		
	
		
			
				|  |  |  |  |   if(scene.pool == VK_NULL_HANDLE) { | 
		
	
		
			
				|  |  |  |  |     return; | 
		
	
	
		
			
				
					|  |  |  | @ -3039,7 +3056,7 @@ void main_loop(GLFWwindow* window, VulkanContext* context) { | 
		
	
		
			
				|  |  |  |  |     return; | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Object triangle_object = create_simple_mesh_object(&simple_mesh_material, context->memories, context->device, context->transfer_command_pool, context->queues.transfer, context->max_frames_in_flight, simple_pool); | 
		
	
		
			
				|  |  |  |  |   Object triangle_object = create_simple_mesh_object(ply_mesh, &simple_mesh_material, context->memories, context->device, context->transfer_command_pool, context->queues.transfer, context->max_frames_in_flight, simple_pool); | 
		
	
		
			
				|  |  |  |  |   if(triangle_object.attributes.buckets == 0) { | 
		
	
		
			
				|  |  |  |  |     fprintf(stderr, "failed to create simple mesh object\n"); | 
		
	
		
			
				|  |  |  |  |     return; | 
		
	
	
		
			
				
					|  |  |  | @ -3201,7 +3218,7 @@ int main() { | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   glfwSetKeyCallback(window, key_callback); | 
		
	
		
			
				|  |  |  |  |   main_loop(window, context); | 
		
	
		
			
				|  |  |  |  |   main_loop(monkey, window, context); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   cleanup(window, context); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
	
		
			
				
					|  |  |  | 
 |