1 #include <vulkan/vulkan.h>
5 #include "renderer-vk.h"
8 #include "vkutil-pipeline.h"
10 static void set_resources_layouts(VkuPipelineGenerator *pipe_gen, std::vector<ResourceVK> *res);
12 RendererVK::RendererVK()
28 RendererVK::~RendererVK()
35 bool RendererVK::create_resources()
37 /* default pipeline resources */
39 default_vs_ub = gfx_create_uniform_buffer();
40 int data_size = sizeof default_vs_uniforms;
41 if(!default_vs_ub->create(data_size)) {
42 fprintf(stderr, "Failed to create the default VS uniform buffer.\n");
45 ResourceVK default_vs_res;
46 if(!default_vs_res.create_ds_layout(MATRIX_UNIFORMS,
47 VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
48 VK_SHADER_STAGE_VERTEX_BIT, 0)) {
49 fprintf(stderr, "Failed to create the ds layout for the default vs uniform buffer.\n");
52 default_vs_res.size = data_size;
53 default_resources.push_back(default_vs_res);
55 default_fs_ub = gfx_create_uniform_buffer();
56 if(!default_fs_ub->create(sizeof default_fs_uniforms)) {
57 fprintf(stderr, "Failed to create the default FS uniform buffer.\n");
60 ResourceVK default_fs_res;
61 if(!default_fs_res.create_ds_layout(SHADING_UNIFORMS,
62 VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
63 VK_SHADER_STAGE_FRAGMENT_BIT, 0)) {
64 fprintf(stderr, "Failed to create the ds layout for the default VS uniform buffer.\n");
67 default_resources.push_back(default_fs_res);
68 set_resources_layouts(&default_pipe_gen, &default_resources);
70 /* sky pipeline resources */
72 sky_vs_ub = gfx_create_uniform_buffer();
73 if(!sky_vs_ub->create(sizeof sky_vs_uniforms)) {
74 fprintf(stderr, "Failed to create the VS uniform buffer for the sky.\n");
77 ResourceVK sky_vs_res;
78 if(!sky_vs_res.create_ds_layout(SKY_MATRIX_UNIFORMS,
79 VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
80 VK_SHADER_STAGE_FRAGMENT_BIT, 0)) {
81 fprintf(stderr, "Failed to create the ds layout for the sky VS uniform buffer.\n");
84 sky_resources.push_back(sky_vs_res);
85 set_resources_layouts(&sky_pipe_gen, &sky_resources);
90 bool RendererVK::create()
92 /* if(!create_sky_pipeline()) {
93 fprintf(stderr, "Failed to create sky pipeline.\n");
100 bool RendererVK::create_default_pipeline()
105 bool RendererVK::create_desc_pool()
107 int num_desc = default_resources.size() + sky_resources.size();
108 VkDescriptorPoolCreateInfo dpinf;
109 memset(&dpinf, 0, sizeof dpinf);
111 dpinf.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
112 dpinf.maxSets = num_desc + 1;
113 dpinf.poolSizeCount = num_desc;
115 for(size_t i=0; i<default_resources.size(); i++) {
120 static void set_resources_layouts(VkuPipelineGenerator *pipe_gen, std::vector<ResourceVK> *res)
122 for(size_t i=0; i<res->size(); i++) {
123 if((*res)[i].type == RES_DESC_SET) {
124 pipe_gen->set_resources_layout((*res)[i].layout);