| 
						
						
							
								
							
						
						
					 | 
				
			
			 | 
			 | 
			
				@ -2,16 +2,14 @@
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				#include "gpu.h"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				#include "vulkan/vulkan_core.h"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				VkResult create_hex_pipeline(
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VkDevice device,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VkRenderPass render_pass,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  GraphicsPipeline* graphics,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  ComputePipeline* compute) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				VkResult create_hex_context(
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  RenderContext* gpu,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  HexContext* context) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VkResult result;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  // Compute Pipeline
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VkShaderModule compute_shader = load_shader_file("shader/hex.comp.spv", device);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VkShaderModule compute_shader = load_shader_file("shader/hex.comp.spv", gpu->device);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  if(compute_shader == VK_NULL_HANDLE) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    return VK_ERROR_UNKNOWN;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  }
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -35,20 +33,20 @@ VkResult create_hex_pipeline(
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    .pushConstantRangeCount = 1,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  };
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VK_RESULT(vkCreatePipelineLayout(device, &compute_layout_info, NULL, &compute->layout));
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VK_RESULT(vkCreatePipelineLayout(gpu->device, &compute_layout_info, NULL, &context->compute.layout));
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VkComputePipelineCreateInfo compute_pipeline_info = {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    .stage = compute_shader_stage,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    .layout = compute->layout,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    .layout = context->compute.layout,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  };
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VK_RESULT(vkCreateComputePipelines(device, VK_NULL_HANDLE, 1, &compute_pipeline_info, NULL, &compute->pipeline));
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VK_RESULT(vkCreateComputePipelines(gpu->device, VK_NULL_HANDLE, 1, &compute_pipeline_info, NULL, &context->compute.pipeline));
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  // Graphics Pipeline
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VkShaderModule vert_shader = load_shader_file("shader/hex.vert.spv", device);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VkShaderModule frag_shader = load_shader_file("shader/hex.frag.spv", device);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VkShaderModule vert_shader = load_shader_file("shader/hex.vert.spv", gpu->device);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VkShaderModule frag_shader = load_shader_file("shader/hex.frag.spv", gpu->device);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VkPipelineShaderStageCreateInfo graphics_stages[] = {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    {
 | 
			
		
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
			
			 | 
			 | 
			
				@ -77,7 +75,7 @@ VkResult create_hex_pipeline(
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    .pushConstantRangeCount = 1,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  };
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VK_RESULT(vkCreatePipelineLayout(device, &graphics_layout_info, NULL, &graphics->layout));
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VK_RESULT(vkCreatePipelineLayout(gpu->device, &graphics_layout_info, NULL, &context->graphics.layout));
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VkPipelineVertexInputStateCreateInfo vertex_info = {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
 | 
			
		
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
			
			 | 
			 | 
			
				@ -180,7 +178,7 @@ VkResult create_hex_pipeline(
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VkGraphicsPipelineCreateInfo graphics_pipeline_info = {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    .layout = graphics->layout,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    .layout = context->graphics.layout,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    .stageCount = sizeof(graphics_stages)/sizeof(VkPipelineShaderStageCreateInfo),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    .pStages = graphics_stages,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    .pVertexInputState = &vertex_info,
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -191,13 +189,42 @@ VkResult create_hex_pipeline(
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    .pDynamicState = &dynamic_info,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    .pMultisampleState = &multisample_info,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    .pDepthStencilState = &depth_info,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    .renderPass = render_pass,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    .renderPass = gpu->render_pass,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    .subpass = 0,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    .basePipelineHandle = VK_NULL_HANDLE,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    .basePipelineIndex = -1,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  };
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VK_RESULT(vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &graphics_pipeline_info, NULL, &graphics->pipeline));
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VK_RESULT(vkCreateGraphicsPipelines(gpu->device, VK_NULL_HANDLE, 1, &graphics_pipeline_info, NULL, &context->graphics.pipeline));
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  glm_perspective(30.0, (float)gpu->swapchain_extent.width/(float)gpu->swapchain_extent.height, 0.01, 99.9, context->data.proj);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  glm_mat4_identity(context->data.view);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VK_RESULT(create_storage_buffer(
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        gpu->allocator, 
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        0,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        sizeof(GPUHexContext),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        &context->context,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        &context->context_memory));
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  context->address = buffer_address(gpu->device, context->context);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VK_RESULT(add_transfer(&context->data, context->context, 0, sizeof(GPUHexContext), gpu->current_frame, gpu));
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  return VK_SUCCESS;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				VkResult create_hex_region(uint32_t x, uint32_t y, HexRegion* region, RenderContext* gpu) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VkResult result;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  region->x = x;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  region->y = y;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VK_RESULT(create_storage_buffer(
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        gpu->allocator,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        0,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        sizeof(GPUHexRegion),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        ®ion->region,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        ®ion->region_memory));
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  VK_RESULT(add_transfer(®ion->x, region->region, offsetof(GPUHexRegion, x), sizeof(uint32_t)*2, 0, gpu));
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  region->address = buffer_address(gpu->device, region->region);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				  return VK_SUCCESS;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				}
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
					 | 
				
			
			 | 
			 | 
			
				
 
 |