def create_render_pass(recreate=False):
    global render_pass

    if recreate:
        hvk.destroy_render_pass(api, device, render_pass)

    # Renderpass attachments setup
    color = hvk.attachment_description(
        format=swapchain_image_format,
        initial_layout=vk.IMAGE_LAYOUT_UNDEFINED,
        final_layout=vk.IMAGE_LAYOUT_PRESENT_SRC_KHR)

    depth = hvk.attachment_description(
        format=depth_format,
        initial_layout=vk.IMAGE_LAYOUT_UNDEFINED,
        final_layout=vk.IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)

    window_attachments = (color, depth)
    color_ref = vk.AttachmentReference(
        attachment=0, layout=vk.IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)
    depth_ref = vk.AttachmentReference(
        attachment=1, layout=vk.IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)

    # Render pass subpasses
    subpass_info = hvk.subpass_description(
        pipeline_bind_point=vk.PIPELINE_BIND_POINT_GRAPHICS,
        color_attachments=(color_ref, ),
        depth_stencil_attachment=depth_ref)

    # Renderpass dependencies
    prepare_drawing = hvk.subpass_dependency(
        src_subpass=vk.SUBPASS_EXTERNAL,
        dst_subpass=0,
        src_stage_mask=vk.PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
        dst_stage_mask=vk.PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
        src_access_mask=vk.ACCESS_MEMORY_READ_BIT,
        dst_access_mask=vk.ACCESS_COLOR_ATTACHMENT_READ_BIT
        | vk.ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
    )

    prepare_present = hvk.subpass_dependency(
        src_subpass=0,
        dst_subpass=vk.SUBPASS_EXTERNAL,
        src_stage_mask=vk.PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
        dst_stage_mask=vk.PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
        src_access_mask=vk.ACCESS_COLOR_ATTACHMENT_READ_BIT
        | vk.ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
        dst_access_mask=vk.ACCESS_MEMORY_READ_BIT,
    )

    # Render pass creation
    render_pass = hvk.create_render_pass(
        api, device,
        hvk.render_pass_create_info(attachments=(color, depth),
                                    subpasses=(subpass_info, ),
                                    dependencies=(prepare_drawing,
                                                  prepare_present)))
def clean_resources():
    window.hide()
    hvk.device_wait_idle(api, device)

    hvk.destroy_fence(api, device, staging_fence)
    hvk.destroy_command_pool(api, device, staging_pool)

    hvk.destroy_command_pool(api, device, drawing_pool)

    hvk.destroy_buffer(api, device, mesh_buffer)
    hvk.free_memory(api, device, mesh_memory)

    hvk.destroy_sampler(api, device, texture_sampler)
    hvk.destroy_image_view(api, device, texture_view)
    hvk.destroy_image(api, device, texture_image)
    hvk.free_memory(api, device, texture_image_memory)

    hvk.destroy_descriptor_pool(api, device, descriptor_pool)
    hvk.destroy_buffer(api, device, uniforms_buffer)
    hvk.free_memory(api, device, uniforms_mem)

    hvk.destroy_pipeline(api, device, pipeline)
    hvk.destroy_pipeline_cache(api, device, pipeline_cache)
    hvk.destroy_pipeline_layout(api, device, pipeline_layout)

    for m in shader_modules:
        hvk.destroy_shader_module(api, device, m)

    hvk.destroy_descriptor_set_layout(api, device, descriptor_set_layout)

    for fb in framebuffers:
        hvk.destroy_framebuffer(api, device, fb)

    hvk.destroy_render_pass(api, device, render_pass)

    hvk.destroy_semaphore(api, device, image_ready)
    hvk.destroy_semaphore(api, device, rendering_done)
    for f in render_fences:
        hvk.destroy_fence(api, device, f)

    hvk.destroy_image(api, device, depth_stencil)
    hvk.destroy_image_view(api, device, depth_view)
    hvk.free_memory(api, device, depth_alloc)

    for v in swapchain_image_views:
        hvk.destroy_image_view(api, device, v)

    hvk.destroy_swapchain(api, device, swapchain)
    hvk.destroy_device(api, device)
    hvk.destroy_surface(api, instance, surface)

    debugger.stop()
    hvk.destroy_instance(api, instance)

    window.destroy()
示例#3
0
    def free(self):
        ctx, api, device = self.ctx
        memory_manager = ctx.memory_manager

        hvk.destroy_image_view(api, device, self.depth_stencil.view)
        hvk.destroy_image(api, device, self.depth_stencil.image)
        memory_manager.free_alloc(self.depth_stencil_alloc)

        for fb in self.framebuffers:
            hvk.destroy_framebuffer(api, device, fb)

        for (_, view) in self.swapchain_images:
            hvk.destroy_image_view(api, device, view)

        hvk.destroy_render_pass(api, device, self.render_pass)
        del self.engine