예제 #1
0
    def _setup_depth_stencil(self):
        engine, api, device = self.ctx
        width, height = engine.info["swapchain_extent"].values()
        depth_format = engine.info["depth_format"]
        mem = engine.memory_manager

        if self.depth_stencil is not None:
            hvk.destroy_image_view(api, device, self.depth_stencil.view)
            hvk.destroy_image(api, device, self.depth_stencil.image)
            mem.free_alloc(self.depth_stencil_alloc)

        depth_stencil_image = hvk.create_image(
            api, device,
            hvk.image_create_info(
                format=depth_format,
                extent=vk.Extent3D(width=width, height=height, depth=1),
                usage=vk.IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT))

        alloc = mem.alloc(depth_stencil_image,
                          vk.STRUCTURE_TYPE_IMAGE_CREATE_INFO,
                          types=(vk.MEMORY_PROPERTY_DEVICE_LOCAL_BIT, ))

        depth_stencil_view = hvk.create_image_view(
            api, device,
            hvk.image_view_create_info(
                image=depth_stencil_image,
                format=depth_format,
                subresource_range=hvk.image_subresource_range(
                    aspect_mask=vk.IMAGE_ASPECT_DEPTH_BIT
                    | vk.IMAGE_ASPECT_STENCIL_BIT)))

        self.depth_stencil = ImageAndView(image=depth_stencil_image,
                                          view=depth_stencil_view)
        self.depth_stencil_alloc = alloc
def setup_swapchain_depth_stencil(recreate=False):
    global depth_format, depth_stencil, depth_alloc, depth_view

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

    width, height = window.dimensions()

    # Depth stencil attachment setup
    depth_format = None
    depth_formats = (vk.FORMAT_D32_SFLOAT_S8_UINT, vk.FORMAT_D24_UNORM_S8_UINT,
                     vk.FORMAT_D16_UNORM_S8_UINT)
    for fmt in depth_formats:
        prop = hvk.physical_device_format_properties(api, physical_device, fmt)
        if IntFlag(vk.FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) in IntFlag(
                prop.optimal_tiling_features):
            depth_format = fmt
            break

    if depth_format is None:
        raise RuntimeError("Failed to find a suitable depth stencil format.")

    # Depth stencil image creation
    depth_stencil = hvk.create_image(
        api, device,
        hvk.image_create_info(format=depth_format,
                              extent=vk.Extent3D(width=width,
                                                 height=height,
                                                 depth=1),
                              usage=vk.IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
                              | vk.IMAGE_USAGE_TRANSFER_SRC_BIT))

    # Depth stencil image memory
    image_memreq = hvk.image_memory_requirements(api, device, depth_stencil)
    mt_index = find_memory_type(vk.MEMORY_HEAP_DEVICE_LOCAL_BIT,
                                vk.MEMORY_PROPERTY_DEVICE_LOCAL_BIT)

    depth_stencil_size = image_memreq.size * 2
    depth_alloc = hvk.allocate_memory(
        api, device,
        hvk.memory_allocate_info(allocation_size=depth_stencil_size,
                                 memory_type_index=mt_index))

    hvk.bind_image_memory(api, device, depth_stencil, depth_alloc)

    # Depth stencil image view
    depth_view = hvk.create_image_view(
        api, device,
        hvk.image_view_create_info(
            image=depth_stencil,
            format=depth_format,
            subresource_range=hvk.image_subresource_range(
                aspect_mask=vk.IMAGE_ASPECT_DEPTH_BIT
                | vk.IMAGE_ASPECT_STENCIL_BIT)))
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()
예제 #4
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
예제 #5
0
    def free(self):
        engine, api, device = self.ctx

        hvk.destroy_image(api, device, self.image_handle)