def create_render_resources(recreate=False):
    global drawing_pool, cmd_draw, image_ready, rendering_done, render_fences

    if recreate:
        hvk.destroy_command_pool(api, device, drawing_pool)

    # Render commands setup
    drawing_pool = hvk.create_command_pool(
        api, device,
        hvk.command_pool_create_info(
            queue_family_index=render_queue.family.index,
            flags=vk.COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT))

    cmd_draw = hvk.allocate_command_buffers(
        api, device,
        hvk.command_buffer_allocate_info(
            command_pool=drawing_pool,
            command_buffer_count=len(swapchain_images)))

    if recreate:
        return

    # Render commands synchronisation resources
    info = hvk.semaphore_create_info()
    image_ready = hvk.create_semaphore(api, device, info)
    rendering_done = hvk.create_semaphore(api, device, info)

    info = hvk.fence_create_info(flags=vk.FENCE_CREATE_SIGNALED_BIT)
    render_fences = tuple(
        hvk.create_fence(api, device, info)
        for _ in range(len(swapchain_images)))
Exemple #2
0
    def free(self):
        api, i, d = self.api, self.instance, self.device

        hvk.device_wait_idle(api, d)

        hvk.destroy_command_pool(api, d, self.command_pool)
        hvk.destroy_fence(api, d, self.setup_fence)

        for scene in self.graph:
            scene.free()

        self.compute_runner.free()
        self.renderer.free()
        self.render_target.free()
        self.memory_manager.free()

        hvk.destroy_swapchain(api, d, self.swapchain)
        hvk.destroy_device(api, d)

        hvk.destroy_surface(api, i, self.surface)

        if self.debugger is not None:
            self.debugger.stop()

        if self.debug_ui is not None:
            self.debug_ui.close()

        hvk.destroy_instance(api, i)

        self.window.destroy()
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()
Exemple #4
0
    def free(self):
        engine, api, device = self.ctx
        mem = engine.memory_manager

        if self.uniforms_alloc is not None:
            hvk.destroy_buffer(api, device, self.uniforms_buffer)
            mem.free_alloc(self.uniforms_alloc)

        if self.descriptor_pool is not None:
            hvk.destroy_descriptor_pool(api, device, self.descriptor_pool)

        for pipeline in self.pipelines:
            hvk.destroy_pipeline(api, device, pipeline)

        for pipeline in self.compute_pipelines:
            hvk.destroy_pipeline(api, device, pipeline)

        hvk.destroy_pipeline_cache(api, device, self.pipeline_cache)

        if self.meshes_buffer is not None:
            hvk.destroy_buffer(api, device, self.meshes_buffer)
            mem.free_alloc(self.meshes_alloc)

        for sampler in self.samplers:
            sampler.free()

        for img in self.images:
            for view in img.views.values():
                hvk.destroy_image_view(api, device, view)

            img.free()

        if self.images_alloc is not None:
            mem.free_alloc(self.images_alloc)

        for compute in self.computes:
            compute.free()

        for shader in self.shaders:
            shader.free()

        hvk.destroy_command_pool(api, device, self.command_pool)

        for _, pool in self.compute_pools:
            hvk.destroy_command_pool(api, device, pool)

        # Make it easier for python to deal with the circular dependencies
        del self.engine
        del self.scene
        del self.shaders