Exemplo n.º 1
0
def create_pipeline():
    global pipeline, pipeline_cache

    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]
Exemplo n.º 2
0
    def _setup_pipelines(self):
        engine, api, device = self.ctx
        shaders = self.shaders
        rt = engine.render_target

        assembly = hvk.pipeline_input_assembly_state_create_info()
        multisample = hvk.pipeline_multisample_state_create_info()
        viewport = hvk.pipeline_viewport_state_create_info(viewport_count=1,
                                                           scissor_count=1)
        raster = hvk.pipeline_rasterization_state_create_info()
        depth_stencil = 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 = hvk.pipeline_color_blend_state_create_info(
            attachments=(hvk.pipeline_color_blend_attachment_state(), ))

        dynamic_state = hvk.pipeline_dynamic_state_create_info(
            dynamic_states=(vk.DYNAMIC_STATE_VIEWPORT,
                            vk.DYNAMIC_STATE_SCISSOR))

        pipeline_infos = []
        for shader_index, objects in self._group_objects_by_shaders():
            shader = shaders[shader_index]

            for obj in objects:
                obj.pipeline = shader_index

            info = hvk.graphics_pipeline_create_info(
                stages=shader.stage_infos,
                vertex_input_state=shader.vertex_input_state,
                input_assembly_state=assembly,
                viewport_state=viewport,
                rasterization_state=raster,
                multisample_state=multisample,
                depth_stencil_state=depth_stencil,
                color_blend_state=color_blend,
                dynamic_state=dynamic_state,
                layout=shader.pipeline_layout,
                render_pass=rt.render_pass)

            pipeline_infos.append(info)

        self.pipeline_cache = hvk.create_pipeline_cache(
            api, device, hvk.pipeline_cache_create_info())

        if len(pipeline_infos) > 0:
            self.pipelines = hvk.create_graphics_pipelines(
                api, device, pipeline_infos, self.pipeline_cache)
        else:
            self.pipelines = []