Advertisement
Guest User

Untitled

a guest
Dec 11th, 2022
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 26.40 KB | None | 0 0
  1. #include "vk_local.h"
  2.  
  3. //vk_pipeline.c
  4. //Handles everything relating to shaders, pipelines, descriptor sets, and vertex attributes.
  5.  
  6. //There's waaaay too much data, so while I'm loathe to do this due to it hiding information, I'm putting this in a header for now
  7. //TODO: There should be a better way to do this that isn't as cluttered.
  8. #include "vk_pipeline_data.h"
  9.  
  10. VkPipelineLayout screen_pipeline_layout;
  11. VkPipelineLayout world_pipeline_layout;
  12. VkPipelineLayout bmodel_pipeline_layout;
  13. VkPipelineLayout alias_pipeline_layout;
  14. VkPipelineLayout sky_pipeline_layout;
  15. VkPipelineLayout particle_pipeline_layout;
  16. //Internal pipeline handles, since they're all generated at once. The values in vklogicaldevice_t will be assigned from this pool.
  17. int num_pipelines;
  18. VkPipeline pipelines[32];
  19.  
  20. void VK_CreateDescriptorSets(vklogicaldevice_t* device)
  21. {
  22.     /*typedef struct VkDescriptorSetLayoutCreateInfo {
  23.     VkStructureType                        sType;
  24.     const void*                            pNext;
  25.     VkDescriptorSetLayoutCreateFlags       flags;
  26.     uint32_t                               bindingCount;
  27.     const VkDescriptorSetLayoutBinding*    pBindings;
  28. } VkDescriptorSetLayoutCreateInfo;*/
  29.     VkDescriptorSetLayoutCreateInfo projection_modelview_info =
  30.     {
  31.         VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
  32.         nullptr,
  33.         0,
  34.         1, //bindingCount
  35.         &projection_layout_binding //pBindings
  36.     };
  37.    
  38.     VkDescriptorSetLayoutCreateInfo modelview_info =
  39.     {
  40.         VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
  41.         nullptr,
  42.         0,
  43.         1,
  44.         &modelview_layout_binding,
  45.     }; 
  46.  
  47.     VkDescriptorSetLayoutCreateInfo texture_info =
  48.     {
  49.         VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
  50.         nullptr,
  51.         0,
  52.         1,
  53.         &texture_layout_binding,
  54.     };
  55.    
  56.     VkDescriptorSetLayoutCreateInfo dynamic_uniform_layout_info =
  57.     {
  58.         VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
  59.         nullptr,
  60.         0,
  61.         1,
  62.         &dynamic_uniform_layout_binding,
  63.     };
  64.    
  65.     VkDescriptorSetLayoutCreateInfo storage_layout_info =
  66.     {
  67.         VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
  68.         nullptr,
  69.         0,
  70.         1,
  71.         &alias_storage_layout_binding,
  72.     };
  73.  
  74.     VK_CHECK(vkCreateDescriptorSetLayout(device->handle, &projection_modelview_info, NULL, &device->projection_modelview_layout));
  75.     VK_CHECK(vkCreateDescriptorSetLayout(device->handle, &texture_info, NULL, &device->sampled_texture_layout));
  76.     VK_CHECK(vkCreateDescriptorSetLayout(device->handle, &dynamic_uniform_layout_info, NULL, &device->dynamic_uniform_layout));
  77.     VK_CHECK(vkCreateDescriptorSetLayout(device->handle, &storage_layout_info, NULL, &device->storage_buffer_layout));
  78.     VK_CHECK(vkCreateDescriptorSetLayout(device->handle, &modelview_info, NULL, &device->modelview_layout));
  79.  
  80.     VkDescriptorSetLayout screen_layouts[] = { device->projection_modelview_layout, device->sampled_texture_layout };
  81.     VkDescriptorSetLayout world_layouts[] = { device->projection_modelview_layout, device->sampled_texture_layout, device->sampled_texture_layout };
  82.     VkDescriptorSetLayout thing_layouts[] = { device->projection_modelview_layout, device->sampled_texture_layout, device->sampled_texture_layout, device->modelview_layout };
  83.     VkDescriptorSetLayout alias_layouts[] = { device->projection_modelview_layout, device->sampled_texture_layout, device->storage_buffer_layout, device->modelview_layout };
  84.     VkDescriptorSetLayout sky_layouts[] = { device->projection_modelview_layout, device->sampled_texture_layout };
  85.  
  86.     VkPipelineLayoutCreateInfo screen_pipeline_layout_info =
  87.     {
  88.         VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
  89.         nullptr,
  90.         0,
  91.         2, //setLayoutCount
  92.         screen_layouts //pSetLayouts
  93.     };
  94.  
  95.     VK_CHECK(vkCreatePipelineLayout(device->handle, &screen_pipeline_layout_info, NULL, &screen_pipeline_layout));
  96.  
  97.     VkPipelineLayoutCreateInfo world_pipeline_layout_info =
  98.     {
  99.         VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
  100.         nullptr,
  101.         0,
  102.         3,
  103.         world_layouts,
  104.         1, //pushConstantRangeCount
  105.         &light_modulate_range, //pPushConstantRanges
  106.     };
  107.  
  108.     VK_CHECK(vkCreatePipelineLayout(device->handle, &world_pipeline_layout_info, NULL, &world_pipeline_layout));
  109.  
  110.     VkPipelineLayoutCreateInfo bmodel_pipeline_layout_info =
  111.     {
  112.         VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
  113.         nullptr,
  114.         0,
  115.         4,
  116.         thing_layouts,
  117.         1, //pushConstantRangeCount
  118.         &intensity_time_range,  //pPushConstantRanges
  119.     };
  120.  
  121.     VK_CHECK(vkCreatePipelineLayout(device->handle, &bmodel_pipeline_layout_info, NULL, &bmodel_pipeline_layout));
  122.  
  123.     VkPipelineLayoutCreateInfo alias_pipeline_layout_info =
  124.     {
  125.         VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
  126.         nullptr,
  127.         0,
  128.         4,
  129.         alias_layouts,
  130.     };
  131.  
  132.     VK_CHECK(vkCreatePipelineLayout(device->handle, &alias_pipeline_layout_info, NULL, &alias_pipeline_layout));
  133.  
  134.     VkPipelineLayoutCreateInfo sky_pipeline_layout_info =
  135.     {
  136.         VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
  137.         nullptr,
  138.         0,
  139.         2,
  140.         sky_layouts,
  141.         1,
  142.         &sky_spin_range,
  143.     };
  144.  
  145.     VK_CHECK(vkCreatePipelineLayout(device->handle, &sky_pipeline_layout_info, NULL, &sky_pipeline_layout));
  146.  
  147.     VkPipelineLayoutCreateInfo particle_pipeline_layout_info =
  148.     {
  149.         VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
  150.         nullptr,
  151.         0,
  152.         1,
  153.         &device->projection_modelview_layout,
  154.         1, //pushConstantRangeCount
  155.         &particle_size_range, //pPushConstantRanges
  156.     };
  157.  
  158.     VK_CHECK(vkCreatePipelineLayout(device->handle, &particle_pipeline_layout_info, NULL, &particle_pipeline_layout));
  159. }
  160.  
  161. void VK_DestroyDescriptorSets(vklogicaldevice_t* device)
  162. {
  163.     vkDestroyPipelineLayout(device->handle, screen_pipeline_layout, NULL);
  164.     vkDestroyPipelineLayout(device->handle, world_pipeline_layout, NULL);
  165.     vkDestroyPipelineLayout(device->handle, bmodel_pipeline_layout, NULL);
  166.     vkDestroyPipelineLayout(device->handle, alias_pipeline_layout, NULL);
  167.     vkDestroyPipelineLayout(device->handle, sky_pipeline_layout, NULL);
  168.     vkDestroyPipelineLayout(device->handle, particle_pipeline_layout, NULL);
  169.     vkDestroyDescriptorSetLayout(device->handle, device->projection_modelview_layout, NULL);
  170.     vkDestroyDescriptorSetLayout(device->handle, device->sampled_texture_layout, NULL);
  171.     vkDestroyDescriptorSetLayout(device->handle, device->dynamic_uniform_layout, NULL);
  172.     vkDestroyDescriptorSetLayout(device->handle, device->storage_buffer_layout, NULL);
  173.     vkDestroyDescriptorSetLayout(device->handle, device->modelview_layout, NULL);
  174. }
  175.  
  176. void VK_CreatePipelines(vklogicaldevice_t* device)
  177. {
  178.     VK_CHECK(vkCreateShaderModule(device->handle, &generic_colored_frag_info, NULL, &generic_colored_frag_module));
  179.     VK_CHECK(vkCreateShaderModule(device->handle, &screen_colored_vert_info, NULL, &screen_colored_vert_module));
  180.     VK_CHECK(vkCreateShaderModule(device->handle, &screen_textured_frag_info, NULL, &screen_textured_frag_module));
  181.     VK_CHECK(vkCreateShaderModule(device->handle, &screen_textured_vert_info, NULL, &screen_textured_vert_module));
  182.     VK_CHECK(vkCreateShaderModule(device->handle, &world_lightmap_vert_info, NULL, &world_lightmap_vert_module));
  183.     VK_CHECK(vkCreateShaderModule(device->handle, &world_lightmap_frag_info, NULL, &world_lightmap_frag_module));
  184.     VK_CHECK(vkCreateShaderModule(device->handle, &world_lightmap_unclamped_frag_info, NULL, &world_lightmap_unclamped_frag_module));
  185.     VK_CHECK(vkCreateShaderModule(device->handle, &world_lightmap_only_frag_info, NULL, &world_lightmap_only_frag_module));
  186.     VK_CHECK(vkCreateShaderModule(device->handle, &world_unlit_vert_info, NULL, &world_unlit_vert_module));
  187.     VK_CHECK(vkCreateShaderModule(device->handle, &world_unlit_frag_info, NULL, &world_unlit_frag_module));
  188.     VK_CHECK(vkCreateShaderModule(device->handle, &world_unlit_warped_frag_info, NULL, &world_unlit_warped_frag_module));
  189.     VK_CHECK(vkCreateShaderModule(device->handle, &brush_lightmap_vert_info, NULL, &brush_lightmap_vert_module));
  190.     VK_CHECK(vkCreateShaderModule(device->handle, &alias_vertexlit_vert_info, NULL, &alias_vertexlit_vert_module));
  191.     VK_CHECK(vkCreateShaderModule(device->handle, &alias_vertexlit_frag_info, NULL, &alias_vertexlit_frag_module));
  192.     VK_CHECK(vkCreateShaderModule(device->handle, &world_sky_vert_info, NULL, &world_sky_vert_module));
  193.     VK_CHECK(vkCreateShaderModule(device->handle, &world_sky_frag_info, NULL, &world_sky_frag_module));
  194.     VK_CHECK(vkCreateShaderModule(device->handle, &sprite_textured_vert_info, NULL, &sprite_textured_vert_module));
  195.     VK_CHECK(vkCreateShaderModule(device->handle, &sprite_textured_frag_info, NULL, &sprite_textured_frag_module));
  196.     VK_CHECK(vkCreateShaderModule(device->handle, &particle_vert_info, NULL, &particle_vert_module));
  197.  
  198.     VkPipelineShaderStageCreateInfo screen_colored_info[] =
  199.     {
  200.         {
  201.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  202.             nullptr,
  203.             0,
  204.             VK_SHADER_STAGE_VERTEX_BIT, //stage
  205.             screen_colored_vert_module, //module
  206.             "main",
  207.         },
  208.         {
  209.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  210.             nullptr,
  211.             0,
  212.             VK_SHADER_STAGE_FRAGMENT_BIT, //stage
  213.             generic_colored_frag_module, //module
  214.             "main",
  215.         },
  216.     };
  217.  
  218.     VkPipelineShaderStageCreateInfo screen_textured_info[] =
  219.     {
  220.         {
  221.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  222.             nullptr,
  223.             0,
  224.             VK_SHADER_STAGE_VERTEX_BIT,
  225.             screen_textured_vert_module,
  226.             "main",
  227.         },
  228.         {
  229.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  230.             nullptr,
  231.             0,
  232.             VK_SHADER_STAGE_FRAGMENT_BIT,
  233.             screen_textured_frag_module,
  234.             "main",
  235.         },
  236.     };
  237.  
  238.     VkPipelineShaderStageCreateInfo world_lightmap_info[] =
  239.     {
  240.         {
  241.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  242.             nullptr,
  243.             0,
  244.             VK_SHADER_STAGE_VERTEX_BIT,
  245.             world_lightmap_vert_module,
  246.             "main",
  247.         },
  248.         {
  249.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  250.             nullptr,
  251.             0,
  252.             VK_SHADER_STAGE_FRAGMENT_BIT,
  253.             world_lightmap_frag_module,
  254.             "main",
  255.         },
  256.     };
  257.  
  258.     VkPipelineShaderStageCreateInfo world_lightmap_unclamped_info[] =
  259.     {
  260.         {
  261.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  262.             nullptr,
  263.             0,
  264.             VK_SHADER_STAGE_VERTEX_BIT,
  265.             world_lightmap_vert_module,
  266.             "main",
  267.         },
  268.         {
  269.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  270.             nullptr,
  271.             0,
  272.             VK_SHADER_STAGE_FRAGMENT_BIT,
  273.             world_lightmap_unclamped_frag_module,
  274.             "main",
  275.         },
  276.     };
  277.  
  278.     VkPipelineShaderStageCreateInfo world_lightmap_only_info[] =
  279.     {
  280.         {
  281.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  282.             nullptr,
  283.             0,
  284.             VK_SHADER_STAGE_VERTEX_BIT,
  285.             world_lightmap_vert_module,
  286.             "main",
  287.         },
  288.         {
  289.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  290.             nullptr,
  291.             0,
  292.             VK_SHADER_STAGE_FRAGMENT_BIT,
  293.             world_lightmap_only_frag_module,
  294.             "main",
  295.         },
  296.     };
  297.    
  298.     VkPipelineShaderStageCreateInfo brush_unlit_info[] =
  299.     {
  300.         {
  301.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  302.             nullptr,
  303.             0,
  304.             VK_SHADER_STAGE_VERTEX_BIT,
  305.             world_unlit_vert_module,
  306.             "main",
  307.         },
  308.         {
  309.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  310.             nullptr,
  311.             0,
  312.             VK_SHADER_STAGE_FRAGMENT_BIT,
  313.             world_unlit_frag_module,
  314.             "main",
  315.         },
  316.     };
  317.    
  318.     VkPipelineShaderStageCreateInfo brush_unlit_warped_info[] =
  319.     {
  320.         {
  321.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  322.             nullptr,
  323.             0,
  324.             VK_SHADER_STAGE_VERTEX_BIT,
  325.             world_unlit_vert_module,
  326.             "main",
  327.         },
  328.         {
  329.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  330.             nullptr,
  331.             0,
  332.             VK_SHADER_STAGE_FRAGMENT_BIT,
  333.             world_unlit_warped_frag_module,
  334.             "main",
  335.         },
  336.     };
  337.  
  338.     VkPipelineShaderStageCreateInfo brush_lightmap_info[] =
  339.     {
  340.         {
  341.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  342.             nullptr,
  343.             0,
  344.             VK_SHADER_STAGE_VERTEX_BIT,
  345.             brush_lightmap_vert_module,
  346.             "main",
  347.         },
  348.         {
  349.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  350.             nullptr,
  351.             0,
  352.             VK_SHADER_STAGE_FRAGMENT_BIT,
  353.             world_lightmap_unclamped_frag_module,
  354.             "main",
  355.         },
  356.     };
  357.    
  358.     VkPipelineShaderStageCreateInfo alias_vertexlit_info[] =
  359.     {
  360.         {
  361.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  362.             nullptr,
  363.             0,
  364.             VK_SHADER_STAGE_VERTEX_BIT,
  365.             alias_vertexlit_vert_module,
  366.             "main",
  367.         },
  368.         {
  369.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  370.             nullptr,
  371.             0,
  372.             VK_SHADER_STAGE_FRAGMENT_BIT,
  373.             alias_vertexlit_frag_module,
  374.             "main",
  375.         },
  376.     };
  377.    
  378.     VkPipelineShaderStageCreateInfo world_sky_info[] =
  379.     {
  380.         {
  381.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  382.             nullptr,
  383.             0,
  384.             VK_SHADER_STAGE_VERTEX_BIT,
  385.             world_sky_vert_module,
  386.             "main",
  387.         },
  388.         {
  389.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  390.             nullptr,
  391.             0,
  392.             VK_SHADER_STAGE_FRAGMENT_BIT,
  393.             world_sky_frag_module,
  394.             "main",
  395.         },
  396.     };
  397.    
  398.     VkPipelineShaderStageCreateInfo sprite_textured_info[] =
  399.     {
  400.         {
  401.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  402.             nullptr,
  403.             0,
  404.             VK_SHADER_STAGE_VERTEX_BIT,
  405.             sprite_textured_vert_module,
  406.             "main",
  407.         },
  408.         {
  409.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  410.             nullptr,
  411.             0,
  412.             VK_SHADER_STAGE_FRAGMENT_BIT,
  413.             sprite_textured_frag_module,
  414.             "main",
  415.         },
  416.     };
  417.    
  418.     VkPipelineShaderStageCreateInfo particle_shader_info[] =
  419.     {
  420.         {
  421.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  422.             nullptr,
  423.             0,
  424.             VK_SHADER_STAGE_VERTEX_BIT,
  425.             particle_vert_module,
  426.             "main",
  427.         },
  428.         {
  429.             VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
  430.             nullptr,
  431.             0,
  432.             VK_SHADER_STAGE_FRAGMENT_BIT,
  433.             generic_colored_frag_module,
  434.             "main",
  435.         },
  436.     };
  437.  
  438.     VK_CreateDescriptorSets(device);
  439.  
  440.     VkFormat colorformat = vk_state.phys_device.surfaceformat.format;
  441.     VkPipelineRenderingCreateInfo renderingInfo =
  442.     {
  443.         VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO,
  444.         nullptr, //pNext
  445.         0, //viewmask
  446.         1, //colorAttachmentCount
  447.         &colorformat, //pColorAttachmentFormats
  448.         VK_FORMAT_D32_SFLOAT, //depthAttachmentFormat
  449.     };
  450.  
  451.     //Update the viewport and scissors rects, now that a window has been created.
  452.     viewport.x = viewport.y = 0; viewport.width = vid.width; viewport.height = vid.height; viewport.minDepth = 0.0f; viewport.maxDepth = 1.0f;
  453.     scissors_rect.offset.x = scissors_rect.offset.y = 0; scissors_rect.extent.width = vid.width; scissors_rect.extent.height = vid.height;
  454.     viewport_depthhack = viewport; viewport_depthhack.maxDepth *= .3f;
  455.  
  456.     //The big ol array that contains all the pipelines that are needed
  457.     //TODO: anything to clean up this code would be appreciated.
  458.     VkGraphicsPipelineCreateInfo pipelineInfo[] =
  459.     {
  460.         { //screen_colored
  461.             VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
  462.             &renderingInfo, //pNext
  463.             0, //flags
  464.             2, //stageCount,
  465.             screen_colored_info, //pStages
  466.             &screen_vertex_info, //pVertexInputState
  467.             &triangle_strip_input_info, //pInputAssemblyState
  468.             nullptr, //pTessellationState,
  469.             &viewport_info, //pViewportState
  470.             &rasterization_info, //pRasterizationState
  471.             &no_multisample_info, //pMultisampleState
  472.             &no_depth_test_state, //pDepthStencilState
  473.             &normal_blend_info, //pColorBlendState,
  474.             & viewport_dynamic_info, //pDynamicState
  475.             screen_pipeline_layout, //layout,
  476.         },
  477.         { //screen_textured
  478.             VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
  479.             & renderingInfo, //pNext
  480.             0, //flags
  481.             2, //stageCount,
  482.             screen_textured_info, //pStages
  483.             & screen_vertex_info, //pVertexInputState
  484.             & triangle_strip_input_info, //pInputAssemblyState
  485.             nullptr, //pTessellationState,
  486.             & viewport_info, //pViewportState
  487.             & rasterization_info, //pRasterizationState
  488.             & no_multisample_info, //pMultisampleState
  489.             & no_depth_test_state, //pDepthStencilState
  490.             & normal_blend_info, //pColorBlendState,
  491.             & viewport_dynamic_info, //pDynamicState
  492.             screen_pipeline_layout, //layout,
  493.         },
  494.         { //world_lightmap
  495.             VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
  496.             & renderingInfo, //pNext
  497.             0, //flags
  498.             2, //stageCount,
  499.             world_lightmap_info, //pStages
  500.             & world_vertex_info, //pVertexInputState
  501.             & triangle_input_info, //pInputAssemblyState
  502.             nullptr, //pTessellationState,
  503.             & viewport_info, //pViewportState
  504.             & rasterization_info, //pRasterizationState
  505.             & no_multisample_info, //pMultisampleState
  506.             & full_depth_test_state, //pDepthStencilState
  507.             & no_blend_info, //pColorBlendState,
  508.             &viewport_dynamic_info, //pDynamicState
  509.             world_pipeline_layout, //layout,
  510.         },
  511.         { //world_lightmap_unclamped
  512.             VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
  513.             & renderingInfo, //pNext
  514.             0, //flags
  515.             2, //stageCount,
  516.             world_lightmap_unclamped_info, //pStages
  517.             & world_vertex_info, //pVertexInputState
  518.             & triangle_input_info, //pInputAssemblyState
  519.             nullptr, //pTessellationState,
  520.             & viewport_info, //pViewportState
  521.             & rasterization_info, //pRasterizationState
  522.             & no_multisample_info, //pMultisampleState
  523.             & full_depth_test_state, //pDepthStencilState
  524.             & no_blend_info, //pColorBlendState
  525.             & viewport_dynamic_info, //pDynamicState
  526.             world_pipeline_layout, //layout
  527.         },
  528.         { //world_lightmap_only
  529.             VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
  530.             & renderingInfo, //pNext
  531.             0, //flags
  532.             2, //stageCount,
  533.             world_lightmap_only_info, //pStages
  534.             & world_vertex_info, //pVertexInputState
  535.             & triangle_input_info, //pInputAssemblyState
  536.             nullptr, //pTessellationState,
  537.             & viewport_info, //pViewportState
  538.             & rasterization_info, //pRasterizationState
  539.             & no_multisample_info, //pMultisampleState
  540.             & full_depth_test_state, //pDepthStencilState
  541.             & no_blend_info, //pColorBlendState
  542.             & viewport_dynamic_info, //pDynamicState
  543.             world_pipeline_layout, //layout
  544.         },
  545.         { //brush_unlit
  546.             VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
  547.             & renderingInfo, //pNext
  548.             0, //flags
  549.             2, //stageCount,
  550.             brush_unlit_info, //pStages
  551.             & world_unlit_vertex_info, //pVertexInputState
  552.             & triangle_input_info, //pInputAssemblyState
  553.             nullptr, //pTessellationState,
  554.             & viewport_info, //pViewportState
  555.             & rasterization_info, //pRasterizationState
  556.             & no_multisample_info, //pMultisampleState
  557.             & depth_test_no_write_state, //pDepthStencilState
  558.             & normal_blend_info, //pColorBlendState
  559.             & viewport_dynamic_info, //pDynamicState
  560.             bmodel_pipeline_layout, //layout
  561.         },
  562.         { //brush_warped
  563.             VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
  564.             & renderingInfo, //pNext
  565.             0, //flags
  566.             2, //stageCount,
  567.             brush_unlit_warped_info, //pStages
  568.             & world_unlit_vertex_info, //pVertexInputState
  569.             & triangle_input_info, //pInputAssemblyState
  570.             nullptr, //pTessellationState,
  571.             & viewport_info, //pViewportState
  572.             & rasterization_info, //pRasterizationState
  573.             & no_multisample_info, //pMultisampleState
  574.             & full_depth_test_state, //pDepthStencilState
  575.             & no_blend_info, //pColorBlendState
  576.             & viewport_dynamic_info, //pDynamicState
  577.             bmodel_pipeline_layout, //layout
  578.         },
  579.         { //brush_warped_alpha
  580.             VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
  581.             & renderingInfo, //pNext
  582.             0, //flags
  583.             2, //stageCount,
  584.             brush_unlit_warped_info, //pStages
  585.             & world_unlit_vertex_info, //pVertexInputState
  586.             & triangle_input_info, //pInputAssemblyState
  587.             nullptr, //pTessellationState,
  588.             & viewport_info, //pViewportState
  589.             & rasterization_info, //pRasterizationState
  590.             & no_multisample_info, //pMultisampleState
  591.             & depth_test_no_write_state, //pDepthStencilState
  592.             & normal_blend_info, //pColorBlendState
  593.             & viewport_dynamic_info, //pDynamicState
  594.             bmodel_pipeline_layout, //layout
  595.         },
  596.         { //brush_lightmap
  597.             VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
  598.             & renderingInfo, //pNext
  599.             0, //flags
  600.             2, //stageCount,
  601.             brush_lightmap_info, //pStages
  602.             & world_vertex_info, //pVertexInputState
  603.             & triangle_input_info, //pInputAssemblyState
  604.             nullptr, //pTessellationState,
  605.             & viewport_info, //pViewportState
  606.             & rasterization_info, //pRasterizationState
  607.             & no_multisample_info, //pMultisampleState
  608.             & full_depth_test_state, //pDepthStencilState
  609.             & no_blend_info, //pColorBlendState
  610.             & viewport_dynamic_info, //pDynamicState
  611.             bmodel_pipeline_layout, //layout
  612.         },
  613.         { //alias_vertexlit
  614.             VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
  615.             & renderingInfo, //pNext
  616.             0, //flags
  617.             2, //stageCount,
  618.             alias_vertexlit_info, //pStages
  619.             & alias_vertex_info, //pVertexInputState
  620.             & triangle_input_info, //pInputAssemblyState
  621.             nullptr, //pTessellationState,
  622.             & viewport_info, //pViewportState
  623.             & rasterization_info_alias, //pRasterizationState
  624.             & no_multisample_info, //pMultisampleState
  625.             & full_depth_test_state, //pDepthStencilState
  626.             & no_blend_info, //pColorBlendState
  627.             & viewport_dynamic_info, //pDynamicState
  628.             alias_pipeline_layout, //layout
  629.         },
  630.         { //alias_vertexlit_depthhack
  631.             VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
  632.             & renderingInfo, //pNext
  633.             0, //flags
  634.             2, //stageCount,
  635.             alias_vertexlit_info, //pStages
  636.             & alias_vertex_info, //pVertexInputState
  637.             & triangle_input_info, //pInputAssemblyState
  638.             nullptr, //pTessellationState,
  639.             & viewport_depthhack_info, //pViewportState
  640.             & rasterization_info_alias, //pRasterizationState
  641.             & no_multisample_info, //pMultisampleState
  642.             & full_depth_test_state, //pDepthStencilState
  643.             & no_blend_info, //pColorBlendState
  644.             & viewport_dynamic_info, //pDynamicState
  645.             alias_pipeline_layout, //layout
  646.         },
  647.         { //alias_vertexlit_alpha
  648.             VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
  649.             & renderingInfo, //pNext
  650.             0, //flags
  651.             2, //stageCount,
  652.             alias_vertexlit_info, //pStages
  653.             & alias_vertex_info, //pVertexInputState
  654.             & triangle_input_info, //pInputAssemblyState
  655.             nullptr, //pTessellationState,
  656.             & viewport_info, //pViewportState
  657.             & rasterization_info_alias, //pRasterizationState
  658.             & no_multisample_info, //pMultisampleState
  659.             & depth_test_no_write_state, //pDepthStencilState
  660.             & normal_blend_info, //pColorBlendState
  661.             & viewport_dynamic_info, //pDynamicState
  662.             alias_pipeline_layout, //layout
  663.         },
  664.         { //world_sky
  665.             VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
  666.             & renderingInfo, //pNext
  667.             0, //flags
  668.             2, //stageCount,
  669.             world_sky_info, //pStages
  670.             & world_sky_vertex_info, //pVertexInputState
  671.             & triangle_input_info, //pInputAssemblyState
  672.             nullptr, //pTessellationState,
  673.             & viewport_info, //pViewportState
  674.             & rasterization_info, //pRasterizationState
  675.             & no_multisample_info, //pMultisampleState
  676.             & depth_test_no_write_state, //pDepthStencilState
  677.             & no_blend_info, //pColorBlendState
  678.             & viewport_dynamic_info, //pDynamicState
  679.             sky_pipeline_layout, //layout
  680.         },
  681.         { //sprite_textured
  682.             VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
  683.             & renderingInfo, //pNext
  684.             0, //flags
  685.             2, //stageCount,
  686.             sprite_textured_info, //pStages
  687.             & sprite_textured_vertex_info, //pVertexInputState
  688.             & triangle_strip_input_info, //pInputAssemblyState
  689.             nullptr, //pTessellationState,
  690.             & viewport_info, //pViewportState
  691.             & rasterization_info, //pRasterizationState
  692.             & no_multisample_info, //pMultisampleState
  693.             & full_depth_test_state, //pDepthStencilState
  694.             & no_blend_info, //pColorBlendState
  695.             & viewport_dynamic_info, //pDynamicState
  696.             alias_pipeline_layout, //layout
  697.         },
  698.         { //sprite_textured_alpha
  699.             VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
  700.             & renderingInfo, //pNext
  701.             0, //flags
  702.             2, //stageCount,
  703.             sprite_textured_info, //pStages
  704.             & sprite_textured_vertex_info, //pVertexInputState
  705.             & triangle_strip_input_info, //pInputAssemblyState
  706.             nullptr, //pTessellationState,
  707.             & viewport_info, //pViewportState
  708.             & rasterization_info, //pRasterizationState
  709.             & no_multisample_info, //pMultisampleState
  710.             & depth_test_no_write_state, //pDepthStencilState
  711.             & normal_blend_info, //pColorBlendState
  712.             & viewport_dynamic_info, //pDynamicState
  713.             alias_pipeline_layout, //layout
  714.         },
  715.         { //particle_colored
  716.             VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
  717.             & renderingInfo, //pNext
  718.             0, //flags
  719.             2, //stageCount,
  720.             particle_shader_info, //pStages
  721.             & particle_vertex_info, //pVertexInputState
  722.             & point_input_info, //pInputAssemblyState
  723.             nullptr, //pTessellationState,
  724.             & viewport_info, //pViewportState
  725.             & rasterization_info, //pRasterizationState
  726.             & no_multisample_info, //pMultisampleState
  727.             & depth_test_no_write_state, //pDepthStencilState
  728.             & normal_blend_info, //pColorBlendState
  729.             & viewport_dynamic_info, //pDynamicState
  730.             particle_pipeline_layout, //layout
  731.         },
  732.     };
  733.  
  734.     num_pipelines = sizeof(pipelineInfo) / sizeof(pipelineInfo[0]);
  735.     VK_CHECK(vkCreateGraphicsPipelines(device->handle, VK_NULL_HANDLE, num_pipelines, pipelineInfo, NULL, pipelines));
  736.  
  737.     //Assign the pipelines from the big pipeline array
  738.     device->screen_colored = pipelines[0];
  739.     device->screen_textured = pipelines[1];
  740.     device->world_lightmap = pipelines[2];
  741.     device->world_lightmap_unclamped = pipelines[3];
  742.     device->world_lightmap_only = pipelines[4];
  743.     device->brush_unlit = pipelines[5];
  744.     device->brush_unlit_warped = pipelines[6];
  745.     device->brush_unlit_warped_alpha = pipelines[7];
  746.     device->brush_lightmap = pipelines[8];
  747.     device->alias_vertexlit = pipelines[9];
  748.     device->alias_vertexlit_depthhack = pipelines[10];
  749.     device->alias_vertexlit_alpha = pipelines[11];
  750.     device->world_sky = pipelines[12];
  751.     device->sprite_textured = pipelines[13];
  752.     device->sprite_textured_alpha = pipelines[14];
  753.     device->particle_colored = pipelines[15];
  754.  
  755.     vkDestroyShaderModule(device->handle, screen_textured_vert_module, NULL);
  756.     vkDestroyShaderModule(device->handle, screen_textured_frag_module, NULL);
  757.     vkDestroyShaderModule(device->handle, screen_colored_vert_module, NULL);
  758.     vkDestroyShaderModule(device->handle, generic_colored_frag_module, NULL);
  759.     vkDestroyShaderModule(device->handle, world_lightmap_vert_module, NULL);
  760.     vkDestroyShaderModule(device->handle, world_lightmap_frag_module, NULL);
  761.     vkDestroyShaderModule(device->handle, world_lightmap_unclamped_frag_module, NULL);
  762.     vkDestroyShaderModule(device->handle, world_lightmap_only_frag_module, NULL);
  763.     vkDestroyShaderModule(device->handle, world_unlit_vert_module, NULL);
  764.     vkDestroyShaderModule(device->handle, world_unlit_frag_module, NULL);
  765.     vkDestroyShaderModule(device->handle, world_unlit_warped_frag_module, NULL);
  766.     vkDestroyShaderModule(device->handle, brush_lightmap_vert_module, NULL);
  767.     vkDestroyShaderModule(device->handle, alias_vertexlit_vert_module, NULL);
  768.     vkDestroyShaderModule(device->handle, alias_vertexlit_frag_module, NULL);
  769.     vkDestroyShaderModule(device->handle, world_sky_vert_module, NULL);
  770.     vkDestroyShaderModule(device->handle, world_sky_frag_module, NULL);
  771.     vkDestroyShaderModule(device->handle, sprite_textured_vert_module, NULL);
  772.     vkDestroyShaderModule(device->handle, sprite_textured_frag_module, NULL);
  773.     vkDestroyShaderModule(device->handle, particle_vert_module, NULL);
  774. }
  775.  
  776. void VK_DestroyPipelines(vklogicaldevice_t* device)
  777. {
  778.     for (int i = 0; i < num_pipelines; i++)
  779.     {
  780.         vkDestroyPipeline(device->handle, pipelines[i], NULL);
  781.     }
  782.     VK_DestroyDescriptorSets(device);
  783. }
  784.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement