From 18784e6500e66c6fd01ba8b02ec2fc732f37049e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Thu, 7 Feb 2019 09:59:16 +0100 Subject: [PATCH] vkd3d-shader: Translate vForkInstanceId registers. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Józef Kucia Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- libs/vkd3d-shader/spirv.c | 56 ++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index f14306e6..da9d162c 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -2320,6 +2320,9 @@ static bool vkd3d_dxbc_compiler_get_register_name(char *buffer, unsigned int buf case VKD3DSPR_DEPTHOUTLE: snprintf(buffer, buffer_size, "oDepth"); break; + case VKD3DSPR_FORKINSTID: + snprintf(buffer, buffer_size, "vForkInstanceId"); + break; case VKD3DSPR_TESSCOORD: snprintf(buffer, buffer_size, "vDomainLocation"); break; @@ -2756,12 +2759,21 @@ static uint32_t vkd3d_dxbc_compiler_emit_load_reg(struct vkd3d_dxbc_compiler *co } vkd3d_dxbc_compiler_emit_dereference_register(compiler, reg, ®_info); - if (component_count == 1) + /* Intermediate value (no storage class). */ + if (reg_info.storage_class == SpvStorageClassMax) + { + val_id = reg_info.id; + } + else if (component_count == 1) + { return vkd3d_dxbc_compiler_emit_load_scalar(compiler, reg, swizzle, write_mask, ®_info); - - type_id = vkd3d_spirv_get_type_id(builder, - reg_info.component_type, vkd3d_write_mask_component_count(reg_info.write_mask)); - val_id = vkd3d_spirv_build_op_load(builder, type_id, reg_info.id, SpvMemoryAccessMaskNone); + } + else + { + type_id = vkd3d_spirv_get_type_id(builder, + reg_info.component_type, vkd3d_write_mask_component_count(reg_info.write_mask)); + val_id = vkd3d_spirv_build_op_load(builder, type_id, reg_info.id, SpvMemoryAccessMaskNone); + } val_id = vkd3d_dxbc_compiler_emit_swizzle_ext(compiler, val_id, reg_info.write_mask, reg_info.component_type, swizzle, write_mask); @@ -3523,6 +3535,35 @@ static void vkd3d_dxbc_compiler_emit_input_register(struct vkd3d_dxbc_compiler * vkd3d_dxbc_compiler_emit_register_debug_name(builder, input_id, reg); } +static void vkd3d_dxbc_compiler_emit_shader_phase_input(struct vkd3d_dxbc_compiler *compiler, + const struct vkd3d_shader_phase *phase, const struct vkd3d_shader_dst_param *dst) +{ + struct vkd3d_spirv_builder *builder = &compiler->spirv_builder; + const struct vkd3d_shader_register *reg = &dst->reg; + struct vkd3d_symbol reg_symbol; + uint32_t val_id; + + switch (reg->type) + { + case VKD3DSPR_FORKINSTID: + val_id = phase->instance_id; + break; + default: + FIXME("Unhandled shader phase input register %#x.\n", reg->type); + return; + } + + vkd3d_symbol_make_register(®_symbol, reg); + reg_symbol.id = val_id; + reg_symbol.info.reg.storage_class = SpvStorageClassMax; /* Intermediate value */ + reg_symbol.info.reg.member_idx = 0; + reg_symbol.info.reg.component_type = VKD3D_TYPE_UINT; + reg_symbol.info.reg.write_mask = VKD3DSP_WRITEMASK_0; + reg_symbol.info.reg.is_aggregate = false; + vkd3d_dxbc_compiler_put_symbol(compiler, ®_symbol); + vkd3d_dxbc_compiler_emit_register_debug_name(builder, val_id, reg); +} + static unsigned int vkd3d_dxbc_compiler_get_output_variable_index( struct vkd3d_dxbc_compiler *compiler, unsigned int register_idx) { @@ -4515,8 +4556,11 @@ static void vkd3d_dxbc_compiler_emit_dcl_input(struct vkd3d_dxbc_compiler *compi const struct vkd3d_shader_instruction *instruction) { const struct vkd3d_shader_dst_param *dst = &instruction->declaration.dst; + const struct vkd3d_shader_phase *phase; - if (vkd3d_shader_register_is_input(&dst->reg)) + if ((phase = vkd3d_dxbc_compiler_get_current_shader_phase(compiler))) + vkd3d_dxbc_compiler_emit_shader_phase_input(compiler, phase, dst); + else if (vkd3d_shader_register_is_input(&dst->reg)) vkd3d_dxbc_compiler_emit_input(compiler, dst, VKD3D_SIV_NONE); else vkd3d_dxbc_compiler_emit_input_register(compiler, dst);