def create_pipeline(recreate=False): global pipeline, pipeline_cache if recreate: hvk.destroy_pipeline_cache(api, device, pipeline_cache) hvk.destroy_pipeline(api, device, pipeline) width, height = window.dimensions() viewport = hvk.viewport(width=width, height=height) render_area = hvk.rect_2d(0, 0, width, height) pipeline_info = hvk.graphics_pipeline_create_info( stages=stage_infos, vertex_input_state=hvk.pipeline_vertex_input_state_create_info( vertex_binding_descriptions=vertex_bindings, vertex_attribute_descriptions=vertex_attributes), input_assembly_state=hvk.pipeline_input_assembly_state_create_info(), viewport_state=hvk.pipeline_viewport_state_create_info( viewports=(viewport, ), scissors=(render_area, )), rasterization_state=hvk.pipeline_rasterization_state_create_info(), multisample_state=hvk.pipeline_multisample_state_create_info(), depth_stencil_state=hvk.pipeline_depth_stencil_state_create_info( depth_test_enable=vk.TRUE, depth_write_enable=vk.TRUE, depth_compare_op=vk.COMPARE_OP_LESS_OR_EQUAL, ), color_blend_state=hvk.pipeline_color_blend_state_create_info( attachments=(hvk.pipeline_color_blend_attachment_state(), )), layout=pipeline_layout, render_pass=render_pass) pipeline_cache = hvk.create_pipeline_cache( api, device, hvk.pipeline_cache_create_info()) pipeline = hvk.create_graphics_pipelines(api, device, (pipeline_info, ), pipeline_cache)[0]
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()
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