X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=src%2Fvulkan%2Fvk.cc;h=654165be411025b83915710d973621be8f9734ee;hb=dbce2a319517c09fcf1a9be60ae46a0ff20c423e;hp=a0f77514c47ed568dbf8793b9fde1ce1a7a9b8da;hpb=855c42d8e50fff743fd7b1be5e91cb0db18def77;p=demo diff --git a/src/vulkan/vk.cc b/src/vulkan/vk.cc index a0f7751..654165b 100644 --- a/src/vulkan/vk.cc +++ b/src/vulkan/vk.cc @@ -32,16 +32,12 @@ static const VkFormat dformat = VK_FORMAT_D32_SFLOAT_S8_UINT; static VkImage *images; static VkImageView *iviews; static uint32_t num_images; -//renderpass -static VkRenderPass rpass; static VkFramebuffer fbs[2]; //semaphores-drawing-presentation static uint32_t curr_img; // current sc image static VkSemaphore psema; - /* static variables */ -static VkDeviceMemory gpu_mem; // to be replaced when I fix the allocator static Vec4 clear_color(1, 0.1, 0.1, 1.0); /* static functions */ @@ -59,7 +55,6 @@ static bool create_swapchain(VkSwapchainKHR *sc); static bool create_zbuffer(); static bool create_renderpass(); static bool create_framebuffers(); -static bool create_pipelines(); static bool begin_init_command_buffer(VkCommandBuffer *cb); static bool end_init_command_buffer(VkCommandBuffer *cb); static bool allocate_rendering_command_buffers(VkCommandBuffer *bufs); @@ -87,7 +82,7 @@ bool init_vulkan() return false; } - if(!glfwGetPhysicalDevicePresentationSupport(vkinst, vk_physical, vkqfamily)) { + if(!glfwGetPhysicalDevicePresentationSupport(vk_instance, vk_physical, vk_qfamily)) { fprintf(stderr, "Presentation support not found.\n"); return false; } @@ -98,7 +93,7 @@ bool init_vulkan() return false; } - VkResult res = glfwCreateWindowSurface(vkinst, win, 0, &vk_surface); + VkResult res = glfwCreateWindowSurface(vk_instance, win, 0, &vk_surface); if(res != VK_SUCCESS) { fprintf(stderr, "Failed to create KHR surface: %s\n", vku_get_vulkan_error_str(res)); return false; @@ -130,11 +125,6 @@ bool init_vulkan() return false; } - if(!create_pipelines()) { - fprintf(stderr, "Failed to create the pipelines.\n"); - return false; - } - if(!end_init_command_buffer(&init_buf)) { fprintf(stderr, "Failed to end the command buffer.\n"); return false; @@ -354,12 +344,13 @@ static bool create_zbuffer() VkMemoryRequirements dmem_reqs; vkGetImageMemoryRequirements(vk_device, dimg, &dmem_reqs); - gpu_mem = vk_allocate(dmem_reqs.size); - - if(!gpu_mem) + DevMemBlock block; + if(!vku_allocate(dmem_reqs.size, &block)) { + fprintf(stderr, "Failed to allocate zbuffer image.\n"); return false; + } - vkBindImageMemory(vk_device, dimg, gpu_mem, 0); + vkBindImageMemory(vk_device, dimg, block.dev_mem, 0); if(!vk_image_set_layout(init_buf, dimg, VK_IMAGE_ASPECT_DEPTH_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, @@ -440,8 +431,8 @@ static bool create_renderpass() rinf.subpassCount = 1; rinf.pSubpasses = &sd; - if(vkCreateRenderPass(vk_device, &rinf, 0, &rpass) != VK_SUCCESS) { - fprintf(stderr, "Failed to create rpass.\n"); + if(vkCreateRenderPass(vk_device, &rinf, 0, &vk_renderpass) != VK_SUCCESS) { + fprintf(stderr, "Failed to create render pass.\n"); return false; } @@ -457,7 +448,7 @@ static bool create_framebuffers() VkFramebufferCreateInfo fbinf; memset(&fbinf, 0, sizeof fbinf); fbinf.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; - fbinf.renderPass = rpass; + fbinf.renderPass = vk_renderpass; fbinf.attachmentCount = 2; fbinf.pAttachments = fb_att; fbinf.width = win_w; @@ -474,57 +465,6 @@ static bool create_framebuffers() return true; } -static bool create_pipelines() -{ - VkDescriptorSetLayoutBinding dslb[1]; - memset(&dslb[0], 0, sizeof dslb[0]); - dslb[0].binding = 0; - dslb[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; - dslb[0].descriptorCount = 1; - dslb[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; - - VkDescriptorSetLayoutCreateInfo dslinf; - memset(&dslinf, 0, sizeof dslinf); - dslinf.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; - dslinf.bindingCount = 1; //dslb.size(); - dslinf.pBindings = dslb; - - VkDescriptorSetLayout dsl; - if(vkCreateDescriptorSetLayout(vk_device, &dslinf, 0, &dsl) != VK_SUCCESS) { - fprintf(stderr, "Failed to create descriptor set layout.\n"); - return false; - } - - VkPipelineLayoutCreateInfo pinf; - memset(&pinf, 0, sizeof pinf); - pinf.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; - pinf.setLayoutCount = 1; - pinf.pSetLayouts = &dsl; - - VkPipelineLayout pl; - if(vkCreatePipelineLayout(vk_device, &pinf, 0, &pl) != VK_SUCCESS) { - fprintf(stderr, "Failed to create pipeline layout.\n"); - return false; - } - - VkPipelineCacheCreateInfo pcinf; - memset(&pcinf, 0, sizeof pcinf); - pcinf.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; - - VkPipelineCache pcache; - if(vkCreatePipelineCache(vk_device, &pcinf, 0, &pcache) != VK_SUCCESS) { - fprintf(stderr, "Failed to create pipeline cache.\n"); - return false; - } - - VkGraphicsPipelineCreateInfo ginf; - memset(&ginf, 0, sizeof ginf); - ginf.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; - ginf.stageCount = 2; - - return true; -} - static bool end_init_command_buffer(VkCommandBuffer *cb) { if(vkEndCommandBuffer(*cb) != VK_SUCCESS) { @@ -609,7 +549,7 @@ static bool begin_rendering_command_buffers(VkCommandBuffer *bufs, int count) VkRenderPassBeginInfo rbinf; memset(&rbinf, 0, sizeof rbinf); rbinf.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; - rbinf.renderPass = rpass; + rbinf.renderPass = vk_renderpass; rbinf.framebuffer = fbs[i]; rbinf.renderArea.extent.width = win_w; rbinf.renderArea.extent.height = win_h; @@ -656,7 +596,6 @@ static bool begin_rendering_command_buffers(VkCommandBuffer *bufs, int count) void cleanup_vulkan() { - //TODO!!! free_rendering_command_buffers(rbufs, 2); if(win) { glfwDestroyWindow(win); @@ -675,17 +614,6 @@ static void error_callback(int error, const char *description) static void reshape(int width, int height) { -// VkSwapchainKHR sc; -// if(!(sc = vku_create_swapchain(vk_surface, width, height, 2, VK_PRESENT_MODE_FIFO_KHR, -// vk_swapchain))) { -// fprintf(stderr, "Failed to create %dx%d double-buffered swapchain\n", width, height); -// return; -// } -// vk_swapchain = sc; -// -// delete [] vkswapchain_images; -// vkswapchain_images = vku_get_swapchain_images(sc, 0); -// vk_curr_swapchain_image = vku_get_next_image(vk_swapchain); } static void clear(float r, float g, float b)