Exemplo n.º 1
0
    def _compile_shader(self):
        engine, api, device = self.ctx
        shader = self.shader
        constants = shader.mapping.get('constants')
        modules = []
        stage_infos = []

        modules_src = (
            (vk.SHADER_STAGE_VERTEX_BIT, shader.vert),
            (vk.SHADER_STAGE_FRAGMENT_BIT, shader.frag),
        )

        for stage, code in modules_src:
            module = hvk.create_shader_module(
                api, device, hvk.shader_module_create_info(code=code))
            modules.append(module)

            spez = None
            if constants is not None and len(constants) > 0:
                spez = setup_specialization_constants(stage, constants)

            stage_infos.append(
                hvk.pipeline_shader_stage_create_info(
                    stage=stage, module=module, specialization_info=spez))

        self.modules = modules
        self.stage_infos = stage_infos
Exemplo n.º 2
0
def create_compute_pipeline():
    global compute_pipeline, compute_pipeline_cache

    compute_pipeline_cache = hvk.create_pipeline_cache(
        api, device, hvk.pipeline_cache_create_info())

    compute_info = hvk.compute_pipeline_create_info(
        stage=hvk.pipeline_shader_stage_create_info(
            stage=vk.SHADER_STAGE_COMPUTE_BIT, module=compute_module),
        layout=compute_pipeline_layout)

    compute_pipelines = hvk.create_compute_pipelines(api, device,
                                                     (compute_info, ),
                                                     compute_pipeline_cache)
    compute_pipeline = compute_pipelines[0]
Exemplo n.º 3
0
    def _compile_shader(self):
        engine, api, device = self.ctx
        compute = self.compute

        module = hvk.create_shader_module(api, device, hvk.shader_module_create_info(code=compute.src))

        spez = None
        constants = compute.mapping.get('constants')
        if constants is not None and len(constants) > 0:
            spez = setup_specialization_constants(vk.SHADER_STAGE_COMPUTE_BIT, constants)

        stage = hvk.pipeline_shader_stage_create_info(
            stage = vk.SHADER_STAGE_COMPUTE_BIT,
            module = module,
            specialization_info = spez
        )

        self.module = module
        self.module_stage = stage
Exemplo n.º 4
0
def create_shaders():
    global shader_modules, stage_infos

    shader_modules, stage_infos = [], []
    shader_sources = {
        vk.SHADER_STAGE_VERTEX_BIT:
        'resources/shaders/simple_triangle/simple_triangle.vert.spv',
        vk.SHADER_STAGE_FRAGMENT_BIT:
        'resources/shaders/simple_triangle/simple_triangle.frag.spv'
    }
    for stage, src in shader_sources.items():
        with open(src, 'rb') as f:
            stage_module = hvk.create_shader_module(
                api, device, hvk.shader_module_create_info(code=f.read()))
            shader_modules.append(stage_module)

            stage_infos.append(
                hvk.pipeline_shader_stage_create_info(
                    stage=stage,
                    module=stage_module,
                ))